diff --git a/apps/common/drf/fields.py b/apps/common/drf/fields.py index 9f2527d8a..c666d9b76 100644 --- a/apps/common/drf/fields.py +++ b/apps/common/drf/fields.py @@ -120,6 +120,13 @@ class BitChoicesField(TreeChoicesMixin, serializers.MultipleChoiceField): super().__init__(choices=choices, **kwargs) def to_representation(self, value): + if isinstance(value, list) and len(value) == 1: + # Swagger 会使用 field.choices.keys() 迭代传递进来 + return [ + {"value": c.name, "label": c.label} + for c in self._choice_cls + if c.name == value[0] + ] return [ {"value": c.name, "label": c.label} for c in self._choice_cls diff --git a/apps/perms/serializers/permission.py b/apps/perms/serializers/permission.py index 9a31058f6..fc2bf1cf3 100644 --- a/apps/perms/serializers/permission.py +++ b/apps/perms/serializers/permission.py @@ -16,7 +16,7 @@ __all__ = ["AssetPermissionSerializer", "ActionChoicesField"] class ActionChoicesField(BitChoicesField): def __init__(self, **kwargs): - super().__init__(ActionChoices, **kwargs) + super().__init__(choice_cls=ActionChoices, **kwargs) class AssetPermissionSerializer(BulkOrgResourceModelSerializer): diff --git a/apps/perms/urls/asset_permission.py b/apps/perms/urls/asset_permission.py index f402372df..cdf502c0f 100644 --- a/apps/perms/urls/asset_permission.py +++ b/apps/perms/urls/asset_permission.py @@ -65,12 +65,15 @@ user_permission_urlpatterns = [ # 收藏的资产 path('/nodes/favorite/assets/', api.UserFavoriteGrantedAssetsApi.as_view(), name='user-ungrouped-assets'), - path('nodes/favorite/assets/', api.MyFavoriteGrantedAssetsApi.as_view(), name='my-ungrouped-assets'), + path('nodes/favorite/assets/', api.MyFavoriteGrantedAssetsApi.as_view(), + name='my-ungrouped-assets'), # 获取授权给用户某个资产的所有账号 path('/assets//accounts/', api.UserGrantedAssetAccountsApi.as_view(), name='user-asset-accounts'), - path('assets//accounts/', api.MyGrantedAssetAccountsApi.as_view(), name='my-asset-accounts'), + path('/((?P[^/.]+)/)?assets//accounts/', + api.UserGrantedAssetAccountsApi.as_view(), + name='my-asset-accounts'), ] user_group_permission_urlpatterns = [