diff --git a/backend/core/apps.py b/backend/core/apps.py index e0fda3869..935f0c2e0 100644 --- a/backend/core/apps.py +++ b/backend/core/apps.py @@ -378,7 +378,7 @@ def _ready(self): # Remove the 3 following lines after """from core.models import LoadedLibrary - for lib in LoadedLibrary.objects.all() : + for lib in StoredLibrary.objects.all() : lib.delete()""" start = time.perf_counter() diff --git a/backend/core/migrations/0010_alter_storedlibrary_dependencies.py b/backend/core/migrations/0010_alter_storedlibrary_dependencies.py new file mode 100644 index 000000000..27bf93e4e --- /dev/null +++ b/backend/core/migrations/0010_alter_storedlibrary_dependencies.py @@ -0,0 +1,18 @@ +# Generated by Django 5.0.4 on 2024-04-24 14:20 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('core', '0009_loadedlibrary_alter_framework_library_and_more'), + ] + + operations = [ + migrations.AlterField( + model_name='storedlibrary', + name='dependencies', + field=models.JSONField(null=True), + ), + ] diff --git a/backend/core/models.py b/backend/core/models.py index 574412e6a..6bdcce3c3 100644 --- a/backend/core/models.py +++ b/backend/core/models.py @@ -102,7 +102,7 @@ class Meta: ) builtin = models.BooleanField(default=False) objects_meta = models.JSONField() - dependencies = models.CharField(blank=False,null=True,max_length=16384) + dependencies = models.JSONField(null=True) # models.CharField(blank=False,null=True,max_length=16384) def get_dependencies(self) -> List[str] : # We should add some kind of descriptor to LibaryMixin so that model_instance.dependencies directly returns a list instead of a string, using a function to get the desired value of a field is bad return [] if self.dependencies is None else self.dependencies.split(" ") @@ -169,9 +169,7 @@ def store_library_file(fname: str) -> Union[str,None] : for key, value in library_data["objects"].items() } - dependencies = library_data.get("dependencies") - if dependencies is not None : - dependencies = " ".join(dependencies) # Which means we have to make the URN format more restrictive so that an URN is considered invalid if it contains any kind of whitespace. + dependencies = library_data.get("dependencies") # I don't want whitespaces in URN anymore nontheless library_objects = json.dumps(library_data["objects"]) StoredLibrary.objects.create( diff --git a/backend/library/libraries/critical_risk_matrix_3x3.yaml b/backend/library/libraries/critical_risk_matrix_3x3.yaml index 87eee8a28..ba72f3327 100644 --- a/backend/library/libraries/critical_risk_matrix_3x3.yaml +++ b/backend/library/libraries/critical_risk_matrix_3x3.yaml @@ -1,7 +1,7 @@ urn: urn:intuitem:risk:library:critical_risk_matrix_3x3 locale: en ref_id: critical_3x3 -nam: Critical risk matrix 3x3 +name: Critical risk matrix 3x3 description: Critical risk matrix 3x3 version: 1 provider: intuitem diff --git a/backend/library/serializers.py b/backend/library/serializers.py index 7bd6d9b51..5cf92c62b 100644 --- a/backend/library/serializers.py +++ b/backend/library/serializers.py @@ -31,6 +31,7 @@ class Meta: # objects_meta = serializers.JSONField() class StoredLibraryDetailedSerializer(serializers.ModelSerializer): + dependencies = lambda dependencies: dependencies.split(" ") class Meta: model = StoredLibrary fields = "__all__"