From c87a4baefb98685a91b055f7bfee18f8fa3c8062 Mon Sep 17 00:00:00 2001 From: guohelu <141622458+guohelu@users.noreply.github.com> Date: Fri, 29 Nov 2024 15:11:38 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=96=B0=E5=A2=9Eget=5Ftemplate=5Flist?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3=E6=94=AF=E6=8C=81=E6=A0=87=E7=AD=BE=E8=BF=87?= =?UTF-8?q?=E6=BB=A4=E8=83=BD=E5=8A=9B=20#7603=20(#7610)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * feat: 新增get_template_list接口支持标签过滤能力 #7603 * fix: 修复测试错误 #7603 * fix: 修复参数拼接错误 #7603 * fix: 修正获取参数 #7603 * fix: 修正参数命名问题 #7603 * fix: 修复返回协议问题 #7603 * fix: 修复测试问题 #7603 --- gcloud/apigw/views/get_template_list.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/gcloud/apigw/views/get_template_list.py b/gcloud/apigw/views/get_template_list.py index 654b35028a..6bbfe94e06 100644 --- a/gcloud/apigw/views/get_template_list.py +++ b/gcloud/apigw/views/get_template_list.py @@ -26,6 +26,7 @@ from gcloud.iam_auth.utils import get_flow_allowed_actions_for_user from gcloud.iam_auth.view_interceptors.apigw import ProjectViewInterceptor from apigw_manager.apigw.decorators import apigw_require +from gcloud.label.models import TemplateLabelRelation, Label @login_exempt @@ -40,6 +41,7 @@ def get_template_list(request, project_id): template_source = request.GET.get("template_source", PROJECT) id_in = request.GET.get("id_in", None) name_keyword = request.GET.get("name_keyword", None) + label_names = request.GET.get("label_names", None) if id_in: try: @@ -48,6 +50,19 @@ def get_template_list(request, project_id): id_in = None logger.exception("[API] id_in[{}] resolve fail, ignore.".format(id_in)) + if label_names: + try: + label_names = label_names.split(",") + label_ids = Label.objects.filter(name__in=label_names, project_id=project_id).values_list("id", flat=True) + template_ids = TemplateLabelRelation.objects.fetch_template_ids_using_labels(label_ids) + template_ids = list(map(str, template_ids)) + if id_in is None: + id_in = template_ids + else: + id_in = list(set(id_in + template_ids)) + except Exception: + logger.exception("[API] label_names[{}] resolve fail, ignore.".format(label_names)) + filter_kwargs = dict(is_deleted=False) if id_in: filter_kwargs["id__in"] = id_in @@ -72,4 +87,9 @@ def get_template_list(request, project_id): if allowed: template_info["auth_actions"].append(action) + if label_names: + templates_labels = TemplateLabelRelation.objects.fetch_templates_labels(template_id_list) + for obj in template_list: + obj["template_labels"] = templates_labels.get(obj["id"], []) + return {"result": True, "data": template_list, "code": err_code.SUCCESS.code}