This repository was archived by the owner on Sep 30, 2024. It is now read-only.
rbac: create users and assign role in single transaction - #47700
Merged
BolajiOlajide merged 8 commits intoFeb 17, 2023
Conversation
Contributor
|
❌ Problem: the label |
Contributor
|
Codenotify: Notifying subscribers in CODENOTIFY files for diff 26d6843eee7a4c3a7dd9a1787051c5dfecf94757...852e4ebf207a5151e5574f6b8265850f39475709.
|
Contributor
|
Codenotify: Notifying subscribers in OWNERS files for diff 26d6843eee7a4c3a7dd9a1787051c5dfecf94757...852e4ebf207a5151e5574f6b8265850f39475709.
|
kopancek
approved these changes
Feb 16, 2023
kopancek
left a comment
Contributor
There was a problem hiding this comment.
Thanks, this looks much neater and I like that it removed more lines than it added :)
BolajiOlajide
added a commit
that referenced
this pull request
Feb 17, 2023
## Context We have several `Assign`-ment methods in the store for `user_roles` and `role_permissions`, however most of the call site for these methods don't use the `types.UserRole` or `types.RolePermission` returned. While working on #47700, I noticed that some tests were failing because: * The tests had a call to `db.Users().Create`, which creates a site admin user because the `GlobalState` hasn't been initialized. Then calling `db.Users().SetIsSiteAdmin` after that results in a `sql: no rows in result set` error being returned because the [`ON CONFLICT DO NOTHING` clause](https://sourcegraph.com/github.com/sourcegraph/sourcegraph/-/blob/internal/database/user_roles.go?L111) in the upsert statement doesn't return a result set if the user is already assigned a role. This PR adds an extra check so that we don't return an error when an upsert is done. I also updated the signature to only return an error since we never use the relationship result in the call site for Role / Permission assignment.
BolajiOlajide
force-pushed
the
bo/create-users-and-assign-role-in-single-transaction
branch
from
February 17, 2023 12:13
852e4eb to
7c0930d
Compare
BolajiOlajide
deleted the
bo/create-users-and-assign-role-in-single-transaction
branch
February 17, 2023 14:07
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This is a follow-up to this comment on #47406.
This ensures that we don't have
zombieusers (users without any role assigned to them) on a Sourcegraph instance.Test plan