feat: system profile (#3193)
This commit is contained in:
parent
28c09ae220
commit
445a87143b
@ -20,8 +20,10 @@ class Cache_Version(Enum):
|
|||||||
ROLE_LIST = "ROLE:LIST", lambda user_id: user_id
|
ROLE_LIST = "ROLE:LIST", lambda user_id: user_id
|
||||||
# 当前用户所有权限
|
# 当前用户所有权限
|
||||||
PERMISSION_LIST = "PERMISSION:LIST", lambda user_id: user_id
|
PERMISSION_LIST = "PERMISSION:LIST", lambda user_id: user_id
|
||||||
|
# 验证码
|
||||||
CAPTCHA = "CAPTCHA", lambda captcha: captcha
|
CAPTCHA = "CAPTCHA", lambda captcha: captcha
|
||||||
|
# 系统
|
||||||
|
SYSTEM = "SYSTEM", lambda key: key
|
||||||
|
|
||||||
def get_version(self):
|
def get_version(self):
|
||||||
return self.value[0]
|
return self.value[0]
|
||||||
|
|||||||
@ -155,3 +155,5 @@ STATIC_URL = 'static/'
|
|||||||
# https://docs.djangoproject.com/en/4.2/ref/settings/#default-auto-field
|
# https://docs.djangoproject.com/en/4.2/ref/settings/#default-auto-field
|
||||||
|
|
||||||
DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
|
DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
|
||||||
|
|
||||||
|
edition = 'CE'
|
||||||
|
|||||||
22
apps/system_manage/api/system.py
Normal file
22
apps/system_manage/api/system.py
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
# coding=utf-8
|
||||||
|
"""
|
||||||
|
@project: MaxKB
|
||||||
|
@Author:虎虎
|
||||||
|
@file: system_setting.py
|
||||||
|
@date:2025/6/4 16:34
|
||||||
|
@desc:
|
||||||
|
"""
|
||||||
|
from common.mixins.api_mixin import APIMixin
|
||||||
|
from common.result import ResultSerializer
|
||||||
|
from system_manage.serializers.system import SystemProfileResponseSerializer
|
||||||
|
|
||||||
|
|
||||||
|
class SystemProfileResult(ResultSerializer):
|
||||||
|
def get_data(self):
|
||||||
|
return SystemProfileResponseSerializer()
|
||||||
|
|
||||||
|
|
||||||
|
class SystemProfileAPI(APIMixin):
|
||||||
|
@staticmethod
|
||||||
|
def get_response():
|
||||||
|
return SystemProfileResult
|
||||||
41
apps/system_manage/serializers/system.py
Normal file
41
apps/system_manage/serializers/system.py
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
# coding=utf-8
|
||||||
|
"""
|
||||||
|
@project: MaxKB
|
||||||
|
@Author:虎虎
|
||||||
|
@file: system.py
|
||||||
|
@date:2025/6/4 16:01
|
||||||
|
@desc:
|
||||||
|
"""
|
||||||
|
import os
|
||||||
|
|
||||||
|
from django.db import models
|
||||||
|
from rest_framework import serializers
|
||||||
|
from django.core.cache import cache
|
||||||
|
|
||||||
|
from common.constants.cache_version import Cache_Version
|
||||||
|
from maxkb import settings
|
||||||
|
|
||||||
|
|
||||||
|
class SettingType(models.CharField):
|
||||||
|
# Community Edition
|
||||||
|
CE = "CE", "社区"
|
||||||
|
# Enterprise Edition
|
||||||
|
PE = "PE", "专业版"
|
||||||
|
# Professional Edition
|
||||||
|
EE = "EE", '企业版'
|
||||||
|
|
||||||
|
|
||||||
|
class SystemProfileResponseSerializer(serializers.Serializer):
|
||||||
|
version = serializers.CharField(required=True, label="version")
|
||||||
|
edition = serializers.CharField(required=True, label="edition")
|
||||||
|
license_is_valid = serializers.BooleanField(required=True, label="License is valid")
|
||||||
|
|
||||||
|
|
||||||
|
class SystemProfileSerializer(serializers.Serializer):
|
||||||
|
@staticmethod
|
||||||
|
def profile():
|
||||||
|
version = os.environ.get('MAXKB_VERSION')
|
||||||
|
license_is_valid = cache.get(Cache_Version.SYSTEM.get_key(key='license_is_valid'),
|
||||||
|
version=Cache_Version.SYSTEM.get_version())
|
||||||
|
return {'version': version, 'edition': settings.edition,
|
||||||
|
'license_is_valid': license_is_valid if license_is_valid is not None else False}
|
||||||
@ -7,4 +7,5 @@ urlpatterns = [
|
|||||||
path('workspace/<str:workspace_id>/user_resource_permission/user/<str:user_id>',
|
path('workspace/<str:workspace_id>/user_resource_permission/user/<str:user_id>',
|
||||||
views.WorkSpaceUserResourcePermissionView.as_view()),
|
views.WorkSpaceUserResourcePermissionView.as_view()),
|
||||||
path('email_setting', views.SystemSetting.Email.as_view()),
|
path('email_setting', views.SystemSetting.Email.as_view()),
|
||||||
|
path('profile', views.SystemProfile.as_view())
|
||||||
]
|
]
|
||||||
|
|||||||
@ -8,3 +8,4 @@
|
|||||||
"""
|
"""
|
||||||
from .user_resource_permission import *
|
from .user_resource_permission import *
|
||||||
from .email_setting import *
|
from .email_setting import *
|
||||||
|
from .system_profile import *
|
||||||
|
|||||||
28
apps/system_manage/views/system_profile.py
Normal file
28
apps/system_manage/views/system_profile.py
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
# coding=utf-8
|
||||||
|
"""
|
||||||
|
@project: MaxKB
|
||||||
|
@Author:虎虎
|
||||||
|
@file: system_profile.py
|
||||||
|
@date:2025/6/4 15:59
|
||||||
|
@desc:
|
||||||
|
"""
|
||||||
|
from django.utils.translation import gettext_lazy as _
|
||||||
|
from drf_spectacular.utils import extend_schema
|
||||||
|
from rest_framework.request import Request
|
||||||
|
from rest_framework.views import APIView
|
||||||
|
|
||||||
|
from common import result
|
||||||
|
from system_manage.api.system import SystemProfileAPI
|
||||||
|
from system_manage.serializers.system import SystemProfileSerializer
|
||||||
|
|
||||||
|
|
||||||
|
class SystemProfile(APIView):
|
||||||
|
@extend_schema(
|
||||||
|
methods=['GET'],
|
||||||
|
description=_('Get MaxKB related information'),
|
||||||
|
operation_id=_('Get MaxKB related information'), # type: ignore
|
||||||
|
responses=SystemProfileAPI.get_response(),
|
||||||
|
tags=[_('System parameters')] # type: ignore
|
||||||
|
)
|
||||||
|
def get(self, request: Request):
|
||||||
|
return result.success(SystemProfileSerializer.profile())
|
||||||
Loading…
Reference in New Issue
Block a user