Skip to content

Package scan from UI #1613

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from
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
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
8 changes: 8 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
Loading