##// END OF EJS Templates
Fixes:...
Jean-Philippe Lang -
r1147:e5daf25618e0
parent child
Show More
@@ -178,16 +178,20 module ApplicationHelper
178 case args.size
178 case args.size
179 when 1
179 when 1
180 obj = nil
180 obj = nil
181 text = args.shift || ''
181 text = args.shift
182 when 2
182 when 2
183 obj = args.shift
183 obj = args.shift
184 text = obj.send(args.shift)
184 text = obj.send(args.shift).to_s
185 else
185 else
186 raise ArgumentError, 'invalid arguments to textilizable'
186 raise ArgumentError, 'invalid arguments to textilizable'
187 end
187 end
188 return '' if text.blank?
189
190 only_path = options.delete(:only_path) == false ? false : true
188
191
189 # when using an image link, try to use an attachment, if possible
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 if attachments
195 if attachments
192 text = text.gsub(/!((\<|\=|\>)?(\([^\)]+\))?(\[[^\]]+\])?(\{[^\}]+\})?)(\S+\.(gif|jpg|jpeg|png))!/) do |m|
196 text = text.gsub(/!((\<|\=|\>)?(\([^\)]+\))?(\[[^\]]+\])?(\{[^\}]+\})?)(\S+\.(gif|jpg|jpeg|png))!/) do |m|
193 style = $1
197 style = $1
@@ -195,7 +199,7 module ApplicationHelper
195 rf = Regexp.new(filename, Regexp::IGNORECASE)
199 rf = Regexp.new(filename, Regexp::IGNORECASE)
196 # search for the picture in attachments
200 # search for the picture in attachments
197 if found = attachments.detect { |att| att.filename =~ rf }
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 "!#{style}#{image_url}!"
203 "!#{style}#{image_url}!"
200 else
204 else
201 "!#{style}#{filename}!"
205 "!#{style}#{filename}!"
@@ -216,10 +220,10 module ApplicationHelper
216 # used for single-file wiki export
220 # used for single-file wiki export
217 format_wiki_link = Proc.new {|project, title| "##{title}" }
221 format_wiki_link = Proc.new {|project, title| "##{title}" }
218 else
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 end
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 # Wiki links
228 # Wiki links
225 #
229 #
@@ -278,7 +282,8 module ApplicationHelper
278 if esc.nil?
282 if esc.nil?
279 if prefix.nil? && sep == 'r'
283 if prefix.nil? && sep == 'r'
280 if project && (changeset = project.changesets.find_by_revision(oid))
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 :title => truncate(changeset.comments, 100))
287 :title => truncate(changeset.comments, 100))
283 end
288 end
284 elsif sep == '#'
289 elsif sep == '#'
@@ -286,17 +291,20 module ApplicationHelper
286 case prefix
291 case prefix
287 when nil
292 when nil
288 if issue = Issue.find_by_id(oid, :include => [:project, :status], :conditions => Project.visible_by(User.current))
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 :title => "#{truncate(issue.subject, 100)} (#{issue.status.name})")
296 :title => "#{truncate(issue.subject, 100)} (#{issue.status.name})")
291 link = content_tag('del', link) if issue.closed?
297 link = content_tag('del', link) if issue.closed?
292 end
298 end
293 when 'document'
299 when 'document'
294 if document = Document.find_by_id(oid, :include => [:project], :conditions => Project.visible_by(User.current))
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 end
303 end
297 when 'version'
304 when 'version'
298 if version = Version.find_by_id(oid, :include => [:project], :conditions => Project.visible_by(User.current))
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 end
308 end
301 end
309 end
302 elsif sep == ':'
310 elsif sep == ':'
@@ -305,15 +313,18 module ApplicationHelper
305 case prefix
313 case prefix
306 when 'document'
314 when 'document'
307 if project && document = project.documents.find_by_title(name)
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 end
318 end
310 when 'version'
319 when 'version'
311 if project && version = project.versions.find_by_name(name)
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 end
323 end
314 when 'attachment'
324 when 'attachment'
315 if attachments && attachment = attachments.detect {|a| a.filename == name }
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 end
328 end
318 end
329 end
319 end
330 end
@@ -51,7 +51,14 class Journal < ActiveRecord::Base
51 end
51 end
52
52
53 def editable_by?(usr)
53 def editable_by?(usr)
54 project = journalized.project
55 usr && usr.logged? && (usr.allowed_to?(:edit_issue_notes, project) || (self.user == usr && usr.allowed_to?(:edit_own_issue_notes, project)))
54 usr && usr.logged? && (usr.allowed_to?(:edit_issue_notes, project) || (self.user == usr && usr.allowed_to?(:edit_own_issue_notes, project)))
56 end
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 end
64 end
@@ -12,4 +12,4
12 <% end %>
12 <% end %>
13 </ul>
13 </ul>
14
14
15 <%= textilizable(issue.description) %>
15 <%= textilizable(issue, :description, :only_path => false) %>
@@ -1,3 +1,3
1 <%= link_to @document.title, @document_url %> (<%= @document.category.name %>)<br />
1 <%= link_to @document.title, @document_url %> (<%= @document.category.name %>)<br />
2 <br />
2 <br />
3 <%= textilizable(@document.description) %>
3 <%= textilizable(@document, :description, :only_path => false) %>
@@ -6,6 +6,6
6 <% end %>
6 <% end %>
7 </ul>
7 </ul>
8
8
9 <%= textilizable(@journal.notes) %>
9 <%= textilizable(@journal, :notes, :only_path => false) %>
10 <hr />
10 <hr />
11 <%= render :partial => "issue_text_html", :locals => { :issue => @issue, :issue_url => @issue_url } %>
11 <%= render :partial => "issue_text_html", :locals => { :issue => @issue, :issue_url => @issue_url } %>
@@ -1,4 +1,4
1 <h1><%=h @message.board.project.name %> - <%=h @message.board.name %>: <%= link_to @message.subject, @message_url %></h1>
1 <h1><%=h @message.board.project.name %> - <%=h @message.board.name %>: <%= link_to @message.subject, @message_url %></h1>
2 <em><%= @message.author %></em>
2 <em><%= @message.author %></em>
3
3
4 <%= textilizable @message.content %>
4 <%= textilizable(@message, :content, :only_path => false) %>
@@ -1,4 +1,4
1 <h1><%= link_to @news.title, @news_url %></h1>
1 <h1><%= link_to @news.title, @news_url %></h1>
2 <em><%= @news.author.name %></em>
2 <em><%= @news.author.name %></em>
3
3
4 <%= textilizable(@news.description) %>
4 <%= textilizable(@news, :description, :only_path => false) %>
@@ -8,7 +8,7 journals_001:
8 journalized_id: 1
8 journalized_id: 1
9 journals_002:
9 journals_002:
10 created_on: <%= 1.days.ago.to_date.to_s(:db) %>
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 id: 2
12 id: 2
13 journalized_type: Issue
13 journalized_type: Issue
14 user_id: 2
14 user_id: 2
@@ -18,7 +18,26
18 require File.dirname(__FILE__) + '/../test_helper'
18 require File.dirname(__FILE__) + '/../test_helper'
19
19
20 class MailerTest < Test::Unit::TestCase
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
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
22
41
23 # test mailer methods for each language
42 # test mailer methods for each language
24 def test_issue_add
43 def test_issue_add
General Comments 0
You need to be logged in to leave comments. Login now