diff --git a/backend/core/migrations/0003_organization_risks.py b/backend/core/migrations/0003_organization_risks.py new file mode 100644 index 0000000..688f312 --- /dev/null +++ b/backend/core/migrations/0003_organization_risks.py @@ -0,0 +1,18 @@ +# Generated by Django 5.1.3 on 2025-02-12 10:37 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('core', '0002_risk_document_documentsegment'), + ] + + operations = [ + migrations.AddField( + model_name='organization', + name='risks', + field=models.ManyToManyField(blank=True, related_name='organizations', to='core.risk'), + ), + ] diff --git a/backend/core/migrations/0004_alter_document_id.py b/backend/core/migrations/0004_alter_document_id.py new file mode 100644 index 0000000..d075ea7 --- /dev/null +++ b/backend/core/migrations/0004_alter_document_id.py @@ -0,0 +1,19 @@ +# Generated by Django 5.1.3 on 2025-02-12 10:56 + +import uuid +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('core', '0003_organization_risks'), + ] + + operations = [ + migrations.AlterField( + model_name='document', + name='id', + field=models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False), + ), + ] diff --git a/backend/core/models.py b/backend/core/models.py index 1424034..76514e4 100644 --- a/backend/core/models.py +++ b/backend/core/models.py @@ -66,6 +66,8 @@ class Organization(models.Model): sensitive_data = models.JSONField(null=True, blank=True) # Stores selected sensitive data types as a list integration_level = models.CharField(max_length=20, null=True, blank=True) + risks = models.ManyToManyField('Risk', related_name='organizations', blank=True) + def __str__(self): return self.name @@ -95,6 +97,7 @@ class DocumentSegment(models.Model): class Document(models.Model): + id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False) organization = models.ForeignKey(Organization, on_delete=models.CASCADE, related_name='documents') created_at = models.DateTimeField(auto_now_add=True) modified_at = models.DateTimeField(auto_now=True) diff --git a/backend/core/templates/document.html b/backend/core/templates/document.html index 49de32c..f1ec85c 100644 --- a/backend/core/templates/document.html +++ b/backend/core/templates/document.html @@ -1,4 +1,4 @@ -% extends 'base.html' %} +{% extends 'base.html' %} {% block content %}
diff --git a/backend/core/templates/thankyou.html b/backend/core/templates/thankyou.html index 25d161f..37cdddd 100644 --- a/backend/core/templates/thankyou.html +++ b/backend/core/templates/thankyou.html @@ -5,39 +5,9 @@

Thank you.

We will send the document to {{ email }} when it is ready. + View Your Document
-

Top 10 Identified Risks

- - - - - - - - - - - - - - - - {% for risk in top_risks %} - - - - - - - - - - - - {% endfor %} - -
Risk IDRisk NameCategoryPrimary ImpactSecondary ImpactTertiary ImpactDetection DifficultyRecovery ComplexityBusiness Impact Severity
{{ risk.risk_id }}{{ risk.risk_name }}{{ risk.category }}{{ risk.primary_impact }}{{ risk.secondary_impact }}{{ risk.tretiary_impact }}{{ risk.detection_difficulty }}{{ risk.recovery_complexity }}{{ risk.businnes_impact_severity }}
{% endblock content %} diff --git a/backend/core/urls.py b/backend/core/urls.py index 7250eda..0b6d5e0 100644 --- a/backend/core/urls.py +++ b/backend/core/urls.py @@ -9,5 +9,5 @@ urlpatterns = [ path('signup/', v.signup, name='signup'), path('thankyou/', v.thankyou, name='thankyou'), # url document/ recieves a parameter named 'uuid' and passes it to the view - path('document//', v.document, name='document'), + path('document//', v.document, name='document'), ] diff --git a/backend/core/views.py b/backend/core/views.py index 52c4453..56177f2 100644 --- a/backend/core/views.py +++ b/backend/core/views.py @@ -1,9 +1,10 @@ import logging -from django.shortcuts import render, redirect +from django.shortcuts import render, redirect , get_object_or_404 from .forms import OrganizationForm from .models import Organization,Document,Risk from backend.core.utils import get_top_risk +from django.urls import reverse # @login_required # def index(request): # return HttpResponse('

Django

Página simples.

') @@ -24,17 +25,28 @@ def signup(request): top_risk_ids = get_top_risk(organization) top_risks = Risk.objects.filter(risk_id__in = top_risk_ids) + organization.risks.set(top_risks) + document = Document.objects.create(organization=organization) document.add_segment('h1', "Top 10 Risk Identified") - for risk in top_risks: - document.add_segment('h2',f"Risk: {risk.risk_id}:{risk.risk_name}") - document.add_segment('body',f"Category: {risk.category} \n Primary Impact: {risk.primary_impact} \n Secondary Impact: {risk.secondary_impact} \n Tertiary Impact: {risk.tretiary_impact} \n Detection Difficulty: {risk.detection_difficulty} \n Recovery Complexity: {risk.recovery_complexity} \n Business Impact Severity: {risk.businnes_impact_severity} ") + risk_content = "\n\n".join([ + f"Risk: {risk.risk_id} : {risk.risk_name} \n" + f"Category: {risk.category}\n" + f"Primary Impaact: {risk.primary_impact} \n" + f"Secondary Impact: {risk.secondary_impact}\n" + f"Tertiary Impact: {risk.tretiary_impact} \n" + f"Detection Difficulty: {risk.detection_difficulty} \n" + f"Recovery Complexity: {risk.recovery_complexity} \n" + f"Business Impact Severity: {risk.businnes_impact_severity}\n" + for risk in top_risks + ]) + + document.add_segment('body',f"Identified Risks: \n\n{risk_content}") return render(request, 'thankyou.html', { 'email': form.data['email'], - 'top_risks':top_risks, - 'document':document + 'document_link': reverse('core:document', args=[str(document.id)]) }) else: logging.error(form.errors) @@ -48,5 +60,12 @@ def signup(request): def thankyou(request): return render(request, 'thankyou.html') -def document(request): - return render(request, 'document.html') \ No newline at end of file +def document(request, document_id): + print(f"Document ID received: {document_id}") + doc = get_object_or_404(Document, id=document_id) + + return render(request, 'document.html', { + 'document': doc, + 'organization': doc.organization, + 'segments': doc.segments.all(), + })