diff --git a/Changelog.md b/Changelog.md index 1aac93634..9287182bd 100644 --- a/Changelog.md +++ b/Changelog.md @@ -10,6 +10,7 @@ ## Features * Add tags to tumblr posts [#8244](https://github.com/diaspora/diaspora/pull/8244) * Add blocks to the archive export [#8263](https://github.com/diaspora/diaspora/pull/8263) +* Allow points and dashes in the username [#8266](https://github.com/diaspora/diaspora/pull/8266) # 0.7.15.0 diff --git a/app/models/user.rb b/app/models/user.rb index bfc97325b..14eb4562c 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -36,10 +36,8 @@ class User < ApplicationRecord before_validation :set_current_language, :on => :create before_validation :set_default_color_theme, on: :create - validates :username, :presence => true, :uniqueness => true - validates_format_of :username, :with => /\A[A-Za-z0-9_]+\z/ - validates_length_of :username, :maximum => 32 - validates_exclusion_of :username, :in => AppConfig.settings.username_blacklist + validates :username, presence: true, uniqueness: true, format: {with: /\A[A-Za-z0-9_.\-]+\z/}, + length: {maximum: 32}, exclusion: {in: AppConfig.settings.username_blacklist} validates_inclusion_of :language, :in => AVAILABLE_LANGUAGE_CODES validates :color_theme, inclusion: {in: AVAILABLE_COLOR_THEMES}, allow_blank: true validates_format_of :unconfirmed_email, :with => Devise.email_regexp, :allow_blank => true diff --git a/app/views/registrations/_form.haml b/app/views/registrations/_form.haml index 9cd6ce0f7..b9f99cfa5 100644 --- a/app/views/registrations/_form.haml +++ b/app/views/registrations/_form.haml @@ -32,7 +32,7 @@ placeholder: t("registrations.new.username"), title: t("registrations.new.enter_username"), required: true, - pattern: "[A-Za-z0-9_]+", + pattern: "[A-Za-z0-9_.\-]+", aria: {labelledby: "usernameLabel"} - if mobile diff --git a/config/routes.rb b/config/routes.rb index 8a4f45ebe..bd624d1f4 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -186,7 +186,11 @@ Rails.application.routes.draw do post 'by_handle' => :retrieve_remote, :as => 'person_by_handle' end end - get '/u/:username' => 'people#show', :as => 'user_profile', :constraints => { :username => /[^\/]+/ } + + # Note: The contraint for this route's username parameter cannot be removed. + # This constraint turns off the format parameter, so that an username + # doctor.example would not try to render the user `doctor` in `example` format. + get "/u/:username" => "people#show", :as => "user_profile", :constraints => {username: %r{[^/]+}} # External diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index 560432927..f457c9b28 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -267,11 +267,6 @@ describe User, :type => :model do expect(alice).not_to be_valid end - it 'should not contain periods' do - alice.username = "kittens." - expect(alice).not_to be_valid - end - it "can be 32 characters long" do alice.username = "hexagoooooooooooooooooooooooooon" expect(alice).to be_valid