mirror of https://github.com/openspug/spug
A 添加发布申请单个删除功能
parent
b727f06318
commit
40165e6a31
|
@ -58,9 +58,8 @@ class DeployRequest(models.Model, ModelMixin):
|
|||
return f'{settings.REQUEST_KEY}:{self.id}'
|
||||
|
||||
def delete(self, using=None, keep_parents=False):
|
||||
super().delete(using, keep_parents)
|
||||
if self.repository_id:
|
||||
if not DeployRequest.objects.filter(repository=self.repository).exists():
|
||||
if not self.repository.deployrequest_set.exclude(id=self.id).exists():
|
||||
self.repository.delete()
|
||||
if self.deploy.extend == '2':
|
||||
for p in Path(settings.REPOS_DIR, str(self.deploy_id)).glob(f'{self.spug_version}*'):
|
||||
|
@ -73,6 +72,7 @@ class DeployRequest(models.Model, ModelMixin):
|
|||
p.unlink()
|
||||
except FileNotFoundError:
|
||||
pass
|
||||
super().delete(using, keep_parents)
|
||||
|
||||
def __repr__(self):
|
||||
return f'<DeployRequest name={self.name}>'
|
||||
|
|
|
@ -5,7 +5,7 @@ from django.views.generic import View
|
|||
from django.db.models import F
|
||||
from django.conf import settings
|
||||
from django.http.response import HttpResponseBadRequest
|
||||
from libs import json_response, JsonParser, Argument, human_datetime, human_time, auth, AttrDict
|
||||
from libs import json_response, JsonParser, Argument, human_datetime, auth, AttrDict
|
||||
from apps.deploy.models import DeployRequest
|
||||
from apps.app.models import Deploy, DeployExtend2
|
||||
from apps.repository.models import Repository
|
||||
|
@ -68,9 +68,7 @@ class RequestView(View):
|
|||
).parse(request.GET)
|
||||
if error is None:
|
||||
if form.id:
|
||||
deploy = DeployRequest.objects.filter(pk=form.id).first()
|
||||
if not deploy or deploy.status not in ('0', '1', '-1'):
|
||||
return json_response(error='未找到指定发布申请或当前状态不允许删除')
|
||||
deploy = DeployRequest.objects.get(pk=form.id)
|
||||
deploy.delete()
|
||||
return json_response()
|
||||
|
||||
|
|
|
@ -54,7 +54,6 @@ class Repository(models.Model, ModelMixin):
|
|||
return tmp
|
||||
|
||||
def delete(self, using=None, keep_parents=False):
|
||||
super().delete(using, keep_parents)
|
||||
try:
|
||||
Path(settings.BUILD_DIR, f'{self.spug_version}.tar.gz').unlink()
|
||||
except FileNotFoundError:
|
||||
|
@ -65,6 +64,7 @@ class Repository(models.Model, ModelMixin):
|
|||
p.unlink()
|
||||
except FileNotFoundError:
|
||||
pass
|
||||
super().delete(using, keep_parents)
|
||||
|
||||
class Meta:
|
||||
db_table = 'repositories'
|
||||
|
|
|
@ -94,7 +94,6 @@ export default observer(function () {
|
|||
formData['extra'] = [git_type, extra1, extra2];
|
||||
http.post('/api/repository/', formData)
|
||||
.then(res => {
|
||||
message.success('操作成功');
|
||||
store.formVisible = false;
|
||||
store.showConsole(res)
|
||||
}, () => setLoading(false))
|
||||
|
|
|
@ -97,7 +97,7 @@ function ComTable() {
|
|||
}, {
|
||||
title: '状态',
|
||||
fixed: 'right',
|
||||
className: S.min120,
|
||||
width: 120,
|
||||
render: info => {
|
||||
if (info.status === '-1' && info.reason) {
|
||||
return <Popover title="驳回原因:" content={info.reason}>
|
||||
|
@ -120,6 +120,7 @@ function ComTable() {
|
|||
}, {
|
||||
title: '操作',
|
||||
fixed: 'right',
|
||||
width: 220,
|
||||
className: hasPermission('deploy.request.do|deploy.request.edit|deploy.request.approve|deploy.request.del') ? S.min180 : 'none',
|
||||
render: info => {
|
||||
switch (info.status) {
|
||||
|
@ -130,6 +131,7 @@ function ComTable() {
|
|||
{info.visible_rollback && (
|
||||
<Action.Button auth="deploy.request.do" onClick={() => store.rollback(info)}>回滚</Action.Button>
|
||||
)}
|
||||
<Action.Button danger auth="deploy.request.del" onClick={() => handleDelete(info)}>删除</Action.Button>
|
||||
</Action>;
|
||||
case '3':
|
||||
return <Action>
|
||||
|
@ -137,6 +139,7 @@ function ComTable() {
|
|||
{info.visible_rollback && (
|
||||
<Action.Button auth="deploy.request.do" onClick={() => store.rollback(info)}>回滚</Action.Button>
|
||||
)}
|
||||
<Action.Button danger auth="deploy.request.del" onClick={() => handleDelete(info)}>删除</Action.Button>
|
||||
</Action>;
|
||||
case '4':
|
||||
return <Action>
|
||||
|
@ -145,11 +148,13 @@ function ComTable() {
|
|||
{info.visible_rollback && (
|
||||
<Action.Button auth="deploy.request.do" onClick={() => store.rollback(info)}>回滚</Action.Button>
|
||||
)}
|
||||
<Action.Button danger auth="deploy.request.del" onClick={() => handleDelete(info)}>删除</Action.Button>
|
||||
</Action>;
|
||||
case '-1':
|
||||
return <Action>
|
||||
<Action.Button auth="deploy.request.edit" onClick={() => store.showForm(info)}>编辑</Action.Button>
|
||||
<Action.Button auth="deploy.request.del" onClick={() => handleDelete(info)}>删除</Action.Button>
|
||||
<Action.Button danger auth="deploy.request.del" onClick={() => handleDelete(info)}>删除</Action.Button>
|
||||
</Action>;
|
||||
case '0':
|
||||
return <Action>
|
||||
|
@ -165,6 +170,7 @@ function ComTable() {
|
|||
case '2':
|
||||
return <Action>
|
||||
<Action.Button auth="deploy.request.do" onClick={() => store.readConsole(info)}>查看</Action.Button>
|
||||
<Action.Button danger auth="deploy.request.del" onClick={() => handleDelete(info)}>删除</Action.Button>
|
||||
</Action>;
|
||||
default:
|
||||
return null
|
||||
|
@ -196,7 +202,7 @@ function ComTable() {
|
|||
function handleDelete(info) {
|
||||
Modal.confirm({
|
||||
title: '删除确认',
|
||||
content: `确定要删除【${info['name']}】?`,
|
||||
content: `确定要删除发布申请【${info['name']}】?`,
|
||||
onOk: () => {
|
||||
return http.delete('/api/deploy/request/', {params: {id: info.id}})
|
||||
.then(() => {
|
||||
|
|
Loading…
Reference in New Issue