diff options
author | Jessica Tallon <tsyesika@tsyesika.se> | 2015-10-20 12:24:54 +0000 |
---|---|---|
committer | Jessica Tallon <tsyesika@tsyesika.se> | 2015-10-20 12:24:54 +0000 |
commit | 64a456a4e50b03e4fa2b33ceb208e88d2e02fce7 (patch) | |
tree | f60658eb937886dfd1cc349cab605c13a02942e5 /mediagoblin/api | |
parent | fd703bb4d0665958d853b89f6069eefd8a8c8113 (diff) | |
download | mediagoblin-64a456a4e50b03e4fa2b33ceb208e88d2e02fce7.tar.lz mediagoblin-64a456a4e50b03e4fa2b33ceb208e88d2e02fce7.tar.xz mediagoblin-64a456a4e50b03e4fa2b33ceb208e88d2e02fce7.zip |
Comment changes for federation
This adds a new Comment link table that is used to link between some
object and then the comment object, which can be more or less any
object in Mediagoblin. The MediaComment has been renamed to
TextComment as that more aptly describes what it is. There is
migrations for these changes.
There is also the conslidation of the Report tables into a single
Report table, the same with the Notification objects. This is because
both of them split out MediaEntry and Comment versions into their own
polymorphic versions from a base, this is no longer a meaningful
distinction as comments can be anything.
Diffstat (limited to 'mediagoblin/api')
-rw-r--r-- | mediagoblin/api/views.py | 79 |
1 files changed, 58 insertions, 21 deletions
diff --git a/mediagoblin/api/views.py b/mediagoblin/api/views.py index c515a8fa..671c3b36 100644 --- a/mediagoblin/api/views.py +++ b/mediagoblin/api/views.py @@ -22,7 +22,7 @@ from werkzeug.datastructures import FileStorage from mediagoblin.decorators import oauth_required, require_active_login from mediagoblin.api.decorators import user_has_privilege -from mediagoblin.db.models import User, LocalUser, MediaEntry, MediaComment, Activity +from mediagoblin.db.models import User, LocalUser, MediaEntry, Comment, TextComment, Activity from mediagoblin.tools.federation import create_activity, create_generator from mediagoblin.tools.routing import extract_url_arguments from mediagoblin.tools.response import redirect, json_response, json_error, \ @@ -268,7 +268,7 @@ def feed_endpoint(request, outbox=None): status=403 ) - comment = MediaComment(actor=request.user.id) + comment = TextComment(actor=request.user.id) comment.unserialize(data["object"], request) comment.save() @@ -278,7 +278,7 @@ def feed_endpoint(request, outbox=None): verb="post", actor=request.user, obj=comment, - target=comment.get_entry, + target=comment.get_reply_to(), generator=generator ) @@ -286,12 +286,22 @@ def feed_endpoint(request, outbox=None): elif obj.get("objectType", None) == "image": # Posting an image to the feed - media_id = int(extract_url_arguments( + media_id = extract_url_arguments( url=data["object"]["id"], urlmap=request.app.url_map - )["id"]) + )["id"] - media = MediaEntry.query.filter_by(id=media_id).first() + # Build public_id + public_id = request.urlgen( + "mediagoblin.api.object", + object_type=obj["objectType"], + id=media_id, + qualified=True + ) + + media = MediaEntry.query.filter_by( + public_id=public_id + ).first() if media is None: return json_response( @@ -345,10 +355,17 @@ def feed_endpoint(request, outbox=None): if "id" not in obj: return json_error("Object ID has not been specified.") - obj_id = int(extract_url_arguments( + obj_id = extract_url_arguments( url=obj["id"], urlmap=request.app.url_map - )["id"]) + )["id"] + + public_id = request.urlgen( + "mediagoblin.api.object", + object_type=obj["objectType"], + id=obj_id, + qualified=True + ) # Now try and find object if obj["objectType"] == "comment": @@ -358,7 +375,9 @@ def feed_endpoint(request, outbox=None): status=403 ) - comment = MediaComment.query.filter_by(id=obj_id).first() + comment = TextComment.query.filter_by( + public_id=public_id + ).first() if comment is None: return json_error( "No such 'comment' with id '{0}'.".format(obj_id) @@ -391,7 +410,9 @@ def feed_endpoint(request, outbox=None): return json_response(activity.serialize(request)) elif obj["objectType"] == "image": - image = MediaEntry.query.filter_by(id=obj_id).first() + image = MediaEntry.query.filter_by( + public_id=public_id + ).first() if image is None: return json_error( "No such 'image' with the id '{0}'.".format(obj["id"]) @@ -454,15 +475,22 @@ def feed_endpoint(request, outbox=None): return json_error("Object ID has not been specified.") # Parse out the object ID - obj_id = int(extract_url_arguments( + obj_id = extract_url_arguments( url=obj["id"], urlmap=request.app.url_map - )["id"]) + )["id"] + + public_id = request.urlgen( + "mediagoblin.api.object", + object_type=obj["objectType"], + id=obj_id, + qualified=True + ) if obj.get("objectType", None) == "comment": # Find the comment asked for - comment = MediaComment.query.filter_by( - id=obj_id, + comment = TextComment.query.filter_by( + public_id=public_id, actor=request.user.id ).first() @@ -491,7 +519,7 @@ def feed_endpoint(request, outbox=None): if obj.get("objectType", None) == "image": # Find the image entry = MediaEntry.query.filter_by( - id=obj_id, + public_id=public_id, actor=request.user.id ).first() @@ -500,10 +528,6 @@ def feed_endpoint(request, outbox=None): "No such 'image' with id '{0}'.".format(obj_id) ) - # Okay lets do our best to ensure there is a public_id for - # this image, there most likely is but it's important! - entry.get_public_id(request.urlgen) - # Make the delete activity generator = create_generator(request) activity = create_activity( @@ -621,7 +645,14 @@ def object_endpoint(request): status=404 ) - media = MediaEntry.query.filter_by(id=object_id).first() + public_id = request.urlgen( + "mediagoblin.api.object", + object_type=object_type, + id=object_id, + qualified=True + ) + + media = MediaEntry.query.filter_by(public_id=public_id).first() if media is None: return json_error( "Can't find '{0}' with ID '{1}'".format(object_type, object_id), @@ -633,7 +664,13 @@ def object_endpoint(request): @oauth_required def object_comments(request): """ Looks up for the comments on a object """ - media = MediaEntry.query.filter_by(id=request.matchdict["id"]).first() + public_id = request.urlgen( + "mediagoblin.api.object", + object_type=request.matchdict["object_type"], + id=request.matchdict["id"], + qualified=True + ) + media = MediaEntry.query.filter_by(public_id=public_id).first() if media is None: return json_error("Can't find '{0}' with ID '{1}'".format( request.matchdict["object_type"], |