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

37 lines
895 B
Ruby
Raw Normal View History

class SentNotificationsController < ApplicationController
skip_before_action :authenticate_user!
def unsubscribe
@sent_notification = SentNotification.for(params[:id])
2016-09-29 09:46:39 +05:30
return render_404 unless @sent_notification && @sent_notification.unsubscribable?
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
def unsubscribe_and_redirect
noteable = @sent_notification.noteable
2017-08-17 22:00:37 +05:30
noteable.unsubscribe(@sent_notification.recipient, @sent_notification.project)
flash[:notice] = "You have been unsubscribed from this thread."
2016-09-29 09:46:39 +05:30
if current_user
2018-10-15 14:42:47 +05:30
redirect_to noteable_path(noteable)
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