diff options
Diffstat (limited to 'app/services/users')
-rw-r--r-- | app/services/users/update_service.rb | 19 |
1 files changed, 18 insertions, 1 deletions
diff --git a/app/services/users/update_service.rb b/app/services/users/update_service.rb index 422c8ed6575..dfbb65b7fcf 100644 --- a/app/services/users/update_service.rb +++ b/app/services/users/update_service.rb @@ -17,6 +17,8 @@ module Users yield(@user) if block_given? user_exists = @user.persisted? + + discard_read_only_attributes assign_attributes assign_identity @@ -50,13 +52,28 @@ module Users success end - def assign_attributes + def discard_read_only_attributes + discard_synced_attributes + discard_name unless name_updatable? + end + + def discard_synced_attributes if (metadata = @user.user_synced_attributes_metadata) read_only = metadata.read_only_attributes params.reject! { |key, _| read_only.include?(key.to_sym) } end + end + def discard_name + params.delete(:name) + end + + def name_updatable? + can?(current_user, :update_name, @user) + end + + def assign_attributes @user.assign_attributes(params.except(*identity_attributes)) unless params.empty? end |