mirror of
https://github.com/i701/sarlink-portal-api.git
synced 2025-10-05 13:35:23 +00:00
fix(devices): update DeviceBlockAPIView to handle omada_client response correctly 🐛
All checks were successful
Build and Push Docker Images / Build and Push Docker Images (push) Successful in 5m24s
All checks were successful
Build and Push Docker Images / Build and Push Docker Images (push) Successful in 5m24s
This commit is contained in:
@@ -145,10 +145,11 @@ class DeviceBlockAPIView(StaffEditorPermissionMixin, generics.UpdateAPIView):
|
|||||||
if not isinstance(blocked, bool):
|
if not isinstance(blocked, bool):
|
||||||
return Response({"message": "Blocked field must be a boolean."}, status=400)
|
return Response({"message": "Blocked field must be a boolean."}, status=400)
|
||||||
omada_client = Omada()
|
omada_client = Omada()
|
||||||
blocked = omada_client.block_device(
|
omada_response = omada_client.block_device(
|
||||||
instance.mac, operation="block" if blocked else "unblock"
|
instance.mac, operation="block" if blocked else "unblock"
|
||||||
)
|
)
|
||||||
if blocked.errorCode == 0:
|
print(f"Blocked: {blocked}")
|
||||||
|
if omada_response.errorCode == 0:
|
||||||
instance.blocked = blocked
|
instance.blocked = blocked
|
||||||
instance.save()
|
instance.save()
|
||||||
serializer = self.get_serializer(instance, data=request.data, partial=False)
|
serializer = self.get_serializer(instance, data=request.data, partial=False)
|
||||||
@@ -157,7 +158,7 @@ class DeviceBlockAPIView(StaffEditorPermissionMixin, generics.UpdateAPIView):
|
|||||||
return Response(serializer.data)
|
return Response(serializer.data)
|
||||||
else:
|
else:
|
||||||
return Response(
|
return Response(
|
||||||
{"message": blocked.msg},
|
{"message": omada_response.msg},
|
||||||
status=status.HTTP_400_BAD_REQUEST,
|
status=status.HTTP_400_BAD_REQUEST,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user