- Notifications
You must be signed in to change notification settings - Fork927
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Changes fromall commits
3ca152a
d231cdf
5c80ea0
b55d1c5
fb1dddc
5eaf868
3f56f51
715efa2
816f97c
6e88678
282f261
d633afc
5ac97f8
c6335cf
File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more abouthow customized files appear on GitHub.
Uh oh!
There was an error while loading.Please reload this page.
Some generated files are not rendered by default. Learn more abouthow customized files appear on GitHub.
Uh oh!
There was an error while loading.Please reload this page.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -600,14 +600,29 @@ func (q *querier) canAssignRoles(ctx context.Context, orgID *uuid.UUID, added, r | ||
customRoles := make([]string, 0) | ||
// Validate that the roles being assigned are valid. | ||
for _, r := range grantedRoles { | ||
roleOrgIDStr, isOrgRole := rbac.IsOrgRole(r) | ||
if shouldBeOrgRoles && !isOrgRole { | ||
return xerrors.Errorf("Must only update org roles") | ||
} | ||
if !shouldBeOrgRoles && isOrgRole { | ||
return xerrors.Errorf("Must only update site wide roles") | ||
} | ||
if shouldBeOrgRoles { | ||
roleOrgID, err := uuid.Parse(roleOrgIDStr) | ||
if err != nil { | ||
return xerrors.Errorf("role %q has invalid uuid for org: %w", r, err) | ||
} | ||
if orgID == nil { | ||
return xerrors.Errorf("should never happen, orgID is nil, but trying to assign an organization role") | ||
} | ||
if roleOrgID != *orgID { | ||
johnstcn marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
return xerrors.Errorf("attempted to assign role from a different org, role %q to %q", r, orgID.String()) | ||
} | ||
} | ||
// All roles should be valid roles | ||
if _, err := rbac.RoleByName(r); err != nil { | ||
customRoles = append(customRoles, r) | ||
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,8 @@ | ||
package coderd | ||
import ( | ||
"net/http" | ||
"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.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)) | ||
} | ||
Comment on lines -66 to -94 MemberAuthor 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.
Uh oh!
There was an error while loading.Please reload this page.