route: scm: split entry and raw actions

git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@9625 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
Toshi MARUYAMA 2012-05-05 01:01:29 +00:00
parent 569e1b37cc
commit b0414ec1fb
7 changed files with 35 additions and 34 deletions

View File

@ -152,7 +152,15 @@ class RepositoriesController < ApplicationController
end
end
def raw
entry_and_raw(true)
end
def entry
entry_and_raw(false)
end
def entry_and_raw(is_raw)
@entry = @repository.entry(@path, @rev)
(show_error_not_found; return) unless @entry
@ -161,7 +169,7 @@ class RepositoriesController < ApplicationController
@content = @repository.cat(@path, @rev)
(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) ||
! is_entry_text_data?(@content, @path)
# Force the download
@ -177,6 +185,7 @@ class RepositoriesController < ApplicationController
@changeset = @repository.find_changeset_by_name(@rev)
end
end
private :entry_and_raw
def is_entry_text_data?(ent, path)
# UTF-16 contains "\x00".

View File

@ -8,7 +8,11 @@
<% 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 } %> |
<% 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 %>
</p>

View File

@ -222,16 +222,10 @@ RedmineApp::Application.routes.draw do
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'
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))',
:controller => 'repositories',
:constraints => {
:action => /(browse|show|entry|annotate|diff)/,
:action => /(browse|show|entry|raw|annotate|diff)/,
:rev => /[a-z0-9\.\-_]+/
}
@ -246,24 +240,20 @@ RedmineApp::Application.routes.draw do
get 'projects/:id/repository/revision', :to => 'repositories#revision'
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'
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))',
:controller => 'repositories',
:constraints => {
:action => /(browse|show|entry|annotate|diff)/,
:action => /(browse|show|entry|raw|annotate|diff)/,
: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/: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
# additional routes for having the file name at the end of url

View File

@ -125,7 +125,7 @@ Redmine::AccessControl.map do |map|
map.project_module :repository do |map|
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 :commit_access, {}
map.permission :manage_related_issues, {:repositories => [:add_related_issue, :remove_related_issue]}

View File

@ -78,8 +78,7 @@ class RepositoriesFilesystemControllerTest < ActionController::TestCase
end
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_equal 'application/octet-stream', @response.content_type
end

View File

@ -216,9 +216,8 @@ class RepositoriesSubversionControllerTest < ActionController::TestCase
@repository.fetch_changesets
@project.reload
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_equal 'attachment; filename="helloworld.c"', @response.headers['Content-Disposition']
end

View File

@ -184,8 +184,8 @@ class RoutingRepositoriesTest < ActionController::IntegrationTest
assert_routing(
{ :method => 'get',
: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(
{ :method => 'get',
@ -278,8 +278,8 @@ class RoutingRepositoriesTest < ActionController::IntegrationTest
assert_routing(
{ :method => 'get',
: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(
{ :method => 'get',
@ -311,8 +311,8 @@ class RoutingRepositoriesTest < ActionController::IntegrationTest
assert_routing(
{ :method => 'get',
: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(
{ :method => 'get',
@ -355,8 +355,8 @@ class RoutingRepositoriesTest < ActionController::IntegrationTest
assert_routing(
{ :method => 'get',
: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(
{ :method => 'get',