allura-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hei...@apache.org
Subject [14/50] allura git commit: [#8044] ticket:891 Add tool_name parameter to notification API, change API documentation
Date Wed, 27 Jan 2016 20:22:28 GMT
[#8044] ticket:891 Add tool_name parameter to notification API, change API documentation


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

Branch: refs/heads/hs/8035
Commit: 1ec256c5033618836b96719b43d59817cd27e084
Parents: 62cbf93
Author: Denis Kotov <deniskkotov@gmail.com>
Authored: Sat Jan 23 19:26:48 2016 +0200
Committer: Dave Brondsema <dave@brondsema.net>
Committed: Wed Jan 27 12:37:38 2016 -0500

----------------------------------------------------------------------
 Allura/allura/controllers/rest.py           |  3 ++-
 Allura/allura/lib/plugin.py                 |  9 +++++----
 Allura/allura/tests/functional/test_rest.py |  7 ++++---
 Allura/docs/api-rest/api.raml               | 24 +++++++++++++++---------
 4 files changed, 26 insertions(+), 17 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/allura/blob/1ec256c5/Allura/allura/controllers/rest.py
----------------------------------------------------------------------
diff --git a/Allura/allura/controllers/rest.py b/Allura/allura/controllers/rest.py
index 70a9ffd..915517c 100644
--- a/Allura/allura/controllers/rest.py
+++ b/Allura/allura/controllers/rest.py
@@ -90,12 +90,13 @@ class RestController(object):
         return summary
 
     @expose('json:')
-    def notification(self, cookie='', url='', **kw):
+    def notification(self, cookie='', url='', tool_name='', **kw):
         c.api_token = self._authenticate_request()
         user = c.api_token.user if c.api_token else c.user
         r = g.theme._get_site_notification(
             url=url,
             user=user,
+            tool_name=tool_name,
             site_notification_cookie_value=cookie
         )
         if r:

http://git-wip-us.apache.org/repos/asf/allura/blob/1ec256c5/Allura/allura/lib/plugin.py
----------------------------------------------------------------------
diff --git a/Allura/allura/lib/plugin.py b/Allura/allura/lib/plugin.py
index dffd1fa..e76c53c 100644
--- a/Allura/allura/lib/plugin.py
+++ b/Allura/allura/lib/plugin.py
@@ -1310,12 +1310,12 @@ class ThemeProvider(object):
         else:
             return app.icon_url(size)
 
-    def _get_site_notification(self, url='', user=None, site_notification_cookie_value=''):
+    def _get_site_notification(self, url='', user=None, tool_name='', site_notification_cookie_value=''):
         from allura.model.notification import SiteNotification
         note = SiteNotification.current()
         if note is None:
             return None
-        if note.user_role and user.is_anonymous():
+        if note.user_role and (not user or user.is_anonymous()):
             return None
         if note.user_role:
             projects = user.my_projects_by_role_name(note.user_role)
@@ -1324,7 +1324,7 @@ class ThemeProvider(object):
 
         if note.page_regex and re.search(note.page_regex, url) is None:
             return None
-        if note.page_tool_type and (c.app is None or c.app.config.tool_name.lower() != note.page_tool_type.lower()):
+        if note.page_tool_type and (c.app is None or tool_name.lower() != note.page_tool_type.lower()):
             return None
 
         cookie = site_notification_cookie_value.split('-')
@@ -1342,10 +1342,11 @@ class ThemeProvider(object):
 
     def get_site_notification(self):
         from pylons import request, response
-
+        tool_name = c.app.config.tool_name if c.app else ''
         r = self._get_site_notification(
             request.path_qs,
             c.user,
+            tool_name,
             request.cookies.get('site-notification', '')
         )
         if not r:

http://git-wip-us.apache.org/repos/asf/allura/blob/1ec256c5/Allura/allura/tests/functional/test_rest.py
----------------------------------------------------------------------
diff --git a/Allura/allura/tests/functional/test_rest.py b/Allura/allura/tests/functional/test_rest.py
index 3ec58f6..91cf40f 100644
--- a/Allura/allura/tests/functional/test_rest.py
+++ b/Allura/allura/tests/functional/test_rest.py
@@ -392,11 +392,12 @@ class TestRestHome(TestRestApiBase):
         cookie = '{}-1-False'.format(note._id)
         g.theme._get_site_notification = mock.Mock(return_value=(note, cookie))
 
-        r = self.app.get('/rest/notification?url=test_url&cookie=test_cookie')
+        r = self.app.get('/rest/notification?url=test_url&cookie=test_cookie&tool_name=test_tool')
         g.theme._get_site_notification.assert_called_once_with(
             url='test_url',
-            site_notification_cookie_value='test_cookie',
-            user=user
+            user=user,
+            tool_name='test_tool',
+            site_notification_cookie_value='test_cookie'
         )
 
         assert r.status_int == 200

http://git-wip-us.apache.org/repos/asf/allura/blob/1ec256c5/Allura/docs/api-rest/api.raml
----------------------------------------------------------------------
diff --git a/Allura/docs/api-rest/api.raml b/Allura/docs/api-rest/api.raml
index 6326978..9c50d9d 100755
--- a/Allura/docs/api-rest/api.raml
+++ b/Allura/docs/api-rest/api.raml
@@ -35,14 +35,6 @@ documentation:
   - title: API Overview
     content: !include docs.md
 
-/notification:
-  description: |
-    Get current Site Notification
-  uriParameters:
-    cookie:
-      description: site-notification cookie value
-      example: "56a111736c4ff90011b9f932-1-False"
-
 /{neighborhood}:
     description: |
       Neighborhoods are groups of logically related projects, which have the same default
options.
@@ -743,4 +735,18 @@ documentation:
           example: !include examples/userProfile.json,
           schema: !include schemas/userProfile.json
         }
-      }
\ No newline at end of file
+      }
+
+/notification:
+  description: |
+    Get current Site Notification
+  uriParameters:
+    cookie:
+      description: site-notification cookie value
+      example: "56a111736c4ff90011b9f932-1-False"
+    url:
+      description: page where must be shown notification
+      example: "/p/test-project"
+    tool_name:
+      description: tool's name which used on page
+      exaple: "Git"
\ No newline at end of file


Mime
View raw message