2023-07-24 03:52:25 +00:00
|
|
|
from django.utils.translation import gettext_lazy as _
|
2021-09-09 06:00:50 +00:00
|
|
|
from rest_framework import serializers
|
|
|
|
|
2023-12-21 08:07:11 +00:00
|
|
|
from orgs.models import Organization
|
|
|
|
|
2021-09-09 06:00:50 +00:00
|
|
|
|
|
|
|
class BasicSettingSerializer(serializers.Serializer):
|
2022-11-04 06:22:38 +00:00
|
|
|
PREFIX_TITLE = _('Basic')
|
|
|
|
|
2021-09-09 06:00:50 +00:00
|
|
|
SITE_URL = serializers.URLField(
|
|
|
|
required=True, label=_("Site url"),
|
2023-08-24 02:58:27 +00:00
|
|
|
help_text=_(
|
|
|
|
'External URL, email links or other system callbacks are used to access it, '
|
|
|
|
'eg: http://dev.jumpserver.org:8080'
|
|
|
|
)
|
2021-09-09 06:00:50 +00:00
|
|
|
)
|
|
|
|
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')
|
|
|
|
)
|
|
|
|
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')
|
|
|
|
)
|
2023-08-15 05:45:44 +00:00
|
|
|
HELP_DOCUMENT_URL = serializers.URLField(
|
|
|
|
required=False, allow_blank=True, allow_null=True, label=_("Help Docs URL"),
|
|
|
|
help_text=_('default: http://docs.jumpserver.org')
|
|
|
|
)
|
|
|
|
HELP_SUPPORT_URL = serializers.URLField(
|
|
|
|
required=False, allow_blank=True, allow_null=True, label=_("Help Support URL"),
|
|
|
|
help_text=_('default: http://www.jumpserver.org/support/')
|
|
|
|
)
|
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('/')
|
2023-12-21 08:07:11 +00:00
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
def validate_GLOBAL_ORG_DISPLAY_NAME(s):
|
|
|
|
org_names = Organization.objects.values_list('name', flat=True)
|
|
|
|
if s in org_names:
|
|
|
|
raise serializers.ValidationError(_('Organization name already exists'))
|
|
|
|
return s
|