Skip to content

Commit 505767b

Browse files
committed
Move the is_locked field on the ProductStatus model #310
Signed-off-by: tdruez <[email protected]>
1 parent 5c6189e commit 505767b

File tree

9 files changed

+34
-30
lines changed

9 files changed

+34
-30
lines changed

component_catalog/forms.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -624,9 +624,10 @@ def __init__(self, user, *args, **kwargs):
624624
super().__init__(user, *args, **kwargs)
625625

626626
product_field = self.fields["product"]
627-
perms = ["view_product", "change_product"]
628-
product_field.queryset = Product.objects.get_queryset(user, perms=perms).filter(
629-
is_locked=False
627+
product_field.queryset = Product.objects.get_queryset(
628+
user=user,
629+
perms=["view_product", "change_product"],
630+
exclude_locked=True,
630631
)
631632

632633
if relation_instance:
@@ -710,11 +711,11 @@ def __init__(self, request, model, relation_model, *args, **kwargs):
710711
self.model = model
711712
self.relation_model = relation_model
712713
self.dataspace = request.user.dataspace
713-
product_qs = Product.objects.get_queryset(
714+
self.fields["product"].queryset = Product.objects.get_queryset(
714715
user=request.user,
715716
perms=["view_product", "change_product"],
717+
exclude_locked=True,
716718
)
717-
self.fields["product"].queryset = product_qs.filter(is_locked=False)
718719

719720
def get_selected_objects(self):
720721
ids = self.initial.get("ids") or self.cleaned_data["ids"]

dje/tests/testfiles/test_dataset_pp_only.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,8 @@
6161
"default_on_addition": false,
6262
"label": "Approved",
6363
"text": "Approved",
64-
"request_to_generate": null
64+
"request_to_generate": null,
65+
"is_locked": false
6566
}
6667
},
6768
{
@@ -94,7 +95,6 @@
9495
"notice_text": "Starship Widget Framework (SWF) \nis an adaptation of the open source\nOZONE Widget Framework (OWF)\n\nPortions of this software were developed under contract to the U.S. Government, and are made available pursuant to the DFARS clauses cited below.\n\nCopyright 2009-2012, Next Century Corporation.\nThe U.S. Government has Unlimited Rights in this computer software pursuant to\nthe clause DFARS 252.227-7014 of contract no. H98230-07-C-0614. Any\nreproduction of this computer software, or portions thereof, marked with this\nlegend must also reproduce these markings.\n\nCopyright 2009-2010, Texeltek Inc.\nThe U.S. Government has Unlimited Rights in this computer software pursuant to\nthe clause DFARS 252.227-7014 of contract no. H98230-07-C-0046. Any\nreproduction of this computer software, or portions thereof, marked with this\nlegend must also reproduce these markings.\n\nThis product further may include software developed by other individuals, entities, or agencies. These groups have granted rights to the OWFGOSS Board to apply that code in the OWF or Marketplace code baselines, without further claim or copyright.\n\nThe product further references the following libraries or capabilities which are NOT included as part of this copyright statement, and are hereby listed with their license terms.\n* Ext JS, developed by Sencha, licensed under GNU General Public License, Version 3, http://www.gnu.org/licenses/gpl.html \n* Grails and its supporting capabilities, including Groovy, Hibernate, and Spring. Available at grails.org, licensed Apache License, Version 2.0, http://grails.org/License\n* YUI Compressor Javascript/CSS compressor , http://yuilibrary.com/license/ (based on BSD license)\n* Dojo cross-domain library, Dojo BSD License, http://dojotoolkit.org/license\n* Shindig messaging library, http://shindig.apache.org/, Apache License, Version 2.0, http://www.apache.org/licenses/\n* JQuery Ajax/eventing library, http://jquery.com, based on MIT License, https://raw.github.com/jquery/jquery/master/MIT-LICENSE.txt\n* Spring Security jars, licensed under Apache License, Version 2, http://www.apache.org/licenses/ \n* log4javascript logging library, http://log4javascript.org, Apache License, Version 2.0, http://www.apache.org/licenses/\n* stubconsole logging utility, http://getfirebug.com/firebug/firebugx.js, Firebug BSD License, http://fbug.googlecode.com/svn/trunk/license.txt\n* UXMedia, Ext Flash / Flex components, see http://code.google.com/p/uxmedia. GNU General Public License, Version 3, http://www.gnu.org/licenses/gpl.html \n",
9596
"license_expression": "commercial-option",
9697
"is_active": true,
97-
"is_locked": false,
9898
"configuration_status": [
9999
"nexB",
100100
"addd9c5d-a5ec-48ec-a565-ddb81092f49d"

product_portfolio/admin.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ class ProductStatusAdmin(BaseStatusAdmin):
8888
"label",
8989
"text",
9090
"default_on_addition",
91+
"is_locked",
9192
"request_to_generate",
9293
"get_dataspace",
9394
)
@@ -99,6 +100,7 @@ class ProductStatusAdmin(BaseStatusAdmin):
99100
"label",
100101
"text",
101102
"default_on_addition",
103+
"is_locked",
102104
"request_to_generate",
103105
"dataspace",
104106
"uuid",
@@ -317,7 +319,6 @@ class ProductAdmin(
317319
AsLink("owner"),
318320
AsJoinList("keywords", "<br>", short_description="Keywords"),
319321
"is_active",
320-
"is_locked",
321322
"configuration_status",
322323
"primary_language",
323324
"contact",
@@ -333,7 +334,6 @@ class ProductAdmin(
333334
ReportingQueryListFilter,
334335
("configuration_status", LimitToDataspaceListFilter),
335336
"is_active",
336-
"is_locked",
337337
)
338338
search_fields = (
339339
"name",
@@ -366,7 +366,6 @@ class ProductAdmin(
366366
"primary_language",
367367
"admin_notes",
368368
"is_active",
369-
"is_locked",
370369
"configuration_status",
371370
"contact",
372371
"vulnerabilities_risk_threshold",

product_portfolio/api.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,6 @@ class Meta:
119119
"name",
120120
"version",
121121
"owner",
122-
"is_locked",
123122
"configuration_status",
124123
"license_expression",
125124
"licenses",

product_portfolio/filters.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,6 @@ class Meta:
126126
"primary_language",
127127
"configuration_status",
128128
"keywords",
129-
"is_locked",
130129
]
131130

132131

product_portfolio/forms.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,6 @@ class Meta:
123123
"homepage_url",
124124
"primary_language",
125125
"is_active",
126-
"is_locked",
127126
"configuration_status",
128127
"contact",
129128
"keywords",
@@ -178,7 +177,7 @@ def helper(self):
178177
Group("description", "keywords"),
179178
Group("primary_language", "homepage_url", "contact"),
180179
HTML("<hr>"),
181-
Group("is_active", "is_locked", "configuration_status", "release_date"),
180+
Group("is_active", "configuration_status", "release_date"),
182181
HTML("<hr>"),
183182
Group("vulnerabilities_risk_threshold", HTML(""), HTML("")),
184183
HTML("<hr>"),
@@ -251,7 +250,6 @@ class Meta:
251250
"primary_language",
252251
"admin_notes",
253252
"is_active",
254-
"is_locked",
255253
"configuration_status",
256254
"contact",
257255
"vcs_url",

product_portfolio/migrations/0013_product_is_locked_and_more.py renamed to product_portfolio/migrations/0013_productstatus_is_locked_and_more.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Generated by Django 5.1.9 on 2025-05-30 07:11
1+
# Generated by Django 5.1.9 on 2025-05-30 14:30
22

33
import django.db.models.deletion
44
from django.db import migrations, models
@@ -13,9 +13,9 @@ class Migration(migrations.Migration):
1313

1414
operations = [
1515
migrations.AddField(
16-
model_name='product',
16+
model_name='productstatus',
1717
name='is_locked',
18-
field=models.BooleanField(db_index=True, default=False, help_text='Marks this product version as read-only, preventing any modifications to its inventory.', verbose_name='Locked'),
18+
field=models.BooleanField(db_index=True, default=False, help_text='Marks this product version as read-only, preventing any modifications to its inventory.', verbose_name='Locked inventory'),
1919
),
2020
migrations.AlterField(
2121
model_name='productdependency',

product_portfolio/models.py

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,15 @@ class ProductStatus(BaseStatusMixin, DataspacedModel):
115115
"fields, since DejaCode will be creating the Request automatically."
116116
),
117117
)
118+
is_locked = models.BooleanField(
119+
verbose_name=_("Locked inventory"),
120+
default=False,
121+
db_index=True,
122+
help_text=_(
123+
"Marks this product version as read-only, preventing any modifications to "
124+
"its inventory."
125+
),
126+
)
118127

119128
class Meta(BaseStatusMixin.Meta):
120129
verbose_name_plural = _("product status")
@@ -141,7 +150,9 @@ def get_by_natural_key(self, dataspace_name, uuid):
141150
"""
142151
return self.model.unsecured_objects.get(dataspace__name=dataspace_name, uuid=uuid)
143152

144-
def get_queryset(self, user=None, perms="view_product", include_inactive=False):
153+
def get_queryset(
154+
self, user=None, perms="view_product", include_inactive=False, exclude_locked=False
155+
):
145156
"""
146157
Force the object level protection at the QuerySet level.
147158
Always Return an empty QuerySet unless a `user` is provided.
@@ -162,6 +173,9 @@ def get_queryset(self, user=None, perms="view_product", include_inactive=False):
162173
user, perms, klass=queryset_class, accept_global_perms=False
163174
).scope(user.dataspace)
164175

176+
if exclude_locked:
177+
queryset = queryset.exclude(configuration_status__is_locked=True)
178+
165179
if include_inactive:
166180
return queryset
167181

@@ -221,16 +235,6 @@ class Product(BaseProductMixin, FieldChangesMixin, KeywordsMixin, DataspacedMode
221235
),
222236
)
223237

224-
is_locked = models.BooleanField(
225-
verbose_name=_("Locked"),
226-
default=False,
227-
db_index=True,
228-
help_text=_(
229-
"Marks this product version as read-only, preventing any modifications to "
230-
"its inventory."
231-
),
232-
)
233-
234238
configuration_status = models.ForeignKey(
235239
to="product_portfolio.ProductStatus",
236240
on_delete=models.PROTECT,
@@ -360,6 +364,11 @@ def actions_on_status_change(self):
360364
object_id=self.id,
361365
)
362366

367+
@cached_property
368+
def is_locked(self):
369+
if self.configuration_status_id:
370+
return self.configuration_status.is_locked
371+
363372
@cached_property
364373
def all_packages(self):
365374
return Package.objects.filter(

product_portfolio/views.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,6 @@ def get_queryset(self):
194194
"primary_language",
195195
"keywords",
196196
"configuration_status",
197-
"is_locked",
198197
"request_count",
199198
"dataspace",
200199
)

0 commit comments

Comments
 (0)