feat: public settings 区分 public 和 open

pull/8199/head
Jiangjie.Bai 2022-05-06 16:27:14 +08:00 committed by 老广
parent 56862a965d
commit 3f856e68f0
3 changed files with 102 additions and 50 deletions

View File

@ -1,5 +1,5 @@
from rest_framework import generics
from rest_framework.permissions import AllowAny
from rest_framework.permissions import AllowAny, IsAuthenticated
from django.conf import settings
from jumpserver.utils import has_valid_xpack_license, get_xpack_license_info
@ -9,10 +9,10 @@ from ..utils import get_interface_setting
logger = get_logger(__name__)
__all__ = ['PublicSettingApi']
__all__ = ['PublicSettingApi', 'OpenPublicSettingApi']
class PublicSettingApi(generics.RetrieveAPIView):
class OpenPublicSettingApi(generics.RetrieveAPIView):
permission_classes = (AllowAny,)
serializer_class = serializers.PublicSettingSerializer
@ -27,9 +27,25 @@ class PublicSettingApi(generics.RetrieveAPIView):
interface = get_interface_setting()
return interface['login_title']
def get_open_public_settings(self):
return {
"XPACK_ENABLED": settings.XPACK_ENABLED,
"LOGIN_TITLE": self.get_login_title(),
"LOGO_URLS": self.get_logo_urls(),
'SECURITY_WATERMARK_ENABLED': settings.SECURITY_WATERMARK_ENABLED,
}
def get_object(self):
instance = {
"data": {
return self.get_open_public_settings()
class PublicSettingApi(OpenPublicSettingApi):
permission_classes = (IsAuthenticated,)
serializer_class = serializers.PrivateSettingSerializer
@staticmethod
def get_public_settings():
return {
# Security
"WINDOWS_SKIP_ALL_MANUAL_PASSWORD": settings.WINDOWS_SKIP_ALL_MANUAL_PASSWORD,
"OLD_PASSWORD_HISTORY_LIMIT_COUNT": settings.OLD_PASSWORD_HISTORY_LIMIT_COUNT,
@ -47,15 +63,11 @@ class PublicSettingApi(generics.RetrieveAPIView):
'SECURITY_PASSWORD_NUMBER': settings.SECURITY_PASSWORD_NUMBER,
'SECURITY_PASSWORD_SPECIAL_CHAR': settings.SECURITY_PASSWORD_SPECIAL_CHAR,
},
'SECURITY_WATERMARK_ENABLED': settings.SECURITY_WATERMARK_ENABLED,
'SECURITY_SESSION_SHARE': settings.SECURITY_SESSION_SHARE,
# XPACK
"XPACK_ENABLED": settings.XPACK_ENABLED,
"XPACK_LICENSE_IS_VALID": has_valid_xpack_license(),
"XPACK_LICENSE_INFO": get_xpack_license_info(),
# Performance
"LOGIN_TITLE": self.get_login_title(),
"LOGO_URLS": self.get_logo_urls(),
"HELP_DOCUMENT_URL": settings.HELP_DOCUMENT_URL,
"HELP_SUPPORT_URL": settings.HELP_SUPPORT_URL,
# Auth
@ -71,5 +83,12 @@ class PublicSettingApi(generics.RetrieveAPIView):
"ANNOUNCEMENT": settings.ANNOUNCEMENT,
"AUTH_TEMP_TOKEN": settings.AUTH_TEMP_TOKEN,
}
def get_object(self):
open_public = self.get_open_public_settings()
public = self.get_public_settings()
return {
**open_public,
**public
}
return instance

View File

@ -3,8 +3,40 @@
from rest_framework import serializers
__all__ = ['PublicSettingSerializer']
__all__ = ['PublicSettingSerializer', 'PrivateSettingSerializer']
class PublicSettingSerializer(serializers.Serializer):
data = serializers.DictField(read_only=True)
XPACK_ENABLED = serializers.BooleanField()
SECURITY_WATERMARK_ENABLED = serializers.BooleanField()
LOGIN_TITLE = serializers.CharField()
LOGO_URLS = serializers.DictField()
class PrivateSettingSerializer(PublicSettingSerializer):
WINDOWS_SKIP_ALL_MANUAL_PASSWORD = serializers.BooleanField()
OLD_PASSWORD_HISTORY_LIMIT_COUNT = serializers.IntegerField()
SECURITY_MAX_IDLE_TIME = serializers.IntegerField()
SECURITY_VIEW_AUTH_NEED_MFA = serializers.BooleanField()
SECURITY_MFA_VERIFY_TTL = serializers.IntegerField()
SECURITY_COMMAND_EXECUTION = serializers.BooleanField()
SECURITY_PASSWORD_EXPIRATION_TIME = serializers.IntegerField()
SECURITY_LUNA_REMEMBER_AUTH = serializers.BooleanField()
PASSWORD_RULE = serializers.DictField()
SECURITY_SESSION_SHARE = serializers.BooleanField()
XPACK_LICENSE_IS_VALID = serializers.BooleanField()
XPACK_LICENSE_INFO = serializers.DictField()
HELP_DOCUMENT_URL = serializers.CharField()
HELP_SUPPORT_URL = serializers.CharField()
AUTH_WECOM = serializers.BooleanField()
AUTH_DINGTALK = serializers.BooleanField()
AUTH_FEISHU = serializers.BooleanField()
AUTH_TEMP_TOKEN = serializers.BooleanField()
XRDP_ENABLED = serializers.BooleanField()
TERMINAL_MAGNUS_ENABLED = serializers.BooleanField()
TERMINAL_KOKO_SSH_ENABLED = serializers.BooleanField()
ANNOUNCEMENT_ENABLED = serializers.BooleanField()
ANNOUNCEMENT = serializers.CharField()

View File

@ -22,4 +22,5 @@ urlpatterns = [
path('setting/', api.SettingsApi.as_view(), name='settings-setting'),
path('public/', api.PublicSettingApi.as_view(), name='public-setting'),
path('public/open/', api.OpenPublicSettingApi.as_view(), name='open-public-setting'),
]