mirror of
https://github.com/Retrospring/retrospring.git
synced 2025-02-24 15:53:02 +01:00
prevent screen name changes
This commit is contained in:
parent
1e5a2082dc
commit
5e7ae90858
2 changed files with 12 additions and 1 deletions
|
@ -72,7 +72,8 @@ class User < ApplicationRecord
|
|||
format: { with: SCREEN_NAME_REGEX, message: I18n.t("activerecord.validation.user.screen_name.format") },
|
||||
length: { minimum: 1, maximum: 16 },
|
||||
uniqueness: { case_sensitive: false },
|
||||
screen_name: true
|
||||
screen_name: true,
|
||||
read_only: true
|
||||
|
||||
mount_uploader :profile_picture, ProfilePictureUploader, mount_on: :profile_picture_file_name
|
||||
process_in_background :profile_picture
|
||||
|
|
10
app/validators/read_only_validator.rb
Normal file
10
app/validators/read_only_validator.rb
Normal file
|
@ -0,0 +1,10 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class ReadOnlyValidator < ActiveModel::EachValidator
|
||||
def validate_each(record, attribute, value)
|
||||
return unless Retrospring::Config.readonly?
|
||||
return if value == record.public_send(:"#{attribute}_was")
|
||||
|
||||
record.errors.add(attribute, message: I18n.t("errors.read_only_mode"))
|
||||
end
|
||||
end
|
Loading…
Reference in a new issue