Add simple API endpoint to activate and deactivate a list

Access is restricted by IP for the list server. Once the migration is
done, we should probably remove the endpoint again.
This commit is contained in:
Magnus Hagander
2017-07-03 15:35:55 +01:00
parent 07199c7846
commit 20a0e178c5
3 changed files with 18 additions and 2 deletions

View File

@ -1,5 +1,5 @@
from django.shortcuts import render_to_response
from django.http import HttpResponse
from django.shortcuts import render_to_response, get_object_or_404
from django.http import HttpResponse, HttpResponseForbidden
from django.views.decorators.csrf import csrf_exempt
from django.conf import settings
@ -67,3 +67,17 @@ def listinfo(request):
} for l in MailingList.objects.all()]
json.dump({'groups': groupdata, 'lists': listdata}, resp)
return resp
# Temporary API endpoint
def activate(request):
if not request.META['REMOTE_ADDR'] in settings.LIST_ACTIVATORS:
return HttpResponseForbidden()
listname = request.GET['listname']
active = (request.GET['active'] == '1')
l = get_object_or_404(MailingList, listname=listname)
if l.active == active:
return HttpResponse("Not changed")
l.active = active
l.save()
return HttpResponse("Changed")