U 优化服务删除逻辑

pull/418/head
vapao 2021-12-02 09:29:28 +08:00
parent 6a9f9629f7
commit eb68491043
4 changed files with 15 additions and 7 deletions

View File

@ -4,7 +4,7 @@
from django.views.generic import View
from django.db.models import F
from libs import json_response, JsonParser, Argument, auth
from apps.app.models import Deploy
from apps.app.models import Deploy, App
from apps.config.models import *
import json
import re
@ -111,8 +111,16 @@ class ServiceView(View):
Argument('id', type=int, help='请指定操作对象')
).parse(request.GET)
if error is None:
if Config.objects.filter(type='src', o_id=form.id).exists():
return json_response(error='该服务已存在关联的配置信息,请删除相关配置后再尝试删除')
rel_apps = []
for app in App.objects.filter(rel_services__isnull=False):
rel_services = json.loads(app.rel_services)
if form.id in rel_services:
rel_apps.append(app.name)
if rel_apps:
return json_response(error=f'该服务在配置中心已被 "{", ".join(rel_apps)}" 依赖,请解除依赖关系后再尝试删除。')
# auto delete configs
Config.objects.filter(type='src', o_id=form.id).delete()
ConfigHistory.objects.filter(type='src', o_id=form.id).delete()
Service.objects.filter(pk=form.id).delete()
return json_response(error=error)

View File

@ -70,9 +70,9 @@ class ComTable extends React.Component {
<Table.Column width={210} title="操作" render={info => (
<Action>
<Action.Button auth="config.app.edit" onClick={() => store.showForm(info)}>编辑</Action.Button>
<Action.Button auth="config.app.del" onClick={() => this.handleDelete(info)}>删除</Action.Button>
<Action.Button auth="config.app.view_config" onClick={() => store.showRel(info)}>依赖</Action.Button>
<Action.Button auth="config.app.view_config" onClick={() => this.toConfig(info)}>配置</Action.Button>
<Action.Button danger auth="config.app.del" onClick={() => this.handleDelete(info)}>删除</Action.Button>
</Action>
)}/>
)}

View File

@ -76,7 +76,7 @@ function ComTable() {
<Table.Column title="操作" render={info => (
<Action>
<Action.Button auth="config.env.edit" onClick={() => store.showForm(info)}>编辑</Action.Button>
<Action.Button auth="config.env.del" onClick={() => handleDelete(info)}>删除</Action.Button>
<Action.Button danger auth="config.env.del" onClick={() => handleDelete(info)}>删除</Action.Button>
</Action>
)}/>
)}

View File

@ -20,7 +20,7 @@ class ComTable extends React.Component {
handleDelete = (text) => {
Modal.confirm({
title: '删除确认',
content: `确定要删除【${text['name']}】?`,
content: `将会同步删除服务的配置信息,确定要删除服务${text['name']}】? `,
onOk: () => {
return http.delete('/api/config/service/', {params: {id: text.id}})
.then(() => {
@ -66,8 +66,8 @@ class ComTable extends React.Component {
<Table.Column title="操作" render={info => (
<Action>
<Action.Button auth="config.src.edit" onClick={() => store.showForm(info)}>编辑</Action.Button>
<Action.Button auth="config.src.del" onClick={() => this.handleDelete(info)}>删除</Action.Button>
<Action.Button auth="config.src.view_config" onClick={() => this.toConfig(info)}>配置</Action.Button>
<Action.Button danger auth="config.src.del" onClick={() => this.handleDelete(info)}>删除</Action.Button>
</Action>
)}/>
)}