Skip to content

Commit

Permalink
Add new license fields in UI and related features #63
Browse files Browse the repository at this point in the history
Signed-off-by: tdruez <tdruez@nexb.com>
  • Loading branch information
tdruez committed Jun 10, 2024
1 parent 8fa6df9 commit f851058
Show file tree
Hide file tree
Showing 8 changed files with 195 additions and 69 deletions.
14 changes: 13 additions & 1 deletion component_catalog/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -826,6 +826,13 @@ class PackageAdmin(
{
"fields": (
"license_expression",
"declared_license_expression",
"declared_license_expression_spdx",
"license_detections",
"other_license_expression",
"other_license_expression_spdx",
"other_license_detections",
"extracted_license_statement",
"copyright",
"holder",
"author",
Expand Down Expand Up @@ -880,7 +887,12 @@ class PackageAdmin(
),
get_additional_information_fieldset(),
]
readonly_fields = DataspacedAdmin.readonly_fields + ("package_url", "inferred_url")
readonly_fields = DataspacedAdmin.readonly_fields + (
"package_url",
"inferred_url",
"declared_license_expression_spdx",
"other_license_expression_spdx",
)
form = PackageAdminForm
importer_class = PackageImporter
mass_update_form = PackageMassUpdateForm
Expand Down
28 changes: 28 additions & 0 deletions component_catalog/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,13 @@ class Meta:
"holder",
"author",
"license_expression",
"declared_license_expression",
"declared_license_expression_spdx",
"license_detections",
"other_license_expression",
"other_license_expression_spdx",
"other_license_detections",
"extracted_license_statement",
"reference_notes",
"homepage_url",
"vcs_url",
Expand Down Expand Up @@ -323,6 +330,13 @@ class Meta:
"licenses_summary",
"license_choices_expression",
"license_choices",
"declared_license_expression",
"declared_license_expression_spdx",
"license_detections",
"other_license_expression",
"other_license_expression_spdx",
"other_license_detections",
"extracted_license_statement",
"created_date",
"last_modified_date",
)
Expand Down Expand Up @@ -524,6 +538,13 @@ class Meta(ComponentSerializer.Meta):
"copyright",
"holder",
"license_expression",
"declared_license_expression",
"declared_license_expression_spdx",
"license_detections",
"other_license_expression",
"other_license_expression_spdx",
"other_license_detections",
"extracted_license_statement",
"reference_notes",
"release_date",
"description",
Expand Down Expand Up @@ -639,6 +660,13 @@ class Meta:
"licenses_summary",
"license_choices_expression",
"license_choices",
"declared_license_expression",
"declared_license_expression_spdx",
"license_detections",
"other_license_expression",
"other_license_expression_spdx",
"other_license_detections",
"extracted_license_statement",
"reference_notes",
"homepage_url",
"vcs_url",
Expand Down
24 changes: 23 additions & 1 deletion component_catalog/migrations/0005_license_fields.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Generated by Django 5.0.6 on 2024-06-10 05:01
# Generated by Django 5.0.6 on 2024-06-10 06:37

from django.db import migrations, models

Expand Down Expand Up @@ -130,4 +130,26 @@ class Migration(migrations.Migration):
verbose_name="Other license expression SPDX",
),
),
migrations.AlterField(
model_name="component",
name="license_expression",
field=models.CharField(
blank=True,
db_index=True,
help_text='The License Expression assigned to a DejaCode Package or Component is an editable value equivalent to a "concluded license" as determined by a curator who has performed analysis to clarify or correct the declared license expression, which may have been assigned automatically (from a scan or an associated package definition) when the Package or Component was originally created. A license expression defines the relationship of one or more licenses to a software object. More than one applicable license can be expressed as "license-key-a AND license-key-b". A choice of applicable licenses can be expressed as "license-key-a OR license-key-b", and you can indicate the primary (preferred) license by placing it first, on the left-hand side of the OR relationship. The relationship words (OR, AND) can be combined as needed, and the use of parentheses can be applied to clarify the meaning; for example "((license-key-a AND license-key-b) OR (license-key-c))". An exception to a license can be expressed as "license-key WITH license-exception-key".',
max_length=1024,
verbose_name="Concluded license expression",
),
),
migrations.AlterField(
model_name="package",
name="license_expression",
field=models.CharField(
blank=True,
db_index=True,
help_text='The License Expression assigned to a DejaCode Package or Component is an editable value equivalent to a "concluded license" as determined by a curator who has performed analysis to clarify or correct the declared license expression, which may have been assigned automatically (from a scan or an associated package definition) when the Package or Component was originally created. A license expression defines the relationship of one or more licenses to a software object. More than one applicable license can be expressed as "license-key-a AND license-key-b". A choice of applicable licenses can be expressed as "license-key-a OR license-key-b", and you can indicate the primary (preferred) license by placing it first, on the left-hand side of the OR relationship. The relationship words (OR, AND) can be combined as needed, and the use of parentheses can be applied to clarify the meaning; for example "((license-key-a AND license-key-b) OR (license-key-c))". An exception to a license can be expressed as "license-key WITH license-exception-key".',
max_length=1024,
verbose_name="Concluded license expression",
),
),
]
59 changes: 28 additions & 31 deletions component_catalog/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,24 @@
"version",
]

LICENSE_EXPRESSION_HELP_TEXT = _(
"The License Expression assigned to a DejaCode Package or Component is an editable "
'value equivalent to a "concluded license" as determined by a curator who has '
"performed analysis to clarify or correct the declared license expression, which "
"may have been assigned automatically (from a scan or an associated package "
"definition) when the Package or Component was originally created. "
"A license expression defines the relationship of one or more licenses to a "
"software object. More than one applicable license can be expressed as "
'"license-key-a AND license-key-b". A choice of applicable licenses can be '
'expressed as "license-key-a OR license-key-b", and you can indicate the primary '
"(preferred) license by placing it first, on the left-hand side of the OR "
"relationship. The relationship words (OR, AND) can be combined as needed, "
"and the use of parentheses can be applied to clarify the meaning; "
'for example "((license-key-a AND license-key-b) OR (license-key-c))". '
"An exception to a license can be expressed as "
'"license-key WITH license-exception-key".'
)


def validate_filename(value):
invalid_chars = ["/", "\\", ":"]
Expand Down Expand Up @@ -755,25 +773,6 @@ class BaseComponentMixin(
),
)

license_expression = models.CharField(
_("License expression"),
max_length=1024,
blank=True,
db_index=True,
help_text=_(
"On a component or a product in DejaCode, a license expression defines the "
"relationship of one or more licenses to that software as declared by its "
'licensor. More than one applicable license can be expressed as "license-key-a '
'AND license-key-b". A choice of applicable licenses can be expressed as '
'"license-key-a OR license-key-b", and you can indicate the primary (preferred) '
"license by placing it first, on the left-hand side of the OR relationship. "
"The relationship words (OR, AND) can be combined as needed, and the use of "
'parentheses can be applied to clarify the meaning; for example "((license-key-a '
'AND license-key-b) OR (license-key-c))". An exception to a license can be '
'expressed as “license-key WITH license-exception-key".'
),
)

class Meta:
abstract = True
unique_together = (("dataspace", "name", "version"), ("dataspace", "uuid"))
Expand Down Expand Up @@ -888,6 +887,14 @@ class Component(
BaseComponentMixin,
DataspacedModel,
):
license_expression = models.CharField(
_("Concluded license expression"),
max_length=1024,
blank=True,
db_index=True,
help_text=LICENSE_EXPRESSION_HELP_TEXT,
)

configuration_status = models.ForeignKey(
to="component_catalog.ComponentStatus",
on_delete=models.PROTECT,
Expand Down Expand Up @@ -1738,21 +1745,11 @@ class Package(
)

license_expression = models.CharField(
_("License expression"),
_("Concluded license expression"),
max_length=1024,
blank=True,
db_index=True,
help_text=_(
"On a package in DejaCode, a license expression defines the relationship of one or "
"more licenses to that software as declared by its licensor. More than one "
'applicable license can be expressed as "license-key-a AND license-key-b". A choice '
'of applicable licenses can be expressed as "license-key-a OR license-key-b", and you '
"can indicate the primary (preferred) license by placing it first, on the left-hand "
"side of the OR relationship. The relationship words (OR, AND) can be combined as "
"needed, and the use of parentheses can be applied to clarify the meaning; for "
'example "((license-key-a AND license-key-b) OR (license-key-c))". An exception to '
'a license can be expressed as “license-key WITH license-exception-key".'
),
help_text=LICENSE_EXPRESSION_HELP_TEXT,
)

copyright = models.TextField(
Expand Down
18 changes: 16 additions & 2 deletions component_catalog/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -435,7 +435,7 @@ class ComponentListView(
Header("name", _("Component name")),
Header("version", _("Version")),
Header("usage_policy", _("Policy"), filter="usage_policy", condition=include_policy),
Header("license_expression", _("License"), filter="licenses"),
Header("license_expression", _("Concluded license"), filter="licenses"),
Header("primary_language", _("Language"), filter="primary_language"),
Header("owner", _("Owner")),
Header("keywords", _("Keywords"), filter="keywords"),
Expand Down Expand Up @@ -562,6 +562,13 @@ class ComponentDetailsView(
"reference_notes",
"licenses",
"licenses_summary",
"declared_license_expression",
"declared_license_expression_spdx",
"license_detections",
"other_license_expression",
"other_license_expression_spdx",
"other_license_detections",
"extracted_license_statement",
],
},
"hierarchy": {},
Expand Down Expand Up @@ -1073,7 +1080,7 @@ class PackageListView(
table_headers = (
Header("sortable_identifier", _("Identifier"), Package.identifier_help()),
Header("usage_policy", _("Policy"), filter="usage_policy", condition=include_policy),
Header("license_expression", _("License"), filter="licenses"),
Header("license_expression", _("Concluded license"), filter="licenses"),
Header("primary_language", _("Language"), filter="primary_language"),
Header("filename", _("Download"), help_text="Download link"),
Header("components", "Components", PACKAGE_COMPONENTS_HELP, "component"),
Expand Down Expand Up @@ -1214,6 +1221,13 @@ class PackageDetailsView(
"reference_notes",
"licenses",
"licenses_summary",
"declared_license_expression",
"declared_license_expression_spdx",
"license_detections",
"other_license_expression",
"other_license_expression_spdx",
"other_license_detections",
"extracted_license_statement",
],
},
"terms": {
Expand Down
45 changes: 45 additions & 0 deletions product_portfolio/migrations/0005_license_fields.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# Generated by Django 5.0.6 on 2024-06-10 06:37

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
("product_portfolio", "0004_alter_scancodeproject_type"),
]

operations = [
migrations.AlterField(
model_name="product",
name="license_expression",
field=models.CharField(
blank=True,
db_index=True,
help_text='On a product in DejaCode, a license expression defines the relationship of one or more licenses to that software as declared by its licensor. More than one applicable license can be expressed as "license-key-a AND license-key-b". A choice of applicable licenses can be expressed as "license-key-a OR license-key-b", and you can indicate the primary (preferred) license by placing it first, on the left-hand side of the OR relationship. The relationship words (OR, AND) can be combined as needed, and the use of parentheses can be applied to clarify the meaning; for example "((license-key-a AND license-key-b) OR (license-key-c))". An exception to a license can be expressed as "license-key WITH license-exception-key".',
max_length=1024,
),
),
migrations.AlterField(
model_name="productcomponent",
name="license_expression",
field=models.CharField(
blank=True,
db_index=True,
help_text='The License Expression assigned to a DejaCode Product Package or Product Component is an editable value equivalent to a "concluded license" as determined by a curator who has performed analysis to clarify or correct the declared license expression, which may have been assigned automatically (from a scan or an associated package definition) when the Package or Component was originally created, or which may require the assertion of a choice of license.A license expression defines the relationship of one or more licenses to a software object. More than one applicable license can be expressed as "license-key-a AND license-key-b". A choice of applicable licenses can be expressed as "license-key-a OR license-key-b", and you can indicate the primary (preferred) license by placing it first, on the left-hand side of the OR relationship. The relationship words (OR, AND) can be combined as needed, and the use of parentheses can be applied to clarify the meaning; for example "((license-key-a AND license-key-b) OR (license-key-c))". An exception to a license can be expressed as "license-key WITH license-exception-key".',
max_length=1024,
verbose_name="Concluded license expression",
),
),
migrations.AlterField(
model_name="productpackage",
name="license_expression",
field=models.CharField(
blank=True,
db_index=True,
help_text='The License Expression assigned to a DejaCode Product Package or Product Component is an editable value equivalent to a "concluded license" as determined by a curator who has performed analysis to clarify or correct the declared license expression, which may have been assigned automatically (from a scan or an associated package definition) when the Package or Component was originally created, or which may require the assertion of a choice of license.A license expression defines the relationship of one or more licenses to a software object. More than one applicable license can be expressed as "license-key-a AND license-key-b". A choice of applicable licenses can be expressed as "license-key-a OR license-key-b", and you can indicate the primary (preferred) license by placing it first, on the left-hand side of the OR relationship. The relationship words (OR, AND) can be combined as needed, and the use of parentheses can be applied to clarify the meaning; for example "((license-key-a AND license-key-b) OR (license-key-c))". An exception to a license can be expressed as "license-key WITH license-exception-key".',
max_length=1024,
verbose_name="Concluded license expression",
),
),
]
Loading

0 comments on commit f851058

Please sign in to comment.