From a99865792330b86d0c29c056e8a40ae9e3ed97e6 Mon Sep 17 00:00:00 2001 From: FinnStutzenstein Date: Fri, 1 Dec 2017 10:10:35 +0100 Subject: [PATCH] extended the legal notice page (fixes #3504) --- openslides/__init__.py | 2 ++ openslides/core/static/js/core/site.js | 2 ++ .../core/static/templates/legalnotice.html | 22 ++++++++++--- openslides/core/views.py | 20 ++++++++++-- openslides/utils/plugins.py | 32 +++++++++++++++++++ setup.py | 6 ++-- tests/integration/core/test_views.py | 8 ++++- tests/integration/test_plugin/__init__.py | 1 + tests/integration/test_plugin/apps.py | 3 +- 9 files changed, 85 insertions(+), 11 deletions(-) diff --git a/openslides/__init__.py b/openslides/__init__.py index a1e659cde..e85db05b2 100644 --- a/openslides/__init__.py +++ b/openslides/__init__.py @@ -1,3 +1,5 @@ __author__ = 'OpenSlides Team ' __description__ = 'Presentation and assembly system' __version__ = '2.1.2-dev' +__license__ = 'MIT' +__url__ = 'https://openslides.org' diff --git a/openslides/core/static/js/core/site.js b/openslides/core/static/js/core/site.js index 7b0f19a54..37f9a6b5e 100644 --- a/openslides/core/static/js/core/site.js +++ b/openslides/core/static/js/core/site.js @@ -1111,6 +1111,8 @@ angular.module('OpenSlidesApp.core.site', [ function ($scope, $http) { $http.get('/core/version/').then(function (success) { $scope.core_version = success.data.openslides_version; + $scope.core_license = success.data.openslides_license; + $scope.core_url = success.data.openslides_url; $scope.plugins = success.data.plugins; }); } diff --git a/openslides/core/static/templates/legalnotice.html b/openslides/core/static/templates/legalnotice.html index 431fd1174..68e2e77b9 100644 --- a/openslides/core/static/templates/legalnotice.html +++ b/openslides/core/static/templates/legalnotice.html @@ -7,12 +7,26 @@

-

OpenSlides {{ core_version }} +

+ + OpenSlides {{ core_version }} + + (License: {{ core_license }}) +

Installed plugins:

-
    +
    • - {{ plugin.verbose_name }}: {{ plugin.version }} -
+ + {{ plugin.verbose_name }} {{ plugin.version }} + + + {{ plugin.verbose_name }} {{ plugin.version }} + + + (License: {{ plugin.license}}) + + +
diff --git a/openslides/core/views.py b/openslides/core/views.py index bd8e5c038..018523e5f 100644 --- a/openslides/core/views.py +++ b/openslides/core/views.py @@ -13,12 +13,16 @@ from django.utils.timezone import now from django.utils.translation import ugettext as _ from mypy_extensions import TypedDict +from .. import __license__ as license +from .. import __url__ as url from .. import __version__ as version from ..utils import views as utils_views from ..utils.auth import anonymous_is_enabled, has_perm from ..utils.autoupdate import inform_changed_data, inform_deleted_data from ..utils.plugins import ( get_plugin_description, + get_plugin_license, + get_plugin_url, get_plugin_verbose_name, get_plugin_version, ) @@ -783,12 +787,22 @@ class VersionView(utils_views.APIView): http_method_names = ['get'] def get_context_data(self, **context): - Result = TypedDict('Result', {'openslides_version': str, 'plugins': List[Dict[str, str]]}) # noqa - result = dict(openslides_version=version, plugins=[]) # type: Result + Result = TypedDict('Result', { # noqa + 'openslides_version': str, + 'openslides_license': str, + 'openslides_url': str, + 'plugins': List[Dict[str, str]]}) + result = dict( + openslides_version=version, + openslides_license=license, + openslides_url=url, + plugins=[]) # type: Result # Versions of plugins. for plugin in settings.INSTALLED_PLUGINS: result['plugins'].append({ 'verbose_name': get_plugin_verbose_name(plugin), 'description': get_plugin_description(plugin), - 'version': get_plugin_version(plugin)}) + 'version': get_plugin_version(plugin), + 'license': get_plugin_license(plugin), + 'url': get_plugin_url(plugin)}) return result diff --git a/openslides/utils/plugins.py b/openslides/utils/plugins.py index 184c79de1..ddc773f97 100644 --- a/openslides/utils/plugins.py +++ b/openslides/utils/plugins.py @@ -93,6 +93,38 @@ def get_plugin_version(plugin: str) -> str: return version +def get_plugin_license(plugin: str) -> str: + """ + Returns the license string of a plugin. The plugin argument must be a + python dotted module path. + """ + plugin_app_config = apps.get_app_config(plugin) + try: + license = plugin_app_config.get_license() + except AttributeError: + try: + license = plugin_app_config.license + except AttributeError: + license = '' + return license + + +def get_plugin_url(plugin: str) -> str: + """ + Returns the url of a plugin. The plugin argument must be a + python dotted module path. + """ + plugin_app_config = apps.get_app_config(plugin) + try: + url = plugin_app_config.get_url() + except AttributeError: + try: + url = plugin_app_config.url + except AttributeError: + url = '' + return url + + def get_plugin_urlpatterns(plugin: str) -> Any: """ Returns the urlpatterns object for a plugin. The plugin argument must be diff --git a/setup.py b/setup.py index acaf76802..2baccfeea 100644 --- a/setup.py +++ b/setup.py @@ -5,6 +5,8 @@ from setuptools import find_packages, setup from openslides import __author__ as openslides_author from openslides import __description__ as openslides_description from openslides import __version__ as openslides_version +from openslides import __license__ as openslides_license +from openslides import __url__ as openslides_url with open('README.rst') as readme: long_description = readme.read() @@ -17,9 +19,9 @@ setup( author=openslides_author, author_email='support@openslides.org', description=openslides_description, - license='MIT', + license=openslides_license, long_description=long_description, - url='https://openslides.org', + url=openslides_url, version=openslides_version, classifiers=[ diff --git a/tests/integration/core/test_views.py b/tests/integration/core/test_views.py index 02e5eecff..d793e2301 100644 --- a/tests/integration/core/test_views.py +++ b/tests/integration/core/test_views.py @@ -5,6 +5,8 @@ from django.core.urlresolvers import reverse from rest_framework import status from rest_framework.test import APIClient +from openslides import __license__ as license +from openslides import __url__ as url from openslides import __version__ as version from openslides.core.config import ConfigVariable, config from openslides.core.models import Projector @@ -71,10 +73,14 @@ class VersionView(TestCase): response = self.client.get(reverse('core_version')) self.assertEqual(json.loads(response.content.decode()), { 'openslides_version': version, + 'openslides_license': license, + 'openslides_url': url, 'plugins': [ {'verbose_name': 'OpenSlides Test Plugin', 'description': 'This is a test plugin for OpenSlides.', - 'version': 'unknown'}]}) + 'version': 'unknown', + 'license': 'MIT', + 'url': ''}]}) class WebclientJavaScriptView(TestCase): diff --git a/tests/integration/test_plugin/__init__.py b/tests/integration/test_plugin/__init__.py index e6e60f0e6..d7708b634 100644 --- a/tests/integration/test_plugin/__init__.py +++ b/tests/integration/test_plugin/__init__.py @@ -1,4 +1,5 @@ __verbose_name__ = 'OpenSlides Test Plugin' __description__ = 'This is a test plugin for OpenSlides.' +__license__ = 'MIT' default_app_config = 'tests.integration.test_plugin.apps.TestPluginAppConfig' diff --git a/tests/integration/test_plugin/apps.py b/tests/integration/test_plugin/apps.py index dfaee9885..8e295918b 100644 --- a/tests/integration/test_plugin/apps.py +++ b/tests/integration/test_plugin/apps.py @@ -1,6 +1,6 @@ from django.apps import AppConfig -from . import __description__, __verbose_name__ +from . import __description__, __license__, __verbose_name__ class TestPluginAppConfig(AppConfig): @@ -11,3 +11,4 @@ class TestPluginAppConfig(AppConfig): label = 'tests.integration.test_plugin' verbose_name = __verbose_name__ description = __description__ + license = __license__