Skip to content

Commit

Permalink
Merge pull request #48 from pep-un/feature-control
Browse files Browse the repository at this point in the history
Feature control
  • Loading branch information
pep-un authored Jan 2, 2024
2 parents 4e7af81 + ca2ba41 commit e90f071
Show file tree
Hide file tree
Showing 18 changed files with 206 additions and 38 deletions.
26 changes: 15 additions & 11 deletions conformity/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,58 +5,62 @@
from django.contrib import admin
from import_export import resources
from import_export.admin import ImportExportModelAdmin
from .models import Organization, Policy, Measure, Conformity, Audit, Finding, Action
from .models import Organization, Policy, Measure, Conformity, Audit, Finding, Action, Control, ControlPoint


# Organization
class OrganizationResources(resources.ModelResource):
class Meta:
model = Organization


class OrganizationAdmin(ImportExportModelAdmin):
ressource_class = Organization

admin.site.register(Organization, OrganizationAdmin)

# Policy
class PolicyResources(resources.ModelResource):
class Meta:
model = Policy


class PolicyAdmin(ImportExportModelAdmin):
ressource_class = Policy

admin.site.register(Policy, PolicyAdmin)

# Measure
class MeasureResources(resources.ModelResource):
class Meta:
model = Measure


class MeasureAdmin(ImportExportModelAdmin):
ressource_class = Measure

admin.site.register(Measure, MeasureAdmin)

# Conformity
class ConformityResources(resources.ModelResource):
class Meta:
model = Conformity


class ConformityAdmin(ImportExportModelAdmin):
ressource_class = Conformity

admin.site.register(Conformity, ConformityAdmin)

# Action
class ActionResources(resources.ModelResource):
class Meta:
model = Action


class ActionAdmin(ImportExportModelAdmin):
ressource_class = Action


# Registration
admin.site.register(Policy, PolicyAdmin)
admin.site.register(Measure, MeasureAdmin)
admin.site.register(Conformity, ConformityAdmin)
admin.site.register(Action, ActionAdmin)
###
admin.site.register(Audit)
admin.site.register(Finding)

admin.site.register(Organization, OrganizationAdmin)
admin.site.register(Control)
admin.site.register(ControlPoint)
15 changes: 15 additions & 0 deletions conformity/filterset.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
from django_filters import FilterSet, CharFilter
from .models import Action, ControlPoint


class ActionFilter(FilterSet):
class Meta:
model = Action
fields = ['status', 'organization', 'owner', 'associated_conformity__id', 'associated_findings__id',
'associated_controlPoints__id']


class ControlFilter(FilterSet):
class Meta:
model = ControlPoint
fields = ['control__level', 'control__organization', 'control__conformity__id', 'control__control__id', 'control__frequency', 'control__level']
2 changes: 1 addition & 1 deletion conformity/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def __init__(self, *args, **kwargs):
self.fields['create_date'].disabled = True
self.fields['update_date'].disabled = True

generic_fields = ['title', 'owner', 'status', 'status_comment']
generic_fields = ['title', 'owner', 'status', 'status_comment', 'reference']
analyse_fields = ['organization', 'associated_conformity', 'associated_findings', 'associated_controlPoints', 'description']
plan_fields = ['plan_start_date', 'plan_end_date', 'plan_comment']
implement_fields = ['implement_start_date', 'implement_end_date', 'implement_status', 'implement_comment']
Expand Down
23 changes: 23 additions & 0 deletions conformity/migrations/0038_action_reference_control_level.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Generated by Django 4.1.6 on 2023-03-11 22:58

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('conformity', '0037_alter_controlpoint_control_date'),
]

operations = [
migrations.AddField(
model_name='action',
name='reference',
field=models.URLField(blank=True),
),
migrations.AddField(
model_name='control',
name='level',
field=models.IntegerField(choices=[(1, '1st level control'), (2, '2nd level control')], default=1),
),
]
18 changes: 18 additions & 0 deletions conformity/migrations/0039_control_control.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 4.1.6 on 2023-03-14 01:56

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('conformity', '0038_action_reference_control_level'),
]

operations = [
migrations.AddField(
model_name='control',
name='control',
field=models.ManyToManyField(blank=True, to='conformity.control'),
),
]
18 changes: 18 additions & 0 deletions conformity/migrations/0040_alter_control_level.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 4.1.6 on 2023-03-18 05:28

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('conformity', '0039_control_control'),
]

operations = [
migrations.AlterField(
model_name='control',
name='level',
field=models.IntegerField(choices=[(1, '1st level'), (2, '2nd level')], default=1),
),
]
30 changes: 26 additions & 4 deletions conformity/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,10 @@ def get_action(self):
"""Return the list of Action associated with this Conformity"""
return Action.objects.filter(associated_conformity=self.id).filter(active=True)

def get_control(self):
"""Return the list of Control associated with this Conformity"""
return Control.objects.filter(conformity=self.id)

def set_status(self, i):
"""Update the status and call recursive update function"""
self.status = i
Expand Down Expand Up @@ -243,6 +247,7 @@ def update(self):
# Callback functions



@receiver(pre_save, sender=Measure)
def post_init_callback(instance, **kwargs):
"""This function keep hierarchy of the Measure working on each Measure instantiation"""
Expand Down Expand Up @@ -385,10 +390,9 @@ def get_severity(self):
"""return the readable version of the Findings Severity"""
return self.Severity(self.severity).label

@staticmethod
def get_absolute_url():
"""return the absolute URL for Forms, could probably do better"""
return reverse('conformity:audit_index')
def get_absolute_url(self):
""""return somewhere else when a edit has work """
return reverse('conformity:audit_detail', kwargs={'pk': self.audit_id})

def get_action(self):
"""Return the list of Action associated with this Findings"""
Expand All @@ -408,14 +412,27 @@ class Frequency(models.IntegerChoices):
BIMONTHLY = '6', _('Bimonthly')
MONTHLY = '12', _('Monthly')

class Level(models.IntegerChoices):
""" List of control level possible for a control """
FIRST = '1', _('1st level')
SECOND = '2', _('2nd level')

title = models.CharField(max_length=256)
description = models.TextField(max_length=4096, blank=True)
organization = models.ForeignKey(Organization, on_delete=models.CASCADE, blank=True, null=True)
conformity = models.ManyToManyField(Conformity, blank=True)
control = models.ManyToManyField('self', blank=True)
frequency = models.IntegerField(
choices=Frequency.choices,
default=Frequency.YEARLY,
)
level = models.IntegerField(
choices=Level.choices,
default=Level.FIRST,
)

def __str__(self):
return "[" + str(self.organization) + "] " + self.title

@staticmethod
def get_absolute_url():
Expand Down Expand Up @@ -484,6 +501,10 @@ def __str__(self):
+ self.period_end_date.strftime('%b-%Y') + ")"


def get_action(self):
"""Return the list of Action associated with this Findings"""
return Action.objects.filter(associated_controlPoints=self.id)

class Action(models.Model):
"""
Action class represent the actions taken by the Organization to improve security.
Expand Down Expand Up @@ -511,6 +532,7 @@ class Status(models.TextChoices):
default=Status.ANALYSING,
)
status_comment = models.TextField(max_length=4096, blank=True)
reference = models.URLField(blank=True)
active = models.BooleanField(default=True)

' Analyse Phase'
Expand Down
1 change: 1 addition & 0 deletions conformity/templates/conformity/action_form.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ <h1 class="h1 bi bi-pencil-square" xmlns="http://www.w3.org/1999/html"> Edit of
{% bootstrap_field form.title layout='floating' %}
{% bootstrap_field form.owner layout='floating' %}
{% bootstrap_field form.status layout='floating' %}
{% bootstrap_field form.reference layout='floating' %}
{% bootstrap_field form.status_comment layout='floating' %}
<p class="text-center fw-lighter mx-3">Created on {{ form.create_date.value }}, last update {{ form.update_date.value }}.</p>
<div class="accordion" id="accordion">
Expand Down
8 changes: 7 additions & 1 deletion conformity/templates/conformity/action_list.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,12 @@ <h1 class="h1 bi bi-arrow-repeat"> Actions </h1>
<th scope="col" class="">Owner</th>
<th scope="col" class="">Status</th>
<th scope="col" class="">Last Update</th>
<th scope="col" class="text-center">Ref.</th>
<th scope="col" class="text-center">Edit</th>
</tr>
</thead>
<tbody>
{% for action in action_list %}
{% for action in object_list %}
<tr>
<td class="col">
{{ action.title }}
Expand Down Expand Up @@ -56,6 +57,11 @@ <h1 class="h1 bi bi-arrow-repeat"> Actions </h1>
<td class="col">
{{ action.update_date | date:'d-M-Y'}}
</td>
<td class="text-center">
{% if action.reference %}
<a href="{{ action.reference }}" class="bi bi-box-arrow-up-right"></a>
{% endif %}
</td>
<td class="text-center">
<a href="{% url 'conformity:action_form' action.id %}" class="bi bi-pencil-square"></a>
</td>
Expand Down
36 changes: 31 additions & 5 deletions conformity/templates/conformity/conformity_orgpol_list.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ <h1 class="h1 bi bi-shield-shaded">
<th scope="col" class="">Measure</th>
<th scope="col" class="text-center">Status</th>
<th scope="col" class="text-center">Owner</th>
<th scope="col" class="text-center">Controls</th>
<th scope="col" class="text-center">Actions</th>
<th scope="col" class="text-center">Comment</th>
<th scope="col" class="text-center">Edit</th>
Expand Down Expand Up @@ -42,16 +43,23 @@ <h1 class="h1 bi bi-shield-shaded">
{{ con.responsible|capfirst }}
{% endif %}
</td>
<td class="col-1 text-center">
{% if con.get_control %}
<a href="{% url 'conformity:control_index' %}?control__conformity__id={{con.id}}">
<button type="button" class="btn btn-outline-primary btn-sm">{{ con.get_control | length }}</button>
</a>
{% endif %}
</td>
<td class="col-1 text-center">
{% if con.get_action %}
<a href="{% url 'conformity:action_con_index' con.id %}"
<button type="button" class="btn btn-outline-primary btn-sm">{{ con.get_action | length }}</button>
<a href="{% url 'conformity:action_index' %}?associated_conformity__id={{con.id}}">
<button type="button" class="btn btn-outline-primary btn-sm">{{ con.get_action | length }}</button>
</a>
{% endif %}
</td>
<td class="col-1 text-center">
{% if con.comment %}
<i class="bi bi-chat-text"></i>
<i class="bi bi-chat-text" title="{{ con.comment }}"></i>
{% endif %}
</td>
<td class="col-1 text-center"> <a href="{% url 'conformity:conformity_form' con.id %}"> <i class="bi bi-pencil-square"></i> </a> </td>
Expand Down Expand Up @@ -79,14 +87,23 @@ <h1 class="h1 bi bi-shield-shaded">
{{ con.responsible|capfirst }}
{% endif %}
</td>
<td class="col-1 text-center">
{% if con.get_control %}
<a href="{% url 'conformity:control_index' %}?control__conformity__id={{con.id}}">
<button type="button" class="btn btn-outline-primary btn-sm">{{ con.get_control | length }}</button>
</a>
{% endif %}
</td>
<td class="col-1 text-center">
{% if con.get_action %}
<a href="{% url 'conformity:action_index' %}?associated_conformity__id={{con.id}}">
<button type="button" class="btn btn-outline-primary btn-sm">{{ con.get_action | length }}</button>
</a>
{% endif %}
</td>
<td class="col-1 text-center">
{% if con.comment %}
<i class="bi bi-chat-text"></i>
<i class="bi bi-chat-text" title="{{ con.comment }}"></i>
{% endif %}
</td>
<td class="text-center">
Expand Down Expand Up @@ -116,14 +133,23 @@ <h1 class="h1 bi bi-shield-shaded">
{{ con.responsible|capfirst }}
{% endif %}
</td>
<td class="col-1 text-center">
{% if con.get_control %}
<a href="{% url 'conformity:control_index' %}?control_conformity__id={{con.id}}">
<button type="button" class="btn btn-outline-primary btn-sm">{{ con.get_control | length }}</button>
</a>
{% endif %}
</td>
<td class="col-1 text-center">
{% if con.get_action %}
<a href="{% url 'conformity:action_index' %}?associated_conformity__id={{con.id}}">
<button type="button" class="btn btn-outline-primary btn-sm">{{ con.get_action | length }}</button>
</a>
{% endif %}
</td>
<td class="col-1 text-center">
{% if con.comment %}
<i class="bi bi-chat-text"></i>
<i class="bi bi-chat-text" title="{{ con.comment }}"></i>
{% endif %}
</td>
<td class="text-center">
Expand Down
16 changes: 16 additions & 0 deletions conformity/templates/conformity/controlpoint_form.html
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,23 @@ <h2>{{ controlpoint.control.title }}</h2>
</ul>
<hr />
{% bootstrap_form form %}
<h2 class="h4">Associated actions</h2>
<div class="col list-group mb-3">
{% for action in controlpoint.get_action %}
<a class="list-group-item list-group-item-action d-flex justify-content-between align-items-start" href="{% url 'conformity:action_form' action.id %}">
{{action}} <span class="badge bg-primary rounded-pill"> {{ action.get_status_display }} </span>
</a>
{% empty %}
<p class="list-group-item list-group-item-warning text-center my-0">No action associated</p>
{% endfor %}
<a class="list-group-item list-group-item-action list-group-item-success text-center" href="{% url 'conformity:action_create' %}" class="text-success">
<i class="bi bi-plus-circle"></i> Register a corrective action
</a>
</div>
<br />
<br />
{% bootstrap_button button_type="submit" content="Save" %}
</a>
</div>
</div>
</form>
Expand Down
Loading

0 comments on commit e90f071

Please sign in to comment.