update.rb 1.1 KB

1234567891011121314151617181920212223242526272829303132333435
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. module Gql::Mutations
  3. class Organization::Update < BaseMutation
  4. description 'Update organization data.'
  5. argument :id, GraphQL::Types::ID, description: 'The organization ID', as: :current_organization, loads: Gql::Types::OrganizationType
  6. argument :input, Gql::Types::Input::OrganizationInputType, description: 'The organization data'
  7. field :organization, Gql::Types::OrganizationType, description: 'The updated organization.'
  8. # TODO/FIXME: Remove this again when we have a proper solution to deal with Pundit stuff in GraphQL mutations.
  9. def self.authorize(_obj, ctx)
  10. ctx.current_user.permissions?(['admin.organization', 'ticket.agent'])
  11. end
  12. def resolve(current_organization:, input:)
  13. { organization: update(current_organization, input) }
  14. end
  15. private
  16. def update(current_organization, input)
  17. params = input.to_h
  18. set_core_workflow_information(params, ::Organization, 'edit')
  19. current_organization.with_lock do
  20. current_organization.update!(params)
  21. end
  22. current_organization
  23. end
  24. end
  25. end