diff --git a/backend/core/migrations/0012_alter_appliedcontrol_updated_at_and_more.py b/backend/core/migrations/0012_alter_appliedcontrol_updated_at_and_more.py index 23137413d..ee9779bb0 100644 --- a/backend/core/migrations/0012_alter_appliedcontrol_updated_at_and_more.py +++ b/backend/core/migrations/0012_alter_appliedcontrol_updated_at_and_more.py @@ -74,7 +74,7 @@ def adapt_libraries(apps, schema_editor): "frameworks": library.frameworks.count(), "threats": library.threats.count(), "reference_controls": library.reference_controls.count(), - "risk_matrix": library.risk_matrices.count() + "risk_matrix": library.risk_matrices.count(), } library.save() diff --git a/backend/core/models.py b/backend/core/models.py index b76629b47..29dc2d536 100644 --- a/backend/core/models.py +++ b/backend/core/models.py @@ -149,9 +149,7 @@ def store_library_content(cls, library_content: bytes) -> "StoredLibrary | None" locale = library_data.get("locale", "en") version = int(library_data["version"]) is_loaded = LoadedLibrary.objects.filter( - urn=urn, - locale=locale, - version=version + urn=urn, locale=locale, version=version ).exists() library_matches = [*StoredLibrary.objects.filter(urn=urn, locale=locale)] diff --git a/backend/library/views.py b/backend/library/views.py index a7c1391b2..88ce401ee 100644 --- a/backend/library/views.py +++ b/backend/library/views.py @@ -63,17 +63,17 @@ def retrieve(self, request, *args, pk, **kwargs): return Response(data) def content(self, request, pk): - try : + try: lib = StoredLibrary.objects.get(urn=pk) - except : + except: return Response("Library not found.", status=HTTP_404_NOT_FOUND) return Response(lib.content) @action(detail=True, methods=["get"]) def content(self, request, pk): - try : + try: lib = StoredLibrary.objects.get(urn=pk) - except : + except: return Response("Library not found.", status=HTTP_404_NOT_FOUND) return Response(lib.content) @@ -251,9 +251,9 @@ def destroy(self, request, *args, pk, **kwargs): @action(detail=True, methods=["get"]) def content(self, request, pk): - try : + try: lib = LoadedLibrary.objects.get(urn=pk) - except : + except: return Response("Library not found.", status=HTTP_404_NOT_FOUND) return Response(lib._objects) @@ -261,7 +261,6 @@ def content(self, request, pk): def tree( self, request, pk ): # We must ensure that users that are not allowed to read the content of libraries can't have any access to them either from the /api/{URLModel/{library_urn}/tree view or the /api/{URLModel}/{library_urn} view. - try: lib = LoadedLibrary.objects.get(urn=pk) except: diff --git a/tools/add_builtin.py b/tools/add_builtin.py index e69afa3a5..cfb10e58e 100644 --- a/tools/add_builtin.py +++ b/tools/add_builtin.py @@ -3,24 +3,18 @@ # This is a temporary tool that adds "builtin: true" to all libraries stored as yaml files under ./backend/library/libraries. current_path = "/".join(__file__.split("/")[:-1]) -library_path = os.path.join(current_path,"..","backend","library","libraries") -fnames = [ - fname for fname in os.listdir(library_path) - if fname.endswith(".yaml") -] +library_path = os.path.join(current_path, "..", "backend", "library", "libraries") +fnames = [fname for fname in os.listdir(library_path) if fname.endswith(".yaml")] -for fname in fnames : - lib = os.path.join(library_path,fname) +for fname in fnames: + lib = os.path.join(library_path, fname) - with open(lib,"r",encoding="utf-8") as f: - content = f.read() - lines = content.split("\n") + with open(lib, "r", encoding="utf-8") as f: + content = f.read() + lines = content.split("\n") - if not any( - re.match(r"^builtin.*:.*true",line) is not None - for line in lines - ) : - lines.insert(1,"builtin: true") - with open(lib,"w",encoding="utf-8") as f : - f.write("\n".join(lines)) - print(f"Library '{fname}' updated.") + if not any(re.match(r"^builtin.*:.*true", line) is not None for line in lines): + lines.insert(1, "builtin: true") + with open(lib, "w", encoding="utf-8") as f: + f.write("\n".join(lines)) + print(f"Library '{fname}' updated.")