Commit 75ab2e87 authored by Joren Vrancken's avatar Joren Vrancken

Merge branch 'remove-mailinglists-api' into 'master'

Remove mailinglists API

See merge request !1397
parents 19382ff7 6dc2becf
mailinglists.api package
.. automodule:: mailinglists.api
mailinglists.api.permissions module
.. automodule:: mailinglists.api.permissions
mailinglists.api.serializers module
.. automodule:: mailinglists.api.serializers
mailinglists.api.urls module
.. automodule:: mailinglists.api.urls
mailinglists.api.viewsets module
.. automodule:: mailinglists.api.viewsets
......@@ -6,13 +6,6 @@ mailinglists package
.. toctree::
"""DRF permissions defined by the mailinglists package"""
from django.conf import settings
from rest_framework import permissions
class MailingListPermission(permissions.BasePermission):
"""Permission check for mailing list secret key."""
def has_permission(self, request, view):
"""Return whether the user has access to the mailing list api."""
if request.user.is_superuser:
return True
if 'secret' in request.GET:
return (request.GET['secret']
return False
"""DRF serializers defined by the mailinglists package"""
from rest_framework import serializers
from mailinglists.models import MailingList
class MailingListSerializer(serializers.ModelSerializer):
"""Serializer for serializing mailing lists."""
class Meta:
"""Meta class for the MailingListSerializer."""
model = MailingList
fields = ('names', 'prefix', 'archived', 'moderated', 'addresses',
'autoresponse_enabled', 'autoresponse_text')
names = serializers.SerializerMethodField('_names')
addresses = serializers.SerializerMethodField('_addresses')
def _names(self, instance):
"""Return list of names of the the mailing list and its aliases."""
return [] + [x.alias for x in instance.aliases.all()]
def _addresses(self, instance):
"""Return list of all subscribed addresses."""
return instance.all_addresses()
"""DRF routes defined by the mailinglists package"""
from rest_framework import routers
from mailinglists.api import viewsets
router = routers.SimpleRouter()
router.register(r'mailinglists', viewsets.MailingListViewset)
urlpatterns = router.urls
"""DRF viewsets defined by the mailinglists package"""
from rest_framework import viewsets
from mailinglists import services
from mailinglists.api.permissions import MailingListPermission
from mailinglists.api.serializers import MailingListSerializer
from mailinglists.models import MailingList
class MailingListViewset(viewsets.ReadOnlyModelViewSet):
"""Viewswet class for mailing lists."""
permission_classes = [MailingListPermission]
queryset = MailingList.objects.all()
serializer_class = MailingListSerializer
def list(self, request, *args, **kwargs):
"""Return response with a list of serialized mailing lists."""
response = super().list(request, *args, **kwargs)
automatic_lists = services.get_automatic_lists()
if automatic_lists is not None: = list( + automatic_lists
return response
......@@ -292,9 +292,6 @@ CONSCRIBO_PASSWORD = os.environ.get('CONSCRIBO_PASSWORD', '')
# Payments creditor identifier
# Mailinglist API key
# Members Sentry API key
......@@ -103,7 +103,6 @@ urlpatterns = [ # pylint: disable=invalid-name
path('', include('events.api.urls')),
path('', include('members.api.urls')),
path('', include('partners.api.urls')),
path('', include('mailinglists.api.urls')),
path('', include('pizzas.api.urls')),
path('', include('photos.api.urls')),
path('', include('pushnotifications.api.urls')),
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment