BigW Consortium Gitlab

sent_notifications_controller.rb 868 Bytes
Newer Older
1 2 3 4 5
class SentNotificationsController < ApplicationController
  skip_before_action :authenticate_user!

  def unsubscribe
    @sent_notification = SentNotification.for(params[:id])
6

7
    return render_404 unless @sent_notification && @sent_notification.unsubscribable?
8 9 10 11
    return unsubscribe_and_redirect if current_user || params[:force]
  end

  private
12

13
  def unsubscribe_and_redirect
14
    noteable = @sent_notification.noteable
15
    noteable.unsubscribe(@sent_notification.recipient, @sent_notification.project)
16 17

    flash[:notice] = "You have been unsubscribed from this thread."
18

19
    if current_user
20
      case noteable
21 22 23 24 25 26 27 28 29 30 31 32
      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