Project

General

Profile

Feature #3346 » cross-project_revision_and_commit_links_v3.diff

Patch v3 - Fix link_to_if_authorized and link_to_remote_if_authorized helpers because it breaks contextual links - Babar O'Cap, 2009-08-20 09:26

View differences:

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
......
# #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))
title = truncate_single_line(changeset.comments, :length => 100) if authorize_for('repositories', 'revision', link_project)
link = link_to h("#{revproj}:r#{oid}"), {:only_path => only_path, :controller => 'repositories', :action => 'revision', :id => link_project, :rev => oid},
:class => 'changeset',
:title => title
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}%"]))
title = truncate_single_line(changeset.comments, :length => 100) if authorize_for('repositories', 'revision', link_project)
link = link_to h("#{revproj}:#{name}"), {:only_path => only_path, :controller => 'repositories', :action => 'revision', :id => link_project, :rev => changeset.revision},
:class => 'changeset',
:title => title
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
(5-5/7)