Issue#4: Staviti izabrane rizike u bazu kako treba. #53
18
backend/core/migrations/0003_organization_risks.py
Normal file
18
backend/core/migrations/0003_organization_risks.py
Normal file
@@ -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'),
|
||||
),
|
||||
]
|
||||
19
backend/core/migrations/0004_alter_document_id.py
Normal file
19
backend/core/migrations/0004_alter_document_id.py
Normal file
@@ -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),
|
||||
),
|
||||
]
|
||||
@@ -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)
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
% extends 'base.html' %}
|
||||
{% extends 'base.html' %}
|
||||
|
||||
{% block content %}
|
||||
<div class="document-container">
|
||||
|
||||
@@ -5,39 +5,9 @@
|
||||
<div class="col">
|
||||
<h1 class="pt-4 mt-5 mb-4">Thank you.</h1>
|
||||
We will send the document to {{ email }} when it is ready.
|
||||
<a href="{{ document_link }}">View Your Document</a>
|
||||
</div>
|
||||
</div>
|
||||
<h2>Top 10 Identified Risks</h2>
|
||||
<table class="table table-striped table-bordered">
|
||||
<thead>
|
||||
<tr>
|
||||
<th scope="col">Risk ID</th>
|
||||
<th scope="col">Risk Name</th>
|
||||
<th scope="col">Category</th>
|
||||
<th scope="col">Primary Impact</th>
|
||||
<th scope="col">Secondary Impact</th>
|
||||
<th scope="col">Tertiary Impact</th>
|
||||
<th scope="col">Detection Difficulty</th>
|
||||
<th scope="col">Recovery Complexity</th>
|
||||
<th scope="col">Business Impact Severity</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{% for risk in top_risks %}
|
||||
<tr>
|
||||
<td>{{ risk.risk_id }}</td>
|
||||
<td>{{ risk.risk_name }}</td>
|
||||
<td>{{ risk.category }}</td>
|
||||
<td>{{ risk.primary_impact }}</td>
|
||||
<td>{{ risk.secondary_impact }}</td>
|
||||
<td>{{ risk.tretiary_impact }}</td>
|
||||
<td>{{ risk.detection_difficulty }}</td>
|
||||
<td>{{ risk.recovery_complexity }}</td>
|
||||
<td>{{ risk.businnes_impact_severity }}</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
{% endblock content %}
|
||||
|
||||
|
||||
@@ -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/<uuid:uuid>/', v.document, name='document'),
|
||||
path('document/<uuid:document_id>/', v.document, name='document'),
|
||||
]
|
||||
|
||||
@@ -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('<h1>Django</h1><p>Página simples.</p>')
|
||||
@@ -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')
|
||||
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(),
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user