public inbox for [email protected]  
help / color / mirror / Atom feed
From: Célestin Matte <[email protected]>
To: [email protected]
Subject: Re: [PATCH] pgarchives: pglister_sync: import lists with subscriber_access set to True
Date: Mon, 3 Apr 2023 17:16:18 +0200
Message-ID: <[email protected]> (raw)
In-Reply-To: <[email protected]>
References: <[email protected]>
	<CABUevEyBc9+zspBNE_TgKwtURKeuAsf++Wgszb8rnpDu=KPdKQ@mail.gmail.com>
	<[email protected]>
	<CABUevEyrMwAsTG8c4ECj-zBBFsB-52CcKg02bkbkr=JBMz6_LA@mail.gmail.com>
	<[email protected]>

Update: previously attached patches were incorrectly using subscriber_access in ListGroup, although it's a field of List in pgarchives.
Besides, they were not built on top of upstream. Please note that this set of patches is built on top of the patch I sent in gitlab [1], as upstream currently crashes on migration.
New sets of patched attached.

[1] https://gitlab.com/pglister/pglister/-/merge_requests/33

On 28/02/2023 11:39, Célestin Matte wrote:
> 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-List.patch (1.9K, 2-0001-Add-subscriber_access-field-to-List.patch)
  download | inline diff:
From 82d233cbd4d94f1cf7376aff35ec53737bc650a6 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?C=C3=A9lestin=20Matte?= <[email protected]>
Date: Mon, 3 Apr 2023 17:07:52 +0200
Subject: [PATCH 1/2] Add subscriber_access field to List

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

diff --git a/web/pglister/lists/migrations/0058_list_subscriber_access.py b/web/pglister/lists/migrations/0058_list_subscriber_access.py
new file mode 100644
index 0000000..f748b68
--- /dev/null
+++ b/web/pglister/lists/migrations/0058_list_subscriber_access.py
@@ -0,0 +1,18 @@
+# Generated by Django 2.2.24 on 2023-04-03 10:41
+
+from django.db import migrations, models
+
+
+class Migration(migrations.Migration):
+
+    dependencies = [
+        ('lists', '0057_neverblockregexp'),
+    ]
+
+    operations = [
+        migrations.AddField(
+            model_name='list',
+            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..3df6252 100644
--- a/web/pglister/lists/models.py
+++ b/web/pglister/lists/models.py
@@ -163,6 +163,8 @@ class List(models.Model):
 
     apikey_ro = models.CharField(max_length=100, null=False, blank=True, verbose_name="Read-only API key")
     apikey_rw = models.CharField(max_length=100, null=False, blank=True, verbose_name="Read-write API key")
+    subscriber_access = models.BooleanField(null=True, blank=False, default=False,
+                                            help_text="Can subscribers get full access to the archives?")
 
     def __str__(self):
         return "{0}@{1}".format(self.name, self.domain.name)
-- 
2.40.0



  [text/x-patch] 0001-pglister_sync-obtain-subscriber_access-from-API.patch (2.5K, 3-0001-pglister_sync-obtain-subscriber_access-from-API.patch)
  download | inline diff:
From 6ea77326553f23fcfc3835e9211a8d777380d9d8 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?C=C3=A9lestin=20Matte?= <[email protected]>
Date: Mon, 3 Apr 2023 11:24:29 +0200
Subject: [PATCH] pglister_sync: obtain subscriber_access from API

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

diff --git a/loader/pglister_sync.py b/loader/pglister_sync.py
index d7e1925..94ef5c7 100755
--- a/loader/pglister_sync.py
+++ b/loader/pglister_sync.py
@@ -60,20 +60,22 @@ if __name__ == "__main__":
             'name': l['listname'],
         })
         if curs.rowcount == 0:
-            curs.execute("INSERT INTO lists (listname, shortdesc, description, active, groupid, subscriber_access) SELECT %(name)s, %(name)s, %(desc)s, 't', groupid, 'f' FROM listgroups WHERE groupname=%(groupname)s RETURNING listid, listname", {
+            curs.execute("INSERT INTO lists (listname, shortdesc, description, active, groupid, subscriber_access) SELECT %(name)s, %(name)s, %(desc)s, 't', groupid, %(subscriber_access)s FROM listgroups WHERE groupname=%(groupname)s RETURNING listid, listname", {
                 'name': l['listname'],
                 'desc': l['longdesc'],
                 'groupname': l['group']['groupname'],
+                'subscriber_access': l['subscriber_access'],
             })
             listid, name = curs.fetchone()
             print("Added list %s" % name)
         else:
             listid, name = curs.fetchone()
-            curs.execute("UPDATE lists SET shortdesc=%(name)s, description=%(desc)s, groupid=(SELECT groupid FROM listgroups WHERE groupname=%(groupname)s), active=true WHERE listid=%(id)s AND NOT (active AND shortdesc=%(name)s AND description=%(desc)s AND groupid=(SELECT groupid FROM listgroups WHERE groupname=%(groupname)s)) RETURNING listname", {
+            curs.execute("UPDATE lists SET shortdesc=%(name)s, description=%(desc)s, groupid=(SELECT groupid FROM listgroups WHERE groupname=%(groupname)s), active=true, subscriber_access=%(subscriber_access)s WHERE listid=%(id)s AND NOT (active AND shortdesc=%(name)s AND description=%(desc)s AND groupid=(SELECT groupid FROM listgroups WHERE groupname=%(groupname)s)) RETURNING listname", {
                 'id': listid,
                 'name': l['listname'],
                 'desc': l['longdesc'],
                 'groupname': l['group']['groupname'],
+                'subscriber_access': l['subscriber_access'],
             })
             for n, in curs.fetchall():
                 print("Updated list %s " % n)
-- 
2.40.0



  [text/x-patch] 0002-Add-subscriber_access-to-archives-API.patch (2.8K, 4-0002-Add-subscriber_access-to-archives-API.patch)
  download | inline diff:
From e941294dfe3e82459efd2b36ca57c6ea807b814a Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?C=C3=A9lestin=20Matte?= <[email protected]>
Date: Mon, 3 Apr 2023 17:08:22 +0200
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..e957c2d 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) AS group, COALESCE(array_agg(u.username) FILTER (WHERE u.username IS NOT NULL), ARRAY[]::text[]) AS subscribers, l.subscriber_access AS subscriber_access 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) AS group, l.subscriber_access AS subscriber_access 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.40.0



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]
  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