Skip to content

Commit

Permalink
Fix request is not in canceled state after cancel
Browse files Browse the repository at this point in the history
  • Loading branch information
elias-boulharts authored and Sispheor committed Sep 26, 2023
1 parent e370591 commit 96ce19f
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 9 deletions.
4 changes: 2 additions & 2 deletions service_catalog/api/views/request_state_machine_api_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,8 @@ def cancel(self, request, pk=None):
raise PermissionDenied
if not can_proceed(target_request.cancel):
raise PermissionDenied
if target_request.cancel():
target_request.save()
target_request.cancel()
target_request.save()
send_email_request_canceled(target_request,
user_applied_state=request.user)
if Request.objects.filter(id=pk).exists():
Expand Down
2 changes: 0 additions & 2 deletions service_catalog/models/request.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,8 +147,6 @@ def cancel(self):
if self.instance.state == InstanceState.PENDING:
self.instance.abort()
self.instance.save()
return False
return True

@transition(field=state, source=[RequestState.SUBMITTED, RequestState.ACCEPTED, RequestState.NEED_INFO],
target=RequestState.REJECTED)
Expand Down
8 changes: 3 additions & 5 deletions service_catalog/views/request.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,11 +102,9 @@ def request_cancel(request, pk):
if not can_proceed(target_request.cancel):
raise PermissionDenied
if request.method == "POST":
send_email_request_canceled(target_request,
user_applied_state=request.user)

if target_request.cancel():
target_request.save()
send_email_request_canceled(target_request, user_applied_state=request.user)
target_request.cancel()
target_request.save()
return redirect(target_request.get_absolute_url())
context = {
'breadcrumbs': [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ def _assert_can_cancel(self):
self.assertEqual(302, response.status_code)
self.test_request.refresh_from_db()
self.assertEqual(self.test_request.instance.state, InstanceState.ABORTED)
self.assertEqual(self.test_request.state, RequestState.CANCELED)

def _assert_cannot_cancel(self):
args = {
Expand Down

0 comments on commit 96ce19f

Please sign in to comment.