mirror of
https://github.com/i701/sarlink-portal-api.git
synced 2025-10-05 13:35:23 +00:00
feat(admin): enhance AdminTopupCreateView to support custom top-up descriptions ✨
All checks were successful
Build and Push Docker Images / Build and Push Docker Images (push) Successful in 4m25s
All checks were successful
Build and Push Docker Images / Build and Push Docker Images (push) Successful in 4m25s
This commit is contained in:
@@ -606,6 +606,8 @@ class AdminTopupCreateView(StaffEditorPermissionMixin, generics.CreateAPIView):
|
|||||||
data = request.data
|
data = request.data
|
||||||
user_id = data.get("user_id")
|
user_id = data.get("user_id")
|
||||||
amount = data.get("amount")
|
amount = data.get("amount")
|
||||||
|
topup_description = ""
|
||||||
|
admin_description = data.get("description", "")
|
||||||
if not getattr(request.user, "is_admin", False):
|
if not getattr(request.user, "is_admin", False):
|
||||||
return Response(
|
return Response(
|
||||||
{"message": "You are not authorized to perform this action."},
|
{"message": "You are not authorized to perform this action."},
|
||||||
@@ -635,8 +637,12 @@ class AdminTopupCreateView(StaffEditorPermissionMixin, generics.CreateAPIView):
|
|||||||
payment_type="CASH",
|
payment_type="CASH",
|
||||||
status="PAID",
|
status="PAID",
|
||||||
)
|
)
|
||||||
description = f"Topup of {amount} MVR (Cash)"
|
default_description = f"Topup of {amount} MVR (Cash)"
|
||||||
user.add_wallet_funds(amount, description, topup.id)
|
if admin_description and admin_description.strip() != "":
|
||||||
|
topup_description = admin_description.strip()
|
||||||
|
else:
|
||||||
|
topup_description = default_description
|
||||||
|
user.add_wallet_funds(amount, topup_description, topup.id)
|
||||||
serializer = TopupSerializer(topup)
|
serializer = TopupSerializer(topup)
|
||||||
return Response(serializer.data, status=status.HTTP_201_CREATED)
|
return Response(serializer.data, status=status.HTTP_201_CREATED)
|
||||||
|
|
||||||
|
@@ -76,7 +76,8 @@ class DeviceListCreateAPIView(
|
|||||||
{"message": "Device name is too long."},
|
{"message": "Device name is too long."},
|
||||||
status=400,
|
status=400,
|
||||||
)
|
)
|
||||||
mac = request.data.get("mac", None)
|
raw_mac = request.data.get("mac", None)
|
||||||
|
mac = raw_mac.strip() if raw_mac else 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]")
|
||||||
if not isinstance(mac, str) or not MAC_REGEX.match(mac):
|
if not isinstance(mac, str) or not MAC_REGEX.match(mac):
|
||||||
|
Reference in New Issue
Block a user