@@ -12,7 +12,7 @@ class User < ApplicationRecord
1212 has_many :creators , -> { where ( "caber_relations.permission" : "own" ) } , through : :caber_relations , source_type : "Creator" , source : :object
1313 accepts_nested_attributes_for :creators
1414
15- before_validation :set_json_field_defaults , on : :create
15+ before_validation :set_json_field_defaults
1616 before_save :set_quota
1717
1818 acts_as_federails_actor (
@@ -29,22 +29,22 @@ class User < ApplicationRecord
2929
3030 devise :omniauthable , omniauth_providers : %i[ openid_connect ] if SiteSettings . oidc_enabled?
3131
32- validates :username , multimodel_uniqueness : { punctuation_sensitive : false , case_sensitive : false , check : FederailsCommon :: FEDIVERSE_USERNAMES }
33-
34- validates :username ,
35- presence : true ,
36- uniqueness : { case_sensitive : false } ,
37- format : { with : /\A [[:alnum:].\- _;]+\z / }
38-
39- validates :email ,
40- presence : true ,
41- uniqueness : { case_sensitive : false } ,
42- format : { with : URI ::MailTo ::EMAIL_REGEXP }
43-
44- validates :password ,
45- presence : true ,
46- confirmation : true ,
47- if : :password_required?
32+ # Reduce validations if only safe settings are being changed
33+ with_options unless : :only_settings_changed? do
34+ validates :username ,
35+ presence : true ,
36+ uniqueness : { case_sensitive : false } ,
37+ format : { with : /\A [[:alnum:].\- _;]+\z / } ,
38+ multimodel_uniqueness : { punctuation_sensitive : false , case_sensitive : false , check : FederailsCommon :: FEDIVERSE_USERNAMES }
39+ validates :email ,
40+ presence : true ,
41+ uniqueness : { case_sensitive : false } ,
42+ format : { with : URI ::MailTo ::EMAIL_REGEXP }
43+ validates :password ,
44+ presence : true ,
45+ confirmation : true ,
46+ if : :password_required?
47+ end
4848
4949 after_create :assign_default_role
5050
@@ -234,4 +234,12 @@ def set_json_field_defaults
234234 self . file_list_settings ||= SiteSettings ::UserDefaults ::FILE_LIST
235235 self . tour_state ||= DEFAULT_TOUR_STATE
236236 end
237+
238+ def only_settings_changed?
239+ return false unless changed?
240+ settings_attributes = [
241+ "tour_state"
242+ ] . freeze
243+ ( changed - settings_attributes ) . empty?
244+ end
237245end
0 commit comments