Accept display-style labels when resolving team invite roles.
Map inputs like Super Admin to built-in SUPER_ADMIN during team_role validation so invite API matches RBAC role keys. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
parent
2c107cf35a
commit
d276e3060f
|
|
@ -52,6 +52,17 @@ func NormalizeTeamRoleKey(role string) string {
|
|||
return strings.ToUpper(strings.TrimSpace(role))
|
||||
}
|
||||
|
||||
// CanonicalTeamRoleKey normalizes display-style role labels to underscore keys
|
||||
// (e.g. "Super Admin" / "super-admin" → "SUPER_ADMIN"). Does not alter custom RBAC
|
||||
// names that are looked up by exact/ignore-case match separately.
|
||||
func CanonicalTeamRoleKey(role string) string {
|
||||
s := strings.TrimSpace(role)
|
||||
s = strings.ReplaceAll(s, "-", " ")
|
||||
s = strings.ReplaceAll(s, "_", " ")
|
||||
fields := strings.Fields(s)
|
||||
return strings.ToUpper(strings.Join(fields, "_"))
|
||||
}
|
||||
|
||||
// TeamRoleForbiddenForMembers are platform learner roles that must not be assigned to team members.
|
||||
var TeamRoleForbiddenForMembers = map[string]struct{}{
|
||||
string(RoleStudent): {},
|
||||
|
|
|
|||
|
|
@ -28,3 +28,18 @@ func TestIsForbiddenTeamMemberRole(t *testing.T) {
|
|||
t.Fatal("custom staff role should be allowed")
|
||||
}
|
||||
}
|
||||
|
||||
func TestCanonicalTeamRoleKey(t *testing.T) {
|
||||
cases := map[string]string{
|
||||
"Super Admin": "SUPER_ADMIN",
|
||||
"super-admin": "SUPER_ADMIN",
|
||||
"SUPER_ADMIN": "SUPER_ADMIN",
|
||||
" admin ": "ADMIN",
|
||||
"Content Manager New": "CONTENT_MANAGER_NEW",
|
||||
}
|
||||
for in, want := range cases {
|
||||
if got := CanonicalTeamRoleKey(in); got != want {
|
||||
t.Fatalf("CanonicalTeamRoleKey(%q) = %q, want %q", in, got, want)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -60,13 +60,17 @@ func (s *Service) resolveAndValidateTeamRole(ctx context.Context, raw string) (d
|
|||
}
|
||||
|
||||
normalized := domain.NormalizeTeamRoleKey(key)
|
||||
if normalized == "" || domain.IsForbiddenTeamMemberRole(normalized) {
|
||||
canonical := domain.CanonicalTeamRoleKey(key)
|
||||
if normalized == "" || domain.IsForbiddenTeamMemberRole(normalized) || domain.IsForbiddenTeamMemberRole(canonical) {
|
||||
return "", teamRoleNotFoundError(raw)
|
||||
}
|
||||
|
||||
teamRole := domain.TeamRole(normalized)
|
||||
if teamRole.IsBuiltinTeamRole() {
|
||||
return teamRole, nil
|
||||
if domain.TeamRole(normalized).IsBuiltinTeamRole() {
|
||||
return domain.TeamRole(normalized), nil
|
||||
}
|
||||
// Accept UI display labels for built-ins (e.g. "Super Admin" → SUPER_ADMIN).
|
||||
if domain.TeamRole(canonical).IsBuiltinTeamRole() {
|
||||
return domain.TeamRole(canonical), nil
|
||||
}
|
||||
|
||||
rec, err := s.lookupRBACRole(ctx, key)
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user