mirror of
https://github.com/i701/sarlink-portal-api.git
synced 2025-06-28 09:50:05 +00:00
Refactor and enhance device management and authentication features
Some checks failed
Build and Push Docker Images / Build and Push Docker Images (push) Failing after 4m12s
Some checks failed
Build and Push Docker Images / Build and Push Docker Images (push) Failing after 4m12s
- Updated the `reverse_dhivehi_string` function to correct the range for combining characters. - Added new device handling in the health check view and integrated the `add_new_devices_to_omada` task. - Improved date handling in `CreateTemporaryUserView` to ensure proper string conversion. - Enhanced OTP sending by converting mobile numbers to strings. - Implemented MAC address validation in the `Device` model using a custom validator. - Removed unnecessary fields from the `CreateDeviceSerializer`. - Normalized MAC address format in the `DeviceListCreateAPIView`. - Updated the `djangopasswordlessknox` package to improve code consistency and readability. - Added migration to enforce MAC address validation in the database.
This commit is contained in:
@ -1,32 +1,25 @@
|
||||
# Create your views here.
|
||||
# billing/views.py
|
||||
import os
|
||||
from datetime import timedelta
|
||||
from django.utils import timezone
|
||||
|
||||
import requests
|
||||
|
||||
from django.utils import timezone
|
||||
from django.utils.timezone import localtime
|
||||
from rest_framework import generics, status
|
||||
from rest_framework.response import Response
|
||||
|
||||
from api.mixins import StaffEditorPermissionMixin
|
||||
from api.tasks import add_new_devices_to_omada
|
||||
from apibase.env import BASE_DIR, env
|
||||
|
||||
from .models import Device, Payment
|
||||
from .serializers import PaymentSerializer, UpdatePaymentSerializer
|
||||
|
||||
from apibase.env import env, BASE_DIR
|
||||
from django.utils.timezone import localtime
|
||||
import os
|
||||
|
||||
env.read_env(os.path.join(BASE_DIR, ".env"))
|
||||
|
||||
PAYMENT_BASE_URL = env("PAYMENT_BASE_URL", default=None)
|
||||
OMADA_PROXY_URL = env("OMADA_PROXY_URL", default=None)
|
||||
|
||||
|
||||
if not OMADA_PROXY_URL:
|
||||
raise ValueError(
|
||||
"OMADA_PROXY_URL is not set. Please set it in your environment variables."
|
||||
)
|
||||
if not PAYMENT_BASE_URL:
|
||||
raise ValueError(
|
||||
"PAYMENT_BASE_URL is not set. Please set it in your environment variables."
|
||||
@ -180,10 +173,19 @@ class VerifyPaymentView(StaffEditorPermissionMixin, generics.UpdateAPIView):
|
||||
registered=True,
|
||||
)
|
||||
# Need to add to omada if its a new device and not an existing device
|
||||
device_list = []
|
||||
for device in devices:
|
||||
device_list.append(
|
||||
{
|
||||
"mac": device.mac,
|
||||
"name": device.name,
|
||||
}
|
||||
)
|
||||
if not device.registered:
|
||||
# Add to omada
|
||||
pass
|
||||
add_new_devices_to_omada.delay(new_devices=device_list)
|
||||
device.registered = True
|
||||
device.save()
|
||||
|
||||
return Response(
|
||||
{"message": f"Payment verified successfully using [{method}]."}
|
||||
@ -242,12 +244,3 @@ class DeletePaymentView(StaffEditorPermissionMixin, generics.DestroyAPIView):
|
||||
devices = instance.devices.all()
|
||||
devices.update(is_active=False, expiry_date=None, has_a_pending_payment=False)
|
||||
return super().delete(request, *args, **kwargs)
|
||||
|
||||
|
||||
def get_existing_devices(OMADA_SITE_ID: str, OMADA_GROUP_ID: str):
|
||||
# Get existing devices from omada
|
||||
response = requests.get(
|
||||
f"{OMADA_PROXY_URL}/{OMADA_GROUP_ID}/api/v2/sites/{OMADA_SITE_ID}/setting/profiles/groups",
|
||||
)
|
||||
response.raise_for_status()
|
||||
return response.json()
|
||||
|
Reference in New Issue
Block a user