about summary refs log tree commit diff
path: root/app/controllers/settings/aliases_controller.rb
blob: a421b8ede312920d3bc969917c418b358a0f13a2 (plain) (blame)
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
# frozen_string_literal: true

class Settings::AliasesController < Settings::BaseController
  skip_before_action :require_functional!

  before_action :require_not_suspended!
  before_action :set_aliases, except: :destroy
  before_action :set_alias, only: :destroy

  def index
    @alias = current_account.aliases.build
  end

  def create
    @alias = current_account.aliases.build(resource_params)

    if @alias.save
      ActivityPub::UpdateDistributionWorker.perform_async(current_account.id)
      redirect_to settings_aliases_path, notice: I18n.t('aliases.created_msg')
    else
      render :index
    end
  end

  def destroy
    @alias.destroy!
    redirect_to settings_aliases_path, notice: I18n.t('aliases.deleted_msg')
  end

  private

  def resource_params
    params.require(:account_alias).permit(:acct)
  end

  def set_alias
    @alias = current_account.aliases.find(params[:id])
  end

  def set_aliases
    @aliases = current_account.aliases.order(id: :desc).reject(&:new_record?)
  end
end