summaryrefslogtreecommitdiff
path: root/app/controllers/sent_notifications_controller.rb
diff options
context:
space:
mode:
Diffstat (limited to 'app/controllers/sent_notifications_controller.rb')
-rw-r--r--app/controllers/sent_notifications_controller.rb14
1 files changed, 12 insertions, 2 deletions
diff --git a/app/controllers/sent_notifications_controller.rb b/app/controllers/sent_notifications_controller.rb
index 893f5145e99..20134de81a0 100644
--- a/app/controllers/sent_notifications_controller.rb
+++ b/app/controllers/sent_notifications_controller.rb
@@ -6,14 +6,24 @@ class SentNotificationsController < ApplicationController
def unsubscribe
@sent_notification = SentNotification.for(params[:id])
- return render_404 unless @sent_notification && @sent_notification.unsubscribable?
+ return render_404 unless unsubscribe_prerequisites_met?
+
return unsubscribe_and_redirect if current_user || params[:force]
end
private
+ def unsubscribe_prerequisites_met?
+ @sent_notification.present? &&
+ @sent_notification.unsubscribable? &&
+ noteable.present?
+ end
+
+ def noteable
+ @sent_notification.noteable
+ end
+
def unsubscribe_and_redirect
- noteable = @sent_notification.noteable
noteable.unsubscribe(@sent_notification.recipient, @sent_notification.project)
flash[:notice] = _("You have been unsubscribed from this thread.")