create.rb 671 B

12345678910111213141516171819202122232425262728
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. class Service::Ticket::SharedDraft::Start::Create < Service::Base
  3. attr_reader :user, :name, :group, :content, :form_id
  4. def initialize(user, form_id, name:, group:, content:)
  5. super()
  6. @user = user
  7. @form_id = form_id
  8. @name = name
  9. @group = group
  10. @content = content
  11. end
  12. def execute
  13. shared_draft = ::Ticket::SharedDraftStart.new(name:, group:, content:)
  14. Pundit.authorize(user, shared_draft, :create?)
  15. UserInfo.with_user_id(user.id) do
  16. shared_draft.save!
  17. shared_draft.attach_upload_cache form_id
  18. end
  19. shared_draft
  20. end
  21. end