Implement TUI support for multiple users in each position
continuous-integration/drone/pr Build is failing
Details
continuous-integration/drone/pr Build is failing
Details
This commit is contained in:
parent
c30ca54752
commit
769785c299
|
@ -15,7 +15,10 @@ def get_positions():
|
||||||
positions = {}
|
positions = {}
|
||||||
for user in ldap_srv.get_users_with_positions():
|
for user in ldap_srv.get_users_with_positions():
|
||||||
for position in user.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
|
return positions
|
||||||
|
|
||||||
|
@ -29,9 +32,10 @@ def update_positions():
|
||||||
required = cfg.get('positions_required')
|
required = cfg.get('positions_required')
|
||||||
available = cfg.get('positions_available')
|
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 = {
|
body = {
|
||||||
positions: username for positions, username in body.items()
|
positions: username.replace(' ','').split(',') for positions, username in body.items()
|
||||||
if username
|
if username
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2,6 +2,7 @@ from collections import defaultdict
|
||||||
from typing import Dict
|
from typing import Dict
|
||||||
|
|
||||||
from zope import component
|
from zope import component
|
||||||
|
from typing import Union
|
||||||
|
|
||||||
from ..AbstractTransaction import AbstractTransaction
|
from ..AbstractTransaction import AbstractTransaction
|
||||||
from ceo_common.interfaces import ILDAPService, IConfig, IUser
|
from ceo_common.interfaces import ILDAPService, IConfig, IUser
|
||||||
|
@ -20,7 +21,7 @@ class UpdateMemberPositionsTransaction(AbstractTransaction):
|
||||||
'subscribe_to_mailing_lists',
|
'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
|
# positions_reversed is position -> username
|
||||||
super().__init__()
|
super().__init__()
|
||||||
self.ldap_srv = component.getUtility(ILDAPService)
|
self.ldap_srv = component.getUtility(ILDAPService)
|
||||||
|
@ -28,7 +29,13 @@ class UpdateMemberPositionsTransaction(AbstractTransaction):
|
||||||
# Reverse the dict so it's easier to use (username -> positions)
|
# Reverse the dict so it's easier to use (username -> positions)
|
||||||
self.positions = defaultdict(list)
|
self.positions = defaultdict(list)
|
||||||
for position, username in positions_reversed.items():
|
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)
|
# a cached Dict of the Users who need to be modified (username -> User)
|
||||||
self.users: Dict[str, IUser] = {}
|
self.users: Dict[str, IUser] = {}
|
||||||
|
|
Loading…
Reference in New Issue