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

fix: 模板市场导入业务优化 --story=121432122 #7662

Merged
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
7 changes: 5 additions & 2 deletions gcloud/apigw/validators/copy_template_across_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,10 @@ def validate(self, request, *args, **kwargs):
return valid, err

data = json.loads(request.body)
if not data.get("new_project_id") or not data.get("template_id"):
return False, "new_project_id and template_id are required"
if not data.get("new_project_id") or not data.get("template_ids"):
return False, "new_project_id and template_ids are required"

if data.get("new_project_id") == request.project.id:
return False, "无法导入流程到到同一个项目"

return True, ""
12 changes: 10 additions & 2 deletions gcloud/apigw/views/copy_template_across_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
from gcloud.iam_auth.view_interceptors.apigw import CopyTemplateInterceptor
from gcloud.apigw.validators.copy_template_across_project import CopyTemplateAcrossProjectValidator

TEMPLATE_COPY_MAX_NUMBER = 10


@login_exempt
@csrf_exempt
Expand All @@ -51,10 +53,16 @@ def copy_template_across_project(request, project_id):

params_data = json.loads(request.body)
new_project_id = params_data["new_project_id"]
template_id = params_data["template_id"]
template_ids = params_data["template_ids"]

try:
export_data = TaskTemplate.objects.export_templates([template_id], is_full=False, project_id=request.project.id)
export_data = TaskTemplate.objects.export_templates(template_ids, is_full=False, project_id=request.project.id)
if len(export_data["template"]) > TEMPLATE_COPY_MAX_NUMBER:
return {
"result": False,
"message": "only {} templates can be copied once.".format(TEMPLATE_COPY_MAX_NUMBER),
"code": err_code.INVALID_OPERATION.code,
}
import_result = TaskTemplate.objects.import_templates(
template_data=export_data,
override=False,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,16 @@ class CopyTemplateInterceptor(ViewInterceptor):
def process(self, request, *args, **kwargs):
data = json.loads(request.body)
new_project_id = data.get("new_project_id")
template_id = data.get("template_id")
template_ids = data.get("template_ids")
subject = Subject("user", request.user.username)

record = TemplateSharedRecord.objects.filter(project_id=request.project.id, template_id=template_id).first()
if record is None:
error_message = f"Unable to find template {template_id} in project {request.project.id}."
existing_records = TemplateSharedRecord.objects.filter(
project_id=request.project.id, template_id__in=template_ids
).values_list("template_id", flat=True)

missing_template_ids = set(template_ids) - set(existing_records)
if missing_template_ids:
error_message = f"The following templates are not shared {missing_template_ids}"
logging.error(error_message)
raise ValueError(error_message)

Expand Down
Loading