From 6acb869ebcb048b89ac6f283c683bdcc7470d7fd Mon Sep 17 00:00:00 2001 From: Magnus Hagander Date: Sat, 23 Oct 2021 16:25:38 +0200 Subject: [PATCH] Clean up accidentally commited files MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Back in 2018, commit 4d159ca accidentally included unrelated functionality which was not completed. This causes the database to be out of sync with the models defined in the code. This commit reverts those parts that were not supposed to be included and leaves the changes that actually were. The code can be re-added once completed... Spotted by Célestin Matte --- django/archives/mailarchives/api.py | 26 +------------------ django/archives/mailarchives/models.py | 17 ------------- django/archives/urls.py | 1 - loader/sql/schema.sql | 35 -------------------------- 4 files changed, 1 insertion(+), 78 deletions(-) diff --git a/django/archives/mailarchives/api.py b/django/archives/mailarchives/api.py index 4209811..8909dac 100644 --- a/django/archives/mailarchives/api.py +++ b/django/archives/mailarchives/api.py @@ -3,7 +3,7 @@ from django.shortcuts import get_object_or_404 from django.conf import settings from .views import cache -from .models import Message, List, ApiClient, ThreadSubscription +from .models import Message, List import json @@ -115,27 +115,3 @@ def thread(request, msgid): if settings.PUBLIC_ARCHIVES: resp['xkey'] = 'pgat_{0}'.format(msg.threadid) return resp - - -def thread_subscribe(request, msgid): - if not settings.PUBLIC_ARCHIVES: - return HttpResponseForbidden('No API access on private archives for now') - - if not request.META['REMOTE_ADDR'] in settings.API_CLIENTS: - return HttpResponseForbidden('Invalid host') - - if 'HTTP_X_APIKEY' not in request.META: - return HttpResponseForbidden('No API key') - - if request.method != 'PUT': - return HttpResponseForbidden('Invalid HTTP verb') - - apiclient = get_object_or_404(ApiClient, apikey=request.META['HTTP_X_APIKEY']) - msg = get_object_or_404(Message, messageid=msgid) - - (obj, created) = ThreadSubscription.objects.get_or_create(apiclient=apiclient, - threadid=msg.threadid) - if created: - return HttpResponse(status=201) - else: - return HttpResponse(status=200) diff --git a/django/archives/mailarchives/models.py b/django/archives/mailarchives/models.py index afd0c09..44c4469 100644 --- a/django/archives/mailarchives/models.py +++ b/django/archives/mailarchives/models.py @@ -141,20 +141,3 @@ class ResendMessage(models.Model): class LastResentMessage(models.Model): sentto = models.OneToOneField(User, null=False, blank=False, primary_key=True, on_delete=models.CASCADE) sentat = models.DateTimeField(null=False, blank=False) - - -class ApiClient(models.Model): - apikey = models.CharField(max_length=100, null=False, blank=False) - postback = models.URLField(max_length=500, null=False, blank=False) - - class Meta: - db_table = 'apiclients' - - -class ThreadSubscription(models.Model): - apiclient = models.ForeignKey(ApiClient, null=False, blank=False, on_delete=models.CASCADE) - threadid = models.IntegerField(null=False, blank=False) - - class Meta: - db_table = 'threadsubscriptions' - unique_together = (('apiclient', 'threadid'),) diff --git a/django/archives/urls.py b/django/archives/urls.py index 091fa5e..bc8a18d 100644 --- a/django/archives/urls.py +++ b/django/archives/urls.py @@ -57,7 +57,6 @@ urlpatterns = [ url(r'^list/([\w-]+|\*)/latest.json$', archives.mailarchives.api.latest), url(r'^message-id.json/(.+)$', archives.mailarchives.api.thread), url(r'^listinfo/$', archives.mailarchives.api.listinfo), - # url(r'^thread/(.+)/subscribe/$', archives.mailarchives.api.thread_subscribe), # Normally served off www.postgresql.org, but manually handled here for # development installs. diff --git a/loader/sql/schema.sql b/loader/sql/schema.sql index d9b5d5f..be735d9 100644 --- a/loader/sql/schema.sql +++ b/loader/sql/schema.sql @@ -80,24 +80,6 @@ CREATE TABLE attachments( ); CREATE INDEX idx_attachments_msg ON attachments(message); -CREATE TABLE apiclients( - id SERIAL NOT NULL PRIMARY KEY, - apikey varchar(100) NOT NULL, - postback varchar(500) NOT NULL -); - -CREATE TABLE threadsubscriptions( - id SERIAL NOT NULL PRIMARY KEY, - apiclient_id integer NOT NULL REFERENCES apiclients(id), - threadid integer NOT NULL -); - -CREATE TABLE threadnotifications( - apiclient_id integer NOT NULL REFERENCES apiclients(id), - threadid integer NOT NULL, - CONSTRAINT threadnotifications_pkey PRIMARY KEY (apiclient_id, threadid) -); - CREATE TABLE loaderrors( id SERIAL NOT NULL PRIMARY KEY, listid int NOT NULL, @@ -145,23 +127,6 @@ CREATE TRIGGER messages_fti_trigger FOR EACH ROW EXECUTE PROCEDURE messages_fti_trigger_func(); CREATE INDEX messages_fti_idx ON messages USING gin(fti); -CREATE OR REPLACE FUNCTION messages_notify_threads_trg_func() RETURNS trigger AS $$ -BEGIN - INSERT INTO threadnotifications (apiclient_id, threadid) - SELECT apiclient_id, threadid - FROM threadsubscriptions - WHERE threadsubscriptions.threadid=NEW.threadid - ON CONFLICT DO NOTHING; - IF FOUND THEN - NOTIFY thread_updated; - END IF; - RETURN NEW; -END -$$ LANGUAGE 'plpgsql'; -CREATE TRIGGER messages_notify_trigger - AFTER INSERT ON messages - FOR EACH ROW EXECUTE PROCEDURE messages_notify_threads_trg_func(); - CREATE TABLE legacymap( listid int not null, year int not null, -- 2.39.5