From e8f68eb6c190b25551c79a9f00525d4055dc4e98 Mon Sep 17 00:00:00 2001 From: BaiJiangJie <32935519+BaiJiangJie@users.noreply.github.com> Date: Sat, 6 Jul 2019 14:02:56 +0800 Subject: [PATCH] =?UTF-8?q?[Update]=20=E8=A7=A3=E5=86=B3=E6=8E=88=E6=9D=83?= =?UTF-8?q?=E8=A7=84=E5=88=99actions=E5=AD=97=E6=AE=B5=E4=B8=BA=E7=A9=BA?= =?UTF-8?q?=E5=88=97=E8=A1=A8=E6=88=96=E5=8F=AA=E5=A1=AB=E4=B8=80=E4=B8=AA?= =?UTF-8?q?action=E7=9A=84=E9=97=AE=E9=A2=98=20(#2888)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * [Update] 解决授权规则actions字段为空列表或只填一个action的问题 * [Update] Action NO改为NULL * [Update] Action NULL改为NONE --- apps/perms/models/asset_permission.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/apps/perms/models/asset_permission.py b/apps/perms/models/asset_permission.py index 296e0e5d4..53bceb392 100644 --- a/apps/perms/models/asset_permission.py +++ b/apps/perms/models/asset_permission.py @@ -16,6 +16,7 @@ __all__ = [ class Action: + NONE = 0 CONNECT = 0b00000001 UPLOAD = 0b00000010 DOWNLOAD = 0b00000100 @@ -51,12 +52,15 @@ class Action: @classmethod def choices_to_value(cls, value): - def to_choices(x, y): - x = cls.NAME_MAP_REVERSE.get(x, 0) - y = cls.NAME_MAP_REVERSE.get(y, 0) - return x | y if not value: - return None + return cls.NONE + if len(value) == 1: + return cls.NAME_MAP_REVERSE.get(value[0], cls.NONE) + + def to_choices(x, y): + x = cls.NAME_MAP_REVERSE.get(x, cls.NONE) + y = cls.NAME_MAP_REVERSE.get(y, cls.NONE) + return x | y return reduce(to_choices, value) @classmethod