Skip to content

Commit

Permalink
Merge pull request #774 from intuitem/model/appliec-control-status-ch…
Browse files Browse the repository at this point in the history
…oices

Update AppliedControl status choices
  • Loading branch information
ab-smith authored Aug 30, 2024
2 parents d0f5564 + 8621e87 commit f43d6df
Show file tree
Hide file tree
Showing 15 changed files with 213 additions and 81 deletions.
18 changes: 9 additions & 9 deletions backend/app_tests/api/test_api_applied_controls.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
APPLIED_CONTROL_DESCRIPTION = "Test Description"
APPLIED_CONTROL_CATEGORY = ("technical", "Technical")
APPLIED_CONTROL_CATEGORY2 = ("process", "Process")
APPLIED_CONTROL_STATUS = ("planned", "Planned")
APPLIED_CONTROL_STATUS2 = ("active", "Active")
APPLIED_CONTROL_STATUS = AppliedControl.Status.IN_PROGRESS
APPLIED_CONTROL_STATUS2 = AppliedControl.Status.ACTIVE
APPLIED_CONTROL_EFFORT = ("L", "Large")
APPLIED_CONTROL_EFFORT2 = ("M", "Medium")
APPLIED_CONTROL_LINK = "https://example.com"
Expand Down Expand Up @@ -100,7 +100,7 @@ def test_get_applied_controls(self, test):
"name": APPLIED_CONTROL_NAME,
"description": APPLIED_CONTROL_DESCRIPTION,
"category": APPLIED_CONTROL_CATEGORY[0],
"status": APPLIED_CONTROL_STATUS[0],
"status": APPLIED_CONTROL_STATUS._value_,
"link": APPLIED_CONTROL_LINK,
"eta": APPLIED_CONTROL_ETA,
"effort": APPLIED_CONTROL_EFFORT[0],
Expand All @@ -110,7 +110,7 @@ def test_get_applied_controls(self, test):
"folder": {"id": str(test.folder.id), "str": test.folder.name},
"reference_control": None,
"category": APPLIED_CONTROL_CATEGORY[1],
"status": APPLIED_CONTROL_STATUS[1],
"status": APPLIED_CONTROL_STATUS._value_,
"effort": APPLIED_CONTROL_EFFORT[1],
},
user_group=test.user_group,
Expand All @@ -131,7 +131,7 @@ def test_create_applied_controls(self, test):
"name": APPLIED_CONTROL_NAME,
"description": APPLIED_CONTROL_DESCRIPTION,
"category": APPLIED_CONTROL_CATEGORY[0],
"status": APPLIED_CONTROL_STATUS[0],
"status": APPLIED_CONTROL_STATUS._value_,
"link": APPLIED_CONTROL_LINK,
"eta": APPLIED_CONTROL_ETA,
"effort": APPLIED_CONTROL_EFFORT[0],
Expand All @@ -140,7 +140,7 @@ def test_create_applied_controls(self, test):
{
"folder": {"id": str(test.folder.id), "str": test.folder.name},
"category": APPLIED_CONTROL_CATEGORY[1],
"status": APPLIED_CONTROL_STATUS[1],
"status": APPLIED_CONTROL_STATUS._value_,
"effort": APPLIED_CONTROL_EFFORT[1],
},
user_group=test.user_group,
Expand All @@ -163,7 +163,7 @@ def test_update_applied_controls(self, test):
"name": APPLIED_CONTROL_NAME,
"description": APPLIED_CONTROL_DESCRIPTION,
"category": APPLIED_CONTROL_CATEGORY[0],
"status": APPLIED_CONTROL_STATUS[0],
"status": APPLIED_CONTROL_STATUS._value_,
"link": APPLIED_CONTROL_LINK,
"eta": APPLIED_CONTROL_ETA,
"effort": APPLIED_CONTROL_EFFORT[0],
Expand All @@ -173,7 +173,7 @@ def test_update_applied_controls(self, test):
"name": "new " + APPLIED_CONTROL_NAME,
"description": "new " + APPLIED_CONTROL_DESCRIPTION,
"category": APPLIED_CONTROL_CATEGORY2[0],
"status": APPLIED_CONTROL_STATUS2[0],
"status": APPLIED_CONTROL_STATUS2._value_,
"link": "new " + APPLIED_CONTROL_LINK,
"eta": "2025-01-01",
"effort": APPLIED_CONTROL_EFFORT2[0],
Expand All @@ -182,7 +182,7 @@ def test_update_applied_controls(self, test):
{
"folder": {"id": str(test.folder.id), "str": test.folder.name},
"category": APPLIED_CONTROL_CATEGORY[1],
"status": APPLIED_CONTROL_STATUS[1],
"status": APPLIED_CONTROL_STATUS._value_,
"effort": APPLIED_CONTROL_EFFORT[1],
},
user_group=test.user_group,
Expand Down
18 changes: 9 additions & 9 deletions backend/app_tests/api/test_api_policies.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
# Generic policy data for tests
POLICY_NAME = "Test Policy"
POLICY_DESCRIPTION = "Test Description"
POLICY_STATUS = ("planned", "Planned")
POLICY_STATUS2 = ("active", "Active")
POLICY_STATUS = Policy.Status.TO_DO
POLICY_STATUS2 = Policy.Status.ACTIVE
POLICY_EFFORT = ("L", "Large")
POLICY_EFFORT2 = ("M", "Medium")
POLICY_LINK = "https://example.com"
Expand Down Expand Up @@ -97,7 +97,7 @@ def test_get_policies(self, test):
{
"name": POLICY_NAME,
"description": POLICY_DESCRIPTION,
"status": POLICY_STATUS[0],
"status": POLICY_STATUS._value_,
"link": POLICY_LINK,
"eta": POLICY_ETA,
"effort": POLICY_EFFORT[0],
Expand All @@ -106,7 +106,7 @@ def test_get_policies(self, test):
{
"folder": {"id": str(test.folder.id), "str": test.folder.name},
"reference_control": None,
"status": POLICY_STATUS[1],
"status": POLICY_STATUS._value_,
"effort": POLICY_EFFORT[1],
},
user_group=test.user_group,
Expand All @@ -122,15 +122,15 @@ def test_create_policies(self, test):
{
"name": POLICY_NAME,
"description": POLICY_DESCRIPTION,
"status": POLICY_STATUS[0],
"status": POLICY_STATUS._value_,
"link": POLICY_LINK,
"eta": POLICY_ETA,
"effort": POLICY_EFFORT[0],
"folder": str(test.folder.id),
},
{
"folder": {"id": str(test.folder.id), "str": test.folder.name},
"status": POLICY_STATUS[1],
"status": POLICY_STATUS._value_,
"effort": POLICY_EFFORT[1],
},
user_group=test.user_group,
Expand All @@ -149,7 +149,7 @@ def test_update_policies(self, test):
{
"name": POLICY_NAME,
"description": POLICY_DESCRIPTION,
"status": POLICY_STATUS[0],
"status": POLICY_STATUS._value_,
"link": POLICY_LINK,
"eta": POLICY_ETA,
"effort": POLICY_EFFORT[0],
Expand All @@ -158,15 +158,15 @@ def test_update_policies(self, test):
{
"name": "new " + POLICY_NAME,
"description": "new " + POLICY_DESCRIPTION,
"status": POLICY_STATUS2[0],
"status": POLICY_STATUS2._value_,
"link": "new " + POLICY_LINK,
"eta": "2025-01-01",
"effort": POLICY_EFFORT2[0],
"folder": str(folder.id),
},
{
"folder": {"id": str(test.folder.id), "str": test.folder.name},
"status": POLICY_STATUS[1],
"status": POLICY_STATUS._value_,
"effort": POLICY_EFFORT[1],
},
user_group=test.user_group,
Expand Down
28 changes: 14 additions & 14 deletions backend/core/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,10 @@ def flatten_dict(

STATUS_COLOR_MAP = { # TODO: Move these kinds of color maps to frontend
"undefined": "#CCC",
"planned": "#BFDBFE",
"--": "#CCC",
"to_do": "#BFDBFE",
"active": "#46D39A",
"inactive": "#E55759",
"deprecated": "#E55759",
"in_progress": "#5470c6",
"in_review": "#BBF7D0",
"done": "#46D39A",
Expand Down Expand Up @@ -508,10 +509,12 @@ def applied_control_per_status(user: User):
labels = list()
local_lables = list()
color_map = {
"undefined": "#CCC",
"planned": "#BFDBFE",
"active": "#46D39A",
"inactive": "#E55759",
AppliedControl.Status.UNDEFINED: "#CCC",
AppliedControl.Status.TO_DO: "#BFDBFE",
AppliedControl.Status.ACTIVE: "#46D39A",
AppliedControl.Status.IN_PROGRESS: "#392F5A",
AppliedControl.Status.ON_HOLD: "#F4D06F",
AppliedControl.Status.DEPRECATED: "#E55759",
}
(
object_ids_view,
Expand All @@ -521,16 +524,11 @@ def applied_control_per_status(user: User):
Folder.get_root_folder(), user, AppliedControl
)
viewable_applied_controls = AppliedControl.objects.filter(id__in=object_ids_view)
undefined_count = viewable_applied_controls.filter(status__isnull=True).count()
values.append(
{"value": undefined_count, "itemStyle": {"color": color_map["undefined"]}}
)
for st in AppliedControl.Status.choices:
count = viewable_applied_controls.filter(status=st[0]).count()
v = {"value": count, "itemStyle": {"color": color_map[st[0]]}}
values.append(v)
labels.append(st[1])
labels.insert(0, "undefined")
local_lables = [camel_case(str(label)) for label in labels]
return {"localLables": local_lables, "labels": labels, "values": values}

Expand Down Expand Up @@ -799,9 +797,11 @@ def risk_status(user: User, risk_assessment_list):
}
mtg_status_out = {
"--": list(),
"planned": list(),
"to_do": list(),
"in_progress": list(),
"on_hold": list(),
"active": list(),
"inactive": list(),
"deprecated": list(),
}

max_tmp = list()
Expand Down Expand Up @@ -916,7 +916,7 @@ def compile_risk_assessment_for_composer(user, risk_assessment_list: list):

values = list()
labels = list()

# WARNING: this is wrong - FIX ME because we compute the controls multiple times if used accross multiple scenarios
for st in AppliedControl.Status.choices:
count = (
AppliedControl.objects.filter(status=st[0])
Expand Down
45 changes: 45 additions & 0 deletions backend/core/migrations/0023_alter_appliedcontrol_status.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# Generated by Django 5.1 on 2024-08-29 13:41

from django.db import migrations, models


def update_status(apps, schema_editor):
AppliedControl = apps.get_model("core", "AppliedControl")
for control in AppliedControl.objects.all():
if control.status == "planned":
control.status = "to_do"
control.save()
elif control.status == "inactive":
control.status = "deprecated"
control.save()
elif control.status is None:
control.status = "--"
control.save()


class Migration(migrations.Migration):
dependencies = [
("core", "0022_riskscenario_qualifications"),
]

operations = [
migrations.AlterField(
model_name="appliedcontrol",
name="status",
field=models.CharField(
blank=True,
choices=[
("to_do", "To do"),
("in_progress", "In progress"),
("active", "Active"),
("on_hold", "On hold"),
("deprecated", "Deprecated"),
("--", "Undefined"),
],
default="--",
max_length=20,
verbose_name="Status",
),
),
migrations.RunPython(update_status),
]
9 changes: 6 additions & 3 deletions backend/core/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -1188,9 +1188,12 @@ def get_size(self):

class AppliedControl(NameDescriptionMixin, FolderMixin, PublishInRootFolderMixin):
class Status(models.TextChoices):
PLANNED = "planned", _("Planned")
TO_DO = "to_do", _("To do")
IN_PROGRESS = "in_progress", _("In progress")
ON_HOLD = "on_hold", _("On hold")
ACTIVE = "active", _("Active")
INACTIVE = "inactive", _("Inactive")
DEPRECATED = "deprecated", _("Deprecated")
UNDEFINED = "--", _("Undefined")

CATEGORY = ReferenceControl.CATEGORY
CSF_FUNCTION = ReferenceControl.CSF_FUNCTION
Expand Down Expand Up @@ -1234,7 +1237,7 @@ class Status(models.TextChoices):
status = models.CharField(
max_length=20,
choices=Status.choices,
null=True,
default=Status.UNDEFINED,
blank=True,
verbose_name=_("Status"),
)
Expand Down
1 change: 0 additions & 1 deletion backend/core/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,6 @@ class AppliedControlReadSerializer(AppliedControlWriteSerializer):
csf_function = serializers.CharField(
source="get_csf_function_display"
) # type : get_type_display
status = serializers.CharField(source="get_status_display")
evidences = FieldsRelatedField(many=True)
effort = serializers.CharField(source="get_effort_display")

Expand Down
32 changes: 19 additions & 13 deletions backend/core/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -1312,10 +1312,12 @@ def action_plan(self, request, pk):
)
if UUID(pk) in viewable_objects:
response = {
"planned": [],
"active": [],
"inactive": [],
"none": [],
"to_do": [],
"in_progress": [],
"on_hold": [],
"active": [],
"deprecated": [],
}
compliance_assessment_object = self.get_object()
requirement_assessments_objects = (
Expand All @@ -1335,11 +1337,11 @@ def action_plan(self, request, pk):
.filter(applied_controls=applied_control["id"])
.count()
)
response[applied_control["status"].lower()].append(
applied_control
) if applied_control["status"] else response["none"].append(
applied_control
)
if applied_control["status"] == "--":
response["none"].append(applied_control)
else:
response[applied_control["status"].lower()].append(applied_control)

return Response(response)

@action(detail=True, name="Get action plan PDF")
Expand All @@ -1349,15 +1351,19 @@ def action_plan_pdf(self, request, pk):
)
if UUID(pk) in object_ids_view:
context = {
"planned": list(),
"to_do": list(),
"in_progress": list(),
"on_hold": list(),
"active": list(),
"inactive": list(),
"deprecated": list(),
"no status": list(),
}
color_map = {
"planned": "#93c5fd",
"active": "#86efac",
"inactive": "#fca5a5",
"to_do": "#FFF8F0",
"in_progress": "#392F5A",
"on_hold": "#F4D06F",
"active": "#9DD9D2",
"deprecated": "#ff8811",
"no status": "#e5e7eb",
}
status = AppliedControl.Status.choices
Expand Down
1 change: 1 addition & 0 deletions frontend/messages/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -465,6 +465,7 @@
"inProgress": "In progress",
"inReview": "In review",
"deprecated": "Deprecated",
"onHold": "On hold",
"done": "Done",
"nonCompliant": "Non compliant",
"nonCompliantMinor": "Non compliant minor",
Expand Down
Loading

0 comments on commit f43d6df

Please sign in to comment.