attachments_controller.rb 736 B

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