Skip to content

Commit

Permalink
Merge pull request cosmo-workspace#794 from jlandowner/change-group-a…
Browse files Browse the repository at this point in the history
…dmin

Support group-admin is admin for group
  • Loading branch information
oruharo authored Aug 2, 2023
2 parents 1b22a8a + 6477b4a commit d6bd69d
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
9 changes: 8 additions & 1 deletion api/v1alpha1/user_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,14 @@ type UserRole struct {
func (r UserRole) GetGroupAndRole() (group string, role string) {
v := strings.Split(r.Name, "-")
if len(v) > 0 {
return strings.Join(v[:len(v)-1], "-"), v[len(v)-1]
group := strings.Join(v[:len(v)-1], "-")
role := v[len(v)-1]

if group == "" {
return r.Name, ""
}

return group, role
}
return r.Name, ""
}
Expand Down
24 changes: 24 additions & 0 deletions api/v1alpha1/user_types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,30 @@ func TestUserRole_GetGroupAndRole(t *testing.T) {
wantGroup: "cosmo-admin",
wantRole: "developer",
},
{
name: "non-admin: no hyphen",
fields: fields{
Name: "チームX",
},
wantGroup: "チームX",
wantRole: "",
},
{
name: "non-admin: prefix",
fields: fields{
Name: "-XXX",
},
wantGroup: "-XXX",
wantRole: "",
},
{
name: "admin: prefix",
fields: fields{
Name: "-XXX-admin",
},
wantGroup: "-XXX",
wantRole: "admin",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
Expand Down

0 comments on commit d6bd69d

Please sign in to comment.