@@ -34,6 +34,7 module Redmine | |||||
34 | options.merge(:as => :container, :dependent => :destroy, :inverse_of => :container) |
|
34 | options.merge(:as => :container, :dependent => :destroy, :inverse_of => :container) | |
35 | send :include, Redmine::Acts::Attachable::InstanceMethods |
|
35 | send :include, Redmine::Acts::Attachable::InstanceMethods | |
36 | before_save :attach_saved_attachments |
|
36 | before_save :attach_saved_attachments | |
|
37 | validate :warn_about_failed_attachments | |||
37 | end |
|
38 | end | |
38 | end |
|
39 | end | |
39 |
|
40 | |||
@@ -82,6 +83,7 module Redmine | |||||
82 | attachments = attachments.map(&:last) |
|
83 | attachments = attachments.map(&:last) | |
83 | end |
|
84 | end | |
84 | if attachments.is_a?(Array) |
|
85 | if attachments.is_a?(Array) | |
|
86 | @failed_attachment_count = 0 | |||
85 | attachments.each do |attachment| |
|
87 | attachments.each do |attachment| | |
86 | next unless attachment.is_a?(Hash) |
|
88 | next unless attachment.is_a?(Hash) | |
87 | a = nil |
|
89 | a = nil | |
@@ -90,7 +92,10 module Redmine | |||||
90 | a = Attachment.create(:file => file, :author => author) |
|
92 | a = Attachment.create(:file => file, :author => author) | |
91 | elsif token = attachment['token'] |
|
93 | elsif token = attachment['token'] | |
92 | a = Attachment.find_by_token(token) |
|
94 | a = Attachment.find_by_token(token) | |
93 |
|
|
95 | unless a | |
|
96 | @failed_attachment_count += 1 | |||
|
97 | next | |||
|
98 | end | |||
94 | a.filename = attachment['filename'] unless attachment['filename'].blank? |
|
99 | a.filename = attachment['filename'] unless attachment['filename'].blank? | |
95 | a.content_type = attachment['content_type'] unless attachment['content_type'].blank? |
|
100 | a.content_type = attachment['content_type'] unless attachment['content_type'].blank? | |
96 | end |
|
101 | end | |
@@ -112,6 +117,12 module Redmine | |||||
112 | end |
|
117 | end | |
113 | end |
|
118 | end | |
114 |
|
119 | |||
|
120 | def warn_about_failed_attachments | |||
|
121 | if @failed_attachment_count && @failed_attachment_count > 0 | |||
|
122 | errors.add :base, ::I18n.t('warning_attachments_not_saved', count: @failed_attachment_count) | |||
|
123 | end | |||
|
124 | end | |||
|
125 | ||||
115 | module ClassMethods |
|
126 | module ClassMethods | |
116 | end |
|
127 | end | |
117 | end |
|
128 | end |
@@ -2527,6 +2527,17 class IssueTest < ActiveSupport::TestCase | |||||
2527 | assert_equal %w(upload foo bar), issue.attachments.map(&:filename) |
|
2527 | assert_equal %w(upload foo bar), issue.attachments.map(&:filename) | |
2528 | end |
|
2528 | end | |
2529 |
|
2529 | |||
|
2530 | def test_save_attachments_with_array_should_warn_about_missing_tokens | |||
|
2531 | set_tmp_attachments_directory | |||
|
2532 | issue = Issue.generate! | |||
|
2533 | issue.save_attachments([ | |||
|
2534 | {'token' => 'missing'} | |||
|
2535 | ]) | |||
|
2536 | assert !issue.save | |||
|
2537 | assert issue.errors[:base].present? | |||
|
2538 | assert_equal 0, issue.reload.attachments.count | |||
|
2539 | end | |||
|
2540 | ||||
2530 | def test_closed_on_should_be_nil_when_creating_an_open_issue |
|
2541 | def test_closed_on_should_be_nil_when_creating_an_open_issue | |
2531 | issue = Issue.generate!(:status_id => 1).reload |
|
2542 | issue = Issue.generate!(:status_id => 1).reload | |
2532 | assert !issue.closed? |
|
2543 | assert !issue.closed? |
General Comments 0
You need to be logged in to leave comments.
Login now