From c17f1a03e47fb862dda0dd78b63ae54199b15061 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Laur=C3=A9line=20Gu=C3=A9rin?= <zebuline@entrouvert.com>
Date: Tue, 22 Oct 2019 09:19:06 +0200
Subject: [PATCH] page: display page visibility on page list (#16028)

---
 combo/data/models.py                          |  5 ++++-
 combo/manager/static/css/combo.manager.css    |  9 +++++---
 .../manager/templates/combo/manager_home.html | 17 ++++++++++++--
 tests/test_manager.py                         | 22 +++++++++++++++++++
 4 files changed, 47 insertions(+), 6 deletions(-)

diff --git a/combo/data/models.py b/combo/data/models.py
index 66b9393..c6f34a7 100644
--- a/combo/data/models.py
+++ b/combo/data/models.py
@@ -336,7 +336,10 @@ class Page(models.Model):
     def visibility(self):
         if self.public:
             return _('Public')
-        return _('Private (%s)') % ', '.join([x.name for x in self.groups.all()])
+        groups = self.groups.all()
+        if groups:
+            return _('Private (%s)') % ', '.join([x.name for x in groups])
+        return _('Private (logged users)')
 
     def is_visible(self, user=None):
         return element_is_visible(self, user=user)
diff --git a/combo/manager/static/css/combo.manager.css b/combo/manager/static/css/combo.manager.css
index 99d49e7..e9cc94e 100644
--- a/combo/manager/static/css/combo.manager.css
+++ b/combo/manager/static/css/combo.manager.css
@@ -53,7 +53,8 @@ div.cell > h3 {
 	white-space: nowrap;
 }
 
-div.cell h3 .group1 {
+div.cell h3 .group1,
+div.page .group1 {
 	display: inline-block;
 	overflow: hidden;
 	white-space: nowrap;
@@ -68,7 +69,8 @@ div.cell h3 span.extra-css-class {
 }
 
 div.cell h3 span.additional-label,
-div.cell h3 span.visibility-summary {
+div.cell h3 span.visibility-summary,
+div.page span.visibility-summary {
 	font-size: 80%;
 	padding-left: 1em;
 	display: inline-block;
@@ -78,7 +80,8 @@ div.cell h3 span.visibility-summary {
 	vertical-align: middle;
 }
 
-div.cell h3 span.visibility-summary::before {
+div.cell h3 span.visibility-summary::before,
+div.page span.visibility-summary::before {
 	content: "\f06e"; /* fa-eye */
 	font-family: FontAwesome;
 }
diff --git a/combo/manager/templates/combo/manager_home.html b/combo/manager/templates/combo/manager_home.html
index 305ac61..d158b26 100644
--- a/combo/manager/templates/combo/manager_home.html
+++ b/combo/manager/templates/combo/manager_home.html
@@ -28,8 +28,21 @@ Use drag and drop with the ⣿ handles to reorder and change hierarchy of pages.
 
 <div class="objects-list" id="pages-list" data-page-order-url="{% url 'combo-manager-page-order' %}">
  {% for page in object_list %}
- <div class="level-{{page.level}}" data-page-id="{{page.id}}" data-level="{{page.level}}">
-	 <span class="handle">⣿</span> <a href="{% url 'combo-manager-page-view' pk=page.id %}">{{ page.title }}</a>
+ <div class="page level-{{page.level}}" data-page-id="{{page.id}}" data-level="{{page.level}}">
+    <span class="handle">⣿</span>
+    <span class="group1">
+      <a href="{% url 'combo-manager-page-view' pk=page.id %}">{{ page.title }}</a>
+    </span>
+    {% if not page.public %}
+    <span class="visibility-summary" title="{% trans 'Restricted visibility' %}">
+    {% with page.groups.all as page_groups %}
+    {% for group in page_groups %}{{ group.name }}{% if not forloop.last %}, {% endif %}
+    {% empty %}
+    {% trans "logged users" %}
+    {% endfor %}
+    {% endwith %}
+    </span>
+    {% endif %}
  </div>
  {% endfor %}
 </div>
diff --git a/tests/test_manager.py b/tests/test_manager.py
index d5c67aa..136e8f9 100644
--- a/tests/test_manager.py
+++ b/tests/test_manager.py
@@ -186,6 +186,28 @@ def test_page_edit_picture(app, admin_user):
     assert '<img' in resp.text
     assert Page.objects.get(id=page.id).picture.url in resp.text
 
+
+def test_page_placeholder_restricted_visibility(app, admin_user):
+    app = login(app)
+
+    page = Page.objects.create()
+    group = Group.objects.create(name='foobar')
+
+    resp = app.get(reverse('combo-manager-homepage'))
+    assert '<span class="visibility-summary"' not in resp.text
+
+    page.public = False
+    page.save()
+    resp = app.get(reverse('combo-manager-homepage'))
+    assert '<span class="visibility-summary" title="Restricted visibility">' in resp.text
+    assert 'foobar' not in resp.text
+
+    page.groups.set([group])
+    resp = app.get(reverse('combo-manager-homepage'))
+    assert '<span class="visibility-summary" title="Restricted visibility">' in resp.text
+    assert 'foobar' in resp.text
+
+
 def test_delete_page(app, admin_user):
     Page.objects.all().delete()
     page = Page(title='One', slug='one', template_name='standard')
-- 
2.20.1

