upsert.rb 1.5 KB

123456789101112131415161718192021222324252627282930313233343536
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. module Gql::Mutations
  3. # At the moment the implementaion is more or less only for the "live" user handling in the
  4. # mobile view, because we have no "real" taskbar in the mobile view.
  5. # For the future we should refactor the complete taskbar handling (e.g. split taskbar/auto-save/live-user) handling.
  6. class Ticket::LiveUser::Upsert < Ticket::LiveUser::Base
  7. description 'Updates the current live user entry. If no matching live user entry is found, a new live user entry for the current user and ticket will be created.'
  8. argument :editing, Boolean, description: 'Indicates if the user is currently editing the ticket.'
  9. field :success, Boolean, null: false, description: 'Did we succeed to insert/update the live user entry?'
  10. def resolve(ticket:, app:, editing:)
  11. taskbar_key = taskbar_key(ticket.id)
  12. taskbar_item = taskbar_item(taskbar_key, app)
  13. if taskbar_item.present?
  14. taskbar_item.update!({ state: { editing: editing } })
  15. else
  16. Taskbar.create!({
  17. user_id: context.current_user.id,
  18. active: true,
  19. app: app,
  20. key: taskbar_key,
  21. callback: 'TicketDetailView',
  22. params: { ticket_id: ticket.id },
  23. state: { editing: editing },
  24. prio: 100,
  25. })
  26. end
  27. { success: true }
  28. end
  29. end
  30. end