permissions.rb 517 B

12345678910111213141516171819202122
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. module Token::Permissions
  3. extend ActiveSupport::Concern
  4. def permissions
  5. Permission.where(
  6. name: Array(preferences[:permission]),
  7. active: true,
  8. )
  9. end
  10. def permissions?(query)
  11. effective_user.permissions?(query) && Auth::Permissions.authorized?(self, query)
  12. end
  13. def permissions!(query)
  14. return true if permissions?(query)
  15. raise Exceptions::Forbidden, __('Token authorization failed.')
  16. end
  17. end