|
|
|
@ -40,6 +40,31 @@ module API |
|
|
|
|
attachments.count, |
|
|
|
|
self_path) |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
post do |
|
|
|
|
authorize(:edit_work_packages, context: @work_package.project) |
|
|
|
|
|
|
|
|
|
metadata = params[:metadata] |
|
|
|
|
file = params[:file] |
|
|
|
|
|
|
|
|
|
# TODO: verify input (valid JSON + file given) |
|
|
|
|
|
|
|
|
|
# FIXME: we should be using the representer to parse the metadata |
|
|
|
|
parsed_metadata = JSON.parse(metadata) |
|
|
|
|
|
|
|
|
|
uploaded_file = Rack::Multipart::UploadedFile.new file[:tempfile].path, |
|
|
|
|
file[:type], |
|
|
|
|
true |
|
|
|
|
# I wish I could set the file name in a better way *sigh* |
|
|
|
|
uploaded_file.instance_variable_set(:@original_filename, parsed_metadata['fileName']) |
|
|
|
|
attachment = Attachment.new(file: uploaded_file, |
|
|
|
|
container: @work_package, |
|
|
|
|
description: parsed_metadata['description']['raw'], |
|
|
|
|
author: current_user) |
|
|
|
|
attachment.save! |
|
|
|
|
|
|
|
|
|
::API::V3::Attachments::AttachmentRepresenter.new(attachment) |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|