Skip to content

Commit

Permalink
chore: ruff format
Browse files Browse the repository at this point in the history
  • Loading branch information
nas-tabchiche committed Jan 15, 2025
1 parent 5529bd8 commit 89a0981
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 34 deletions.
42 changes: 14 additions & 28 deletions backend/core/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,7 @@ def _get_serializer_class(self, serializer_name: str):
class BaseModelSerializer(serializers.ModelSerializer):
def update(self, instance: models.Model, validated_data: Any) -> models.Model:
if hasattr(instance, "urn") and getattr(instance, "urn"):
raise PermissionDenied(
{"urn": "Imported objects cannot be modified"})
raise PermissionDenied({"urn": "Imported objects cannot be modified"})
try:
object_updated = super().update(instance, validated_data)
return object_updated
Expand Down Expand Up @@ -172,8 +171,7 @@ class Meta:

class VulnerabilityImportExportSerializer(BaseModelSerializer):
folder = HashSlugRelatedField(slug_field="pk", read_only=True)
applied_controls = HashSlugRelatedField(
slug_field="pk", read_only=True, many=True)
applied_controls = HashSlugRelatedField(slug_field="pk", read_only=True, many=True)

class Meta:
model = Vulnerability
Expand Down Expand Up @@ -254,10 +252,8 @@ class RiskAssessmentReadSerializer(AssessmentReadSerializer):
str = serializers.CharField(source="__str__")
project = FieldsRelatedField(["id", "folder"])
folder = FieldsRelatedField()
risk_scenarios = FieldsRelatedField(
many=True, fields=["id", "name", "ref_id"])
risk_scenarios_count = serializers.IntegerField(
source="risk_scenarios.count")
risk_scenarios = FieldsRelatedField(many=True, fields=["id", "name", "ref_id"])
risk_scenarios_count = serializers.IntegerField(source="risk_scenarios.count")
risk_matrix = FieldsRelatedField()
ebios_rm_study = FieldsRelatedField(["id", "name"])

Expand All @@ -267,8 +263,7 @@ class Meta:


class RiskAssessmentImportExportSerializer(BaseModelSerializer):
risk_matrix = serializers.SlugRelatedField(
slug_field="urn", read_only=True)
risk_matrix = serializers.SlugRelatedField(slug_field="urn", read_only=True)

folder = HashSlugRelatedField(slug_field="pk", read_only=True)
project = HashSlugRelatedField(slug_field="pk", read_only=True)
Expand Down Expand Up @@ -338,8 +333,7 @@ class AssetReadSerializer(AssetWriteSerializer):

class AssetImportExportSerializer(BaseModelSerializer):
folder = HashSlugRelatedField(slug_field="pk", read_only=True)
parent_assets = HashSlugRelatedField(
slug_field="pk", read_only=True, many=True)
parent_assets = HashSlugRelatedField(slug_field="pk", read_only=True, many=True)

class Meta:
model = Asset
Expand Down Expand Up @@ -481,8 +475,7 @@ class RiskScenarioReadSerializer(RiskScenarioWriteSerializer):
residual_impact = serializers.JSONField(source="get_residual_impact")
residual_level = serializers.JSONField(source="get_residual_risk")

strength_of_knowledge = serializers.JSONField(
source="get_strength_of_knowledge")
strength_of_knowledge = serializers.JSONField(source="get_strength_of_knowledge")

applied_controls = FieldsRelatedField(many=True)
existing_applied_controls = FieldsRelatedField(many=True)
Expand All @@ -497,14 +490,12 @@ class RiskScenarioImportExportSerializer(BaseModelSerializer):

threats = HashSlugRelatedField(slug_field="pk", many=True, read_only=True)
risk_assessment = HashSlugRelatedField(slug_field="pk", read_only=True)
vulnerabilities = HashSlugRelatedField(
slug_field="pk", read_only=True, many=True)
vulnerabilities = HashSlugRelatedField(slug_field="pk", read_only=True, many=True)
assets = HashSlugRelatedField(slug_field="pk", read_only=True, many=True)
existing_applied_controls = HashSlugRelatedField(
slug_field="pk", read_only=True, many=True
)
applied_controls = HashSlugRelatedField(
slug_field="pk", read_only=True, many=True)
applied_controls = HashSlugRelatedField(slug_field="pk", read_only=True, many=True)

class Meta:
model = RiskScenario
Expand Down Expand Up @@ -568,8 +559,7 @@ class Meta:
class AppliedControlImportExportSerializer(BaseModelSerializer):
reference_control = HashSlugRelatedField(slug_field="pk", read_only=True)
folder = HashSlugRelatedField(slug_field="pk", read_only=True)
evidences = HashSlugRelatedField(
slug_field="pk", read_only=True, many=True)
evidences = HashSlugRelatedField(slug_field="pk", read_only=True, many=True)

class Meta:
model = AppliedControl
Expand Down Expand Up @@ -1026,16 +1016,12 @@ class Meta:


class RequirementAssessmentImportExportSerializer(BaseModelSerializer):
requirement = serializers.SlugRelatedField(
slug_field="urn", read_only=True)
requirement = serializers.SlugRelatedField(slug_field="urn", read_only=True)

folder = HashSlugRelatedField(slug_field="pk", read_only=True)
compliance_assessment = HashSlugRelatedField(
slug_field="pk", read_only=True)
evidences = HashSlugRelatedField(
slug_field="pk", read_only=True, many=True)
applied_controls = HashSlugRelatedField(
slug_field="pk", read_only=True, many=True)
compliance_assessment = HashSlugRelatedField(slug_field="pk", read_only=True)
evidences = HashSlugRelatedField(slug_field="pk", read_only=True, many=True)
applied_controls = HashSlugRelatedField(slug_field="pk", read_only=True, many=True)

class Meta:
model = RequirementAssessment
Expand Down
3 changes: 1 addition & 2 deletions backend/library/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,7 @@ class Meta:

class LoadedLibraryImportExportSerializer(BaseModelSerializer):
folder = HashSlugRelatedField(slug_field="pk", read_only=True)
dependencies = HashSlugRelatedField(
slug_field="pk", read_only=True, many=True)
dependencies = HashSlugRelatedField(slug_field="pk", read_only=True, many=True)

class Meta:
model = LoadedLibrary
Expand Down
6 changes: 2 additions & 4 deletions backend/serdes/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,13 +207,11 @@ def get_domain_export_objects(domain: Folder):
risk_assessment__in=risk_assessments
).distinct()

ebios_rm_studies = EbiosRMStudy.objects.filter(
folder__in=folders).distinct()
ebios_rm_studies = EbiosRMStudy.objects.filter(folder__in=folders).distinct()
feared_events = FearedEvent.objects.filter(
ebios_rm_study__in=ebios_rm_studies
).distinct()
ro_tos = RoTo.objects.filter(
ebios_rm_study__in=ebios_rm_studies).distinct()
ro_tos = RoTo.objects.filter(ebios_rm_study__in=ebios_rm_studies).distinct()
strategic_scenarios = StrategicScenario.objects.filter(
ebios_rm_study__in=ebios_rm_studies
).distinct()
Expand Down

0 comments on commit 89a0981

Please sign in to comment.