mirror of
https://github.com/i701/sarlink-portal-api.git
synced 2025-10-05 01:15:23 +00:00
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
All checks were successful
Build and Push Docker Images / Build and Push Docker Images (push) Successful in 4m1s
This commit is contained in:
@@ -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:
|
||||
|
@@ -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]")
|
||||
|
Reference in New Issue
Block a user