MCPcopy Index your code
hub / github.com/coder/coder / RoleByName

Function RoleByName

coderd/rbac/roles.go:845–867  ·  view source on GitHub ↗

RoleByName returns the permissions associated with a given role name. This allows just the role names to be stored and expanded when required. This function is exported so that the Display name can be returned to the api. We should maybe make an exported function that returns just the human-readabl

(name RoleIdentifier)

Source from the content-addressed store, hash-verified

843// api. We should maybe make an exported function that returns just the
844// human-readable content of the Role struct (name + display name).
845func RoleByName(name RoleIdentifier) (Role, error) {
846 roleFunc, ok := builtInRoles[name.Name]
847 if !ok {
848 // No role found
849 return Role{}, xerrors.Errorf("role %q not found", name.String())
850 }
851
852 // Ensure all org roles are properly scoped a non-empty organization id.
853 // This is just some defensive programming.
854 role := roleFunc(name.OrganizationID)
855 if len(role.ByOrgID) > 0 && name.OrganizationID == uuid.Nil {
856 return Role{}, xerrors.Errorf("expect a org id for role %q", name.String())
857 }
858
859 // This can happen if a custom role shares the same name as a built-in role.
860 // You could make an org role called "owner", and we should not return the
861 // owner role itself.
862 if name.OrganizationID != role.Identifier.OrganizationID {
863 return Role{}, xerrors.Errorf("role %q not found", name.String())
864 }
865
866 return role, nil
867}
868
869func rolesByNames(roleNames []RoleIdentifier) ([]Role, error) {
870 roles := make([]Role, 0, len(roleNames))

Callers 15

TestWorkspaceUpdatesFunction · 0.92
TestCacheRBACFunction · 0.92
syncSiteWideRolesMethod · 0.92
MemberSubjectFunction · 0.92
TestRolePermissionsFunction · 0.92
ExpandFunction · 0.92
TestAuthorizedAuditLogsFunction · 0.92
SlimRoleFromNameFunction · 0.92
TestInsertCustomRolesFunction · 0.92

Calls 2

ErrorfMethod · 0.45
StringMethod · 0.45

Tested by 14

TestWorkspaceUpdatesFunction · 0.74
TestCacheRBACFunction · 0.74
TestRolePermissionsFunction · 0.74
TestAuthorizedAuditLogsFunction · 0.74
TestInsertCustomRolesFunction · 0.74
convertRoleFunction · 0.74
TestAuthorizeDomainFunction · 0.68
TestAuthorizeLevelsFunction · 0.68
TestAuthorizeScopeFunction · 0.68