#9 Active Storage - new revisions
This commit is contained in:
parent
64de6a1e9d
commit
911457de79
@ -131,24 +131,24 @@ class DmsfFilesController < ApplicationController
|
|||||||
revision.minor_version = DmsfUploadHelper.db_version(params[:version_minor])
|
revision.minor_version = DmsfUploadHelper.db_version(params[:version_minor])
|
||||||
revision.patch_version = DmsfUploadHelper.db_version(params[:version_patch])
|
revision.patch_version = DmsfUploadHelper.db_version(params[:version_patch])
|
||||||
|
|
||||||
|
# New content
|
||||||
if params[:dmsf_attachments].present?
|
if params[:dmsf_attachments].present?
|
||||||
keys = params[:dmsf_attachments].keys
|
keys = params[:dmsf_attachments].keys
|
||||||
file_upload = params[:dmsf_attachments][keys.first] if keys&.first
|
file_upload = params[:dmsf_attachments][keys.first] if keys&.first
|
||||||
end
|
a = Attachment.find_by_token(file_upload[:token]) if file_upload
|
||||||
if file_upload
|
if a
|
||||||
upload = DmsfUpload.create_from_uploaded_attachment(@project, @folder, file_upload)
|
revision.size = a.filesize
|
||||||
if upload
|
revision.shared_file.attach(
|
||||||
revision.size = upload.size
|
io: File.open(a.diskfile),
|
||||||
revision.file.attach(
|
filename: a.filename,
|
||||||
io: File.open(upload.tempfile_path),
|
content_type: a.content_type.presence || 'application/octet-stream',
|
||||||
filename: file_upload.filename,
|
|
||||||
content_type: Redmine::MimeType.of(file_upload.filename),
|
|
||||||
identify: false
|
identify: false
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
revision.size = last_revision.size
|
revision.size = last_revision.size
|
||||||
end
|
end
|
||||||
|
|
||||||
# Custom fields
|
# Custom fields
|
||||||
revision.copy_custom_field_values(params[:dmsf_file_revision][:custom_field_values], last_revision)
|
revision.copy_custom_field_values(params[:dmsf_file_revision][:custom_field_values], last_revision)
|
||||||
ok = true
|
ok = true
|
||||||
|
|||||||
@ -65,11 +65,6 @@ class DmsfUploadController < ApplicationController
|
|||||||
|
|
||||||
# REST API and Redmine attachment form
|
# REST API and Redmine attachment form
|
||||||
def upload
|
def upload
|
||||||
unless request.media_type == 'application/octet-stream'
|
|
||||||
head :not_acceptable
|
|
||||||
return
|
|
||||||
end
|
|
||||||
|
|
||||||
@attachment = Attachment.new(file: request.body)
|
@attachment = Attachment.new(file: request.body)
|
||||||
@attachment.author = User.current
|
@attachment.author = User.current
|
||||||
@attachment.filename = params[:filename].presence || Redmine::Utils.random_hex(16)
|
@attachment.filename = params[:filename].presence || Redmine::Utils.random_hex(16)
|
||||||
|
|||||||
@ -91,7 +91,7 @@ module DmsfUploadHelper
|
|||||||
a = Attachment.find_by_token(committed_file[:token])
|
a = Attachment.find_by_token(committed_file[:token])
|
||||||
committed_file[:tempfile_path] = a.diskfile if a
|
committed_file[:tempfile_path] = a.diskfile if a
|
||||||
end
|
end
|
||||||
new_revision.file.attach(
|
new_revision.shared_file.attach(
|
||||||
io: File.open(committed_file[:tempfile_path]),
|
io: File.open(committed_file[:tempfile_path]),
|
||||||
filename: new_revision.name,
|
filename: new_revision.name,
|
||||||
content_type: committed_file[:mime_type],
|
content_type: committed_file[:mime_type],
|
||||||
|
|||||||
@ -333,7 +333,7 @@ class DmsfFile < ApplicationRecord
|
|||||||
end
|
end
|
||||||
if last_revision.file.attached?
|
if last_revision.file.attached?
|
||||||
begin
|
begin
|
||||||
new_revision.file.attach(
|
new_revision.shared_file.attach(
|
||||||
io: StringIO.new(last_revision.file.download),
|
io: StringIO.new(last_revision.file.download),
|
||||||
filename: filename,
|
filename: filename,
|
||||||
content_type: new_revision.file.content_type,
|
content_type: new_revision.file.content_type,
|
||||||
|
|||||||
@ -278,7 +278,7 @@ class DmsfFileRevision < ApplicationRecord
|
|||||||
end
|
end
|
||||||
|
|
||||||
def copy_file_content(open_file)
|
def copy_file_content(open_file)
|
||||||
file.attach io: open_file, filename: dmsf_file.name
|
shared_file.attach io: open_file, filename: dmsf_file.name
|
||||||
end
|
end
|
||||||
|
|
||||||
# Overrides Redmine::Acts::Customizable::InstanceMethods#available_custom_fields
|
# Overrides Redmine::Acts::Customizable::InstanceMethods#available_custom_fields
|
||||||
|
|||||||
@ -44,10 +44,10 @@ class ActiveStorageMigration < ActiveRecord::Migration[7.0]
|
|||||||
.find_each
|
.find_each
|
||||||
.with_index do |r, i|
|
.with_index do |r, i|
|
||||||
if i.zero?
|
if i.zero?
|
||||||
r.file.attach(
|
r.shared_file.attach(
|
||||||
io: File.open(path),
|
io: File.open(path),
|
||||||
filename: r.name,
|
filename: r.name,
|
||||||
content_type: r.content_type,
|
content_type: r.content_type || 'application/octet-stream',
|
||||||
identify: false
|
identify: false
|
||||||
)
|
)
|
||||||
# Remove the original file
|
# Remove the original file
|
||||||
|
|||||||
@ -779,7 +779,7 @@ module RedmineDmsf
|
|||||||
r.custom_field_values << CustomValue.new({ custom_field: cf, value: cf.default_value })
|
r.custom_field_values << CustomValue.new({ custom_field: cf, value: cf.default_value })
|
||||||
end
|
end
|
||||||
if r.save(validate: false) # Skip validation due to invalid characters in the filename
|
if r.save(validate: false) # Skip validation due to invalid characters in the filename
|
||||||
r.file.attach(
|
r.shared_file.attach(
|
||||||
io: File.new(DmsfHelper.temp_filename(basename), File::CREAT),
|
io: File.new(DmsfHelper.temp_filename(basename), File::CREAT),
|
||||||
filename: basename,
|
filename: basename,
|
||||||
content_type: 'application/octet-stream',
|
content_type: 'application/octet-stream',
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user