Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commita79bb89

Browse files
committed
chore: include custom roles in list org roles
1 parentfa9edc1 commita79bb89

File tree

14 files changed

+123
-34
lines changed

14 files changed

+123
-34
lines changed

‎coderd/apidoc/docs.go

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more aboutcustomizing how changed files appear on GitHub.

‎coderd/apidoc/swagger.json

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more aboutcustomizing how changed files appear on GitHub.

‎coderd/database/db2sdk/db2sdk.go

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -527,12 +527,17 @@ func ProvisionerDaemon(dbDaemon database.ProvisionerDaemon) codersdk.Provisioner
527527
}
528528

529529
funcRole(role rbac.Role) codersdk.Role {
530+
roleName,orgIDStr,err:=rbac.RoleSplit(role.Name)
531+
iferr!=nil {
532+
roleName=role.Name
533+
}
530534
return codersdk.Role{
531-
Name:role.Name,
535+
Name:roleName,
536+
OrganizationID:orgIDStr,
532537
DisplayName:role.DisplayName,
533538
SitePermissions:List(role.Site,Permission),
534539
OrganizationPermissions:Map(role.Org,ListLazy(Permission)),
535-
UserPermissions:List(role.Site,Permission),
540+
UserPermissions:List(role.User,Permission),
536541
}
537542
}
538543

@@ -546,7 +551,7 @@ func Permission(permission rbac.Permission) codersdk.Permission {
546551

547552
funcRoleToRBAC(role codersdk.Role) rbac.Role {
548553
return rbac.Role{
549-
Name:role.Name,
554+
Name:rbac.RoleName(role.Name,role.OrganizationID),
550555
DisplayName:role.DisplayName,
551556
Site:List(role.SitePermissions,PermissionToRBAC),
552557
Org:Map(role.OrganizationPermissions,ListLazy(PermissionToRBAC)),

‎coderd/database/models.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more aboutcustomizing how changed files appear on GitHub.

‎coderd/database/querier.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more aboutcustomizing how changed files appear on GitHub.

‎coderd/database/queries.sql.go

Lines changed: 17 additions & 7 deletions
Some generated files are not rendered by default. Learn more aboutcustomizing how changed files appear on GitHub.

‎coderd/database/queries/roles.sql

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,19 @@ WHERE
1616
organization_id ISnull
1717
ELSE true
1818
END
19+
-- Org scoping filter, to only fetch site wide roles
20+
AND CASE WHEN @organization_id :: uuid!='00000000-0000-0000-0000-000000000000'::uuid THEN
21+
organization_id= @organization_id
22+
ELSE true
23+
END
1924
;
2025

2126
-- name: UpsertCustomRole :one
2227
INSERT INTO
2328
custom_roles (
2429
name,
2530
display_name,
31+
organization_id,
2632
site_permissions,
2733
org_permissions,
2834
user_permissions,
@@ -33,6 +39,7 @@ VALUES (
3339
-- Always force lowercase names
3440
lower(@name),
3541
@display_name,
42+
@organization_id,
3643
@site_permissions,
3744
@org_permissions,
3845
@user_permissions,

‎coderd/rbac/roles.go

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -53,29 +53,29 @@ func (names RoleNames) Names() []string {
5353
// site and orgs, and these functions can be removed.
5454

5555
funcRoleOwner()string {
56-
returnroleName(owner,"")
56+
returnRoleName(owner,"")
5757
}
5858

59-
funcCustomSiteRole()string {returnroleName(customSiteRole,"") }
59+
funcCustomSiteRole()string {returnRoleName(customSiteRole,"") }
6060

6161
funcRoleTemplateAdmin()string {
62-
returnroleName(templateAdmin,"")
62+
returnRoleName(templateAdmin,"")
6363
}
6464

6565
funcRoleUserAdmin()string {
66-
returnroleName(userAdmin,"")
66+
returnRoleName(userAdmin,"")
6767
}
6868

6969
funcRoleMember()string {
70-
returnroleName(member,"")
70+
returnRoleName(member,"")
7171
}
7272

7373
funcRoleOrgAdmin(organizationID uuid.UUID)string {
74-
returnroleName(orgAdmin,organizationID.String())
74+
returnRoleName(orgAdmin,organizationID.String())
7575
}
7676

7777
funcRoleOrgMember(organizationID uuid.UUID)string {
78-
returnroleName(orgMember,organizationID.String())
78+
returnRoleName(orgMember,organizationID.String())
7979
}
8080

8181
funcallPermsExcept(excepts...Objecter) []Permission {
@@ -273,7 +273,7 @@ func ReloadBuiltinRoles(opts *RoleOptions) {
273273
// organization scope.
274274
orgAdmin:func(organizationIDstring)Role {
275275
returnRole{
276-
Name:roleName(orgAdmin,organizationID),
276+
Name:RoleName(orgAdmin,organizationID),
277277
DisplayName:"Organization Admin",
278278
Site: []Permission{},
279279
Org:map[string][]Permission{
@@ -291,7 +291,7 @@ func ReloadBuiltinRoles(opts *RoleOptions) {
291291
// in an organization.
292292
orgMember:func(organizationIDstring)Role {
293293
returnRole{
294-
Name:roleName(orgMember,organizationID),
294+
Name:RoleName(orgMember,organizationID),
295295
DisplayName:"",
296296
Site: []Permission{},
297297
Org:map[string][]Permission{
@@ -475,13 +475,13 @@ func CanAssignRole(expandable ExpandableRoles, assignedRole string) bool {
475475
// For CanAssignRole, we only care about the names of the roles.
476476
roles:=expandable.Names()
477477

478-
assigned,assignedOrg,err:=roleSplit(assignedRole)
478+
assigned,assignedOrg,err:=RoleSplit(assignedRole)
479479
iferr!=nil {
480480
returnfalse
481481
}
482482

483483
for_,longRole:=rangeroles {
484-
role,orgID,err:=roleSplit(longRole)
484+
role,orgID,err:=RoleSplit(longRole)
485485
iferr!=nil {
486486
continue
487487
}
@@ -510,7 +510,7 @@ func CanAssignRole(expandable ExpandableRoles, assignedRole string) bool {
510510
// api. We should maybe make an exported function that returns just the
511511
// human-readable content of the Role struct (name + display name).
512512
funcRoleByName(namestring) (Role,error) {
513-
roleName,orgID,err:=roleSplit(name)
513+
roleName,orgID,err:=RoleSplit(name)
514514
iferr!=nil {
515515
returnRole{},xerrors.Errorf("parse role name: %w",err)
516516
}
@@ -544,7 +544,7 @@ func rolesByNames(roleNames []string) ([]Role, error) {
544544
}
545545

546546
funcIsOrgRole(roleNamestring) (string,bool) {
547-
_,orgID,err:=roleSplit(roleName)
547+
_,orgID,err:=RoleSplit(roleName)
548548
iferr==nil&&orgID!="" {
549549
returnorgID,true
550550
}
@@ -561,7 +561,7 @@ func OrganizationRoles(organizationID uuid.UUID) []Role {
561561
varroles []Role
562562
for_,roleF:=rangebuiltInRoles {
563563
role:=roleF(organizationID.String())
564-
_,scope,err:=roleSplit(role.Name)
564+
_,scope,err:=RoleSplit(role.Name)
565565
iferr!=nil {
566566
// This should never happen
567567
continue
@@ -582,7 +582,7 @@ func SiteRoles() []Role {
582582
varroles []Role
583583
for_,roleF:=rangebuiltInRoles {
584584
role:=roleF("random")
585-
_,scope,err:=roleSplit(role.Name)
585+
_,scope,err:=RoleSplit(role.Name)
586586
iferr!=nil {
587587
// This should never happen
588588
continue
@@ -625,19 +625,19 @@ func ChangeRoleSet(from []string, to []string) (added []string, removed []string
625625
returnadded,removed
626626
}
627627

628-
//roleName is a quick helper function to return
628+
//RoleName is a quick helper function to return
629629
//
630630
//role_name:scopeID
631631
//
632632
// If no scopeID is required, only 'role_name' is returned
633-
funcroleName(namestring,orgIDstring)string {
633+
funcRoleName(namestring,orgIDstring)string {
634634
iforgID=="" {
635635
returnname
636636
}
637637
returnname+":"+orgID
638638
}
639639

640-
funcroleSplit(rolestring) (namestring,orgIDstring,errerror) {
640+
funcRoleSplit(rolestring) (namestring,orgIDstring,errerror) {
641641
arr:=strings.Split(role,":")
642642
iflen(arr)>2 {
643643
return"","",xerrors.Errorf("too many colons in role name")

‎coderd/rbac/rolestore/rolestore.go

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"encoding/json"
66
"net/http"
77

8+
"github.com/google/uuid"
89
"golang.org/x/xerrors"
910

1011
"github.com/coder/coder/v2/coderd/database"
@@ -95,8 +96,12 @@ func Expand(ctx context.Context, db database.Store, names []string) (rbac.Roles,
9596
}
9697

9798
funcConvertDBRole(dbRole database.CustomRole) (rbac.Role,error) {
99+
name:=dbRole.Name
100+
ifdbRole.OrganizationID.Valid {
101+
name=rbac.RoleName(dbRole.Name,dbRole.OrganizationID.UUID.String())
102+
}
98103
role:= rbac.Role{
99-
Name:dbRole.Name,
104+
Name:name,
100105
DisplayName:dbRole.DisplayName,
101106
Site:nil,
102107
Org:nil,
@@ -122,11 +127,27 @@ func ConvertDBRole(dbRole database.CustomRole) (rbac.Role, error) {
122127
}
123128

124129
funcConvertRoleToDB(role rbac.Role) (database.CustomRole,error) {
130+
roleName,orgIDStr,err:=rbac.RoleSplit(role.Name)
131+
iferr!=nil {
132+
return database.CustomRole{},xerrors.Errorf("split role %q: %w",role.Name,err)
133+
}
134+
125135
dbRole:= database.CustomRole{
126-
Name:role.Name,
136+
Name:roleName,
127137
DisplayName:role.DisplayName,
128138
}
129139

140+
iforgIDStr!="" {
141+
orgID,err:=uuid.Parse(orgIDStr)
142+
iferr!=nil {
143+
return database.CustomRole{},xerrors.Errorf("parse org id %q: %w",orgIDStr,err)
144+
}
145+
dbRole.OrganizationID= uuid.NullUUID{
146+
UUID:orgID,
147+
Valid:true,
148+
}
149+
}
150+
130151
siteData,err:=json.Marshal(role.Site)
131152
iferr!=nil {
132153
returndbRole,xerrors.Errorf("marshal site permissions: %w",err)

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp