Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

perf: 轻应用修改名称和简介的长度限制 #7295 #7333

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ repos:
hooks:
- id: check-merge-conflict
- repo: https://github.com/psf/black
rev: stable
rev: 22.8.0
hooks:
- id: black
language_version: python3.6
Expand Down
18 changes: 18 additions & 0 deletions gcloud/contrib/appmaker/migrations/0012_auto_20240125_1119.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 3.2.15 on 2024-01-25 03:19

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
("appmaker", "0011_appmaker_new_category"),
]

operations = [
migrations.AlterField(
model_name="appmaker",
name="desc",
field=models.CharField(max_length=500, null=True, verbose_name="APP描述信息"),
),
]
24 changes: 7 additions & 17 deletions gcloud/contrib/appmaker/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,30 +17,20 @@
from django.db import models
from django.db.models import Count
from django.utils.translation import ugettext_lazy as _

from gcloud.utils import managermixins

from iam import Subject, Action
from iam import Action, Subject
from iam.shortcuts import allow_or_raise_auth_failed

from gcloud.conf import settings
from gcloud.core.api_adapter import (
create_maker_app,
edit_maker_app,
del_maker_app,
modify_app_logo,
get_app_logo_url,
)
from gcloud.constants import AE, TASK_CATEGORY
from gcloud.core.api_adapter import create_maker_app, del_maker_app, edit_maker_app, get_app_logo_url, modify_app_logo
from gcloud.core.models import Project
from gcloud.core.utils import convert_readable_username
from gcloud.iam_auth import IAMMeta, get_iam_client
from gcloud.tasktmpl3.models import TaskTemplate
from gcloud.utils import managermixins
from gcloud.utils.dates import time_now_str
from gcloud.core.utils import convert_readable_username
from gcloud.utils.strings import standardize_name

from gcloud.iam_auth import IAMMeta
from gcloud.iam_auth import get_iam_client

logger = logging.getLogger("root")
iam = get_iam_client()

Expand All @@ -62,7 +52,7 @@ def save_app_maker(self, project_id, app_params, fake=False):
app_id = None
template_id = app_params["template_id"]
app_params["name"] = standardize_name(app_params["name"], 20)
app_params["desc"] = standardize_name(app_params.get("desc", ""), 30)
app_params["desc"] = standardize_name(app_params.get("desc", ""), 500)
proj = Project.objects.get(id=project_id)
try:
task_template = TaskTemplate.objects.get(pk=template_id, project_id=project_id, is_deleted=False)
Expand Down Expand Up @@ -259,7 +249,7 @@ class AppMaker(models.Model):
name = models.CharField(_("APP名称"), max_length=255)
code = models.CharField(_("APP编码"), max_length=255)
info = models.CharField(_("APP基本信息"), max_length=255, null=True)
desc = models.CharField(_("APP描述信息"), max_length=255, null=True)
desc = models.CharField(_("APP描述信息"), max_length=500, null=True)
logo_url = models.TextField(_("轻应用logo存放地址"), default="", blank=True)
link = models.URLField(_("gcloud链接"), max_length=255)
creator = models.CharField(_("创建人"), max_length=100)
Expand Down
4 changes: 4 additions & 0 deletions gcloud/taskflow3/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -1061,6 +1061,10 @@ def change_parent_task_node_state_to_running(self):
parent_task.change_parent_task_node_state_to_running()

def task_action(self, action, username):
if self.is_deleted:
message = _(f"任务操作失败: 任务[ID: {self.id}]已被删除.请重新创建任务 | task_action")
logger.error(message)
return {"result": False, "message": message, "code": err_code.INVALID_OPERATION.code}
if self.current_flow != "execute_task":
return {
"result": False,
Expand Down
68 changes: 49 additions & 19 deletions pipeline_plugins/components/query/sites/open/cc.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,31 +14,26 @@
import logging
import traceback

from django.http import JsonResponse
from django.conf.urls import url

from django.http import JsonResponse
from django.utils.translation import ugettext_lazy as _
from iam.contrib.http import HTTP_AUTH_FORBIDDEN_CODE
from iam.exceptions import RawAuthFailedException

from api.utils.request import batch_request
from gcloud.conf import settings
from gcloud.core.utils import get_user_business_list
from gcloud.exceptions import APIError, ApiRequestError
from gcloud.iam_auth.utils import check_and_raise_raw_auth_fail_exception
from pipeline_plugins.base.utils.inject import (
supplier_account_inject,
supplier_id_inject,
)
from gcloud.utils.handlers import handle_api_error
from pipeline_plugins.base.utils.inject import supplier_account_inject, supplier_id_inject
from pipeline_plugins.cmdb_ip_picker.query import (
cmdb_search_host,
cmdb_search_topo_tree,
cmdb_get_mainline_object_topo,
cmdb_search_dynamic_group,
cmdb_search_host,
cmdb_search_topo_tree,
)

from gcloud.conf import settings
from gcloud.utils.handlers import handle_api_error
from gcloud.exceptions import APIError, ApiRequestError
from gcloud.core.utils import get_user_business_list
from pipeline_plugins.components.utils import batch_execute_func
from django.utils.translation import ugettext_lazy as _

logger = logging.getLogger("root")
get_client_by_user = settings.ESB_GET_CLIENT_BY_USER
Expand Down Expand Up @@ -247,15 +242,21 @@ def cc_list_service_template(request, biz_cc_id, supplier_account):
return JsonResponse({"result": True, "data": service_templates, "message": "success"})


def cc_format_topo_data(data, obj_id, category):
def cc_format_topo_data(data, obj_id, category, sets, modules):
"""
@summary: 格式化拓扑数据
@param obj_id set or module
@param category prev(获取obj_id上一层级拓扑) or normal (获取obj_id层级拓扑) or picker(ip选择器拓扑)
@param sets 可更新的集群id列表
@param modules 可更新的模块id列表
@return 拓扑数据列表
"""
tree_data = []
for item in data:
if item["bk_obj_id"] == "set" and item["bk_inst_id"] not in sets:
continue
if item["bk_obj_id"] == "module" and item["bk_inst_id"] not in modules:
continue
tree_item = {
"id": "%s_%s" % (item["bk_obj_id"], item["bk_inst_id"]),
"label": item["bk_inst_name"],
Expand All @@ -264,12 +265,12 @@ def cc_format_topo_data(data, obj_id, category):
if item["bk_obj_id"] != obj_id:
tree_data.append(tree_item)
if "child" in item:
tree_item["children"] = cc_format_topo_data(item["child"], obj_id, category)
tree_item["children"] = cc_format_topo_data(item["child"], obj_id, category, sets, modules)
else:
if item["bk_obj_id"] == obj_id:
tree_data.append(tree_item)
elif "child" in item:
tree_item["children"] = cc_format_topo_data(item["child"], obj_id, category)
tree_item["children"] = cc_format_topo_data(item["child"], obj_id, category, sets, modules)
tree_data.append(tree_item)

return tree_data
Expand Down Expand Up @@ -326,10 +327,11 @@ def cc_search_topo(request, obj_id, category, biz_cc_id, supplier_account):
cc_result["data"] = insert_inter_result_to_topo_data(inter_result["data"], cc_result["data"])

if category in ["normal", "prev"]:
cc_topo = cc_format_topo_data(cc_result["data"], obj_id, category)
modules = cc_search_modules(request, biz_cc_id, supplier_account)
sets = cc_search_sets(request, biz_cc_id, supplier_account)
cc_topo = cc_format_topo_data(cc_result["data"], obj_id, category, sets, modules)
else:
cc_topo = []

return JsonResponse({"result": True, "data": cc_topo})


Expand Down Expand Up @@ -539,6 +541,34 @@ def list_business_set(request):
return JsonResponse({"result": True, "data": business_set})


def cc_search_sets(request, biz_cc_id, supplier_account) -> dict:
client = get_client_by_user(request.user.username)
kwargs = {
"bk_biz_id": biz_cc_id,
"bk_supplier_account": supplier_account,
"fields": ["bk_set_id", "set_template_id"],
}
cc_result = client.cc.search_set(kwargs)
if not cc_result["result"]:
return {}
data = cc_result["data"]["info"]
sets = {item["bk_set_id"] for item in data if not item["set_template_id"]}
return sets


def cc_search_modules(request, biz_cc_id, supplier_account):
client = get_client_by_user(request.user.username)
kwargs = {
"bk_biz_id": biz_cc_id,
"bk_supplier_account": supplier_account,
"fields": ["service_template_id", "bk_module_id"],
}
cc_result = client.cc.search_module(kwargs)
data = cc_result["data"]["info"]
modules = {item["bk_module_id"] for item in data if not item["service_template_id"]}
return modules


cc_urlpatterns = [
url(r"^cc_get_editable_module_attribute/(?P<biz_cc_id>\d+)/$", cc_get_editable_module_attribute),
url(
Expand Down
Loading