2020-04-29 03:08:09 +00:00
|
|
|
# coding: utf-8
|
2022-11-04 06:22:38 +00:00
|
|
|
from django.core.cache import cache
|
|
|
|
from django.utils.translation import ugettext_lazy as _
|
2020-04-29 03:08:09 +00:00
|
|
|
|
2021-09-09 06:00:50 +00:00
|
|
|
from .basic import BasicSettingSerializer
|
|
|
|
from .other import OtherSettingSerializer
|
|
|
|
from .email import EmailSettingSerializer, EmailContentSettingSerializer
|
|
|
|
from .auth import (
|
|
|
|
LDAPSettingSerializer, OIDCSettingSerializer, KeycloakSettingSerializer,
|
|
|
|
CASSettingSerializer, RadiusSettingSerializer, FeiShuSettingSerializer,
|
2021-08-24 06:20:54 +00:00
|
|
|
WeComSettingSerializer, DingTalkSettingSerializer, AlibabaSMSSettingSerializer,
|
2022-11-04 06:22:38 +00:00
|
|
|
TencentSMSSettingSerializer, CMPP2SMSSettingSerializer, AuthSettingSerializer,
|
|
|
|
SAML2SettingSerializer, OAuth2SettingSerializer, SSOSettingSerializer
|
2021-09-09 06:00:50 +00:00
|
|
|
)
|
|
|
|
from .terminal import TerminalSettingSerializer
|
|
|
|
from .security import SecuritySettingSerializer
|
|
|
|
from .cleaning import CleaningSerializer
|
2020-04-29 03:08:09 +00:00
|
|
|
|
2021-08-24 06:20:54 +00:00
|
|
|
|
2021-01-26 09:54:12 +00:00
|
|
|
__all__ = [
|
2021-09-09 06:00:50 +00:00
|
|
|
'SettingsSerializer',
|
2021-01-26 09:54:12 +00:00
|
|
|
]
|
2020-04-29 03:08:09 +00:00
|
|
|
|
|
|
|
|
2021-01-26 09:54:12 +00:00
|
|
|
class SettingsSerializer(
|
|
|
|
BasicSettingSerializer,
|
|
|
|
LDAPSettingSerializer,
|
2022-11-04 06:22:38 +00:00
|
|
|
AuthSettingSerializer,
|
2021-01-26 09:54:12 +00:00
|
|
|
TerminalSettingSerializer,
|
2021-03-24 11:01:35 +00:00
|
|
|
SecuritySettingSerializer,
|
|
|
|
WeComSettingSerializer,
|
|
|
|
DingTalkSettingSerializer,
|
2021-08-12 08:44:06 +00:00
|
|
|
FeiShuSettingSerializer,
|
2021-09-09 06:00:50 +00:00
|
|
|
EmailSettingSerializer,
|
|
|
|
EmailContentSettingSerializer,
|
|
|
|
OtherSettingSerializer,
|
|
|
|
OIDCSettingSerializer,
|
2022-11-04 06:22:38 +00:00
|
|
|
SAML2SettingSerializer,
|
|
|
|
OAuth2SettingSerializer,
|
2021-09-09 06:00:50 +00:00
|
|
|
KeycloakSettingSerializer,
|
|
|
|
CASSettingSerializer,
|
|
|
|
RadiusSettingSerializer,
|
2022-11-04 06:22:38 +00:00
|
|
|
SSOSettingSerializer,
|
2021-08-24 06:20:54 +00:00
|
|
|
CleaningSerializer,
|
|
|
|
AlibabaSMSSettingSerializer,
|
|
|
|
TencentSMSSettingSerializer,
|
2022-08-09 08:09:20 +00:00
|
|
|
CMPP2SMSSettingSerializer,
|
2021-01-26 09:54:12 +00:00
|
|
|
):
|
2022-11-04 06:22:38 +00:00
|
|
|
CACHE_KEY = 'SETTING_FIELDS_MAPPING'
|
|
|
|
|
2021-01-26 09:54:12 +00:00
|
|
|
# encrypt_fields 现在使用 write_only 来判断了
|
2022-11-04 06:22:38 +00:00
|
|
|
def __init__(self, **kwargs):
|
|
|
|
super().__init__(**kwargs)
|
|
|
|
self.fields_label_mapping = None
|
|
|
|
|
|
|
|
# 单次计算量不大,搞个缓存,以防操作日志大量写入时,这里影响性能
|
|
|
|
def get_field_label(self, field_name):
|
|
|
|
if self.fields_label_mapping is None:
|
|
|
|
self.fields_label_mapping = {}
|
|
|
|
for subclass in SettingsSerializer.__bases__:
|
|
|
|
prefix = getattr(subclass, 'PREFIX_TITLE', _('Setting'))
|
|
|
|
fields = subclass().get_fields()
|
|
|
|
for name, item in fields.items():
|
|
|
|
label = '[%s] %s' % (prefix, getattr(item, 'label', ''))
|
|
|
|
self.fields_label_mapping[name] = label
|
|
|
|
cache.set(self.CACHE_KEY, self.fields_label_mapping, 3600 * 24)
|
|
|
|
return self.fields_label_mapping.get(field_name)
|