Add test for get_all_media()
[mediagoblin.git] / mediagoblin / decorators.py
index 952b45724b7dbcad02111f6df8965c39bab12133..daeddb3f199352258988eef024d4022b705cce29 100644 (file)
@@ -23,7 +23,8 @@ from six.moves.urllib.parse import urljoin
 
 from mediagoblin import mg_globals as mgg
 from mediagoblin import messages
-from mediagoblin.db.models import MediaEntry, LocalUser, MediaComment, AccessToken
+from mediagoblin.db.models import MediaEntry, LocalUser, TextComment, \
+                                  AccessToken, Comment
 from mediagoblin.tools.response import (
     redirect, render_404,
     render_user_banned, json_response)
@@ -325,11 +326,11 @@ def allow_reporting(controller):
 
 def get_optional_media_comment_by_id(controller):
     """
-    Pass in a MediaComment based off of a url component. Because of this decor-
-    -ator's use in filing Media or Comment Reports, it has two valid outcomes.
+    Pass in a Comment based off of a url component. Because of this decor-
+    -ator's use in filing Reports, it has two valid outcomes.
 
     :returns        The view function being wrapped with kwarg `comment` set to
-                        the MediaComment who's id is in the URL. If there is a
+                        the Comment who's id is in the URL. If there is a
                         comment id in the URL and if it is valid.
     :returns        The view function being wrapped with kwarg `comment` set to
                         None. If there is no comment id in the URL.
@@ -339,8 +340,9 @@ def get_optional_media_comment_by_id(controller):
     @wraps(controller)
     def wrapper(request, *args, **kwargs):
         if 'comment' in request.matchdict:
-            comment = MediaComment.query.filter_by(
-                    id=request.matchdict['comment']).first()
+            comment = Comment.query.filter_by(
+                    id=request.matchdict['comment']
+            ).first()
 
             if comment is None:
                 return render_404(request)
@@ -414,14 +416,14 @@ def oauth_required(controller):
                 )
 
         if not valid:
-            error = "Invalid oauth prarameter."
+            error = "Invalid oauth parameter."
             return json_response({"error": error}, status=400)
 
         # Fill user if not already
         token = authorization[u"oauth_token"]
         request.access_token = AccessToken.query.filter_by(token=token).first()
         if request.access_token is not None and request.user is None:
-            user_id = request.access_token.user
+            user_id = request.access_token.actor
             request.user = LocalUser.query.filter_by(id=user_id).first()
 
         return controller(request, *args, **kwargs)