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
:members:
:undoc-members:
:show-inheritance:
Submodules
----------
mailinglists.api.permissions module
-----------------------------------
.. automodule:: mailinglists.api.permissions
:members:
:undoc-members:
:show-inheritance:
mailinglists.api.serializers module
-----------------------------------
.. automodule:: mailinglists.api.serializers
:members:
:undoc-members:
:show-inheritance:
mailinglists.api.urls module
----------------------------
.. automodule:: mailinglists.api.urls
:members:
:undoc-members:
:show-inheritance:
mailinglists.api.viewsets module
--------------------------------
.. automodule:: mailinglists.api.viewsets
:members:
:undoc-members:
:show-inheritance:
......@@ -6,13 +6,6 @@ mailinglists package
:undoc-members:
:show-inheritance:
Subpackages
-----------
.. toctree::
mailinglists.api
Submodules
----------
......
"""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']
== settings.MAILINGLIST_API_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 [instance.name] + [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:
response.data = list(response.data) + automatic_lists
return response
......@@ -292,9 +292,6 @@ CONSCRIBO_PASSWORD = os.environ.get('CONSCRIBO_PASSWORD', '')
# Payments creditor identifier
SEPA_CREDITOR_ID = os.environ.get('SEPA_CREDITOR_ID', 'PLACEHOLDER')
# Mailinglist API key
MAILINGLIST_API_SECRET = os.environ.get('MAILINGLIST_API_SECRET', '')
# Members Sentry API key
MEMBERS_SENTRY_API_SECRET = os.environ.get('MEMBERS_SENTRY_API_SECRET', '')
......
......@@ -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