Project

General

Profile

« Previous | Next » 

Revision 1161

Fixes:
  • email notifications: host name is missing in generated links (#639, #201)
  • email notifications: referenced changesets, wiki pages, attachments... are not turned into links (only ticket ids are)
  • attachment links and inline images don't work in issue notes

View differences:

trunk/app/helpers/application_helper.rb
178 178
    case args.size
179 179
    when 1
180 180
      obj = nil
181
      text = args.shift || ''
181
      text = args.shift
182 182
    when 2
183 183
      obj = args.shift
184
      text = obj.send(args.shift)
184
      text = obj.send(args.shift).to_s
185 185
    else
186 186
      raise ArgumentError, 'invalid arguments to textilizable'
187 187
    end
188
    return '' if text.blank?
189
    
190
    only_path = options.delete(:only_path) == false ? false : true
188 191

  
189 192
    # when using an image link, try to use an attachment, if possible
190
    attachments = options[:attachments]
193
    attachments = options[:attachments] || (obj && obj.respond_to?(:attachments) ? obj.attachments : nil)
194
    
191 195
    if attachments
192 196
      text = text.gsub(/!((\<|\=|\>)?(\([^\)]+\))?(\[[^\]]+\])?(\{[^\}]+\})?)(\S+\.(gif|jpg|jpeg|png))!/) do |m|
193 197
        style = $1
......
195 199
        rf = Regexp.new(filename,  Regexp::IGNORECASE)
196 200
        # search for the picture in attachments
197 201
        if found = attachments.detect { |att| att.filename =~ rf }
198
          image_url = url_for :controller => 'attachments', :action => 'download', :id => found.id
202
          image_url = url_for :only_path => only_path, :controller => 'attachments', :action => 'download', :id => found.id
199 203
          "!#{style}#{image_url}!"
200 204
        else
201 205
          "!#{style}#{filename}!"
......
216 220
      # used for single-file wiki export
217 221
      format_wiki_link = Proc.new {|project, title| "##{title}" }
218 222
    else
219
      format_wiki_link = Proc.new {|project, title| url_for :controller => 'wiki', :action => 'index', :id => project, :page => title }
223
      format_wiki_link = Proc.new {|project, title| url_for(:only_path => only_path, :controller => 'wiki', :action => 'index', :id => project, :page => title) }
220 224
    end
221 225
    
222
    project = options[:project] || @project
226
    project = options[:project] || @project || (obj && obj.respond_to?(:project) ? obj.project : nil)
223 227
    
224 228
    # Wiki links
225 229
    # 
......
278 282
      if esc.nil?
279 283
        if prefix.nil? && sep == 'r'
280 284
          if project && (changeset = project.changesets.find_by_revision(oid))
281
            link = link_to("r#{oid}", {:controller => 'repositories', :action => 'revision', :id => project.id, :rev => oid}, :class => 'changeset',
285
            link = link_to("r#{oid}", {:only_path => only_path, :controller => 'repositories', :action => 'revision', :id => project.id, :rev => oid},
286
                                      :class => 'changeset',
282 287
                                      :title => truncate(changeset.comments, 100))
283 288
          end
284 289
        elsif sep == '#'
......
286 291
          case prefix
287 292
          when nil
288 293
            if issue = Issue.find_by_id(oid, :include => [:project, :status], :conditions => Project.visible_by(User.current))        
289
              link = link_to("##{oid}", {:controller => 'issues', :action => 'show', :id => oid}, :class => 'issue',
294
              link = link_to("##{oid}", {:only_path => only_path, :controller => 'issues', :action => 'show', :id => oid},
295
                                        :class => 'issue',
290 296
                                        :title => "#{truncate(issue.subject, 100)} (#{issue.status.name})")
291 297
              link = content_tag('del', link) if issue.closed?
292 298
            end
293 299
          when 'document'
294 300
            if document = Document.find_by_id(oid, :include => [:project], :conditions => Project.visible_by(User.current))
295
              link = link_to h(document.title), {:controller => 'documents', :action => 'show', :id => document}, :class => 'document'
301
              link = link_to h(document.title), {:only_path => only_path, :controller => 'documents', :action => 'show', :id => document},
302
                                                :class => 'document'
296 303
            end
297 304
          when 'version'
298 305
            if version = Version.find_by_id(oid, :include => [:project], :conditions => Project.visible_by(User.current))
299
              link = link_to h(version.name), {:controller => 'versions', :action => 'show', :id => version}, :class => 'version'
306
              link = link_to h(version.name), {:only_path => only_path, :controller => 'versions', :action => 'show', :id => version},
307
                                              :class => 'version'
300 308
            end
301 309
          end
302 310
        elsif sep == ':'
......
305 313
          case prefix
306 314
          when 'document'
307 315
            if project && document = project.documents.find_by_title(name)
308
              link = link_to h(document.title), {:controller => 'documents', :action => 'show', :id => document}, :class => 'document'
316
              link = link_to h(document.title), {:only_path => only_path, :controller => 'documents', :action => 'show', :id => document},
317
                                                :class => 'document'
309 318
            end
310 319
          when 'version'
311 320
            if project && version = project.versions.find_by_name(name)
312
              link = link_to h(version.name), {:controller => 'versions', :action => 'show', :id => version}, :class => 'version'
321
              link = link_to h(version.name), {:only_path => only_path, :controller => 'versions', :action => 'show', :id => version},
322
                                              :class => 'version'
313 323
            end
314 324
          when 'attachment'
315 325
            if attachments && attachment = attachments.detect {|a| a.filename == name }
316
              link = link_to h(attachment.filename), {:controller => 'attachments', :action => 'download', :id => attachment}, :class => 'attachment'
326
              link = link_to h(attachment.filename), {:only_path => only_path, :controller => 'attachments', :action => 'download', :id => attachment},
327
                                                     :class => 'attachment'
317 328
            end
318 329
          end
319 330
        end
trunk/app/models/journal.rb
51 51
  end
52 52
  
53 53
  def editable_by?(usr)
54
    project = journalized.project
55 54
    usr && usr.logged? && (usr.allowed_to?(:edit_issue_notes, project) || (self.user == usr && usr.allowed_to?(:edit_own_issue_notes, project)))
56 55
  end
56
  
57
  def project
58
    journalized.respond_to?(:project) ? journalized.project : nil
59
  end
60
  
61
  def attachments
62
    journalized.respond_to?(:attachments) ? journalized.attachments : nil
63
  end
57 64
end
trunk/app/views/mailer/_issue_text_html.rhtml
12 12
<% end %>
13 13
</ul>
14 14

  
15
<%= textilizable(issue.description) %>
15
<%= textilizable(issue, :description, :only_path => false) %>
trunk/app/views/mailer/document_added.text.html.rhtml
1 1
<%= link_to @document.title, @document_url %> (<%= @document.category.name %>)<br />
2 2
<br />
3
<%= textilizable(@document.description) %>
3
<%= textilizable(@document, :description, :only_path => false) %>
trunk/app/views/mailer/issue_edit.text.html.rhtml
6 6
<% end %>
7 7
</ul>
8 8

  
9
<%= textilizable(@journal.notes) %>
9
<%= textilizable(@journal, :notes, :only_path => false) %>
10 10
<hr />
11 11
<%= render :partial => "issue_text_html", :locals => { :issue => @issue, :issue_url => @issue_url } %>
trunk/app/views/mailer/message_posted.text.html.rhtml
1 1
<h1><%=h @message.board.project.name %> - <%=h @message.board.name %>: <%= link_to @message.subject, @message_url %></h1>
2 2
<em><%= @message.author %></em>
3 3

  
4
<%= textilizable @message.content %>
4
<%= textilizable(@message, :content, :only_path => false) %>
trunk/app/views/mailer/news_added.text.html.rhtml
1 1
<h1><%= link_to @news.title, @news_url %></h1>
2 2
<em><%= @news.author.name %></em>
3 3

  
4
<%= textilizable(@news.description) %>
4
<%= textilizable(@news, :description, :only_path => false) %>
trunk/test/fixtures/journals.yml
8 8
  journalized_id: 1
9 9
journals_002: 
10 10
  created_on: <%= 1.days.ago.to_date.to_s(:db) %>
11
  notes: "Some notes"
11
  notes: "Some notes with Redmine links: #2, r2."
12 12
  id: 2
13 13
  journalized_type: Issue
14 14
  user_id: 2
trunk/test/unit/mailer_test.rb
18 18
require File.dirname(__FILE__) + '/../test_helper'
19 19

  
20 20
class MailerTest < Test::Unit::TestCase
21
  fixtures :projects, :issues, :users, :members, :documents, :attachments, :news, :tokens, :journals, :journal_details, :trackers, :issue_statuses, :enumerations
21
  fixtures :projects, :issues, :users, :members, :documents, :attachments, :news, :tokens, :journals, :journal_details, :changesets, :trackers, :issue_statuses, :enumerations
22 22
  
23
  def test_generated_links_in_emails
24
    ActionMailer::Base.deliveries.clear
25
    Setting.host_name = 'mydomain.foo'
26
    Setting.protocol = 'https'
27
    
28
    journal = Journal.find(2)
29
    assert Mailer.deliver_issue_edit(journal)
30
    
31
    mail = ActionMailer::Base.deliveries.last
32
    assert_kind_of TMail::Mail, mail
33
    # link to the main ticket
34
    assert mail.body.include?('<a href="https://mydomain.foo/issues/show/1">Bug #1: Can\'t print recipes</a>')
35
    
36
    # link to a referenced ticket
37
    assert mail.body.include?('<a href="https://mydomain.foo/issues/show/2" class="issue" title="Add ingredients categories (Assigned)">#2</a>')
38
    # link to a changeset
39
    assert mail.body.include?('<a href="https://mydomain.foo/repositories/revision/1?rev=2" class="changeset" title="This commit fixes #1, #2 and references #1 &amp; #3">r2</a>')
40
  end
41
  
23 42
  # test mailer methods for each language
24 43
  def test_issue_add
25 44
    issue = Issue.find(1)

Also available in: Unified diff