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
|
|
|
|
|
|
|
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
|
2018-05-03 17:32:20 -04:00
|
|
|
redirect_to noteable_path(noteable)
|
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
|