mirror of
https://github.com/jumpserver/jumpserver.git
synced 2025-12-16 17:12:53 +00:00
Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
6f8da63117 |
@@ -81,7 +81,7 @@ class AccountAssetSerializer(serializers.ModelSerializer):
|
||||
|
||||
def to_internal_value(self, data):
|
||||
if isinstance(data, dict):
|
||||
i = data.get('id') or data.get('pk')
|
||||
i = data.get('id')
|
||||
else:
|
||||
i = data
|
||||
|
||||
|
||||
@@ -71,8 +71,7 @@ class AssetAccountSerializer(
|
||||
template = serializers.BooleanField(
|
||||
default=False, label=_("Template"), write_only=True
|
||||
)
|
||||
name = serializers.CharField(max_length=128, required=False, label=_("Name"))
|
||||
secret_type = serializers.CharField(max_length=64, default='password', label=_("Secret type"))
|
||||
name = serializers.CharField(max_length=128, required=True, label=_("Name"))
|
||||
|
||||
class Meta:
|
||||
model = Account
|
||||
|
||||
@@ -9,7 +9,8 @@ from django.conf import settings
|
||||
from django.contrib import auth
|
||||
from django.contrib.auth import (
|
||||
BACKEND_SESSION_KEY, load_backend,
|
||||
PermissionDenied, user_login_failed, _clean_credentials,
|
||||
PermissionDenied, user_login_failed,
|
||||
_clean_credentials,
|
||||
)
|
||||
from django.core.cache import cache
|
||||
from django.core.exceptions import ImproperlyConfigured
|
||||
|
||||
@@ -111,7 +111,7 @@ class BaseFileParser(BaseParser):
|
||||
return {'pk': obj_id, 'name': obj_name}
|
||||
|
||||
def parse_value(self, field, value):
|
||||
if value == '-' and field and field.allow_null:
|
||||
if value is '-':
|
||||
return None
|
||||
elif hasattr(field, 'to_file_internal_value'):
|
||||
value = field.to_file_internal_value(value)
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
#
|
||||
import phonenumbers
|
||||
from django.core.exceptions import ObjectDoesNotExist
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
from rest_framework import serializers
|
||||
@@ -18,7 +17,6 @@ __all__ = [
|
||||
"BitChoicesField",
|
||||
"TreeChoicesField",
|
||||
"LabeledMultipleChoiceField",
|
||||
"PhoneField",
|
||||
]
|
||||
|
||||
|
||||
@@ -203,11 +201,3 @@ class BitChoicesField(TreeChoicesField):
|
||||
value = self.to_internal_value(data)
|
||||
self.run_validators(value)
|
||||
return value
|
||||
|
||||
|
||||
class PhoneField(serializers.CharField):
|
||||
def to_representation(self, value):
|
||||
if value:
|
||||
phone = phonenumbers.parse(value, 'CN')
|
||||
value = {'code': '+%s' % phone.country_code, 'phone': phone.national_number}
|
||||
return value
|
||||
|
||||
@@ -2,15 +2,12 @@
|
||||
#
|
||||
import re
|
||||
|
||||
import phonenumbers
|
||||
|
||||
from django.core.validators import RegexValidator
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
from rest_framework.validators import (
|
||||
UniqueTogetherValidator, ValidationError
|
||||
)
|
||||
from rest_framework import serializers
|
||||
from phonenumbers.phonenumberutil import NumberParseException
|
||||
|
||||
from common.utils.strings import no_special_chars
|
||||
|
||||
@@ -45,14 +42,9 @@ class NoSpecialChars:
|
||||
|
||||
|
||||
class PhoneValidator:
|
||||
pattern = re.compile(r"^1[3456789]\d{9}$")
|
||||
message = _('The mobile phone number format is incorrect')
|
||||
|
||||
def __call__(self, value):
|
||||
try:
|
||||
phone = phonenumbers.parse(value, 'CN')
|
||||
valid = phonenumbers.is_valid_number(phone)
|
||||
except NumberParseException:
|
||||
valid = False
|
||||
|
||||
if not valid:
|
||||
if not self.pattern.match(value):
|
||||
raise serializers.ValidationError(self.message)
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
#
|
||||
from django.db.models import Q
|
||||
|
||||
from django.db.models import Q, QuerySet
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
from rest_framework import serializers
|
||||
|
||||
@@ -118,10 +119,7 @@ class AssetPermissionSerializer(BulkOrgResourceModelSerializer):
|
||||
return
|
||||
assets = self.get_all_assets(nodes, assets)
|
||||
accounts = self.create_accounts(assets)
|
||||
account_ids = [str(account.id) for account in accounts]
|
||||
slice_count = 20
|
||||
for i in range(0, len(account_ids), slice_count):
|
||||
push_accounts_to_assets_task.delay(account_ids[i:i + slice_count])
|
||||
push_accounts_to_assets_task.delay([str(account.id) for account in accounts])
|
||||
|
||||
def validate_accounts(self, usernames: list[str]):
|
||||
template_ids = []
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
from celery import shared_task
|
||||
from django.conf import settings
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
from django.db import transaction
|
||||
|
||||
from common.utils import get_logger
|
||||
from ops.celery.decorator import after_app_ready_start
|
||||
from ops.celery.utils import (
|
||||
@@ -22,7 +22,6 @@ def sync_ldap_user():
|
||||
|
||||
|
||||
@shared_task(verbose_name=_('Import ldap user'))
|
||||
@transaction.atomic
|
||||
def import_ldap_user():
|
||||
logger.info("Start import ldap user task")
|
||||
util_server = LDAPServerUtil()
|
||||
|
||||
@@ -1,16 +1,12 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
#
|
||||
import phonenumbers
|
||||
|
||||
from functools import partial
|
||||
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
from rest_framework import serializers
|
||||
|
||||
from common.serializers import CommonBulkSerializerMixin
|
||||
from common.serializers.fields import (
|
||||
EncryptedField, ObjectRelatedField, LabeledChoiceField, PhoneField
|
||||
)
|
||||
from common.serializers.fields import EncryptedField, ObjectRelatedField, LabeledChoiceField
|
||||
from common.utils import pretty_string, get_logger
|
||||
from common.validators import PhoneValidator
|
||||
from rbac.builtin import BuiltinRole
|
||||
@@ -105,9 +101,6 @@ class UserSerializer(RolesSerializerMixin, CommonBulkSerializerMixin, serializer
|
||||
label=_("Password"), required=False, allow_blank=True,
|
||||
allow_null=True, max_length=1024,
|
||||
)
|
||||
phone = PhoneField(
|
||||
validators=[PhoneValidator()], required=False, allow_blank=True, allow_null=True, label=_("Phone")
|
||||
)
|
||||
custom_m2m_fields = {
|
||||
"system_roles": [BuiltinRole.system_user],
|
||||
"org_roles": [BuiltinRole.org_user],
|
||||
@@ -174,6 +167,7 @@ class UserSerializer(RolesSerializerMixin, CommonBulkSerializerMixin, serializer
|
||||
"created_by": {"read_only": True, "allow_blank": True},
|
||||
"role": {"default": "User"},
|
||||
"is_otp_secret_key_bound": {"label": _("Is OTP bound")},
|
||||
"phone": {"validators": [PhoneValidator()]},
|
||||
'mfa_level': {'label': _("MFA level")},
|
||||
}
|
||||
|
||||
|
||||
@@ -29,7 +29,6 @@ pycparser==2.21
|
||||
cryptography==38.0.4
|
||||
pycryptodome==3.15.0
|
||||
pycryptodomex==3.15.0
|
||||
phonenumbers==8.13.8
|
||||
gmssl==3.2.1
|
||||
itsdangerous==1.1.0
|
||||
pyotp==2.6.0
|
||||
|
||||
Reference in New Issue
Block a user