2021-09-09 06:00:50 +00:00
|
|
|
from django.conf import settings
|
2023-02-09 12:48:25 +00:00
|
|
|
from rest_framework import generics
|
|
|
|
from rest_framework.permissions import AllowAny
|
2021-09-09 06:00:50 +00:00
|
|
|
|
2023-10-12 08:17:32 +00:00
|
|
|
from authentication.permissions import IsValidUserOrConnectionToken
|
2024-02-02 08:52:57 +00:00
|
|
|
from common.const.choices import COUNTRY_CALLING_CODES
|
2023-02-09 12:48:25 +00:00
|
|
|
from common.utils import get_logger, lazyproperty
|
2023-07-28 02:40:48 +00:00
|
|
|
from common.utils.timezone import local_now
|
2021-09-09 06:00:50 +00:00
|
|
|
from .. import serializers
|
2022-07-05 06:43:56 +00:00
|
|
|
from ..utils import get_interface_setting_or_default
|
2021-09-09 06:00:50 +00:00
|
|
|
|
|
|
|
logger = get_logger(__name__)
|
|
|
|
|
2023-07-28 02:40:48 +00:00
|
|
|
__all__ = ['PublicSettingApi', 'OpenPublicSettingApi', 'ServerInfoApi']
|
2021-09-09 06:00:50 +00:00
|
|
|
|
|
|
|
|
2022-05-06 08:27:14 +00:00
|
|
|
class OpenPublicSettingApi(generics.RetrieveAPIView):
|
2021-09-09 06:00:50 +00:00
|
|
|
permission_classes = (AllowAny,)
|
|
|
|
serializer_class = serializers.PublicSettingSerializer
|
|
|
|
|
2022-07-05 06:43:56 +00:00
|
|
|
@lazyproperty
|
|
|
|
def interface_setting(self):
|
|
|
|
return get_interface_setting_or_default()
|
2021-09-09 06:00:50 +00:00
|
|
|
|
2022-05-11 09:09:23 +00:00
|
|
|
def get_object(self):
|
2022-05-06 08:27:14 +00:00
|
|
|
return {
|
|
|
|
"XPACK_ENABLED": settings.XPACK_ENABLED,
|
2024-02-02 08:52:57 +00:00
|
|
|
"INTERFACE": self.interface_setting,
|
|
|
|
"COUNTRY_CALLING_CODES": COUNTRY_CALLING_CODES
|
2022-05-06 08:27:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
class PublicSettingApi(OpenPublicSettingApi):
|
2022-07-15 06:56:51 +00:00
|
|
|
permission_classes = (IsValidUserOrConnectionToken,)
|
2022-05-06 08:27:14 +00:00
|
|
|
serializer_class = serializers.PrivateSettingSerializer
|
|
|
|
|
2022-05-11 09:09:23 +00:00
|
|
|
def get_object(self):
|
|
|
|
values = super().get_object()
|
|
|
|
values.update({
|
2023-10-18 06:10:24 +00:00
|
|
|
"XPACK_LICENSE_IS_VALID": settings.XPACK_LICENSE_IS_VALID,
|
|
|
|
"XPACK_LICENSE_INFO": settings.XPACK_LICENSE_INFO,
|
2022-05-06 08:27:14 +00:00
|
|
|
"PASSWORD_RULE": {
|
|
|
|
'SECURITY_PASSWORD_MIN_LENGTH': settings.SECURITY_PASSWORD_MIN_LENGTH,
|
|
|
|
'SECURITY_ADMIN_USER_PASSWORD_MIN_LENGTH': settings.SECURITY_ADMIN_USER_PASSWORD_MIN_LENGTH,
|
|
|
|
'SECURITY_PASSWORD_UPPER_CASE': settings.SECURITY_PASSWORD_UPPER_CASE,
|
|
|
|
'SECURITY_PASSWORD_LOWER_CASE': settings.SECURITY_PASSWORD_LOWER_CASE,
|
|
|
|
'SECURITY_PASSWORD_NUMBER': settings.SECURITY_PASSWORD_NUMBER,
|
|
|
|
'SECURITY_PASSWORD_SPECIAL_CHAR': settings.SECURITY_PASSWORD_SPECIAL_CHAR,
|
|
|
|
},
|
2022-05-11 09:09:23 +00:00
|
|
|
})
|
2022-05-12 03:27:32 +00:00
|
|
|
|
|
|
|
serializer = self.serializer_class()
|
|
|
|
field_names = list(serializer.fields.keys())
|
|
|
|
for name in field_names:
|
|
|
|
if name in values:
|
|
|
|
continue
|
|
|
|
# 提前把异常爆出来
|
|
|
|
values[name] = getattr(settings, name)
|
2022-05-11 09:09:23 +00:00
|
|
|
return values
|
2023-07-28 02:40:48 +00:00
|
|
|
|
|
|
|
|
|
|
|
class ServerInfoApi(generics.RetrieveAPIView):
|
|
|
|
permission_classes = (IsValidUserOrConnectionToken,)
|
|
|
|
serializer_class = serializers.ServerInfoSerializer
|
|
|
|
|
|
|
|
def get_object(self):
|
|
|
|
return {
|
|
|
|
"CURRENT_TIME": local_now(),
|
|
|
|
}
|