Skip to content

Commit

Permalink
Add country manager mailing lists
Browse files Browse the repository at this point in the history
Meant for sending test newsletters

Ref syslabcom/scrum#2636
  • Loading branch information
reinhardt committed Jan 29, 2025
1 parent 4b06ad2 commit 208a9be
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 9 deletions.
4 changes: 4 additions & 0 deletions docs/changes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ Changelog
- Require Python 3.11 and 3.12 as Euphorie does
[ale-rt]

- Add country manager mailing lists
(`#2636 <https://github.com/syslabcom/scrum/issues/2636>`_)
[reinhardt]


10.1.0 (2025-01-15)
-------------------
Expand Down
40 changes: 31 additions & 9 deletions src/osha/oira/client/browser/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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 = []
Expand All @@ -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)
Expand Down

0 comments on commit 208a9be

Please sign in to comment.