- Notifications
You must be signed in to change notification settings - Fork1.1k
feat: add name field to setup screen + CLI#13491
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
Uh oh!
There was an error while loading.Please reload this page.
Changes fromall commits
22335c764af35831313bc2805571a62a8eeec1befde80f4c8c3849be7cf406dca2bafa3eadba7File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -58,6 +58,21 @@ func promptFirstUsername(inv *serpent.Invocation) (string, error) { | ||||||||||||||||||||||||||
| return username, nil | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
| func promptFirstName(inv *serpent.Invocation) (string, error) { | ||||||||||||||||||||||||||
| name, err := cliui.Prompt(inv, cliui.PromptOptions{ | ||||||||||||||||||||||||||
| Text: "(Optional) What " + pretty.Sprint(cliui.DefaultStyles.Field, "name") + " would you like?", | ||||||||||||||||||||||||||
| Default: "", | ||||||||||||||||||||||||||
| }) | ||||||||||||||||||||||||||
| if errors.Is(err, cliui.Canceled) { | ||||||||||||||||||||||||||
| return "", nil | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
| if err != nil { | ||||||||||||||||||||||||||
| return "", err | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
Comment on lines +66 to +71 Member 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. Suggested change
Minor nit: one error handling block has less chance of being disconnected in future. | ||||||||||||||||||||||||||
| return name, nil | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
| func promptFirstPassword(inv *serpent.Invocation) (string, error) { | ||||||||||||||||||||||||||
| retry: | ||||||||||||||||||||||||||
| password, err := cliui.Prompt(inv, cliui.PromptOptions{ | ||||||||||||||||||||||||||
| @@ -130,6 +145,7 @@ func (r *RootCmd) login() *serpent.Command { | ||||||||||||||||||||||||||
| var ( | ||||||||||||||||||||||||||
| email string | ||||||||||||||||||||||||||
| username string | ||||||||||||||||||||||||||
| name string | ||||||||||||||||||||||||||
| password string | ||||||||||||||||||||||||||
| trial bool | ||||||||||||||||||||||||||
| useTokenForSession bool | ||||||||||||||||||||||||||
| @@ -191,6 +207,7 @@ func (r *RootCmd) login() *serpent.Command { | ||||||||||||||||||||||||||
| _, _ = fmt.Fprintf(inv.Stdout, "Attempting to authenticate with %s URL: '%s'\n", urlSource, serverURL) | ||||||||||||||||||||||||||
| // nolint: nestif | ||||||||||||||||||||||||||
| if !hasFirstUser { | ||||||||||||||||||||||||||
| _, _ = fmt.Fprintf(inv.Stdout, Caret+"Your Coder deployment hasn't been set up!\n") | ||||||||||||||||||||||||||
| @@ -212,6 +229,10 @@ func (r *RootCmd) login() *serpent.Command { | ||||||||||||||||||||||||||
| if err != nil { | ||||||||||||||||||||||||||
| return err | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
| name, err = promptFirstName(inv) | ||||||||||||||||||||||||||
| if err != nil { | ||||||||||||||||||||||||||
| return err | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
| if email == "" { | ||||||||||||||||||||||||||
| @@ -249,6 +270,7 @@ func (r *RootCmd) login() *serpent.Command { | ||||||||||||||||||||||||||
| _, err = client.CreateFirstUser(ctx, codersdk.CreateFirstUserRequest{ | ||||||||||||||||||||||||||
| Email: email, | ||||||||||||||||||||||||||
| Username: username, | ||||||||||||||||||||||||||
| FullName: name, | ||||||||||||||||||||||||||
| Password: password, | ||||||||||||||||||||||||||
| Trial: trial, | ||||||||||||||||||||||||||
| }) | ||||||||||||||||||||||||||
| @@ -353,6 +375,12 @@ func (r *RootCmd) login() *serpent.Command { | ||||||||||||||||||||||||||
| Description: "Specifies a username to use if creating the first user for the deployment.", | ||||||||||||||||||||||||||
| Value: serpent.StringOf(&username), | ||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||
| Flag: "first-user-full-name", | ||||||||||||||||||||||||||
| Env: "CODER_FIRST_USER_FULL_NAME", | ||||||||||||||||||||||||||
| Description: "Specifies a human-readable name for the first user of the deployment.", | ||||||||||||||||||||||||||
| Value: serpent.StringOf(&name), | ||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||
| Flag: "first-user-password", | ||||||||||||||||||||||||||
| Env: "CODER_FIRST_USER_PASSWORD", | ||||||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -10,6 +10,9 @@ OPTIONS: | ||
| Specifies an email address to use if creating the first user for the | ||
| deployment. | ||
| --first-user-full-name string, $CODER_FIRST_USER_FULL_NAME | ||
Contributor 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. Nit: I think we should use "name" instead of "full name" since it is uncommon. MemberAuthor 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. I originally used Contributor 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. I see.... 👍 | ||
| Specifies a human-readable name for the first user of the deployment. | ||
| --first-user-password string, $CODER_FIRST_USER_PASSWORD | ||
| Specifies a password to use if creating the first user for the | ||
| deployment. | ||
Some generated files are not rendered by default. Learn more abouthow customized files appear on GitHub.
Uh oh!
There was an error while loading.Please reload this page.
Some generated files are not rendered by default. Learn more abouthow customized files appear on GitHub.
Uh oh!
There was an error while loading.Please reload this page.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -12,6 +12,8 @@ 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" | ||
| @@ -200,6 +202,19 @@ func (api *API) postFirstUser(rw http.ResponseWriter, r *http.Request) { | ||
| return | ||
| } | ||
| //nolint:gocritic // Needed to create first user. | ||
| if _, err := api.Database.UpdateUserProfile(dbauthz.AsSystemRestricted(ctx), database.UpdateUserProfileParams{ | ||
Contributor 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. Why do we need to run a separate query to update the name? In my head, it would be done in the MemberAuthor 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. I'm not sure what you mean; there is no such query Contributor 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. Contributor 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. I can't see a good reason to create a user without the name and after, update it. IMO, it should be a single operation. | ||
| ID: user.ID, | ||
| UpdatedAt: dbtime.Now(), | ||
| Email: user.Email, | ||
| Username: user.Username, | ||
| AvatarURL: user.AvatarURL, | ||
| Name: createUser.FullName, | ||
| }); err != nil { | ||
| // This should not be a fatal error. Updating the user's profile can be done separately. | ||
| api.Logger.Error(ctx, "failed to update userprofile.Name", slog.Error(err)) | ||
| } | ||
| if api.RefreshEntitlements != nil { | ||
| err = api.RefreshEntitlements(ctx) | ||
| if err != nil { | ||
Uh oh!
There was an error while loading.Please reload this page.