Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJames Lopez <james@jameslopez.es>2017-06-19 16:35:44 +0300
committerJames Lopez <james@jameslopez.es>2017-06-23 12:41:42 +0300
commit831b2fccf9a2efc772d62c05f52c612f23a63ea9 (patch)
treec36fd08364a01f2ba713f8df5aa3dd1c69314220
parent87bf08c96cf9f3c451d0746d11ceac149adf22db (diff)
update missing email actions
-rw-r--r--app/controllers/profiles/emails_controller.rb2
-rw-r--r--app/models/user.rb2
-rw-r--r--app/services/emails/create_service.rb2
-rw-r--r--lib/api/users.rb10
4 files changed, 7 insertions, 9 deletions
diff --git a/app/controllers/profiles/emails_controller.rb b/app/controllers/profiles/emails_controller.rb
index 9159c217f1b..40b43278439 100644
--- a/app/controllers/profiles/emails_controller.rb
+++ b/app/controllers/profiles/emails_controller.rb
@@ -7,7 +7,7 @@ class Profiles::EmailsController < Profiles::ApplicationController
def create
@email = current_user.emails.new(email_params)
- if @email.save
+ if Emails::CreateService.new(current_user, current_user, email_params).execute
NotificationService.new.new_email(@email)
else
flash[:alert] = @email.errors.full_messages.first
diff --git a/app/models/user.rb b/app/models/user.rb
index bc754768ab1..6ca78278db8 100644
--- a/app/models/user.rb
+++ b/app/models/user.rb
@@ -495,7 +495,7 @@ class User < ActiveRecord::Base
primary_email_record = emails.find_by(email: email)
if primary_email_record
Emails::DestroyService.new(self, self, email: email).execute
- emails.create(email: email_was)
+ Emails::CreateService.new(self, self, email: email_was).execute
update_secondary_emails!
end
diff --git a/app/services/emails/create_service.rb b/app/services/emails/create_service.rb
index 95e226ec710..ea65b82e418 100644
--- a/app/services/emails/create_service.rb
+++ b/app/services/emails/create_service.rb
@@ -3,7 +3,7 @@ module Emails
def execute(skip_authorization: false)
raise Gitlab::Access::AccessDeniedError unless skip_authorization || can_manage_emails?
- @user.emails.create!(email: @email)
+ @user.emails.create(email: @email)
end
end
end
diff --git a/lib/api/users.rb b/lib/api/users.rb
index 940f8b64026..190e2e71884 100644
--- a/lib/api/users.rb
+++ b/lib/api/users.rb
@@ -98,7 +98,7 @@ module API
authenticated_as_admin!
params = declared_params(include_missing: false)
- user = ::Users::CreateService.new(current_user, params).execute
+ user = ::Users::CreateService.new(current_user, params).execute(skip_authorization: true)
if user.persisted?
present user, with: Entities::UserPublic
@@ -236,9 +236,7 @@ module API
user = User.find_by(id: params.delete(:id))
not_found!('User') unless user
- email = user.emails.new(declared_params(include_missing: false))
-
- if email.save
+ if Emails::CreateService.new(current_user, user, declared_params(include_missing: false)).execute(skip_authorization: true)
NotificationService.new.new_email(email)
present email, with: Entities::Email
else
@@ -276,7 +274,7 @@ module API
email = user.emails.find_by(id: params[:email_id])
not_found!('Email') unless email
- Emails::DestroyService.new(current_user, user, email: email.email).execute
+ Emails::DestroyService.new(current_user, user, email: email.email).execute(skip_authorization: true)
::Users::UpdateService.new(current_user, user).execute do |user|
user.update_secondary_emails!
@@ -494,7 +492,7 @@ module API
post "emails" do
email = current_user.emails.new(declared_params)
- if email.save
+ if Emails::CreateService.new(current_user, current_user, declared_params).execute
NotificationService.new.new_email(email)
present email, with: Entities::Email
else