- Notifications
You must be signed in to change notification settings - Fork1.2k
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 from1 commit
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
- Loading branch information
Uh oh!
There was an error while loading.Please reload this page.
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 | ||||||||||||||||||||||||||
| @@ -212,6 +228,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 +269,7 @@ func (r *RootCmd) login() *serpent.Command { | ||||||||||||||||||||||||||
| _, err = client.CreateFirstUser(ctx, codersdk.CreateFirstUserRequest{ | ||||||||||||||||||||||||||
| Email: email, | ||||||||||||||||||||||||||
| Username: username, | ||||||||||||||||||||||||||
| Name: name, | ||||||||||||||||||||||||||
| Password: password, | ||||||||||||||||||||||||||
| Trial: trial, | ||||||||||||||||||||||||||
| }) | ||||||||||||||||||||||||||
| @@ -353,6 +374,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-name", | ||||||||||||||||||||||||||
| Env: "CODER_FIRST_USER_AME", | ||||||||||||||||||||||||||
| Description: "Specifies a human-readable name for the first user of the deployment.", | ||||||||||||||||||||||||||
| Value: serpent.StringOf(&username), | ||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||
| Flag: "first-user-password", | ||||||||||||||||||||||||||
| Env: "CODER_FIRST_USER_PASSWORD", | ||||||||||||||||||||||||||
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 // Neded 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.Name, | ||
| }); 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 { | ||
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.
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 |
|---|---|---|
| @@ -23,6 +23,8 @@ import { countries } from "./countries"; | ||
| export const Language = { | ||
| emailLabel: "Email", | ||
| passwordLabel: "Password", | ||
| nameLabel: "Name", | ||
| nameHelperText: 'Optional human-readable name', | ||
| usernameLabel: "Username", | ||
| emailInvalid: "Please enter a valid email address.", | ||
| emailRequired: "Please enter an email address.", | ||
| @@ -93,6 +95,7 @@ export const SetupPageView: FC<SetupPageViewProps> = ({ | ||
| email: "", | ||
| password: "", | ||
| username: "", | ||
| name: "", | ||
| trial: false, | ||
| trial_info: { | ||
| first_name: "", | ||
| @@ -164,7 +167,18 @@ export const SetupPageView: FC<SetupPageViewProps> = ({ | ||
| label={Language.passwordLabel} | ||
| type="password" | ||
| /> | ||
| <TextField | ||
| autoFocus | ||
| {...getFieldHelpers("name")} | ||
| onBlur={(e) => { | ||
| e.target.value = e.target.value.trim(); | ||
| form.handleChange(e); | ||
| }} | ||
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 this? 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 want to ensure that any leading/trailing whitespace is removed before submission. 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 feel this should be done in the BE before saving the data on DB - so it is consistent between clients. We don't do that in any other form in the UI so, IMO, we can remove this for now. 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 saw that it was done
| ||
| autoComplete="name" | ||
| fullWidth | ||
| label={Language.nameLabel} | ||
| helperText={Language.nameHelperText} | ||
| /> | ||
| <label | ||
| htmlFor="trial" | ||
| css={{ | ||