diff --git a/app/models/user.rb b/app/models/user.rb index 50a88d2b..b3b5bee5 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -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 diff --git a/app/validators/read_only_validator.rb b/app/validators/read_only_validator.rb new file mode 100644 index 00000000..b9b1301b --- /dev/null +++ b/app/validators/read_only_validator.rb @@ -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