From: Jessica Tallon Date: Mon, 8 Dec 2014 14:46:48 +0000 (+0000) Subject: Fix #1054 - Add missing attributes to Activity.serialize X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=35885226061c997d6e95a387d231ddd98dacb4de;p=mediagoblin.git Fix #1054 - Add missing attributes to Activity.serialize --- diff --git a/mediagoblin/db/mixin.py b/mediagoblin/db/mixin.py index e650ceb5..4327537c 100644 --- a/mediagoblin/db/mixin.py +++ b/mediagoblin/db/mixin.py @@ -465,6 +465,11 @@ class ActivityMixin(object): "url": self.get_url(request), "object": self.get_object.serialize(request), "objectType": self.object_type, + "links": { + "self": { + "href": href, + }, + }, } if self.generator: diff --git a/mediagoblin/federation/views.py b/mediagoblin/federation/views.py index 9823fffe..26187266 100644 --- a/mediagoblin/federation/views.py +++ b/mediagoblin/federation/views.py @@ -181,7 +181,7 @@ def feed_endpoint(request): comment = MediaComment(author=request.user.id) comment.unserialize(data["object"], request) comment.save() - + # Create activity for comment generator = create_generator(request) activity = create_activity( @@ -192,11 +192,7 @@ def feed_endpoint(request): generator=generator ) - data = { - "verb": "post", - "object": comment.serialize(request) - } - return json_response(data) + return json_response(activity.serialize(request)) elif obj.get("objectType", None) == "image": # Posting an image to the feed @@ -231,12 +227,9 @@ def feed_endpoint(request): Location.create(data["location"], self) media.save() - api_add_to_feed(request, media) + activity = api_add_to_feed(request, media) - return json_response({ - "verb": "post", - "object": media.serialize(request) - }) + return json_response(activity.serialize(request)) elif obj.get("objectType", None) is None: # They need to tell us what type of object they're giving us. @@ -296,11 +289,16 @@ def feed_endpoint(request): comment.save() - activity = { - "verb": "update", - "object": comment.serialize(request), - } - return json_response(activity) + # Create an update activity + generator = create_generator(request) + activity = create_activity( + verb="update", + actor=request.user, + obj=comment, + generator=generator + ) + + return json_response(activity.serialize(request)) elif obj["objectType"] == "image": image = MediaEntry.query.filter_by(id=obj_id).first() @@ -324,11 +322,16 @@ def feed_endpoint(request): image.generate_slug() image.save() - activity = { - "verb": "update", - "object": image.serialize(request), - } - return json_response(activity) + # Create an update activity + generator = create_generator(request) + activity = create_activity( + verb="update", + actor=request.user, + obj=image, + generator=generator + ) + + return json_response(activity.serialize(request)) elif obj["objectType"] == "person": # check this is the same user if "id" not in obj or obj["id"] != requested_user.id: @@ -339,6 +342,16 @@ def feed_endpoint(request): requested_user.unserialize(obj) requested_user.save() + generator = create_generator(request) + activity = create_activity( + verb="update", + actor=request.user, + obj=requested_user, + generator=generator + ) + + return json_response(activity.serialize(request)) + elif request.method != "GET": return json_error( "Unsupported HTTP method {0}".format(request.method), diff --git a/mediagoblin/submit/lib.py b/mediagoblin/submit/lib.py index 1469bc6a..541447e4 100644 --- a/mediagoblin/submit/lib.py +++ b/mediagoblin/submit/lib.py @@ -294,7 +294,7 @@ def api_add_to_feed(request, entry): add_comment_subscription(request.user, entry) # Create activity - create_activity( + activity = create_activity( verb="post", obj=entry, actor=entry.uploader, @@ -303,4 +303,4 @@ def api_add_to_feed(request, entry): entry.save() run_process_media(entry, feed_url) - return json_response(entry.serialize(request)) + return activity