Project

General

Profile

Feature #35462 » 35462-2.patch

Takenori TAKAKI, 2021-07-28 08:44

View differences:

app/controllers/attachments_controller.rb
rescue
nil
end
unless klass && klass.reflect_on_association(:attachments)
unless klass && (klass.reflect_on_association(:attachments) || klass.method_defined?(:attachments))
render_404
return
end
app/controllers/journals_controller.rb
helper :issues
helper :custom_fields
helper :queries
helper :attachments
include QueriesHelper
def index
app/helpers/application_helper.rb
# when using an image link, try to use an attachment, if possible
attachments = options[:attachments] || []
attachments += obj.attachments if obj.respond_to?(:attachments)
if obj.is_a?(Journal)
attachments += obj.journalized.attachments if obj.journalized.respond_to?(:attachments)
else
attachments += obj.attachments if obj.respond_to?(:attachments)
end
if attachments.present?
text.gsub!(/src="([^\/"]+\.(bmp|gif|jpg|jpe|jpeg|png))"(\s+alt="([^"]*)")?/i) do |m|
filename, ext, alt, alttext = $1, $2, $3, $4
app/models/journal.rb
end
def attachments
journalized.respond_to?(:attachments) ? journalized.attachments : []
details.select{ |d| d.property == 'attachment' }.map{ |d| Attachment.find_by(:id => d.prop_key) }.compact
end
# Returns a string of css classes
app/views/issues/tabs/_history.html.erb
</h4>
<% if journal.details.any? %>
<ul class="details">
<% details_to_strings(journal.visible_details).each do |string| %>
<li><%= string %></li>
<% end %>
</ul>
<div class="note-details">
<% if journal.attachments.size > 1 %>
<div class="contextual">
<%= link_to(l(:label_download_all_attachments),
container_attachments_download_path(journal),
:title => l(:label_download_all_attachments),
:class => 'icon-only icon-download') %>
</div>
<% end %>
<ul class="details">
<% details_to_strings(journal.visible_details).each do |string| %>
<li><%= string %></li>
<% end %>
</ul>
</div>
<% if Setting.thumbnails_enabled? && (thumbnail_attachments = journal_thumbnail_attachments(journal)).any? %>
<div class="thumbnails">
<% thumbnail_attachments.each do |attachment| %>
test/helpers/application_helper_test.rb
to_test.each {|text, result| assert_equal "<p>#{result}</p>", textilizable(text, :attachments => attachments)}
end
def test_attached_images_on_issue
issue = Issue.generate!
attachment_1 = Attachment.generate!(:file => mock_file_with_options(:original_filename => "attached_on_issue.png"), :container => issue)
journal = issue.init_journal(User.find(2), issue)
attachment_2 = Attachment.generate!(:file => mock_file_with_options(:original_filename => "attached_on_journal.png"), :container => issue)
journal.journalize_attachment(attachment_2, :added)
raw = <<~RAW
!attached_on_issue.png!
!attached_on_journal.png!
RAW
assert textilizable(raw, :object => journal).include?("<img src=\"/attachments/download/#{attachment_1.id}/attached_on_issue.png\" alt=\"\" />")
assert textilizable(raw, :object => journal).include?("<img src=\"/attachments/download/#{attachment_2.id}/attached_on_journal.png\" alt=\"\" />")
end
def test_attached_images_with_textile_and_non_ascii_filename
to_test = {
'CAFÉ.JPG' => 'CAF%C3%89.JPG',
test/unit/journal_test.rb
visible_details = journal.visible_details(User.find(2))
assert_equal 2, visible_details.size
end
def test_attachments
journal = Journal.new
2.times.map{ |i| Attachment.generate!(:file => mock_file_with_options(:original_filename => "image#{i}.png")) }.each do |attachment|
journal.details << JournalDetail.new(:property => 'attachment', :prop_key => attachment.id, :value => attachment.filename)
end
attachments = journal.attachments
assert_equal 2, attachments.size
attachments.each_with_index do |attachment, i|
assert_kind_of Attachment, attachment
assert_equal "image#{i}.png", attachment.filename
end
end
end
(5-5/5)