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

Function CreateSystemRole

coderd/rbac/rolestore/rolestore.go:347–374  ·  view source on GitHub ↗

CreateSystemRole inserts a new system role into the database with permissions produced by permsFunc based on the organization's current settings.

(
	ctx context.Context,
	tx database.Store,
	org database.Organization,
	roleName string,
)

Source from the content-addressed store, hash-verified

345// permissions produced by permsFunc based on the organization's current
346// settings.
347func CreateSystemRole(
348 ctx context.Context,
349 tx database.Store,
350 org database.Organization,
351 roleName string,
352) error {
353 permsFunc, ok := systemRoles[roleName]
354 if !ok {
355 panic("dev error: no permissions function exists for role " + roleName)
356 }
357 perms := permsFunc(orgSettings(org))
358
359 _, err := tx.InsertCustomRole(ctx, database.InsertCustomRoleParams{
360 Name: roleName,
361 DisplayName: "",
362 OrganizationID: uuid.NullUUID{UUID: org.ID, Valid: true},
363 SitePermissions: database.CustomRolePermissions{},
364 OrgPermissions: ConvertPermissionsToDB(perms.Org),
365 UserPermissions: database.CustomRolePermissions{},
366 MemberPermissions: ConvertPermissionsToDB(perms.Member),
367 IsSystem: true,
368 })
369 if err != nil {
370 return xerrors.Errorf("insert %s role: %w", roleName, err)
371 }
372
373 return nil
374}

Callers 2

OrganizationFunction · 0.92
ReconcileSystemRolesFunction · 0.85

Calls 4

orgSettingsFunction · 0.85
ConvertPermissionsToDBFunction · 0.85
InsertCustomRoleMethod · 0.65
ErrorfMethod · 0.45

Tested by

no test coverage detected