2019-12-05 07:09:25 +00:00
|
|
|
# coding: utf-8
|
2022-05-20 02:01:41 +00:00
|
|
|
#
|
2024-01-02 09:00:15 +00:00
|
|
|
from django.db import models
|
2023-07-24 03:52:25 +00:00
|
|
|
from django.utils.translation import gettext_lazy as _
|
2019-12-05 07:09:25 +00:00
|
|
|
from rest_framework import serializers
|
|
|
|
|
2023-01-16 11:02:09 +00:00
|
|
|
from common.serializers.fields import EncryptedField
|
2022-05-20 02:01:41 +00:00
|
|
|
|
2024-01-02 09:00:15 +00:00
|
|
|
|
2023-08-15 05:45:44 +00:00
|
|
|
__all__ = [
|
|
|
|
'MailTestSerializer', 'EmailSettingSerializer',
|
|
|
|
'EmailContentSettingSerializer', 'SMSBackendSerializer',
|
|
|
|
]
|
2019-12-05 07:09:25 +00:00
|
|
|
|
|
|
|
|
|
|
|
class MailTestSerializer(serializers.Serializer):
|
2022-11-14 08:19:00 +00:00
|
|
|
EMAIL_FROM = serializers.CharField(required=False, allow_null=True, allow_blank=True)
|
|
|
|
EMAIL_RECIPIENT = serializers.CharField(required=False, allow_null=True, allow_blank=True)
|
2021-09-09 06:00:50 +00:00
|
|
|
|
|
|
|
|
|
|
|
class EmailSettingSerializer(serializers.Serializer):
|
2022-11-04 06:22:38 +00:00
|
|
|
PREFIX_TITLE = _('Email')
|
2021-09-09 06:00:50 +00:00
|
|
|
|
2024-01-02 09:00:15 +00:00
|
|
|
class EmailProtocol(models.TextChoices):
|
|
|
|
smtp = 'smtp', _('SMTP')
|
|
|
|
exchange = 'exchange', _('EXCHANGE')
|
|
|
|
|
|
|
|
EMAIL_PROTOCOL = serializers.ChoiceField(
|
|
|
|
choices=EmailProtocol.choices, label=_("Protocol"), default=EmailProtocol.smtp
|
|
|
|
)
|
|
|
|
EMAIL_HOST = serializers.CharField(max_length=1024, required=True, label=_("Host"))
|
|
|
|
EMAIL_PORT = serializers.CharField(max_length=5, required=True, label=_("Port"))
|
|
|
|
EMAIL_HOST_USER = serializers.CharField(max_length=128, required=True, label=_("Account"))
|
2022-05-20 02:01:41 +00:00
|
|
|
EMAIL_HOST_PASSWORD = EncryptedField(
|
2024-01-02 09:00:15 +00:00
|
|
|
max_length=1024, required=False, label=_("Password"),
|
2021-09-09 06:00:50 +00:00
|
|
|
help_text=_("Tips: Some provider use token except password")
|
|
|
|
)
|
|
|
|
EMAIL_FROM = serializers.CharField(
|
|
|
|
max_length=128, allow_blank=True, required=False, label=_('Send user'),
|
|
|
|
help_text=_('Tips: Send mail account, default SMTP account as the send account')
|
|
|
|
)
|
|
|
|
EMAIL_RECIPIENT = serializers.CharField(
|
|
|
|
max_length=128, allow_blank=True, required=False, label=_('Test recipient'),
|
|
|
|
help_text=_('Tips: Used only as a test mail recipient')
|
|
|
|
)
|
|
|
|
EMAIL_USE_SSL = serializers.BooleanField(
|
|
|
|
required=False, label=_('Use SSL'),
|
|
|
|
help_text=_('If SMTP port is 465, may be select')
|
|
|
|
)
|
|
|
|
EMAIL_USE_TLS = serializers.BooleanField(
|
|
|
|
required=False, label=_("Use TLS"),
|
|
|
|
help_text=_('If SMTP port is 587, may be select')
|
|
|
|
)
|
|
|
|
EMAIL_SUBJECT_PREFIX = serializers.CharField(
|
|
|
|
max_length=1024, required=True, label=_('Subject prefix')
|
|
|
|
)
|
2023-08-14 11:40:21 +00:00
|
|
|
EMAIL_SUFFIX = serializers.CharField(
|
|
|
|
required=False, max_length=1024, label=_("Email suffix"),
|
|
|
|
help_text=_('This is used by default if no email is returned during SSO authentication')
|
|
|
|
)
|
2021-09-09 06:00:50 +00:00
|
|
|
|
|
|
|
|
|
|
|
class EmailContentSettingSerializer(serializers.Serializer):
|
2022-11-04 06:22:38 +00:00
|
|
|
PREFIX_TITLE = _('Email')
|
|
|
|
|
2021-09-09 06:00:50 +00:00
|
|
|
EMAIL_CUSTOM_USER_CREATED_SUBJECT = serializers.CharField(
|
|
|
|
max_length=1024, allow_blank=True, required=False,
|
|
|
|
label=_('Create user email subject'),
|
|
|
|
help_text=_('Tips: When creating a user, send the subject of the email (eg:Create account successfully)')
|
|
|
|
)
|
|
|
|
EMAIL_CUSTOM_USER_CREATED_HONORIFIC = serializers.CharField(
|
|
|
|
max_length=1024, allow_blank=True, required=False,
|
|
|
|
label=_('Create user honorific'),
|
|
|
|
help_text=_('Tips: When creating a user, send the honorific of the email (eg:Hello)')
|
|
|
|
)
|
|
|
|
EMAIL_CUSTOM_USER_CREATED_BODY = serializers.CharField(
|
|
|
|
max_length=4096, allow_blank=True, required=False,
|
|
|
|
label=_('Create user email content'),
|
2023-01-16 11:02:09 +00:00
|
|
|
help_text=_(
|
|
|
|
'Tips: When creating a user, send the content of the email, support {username} {name} {email} label')
|
2021-09-09 06:00:50 +00:00
|
|
|
)
|
|
|
|
EMAIL_CUSTOM_USER_CREATED_SIGNATURE = serializers.CharField(
|
|
|
|
max_length=512, allow_blank=True, required=False, label=_('Signature'),
|
|
|
|
help_text=_('Tips: Email signature (eg:jumpserver)')
|
|
|
|
)
|
2023-08-15 05:45:44 +00:00
|
|
|
|
|
|
|
|
|
|
|
class SMSBackendSerializer(serializers.Serializer):
|
|
|
|
name = serializers.CharField(max_length=256, required=True, label=_('Name'))
|
|
|
|
label = serializers.CharField(max_length=256, required=True, label=_('Label'))
|