allura-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jetm...@apache.org
Subject [4/9] allura git commit: [#8023] ticket:867 add SiteNotification.user_role, add check role in ThemeProvider.get_site_notification
Date Tue, 08 Dec 2015 11:32:38 GMT
[#8023] ticket:867 add SiteNotification.user_role, add check role in ThemeProvider.get_site_notification


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

Branch: refs/heads/ib/8023a
Commit: 309a1387f2246d3458f110cad873eb8df3237a3b
Parents: 36303a1
Author: Denis Kotov <deniskkotov@gmail.com>
Authored: Wed Dec 2 20:55:01 2015 +0200
Committer: Igor Bondarenko <jetmind2@gmail.com>
Committed: Mon Dec 7 10:28:26 2015 +0200

----------------------------------------------------------------------
 Allura/allura/lib/plugin.py         |  2 ++
 Allura/allura/model/notification.py |  3 ++-
 Allura/allura/tests/test_plugin.py  | 26 ++++++++++++++++++++++++++
 3 files changed, 30 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/allura/blob/309a1387/Allura/allura/lib/plugin.py
----------------------------------------------------------------------
diff --git a/Allura/allura/lib/plugin.py b/Allura/allura/lib/plugin.py
index e061323..e2f6e5b 100644
--- a/Allura/allura/lib/plugin.py
+++ b/Allura/allura/lib/plugin.py
@@ -1316,6 +1316,8 @@ class ThemeProvider(object):
         note = SiteNotification.current()
         if note is None:
             return None
+        if note.user_role is not None and not c.user.my_projects_by_role_name(note.user_role).first():
+            return None
         cookie = request.cookies.get('site-notification', '').split('-')
         if len(cookie) == 3 and cookie[0] == str(note._id):
             views = asint(cookie[1]) + 1

http://git-wip-us.apache.org/repos/asf/allura/blob/309a1387/Allura/allura/model/notification.py
----------------------------------------------------------------------
diff --git a/Allura/allura/model/notification.py b/Allura/allura/model/notification.py
index 01482f0..b9381d0 100644
--- a/Allura/allura/model/notification.py
+++ b/Allura/allura/model/notification.py
@@ -713,10 +713,11 @@ class SiteNotification(MappedClass):
     active = FieldProperty(bool, if_missing=True)
     impressions = FieldProperty(
         int, if_missing=lambda: config.get('site_notification.impressions', 0))
+    user_role = FieldProperty(str, if_missing=None)
 
     @classmethod
     def current(cls):
         note = cls.query.find().sort('_id', -1).limit(1).first()
         if note is None or not note.active:
             return None
-        return note
+        return note
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/allura/blob/309a1387/Allura/allura/tests/test_plugin.py
----------------------------------------------------------------------
diff --git a/Allura/allura/tests/test_plugin.py b/Allura/allura/tests/test_plugin.py
index 272ee35..bf05335 100644
--- a/Allura/allura/tests/test_plugin.py
+++ b/Allura/allura/tests/test_plugin.py
@@ -270,6 +270,7 @@ class TestThemeProvider(object):
     @patch('pylons.request')
     def test_get_site_notification_closed(self, request, response, SiteNotification):
         SiteNotification.current.return_value._id = 'deadbeef'
+        SiteNotification.current.return_value.user_role = None
         request.cookies = {'site-notification': 'deadbeef-1-true'}
         assert_is_none(ThemeProvider().get_site_notification())
         assert not response.set_cookie.called
@@ -281,6 +282,7 @@ class TestThemeProvider(object):
         note = SiteNotification.current.return_value
         note._id = 'deadbeef'
         note.impressions = 2
+        note.user_role = None
         request.cookies = {'site-notification': 'deadbeef-3-false'}
         assert_is_none(ThemeProvider().get_site_notification())
         assert not response.set_cookie.called
@@ -292,6 +294,7 @@ class TestThemeProvider(object):
         note = SiteNotification.current.return_value
         note._id = 'deadbeef'
         note.impressions = 2
+        note.user_role = None
         request.cookies = {'site-notification': 'deadbeef-1-false'}
         assert_is(ThemeProvider().get_site_notification(), note)
         response.set_cookie.assert_called_once_with(
@@ -304,6 +307,7 @@ class TestThemeProvider(object):
         note = SiteNotification.current.return_value
         note._id = 'deadbeef'
         note.impressions = 0
+        note.user_role = None
         request.cookies = {'site-notification': 'deadbeef-1000-false'}
         assert_is(ThemeProvider().get_site_notification(), note)
 
@@ -314,6 +318,7 @@ class TestThemeProvider(object):
         note = SiteNotification.current.return_value
         note._id = 'deadbeef'
         note.impressions = 1
+        note.user_role = None
         request.cookies = {'site-notification': '0ddba11-1000-true'}
         assert_is(ThemeProvider().get_site_notification(), note)
         response.set_cookie.assert_called_once_with(
@@ -326,6 +331,7 @@ class TestThemeProvider(object):
         note = SiteNotification.current.return_value
         note._id = 'deadbeef'
         note.impressions = 0
+        note.user_role = None
         request.cookies = {}
         assert_is(ThemeProvider().get_site_notification(), note)
         response.set_cookie.assert_called_once_with(
@@ -338,6 +344,7 @@ class TestThemeProvider(object):
         note = SiteNotification.current.return_value
         note._id = 'deadbeef'
         note.impressions = 0
+        note.user_role = None
         request.cookies = {'site-notification': 'deadbeef-1000-true-bad'}
         assert_is(ThemeProvider().get_site_notification(), note)
         response.set_cookie.assert_called_once_with(
@@ -372,6 +379,25 @@ class TestThemeProvider(object):
                       g.theme_href.return_value)
         g.theme_href.assert_called_with('images/testapp_24.png')
 
+    @patch('pylons.tmpl_context.user')
+    @patch('allura.model.notification.SiteNotification')
+    def test_get_site_notification_with_role(self, SiteNotification, User):
+        note = SiteNotification.current.return_value
+        note.user_role = 'Test'
+        first = User.my_projects_by_role_name.return_value.first
+        first.return_value = True
+        assert_is(ThemeProvider().get_site_notification(), note)
+
+        first.return_value = False
+        assert_is(ThemeProvider().get_site_notification(), None)
+
+    @patch('allura.model.notification.SiteNotification')
+    def test_get_site_notification_without_role(self, SiteNotification):
+        note = SiteNotification.current.return_value
+        note.user_role = None
+        assert_is(ThemeProvider().get_site_notification(), note)
+
+
 
 class TestLocalAuthenticationProvider(object):
 


Mime
View raw message