Commit 7aaf3692 authored by James Lopez's avatar James Lopez

add create and destroy services for emails

parent cabbfe94
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
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
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
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment