From 92d0cf90ae84bc1f6015e9c01ca80ef070b00d04 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karel=20Pi=C4=8Dman?= Date: Wed, 8 Jun 2022 16:28:44 +0200 Subject: [PATCH] No journal when delete / de-attach document #1365 --- app/controllers/dmsf_files_controller.rb | 7 ++++++- app/helpers/dmsf_upload_helper.rb | 2 +- app/models/dmsf_file.rb | 12 +++++++++++- 3 files changed, 18 insertions(+), 3 deletions(-) diff --git a/app/controllers/dmsf_files_controller.rb b/app/controllers/dmsf_files_controller.rb index a5d0bf0e..621dc691 100644 --- a/app/controllers/dmsf_files_controller.rb +++ b/app/controllers/dmsf_files_controller.rb @@ -207,7 +207,12 @@ class DmsfFilesController < ApplicationController result = @file.delete(commit) if result flash[:notice] = l(:notice_file_deleted) - unless commit + if commit + container = @file.container + if container + container.dmsf_file_removed @file + end + else begin recipients = DmsfMailer.deliver_files_deleted(@project, [@file]) if Setting.plugin_redmine_dmsf['dmsf_display_notified_recipients'] diff --git a/app/helpers/dmsf_upload_helper.rb b/app/helpers/dmsf_upload_helper.rb index 08b012f4..fcc2c037 100644 --- a/app/helpers/dmsf_upload_helper.rb +++ b/app/helpers/dmsf_upload_helper.rb @@ -94,7 +94,7 @@ module DmsfUploadHelper FileUtils.chmod 'u=wr,g=r', new_revision.disk_file(false) file.set_last_revision new_revision files.push file - if container && container.is_a?(Issue) && (!new_object) + if container && (!new_object) container.dmsf_file_added file end Redmine::Hook.call_hook :dmsf_helper_upload_after_commit, { file: file } diff --git a/app/models/dmsf_file.rb b/app/models/dmsf_file.rb index 28ff9a8b..5c35a1ac 100644 --- a/app/models/dmsf_file.rb +++ b/app/models/dmsf_file.rb @@ -606,7 +606,7 @@ class DmsfFile < ActiveRecord::Base target = File.join(Attachment.thumbnails_storage_path, "#{id}_#{last_revision.digest}_#{size}.thumb") begin - Redmine::Thumbnail.generate(last_revision.disk_file.to_s, target, size) + Redmine::Thumbnail.generate last_revision.disk_file.to_s, target, size rescue => e Rails.logger.error "An error occured while generating thumbnail for #{last_revision.disk_file} to #{target}\nException was: #{e.message}" nil @@ -625,4 +625,14 @@ class DmsfFile < ActiveRecord::Base l(:title_unlock_file) end + def container + if dmsf_folder&.system && dmsf_folder.title.match(/(^\d+)/) + issue_id = $1 + parent = dmsf_folder.dmsf_folder + if parent && parent.title.match(/^\.(.+)s/) + $1.constantize.visible.find_by(id: issue_id) + end + end + end + end