Skip to content

Commit

Permalink
#158 - Update link references (comments and docs) of ownership from n…
Browse files Browse the repository at this point in the history
…exB to aboutcode-org

Signed-off-by: Chin Yeung Li <[email protected]>
  • Loading branch information
chinyeungli committed Aug 16, 2024
1 parent 0f01d2b commit 95058ba
Show file tree
Hide file tree
Showing 258 changed files with 7,543 additions and 4,160 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# Copyright (c) nexB Inc. and others. All rights reserved.
# DejaCode is a trademark of nexB Inc.
# SPDX-License-Identifier: AGPL-3.0-only
# See https://github.com/nexB/dejacode for support or download.
# See https://github.com/aboutcode-org/dejacode for support or download.
# See https://aboutcode.org for more information about AboutCode FOSS projects.
#

Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# Copyright (c) nexB Inc. and others. All rights reserved.
# DejaCode is a trademark of nexB Inc.
# SPDX-License-Identifier: AGPL-3.0-only
# See https://github.com/nexB/dejacode for support or download.
# See https://github.com/aboutcode-org/dejacode for support or download.
# See https://aboutcode.org for more information about AboutCode FOSS projects.
#

Expand Down
2 changes: 1 addition & 1 deletion component_catalog/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
# Copyright (c) nexB Inc. and others. All rights reserved.
# DejaCode is a trademark of nexB Inc.
# SPDX-License-Identifier: AGPL-3.0-only
# See https://github.com/nexB/dejacode for support or download.
# See https://github.com/aboutcode-org/dejacode for support or download.
# See https://aboutcode.org for more information about AboutCode FOSS projects.
#
50 changes: 33 additions & 17 deletions component_catalog/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# Copyright (c) nexB Inc. and others. All rights reserved.
# DejaCode is a trademark of nexB Inc.
# SPDX-License-Identifier: AGPL-3.0-only
# See https://github.com/nexB/dejacode for support or download.
# See https://github.com/aboutcode-org/dejacode for support or download.
# See https://aboutcode.org for more information about AboutCode FOSS projects.
#

Expand Down Expand Up @@ -151,7 +151,8 @@ def add_view(self, request, form_url="", extra_context=None):
def change_view(self, request, object_id, form_url="", extra_context=None):
response = super().change_view(request, object_id, form_url, extra_context)

context_data = response.context_data if hasattr(response, "context_data") else None
context_data = response.context_data if hasattr(
response, "context_data") else None
instance = context_data.get("original") if context_data else None
self.setup_license_builder(request, instance)

Expand All @@ -170,7 +171,8 @@ class ComponentTypeAdmin(DataspacedAdmin):
"notes",
)

short_description = _("A component type provides a label to filter and sort components.")
short_description = _(
"A component type provides a label to filter and sort components.")

long_description = _(
"Your dataspace has the specific component types that meet the "
Expand All @@ -189,7 +191,8 @@ class BaseStatusAdmin(DataspacedAdmin):
"label",
"text",
)
fieldsets = (("", {"fields": ("label", "text", "default_on_addition", "dataspace", "uuid")}),)
fieldsets = (
("", {"fields": ("label", "text", "default_on_addition", "dataspace", "uuid")}),)


@admin.register(ComponentStatus, site=dejacode_site)
Expand All @@ -209,7 +212,8 @@ class ComponentStatusAdmin(BaseStatusAdmin):
class ComponentKeywordAdmin(DataspacedAdmin):
list_display = ("label", "description")
search_fields = ("label", "description")
fieldsets = (("", {"fields": ("label", "description", "dataspace", "uuid")}),)
fieldsets = (
("", {"fields": ("label", "description", "dataspace", "uuid")}),)
list_filter = DataspacedAdmin.list_filter + (MissingInFilter,)

short_description = _(
Expand Down Expand Up @@ -237,7 +241,8 @@ class AcceptableLinkageAdmin(DataspacedAdmin):
)
list_display = ("label", "description")
search_fields = ("label", "description")
fieldsets = (("", {"fields": ("label", "description", "dataspace", "uuid")}),)
fieldsets = (
("", {"fields": ("label", "description", "dataspace", "uuid")}),)

def get_readonly_fields(self, request, obj=None):
"""Force `label` as readonly on edit."""
Expand Down Expand Up @@ -273,7 +278,8 @@ class ComponentAdmin(
AsLink("owner"),
AsJoinList("keywords", "<br>", short_description="Keywords"),
"configuration_status",
AsLinkList("packages", "component", qs_limit=5, html_class="width300 word-break"),
AsLinkList("packages", "component", qs_limit=5,
html_class="width300 word-break"),
"cpe",
"project",
"is_active",
Expand Down Expand Up @@ -492,10 +498,13 @@ def response_change(self, request, obj):

for model_class, ids in errors.items():
opts = model_class._meta
url = reverse(f"admin:{opts.app_label}_{opts.model_name}_changelist")
href = "{}?{}".format(url, urlencode({"id__in": ",".join(str(id_) for id_ in ids)}))
url = reverse(
f"admin:{opts.app_label}_{opts.model_name}_changelist")
href = "{}?{}".format(url, urlencode(
{"id__in": ",".join(str(id_) for id_ in ids)}))
changelist_links.append(
CHANGELIST_LINK_TEMPLATE.format(href, len(ids), opts.verbose_name_plural)
CHANGELIST_LINK_TEMPLATE.format(
href, len(ids), opts.verbose_name_plural)
)

if changelist_links:
Expand All @@ -522,7 +531,8 @@ def get_urls(self):
urls = [
path(
"add_to_product/",
self.admin_site.admin_view(ComponentAddToProductAdminView.as_view()),
self.admin_site.admin_view(
ComponentAddToProductAdminView.as_view()),
name="{}_{}_add_to_product".format(*info),
),
path(
Expand All @@ -546,7 +556,8 @@ def set_policy(self, request, queryset):
def get_actions(self, request):
actions = super().get_actions(request)
is_another_dataspace = DataspaceFilter.parameter_name in request.GET
has_perm = request.user.has_perm("product_portfolio.add_productcomponent")
has_perm = request.user.has_perm(
"product_portfolio.add_productcomponent")
if (is_another_dataspace or not has_perm) and "add_to_product" in actions:
del actions["add_to_product"]
if is_another_dataspace and "set_policy" in actions:
Expand Down Expand Up @@ -584,7 +595,8 @@ def get_inline_formsets(self, request, formsets, inline_instances, obj=None):
inline_formset.
If not, the FormDataOutdated is raised to be catch in the changeform_view.
"""
inline_formsets = super().get_inline_formsets(request, formsets, inline_instances, obj)
inline_formsets = super().get_inline_formsets(
request, formsets, inline_instances, obj)

for inline_formset in inline_formsets:
if not inline_formset.formset.is_bound:
Expand Down Expand Up @@ -700,7 +712,8 @@ def get_urls(self):
urls = [
path(
"set_policy/",
self.admin_site.admin_view(SetSubcomponentPolicyView.as_view()),
self.admin_site.admin_view(
SetSubcomponentPolicyView.as_view()),
name="{}_{}_set_policy".format(*info),
),
]
Expand All @@ -727,7 +740,8 @@ def get_inline_instances(self, request, obj=None):
is_popup = any(
[
IS_POPUP_VAR in request.GET,
IS_POPUP_VAR in QueryDict(request.GET.get("_changelist_filters")),
IS_POPUP_VAR in QueryDict(
request.GET.get("_changelist_filters")),
]
)

Expand Down Expand Up @@ -926,7 +940,8 @@ def get_urls(self):
urls = [
path(
"add_to_product/",
self.admin_site.admin_view(PackageAddToProductAdminView.as_view()),
self.admin_site.admin_view(
PackageAddToProductAdminView.as_view()),
name="{}_{}_add_to_product".format(*info),
),
path(
Expand Down Expand Up @@ -1020,7 +1035,8 @@ def collect_data_action(self, request, queryset):
package.last_modified_by = request.user
package.save()
message = f'Data collected for: {", ".join(update_fields)}.'
History.log_change(request.user, package, message, serialized_data)
History.log_change(request.user, package,
message, serialized_data)
update_count += 1

not_updated = count - update_count
Expand Down
29 changes: 19 additions & 10 deletions component_catalog/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# Copyright (c) nexB Inc. and others. All rights reserved.
# DejaCode is a trademark of nexB Inc.
# SPDX-License-Identifier: AGPL-3.0-only
# See https://github.com/nexB/dejacode for support or download.
# See https://github.com/aboutcode-org/dejacode for support or download.
# See https://aboutcode.org for more information about AboutCode FOSS projects.
#

Expand Down Expand Up @@ -100,7 +100,8 @@ def get_license_choices(self, obj):
return []

all_licenses = License.objects.scope(obj.dataspace)
choice_licenses = get_license_objects(obj.license_choices_expression, all_licenses)
choice_licenses = get_license_objects(
obj.license_choices_expression, all_licenses)

return [
{"key": license.key, "short_name": license.short_name} for license in choice_licenses
Expand Down Expand Up @@ -176,7 +177,8 @@ def create_missing_keywords(self, keywords):
user = self.context["request"].user
dataspace = user.dataspace

qs = ComponentKeyword.objects.scope(dataspace).filter(label__in=keywords)
qs = ComponentKeyword.objects.scope(
dataspace).filter(label__in=keywords)
existing_labels = qs.values_list("label", flat=True)

for label in keywords:
Expand All @@ -190,7 +192,8 @@ def create_missing_keywords(self, keywords):
def run_child_validation(self, data):
result = super().run_child_validation(data)
if result:
result = [value for value in result if value != ""] # Clean empty string
# Clean empty string
result = [value for value in result if value != ""]
self.create_missing_keywords(keywords=result)
return result

Expand Down Expand Up @@ -251,11 +254,13 @@ class ComponentSerializer(
many=True,
read_only=True,
)
licenses_summary = serializers.SerializerMethodField(source="get_licenses_summary")
licenses_summary = serializers.SerializerMethodField(
source="get_licenses_summary")
license_choices_expression = serializers.SerializerMethodField(
source="get_license_choices_expression"
)
license_choices = serializers.SerializerMethodField(source="get_license_choices")
license_choices = serializers.SerializerMethodField(
source="get_license_choices")

class Meta:
model = Component
Expand Down Expand Up @@ -594,11 +599,13 @@ class PackageSerializer(
keywords = KeywordsField(
required=False,
)
licenses_summary = serializers.SerializerMethodField(source="get_licenses_summary")
licenses_summary = serializers.SerializerMethodField(
source="get_licenses_summary")
license_choices_expression = serializers.SerializerMethodField(
source="get_license_choices_expression"
)
license_choices = serializers.SerializerMethodField(source="get_license_choices")
license_choices = serializers.SerializerMethodField(
source="get_license_choices")
usage_policy = DataspacedSlugRelatedField(
slug_field="label",
allow_null=True,
Expand Down Expand Up @@ -700,7 +707,8 @@ def create(self, validated_data):

package_url = url2purl.get_purl(download_url)
if package_url:
collected_data.update(package_url.to_dict(encode=True, empty=""))
collected_data.update(
package_url.to_dict(encode=True, empty=""))

validated_data.update(collected_data)

Expand Down Expand Up @@ -806,7 +814,8 @@ class Meta:

def collect_create_scan(download_url, user):
dataspace = user.dataspace
package_qs = Package.objects.filter(download_url=download_url, dataspace=dataspace)
package_qs = Package.objects.filter(
download_url=download_url, dataspace=dataspace)
if package_qs.exists():
return False

Expand Down
2 changes: 1 addition & 1 deletion component_catalog/apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# Copyright (c) nexB Inc. and others. All rights reserved.
# DejaCode is a trademark of nexB Inc.
# SPDX-License-Identifier: AGPL-3.0-only
# See https://github.com/nexB/dejacode for support or download.
# See https://github.com/aboutcode-org/dejacode for support or download.
# See https://aboutcode.org for more information about AboutCode FOSS projects.
#

Expand Down
5 changes: 3 additions & 2 deletions component_catalog/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# Copyright (c) nexB Inc. and others. All rights reserved.
# DejaCode is a trademark of nexB Inc.
# SPDX-License-Identifier: AGPL-3.0-only
# See https://github.com/nexB/dejacode for support or download.
# See https://github.com/aboutcode-org/dejacode for support or download.
# See https://aboutcode.org for more information about AboutCode FOSS projects.
#

Expand Down Expand Up @@ -133,7 +133,8 @@ def queryset(self, request, queryset):
except Component.DoesNotExist as e:
raise IncorrectLookupParameters(e)

ids = list(instance.children.values_list("id", flat=True)) + [instance.id]
ids = list(instance.children.values_list(
"id", flat=True)) + [instance.id]
return queryset.filter(component__id__in=ids)


Expand Down
Loading

0 comments on commit 95058ba

Please sign in to comment.