(t *testing.T)
| 116 | } |
| 117 | |
| 118 | func TestAssignOrganizationMemberRole(t *testing.T) { |
| 119 | t.Parallel() |
| 120 | |
| 121 | t.Run("OK", func(t *testing.T) { |
| 122 | t.Parallel() |
| 123 | ownerClient, owner := coderdenttest.New(t, &coderdenttest.Options{ |
| 124 | LicenseOptions: &coderdenttest.LicenseOptions{ |
| 125 | Features: license.Features{ |
| 126 | codersdk.FeatureCustomRoles: 1, |
| 127 | }, |
| 128 | }, |
| 129 | }) |
| 130 | _, user := coderdtest.CreateAnotherUser(t, ownerClient, owner.OrganizationID, rbac.RoleUserAdmin()) |
| 131 | |
| 132 | ctx := testutil.Context(t, testutil.WaitMedium) |
| 133 | // nolint:gocritic // requires owner role to create |
| 134 | customRole, err := ownerClient.CreateOrganizationRole(ctx, codersdk.Role{ |
| 135 | Name: "custom-role", |
| 136 | OrganizationID: owner.OrganizationID.String(), |
| 137 | DisplayName: "Custom Role", |
| 138 | SitePermissions: nil, |
| 139 | OrganizationPermissions: codersdk.CreatePermissions(map[codersdk.RBACResource][]codersdk.RBACAction{ |
| 140 | codersdk.ResourceWorkspace: {codersdk.ActionRead}, |
| 141 | }), |
| 142 | UserPermissions: nil, |
| 143 | }) |
| 144 | require.NoError(t, err) |
| 145 | |
| 146 | inv, root := clitest.New(t, "organization", "members", "edit-roles", user.Username, codersdk.RoleOrganizationAdmin, customRole.Name) |
| 147 | // nolint:gocritic // you cannot change your own roles |
| 148 | clitest.SetupConfig(t, ownerClient, root) |
| 149 | |
| 150 | buf := new(bytes.Buffer) |
| 151 | inv.Stdout = buf |
| 152 | err = inv.WithContext(ctx).Run() |
| 153 | require.NoError(t, err) |
| 154 | require.Contains(t, buf.String(), must(rbac.RoleByName(rbac.ScopedRoleOrgAdmin(owner.OrganizationID))).DisplayName) |
| 155 | require.Contains(t, buf.String(), customRole.DisplayName) |
| 156 | }) |
| 157 | } |
| 158 | |
| 159 | func must[V any](v V, err error) V { |
| 160 | if err != nil { |
nothing calls this directly
no test coverage detected