Fix #1054 - Add missing attributes to Activity.serialize
authorJessica Tallon <jessica@megworld.co.uk>
Mon, 8 Dec 2014 14:46:48 +0000 (14:46 +0000)
committerJessica Tallon <jessica@megworld.co.uk>
Mon, 8 Dec 2014 14:46:48 +0000 (14:46 +0000)
mediagoblin/db/mixin.py
mediagoblin/federation/views.py
mediagoblin/submit/lib.py

index e650ceb54ae88246f8bd6db0e82237e1a9e7d278..4327537c6718cb5dddb2df61f0e3ecf8bd35d2de 100644 (file)
@@ -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:
index 9823fffe3696d689f290e5dd04556456a8b62596..261872665ec7359d85dd8383ed1d03127cad69aa 100644 (file)
@@ -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),
index 1469bc6a5e8a4e6c8d12d1e0b7eb778807fa6279..541447e45fe9055edbb0156a9ee178a6bcf7578b 100644 (file)
@@ -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