##// END OF EJS Templates
core: no longer rely on webob exception inside get_or_404 function....
marcink -
r1956:a7a935de default
parent child Browse files
Show More
@@ -221,6 +221,7 b' class RepoAppView(BaseAppView):'
221
221
222 return default
222 return default
223
223
224
224 class DataGridAppView(object):
225 class DataGridAppView(object):
225 """
226 """
226 Common class to have re-usable grid rendering components
227 Common class to have re-usable grid rendering components
@@ -55,7 +55,7 b' class AdminMainView(BaseAppView):'
55 """
55 """
56
56
57 pull_request_id = self.request.matchdict.get('pull_request_id')
57 pull_request_id = self.request.matchdict.get('pull_request_id')
58 pull_request = PullRequest.get_or_404(pull_request_id, pyramid_exc=True)
58 pull_request = PullRequest.get_or_404(pull_request_id)
59 repo_name = pull_request.target_repo.repo_name
59 repo_name = pull_request.target_repo.repo_name
60
60
61 raise HTTPFound(
61 raise HTTPFound(
@@ -159,7 +159,7 b' class AdminUsersView(BaseAppView, DataGr'
159 c = self.load_default_context()
159 c = self.load_default_context()
160
160
161 user_id = self.request.matchdict.get('user_id')
161 user_id = self.request.matchdict.get('user_id')
162 c.user = User.get_or_404(user_id, pyramid_exc=True)
162 c.user = User.get_or_404(user_id)
163 self._redirect_for_default_user(c.user.username)
163 self._redirect_for_default_user(c.user.username)
164
164
165 c.active = 'auth_tokens'
165 c.active = 'auth_tokens'
@@ -194,7 +194,7 b' class AdminUsersView(BaseAppView, DataGr'
194 c = self.load_default_context()
194 c = self.load_default_context()
195
195
196 user_id = self.request.matchdict.get('user_id')
196 user_id = self.request.matchdict.get('user_id')
197 c.user = User.get_or_404(user_id, pyramid_exc=True)
197 c.user = User.get_or_404(user_id)
198
198
199 self._redirect_for_default_user(c.user.username)
199 self._redirect_for_default_user(c.user.username)
200
200
@@ -227,14 +227,14 b' class AdminUsersView(BaseAppView, DataGr'
227 c = self.load_default_context()
227 c = self.load_default_context()
228
228
229 user_id = self.request.matchdict.get('user_id')
229 user_id = self.request.matchdict.get('user_id')
230 c.user = User.get_or_404(user_id, pyramid_exc=True)
230 c.user = User.get_or_404(user_id)
231 self._redirect_for_default_user(c.user.username)
231 self._redirect_for_default_user(c.user.username)
232 user_data = c.user.get_api_data()
232 user_data = c.user.get_api_data()
233
233
234 del_auth_token = self.request.POST.get('del_auth_token')
234 del_auth_token = self.request.POST.get('del_auth_token')
235
235
236 if del_auth_token:
236 if del_auth_token:
237 token = UserApiKeys.get_or_404(del_auth_token, pyramid_exc=True)
237 token = UserApiKeys.get_or_404(del_auth_token)
238 token_data = token.get_api_data()
238 token_data = token.get_api_data()
239
239
240 AuthTokenModel().delete(del_auth_token, c.user.user_id)
240 AuthTokenModel().delete(del_auth_token, c.user.user_id)
@@ -257,7 +257,7 b' class AdminUsersView(BaseAppView, DataGr'
257 c = self.load_default_context()
257 c = self.load_default_context()
258
258
259 user_id = self.request.matchdict.get('user_id')
259 user_id = self.request.matchdict.get('user_id')
260 c.user = User.get_or_404(user_id, pyramid_exc=True)
260 c.user = User.get_or_404(user_id)
261 self._redirect_for_default_user(c.user.username)
261 self._redirect_for_default_user(c.user.username)
262
262
263 c.active = 'emails'
263 c.active = 'emails'
@@ -276,7 +276,7 b' class AdminUsersView(BaseAppView, DataGr'
276 c = self.load_default_context()
276 c = self.load_default_context()
277
277
278 user_id = self.request.matchdict.get('user_id')
278 user_id = self.request.matchdict.get('user_id')
279 c.user = User.get_or_404(user_id, pyramid_exc=True)
279 c.user = User.get_or_404(user_id)
280 self._redirect_for_default_user(c.user.username)
280 self._redirect_for_default_user(c.user.username)
281
281
282 email = self.request.POST.get('new_email')
282 email = self.request.POST.get('new_email')
@@ -307,7 +307,7 b' class AdminUsersView(BaseAppView, DataGr'
307 c = self.load_default_context()
307 c = self.load_default_context()
308
308
309 user_id = self.request.matchdict.get('user_id')
309 user_id = self.request.matchdict.get('user_id')
310 c.user = User.get_or_404(user_id, pyramid_exc=True)
310 c.user = User.get_or_404(user_id)
311 self._redirect_for_default_user(c.user.username)
311 self._redirect_for_default_user(c.user.username)
312
312
313 email_id = self.request.POST.get('del_email_id')
313 email_id = self.request.POST.get('del_email_id')
@@ -334,7 +334,7 b' class AdminUsersView(BaseAppView, DataGr'
334 c = self.load_default_context()
334 c = self.load_default_context()
335
335
336 user_id = self.request.matchdict.get('user_id')
336 user_id = self.request.matchdict.get('user_id')
337 c.user = User.get_or_404(user_id, pyramid_exc=True)
337 c.user = User.get_or_404(user_id)
338 self._redirect_for_default_user(c.user.username)
338 self._redirect_for_default_user(c.user.username)
339
339
340 c.active = 'ips'
340 c.active = 'ips'
@@ -357,7 +357,7 b' class AdminUsersView(BaseAppView, DataGr'
357 c = self.load_default_context()
357 c = self.load_default_context()
358
358
359 user_id = self.request.matchdict.get('user_id')
359 user_id = self.request.matchdict.get('user_id')
360 c.user = User.get_or_404(user_id, pyramid_exc=True)
360 c.user = User.get_or_404(user_id)
361 # NOTE(marcink): this view is allowed for default users, as we can
361 # NOTE(marcink): this view is allowed for default users, as we can
362 # edit their IP white list
362 # edit their IP white list
363
363
@@ -407,7 +407,7 b' class AdminUsersView(BaseAppView, DataGr'
407 c = self.load_default_context()
407 c = self.load_default_context()
408
408
409 user_id = self.request.matchdict.get('user_id')
409 user_id = self.request.matchdict.get('user_id')
410 c.user = User.get_or_404(user_id, pyramid_exc=True)
410 c.user = User.get_or_404(user_id)
411 # NOTE(marcink): this view is allowed for default users, as we can
411 # NOTE(marcink): this view is allowed for default users, as we can
412 # edit their IP white list
412 # edit their IP white list
413
413
@@ -436,7 +436,7 b' class AdminUsersView(BaseAppView, DataGr'
436 c = self.load_default_context()
436 c = self.load_default_context()
437
437
438 user_id = self.request.matchdict.get('user_id')
438 user_id = self.request.matchdict.get('user_id')
439 c.user = User.get_or_404(user_id, pyramid_exc=True)
439 c.user = User.get_or_404(user_id)
440 c.data = c.user.group_member
440 c.data = c.user.group_member
441 self._redirect_for_default_user(c.user.username)
441 self._redirect_for_default_user(c.user.username)
442 groups = [UserGroupModel.get_user_groups_as_dict(group.users_group)
442 groups = [UserGroupModel.get_user_groups_as_dict(group.users_group)
@@ -456,7 +456,7 b' class AdminUsersView(BaseAppView, DataGr'
456 c = self.load_default_context()
456 c = self.load_default_context()
457
457
458 user_id = self.request.matchdict.get('user_id')
458 user_id = self.request.matchdict.get('user_id')
459 c.user = User.get_or_404(user_id, pyramid_exc=True)
459 c.user = User.get_or_404(user_id)
460 self._redirect_for_default_user(c.user.username)
460 self._redirect_for_default_user(c.user.username)
461
461
462 users_groups = set(self.request.POST.getall('users_group_id'))
462 users_groups = set(self.request.POST.getall('users_group_id'))
@@ -484,7 +484,7 b' class AdminUsersView(BaseAppView, DataGr'
484 c = self.load_default_context()
484 c = self.load_default_context()
485
485
486 user_id = self.request.matchdict.get('user_id')
486 user_id = self.request.matchdict.get('user_id')
487 c.user = User.get_or_404(user_id, pyramid_exc=True)
487 c.user = User.get_or_404(user_id)
488 self._redirect_for_default_user(c.user.username)
488 self._redirect_for_default_user(c.user.username)
489 c.active = 'audit'
489 c.active = 'audit'
490
490
@@ -211,7 +211,7 b' class MyAccountView(BaseAppView, DataGri'
211 del_auth_token = self.request.POST.get('del_auth_token')
211 del_auth_token = self.request.POST.get('del_auth_token')
212
212
213 if del_auth_token:
213 if del_auth_token:
214 token = UserApiKeys.get_or_404(del_auth_token, pyramid_exc=True)
214 token = UserApiKeys.get_or_404(del_auth_token)
215 token_data = token.get_api_data()
215 token_data = token.get_api_data()
216
216
217 AuthTokenModel().delete(del_auth_token, c.user.user_id)
217 AuthTokenModel().delete(del_auth_token, c.user.user_id)
@@ -279,7 +279,7 b' class MyAccountView(BaseAppView, DataGri'
279
279
280 del_email_id = self.request.POST.get('del_email_id')
280 del_email_id = self.request.POST.get('del_email_id')
281 if del_email_id:
281 if del_email_id:
282 email = UserEmailMap.get_or_404(del_email_id, pyramid_exc=True).email
282 email = UserEmailMap.get_or_404(del_email_id).email
283 UserModel().delete_extra_email(c.user.user_id, del_email_id)
283 UserModel().delete_extra_email(c.user.user_id, del_email_id)
284 audit_logger.store_web(
284 audit_logger.store_web(
285 'user.edit.email.delete', action_data={
285 'user.edit.email.delete', action_data={
@@ -492,7 +492,7 b' class RepoCommitsView(RepoAppView):'
492 commit_id = self.request.matchdict['commit_id']
492 commit_id = self.request.matchdict['commit_id']
493 comment_id = self.request.matchdict['comment_id']
493 comment_id = self.request.matchdict['comment_id']
494
494
495 comment = ChangesetComment.get_or_404(safe_int(comment_id))
495 comment = ChangesetComment.get_or_404(comment_id)
496 if not comment:
496 if not comment:
497 log.debug('Comment with id:%s not found, skipping', comment_id)
497 log.debug('Comment with id:%s not found, skipping', comment_id)
498 # comment already deleted in another call probably
498 # comment already deleted in another call probably
@@ -987,7 +987,7 b' class PullrequestsController(BaseRepoCon'
987 @auth.CSRFRequired()
987 @auth.CSRFRequired()
988 @jsonify
988 @jsonify
989 def delete_comment(self, repo_name, comment_id):
989 def delete_comment(self, repo_name, comment_id):
990 comment = ChangesetComment.get_or_404(safe_int(comment_id))
990 comment = ChangesetComment.get_or_404(comment_id)
991 if not comment:
991 if not comment:
992 log.debug('Comment with id:%s not found, skipping', comment_id)
992 log.debug('Comment with id:%s not found, skipping', comment_id)
993 # comment already deleted in another call probably
993 # comment already deleted in another call probably
@@ -206,22 +206,17 b' class BaseModel(object):'
206 return cls.query().get(id_)
206 return cls.query().get(id_)
207
207
208 @classmethod
208 @classmethod
209 def get_or_404(cls, id_, pyramid_exc=False):
209 def get_or_404(cls, id_):
210 if pyramid_exc:
210 from pyramid.httpexceptions import HTTPNotFound
211 # NOTE(marcink): backward compat, once migration to pyramid
212 # this should only use pyramid exceptions
213 from pyramid.httpexceptions import HTTPNotFound
214 else:
215 from webob.exc import HTTPNotFound
216
211
217 try:
212 try:
218 id_ = int(id_)
213 id_ = int(id_)
219 except (TypeError, ValueError):
214 except (TypeError, ValueError):
220 raise HTTPNotFound
215 raise HTTPNotFound()
221
216
222 res = cls.query().get(id_)
217 res = cls.query().get(id_)
223 if not res:
218 if not res:
224 raise HTTPNotFound
219 raise HTTPNotFound()
225 return res
220 return res
226
221
227 @classmethod
222 @classmethod
@@ -3776,16 +3771,12 b' class Gist(Base, BaseModel):'
3776 return h.escape(self.gist_description)
3771 return h.escape(self.gist_description)
3777
3772
3778 @classmethod
3773 @classmethod
3779 def get_or_404(cls, id_, pyramid_exc=False):
3774 def get_or_404(cls, id_):
3780
3775 from pyramid.httpexceptions import HTTPNotFound
3781 if pyramid_exc:
3782 from pyramid.httpexceptions import HTTPNotFound
3783 else:
3784 from webob.exc import HTTPNotFound
3785
3776
3786 res = cls.query().filter(cls.gist_access_id == id_).scalar()
3777 res = cls.query().filter(cls.gist_access_id == id_).scalar()
3787 if not res:
3778 if not res:
3788 raise HTTPNotFound
3779 raise HTTPNotFound()
3789 return res
3780 return res
3790
3781
3791 @classmethod
3782 @classmethod
General Comments 0
You need to be logged in to leave comments. Login now