Transition webob.HttpForbidden to webob's exceptions Forbidden
Also the BadRequest exception.
This commit is contained in:
parent
059eaee4df
commit
62d14bf50b
@ -18,6 +18,7 @@ from webob import exc
|
|||||||
from cgi import FieldStorage
|
from cgi import FieldStorage
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
|
|
||||||
|
from werkzeug.exceptions import Forbidden
|
||||||
from werkzeug.utils import secure_filename
|
from werkzeug.utils import secure_filename
|
||||||
|
|
||||||
from mediagoblin import messages
|
from mediagoblin import messages
|
||||||
@ -41,7 +42,7 @@ import mimetypes
|
|||||||
@require_active_login
|
@require_active_login
|
||||||
def edit_media(request, media):
|
def edit_media(request, media):
|
||||||
if not may_edit_media(request, media):
|
if not may_edit_media(request, media):
|
||||||
return exc.HTTPForbidden()
|
return Forbidden("User may not edit this media")
|
||||||
|
|
||||||
defaults = dict(
|
defaults = dict(
|
||||||
title=media.title,
|
title=media.title,
|
||||||
@ -165,7 +166,7 @@ def edit_attachments(request, media):
|
|||||||
{'media': media,
|
{'media': media,
|
||||||
'form': form})
|
'form': form})
|
||||||
else:
|
else:
|
||||||
return exc.HTTPForbidden()
|
return Forbidden("Attachments are disabled")
|
||||||
|
|
||||||
|
|
||||||
@require_active_login
|
@require_active_login
|
||||||
|
@ -17,7 +17,7 @@
|
|||||||
import random
|
import random
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
from webob.exc import HTTPForbidden
|
from werkzeug.exceptions import Forbidden
|
||||||
from wtforms import Form, HiddenField, validators
|
from wtforms import Form, HiddenField, validators
|
||||||
|
|
||||||
from mediagoblin import mg_globals
|
from mediagoblin import mg_globals
|
||||||
@ -128,8 +128,9 @@ class CsrfMeddleware(BaseMeddleware):
|
|||||||
|
|
||||||
if cookie_token is None:
|
if cookie_token is None:
|
||||||
# the CSRF cookie must be present in the request
|
# the CSRF cookie must be present in the request
|
||||||
_log.error('CSRF cookie not present')
|
errstr = 'CSRF cookie not present'
|
||||||
return HTTPForbidden()
|
_log.error(errstr)
|
||||||
|
return Forbidden(errstr)
|
||||||
|
|
||||||
# get the form token and confirm it matches
|
# get the form token and confirm it matches
|
||||||
form = CsrfForm(request.form)
|
form = CsrfForm(request.form)
|
||||||
@ -142,5 +143,6 @@ class CsrfMeddleware(BaseMeddleware):
|
|||||||
|
|
||||||
# either the tokens didn't match or the form token wasn't
|
# either the tokens didn't match or the form token wasn't
|
||||||
# present; either way, the request is denied
|
# present; either way, the request is denied
|
||||||
_log.error('CSRF validation failed')
|
errstr = 'CSRF validation failed'
|
||||||
return HTTPForbidden()
|
_log.error(errstr)
|
||||||
|
return Forbidden(errstr)
|
||||||
|
@ -18,8 +18,9 @@ import logging
|
|||||||
import json
|
import json
|
||||||
|
|
||||||
from functools import wraps
|
from functools import wraps
|
||||||
from webob import exc, Response
|
from webob import Response
|
||||||
from urlparse import urljoin
|
from urlparse import urljoin
|
||||||
|
from werkzeug.exceptions import Forbidden
|
||||||
|
|
||||||
from mediagoblin import mg_globals
|
from mediagoblin import mg_globals
|
||||||
from mediagoblin.tools.pluginapi import PluginManager
|
from mediagoblin.tools.pluginapi import PluginManager
|
||||||
@ -143,7 +144,7 @@ def api_auth(controller):
|
|||||||
# If we can't find any authentication methods, we should not let them
|
# If we can't find any authentication methods, we should not let them
|
||||||
# pass.
|
# pass.
|
||||||
if not auth_candidates:
|
if not auth_candidates:
|
||||||
return exc.HTTPForbidden()
|
return Forbidden()
|
||||||
|
|
||||||
# For now, just select the first one in the list
|
# For now, just select the first one in the list
|
||||||
auth = auth_candidates[0]
|
auth = auth_candidates[0]
|
||||||
@ -157,7 +158,7 @@ def api_auth(controller):
|
|||||||
'status': 403,
|
'status': 403,
|
||||||
'errors': auth.errors})
|
'errors': auth.errors})
|
||||||
|
|
||||||
return exc.HTTPForbidden()
|
return Forbidden()
|
||||||
|
|
||||||
return controller(request, *args, **kw)
|
return controller(request, *args, **kw)
|
||||||
|
|
||||||
|
@ -19,7 +19,8 @@ import logging
|
|||||||
import uuid
|
import uuid
|
||||||
|
|
||||||
from os.path import splitext
|
from os.path import splitext
|
||||||
from webob import exc, Response
|
from webob import Response
|
||||||
|
from werkzeug.exceptions import BadRequest, Forbidden
|
||||||
from werkzeug.utils import secure_filename
|
from werkzeug.utils import secure_filename
|
||||||
from werkzeug.datastructures import FileStorage
|
from werkzeug.datastructures import FileStorage
|
||||||
from celery import registry
|
from celery import registry
|
||||||
@ -47,13 +48,13 @@ def post_entry(request):
|
|||||||
|
|
||||||
if request.method != 'POST':
|
if request.method != 'POST':
|
||||||
_log.debug('Must POST against post_entry')
|
_log.debug('Must POST against post_entry')
|
||||||
return exc.HTTPBadRequest()
|
return BadRequest()
|
||||||
|
|
||||||
if not 'file' in request.files \
|
if not 'file' in request.files \
|
||||||
or not isinstance(request.files['file'], FileStorage) \
|
or not isinstance(request.files['file'], FileStorage) \
|
||||||
or not request.files['file'].stream:
|
or not request.files['file'].stream:
|
||||||
_log.debug('File field not found')
|
_log.debug('File field not found')
|
||||||
return exc.HTTPBadRequest()
|
return BadRequest()
|
||||||
|
|
||||||
media_file = request.files['file']
|
media_file = request.files['file']
|
||||||
|
|
||||||
@ -129,7 +130,7 @@ def post_entry(request):
|
|||||||
@api_auth
|
@api_auth
|
||||||
def api_test(request):
|
def api_test(request):
|
||||||
if not request.user:
|
if not request.user:
|
||||||
return exc.HTTPForbidden()
|
return Forbidden()
|
||||||
|
|
||||||
user_data = {
|
user_data = {
|
||||||
'username': request.user.username,
|
'username': request.user.username,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user