~cytrogen/masto-fe

ref: 937dc42f101be905e3af41b879901a4445b0223a masto-fe/app/controllers/mail_subscriptions_controller.rb -rw-r--r-- 848 bytes
937dc42f — Matt Jankowski Extract methods for file movement in `CLI::Upgrade` (#25120) 2 years ago
                                                                                
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
39
40
41
42
43
44
# frozen_string_literal: true

class MailSubscriptionsController < ApplicationController
  layout 'auth'

  skip_before_action :require_functional!

  before_action :set_body_classes
  before_action :set_user
  before_action :set_type

  protect_from_forgery with: :null_session

  def show; end

  def create
    @user.settings[email_type_from_param] = false
    @user.save!
  end

  private

  def set_user
    @user = GlobalID::Locator.locate_signed(params[:token], for: 'unsubscribe')
    not_found unless @user
  end

  def set_body_classes
    @body_classes = 'lighter'
  end

  def set_type
    @type = email_type_from_param
  end

  def email_type_from_param
    case params[:type]
    when 'follow', 'reblog', 'favourite', 'mention', 'follow_request'
      "notification_emails.#{params[:type]}"
    else
      not_found
    end
  end
end