-
Notifications
You must be signed in to change notification settings - Fork 927
feat: add api for patching custom org roles #13357
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
3ca152a
d231cdf
5c80ea0
b55d1c5
fb1dddc
5eaf868
3f56f51
715efa2
816f97c
6e88678
282f261
d633afc
5ac97f8
c6335cf
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,8 @@ | ||
package coderd | ||
|
||
import ( | ||
"context" | ||
"net/http" | ||
|
||
"github.com/google/uuid" | ||
|
||
"golang.org/x/xerrors" | ||
|
||
"github.com/coder/coder/v2/coderd/database/db2sdk" | ||
"github.com/coder/coder/v2/coderd/rbac" | ||
|
||
|
@@ -48,7 +43,7 @@ func (api *API) putMemberRoles(rw http.ResponseWriter, r *http.Request) { | |
return | ||
} | ||
|
||
updatedUser, err := api.updateOrganizationMemberRoles(ctx, database.UpdateMemberRolesParams{ | ||
updatedUser, err := api.Database.UpdateMemberRoles(ctx, database.UpdateMemberRolesParams{ | ||
GrantedRoles: params.Roles, | ||
UserID: member.UserID, | ||
OrgID: organization.ID, | ||
|
@@ -63,36 +58,6 @@ func (api *API) putMemberRoles(rw http.ResponseWriter, r *http.Request) { | |
httpapi.Write(ctx, rw, http.StatusOK, convertOrganizationMember(updatedUser)) | ||
} | ||
|
||
func (api *API) updateOrganizationMemberRoles(ctx context.Context, args database.UpdateMemberRolesParams) (database.OrganizationMember, error) { | ||
// Enforce only site wide roles | ||
for _, r := range args.GrantedRoles { | ||
// Must be an org role for the org in the args | ||
orgID, ok := rbac.IsOrgRole(r) | ||
if !ok { | ||
return database.OrganizationMember{}, xerrors.Errorf("must only update organization roles") | ||
} | ||
|
||
roleOrg, err := uuid.Parse(orgID) | ||
if err != nil { | ||
return database.OrganizationMember{}, xerrors.Errorf("Role must have proper UUIDs for organization, %q does not", r) | ||
} | ||
|
||
if roleOrg != args.OrgID { | ||
return database.OrganizationMember{}, xerrors.Errorf("Must only pass roles for org %q", args.OrgID.String()) | ||
} | ||
|
||
if _, err := rbac.RoleByName(r); err != nil { | ||
return database.OrganizationMember{}, xerrors.Errorf("%q is not a supported organization role", r) | ||
} | ||
} | ||
|
||
updatedUser, err := api.Database.UpdateMemberRoles(ctx, args) | ||
if err != nil { | ||
return database.OrganizationMember{}, xerrors.Errorf("Update site roles: %w", err) | ||
} | ||
return updatedUser, nil | ||
} | ||
Comment on lines
-66
to
-94
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is all moved to dbauthz. The same is done for site wide roles in dbauthz already. |
||
|
||
func convertOrganizationMember(mem database.OrganizationMember) codersdk.OrganizationMember { | ||
convertedMember := codersdk.OrganizationMember{ | ||
UserID: mem.UserID, | ||
|
Uh oh!
There was an error while loading. Please reload this page.