about summary refs log tree commit diff
path: root/app/controllers/concerns/account_owned_concern.rb
blob: 65168efff676615904defcf6b826ad9da68ae6e5 (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
# frozen_string_literal: true

module AccountOwnedConcern
  extend ActiveSupport::Concern

  included do
    #before_action :authenticate_user!, if: -> { whitelist_mode? && request.format != :json }
    before_action :set_account, if: :account_required?
    before_action :check_account_approval, if: :account_required?
    before_action :check_account_suspension, if: :account_required?
  end

  private

  def account_required?
    true
  end

  def set_account
    @account = Account.find_local!(username_param)
  end

  def username_param
    params[:account_username]
  end

  def check_account_approval
    not_found if @account.local? && @account.user_pending?
  end

  def check_account_suspension
    expires_in(3.minutes, public: true) && gone if @account.suspended?
  end
end