From 56b1b9a2ea8a672f552bc328641255fb178807bf Mon Sep 17 00:00:00 2001
From: Valentin Deniaud <vdeniaud@entrouvert.com>
Date: Fri, 8 Mar 2019 13:56:25 +0100
Subject: [PATCH 1/2] manager: access context through table object bis (#31222)

Related to #31092.
---
 .../manager/locale/fr/LC_MESSAGES/django.po          | 12 ++++++------
 .../authentic2/manager/role_members_table.html       |  2 +-
 .../authentic2/manager/role_permissions_table.html   |  2 +-
 .../authentic2/manager/service_roles_table.html      |  2 +-
 .../manager/templates/authentic2/manager/table.html  |  4 ++--
 .../templates/authentic2/manager/user_roles.html     |  1 -
 .../authentic2/manager/user_roles_table.html         |  2 +-
 tests/test_manager.py                                |  1 +
 8 files changed, 13 insertions(+), 13 deletions(-)

diff --git a/src/authentic2/manager/locale/fr/LC_MESSAGES/django.po b/src/authentic2/manager/locale/fr/LC_MESSAGES/django.po
index 1a3b3ddd..00c5c882 100644
--- a/src/authentic2/manager/locale/fr/LC_MESSAGES/django.po
+++ b/src/authentic2/manager/locale/fr/LC_MESSAGES/django.po
@@ -593,9 +593,9 @@ msgstr "rôle hérité"
 #, python-format
 msgid ""
 "Do you really want to remove user &quot;%(username)s&quot; from role &quot;"
-"%(object)s&quot;&nbsp;?"
+"%(role)s&quot;&nbsp;?"
 msgstr ""
-"Souhaitez-vous vraiment retirer le rôle « %(object)s » à l'utilisateur "
+"Souhaitez-vous vraiment retirer le rôle « %(role)s » à l'utilisateur "
 "« %(username)s » ?"
 
 #: src/authentic2/manager/templates/authentic2/manager/role_permissions.html:19
@@ -655,10 +655,10 @@ msgstr "Rôles visibles uniquement de ce service"
 #, python-format
 msgid ""
 "Do you really want to remove role &quot;%(name)s&quot; from service &quot;"
-"%(object)s&quot;&nbsp;?"
+"%(slug)s&quot;&nbsp;?"
 msgstr ""
 "Souhaitez-vous vraiment retirer le rôle « %(name)s » du service "
-"« %(object)s » ?"
+"« %(slug)s » ?"
 
 #: src/authentic2/manager/templates/authentic2/manager/site_import.html:5
 msgid "Site Import"
@@ -867,10 +867,10 @@ msgstr "Éditer les rôles de l'utilisateur"
 #, python-format
 msgid ""
 "Do you really want to remove role &quot;%(name)s&quot; from user &quot;"
-"%(object)s&quot;&nbsp;?"
+"%(username)s&quot;&nbsp;?"
 msgstr ""
 "Souhaitez-vous vraiment retirer le rôle « %(name)s » à l'utilisateur "
-"« %(object)s » ?"
+"« %(username)s » ?"
 
 #: src/authentic2/manager/templates/authentic2/manager/users.html:13
 #: src/authentic2/manager/templates/authentic2/manager/users.html:20
diff --git a/src/authentic2/manager/templates/authentic2/manager/role_members_table.html b/src/authentic2/manager/templates/authentic2/manager/role_members_table.html
index 570dcfeb..cffdaa1e 100644
--- a/src/authentic2/manager/templates/authentic2/manager/role_members_table.html
+++ b/src/authentic2/manager/templates/authentic2/manager/role_members_table.html
@@ -7,6 +7,6 @@
     <th></th>
   {% endblock %}
   {% block table.tbody.last.column %}
-    <td>{% if view.can_change and row.record.direct %}<a class="icon-remove-sign js-remove-object" data-confirm="{% blocktrans with username=row.record.get_full_name role=active_role.name %}Do you really want to remove user &quot;{{ username }}&quot; from role &quot;{{ object }}&quot;&nbsp;?{% endblocktrans %}" href="#" data-pk-arg="user"></a>{% endif %}</td>
+  <td>{% if table.context.view.can_change and row.record.direct %}<a class="icon-remove-sign js-remove-object" data-confirm="{% blocktrans with username=row.record.get_full_name role=table.context.object %}Do you really want to remove user &quot;{{ username }}&quot; from role &quot;{{ role }}&quot;&nbsp;?{% endblocktrans %}" href="#" data-pk-arg="user"></a>{% endif %}</td>
   {% endblock %}
 {% endif %}
diff --git a/src/authentic2/manager/templates/authentic2/manager/role_permissions_table.html b/src/authentic2/manager/templates/authentic2/manager/role_permissions_table.html
index e37af8d5..8675ed9e 100644
--- a/src/authentic2/manager/templates/authentic2/manager/role_permissions_table.html
+++ b/src/authentic2/manager/templates/authentic2/manager/role_permissions_table.html
@@ -7,6 +7,6 @@
     <th></th>
   {% endblock %}
   {% block table.tbody.last.column %}
-    <td>{% if view.can_change %}<a class="icon-remove-sign js-remove-object" href="#" data-pk-arg="permission"></a>{% endif %}</td>
+    <td>{% if table.context.view.can_change %}<a class="icon-remove-sign js-remove-object" href="#" data-pk-arg="permission"></a>{% endif %}</td>
   {% endblock %}
 {% endif %}
diff --git a/src/authentic2/manager/templates/authentic2/manager/service_roles_table.html b/src/authentic2/manager/templates/authentic2/manager/service_roles_table.html
index 01cafaa3..6b440f58 100644
--- a/src/authentic2/manager/templates/authentic2/manager/service_roles_table.html
+++ b/src/authentic2/manager/templates/authentic2/manager/service_roles_table.html
@@ -7,6 +7,6 @@
     <th></th>
   {% endblock %}
   {% block table.tbody.last.column %}
-    <td>{% if view.can_change %}<a class="icon-remove-sign js-remove-object" data-confirm="{% blocktrans with name=row.record.name slug=row.record.slug %}Do you really want to remove role &quot;{{ name }}&quot; from service &quot;{{ object }}&quot;&nbsp;?{% endblocktrans %}" href="#" data-pk-arg="role"></a>{% endif %}</td>
+    <td>{% if table.context.view.can_change %}<a class="icon-remove-sign js-remove-object" data-confirm="{% blocktrans with name=row.record.name slug=table.context.object %}Do you really want to remove role &quot;{{ name }}&quot; from service &quot;{{ slug }}&quot;&nbsp;?{% endblocktrans %}" href="#" data-pk-arg="role"></a>{% endif %}</td>
   {% endblock %}
 {% endif %}
diff --git a/src/authentic2/manager/templates/authentic2/manager/table.html b/src/authentic2/manager/templates/authentic2/manager/table.html
index e67bc260..b64ae94e 100644
--- a/src/authentic2/manager/templates/authentic2/manager/table.html
+++ b/src/authentic2/manager/templates/authentic2/manager/table.html
@@ -24,8 +24,8 @@
        {% if popup_edit %}
          rel="popup"
        {% endif %}
-       {% if url_name %}
-         data-url="{% url url_name pk=row.record.pk %}"
+       {% if table.context.url_name %}
+         data-url="{% url table.context.url_name pk=row.record.pk %}"
        {% else %}
          data-url="{{ row.record.pk }}/"
        {% endif %}
diff --git a/src/authentic2/manager/templates/authentic2/manager/user_roles.html b/src/authentic2/manager/templates/authentic2/manager/user_roles.html
index af472986..fa99f710 100644
--- a/src/authentic2/manager/templates/authentic2/manager/user_roles.html
+++ b/src/authentic2/manager/templates/authentic2/manager/user_roles.html
@@ -11,7 +11,6 @@
 {% block page_title %}
 {% trans "Edit User Roles" %}
 {% endblock %}
-
 {% block extrascripts %}
   {{ block.super }}
   <script>
diff --git a/src/authentic2/manager/templates/authentic2/manager/user_roles_table.html b/src/authentic2/manager/templates/authentic2/manager/user_roles_table.html
index 542117a3..d173a54f 100644
--- a/src/authentic2/manager/templates/authentic2/manager/user_roles_table.html
+++ b/src/authentic2/manager/templates/authentic2/manager/user_roles_table.html
@@ -7,6 +7,6 @@
     <th></th>
   {% endblock %}
   {% block table.tbody.last.column %}
-  <td>{% if view.can_change and row.record.member %}<a class="icon-remove-sign js-remove-object" data-confirm="{% blocktrans with name=row.record.name role=active_role.name %}Do you really want to remove role &quot;{{ name }}&quot; from user &quot;{{ object }}&quot;&nbsp;?{% endblocktrans %}" href="#" data-pk-arg="role"></a>{% endif %}</td>
+  <td>{% if table.context.view.can_change and row.record.member %}<a class="icon-remove-sign js-remove-object" data-confirm="{% blocktrans with name=row.record.name username=table.context.object.get_full_name %}Do you really want to remove role &quot;{{ name }}&quot; from user &quot;{{ username }}&quot;&nbsp;?{% endblocktrans %}" href="#" data-pk-arg="role"></a>{% endif %}</td>
   {% endblock %}
 {% endif %}
diff --git a/tests/test_manager.py b/tests/test_manager.py
index 3d6ce970..c805e81b 100644
--- a/tests/test_manager.py
+++ b/tests/test_manager.py
@@ -319,6 +319,7 @@ def test_manager_one_ou(app, superuser, admin, simple_role, settings):
         q = response.pyquery.remove_namespaces()
         assert len(q('table tbody tr')) == 1
         assert q('table tbody tr').text() == u'simple role'
+        assert q('table tbody tr').attr('data-url') == '/manage/roles/%s/' % simple_role.pk
 
         form.set('search-internals', True)
         response = form.submit()
-- 
2.20.1

