Moving Issue to other project does not move attached documents in DMS #812

This commit is contained in:
Karel Picman 2018-01-04 14:45:17 +01:00
parent 150b28f724
commit c39d8dce4a
2 changed files with 37 additions and 7 deletions

View File

@ -49,7 +49,7 @@ module RedmineDmsf
end
def controller_issues_edit_after_save(context={})
controller_issues_after_save(context)
controller_issues_after_save(context, true)
end
private
@ -58,7 +58,9 @@ module RedmineDmsf
if context.is_a?(Hash)
issue = context[:issue]
params = context[:params]
# Save upload preferences DMS/Attachments
User.current.pref.update_attribute :dmsf_attachments_upload_choice, params[:dmsf_attachments_upload_choice]
# Save attachments
issue.save_dmsf_attachments(params[:dmsf_attachments])
issue.save_dmsf_links(params[:dmsf_links])
issue.save_dmsf_attachments_wfs(params[:dmsf_attachments_wfs], params[:dmsf_attachments])
@ -66,10 +68,37 @@ module RedmineDmsf
end
end
def controller_issues_after_save(context)
def controller_issues_after_save(context, edit = false)
if context.is_a?(Hash)
issue = context[:issue]
params = context[:params]
# Move existing attached documents if needed
if edit
project_id = params[:issue][:project_id].to_i
old_project_id = context[:project].id
system_folder = issue.system_folder(false, old_project_id)
if system_folder
# Change the title if the issue's subject changed
system_folder.title = "#{issue.id} - #{issue.subject}"
# Move system folders if needed
if system_folder.dmsf_folder
system_folder.dmsf_folder.project_id = project_id
system_folder.dmsf_folder.save!
end
system_folder.project_id = project_id
system_folder.save!
# Move documents
issue.dmsf_files.each do |dmsf_file|
dmsf_file.project_id = project_id
dmsf_file.save!
end
# Move links
issue.dmsf_links.each do | dmsf_link|
dmsf_link.project_id = project_id
dmsf_link.save!
end
end
end
# Attach DMS documents
uploaded_files = params[:dmsf_attachments]
if uploaded_files && uploaded_files.is_a?(Hash)

View File

@ -94,11 +94,12 @@ module RedmineDmsf
@saved_dmsf_links_wfs || {}
end
def system_folder(create = false)
parent = DmsfFolder.system.where(:project_id => self.project_id, :title => '.Issues').first
def system_folder(create = false, prj_id = nil)
prj_id ||= self.project_id
parent = DmsfFolder.system.where(:project_id => prj_id, :title => '.Issues').first
if create && !parent
parent = DmsfFolder.new
parent.project_id = self.project_id
parent.project_id = prj_id
parent.title = '.Issues'
parent.description = 'Documents assigned to issues'
parent.user_id = User.anonymous.id
@ -107,11 +108,11 @@ module RedmineDmsf
end
if parent
folder = DmsfFolder.system.where(["project_id = ? AND dmsf_folder_id = ? AND title LIKE '? - %'",
self.project_id, parent.id, self.id]).first
prj_id, parent.id, self.id]).first
if create && !folder
folder = DmsfFolder.new
folder.dmsf_folder_id = parent.id
folder.project_id = self.project_id
folder.project_id = prj_id
folder.title = "#{self.id} - #{self.subject}"
folder.user_id = User.anonymous.id
folder.system = true