2018-09-14 01:42:05 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2015-12-09 05:59:25 -05:00
|
|
|
class SentNotificationsController < ApplicationController
|
|
|
|
skip_before_action :authenticate_user!
|
|
|
|
|
|
|
|
def unsubscribe
|
|
|
|
@sent_notification = SentNotification.for(params[:id])
|
2016-07-13 19:56:54 -04:00
|
|
|
|
2016-01-11 08:23:45 -05:00
|
|
|
return render_404 unless @sent_notification && @sent_notification.unsubscribable?
|
2016-09-16 11:08:09 -04:00
|
|
|
return unsubscribe_and_redirect if current_user || params[:force]
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
2015-12-09 05:59:25 -05:00
|
|
|
|
2016-09-16 11:08:09 -04:00
|
|
|
def unsubscribe_and_redirect
|
2015-12-09 05:59:25 -05:00
|
|
|
noteable = @sent_notification.noteable
|
2016-11-04 14:19:08 -04:00
|
|
|
noteable.unsubscribe(@sent_notification.recipient, @sent_notification.project)
|
2015-12-09 05:59:25 -05:00
|
|
|
|
2019-04-08 10:17:45 -04:00
|
|
|
flash[:notice] = _("You have been unsubscribed from this thread.")
|
2016-07-13 19:56:54 -04:00
|
|
|
|
2015-12-09 05:59:25 -05:00
|
|
|
if current_user
|
2019-09-10 08:30:07 -04: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 05:59:25 -05:00
|
|
|
else
|
|
|
|
redirect_to new_user_session_path
|
|
|
|
end
|
|
|
|
end
|
2018-05-03 17:32:20 -04: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 05:59:25 -05:00
|
|
|
end
|
2019-09-13 09:26:31 -04:00
|
|
|
|
|
|
|
SentNotificationsController.prepend_if_ee('EE::SentNotificationsController')
|