feat(devices): enhance device naming to include user details and enforce name length limit
All checks were successful
Build and Push Docker Images / Build and Push Docker Images (push) Successful in 4m1s

This commit is contained in:
2025-07-27 14:59:08 +05:00
parent b52cd9285a
commit ee54386fd5
2 changed files with 12 additions and 2 deletions

View File

@@ -183,6 +183,7 @@ class VerifyPaymentView(StaffEditorPermissionMixin, generics.UpdateAPIView):
devices = payment.devices.all()
data = request.data
user = request.user
user_details = f"{user.first_name.capitalize() if user.first_name else ''} {user.last_name.capitalize() if user.last_name else ''} {user.mobile}" # type: ignore
omada_client = Omada()
if payment.paid:
return Response(
@@ -218,7 +219,7 @@ class VerifyPaymentView(StaffEditorPermissionMixin, generics.UpdateAPIView):
device_list.append(
{
"mac": device.mac,
"name": device.name,
"name": f"{user_details} - {device.name}",
}
)
if device.registered:
@@ -261,7 +262,7 @@ class VerifyPaymentView(StaffEditorPermissionMixin, generics.UpdateAPIView):
device_list.append(
{
"mac": device.mac,
"name": device.name,
"name": f"{user_details} - {device.name}",
}
)
if device.registered:

View File

@@ -67,6 +67,15 @@ class DeviceListCreateAPIView(
return DeviceSerializer
def create(self, request, *args, **kwargs):
user = request.user
name = request.data.get("name", None)
user_details = f"{user.first_name.capitalize() if user.first_name else ''} {user.last_name.capitalize() if user.last_name else ''} {user.mobile}" # type: ignore
omada_device_name = f"{user_details} - {name}" if name else user_details
if len(omada_device_name) > 64:
return Response(
{"message": "Device name is too long."},
status=400,
)
mac = request.data.get("mac", None)
MAC_REGEX = re.compile(r"^([0-9A-Fa-f]{2}([.:-]?)){5}[0-9A-Fa-f]{2}$")
NORMALIZE_MAC_REGEX = re.compile(r"[^0-9A-Fa-f]")