From e53f5184ed74e73add71512850800b7221970912 Mon Sep 17 00:00:00 2001 From: Scott Koranda Date: Thu, 21 Feb 2019 15:31:44 -0600 Subject: [PATCH] Updated for Mailman 3.2.0 Changes necessary to ingegrate COmanage Registry with Mailman 3.2.0. --- comanage-registry-mailman/core/Dockerfile | 2 +- comanage-registry-mailman/core/addresses.py | 5 +--- comanage-registry-mailman/core/users.py | 26 ++++++++++-------- comanage-registry-mailman/web/Dockerfile | 27 +++++++------------ .../web/mailman-web/manage.py | 2 +- .../web/mailman-web/settings.py | 19 ++++++++++--- .../web/mailman-web/urls.py | 4 +-- 7 files changed, 44 insertions(+), 41 deletions(-) diff --git a/comanage-registry-mailman/core/Dockerfile b/comanage-registry-mailman/core/Dockerfile index 1d62ffc..637eef4 100644 --- a/comanage-registry-mailman/core/Dockerfile +++ b/comanage-registry-mailman/core/Dockerfile @@ -29,7 +29,7 @@ RUN apt-get update \ postgresql-client \ python3-dev \ && pip install psycopg2 \ - mailman==3.1.1 \ + mailman==3.2 \ mailman-hyperkitty==1.1.0 \ pymysql \ && adduser --system mailman diff --git a/comanage-registry-mailman/core/addresses.py b/comanage-registry-mailman/core/addresses.py index a249053..d42d394 100644 --- a/comanage-registry-mailman/core/addresses.py +++ b/comanage-registry-mailman/core/addresses.py @@ -1,4 +1,4 @@ -# Copyright (C) 2011-2017 by the Free Software Foundation, Inc. +# Copyright (C) 2011-2018 by the Free Software Foundation, Inc. # # This file is part of GNU Mailman. # @@ -196,9 +196,7 @@ def on_post(self, request, response): Add a new address to the user record. """ assert self._user is not None - preferred = None - user_manager = getUtility(IUserManager) validator = Validator(email=str, display_name=str, @@ -207,7 +205,6 @@ def on_post(self, request, response): _optional=('display_name', 'absorb_existing', 'preferred')) try: data = validator(request) - # We cannot set the address to be preferred when it is # created so remove it from the arguments here and # set it below. diff --git a/comanage-registry-mailman/core/users.py b/comanage-registry-mailman/core/users.py index 4813ac9..0387628 100644 --- a/comanage-registry-mailman/core/users.py +++ b/comanage-registry-mailman/core/users.py @@ -1,4 +1,4 @@ -# Copyright (C) 2011-2017 by the Free Software Foundation, Inc. +# Copyright (C) 2011-2018 by the Free Software Foundation, Inc. # # This file is part of GNU Mailman. # @@ -152,7 +152,8 @@ def create_user(api, arguments, response): user.link(address) else: bad_request( - response, 'User already exists: {}'.format(error.address)) + response, + 'User already exists: {}'.format(error.address).encode()) return None if password is None: # This will have to be reset since it cannot be retrieved. @@ -296,16 +297,16 @@ def on_patch(self, request, response): return try: validator = PatchValidator(request, ATTRIBUTES) - validator.update(self._user, request) except UnknownPATCHRequestError as error: bad_request( - response, b'Unknown attribute: {0}'.format(error.attribute)) + response, + 'Unknown attribute: {0}'.format(error.attribute).encode()) except ReadOnlyPATCHRequestError as error: bad_request( - response, b'Read-only attribute: {0}'.format(error.attribute)) - except ValueError as error: - bad_request(response, str(error)) + response, + 'Read-only attribute: {0}'.format(error.attribute).encode()) else: + validator.update(self._user, request) no_content(response) def on_put(self, request, response): @@ -318,10 +319,12 @@ def on_put(self, request, response): validator.update(self._user, request) except UnknownPATCHRequestError as error: bad_request( - response, b'Unknown attribute: {0}'.format(error.attribute)) + response, + 'Unknown attribute: {0}'.format(error.attribute).encode()) except ReadOnlyPATCHRequestError as error: bad_request( - response, b'Read-only attribute: {0}'.format(error.attribute)) + response, + 'Read-only attribute: {0}'.format(error.attribute).encode()) except ValueError as error: bad_request(response, str(error)) else: @@ -385,7 +388,7 @@ def on_post(self, request, response): user = user_manager.get_user_by_id(user_id) if user is None: bad_request(response, 'No user with ID {}'.format( - self.api.from_uuid(user_id))) + self.api.from_uuid(user_id)).encode()) return okay(response) else: @@ -420,7 +423,8 @@ def on_put(self, request, response): user_id = arguments['user_id'] user = user_manager.get_user_by_id(user_id) if user is None: - not_found(response, b'No user with ID {}'.format(user_id)) + not_found(response, + 'No user with ID {}'.format(user_id).encode()) return okay(response) else: diff --git a/comanage-registry-mailman/web/Dockerfile b/comanage-registry-mailman/web/Dockerfile index e869e40..95c082a 100644 --- a/comanage-registry-mailman/web/Dockerfile +++ b/comanage-registry-mailman/web/Dockerfile @@ -17,7 +17,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -FROM python:2.7-stretch +FROM python:3.6-stretch RUN apt-get update \ && apt-get install -y --no-install-recommends \ @@ -29,35 +29,26 @@ RUN apt-get update \ postgresql-client \ sassc \ && pip install --upgrade pip \ - && pip install django-allauth==0.35.0 \ - django-appconf==1.0.2 \ - django-compressor==2.2 \ - django-extensions==2.0.7 \ - django-gravatar2==1.4.2 \ - django-haystack==2.8.1 \ - django-mailman3==1.1.0 \ - django-paintstore==0.2 \ - django-picklefield==1.0.0 \ - django-q==0.9.4 \ - djangorestframework==3.8.2 \ - && pip install django==1.11 \ - && pip install mailmanclient==3.1.1 \ - postorius==1.1.2 \ - hyperkitty==1.1.4 \ - django-mailman3==1.1.0 \ + && pip install django==2.1.5 \ + && pip install \ + mailmanclient==3.2.1 \ + postorius==1.2.3 \ + hyperkitty==1.2.1 \ + django-mailman3==1.2.0 \ whoosh \ uwsgi \ psycopg2 \ dj-database-url \ mysqlclient \ typing \ + xapian-haystack \ && adduser --system --no-create-home --group mailman # Add needed files for uwsgi server + settings for django COPY mailman-web /opt/mailman-web # Overlay customized template for Postorius login -COPY login.html /usr/local/lib/python2.7/site-packages/django_mailman3/templates/account/ +#COPY login.html /usr/local/lib/python2.7/site-packages/django_mailman3/templates/account/ RUN chown -R mailman:mailman /opt/mailman-web/ \ && chmod u+x /opt/mailman-web/manage.py diff --git a/comanage-registry-mailman/web/mailman-web/manage.py b/comanage-registry-mailman/web/mailman-web/manage.py index f9726f9..4eb6f34 100755 --- a/comanage-registry-mailman/web/mailman-web/manage.py +++ b/comanage-registry-mailman/web/mailman-web/manage.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 import os import sys diff --git a/comanage-registry-mailman/web/mailman-web/settings.py b/comanage-registry-mailman/web/mailman-web/settings.py index 35a57f8..6bc7bcc 100644 --- a/comanage-registry-mailman/web/mailman-web/settings.py +++ b/comanage-registry-mailman/web/mailman-web/settings.py @@ -65,7 +65,7 @@ # Application definition -INSTALLED_APPS = ( +INSTALLED_APPS = [ 'hyperkitty', 'postorius', 'django_mailman3', @@ -81,7 +81,6 @@ 'django.contrib.staticfiles', 'rest_framework', 'django_gravatar', - 'paintstore', 'compressor', 'haystack', 'django_extensions', @@ -94,7 +93,17 @@ 'allauth.socialaccount.providers.github', 'allauth.socialaccount.providers.gitlab', 'allauth.socialaccount.providers.google', -) +] + +# Optionally include paintstore, if it was installed with Hyperkitty. +# TODO: Remove this after a new version of Hyperkitty is released and +# neither the stable nor the rolling version needs it. +try: + import paintstore + INSTALLED_APPS.append('paintstore') +except ImportError: + pass + _MIDDLEWARE = ( 'django.contrib.sessions.middleware.SessionMiddleware', @@ -102,7 +111,6 @@ 'django.middleware.csrf.CsrfViewMiddleware', 'django.middleware.locale.LocaleMiddleware', 'django.contrib.auth.middleware.AuthenticationMiddleware', - 'django.contrib.auth.middleware.SessionAuthenticationMiddleware', 'django.contrib.messages.middleware.MessageMiddleware', 'django.middleware.clickjacking.XFrameOptionsMiddleware', 'django.middleware.security.SecurityMiddleware', @@ -259,6 +267,7 @@ SOCIALACCOUNT_PROVIDERS = {} + # django-compressor # https://pypi.python.org/pypi/django_compressor # @@ -378,6 +387,8 @@ 'orm': 'default', } +POSTORIUS_TEMPLATE_BASE_URL = os.environ.get('POSTORIUS_TEMPLATE_BASE_URL', 'http://mailman-web:8000') + try: from settings_local import * except ImportError: diff --git a/comanage-registry-mailman/web/mailman-web/urls.py b/comanage-registry-mailman/web/mailman-web/urls.py index a6b9174..e8bb66c 100644 --- a/comanage-registry-mailman/web/mailman-web/urls.py +++ b/comanage-registry-mailman/web/mailman-web/urls.py @@ -19,7 +19,7 @@ from django.conf.urls import include, url from django.contrib import admin -from django.core.urlresolvers import reverse_lazy +from django.urls import reverse_lazy from django.views.generic import RedirectView urlpatterns = [ @@ -31,5 +31,5 @@ url(r'', include('django_mailman3.urls')), url(r'^accounts/', include('allauth.urls')), # Django admin - url(r'^admin/', include(admin.site.urls)), + url(r'^admin/', admin.site.urls), ]