diff --git a/app/controllers/attachments_controller.rb b/app/controllers/attachments_controller.rb index 8e28194a30..4af060b40c 100644 --- a/app/controllers/attachments_controller.rb +++ b/app/controllers/attachments_controller.rb @@ -225,7 +225,7 @@ class AttachmentsController < ApplicationController 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 diff --git a/app/controllers/journals_controller.rb b/app/controllers/journals_controller.rb index 95f47e360b..c2674a4c42 100644 --- a/app/controllers/journals_controller.rb +++ b/app/controllers/journals_controller.rb @@ -28,6 +28,7 @@ class JournalsController < ApplicationController helper :issues helper :custom_fields helper :queries + helper :attachments include QueriesHelper def index diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 0db8954410..04852551fa 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -930,7 +930,11 @@ module ApplicationHelper # 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 diff --git a/app/models/journal.rb b/app/models/journal.rb index a608703d7f..f42394bc91 100644 --- a/app/models/journal.rb +++ b/app/models/journal.rb @@ -138,7 +138,7 @@ class Journal < ActiveRecord::Base 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 diff --git a/app/views/issues/tabs/_history.html.erb b/app/views/issues/tabs/_history.html.erb index 0769f57254..5c2e4e23f4 100644 --- a/app/views/issues/tabs/_history.html.erb +++ b/app/views/issues/tabs/_history.html.erb @@ -18,11 +18,21 @@ <% if journal.details.any? %> -
#{result}
", 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?("