Implement TUI support for multiple users in each position
continuous-integration/drone/pr Build is failing Details

This commit is contained in:
Justin Chung 2022-10-13 17:52:01 -04:00
parent c30ca54752
commit 769785c299
Signed by: j24chung
GPG Key ID: F010CF575BA74CC3
2 changed files with 17 additions and 6 deletions

View File

@ -15,6 +15,9 @@ def get_positions():
positions = {}
for user in ldap_srv.get_users_with_positions():
for position in user.positions:
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
}

View File

@ -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,7 +29,13 @@ 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():
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] = {}