From 208a9bedf583af6fa59b33686ec3059401f24fb7 Mon Sep 17 00:00:00 2001 From: Manuel Reinhardt Date: Wed, 29 Jan 2025 15:55:42 +0100 Subject: [PATCH] Add country manager mailing lists Meant for sending test newsletters Ref https://github.com/syslabcom/scrum/issues/2636 --- docs/changes.rst | 4 +++ src/osha/oira/client/browser/client.py | 40 ++++++++++++++++++++------ 2 files changed, 35 insertions(+), 9 deletions(-) diff --git a/docs/changes.rst b/docs/changes.rst index 82817a2a..784bc82f 100644 --- a/docs/changes.rst +++ b/docs/changes.rst @@ -11,6 +11,10 @@ Changelog - Require Python 3.11 and 3.12 as Euphorie does [ale-rt] +- Add country manager mailing lists + (`#2636 `_) + [reinhardt] + 10.1.0 (2025-01-15) ------------------- diff --git a/src/osha/oira/client/browser/client.py b/src/osha/oira/client/browser/client.py index d99cb4e7..7aaa5dd5 100644 --- a/src/osha/oira/client/browser/client.py +++ b/src/osha/oira/client/browser/client.py @@ -140,6 +140,10 @@ def _get_mailing_lists_for(self, brain): "-".join((brain.getId, language)), f"{brain.Title} ({language})" ) for language in sorted(languages) + ] + [ + self._get_entry( + f"{brain.getId}-managers", f"{brain.Title} country managers" + ) ] def filter_permission(self, brains, query, user): @@ -286,6 +290,28 @@ def get_token(self): raise Unauthorized("Invalid token") return token + def get_addresses_per_language(self, country, lang): + country_subscribers = ( + Session.query(Account.loginname) + .filter(Account.id == NewsletterSubscription.account_id) + .filter(NewsletterSubscription.zodb_path == (country)) + .filter(Account.id == NewsletterSetting.account_id) + .filter(NewsletterSetting.value == f"language:{lang}") + .group_by(Account.loginname) + ) + return [s.loginname for s in country_subscribers] + + def get_addresses_of_country_managers(self, country): + sectors = api.portal.get().sectors + country_obj = sectors.get(country) + if not country_obj: + return [] + return [ + entry[0] + for entry in country_obj.get_local_roles() + if "CountryManager" in entry[1] + ] + def get_addresses_for_groups(self, group_paths): subscribers = [] other = [] @@ -295,15 +321,11 @@ def get_addresses_for_groups(self, group_paths): continue # Special handling for language specific mailing lists, e.g. "be-fr" country, lang = group_id.split("-") - country_subscribers = ( - Session.query(Account.loginname) - .filter(Account.id == NewsletterSubscription.account_id) - .filter(NewsletterSubscription.zodb_path == (country)) - .filter(Account.id == NewsletterSetting.account_id) - .filter(NewsletterSetting.value == f"language:{lang}") - .group_by(Account.loginname) - ) - subscribers.extend([s.loginname for s in country_subscribers]) + if lang == "managers": + # Not actually a language, but the special country managers test list + subscribers.extend(self.get_addresses_of_country_managers(country)) + else: + subscribers.extend(self.get_addresses_per_language(country, lang)) other_subscribers = ( Session.query(Account.loginname)