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/15 15:24:33 UTC
[01/12] allura git commit: [#8023] ticket:868 Added page_regex,
page_tool_type to Sitenotification
Repository: allura
Updated Branches:
refs/heads/ib/8023b [created] 250edeb12
[#8023] ticket:868 Added page_regex, page_tool_type to Sitenotification
Project: http://git-wip-us.apache.org/repos/asf/allura/repo
Commit: http://git-wip-us.apache.org/repos/asf/allura/commit/b77e21ef
Tree: http://git-wip-us.apache.org/repos/asf/allura/tree/b77e21ef
Diff: http://git-wip-us.apache.org/repos/asf/allura/diff/b77e21ef
Branch: refs/heads/ib/8023b
Commit: b77e21ef28b73616fa9efd8289564115bf51d463
Parents: 2254ed2
Author: Denis Kotov <de...@gmail.com>
Authored: Fri Dec 4 15:56:39 2015 +0200
Committer: Igor Bondarenko <je...@gmail.com>
Committed: Tue Dec 15 13:43:02 2015 +0200
----------------------------------------------------------------------
Allura/allura/model/notification.py | 3 +++
1 file changed, 3 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/allura/blob/b77e21ef/Allura/allura/model/notification.py
----------------------------------------------------------------------
diff --git a/Allura/allura/model/notification.py b/Allura/allura/model/notification.py
index b9381d0..b9be654 100644
--- a/Allura/allura/model/notification.py
+++ b/Allura/allura/model/notification.py
@@ -714,6 +714,9 @@ class SiteNotification(MappedClass):
impressions = FieldProperty(
int, if_missing=lambda: config.get('site_notification.impressions', 0))
user_role = FieldProperty(str, if_missing=None)
+ page_regex = FieldProperty(str, if_missing=None)
+ page_tool_type = FieldProperty(str, if_missing=None)
+
@classmethod
def current(cls):
[08/12] allura git commit: [#8023] ticket:879 change
get_site_notification, fix tests
Posted by je...@apache.org.
[#8023] ticket:879 change get_site_notification, fix tests
Project: http://git-wip-us.apache.org/repos/asf/allura/repo
Commit: http://git-wip-us.apache.org/repos/asf/allura/commit/697dccfc
Tree: http://git-wip-us.apache.org/repos/asf/allura/tree/697dccfc
Diff: http://git-wip-us.apache.org/repos/asf/allura/diff/697dccfc
Branch: refs/heads/ib/8023b
Commit: 697dccfc92a4095387243e9c2be9e1d5ce499b5a
Parents: 2149cfa
Author: Denis Kotov <de...@gmail.com>
Authored: Fri Dec 11 16:57:34 2015 +0200
Committer: Igor Bondarenko <je...@gmail.com>
Committed: Tue Dec 15 13:43:03 2015 +0200
----------------------------------------------------------------------
Allura/allura/lib/plugin.py | 18 ++++++++----------
Allura/allura/tests/test_plugin.py | 26 +++++++++++++-------------
2 files changed, 21 insertions(+), 23 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/allura/blob/697dccfc/Allura/allura/lib/plugin.py
----------------------------------------------------------------------
diff --git a/Allura/allura/lib/plugin.py b/Allura/allura/lib/plugin.py
index 7768e2b..9247577 100644
--- a/Allura/allura/lib/plugin.py
+++ b/Allura/allura/lib/plugin.py
@@ -1316,18 +1316,16 @@ class ThemeProvider(object):
note = SiteNotification.current()
if note is None:
return None
- if note.user_role is not None and c.user.is_anonymous():
+ if note.user_role and c.user.is_anonymous():
return None
- if note.user_role is not None:
- projects = c.user.my_projects_by_role_name(note.user_role)
- if projects is not None:
- only_user_project = projects.count() == 1 and projects.first().is_user_project
- if projects.count() == 0 or only_user_project:
- return None
-
- if note.page_regex is not None and re.search(note.page_regex, request.url) is None:
+ if note.user_role:
+ projects = c.user.my_projects_by_role_name(note.user_role).all()
+ if len(projects) == 0 or len(projects) == 1 and projects[0].is_user_project:
+ return None
+
+ if note.page_regex and re.search(note.page_regex, request.path_qs) 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()):
+ if note.page_tool_type 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('-')
http://git-wip-us.apache.org/repos/asf/allura/blob/697dccfc/Allura/allura/tests/test_plugin.py
----------------------------------------------------------------------
diff --git a/Allura/allura/tests/test_plugin.py b/Allura/allura/tests/test_plugin.py
index 2e7baae..827ef73 100644
--- a/Allura/allura/tests/test_plugin.py
+++ b/Allura/allura/tests/test_plugin.py
@@ -400,23 +400,23 @@ class TestThemeProvider(object):
note.user_role = 'Test'
note.page_regex = None
note.page_tool_type = None
- projects = User.my_projects_by_role_name.return_value
+ projects = User.my_projects_by_role_name.return_value.all
User.is_anonymous.return_value = True
assert_is(ThemeProvider().get_site_notification(), None)
User.is_anonymous.return_value = False
- projects.count.return_value = 0
+ projects.return_value = []
assert_is(ThemeProvider().get_site_notification(), None)
- projects.count.return_value = 1
- projects.first.return_value.is_user_project = True
+ projects.return_value = [Mock()]
+ projects.return_value[0].is_user_project = True
assert_is(ThemeProvider().get_site_notification(), None)
- projects.first.return_value.is_user_project = False
+ projects.return_value[0].is_user_project = False
assert_is(ThemeProvider().get_site_notification(), note)
- projects.count.return_value = 2
+ projects.projects.return_value = [Mock(), Mock()]
assert_is(ThemeProvider().get_site_notification(), note)
@patch('allura.model.notification.SiteNotification')
@@ -458,33 +458,33 @@ class TestThemeProvider(object):
c.app = None
assert_is(ThemeProvider().get_site_notification(), None)
- @patch('re.search')
+ @patch('pylons.request')
@patch('allura.model.notification.SiteNotification')
- def test_get_site_notification_with_page_tool_type_page_regex(self, SiteNotification, search):
+ def test_get_site_notification_with_page_tool_type_page_regex(self, SiteNotification, request):
note = SiteNotification.current.return_value
note.user_role = None
note.page_regex = 'test'
c.app = Mock()
note.page_tool_type.lower.return_value = 'test1'
- search.return_value = None
+ request.path_qs = 'ttt'
c.app.config.tool_name.lower.return_value = 'test2'
assert_is(ThemeProvider().get_site_notification(), None)
- search.return_value = True
+ request.path_qs = 'test'
assert_is(ThemeProvider().get_site_notification(), None)
- search.return_value = None
+ request.path_qs = 'ttt'
c.app.config.tool_name.lower.return_value = 'test1'
assert_is(ThemeProvider().get_site_notification(), None)
- search.return_value = True
+ request.path_qs = 'test'
assert_is(ThemeProvider().get_site_notification(), note)
c.app = None
assert_is(ThemeProvider().get_site_notification(), None)
- search.return_value = None
+ request.path_qs = 'ttt'
assert_is(ThemeProvider().get_site_notification(), None)
[07/12] allura git commit: [#8023] ticket:868 Tweak docs a bit
Posted by je...@apache.org.
[#8023] ticket:868 Tweak docs a bit
Project: http://git-wip-us.apache.org/repos/asf/allura/repo
Commit: http://git-wip-us.apache.org/repos/asf/allura/commit/2149cfa1
Tree: http://git-wip-us.apache.org/repos/asf/allura/tree/2149cfa1
Diff: http://git-wip-us.apache.org/repos/asf/allura/diff/2149cfa1
Branch: refs/heads/ib/8023b
Commit: 2149cfa19d538bb80b7ab248c6dfc3417f2ee28e
Parents: f5567d4
Author: Igor Bondarenko <je...@gmail.com>
Authored: Tue Dec 8 13:30:42 2015 +0200
Committer: Igor Bondarenko <je...@gmail.com>
Committed: Tue Dec 15 13:43:03 2015 +0200
----------------------------------------------------------------------
Allura/docs/getting_started/administration.rst | 17 ++++++++++-------
1 file changed, 10 insertions(+), 7 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/allura/blob/2149cfa1/Allura/docs/getting_started/administration.rst
----------------------------------------------------------------------
diff --git a/Allura/docs/getting_started/administration.rst b/Allura/docs/getting_started/administration.rst
index f812d8f..84aa018 100644
--- a/Allura/docs/getting_started/administration.rst
+++ b/Allura/docs/getting_started/administration.rst
@@ -283,16 +283,19 @@ manual mongo queries, however:
... impressions: 10,
... content: 'You can now reimport exported project data.',
... user_role: 'Developer',
- ... page_regex: '/p/wiki/(home|browse_pages)/',
+ ... page_regex: '(Home|browse_pages)',
... page_tool_type: 'wiki'
... })
-This will create a notification that will be shown for 10 page views or until the
-user closes it manually. This Notification will be shown only for users with Developer`s rights.
-And if url page is according to `/p/wiki/(home|browse_pages)/` or app tool name is equal to `wiki`.
-An `impressions` value of 0 will show the notification indefinitely (until closed).
-The notification content can contain HTML. Only the most recent notification will be shown,
-unless it has `active:false`, in which case no notification will be shown.
+This will create a notification that will be shown for 10 page views or until
+the user closes it manually. The notification will be shown only for users
+which have role 'Developer' or higher in one of their projects. And if url of
+the current page is matching regex :code:`(Home|browse_pages)` and app
+tool type is :code:`wiki`. An :code:`impressions` value of 0 will show the
+notification indefinitely (until closed). The notification content can contain
+HTML. Only the most recent notification will be shown, unless it has
+:code:`active:false`, in which case no notification will be shown.
+:code:`user_role`, :code:`page_regex` and :code:`page_tool_type` are optional.
.. _delete-projects:
[04/12] allura git commit: [#8023] ticket:867 added check
authorization, changed check user rights
Posted by je...@apache.org.
[#8023] ticket:867 added check authorization, changed check user rights
Project: http://git-wip-us.apache.org/repos/asf/allura/repo
Commit: http://git-wip-us.apache.org/repos/asf/allura/commit/514c0def
Tree: http://git-wip-us.apache.org/repos/asf/allura/tree/514c0def
Diff: http://git-wip-us.apache.org/repos/asf/allura/diff/514c0def
Branch: refs/heads/ib/8023b
Commit: 514c0def9cf0982936c5956123f89d39eabe2f8c
Parents: e877403
Author: Denis Kotov <de...@gmail.com>
Authored: Thu Dec 3 16:26:14 2015 +0200
Committer: Igor Bondarenko <je...@gmail.com>
Committed: Tue Dec 15 13:43:02 2015 +0200
----------------------------------------------------------------------
Allura/allura/lib/plugin.py | 6 +++++-
Allura/allura/tests/test_plugin.py | 20 ++++++++++++++++----
2 files changed, 21 insertions(+), 5 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/allura/blob/514c0def/Allura/allura/lib/plugin.py
----------------------------------------------------------------------
diff --git a/Allura/allura/lib/plugin.py b/Allura/allura/lib/plugin.py
index e2f6e5b..8b7a282 100644
--- a/Allura/allura/lib/plugin.py
+++ b/Allura/allura/lib/plugin.py
@@ -1316,7 +1316,11 @@ 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():
+ if note.user_role is not None and c.user.is_anonymous():
+ return None
+ projects = c.user.my_projects_by_role_name(note.user_role)
+ if note.user_role is not None and \
+ projects.count() == 0 or (projects.count() == 1 and projects.first().is_user_project):
return None
cookie = request.cookies.get('site-notification', '').split('-')
if len(cookie) == 3 and cookie[0] == str(note._id):
http://git-wip-us.apache.org/repos/asf/allura/blob/514c0def/Allura/allura/tests/test_plugin.py
----------------------------------------------------------------------
diff --git a/Allura/allura/tests/test_plugin.py b/Allura/allura/tests/test_plugin.py
index bf05335..0d55330 100644
--- a/Allura/allura/tests/test_plugin.py
+++ b/Allura/allura/tests/test_plugin.py
@@ -384,13 +384,25 @@ class TestThemeProvider(object):
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)
+ projects = User.my_projects_by_role_name.return_value
+
+ User.is_anonymous.return_value = True
+ assert_is(ThemeProvider().get_site_notification(), None)
+
+ User.is_anonymous.return_value = False
+ projects.count.return_value = 0
+ assert_is(ThemeProvider().get_site_notification(), None)
- first.return_value = False
+ projects.count.return_value = 1
+ projects.first.return_value.is_user_project = True
assert_is(ThemeProvider().get_site_notification(), None)
+ projects.first.return_value.is_user_project = False
+ assert_is(ThemeProvider().get_site_notification(), note)
+
+ projects.count.return_value = 2
+ assert_is(ThemeProvider().get_site_notification(), note)
+
@patch('allura.model.notification.SiteNotification')
def test_get_site_notification_without_role(self, SiteNotification):
note = SiteNotification.current.return_value
[11/12] allura git commit: [#8023] ticket:868 change logic in
checking rights, fix tests
Posted by je...@apache.org.
[#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/f5567d44
Tree: http://git-wip-us.apache.org/repos/asf/allura/tree/f5567d44
Diff: http://git-wip-us.apache.org/repos/asf/allura/diff/f5567d44
Branch: refs/heads/ib/8023b
Commit: f5567d4488c42de459c18e5d282574c08afd6ee3
Parents: 35fad31
Author: Denis Kotov <de...@gmail.com>
Authored: Mon Dec 7 19:21:34 2015 +0200
Committer: Igor Bondarenko <je...@gmail.com>
Committed: Tue Dec 15 13:43:03 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/f5567d44/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/f5567d44/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)
[05/12] allura git commit: [#8023] ticket:868 Fixed old tests,
added tests for check check matching
Posted by je...@apache.org.
[#8023] ticket:868 Fixed old tests, added tests for check check matching
Project: http://git-wip-us.apache.org/repos/asf/allura/repo
Commit: http://git-wip-us.apache.org/repos/asf/allura/commit/e53335d8
Tree: http://git-wip-us.apache.org/repos/asf/allura/tree/e53335d8
Diff: http://git-wip-us.apache.org/repos/asf/allura/diff/e53335d8
Branch: refs/heads/ib/8023b
Commit: e53335d863529641c32ed1be8aa13502a05c5008
Parents: 1064173
Author: Denis Kotov <de...@gmail.com>
Authored: Fri Dec 4 17:20:23 2015 +0200
Committer: Igor Bondarenko <je...@gmail.com>
Committed: Tue Dec 15 13:43:03 2015 +0200
----------------------------------------------------------------------
Allura/allura/tests/test_plugin.py | 77 +++++++++++++++++++++++++++++++++
1 file changed, 77 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/allura/blob/e53335d8/Allura/allura/tests/test_plugin.py
----------------------------------------------------------------------
diff --git a/Allura/allura/tests/test_plugin.py b/Allura/allura/tests/test_plugin.py
index 0d55330..f1693be 100644
--- a/Allura/allura/tests/test_plugin.py
+++ b/Allura/allura/tests/test_plugin.py
@@ -271,6 +271,8 @@ class TestThemeProvider(object):
def test_get_site_notification_closed(self, request, response, SiteNotification):
SiteNotification.current.return_value._id = 'deadbeef'
SiteNotification.current.return_value.user_role = None
+ SiteNotification.current.return_value.page_regex = None
+ SiteNotification.current.return_value.page_tool_type = None
request.cookies = {'site-notification': 'deadbeef-1-true'}
assert_is_none(ThemeProvider().get_site_notification())
assert not response.set_cookie.called
@@ -283,6 +285,8 @@ class TestThemeProvider(object):
note._id = 'deadbeef'
note.impressions = 2
note.user_role = None
+ note.page_regex = None
+ note.page_tool_type = None
request.cookies = {'site-notification': 'deadbeef-3-false'}
assert_is_none(ThemeProvider().get_site_notification())
assert not response.set_cookie.called
@@ -295,6 +299,8 @@ class TestThemeProvider(object):
note._id = 'deadbeef'
note.impressions = 2
note.user_role = None
+ note.page_regex = None
+ note.page_tool_type = None
request.cookies = {'site-notification': 'deadbeef-1-false'}
assert_is(ThemeProvider().get_site_notification(), note)
response.set_cookie.assert_called_once_with(
@@ -308,6 +314,8 @@ class TestThemeProvider(object):
note._id = 'deadbeef'
note.impressions = 0
note.user_role = None
+ note.page_regex = None
+ note.page_tool_type = None
request.cookies = {'site-notification': 'deadbeef-1000-false'}
assert_is(ThemeProvider().get_site_notification(), note)
@@ -319,6 +327,8 @@ class TestThemeProvider(object):
note._id = 'deadbeef'
note.impressions = 1
note.user_role = None
+ note.page_regex = None
+ note.page_tool_type = None
request.cookies = {'site-notification': '0ddba11-1000-true'}
assert_is(ThemeProvider().get_site_notification(), note)
response.set_cookie.assert_called_once_with(
@@ -332,6 +342,8 @@ class TestThemeProvider(object):
note._id = 'deadbeef'
note.impressions = 0
note.user_role = None
+ note.page_regex = None
+ note.page_tool_type = None
request.cookies = {}
assert_is(ThemeProvider().get_site_notification(), note)
response.set_cookie.assert_called_once_with(
@@ -345,6 +357,8 @@ class TestThemeProvider(object):
note._id = 'deadbeef'
note.impressions = 0
note.user_role = None
+ note.page_regex = None
+ note.page_tool_type = None
request.cookies = {'site-notification': 'deadbeef-1000-true-bad'}
assert_is(ThemeProvider().get_site_notification(), note)
response.set_cookie.assert_called_once_with(
@@ -384,6 +398,8 @@ class TestThemeProvider(object):
def test_get_site_notification_with_role(self, SiteNotification, User):
note = SiteNotification.current.return_value
note.user_role = 'Test'
+ note.page_regex = None
+ note.page_tool_type = None
projects = User.my_projects_by_role_name.return_value
User.is_anonymous.return_value = True
@@ -407,8 +423,69 @@ class TestThemeProvider(object):
def test_get_site_notification_without_role(self, SiteNotification):
note = SiteNotification.current.return_value
note.user_role = None
+ note.page_regex = None
+ note.page_tool_type = None
assert_is(ThemeProvider().get_site_notification(), note)
+ @patch('re.search')
+ @patch('allura.model.notification.SiteNotification')
+ def test_get_site_notification_with_page_regex(self, SiteNotification, search):
+ note = SiteNotification.current.return_value
+ note.user_role = None
+ note.page_regex = 'test'
+ note.page_tool_type = None
+
+ search.return_value = True
+ assert_is(ThemeProvider().get_site_notification(), note)
+
+ search.return_value = False
+ assert_is(ThemeProvider().get_site_notification(), note)
+
+ @patch('allura.model.notification.SiteNotification')
+ def test_get_site_notification_with_page_tool_type(self, SiteNotification):
+ note = SiteNotification.current.return_value
+ note.user_role = None
+ note.page_regex = None
+ c.app = Mock()
+ note.page_tool_type.lower.return_value = 'test1'
+
+ c.app.config.tool_name.lower.return_value = 'test1'
+ assert_is(ThemeProvider().get_site_notification(), note)
+
+ c.app.config.tool_name.lower.return_value = 'test2'
+ assert_is(ThemeProvider().get_site_notification(), note)
+
+ c.app = None
+ assert_is(ThemeProvider().get_site_notification(), note)
+
+ @patch('re.search')
+ @patch('allura.model.notification.SiteNotification')
+ def test_get_site_notification_with_page_tool_type_page_regex(self, SiteNotification, search):
+ note = SiteNotification.current.return_value
+ note.user_role = None
+ note.page_regex = 'test'
+ c.app = Mock()
+ note.page_tool_type.lower.return_value = 'test1'
+
+ search.return_value = False
+ 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)
+
+ search.return_value = False
+ c.app.config.tool_name.lower.return_value = 'test1'
+ assert_is(ThemeProvider().get_site_notification(), note)
+
+ search.return_value = True
+ assert_is(ThemeProvider().get_site_notification(), note)
+
+ c.app = None
+ assert_is(ThemeProvider().get_site_notification(), note)
+
+ search.return_value = False
+ assert_is(ThemeProvider().get_site_notification(), None)
class TestLocalAuthenticationProvider(object):
[06/12] allura git commit: [#8023] ticket:868 Changed documentation
Posted by je...@apache.org.
[#8023] ticket:868 Changed documentation
Project: http://git-wip-us.apache.org/repos/asf/allura/repo
Commit: http://git-wip-us.apache.org/repos/asf/allura/commit/35fad31c
Tree: http://git-wip-us.apache.org/repos/asf/allura/tree/35fad31c
Diff: http://git-wip-us.apache.org/repos/asf/allura/diff/35fad31c
Branch: refs/heads/ib/8023b
Commit: 35fad31cc45b2510b2f7eb78b158c4db69ea3ff3
Parents: e53335d
Author: Denis Kotov <de...@gmail.com>
Authored: Fri Dec 4 18:00:13 2015 +0200
Committer: Igor Bondarenko <je...@gmail.com>
Committed: Tue Dec 15 13:43:03 2015 +0200
----------------------------------------------------------------------
Allura/docs/getting_started/administration.rst | 14 +++++++++-----
1 file changed, 9 insertions(+), 5 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/allura/blob/35fad31c/Allura/docs/getting_started/administration.rst
----------------------------------------------------------------------
diff --git a/Allura/docs/getting_started/administration.rst b/Allura/docs/getting_started/administration.rst
index d1b4b93..f812d8f 100644
--- a/Allura/docs/getting_started/administration.rst
+++ b/Allura/docs/getting_started/administration.rst
@@ -281,14 +281,18 @@ manual mongo queries, however:
> db.site_notification.insert({
... active: true,
... impressions: 10,
- ... content: 'You can now reimport exported project data.'
+ ... content: 'You can now reimport exported project data.',
+ ... user_role: 'Developer',
+ ... page_regex: '/p/wiki/(home|browse_pages)/',
+ ... page_tool_type: 'wiki'
... })
This will create a notification that will be shown for 10 page views or until the
-user closes it manually. An `impressions` value of 0 will show the notification
-indefinitely (until closed). The notification content can contain HTML. Only the
-most recent notification will be shown, unless it has `active:false`, in which case
-no notification will be shown.
+user closes it manually. This Notification will be shown only for users with Developer`s rights.
+And if url page is according to `/p/wiki/(home|browse_pages)/` or app tool name is equal to `wiki`.
+An `impressions` value of 0 will show the notification indefinitely (until closed).
+The notification content can contain HTML. Only the most recent notification will be shown,
+unless it has `active:false`, in which case no notification will be shown.
.. _delete-projects:
[02/12] allura git commit: [#8023] ticket:867 add
SiteNotification.user_role,
add check role in ThemeProvider.get_site_notification
Posted by je...@apache.org.
[#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/e877403e
Tree: http://git-wip-us.apache.org/repos/asf/allura/tree/e877403e
Diff: http://git-wip-us.apache.org/repos/asf/allura/diff/e877403e
Branch: refs/heads/ib/8023b
Commit: e877403eee2618bec9fa9bc901222fb8741730d0
Parents: a54dbbf
Author: Denis Kotov <de...@gmail.com>
Authored: Wed Dec 2 20:55:01 2015 +0200
Committer: Igor Bondarenko <je...@gmail.com>
Committed: Tue Dec 15 13:43:02 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/e877403e/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/e877403e/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/e877403e/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):
[12/12] allura git commit: [#8023] ticket:879 change
my_projects_by_role_name, fix tests
Posted by je...@apache.org.
[#8023] ticket:879 change my_projects_by_role_name, fix tests
Project: http://git-wip-us.apache.org/repos/asf/allura/repo
Commit: http://git-wip-us.apache.org/repos/asf/allura/commit/5dc99b3f
Tree: http://git-wip-us.apache.org/repos/asf/allura/tree/5dc99b3f
Diff: http://git-wip-us.apache.org/repos/asf/allura/diff/5dc99b3f
Branch: refs/heads/ib/8023b
Commit: 5dc99b3f5a7fda3ce6aa9e860524759755d74dbf
Parents: 697dccf
Author: Denis Kotov <de...@gmail.com>
Authored: Fri Dec 11 17:07:05 2015 +0200
Committer: Igor Bondarenko <je...@gmail.com>
Committed: Tue Dec 15 13:43:03 2015 +0200
----------------------------------------------------------------------
Allura/allura/lib/plugin.py | 2 +-
Allura/allura/model/auth.py | 2 +-
Allura/allura/tests/test_plugin.py | 2 +-
3 files changed, 3 insertions(+), 3 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/allura/blob/5dc99b3f/Allura/allura/lib/plugin.py
----------------------------------------------------------------------
diff --git a/Allura/allura/lib/plugin.py b/Allura/allura/lib/plugin.py
index 9247577..cf833c1 100644
--- a/Allura/allura/lib/plugin.py
+++ b/Allura/allura/lib/plugin.py
@@ -1319,7 +1319,7 @@ class ThemeProvider(object):
if note.user_role and c.user.is_anonymous():
return None
if note.user_role:
- projects = c.user.my_projects_by_role_name(note.user_role).all()
+ projects = c.user.my_projects_by_role_name(note.user_role)
if len(projects) == 0 or len(projects) == 1 and projects[0].is_user_project:
return None
http://git-wip-us.apache.org/repos/asf/allura/blob/5dc99b3f/Allura/allura/model/auth.py
----------------------------------------------------------------------
diff --git a/Allura/allura/model/auth.py b/Allura/allura/model/auth.py
index 955c952..34d0877 100644
--- a/Allura/allura/model/auth.py
+++ b/Allura/allura/model/auth.py
@@ -770,7 +770,7 @@ class User(MappedClass, ActivityNode, ActivityObject, SearchIndexable):
projects = [r['project_id'] for r in reaching_roles]
from .project import Project
- return Project.query.find({'_id': {'$in': projects}, 'deleted': False})
+ return Project.query.find({'_id': {'$in': projects}, 'deleted': False}).all()
def set_password(self, new_password):
return plugin.AuthenticationProvider.get(request).set_password(
http://git-wip-us.apache.org/repos/asf/allura/blob/5dc99b3f/Allura/allura/tests/test_plugin.py
----------------------------------------------------------------------
diff --git a/Allura/allura/tests/test_plugin.py b/Allura/allura/tests/test_plugin.py
index 827ef73..d379d97 100644
--- a/Allura/allura/tests/test_plugin.py
+++ b/Allura/allura/tests/test_plugin.py
@@ -400,7 +400,7 @@ class TestThemeProvider(object):
note.user_role = 'Test'
note.page_regex = None
note.page_tool_type = None
- projects = User.my_projects_by_role_name.return_value.all
+ projects = User.my_projects_by_role_name
User.is_anonymous.return_value = True
assert_is(ThemeProvider().get_site_notification(), None)
[10/12] allura git commit: [#8023] ticket:872 change
my_projects_by_role_name call in controller
Posted by je...@apache.org.
[#8023] ticket:872 change my_projects_by_role_name call in controller
Project: http://git-wip-us.apache.org/repos/asf/allura/repo
Commit: http://git-wip-us.apache.org/repos/asf/allura/commit/250edeb1
Tree: http://git-wip-us.apache.org/repos/asf/allura/tree/250edeb1
Diff: http://git-wip-us.apache.org/repos/asf/allura/diff/250edeb1
Branch: refs/heads/ib/8023b
Commit: 250edeb1293e7420d0105af21627e065c71494d8
Parents: 5dc99b3
Author: Denis Kotov <de...@gmail.com>
Authored: Fri Dec 11 17:52:06 2015 +0200
Committer: Igor Bondarenko <je...@gmail.com>
Committed: Tue Dec 15 13:43:03 2015 +0200
----------------------------------------------------------------------
Allura/allura/controllers/auth.py | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/allura/blob/250edeb1/Allura/allura/controllers/auth.py
----------------------------------------------------------------------
diff --git a/Allura/allura/controllers/auth.py b/Allura/allura/controllers/auth.py
index 27c7c4d..b0e4143 100644
--- a/Allura/allura/controllers/auth.py
+++ b/Allura/allura/controllers/auth.py
@@ -1051,7 +1051,7 @@ class DisableAccountController(BaseController):
def index(self, **kw):
provider = plugin.AuthenticationProvider.get(request)
menu = provider.account_navigation()
- my_projects = c.user.my_projects_by_role_name('Admin').all()
+ my_projects = c.user.my_projects_by_role_name('Admin')
return {
'menu': menu,
'my_projects': my_projects,
[09/12] allura git commit: [#8023] ticket:868 Added check mathing url
with page_regex and tool_name with page_tool_type
Posted by je...@apache.org.
[#8023] ticket:868 Added check mathing url with page_regex and tool_name with page_tool_type
Project: http://git-wip-us.apache.org/repos/asf/allura/repo
Commit: http://git-wip-us.apache.org/repos/asf/allura/commit/10641731
Tree: http://git-wip-us.apache.org/repos/asf/allura/tree/10641731
Diff: http://git-wip-us.apache.org/repos/asf/allura/diff/10641731
Branch: refs/heads/ib/8023b
Commit: 10641731d371f0152e7802777572d2da1f1f9d4f
Parents: b77e21e
Author: Denis Kotov <de...@gmail.com>
Authored: Fri Dec 4 15:57:21 2015 +0200
Committer: Igor Bondarenko <je...@gmail.com>
Committed: Tue Dec 15 13:43:03 2015 +0200
----------------------------------------------------------------------
Allura/allura/lib/plugin.py | 8 ++++++++
1 file changed, 8 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/allura/blob/10641731/Allura/allura/lib/plugin.py
----------------------------------------------------------------------
diff --git a/Allura/allura/lib/plugin.py b/Allura/allura/lib/plugin.py
index 2daf8ee..43cc98f 100644
--- a/Allura/allura/lib/plugin.py
+++ b/Allura/allura/lib/plugin.py
@@ -1324,6 +1324,14 @@ 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:
+ return None
cookie = request.cookies.get('site-notification', '').split('-')
if len(cookie) == 3 and cookie[0] == str(note._id):
views = asint(cookie[1]) + 1
[03/12] allura git commit: [#8023] ticket:867 changed check user
rights
Posted by je...@apache.org.
[#8023] ticket:867 changed check user rights
Project: http://git-wip-us.apache.org/repos/asf/allura/repo
Commit: http://git-wip-us.apache.org/repos/asf/allura/commit/2254ed23
Tree: http://git-wip-us.apache.org/repos/asf/allura/tree/2254ed23
Diff: http://git-wip-us.apache.org/repos/asf/allura/diff/2254ed23
Branch: refs/heads/ib/8023b
Commit: 2254ed23f9999206b86ff41e771f27a2761fa745
Parents: 514c0de
Author: Denis Kotov <de...@gmail.com>
Authored: Fri Dec 4 11:09:27 2015 +0200
Committer: Igor Bondarenko <je...@gmail.com>
Committed: Tue Dec 15 13:43:02 2015 +0200
----------------------------------------------------------------------
Allura/allura/lib/plugin.py | 10 ++++++----
1 file changed, 6 insertions(+), 4 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/allura/blob/2254ed23/Allura/allura/lib/plugin.py
----------------------------------------------------------------------
diff --git a/Allura/allura/lib/plugin.py b/Allura/allura/lib/plugin.py
index 8b7a282..2daf8ee 100644
--- a/Allura/allura/lib/plugin.py
+++ b/Allura/allura/lib/plugin.py
@@ -1318,10 +1318,12 @@ class ThemeProvider(object):
return None
if note.user_role is not None and c.user.is_anonymous():
return None
- projects = c.user.my_projects_by_role_name(note.user_role)
- if note.user_role is not None and \
- projects.count() == 0 or (projects.count() == 1 and projects.first().is_user_project):
- return None
+ if note.user_role is not None:
+ projects = c.user.my_projects_by_role_name(note.user_role)
+ if projects is not None:
+ only_user_project = projects.count() == 1 and projects.first().is_user_project
+ if projects.count() == 0 or only_user_project:
+ return None
cookie = request.cookies.get('site-notification', '').split('-')
if len(cookie) == 3 and cookie[0] == str(note._id):
views = asint(cookie[1]) + 1