2022-01-26 10:16:33 +01:00
|
|
|
package query
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"strings"
|
|
|
|
|
2022-04-27 01:01:45 +02:00
|
|
|
"github.com/zitadel/zitadel/internal/api/authz"
|
|
|
|
"github.com/zitadel/zitadel/internal/domain"
|
2022-01-26 10:16:33 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
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) {
|
2022-06-14 07:51:00 +02:00
|
|
|
instance, err := q.Instance(ctx, false)
|
2022-01-26 10:16:33 +01:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
roles := make([]string, 0)
|
2022-06-14 07:51:00 +02:00
|
|
|
defaultOrg := authz.GetCtxData(ctx).OrgID == instance.DefaultOrgID
|
2022-01-26 10:16:33 +01:00
|
|
|
for _, roleMap := range q.zitadelRoles {
|
|
|
|
if strings.HasPrefix(roleMap.Role, "PROJECT") && !strings.HasPrefix(roleMap.Role, "PROJECT_GRANT") {
|
2022-06-14 07:51:00 +02:00
|
|
|
if defaultOrg && !strings.HasSuffix(roleMap.Role, "GLOBAL") {
|
2022-01-26 10:16:33 +01:00
|
|
|
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
|
|
|
|
}
|