From db4f05afbe9475793b9c26395994627f98c7faa9 Mon Sep 17 00:00:00 2001 From: jiangweidong Date: Mon, 14 Aug 2023 11:07:28 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E8=A7=A3=E5=86=B3=E7=B1=BB=E5=9E=8B?= =?UTF-8?q?=E6=A0=91=E5=B1=95=E5=BC=80=E5=85=A8=E9=83=A8=E6=97=B6=EF=BC=8C?= =?UTF-8?q?=E6=A0=B9=E8=8A=82=E7=82=B9=E6=97=A0=E9=99=90=E9=80=92=E5=BD=92?= =?UTF-8?q?=E5=B1=95=E5=BC=80=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/assets/const/types.py | 6 +++--- apps/perms/api/user_permission/tree/node_with_asset.py | 4 +++- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/apps/assets/const/types.py b/apps/assets/const/types.py index afa0f6d05..8654002b9 100644 --- a/apps/assets/const/types.py +++ b/apps/assets/const/types.py @@ -224,7 +224,7 @@ class AllTypes(ChoicesMixin): return dict(id='ROOT', name=_('All types'), title=_('All types'), open=True, isParent=True) @classmethod - def get_tree_nodes(cls, resource_platforms, include_asset=False): + def get_tree_nodes(cls, resource_platforms, include_asset=False, get_root=True): from ..models import Platform platform_count = defaultdict(int) for platform_id in resource_platforms: @@ -239,10 +239,10 @@ class AllTypes(ChoicesMixin): category_type_mapper[p.category] += platform_count[p.id] tp_platforms[p.category + '_' + p.type].append(p) - nodes = [cls.get_root_nodes()] + nodes = [cls.get_root_nodes()] if get_root else [] for category, type_cls in cls.category_types(): # Category 格式化 - meta = {'type': 'category', 'category': category.value} + meta = {'type': 'category', 'category': category.value, '_type': category.value} category_node = cls.choice_to_node(category, 'ROOT', meta=meta) category_count = category_type_mapper.get(category, 0) category_node['name'] += f'({category_count})' diff --git a/apps/perms/api/user_permission/tree/node_with_asset.py b/apps/perms/api/user_permission/tree/node_with_asset.py index 72080247a..d67eda467 100644 --- a/apps/perms/api/user_permission/tree/node_with_asset.py +++ b/apps/perms/api/user_permission/tree/node_with_asset.py @@ -177,8 +177,10 @@ class UserPermedNodeChildrenWithAssetsAsCategoryTreeApi( return [] pid = f'ROOT_{str(assets[0].category).upper()}_{tp}' return self.serialize_assets(assets, pid=pid) + params = self.request.query_params + get_root = not list(filter(lambda x: params.get(x), ('type', 'n'))) resource_platforms = assets.order_by('id').values_list('platform_id', flat=True) - node_all = AllTypes.get_tree_nodes(resource_platforms) + node_all = AllTypes.get_tree_nodes(resource_platforms, get_root=get_root) pattern = re.compile(r'\(0\)?') nodes = [] for node in node_all: