2016-01-19 16:12:03 +05:30
|
|
|
class SentNotificationsController < ApplicationController
|
|
|
|
skip_before_action :authenticate_user!
|
|
|
|
|
|
|
|
def unsubscribe
|
|
|
|
@sent_notification = SentNotification.for(params[:id])
|
2016-09-29 09:46:39 +05:30
|
|
|
|
2016-01-19 16:12:03 +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-01-19 16:12:03 +05:30
|
|
|
|
2016-09-29 09:46:39 +05:30
|
|
|
private
|
|
|
|
|
|
|
|
def unsubscribe_and_redirect
|
2016-01-19 16:12:03 +05:30
|
|
|
noteable = @sent_notification.noteable
|
|
|
|
noteable.unsubscribe(@sent_notification.recipient)
|
|
|
|
|
|
|
|
flash[:notice] = "You have been unsubscribed from this thread."
|
2016-09-29 09:46:39 +05:30
|
|
|
|
2016-01-19 16:12:03 +05:30
|
|
|
if current_user
|
|
|
|
case noteable
|
|
|
|
when Issue
|
|
|
|
redirect_to issue_path(noteable)
|
|
|
|
when MergeRequest
|
|
|
|
redirect_to merge_request_path(noteable)
|
|
|
|
else
|
|
|
|
redirect_to root_path
|
|
|
|
end
|
|
|
|
else
|
|
|
|
redirect_to new_user_session_path
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|