fix: use default org over index [0] for new scim (#12284)

This commit is contained in:
Steven Masley
2024-02-23 15:31:36 -06:00
committed by GitHub
parent 0dd126e025
commit c33c452663

View File

@ -200,27 +200,22 @@ func (api *API) scimPostUser(rw http.ResponseWriter, r *http.Request) {
sUser.UserName = httpapi.UsernameFrom(sUser.UserName) sUser.UserName = httpapi.UsernameFrom(sUser.UserName)
} }
var organizationID uuid.UUID // TODO: This is a temporary solution that does not support multi-org
// deployments. This assumption places all new SCIM users into the
// default organization.
//nolint:gocritic //nolint:gocritic
organizations, err := api.Database.GetOrganizations(dbauthz.AsSystemRestricted(ctx)) defaultOrganization, err := api.Database.GetDefaultOrganization(dbauthz.AsSystemRestricted(ctx))
if err != nil { if err != nil {
_ = handlerutil.WriteError(rw, err) _ = handlerutil.WriteError(rw, err)
return 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.
organizationID = organizations[0].ID
}
//nolint:gocritic // needed for SCIM //nolint:gocritic // needed for SCIM
dbUser, _, err = api.AGPL.CreateUser(dbauthz.AsSystemRestricted(ctx), api.Database, agpl.CreateUserRequest{ dbUser, _, err = api.AGPL.CreateUser(dbauthz.AsSystemRestricted(ctx), api.Database, agpl.CreateUserRequest{
CreateUserRequest: codersdk.CreateUserRequest{ CreateUserRequest: codersdk.CreateUserRequest{
Username: sUser.UserName, Username: sUser.UserName,
Email: email, Email: email,
OrganizationID: organizationID, OrganizationID: defaultOrganization.ID,
}, },
LoginType: database.LoginTypeOIDC, LoginType: database.LoginTypeOIDC,
}) })