mirror of https://github.com/jumpserver/jumpserver
Merge branch 'v3' of github.com:jumpserver/jumpserver into v3
commit
e2001d7779
|
@ -4,7 +4,7 @@ import six
|
|||
from django.core.exceptions import ObjectDoesNotExist
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
from rest_framework import serializers
|
||||
from rest_framework.fields import ChoiceField
|
||||
from rest_framework.fields import ChoiceField, empty
|
||||
|
||||
from common.db.fields import BitChoices
|
||||
from common.utils import decrypt_password
|
||||
|
@ -153,3 +153,17 @@ class BitChoicesField(TreeChoicesMixin, serializers.MultipleChoiceField):
|
|||
raise serializers.ValidationError(_("Invalid choice: {}").format(name))
|
||||
value |= name_value_map[name]
|
||||
return value
|
||||
|
||||
def run_validation(self, data=empty):
|
||||
"""
|
||||
备注:
|
||||
创建授权规则不包含 actions 字段时, 会使用默认值(AssetPermission 中设置),
|
||||
会直接使用 ['connect', '...'] 等字段保存到数据库,导致类型错误
|
||||
这里将获取到的值再执行一下 to_internal_value 方法, 转化为内部值
|
||||
"""
|
||||
data = super().run_validation(data)
|
||||
if isinstance(data, int):
|
||||
return data
|
||||
value = self.to_internal_value(data)
|
||||
self.run_validators(value)
|
||||
return value
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
def bit(x):
|
||||
if x == 0:
|
||||
return 0
|
||||
else:
|
||||
return 2 ** (x - 1)
|
||||
if x < 1:
|
||||
raise ValueError("x must be greater than 1")
|
||||
return 2 ** (x - 1)
|
||||
|
|
|
@ -10,11 +10,11 @@ __all__ = ["ActionChoices"]
|
|||
|
||||
|
||||
class ActionChoices(BitChoices):
|
||||
connect = bit(0), _("Connect")
|
||||
upload = bit(1), _("Upload")
|
||||
download = bit(2), _("Download")
|
||||
copy = bit(3), _("Copy")
|
||||
paste = bit(4), _("Paste")
|
||||
connect = bit(1), _("Connect")
|
||||
upload = bit(2), _("Upload")
|
||||
download = bit(3), _("Download")
|
||||
copy = bit(4), _("Copy")
|
||||
paste = bit(5), _("Paste")
|
||||
|
||||
@classmethod
|
||||
def is_tree(cls):
|
||||
|
|
Loading…
Reference in New Issue