authorization.rb 426 B

1234567891011121314151617181920212223
  1. # frozen_string_literal: true
  2. module Authorization
  3. extend ActiveSupport::Concern
  4. include Pundit
  5. def pundit_user
  6. current_account
  7. end
  8. def authorize(*)
  9. super
  10. rescue Pundit::NotAuthorizedError
  11. raise Mastodon::NotPermittedError
  12. end
  13. def authorize_with(user, record, query)
  14. Pundit.authorize(user, record, query)
  15. rescue Pundit::NotAuthorizedError
  16. raise Mastodon::NotPermittedError
  17. end
  18. end