TestAssignCustomOrgRoles verifies an organization admin (not just an owner) can create a custom role and assign it to an organization user.
(t *testing.T)
| 249 | // TestAssignCustomOrgRoles verifies an organization admin (not just an owner) can create |
| 250 | // a custom role and assign it to an organization user. |
| 251 | func TestAssignCustomOrgRoles(t *testing.T) { |
| 252 | t.Parallel() |
| 253 | |
| 254 | ownerClient, owner := coderdenttest.New(t, &coderdenttest.Options{ |
| 255 | Options: &coderdtest.Options{ |
| 256 | IncludeProvisionerDaemon: true, |
| 257 | }, |
| 258 | LicenseOptions: &coderdenttest.LicenseOptions{ |
| 259 | Features: license.Features{ |
| 260 | codersdk.FeatureCustomRoles: 1, |
| 261 | }, |
| 262 | }, |
| 263 | }) |
| 264 | |
| 265 | client, _ := coderdtest.CreateAnotherUser(t, ownerClient, owner.OrganizationID, rbac.ScopedRoleOrgAdmin(owner.OrganizationID)) |
| 266 | tv := coderdtest.CreateTemplateVersion(t, client, owner.OrganizationID, nil) |
| 267 | coderdtest.AwaitTemplateVersionJobCompleted(t, client, tv.ID) |
| 268 | |
| 269 | ctx := testutil.Context(t, testutil.WaitShort) |
| 270 | // Create a custom role as an organization admin that allows making templates. |
| 271 | auditorRole, err := client.CreateOrganizationRole(ctx, codersdk.Role{ |
| 272 | Name: "org-template-admin", |
| 273 | OrganizationID: owner.OrganizationID.String(), |
| 274 | DisplayName: "Template Admin", |
| 275 | SitePermissions: nil, |
| 276 | OrganizationPermissions: codersdk.CreatePermissions(map[codersdk.RBACResource][]codersdk.RBACAction{ |
| 277 | codersdk.ResourceTemplate: codersdk.RBACResourceActions[codersdk.ResourceTemplate], // All template perms |
| 278 | }), |
| 279 | UserPermissions: nil, |
| 280 | }) |
| 281 | require.NoError(t, err) |
| 282 | |
| 283 | createTemplateReq := codersdk.CreateTemplateRequest{ |
| 284 | Name: "name", |
| 285 | DisplayName: "Template", |
| 286 | VersionID: tv.ID, |
| 287 | } |
| 288 | memberClient, member := coderdtest.CreateAnotherUser(t, ownerClient, owner.OrganizationID) |
| 289 | // Check the member cannot create a template |
| 290 | _, err = memberClient.CreateTemplate(ctx, owner.OrganizationID, createTemplateReq) |
| 291 | require.Error(t, err) |
| 292 | |
| 293 | // Assign new role to the member as the org admin |
| 294 | _, err = client.UpdateOrganizationMemberRoles(ctx, owner.OrganizationID, member.ID.String(), codersdk.UpdateRoles{ |
| 295 | Roles: []string{auditorRole.Name}, |
| 296 | }) |
| 297 | require.NoError(t, err) |
| 298 | |
| 299 | // Now the member can create the template |
| 300 | _, err = memberClient.CreateTemplate(ctx, owner.OrganizationID, createTemplateReq) |
| 301 | require.NoError(t, err) |
| 302 | } |
| 303 | |
| 304 | func TestGrantSiteRoles(t *testing.T) { |
| 305 | t.Parallel() |
nothing calls this directly
no test coverage detected