git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@9625 e93f8b46-1217-0410-a6f0-8f06a7374b81tags/2.0.0
end | end | ||||
end | end | ||||
def raw | |||||
entry_and_raw(true) | |||||
end | |||||
def entry | def entry | ||||
entry_and_raw(false) | |||||
end | |||||
def entry_and_raw(is_raw) | |||||
@entry = @repository.entry(@path, @rev) | @entry = @repository.entry(@path, @rev) | ||||
(show_error_not_found; return) unless @entry | (show_error_not_found; return) unless @entry | ||||
@content = @repository.cat(@path, @rev) | @content = @repository.cat(@path, @rev) | ||||
(show_error_not_found; return) unless @content | (show_error_not_found; return) unless @content | ||||
if 'raw' == params[:format] || | |||||
if is_raw || | |||||
(@content.size && @content.size > Setting.file_max_size_displayed.to_i.kilobyte) || | (@content.size && @content.size > Setting.file_max_size_displayed.to_i.kilobyte) || | ||||
! is_entry_text_data?(@content, @path) | ! is_entry_text_data?(@content, @path) | ||||
# Force the download | # Force the download | ||||
@changeset = @repository.find_changeset_by_name(@rev) | @changeset = @repository.find_changeset_by_name(@rev) | ||||
end | end | ||||
end | end | ||||
private :entry_and_raw | |||||
def is_entry_text_data?(ent, path) | def is_entry_text_data?(ent, path) | ||||
# UTF-16 contains "\x00". | # UTF-16 contains "\x00". |
<% if @repository.supports_annotate? %> | <% if @repository.supports_annotate? %> | ||||
<%= link_to_if action_name != 'annotate', l(:button_annotate), {:action => 'annotate', :id => @project, :repository_id => @repository.identifier_param, :path => to_path_param(@path), :rev => @rev } %> | | <%= link_to_if action_name != 'annotate', l(:button_annotate), {:action => 'annotate', :id => @project, :repository_id => @repository.identifier_param, :path => to_path_param(@path), :rev => @rev } %> | | ||||
<% end %> | <% end %> | ||||
<%= link_to(l(:button_download), {:action => 'entry', :id => @project, :repository_id => @repository.identifier_param, :path => to_path_param(@path), :rev => @rev, :format => 'raw' }) if @repository.supports_cat? %> | |||||
<%= link_to(l(:button_download), | |||||
{:action => 'raw', :id => @project, | |||||
:repository_id => @repository.identifier_param, | |||||
:path => to_path_param(@path), | |||||
:rev => @rev}) if @repository.supports_cat? %> | |||||
<%= "(#{number_to_human_size(@entry.size)})" if @entry.size %> | <%= "(#{number_to_human_size(@entry.size)})" if @entry.size %> | ||||
</p> | </p> | ||||
post 'projects/:id/repository/:repository_id/revisions/:rev/issues', :to => 'repositories#add_related_issue' | post 'projects/:id/repository/:repository_id/revisions/:rev/issues', :to => 'repositories#add_related_issue' | ||||
delete 'projects/:id/repository/:repository_id/revisions/:rev/issues/:issue_id', :to => 'repositories#remove_related_issue' | delete 'projects/:id/repository/:repository_id/revisions/:rev/issues/:issue_id', :to => 'repositories#remove_related_issue' | ||||
get 'projects/:id/repository/:repository_id/revisions', :to => 'repositories#revisions' | get 'projects/:id/repository/:repository_id/revisions', :to => 'repositories#revisions' | ||||
get 'projects/:id/repository/:repository_id/revisions/:rev/:format(/*path(.:ext))', | |||||
:to => 'repositories#entry', | |||||
:constraints => { | |||||
:format => 'raw', | |||||
:rev => /[a-z0-9\.\-_]+/ | |||||
} | |||||
get 'projects/:id/repository/:repository_id/revisions/:rev/:action(/*path(.:ext))', | get 'projects/:id/repository/:repository_id/revisions/:rev/:action(/*path(.:ext))', | ||||
:controller => 'repositories', | :controller => 'repositories', | ||||
:constraints => { | :constraints => { | ||||
:action => /(browse|show|entry|annotate|diff)/, | |||||
:action => /(browse|show|entry|raw|annotate|diff)/, | |||||
:rev => /[a-z0-9\.\-_]+/ | :rev => /[a-z0-9\.\-_]+/ | ||||
} | } | ||||
get 'projects/:id/repository/revision', :to => 'repositories#revision' | get 'projects/:id/repository/revision', :to => 'repositories#revision' | ||||
post 'projects/:id/repository/revisions/:rev/issues', :to => 'repositories#add_related_issue' | post 'projects/:id/repository/revisions/:rev/issues', :to => 'repositories#add_related_issue' | ||||
delete 'projects/:id/repository/revisions/:rev/issues/:issue_id', :to => 'repositories#remove_related_issue' | delete 'projects/:id/repository/revisions/:rev/issues/:issue_id', :to => 'repositories#remove_related_issue' | ||||
get 'projects/:id/repository/revisions/:rev/:format(/*path(.:ext))', | |||||
:to => 'repositories#entry', | |||||
:constraints => { | |||||
:format => 'raw', | |||||
:rev => /[a-z0-9\.\-_]+/ | |||||
} | |||||
get 'projects/:id/repository/revisions/:rev/:action(/*path(.:ext))', | get 'projects/:id/repository/revisions/:rev/:action(/*path(.:ext))', | ||||
:controller => 'repositories', | :controller => 'repositories', | ||||
:constraints => { | :constraints => { | ||||
:action => /(browse|show|entry|annotate|diff)/, | |||||
:action => /(browse|show|entry|raw|annotate|diff)/, | |||||
:rev => /[a-z0-9\.\-_]+/ | :rev => /[a-z0-9\.\-_]+/ | ||||
} | } | ||||
get 'projects/:id/repository/:repository_id/:format(/*path(.:ext))', :to => 'repositories#entry', :format => /raw/ | |||||
get 'projects/:id/repository/:repository_id/:action(/*path(.:ext))', :controller => 'repositories', :action => /(browse|show|entry|changes|annotate|diff)/ | |||||
get 'projects/:id/repository/:repository_id/:action(/*path(.:ext))', | |||||
:controller => 'repositories', | |||||
:action => /(browse|show|entry|raw|changes|annotate|diff)/ | |||||
get 'projects/:id/repository/:repository_id', :to => 'repositories#show', :path => nil | get 'projects/:id/repository/:repository_id', :to => 'repositories#show', :path => nil | ||||
get 'projects/:id/repository/:format(/*path(.:ext))', :to => 'repositories#entry', :format => /raw/ | |||||
get 'projects/:id/repository/:action(/*path(.:ext))', :controller => 'repositories', :action => /(browse|show|entry|changes|annotate|diff)/ | |||||
get 'projects/:id/repository/:action(/*path(.:ext))', | |||||
:controller => 'repositories', | |||||
:action => /(browse|show|entry|raw|changes|annotate|diff)/ | |||||
get 'projects/:id/repository', :to => 'repositories#show', :path => nil | get 'projects/:id/repository', :to => 'repositories#show', :path => nil | ||||
# additional routes for having the file name at the end of url | # additional routes for having the file name at the end of url |
map.project_module :repository do |map| | map.project_module :repository do |map| | ||||
map.permission :manage_repository, {:repositories => [:new, :create, :edit, :update, :committers, :destroy]}, :require => :member | map.permission :manage_repository, {:repositories => [:new, :create, :edit, :update, :committers, :destroy]}, :require => :member | ||||
map.permission :browse_repository, :repositories => [:show, :browse, :entry, :annotate, :changes, :diff, :stats, :graph] | |||||
map.permission :browse_repository, :repositories => [:show, :browse, :entry, :raw, :annotate, :changes, :diff, :stats, :graph] | |||||
map.permission :view_changesets, :repositories => [:show, :revisions, :revision] | map.permission :view_changesets, :repositories => [:show, :revisions, :revision] | ||||
map.permission :commit_access, {} | map.permission :commit_access, {} | ||||
map.permission :manage_related_issues, {:repositories => [:add_related_issue, :remove_related_issue]} | map.permission :manage_related_issues, {:repositories => [:add_related_issue, :remove_related_issue]} |
end | end | ||||
def test_entry_download_no_extension | def test_entry_download_no_extension | ||||
get :entry, :id => PRJ_ID, :path => repository_path_hash(['test'])[:param], | |||||
:format => 'raw' | |||||
get :raw, :id => PRJ_ID, :path => repository_path_hash(['test'])[:param] | |||||
assert_response :success | assert_response :success | ||||
assert_equal 'application/octet-stream', @response.content_type | assert_equal 'application/octet-stream', @response.content_type | ||||
end | end |
@repository.fetch_changesets | @repository.fetch_changesets | ||||
@project.reload | @project.reload | ||||
assert_equal NUM_REV, @repository.changesets.count | assert_equal NUM_REV, @repository.changesets.count | ||||
get :entry, :id => PRJ_ID, | |||||
:path => repository_path_hash(['subversion_test', 'helloworld.c'])[:param], | |||||
:format => 'raw' | |||||
get :raw, :id => PRJ_ID, | |||||
:path => repository_path_hash(['subversion_test', 'helloworld.c'])[:param] | |||||
assert_response :success | assert_response :success | ||||
assert_equal 'attachment; filename="helloworld.c"', @response.headers['Content-Disposition'] | assert_equal 'attachment; filename="helloworld.c"', @response.headers['Content-Disposition'] | ||||
end | end |
assert_routing( | assert_routing( | ||||
{ :method => 'get', | { :method => 'get', | ||||
:path => "/projects/redmine/repository/revisions/2/raw/#{@path_hash[:path]}" }, | :path => "/projects/redmine/repository/revisions/2/raw/#{@path_hash[:path]}" }, | ||||
{ :controller => 'repositories', :action => 'entry', :id => 'redmine', | |||||
:path => @path_hash[:param], :rev => '2', :format => 'raw' } | |||||
{ :controller => 'repositories', :action => 'raw', :id => 'redmine', | |||||
:path => @path_hash[:param], :rev => '2' } | |||||
) | ) | ||||
assert_routing( | assert_routing( | ||||
{ :method => 'get', | { :method => 'get', | ||||
assert_routing( | assert_routing( | ||||
{ :method => 'get', | { :method => 'get', | ||||
:path => "/projects/redmine/repository/foo/revisions/2/raw/#{@path_hash[:path]}" }, | :path => "/projects/redmine/repository/foo/revisions/2/raw/#{@path_hash[:path]}" }, | ||||
{ :controller => 'repositories', :action => 'entry', :id => 'redmine', :repository_id => 'foo', | |||||
:path => @path_hash[:param], :rev => '2', :format => 'raw' } | |||||
{ :controller => 'repositories', :action => 'raw', :id => 'redmine', :repository_id => 'foo', | |||||
:path => @path_hash[:param], :rev => '2' } | |||||
) | ) | ||||
assert_routing( | assert_routing( | ||||
{ :method => 'get', | { :method => 'get', | ||||
assert_routing( | assert_routing( | ||||
{ :method => 'get', | { :method => 'get', | ||||
:path => "/projects/redmine/repository/raw/#{@path_hash[:path]}" }, | :path => "/projects/redmine/repository/raw/#{@path_hash[:path]}" }, | ||||
{ :controller => 'repositories', :action => 'entry', :id => 'redmine', | |||||
:path => @path_hash[:param], :format => 'raw' } | |||||
{ :controller => 'repositories', :action => 'raw', :id => 'redmine', | |||||
:path => @path_hash[:param] } | |||||
) | ) | ||||
assert_routing( | assert_routing( | ||||
{ :method => 'get', | { :method => 'get', | ||||
assert_routing( | assert_routing( | ||||
{ :method => 'get', | { :method => 'get', | ||||
:path => "/projects/redmine/repository/foo/raw/#{@path_hash[:path]}" }, | :path => "/projects/redmine/repository/foo/raw/#{@path_hash[:path]}" }, | ||||
{ :controller => 'repositories', :action => 'entry', :id => 'redmine', :repository_id => 'foo', | |||||
:path => @path_hash[:param], :format => 'raw' } | |||||
{ :controller => 'repositories', :action => 'raw', :id => 'redmine', :repository_id => 'foo', | |||||
:path => @path_hash[:param] } | |||||
) | ) | ||||
assert_routing( | assert_routing( | ||||
{ :method => 'get', | { :method => 'get', |