aboutsummaryrefslogtreecommitdiffstats
path: root/mediagoblin/decorators.py
diff options
context:
space:
mode:
authorSebastian Spaeth <Sebastian@SSpaeth.de>2013-01-08 08:59:32 +0100
committerSebastian Spaeth <Sebastian@SSpaeth.de>2013-01-08 08:59:32 +0100
commit7f4e42b0b15aefcc885c9aacefac3a76f2f7b5ad (patch)
treef5cf72fe2dca8c5472d774616eddd8142aa015ce /mediagoblin/decorators.py
parent76e6c2b15ee6a42e754584142e76e7ce9854eec9 (diff)
downloadmediagoblin-7f4e42b0b15aefcc885c9aacefac3a76f2f7b5ad.tar.lz
mediagoblin-7f4e42b0b15aefcc885c9aacefac3a76f2f7b5ad.tar.xz
mediagoblin-7f4e42b0b15aefcc885c9aacefac3a76f2f7b5ad.zip
Fix slug lookup regression (#587)
Removing the Mongo InvalidID legacy code removed an explicit check for "int" for the id lookup. This led the @get_user_media_entry decorator to fail if we looked up a nonexisting non-numerical slug (it tried to query the id with a string, which failed). Cast id to int and return 404 in case it is non-numeric which fixes the regression. It does not fix the underlying problem of slug_or_id lookups that were discussed. Signed-off-by: Sebastian Spaeth <Sebastian@SSpaeth.de>
Diffstat (limited to 'mediagoblin/decorators.py')
-rw-r--r--mediagoblin/decorators.py38
1 files changed, 21 insertions, 17 deletions
diff --git a/mediagoblin/decorators.py b/mediagoblin/decorators.py
index 4ae1b867..5533e81d 100644
--- a/mediagoblin/decorators.py
+++ b/mediagoblin/decorators.py
@@ -17,7 +17,7 @@
from functools import wraps
from urlparse import urljoin
-from werkzeug.exceptions import Forbidden
+from werkzeug.exceptions import Forbidden, NotFound
from werkzeug.urls import url_quote
from mediagoblin.db.models import MediaEntry, User
@@ -120,25 +120,29 @@ def get_user_media_entry(controller):
"""
@wraps(controller)
def wrapper(request, *args, **kwargs):
- user = request.db.User.find_one(
- {'username': request.matchdict['user']})
-
+ user = User.query.filter_by(username=request.matchdict['user']).first()
if not user:
- return render_404(request)
- media = request.db.MediaEntry.find_one(
- {'slug': request.matchdict['media'],
- 'state': u'processed',
- 'uploader': user.id})
+ raise NotFound()
+
+ media = MediaEntry.query.filter_by(
+ slug = request.matchdict['media'],
+ state = u'processed',
+ uploader = user.id).first()
- # no media via slug? Grab it via object id
if not media:
- media = MediaEntry.query.filter_by(
- id=request.matchdict['media'],
- state=u'processed',
- uploader=user.id).first()
- # Still no media? Okay, 404.
- if not media:
- return render_404(request)
+ # no media via slug? Grab it via object id
+ try:
+ media = MediaEntry.query.filter_by(
+ id = int(request.matchdict['media']),
+ state = u'processed',
+ uploader = user.id).first()
+ except ValueError:
+ # media "id" was no int
+ raise NotFound()
+
+ if not media:
+ # no media by that id? Okay, 404.
+ raise NotFound()
return controller(request, media=media, *args, **kwargs)