2021-09-28 10:17:10 +00:00
|
|
|
import uuid
|
|
|
|
|
2021-09-09 06:00:50 +00:00
|
|
|
from django.utils.translation import ugettext_lazy as _
|
|
|
|
from rest_framework import serializers
|
|
|
|
|
|
|
|
|
2021-09-28 09:01:47 +00:00
|
|
|
class AnnouncementSerializer(serializers.Serializer):
|
2021-09-28 10:17:10 +00:00
|
|
|
ID = serializers.CharField(required=False, allow_blank=True, allow_null=True)
|
2021-09-28 09:01:47 +00:00
|
|
|
SUBJECT = serializers.CharField(required=True, max_length=1024, label=_("Subject"))
|
|
|
|
CONTENT = serializers.CharField(label=_("Content"))
|
|
|
|
LINK = serializers.URLField(
|
|
|
|
required=False, allow_null=True, allow_blank=True,
|
|
|
|
label=_("More url"), default='',
|
|
|
|
)
|
|
|
|
|
|
|
|
def to_representation(self, instance):
|
2021-09-28 10:17:10 +00:00
|
|
|
defaults = {'ID': '', 'SUBJECT': '', 'CONTENT': '', 'LINK': '', 'ENABLED': False}
|
2021-09-28 09:01:47 +00:00
|
|
|
data = {**defaults, **instance}
|
|
|
|
return super().to_representation(data)
|
|
|
|
|
2021-09-28 10:17:10 +00:00
|
|
|
def to_internal_value(self, data):
|
|
|
|
data['ID'] = str(uuid.uuid4())
|
|
|
|
return super().to_internal_value(data)
|
|
|
|
|
2021-09-28 09:01:47 +00:00
|
|
|
|
2021-09-09 06:00:50 +00:00
|
|
|
class BasicSettingSerializer(serializers.Serializer):
|
|
|
|
SITE_URL = serializers.URLField(
|
|
|
|
required=True, label=_("Site url"),
|
|
|
|
help_text=_('eg: http://dev.jumpserver.org:8080')
|
|
|
|
)
|
|
|
|
USER_GUIDE_URL = serializers.URLField(
|
|
|
|
required=False, allow_blank=True, allow_null=True, label=_("User guide url"),
|
|
|
|
help_text=_('User first login update profile done redirect to it')
|
|
|
|
)
|
|
|
|
FORGOT_PASSWORD_URL = serializers.URLField(
|
|
|
|
required=False, allow_blank=True, allow_null=True, label=_("Forgot password url"),
|
|
|
|
help_text=_('The forgot password url on login page, If you use '
|
|
|
|
'ldap or cas external authentication, you can set it')
|
|
|
|
)
|
|
|
|
GLOBAL_ORG_DISPLAY_NAME = serializers.CharField(
|
|
|
|
required=False, max_length=1024, allow_blank=True, allow_null=True, label=_("Global organization name"),
|
|
|
|
help_text=_('The name of global organization to display')
|
|
|
|
)
|
2021-09-28 09:01:47 +00:00
|
|
|
TICKETS_ENABLED = serializers.BooleanField(required=False, default=True, label=_("Enable tickets"))
|
2021-09-28 10:57:21 +00:00
|
|
|
ANNOUNCEMENT_ENABLED = serializers.BooleanField(label=_('Enable announcement'), default=True)
|
2021-09-28 09:01:47 +00:00
|
|
|
ANNOUNCEMENT = AnnouncementSerializer(label=_("Announcement"))
|
2021-12-15 10:44:51 +00:00
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
def validate_SITE_URL(s):
|
|
|
|
if not s:
|
|
|
|
return 'http://127.0.0.1'
|
|
|
|
return s.strip('/')
|
|
|
|
|