Skip to content

Commit

Permalink
Add project_purl field to project
Browse files Browse the repository at this point in the history
Signed-off-by: Keshav Priyadarshi <[email protected]>
  • Loading branch information
keshav-space committed Oct 23, 2024
1 parent 72c97c9 commit fabb308
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 0 deletions.
1 change: 1 addition & 0 deletions scanpipe/api/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,7 @@ class Meta:
"name",
"url",
"uuid",
"project_purl",
"upload_file",
"upload_file_tag",
"input_urls",
Expand Down
15 changes: 15 additions & 0 deletions scanpipe/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
from django.core.exceptions import ObjectDoesNotExist
from django.core.exceptions import ValidationError

from packageurl import PackageURL
from taggit.forms import TagField
from taggit.forms import TagWidget

Expand Down Expand Up @@ -458,12 +459,26 @@ class Meta:
fields = [
"name",
"notes",
"project_purl",
]
widgets = {
"name": forms.TextInput(attrs={"class": "input"}),
"notes": forms.Textarea(attrs={"rows": 3, "class": "textarea is-dynamic"}),
"project_purl": forms.TextInput(attrs={"class": "input"}),
}

def clean_project_purl(self):
"""Validate the Project PURL."""
project_purl = self.cleaned_data.get("project_purl")

if project_purl:
try:
PackageURL.from_string(project_purl)
except ValueError:
raise forms.ValidationError("Project PURL must be a valid PackageURL")

return project_purl

def __init__(self, *args, **kwargs):
"""Load initial values from Project ``settings`` field."""
super().__init__(*args, **kwargs)
Expand Down
18 changes: 18 additions & 0 deletions scanpipe/migrations/0068_project_project_purl.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 5.0.7 on 2024-10-22 14:37

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('scanpipe', '0067_discoveredpackage_notes'),
]

operations = [
migrations.AddField(
model_name='project',
name='project_purl',
field=models.CharField(blank=True, help_text='Project Package URL.', max_length=2048),
),
]
6 changes: 6 additions & 0 deletions scanpipe/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -561,6 +561,11 @@ class Project(UUIDPKModel, ExtraDataFieldMixin, UpdateMixin, models.Model):
notes = models.TextField(blank=True)
settings = models.JSONField(default=dict, blank=True)
labels = TaggableManager(through=UUIDTaggedItem)
project_purl = models.CharField(
max_length=2048,
blank=True,
help_text=_("Project Package URL."),
)

objects = ProjectQuerySet.as_manager()

Expand Down Expand Up @@ -704,6 +709,7 @@ def clone(
"""Clone this project using the provided ``clone_name`` as new project name."""
new_project = Project.objects.create(
name=clone_name,
project_purl=self.project_purl,
settings=self.settings if copy_settings else {},
)

Expand Down
8 changes: 8 additions & 0 deletions scanpipe/templates/scanpipe/project_settings.html
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,14 @@
{{ form.name }}
</div>
</div>
<div class="field">
<label class="label" for="{{ form.name.id_for_label }}">
Project PURL
</label>
<div class="control">
{{ form.project_purl }}
</div>
</div>
<div class="field">
<label class="label" for="{{ form.notes.id_for_label }}">
{{ form.notes.label }}
Expand Down

0 comments on commit fabb308

Please sign in to comment.