Commit ca559099 authored by James Lopez's avatar James Lopez

refactor services

parent ab603346
module Emails
class BaseService
def initialize(user, opts)
def initialize(current_user, user, opts)
@current_user = current_user
@user = user
@email = opts[:email]
end
......
......@@ -3,7 +3,8 @@ module Users
include NewUserNotifier
prepend EE::Users::UpdateService
def initialize(user, params = {})
def initialize(current_user, user, params = {})
@current_user = current_user
@user = user
@params = params.dup
end
......@@ -16,9 +17,7 @@ module Users
user_exists = @user.persisted?
if @user.save(validate: validate)
notify_new_user(@user, nil) unless user_exists
success
notify_success
else
error(@user.errors.full_messages.uniq.join('. '))
end
......@@ -32,6 +31,14 @@ module Users
true
end
protected
def notify_success
notify_new_user(@user, nil) unless @user.persisted?
success
end
private
def assign_attributes(&block)
......
module EE
module Emails
module BaseService
def initialize(current_user, user, opts)
@current_user = current_user
super(user, opts)
end
private
def log_audit_event(options = {})
......
......@@ -3,25 +3,17 @@ module EE
module UpdateService
include EE::Audit::Changes
def initialize(current_user, user, params = {})
@current_user = current_user
super(user, params)
end
private
def execute(*args, &block)
result = super(*args, &block)
def notify_success
notify_new_user(@user, nil) unless @user.persisted?
if result[:status] == :success
audit_changes(:email, as: 'email address')
audit_changes(:encrypted_password, as: 'password', skip_changes: true)
end
result
success
end
private
def model
@user
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