handles_possible_objects.rb 702 B

1234567891011121314151617181920212223242526272829303132
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. module Gql::Concerns::HandlesPossibleObjects
  3. extend ActiveSupport::Concern
  4. included do
  5. private
  6. def fetch_object(object_id, permission: :show?)
  7. Gql::ZammadSchema
  8. .authorized_object_from_id(
  9. object_id,
  10. user: context.current_user,
  11. query: permission,
  12. type: self.class.possible_objects
  13. )
  14. end
  15. end
  16. class_methods do
  17. def possible_objects(*list)
  18. if list.present?
  19. @possible_objects = list.to_a
  20. elsif defined?(@possible_objects)
  21. @possible_objects
  22. else
  23. @possible_objects = []
  24. end
  25. end
  26. end
  27. end