form_updater.rb 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. module Gql::Queries
  3. class FormUpdater < BaseQuery
  4. description 'Return updated form information for a frontend form (e.g. core workflow information or resolved relations).'
  5. attr_reader :form_updater
  6. argument :form_updater_id, Gql::Types::Enum::FormUpdaterIdType, description: 'Form updater identifier'
  7. argument :relation_fields, [Gql::Types::Input::FormUpdater::RelationFieldType], description: 'Relation field information'
  8. argument :meta, Gql::Types::Input::FormUpdater::MetaInputType, description: 'Form meta information'
  9. argument :data, GraphQL::Types::JSON, description: 'Current form data from'
  10. argument :id, GraphQL::Types::ID, required: false, description: 'Optional ID for related entity (e.g. for update forms)'
  11. type GraphQL::Types::JSON, null: false
  12. def initialize(*args, **kwargs, &)
  13. super(*args, **kwargs, &)
  14. arguments = context[:current_arguments]
  15. @form_updater = arguments[:form_updater_id].new(
  16. context: context,
  17. relation_fields: arguments[:relation_fields],
  18. meta: arguments[:meta].to_h,
  19. data: arguments[:data].dup,
  20. id: arguments[:id]
  21. )
  22. raise ActiveRecord::RecordNotFound, __('FormSchema could not be found.') if !@form_updater
  23. end
  24. def self.authorize(_obj, ctx)
  25. # Per default the queries require a authenticated user.
  26. if !ctx[:current_arguments][:form_updater_id].requires_authentication
  27. true
  28. end
  29. super
  30. end
  31. def authorized?(...)
  32. if form_updater.respond_to?(:authorized?)
  33. return form_updater.authorized?
  34. end
  35. super
  36. end
  37. def resolve(...)
  38. form_updater.resolve
  39. end
  40. end
  41. end