Skip to content

Commit 41328aa

Browse files
committed
Refactor the Request close logic to the model #349
Signed-off-by: tdruez <tdruez@nexb.com>
1 parent 4d851f8 commit 41328aa

2 files changed

Lines changed: 17 additions & 9 deletions

File tree

workflow/models.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -569,6 +569,22 @@ def serialize_hook(self, hook):
569569
"data": serializer.data,
570570
}
571571

572+
def close(self, user, reason):
573+
"""
574+
Set the Request status to CLOSED.
575+
A RequestEvent is created and returned.
576+
"""
577+
self.status = self.Status.CLOSED
578+
self.last_modified_by = user
579+
self.save()
580+
event_instance = self.events.create(
581+
user=user,
582+
text=reason,
583+
event_type=RequestEvent.CLOSED,
584+
dataspace=self.dataspace,
585+
)
586+
return event_instance
587+
572588
def link_external_issue(self, platform, repo, issue_id):
573589
"""Create or return an ExternalIssueLink associated with this Request."""
574590
if self.external_issue:

workflow/views.py

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -244,15 +244,7 @@ def request_details_view(request, request_uuid):
244244

245245
closed_reason = request.POST.get("closed_reason")
246246
if closed_reason and request_instance.has_close_permission(request.user):
247-
request_instance.status = Request.Status.CLOSED
248-
request_instance.last_modified_by = request.user
249-
request_instance.save()
250-
event_instance = request_instance.events.create(
251-
user=request.user,
252-
text=closed_reason,
253-
event_type=RequestEvent.CLOSED,
254-
dataspace=request_instance.dataspace,
255-
)
247+
event_instance = request_instance.close(user=request.user, reason=closed_reason)
256248
send_request_comment_notification(request, event_instance, closed=True)
257249
messages.success(request, f"Request {request_instance} closed")
258250
return redirect("workflow:request_list")

0 commit comments

Comments
 (0)