Feature #4052 » 091018-cross-project_redmine_links-tests.patch
| app/helpers/application_helper.rb (working copy) | ||
|---|---|---|
|
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
|
||
|
# project:r52 -> Link to revision 52 of an other project, using project name or identifier
|
||
|
# commit:a85130f -> Link to scmid starting with a85130f
|
||
|
# project:commit:a85130f -> Link to scmid starting with a85130f of an other project, using project name or identifier
|
||
|
# If your project name contains spaces, use quotation marks :
|
||
|
# "My Project":r52
|
||
|
# "My Project":commit:a85130f
|
||
|
# Documents:
|
||
|
# document#17 -> Link to document with id 17
|
||
|
# document:Greetings -> Link to the document with title "Greetings"
|
||
| ... | ... | |
|
# Attachments:
|
||
|
# attachment:file.zip -> Link to the attachment of the current object named file.zip
|
||
|
# Source files:
|
||
|
# ["Link alternate display title"=][project:]source:some/path[/file][@52][#L120]
|
||
|
# ["Link alternate display title"=][project:]export:some/path/file[@52]
|
||
|
# source:some/file -> Link to the file located at /some/file in the project's repository
|
||
|
# source:some/file@52 -> Link to the file's revision 52
|
||
|
# source:some/file#L120 -> Link to line 120 of the file
|
||
|
# "click here"=source:some/file#L120 -> Link to line 120 of the file
|
||
|
# "click here"=wizbang:source:some/file#L120 -> Link to line 120 of the file in the repo for the wizbang project
|
||
|
# source:some/file@52#L120 -> Link to line 120 of the file's revision 52
|
||
|
# export:some/file -> Force the download of the file
|
||
|
# "Download This File"=export:some/file -> Force the download of the file
|
||
|
# "Download This File"=myproject:export:some/file -> Force the download of the file in repository for myproject project
|
||
|
# 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\(,\-\>]|^)(!)?(\"[^\"\n]+\"=)?(attachment|document|version|(\"[^:<>\r\n\b]+\":|[^:<>\s\r\n\b]+:)?(commit|source|export)|message)?((#|(\"[^:<>\r\n\b]+\":|[^:<>\s\r\n\b]+:)?(r))(\d+)|(:)([^"\s<>][^:\s\r\n\b<>]*?|"[^"]+?"))(?=(?=[[:punct:]]\W)|,|\s|<|$)}) do |m|
|
||
|
leading, esc, linktitle, prefix, sep, revproj, oid = $1, $2, $3, $6 || $3, $12 || $10 || $8, $5 || $9, $11 || $13
|
||
|
link = nil
|
||
|
if esc.nil?
|
||
|
if prefix.nil? && sep == 'r'
|
||
|
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))
|
||
|
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
|
||
| ... | ... | |
|
:class => 'version'
|
||
|
end
|
||
|
when 'commit'
|
||
|
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)
|
||
|
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
|
||
|
if revproj.nil?
|
||
|
link_project = project
|
||
|
else
|
||
|
revproj.gsub!(/[\:"]/,'')
|
||
|
link_project = Project.find_by_name(h(revproj)) || Project.find_by_identifier(h(revproj))
|
||
|
end
|
||
|
if link_project && link_project.repository
|
||
|
name =~ %r{^[/\\]*(.*?)(@([0-9a-f]+))?(#(L\d+))?$}
|
||
|
path, rev, anchor = $1, $3, $5
|
||
|
link = link_to h("#{prefix}:#{name}"), {:controller => 'repositories', :action => 'entry', :id => project,
|
||
|
link_title = linktitle ? linktitle.gsub!(/[\"=]/,'') : (link_project != project ? "#{revproj}:" : "") + "#{prefix}:#{name}"
|
||
|
link = link_to h(link_title), {:only_path => only_path, :controller => 'repositories', :action => 'entry', :id => link_project,
|
||
|
:path => to_path_param(path),
|
||
|
:rev => rev,
|
||
|
:anchor => anchor,
|
||
| ... | ... | |
|
end
|
||
|
end
|
||
|
end
|
||
|
leading + (link || "#{prefix}#{sep}#{oid}")
|
||
|
leading + (link || (revproj ? "#{revproj}:" : "") + "#{prefix}#{sep}#{oid}")
|
||
|
end
|
||
|
text
|
||
| public/help/wiki_syntax.html (working copy) | ||
|---|---|---|
|
<tr><th><img src="../images/jstoolbar/bt_link.png" style="border: 1px solid #bbb;" alt="Link to a Wiki page" /></th><td>[[Wiki page]]</td><td><a href="#">Wiki page</a></td></tr>
|
||
|
<tr><th></th><td>Issue #12</td><td>Issue <a href="#">#12</a></td></tr>
|
||
|
<tr><th></th><td>Revision r43</td><td>Revision <a href="#">r43</a></td></tr>
|
||
|
<tr><th></th><td>myproj:r43</td><td><a href="#">myproj:r43</a></td></tr>
|
||
|
<tr><th></th><td>commit:f30e13e43</td><td><a href="#">f30e13e4</a></td></tr>
|
||
|
<tr><th></th><td>proj:commit:f30e13e43</td><td><a href="#">proj:f30e13e4</a></td></tr>
|
||
|
<tr><th></th><td>source:some/file</td><td><a href="#">source:some/file</a></td></tr>
|
||
|
<tr><th></th><td>proj:source:some/file</td><td><a href="#">proj:source:some/file</a></td></tr>
|
||
|
<tr><th></th><td>"File Src"=source:some/file</td><td><a href="#">File Src</a></td></tr>
|
||
|
<tr><th></th><td>"Download"=proj:export:some/file</td><td><a href="#">Download</a></td></tr>
|
||
|
<tr><th colspan="3">Inline images</th></tr>
|
||
|
<tr><th><img src="../images/jstoolbar/bt_img.png" style="border: 1px solid #bbb;" alt="Image" /></th><td>!<em>image_url</em>!</td><td></td></tr>
|
||
| public/help/wiki_syntax_detailed.html (working copy) | ||
|---|---|---|
|
<li>Link to a changeset with a non-numeric hash: <strong>commit:c6f4d0fd</strong> (displays c6f4d0fd). Added in <a href="/repositories/revision/1?rev=1236" class="changeset" title="Merged Git support branch (r1200 to r1226).">r1236</a>.</li>
|
||
|
</ul>
|
||
|
|
||
|
<p>You can also link to changesets of an other project repository:</p>
|
||
|
|
||
|
<ul>
|
||
|
<li>Link to a changeset of SandBox project: <strong>sandbox:r758</strong> (displays <a href="/repositories/revision/1?rev=758" class="changeset" title="Search engine now only searches objects the user is allowed to view.">sandbox:r758</a>)</li>
|
||
|
<li>Link to a changeset of SandBox project with a non-numeric hash: <strong>sandbox:commit:c6f4d0fd</strong> (displays sandbox:c6f4d0fd).</li>
|
||
|
<li>If your project name contains spaces, use quotation marks : <strong>"My Project":r758</strong> or <strong>"My Project":commit:c6f4d0fd</strong></li>
|
||
|
</ul>
|
||
|
|
||
|
<p>Wiki links:</p>
|
||
|
|
||
|
<ul>
|
||
| ... | ... | |
|
<ul>
|
||
|
<li>Repository files
|
||
|
<ul>
|
||
|
<li><strong>["Link display title"=][project:]source:some/path[/file][@52][#L120]</strong> -- Link to the file located at /some/file in the project's repository</li>
|
||
|
<li><strong>["Link alternate display title"=][project:]export:some/path/file[@52]</strong> -- Link to the file located at /some/file in the project's repository</li>
|
||
|
<li><strong>source:some/file</strong> -- Link to the file located at /some/file in the project's repository</li>
|
||
|
<li><strong>source:some/file@52</strong> -- Link to the file's revision 52</li>
|
||
|
<li><strong>source:some/file#L120</strong> -- Link to line 120 of the file</li>
|
||
|
<li><strong>"click here"=source:some/file#L120</strong> -- "click here" Link to line 120 of the file</li>
|
||
|
<li><strong>"click here"=wizbang:source:some/file#L120</strong> -- Link to line 120 of the file in the repo for the wizbang project</li>
|
||
|
<li><strong>source:some/file@52#L120</strong> -- Link to line 120 of the file's revision 52</li>
|
||
|
<li><strong>export:some/file</strong> -- Force the download of the file</li>
|
||
|
<li><strong>"Download This File"=export:some/file</strong> -- Force the download of the file</li>
|
||
|
<li><strong>"Download This File"=myproject:export:some/file</strong> -- Force the download of the file in repository for myproject project</li>
|
||
|
</ul></li>
|
||
|
</ul>
|
||
|
|
||
| test/fixtures/changes.yml (working copy) | ||
|---|---|---|
|
path: /test/some/path/in/the/repo
|
||
|
from_path:
|
||
|
from_revision:
|
||
|
changes_009:
|
||
|
id: 9
|
||
|
changeset_id: 108
|
||
|
action: M
|
||
|
path: /test/some/path/in/the/repo
|
||
|
from_path:
|
||
|
from_revision:
|
||
|
changes_0010:
|
||
|
id: 10
|
||
|
changeset_id: 109
|
||
|
action: M
|
||
|
path: /test/some/path/in/the/repo
|
||
|
from_path:
|
||
|
from_revision:
|
||
|
|
||
| test/fixtures/changesets.yml (working copy) | ||
|---|---|---|
|
user_id: 3
|
||
|
repository_id: 10
|
||
|
committer: dlopper
|
||
|
changesets_009:
|
||
|
commit_date: 2007-04-11
|
||
|
committed_on: 2007-04-11 15:14:44 +02:00
|
||
|
revision: 1
|
||
|
id: 108
|
||
|
comments: My very first commit
|
||
|
repository_id: 12
|
||
|
committer: dlopper
|
||
|
user_id: 3
|
||
|
changesets_010:
|
||
|
commit_date: 2007-04-12
|
||
|
committed_on: 2007-04-12 15:14:44 +02:00
|
||
|
revision: 2
|
||
|
id: 109
|
||
|
comments: 'This commit fixes #5'
|
||
|
repository_id: 12
|
||
|
committer: dlopper
|
||
|
user_id: 3
|
||
|
|
||
| test/fixtures/repositories.yml (working copy) | ||
|---|---|---|
|
password: ""
|
||
|
login: ""
|
||
|
type: Subversion
|
||
|
|
||
|
repositories_003:
|
||
|
project_id: 3
|
||
|
url: svn://localhost/test
|
||
|
id: 12
|
||
|
root_url: svn://localhost
|
||
|
password: ""
|
||
|
login: ""
|
||
|
type: Subversion
|
||
| test/unit/helpers/application_helper_test.rb (working copy) | ||
|---|---|---|
|
def setup
|
||
|
super
|
||
|
@admin = User.find(1)
|
||
|
@jsmith = User.find(2)
|
||
|
@dlopper = User.find(3)
|
||
|
end
|
||
|
|
||
|
def test_auto_links
|
||
| ... | ... | |
|
:class => 'changeset', :title => 'My very first commit')
|
||
|
changeset_link2 = link_to('r2', {:controller => 'repositories', :action => 'revision', :id => 'ecookbook', :rev => 2},
|
||
|
:class => 'changeset', :title => 'This commit fixes #1, #2 and references #1 & #3')
|
||
|
|
||
|
changeset_link_other_project_id = link_to('subproject1:r1', {:controller => 'repositories', :action => 'revision', :id => 'subproject1', :rev => 1},
|
||
|
:class => 'changeset', :title => 'My very first commit')
|
||
|
changeset_link_other_project_name = link_to('eCookbook Subproject 1:r2', {:controller => 'repositories', :action => 'revision', :id => 'subproject1', :rev => 2},
|
||
|
:class => 'changeset', :title => 'This commit fixes #5')
|
||
|
document_link = link_to('Test document', {:controller => 'documents', :action => 'show', :id => 1},
|
||
|
:class => 'document')
|
||
|
|
||
| ... | ... | |
|
'r1.' => "#{changeset_link}.",
|
||
|
'r1, r2' => "#{changeset_link}, #{changeset_link2}",
|
||
|
'r1,r2' => "#{changeset_link},#{changeset_link2}",
|
||
|
'subproject1:r1' => "#{changeset_link_other_project_id}",
|
||
|
'subproject1:r1.' => "#{changeset_link_other_project_id}.",
|
||
|
'subproject1:r1,"eCookbook Subproject 1":r2' => "#{changeset_link_other_project_id},#{changeset_link_other_project_name}",
|
||
|
# documents
|
||
|
'document#1' => document_link,
|
||
|
'document:"Test document"' => document_link,
|
||
| ... | ... | |
|
"http://foo.bar/FAQ#3" => '<a class="external" href="http://foo.bar/FAQ#3">http://foo.bar/FAQ#3</a>',
|
||
|
}
|
||
|
@project = Project.find(1)
|
||
|
User.current = @admin
|
||
|
|
||
|
to_test.each { |text, result| assert_equal "<p>#{result}</p>", textilizable(text) }
|
||
|
User.current = nil
|
||
|
end
|
||
|
|
||
|
def test_wiki_links
|
||
| ... | ... | |
|
}
|
||
|
to_test.each { |text, result| assert_equal "<p>#{result}</p>", textilizable(text) }
|
||
|
end
|
||
|
|
||
|
def test_wiki_horizontal_rule
|
||
|
assert_equal '<hr />', textilizable('---')
|
||
|
assert_equal '<p>Dashes: ---</p>', textilizable('Dashes: ---')
|
||