-
Notifications
You must be signed in to change notification settings - Fork 482
/
member_roles.go
60 lines (54 loc) · 1.44 KB
/
member_roles.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
package query
import (
"context"
"strings"
"github.com/zitadel/zitadel/internal/api/authz"
"github.com/zitadel/zitadel/internal/domain"
)
func (q *Queries) GetIAMMemberRoles() []string {
roles := make([]string, 0)
for _, roleMap := range q.zitadelRoles {
if strings.HasPrefix(roleMap.Role, "IAM") {
roles = append(roles, roleMap.Role)
}
}
return roles
}
func (q *Queries) GetOrgMemberRoles(isGlobal bool) []string {
roles := make([]string, 0)
for _, roleMap := range q.zitadelRoles {
if strings.HasPrefix(roleMap.Role, "ORG") {
roles = append(roles, roleMap.Role)
}
}
if isGlobal {
roles = append(roles, domain.RoleSelfManagementGlobal)
}
return roles
}
func (q *Queries) GetProjectMemberRoles(ctx context.Context) ([]string, error) {
iam, err := q.IAMByID(ctx, domain.IAMID)
if err != nil {
return nil, err
}
roles := make([]string, 0)
global := authz.GetCtxData(ctx).OrgID == iam.GlobalOrgID
for _, roleMap := range q.zitadelRoles {
if strings.HasPrefix(roleMap.Role, "PROJECT") && !strings.HasPrefix(roleMap.Role, "PROJECT_GRANT") {
if global && !strings.HasSuffix(roleMap.Role, "GLOBAL") {
continue
}
roles = append(roles, roleMap.Role)
}
}
return roles, nil
}
func (q *Queries) GetProjectGrantMemberRoles() []string {
roles := make([]string, 0)
for _, roleMap := range q.zitadelRoles {
if strings.HasPrefix(roleMap.Role, "PROJECT_GRANT") {
roles = append(roles, roleMap.Role)
}
}
return roles
}