-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathdn.go
68 lines (56 loc) · 1.23 KB
/
dn.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
package organization
import (
"fmt"
"github.com/DoloresTeam/organization/godn"
"github.com/rs/xid"
)
const (
member = 0
role = 1
unitPermission = 2
memberPermission = 3
unitType = 4
memberType = 5
unit = 6
audit = 7
)
func (org *Organization) dn(id string, category int) string {
return fmt.Sprintf(`id=%s,%s`, id, org.parentDN(category))
}
func (org *Organization) parentDN(category int) string {
baseDN := org.subffix
switch category {
case member:
baseDN = godn.Member(org.subffix)
case role:
baseDN = godn.Role(org.subffix)
case unitPermission:
baseDN = godn.Permission(org.subffix, true)
case memberPermission:
baseDN = godn.Permission(org.subffix, false)
case unitType:
baseDN = godn.DoloresType(org.subffix, true)
case memberType:
baseDN = godn.DoloresType(org.subffix, false)
case unit:
baseDN = godn.Unit(org.subffix)
case audit:
baseDN = godn.Audit(org.subffix)
}
return baseDN
}
func typeCategory(isUnit bool) int {
if isUnit {
return unitType
}
return memberType
}
func permissionCategory(isUnit bool) int {
if isUnit {
return unitPermission
}
return memberPermission
}
func generateNewID() string {
return xid.New().String()
}