mirror of
https://gitlab.com/sfz.aalen/infra/fabaccess.git
synced 2025-03-12 15:01:47 +01:00
Fix get_user_by_card_id by implementing own filter
This commit is contained in:
parent
1b30093322
commit
0c6e188367
@ -17,17 +17,18 @@ class KeycloakHandler:
|
||||
|
||||
@staticmethod
|
||||
def get_user_by_card_id(card_id):
|
||||
users = KeycloakHandler.admin.get_users(
|
||||
{ 'attributes': { 'FabCard': card_id }}
|
||||
)
|
||||
print(f'Found {len(users)} users with card_id: {card_id}')
|
||||
users = KeycloakHandler.admin.get_users()
|
||||
# Filter not working for Attributes because of multidimensional JSON
|
||||
|
||||
match len(users):
|
||||
user = [user for user in users if "attributes" in user and "FabCard" in user["attributes"] and user["attributes"]["FabCard"] == [card_id]]
|
||||
print(f'Found {len(user)} user(s) with card_id: {card_id}')
|
||||
|
||||
match len(user):
|
||||
case 0:
|
||||
return None
|
||||
case 1:
|
||||
print(f'FabCard matches with user {users[0]["username"]}')
|
||||
return users[0]
|
||||
print(f'FabCard matches with user {user[0]["username"]}')
|
||||
return user[0]
|
||||
case other:
|
||||
print(f'Error! too many users with card_id: {card_id}')
|
||||
return None
|
||||
|
Loading…
x
Reference in New Issue
Block a user