mirror of
https://github.com/coder/coder.git
synced 2026-09-24 15:04:27 +08:00
fix: don't require organization_id in body when updating a custom role (#14102)
This commit is contained in:
+23
-5
@@ -50,7 +50,7 @@ type Permission struct {
|
||||
Action RBACAction `json:"action"`
|
||||
}
|
||||
|
||||
// Role is a longer form of SlimRole used to edit custom roles.
|
||||
// Role is a longer form of SlimRole that includes permissions details.
|
||||
type Role struct {
|
||||
Name string `json:"name" table:"name,default_sort" validate:"username"`
|
||||
OrganizationID string `json:"organization_id,omitempty" table:"organization_id" format:"uuid"`
|
||||
@@ -61,6 +61,16 @@ type Role struct {
|
||||
UserPermissions []Permission `json:"user_permissions" table:"user_permissions"`
|
||||
}
|
||||
|
||||
// PatchRoleRequest is used to edit custom roles.
|
||||
type PatchRoleRequest struct {
|
||||
Name string `json:"name" table:"name,default_sort" validate:"username"`
|
||||
DisplayName string `json:"display_name" table:"display_name"`
|
||||
SitePermissions []Permission `json:"site_permissions" table:"site_permissions"`
|
||||
// OrganizationPermissions are specific to the organization the role belongs to.
|
||||
OrganizationPermissions []Permission `json:"organization_permissions" table:"organization_permissions"`
|
||||
UserPermissions []Permission `json:"user_permissions" table:"user_permissions"`
|
||||
}
|
||||
|
||||
// FullName returns the role name scoped to the organization ID. This is useful if
|
||||
// printing a set of roles from different scopes, as duplicated names across multiple
|
||||
// scopes will become unique.
|
||||
@@ -73,9 +83,17 @@ func (r Role) FullName() string {
|
||||
}
|
||||
|
||||
// PatchOrganizationRole will upsert a custom organization role
|
||||
func (c *Client) PatchOrganizationRole(ctx context.Context, organizationID uuid.UUID, req Role) (Role, error) {
|
||||
func (c *Client) PatchOrganizationRole(ctx context.Context, role Role) (Role, error) {
|
||||
req := PatchRoleRequest{
|
||||
Name: role.Name,
|
||||
DisplayName: role.DisplayName,
|
||||
SitePermissions: role.SitePermissions,
|
||||
OrganizationPermissions: role.OrganizationPermissions,
|
||||
UserPermissions: role.UserPermissions,
|
||||
}
|
||||
|
||||
res, err := c.Request(ctx, http.MethodPatch,
|
||||
fmt.Sprintf("/api/v2/organizations/%s/members/roles", organizationID.String()), req)
|
||||
fmt.Sprintf("/api/v2/organizations/%s/members/roles", role.OrganizationID), req)
|
||||
if err != nil {
|
||||
return Role{}, err
|
||||
}
|
||||
@@ -83,8 +101,8 @@ func (c *Client) PatchOrganizationRole(ctx context.Context, organizationID uuid.
|
||||
if res.StatusCode != http.StatusOK {
|
||||
return Role{}, ReadBodyAsError(res)
|
||||
}
|
||||
var role Role
|
||||
return role, json.NewDecoder(res.Body).Decode(&role)
|
||||
var r Role
|
||||
return r, json.NewDecoder(res.Body).Decode(&r)
|
||||
}
|
||||
|
||||
// ListSiteRoles lists all assignable site wide roles.
|
||||
|
||||
Reference in New Issue
Block a user