Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions scanpipe/migrations/0070_discoveredpackage_analysis_subproject.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Generated by Django 5.1.5 on 2025-03-03 06:53

import django.db.models.deletion
from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('scanpipe', '0069_project_purl'),
]

operations = [
migrations.AddField(
model_name='discoveredpackage',
name='analysis_subproject',
field=models.OneToOneField(blank=True, editable=False, help_text='Sub-project dedicated to analyzing this package.', null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='analyzed_package', to='scanpipe.project'),
),
]
9 changes: 9 additions & 0 deletions scanpipe/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -3442,6 +3442,15 @@ class DiscoveredPackage(
notes = models.TextField(blank=True)
source_packages = models.JSONField(default=list, blank=True)
tag = models.CharField(blank=True, max_length=50)
analysis_subproject = models.OneToOneField(
Project,
related_name="analyzed_package",
help_text=_("Sub-project dedicated to analyzing this package."),
on_delete=models.SET_NULL,
blank=True,
null=True,
editable=False,
)

objects = DiscoveredPackageQuerySet.as_manager()

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<section class="pt-0 mx-5 mb-3">
<article class="message is-warning">
<div class="message-body">
<p class="block">
<span class="icon width-1 height-1 mr-1">
<i class="fa-solid fa-info-circle"></i>
</span>
<span>
This package analysis was initiated for the
<strong>
<a href="{% url 'package_detail' project.analyzed_package.project.slug project.analyzed_package.uuid %}">
{{ project.analyzed_package.package_url }}
</a>
</strong>
package of the
<strong>
<a href="{% url 'project_detail' project.analyzed_package.project.slug %}">
{{ project.analyzed_package.project.slug }}
</a>
</strong>
project.
</span>
</p>
</div>
</article>
</section>
36 changes: 28 additions & 8 deletions scanpipe/templates/scanpipe/package_list.html
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,34 @@
<tbody>
{% for package in object_list %}
<tr class="break-word">
<td style="min-width: 500px;" title="{{ package.package_uid }}">
{# CAUTION: Avoid relying on get_absolute_url to prevent unnecessary query triggers #}
<a href="{% url 'package_detail' project.slug package.uuid %}">{{ package.package_url }}</a>
{% if package.is_vulnerable %}
<a href="{% url 'package_detail' project.slug package.uuid %}#vulnerabilities">
<i class="fa-solid fa-bug fa-sm has-text-danger" title="Vulnerabilities"></i>
</a>
{% endif %}
<td style="min-width: 500px;">
<div class="is-flex is-justify-content-space-between">
<div title="{{ package.package_uid }}">
{# CAUTION: Avoid relying on get_absolute_url to prevent unnecessary query triggers #}
<a href="{% url 'package_detail' project.slug package.uuid %}">{{ package.package_url }}</a>
</div>
<div>
{% if package.is_vulnerable %}
<a href="{% url 'package_detail' project.slug package.uuid %}#vulnerabilities">
<i class="fa-solid fa-bug fa-sm has-text-danger" title="Vulnerabilities"></i>
</a>
{% endif %}
{% if package.download_url %}
<a class="is-grey-link ml-1" href="{{ package.download_url }}" title="Download {{ package.download_url }}" target="_blank">
<i class="fa-solid fa-download fa-sm"></i>
</a>
{% if package.analysis_subproject %}
<a class="is-grey-link ml-1" title="View scan page" href="{% url 'project_detail' package.analysis_subproject.slug %}" target="_blank">
<i class="fa-solid fa-eye fa-sm"></i>
</a>
{% else %}
<a class="is-grey-link ml-1" title="Scan package" href="{% url 'project_add' %}?name=package-{{ package.uuid }}&input_urls={{ package.download_url }}&pipeline=scan_single_package" target="_blank">
<i class="fa-solid fa-barcode fa-sm"></i>
</a>
{% endif %}
{% endif %}
</div>
</div>
</td>
<td style="min-width: 300px; max-width: 400px;">
<a href="?declared_license_expression={{ package.declared_license_expression }}" class="is-black-link">
Expand Down
4 changes: 4 additions & 0 deletions scanpipe/templates/scanpipe/project_detail.html
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@
</section>

<hr class="mx-5 mt-0">

{% if project.analyzed_package %}
{% include "scanpipe/includes/project_analyzed_package_warning.html" %}
{% endif %}
{% include "scanpipe/includes/project_summary_level.html" with project=project title_class="title" %}

<section class="pt-0 mx-5">
Expand Down
1 change: 1 addition & 0 deletions scanpipe/tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -2503,6 +2503,7 @@ def test_scanpipe_package_model_integrity_with_toolkit_package_model(self):
"resolved_from_dependencies",
"parent_packages",
"children_packages",
"analysis_subproject",
"notes",
]

Expand Down
10 changes: 10 additions & 0 deletions scanpipe/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -639,6 +639,14 @@ class ProjectCreateView(ConditionalLoginRequired, FormAjaxMixin, generic.CreateV
form_class = ProjectForm
template_name = "scanpipe/project_form.html"

def get_initial(self):
"""Get initial data for the form from the URL query parameters."""
initial = super().get_initial()
for field in self.form_class().fields:
if value := self.request.GET.get(field):
initial[field] = value
return initial

def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
pipelines = {
Expand Down Expand Up @@ -1654,11 +1662,13 @@ def get_queryset(self):
"package_uid",
*PACKAGE_URL_FIELDS,
"project",
"download_url",
"primary_language",
"declared_license_expression",
"compliance_alert",
"copyright",
"affected_by_vulnerabilities",
"analysis_subproject",
)
.with_resources_count()
.order_by_package_url()
Expand Down
Loading