2019-06-04 03:40:48 +00:00
|
|
|
# Copyright (C) 2012-2017 Zammad Foundation, http://zammad-foundation.org/
|
|
|
|
|
|
|
|
class KnowledgeBase::Answer::AttachmentsController < ApplicationController
|
|
|
|
prepend_before_action :authentication_check
|
2020-04-20 09:47:45 +00:00
|
|
|
before_action :authorize!
|
2019-06-04 03:40:48 +00:00
|
|
|
before_action :fetch_answer
|
|
|
|
|
|
|
|
def create
|
2020-02-19 16:41:25 +00:00
|
|
|
@answer.add_attachment params[:file]
|
2019-06-04 03:40:48 +00:00
|
|
|
|
2020-02-19 16:41:25 +00:00
|
|
|
render json: @answer.assets({})
|
2019-06-04 03:40:48 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def destroy
|
2020-02-19 16:41:25 +00:00
|
|
|
@answer.remove_attachment params[:id]
|
2019-06-04 03:40:48 +00:00
|
|
|
|
2020-02-19 16:41:25 +00:00
|
|
|
render json: @answer.assets({})
|
2019-06-04 03:40:48 +00:00
|
|
|
end
|
|
|
|
|
2020-04-20 09:47:45 +00:00
|
|
|
def clone_to_form
|
|
|
|
new_attachments = @answer.clone_attachments('UploadCache', params[:form_id], only_attached_attachments: true)
|
|
|
|
|
|
|
|
render json: {
|
|
|
|
attachments: new_attachments
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
2019-06-04 03:40:48 +00:00
|
|
|
private
|
|
|
|
|
|
|
|
def fetch_answer
|
|
|
|
@answer = KnowledgeBase::Answer.find params[:answer_id]
|
|
|
|
end
|
|
|
|
end
|