闭社主体 forked from https://github.com/tootsuite/mastodon
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

34 lines
786 B

  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