Commit e348f63b authored by James Lopez's avatar James Lopez

refactor users update service into a EE module

parent 7367431d
module Users
class UpdateService < BaseService
include EE::Audit::Changes
include NewUserNotifier
prepend EE::Users::UpdateService
def initialize(current_user, user, params = {})
@current_user = current_user
def initialize(user, params = {})
@user = user
@params = params.dup
end
......@@ -17,9 +16,6 @@ module Users
user_exists = @user.persisted?
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
success
......@@ -39,15 +35,7 @@ module Users
private
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?
end
def model
@user
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