-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathhelper.go
69 lines (57 loc) · 1.29 KB
/
helper.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
package acl
var listvalue = []int{1, 2, 4, 8, 16, 32, 64, 128}
var listgrantvalue = []AccessTypeEnum{1, 2, 4, 8, 16, 32, 64, 128}
var mapaccessenum = map[string]AccessTypeEnum{"create": 1, "read": 2, "update": 4,
"delete": 8, "special1": 16, "special2": 32, "special3": 64, "special4": 128}
func splitgrantvalue(in AccessTypeEnum) []int {
ain := make([]int, 0, 0)
for _, i := range listvalue {
if Matchaccess(i, int(in)) {
ain = append(ain, i)
}
}
return ain
}
func Splitinttogrant(in int) []AccessTypeEnum {
ain := make([]AccessTypeEnum, 0, 0)
for _, i := range listgrantvalue {
if Matchaccess(int(i), in) {
ain = append(ain, i)
}
}
return ain
}
func GetAccessEnum(key string) AccessTypeEnum {
v, k := mapaccessenum[key]
if k {
return v
}
return 0
}
func Matchaccess(searchAccess int, sourceAccess int) bool {
if searchAccess == (searchAccess & sourceAccess) {
return true
}
return false
}
func getgrantindex(ag []AccessGrant, AccessID string) (found bool, in int) {
found = false
for i, v := range ag {
if v.AccessID == AccessID {
in = i
found = true
break
}
}
return
}
func getlastpassword(UserId string) (passwd string) {
passwd = ""
tUser := new(User)
err := FindByID(tUser, UserId)
if err != nil {
return
}
passwd = tUser.Password
return
}