This is an automated email from the ASF dual-hosted git repository.

gcruz pushed a commit to branch gc/8573
in repository https://gitbox.apache.org/repos/asf/allura.git


The following commit(s) were added to refs/heads/gc/8573 by this push:
     new 20cfb1054 fixup! [#8573] hide admin/update/create permissions for 
authorized and anonymous users
20cfb1054 is described below

commit 20cfb10545aed8b3b3991f87ebdd021c55e866e2
Author: Guillermo Cruz <[email protected]>
AuthorDate: Fri Jan 10 14:32:52 2025 -0700

    fixup! [#8573] hide admin/update/create permissions for authorized and 
anonymous users
---
 .../allura/ext/admin/templates/project_groups.html | 10 ++------
 Allura/allura/tests/functional/test_admin.py       | 30 ++++++++++++++++++++++
 2 files changed, 32 insertions(+), 8 deletions(-)

diff --git a/Allura/allura/ext/admin/templates/project_groups.html 
b/Allura/allura/ext/admin/templates/project_groups.html
index 3a10e9042..49b7e51b6 100644
--- a/Allura/allura/ext/admin/templates/project_groups.html
+++ b/Allura/allura/ext/admin/templates/project_groups.html
@@ -31,14 +31,8 @@
 {% macro show_perms_for_role(role) %}
   <ul class="permissions">
     {% for perm in permissions_by_role[role._id.__str__()] %}
-        {%  set is_auth_or_anon = role.name not in ['Admin', 'Developer', 
'Member'] %}
-        {% if (private_projects and not is_auth_or_anon) or (not 
private_projects and perm['name'] != 'read' and not is_auth_or_anon) or (not 
private_projects and perm['name'] == 'read' and not is_auth_or_anon) and 
perm['has'] == 'no'  %}
-            <li class="{{perm['has']}}" data-permission="{{perm['name']}}">
-              {{ g.icons['perm_has_%s'%perm['has']].render(title=perm['text'], 
closing_tag=False) }}
-                {{perm['name']}}
-              </a> {# close tag, opened by render #}
-            </li>
-        {% elif is_auth_or_anon and perm['name'] == 'read' %}
+        {%  set display_perms = role.name not in ['*authenticated', 
'*anonymous'] %}
+        {% if display_perms and (private_projects or perm['name'] != 'read' or 
(perm['name'] == 'read' and perm['has'] == 'no')) %}
             <li class="{{perm['has']}}" data-permission="{{perm['name']}}">
               {{ g.icons['perm_has_%s'%perm['has']].render(title=perm['text'], 
closing_tag=False) }}
                 {{perm['name']}}
diff --git a/Allura/allura/tests/functional/test_admin.py 
b/Allura/allura/tests/functional/test_admin.py
index 9f334f1be..b43b421e0 100644
--- a/Allura/allura/tests/functional/test_admin.py
+++ b/Allura/allura/tests/functional/test_admin.py
@@ -1005,6 +1005,36 @@ class TestProjectAdmin(TestController):
         r = self.app.get('/p/test/admin/groups/edit_label')
         r.mustcontain('<form method="post" 
action="/p/test/admin/groups/update_label">')
 
+    def test_project_perms_display(self):
+        # Turn off private
+        neighborhood = M.Neighborhood.query.get(name='Projects')
+        neighborhood.features['private_projects'] = False
+        r = self.app.get('/admin/groups/')
+        groups = r.html.find('table', {'id': 
'usergroup_admin'}).select_one('tbody').findAll('tr')[:-1]
+        for gr in groups:
+            group_name = gr.select_one('td').text.strip()
+            group_perms = gr.find('ul', {'class': 'permissions'}).findAll('li')
+            if group_name in ['Authenticated', 'Anonymous']:
+                assert len(group_perms) == 0
+            else:
+                assert len(group_perms) == 3
+
+    def test_private_projects_perms(self):
+        # Turn on private
+        neighborhood = M.Neighborhood.query.get(name='Projects')
+        neighborhood.features['private_projects'] = True
+        r = self.app.get('/admin/groups/')
+        groups = r.html.find('table', {'id': 
'usergroup_admin'}).select_one('tbody').findAll('tr')[:-1]
+        for gr in groups:
+            group_name = gr.select_one('td').text.strip()
+            group_perms = gr.find('ul', {'class': 'permissions'}).findAll('li')
+            if group_name not in ['Authenticated', 'Anonymous']:
+                assert len(group_perms) == 4 # read permission is being 
displayed
+            else:
+                assert len(group_perms) == 0
+                
+                
+
 
 class TestExport(TestController):
 

Reply via email to