Convert return HttpException to raise HttpException
authorSebastian Spaeth <Sebastian@SSpaeth.de>
Sun, 23 Dec 2012 10:58:51 +0000 (11:58 +0100)
committerSebastian Spaeth <Sebastian@SSpaeth.de>
Sun, 23 Dec 2012 10:58:51 +0000 (11:58 +0100)
controllers (view function) raise HttpException's and do not return them.

Signed-off-by: Sebastian Spaeth <Sebastian@SSpaeth.de>
mediagoblin/admin/views.py
mediagoblin/decorators.py
mediagoblin/edit/views.py
mediagoblin/meddleware/csrf.py
mediagoblin/plugins/api/tools.py
mediagoblin/plugins/api/views.py

index 9c14c55c313989b27a9dc67d3dd3cfceec66baab..d0665151968648b57c888a64f27aba418fc81932 100644 (file)
 # 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/>.
 
+from werkzeug.exceptions import Forbidden
+
 from mediagoblin.db.util import DESCENDING
 from mediagoblin.decorators import require_active_login
-from mediagoblin.tools.response import (render_to_response, render_403,
-                                        render_404)
+from mediagoblin.tools.response import render_to_response
 
 @require_active_login
 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?
     if not request.user.is_admin:
-        return render_403(request)
+        raise Forbidden()
 
     processing_entries = request.db.MediaEntry.find(
         {'state': u'processing'}).sort('created', DESCENDING)
index e45d327266e03cbe740903963e2fd02478e67ce6..0903dd41937408a929f42783434b0aae296cfaa4 100644 (file)
@@ -74,7 +74,7 @@ def user_may_delete_media(controller):
             {'id': ObjectId(request.matchdict['media'])}).uploader
         if not (request.user.is_admin or
                 request.user.id == uploader_id):
-            return Forbidden()
+            raise Forbidden()
 
         return controller(request, *args, **kwargs)
 
@@ -91,7 +91,7 @@ def user_may_alter_collection(controller):
             {'username': request.matchdict['user']}).id
         if not (request.user.is_admin or
                 request.user.id == creator_id):
-            return Forbidden()
+            raise Forbidden()
 
         return controller(request, *args, **kwargs)
 
index 8840f36f0547b817b71cc4c1f81b8ed84a68c681..9de034bba629979a76337a855c062f3999778c49 100644 (file)
@@ -41,7 +41,7 @@ import mimetypes
 @require_active_login
 def 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(
         title=media.title,
@@ -165,7 +165,7 @@ def edit_attachments(request, media):
             {'media': media,
              'form': form})
     else:
-        return Forbidden("Attachments are disabled")
+        raise Forbidden("Attachments are disabled")
 
 
 @require_active_login
index 65db9827045c326fe8f5677d6314db8cc966bfde..2984ebb9cb8ba55b9eea1d7c2950d8b763189895 100644 (file)
@@ -130,7 +130,7 @@ class CsrfMeddleware(BaseMeddleware):
             # the CSRF cookie must be present in the request
             errstr = 'CSRF cookie not present'
             _log.error(errstr)
-            return Forbidden(errstr)
+            raise Forbidden(errstr)
 
         # get the form token and confirm it matches
         form = CsrfForm(request.form)
@@ -145,4 +145,4 @@ class CsrfMeddleware(BaseMeddleware):
         # present; either way, the request is denied
         errstr = 'CSRF validation failed'
         _log.error(errstr)
-        return Forbidden(errstr)
+        raise Forbidden(errstr)
index 0ef9112755ca0faccb730794ac38d4245c38a13f..03f528cec1734a4bf0af470c84faae5f268b6578 100644 (file)
@@ -142,7 +142,7 @@ def api_auth(controller):
         # If we can't find any authentication methods, we should not let them
         # pass.
         if not auth_candidates:
-            return Forbidden()
+            raise Forbidden()
 
         # For now, just select the first one in the list
         auth = auth_candidates[0]
@@ -156,7 +156,7 @@ def api_auth(controller):
                         'status': 403,
                         'errors': auth.errors})
 
-            return Forbidden()
+            raise Forbidden()
 
         return controller(request, *args, **kw)
 
index 8e02d7bd5b3143ff7ea598581c92843bcaaea305..3d9437e043be566845d4708836ba03051e3fda0b 100644 (file)
@@ -48,13 +48,13 @@ def post_entry(request):
 
     if request.method != 'POST':
         _log.debug('Must POST against post_entry')
-        return BadRequest()
+        raise BadRequest()
 
     if not 'file' in request.files \
             or not isinstance(request.files['file'], FileStorage) \
             or not request.files['file'].stream:
         _log.debug('File field not found')
-        return BadRequest()
+        raise BadRequest()
 
     media_file = request.files['file']
 
@@ -130,7 +130,7 @@ def post_entry(request):
 @api_auth
 def api_test(request):
     if not request.user:
-        return Forbidden()
+        raise Forbidden()
 
     user_data = {
             'username': request.user.username,