feat: Enhance Risk Management Module
- Updated Risk model to include description, created_at, and updated_at fields.
- Modified RiskSerializer to include created_at and updated_at in serialized output.
- Improved logging in signals for Risk and Control models, including serialization of values.
- Added new template tags for CIA label mapping.
- Refactored URL patterns for better clarity and added detail views for risks, controls, and incidents.
- Implemented list and detail views for risks, controls, and incidents with filtering options.
- Enhanced CSS for better UI/UX, including breadcrumbs and table styling.
- Created new templates for displaying individual risks, controls, and incidents with detailed information.
2025-09-08 15:03:12 +02:00
|
|
|
from datetime import date, datetime
|
|
|
|
from django.db.models import Model
|
2025-09-07 20:52:19 +02:00
|
|
|
from django.db.models.signals import post_save, post_delete, m2m_changed
|
|
|
|
from django.dispatch import receiver
|
2025-09-09 12:00:29 +02:00
|
|
|
from .audit_context import get_current_user
|
2025-09-07 20:52:19 +02:00
|
|
|
from .models import Control, Risk, ResidualRisk, AuditLog, Incident
|
|
|
|
from .utils import model_diff
|
|
|
|
|
feat: Enhance Risk Management Module
- Updated Risk model to include description, created_at, and updated_at fields.
- Modified RiskSerializer to include created_at and updated_at in serialized output.
- Improved logging in signals for Risk and Control models, including serialization of values.
- Added new template tags for CIA label mapping.
- Refactored URL patterns for better clarity and added detail views for risks, controls, and incidents.
- Implemented list and detail views for risks, controls, and incidents with filtering options.
- Enhanced CSS for better UI/UX, including breadcrumbs and table styling.
- Created new templates for displaying individual risks, controls, and incidents with detailed information.
2025-09-08 15:03:12 +02:00
|
|
|
# ---------------------------------------------------------------------------
|
|
|
|
# General definitions
|
|
|
|
# ---------------------------------------------------------------------------
|
2025-09-07 20:52:19 +02:00
|
|
|
|
feat: Enhance Risk Management Module
- Updated Risk model to include description, created_at, and updated_at fields.
- Modified RiskSerializer to include created_at and updated_at in serialized output.
- Improved logging in signals for Risk and Control models, including serialization of values.
- Added new template tags for CIA label mapping.
- Refactored URL patterns for better clarity and added detail views for risks, controls, and incidents.
- Implemented list and detail views for risks, controls, and incidents with filtering options.
- Enhanced CSS for better UI/UX, including breadcrumbs and table styling.
- Created new templates for displaying individual risks, controls, and incidents with detailed information.
2025-09-08 15:03:12 +02:00
|
|
|
def serialize_value(value):
|
|
|
|
if isinstance(value, Model):
|
|
|
|
return value.pk # oder str(value), wenn du mehr Infos willst
|
|
|
|
if isinstance(value, (datetime, date)):
|
|
|
|
return value.isoformat()
|
|
|
|
return value
|
2025-09-07 20:52:19 +02:00
|
|
|
|
feat: Enhance Risk Management Module
- Updated Risk model to include description, created_at, and updated_at fields.
- Modified RiskSerializer to include created_at and updated_at in serialized output.
- Improved logging in signals for Risk and Control models, including serialization of values.
- Added new template tags for CIA label mapping.
- Refactored URL patterns for better clarity and added detail views for risks, controls, and incidents.
- Implemented list and detail views for risks, controls, and incidents with filtering options.
- Enhanced CSS for better UI/UX, including breadcrumbs and table styling.
- Created new templates for displaying individual risks, controls, and incidents with detailed information.
2025-09-08 15:03:12 +02:00
|
|
|
# ---------------------------------------------------------------------------
|
|
|
|
# Risks
|
|
|
|
# ---------------------------------------------------------------------------
|
2025-09-07 20:52:19 +02:00
|
|
|
@receiver(post_save, sender=Risk)
|
|
|
|
def log_risk_save(sender, instance, created, **kwargs):
|
|
|
|
if created:
|
|
|
|
AuditLog.objects.create(
|
|
|
|
user=getattr(instance, "_changed_by", None),
|
|
|
|
action="create",
|
|
|
|
model="Risk",
|
|
|
|
object_id=instance.pk,
|
feat: Enhance Risk Management Module
- Updated Risk model to include description, created_at, and updated_at fields.
- Modified RiskSerializer to include created_at and updated_at in serialized output.
- Improved logging in signals for Risk and Control models, including serialization of values.
- Added new template tags for CIA label mapping.
- Refactored URL patterns for better clarity and added detail views for risks, controls, and incidents.
- Implemented list and detail views for risks, controls, and incidents with filtering options.
- Enhanced CSS for better UI/UX, including breadcrumbs and table styling.
- Created new templates for displaying individual risks, controls, and incidents with detailed information.
2025-09-08 15:03:12 +02:00
|
|
|
changes={
|
|
|
|
f.name: {
|
|
|
|
"old": None,
|
|
|
|
"new": serialize_value(getattr(instance, f.name))
|
|
|
|
} for f in instance._meta.fields
|
|
|
|
},
|
2025-09-07 20:52:19 +02:00
|
|
|
)
|
|
|
|
else:
|
|
|
|
old = Risk.objects.get(pk=instance.pk)
|
|
|
|
changes = model_diff(old, instance)
|
|
|
|
if changes:
|
feat: Enhance Risk Management Module
- Updated Risk model to include description, created_at, and updated_at fields.
- Modified RiskSerializer to include created_at and updated_at in serialized output.
- Improved logging in signals for Risk and Control models, including serialization of values.
- Added new template tags for CIA label mapping.
- Refactored URL patterns for better clarity and added detail views for risks, controls, and incidents.
- Implemented list and detail views for risks, controls, and incidents with filtering options.
- Enhanced CSS for better UI/UX, including breadcrumbs and table styling.
- Created new templates for displaying individual risks, controls, and incidents with detailed information.
2025-09-08 15:03:12 +02:00
|
|
|
clean_changes = {
|
|
|
|
field: {"old": serialize_value(vals["old"]), "new": serialize_value(vals["new"])}
|
|
|
|
for field, vals in changes.items()
|
|
|
|
}
|
2025-09-07 20:52:19 +02:00
|
|
|
AuditLog.objects.create(
|
|
|
|
user=getattr(instance, "_changed_by", None),
|
|
|
|
action="update",
|
|
|
|
model="Risk",
|
|
|
|
object_id=instance.pk,
|
2025-09-09 12:00:29 +02:00
|
|
|
changes=clean_changes,
|
2025-09-07 20:52:19 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
@receiver(post_delete, sender=Risk)
|
|
|
|
def log_risk_delete(sender, instance, **kwargs):
|
|
|
|
"""
|
|
|
|
Signal that runs after a Risk is deleted.
|
|
|
|
"""
|
2025-09-09 12:00:29 +02:00
|
|
|
user = getattr(instance, "_changed_by", None) or get_current_user()
|
2025-09-07 20:52:19 +02:00
|
|
|
AuditLog.objects.create(
|
2025-09-09 12:00:29 +02:00
|
|
|
user=user,
|
2025-09-07 20:52:19 +02:00
|
|
|
action="delete",
|
|
|
|
model="Risk",
|
|
|
|
object_id=instance.pk,
|
|
|
|
changes=None, # no fields to track on deletion
|
|
|
|
)
|
|
|
|
|
feat: Enhance Risk Management Module
- Updated Risk model to include description, created_at, and updated_at fields.
- Modified RiskSerializer to include created_at and updated_at in serialized output.
- Improved logging in signals for Risk and Control models, including serialization of values.
- Added new template tags for CIA label mapping.
- Refactored URL patterns for better clarity and added detail views for risks, controls, and incidents.
- Implemented list and detail views for risks, controls, and incidents with filtering options.
- Enhanced CSS for better UI/UX, including breadcrumbs and table styling.
- Created new templates for displaying individual risks, controls, and incidents with detailed information.
2025-09-08 15:03:12 +02:00
|
|
|
# ---------------------------------------------------------------------------
|
|
|
|
# Controls
|
|
|
|
# ---------------------------------------------------------------------------
|
2025-09-07 20:52:19 +02:00
|
|
|
|
|
|
|
@receiver(post_save, sender=Control)
|
|
|
|
def log_control_save(sender, instance, created, **kwargs):
|
|
|
|
if created:
|
|
|
|
AuditLog.objects.create(
|
|
|
|
user=getattr(instance, "_changed_by", None),
|
|
|
|
action="create",
|
|
|
|
model="Control",
|
|
|
|
object_id=instance.pk,
|
feat: Enhance Risk Management Module
- Updated Risk model to include description, created_at, and updated_at fields.
- Modified RiskSerializer to include created_at and updated_at in serialized output.
- Improved logging in signals for Risk and Control models, including serialization of values.
- Added new template tags for CIA label mapping.
- Refactored URL patterns for better clarity and added detail views for risks, controls, and incidents.
- Implemented list and detail views for risks, controls, and incidents with filtering options.
- Enhanced CSS for better UI/UX, including breadcrumbs and table styling.
- Created new templates for displaying individual risks, controls, and incidents with detailed information.
2025-09-08 15:03:12 +02:00
|
|
|
changes={
|
|
|
|
f.name: {
|
|
|
|
"old": None,
|
|
|
|
"new": serialize_value(getattr(instance, f.name))
|
|
|
|
} for f in instance._meta.fields
|
|
|
|
},
|
2025-09-07 20:52:19 +02:00
|
|
|
)
|
|
|
|
else:
|
|
|
|
old = Control.objects.get(pk=instance.pk)
|
|
|
|
changes = model_diff(old, instance)
|
|
|
|
if changes:
|
feat: Enhance Risk Management Module
- Updated Risk model to include description, created_at, and updated_at fields.
- Modified RiskSerializer to include created_at and updated_at in serialized output.
- Improved logging in signals for Risk and Control models, including serialization of values.
- Added new template tags for CIA label mapping.
- Refactored URL patterns for better clarity and added detail views for risks, controls, and incidents.
- Implemented list and detail views for risks, controls, and incidents with filtering options.
- Enhanced CSS for better UI/UX, including breadcrumbs and table styling.
- Created new templates for displaying individual risks, controls, and incidents with detailed information.
2025-09-08 15:03:12 +02:00
|
|
|
clean_changes = {
|
|
|
|
field: {"old": serialize_value(vals["old"]), "new": serialize_value(vals["new"])}
|
|
|
|
for field, vals in changes.items()
|
|
|
|
}
|
2025-09-07 20:52:19 +02:00
|
|
|
AuditLog.objects.create(
|
|
|
|
user=getattr(instance, "_changed_by", None),
|
|
|
|
action="update",
|
|
|
|
model="Control",
|
|
|
|
object_id=instance.pk,
|
2025-09-09 12:00:29 +02:00
|
|
|
changes=clean_changes,
|
2025-09-07 20:52:19 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
@receiver(post_delete, sender=Control)
|
|
|
|
def log_control_delete(sender, instance, **kwargs):
|
2025-09-09 12:00:29 +02:00
|
|
|
user = getattr(instance, "_changed_by", None) or get_current_user()
|
2025-09-07 20:52:19 +02:00
|
|
|
AuditLog.objects.create(
|
2025-09-09 12:00:29 +02:00
|
|
|
user=user,
|
2025-09-07 20:52:19 +02:00
|
|
|
action="delete",
|
|
|
|
model="Control",
|
|
|
|
object_id=instance.pk,
|
|
|
|
changes=None,
|
|
|
|
)
|
|
|
|
|
2025-09-09 12:00:29 +02:00
|
|
|
@receiver(m2m_changed, sender=Control.risks.through)
|
|
|
|
def control_risks_changed(sender, instance, action, reverse, pk_set, **kwargs):
|
|
|
|
if action in {"post_add", "post_remove", "post_clear"}:
|
|
|
|
if action == "post_clear":
|
|
|
|
affected_risks = instance.risks.all()
|
|
|
|
elif pk_set:
|
|
|
|
if reverse:
|
|
|
|
from .models import Risk
|
|
|
|
affected_risks = Risk.objects.filter(pk__in=pk_set)
|
|
|
|
else:
|
|
|
|
affected_risks = Risk.objects.filter(pk__in=pk_set)
|
|
|
|
else:
|
|
|
|
affected_risks = instance.risks.all()
|
|
|
|
|
|
|
|
from .models import ResidualRisk
|
|
|
|
for risk in affected_risks:
|
|
|
|
residual, _ = ResidualRisk.objects.get_or_create(risk=risk)
|
|
|
|
residual.review_required = True
|
|
|
|
residual.save()
|
feat: Enhance Risk Management Module
- Updated Risk model to include description, created_at, and updated_at fields.
- Modified RiskSerializer to include created_at and updated_at in serialized output.
- Improved logging in signals for Risk and Control models, including serialization of values.
- Added new template tags for CIA label mapping.
- Refactored URL patterns for better clarity and added detail views for risks, controls, and incidents.
- Implemented list and detail views for risks, controls, and incidents with filtering options.
- Enhanced CSS for better UI/UX, including breadcrumbs and table styling.
- Created new templates for displaying individual risks, controls, and incidents with detailed information.
2025-09-08 15:03:12 +02:00
|
|
|
|
|
|
|
# ---------------------------------------------------------------------------
|
|
|
|
# Residual risks
|
|
|
|
# ---------------------------------------------------------------------------
|
2025-09-07 20:52:19 +02:00
|
|
|
|
|
|
|
@receiver(post_save, sender=ResidualRisk)
|
|
|
|
def log_residual_save(sender, instance, created, **kwargs):
|
|
|
|
if created:
|
|
|
|
AuditLog.objects.create(
|
|
|
|
user=getattr(instance, "_changed_by", None),
|
|
|
|
action="create",
|
|
|
|
model="ResidualRisk",
|
|
|
|
object_id=instance.pk,
|
feat: Enhance Risk Management Module
- Updated Risk model to include description, created_at, and updated_at fields.
- Modified RiskSerializer to include created_at and updated_at in serialized output.
- Improved logging in signals for Risk and Control models, including serialization of values.
- Added new template tags for CIA label mapping.
- Refactored URL patterns for better clarity and added detail views for risks, controls, and incidents.
- Implemented list and detail views for risks, controls, and incidents with filtering options.
- Enhanced CSS for better UI/UX, including breadcrumbs and table styling.
- Created new templates for displaying individual risks, controls, and incidents with detailed information.
2025-09-08 15:03:12 +02:00
|
|
|
changes={
|
|
|
|
f.name: {
|
|
|
|
"old": None,
|
|
|
|
"new": serialize_value(getattr(instance, f.name))
|
|
|
|
} for f in instance._meta.fields
|
|
|
|
},
|
2025-09-07 20:52:19 +02:00
|
|
|
)
|
|
|
|
else:
|
|
|
|
old = ResidualRisk.objects.get(pk=instance.pk)
|
|
|
|
changes = model_diff(old, instance)
|
|
|
|
if changes:
|
feat: Enhance Risk Management Module
- Updated Risk model to include description, created_at, and updated_at fields.
- Modified RiskSerializer to include created_at and updated_at in serialized output.
- Improved logging in signals for Risk and Control models, including serialization of values.
- Added new template tags for CIA label mapping.
- Refactored URL patterns for better clarity and added detail views for risks, controls, and incidents.
- Implemented list and detail views for risks, controls, and incidents with filtering options.
- Enhanced CSS for better UI/UX, including breadcrumbs and table styling.
- Created new templates for displaying individual risks, controls, and incidents with detailed information.
2025-09-08 15:03:12 +02:00
|
|
|
clean_changes = {
|
|
|
|
field: {"old": serialize_value(vals["old"]), "new": serialize_value(vals["new"])}
|
|
|
|
for field, vals in changes.items()
|
|
|
|
}
|
2025-09-07 20:52:19 +02:00
|
|
|
AuditLog.objects.create(
|
|
|
|
user=getattr(instance, "_changed_by", None),
|
|
|
|
action="update",
|
|
|
|
model="ResidualRisk",
|
|
|
|
object_id=instance.pk,
|
feat: Enhance Risk Management Module
- Updated Risk model to include description, created_at, and updated_at fields.
- Modified RiskSerializer to include created_at and updated_at in serialized output.
- Improved logging in signals for Risk and Control models, including serialization of values.
- Added new template tags for CIA label mapping.
- Refactored URL patterns for better clarity and added detail views for risks, controls, and incidents.
- Implemented list and detail views for risks, controls, and incidents with filtering options.
- Enhanced CSS for better UI/UX, including breadcrumbs and table styling.
- Created new templates for displaying individual risks, controls, and incidents with detailed information.
2025-09-08 15:03:12 +02:00
|
|
|
changes=clean_changes,
|
2025-09-07 20:52:19 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
@receiver(post_delete, sender=ResidualRisk)
|
|
|
|
def log_residual_delete(sender, instance, **kwargs):
|
2025-09-09 12:00:29 +02:00
|
|
|
user = getattr(instance, "_changed_by", None) or get_current_user()
|
2025-09-07 20:52:19 +02:00
|
|
|
AuditLog.objects.create(
|
2025-09-09 12:00:29 +02:00
|
|
|
user=user,
|
2025-09-07 20:52:19 +02:00
|
|
|
action="delete",
|
|
|
|
model="ResidualRisk",
|
|
|
|
object_id=instance.pk,
|
|
|
|
changes=None,
|
|
|
|
)
|
|
|
|
|
feat: Enhance Risk Management Module
- Updated Risk model to include description, created_at, and updated_at fields.
- Modified RiskSerializer to include created_at and updated_at in serialized output.
- Improved logging in signals for Risk and Control models, including serialization of values.
- Added new template tags for CIA label mapping.
- Refactored URL patterns for better clarity and added detail views for risks, controls, and incidents.
- Implemented list and detail views for risks, controls, and incidents with filtering options.
- Enhanced CSS for better UI/UX, including breadcrumbs and table styling.
- Created new templates for displaying individual risks, controls, and incidents with detailed information.
2025-09-08 15:03:12 +02:00
|
|
|
# ---------------------------------------------------------------------------
|
|
|
|
# Incidents
|
|
|
|
# ---------------------------------------------------------------------------
|
2025-09-07 20:52:19 +02:00
|
|
|
|
|
|
|
@receiver(post_save, sender=Incident)
|
|
|
|
def log_incident_save(sender, instance, created, **kwargs):
|
|
|
|
if created:
|
|
|
|
AuditLog.objects.create(
|
|
|
|
user=getattr(instance, "_changed_by", None),
|
|
|
|
action="create",
|
|
|
|
model="Incident",
|
|
|
|
object_id=instance.pk,
|
2025-09-09 12:00:29 +02:00
|
|
|
changes={
|
|
|
|
f.name: {
|
|
|
|
"old": None,
|
|
|
|
"new": serialize_value(getattr(instance, f.name))
|
|
|
|
} for f in instance._meta.fields
|
|
|
|
},
|
2025-09-07 20:52:19 +02:00
|
|
|
)
|
|
|
|
else:
|
|
|
|
old = Incident.objects.get(pk=instance.pk)
|
|
|
|
changes = model_diff(old, instance)
|
|
|
|
if changes:
|
feat: Enhance Risk Management Module
- Updated Risk model to include description, created_at, and updated_at fields.
- Modified RiskSerializer to include created_at and updated_at in serialized output.
- Improved logging in signals for Risk and Control models, including serialization of values.
- Added new template tags for CIA label mapping.
- Refactored URL patterns for better clarity and added detail views for risks, controls, and incidents.
- Implemented list and detail views for risks, controls, and incidents with filtering options.
- Enhanced CSS for better UI/UX, including breadcrumbs and table styling.
- Created new templates for displaying individual risks, controls, and incidents with detailed information.
2025-09-08 15:03:12 +02:00
|
|
|
clean_changes = {
|
|
|
|
field: {"old": serialize_value(vals["old"]), "new": serialize_value(vals["new"])}
|
|
|
|
for field, vals in changes.items()
|
|
|
|
}
|
2025-09-07 20:52:19 +02:00
|
|
|
AuditLog.objects.create(
|
|
|
|
user=getattr(instance, "_changed_by", None),
|
|
|
|
action="update",
|
|
|
|
model="Incident",
|
|
|
|
object_id=instance.pk,
|
2025-09-09 12:00:29 +02:00
|
|
|
changes=clean_changes,
|
2025-09-07 20:52:19 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
@receiver(m2m_changed, sender=Incident.related_risks.through)
|
|
|
|
def log_incident_risks_change(sender, instance, action, reverse, model, pk_set, **kwargs):
|
|
|
|
if action in ["post_add", "post_remove", "post_clear"]:
|
2025-09-09 12:00:29 +02:00
|
|
|
user = getattr(instance, "_changed_by", None) or get_current_user()
|
2025-09-07 20:52:19 +02:00
|
|
|
AuditLog.objects.create(
|
2025-09-09 12:00:29 +02:00
|
|
|
user=user,
|
2025-09-07 20:52:19 +02:00
|
|
|
action="update",
|
|
|
|
model="Incident",
|
|
|
|
object_id=instance.pk,
|
|
|
|
changes={"related_risks": {"action": action, "ids": list(pk_set)}},
|
|
|
|
)
|
|
|
|
|
|
|
|
@receiver(post_delete, sender=Incident)
|
|
|
|
def log_incident_delete(sender, instance, **kwargs):
|
2025-09-09 12:00:29 +02:00
|
|
|
user = getattr(instance, "_changed_by", None) or get_current_user()
|
2025-09-07 20:52:19 +02:00
|
|
|
AuditLog.objects.create(
|
2025-09-09 12:00:29 +02:00
|
|
|
user=user,
|
2025-09-07 20:52:19 +02:00
|
|
|
action="delete",
|
|
|
|
model="Incident",
|
|
|
|
object_id=instance.pk,
|
|
|
|
changes=None,
|
|
|
|
)
|