Skip to content

chore: ensure default org always exists #12412

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 12 commits into from
Mar 5, 2024
Prev Previous commit
Next Next commit
log critical on a 'should never happen' parsing org roles
  • Loading branch information
Emyrk committed Mar 5, 2024
commit d35933d4f07c4a4f94d59fdb41747c43bf2b389e
13 changes: 9 additions & 4 deletions coderd/users.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"github.com/google/uuid"
"golang.org/x/xerrors"

"cdr.dev/slog"
"github.com/coder/coder/v2/coderd/audit"
"github.com/coder/coder/v2/coderd/database"
"github.com/coder/coder/v2/coderd/database/db2sdk"
Expand Down Expand Up @@ -196,10 +197,9 @@ func (api *API) postFirstUser(rw http.ResponseWriter, r *http.Request) {
//nolint:gocritic // needed to create first user
user, organizationID, err := api.CreateUser(dbauthz.AsSystemRestricted(ctx), api.Database, CreateUserRequest{
CreateUserRequest: codersdk.CreateUserRequest{
Email: createUser.Email,
Username: createUser.Username,
Password: createUser.Password,
// Create an org for the first user.
Email: createUser.Email,
Username: createUser.Username,
Password: createUser.Password,
OrganizationID: defaultOrg.ID,
},
CreateOrganization: false,
Copy link
Contributor

Choose a reason for hiding this comment

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

I think you can remove this field, which also allows cleaning up a lot of cruft in userauth.go

Copy link
Member Author

Choose a reason for hiding this comment

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

Oh you are right. I think we can drop the CreateOrganization behavior entirely. I'll make a new PR that will look into dropping it.

Expand Down Expand Up @@ -1083,6 +1083,11 @@ func (api *API) userRoles(rw http.ResponseWriter, r *http.Request) {

uid, err := uuid.Parse(orgID)
if err != nil {
api.Logger.Critical(r.Context(), "org role contains invalid uuid",
slog.F("username", user.Username),
slog.F("user_id", user.ID.String()),
slog.F("role", role),
)
continue // This should never happen
}
if _, ok := allowedOrgs[uid]; ok {
Expand Down