Remove InvalidId
It was a NoOp in our Non-mongo world. So it is safe to remove. Signed-off-by: Sebastian Spaeth <Sebastian@SSpaeth.de>
This commit is contained in:
parent
9536988425
commit
7c029a1f33
@ -24,7 +24,6 @@ Currently:
|
|||||||
- ObjectId "class": It's a function mostly doing
|
- ObjectId "class": It's a function mostly doing
|
||||||
int(init_arg) to convert string primary keys into
|
int(init_arg) to convert string primary keys into
|
||||||
integer primary keys.
|
integer primary keys.
|
||||||
- InvalidId exception
|
|
||||||
- DESCENDING "constant"
|
- DESCENDING "constant"
|
||||||
"""
|
"""
|
||||||
|
|
||||||
@ -32,14 +31,7 @@ Currently:
|
|||||||
DESCENDING = object() # a unique object for this "constant"
|
DESCENDING = object() # a unique object for this "constant"
|
||||||
|
|
||||||
|
|
||||||
class InvalidId(Exception):
|
|
||||||
pass
|
|
||||||
|
|
||||||
|
|
||||||
def ObjectId(value=None):
|
def ObjectId(value=None):
|
||||||
if value is None:
|
if value is None:
|
||||||
return None
|
return None
|
||||||
try:
|
|
||||||
return int(value)
|
return int(value)
|
||||||
except ValueError:
|
|
||||||
raise InvalidId("%r is an invalid id" % value)
|
|
||||||
|
@ -15,6 +15,6 @@
|
|||||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
#TODO: check now after mongo removal if we can't rip out a layer of abstraction
|
#TODO: check now after mongo removal if we can't rip out a layer of abstraction
|
||||||
from mediagoblin.db.sql.fake import ObjectId, InvalidId, DESCENDING
|
from mediagoblin.db.sql.fake import ObjectId, DESCENDING
|
||||||
from mediagoblin.db.sql.util import atomic_update, check_media_slug_used, \
|
from mediagoblin.db.sql.util import atomic_update, check_media_slug_used, \
|
||||||
media_entries_for_tag_slug, check_collection_slug_used
|
media_entries_for_tag_slug, check_collection_slug_used
|
||||||
|
@ -20,7 +20,7 @@ from urlparse import urljoin
|
|||||||
from werkzeug.exceptions import Forbidden
|
from werkzeug.exceptions import Forbidden
|
||||||
from werkzeug.urls import url_quote
|
from werkzeug.urls import url_quote
|
||||||
|
|
||||||
from mediagoblin.db.util import ObjectId, InvalidId
|
from mediagoblin.db.util import ObjectId
|
||||||
from mediagoblin.db.sql.models import User
|
from mediagoblin.db.sql.models import User
|
||||||
from mediagoblin.tools.response import redirect, render_404
|
from mediagoblin.tools.response import redirect, render_404
|
||||||
|
|
||||||
@ -134,14 +134,10 @@ def get_user_media_entry(controller):
|
|||||||
|
|
||||||
# no media via slug? Grab it via ObjectId
|
# no media via slug? Grab it via ObjectId
|
||||||
if not media:
|
if not media:
|
||||||
try:
|
|
||||||
media = request.db.MediaEntry.find_one(
|
media = request.db.MediaEntry.find_one(
|
||||||
{'id': ObjectId(request.matchdict['media']),
|
{'id': ObjectId(request.matchdict['media']),
|
||||||
'state': u'processed',
|
'state': u'processed',
|
||||||
'uploader': user.id})
|
'uploader': user.id})
|
||||||
except InvalidId:
|
|
||||||
return render_404(request)
|
|
||||||
|
|
||||||
# Still no media? Okay, 404.
|
# Still no media? Okay, 404.
|
||||||
if not media:
|
if not media:
|
||||||
return render_404(request)
|
return render_404(request)
|
||||||
@ -210,13 +206,9 @@ def get_media_entry_by_id(controller):
|
|||||||
"""
|
"""
|
||||||
@wraps(controller)
|
@wraps(controller)
|
||||||
def wrapper(request, *args, **kwargs):
|
def wrapper(request, *args, **kwargs):
|
||||||
try:
|
|
||||||
media = request.db.MediaEntry.find_one(
|
media = request.db.MediaEntry.find_one(
|
||||||
{'id': ObjectId(request.matchdict['media']),
|
{'id': ObjectId(request.matchdict['media']),
|
||||||
'state': u'processed'})
|
'state': u'processed'})
|
||||||
except InvalidId:
|
|
||||||
return render_404(request)
|
|
||||||
|
|
||||||
# Still no media? Okay, 404.
|
# Still no media? Okay, 404.
|
||||||
if not media:
|
if not media:
|
||||||
return render_404(request)
|
return render_404(request)
|
||||||
|
@ -15,7 +15,7 @@
|
|||||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
from mediagoblin.db.util import ObjectId, InvalidId
|
from mediagoblin.db.util import ObjectId
|
||||||
|
|
||||||
_log = logging.getLogger(__name__)
|
_log = logging.getLogger(__name__)
|
||||||
|
|
||||||
@ -29,17 +29,11 @@ def setup_user_in_request(request):
|
|||||||
request.user = None
|
request.user = None
|
||||||
return
|
return
|
||||||
|
|
||||||
try:
|
request.user = User.query.get(request.session['user_id'])
|
||||||
oid = ObjectId(request.session['user_id'])
|
|
||||||
except InvalidId:
|
|
||||||
user = None
|
|
||||||
else:
|
|
||||||
user = request.db.User.find_one({'id': oid})
|
|
||||||
|
|
||||||
if not user:
|
if not request.user:
|
||||||
# Something's wrong... this user doesn't exist? Invalidate
|
# Something's wrong... this user doesn't exist? Invalidate
|
||||||
# this session.
|
# this session.
|
||||||
_log.warn("Killing session for user id %r", request.session['user_id'])
|
_log.warn("Killing session for user id %r", request.session['user_id'])
|
||||||
request.session.invalidate()
|
request.session.invalidate()
|
||||||
|
|
||||||
request.user = user
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user