From 937cc9a7bd46dfd1eb547c64ddb5f95d785ab88d Mon Sep 17 00:00:00 2001 From: Mohamed-Hacene Date: Mon, 15 Apr 2024 14:45:14 +0200 Subject: [PATCH 01/12] feat: add scoring notion --- backend/core/models.py | 6 ++ backend/core/views.py | 6 ++ .../src/lib/components/Forms/Score.svelte | 70 +++++++++++++++++++ frontend/src/lib/utils/crud.ts | 2 +- frontend/src/lib/utils/schemas.ts | 1 + .../[id=uuid]/+page.svelte | 2 + 6 files changed, 86 insertions(+), 1 deletion(-) create mode 100644 frontend/src/lib/components/Forms/Score.svelte diff --git a/backend/core/models.py b/backend/core/models.py index 04762a1ad..3c5bb57fd 100644 --- a/backend/core/models.py +++ b/backend/core/models.py @@ -1465,6 +1465,7 @@ def quality_check(self) -> dict: class RequirementAssessment(AbstractBaseModel, FolderMixin): + class Status(models.TextChoices): TODO = "to_do", _("To do") IN_PROGRESS = "in_progress", _("In progress") @@ -1473,12 +1474,17 @@ class Status(models.TextChoices): COMPLIANT = "compliant", _("Compliant") NOT_APPLICABLE = "not_applicable", _("Not applicable") + status = models.CharField( max_length=100, choices=Status.choices, default=Status.TODO, verbose_name=_("Status"), ) + score = models.IntegerField( + default=-1, + choices=[(i, i) for i in range(-1, 101)] + ) evidences = models.ManyToManyField( Evidence, blank=True, diff --git a/backend/core/views.py b/backend/core/views.py index b53230040..8999bcc66 100644 --- a/backend/core/views.py +++ b/backend/core/views.py @@ -1373,6 +1373,12 @@ def to_review(self, request): @action(detail=False, name="Get status choices") def status(self, request): return Response(dict(RequirementAssessment.Status.choices)) + + @action(detail=False, name="Get score choices") + def score(self, request): + dict_score = dict([('--', -1)]) + dict_score.update([(i, i) for i in range(0, 101)]) + return Response(dict_score) @api_view(["GET"]) diff --git a/frontend/src/lib/components/Forms/Score.svelte b/frontend/src/lib/components/Forms/Score.svelte new file mode 100644 index 000000000..d16de226c --- /dev/null +++ b/frontend/src/lib/components/Forms/Score.svelte @@ -0,0 +1,70 @@ + + +
+ {#if label !== undefined} + {#if $constraints?.required} + + {:else} + + {/if} + {/if} + {#if $errors && $errors.length > 0} +
+ {#each $errors as error} +

{error}

+ {/each} +
+ {/if} +
+ +
+ {#if helpText} +

{helpText}

+ {/if} +
diff --git a/frontend/src/lib/utils/crud.ts b/frontend/src/lib/utils/crud.ts index c8ec94b36..c56cffeae 100644 --- a/frontend/src/lib/utils/crud.ts +++ b/frontend/src/lib/utils/crud.ts @@ -390,7 +390,7 @@ export const URL_MODEL_MAP: ModelMap = { localFrGender: 'f', verboseName: 'Requirement assessment', verboseNamePlural: 'Requirement assessments', - selectFields: [{ field: 'status' }], + selectFields: [{ field: 'status' }, { field: 'score' }], foreignKeyFields: [ { field: 'applied_controls', urlModel: 'applied-controls' }, { field: 'evidences', urlModel: 'evidences' }, diff --git a/frontend/src/lib/utils/schemas.ts b/frontend/src/lib/utils/schemas.ts index 90fdc861e..fa4208243 100644 --- a/frontend/src/lib/utils/schemas.ts +++ b/frontend/src/lib/utils/schemas.ts @@ -151,6 +151,7 @@ export const AssetSchema = baseNamedObject({ export const RequirementAssessmentSchema = z.object({ status: z.string(), + score: z.number().optional().nullable(), comment: z.string().optional().nullable(), folder: z.string(), requirement: z.string(), diff --git a/frontend/src/routes/(app)/requirement-assessments/[id=uuid]/+page.svelte b/frontend/src/routes/(app)/requirement-assessments/[id=uuid]/+page.svelte index bc03d3bf4..1fa3c43e8 100644 --- a/frontend/src/routes/(app)/requirement-assessments/[id=uuid]/+page.svelte +++ b/frontend/src/routes/(app)/requirement-assessments/[id=uuid]/+page.svelte @@ -11,6 +11,7 @@ import SuperForm from '$lib/components/Forms/Form.svelte'; import HiddenInput from '$lib/components/Forms/HiddenInput.svelte'; import Select from '$lib/components/Forms/Select.svelte'; + import Score from '$lib/components/Forms/Score.svelte'; import TextArea from '$lib/components/Forms/TextArea.svelte'; import CreateModal from '$lib/components/Modals/CreateModal.svelte'; import ModelTable from '$lib/components/ModelTable/ModelTable.svelte'; @@ -266,6 +267,7 @@