diff options
author | Jean-Philippe Lang <jp_lang@yahoo.fr> | 2016-05-07 10:31:20 +0000 |
---|---|---|
committer | Jean-Philippe Lang <jp_lang@yahoo.fr> | 2016-05-07 10:31:20 +0000 |
commit | 40c9c3e922e15ab7d88b5d06c60e51ed1ba40a7f (patch) | |
tree | 0fe287037410c16fa9e4bc1743b4c00482c99bd4 /lib/plugins | |
parent | 3c45e433d5551a7bff114db8926f9a449aacc85d (diff) | |
download | redmine-40c9c3e922e15ab7d88b5d06c60e51ed1ba40a7f.tar.gz redmine-40c9c3e922e15ab7d88b5d06c60e51ed1ba40a7f.zip |
Notify the user of missing attachments (#22401).
under certain (rare) circumstances it may happen that, when an issue or other
container is saved, added attachments have already been removed (i.e. by the
attachments:prune rake task). This patch adds a validation error to the
container in this case.
Patch by Jens Kraemer.
git-svn-id: http://svn.redmine.org/redmine/trunk@15378 e93f8b46-1217-0410-a6f0-8f06a7374b81
Diffstat (limited to 'lib/plugins')
-rw-r--r-- | lib/plugins/acts_as_attachable/lib/acts_as_attachable.rb | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/lib/plugins/acts_as_attachable/lib/acts_as_attachable.rb b/lib/plugins/acts_as_attachable/lib/acts_as_attachable.rb index 31403d7dc..bc4242564 100644 --- a/lib/plugins/acts_as_attachable/lib/acts_as_attachable.rb +++ b/lib/plugins/acts_as_attachable/lib/acts_as_attachable.rb @@ -34,6 +34,7 @@ module Redmine options.merge(:as => :container, :dependent => :destroy, :inverse_of => :container) send :include, Redmine::Acts::Attachable::InstanceMethods before_save :attach_saved_attachments + validate :warn_about_failed_attachments end end @@ -82,6 +83,7 @@ module Redmine attachments = attachments.map(&:last) end if attachments.is_a?(Array) + @failed_attachment_count = 0 attachments.each do |attachment| next unless attachment.is_a?(Hash) a = nil @@ -90,7 +92,10 @@ module Redmine a = Attachment.create(:file => file, :author => author) elsif token = attachment['token'] a = Attachment.find_by_token(token) - next unless a + unless a + @failed_attachment_count += 1 + next + end a.filename = attachment['filename'] unless attachment['filename'].blank? a.content_type = attachment['content_type'] unless attachment['content_type'].blank? end @@ -112,6 +117,12 @@ module Redmine end end + def warn_about_failed_attachments + if @failed_attachment_count && @failed_attachment_count > 0 + errors.add :base, ::I18n.t('warning_attachments_not_saved', count: @failed_attachment_count) + end + end + module ClassMethods end end |