- Notifications
You must be signed in to change notification settings - Fork927
chore: remove organization_id suffix from org_member roles in database#13473
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
f7d22ea
5bd1280
01a492e
3949498
bd4d483
356099b
cf93307
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 |
---|---|---|
@@ -2472,7 +2472,7 @@ func (q *querier) InsertOrganization(ctx context.Context, arg database.InsertOrg | ||
func (q *querier) InsertOrganizationMember(ctx context.Context, arg database.InsertOrganizationMemberParams) (database.OrganizationMember, error) { | ||
// All roles are added roles. Org member is always implied. | ||
addedRoles := append(arg.Roles, rbac.ScopedRoleOrgMember(arg.OrganizationID)) | ||
err := q.canAssignRoles(ctx, &arg.OrganizationID, addedRoles, []string{}) | ||
if err != nil { | ||
return database.OrganizationMember{}, err | ||
@@ -2847,8 +2847,22 @@ func (q *querier) UpdateMemberRoles(ctx context.Context, arg database.UpdateMemb | ||
return database.OrganizationMember{}, err | ||
} | ||
// The 'rbac' package expects role names to be scoped. | ||
// Convert the argument roles for validation. | ||
scopedGranted := make([]string, 0, len(arg.GrantedRoles)) | ||
for _, grantedRole := range arg.GrantedRoles { | ||
// This check is a developer safety check. Old code might try to invoke this code path with | ||
// organization id suffixes. Catch this and return a nice error so it can be fixed. | ||
_, foundOrg, _ := rbac.RoleSplit(grantedRole) | ||
if foundOrg != "" { | ||
return database.OrganizationMember{}, xerrors.Errorf("attempt to assign a role %q, remove the ':<organization_id> suffix", grantedRole) | ||
} | ||
Comment on lines +2854 to +2859 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 not required, but added as a safety check to catch dev errors from using the previous | ||
scopedGranted = append(scopedGranted, rbac.RoleName(grantedRole, arg.OrgID.String())) | ||
} | ||
// The org member role is always implied. | ||
impliedTypes := append(scopedGranted, rbac.ScopedRoleOrgMember(arg.OrgID)) | ||
added, removed := rbac.ChangeRoleSet(member.Roles, impliedTypes) | ||
err = q.canAssignRoles(ctx, &arg.OrgID, added, removed) | ||
if err != nil { | ||
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 |
---|---|---|
@@ -0,0 +1 @@ | ||
ALTER TABLE ONLY organization_members ALTER COLUMN roles SET DEFAULT '{organization-member}'; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
-- The default was 'organization-member', but we imply that in the | ||
-- 'GetAuthorizationUserRoles' query. | ||
ALTER TABLE ONLY organization_members ALTER COLUMN roles SET DEFAULT '{}'; | ||
-- No one should be using organization roles yet. If they are, the names in the | ||
-- database are now incorrect. Just remove them all. | ||
UPDATE organization_members SET roles = '{}'; | ||
Comment on lines +1 to +7 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. another good thing to call out |
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.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.