debian-mirror-gitlab/app/controllers/sent_notifications_controller.rb

57 lines
1.3 KiB
Ruby
Raw Normal View History

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