From a05c136ee519248ae05a831aa1f6c6abc00975a5 Mon Sep 17 00:00:00 2001 From: Valentin Deniaud Date: Mon, 17 Jan 2022 15:35:03 +0100 Subject: [PATCH] manager: simplify data-url in tables (#60678) --- src/authentic2/a2_rbac/models.py | 3 +++ .../manager/templates/authentic2/manager/role_members.html | 2 +- .../manager/templates/authentic2/manager/service.html | 4 ++-- .../manager/templates/authentic2/manager/table.html | 6 +----- .../manager/templates/authentic2/manager/user_roles.html | 2 +- src/authentic2/models.py | 4 ++++ tests/test_manager.py | 2 +- 7 files changed, 13 insertions(+), 10 deletions(-) diff --git a/src/authentic2/a2_rbac/models.py b/src/authentic2/a2_rbac/models.py index 22fb1219..b16ce760 100644 --- a/src/authentic2/a2_rbac/models.py +++ b/src/authentic2/a2_rbac/models.py @@ -188,6 +188,9 @@ class OrganizationalUnit(OrganizationalUnitAbstractBase): def __str__(self): return str(self.name) + def get_absolute_url(self): + return reverse('a2-manager-ou-detail', kwargs={'pk': self.pk}) + OrganizationalUnit._meta.natural_key = [['uuid'], ['slug'], ['name']] diff --git a/src/authentic2/manager/templates/authentic2/manager/role_members.html b/src/authentic2/manager/templates/authentic2/manager/role_members.html index aa949ae7..7a350e35 100644 --- a/src/authentic2/manager/templates/authentic2/manager/role_members.html +++ b/src/authentic2/manager/templates/authentic2/manager/role_members.html @@ -61,7 +61,7 @@ {% trans "This role is synchronised from LDAP, changing members is not allowed." %} {% endif %} - {% with row_link=1 url_name="a2-manager-user-detail" %} + {% with row_link=1 %} {% render_table table "authentic2/manager/role_members_table.html" %} {% endwith %} diff --git a/src/authentic2/manager/templates/authentic2/manager/service.html b/src/authentic2/manager/templates/authentic2/manager/service.html index 2481c970..7fb3a3df 100644 --- a/src/authentic2/manager/templates/authentic2/manager/service.html +++ b/src/authentic2/manager/templates/authentic2/manager/service.html @@ -37,7 +37,7 @@

{% trans "Roles of users allowed on this service" %}

- {% with row_link=1 url_name='a2-manager-role-members' %} + {% with row_link=1 %} {% render_table table "authentic2/manager/service_roles_table.html" %} {% endwith %}
@@ -51,7 +51,7 @@

{% trans "Roles solely visible from this service" %}

- {% with row_link=1 url_name='a2-manager-role-members' table=roles_table%} + {% with row_link=1 table=roles_table %} {% render_table table "authentic2/manager/table.html" %} {% endwith %}
diff --git a/src/authentic2/manager/templates/authentic2/manager/table.html b/src/authentic2/manager/templates/authentic2/manager/table.html index 0c7c3f1d..ac827db5 100644 --- a/src/authentic2/manager/templates/authentic2/manager/table.html +++ b/src/authentic2/manager/templates/authentic2/manager/table.html @@ -25,11 +25,7 @@ {% if popup_edit %} rel="popup" {% endif %} - {% if table.context.url_name %} - data-url="{% url table.context.url_name pk=row.record.pk %}" - {% else %} - data-url="{{ row.record.pk }}/" - {% endif %} + data-url="{{ row.record.get_absolute_url }}" {% endif %}> {% for column, cell in row.items %} {% if column.localize == None %}{{ cell }}{% else %}{% if column.localize %}{{ cell|localize }}{% else %}{{ cell|unlocalize }}{% endif %}{% endif %} diff --git a/src/authentic2/manager/templates/authentic2/manager/user_roles.html b/src/authentic2/manager/templates/authentic2/manager/user_roles.html index 7afeddd3..ae8c7e14 100644 --- a/src/authentic2/manager/templates/authentic2/manager/user_roles.html +++ b/src/authentic2/manager/templates/authentic2/manager/user_roles.html @@ -13,7 +13,7 @@ {% endblock %} {% block main %} - {% with row_link=1 url_name="a2-manager-role-members" %} + {% with row_link=1 %} {% render_table table "authentic2/manager/user_roles_table.html" %} {% endwith %} diff --git a/src/authentic2/models.py b/src/authentic2/models.py index 1fb386fd..c7dddb49 100644 --- a/src/authentic2/models.py +++ b/src/authentic2/models.py @@ -29,6 +29,7 @@ from django.contrib.postgres.search import SearchVectorField from django.core.exceptions import ValidationError from django.db import models, transaction from django.db.models.query import Q +from django.urls import reverse from django.utils import timezone from django.utils.http import urlquote from django.utils.translation import ugettext_lazy as _ @@ -447,6 +448,9 @@ class Service(models.Model): 'roles': [role.to_json() for role in roles], } + def get_absolute_url(self): + return reverse('a2-manager-service', kwargs={'service_pk': self.pk}) + Service._meta.natural_key = [['slug', 'ou']] diff --git a/tests/test_manager.py b/tests/test_manager.py index 85068603..b78e6b08 100644 --- a/tests/test_manager.py +++ b/tests/test_manager.py @@ -806,7 +806,7 @@ def test_manager_ou(app, superuser_or_admin, ou1): ou2 = OU.objects.get(name='ou2') assert {e.text for e in ou_homepage.pyquery('td.name')} == {'OU1', 'Default organizational unit', 'ou2'} assert len(ou_homepage.pyquery('tr[data-pk="%s"] td.default span.true' % ou2.pk)) == 1 - assert len(ou_homepage.pyquery('tr[data-url="%s/"] td.default span.true' % ou2.pk)) == 1 + assert len(ou_homepage.pyquery('tr[data-url="%s"] td.default span.true' % ou2.get_absolute_url())) == 1 # FIXME: table lines are not clickable as they do not contain an anchor # default ou cannot be deleted -- 2.30.2