Skip to content

Commit

Permalink
fix: 导入业务优化 --story=121224121
Browse files Browse the repository at this point in the history
  • Loading branch information
guohelu committed Jan 2, 2025
1 parent 156d014 commit 5354ee4
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 8 deletions.
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, ""
4 changes: 2 additions & 2 deletions gcloud/apigw/views/copy_template_across_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,10 @@ 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)
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

0 comments on commit 5354ee4

Please sign in to comment.