From ab6116aab1f3e0f9f1507cff75c77eccd3d57784 Mon Sep 17 00:00:00 2001
From: Tom Teichler <tom.teichler@teckids.org>
Date: Sat, 18 Apr 2020 12:26:29 +0200
Subject: [PATCH] Add first permissions for person object

---
 aleksis/core/models.py                       |  4 ++
 aleksis/core/templates/core/person_full.html | 48 +++++++++++---------
 2 files changed, 31 insertions(+), 21 deletions(-)

diff --git a/aleksis/core/models.py b/aleksis/core/models.py
index 2bc80574d..b8b35f41f 100644
--- a/aleksis/core/models.py
+++ b/aleksis/core/models.py
@@ -95,6 +95,10 @@ class Person(ExtensibleModel):
         ordering = ["last_name", "first_name"]
         verbose_name = _("Person")
         verbose_name_plural = _("Persons")
+        permissions = (
+            ("see_address", _("Can see address")),
+            ("see_contact_details", _("Can see contact details")),
+        )
 
     icon_ = "person"
 
diff --git a/aleksis/core/templates/core/person_full.html b/aleksis/core/templates/core/person_full.html
index 73e099fea..c44b5fb81 100644
--- a/aleksis/core/templates/core/person_full.html
+++ b/aleksis/core/templates/core/person_full.html
@@ -2,7 +2,7 @@
 
 {% extends "core/base.html" %}
 
-{% load i18n static cropping rules %}
+{% load i18n static cropping guardian_tags rules %}
 {% load render_table from django_tables2 %}
 
 {% block browser_title %}{{ person.first_name }} {{ person.last_name }}{% endblock %}
@@ -10,6 +10,8 @@
 {% block content %}
   <h4>{{ person.first_name }} {{ person.last_name }}</h4>
 
+  {% get_obj_perms request.user for person as "person_perms" %}
+
   {% has_perm 'core.change_person' user person as can_change_person %}
   {% if can_change_person %}
     <p>
@@ -50,26 +52,30 @@
           </td>
           <td colspan="3">{{ person.get_sex_display }}</td>
         </tr>
-        <tr>
-          <td>
-            <i class="material-icons small">home</i>
-          </td>
-          <td colspan="2">{{ person.street }} {{ person.housenumber }}</td>
-          <td colspan="2">{{ person.postal_code }} {{ person.place }}</td>
-        </tr>
-        <tr>
-          <td>
-            <i class="material-icons small">phone</i>
-          </td>
-          <td>{{ person.phone_number }}</td>
-          <td>{{ person.mobile_number }}</td>
-        </tr>
-        <tr>
-          <td>
-            <i class="material-icons small">email</i>
-          </td>
-          <td colspan="3">{{ person.email }}</td>
-        </tr>
+        {% if "see_address" in person_perms %}
+          <tr>
+            <td>
+              <i class="material-icons small">home</i>
+            </td>
+            <td colspan="2">{{ person.street }} {{ person.housenumber }}</td>
+            <td colspan="2">{{ person.postal_code }} {{ person.place }}</td>
+          </tr>
+        {% endif %}
+        {% if "see_contact_details" in person_perms %}
+          <tr>
+            <td>
+              <i class="material-icons small">phone</i>
+            </td>
+            <td>{{ person.phone_number }}</td>
+            <td>{{ person.mobile_number }}</td>
+          </tr>
+          <tr>
+            <td>
+              <i class="material-icons small">email</i>
+            </td>
+            <td colspan="3">{{ person.email }}</td>
+          </tr>
+        {% endif %}
         <tr>
           <td>
             <i class="material-icons small">cake</i>
-- 
GitLab