account_owned_concern.rb 786 B

12345678910111213141516171819202122232425262728293031323334
  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. expires_in(3.minutes, public: true) && gone if @account.suspended?
  25. end
  26. end