- Notifications
You must be signed in to change notification settings - Fork925
feat: implement sign up with GitHub for the first user#16629
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
Uh oh!
There was an error while loading.Please reload this page.
Merged
Changes fromall commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
33 changes: 32 additions & 1 deletioncoderd/userauth.go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
64 changes: 55 additions & 9 deletionscoderd/userauth_test.go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
39 changes: 18 additions & 21 deletionscoderd/users.go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -118,6 +118,8 @@ func (api *API) firstUser(rw http.ResponseWriter, r *http.Request) { | ||
// @Success 201 {object} codersdk.CreateFirstUserResponse | ||
// @Router /users/first [post] | ||
func (api *API) postFirstUser(rw http.ResponseWriter, r *http.Request) { | ||
// The first user can also be created via oidc, so if making changes to the flow, | ||
// ensure that the oidc flow is also updated. | ||
ctx := r.Context() | ||
var createUser codersdk.CreateFirstUserRequest | ||
if !httpapi.Read(ctx, rw, r, &createUser) { | ||
@@ -198,6 +200,7 @@ func (api *API) postFirstUser(rw http.ResponseWriter, r *http.Request) { | ||
OrganizationIDs: []uuid.UUID{defaultOrg.ID}, | ||
}, | ||
LoginType: database.LoginTypePassword, | ||
RBACRoles: []string{rbac.RoleOwner().String()}, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. ❤️ | ||
accountCreatorName: "coder", | ||
}) | ||
if err != nil { | ||
@@ -225,23 +228,6 @@ func (api *API) postFirstUser(rw http.ResponseWriter, r *http.Request) { | ||
Users: []telemetry.User{telemetryUser}, | ||
}) | ||
httpapi.Write(ctx, rw, http.StatusCreated, codersdk.CreateFirstUserResponse{ | ||
UserID: user.ID, | ||
OrganizationID: defaultOrg.ID, | ||
@@ -1351,6 +1337,7 @@ type CreateUserRequest struct { | ||
LoginType database.LoginType | ||
SkipNotifications bool | ||
accountCreatorName string | ||
RBACRoles []string | ||
} | ||
func (api *API) CreateUser(ctx context.Context, store database.Store, req CreateUserRequest) (database.User, error) { | ||
@@ -1360,6 +1347,13 @@ func (api *API) CreateUser(ctx context.Context, store database.Store, req Create | ||
return database.User{}, xerrors.Errorf("invalid username %q: %w", req.Username, usernameValid) | ||
} | ||
// If the caller didn't specify rbac roles, default to | ||
// a member of the site. | ||
rbacRoles := []string{} | ||
if req.RBACRoles != nil { | ||
rbacRoles = req.RBACRoles | ||
} | ||
var user database.User | ||
err := store.InTx(func(tx database.Store) error { | ||
orgRoles := make([]string, 0) | ||
@@ -1376,10 +1370,9 @@ func (api *API) CreateUser(ctx context.Context, store database.Store, req Create | ||
CreatedAt: dbtime.Now(), | ||
UpdatedAt: dbtime.Now(), | ||
HashedPassword: []byte{}, | ||
RBACRoles: rbacRoles, | ||
LoginType: req.LoginType, | ||
Status: status, | ||
} | ||
// If a user signs up with OAuth, they can have no password! | ||
if req.Password != "" { | ||
@@ -1437,6 +1430,10 @@ func (api *API) CreateUser(ctx context.Context, store database.Store, req Create | ||
} | ||
for _, u := range userAdmins { | ||
if u.ID == user.ID { | ||
// If the new user is an admin, don't notify them about themselves. | ||
continue | ||
} | ||
if _, err := api.NotificationsEnqueuer.EnqueueWithData( | ||
// nolint:gocritic // Need notifier actor to enqueue notifications | ||
dbauthz.AsNotifier(ctx), | ||
1 change: 0 additions & 1 deletionsite/e2e/setup/addUsersAndLicense.spec.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
3 changes: 0 additions & 3 deletionssite/src/pages/SetupPage/SetupPage.test.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
6 changes: 4 additions & 2 deletionssite/src/pages/SetupPage/SetupPage.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Oops, something went wrong.
Uh oh!
There was an error while loading.Please reload this page.
Oops, something went wrong.
Uh oh!
There was an error while loading.Please reload this page.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.