about summary refs log tree commit diff
path: root/app/controllers/settings/pictures_controller.rb
blob: 58a4325307f3b42c028e14e71b9061c3fd982ad7 (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
# frozen_string_literal: true

module Settings
  class PicturesController < BaseController
    before_action :set_account
    before_action :set_picture

    def destroy
      if valid_picture?
        if UpdateAccountService.new.call(@account, { @picture => nil, "#{@picture}_remote_url" => '' })
          ActivityPub::UpdateDistributionWorker.perform_async(@account.id)
          redirect_to settings_profile_path, notice: I18n.t('generic.changes_saved_msg'), status: 303
        else
          redirect_to settings_profile_path
        end
      else
        bad_request
      end
    end

    private

    def set_account
      @account = current_account
    end

    def set_picture
      @picture = params[:id]
    end

    def valid_picture?
      %w(avatar header).include?(@picture)
    end
  end
end