|
|
|
@ -2,6 +2,7 @@ from collections import defaultdict |
|
|
|
|
from typing import Dict |
|
|
|
|
|
|
|
|
|
from zope import component |
|
|
|
|
from typing import Union |
|
|
|
|
|
|
|
|
|
from ..AbstractTransaction import AbstractTransaction |
|
|
|
|
from ceo_common.interfaces import ILDAPService, IConfig, IUser |
|
|
|
@ -20,7 +21,7 @@ class UpdateMemberPositionsTransaction(AbstractTransaction): |
|
|
|
|
'subscribe_to_mailing_lists', |
|
|
|
|
] |
|
|
|
|
|
|
|
|
|
def __init__(self, positions_reversed: Dict[str, str]): |
|
|
|
|
def __init__(self, positions_reversed: Dict[str, Union[str,list]]): |
|
|
|
|
# positions_reversed is position -> username |
|
|
|
|
super().__init__() |
|
|
|
|
self.ldap_srv = component.getUtility(ILDAPService) |
|
|
|
@ -28,8 +29,14 @@ class UpdateMemberPositionsTransaction(AbstractTransaction): |
|
|
|
|
# Reverse the dict so it's easier to use (username -> positions) |
|
|
|
|
self.positions = defaultdict(list) |
|
|
|
|
for position, username in positions_reversed.items(): |
|
|
|
|
self.positions[username].append(position) |
|
|
|
|
|
|
|
|
|
if isinstance(username, str): |
|
|
|
|
self.positions[username].append(position) |
|
|
|
|
elif isinstance(username, list): |
|
|
|
|
for user in username: |
|
|
|
|
self.positions[user].append(position) |
|
|
|
|
else: |
|
|
|
|
raise TypeError("Username(s) under each position must either be a string or a list") |
|
|
|
|
|
|
|
|
|
# a cached Dict of the Users who need to be modified (username -> User) |
|
|
|
|
self.users: Dict[str, IUser] = {} |
|
|
|
|
|
|
|
|
|