F 修复某些情况下删除条件检查未生效的问题

pull/220/head
vapao 2020-09-24 16:22:56 +08:00
parent dd6d76bd12
commit dc1975c52c
2 changed files with 4 additions and 4 deletions

View File

@ -40,7 +40,7 @@ class GroupView(View):
Argument('id', type=int, help='请指定操作对象') Argument('id', type=int, help='请指定操作对象')
).parse(request.GET) ).parse(request.GET)
if error is None: if error is None:
detection = Detection.objects.filter(notify_grp__regex=fr'\D{form.id}\D').first() detection = Detection.objects.filter(notify_grp__regex=fr'[^0-9]{form.id}[^0-9]').first()
if detection: if detection:
return json_response(error=f'监控任务【{detection.name}】正在使用该报警组,请解除关联后再尝试删除该联系组') return json_response(error=f'监控任务【{detection.name}】正在使用该报警组,请解除关联后再尝试删除该联系组')
Group.objects.filter(pk=form.id).delete() Group.objects.filter(pk=form.id).delete()

View File

@ -75,19 +75,19 @@ class HostView(View):
Argument('id', type=int, help='请指定操作对象') Argument('id', type=int, help='请指定操作对象')
).parse(request.GET) ).parse(request.GET)
if error is None: if error is None:
deploy = Deploy.objects.filter(host_ids__regex=fr'\D{form.id}\D').annotate( deploy = Deploy.objects.filter(host_ids__regex=fr'[^0-9]{form.id}[^0-9]').annotate(
app_name=F('app__name'), app_name=F('app__name'),
env_name=F('env__name') env_name=F('env__name')
).first() ).first()
if deploy: if deploy:
return json_response(error=f'应用【{deploy.app_name}】在【{deploy.env_name}】的发布配置关联了该主机,请解除关联后再尝试删除该主机') return json_response(error=f'应用【{deploy.app_name}】在【{deploy.env_name}】的发布配置关联了该主机,请解除关联后再尝试删除该主机')
task = Task.objects.filter(targets__regex=fr'\D{form.id}\D').first() task = Task.objects.filter(targets__regex=fr'[^0-9]{form.id}[^0-9]').first()
if task: if task:
return json_response(error=f'任务计划中的任务【{task.name}】关联了该主机,请解除关联后再尝试删除该主机') return json_response(error=f'任务计划中的任务【{task.name}】关联了该主机,请解除关联后再尝试删除该主机')
detection = Detection.objects.filter(type__in=('3', '4'), addr=form.id).first() detection = Detection.objects.filter(type__in=('3', '4'), addr=form.id).first()
if detection: if detection:
return json_response(error=f'监控中心的任务【{detection.name}】关联了该主机,请解除关联后再尝试删除该主机') return json_response(error=f'监控中心的任务【{detection.name}】关联了该主机,请解除关联后再尝试删除该主机')
role = Role.objects.filter(host_perms__regex=fr'\D{form.id}\D').first() role = Role.objects.filter(host_perms__regex=fr'[^0-9]{form.id}[^0-9]').first()
if role: if role:
return json_response(error=f'角色【{role.name}】的主机权限关联了该主机,请解除关联后再尝试删除该主机') return json_response(error=f'角色【{role.name}】的主机权限关联了该主机,请解除关联后再尝试删除该主机')
Host.objects.filter(pk=form.id).update( Host.objects.filter(pk=form.id).update(