- Notifications
You must be signed in to change notification settings - Fork927
feat: set groupsync to use default org#12146
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.
Conversation
coderd/userauth.go Outdated
//nolint:gocritic // No user present in the context. | ||
defaultOrganization, err := tx.GetDefaultOrganization(dbauthz.AsSystemRestricted(ctx)) | ||
if err != nil { | ||
// If there is no default org, then we can't assign groups. | ||
// By default, we assume all groups belong to the default org. | ||
return xerrors.Errorf("get default organization: %w", err) | ||
} | ||
//nolint:gocritic // No user present in the context. | ||
memberships, err := tx.GetOrganizationMembershipsByUserID(dbauthz.AsSystemRestricted(ctx), user.ID) | ||
if err != nil { | ||
return xerrors.Errorf("get organization memberships: %w", err) | ||
} | ||
inDefault := false | ||
for _, membership := range memberships { | ||
if membership.OrganizationID == defaultOrganization.ID { | ||
inDefault = true | ||
break | ||
} | ||
} | ||
if !inDefault { | ||
return xerrors.Errorf("user %s is not a member of the default organization, cannot assign to groups in the org", user.ID) | ||
} | ||
//nolint:gocritic | ||
err := api.Options.SetUserGroups(dbauthz.AsSystemRestricted(ctx), logger, tx, user.ID, filtered, params.CreateMissingGroups) | ||
err = api.Options.SetUserGroups(dbauthz.AsSystemRestricted(ctx), logger, tx, user.ID, map[uuid.UUID][]string{ | ||
defaultOrganization.ID: filtered, | ||
}, params.CreateMissingGroups) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
I do not love how much code this ended up being. I can reduce it by adding another query, but this is all temporary. We need to solve group mapping to orgs, this code is static to only work with the default org.
This PR is required to remove the single org assumption.
// TODO: This could likely be improved by making these single queries. | ||
// Either by batching or some other means. This for loop could be really | ||
//inefficient if there are a lot of organizations. There was deployments | ||
//on v1 with >100 orgs. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
This is just phase 1 to getting the codebase to accept multi orgs. I do not want to prematurely optimize by coming up with some batching that might be removed.
I think we should move topgx
as our pg driver in sqlc to get batching support.
5322f4e
toddb828c
Compare9e0314c
to723f42d
Compareddb828c
tofc2fce2
Compare723f42d
to6b10251
CompareThis is not a final solution, as we eventually want to be ableto map to different orgs. This makes it so multi-org does not break oauth/oidc.
fc2fce2
to872f4a2
Compare5bbfa1a
toced4905
Compareced4905
toda6c21c
CompareThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
LGTM, thanks for adding comments along the way!
coderd/userauth.go Outdated
inDefault = true | ||
break | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
@@ -1301,7 +1303,6 @@ func (api *API) oauthLogin(r *http.Request, params *oauthLoginParams) ([]*http.C | |||
link database.UserLink | |||
err error | |||
) | |||
user = params.User | |||
link = params.Link | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Uh oh!
There was an error while loading.Please reload this page.
Closes#11938