##// END OF EJS Templates
missing files or bad files revisions should return 404s not redirects - ref #808
marcink -
r3621:fe012b7d beta
parent child Browse files
Show More
@@ -56,6 +56,7 b' from rhodecode.model.db import Repositor'
56
56
57 from rhodecode.controllers.changeset import anchor_url, _ignorews_url,\
57 from rhodecode.controllers.changeset import anchor_url, _ignorews_url,\
58 _context_url, get_line_ctx, get_ignore_ws
58 _context_url, get_line_ctx, get_ignore_ws
59 from webob.exc import HTTPNotFound
59
60
60
61
61 log = logging.getLogger(__name__)
62 log = logging.getLogger(__name__)
@@ -89,9 +90,9 b' class FilesController(BaseRepoController'
89 category='warning')
90 category='warning')
90 redirect(h.url('summary_home', repo_name=repo_name))
91 redirect(h.url('summary_home', repo_name=repo_name))
91
92
92 except RepositoryError, e: # including ChangesetDoesNotExistError
93 except RepositoryError, e: # including ChangesetDoesNotExistError
93 h.flash(str(e), category='error')
94 h.flash(str(e), category='error')
94 redirect(h.url('files_home', repo_name=repo_name, revision='tip'))
95 raise HTTPNotFound()
95
96
96 def __get_filenode_or_redirect(self, repo_name, cs, path):
97 def __get_filenode_or_redirect(self, repo_name, cs, path):
97 """
98 """
@@ -109,8 +110,7 b' class FilesController(BaseRepoController'
109 raise RepositoryError('given path is a directory')
110 raise RepositoryError('given path is a directory')
110 except RepositoryError, e:
111 except RepositoryError, e:
111 h.flash(str(e), category='error')
112 h.flash(str(e), category='error')
112 redirect(h.url('files_home', repo_name=repo_name,
113 raise HTTPNotFound()
113 revision=cs.raw_id))
114
114
115 return file_node
115 return file_node
116
116
@@ -122,8 +122,6 b' class FilesController(BaseRepoController'
122 post_revision = request.POST.get('at_rev', None)
122 post_revision = request.POST.get('at_rev', None)
123 if post_revision:
123 if post_revision:
124 cs = self.__get_cs_or_redirect(post_revision, repo_name)
124 cs = self.__get_cs_or_redirect(post_revision, repo_name)
125 redirect(url('files_home', repo_name=c.repo_name,
126 revision=cs.raw_id, f_path=f_path))
127
125
128 c.changeset = self.__get_cs_or_redirect(revision, repo_name)
126 c.changeset = self.__get_cs_or_redirect(revision, repo_name)
129 c.branch = request.GET.get('branch', None)
127 c.branch = request.GET.get('branch', None)
@@ -176,9 +174,8 b' class FilesController(BaseRepoController'
176 else:
174 else:
177 c.authors = c.file_history = []
175 c.authors = c.file_history = []
178 except RepositoryError, e:
176 except RepositoryError, e:
179 h.flash(str(e), category='warning')
177 h.flash(str(e), category='error')
180 redirect(h.url('files_home', repo_name=repo_name,
178 raise HTTPNotFound()
181 revision='tip'))
182
179
183 if request.environ.get('HTTP_X_PARTIAL_XHR'):
180 if request.environ.get('HTTP_X_PARTIAL_XHR'):
184 return render('files/files_ypjax.html')
181 return render('files/files_ypjax.html')
@@ -309,8 +306,7 b' class FilesController(BaseRepoController'
309 author = self.rhodecode_user.full_contact
306 author = self.rhodecode_user.full_contact
310
307
311 if content == old_content:
308 if content == old_content:
312 h.flash(_('No changes'),
309 h.flash(_('No changes'), category='warning')
313 category='warning')
314 return redirect(url('changeset_home', repo_name=c.repo_name,
310 return redirect(url('changeset_home', repo_name=c.repo_name,
315 revision='tip'))
311 revision='tip'))
316 try:
312 try:
@@ -289,12 +289,10 b' removed extra unicode conversion in diff'
289 response = self.app.get(url(controller='files', action='rawfile',
289 response = self.app.get(url(controller='files', action='rawfile',
290 repo_name=HG_REPO,
290 repo_name=HG_REPO,
291 revision=rev,
291 revision=rev,
292 f_path=f_path))
292 f_path=f_path), status=404)
293
293
294 msg = """Revision %s does not exist for this repository""" % (rev)
294 msg = """Revision %s does not exist for this repository""" % (rev)
295 self.checkSessionFlash(response, msg)
295 response.mustcontain(msg)
296
297 self.assertEqual('http://localhost/%s/files/tip/' % HG_REPO, response.headers['location'])
298
296
299 def test_raw_file_wrong_f_path(self):
297 def test_raw_file_wrong_f_path(self):
300 self.log_user()
298 self.log_user()
@@ -303,10 +301,10 b' removed extra unicode conversion in diff'
303 response = self.app.get(url(controller='files', action='rawfile',
301 response = self.app.get(url(controller='files', action='rawfile',
304 repo_name=HG_REPO,
302 repo_name=HG_REPO,
305 revision=rev,
303 revision=rev,
306 f_path=f_path))
304 f_path=f_path), status=404)
307
305
308 msg = "There is no file nor directory at the given path: '%s' at revision %s" % (f_path, rev[:12])
306 msg = "There is no file nor directory at the given path: '%s' at revision %s" % (f_path, rev[:12])
309 self.checkSessionFlash(response, msg)
307 response.mustcontain(msg)
310
308
311 #==========================================================================
309 #==========================================================================
312 # RAW RESPONSE - PLAIN
310 # RAW RESPONSE - PLAIN
@@ -328,11 +326,10 b' removed extra unicode conversion in diff'
328 response = self.app.get(url(controller='files', action='raw',
326 response = self.app.get(url(controller='files', action='raw',
329 repo_name=HG_REPO,
327 repo_name=HG_REPO,
330 revision=rev,
328 revision=rev,
331 f_path=f_path))
329 f_path=f_path), status=404)
330
332 msg = """Revision %s does not exist for this repository""" % (rev)
331 msg = """Revision %s does not exist for this repository""" % (rev)
333 self.checkSessionFlash(response, msg)
332 response.mustcontain(msg)
334
335 self.assertEqual('http://localhost/%s/files/tip/' % HG_REPO, response.headers['location'])
336
333
337 def test_raw_wrong_f_path(self):
334 def test_raw_wrong_f_path(self):
338 self.log_user()
335 self.log_user()
@@ -341,15 +338,40 b' removed extra unicode conversion in diff'
341 response = self.app.get(url(controller='files', action='raw',
338 response = self.app.get(url(controller='files', action='raw',
342 repo_name=HG_REPO,
339 repo_name=HG_REPO,
343 revision=rev,
340 revision=rev,
344 f_path=f_path))
341 f_path=f_path), status=404)
345 msg = "There is no file nor directory at the given path: '%s' at revision %s" % (f_path, rev[:12])
342 msg = "There is no file nor directory at the given path: '%s' at revision %s" % (f_path, rev[:12])
346 self.checkSessionFlash(response, msg)
343 response.mustcontain(msg)
347
344
348 def test_ajaxed_files_list(self):
345 def test_ajaxed_files_list(self):
349 self.log_user()
346 self.log_user()
350 rev = '27cd5cce30c96924232dffcd24178a07ffeb5dfc'
347 rev = '27cd5cce30c96924232dffcd24178a07ffeb5dfc'
351 response = self.app.get(
348 response = self.app.get(
352 url('files_nodelist_home', repo_name=HG_REPO,f_path='/',revision=rev),
349 url('files_nodelist_home', repo_name=HG_REPO, f_path='/',
350 revision=rev),
353 extra_environ={'HTTP_X_PARTIAL_XHR': '1'},
351 extra_environ={'HTTP_X_PARTIAL_XHR': '1'},
354 )
352 )
355 response.mustcontain("vcs/web/simplevcs/views/repository.py")
353 response.mustcontain("vcs/web/simplevcs/views/repository.py")
354
355 def test_add_file_view_hg(self):
356 self.log_user()
357 response = self.app.get(url('files_add_home',
358 repo_name=HG_REPO,
359 revision='tip', f_path='/'))
360
361 def test_add_file_view_git(self):
362 self.log_user()
363 response = self.app.get(url('files_add_home',
364 repo_name=GIT_REPO,
365 revision='tip', f_path='/'))
366
367 def test_edit_file_view_hg(self):
368 self.log_user()
369 response = self.app.get(url('files_edit_home',
370 repo_name=HG_REPO,
371 revision='tip', f_path='vcs/nodes.py'))
372
373 def test_edit_file_view_git(self):
374 self.log_user()
375 response = self.app.get(url('files_edit_home',
376 repo_name=GIT_REPO,
377 revision='tip', f_path='vcs/nodes.py'))
General Comments 0
You need to be logged in to leave comments. Login now