2016-10-12 17:07:36 +00:00
|
|
|
require 'gitlab/email/handler/base_handler'
|
|
|
|
|
|
|
|
module Gitlab
|
|
|
|
module Email
|
|
|
|
module Handler
|
|
|
|
class UnsubscribeHandler < BaseHandler
|
2017-04-20 10:33:51 +00:00
|
|
|
delegate :project, to: :sent_notification, allow_nil: true
|
|
|
|
|
2016-10-12 17:07:36 +00:00
|
|
|
def can_handle?
|
|
|
|
mail_key =~ /\A\w+#{Regexp.escape(Gitlab::IncomingEmail::UNSUBSCRIBE_SUFFIX)}\z/
|
|
|
|
end
|
|
|
|
|
|
|
|
def execute
|
|
|
|
raise SentNotificationNotFoundError unless sent_notification
|
|
|
|
return unless sent_notification.unsubscribable?
|
|
|
|
|
|
|
|
noteable = sent_notification.noteable
|
|
|
|
raise NoteableNotFoundError unless noteable
|
|
|
|
noteable.unsubscribe(sent_notification.recipient)
|
|
|
|
end
|
|
|
|
|
2017-04-21 15:11:21 +00:00
|
|
|
def metrics_params
|
2017-05-05 09:33:41 +00:00
|
|
|
super.merge(project: project&.full_path)
|
2017-04-21 15:11:21 +00:00
|
|
|
end
|
|
|
|
|
2016-10-12 17:07:36 +00:00
|
|
|
private
|
|
|
|
|
|
|
|
def sent_notification
|
|
|
|
@sent_notification ||= SentNotification.for(reply_key)
|
|
|
|
end
|
|
|
|
|
|
|
|
def reply_key
|
|
|
|
mail_key.sub(Gitlab::IncomingEmail::UNSUBSCRIBE_SUFFIX, '')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|