From 8ee0b25d1de79afbc5820fa486230706ea353d67 Mon Sep 17 00:00:00 2001 From: QSummerY <51444798+QSummerY@users.noreply.github.com> Date: Mon, 9 Oct 2023 11:16:42 +0800 Subject: [PATCH] Update index.py MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 在操作时都需要判断 ticket 当前是否能够进行操作,处于 pending 状态下才能操作 关闭/通过/拒绝 --- helpdesk/views/api/index.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/helpdesk/views/api/index.py b/helpdesk/views/api/index.py index cd17737f..6c03610e 100644 --- a/helpdesk/views/api/index.py +++ b/helpdesk/views/api/index.py @@ -157,13 +157,13 @@ async def ticket_op(ticket_id: int, op: str, ticket = await Ticket.get(ticket_id) if not ticket: raise HTTPException(status_code=404, detail='Ticket not found') + if ticket.status != "pending": + raise HTTPException(status_code=400, detail='Ticket not pending, can not be operated') if op == 'close': "申请人才可主动关闭工单" if ticket.submitter != current_user.name: raise HTTPException(status_code=403, detail='Permission denied, only submitter can close') - if ticket.status != "pending": - raise HTTPException(status_code=400, detail='Ticket not pending, can not be closed') ticket.annotate(closed=True) ticket.confirmed_by = current_user.name ticket.confirmed_at = datetime.now()