diff --git a/dojo/api_v2/prefetch/schema.py b/dojo/api_v2/prefetch/schema.py index 21791f8daab..86078a86317 100644 --- a/dojo/api_v2/prefetch/schema.py +++ b/dojo/api_v2/prefetch/schema.py @@ -1,5 +1,5 @@ from .prefetcher import _Prefetcher -from .utils import _get_prefetchable_fields +from .utils import get_prefetchable_fields def _get_path_to_GET_serializer_map(generator): @@ -53,7 +53,7 @@ def prefetch_postprocessing_hook(result, generator, request, public): if parameter["name"] == "prefetch": prefetcher = _Prefetcher() - fields = _get_prefetchable_fields( + fields = get_prefetchable_fields( serializer_classes[path](), ) diff --git a/dojo/api_v2/prefetch/utils.py b/dojo/api_v2/prefetch/utils.py index eefb1b642ec..2c2546f9e03 100644 --- a/dojo/api_v2/prefetch/utils.py +++ b/dojo/api_v2/prefetch/utils.py @@ -33,7 +33,7 @@ def _is_one_to_one_relation(field): return isinstance(field, related.ForwardManyToOneDescriptor) -def _get_prefetchable_fields(serializer): +def get_prefetchable_fields(serializer): """ Get the fields that are prefetchable according to the serializer description. Method mainly used by for automatic schema generation. diff --git a/dojo/endpoint/utils.py b/dojo/endpoint/utils.py index 10646ba265c..2cc835aa974 100644 --- a/dojo/endpoint/utils.py +++ b/dojo/endpoint/utils.py @@ -10,7 +10,7 @@ from django.db.models import Count, Q from django.http import HttpResponseRedirect from django.urls import reverse -from hyperlink._url import SCHEME_PORT_MAP +from hyperlink._url import SCHEME_PORT_MAP # noqa: PLC2701 from dojo.models import DojoMeta, Endpoint diff --git a/dojo/models.py b/dojo/models.py index 741f630fb92..d5b672c53c7 100644 --- a/dojo/models.py +++ b/dojo/models.py @@ -129,7 +129,7 @@ def _manage_inherited_tags(obj, incoming_inherited_tags, potentially_existing_ta obj.tags.set(cleaned_tag_list) -def _copy_model_util(model_in_database, exclude_fields: list[str] | None = None): +def copy_model_util(model_in_database, exclude_fields: list[str] | None = None): if exclude_fields is None: exclude_fields = [] new_model_instance = model_in_database.__class__() @@ -750,7 +750,7 @@ class NoteHistory(models.Model): current_editor = models.ForeignKey(Dojo_User, editable=False, null=True, on_delete=models.CASCADE) def copy(self): - copy = _copy_model_util(self) + copy = copy_model_util(self) copy.save() return copy @@ -776,7 +776,7 @@ def __str__(self): return self.entry def copy(self): - copy = _copy_model_util(self) + copy = copy_model_util(self) # Save the necessary ManyToMany relationships old_history = list(self.history.all()) # Save the object before setting any ManyToMany relationships @@ -801,7 +801,7 @@ def delete(self, *args, **kwargs): storage.delete(path) def copy(self): - copy = _copy_model_util(self) + copy = copy_model_util(self) # Add unique modifier to file name copy.title = f"{self.title} - clone-{str(uuid4())[:8]}" # Create new unique file name @@ -1581,7 +1581,7 @@ def get_absolute_url(self): return reverse("view_engagement", args=[str(self.id)]) def copy(self): - copy = _copy_model_util(self) + copy = copy_model_util(self) # Save the necessary ManyToMany relationships old_notes = list(self.notes.all()) old_files = list(self.files.all()) @@ -1699,7 +1699,7 @@ def __str__(self): return f"'{self.finding}' on '{self.endpoint}'" def copy(self, finding=None): - copy = _copy_model_util(self) + copy = copy_model_util(self) current_endpoint = self.endpoint if finding: copy.finding = finding @@ -2161,7 +2161,7 @@ def get_breadcrumbs(self): return bc def copy(self, engagement=None): - copy = _copy_model_util(self) + copy = copy_model_util(self) # Save the necessary ManyToMany relationships old_notes = list(self.notes.all()) old_files = list(self.files.all()) @@ -2827,7 +2827,7 @@ def get_absolute_url(self): return reverse("view_finding", args=[str(self.id)]) def copy(self, test=None): - copy = _copy_model_util(self) + copy = copy_model_util(self) # Save the necessary ManyToMany relationships old_notes = list(self.notes.all()) old_files = list(self.files.all()) @@ -3804,7 +3804,7 @@ def engagement(self): return None def copy(self, engagement=None): - copy = _copy_model_util(self) + copy = copy_model_util(self) # Save the necessary ManyToMany relationships old_notes = list(self.notes.all()) old_accepted_findings_hash_codes = [finding.hash_code for finding in self.accepted_findings.all()] diff --git a/dojo/tools/nexpose/parser.py b/dojo/tools/nexpose/parser.py index d7f197d2b21..9c03ba8f277 100644 --- a/dojo/tools/nexpose/parser.py +++ b/dojo/tools/nexpose/parser.py @@ -4,7 +4,7 @@ import html2text from defusedxml import ElementTree from django.conf import settings -from hyperlink._url import SCHEME_PORT_MAP +from hyperlink._url import SCHEME_PORT_MAP # noqa: PLC2701 from dojo.models import Endpoint, Finding diff --git a/dojo/tools/tenable/xml_format.py b/dojo/tools/tenable/xml_format.py index 53f82a440ac..7bbf36baa66 100644 --- a/dojo/tools/tenable/xml_format.py +++ b/dojo/tools/tenable/xml_format.py @@ -3,7 +3,7 @@ from cvss import CVSS3 from defusedxml import ElementTree -from hyperlink._url import SCHEME_PORT_MAP +from hyperlink._url import SCHEME_PORT_MAP # noqa: PLC2701 from dojo.models import Endpoint, Finding, Test diff --git a/ruff.toml b/ruff.toml index 092bd58fee0..713ca372a66 100644 --- a/ruff.toml +++ b/ruff.toml @@ -82,7 +82,7 @@ select = [ "D2", "D3", "D402", "D403", "D405", "D406", "D407", "D408", "D409", "D410", "D411", "D412", "D413", "D414", "D416", "F", "PGH", - "PLC0", "PLC1", "PLC24", "PLC28", "PLC3", + "PLC", "PLE", "PLR01", "PLR02", "PLR04", "PLR0915", "PLR1711", "PLR1704", "PLR1714", "PLR1716", "PLR172", "PLR173", "PLR2044", "PLR5", "PLR6104", "PLR6201", "PLW", diff --git a/unittests/test_deduplication_logic.py b/unittests/test_deduplication_logic.py index 82ecfb177dd..9ea9ba713a4 100644 --- a/unittests/test_deduplication_logic.py +++ b/unittests/test_deduplication_logic.py @@ -13,7 +13,7 @@ System_Settings, Test, User, - _copy_model_util, + copy_model_util, ) from .dojo_test_case import DojoTestCase @@ -1199,7 +1199,7 @@ def log_summary(self, product=None, engagement=None, test=None): def copy_and_reset_finding(self, find_id): org = Finding.objects.get(id=find_id) - new = _copy_model_util(org) + new = copy_model_util(org) new.duplicate = False new.duplicate_finding = None new.active = True @@ -1236,13 +1236,13 @@ def copy_and_reset_finding_add_endpoints(self, find_id, *, static=False, dynamic def copy_and_reset_test(self, test_id): org = Test.objects.get(id=test_id) - new = _copy_model_util(org) + new = copy_model_util(org) # return unsaved new finding and reloaded existing finding return new, Test.objects.get(id=test_id) def copy_and_reset_engagement(self, eng_id): org = Engagement.objects.get(id=eng_id) - new = _copy_model_util(org) + new = copy_model_util(org) # return unsaved new finding and reloaded existing finding return new, Engagement.objects.get(id=eng_id) diff --git a/unittests/test_duplication_loops.py b/unittests/test_duplication_loops.py index cc0d250774e..d85e52e1046 100644 --- a/unittests/test_duplication_loops.py +++ b/unittests/test_duplication_loops.py @@ -4,7 +4,7 @@ from django.test.utils import override_settings from dojo.management.commands.fix_loop_duplicates import fix_loop_duplicates -from dojo.models import Engagement, Finding, Product, User, _copy_model_util +from dojo.models import Engagement, Finding, Product, User, copy_model_util from dojo.utils import set_duplicate from .dojo_test_case import DojoTestCase @@ -27,19 +27,19 @@ def run(self, result=None): super().run(result) def setUp(self): - self.finding_a = _copy_model_util(Finding.objects.get(id=2), exclude_fields=["duplicate_finding"]) + self.finding_a = copy_model_util(Finding.objects.get(id=2), exclude_fields=["duplicate_finding"]) self.finding_a.title = "A: " + self.finding_a.title self.finding_a.duplicate = False self.finding_a.hash_code = None self.finding_a.save() - self.finding_b = _copy_model_util(Finding.objects.get(id=3), exclude_fields=["duplicate_finding"]) + self.finding_b = copy_model_util(Finding.objects.get(id=3), exclude_fields=["duplicate_finding"]) self.finding_b.title = "B: " + self.finding_b.title self.finding_b.duplicate = False self.finding_b.hash_code = None self.finding_b.save() - self.finding_c = _copy_model_util(Finding.objects.get(id=4), exclude_fields=["duplicate_finding"]) + self.finding_c = copy_model_util(Finding.objects.get(id=4), exclude_fields=["duplicate_finding"]) self.finding_c.pk = None self.finding_c.title = "C: " + self.finding_c.title self.finding_c.duplicate = False @@ -262,7 +262,7 @@ def test_loop_relations_for_three(self): # Another loop-test for 4 findings def test_loop_relations_for_four(self): - self.finding_d = _copy_model_util(Finding.objects.get(id=4), exclude_fields=["duplicate_finding"]) + self.finding_d = copy_model_util(Finding.objects.get(id=4), exclude_fields=["duplicate_finding"]) self.finding_d.duplicate = False self.finding_d.save() diff --git a/unittests/test_false_positive_history_logic.py b/unittests/test_false_positive_history_logic.py index 4a380383f7d..5d8f31a15de 100644 --- a/unittests/test_false_positive_history_logic.py +++ b/unittests/test_false_positive_history_logic.py @@ -12,7 +12,7 @@ System_Settings, Test, User, - _copy_model_util, + copy_model_util, ) from .dojo_test_case import DojoTestCase @@ -1719,7 +1719,7 @@ def log_summary(self, product=None, engagement=None, test=None): def copy_and_reset_finding(self, find_id): org = Finding.objects.get(id=find_id) - new = _copy_model_util(org) + new = copy_model_util(org) new.duplicate = False new.duplicate_finding = None new.false_p = False @@ -1730,19 +1730,19 @@ def copy_and_reset_finding(self, find_id): def copy_and_reset_test(self, test_id): org = Test.objects.get(id=test_id) - new = _copy_model_util(org) + new = copy_model_util(org) # return unsaved new test and reloaded existing test return new, Test.objects.get(id=test_id) def copy_and_reset_engagement(self, eng_id): org = Engagement.objects.get(id=eng_id) - new = _copy_model_util(org) + new = copy_model_util(org) # return unsaved new engagement and reloaded existing engagement return new, Engagement.objects.get(id=eng_id) def copy_and_reset_product(self, prod_id): org = Product.objects.get(id=prod_id) - new = _copy_model_util(org) + new = copy_model_util(org) new.name = f"{org.name} (Copy {datetime.now()})" # return unsaved new product and reloaded existing product return new, Product.objects.get(id=prod_id) diff --git a/unittests/test_rest_framework.py b/unittests/test_rest_framework.py index 4f5120792d4..f32350e2e86 100644 --- a/unittests/test_rest_framework.py +++ b/unittests/test_rest_framework.py @@ -34,7 +34,7 @@ from dojo.api_v2.mixins import DeletePreviewModelMixin from dojo.api_v2.prefetch import PrefetchListMixin, PrefetchRetrieveMixin -from dojo.api_v2.prefetch.utils import _get_prefetchable_fields +from dojo.api_v2.prefetch.utils import get_prefetchable_fields from dojo.api_v2.views import ( AnnouncementViewSet, AppAnalysisViewSet, @@ -416,7 +416,7 @@ def test_detail(self): @skipIfNotSubclass(PrefetchRetrieveMixin) def test_detail_prefetch(self): # print("=======================================================") - prefetchable_fields = [x[0] for x in _get_prefetchable_fields(self.viewset.serializer_class)] + prefetchable_fields = [x[0] for x in get_prefetchable_fields(self.viewset.serializer_class)] current_objects = self.client.get(self.url, format="json").data relative_url = self.url + "{}/".format(current_objects["results"][0]["id"]) @@ -508,7 +508,7 @@ def test_list(self): @skipIfNotSubclass(PrefetchListMixin) def test_list_prefetch(self): - prefetchable_fields = [x[0] for x in _get_prefetchable_fields(self.viewset.serializer_class)] + prefetchable_fields = [x[0] for x in get_prefetchable_fields(self.viewset.serializer_class)] response = self.client.get(self.url, data={ "prefetch": ",".join(prefetchable_fields), diff --git a/unittests/test_utils_deduplication_reopen.py b/unittests/test_utils_deduplication_reopen.py index 91ba2c49d12..a7e72ede118 100644 --- a/unittests/test_utils_deduplication_reopen.py +++ b/unittests/test_utils_deduplication_reopen.py @@ -2,7 +2,7 @@ import logging from dojo.management.commands.fix_loop_duplicates import fix_loop_duplicates -from dojo.models import Finding, _copy_model_util +from dojo.models import Finding, copy_model_util from dojo.utils import set_duplicate from .dojo_test_case import DojoTestCase @@ -14,7 +14,7 @@ class TestDuplicationReopen(DojoTestCase): fixtures = ["dojo_testdata.json"] def setUp(self): - self.finding_a = _copy_model_util(Finding.objects.get(id=2), exclude_fields=["duplicate_finding"]) + self.finding_a = copy_model_util(Finding.objects.get(id=2), exclude_fields=["duplicate_finding"]) self.finding_a.duplicate = False self.finding_a.mitigated = datetime.datetime(1970, 1, 1, tzinfo=datetime.UTC) self.finding_a.is_mitigated = True @@ -22,19 +22,19 @@ def setUp(self): self.finding_a.active = False self.finding_a.save() - self.finding_b = _copy_model_util(Finding.objects.get(id=3), exclude_fields=["duplicate_finding"]) + self.finding_b = copy_model_util(Finding.objects.get(id=3), exclude_fields=["duplicate_finding"]) self.finding_a.active = True self.finding_b.duplicate = False self.finding_b.save() - self.finding_c = _copy_model_util(Finding.objects.get(id=4), exclude_fields=["duplicate_finding"]) + self.finding_c = copy_model_util(Finding.objects.get(id=4), exclude_fields=["duplicate_finding"]) self.finding_c.duplicate = False self.finding_c.out_of_scope = True self.finding_c.active = False logger.debug("creating finding_c") self.finding_c.save() - self.finding_d = _copy_model_util(Finding.objects.get(id=5), exclude_fields=["duplicate_finding"]) + self.finding_d = copy_model_util(Finding.objects.get(id=5), exclude_fields=["duplicate_finding"]) self.finding_d.duplicate = False logger.debug("creating finding_d") self.finding_d.save()