You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@allura.apache.org by jo...@apache.org on 2013/12/16 18:09:56 UTC

[17/36] git commit: [#6831] Added API controller for ForgeActivity

[#6831] Added API controller for ForgeActivity

Signed-off-by: Cory Johns <ad...@users.sf.net>


Project: http://git-wip-us.apache.org/repos/asf/incubator-allura/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-allura/commit/0302ba5e
Tree: http://git-wip-us.apache.org/repos/asf/incubator-allura/tree/0302ba5e
Diff: http://git-wip-us.apache.org/repos/asf/incubator-allura/diff/0302ba5e

Branch: refs/heads/cj/6821
Commit: 0302ba5e704a743dd2772eea54d4657d190075fd
Parents: da7f34a
Author: Cory Johns <ad...@users.sf.net>
Authored: Tue Dec 10 20:42:50 2013 +0000
Committer: Tim Van Steenburgh <tv...@gmail.com>
Committed: Thu Dec 12 05:54:18 2013 +0000

----------------------------------------------------------------------
 ForgeActivity/forgeactivity/main.py | 43 ++++++++++++++++++++++++++++++++
 1 file changed, 43 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/0302ba5e/ForgeActivity/forgeactivity/main.py
----------------------------------------------------------------------
diff --git a/ForgeActivity/forgeactivity/main.py b/ForgeActivity/forgeactivity/main.py
index 3d1e62f..daeb1ce 100644
--- a/ForgeActivity/forgeactivity/main.py
+++ b/ForgeActivity/forgeactivity/main.py
@@ -47,6 +47,7 @@ class ForgeActivityApp(Application):
     def __init__(self, project, config):
         Application.__init__(self, project, config)
         self.root = ForgeActivityController(self)
+        self.api_root = ForgeActivityRestController(self)
 
     def main_menu(self): # pragma no cover
         return []
@@ -132,3 +133,45 @@ class ForgeActivityController(BaseController):
             success=True,
             message=W.follow_toggle.success_message(follow),
             following=follow)
+
+
+class ForgeActivityRestController(BaseController):
+    def __init__(self, app, *args, **kw):
+        super(ForgeActivityRestController, self).__init__(*args, **kw)
+        self.app = app
+
+    @expose('json:')
+    def index(self, **kw):
+        activity_enabled = config.get('activitystream.enabled', False)
+        activity_enabled = request.cookies.get('activitystream.enabled', activity_enabled)
+        activity_enabled = asbool(activity_enabled)
+        if not activity_enabled:
+            raise exc.HTTPNotFound()
+
+        c.follow_toggle = W.follow_toggle
+        if c.project.is_user_project:
+            followee = c.project.user_project_of
+            actor_only = followee != c.user
+        else:
+            followee = c.project
+            actor_only = False
+
+        following = g.director.is_connected(c.user, followee)
+        timeline = g.director.get_timeline(followee, page=kw.get('page', 0),
+                limit=kw.get('limit', 100), actor_only=actor_only,
+                filter_func=perm_check(c.user))
+        return {
+                'following': following,
+                'followee': {
+                    'activity_name': followee.shortname,
+                    'activity_url': followee.url(),
+                    'activity_extras': {},
+                },
+                'timeline': [{
+                        'published': '%s UTC' % a.published,
+                        'actor': a.actor._deinstrument(),
+                        'verb': a.verb,
+                        'obj': a.obj._deinstrument(),
+                        'target': a.target._deinstrument(),
+                    } for a in timeline],
+            }