summaryrefslogtreecommitdiff
path: root/app/controllers/sent_notifications_controller.rb
blob: 77757c4a3ef9fd0f898f92e3a89c7f79a0be7fbe (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# frozen_string_literal: true

class SentNotificationsController < ApplicationController
  skip_before_action :authenticate_user!

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

    return render_404 unless @sent_notification && @sent_notification.unsubscribable?
    return unsubscribe_and_redirect if current_user || params[:force]
  end

  private

  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.")

    if current_user
      redirect_to noteable_path(noteable)
    else
      redirect_to new_user_session_path
    end
  end

  def noteable_path(noteable)
    case noteable
    when Issue
      issue_path(noteable)
    when MergeRequest
      merge_request_path(noteable)
    else
      root_path
    end
  end
end