diff options
author | James Lopez <james@jameslopez.es> | 2017-06-16 16:06:14 +0300 |
---|---|---|
committer | James Lopez <james@jameslopez.es> | 2017-06-23 12:41:42 +0300 |
commit | 7aaf3692b3856fa4d11bfc51ef4ab18c7405fc06 (patch) | |
tree | 02673316a40c917f8d61a072a33440769a56531c /app/services | |
parent | cabbfe94fcc929a48b8bf7402cd8cb1cc00612d6 (diff) |
add create and destroy services for emails
Diffstat (limited to 'app/services')
-rw-r--r-- | app/services/emails/base_service.rb | 15 | ||||
-rw-r--r-- | app/services/emails/create_service.rb | 9 | ||||
-rw-r--r-- | app/services/emails/destroy_service.rb | 9 |
3 files changed, 33 insertions, 0 deletions
diff --git a/app/services/emails/base_service.rb b/app/services/emails/base_service.rb new file mode 100644 index 00000000000..0f8617c08bb --- /dev/null +++ b/app/services/emails/base_service.rb @@ -0,0 +1,15 @@ +module Emails + class BaseService + def initialize(current_user, user, opts) + @current_user = current_user + @user = user + @email = opts[:email] + end + + private + + def can_manage_emails? + @current_user == @user || @current_user.admin? + end + end +end diff --git a/app/services/emails/create_service.rb b/app/services/emails/create_service.rb new file mode 100644 index 00000000000..5d5655256fa --- /dev/null +++ b/app/services/emails/create_service.rb @@ -0,0 +1,9 @@ +module Emails + class CreateService < BaseService + def execute(skip_authorization: false) + raise Gitlab::Access::AccessDeniedError unless skip_authorization || can_manage_emails? + + @user.emails.create!(email: @email) + end + end +end diff --git a/app/services/emails/destroy_service.rb b/app/services/emails/destroy_service.rb new file mode 100644 index 00000000000..5080c08c473 --- /dev/null +++ b/app/services/emails/destroy_service.rb @@ -0,0 +1,9 @@ +module Emails + class DestroyService < BaseService + def execute(skip_authorization: false) + raise Gitlab::Access::AccessDeniedError unless skip_authorization || can_manage_emails? + + Email.find_by_email(@email).destroy! + end + end +end |