Skip to content

Commit

Permalink
Allow creating and updating (user|org) names with dots
Browse files Browse the repository at this point in the history
In #4690, we made it possible to create usernames from SSO signups that include dots.

But it was still not possible to change or manually create an account with a username that
includes a dot in the UI. This PR fixes that.

For consistency, we allow dots in org names too.

Fixes #4909, #4920
  • Loading branch information
tsenart committed Jul 17, 2019
1 parent a5e8889 commit b348857
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 6 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ All notable changes to Sourcegraph are documented in this file.

### Changed

- Usernames can now contain the `.` character (#4690).
- Usernames and org names can now contain the `.` character (#4690).

### Added

Expand Down
13 changes: 13 additions & 0 deletions migrations/1528395581_allows_dots_in_usernames.down.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
BEGIN;

ALTER TABLE orgs
DROP CONSTRAINT orgs_name_valid_chars,
ADD CONSTRAINT orgs_name_valid_chars
CHECK (name ~ '^[a-zA-Z0-9](?:[a-zA-Z0-9]|-(?=[a-zA-Z0-9]))*$');

ALTER TABLE users
DROP CONSTRAINT users_username_valid_chars,
ADD CONSTRAINT users_username_valid_chars
CHECK (username ~ '^[a-zA-Z0-9](?:[a-zA-Z0-9]|-(?=[a-zA-Z0-9]))*$');

COMMIT;
13 changes: 13 additions & 0 deletions migrations/1528395581_allows_dots_in_usernames.up.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
BEGIN;

ALTER TABLE orgs
DROP CONSTRAINT orgs_name_valid_chars,
ADD CONSTRAINT orgs_name_valid_chars
CHECK (name ~ '^[a-zA-Z0-9](?:[a-zA-Z0-9]|[-.](?=[a-zA-Z0-9]))*$');

ALTER TABLE users
DROP CONSTRAINT users_username_valid_chars,
ADD CONSTRAINT users_username_valid_chars
CHECK (username ~ '^[a-zA-Z0-9](?:[a-zA-Z0-9]|[-.](?=[a-zA-Z0-9]))*$');

COMMIT;
4 changes: 2 additions & 2 deletions web/src/org/new/NewOrganizationPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,8 @@ export class NewOrganizationPage extends React.Component<Props, State> {
aria-describedby="new-org-page__form-name-help"
/>
<small id="new-org-page__form-name-help" className="form-text text-muted">
An organization name consists of letters, numbers, hyphens (-) and may not begin or end with
a hyphen
An organization name consists of letters, numbers, hyphens (-), dots (.) and may not begin
or end with a hyphen nor a dot.
</small>
</div>

Expand Down
7 changes: 7 additions & 0 deletions web/src/site-admin/SiteAdminCreateUserPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,13 @@ export class SiteAdminCreateUserPage extends React.Component<Props, State> {
disabled={this.state.loading}
autoFocus={true}
/>
<small
id="site-admin-create-user-page__form-username-help"
className="form-text text-muted"
>
A username consists of letters, numbers, hyphens (-), dots (.) and may not begin or end
with a hyphen nor a dot.
</small>
</div>
<div className="form-group site-admin-create-user-page__form-group">
<label htmlFor="site-admin-create-user-page__form-email">Email</label>
Expand Down
2 changes: 1 addition & 1 deletion web/src/user/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* Regular expression to identify valid username.
*/
export const VALID_USERNAME_REGEXP = /^[a-zA-Z0-9](?:[a-zA-Z0-9]|-(?=[a-zA-Z0-9]))*$/.source
export const VALID_USERNAME_REGEXP = /^[a-zA-Z0-9](?:[a-zA-Z0-9]|[-.](?=[a-zA-Z0-9]))*$/.source

/** Maximum allowed length for a username. */
export const USERNAME_MAX_LENGTH = 255
Expand Down
4 changes: 2 additions & 2 deletions web/src/user/settings/profile/UserSettingsProfilePage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -201,8 +201,8 @@ export class UserSettingsProfilePage extends React.Component<Props, State> {
aria-describedby="user-settings-profile-page__form-username-help"
/>
<small id="user-settings-profile-page__form-username-help" className="form-text text-muted">
A username consists of letters, numbers, hyphens (-) and may not begin or end with a
hyphen
A username consists of letters, numbers, hyphens (-), dots (.) and may not begin or end
with a hyphen nor a dot.
</small>
</div>
<div className="form-group">
Expand Down

0 comments on commit b348857

Please sign in to comment.