Commit e348f63b authored by James Lopez's avatar James Lopez

refactor users update service into a EE module

parent 7367431d
module Users module Users
class UpdateService < BaseService class UpdateService < BaseService
include EE::Audit::Changes
include NewUserNotifier include NewUserNotifier
prepend EE::Users::UpdateService
def initialize(current_user, user, params = {}) def initialize(user, params = {})
@current_user = current_user
@user = user @user = user
@params = params.dup @params = params.dup
end end
...@@ -17,9 +16,6 @@ module Users ...@@ -17,9 +16,6 @@ module Users
user_exists = @user.persisted? user_exists = @user.persisted?
if @user.save(validate: validate) if @user.save(validate: validate)
audit_changes(:email, as: 'email address')
audit_changes(:encrypted_password, as: 'password', skip_changes: true)
notify_new_user(@user, nil) unless user_exists notify_new_user(@user, nil) unless user_exists
success success
...@@ -39,15 +35,7 @@ module Users ...@@ -39,15 +35,7 @@ module Users
private private
def assign_attributes(&block) def assign_attributes(&block)
if @user.user_synced_attributes_metadata
params.except!(*@user.user_synced_attributes_metadata.read_only_attributes)
end
@user.assign_attributes(params) if params.any? @user.assign_attributes(params) if params.any?
end end
def model
@user
end
end end
end end
module EE
module Users
module UpdateService
include EE::Audit::Changes
def initialize(current_user, user, params = {})
@current_user = current_user
super(user, params)
end
def execute(*args, &block)
result = super(*args, &block)
if result[:status] == :success
audit_changes(:email, as: 'email address')
audit_changes(:encrypted_password, as: 'password', skip_changes: true)
end
result
end
private
def model
@user
end
end
end
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment