summaryrefslogtreecommitdiff
path: root/app/services/emails
diff options
context:
space:
mode:
authorStan Hu <stanhu@gmail.com>2018-09-09 14:04:11 -0700
committerStan Hu <stanhu@gmail.com>2018-09-10 22:41:53 -0700
commitced2a932d75272e25f172b879b08de2208ce4b5c (patch)
tree6e05813f0d28d3ccf110823ec128d7257813a5c1 /app/services/emails
parent2f990e3408d00cad473d8dcf8a4e49155cc3cc33 (diff)
downloadgitlab-ce-ced2a932d75272e25f172b879b08de2208ce4b5c.tar.gz
Add ability to skip user email confirmation with API
This gives admins the ability to send a `skip_confirmation` flag in the `POST /users/:id/email` API endpoint to skip the verification step and assume the given e-mail address is verified. Closes #50876
Diffstat (limited to 'app/services/emails')
-rw-r--r--app/services/emails/base_service.rb2
-rw-r--r--app/services/emails/create_service.rb7
2 files changed, 8 insertions, 1 deletions
diff --git a/app/services/emails/base_service.rb b/app/services/emails/base_service.rb
index ba7b689a9af..988215ffc78 100644
--- a/app/services/emails/base_service.rb
+++ b/app/services/emails/base_service.rb
@@ -2,6 +2,8 @@
module Emails
class BaseService
+ attr_reader :current_user
+
def initialize(current_user, params = {})
@current_user, @params = current_user, params.dup
@user = params.delete(:user)
diff --git a/app/services/emails/create_service.rb b/app/services/emails/create_service.rb
index acf575e24e5..56925a724fe 100644
--- a/app/services/emails/create_service.rb
+++ b/app/services/emails/create_service.rb
@@ -3,7 +3,12 @@
module Emails
class CreateService < ::Emails::BaseService
def execute(extra_params = {})
- @user.emails.create(@params.merge(extra_params))
+ skip_confirmation = @params.delete(:skip_confirmation)
+
+ email = @user.emails.create(@params.merge(extra_params))
+
+ email&.confirm if skip_confirmation && current_user.admin?
+ email
end
end
end