From 23d785aa10edcc1f0d020516b6146d00b105684a Mon Sep 17 00:00:00 2001
From: Nicolas ROCHE <nroche@entrouvert.com>
Date: Tue, 6 Oct 2020 17:37:19 +0200
Subject: [PATCH] manager: remind OU in user consents breadcrumb (#47238)

---
 .../authentic2/manager/user_authorizations.html   |  3 +++
 src/authentic2/manager/views.py                   |  4 ++--
 tests/test_user_manager.py                        | 15 +++++++++++++++
 3 files changed, 20 insertions(+), 2 deletions(-)

diff --git a/src/authentic2/manager/templates/authentic2/manager/user_authorizations.html b/src/authentic2/manager/templates/authentic2/manager/user_authorizations.html
index 6a97b2ae..ddd340a7 100644
--- a/src/authentic2/manager/templates/authentic2/manager/user_authorizations.html
+++ b/src/authentic2/manager/templates/authentic2/manager/user_authorizations.html
@@ -5,16 +5,19 @@
 
 {% block appbar %}
 {{ block.super }}
 {% endblock %}
 
 {% block breadcrumb %}
 {{ block.super }}
   <a href="{% url 'a2-manager-users' %}">{% trans 'Users' %}</a>
+  {% if multiple_ou and object.ou %}
+  <a href="../?search-ou={{ object.ou.pk }}">{{ object.ou }}</a>
+  {% endif %}
   <a href="{% url 'a2-manager-user-detail' pk=object.pk %}">{{ object.get_full_name }}</a>
   <a href="#">{% trans "Consent Management" context "manager" %}</a>
 {% endblock %}
 
 {% block sidebar %}
 <aside id="sidebar">
 </aside>
 {% endblock %}
diff --git a/src/authentic2/manager/views.py b/src/authentic2/manager/views.py
index 939e8219..33aa3878 100644
--- a/src/authentic2/manager/views.py
+++ b/src/authentic2/manager/views.py
@@ -416,18 +416,18 @@ class TableHookMixin(object):
     def get_table(self, **kwargs):
         table = super(TableHookMixin, self).get_table(**kwargs)
         import copy
         table = copy.deepcopy(table)
         hooks.call_hooks('manager_modify_table', self, table)
         return table
 
 
-class BaseTableView(TitleMixin, TableHookMixin, FormatsContextData, ModelNameMixin, PermissionMixin,
-                    SearchFormMixin, FilterQuerysetByPermMixin, TableQuerysetMixin,
+class BaseTableView(MultipleOUMixin, TitleMixin, TableHookMixin, FormatsContextData, ModelNameMixin,
+                    PermissionMixin, SearchFormMixin, FilterQuerysetByPermMixin, TableQuerysetMixin,
                     SingleTableView):
     '''Base class for views showing a table of objects'''
     pass
 
 
 class SubTableViewMixin(TableHookMixin, FormatsContextData, ModelNameMixin, PermissionMixin,
                         SearchFormMixin, FilterTableQuerysetByPermMixin,
                         TableQuerysetMixin, SingleObjectMixin,
diff --git a/tests/test_user_manager.py b/tests/test_user_manager.py
index 764cc6ed..cdfbb723 100644
--- a/tests/test_user_manager.py
+++ b/tests/test_user_manager.py
@@ -915,8 +915,23 @@ def test_manager_user_authorizations(app, superuser, simple_user):
     # cannot click it's JS :/
     token = str(resp.context['csrf_token'])
     params = {'authorization': auth.pk, 'csrfmiddlewaretoken': token}
     resp = app.post(user_authorizations_url, params=params, status=302)
     assert OIDCAuthorization.objects.count() == 0
     resp = resp.follow()
     assert resp.html.find('td').text == \
         'This user has not granted profile data access to any service yet.'
+
+def test_manager_user_authorizations_breadcrumb(app, superuser, simple_user):
+    resp = login(app, superuser)
+    user_authorizations_url = reverse(
+        'a2-manager-user-authorizations', kwargs={'pk': simple_user.id})
+    resp = app.get(user_authorizations_url, status=200)
+    assert [x.text for x in resp.html.find('span', {'id': 'breadcrumb'}).find_all('a')] == [
+        'Homepage', 'Administration', 'Users', 'Default organizational unit',
+        'Jôhn Dôe', 'Consent Management']
+    user_authorizations_url = reverse(
+        'a2-manager-user-authorizations', kwargs={'pk': superuser.id})
+    resp = app.get(user_authorizations_url, status=200)
+    assert [x.text for x in resp.html.find('span', {'id': 'breadcrumb'}).find_all('a')] == [
+        'Homepage', 'Administration', 'Users',
+        'super user', 'Consent Management']
-- 
2.28.0

