attachments_controller.rb 757 B

123456789101112131415161718192021222324252627282930313233
  1. # Copyright (C) 2012-2023 Zammad Foundation, https://zammad-foundation.org/
  2. class KnowledgeBase::Answer::AttachmentsController < ApplicationController
  3. prepend_before_action :authentication_check
  4. before_action :authorize!
  5. before_action :fetch_answer
  6. def create
  7. @answer.add_attachment params[:file]
  8. render json: @answer.assets({})
  9. end
  10. def destroy
  11. @answer.remove_attachment params[:id]
  12. render json: @answer.assets({})
  13. end
  14. def clone_to_form
  15. new_attachments = @answer.clone_attachments('UploadCache', params[:form_id], only_attached_attachments: true)
  16. render json: {
  17. attachments: new_attachments
  18. }
  19. end
  20. private
  21. def fetch_answer
  22. @answer = KnowledgeBase::Answer.find params[:answer_id]
  23. end
  24. end