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, )
| 345 | // permissions produced by permsFunc based on the organization's current |
| 346 | // settings. |
| 347 | func 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 | } |
no test coverage detected