@@ -314,16 +314,12 @@ customRoleLoop:
314
314
315
315
func applyOrgResourceActions (role * codersdk.Role , orgID uuid.UUID , resource string , actions []string ) {
316
316
if role .OrganizationPermissions == nil {
317
- role .OrganizationPermissions = map [string ][]codersdk.Permission {}
318
- }
319
-
320
- if _ , ok := role .OrganizationPermissions [orgID .String ()]; ! ok {
321
- role .OrganizationPermissions [orgID .String ()] = []codersdk.Permission {}
317
+ role .OrganizationPermissions = make ([]codersdk.Permission , 0 )
322
318
}
323
319
324
320
// Construct new site perms with only new perms for the resource
325
321
keep := make ([]codersdk.Permission , 0 )
326
- for _ , perm := range role .OrganizationPermissions [ orgID . String ()] {
322
+ for _ , perm := range role .OrganizationPermissions {
327
323
perm := perm
328
324
if string (perm .ResourceType ) != resource {
329
325
keep = append (keep , perm )
@@ -339,16 +335,16 @@ func applyOrgResourceActions(role *codersdk.Role, orgID uuid.UUID, resource stri
339
335
})
340
336
}
341
337
342
- role .OrganizationPermissions [ orgID . String ()] = keep
338
+ role .OrganizationPermissions = keep
343
339
}
344
340
345
341
func defaultActions (role * codersdk.Role , orgID uuid.UUID , resource string ) []string {
346
342
if role .OrganizationPermissions == nil {
347
- role .OrganizationPermissions = map [ string ] []codersdk.Permission {}
343
+ role .OrganizationPermissions = []codersdk.Permission {}
348
344
}
349
345
350
346
defaults := make ([]string , 0 )
351
- for _ , perm := range role .OrganizationPermissions [ orgID . String ()] {
347
+ for _ , perm := range role .OrganizationPermissions {
352
348
if string (perm .ResourceType ) == resource {
353
349
defaults = append (defaults , string (perm .Action ))
354
350
}
@@ -366,11 +362,11 @@ func permissionPreviews(role *codersdk.Role, orgID uuid.UUID, resources []coders
366
362
367
363
func permissionPreview (role * codersdk.Role , orgID uuid.UUID , resource codersdk.RBACResource ) string {
368
364
if role .OrganizationPermissions == nil {
369
- role .OrganizationPermissions = map [ string ] []codersdk.Permission {}
365
+ role .OrganizationPermissions = []codersdk.Permission {}
370
366
}
371
367
372
368
count := 0
373
- for _ , perm := range role .OrganizationPermissions [ orgID . String ()] {
369
+ for _ , perm := range role .OrganizationPermissions {
374
370
if perm .ResourceType == resource {
375
371
count ++
376
372
}
@@ -382,28 +378,17 @@ func roleToTableView(role codersdk.Role) roleTableRow {
382
378
return roleTableRow {
383
379
Name : role .Name ,
384
380
DisplayName : role .DisplayName ,
381
+ OrganizationID : role .OrganizationID ,
385
382
SitePermissions : fmt .Sprintf ("%d permissions" , len (role .SitePermissions )),
386
- OrganizationPermissions : orgPermissionString ( role .OrganizationPermissions ),
383
+ OrganizationPermissions : fmt . Sprintf ( "%d permissions" , len ( role .OrganizationPermissions ) ),
387
384
UserPermissions : fmt .Sprintf ("%d permissions" , len (role .UserPermissions )),
388
385
}
389
386
}
390
387
391
- func orgPermissionString (perms map [string ][]codersdk.Permission ) string {
392
- totalOrg := 0
393
- for _ , o := range perms {
394
- totalOrg += len (o )
395
- }
396
- plural := ""
397
- if len (perms ) > 1 {
398
- plural = "s"
399
- }
400
- return fmt .Sprintf ("%d over %d organization%s" ,
401
- totalOrg , len (perms ), plural )
402
- }
403
-
404
388
type roleTableRow struct {
405
389
Name string `table:"name,default_sort"`
406
390
DisplayName string `table:"display_name"`
391
+ OrganizationID string `table:"organization_id"`
407
392
SitePermissions string ` table:"site_permissions"`
408
393
// map[<org_id>] -> Permissions
409
394
OrganizationPermissions string `table:"org_permissions"`
0 commit comments