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

Method convertToOrganizationRoles

coderd/database/dbauthz/dbauthz.go:1193–1206  ·  view source on GitHub ↗

convertToOrganizationRoles converts a set of scoped role names to their unique scoped names. The database stores roles as an array of strings, and needs to be converted. TODO: Maybe make `[]rbac.RoleIdentifier` a custom type that implements a sql scanner to remove the need for these converters?

(organizationID uuid.UUID, names []string)

Source from the content-addressed store, hash-verified

1191// TODO: Maybe make `[]rbac.RoleIdentifier` a custom type that implements a sql scanner
1192// to remove the need for these converters?
1193func (*querier) convertToOrganizationRoles(organizationID uuid.UUID, names []string) ([]rbac.RoleIdentifier, error) {
1194 uniques := make([]rbac.RoleIdentifier, 0, len(names))
1195 for _, name := range names {
1196 // This check is a developer safety check. Old code might try to invoke this code path with
1197 // organization id suffixes. Catch this and return a nice error so it can be fixed.
1198 if strings.Contains(name, ":") {
1199 return nil, xerrors.Errorf("attempt to assign a role %q, remove the ':<organization_id> suffix", name)
1200 }
1201
1202 uniques = append(uniques, rbac.RoleIdentifier{Name: name, OrganizationID: organizationID})
1203 }
1204
1205 return uniques, nil
1206}
1207
1208// convertToDeploymentRoles converts string role names into deployment wide roles.
1209func (*querier) convertToDeploymentRoles(names []string) []rbac.RoleIdentifier {

Callers 2

UpdateMemberRolesMethod · 0.95

Calls 2

ContainsMethod · 0.45
ErrorfMethod · 0.45

Tested by

no test coverage detected