mirror of
https://github.com/i701/sarlink-portal-api.git
synced 2025-10-05 13:35: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()
|
devices = payment.devices.all()
|
||||||
data = request.data
|
data = request.data
|
||||||
user = request.user
|
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()
|
omada_client = Omada()
|
||||||
if payment.paid:
|
if payment.paid:
|
||||||
return Response(
|
return Response(
|
||||||
@@ -218,7 +219,7 @@ class VerifyPaymentView(StaffEditorPermissionMixin, generics.UpdateAPIView):
|
|||||||
device_list.append(
|
device_list.append(
|
||||||
{
|
{
|
||||||
"mac": device.mac,
|
"mac": device.mac,
|
||||||
"name": device.name,
|
"name": f"{user_details} - {device.name}",
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
if device.registered:
|
if device.registered:
|
||||||
@@ -261,7 +262,7 @@ class VerifyPaymentView(StaffEditorPermissionMixin, generics.UpdateAPIView):
|
|||||||
device_list.append(
|
device_list.append(
|
||||||
{
|
{
|
||||||
"mac": device.mac,
|
"mac": device.mac,
|
||||||
"name": device.name,
|
"name": f"{user_details} - {device.name}",
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
if device.registered:
|
if device.registered:
|
||||||
|
@@ -67,6 +67,15 @@ class DeviceListCreateAPIView(
|
|||||||
return DeviceSerializer
|
return DeviceSerializer
|
||||||
|
|
||||||
def create(self, request, *args, **kwargs):
|
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 = request.data.get("mac", None)
|
||||||
MAC_REGEX = re.compile(r"^([0-9A-Fa-f]{2}([.:-]?)){5}[0-9A-Fa-f]{2}$")
|
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]")
|
NORMALIZE_MAC_REGEX = re.compile(r"[^0-9A-Fa-f]")
|
||||||
|
Reference in New Issue
Block a user