update.rb 880 B

123456789101112131415161718192021222324252627282930313233
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. class Service::Ticket::SharedDraft::Start::Update < Service::Base
  3. attr_reader :user, :name, :group, :content, :form_id, :shared_draft
  4. def initialize(user, shared_draft, form_id, group:, content:, name: nil)
  5. super()
  6. @user = user
  7. @shared_draft = shared_draft
  8. @form_id = form_id
  9. @name = name
  10. @group = group
  11. @content = content
  12. end
  13. def execute
  14. shared_draft.group = group
  15. shared_draft.content = content
  16. # name can be changed via REST api, but GraphQL mutation does not support it
  17. shared_draft.name = name if !name.nil?
  18. Pundit.authorize(user, shared_draft, :update?)
  19. UserInfo.with_user_id(user.id) do
  20. shared_draft.save!
  21. shared_draft.attach_upload_cache form_id
  22. end
  23. shared_draft
  24. end
  25. end