Skip to content

Commit

Permalink
Using proper webhookdeliveries for the related name #1325
Browse files Browse the repository at this point in the history
Signed-off-by: tdruez <[email protected]>
  • Loading branch information
tdruez committed Jul 24, 2024
1 parent 956e812 commit b08f2cb
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 5 deletions.
2 changes: 1 addition & 1 deletion scanpipe/migrations/0064_webhookdelivery.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class Migration(migrations.Migration):
('response_status_code', models.PositiveIntegerField(blank=True, help_text='The HTTP status code received in response to the Webhook request.', null=True)),
('response_text', models.TextField(blank=True, help_text='The text response received from the target URL.')),
('delivery_error', models.TextField(blank=True, help_text='Any error messages encountered during the Webhook delivery.')),
('project', models.ForeignKey(editable=False, on_delete=django.db.models.deletion.CASCADE, related_name='%(class)ss', to='scanpipe.project')),
('project', models.ForeignKey(editable=False, on_delete=django.db.models.deletion.CASCADE, related_name='webhookdeliveries', to='scanpipe.project')),
('webhook_subscription', models.ForeignKey(blank=True, editable=False, help_text='The Webhook subscription associated with this delivery.', null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='deliveries', to='scanpipe.webhooksubscription')),
],
options={
Expand Down
13 changes: 11 additions & 2 deletions scanpipe/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -637,11 +637,14 @@ def delete_related_objects(self):
self.labels.clear()

relationships = [
self.webhookdeliveries,
self.webhooksubscriptions,
self.projectmessages,
self.codebaserelations,
self.discovereddependencies,
self.codebaseresources,
self.runs,
self.inputsources,
]

for qs in relationships:
Expand Down Expand Up @@ -3552,8 +3555,7 @@ class DiscoveredDependency(
manifest or lockfile.
"""

# Overrides the `project` field from `ProjectRelatedModel` to set the proper
# `related_name`.
# Overrides the `project` field to set the proper `related_name`.
project = models.ForeignKey(
Project,
related_name="discovereddependencies",
Expand Down Expand Up @@ -3983,6 +3985,13 @@ class WebhookDelivery(UUIDPKModel, ProjectRelatedModel):
during the delivery process.
"""

# Overrides the `project` field to set the proper `related_name`.
project = models.ForeignKey(
Project,
related_name="webhookdeliveries",
on_delete=models.CASCADE,
editable=False,
)
webhook_subscription = models.ForeignKey(
WebhookSubscription,
related_name="deliveries",
Expand Down
4 changes: 2 additions & 2 deletions scanpipe/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -2090,15 +2090,15 @@ def get_context_data(self, **kwargs):
def run_detail_view(request, uuid):
template = "scanpipe/modals/run_modal_content.html"
run_qs = Run.objects.select_related("project").prefetch_related(
"project__webhookdeliverys",
"project__webhookdeliveries",
)
run = get_object_or_404(run_qs, uuid=uuid)
project = run.project

context = {
"run": run,
"project": project,
"webhook_deliveries": project.webhookdeliverys.all(),
"webhook_deliveries": project.webhookdeliveries.all(),
}

return render(request, template, context)
Expand Down

0 comments on commit b08f2cb

Please sign in to comment.