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
|
|
|
|
noteable.unsubscribe(@sent_notification.recipient)
|
|
|
|
|
|
|
|
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
|
2016-01-09 13:32:03 -05:00
|
|
|
case noteable
|
2015-12-09 05:59:25 -05:00
|
|
|
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
|