incubator-allura-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From john...@apache.org
Subject [32/44] git commit: [#2834] ticket:200 subscribe new project admin to all the tools
Date Tue, 27 Nov 2012 13:46:06 GMT
[#2834] ticket:200 subscribe new project admin to all the tools


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

Branch: refs/heads/cj/4691
Commit: 2b6f2c19c7b134269b9e8b4de05637ea468d6864
Parents: a076cd3
Author: Igor Bondarenko <jetmind2@gmail.com>
Authored: Fri Nov 2 14:06:34 2012 +0000
Committer: Dave Brondsema <dbrondsema@geek.net>
Committed: Wed Nov 7 19:59:43 2012 +0000

----------------------------------------------------------------------
 Allura/allura/app.py                         |    8 +++++
 Allura/allura/ext/admin/admin_main.py        |    3 ++
 Allura/allura/tests/functional/test_admin.py |   34 ++++++++++++++++++++-
 3 files changed, 44 insertions(+), 1 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/2b6f2c19/Allura/allura/app.py
----------------------------------------------------------------------
diff --git a/Allura/allura/app.py b/Allura/allura/app.py
index e8800d0..613e88d 100644
--- a/Allura/allura/app.py
+++ b/Allura/allura/app.py
@@ -194,6 +194,14 @@ class Application(object):
                 project_id=self.project._id,
                 app_config_id=self.config._id)
 
+    def subscribe(self, user):
+        if user and user != model.User.anonymous():
+            model.Mailbox.subscribe(
+                    type='direct',
+                    user_id=user._id,
+                    project_id=self.project._id,
+                    app_config_id=self.config._id)
+
     @classmethod
     def default_options(cls):
         ":return: the default config options"

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/2b6f2c19/Allura/allura/ext/admin/admin_main.py
----------------------------------------------------------------------
diff --git a/Allura/allura/ext/admin/admin_main.py b/Allura/allura/ext/admin/admin_main.py
index 7116990..ad35414 100644
--- a/Allura/allura/ext/admin/admin_main.py
+++ b/Allura/allura/ext/admin/admin_main.py
@@ -691,6 +691,9 @@ class GroupsController(BaseController):
             return dict(error='%s (%s) is already in the group %s.' % (user.display_name,
username, group.name))
         M.AuditLog.log('add user %s to %s', username, group.name)
         user.project_role().roles.append(group._id)
+        if group.name == 'Admin':
+            for ac in c.project.app_configs:
+                c.project.app_instance(ac).subscribe(user)
         g.post_event('project_updated')
         return dict(username=username, displayname=user.display_name)
 

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/2b6f2c19/Allura/allura/tests/functional/test_admin.py
----------------------------------------------------------------------
diff --git a/Allura/allura/tests/functional/test_admin.py b/Allura/allura/tests/functional/test_admin.py
index c32be2e..656f1c9 100644
--- a/Allura/allura/tests/functional/test_admin.py
+++ b/Allura/allura/tests/functional/test_admin.py
@@ -191,7 +191,7 @@ class TestProjectAdmin(TestController):
         r = self.app.get('/p/test/icon')
         image = Image.open(StringIO.StringIO(r.body))
         assert image.size == (48,48)
-        
+
         r = self.app.get('/p/test/icon?foo=bar')
 
     def test_project_screenshot(self):
@@ -418,6 +418,38 @@ class TestProjectAdmin(TestController):
         # Make sure we can open role page for builtin role
         r = self.app.get('/admin/groups/' + developer_id + '/', validate_chunk=True)
 
+    def test_new_admin_subscriptions(self):
+        """Newly added admin must be subscribed to all the tools in the project"""
+        r = self.app.get('/admin/groups/')
+        admin_holder = r.html.find('table', {'id': 'usergroup_admin'}).findAll('tr')[1]
+        admin_id = admin_holder['data-group']
+        with audits('add user test-user to Admin'):
+            self.app.post('/admin/groups/add_user', params={
+                'role_id': admin_id,
+                'username': 'test-user'})
+        p_nbhd = M.Neighborhood.query.get(name='Projects')
+        p = M.Project.query.get(shortname='test', neighborhood_id=p_nbhd._id)
+        uid = M.User.by_username('test-user')._id
+        for ac in p.app_configs:
+            sub = M.Mailbox.subscribed(user_id=uid, project_id=p._id, app_config_id=ac._id)
+            assert sub, 'New admin not subscribed to app %s' % ac
+
+    def test_new_user_subscriptions(self):
+        """Newly added user must not be subscribed to all the tools in the project if he
is not admin"""
+        r = self.app.get('/admin/groups/')
+        dev_holder = r.html.find('table',{'id':'usergroup_admin'}).findAll('tr')[2]
+        developer_id = dev_holder['data-group']
+        with audits('add user test-user to Developer'):
+            self.app.post('/admin/groups/add_user', params={
+                'role_id': developer_id,
+                'username': 'test-user'})
+        p_nbhd = M.Neighborhood.query.get(name='Projects')
+        p = M.Project.query.get(shortname='test', neighborhood_id=p_nbhd._id)
+        uid = M.User.by_username('test-user')._id
+        for ac in p.app_configs:
+            sub = M.Mailbox.subscribed(user_id=uid, project_id=p._id, app_config_id=ac._id)
+            assert not sub, 'New user subscribed to app %s' % ac
+
     def test_subroles(self):
         """Make sure subroles are preserved during group updates."""
         def check_roles(r):


Mime
View raw message