From 519014de345b5909f7aed08c6d04cdcc381374f8 Mon Sep 17 00:00:00 2001 From: Jackson Chen Date: Thu, 14 Sep 2023 19:59:38 +0200 Subject: [PATCH 1/3] fix existing calls to user_list being broken fixes #127 References: https://github.com/JOJ0/synadm/issues/127 --- synadm/api.py | 6 +++--- synadm/cli/notice.py | 5 +++-- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/synadm/api.py b/synadm/api.py index e906da85..a47863e2 100644 --- a/synadm/api.py +++ b/synadm/api.py @@ -468,7 +468,7 @@ def user_list_paginate(self, _limit, _guests, _deactivated, """ while _from is not None: response = self.user_list(_from, _limit, _guests, _deactivated, - _name, _user_id) + _name, _user_id, None) yield response _from = response.get("next_token", None) @@ -1345,7 +1345,7 @@ def notice_send(self, receivers, content_plain, content_html, paginate, # A regular expression was supplied to match receivers. if regex: outputs = [] - response = self.user_list(0, paginate, True, False, "", "") + response = self.user_list(0, paginate, True, False, "", "", None) if "users" not in response: return while True: @@ -1361,7 +1361,7 @@ def notice_send(self, receivers, content_plain, content_html, paginate, if "next_token" not in response: return outputs response = self.user_list(response["next_token"], - 100, True, False, "", "") + 100, True, False, "", "", None) # Only a single user ID was supplied as receiver else: data["user_id"] = receivers diff --git a/synadm/cli/notice.py b/synadm/cli/notice.py index 3e6cf2c5..a52f48c7 100644 --- a/synadm/cli/notice.py +++ b/synadm/cli/notice.py @@ -95,7 +95,7 @@ def confirm_prompt(): # Outer loop: If fetching >1 pages of users is required while ctr < preview_length: batch = helper.api.user_list( - next_token, batch_size, True, False, "", "") + next_token, batch_size, True, False, "", "", None) if "users" not in batch: break batch_mxids = [user['name'] for user in batch["users"]] @@ -135,7 +135,8 @@ def confirm_prompt(): formatted_content = formatted if formatted else plain_content if regex: - if "users" not in helper.api.user_list(0, 100, True, False, "", ""): + if "users" not in helper.api.user_list(0, 100, True, False, "", "", + None): return if not confirm_prompt(): return From df87239d6d14da603c35a501aff5dc1fc1d5f7a6 Mon Sep 17 00:00:00 2001 From: Jackson Chen Date: Thu, 14 Sep 2023 20:25:13 +0200 Subject: [PATCH 2/3] default admin option for user_list_paginate --- synadm/api.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/synadm/api.py b/synadm/api.py index a47863e2..1b8cbd1e 100644 --- a/synadm/api.py +++ b/synadm/api.py @@ -446,7 +446,7 @@ def user_list(self, _from, _limit, _guests, _deactivated, return self.query("get", "v2/users", params=params) def user_list_paginate(self, _limit, _guests, _deactivated, - _name, _user_id, _from="0"): + _name, _user_id, _from="0", admin=None): # documentation is mostly duplicated from user_list... """Yields API responses for all of the pagination. @@ -468,7 +468,7 @@ def user_list_paginate(self, _limit, _guests, _deactivated, """ while _from is not None: response = self.user_list(_from, _limit, _guests, _deactivated, - _name, _user_id, None) + _name, _user_id, admin) yield response _from = response.get("next_token", None) From e5404383a5fb8889079cda8c487c783e5f0985bd Mon Sep 17 00:00:00 2001 From: Jackson Chen Date: Thu, 14 Sep 2023 21:01:21 +0200 Subject: [PATCH 3/3] make default argument for _admin=None fixes #127 References: https://github.com/JOJ0/synadm/issues/127 --- synadm/api.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/synadm/api.py b/synadm/api.py index 1b8cbd1e..75c0cb3d 100644 --- a/synadm/api.py +++ b/synadm/api.py @@ -415,7 +415,7 @@ def __init__(self, log, user, token, base_url, admin_path, timeout, debug, self.user = user def user_list(self, _from, _limit, _guests, _deactivated, - _name, _user_id, _admin): + _name, _user_id, _admin=None): """List and search users Args: