From 97d2c2468951a1c3bbf40f0f33f101c3eb99c11e Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Jaime=20Pe=CC=81rez=20Crespo?= <jaime.perez@uninett.no>
Date: Tue, 16 Jul 2019 13:56:18 +0200
Subject: [PATCH] Enhance the test auth source page.

---
 modules/admin/templates/status.twig | 75 +++++++++++++++++++++++------
 src/js/bundle.js                    |  4 +-
 2 files changed, 62 insertions(+), 17 deletions(-)

diff --git a/modules/admin/templates/status.twig b/modules/admin/templates/status.twig
index 341d3790e..f0ff25562 100644
--- a/modules/admin/templates/status.twig
+++ b/modules/admin/templates/status.twig
@@ -12,24 +12,67 @@
 
     {{ attributesHtml|raw }}
 
-    {% if nameidHtml -%}
-    <h2>{{ '{status:subject_header}'|trans }}</h2>
-    {{  nameidHtml|raw }}
-    {%- endif %}
+    {%- if nameid or authData %}
 
-    {% if authData -%}
-    <h2>{% trans %}AuthData{% endtrans %}</h2>
-    <details><summary>{% trans %}Click to view AuthData{% endtrans %}</summary>
-      <pre>{{ authData|json_encode|raw }}</pre>
-    </details>
-    {%- endif %}    
+    <h2>{% trans %}Technical information{% endtrans %}</h2>
+    {% endif %}
+    {%- if nameid %}
 
-    {% if logout -%}
-    <h2>{{ '{status:logout}'|trans }}</h2>
-    <p>{{ logout }}</p> 
-    {%- endif %}
+    <h3>{% trans %}SAML Subject{% endtrans %}</h3>
+      {%  set items = {'NameId' : nameid.value} %}
+
+      {% if not nameid.value %}
+        {%  set items = items|merge({'NameID' : 'not set'|trans}) %}
+      {% endif %}
+
+      {% if nameid.Format %}
+        {% set items = items|merge({('Format'|trans) : nameid.Format}) %}
+      {% endif %}
+
+      {% if nameid.NameQualifier %}
+        {% set items = items|merge({'NameQualifier' : nameid.NameQualifier}) %}
+      {% endif %}
+
+      {% if nameid.SPNameQualifier %}
+        {% set items = items|merge({'SPNameQualifier' : nameid.SPNameQualifier}) %}
+      {% endif %}
+
+      {% if nameid.SPProvidedID %}
+        {% set items = items|merge({'SPProvidedID' : nameid.SPProvidedID}) %}
+      {%- endif %}
+
+    <table id="table_with_attributes"  class="attributes pure-table pure-table-striped pure-table-attributes"
+           summary="{% trans %}SAML Subject{% endtrans %}">
+      {%- for name, value in items %}
+
+      <tr class="{{ cycle(['odd', 'even'], loop.index0) }}">
+        <td class="attrname">{{ name }}</td>
+        <td class="attrvalue">{{ value }}</td>
+      </tr>
+      {%- endfor %}
+
+    </table>
+    <br/>
+    {% endif %}
+
+    {% if authData %}
+    <h3>{% trans %}Authentication data{% endtrans %}</h3>
+    <div class="code-box hljs">
+      <div class="pure-button-group top-right-corner">
+        <a class="pure-button copy hljs" data-clipboard-target="#auth-data"
+           title="{% trans %}Copy to clipboard{% endtrans %}"><span class="fa fa-copy"></span></a>
+      </div>
+      <code id="auth-data" class="code-box-content json">
+        {{- authData|json_encode(constant("JSON_PRETTY_PRINT") b-or constant("JSON_UNESCAPED_SLASHES")) }}
+      </code>
+    </div>
+    <br/>
+    {% endif %}
+
+    {%- if logouturl %}
 
-    {% if logouturl -%}
-    <a href="{{ logouturl }}">{{ '{status:logout}'|trans }}</a>
+    <div class="center">
+      <a class="pure-button pure-button-red" href="{{ logouturl }}">{{ '{status:logout}'|trans }}</a>
+    </div>
     {%- endif %}
 {% endblock %}
diff --git a/src/js/bundle.js b/src/js/bundle.js
index 2766b06fa..a485174ba 100644
--- a/src/js/bundle.js
+++ b/src/js/bundle.js
@@ -4,6 +4,7 @@ import "selectize/dist/js/selectize";
 import hljs from  "highlight.js/lib/highlight";
 import xml from "highlight.js/lib/languages/xml";
 import php from "highlight.js/lib/languages/php";
+import json from "highlight.js/lib/languages/json";
 
 $(document).ready(function () {
     // get available languages
@@ -39,7 +40,8 @@ $(document).ready(function () {
     // syntax highlight
     hljs.registerLanguage('xml', xml);
     hljs.registerLanguage('php', php);
-    $('.code-box-content.xml, .code-box-content.php').each(function(i, block) {
+    hljs.registerLanguage('json', json);
+    $('.code-box-content.xml, .code-box-content.php, .code-box-content.json').each(function(i, block) {
         hljs.highlightBlock(block)
     });
 
-- 
GitLab