37
37
from dojo .engagement .queries import get_authorized_engagements
38
38
from dojo .finding .queries import get_authorized_findings
39
39
from dojo .group .queries import get_authorized_groups , get_group_member_roles
40
+ from dojo .labels import get_labels
40
41
from dojo .models import (
41
42
EFFORT_FOR_FIXING_CHOICES ,
42
43
SEVERITY_CHOICES ,
118
119
119
120
logger = logging .getLogger (__name__ )
120
121
122
+ labels = get_labels ()
123
+
121
124
RE_DATE = re .compile (r"(\d{4})-(\d\d?)-(\d\d?)$" )
122
125
123
126
FINDING_STATUS = (("verified" , "Verified" ),
@@ -244,6 +247,11 @@ class Product_TypeForm(forms.ModelForm):
244
247
description = forms .CharField (widget = forms .Textarea (attrs = {}),
245
248
required = False )
246
249
250
+ def __init__ (self , * args , ** kwargs ):
251
+ super ().__init__ (* args , ** kwargs )
252
+ self .fields ["critical_product" ].label = labels .ORG_CRITICAL_PRODUCT_LABEL
253
+ self .fields ["key_product" ].label = labels .ORG_KEY_PRODUCT_LABEL
254
+
247
255
class Meta :
248
256
model = Product_Type
249
257
fields = ["name" , "description" , "critical_product" , "key_product" ]
@@ -280,6 +288,7 @@ def __init__(self, *args, **kwargs):
280
288
self .fields ["users" ].queryset = Dojo_User .objects .exclude (
281
289
Q (is_superuser = True )
282
290
| Q (id__in = current_members )).exclude (is_active = False ).order_by ("first_name" , "last_name" )
291
+ self .fields ["product_type" ].label = labels .ORG_LABEL
283
292
self .fields ["product_type" ].disabled = True
284
293
285
294
class Meta :
@@ -288,13 +297,14 @@ class Meta:
288
297
289
298
290
299
class Add_Product_Type_Member_UserForm (forms .ModelForm ):
291
- product_types = forms .ModelMultipleChoiceField (queryset = Product_Type .objects .none (), required = True , label = "Product Types" )
300
+ product_types = forms .ModelMultipleChoiceField (queryset = Product_Type .objects .none (), required = True )
292
301
293
302
def __init__ (self , * args , ** kwargs ):
294
303
super ().__init__ (* args , ** kwargs )
295
304
current_members = Product_Type_Member .objects .filter (user = self .initial ["user" ]).values_list ("product_type" , flat = True )
296
305
self .fields ["product_types" ].queryset = get_authorized_product_types (Permissions .Product_Type_Member_Add_Owner ) \
297
306
.exclude (id__in = current_members )
307
+ self .fields ["product_types" ].label = labels .ORG_PLURAL_LABEL
298
308
self .fields ["user" ].disabled = True
299
309
300
310
class Meta :
@@ -306,6 +316,7 @@ class Delete_Product_Type_MemberForm(Edit_Product_Type_MemberForm):
306
316
def __init__ (self , * args , ** kwargs ):
307
317
super ().__init__ (* args , ** kwargs )
308
318
self .fields ["role" ].disabled = True
319
+ self .fields ["product_type" ].label = labels .ORG_LABEL
309
320
310
321
311
322
class Test_TypeForm (forms .ModelForm ):
@@ -331,8 +342,7 @@ class ProductForm(forms.ModelForm):
331
342
description = forms .CharField (widget = forms .Textarea (attrs = {}),
332
343
required = True )
333
344
334
- prod_type = forms .ModelChoiceField (label = "Product Type" ,
335
- queryset = Product_Type .objects .none (),
345
+ prod_type = forms .ModelChoiceField (queryset = Product_Type .objects .none (),
336
346
required = True )
337
347
338
348
sla_configuration = forms .ModelChoiceField (label = "SLA Configuration" ,
@@ -347,6 +357,10 @@ class ProductForm(forms.ModelForm):
347
357
def __init__ (self , * args , ** kwargs ):
348
358
super ().__init__ (* args , ** kwargs )
349
359
self .fields ["prod_type" ].queryset = get_authorized_product_types (Permissions .Product_Type_Add_Product )
360
+ self .fields ["prod_type" ].label = labels .ORG_LABEL
361
+ self .fields ["product_manager" ].label = labels .ASSET_MANAGER_LABEL
362
+ self .fields ["enable_product_tag_inheritance" ].label = labels .ASSET_TAG_INHERITANCE_ENABLE_LABEL
363
+ self .fields ["enable_product_tag_inheritance" ].help_text = labels .ASSET_TAG_INHERITANCE_ENABLE_HELP
350
364
if prod_type_id := kwargs .get ("instance" , Product ()).prod_type_id : # we are editing existing instance
351
365
self .fields ["prod_type" ].queryset |= Product_Type .objects .filter (pk = prod_type_id ) # even if user does not have permission for any other ProdType we need to add at least assign ProdType to make form submittable (otherwise empty list was here which generated invalid form)
352
366
@@ -415,6 +429,7 @@ class Edit_Product_MemberForm(forms.ModelForm):
415
429
def __init__ (self , * args , ** kwargs ):
416
430
super ().__init__ (* args , ** kwargs )
417
431
self .fields ["product" ].disabled = True
432
+ self .fields ["product" ].label = labels .ASSET_LABEL
418
433
self .fields ["user" ].queryset = Dojo_User .objects .order_by ("first_name" , "last_name" )
419
434
self .fields ["user" ].disabled = True
420
435
@@ -429,6 +444,7 @@ class Add_Product_MemberForm(forms.ModelForm):
429
444
def __init__ (self , * args , ** kwargs ):
430
445
super ().__init__ (* args , ** kwargs )
431
446
self .fields ["product" ].disabled = True
447
+ self .fields ["product" ].label = labels .ASSET_LABEL
432
448
current_members = Product_Member .objects .filter (product = self .initial ["product" ]).values_list ("user" , flat = True )
433
449
self .fields ["users" ].queryset = Dojo_User .objects .exclude (
434
450
Q (is_superuser = True )
@@ -440,13 +456,14 @@ class Meta:
440
456
441
457
442
458
class Add_Product_Member_UserForm (forms .ModelForm ):
443
- products = forms .ModelMultipleChoiceField (queryset = Product .objects .none (), required = True , label = "Products" )
459
+ products = forms .ModelMultipleChoiceField (queryset = Product .objects .none (), required = True )
444
460
445
461
def __init__ (self , * args , ** kwargs ):
446
462
super ().__init__ (* args , ** kwargs )
447
463
current_members = Product_Member .objects .filter (user = self .initial ["user" ]).values_list ("product" , flat = True )
448
464
self .fields ["products" ].queryset = get_authorized_products (Permissions .Product_Member_Add_Owner ) \
449
465
.exclude (id__in = current_members )
466
+ self .fields ["products" ].label = labels .ASSET_PLURAL_LABEL
450
467
self .fields ["user" ].disabled = True
451
468
452
469
class Meta :
@@ -608,6 +625,9 @@ def __init__(self, *args, **kwargs):
608
625
choices .insert (0 , ("" , "---------" ))
609
626
self .fields ["group_by" ].choices = choices
610
627
628
+ self .fields ["close_old_findings_product_scope" ].label = labels .ASSET_FINDINGS_CLOSE_LABEL
629
+ self .fields ["close_old_findings_product_scope" ].help_text = labels .ASSET_FINDINGS_CLOSE_HELP
630
+
611
631
self .endpoints_to_add_list = []
612
632
613
633
def clean (self ):
@@ -1003,9 +1023,8 @@ class EngForm(forms.ModelForm):
1003
1023
))
1004
1024
description = forms .CharField (widget = forms .Textarea (attrs = {}),
1005
1025
required = False , help_text = "Description of the engagement and details regarding the engagement." )
1006
- product = forms .ModelChoiceField (label = "Product" ,
1007
- queryset = Product .objects .none (),
1008
- required = True )
1026
+ product = forms .ModelChoiceField (queryset = Product .objects .none (),
1027
+ required = True )
1009
1028
target_start = forms .DateField (widget = forms .TextInput (
1010
1029
attrs = {"class" : "datepicker" , "autocomplete" : "off" }))
1011
1030
target_end = forms .DateField (widget = forms .TextInput (
@@ -1037,6 +1056,7 @@ def __init__(self, *args, **kwargs):
1037
1056
self .fields ["lead" ].queryset = get_authorized_users (Permissions .Engagement_View ).filter (is_active = True )
1038
1057
1039
1058
self .fields ["product" ].queryset = get_authorized_products (Permissions .Engagement_Add )
1059
+ self .fields ["product" ].label = labels .ASSET_LABEL
1040
1060
1041
1061
# Don't show CICD fields on a interactive engagement
1042
1062
if cicd is False :
@@ -1778,8 +1798,7 @@ class AddEndpointForm(forms.Form):
1778
1798
"Each must be valid." ,
1779
1799
widget = forms .widgets .Textarea (attrs = {"rows" : "15" , "cols" : "400" }))
1780
1800
product = forms .CharField (required = True ,
1781
- widget = forms .widgets .HiddenInput (), help_text = "The product this endpoint should be "
1782
- "associated with." )
1801
+ widget = forms .widgets .HiddenInput ())
1783
1802
tags = TagField (required = False ,
1784
1803
help_text = "Add tags that help describe this endpoint. "
1785
1804
"Choose from the list or add new tags. Press Enter key to add." )
@@ -1789,7 +1808,10 @@ def __init__(self, *args, **kwargs):
1789
1808
if "product" in kwargs :
1790
1809
product = kwargs .pop ("product" )
1791
1810
super ().__init__ (* args , ** kwargs )
1792
- self .fields ["product" ] = forms .ModelChoiceField (queryset = get_authorized_products (Permissions .Endpoint_Add ))
1811
+ self .fields ["product" ] = forms .ModelChoiceField (
1812
+ queryset = get_authorized_products (Permissions .Endpoint_Add ),
1813
+ label = labels .ASSET_LABEL ,
1814
+ help_text = labels .ASSET_ENDPOINT_HELP )
1793
1815
if product is not None :
1794
1816
self .fields ["product" ].initial = product .id
1795
1817
@@ -2196,6 +2218,7 @@ class Add_Product_GroupForm(forms.ModelForm):
2196
2218
def __init__ (self , * args , ** kwargs ):
2197
2219
super ().__init__ (* args , ** kwargs )
2198
2220
self .fields ["product" ].disabled = True
2221
+ self .fields ["product" ].label = labels .ASSET_LABEL
2199
2222
current_groups = Product_Group .objects .filter (product = self .initial ["product" ]).values_list ("group" , flat = True )
2200
2223
authorized_groups = get_authorized_groups (Permissions .Group_View )
2201
2224
authorized_groups = authorized_groups .exclude (id__in = current_groups )
@@ -2207,13 +2230,14 @@ class Meta:
2207
2230
2208
2231
2209
2232
class Add_Product_Group_GroupForm (forms .ModelForm ):
2210
- products = forms .ModelMultipleChoiceField (queryset = Product .objects .none (), required = True , label = "Products" )
2233
+ products = forms .ModelMultipleChoiceField (queryset = Product .objects .none (), required = True )
2211
2234
2212
2235
def __init__ (self , * args , ** kwargs ):
2213
2236
super ().__init__ (* args , ** kwargs )
2214
2237
current_members = Product_Group .objects .filter (group = self .initial ["group" ]).values_list ("product" , flat = True )
2215
2238
self .fields ["products" ].queryset = get_authorized_products (Permissions .Product_Member_Add_Owner ) \
2216
2239
.exclude (id__in = current_members )
2240
+ self .fields ["products" ].label = labels .ASSET_PLURAL_LABEL
2217
2241
self .fields ["group" ].disabled = True
2218
2242
2219
2243
class Meta :
@@ -2226,6 +2250,7 @@ class Edit_Product_Group_Form(forms.ModelForm):
2226
2250
def __init__ (self , * args , ** kwargs ):
2227
2251
super ().__init__ (* args , ** kwargs )
2228
2252
self .fields ["product" ].disabled = True
2253
+ self .fields ["product" ].label = labels .ASSET_LABEL
2229
2254
self .fields ["group" ].disabled = True
2230
2255
2231
2256
class Meta :
@@ -2249,20 +2274,22 @@ def __init__(self, *args, **kwargs):
2249
2274
authorized_groups = authorized_groups .exclude (id__in = current_groups )
2250
2275
self .fields ["groups" ].queryset = authorized_groups
2251
2276
self .fields ["product_type" ].disabled = True
2277
+ self .fields ["product_type" ].label = labels .ORG_LABEL
2252
2278
2253
2279
class Meta :
2254
2280
model = Product_Type_Group
2255
2281
fields = ["product_type" , "groups" , "role" ]
2256
2282
2257
2283
2258
2284
class Add_Product_Type_Group_GroupForm (forms .ModelForm ):
2259
- product_types = forms .ModelMultipleChoiceField (queryset = Product_Type .objects .none (), required = True , label = "Product Types" )
2285
+ product_types = forms .ModelMultipleChoiceField (queryset = Product_Type .objects .none (), required = True )
2260
2286
2261
2287
def __init__ (self , * args , ** kwargs ):
2262
2288
super ().__init__ (* args , ** kwargs )
2263
2289
current_members = Product_Type_Group .objects .filter (group = self .initial ["group" ]).values_list ("product_type" , flat = True )
2264
2290
self .fields ["product_types" ].queryset = get_authorized_product_types (Permissions .Product_Type_Member_Add_Owner ) \
2265
2291
.exclude (id__in = current_members )
2292
+ self .fields ["product_types" ].label = labels .ORG_PLURAL_LABEL
2266
2293
self .fields ["group" ].disabled = True
2267
2294
2268
2295
class Meta :
@@ -2275,6 +2302,7 @@ class Edit_Product_Type_Group_Form(forms.ModelForm):
2275
2302
def __init__ (self , * args , ** kwargs ):
2276
2303
super ().__init__ (* args , ** kwargs )
2277
2304
self .fields ["product_type" ].disabled = True
2305
+ self .fields ["product_type" ].label = labels .ORG_LABEL
2278
2306
self .fields ["group" ].disabled = True
2279
2307
2280
2308
class Meta :
@@ -2415,6 +2443,7 @@ class Meta:
2415
2443
def __init__ (self , * args , ** kwargs ):
2416
2444
super ().__init__ (* args , ** kwargs )
2417
2445
current_user = get_current_user ()
2446
+ self .fields ["role" ].help_text = labels .ASSET_GLOBAL_ROLE_HELP
2418
2447
if not current_user .is_superuser :
2419
2448
self .fields ["role" ].disabled = True
2420
2449
@@ -2440,6 +2469,7 @@ class ProductTypeCountsForm(ProductCountsFormBase):
2440
2469
def __init__ (self , * args , ** kwargs ):
2441
2470
super ().__init__ (* args , ** kwargs )
2442
2471
self .fields ["product_type" ].queryset = get_authorized_product_types (Permissions .Product_Type_View )
2472
+ self .fields ["product_type" ].label = labels .ORG_LABEL
2443
2473
2444
2474
2445
2475
class ProductTagCountsForm (ProductCountsFormBase ):
@@ -2453,6 +2483,7 @@ def __init__(self, *args, **kwargs):
2453
2483
prods = get_authorized_products (Permissions .Product_View )
2454
2484
tags_available_to_user = Product .tags .tag_model .objects .filter (product__in = prods )
2455
2485
self .fields ["product_tag" ].queryset = tags_available_to_user
2486
+ self .fields ["product_tag" ].label = labels .ASSET_TAG_LABEL
2456
2487
2457
2488
2458
2489
class APIKeyForm (forms .ModelForm ):
@@ -2933,6 +2964,20 @@ def __init__(self, *args, **kwargs):
2933
2964
super ().__init__ (* args , ** kwargs )
2934
2965
self .fields ["default_group_role" ].queryset = get_group_member_roles ()
2935
2966
2967
+ self .fields ["enable_product_tracking_files" ].label = labels .SETTINGS_TRACKED_FILES_ENABLE_LABEL
2968
+ self .fields ["enable_product_tracking_files" ].help_text = labels .SETTINGS_TRACKED_FILES_ENABLE_HELP
2969
+
2970
+ self .fields [
2971
+ "enforce_verified_status_product_grading" ].label = labels .SETTINGS_ASSET_GRADING_ENFORCE_VERIFIED_LABEL
2972
+ self .fields [
2973
+ "enforce_verified_status_product_grading" ].help_text = labels .SETTINGS_ASSET_GRADING_ENFORCE_VERIFIED_HELP
2974
+
2975
+ self .fields ["enable_product_grade" ].label = labels .SETTINGS_ASSET_GRADING_ENABLE_LABEL
2976
+ self .fields ["enable_product_grade" ].help_text = labels .SETTINGS_ASSET_GRADING_ENABLE_HELP
2977
+
2978
+ self .fields ["enable_product_tag_inheritance" ].label = labels .SETTINGS_ASSET_TAG_INHERITANCE_ENABLE_LABEL
2979
+ self .fields ["enable_product_tag_inheritance" ].help_text = labels .SETTINGS_ASSET_TAG_INHERITANCE_ENABLE_HELP
2980
+
2936
2981
def clean (self ):
2937
2982
cleaned_data = super ().clean ()
2938
2983
enable_jira_value = cleaned_data .get ("enable_jira" )
0 commit comments