You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@allura.apache.org by je...@apache.org on 2015/12/08 12:32:42 UTC
[8/9] allura git commit: [#8023] ticket:868 change logic in checking
rights, fix tests
[#8023] ticket:868 change logic in checking rights, fix tests
Project: http://git-wip-us.apache.org/repos/asf/allura/repo
Commit: http://git-wip-us.apache.org/repos/asf/allura/commit/2369f73b
Tree: http://git-wip-us.apache.org/repos/asf/allura/tree/2369f73b
Diff: http://git-wip-us.apache.org/repos/asf/allura/diff/2369f73b
Branch: refs/heads/ib/8023a
Commit: 2369f73b002a654ecbd58639212062f5fb80e261
Parents: 23a5ccb
Author: Denis Kotov <de...@gmail.com>
Authored: Mon Dec 7 19:21:34 2015 +0200
Committer: Denis Kotov <de...@gmail.com>
Committed: Mon Dec 7 19:21:34 2015 +0200
----------------------------------------------------------------------
Allura/allura/lib/plugin.py | 12 +++++-------
Allura/allura/tests/test_plugin.py | 20 ++++++++++----------
2 files changed, 15 insertions(+), 17 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/allura/blob/2369f73b/Allura/allura/lib/plugin.py
----------------------------------------------------------------------
diff --git a/Allura/allura/lib/plugin.py b/Allura/allura/lib/plugin.py
index 43cc98f..7768e2b 100644
--- a/Allura/allura/lib/plugin.py
+++ b/Allura/allura/lib/plugin.py
@@ -1324,14 +1324,12 @@ class ThemeProvider(object):
only_user_project = projects.count() == 1 and projects.first().is_user_project
if projects.count() == 0 or only_user_project:
return None
- tool_matching = False
- url_matching = False
- if note.page_tool_type is None or c.app is not None and c.app.config.tool_name.lower() == note.page_tool_type.lower():
- tool_matching = True
- if note.page_regex is None or re.search(note.page_regex, request.url):
- tool_matching = True
- if not tool_matching and not url_matching:
+
+ if note.page_regex is not None and re.search(note.page_regex, request.url) is None:
+ return None
+ if note.page_tool_type is not None and (c.app is None or c.app.config.tool_name.lower() != note.page_tool_type.lower()):
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/2369f73b/Allura/allura/tests/test_plugin.py
----------------------------------------------------------------------
diff --git a/Allura/allura/tests/test_plugin.py b/Allura/allura/tests/test_plugin.py
index f1693be..2e7baae 100644
--- a/Allura/allura/tests/test_plugin.py
+++ b/Allura/allura/tests/test_plugin.py
@@ -438,8 +438,8 @@ class TestThemeProvider(object):
search.return_value = True
assert_is(ThemeProvider().get_site_notification(), note)
- search.return_value = False
- assert_is(ThemeProvider().get_site_notification(), note)
+ search.return_value = None
+ assert_is(ThemeProvider().get_site_notification(), None)
@patch('allura.model.notification.SiteNotification')
def test_get_site_notification_with_page_tool_type(self, SiteNotification):
@@ -453,10 +453,10 @@ class TestThemeProvider(object):
assert_is(ThemeProvider().get_site_notification(), note)
c.app.config.tool_name.lower.return_value = 'test2'
- assert_is(ThemeProvider().get_site_notification(), note)
+ assert_is(ThemeProvider().get_site_notification(), None)
c.app = None
- assert_is(ThemeProvider().get_site_notification(), note)
+ assert_is(ThemeProvider().get_site_notification(), None)
@patch('re.search')
@patch('allura.model.notification.SiteNotification')
@@ -467,24 +467,24 @@ class TestThemeProvider(object):
c.app = Mock()
note.page_tool_type.lower.return_value = 'test1'
- search.return_value = False
+ search.return_value = None
c.app.config.tool_name.lower.return_value = 'test2'
assert_is(ThemeProvider().get_site_notification(), None)
search.return_value = True
- assert_is(ThemeProvider().get_site_notification(), note)
+ assert_is(ThemeProvider().get_site_notification(), None)
- search.return_value = False
+ search.return_value = None
c.app.config.tool_name.lower.return_value = 'test1'
- assert_is(ThemeProvider().get_site_notification(), note)
+ assert_is(ThemeProvider().get_site_notification(), None)
search.return_value = True
assert_is(ThemeProvider().get_site_notification(), note)
c.app = None
- assert_is(ThemeProvider().get_site_notification(), note)
+ assert_is(ThemeProvider().get_site_notification(), None)
- search.return_value = False
+ search.return_value = None
assert_is(ThemeProvider().get_site_notification(), None)