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")

View File

@ -169,6 +169,7 @@ FRONTEND_SERVERS=() # A tuple containing the
FTP_MASTERS=() # A tuple containing the *IP addresses* of all machines
# trusted to upload ftp structure data
VARNISH_PURGERS=() # Extra servers that can do varnish purges through our queue
LIST_ACTIVATORS=() # Servers that can activate lists
ARCHIVES_SEARCH_SERVER="archives.postgresql.org" # Where to post REST request for archives search
FRONTEND_SMTP_RELAY="magus.postgresql.org" # Where to relay user generated email

View File

@ -50,6 +50,7 @@ urlpatterns = patterns('',
(r'^community/lists/$', RedirectView.as_view(url='/list/', permanent=True)),
(r'^community/lists/subscribe/$', 'pgweb.lists.views.subscribe'),
(r'^community/lists/listinfo/$', 'pgweb.lists.views.listinfo'),
(r'^community/lists/activate/$', 'pgweb.lists.views.activate'),
(r'^community/survey/vote/(\d+)/$', 'pgweb.survey.views.vote'),
(r'^community/survey[/\.](\d+)(-.*)?/$', 'pgweb.survey.views.results'),
(r'^community/user-groups/$', 'pgweb.pugs.views.index'),