Implement TUI support for multiple users in each position #80
|
@ -15,7 +15,10 @@ def get_positions():
|
|||
positions = {}
|
||||
for user in ldap_srv.get_users_with_positions():
|
||||
for position in user.positions:
|
||||
positions[position] = user.uid
|
||||
if position in positions:
|
||||
positions[position] += f", {user.uid}"
|
||||
else:
|
||||
positions[position] = user.uid
|
||||
|
||||
return positions
|
||||
|
||||
|
@ -29,9 +32,10 @@ def update_positions():
|
|||
required = cfg.get('positions_required')
|
||||
available = cfg.get('positions_available')
|
||||
|
||||
# remove falsy values
|
||||
# remove falsy values and parse multiple users in each position
|
||||
# Example: "user1,user2, user3" -> ["user1","user2","user3"]
|
||||
body = {
|
||||
positions: username for positions, username in body.items()
|
||||
positions: username.replace(' ','').split(',') for positions, username in body.items()
|
||||
if username
|
||||
}
|
||||
|
||||
|
|
|
@ -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] = {}
|
||||
|
||||
|
|
Loading…
Reference in New Issue