Skip to content

Commit

Permalink
Merge branch 'feat/tprm' of github.com:intuitem/ciso-assistant-commun…
Browse files Browse the repository at this point in the history
…ity into feat/tprm
  • Loading branch information
Mohamed-Hacene committed Sep 13, 2024
2 parents 215c425 + 5d160b6 commit c70f70a
Show file tree
Hide file tree
Showing 58 changed files with 27,459 additions and 4,048 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -481,6 +481,8 @@ Set DJANGO_DEBUG=False for security reason.
- IT: Italian
- PL: Polish
- RO: Romanian
- HI: Hindi
- UR: Urdu

## Built With 💜

Expand Down
4 changes: 2 additions & 2 deletions backend/app_tests/api/test_api_risk_scenarios.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,8 @@
"description": "acceptable risk",
"hexcolor": "#00FF00",
}
RISK_SCENARIO_TREATMENT_STATUS = ("accept", "Accept")
RISK_SCENARIO_TREATMENT_STATUS2 = ("mitigate", "Mitigate")
RISK_SCENARIO_TREATMENT_STATUS = ("accept", "accept")
RISK_SCENARIO_TREATMENT_STATUS2 = ("mitigate", "mitigate")
RISK_SCENARIO_JUSTIFICATION = "Test justification"


Expand Down
2 changes: 2 additions & 0 deletions backend/ciso_assistant/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,8 @@ def set_ciso_assistant_url(_, __, event_dict):
("pt", "Portuguese"),
("ar", "Arabic"),
("ro", "Romanian"),
("hi", "Hindi"),
("ur", "Urdu"),
]

PROJECT_PATH = os.path.dirname(os.path.abspath(__file__))
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,187 @@
# Generated by Django 5.1.1 on 2024-09-12 15:00

import django.db.models.deletion
import iam.models
from django.db import migrations, models


def set_assessment_folder(apps, schema_editor):
RiskAssessment = apps.get_model("core", "RiskAssessment")
ComplianceAssessment = apps.get_model("core", "ComplianceAssessment")
for risk_assessment in RiskAssessment.objects.all():
risk_assessment.folder = risk_assessment.project.folder
risk_assessment.save()
for compliance_assessment in ComplianceAssessment.objects.all():
compliance_assessment.folder = compliance_assessment.project.folder
compliance_assessment.save()


class Migration(migrations.Migration):
dependencies = [
("core", "0024_appliedcontrol_owner"),
("iam", "0006_alter_role_folder_alter_roleassignment_folder_and_more"),
]

operations = [
migrations.AddField(
model_name="complianceassessment",
name="folder",
field=models.ForeignKey(
default=iam.models.Folder.get_root_folder_id,
on_delete=django.db.models.deletion.CASCADE,
related_name="%(class)s_folder",
to="iam.folder",
),
),
migrations.AddField(
model_name="riskassessment",
name="folder",
field=models.ForeignKey(
default=iam.models.Folder.get_root_folder_id,
on_delete=django.db.models.deletion.CASCADE,
related_name="%(class)s_folder",
to="iam.folder",
),
),
migrations.AlterField(
model_name="appliedcontrol",
name="folder",
field=models.ForeignKey(
default=iam.models.Folder.get_root_folder_id,
on_delete=django.db.models.deletion.CASCADE,
related_name="%(class)s_folder",
to="iam.folder",
),
),
migrations.AlterField(
model_name="asset",
name="folder",
field=models.ForeignKey(
default=iam.models.Folder.get_root_folder_id,
on_delete=django.db.models.deletion.CASCADE,
related_name="%(class)s_folder",
to="iam.folder",
),
),
migrations.AlterField(
model_name="evidence",
name="folder",
field=models.ForeignKey(
default=iam.models.Folder.get_root_folder_id,
on_delete=django.db.models.deletion.CASCADE,
related_name="%(class)s_folder",
to="iam.folder",
),
),
migrations.AlterField(
model_name="framework",
name="folder",
field=models.ForeignKey(
default=iam.models.Folder.get_root_folder_id,
on_delete=django.db.models.deletion.CASCADE,
related_name="%(class)s_folder",
to="iam.folder",
),
),
migrations.AlterField(
model_name="loadedlibrary",
name="folder",
field=models.ForeignKey(
default=iam.models.Folder.get_root_folder_id,
on_delete=django.db.models.deletion.CASCADE,
related_name="%(class)s_folder",
to="iam.folder",
),
),
migrations.AlterField(
model_name="project",
name="folder",
field=models.ForeignKey(
default=iam.models.Folder.get_root_folder_id,
on_delete=django.db.models.deletion.CASCADE,
related_name="%(class)s_folder",
to="iam.folder",
),
),
migrations.AlterField(
model_name="referencecontrol",
name="folder",
field=models.ForeignKey(
default=iam.models.Folder.get_root_folder_id,
on_delete=django.db.models.deletion.CASCADE,
related_name="%(class)s_folder",
to="iam.folder",
),
),
migrations.AlterField(
model_name="requirementassessment",
name="folder",
field=models.ForeignKey(
default=iam.models.Folder.get_root_folder_id,
on_delete=django.db.models.deletion.CASCADE,
related_name="%(class)s_folder",
to="iam.folder",
),
),
migrations.AlterField(
model_name="requirementmappingset",
name="folder",
field=models.ForeignKey(
default=iam.models.Folder.get_root_folder_id,
on_delete=django.db.models.deletion.CASCADE,
related_name="%(class)s_folder",
to="iam.folder",
),
),
migrations.AlterField(
model_name="requirementnode",
name="folder",
field=models.ForeignKey(
default=iam.models.Folder.get_root_folder_id,
on_delete=django.db.models.deletion.CASCADE,
related_name="%(class)s_folder",
to="iam.folder",
),
),
migrations.AlterField(
model_name="riskacceptance",
name="folder",
field=models.ForeignKey(
default=iam.models.Folder.get_root_folder_id,
on_delete=django.db.models.deletion.CASCADE,
related_name="%(class)s_folder",
to="iam.folder",
),
),
migrations.AlterField(
model_name="riskmatrix",
name="folder",
field=models.ForeignKey(
default=iam.models.Folder.get_root_folder_id,
on_delete=django.db.models.deletion.CASCADE,
related_name="%(class)s_folder",
to="iam.folder",
),
),
migrations.AlterField(
model_name="storedlibrary",
name="folder",
field=models.ForeignKey(
default=iam.models.Folder.get_root_folder_id,
on_delete=django.db.models.deletion.CASCADE,
related_name="%(class)s_folder",
to="iam.folder",
),
),
migrations.AlterField(
model_name="threat",
name="folder",
field=models.ForeignKey(
default=iam.models.Folder.get_root_folder_id,
on_delete=django.db.models.deletion.CASCADE,
related_name="%(class)s_folder",
to="iam.folder",
),
),
migrations.RunPython(set_assessment_folder),
]
Original file line number Diff line number Diff line change
@@ -1,22 +1,23 @@
# Generated by Django 5.1 on 2024-09-04 13:56
# Generated by Django 5.1.1 on 2024-09-13 15:42

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
("core", "0024_appliedcontrol_owner"),
('core', '0025_complianceassessment_folder_riskassessment_folder_and_more'),
]

operations = [
migrations.AddField(
model_name="requirementassessment",
name="answer",
field=models.JSONField(blank=True, null=True, verbose_name="Answer"),
model_name='requirementassessment',
name='answer',
field=models.JSONField(blank=True, null=True, verbose_name='Answer'),
),
migrations.AddField(
model_name="requirementnode",
name="question",
field=models.JSONField(blank=True, null=True, verbose_name="Question"),
model_name='requirementnode',
name='question',
field=models.JSONField(blank=True, null=True, verbose_name='Question'),
),
]
10 changes: 8 additions & 2 deletions backend/core/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
from django.utils.html import format_html
from django.utils.translation import gettext_lazy as _
from iam.models import Folder, FolderMixin, PublishInRootFolderMixin
from library.helpers import update_translations, update_translations_in_object
from structlog import get_logger

from .base_models import AbstractBaseModel, ETADueDateMixin, NameDescriptionMixin
Expand Down Expand Up @@ -1418,7 +1419,7 @@ def save(self, *args, **kwargs):
########################### Secondary objects #########################


class Assessment(NameDescriptionMixin, ETADueDateMixin):
class Assessment(NameDescriptionMixin, ETADueDateMixin, FolderMixin):
class Status(models.TextChoices):
PLANNED = "planned", _("Planned")
IN_PROGRESS = "in_progress", _("In progress")
Expand Down Expand Up @@ -1463,6 +1464,11 @@ class Status(models.TextChoices):
class Meta:
abstract = True

def save(self, *args, **kwargs) -> None:
if not self.folder or self.folder == Folder.get_root_folder():
self.folder = self.project.folder
return super().save(*args, **kwargs)


class RiskAssessment(Assessment):
risk_matrix = models.ForeignKey(
Expand Down Expand Up @@ -2061,7 +2067,7 @@ def create_requirement_assessments(self, baseline: Self | None = None):
requirement_assessment = RequirementAssessment.objects.create(
compliance_assessment=self,
requirement=requirement,
folder=Folder.objects.get(id=self.project.folder.id),
folder=Folder.objects.get(id=self.folder.id),
answer=transform_question_to_answer(requirement.question)
if requirement.question
else {},
Expand Down
4 changes: 3 additions & 1 deletion backend/core/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,7 @@ class Meta:
class RiskAssessmentReadSerializer(AssessmentReadSerializer):
str = serializers.CharField(source="__str__")
project = FieldsRelatedField(["id", "folder"])
folder = FieldsRelatedField()
risk_scenarios = FieldsRelatedField(many=True)
risk_scenarios_count = serializers.IntegerField(source="risk_scenarios.count")
risk_matrix = FieldsRelatedField()
Expand Down Expand Up @@ -275,7 +276,7 @@ class RiskScenarioReadSerializer(RiskScenarioWriteSerializer):
threats = FieldsRelatedField(many=True)
assets = FieldsRelatedField(many=True)

treatment = serializers.CharField(source="get_treatment_display")
treatment = serializers.CharField()

current_proba = serializers.JSONField(source="get_current_proba")
current_impact = serializers.JSONField(source="get_current_impact")
Expand Down Expand Up @@ -535,6 +536,7 @@ class Meta:

class ComplianceAssessmentReadSerializer(AssessmentReadSerializer):
project = FieldsRelatedField(["id", "folder"])
folder = FieldsRelatedField()
framework = FieldsRelatedField(
["id", "min_score", "max_score", "implementation_groups_definition", "ref_id"]
)
Expand Down
57 changes: 5 additions & 52 deletions backend/core/startup.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
from django.apps import AppConfig
from django.db.models.signals import post_migrate
import os

from ciso_assistant.settings import CISO_ASSISTANT_SUPERUSER_EMAIL
from django.apps import AppConfig
from django.core.management import call_command

from django.db.models.signals import post_migrate
from structlog import get_logger

from ciso_assistant.settings import CISO_ASSISTANT_SUPERUSER_EMAIL

logger = get_logger(__name__)

READER_PERMISSIONS_LIST = [
Expand Down Expand Up @@ -287,7 +287,7 @@ def startup(sender: AppConfig, **kwargs):
Create superuser if CISO_ASSISTANT_SUPERUSER_EMAIL defined
"""
from django.contrib.auth.models import Permission
from allauth.socialaccount.providers.saml.provider import SAMLProvider

from iam.models import Folder, Role, RoleAssignment, User, UserGroup
from tprm.models import Entity
from global_settings.models import GlobalSettings
Expand Down Expand Up @@ -396,53 +396,6 @@ def startup(sender: AppConfig, **kwargs):
except Exception as e:
print(e) # NOTE: Add this exception in the logger

default_attribute_mapping = SAMLProvider.default_attribute_mapping

settings = {
"attribute_mapping": {
"uid": default_attribute_mapping["uid"],
"email_verified": default_attribute_mapping["email_verified"],
"email": default_attribute_mapping["email"],
},
"idp": {
"entity_id": "",
"metadata_url": "",
"sso_url": "",
"slo_url": "",
"x509cert": "",
},
"sp": {
"entity_id": "ciso-assistant",
},
"advanced": {
"allow_repeat_attribute_name": True,
"allow_single_label_domains": False,
"authn_request_signed": False,
"digest_algorithm": "http://www.w3.org/2001/04/xmldsig-more#rsa-sha256",
"logout_request_signed": False,
"logout_response_signed": False,
"metadata_signed": False,
"name_id_encrypted": False,
"reject_deprecated_algorithm": True,
"reject_idp_initiated_sso": True,
"signature_algorithm": "http://www.w3.org/2001/04/xmldsig-more#rsa-sha256",
"want_assertion_encrypted": False,
"want_assertion_signed": False,
"want_attribute_statement": True,
"want_message_signed": False,
"want_name_id": False,
"want_name_id_encrypted": False,
},
}

if not GlobalSettings.objects.filter(name=GlobalSettings.Names.SSO).exists():
logger.info("SSO settings not found, creating default settings")
sso_settings = GlobalSettings.objects.create(
name=GlobalSettings.Names.SSO,
value={"client_id": "0", "settings": settings},
)
logger.info("SSO settings created", settings=sso_settings.value)

call_command("storelibraries")


Expand Down
Loading

0 comments on commit c70f70a

Please sign in to comment.