summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--app/controllers/admin/users_controller.rb2
-rw-r--r--app/controllers/profiles/emails_controller.rb4
-rw-r--r--app/models/user.rb4
-rw-r--r--app/services/emails/base_service.rb4
-rw-r--r--lib/api/users.rb8
-rw-r--r--spec/services/emails/create_service_spec.rb4
-rw-r--r--spec/services/emails/destroy_service_spec.rb2
7 files changed, 14 insertions, 14 deletions
diff --git a/app/controllers/admin/users_controller.rb b/app/controllers/admin/users_controller.rb
index b25040382d8..676a7203c7d 100644
--- a/app/controllers/admin/users_controller.rb
+++ b/app/controllers/admin/users_controller.rb
@@ -155,7 +155,7 @@ class Admin::UsersController < Admin::ApplicationController
def remove_email
email = user.emails.find(params[:email_id])
- success = Emails::DestroyService.new(current_user, user, email: email.email).execute
+ success = Emails::DestroyService.new(current_user, user: user, email: email.email).execute
respond_to do |format|
if success
diff --git a/app/controllers/profiles/emails_controller.rb b/app/controllers/profiles/emails_controller.rb
index 8328d230276..97db84b92d4 100644
--- a/app/controllers/profiles/emails_controller.rb
+++ b/app/controllers/profiles/emails_controller.rb
@@ -5,7 +5,7 @@ class Profiles::EmailsController < Profiles::ApplicationController
end
def create
- @email = Emails::CreateService.new(current_user, current_user, email_params).execute
+ @email = Emails::CreateService.new(current_user, email_params.merge(user: current_user)).execute
if @email.errors.blank?
NotificationService.new.new_email(@email)
@@ -19,7 +19,7 @@ class Profiles::EmailsController < Profiles::ApplicationController
def destroy
@email = current_user.emails.find(params[:id])
- Emails::DestroyService.new(current_user, current_user, email: @email.email).execute
+ Emails::DestroyService.new(current_user, user: current_user, email: @email.email).execute
respond_to do |format|
format.html { redirect_to profile_emails_url, status: 302 }
diff --git a/app/models/user.rb b/app/models/user.rb
index 94674528012..103ac78783f 100644
--- a/app/models/user.rb
+++ b/app/models/user.rb
@@ -526,8 +526,8 @@ class User < ActiveRecord::Base
def update_emails_with_primary_email
primary_email_record = emails.find_by(email: email)
if primary_email_record
- Emails::DestroyService.new(self, self, email: email).execute
- Emails::CreateService.new(self, self, email: email_was).execute
+ Emails::DestroyService.new(self, user: self, email: email).execute
+ Emails::CreateService.new(self, user: self, email: email_was).execute
end
end
diff --git a/app/services/emails/base_service.rb b/app/services/emails/base_service.rb
index 8810f6d8803..7f591c89411 100644
--- a/app/services/emails/base_service.rb
+++ b/app/services/emails/base_service.rb
@@ -1,8 +1,8 @@
module Emails
class BaseService
- def initialize(current_user, user, opts)
+ def initialize(current_user, opts)
@current_user = current_user
- @user = user
+ @user = opts.delete(:user)
@email = opts[:email]
end
end
diff --git a/lib/api/users.rb b/lib/api/users.rb
index ce5d75965d5..99024d1f0ad 100644
--- a/lib/api/users.rb
+++ b/lib/api/users.rb
@@ -326,7 +326,7 @@ module API
user = User.find_by(id: params.delete(:id))
not_found!('User') unless user
- email = Emails::CreateService.new(current_user, user, declared_params(include_missing: false)).execute
+ email = Emails::CreateService.new(current_user, declared_params(include_missing: false).merge(user: user)).execute
if email.errors.blank?
NotificationService.new.new_email(email)
@@ -367,7 +367,7 @@ module API
not_found!('Email') unless email
destroy_conditionally!(email) do |email|
- Emails::DestroyService.new(current_user, user, email: email.email).execute
+ Emails::DestroyService.new(current_user, user: user, email: email.email).execute
end
user.update_secondary_emails!
@@ -672,7 +672,7 @@ module API
requires :email, type: String, desc: 'The new email'
end
post "emails" do
- email = Emails::CreateService.new(current_user, current_user, declared_params).execute
+ email = Emails::CreateService.new(current_user, declared_params.merge(user: current_user)).execute
if email.errors.blank?
NotificationService.new.new_email(email)
@@ -691,7 +691,7 @@ module API
not_found!('Email') unless email
destroy_conditionally!(email) do |email|
- Emails::DestroyService.new(current_user, current_user, email: email.email).execute
+ Emails::DestroyService.new(current_user, user: current_user, email: email.email).execute
end
current_user.update_secondary_emails!
diff --git a/spec/services/emails/create_service_spec.rb b/spec/services/emails/create_service_spec.rb
index 1c8b81c222c..75812c17309 100644
--- a/spec/services/emails/create_service_spec.rb
+++ b/spec/services/emails/create_service_spec.rb
@@ -2,9 +2,9 @@ require 'spec_helper'
describe Emails::CreateService do
let(:user) { create(:user) }
- let(:opts) { { email: 'new@email.com' } }
+ let(:opts) { { email: 'new@email.com', user: user } }
- subject(:service) { described_class.new(user, user, opts) }
+ subject(:service) { described_class.new(user, opts) }
describe '#execute' do
it 'creates an email with valid attributes' do
diff --git a/spec/services/emails/destroy_service_spec.rb b/spec/services/emails/destroy_service_spec.rb
index 138c3ff33b0..7726fc0ef81 100644
--- a/spec/services/emails/destroy_service_spec.rb
+++ b/spec/services/emails/destroy_service_spec.rb
@@ -4,7 +4,7 @@ describe Emails::DestroyService do
let!(:user) { create(:user) }
let!(:email) { create(:email, user: user) }
- subject(:service) { described_class.new(user, user, email: email.email) }
+ subject(:service) { described_class.new(user, user: user, email: email.email) }
describe '#execute' do
it 'removes an email' do