From bacf2adf08ca0ace225a9fc2a58ebd439e517caa Mon Sep 17 00:00:00 2001 From: Abhilash Raj Date: Fri, 15 Jun 2018 12:27:00 -0700 Subject: [PATCH] Display system information for the Administrator. Thanks to Simon Hanna for initial version of this patch that I then modified. --- src/postorius/templates/postorius/base.html | 6 + .../templates/postorius/system_information.html | 19 ++++ ...TestSystemInformationPage.test_system_info.yaml | 122 +++++++++++++++++++++ .../tests/mailman_api_tests/test_system.py | 46 ++++++++ src/postorius/urls.py | 9 +- src/postorius/views/system.py | 47 ++++++++ 6 files changed, 247 insertions(+), 2 deletions(-) create mode 100644 src/postorius/templates/postorius/system_information.html create mode 100644 src/postorius/tests/fixtures/vcr_cassettes/TestSystemInformationPage.test_system_info.yaml create mode 100644 src/postorius/tests/mailman_api_tests/test_system.py create mode 100644 src/postorius/views/system.py diff --git a/src/postorius/templates/postorius/base.html b/src/postorius/templates/postorius/base.html index f0e52c61..5e4111db 100644 --- a/src/postorius/templates/postorius/base.html +++ b/src/postorius/templates/postorius/base.html @@ -44,6 +44,12 @@ {% trans 'Domains' %} +
  • + + + {% trans 'System Information' %} + +
  • {% endif %} {% if 'hyperkitty' in INSTALLED_APPS %}
  • diff --git a/src/postorius/templates/postorius/system_information.html b/src/postorius/templates/postorius/system_information.html new file mode 100644 index 00000000..936f6156 --- /dev/null +++ b/src/postorius/templates/postorius/system_information.html @@ -0,0 +1,19 @@ +{% extends "postorius/base.html" %} +{% load i18n %} +{% load pagination %} + +{% block head_title %} +{% trans 'System Configuration' %} - {{ block.super }} +{% endblock %} + +{% block content %} +

    Mailman System

    + + {% for key, value in configs %} + + + + + {% endfor %} +
    {{ key }}{{ value }}
    +{% endblock content %} diff --git a/src/postorius/tests/fixtures/vcr_cassettes/TestSystemInformationPage.test_system_info.yaml b/src/postorius/tests/fixtures/vcr_cassettes/TestSystemInformationPage.test_system_info.yaml new file mode 100644 index 00000000..b91f1d5b --- /dev/null +++ b/src/postorius/tests/fixtures/vcr_cassettes/TestSystemInformationPage.test_system_info.yaml @@ -0,0 +1,122 @@ +interactions: +- request: + body: null + headers: + accept-encoding: ['gzip, deflate'] + method: GET + uri: http://localhost:9001/3.0/system/versions + response: + body: {string: '{"api_version": "3.0", "http_etag": "\"8db6b3a7e28c91c5dfdcb503723510ac4013fd65\"", + "mailman_version": "GNU Mailman 3.2.0a1 (La Villa Strangiato)", "python_version": + "3.6.4+ (default, Feb 12 2018, 08:25:03) \n[GCC 7.3.0]", "self_link": "http://localhost:9001/3.0/system/versions"}'} + headers: + content-length: ['280'] + content-type: [application/json; charset=UTF-8] + status: {code: 200, message: OK} +- request: + body: null + headers: + accept-encoding: ['gzip, deflate'] + method: GET + uri: http://localhost:9001/3.0/domains + response: + body: {string: '{"http_etag": "\"32223434a0f3af4cdc4673d1fbc5bac1f6d98fd3\"", + "start": 0, "total_size": 0}'} + headers: + content-length: ['90'] + content-type: [application/json; charset=UTF-8] + status: {code: 200, message: OK} +- request: + body: null + headers: + accept-encoding: ['gzip, deflate'] + method: GET + uri: http://localhost:9001/3.0/users + response: + body: {string: '{"http_etag": "\"32223434a0f3af4cdc4673d1fbc5bac1f6d98fd3\"", + "start": 0, "total_size": 0}'} + headers: + content-length: ['90'] + content-type: [application/json; charset=UTF-8] + status: {code: 200, message: OK} +- request: + body: null + headers: + accept-encoding: ['gzip, deflate'] + method: GET + uri: http://localhost:9001/3.0/system/versions + response: + body: {string: '{"api_version": "3.0", "http_etag": "\"8db6b3a7e28c91c5dfdcb503723510ac4013fd65\"", + "mailman_version": "GNU Mailman 3.2.0a1 (La Villa Strangiato)", "python_version": + "3.6.4+ (default, Feb 12 2018, 08:25:03) \n[GCC 7.3.0]", "self_link": "http://localhost:9001/3.0/system/versions"}'} + headers: + content-length: ['280'] + content-type: [application/json; charset=UTF-8] + status: {code: 200, message: OK} +- request: + body: null + headers: + accept-encoding: ['gzip, deflate'] + method: GET + uri: http://localhost:9001/3.0/domains + response: + body: {string: '{"http_etag": "\"32223434a0f3af4cdc4673d1fbc5bac1f6d98fd3\"", + "start": 0, "total_size": 0}'} + headers: + content-length: ['90'] + content-type: [application/json; charset=UTF-8] + status: {code: 200, message: OK} +- request: + body: null + headers: + accept-encoding: ['gzip, deflate'] + method: GET + uri: http://localhost:9001/3.0/users + response: + body: {string: '{"http_etag": "\"32223434a0f3af4cdc4673d1fbc5bac1f6d98fd3\"", + "start": 0, "total_size": 0}'} + headers: + content-length: ['90'] + content-type: [application/json; charset=UTF-8] + status: {code: 200, message: OK} +- request: + body: null + headers: + accept-encoding: ['gzip, deflate'] + method: GET + uri: http://localhost:9001/3.0/system/versions + response: + body: {string: '{"api_version": "3.0", "http_etag": "\"8db6b3a7e28c91c5dfdcb503723510ac4013fd65\"", + "mailman_version": "GNU Mailman 3.2.0a1 (La Villa Strangiato)", "python_version": + "3.6.4+ (default, Feb 12 2018, 08:25:03) \n[GCC 7.3.0]", "self_link": "http://localhost:9001/3.0/system/versions"}'} + headers: + content-length: ['280'] + content-type: [application/json; charset=UTF-8] + status: {code: 200, message: OK} +- request: + body: null + headers: + accept-encoding: ['gzip, deflate'] + method: GET + uri: http://localhost:9001/3.0/domains + response: + body: {string: '{"http_etag": "\"32223434a0f3af4cdc4673d1fbc5bac1f6d98fd3\"", + "start": 0, "total_size": 0}'} + headers: + content-length: ['90'] + content-type: [application/json; charset=UTF-8] + status: {code: 200, message: OK} +- request: + body: null + headers: + accept-encoding: ['gzip, deflate'] + method: GET + uri: http://localhost:9001/3.0/users + response: + body: {string: '{"http_etag": "\"32223434a0f3af4cdc4673d1fbc5bac1f6d98fd3\"", + "start": 0, "total_size": 0}'} + headers: + content-length: ['90'] + content-type: [application/json; charset=UTF-8] + status: {code: 200, message: OK} +version: 1 diff --git a/src/postorius/tests/mailman_api_tests/test_system.py b/src/postorius/tests/mailman_api_tests/test_system.py new file mode 100644 index 00000000..7e3a1a02 --- /dev/null +++ b/src/postorius/tests/mailman_api_tests/test_system.py @@ -0,0 +1,46 @@ +# -*- coding: utf-8 -*- +# Copyright (C) 2018 by the Free Software Foundation, Inc. +# +# This file is part of Postorius. +# +# Postorius is free software: you can redistribute it and/or modify it under +# the terms of the GNU General Public License as published by the Free +# Software Foundation, either version 3 of the License, or (at your option) +# any later version. +# +# Postorius is distributed in the hope that it will be useful, but WITHOUT +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for +# more details. +# +# You should have received a copy of the GNU General Public License along with +# Postorius. If not, see . +# + +from allauth.account.models import EmailAddress +from django.contrib.auth.models import User +from django.urls import reverse + +from postorius.tests.utils import ViewTestCase + + +class TestSystemInformationPage(ViewTestCase): + + def setUp(self): + super().setUp() + self.superuser = User.objects.create_superuser( + 'testsu', 'su@example.com', 'testpass') + EmailAddress.objects.create( + user=self.superuser, email='su@example.com', verified=True) + + def test_system_info(self): + response = self.client.get(reverse('system_information')) + # Logged-out users shouldn't be able to get this information. + self.assertEqual(response.status_code, 302) + # Superuser should have access to this information. + self.assertTrue(self.client.login( + username='testsu', password='testpass')) + response = self.client.get(reverse('system_information')) + self.assertEqual(response.status_code, 200) + self.assertIn(b'Mailman Core API Version', response.content) + self.assertIn(b'Mailman Core Version', response.content) diff --git a/src/postorius/urls.py b/src/postorius/urls.py index d1b44a2f..0ffe75ab 100644 --- a/src/postorius/urls.py +++ b/src/postorius/urls.py @@ -19,10 +19,11 @@ from django.conf.urls import url, include -from postorius.views import list as list_views -from postorius.views import user as user_views from postorius.views import domain as domain_views +from postorius.views import list as list_views from postorius.views import rest as rest_views +from postorius.views import system as system_views +from postorius.views import user as user_views list_patterns = [ @@ -96,6 +97,10 @@ urlpatterns = [ url(r'^lists/$', list_views.list_index, name='list_index'), url(r'^lists/new/$', list_views.list_new, name='list_new'), url(r'^lists/(?P[^/]+)/', include(list_patterns)), + + url(r'^system/$', system_views.system_information, + name='system_information'), + url(r'^api/list/(?P[^/]+)/held_message/(?P\d+)/$', rest_views.get_held_message, name='rest_held_message'), url(r'^api/list/(?P[^/]+)/held_message/(?P\d+)/' diff --git a/src/postorius/views/system.py b/src/postorius/views/system.py new file mode 100644 index 00000000..0447151d --- /dev/null +++ b/src/postorius/views/system.py @@ -0,0 +1,47 @@ +# -*- coding: utf-8 -*- +# Copyright (C) 2018 by the Free Software Foundation, Inc. +# +# This file is part of Postorius. +# +# Postorius is free software: you can redistribute it and/or modify it under +# the terms of the GNU General Public License as published by the Free +# Software Foundation, either version 3 of the License, or (at your option) +# any later version. +# +# Postorius is distributed in the hope that it will be useful, but WITHOUT +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for +# more details. +# +# You should have received a copy of the GNU General Public License along with +# Postorius. If not, see . + +from django.contrib.auth.decorators import login_required +from django.shortcuts import render +from django_mailman3.lib.mailman import get_mailman_client + +from postorius.auth.decorators import superuser_required + + +SYSTEM_INFO_KEYS = ( + ('mailman_version', 'Mailman Core Version'), + ('api_version', 'Mailman Core API Version'), + ('python_version', 'Mailman Core Python Version'), +) + + +@login_required +@superuser_required +def system_information(request): + client = get_mailman_client() + all_configs = client.system + + configs = [] + for key, name in SYSTEM_INFO_KEYS: + configs.append((name, all_configs.get(key))) + + return render( + request, + 'postorius/system_information.html', + {'configs': configs}, + ) -- 2.11.4.GIT