Feature #35462 » 35462.patch
| app/controllers/attachments_controller.rb | ||
|---|---|---|
| 225 | 225 |
rescue |
| 226 | 226 |
nil |
| 227 | 227 |
end |
| 228 |
unless klass && klass.reflect_on_association(:attachments)
|
|
| 228 |
unless klass && (klass.reflect_on_association(:attachments) || klass.method_defined?(:attachments))
|
|
| 229 | 229 |
render_404 |
| 230 | 230 |
return |
| 231 | 231 |
end |
| app/controllers/journals_controller.rb | ||
|---|---|---|
| 28 | 28 |
helper :issues |
| 29 | 29 |
helper :custom_fields |
| 30 | 30 |
helper :queries |
| 31 |
helper :attachments |
|
| 31 | 32 |
include QueriesHelper |
| 32 | 33 | |
| 33 | 34 |
def index |
| app/helpers/application_helper.rb | ||
|---|---|---|
| 918 | 918 | |
| 919 | 919 |
# when using an image link, try to use an attachment, if possible |
| 920 | 920 |
attachments = options[:attachments] || [] |
| 921 |
attachments += obj.attachments if obj.respond_to?(:attachments) |
|
| 921 |
if obj.is_a?(Journal) |
|
| 922 |
attachments += obj.journalized.attachments if obj.journalized.respond_to?(:attachments) |
|
| 923 |
else |
|
| 924 |
attachments += obj.attachments if obj.respond_to?(:attachments) |
|
| 925 |
end |
|
| 922 | 926 |
if attachments.present? |
| 923 | 927 |
text.gsub!(/src="([^\/"]+\.(bmp|gif|jpg|jpe|jpeg|png))"(\s+alt="([^"]*)")?/i) do |m| |
| 924 | 928 |
filename, ext, alt, alttext = $1, $2, $3, $4 |
| app/helpers/journals_helper.rb | ||
|---|---|---|
| 32 | 32 |
indice = journal.indice || @journal.issue.visible_journals_with_index.find{|j| j.id == @journal.id}.indice
|
| 33 | 33 | |
| 34 | 34 |
dropbown_links << copy_object_url_link(issue_url(issue, anchor: "note-#{indice}", only_path: false))
|
| 35 |
if journal.attachments.size > 1 |
|
| 36 |
dropbown_links << link_to(l(:label_download_all_attachments), |
|
| 37 |
container_attachments_download_path(journal), |
|
| 38 |
:title => l(:label_download_all_attachments), |
|
| 39 |
:class => 'icon icon-download' |
|
| 40 |
) |
|
| 41 |
end |
|
| 42 | ||
| 35 | 43 |
if journal.notes.present? |
| 36 | 44 |
if options[:reply_links] |
| 37 | 45 |
links << link_to(l(:button_quote), |
| app/models/journal.rb | ||
|---|---|---|
| 138 | 138 |
end |
| 139 | 139 | |
| 140 | 140 |
def attachments |
| 141 |
journalized.respond_to?(:attachments) ? journalized.attachments : []
|
|
| 141 |
details.select{ |d| d.property == 'attachment' }.map{ |d| Attachment.find_by(:id => d.prop_key) }.compact
|
|
| 142 | 142 |
end |
| 143 | 143 | |
| 144 | 144 |
# Returns a string of css classes |
| test/helpers/application_helper_test.rb | ||
|---|---|---|
| 182 | 182 |
to_test.each {|text, result| assert_equal "<p>#{result}</p>", textilizable(text, :attachments => attachments)}
|
| 183 | 183 |
end |
| 184 | 184 | |
| 185 |
def test_attached_images_on_issue |
|
| 186 |
issue = Issue.generate! |
|
| 187 |
attachment_1 = Attachment.generate!(:file => mock_file_with_options(:original_filename => "attached_on_issue.png"), :container => issue) |
|
| 188 |
journal = issue.init_journal(User.find(2), issue) |
|
| 189 |
attachment_2 = Attachment.generate!(:file => mock_file_with_options(:original_filename => "attached_on_journal.png"), :container => issue) |
|
| 190 |
journal.journalize_attachment(attachment_2, :added) |
|
| 191 | ||
| 192 |
raw = <<~RAW |
|
| 193 |
!attached_on_issue.png! |
|
| 194 |
!attached_on_journal.png!' |
|
| 195 |
RAW |
|
| 196 | ||
| 197 |
assert textilizable(raw, :object => journal).include?("<img src=\"/attachments/download/#{attachment_1.id}/attached_on_issue.png\" alt=\"\" />")
|
|
| 198 |
assert textilizable(raw, :object => journal).include?("<img src=\"/attachments/download/#{attachment_2.id}/attached_on_journal.png\" alt=\"\" />")
|
|
| 199 |
end |
|
| 200 | ||
| 185 | 201 |
def test_attached_images_with_textile_and_non_ascii_filename |
| 186 | 202 |
to_test = {
|
| 187 | 203 |
'CAFÉ.JPG' => 'CAF%C3%89.JPG', |
| test/unit/journal_test.rb | ||
|---|---|---|
| 222 | 222 |
visible_details = journal.visible_details(User.find(2)) |
| 223 | 223 |
assert_equal 2, visible_details.size |
| 224 | 224 |
end |
| 225 | ||
| 226 |
def test_attachments |
|
| 227 |
journal = Journal.new |
|
| 228 |
2.times.map{ |i| Attachment.generate!(:file => mock_file_with_options(:original_filename => "image#{i}.png")) }.each do |attachment|
|
|
| 229 |
journal.details << JournalDetail.new(:property => 'attachment', :prop_key => attachment.id, :value => attachment.filename) |
|
| 230 |
end |
|
| 231 | ||
| 232 |
attachments = journal.attachments |
|
| 233 |
assert_equal 2, attachments.size |
|
| 234 |
attachments.each_with_index do |attachment, i| |
|
| 235 |
assert_kind_of Attachment, attachment |
|
| 236 |
assert_equal "image#{i}.png", attachment.filename
|
|
| 237 |
end |
|
| 238 |
end |
|
| 225 | 239 |
end |