Skip to content

Commit

Permalink
fixup! fixed bug adding mpsk clients
Browse files Browse the repository at this point in the history
  • Loading branch information
agmes4 committed Jan 18, 2025
1 parent 63156e2 commit 56b4dec
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions sipa/model/pycroft/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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:
Expand Down Expand Up @@ -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)
Expand All @@ -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}")
Expand Down

0 comments on commit 56b4dec

Please sign in to comment.