account_owned_concern.rb 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. # frozen_string_literal: true
  2. module AccountOwnedConcern
  3. extend ActiveSupport::Concern
  4. included do
  5. before_action :authenticate_user!, if: -> { whitelist_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. end
  10. private
  11. def account_required?
  12. true
  13. end
  14. def set_account
  15. @account = Account.find_local!(username_param)
  16. end
  17. def username_param
  18. params[:account_username]
  19. end
  20. def check_account_approval
  21. not_found if @account.local? && @account.user_pending?
  22. end
  23. def check_account_suspension
  24. if @account.suspended_permanently?
  25. permanent_suspension_response
  26. elsif @account.suspended? && !skip_temporary_suspension_response?
  27. temporary_suspension_response
  28. end
  29. end
  30. def skip_temporary_suspension_response?
  31. false
  32. end
  33. def permanent_suspension_response
  34. expires_in(3.minutes, public: true)
  35. gone
  36. end
  37. def temporary_suspension_response
  38. expires_in(3.minutes, public: true)
  39. forbidden
  40. end
  41. end