summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJames Lopez <james@jameslopez.es>2017-06-16 15:06:14 +0200
committerJames Lopez <james@jameslopez.es>2017-06-23 11:41:42 +0200
commit7aaf3692b3856fa4d11bfc51ef4ab18c7405fc06 (patch)
tree02673316a40c917f8d61a072a33440769a56531c
parentcabbfe94fcc929a48b8bf7402cd8cb1cc00612d6 (diff)
downloadgitlab-ce-7aaf3692b3856fa4d11bfc51ef4ab18c7405fc06.tar.gz
add create and destroy services for emails
-rw-r--r--app/services/emails/base_service.rb15
-rw-r--r--app/services/emails/create_service.rb9
-rw-r--r--app/services/emails/destroy_service.rb9
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