##// END OF EJS Templates
route: scm: split entry and raw actions...
Toshi MARUYAMA -
r9442:b0414ec1fbab
parent child
Show More
@@ -152,7 +152,15 class RepositoriesController < ApplicationController
152 end
152 end
153 end
153 end
154
154
155 def raw
156 entry_and_raw(true)
157 end
158
155 def entry
159 def entry
160 entry_and_raw(false)
161 end
162
163 def entry_and_raw(is_raw)
156 @entry = @repository.entry(@path, @rev)
164 @entry = @repository.entry(@path, @rev)
157 (show_error_not_found; return) unless @entry
165 (show_error_not_found; return) unless @entry
158
166
@@ -161,7 +169,7 class RepositoriesController < ApplicationController
161
169
162 @content = @repository.cat(@path, @rev)
170 @content = @repository.cat(@path, @rev)
163 (show_error_not_found; return) unless @content
171 (show_error_not_found; return) unless @content
164 if 'raw' == params[:format] ||
172 if is_raw ||
165 (@content.size && @content.size > Setting.file_max_size_displayed.to_i.kilobyte) ||
173 (@content.size && @content.size > Setting.file_max_size_displayed.to_i.kilobyte) ||
166 ! is_entry_text_data?(@content, @path)
174 ! is_entry_text_data?(@content, @path)
167 # Force the download
175 # Force the download
@@ -177,6 +185,7 class RepositoriesController < ApplicationController
177 @changeset = @repository.find_changeset_by_name(@rev)
185 @changeset = @repository.find_changeset_by_name(@rev)
178 end
186 end
179 end
187 end
188 private :entry_and_raw
180
189
181 def is_entry_text_data?(ent, path)
190 def is_entry_text_data?(ent, path)
182 # UTF-16 contains "\x00".
191 # UTF-16 contains "\x00".
@@ -222,16 +222,10 RedmineApp::Application.routes.draw do
222 post 'projects/:id/repository/:repository_id/revisions/:rev/issues', :to => 'repositories#add_related_issue'
222 post 'projects/:id/repository/:repository_id/revisions/:rev/issues', :to => 'repositories#add_related_issue'
223 delete 'projects/:id/repository/:repository_id/revisions/:rev/issues/:issue_id', :to => 'repositories#remove_related_issue'
223 delete 'projects/:id/repository/:repository_id/revisions/:rev/issues/:issue_id', :to => 'repositories#remove_related_issue'
224 get 'projects/:id/repository/:repository_id/revisions', :to => 'repositories#revisions'
224 get 'projects/:id/repository/:repository_id/revisions', :to => 'repositories#revisions'
225 get 'projects/:id/repository/:repository_id/revisions/:rev/:format(/*path(.:ext))',
226 :to => 'repositories#entry',
227 :constraints => {
228 :format => 'raw',
229 :rev => /[a-z0-9\.\-_]+/
230 }
231 get 'projects/:id/repository/:repository_id/revisions/:rev/:action(/*path(.:ext))',
225 get 'projects/:id/repository/:repository_id/revisions/:rev/:action(/*path(.:ext))',
232 :controller => 'repositories',
226 :controller => 'repositories',
233 :constraints => {
227 :constraints => {
234 :action => /(browse|show|entry|annotate|diff)/,
228 :action => /(browse|show|entry|raw|annotate|diff)/,
235 :rev => /[a-z0-9\.\-_]+/
229 :rev => /[a-z0-9\.\-_]+/
236 }
230 }
237
231
@@ -246,24 +240,20 RedmineApp::Application.routes.draw do
246 get 'projects/:id/repository/revision', :to => 'repositories#revision'
240 get 'projects/:id/repository/revision', :to => 'repositories#revision'
247 post 'projects/:id/repository/revisions/:rev/issues', :to => 'repositories#add_related_issue'
241 post 'projects/:id/repository/revisions/:rev/issues', :to => 'repositories#add_related_issue'
248 delete 'projects/:id/repository/revisions/:rev/issues/:issue_id', :to => 'repositories#remove_related_issue'
242 delete 'projects/:id/repository/revisions/:rev/issues/:issue_id', :to => 'repositories#remove_related_issue'
249 get 'projects/:id/repository/revisions/:rev/:format(/*path(.:ext))',
250 :to => 'repositories#entry',
251 :constraints => {
252 :format => 'raw',
253 :rev => /[a-z0-9\.\-_]+/
254 }
255 get 'projects/:id/repository/revisions/:rev/:action(/*path(.:ext))',
243 get 'projects/:id/repository/revisions/:rev/:action(/*path(.:ext))',
256 :controller => 'repositories',
244 :controller => 'repositories',
257 :constraints => {
245 :constraints => {
258 :action => /(browse|show|entry|annotate|diff)/,
246 :action => /(browse|show|entry|raw|annotate|diff)/,
259 :rev => /[a-z0-9\.\-_]+/
247 :rev => /[a-z0-9\.\-_]+/
260 }
248 }
261 get 'projects/:id/repository/:repository_id/:format(/*path(.:ext))', :to => 'repositories#entry', :format => /raw/
249 get 'projects/:id/repository/:repository_id/:action(/*path(.:ext))',
262 get 'projects/:id/repository/:repository_id/:action(/*path(.:ext))', :controller => 'repositories', :action => /(browse|show|entry|changes|annotate|diff)/
250 :controller => 'repositories',
251 :action => /(browse|show|entry|raw|changes|annotate|diff)/
263 get 'projects/:id/repository/:repository_id', :to => 'repositories#show', :path => nil
252 get 'projects/:id/repository/:repository_id', :to => 'repositories#show', :path => nil
264
253
265 get 'projects/:id/repository/:format(/*path(.:ext))', :to => 'repositories#entry', :format => /raw/
254 get 'projects/:id/repository/:action(/*path(.:ext))',
266 get 'projects/:id/repository/:action(/*path(.:ext))', :controller => 'repositories', :action => /(browse|show|entry|changes|annotate|diff)/
255 :controller => 'repositories',
256 :action => /(browse|show|entry|raw|changes|annotate|diff)/
267 get 'projects/:id/repository', :to => 'repositories#show', :path => nil
257 get 'projects/:id/repository', :to => 'repositories#show', :path => nil
268
258
269 # additional routes for having the file name at the end of url
259 # additional routes for having the file name at the end of url
@@ -125,7 +125,7 Redmine::AccessControl.map do |map|
125
125
126 map.project_module :repository do |map|
126 map.project_module :repository do |map|
127 map.permission :manage_repository, {:repositories => [:new, :create, :edit, :update, :committers, :destroy]}, :require => :member
127 map.permission :manage_repository, {:repositories => [:new, :create, :edit, :update, :committers, :destroy]}, :require => :member
128 map.permission :browse_repository, :repositories => [:show, :browse, :entry, :annotate, :changes, :diff, :stats, :graph]
128 map.permission :browse_repository, :repositories => [:show, :browse, :entry, :raw, :annotate, :changes, :diff, :stats, :graph]
129 map.permission :view_changesets, :repositories => [:show, :revisions, :revision]
129 map.permission :view_changesets, :repositories => [:show, :revisions, :revision]
130 map.permission :commit_access, {}
130 map.permission :commit_access, {}
131 map.permission :manage_related_issues, {:repositories => [:add_related_issue, :remove_related_issue]}
131 map.permission :manage_related_issues, {:repositories => [:add_related_issue, :remove_related_issue]}
@@ -78,8 +78,7 class RepositoriesFilesystemControllerTest < ActionController::TestCase
78 end
78 end
79
79
80 def test_entry_download_no_extension
80 def test_entry_download_no_extension
81 get :entry, :id => PRJ_ID, :path => repository_path_hash(['test'])[:param],
81 get :raw, :id => PRJ_ID, :path => repository_path_hash(['test'])[:param]
82 :format => 'raw'
83 assert_response :success
82 assert_response :success
84 assert_equal 'application/octet-stream', @response.content_type
83 assert_equal 'application/octet-stream', @response.content_type
85 end
84 end
@@ -216,9 +216,8 class RepositoriesSubversionControllerTest < ActionController::TestCase
216 @repository.fetch_changesets
216 @repository.fetch_changesets
217 @project.reload
217 @project.reload
218 assert_equal NUM_REV, @repository.changesets.count
218 assert_equal NUM_REV, @repository.changesets.count
219 get :entry, :id => PRJ_ID,
219 get :raw, :id => PRJ_ID,
220 :path => repository_path_hash(['subversion_test', 'helloworld.c'])[:param],
220 :path => repository_path_hash(['subversion_test', 'helloworld.c'])[:param]
221 :format => 'raw'
222 assert_response :success
221 assert_response :success
223 assert_equal 'attachment; filename="helloworld.c"', @response.headers['Content-Disposition']
222 assert_equal 'attachment; filename="helloworld.c"', @response.headers['Content-Disposition']
224 end
223 end
@@ -184,8 +184,8 class RoutingRepositoriesTest < ActionController::IntegrationTest
184 assert_routing(
184 assert_routing(
185 { :method => 'get',
185 { :method => 'get',
186 :path => "/projects/redmine/repository/revisions/2/raw/#{@path_hash[:path]}" },
186 :path => "/projects/redmine/repository/revisions/2/raw/#{@path_hash[:path]}" },
187 { :controller => 'repositories', :action => 'entry', :id => 'redmine',
187 { :controller => 'repositories', :action => 'raw', :id => 'redmine',
188 :path => @path_hash[:param], :rev => '2', :format => 'raw' }
188 :path => @path_hash[:param], :rev => '2' }
189 )
189 )
190 assert_routing(
190 assert_routing(
191 { :method => 'get',
191 { :method => 'get',
@@ -278,8 +278,8 class RoutingRepositoriesTest < ActionController::IntegrationTest
278 assert_routing(
278 assert_routing(
279 { :method => 'get',
279 { :method => 'get',
280 :path => "/projects/redmine/repository/foo/revisions/2/raw/#{@path_hash[:path]}" },
280 :path => "/projects/redmine/repository/foo/revisions/2/raw/#{@path_hash[:path]}" },
281 { :controller => 'repositories', :action => 'entry', :id => 'redmine', :repository_id => 'foo',
281 { :controller => 'repositories', :action => 'raw', :id => 'redmine', :repository_id => 'foo',
282 :path => @path_hash[:param], :rev => '2', :format => 'raw' }
282 :path => @path_hash[:param], :rev => '2' }
283 )
283 )
284 assert_routing(
284 assert_routing(
285 { :method => 'get',
285 { :method => 'get',
@@ -311,8 +311,8 class RoutingRepositoriesTest < ActionController::IntegrationTest
311 assert_routing(
311 assert_routing(
312 { :method => 'get',
312 { :method => 'get',
313 :path => "/projects/redmine/repository/raw/#{@path_hash[:path]}" },
313 :path => "/projects/redmine/repository/raw/#{@path_hash[:path]}" },
314 { :controller => 'repositories', :action => 'entry', :id => 'redmine',
314 { :controller => 'repositories', :action => 'raw', :id => 'redmine',
315 :path => @path_hash[:param], :format => 'raw' }
315 :path => @path_hash[:param] }
316 )
316 )
317 assert_routing(
317 assert_routing(
318 { :method => 'get',
318 { :method => 'get',
@@ -355,8 +355,8 class RoutingRepositoriesTest < ActionController::IntegrationTest
355 assert_routing(
355 assert_routing(
356 { :method => 'get',
356 { :method => 'get',
357 :path => "/projects/redmine/repository/foo/raw/#{@path_hash[:path]}" },
357 :path => "/projects/redmine/repository/foo/raw/#{@path_hash[:path]}" },
358 { :controller => 'repositories', :action => 'entry', :id => 'redmine', :repository_id => 'foo',
358 { :controller => 'repositories', :action => 'raw', :id => 'redmine', :repository_id => 'foo',
359 :path => @path_hash[:param], :format => 'raw' }
359 :path => @path_hash[:param] }
360 )
360 )
361 assert_routing(
361 assert_routing(
362 { :method => 'get',
362 { :method => 'get',
General Comments 0
You need to be logged in to leave comments. Login now