Commit ca559099 authored by James Lopez's avatar James Lopez

refactor services

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