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