Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

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

Merged
Emyrk merged 6 commits intomainfromstevenmasley/set_groups
Feb 16, 2024
Merged

Conversation

Emyrk
Copy link
Member

@EmyrkEmyrk commentedFeb 14, 2024
edited
Loading

Closes#11938

Comment on lines 1475 to 1504
//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)
Copy link
MemberAuthor

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.

mafredri reacted with thumbs up emoji
Comment on lines +44 to +47
// 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.
Copy link
MemberAuthor

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.

mafredri reacted with thumbs up emoji
@EmyrkEmyrk changed the titlefeat: groupsync set groups defaults to default orgfeat: set groupsync to use default orgFeb 14, 2024
@EmyrkEmyrk marked this pull request as ready for reviewFebruary 14, 2024 19:34
@EmyrkEmyrkforce-pushed thestevenmasley/oauth_user branch from5322f4e toddb828cCompareFebruary 15, 2024 16:28
@EmyrkEmyrkforce-pushed thestevenmasley/set_groups branch from9e0314c to723f42dCompareFebruary 15, 2024 16:28
@EmyrkEmyrkforce-pushed thestevenmasley/oauth_user branch fromddb828c tofc2fce2CompareFebruary 15, 2024 17:58
@EmyrkEmyrkforce-pushed thestevenmasley/set_groups branch from723f42d to6b10251CompareFebruary 15, 2024 17:59
This 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.
@EmyrkEmyrkforce-pushed thestevenmasley/oauth_user branch fromfc2fce2 to872f4a2CompareFebruary 15, 2024 18:46
@EmyrkEmyrkforce-pushed thestevenmasley/set_groups branch 2 times, most recently from5bbfa1a toced4905CompareFebruary 15, 2024 18:49
@EmyrkEmyrkforce-pushed thestevenmasley/set_groups branch fromced4905 toda6c21cCompareFebruary 15, 2024 19:34
Copy link
Member

@mafredrimafredri left a 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!

inDefault = true
break
}
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Emyrk reacted with thumbs up emoji
@@ -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

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

[Re: line 1347]

Linter is not happy, rebase issue?

See this comment inline onGraphite.

Base automatically changed fromstevenmasley/oauth_user tomainFebruary 16, 2024 14:47
@EmyrkEmyrk merged commitf17149c intomainFeb 16, 2024
@EmyrkEmyrk deleted the stevenmasley/set_groups branchFebruary 16, 2024 17:09
@github-actionsgithub-actionsbot locked and limited conversation to collaboratorsFeb 16, 2024
Sign up for freeto subscribe to this conversation on GitHub. Already have an account?Sign in.
Reviewers

@mafredrimafredrimafredri approved these changes

Assignees

@EmyrkEmyrk

Labels
None yet
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

setUserGroups requires 1 org
2 participants
@Emyrk@mafredri

[8]ページ先頭

©2009-2025 Movatter.jp