Skip to content

Commit a2fcab8

Browse files
committed
Add custom role cli command
1 parent a3a7ec0 commit a2fcab8

File tree

2 files changed

+15
-17
lines changed

2 files changed

+15
-17
lines changed

cli/organizationroles.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,7 @@ customRoleLoop:
280280
for {
281281
selected, err := cliui.Select(inv, cliui.SelectOptions{
282282
Message: "Select which resources to edit permissions",
283-
Options: append(permissionPreviews(role, orgID, allowedResources), done, abort),
283+
Options: append(permissionPreviews(role, allowedResources), done, abort),
284284
})
285285
if err != nil {
286286
return role, xerrors.Errorf("selecting resource: %w", err)
@@ -297,12 +297,12 @@ customRoleLoop:
297297
actions, err := cliui.MultiSelect(inv, cliui.MultiSelectOptions{
298298
Message: fmt.Sprintf("Select actions to allow across the whole deployment for resources=%q", resource),
299299
Options: slice.ToStrings(codersdk.RBACResourceActions[codersdk.RBACResource(resource)]),
300-
Defaults: defaultActions(role, orgID, resource),
300+
Defaults: defaultActions(role, resource),
301301
})
302302
if err != nil {
303303
return role, xerrors.Errorf("selecting actions for resource %q: %w", resource, err)
304304
}
305-
applyOrgResourceActions(role, orgID, resource, actions)
305+
applyOrgResourceActions(role, resource, actions)
306306
// back to resources!
307307
}
308308
}
@@ -312,7 +312,7 @@ customRoleLoop:
312312
return role, nil
313313
}
314314

315-
func applyOrgResourceActions(role *codersdk.Role, orgID uuid.UUID, resource string, actions []string) {
315+
func applyOrgResourceActions(role *codersdk.Role, resource string, actions []string) {
316316
if role.OrganizationPermissions == nil {
317317
role.OrganizationPermissions = make([]codersdk.Permission, 0)
318318
}
@@ -338,7 +338,7 @@ func applyOrgResourceActions(role *codersdk.Role, orgID uuid.UUID, resource stri
338338
role.OrganizationPermissions = keep
339339
}
340340

341-
func defaultActions(role *codersdk.Role, orgID uuid.UUID, resource string) []string {
341+
func defaultActions(role *codersdk.Role, resource string) []string {
342342
if role.OrganizationPermissions == nil {
343343
role.OrganizationPermissions = []codersdk.Permission{}
344344
}
@@ -352,15 +352,15 @@ func defaultActions(role *codersdk.Role, orgID uuid.UUID, resource string) []str
352352
return defaults
353353
}
354354

355-
func permissionPreviews(role *codersdk.Role, orgID uuid.UUID, resources []codersdk.RBACResource) []string {
355+
func permissionPreviews(role *codersdk.Role, resources []codersdk.RBACResource) []string {
356356
previews := make([]string, 0, len(resources))
357357
for _, resource := range resources {
358-
previews = append(previews, permissionPreview(role, orgID, resource))
358+
previews = append(previews, permissionPreview(role, resource))
359359
}
360360
return previews
361361
}
362362

363-
func permissionPreview(role *codersdk.Role, orgID uuid.UUID, resource codersdk.RBACResource) string {
363+
func permissionPreview(role *codersdk.Role, resource codersdk.RBACResource) string {
364364
if role.OrganizationPermissions == nil {
365365
role.OrganizationPermissions = []codersdk.Permission{}
366366
}

enterprise/cli/organization_test.go

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -39,17 +39,15 @@ func TestEditOrganizationRoles(t *testing.T) {
3939
// Use json input, as interactive mode would be challenging to control
4040
inv.Stdin = bytes.NewBufferString(fmt.Sprintf(`{
4141
"name": "new-role",
42-
"organization_id": "%[1]s",
42+
"organization_id": "%s",
4343
"display_name": "",
4444
"site_permissions": [],
45-
"organization_permissions": {
46-
"%[1]s": [
47-
{
48-
"resource_type": "workspace",
49-
"action": "read"
50-
}
51-
]
52-
},
45+
"organization_permissions": [
46+
{
47+
"resource_type": "workspace",
48+
"action": "read"
49+
}
50+
],
5351
"user_permissions": [],
5452
"assignable": false,
5553
"built_in": false

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy