summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJean-Philippe Lang <jp_lang@yahoo.fr>2008-08-10 22:18:23 +0000
committerJean-Philippe Lang <jp_lang@yahoo.fr>2008-08-10 22:18:23 +0000
commit16509203398f17fafca33136375263aec64b2a0f (patch)
tree7a6aa963c847072ac526142f3ad9150ff9f66dda
parentab4873b83d6f62fa78fdf07da4de2f2f7e0d738d (diff)
downloadredmine-16509203398f17fafca33136375263aec64b2a0f.tar.gz
redmine-16509203398f17fafca33136375263aec64b2a0f.zip
Adds links to forum messages using message#id syntax (#1756).
git-svn-id: http://redmine.rubyforge.org/svn/trunk@1729 e93f8b46-1217-0410-a6f0-8f06a7374b81
-rw-r--r--app/helpers/application_helper.rb14
-rw-r--r--test/unit/helpers/application_helper_test.rb11
2 files changed, 23 insertions, 2 deletions
diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb
index a4102c84a..ed5c6bdb7 100644
--- a/app/helpers/application_helper.rb
+++ b/app/helpers/application_helper.rb
@@ -319,7 +319,9 @@ module ApplicationHelper
# source:some/file#L120 -> Link to line 120 of the file
# source:some/file@52#L120 -> Link to line 120 of the file's revision 52
# export:some/file -> Force the download of the file
- text = text.gsub(%r{([\s\(,\-\>]|^)(!)?(attachment|document|version|commit|source|export)?((#|r)(\d+)|(:)([^"\s<>][^\s<>]*?|"[^"]+?"))(?=(?=[[:punct:]]\W)|\s|<|$)}) do |m|
+ # Forum messages:
+ # message#1218 -> Link to message with id 1218
+ text = text.gsub(%r{([\s\(,\-\>]|^)(!)?(attachment|document|version|commit|source|export|message)?((#|r)(\d+)|(:)([^"\s<>][^\s<>]*?|"[^"]+?"))(?=(?=[[:punct:]]\W)|\s|<|$)}) do |m|
leading, esc, prefix, sep, oid = $1, $2, $3, $5 || $7, $6 || $8
link = nil
if esc.nil?
@@ -349,6 +351,16 @@ module ApplicationHelper
link = link_to h(version.name), {:only_path => only_path, :controller => 'versions', :action => 'show', :id => version},
:class => 'version'
end
+ when 'message'
+ if message = Message.find_by_id(oid, :include => [:parent, {:board => :project}], :conditions => Project.visible_by(User.current))
+ link = link_to h(truncate(message.subject, 60)), {:only_path => only_path,
+ :controller => 'messages',
+ :action => 'show',
+ :board_id => message.board,
+ :id => message.root,
+ :anchor => (message.parent ? "message-#{message.id}" : nil)},
+ :class => 'message'
+ end
end
elsif sep == ':'
# removes the double quotes if any
diff --git a/test/unit/helpers/application_helper_test.rb b/test/unit/helpers/application_helper_test.rb
index 979321bd3..452c0b535 100644
--- a/test/unit/helpers/application_helper_test.rb
+++ b/test/unit/helpers/application_helper_test.rb
@@ -20,7 +20,11 @@ require File.dirname(__FILE__) + '/../../test_helper'
class ApplicationHelperTest < HelperTestCase
include ApplicationHelper
include ActionView::Helpers::TextHelper
- fixtures :projects, :repositories, :changesets, :trackers, :issue_statuses, :issues, :documents, :versions, :wikis, :wiki_pages, :wiki_contents, :roles, :enabled_modules
+ fixtures :projects, :roles, :enabled_modules,
+ :repositories, :changesets,
+ :trackers, :issue_statuses, :issues, :versions, :documents,
+ :wikis, :wiki_pages, :wiki_contents,
+ :boards, :messages
def setup
super
@@ -83,6 +87,8 @@ class ApplicationHelperTest < HelperTestCase
version_link = link_to('1.0', {:controller => 'versions', :action => 'show', :id => 2},
:class => 'version')
+ message_url = {:controller => 'messages', :action => 'show', :board_id => 1, :id => 4}
+
source_url = {:controller => 'repositories', :action => 'entry', :id => 'ecookbook', :path => ['some', 'file']}
source_url_with_ext = {:controller => 'repositories', :action => 'entry', :id => 'ecookbook', :path => ['some', 'file.ext']}
@@ -111,6 +117,9 @@ class ApplicationHelperTest < HelperTestCase
'source:/some/file.ext#L110' => link_to('source:/some/file.ext#L110', source_url_with_ext.merge(:anchor => 'L110'), :class => 'source'),
'source:/some/file@52#L110' => link_to('source:/some/file@52#L110', source_url.merge(:rev => 52, :anchor => 'L110'), :class => 'source'),
'export:/some/file' => link_to('export:/some/file', source_url.merge(:format => 'raw'), :class => 'source download'),
+ # message
+ 'message#4' => link_to('Post 2', message_url, :class => 'message'),
+ 'message#5' => link_to('RE: post 2', message_url.merge(:anchor => 'message-5'), :class => 'message'),
# escaping
'!#3.' => '#3.',
'!r1' => 'r1',