From 56b4dec3600825c3f60144e61ec51ff48356aa7e Mon Sep 17 00:00:00 2001 From: Alex Date: Sat, 18 Jan 2025 09:55:04 +0100 Subject: [PATCH] fixup! fixed bug adding mpsk clients --- sipa/model/pycroft/user.py | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/sipa/model/pycroft/user.py b/sipa/model/pycroft/user.py index 14f0b98b..957dd305 100644 --- a/sipa/model/pycroft/user.py +++ b/sipa/model/pycroft/user.py @@ -17,7 +17,8 @@ from sipa.model.misc import PaymentDetails from sipa.model.exceptions import UserNotFound, PasswordInvalid, \ MacAlreadyExists, NetworkAccessAlreadyActive, TerminationNotPossible, UnknownError, \ - ContinuationNotPossible, SubnetFull, UserNotContactableError, TokenNotFound, LoginNotAllowed + ContinuationNotPossible, SubnetFull, UserNotContactableError, TokenNotFound, LoginNotAllowed, \ + MaximumNumberMPSKClients, NoWiFiPasswordGenerated from .api import PycroftApi from .exc import PycroftBackendError from .schema import UserData, UserStatus @@ -41,6 +42,8 @@ class User(BaseUser): def __init__(self, user_data: dict): try: + user_data["mpsk_clients"] = [] + print(user_data) self.user_data: UserData = UserData.model_validate(user_data) self._userdb: UserDB = UserDB(self) except ValidationError as e: @@ -325,7 +328,7 @@ def membership_end_date(self) -> ActiveProperty[date | None, date | None]: @property def mpsk_clients(self) -> ActiveProperty[str | None, str | None]: - return ActiveProperty(name="mpsk_clients", value=self.user_data.mpsk_clients, capabilities=Capabilities(edit=True, delete=False, displayable=False),) + return ActiveProperty(name="mpsk_clients", value=self.user_data.mpsk_clients, capabilities=Capabilities(edit=True, delete=False),) def change_mpsk_clients(self, mac, name, mpsk_id, password: str): status, _ = api.change_mpsk(self.user_data.id, mac, name, mpsk_id, password) @@ -346,20 +349,24 @@ def add_mpsk_client(self, name, mac, password): password, mac, name) - + print(status) if status == 400: - raise ValueError("Execceds maximum clients") + raise MaximumNumberMPSKClients elif status == 409: raise MacAlreadyExists elif status == 422: raise ValueError + elif status == 412: + raise NoWiFiPasswordGenerated + try: - response = json.loads(response) + response = response + print(f"response {response}") except json.decoder.JSONDecodeError as err: raise ValueError(f"Invalid response from {response}") from err - if ('name', 'mac', 'id') in response.keys(): + if 'name' in response.keys() and 'mac' in response.keys() and 'id' in response.keys(): return MPSKClientEntry(name=response.get('name'), mac=response.get('mac'), id=response.get('id')) else: raise ValueError(f"Invalid response from {response}")