Skip to content

Commit

Permalink
判断是否可取消时区分状态 #1470
Browse files Browse the repository at this point in the history
  • Loading branch information
hhyo committed Apr 30, 2022
1 parent 969b861 commit e66c77f
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
7 changes: 4 additions & 3 deletions sql/utils/sql_review.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,10 +126,11 @@ def can_cancel(user, workflow_id):
workflow_detail = SqlWorkflow.objects.get(id=workflow_id)
result = False
# 审核中的工单,审核人和提交人可终止
if workflow_detail.status in ['workflow_manreviewing', 'workflow_review_pass', 'workflow_timingtask']:
if workflow_detail.status == 'workflow_manreviewing':
from sql.utils.workflow_audit import Audit
if Audit.can_review(user, workflow_id, 2) or user.username == workflow_detail.engineer:
result = True
return any([Audit.can_review(user, workflow_id, 2), user.username == workflow_detail.engineer])
elif workflow_detail.status in ['workflow_review_pass', 'workflow_timingtask']:
return any([can_execute(user, workflow_id), user.username == workflow_detail.engineer])
return result


Expand Down
8 changes: 4 additions & 4 deletions sql/utils/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -434,18 +434,18 @@ def test_can_cancel_true_for_execute_user(self, _can_execute):
self.assertTrue(r)

@patch('sql.utils.sql_review.can_execute')
def test_can_cancel_false(self, _can_execute):
def test_can_cancel_true_for_submit_user(self, _can_execute):
"""
测试是否能取消,审核通过但未执行的工单,无执行权限的用户无法终止
测试是否能取消,审核通过但未执行的工单,提交人可终止
:return:
"""
# 修改工单为workflow_review_pass,当前登录用户为提交人
self.wf1.status = 'workflow_review_pass'
self.wf1.engineer = self.user.username
self.wf1.save(update_fields=('status', 'engineer'))
_can_execute.return_value = False
_can_execute.return_value = True
r = can_cancel(user=self.user, workflow_id=self.wfc1.workflow_id)
self.assertFalse(r)
self.assertTrue(r)

def test_on_correct_time_period(self):
"""
Expand Down

0 comments on commit e66c77f

Please sign in to comment.