2018-09-14 05:42:05 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2015-12-09 10:59:25 +00:00
|
|
|
class SentNotificationsController < ApplicationController
|
|
|
|
skip_before_action :authenticate_user!
|
|
|
|
|
2020-10-05 12:08:47 +00:00
|
|
|
feature_category :users
|
|
|
|
|
2015-12-09 10:59:25 +00:00
|
|
|
def unsubscribe
|
|
|
|
@sent_notification = SentNotification.for(params[:id])
|
2016-07-13 23:56:54 +00:00
|
|
|
|
2020-01-28 12:08:44 +00:00
|
|
|
return render_404 unless unsubscribe_prerequisites_met?
|
|
|
|
|
2016-09-16 15:08:09 +00:00
|
|
|
return unsubscribe_and_redirect if current_user || params[:force]
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
2015-12-09 10:59:25 +00:00
|
|
|
|
2020-01-28 12:08:44 +00:00
|
|
|
def unsubscribe_prerequisites_met?
|
|
|
|
@sent_notification.present? &&
|
|
|
|
@sent_notification.unsubscribable? &&
|
|
|
|
noteable.present?
|
|
|
|
end
|
|
|
|
|
|
|
|
def noteable
|
|
|
|
@sent_notification.noteable
|
|
|
|
end
|
|
|
|
|
2016-09-16 15:08:09 +00:00
|
|
|
def unsubscribe_and_redirect
|
2016-11-04 18:19:08 +00:00
|
|
|
noteable.unsubscribe(@sent_notification.recipient, @sent_notification.project)
|
2015-12-09 10:59:25 +00:00
|
|
|
|
2019-04-08 14:17:45 +00:00
|
|
|
flash[:notice] = _("You have been unsubscribed from this thread.")
|
2016-07-13 23:56:54 +00:00
|
|
|
|
2015-12-09 10:59:25 +00:00
|
|
|
if current_user
|
2019-09-10 12:30:07 +00:00
|
|
|
if current_user.can?(:"read_#{noteable.class.to_ability_name}", noteable)
|
|
|
|
redirect_to noteable_path(noteable)
|
|
|
|
else
|
|
|
|
redirect_to root_path
|
|
|
|
end
|
2015-12-09 10:59:25 +00:00
|
|
|
else
|
|
|
|
redirect_to new_user_session_path
|
|
|
|
end
|
|
|
|
end
|
2018-05-03 21:32:20 +00:00
|
|
|
|
|
|
|
def noteable_path(noteable)
|
|
|
|
case noteable
|
|
|
|
when Issue
|
|
|
|
issue_path(noteable)
|
|
|
|
when MergeRequest
|
|
|
|
merge_request_path(noteable)
|
|
|
|
else
|
|
|
|
root_path
|
|
|
|
end
|
|
|
|
end
|
2015-12-09 10:59:25 +00:00
|
|
|
end
|
2019-09-13 13:26:31 +00:00
|
|
|
|
|
|
|
SentNotificationsController.prepend_if_ee('EE::SentNotificationsController')
|