##// END OF EJS Templates
Wiki links for news and forums (#9600)....
Jean-Philippe Lang -
r7720:9ac86d4f4e73
parent child
Show More
@@ -639,7 +639,7 module ApplicationHelper
639 639 # identifier:version:1.0.0
640 640 # identifier:source:some/file
641 641 def parse_redmine_links(text, project, obj, attr, only_path, options)
642 text.gsub!(%r{([\s\(,\-\[\>]|^)(!)?(([a-z0-9\-]+):)?(attachment|document|version|commit|source|export|message|project)?((#|r)(\d+)|(:)([^"\s<>][^\s<>]*?|"[^"]+?"))(?=(?=[[:punct:]]\W)|,|\s|\]|<|$)}) do |m|
642 text.gsub!(%r{([\s\(,\-\[\>]|^)(!)?(([a-z0-9\-]+):)?(attachment|document|version|forum|news|commit|source|export|message|project)?((#|r)(\d+)|(:)([^"\s<>][^\s<>]*?|"[^"]+?"))(?=(?=[[:punct:]]\W)|,|\s|\]|<|$)}) do |m|
643 643 leading, esc, project_prefix, project_identifier, prefix, sep, identifier = $1, $2, $3, $4, $5, $7 || $9, $8 || $10
644 644 link = nil
645 645 if project_identifier
@@ -676,6 +676,16 module ApplicationHelper
676 676 if message = Message.visible.find_by_id(oid, :include => :parent)
677 677 link = link_to_message(message, {:only_path => only_path}, :class => 'message')
678 678 end
679 when 'forum'
680 if board = Board.visible.find_by_id(oid)
681 link = link_to h(board.name), {:only_path => only_path, :controller => 'boards', :action => 'show', :id => board, :project_id => board.project},
682 :class => 'board'
683 end
684 when 'news'
685 if news = News.visible.find_by_id(oid)
686 link = link_to h(news.title), {:only_path => only_path, :controller => 'news', :action => 'show', :id => news},
687 :class => 'news'
688 end
679 689 when 'project'
680 690 if p = Project.visible.find_by_id(oid)
681 691 link = link_to_project(p, {:only_path => only_path}, :class => 'project')
@@ -695,6 +705,16 module ApplicationHelper
695 705 link = link_to h(version.name), {:only_path => only_path, :controller => 'versions', :action => 'show', :id => version},
696 706 :class => 'version'
697 707 end
708 when 'forum'
709 if project && board = project.boards.visible.find_by_name(name)
710 link = link_to h(board.name), {:only_path => only_path, :controller => 'boards', :action => 'show', :id => board, :project_id => board.project},
711 :class => 'board'
712 end
713 when 'news'
714 if project && news = project.news.visible.find_by_title(name)
715 link = link_to h(news.title), {:only_path => only_path, :controller => 'news', :action => 'show', :id => news},
716 :class => 'news'
717 end
698 718 when 'commit'
699 719 if project && project.repository && (changeset = Changeset.visible.find(:first, :conditions => ["repository_id = ? AND scmid LIKE ?", project.repository.id, "#{name}%"]))
700 720 link = link_to h("#{project_prefix}#{name}"), {:only_path => only_path, :controller => 'repositories', :action => 'revision', :id => project, :rev => changeset.identifier},
@@ -27,6 +27,9 class Board < ActiveRecord::Base
27 27 validates_length_of :name, :maximum => 30
28 28 validates_length_of :description, :maximum => 255
29 29
30 named_scope :visible, lambda {|*args| { :include => :project,
31 :conditions => Project.allowed_to_condition(args.shift || User.current, :view_messages, *args) } }
32
30 33 def visible?(user=User.current)
31 34 !user.nil? && user.allowed_to?(:view_messages, project)
32 35 end
@@ -23,7 +23,7 class ApplicationHelperTest < ActionView::TestCase
23 23 :repositories, :changesets,
24 24 :trackers, :issue_statuses, :issues, :versions, :documents,
25 25 :wikis, :wiki_pages, :wiki_contents,
26 :boards, :messages,
26 :boards, :messages, :news,
27 27 :attachments,
28 28 :enumerations
29 29
@@ -163,7 +163,11 RAW
163 163 version_link = link_to('1.0', {:controller => 'versions', :action => 'show', :id => 2},
164 164 :class => 'version')
165 165
166 board_url = {:controller => 'boards', :action => 'show', :id => 2, :project_id => 'ecookbook'}
167
166 168 message_url = {:controller => 'messages', :action => 'show', :board_id => 1, :id => 4}
169
170 news_url = {:controller => 'news', :action => 'show', :id => 1}
167 171
168 172 project_url = {:controller => 'projects', :action => 'show', :id => 'subproject1'}
169 173
@@ -198,9 +202,15 RAW
198 202 'source:/some/file.ext#L110' => link_to('source:/some/file.ext#L110', source_url_with_ext.merge(:anchor => 'L110'), :class => 'source'),
199 203 'source:/some/file@52#L110' => link_to('source:/some/file@52#L110', source_url.merge(:rev => 52, :anchor => 'L110'), :class => 'source'),
200 204 'export:/some/file' => link_to('export:/some/file', source_url.merge(:format => 'raw'), :class => 'source download'),
205 # forum
206 'forum#2' => link_to('Discussion', board_url, :class => 'board'),
207 'forum:Discussion' => link_to('Discussion', board_url, :class => 'board'),
201 208 # message
202 209 'message#4' => link_to('Post 2', message_url, :class => 'message'),
203 210 'message#5' => link_to('RE: post 2', message_url.merge(:anchor => 'message-5', :r => 5), :class => 'message'),
211 # news
212 'news#1' => link_to('eCookbook first release !', news_url, :class => 'news'),
213 'news:"eCookbook first release !"' => link_to('eCookbook first release !', news_url, :class => 'news'),
204 214 # project
205 215 'project#3' => link_to('eCookbook Subproject 1', project_url, :class => 'project'),
206 216 'project:subproject1' => link_to('eCookbook Subproject 1', project_url, :class => 'project'),
General Comments 0
You need to be logged in to leave comments. Login now