mirror of
https://github.com/coder/coder.git
synced 2026-06-02 20:48:20 +00:00
chore: create type for unique role names (#13506)
* chore: create type for unique role names Using `string` was confusing when something should be combined with org context, and when not to. Naming this new name, "RoleIdentifier"
This commit is contained in:
@@ -7,6 +7,7 @@ import (
|
||||
|
||||
"golang.org/x/exp/maps"
|
||||
"golang.org/x/oauth2"
|
||||
"golang.org/x/xerrors"
|
||||
|
||||
"github.com/coder/coder/v2/coderd/database/dbtime"
|
||||
"github.com/coder/coder/v2/coderd/rbac"
|
||||
@@ -373,3 +374,22 @@ func (p ProvisionerJob) FinishedAt() time.Time {
|
||||
|
||||
return time.Time{}
|
||||
}
|
||||
|
||||
func (r CustomRole) RoleIdentifier() rbac.RoleIdentifier {
|
||||
return rbac.RoleIdentifier{
|
||||
Name: r.Name,
|
||||
OrganizationID: r.OrganizationID.UUID,
|
||||
}
|
||||
}
|
||||
|
||||
func (r GetAuthorizationUserRolesRow) RoleNames() ([]rbac.RoleIdentifier, error) {
|
||||
names := make([]rbac.RoleIdentifier, 0, len(r.Roles))
|
||||
for _, role := range r.Roles {
|
||||
value, err := rbac.RoleNameFromString(role)
|
||||
if err != nil {
|
||||
return nil, xerrors.Errorf("convert role %q: %w", role, err)
|
||||
}
|
||||
names = append(names, value)
|
||||
}
|
||||
return names, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user