2019-07-08 20:03:45 +10:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module AccountOwnedConcern
|
|
|
|
extend ActiveSupport::Concern
|
|
|
|
|
|
|
|
included do
|
2023-08-03 03:32:48 +10:00
|
|
|
before_action :authenticate_user!, if: -> { limited_federation_mode? && request.format != :json }
|
2019-07-08 20:03:45 +10:00
|
|
|
before_action :set_account, if: :account_required?
|
|
|
|
before_action :check_account_approval, if: :account_required?
|
|
|
|
before_action :check_account_suspension, if: :account_required?
|
2022-01-29 00:24:37 +11:00
|
|
|
before_action :check_account_confirmation, if: :account_required?
|
2019-07-08 20:03:45 +10:00
|
|
|
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
|
|
|
|
|
2022-01-29 00:24:37 +11:00
|
|
|
def check_account_confirmation
|
|
|
|
not_found if @account.local? && !@account.user_confirmed?
|
|
|
|
end
|
|
|
|
|
2019-07-08 20:03:45 +10:00
|
|
|
def check_account_suspension
|
2023-12-01 02:43:26 +11:00
|
|
|
if @account.permanently_unavailable?
|
|
|
|
permanent_unavailability_response
|
2020-11-08 10:28:39 +11:00
|
|
|
elsif @account.suspended? && !skip_temporary_suspension_response?
|
|
|
|
temporary_suspension_response
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def skip_temporary_suspension_response?
|
|
|
|
false
|
|
|
|
end
|
|
|
|
|
2023-12-01 02:43:26 +11:00
|
|
|
def permanent_unavailability_response
|
2020-11-08 10:28:39 +11:00
|
|
|
expires_in(3.minutes, public: true)
|
|
|
|
gone
|
|
|
|
end
|
|
|
|
|
|
|
|
def temporary_suspension_response
|
|
|
|
expires_in(3.minutes, public: true)
|
|
|
|
forbidden
|
2019-07-08 20:03:45 +10:00
|
|
|
end
|
|
|
|
end
|