Convert return HttpException to raise HttpException
controllers (view function) raise HttpException's and do not return them. Signed-off-by: Sebastian Spaeth <Sebastian@SSpaeth.de>
This commit is contained in:
parent
785b287fcb
commit
cfa922295e
@ -14,10 +14,11 @@
|
|||||||
# You should have received a copy of the GNU Affero General Public License
|
# You should have received a copy of the GNU Affero General Public License
|
||||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
from werkzeug.exceptions import Forbidden
|
||||||
|
|
||||||
from mediagoblin.db.util import DESCENDING
|
from mediagoblin.db.util import DESCENDING
|
||||||
from mediagoblin.decorators import require_active_login
|
from mediagoblin.decorators import require_active_login
|
||||||
from mediagoblin.tools.response import (render_to_response, render_403,
|
from mediagoblin.tools.response import render_to_response
|
||||||
render_404)
|
|
||||||
|
|
||||||
@require_active_login
|
@require_active_login
|
||||||
def admin_processing_panel(request):
|
def admin_processing_panel(request):
|
||||||
@ -26,7 +27,7 @@ def admin_processing_panel(request):
|
|||||||
'''
|
'''
|
||||||
# TODO: Why not a "require_admin_login" decorator throwing a 403 exception?
|
# TODO: Why not a "require_admin_login" decorator throwing a 403 exception?
|
||||||
if not request.user.is_admin:
|
if not request.user.is_admin:
|
||||||
return render_403(request)
|
raise Forbidden()
|
||||||
|
|
||||||
processing_entries = request.db.MediaEntry.find(
|
processing_entries = request.db.MediaEntry.find(
|
||||||
{'state': u'processing'}).sort('created', DESCENDING)
|
{'state': u'processing'}).sort('created', DESCENDING)
|
||||||
|
@ -74,7 +74,7 @@ def user_may_delete_media(controller):
|
|||||||
{'id': ObjectId(request.matchdict['media'])}).uploader
|
{'id': ObjectId(request.matchdict['media'])}).uploader
|
||||||
if not (request.user.is_admin or
|
if not (request.user.is_admin or
|
||||||
request.user.id == uploader_id):
|
request.user.id == uploader_id):
|
||||||
return Forbidden()
|
raise Forbidden()
|
||||||
|
|
||||||
return controller(request, *args, **kwargs)
|
return controller(request, *args, **kwargs)
|
||||||
|
|
||||||
@ -91,7 +91,7 @@ def user_may_alter_collection(controller):
|
|||||||
{'username': request.matchdict['user']}).id
|
{'username': request.matchdict['user']}).id
|
||||||
if not (request.user.is_admin or
|
if not (request.user.is_admin or
|
||||||
request.user.id == creator_id):
|
request.user.id == creator_id):
|
||||||
return Forbidden()
|
raise Forbidden()
|
||||||
|
|
||||||
return controller(request, *args, **kwargs)
|
return controller(request, *args, **kwargs)
|
||||||
|
|
||||||
|
@ -41,7 +41,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 Forbidden("User may not edit this media")
|
raise Forbidden("User may not edit this media")
|
||||||
|
|
||||||
defaults = dict(
|
defaults = dict(
|
||||||
title=media.title,
|
title=media.title,
|
||||||
@ -165,7 +165,7 @@ def edit_attachments(request, media):
|
|||||||
{'media': media,
|
{'media': media,
|
||||||
'form': form})
|
'form': form})
|
||||||
else:
|
else:
|
||||||
return Forbidden("Attachments are disabled")
|
raise Forbidden("Attachments are disabled")
|
||||||
|
|
||||||
|
|
||||||
@require_active_login
|
@require_active_login
|
||||||
|
@ -130,7 +130,7 @@ class CsrfMeddleware(BaseMeddleware):
|
|||||||
# the CSRF cookie must be present in the request
|
# the CSRF cookie must be present in the request
|
||||||
errstr = 'CSRF cookie not present'
|
errstr = 'CSRF cookie not present'
|
||||||
_log.error(errstr)
|
_log.error(errstr)
|
||||||
return Forbidden(errstr)
|
raise 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)
|
||||||
@ -145,4 +145,4 @@ class CsrfMeddleware(BaseMeddleware):
|
|||||||
# present; either way, the request is denied
|
# present; either way, the request is denied
|
||||||
errstr = 'CSRF validation failed'
|
errstr = 'CSRF validation failed'
|
||||||
_log.error(errstr)
|
_log.error(errstr)
|
||||||
return Forbidden(errstr)
|
raise Forbidden(errstr)
|
||||||
|
@ -142,7 +142,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 Forbidden()
|
raise 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]
|
||||||
@ -156,7 +156,7 @@ def api_auth(controller):
|
|||||||
'status': 403,
|
'status': 403,
|
||||||
'errors': auth.errors})
|
'errors': auth.errors})
|
||||||
|
|
||||||
return Forbidden()
|
raise Forbidden()
|
||||||
|
|
||||||
return controller(request, *args, **kw)
|
return controller(request, *args, **kw)
|
||||||
|
|
||||||
|
@ -48,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 BadRequest()
|
raise 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 BadRequest()
|
raise BadRequest()
|
||||||
|
|
||||||
media_file = request.files['file']
|
media_file = request.files['file']
|
||||||
|
|
||||||
@ -130,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 Forbidden()
|
raise Forbidden()
|
||||||
|
|
||||||
user_data = {
|
user_data = {
|
||||||
'username': request.user.username,
|
'username': request.user.username,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user