account_owned_concern.rb 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. # frozen_string_literal: true
  2. module AccountOwnedConcern
  3. extend ActiveSupport::Concern
  4. included do
  5. before_action :authenticate_user!, if: -> { limited_federation_mode? && request.format != :json }
  6. before_action :set_account, if: :account_required?
  7. before_action :check_account_approval, if: :account_required?
  8. before_action :check_account_suspension, if: :account_required?
  9. before_action :check_account_confirmation, if: :account_required?
  10. end
  11. private
  12. def account_required?
  13. true
  14. end
  15. def set_account
  16. @account = Account.find_local!(username_param)
  17. end
  18. def username_param
  19. params[:account_username]
  20. end
  21. def check_account_approval
  22. not_found if @account.local? && @account.user_pending?
  23. end
  24. def check_account_confirmation
  25. not_found if @account.local? && !@account.user_confirmed?
  26. end
  27. def check_account_suspension
  28. if @account.permanently_unavailable?
  29. permanent_unavailability_response
  30. elsif @account.suspended? && !skip_temporary_suspension_response?
  31. temporary_suspension_response
  32. end
  33. end
  34. def skip_temporary_suspension_response?
  35. false
  36. end
  37. def permanent_unavailability_response
  38. expires_in(3.minutes, public: true)
  39. gone
  40. end
  41. def temporary_suspension_response
  42. expires_in(3.minutes, public: true)
  43. forbidden
  44. end
  45. end