X-Git-Url: https://git.openstreetmap.org./rails.git/blobdiff_plain/9387df91414616b9668185b72a9457e53937523d..81857a744613f3a9f3aa4fb1848e9a9768e174c7:/app/models/user.rb diff --git a/app/models/user.rb b/app/models/user.rb index b04f8e2b9..7faf748cd 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -37,7 +37,6 @@ # users_auth_idx (auth_provider,auth_uid) UNIQUE # users_display_name_canonical_idx (lower(NORMALIZE(display_name, NFKC))) # users_display_name_idx (display_name) UNIQUE -# users_display_name_lower_idx (lower((display_name)::text)) # users_email_idx (email) UNIQUE # users_email_lower_idx (lower((email)::text)) # users_home_idx (home_tile) @@ -100,6 +99,7 @@ class User < ApplicationRecord validates :display_name, :if => proc { |u| u.display_name_changed? }, :characters => { :url_safe => true }, :whitespace => { :leading => false, :trailing => false } + validate :display_name_cannot_be_user_id_with_other_id, :if => proc { |u| u.display_name_changed? } validates :email, :presence => true, :confirmation => true, :characters => true validates :email, :if => proc { |u| u.email_changed? }, :uniqueness => { :case_sensitive => false } @@ -124,6 +124,12 @@ class User < ApplicationRecord before_save :update_tile after_save :spam_check + def display_name_cannot_be_user_id_with_other_id + display_name&.match(/^user_(\d+)$/i) do |m| + errors.add :display_name, I18n.t("activerecord.errors.messages.display_name_is_user_n") unless m[1].to_i == id + end + end + def to_param display_name end