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