mirror of
https://gitlab.com/sfz.aalen/infra/fabaccess.git
synced 2025-03-12 23:11:58 +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
|
@staticmethod
|
||||||
def get_user_by_card_id(card_id):
|
def get_user_by_card_id(card_id):
|
||||||
users = KeycloakHandler.admin.get_users(
|
users = KeycloakHandler.admin.get_users()
|
||||||
{ 'attributes': { 'FabCard': card_id }}
|
# Filter not working for Attributes because of multidimensional JSON
|
||||||
)
|
|
||||||
print(f'Found {len(users)} users with card_id: {card_id}')
|
|
||||||
|
|
||||||
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:
|
case 0:
|
||||||
return None
|
return None
|
||||||
case 1:
|
case 1:
|
||||||
print(f'FabCard matches with user {users[0]["username"]}')
|
print(f'FabCard matches with user {user[0]["username"]}')
|
||||||
return users[0]
|
return user[0]
|
||||||
case other:
|
case other:
|
||||||
print(f'Error! too many users with card_id: {card_id}')
|
print(f'Error! too many users with card_id: {card_id}')
|
||||||
return None
|
return None
|
||||||
|
Loading…
x
Reference in New Issue
Block a user