public inbox for [email protected]  
help / color / mirror / Atom feed
From: Célestin Matte <[email protected]>
To: Magnus Hagander <[email protected]>
To: PostgreSQL WWW <[email protected]>
Subject: Re: [PATCH] pgarchives: pglister_sync: import lists with subscriber_access set to True
Date: Tue, 28 Feb 2023 11:39:09 +0100
Message-ID: <[email protected]> (raw)
In-Reply-To: <CABUevEyrMwAsTG8c4ECj-zBBFsB-52CcKg02bkbkr=JBMz6_LA@mail.gmail.com>
References: <[email protected]>
	<CABUevEyBc9+zspBNE_TgKwtURKeuAsf++Wgszb8rnpDu=KPdKQ@mail.gmail.com>
	<[email protected]>
	<CABUevEyrMwAsTG8c4ECj-zBBFsB-52CcKg02bkbkr=JBMz6_LA@mail.gmail.com>

Attached another proposed solution to that problem, with a series of patches for pglister and pgarchives:
- 0001-Add-subscriber_access-field-to-ListGroup_pglister.patch adds a subscriber_access field in pglister's admin section
- 0002-Add-subscriber_access-to-archives-API_pglister.patch adds subscriber_access to the API's archive section in pglister
- 0001-pglister_sync-obtain-subscriber_access-from-API_pgarchives.patch uses the value received from the API instead of a default "False" that has to be manually changed

As a reminder, the problem was that subscriber_access was set to False by default, which means that any list created on pglister and set to be archived on pgarchives won't be reachable by subscribers, unless the subscriber_access field is manually modified in the database.
-- 
Célestin Matte


Attachments:

  [text/x-patch] 0001-Add-subscriber_access-field-to-ListGroup_pglister.patch (1.8K, 2-0001-Add-subscriber_access-field-to-ListGroup_pglister.patch)
  download | inline diff:
From 872c5cee537a6c387ad9b0de97694fb8fa12f78b Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?C=C3=A9lestin=20Matte?= <[email protected]>
Date: Thu, 23 Feb 2023 18:07:28 +0100
Subject: [PATCH 1/2] Add subscriber_access field to ListGroup

---
 .../migrations/0055_auto_20230223_1706.py      | 18 ++++++++++++++++++
 web/pglister/lists/models.py                   |  2 ++
 2 files changed, 20 insertions(+)
 create mode 100644 web/pglister/lists/migrations/0055_auto_20230223_1706.py

diff --git a/web/pglister/lists/migrations/0055_auto_20230223_1706.py b/web/pglister/lists/migrations/0055_auto_20230223_1706.py
new file mode 100644
index 0000000..bdb4ede
--- /dev/null
+++ b/web/pglister/lists/migrations/0055_auto_20230223_1706.py
@@ -0,0 +1,18 @@
+# Generated by Django 2.2.24 on 2023-02-23 17:06
+
+from django.db import migrations, models
+
+
+class Migration(migrations.Migration):
+
+    dependencies = [
+        ('lists', '0054_add_archivedat'),
+    ]
+
+    operations = [
+        migrations.AddField(
+            model_name='listgroup',
+            name='subscriber_access',
+            field=models.BooleanField(default=False, help_text='Can subscribers get full access to the archives?', null=True),
+        ),
+    ]
diff --git a/web/pglister/lists/models.py b/web/pglister/lists/models.py
index dba9689..cf3ffec 100644
--- a/web/pglister/lists/models.py
+++ b/web/pglister/lists/models.py
@@ -111,6 +111,8 @@ class Domain(models.Model):
 class ListGroup(models.Model):
     groupname = models.CharField(max_length=100, null=False, blank=False)
     sortkey = models.IntegerField(null=False, default=10)
+    subscriber_access = models.BooleanField(null=True, blank=False, default=False,
+                                            help_text="Can subscribers get full access to the archives?")
 
     def __str__(self):
         return self.groupname
-- 
2.39.2



  [text/x-patch] 0001-pglister_sync-obtain-subscriber_access-from-API_pgarchives.patch (1.5K, 3-0001-pglister_sync-obtain-subscriber_access-from-API_pgarchives.patch)
  download | inline diff:
From ff71fc36609ef139837612c5d60906edcd340b63 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?C=C3=A9lestin=20Matte?= <[email protected]>
Date: Mon, 27 Feb 2023 19:22:33 +0100
Subject: [PATCH] pglister_sync: obtain subscriber_access from API

---
 loader/pglister_sync.py | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/loader/pglister_sync.py b/loader/pglister_sync.py
index d7e1925..7440ab8 100755
--- a/loader/pglister_sync.py
+++ b/loader/pglister_sync.py
@@ -42,15 +42,16 @@ if __name__ == "__main__":
     obj = r.json()
 
     # For groups, just add them if they don't exist
-    groups = {g['group']['id']: g['group']['groupname'] for g in obj}
+    groups = {g['group']['id']: (g['group']['groupname'], g['group']['subscriber_access']) for g in obj}
 
-    for id, name in list(groups.items()):
+    for id, (name, subscriber_access) in list(groups.items()):
         curs.execute("SELECT EXISTS (SELECT 1 FROM listgroups WHERE groupname=%(group)s)", {
             'group': name,
         })
         if not curs.fetchone()[0]:
-            curs.execute("INSERT INTO listgroups (groupname, sortkey) VALUES (%(group)s, 100) RETURNING groupname", {
+            curs.execute("INSERT INTO listgroups (groupname, sortkey, subscriber_access) VALUES (%(group)s, 100, %(subscriber_access)s) RETURNING groupname", {
                 'group': name,
+                'subscriber_access': subscriber_access,
             })
             print("Added group %s" % name)
 
-- 
2.39.2



  [text/x-patch] 0002-Add-subscriber_access-to-archives-API_pglister.patch (2.8K, 4-0002-Add-subscriber_access-to-archives-API_pglister.patch)
  download | inline diff:
From 6e94a2380bcb471e1a089a61931e4d9d16e80752 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?C=C3=A9lestin=20Matte?= <[email protected]>
Date: Mon, 27 Feb 2023 19:07:05 +0100
Subject: [PATCH 2/2] Add subscriber_access to archives API

---
 web/pglister/lists/views_api.py | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/web/pglister/lists/views_api.py b/web/pglister/lists/views_api.py
index 24e41df..50de9c8 100644
--- a/web/pglister/lists/views_api.py
+++ b/web/pglister/lists/views_api.py
@@ -140,11 +140,11 @@ class ArchivesApi(View):
     def get_lists(self, with_subscribers):
         curs = connection.cursor()
         if with_subscribers:
-            curs.execute("SELECT l.id AS listid, l.name AS listname, d.name AS domain, l.shortdesc, l.longdesc, json_build_object('id', g.id, 'groupname', g.groupname) AS group, COALESCE(array_agg(u.username) FILTER (WHERE u.username IS NOT NULL), ARRAY[]::text[]) AS subscribers FROM lists_list l INNER JOIN lists_domain d ON l.domain_id=d.id INNER JOIN lists_listgroup g ON l.group_id=g.id LEFT JOIN mailinglist_subscribers s ON s.listid=l.id LEFT JOIN auth_user u ON u.id=s.userid WHERE l.archivedat_id=%(archiveid)s GROUP BY l.id, d.id, g.id ORDER BY 2,1", {
+            curs.execute("SELECT l.id AS listid, l.name AS listname, d.name AS domain, l.shortdesc, l.longdesc, json_build_object('id', g.id, 'groupname', g.groupname, 'subscriber_access', g.subscriber_access) AS group, COALESCE(array_agg(u.username) FILTER (WHERE u.username IS NOT NULL), ARRAY[]::text[]) AS subscribers FROM lists_list l INNER JOIN lists_domain d ON l.domain_id=d.id INNER JOIN lists_listgroup g ON l.group_id=g.id LEFT JOIN mailinglist_subscribers s ON s.listid=l.id LEFT JOIN auth_user u ON u.id=s.userid WHERE l.archivedat_id=%(archiveid)s GROUP BY l.id, d.id, g.id ORDER BY 2,1", {
                 'archiveid': self.archiveserver.id,
             })
         else:
-            curs.execute("SELECT l.id AS listid, l.name AS listname, d.name AS domain, l.shortdesc, l.longdesc, json_build_object('id', g.id, 'groupname', g.groupname) AS group FROM lists_list l INNER JOIN lists_domain d ON l.domain_id=d.id INNER JOIN lists_listgroup g ON l.group_id=g.id WHERE l.archivedat_id=%(archiveid)s GROUP BY l.id, d.id, g.id ORDER BY 2,1", {
+            curs.execute("SELECT l.id AS listid, l.name AS listname, d.name AS domain, l.shortdesc, l.longdesc, json_build_object('id', g.id, 'groupname', g.groupname, 'subscriber_access', g.subscriber_access) AS group FROM lists_list l INNER JOIN lists_domain d ON l.domain_id=d.id INNER JOIN lists_listgroup g ON l.group_id=g.id WHERE l.archivedat_id=%(archiveid)s GROUP BY l.id, d.id, g.id ORDER BY 2,1", {
                 'archiveid': self.archiveserver.id,
             })
         columns = [col[0] for col in curs.description]
-- 
2.39.2



reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: [email protected]
  Cc: [email protected], [email protected], [email protected]
  Subject: Re: [PATCH] pgarchives: pglister_sync: import lists with subscriber_access set to True
  In-Reply-To: <[email protected]>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox