diff --git a/apps/settings/api/settings.py b/apps/settings/api/settings.py index 4dda51408..2047faa08 100644 --- a/apps/settings/api/settings.py +++ b/apps/settings/api/settings.py @@ -34,6 +34,7 @@ class SettingsApi(generics.RetrieveUpdateAPIView): 'sso': serializers.SSOSettingSerializer, 'clean': serializers.CleaningSerializer, 'other': serializers.OtherSettingSerializer, + 'sms': serializers.SMSSettingSerializer, 'alibaba': serializers.AlibabaSMSSettingSerializer, 'tencent': serializers.TencentSMSSettingSerializer, } diff --git a/apps/settings/serializers/auth/sms.py b/apps/settings/serializers/auth/sms.py index 275a8436e..c018720b2 100644 --- a/apps/settings/serializers/auth/sms.py +++ b/apps/settings/serializers/auth/sms.py @@ -3,21 +3,24 @@ from rest_framework import serializers from common.message.backends.sms import BACKENDS -__all__ = ['AlibabaSMSSettingSerializer', 'TencentSMSSettingSerializer'] +__all__ = ['SMSSettingSerializer', 'AlibabaSMSSettingSerializer', 'TencentSMSSettingSerializer'] + + +class SMSSettingSerializer(serializers.Serializer): + SMS_ENABLED = serializers.BooleanField(default=False, label=_('Enable SMS')) + SMS_BACKEND = serializers.ChoiceField(choices=BACKENDS.choices, default=BACKENDS.ALIBABA) class BaseSMSSettingSerializer(serializers.Serializer): - SMS_ENABLED = serializers.BooleanField(default=False, label=_('Enable SMS')) SMS_TEST_PHONE = serializers.CharField(max_length=256, required=False, label=_('Test phone')) def to_representation(self, instance): data = super().to_representation(instance) - data['SMS_BACKEND'] = self.fields['SMS_BACKEND'].default + # data['SMS_BACKEND'] = self.fields['SMS_BACKEND'].default return data class AlibabaSMSSettingSerializer(BaseSMSSettingSerializer): - SMS_BACKEND = serializers.ChoiceField(choices=BACKENDS.choices, default=BACKENDS.ALIBABA) ALIBABA_ACCESS_KEY_ID = serializers.CharField(max_length=256, required=True, label='AccessKeyId') ALIBABA_ACCESS_KEY_SECRET = serializers.CharField( max_length=256, required=False, label='AccessKeySecret', write_only=True) @@ -35,7 +38,6 @@ class AlibabaSMSSettingSerializer(BaseSMSSettingSerializer): class TencentSMSSettingSerializer(BaseSMSSettingSerializer): - SMS_BACKEND = serializers.ChoiceField(choices=BACKENDS.choices, default=BACKENDS.TENCENT) TENCENT_SECRET_ID = serializers.CharField(max_length=256, required=True, label='Secret id') TENCENT_SECRET_KEY = serializers.CharField(max_length=256, required=False, label='Secret key', write_only=True) TENCENT_SDKAPPID = serializers.CharField(max_length=256, required=True, label='SDK app id')