You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@allura.apache.org by br...@apache.org on 2025/01/16 19:33:31 UTC

(allura) branch master updated: [#8573] hide admin/update/create permissions for authorized and anonymous users

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

brondsem pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/allura.git


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

commit eee15e3b88b71185b421c121ffd667eb06bb3028
Author: Guillermo Cruz <gu...@slashdotmedia.com>
AuthorDate: Thu Jan 9 13:06:38 2025 -0700

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

diff --git a/Allura/allura/ext/admin/templates/project_groups.html b/Allura/allura/ext/admin/templates/project_groups.html
index ed941dd9d..341b91e54 100644
--- a/Allura/allura/ext/admin/templates/project_groups.html
+++ b/Allura/allura/ext/admin/templates/project_groups.html
@@ -31,13 +31,20 @@
 {% macro show_perms_for_role(role) %}
   <ul class="permissions">
     {% for perm in permissions_by_role[role._id.__str__()] %}
-    {% if private_projects or (not private_projects and perm['name'] != 'read') or (not private_projects and 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']}}
-      </a> {# close tag, opened by render #}
-    </li>
-    {% endif %}
+        {%  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']}}
+              </a> {# close tag, opened by render #}
+            </li>
+        {% elif private_projects and not display_perms and perm['name'] == 'read' %}
+            <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>
+        {% endif %}
     {% endfor %}
   </ul>
 {% endmacro %}
diff --git a/Allura/allura/tests/functional/test_admin.py b/Allura/allura/tests/functional/test_admin.py
index 9f334f1be..23b8301f0 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) == 1
+                
+                
+
 
 class TestExport(TestController):