Feature #3346 » cross-project_revision_and_commit_links_v2.1.diff
| C:\Depots\redmine\app\helpers\application_helper.rb | ||
|---|---|---|
|
def_delegators :wiki_helper, :wikitoolbar_for, :heads_for_wiki_formatter
|
||
|
|
||
|
# Return true if user is authorized for controller/action, otherwise false
|
||
|
def authorize_for(controller, action)
|
||
|
User.current.allowed_to?({:controller => controller, :action => action}, @project)
|
||
|
def authorize_for(controller, action, project = @project)
|
||
|
User.current.allowed_to?({:controller => controller, :action => action}, project)
|
||
|
end
|
||
|
|
||
|
# Display a link if user is authorized
|
||
|
def link_to_if_authorized(name, options = {}, html_options = nil, *parameters_for_method_reference)
|
||
|
link_to(name, options, html_options, *parameters_for_method_reference) if authorize_for(options[:controller] || params[:controller], options[:action])
|
||
|
link_to(name, options, html_options, *parameters_for_method_reference) if authorize_for(options[:controller] || params[:controller], options[:action], options[:project])
|
||
|
end
|
||
|
|
||
|
# Display a link to remote if user is authorized
|
||
|
def link_to_remote_if_authorized(name, options = {}, html_options = nil)
|
||
|
url = options[:url] || {}
|
||
|
link_to_remote(name, options, html_options) if authorize_for(url[:controller] || params[:controller], url[:action])
|
||
|
link_to_remote(name, options, html_options) if authorize_for(url[:controller] || params[:controller], url[:action], options[:project])
|
||
|
end
|
||
|
|
||
|
# Display a link to user's account page
|
||
| ... | ... | |
|
# #52 -> Link to issue #52
|
||
|
# Changesets:
|
||
|
# r52 -> Link to revision 52
|
||
|
# r:project:52 -> Link to revision 52 of an other project, using project name or identifier
|
||
|
# commit:a85130f -> Link to scmid starting with a85130f
|
||
|
# commit:project:a85130f -> Link to scmid starting with a85130f of an other project, using project name or identifier
|
||
|
# Documents:
|
||
|
# document#17 -> Link to document with id 17
|
||
|
# document:Greetings -> Link to the document with title "Greetings"
|
||
| ... | ... | |
|
# export:some/file -> Force the download of the file
|
||
|
# 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
|
||
|
text = text.gsub(%r{([\s\(,\-\>]|^)(!)?(attachment|document|version|commit|source|export|message)?((#|r)(:[^\s<>][^\:\r\n\b]+[^\s<>]:)?(\d+)|(:)([^\s<>][^\:\r\n\b]+[^\s<>]:)?([^"\:\s<>][^\:\s\r\n\b<>]*?|"[^"]+?"))(?=(?=[[:punct:]]\W)|,|\s|<|$)}) do |m|
|
||
|
leading, esc, prefix, sep, revproj, oid = $1, $2, $3, $8 || $5, $9 || $6, $10 || $7
|
||
|
link = nil
|
||
|
if esc.nil?
|
||
|
if prefix.nil? && sep == 'r'
|
||
|
if revproj.nil?
|
||
|
if project && (changeset = project.changesets.find_by_revision(oid))
|
||
|
link = link_to("r#{oid}", {:only_path => only_path, :controller => 'repositories', :action => 'revision', :id => project, :rev => oid},
|
||
|
:class => 'changeset',
|
||
|
:title => truncate_single_line(changeset.comments, :length => 100))
|
||
|
end
|
||
|
else
|
||
|
revproj.gsub!(/[\:"]/,'')
|
||
|
link_project = Project.find_by_name(h(revproj)) || Project.find_by_identifier(h(revproj))
|
||
|
if link_project && (changeset = link_project.changesets.find_by_revision(oid))
|
||
|
name = h("#{revproj}:r#{oid}")
|
||
|
options = {:only_path => only_path, :controller => 'repositories', :action => 'revision', :id => link_project, :project => link_project, :rev => oid}
|
||
|
html_options = {:class => 'changeset',
|
||
|
:title => truncate_single_line(changeset.comments, :length => 100)}
|
||
|
link = link_to_if_authorized(name, options, html_options) || (options.delete(:project) && html_options.delete(:title) && link_to(name, options, html_options))
|
||
|
end
|
||
|
end
|
||
|
elsif sep == '#'
|
||
|
oid = oid.to_i
|
||
|
case prefix
|
||
| ... | ... | |
|
:class => 'version'
|
||
|
end
|
||
|
when 'commit'
|
||
|
if revproj.nil?
|
||
|
if project && (changeset = project.changesets.find(:first, :conditions => ["scmid LIKE ?", "#{name}%"]))
|
||
|
link = link_to h("#{name}"), {:only_path => only_path, :controller => 'repositories', :action => 'revision', :id => project, :rev => changeset.revision},
|
||
|
:class => 'changeset',
|
||
|
:title => truncate_single_line(changeset.comments, :length => 100)
|
||
|
end
|
||
|
else
|
||
|
revproj.gsub!(/[\:"]/,'')
|
||
|
link_project = Project.find_by_name(h(revproj)) || Project.find_by_identifier(h(revproj))
|
||
|
if link_project && (changeset = link_project.changesets.find(:first, :conditions => ["scmid LIKE ?", "#{name}%"]))
|
||
|
name = h("#{revproj}:#{name}")
|
||
|
options = {:only_path => only_path, :controller => 'repositories', :action => 'revision', :id => link_project, :project => link_project, :rev => changeset.revision}
|
||
|
html_options = {:class => 'changeset',
|
||
|
:title => truncate_single_line(changeset.comments, :length => 100)}
|
||
|
link = link_to_if_authorized(name, options, html_options) || (options.delete(:project) && html_options.delete(:title) && link_to(name, options, html_options))
|
||
|
end
|
||
|
end
|
||
|
when 'source', 'export'
|
||
|
if project && project.repository
|
||
|
name =~ %r{^[/\\]*(.*?)(@([0-9a-f]+))?(#(L\d+))?$}
|
||
| ... | ... | |
|
end
|
||
|
end
|
||
|
end
|
||
|
leading + (link || "#{prefix}#{sep}#{oid}")
|
||
|
leading + (link || (revproj ? "#{revproj}:" : "") + "#{prefix}#{sep}#{oid}")
|
||
|
end
|
||
|
|
||
|
text
|
||