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

Commitde9c2e9

Browse files
committed
fix: don't requireorganization_id in body when updating a custom role
1 parenta27ac30 commitde9c2e9

File tree

4 files changed

+27
-17
lines changed

4 files changed

+27
-17
lines changed

‎cli/organizationroles.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ func (r *RootCmd) editOrganizationRole(orgContext *OrganizationContext) *serpent
203203
// Do not actually post
204204
updated=customRole
205205
}else {
206-
updated,err=client.PatchOrganizationRole(ctx,org.ID,customRole)
206+
updated,err=client.PatchOrganizationRole(ctx,customRole)
207207
iferr!=nil {
208208
returnxerrors.Errorf("patch role: %w",err)
209209
}

‎coderd/roles.go‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,12 @@ import (
2020
// roles. Ideally only included in the enterprise package, but the routes are
2121
// intermixed with AGPL endpoints.
2222
typeCustomRoleHandlerinterface {
23-
PatchOrganizationRole(ctx context.Context,rw http.ResponseWriter,r*http.Request,orgID uuid.UUID,role codersdk.Role) (codersdk.Role,bool)
23+
PatchOrganizationRole(ctx context.Context,rw http.ResponseWriter,r*http.Request,orgID uuid.UUID,role codersdk.PatchRoleRequest) (codersdk.Role,bool)
2424
}
2525

2626
typeagplCustomRoleHandlerstruct{}
2727

28-
func (agplCustomRoleHandler)PatchOrganizationRole(ctx context.Context,rw http.ResponseWriter,_*http.Request,_ uuid.UUID,_ codersdk.Role) (codersdk.Role,bool) {
28+
func (agplCustomRoleHandler)PatchOrganizationRole(ctx context.Context,rw http.ResponseWriter,_*http.Request,_ uuid.UUID,_ codersdk.PatchRoleRequest) (codersdk.Role,bool) {
2929
httpapi.Write(ctx,rw,http.StatusForbidden, codersdk.Response{
3030
Message:"Creating and updating custom roles is an Enterprise feature. Contact sales!",
3131
})
@@ -49,7 +49,7 @@ func (api *API) patchOrgRoles(rw http.ResponseWriter, r *http.Request) {
4949
organization=httpmw.OrganizationParam(r)
5050
)
5151

52-
varreq codersdk.Role
52+
varreq codersdk.PatchRoleRequest
5353
if!httpapi.Read(ctx,rw,r,&req) {
5454
return
5555
}

‎codersdk/roles.go‎

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,16 @@ type Role struct {
6161
UserPermissions []Permission`json:"user_permissions" table:"user_permissions"`
6262
}
6363

64+
// Role is a longer form of SlimRole used to edit custom roles.
65+
typePatchRoleRequeststruct {
66+
Namestring`json:"name" table:"name,default_sort" validate:"username"`
67+
DisplayNamestring`json:"display_name" table:"display_name"`
68+
SitePermissions []Permission`json:"site_permissions" table:"site_permissions"`
69+
// OrganizationPermissions are specific to the organization the role belongs to.
70+
OrganizationPermissions []Permission`json:"organization_permissions" table:"organization_permissions"`
71+
UserPermissions []Permission`json:"user_permissions" table:"user_permissions"`
72+
}
73+
6474
// FullName returns the role name scoped to the organization ID. This is useful if
6575
// printing a set of roles from different scopes, as duplicated names across multiple
6676
// scopes will become unique.
@@ -73,18 +83,26 @@ func (r Role) FullName() string {
7383
}
7484

7585
// PatchOrganizationRole will upsert a custom organization role
76-
func (c*Client)PatchOrganizationRole(ctx context.Context,organizationID uuid.UUID,reqRole) (Role,error) {
86+
func (c*Client)PatchOrganizationRole(ctx context.Context,roleRole) (Role,error) {
87+
req:=PatchRoleRequest{
88+
Name:role.Name,
89+
DisplayName:role.DisplayName,
90+
SitePermissions:role.SitePermissions,
91+
OrganizationPermissions:role.OrganizationPermissions,
92+
UserPermissions:role.UserPermissions,
93+
}
94+
7795
res,err:=c.Request(ctx,http.MethodPatch,
78-
fmt.Sprintf("/api/v2/organizations/%s/members/roles",organizationID.String()),req)
96+
fmt.Sprintf("/api/v2/organizations/%s/members/roles",role.OrganizationID),req)
7997
iferr!=nil {
8098
returnRole{},err
8199
}
82100
deferres.Body.Close()
83101
ifres.StatusCode!=http.StatusOK {
84102
returnRole{},ReadBodyAsError(res)
85103
}
86-
varroleRole
87-
returnrole,json.NewDecoder(res.Body).Decode(&role)
104+
varrRole
105+
returnr,json.NewDecoder(res.Body).Decode(&r)
88106
}
89107

90108
// ListSiteRoles lists all assignable site wide roles.

‎enterprise/coderd/roles.go‎

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ type enterpriseCustomRoleHandler struct {
2121
Enabledbool
2222
}
2323

24-
func (henterpriseCustomRoleHandler)PatchOrganizationRole(ctx context.Context,rw http.ResponseWriter,r*http.Request,orgID uuid.UUID,role codersdk.Role) (codersdk.Role,bool) {
24+
func (henterpriseCustomRoleHandler)PatchOrganizationRole(ctx context.Context,rw http.ResponseWriter,r*http.Request,orgID uuid.UUID,role codersdk.PatchRoleRequest) (codersdk.Role,bool) {
2525
if!h.Enabled {
2626
httpapi.Write(ctx,rw,http.StatusForbidden, codersdk.Response{
2727
Message:"Custom roles are not enabled",
@@ -77,14 +77,6 @@ func (h enterpriseCustomRoleHandler) PatchOrganizationRole(ctx context.Context,
7777
return codersdk.Role{},false
7878
}
7979

80-
ifrole.OrganizationID!=orgID.String() {
81-
httpapi.Write(ctx,rw,http.StatusBadRequest, codersdk.Response{
82-
Message:"Invalid request, organization in role and url must match",
83-
Detail:fmt.Sprintf("role organization=%q does not match URL=%q",role.OrganizationID,orgID.String()),
84-
})
85-
return codersdk.Role{},false
86-
}
87-
8880
originalRoles,err:=db.CustomRoles(ctx, database.CustomRolesParams{
8981
LookupRoles: []database.NameOrganizationPair{
9082
{

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp