Skip to content

feat: use default org for PostUser #12143

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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 16, 2024
Merged

feat: use default org for PostUser #12143

merged 1 commit into from
Feb 16, 2024

Conversation

Emyrk
Copy link
Member

@Emyrk Emyrk commented Feb 14, 2024

Closes #11925

What this does

Instead of assuming only 1 org exists, this uses the is_default org to place a user in if not specified.

Copy link
Member Author

Emyrk commented Feb 14, 2024

@Emyrk Emyrk force-pushed the stevenmasley/post_user branch from 01ec5d8 to bdd0956 Compare February 14, 2024 17:01
Comment on lines -404 to +423
// If no organization is provided, add the user to the first
// organization.
organizations, err := api.Database.GetOrganizations(ctx)
// If no organization is provided, add the user to the default
defaultOrg, err := api.Database.GetDefaultOrganization(ctx)
if err != nil {
if httpapi.Is404Error(err) {
httpapi.Write(ctx, rw, http.StatusNotFound,
codersdk.Response{
Message: "Resource not found or you do not have access to this resource",
Detail: "Organization not found",
},
)
return
}
httpapi.Write(ctx, rw, http.StatusInternalServerError, codersdk.Response{
Message: "Internal error fetching orgs.",
Detail: err.Error(),
})
return
}

if len(organizations) > 0 {
// Add the user to the first organization. Once multi-organization
// support is added, we should enable a configuration map of user
// email to organization.
req.OrganizationID = organizations[0].ID
}
req.OrganizationID = defaultOrg.ID
Copy link
Member Author

Choose a reason for hiding this comment

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

This is the change

@Emyrk Emyrk marked this pull request as ready for review February 14, 2024 17:45
@Emyrk Emyrk force-pushed the stevenmasley/post_user branch from 60775a6 to 04c6149 Compare February 14, 2024 18:08
@Emyrk Emyrk requested a review from mafredri February 15, 2024 15:30
@Emyrk Emyrk force-pushed the stevenmasley/default_org branch from 0f27fcc to 5bb0ffc Compare February 15, 2024 16:28
@Emyrk Emyrk force-pushed the stevenmasley/post_user branch from 04c6149 to 7059828 Compare February 15, 2024 16:28
Base automatically changed from stevenmasley/default_org to main February 15, 2024 17:01
@Emyrk Emyrk force-pushed the stevenmasley/post_user branch from 7059828 to a25537e Compare February 15, 2024 17:12
@Emyrk Emyrk changed the base branch from main to stevenmasley/default_org February 15, 2024 17:13
@Emyrk Emyrk changed the base branch from stevenmasley/default_org to main February 15, 2024 17:13
Instead of assuming only 1 org exists, this uses the
is_default org to place a user in if not specified.
@Emyrk Emyrk force-pushed the stevenmasley/post_user branch from aeb29f2 to 8f61a71 Compare February 15, 2024 17:18
@@ -1016,6 +1016,12 @@ func (q *querier) GetDERPMeshKey(ctx context.Context) (string, error) {
return q.db.GetDERPMeshKey(ctx)
}

func (q *querier) GetDefaultOrganization(ctx context.Context) (database.Organization, error) {
return fetch(q.log, q.auth, func(ctx context.Context, _ any) (database.Organization, error) {
Copy link
Member

Choose a reason for hiding this comment

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

No need for auth here?

Copy link
Member Author

Choose a reason for hiding this comment

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

That does do auth! fetch is the helper function that automatically checks the RBAC on the returned object. So if the caller cannot read the default org, this will fail.

@Emyrk Emyrk merged commit 2a8004b into main Feb 16, 2024
@Emyrk Emyrk deleted the stevenmasley/post_user branch February 16, 2024 14:28
@github-actions github-actions bot locked and limited conversation to collaborators Feb 16, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

PostUser requires organization
2 participants