prevent screen name changes

This commit is contained in:
Jyrki Gadinger 2025-02-21 17:18:03 +01:00 committed by Andreas Nedbal
parent 1e5a2082dc
commit 5e7ae90858
2 changed files with 12 additions and 1 deletions

View file

@ -72,7 +72,8 @@ class User < ApplicationRecord
format: { with: SCREEN_NAME_REGEX, message: I18n.t("activerecord.validation.user.screen_name.format") }, format: { with: SCREEN_NAME_REGEX, message: I18n.t("activerecord.validation.user.screen_name.format") },
length: { minimum: 1, maximum: 16 }, length: { minimum: 1, maximum: 16 },
uniqueness: { case_sensitive: false }, uniqueness: { case_sensitive: false },
screen_name: true screen_name: true,
read_only: true
mount_uploader :profile_picture, ProfilePictureUploader, mount_on: :profile_picture_file_name mount_uploader :profile_picture, ProfilePictureUploader, mount_on: :profile_picture_file_name
process_in_background :profile_picture process_in_background :profile_picture

View 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