From 29b942ceb8594e1f4e57f06ca643acd381fae45b Mon Sep 17 00:00:00 2001 From: Enrico Zini Date: Mon, 20 Apr 2020 23:39:16 +0200 Subject: [PATCH] Added page to see a person's identities. refs: #2 --- signon/templates/signon/audit_identities.html | 69 +++++++++++++++++++ signon/templates/signon/identities.html | 13 ++++ signon/templates/signon/login.html | 58 +++------------- signon/urls.py | 2 + signon/views.py | 12 +++- 5 files changed, 103 insertions(+), 51 deletions(-) create mode 100644 signon/templates/signon/audit_identities.html create mode 100644 signon/templates/signon/identities.html diff --git a/signon/templates/signon/audit_identities.html b/signon/templates/signon/audit_identities.html new file mode 100644 index 0000000..8aa7d8b --- /dev/null +++ b/signon/templates/signon/audit_identities.html @@ -0,0 +1,69 @@ +{% load i18n %} + +{% for identity in identities %} +
+ +
+
+ {% if identity.picture %} + + {% endif %} + {% trans "Account information" %} +
+ + + {% if identity.subject %} + + {% endif %} + {% if identity.fullname %} + + {% endif %} + {% if identity.username %} + + {% endif %} +
{% trans "Last used" %}{{identity.last_used|date:"Y-m-d"}}
{% trans "Subject" %}{{identity.subject}}
{% trans "Full name" %}{{identity.fullname}}
{% trans "User name" %}{{identity.username}}
+
{% trans "Audit log" %}
+ + + + + + + + + + + {% for e in identity.audit_log.all %} + + + + + + + {% empty %} + + {% endfor %} + +
{% trans "Date" %}{% trans "Author" %}{% trans "Notes" %}{% trans "Changes" %}
{{e.logdate|date:"Y-m-d H:i:s"}}{{e.author}}{{e.notes}} +
    + {% for field, old, new in e.get_changes_list %} +
  • {{field}}: {{old}} → {{new}}
  • + {% endfor %} +
+
{% trans "No audit log for this identity" %}
+
+
+{% endfor %} + diff --git a/signon/templates/signon/identities.html b/signon/templates/signon/identities.html new file mode 100644 index 0000000..2309cdb --- /dev/null +++ b/signon/templates/signon/identities.html @@ -0,0 +1,13 @@ +{% extends "nm2-base.html" %} +{% load nm %} +{% load i18n %} + +{% block content %} + +

{{person.fullname}} identities

+ +{% if identities %} +{% include "signon/audit_identities.html" with identities=identities only %} +{% endif %} + +{% endblock %} diff --git a/signon/templates/signon/login.html b/signon/templates/signon/login.html index 07a43ff..0dd6822 100644 --- a/signon/templates/signon/login.html +++ b/signon/templates/signon/login.html @@ -23,19 +23,21 @@ {% for provider in providers_active %}
  • + {% with provider.get_active_identity as identity %} {% if provider.icon %} {% else %} {% endif %} - {% if provider.profile %} - {{provider.label}} + {% if identity.profile %} + {{provider.label}} {% else %} {{provider.label}} {% endif %} - {% if provider.username %} - ({{provider.username}}) + {% if identity.username %} + ({{identity.username}}) {% endif %} + {% endwith %}
    {% if provider.get_active_identity %} @@ -81,52 +83,8 @@ {% endif %} {% if identities %} -

    Identity audit logs

    -{% for identity in identities %} -
    - - - - - - - - - - - - {% for e in identity.audit_log.all %} - - - - - - - {% empty %} - - {% endfor %} - -
    {% trans "Date" %}{% trans "Author" %}{% trans "Notes" %}{% trans "Changes" %}
    {{e.logdate|date:"Y-m-d H:i:s"}}{{e.author}}{{e.notes}} -
      - {% for field, old, new in e.get_changes_list %} -
    • {{field}}: {{old}} → {{new}}
    • - {% endfor %} -
    -
    {% trans "No audit log for this identity" %}
    -
    -{% endfor %} +

    {% trans "Identity audit logs" %}

    +{% include "signon/audit_identities.html" with identities=identities only %} {% endif %} {% endblock %} diff --git a/signon/urls.py b/signon/urls.py index 21b919a..065b4b0 100644 --- a/signon/urls.py +++ b/signon/urls.py @@ -3,6 +3,8 @@ from . import views urlpatterns = [ path('login/', views.Login.as_view(), name='signon_login'), + path('identities/', views.Identities.as_view(), name='signon_identities'), + path('identities//', views.Identities.as_view(), name='signon_identities_person'), path('logout/', views.Logout.as_view(), name='signon_logout'), path('oidc/callback//', views.OIDCAuthenticationCallbackView.as_view(), name='signon_oidc_callback'), ] diff --git a/signon/views.py b/signon/views.py index 68c61ca..8f20912 100644 --- a/signon/views.py +++ b/signon/views.py @@ -4,7 +4,7 @@ from django.views.generic import View, TemplateView from django import http from django.shortcuts import redirect from django.contrib import auth -from backend.mixins import VisitorMixin +from backend.mixins import VisitorMixin, VisitPersonMixin from backend.models import Person from .models import Identity from . import providers @@ -45,6 +45,16 @@ class Logout(View): return redirect("home") +class Identities(VisitPersonMixin, TemplateView): + template_name = "signon/identities.html" + require_visit_perms = "view_person_audit_log" + + def get_context_data(self, **kw): + ctx = super().get_context_data(**kw) + ctx["identities"] = self.person.identities.all() + return ctx + + class OIDCAuthenticationCallbackView(View): def get(self, request, *args, **kw): name = self.kwargs["name"] -- GitLab