Skip to content

Commit

Permalink
Merge pull request #115 from intuitem/CA-264-Display-and-manage-statu…
Browse files Browse the repository at this point in the history
…s-for-assessments

Ca 264 display and manage status for assessments
  • Loading branch information
eric-intuitem authored Mar 11, 2024
2 parents 41661e9 + b2a55b7 commit 57867f4
Show file tree
Hide file tree
Showing 12 changed files with 64 additions and 39 deletions.
16 changes: 0 additions & 16 deletions backend/core/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -363,22 +363,6 @@ class ComplianceAssessmentFilter(GenericFilterSet):
)
project = GenericModelMultipleChoiceFilter(queryset=Project.objects.all())
framework = GenericModelMultipleChoiceFilter(queryset=Framework.objects.all())
is_draft = GenericChoiceFilter(
choices=((True, _("Yes")), (False, _("No"))),
widget=Select(
attrs={
"class": "bg-gray-50 border border-gray-300 text-gray-900 text-sm rounded-lg focus:ring-blue-500 focus:border-blue-500 block w-full p-2.5 disabled:opacity-50"
}
),
)
is_obsolete = GenericChoiceFilter(
choices=((True, _("Yes")), (False, _("No"))),
widget=Select(
attrs={
"class": "bg-gray-50 border border-gray-300 text-gray-900 text-sm rounded-lg focus:ring-blue-500 focus:border-blue-500 block w-full p-2.5 disabled:opacity-50"
}
),
)
orderby = GenericOrderingFilter(
fields=(
("name", "name"),
Expand Down
10 changes: 9 additions & 1 deletion backend/core/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,10 @@ class RiskAssessmentViewSet(BaseModelViewSet):
"status",
]

@action(detail=False, name="Get status choices")
def status(self, request):
return Response(dict(RiskAssessment.Status.choices))

@action(detail=False, name="Get quality check")
def quality_check(self, request):
"""
Expand Down Expand Up @@ -1129,10 +1133,14 @@ class ComplianceAssessmentViewSet(BaseModelViewSet):
"""

model = ComplianceAssessment
filterset_fields = ["framework", "project"]
filterset_fields = ["framework", "project", "status"]
search_fields = ["name", "description"]
ordering_fields = ["name", "description"]

@action(detail=False, name="Get status choices")
def status(self, request):
return Response(dict(ComplianceAssessment.Status.choices))

def perform_create(self, serializer):
"""
Create RequirementAssessment objects for the newly created ComplianceAssessment
Expand Down
3 changes: 3 additions & 0 deletions frontend/messages/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -435,6 +435,9 @@
"support": "Support",
"toDo": "To do",
"inProgress": "In progress",
"inReview": "In review",
"deprecated": "Deprecated",
"done": "Done",
"nonCompliant": "Non compliant",
"partiallyCompliant": "Partially compliant",
"compliant": "Compliant",
Expand Down
3 changes: 3 additions & 0 deletions frontend/messages/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -435,6 +435,9 @@
"support": "Support",
"toDo": "À faire",
"inProgress": "En cours",
"inReview": "En révision",
"deprecated": "Déprécié",
"done": "Terminé",
"nonCompliant": "Non conforme",
"partiallyCompliant": "Partiellement conforme",
"compliant": "Conforme",
Expand Down
12 changes: 12 additions & 0 deletions frontend/src/lib/components/Forms/ModelForm.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,12 @@
hide={initialData.project}
/>
<TextField {form} field="version" label={m.version()} />
<Select
{form}
options={model.selectOptions['status']}
field="status"
label={m.status()}
/>
<AutocompleteSelect
{form}
options={getOptions({ objects: model.foreignKeys['risk_matrix'] })}
Expand Down Expand Up @@ -314,6 +320,12 @@
hide={initialData.project}
/>
<TextField {form} field="version" label={m.version()} />
<Select
{form}
options={model.selectOptions['status']}
field="status"
label={m.status()}
/>
<AutocompleteSelect
{form}
options={getOptions({ objects: model.foreignKeys['framework'] })}
Expand Down
39 changes: 21 additions & 18 deletions frontend/src/lib/utils/crud.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,8 @@ export const URL_MODEL_MAP: ModelMap = {
{ field: 'risk_scenarios', urlModel: 'risk-scenarios' }
],
reverseForeignKeyFields: [{ field: 'risk_assessment', urlModel: 'risk-scenarios' }],
filters: [{ field: 'project' }, { field: 'auditor' }]
selectFields: [{ field: 'status' }],
filters: [{ field: 'project' }, { field: 'auditor' }, { field: 'status' }]
},
threats: {
ref_id: 'ref_id',
Expand Down Expand Up @@ -325,7 +326,9 @@ export const URL_MODEL_MAP: ModelMap = {
{ field: 'framework', urlModel: 'frameworks' },
{ field: 'authors', urlModel: 'users' },
{ field: 'reviewers', urlModel: 'users' }
]
],
selectFields: [{ field: 'status' }],
filters: [{ field: 'status' }]
},
requirements: {
ref_id: 'ref_id',
Expand Down Expand Up @@ -394,10 +397,14 @@ interface FieldColoredTagMap {
export const FIELD_COLORED_TAG_MAP: FieldColoredTagMap = {
'risk-assessments': {
name: {
key: 'is_draft',
key: 'status',
values: {
true: { text: 'draft', cssClasses: 'badge bg-blue-200' }
} // badge bg-blue-200 | bg-blue-500
planned: {text: 'planned', cssClasses: 'badge bg-indigo-300'},
in_progress: {text: 'inProgress', cssClasses: 'badge bg-yellow-300'},
in_review: {text: 'inReview', cssClasses: 'badge bg-cyan-300'},
done: {text: 'done', cssClasses: 'badge bg-lime-300'},
deprecated: {text: 'deprecated', cssClasses: 'badge bg-orange-300'}
}
}
},
'risk-scenarios': {
Expand All @@ -413,20 +420,16 @@ export const FIELD_COLORED_TAG_MAP: FieldColoredTagMap = {
}
},
'compliance-assessments': {
name: [
{
key: 'is_draft',
values: {
true: { text: 'draft', cssClasses: 'badge bg-blue-200' }
}
},
{
key: 'is_obsolete',
values: {
true: { text: 'obsolete', cssClasses: 'badge bg-red-300' }
}
name: {
key: 'status',
values: {
planned: {text: 'planned', cssClasses: 'badge bg-indigo-300'},
in_progress: {text: 'inProgress', cssClasses: 'badge bg-yellow-300'},
in_review: {text: 'inReview', cssClasses: 'badge bg-cyan-300'},
done: {text: 'done', cssClasses: 'badge bg-lime-300'},
deprecated: {text: 'deprecated', cssClasses: 'badge bg-orange-300'}
}
]
}
},
assets: {
name: {
Expand Down
3 changes: 3 additions & 0 deletions frontend/src/lib/utils/locales.ts
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,9 @@ export function localItems(languageTag: string): LocalItems {
support: m.support({ languageTag: languageTag }),
toDo: m.toDo({ languageTag: languageTag }),
inProgress: m.inProgress({ languageTag: languageTag }),
inReview: m.inReview({ languageTag: languageTag }),
deprecated: m.deprecated({ languageTag: languageTag }),
done: m.done({ languageTag: languageTag }),
nonCompliant: m.nonCompliant({ languageTag: languageTag }),
partiallyCompliant: m.partiallyCompliant({ languageTag: languageTag }),
requirementAssessments: m.requirementAssessments({ languageTag: languageTag }),
Expand Down
2 changes: 2 additions & 0 deletions frontend/src/lib/utils/schemas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ export const LibraryUploadSchema = z.object({
export const RiskAssessmentSchema = baseNamedObject({
version: z.string().optional().default('0.1'),
project: z.string(),
status: z.string().optional(),
risk_matrix: z.string(),
eta: z.string().optional().nullable(),
due_date: z.string().optional().nullable(),
Expand Down Expand Up @@ -170,6 +171,7 @@ export const SetPasswordSchema = z.object({
export const ComplianceAssessmentSchema = baseNamedObject({
version: z.string().optional().default('0.1'),
project: z.string(),
status: z.string().optional(),
framework: z.string(),
eta: z.string().optional().nullable(),
due_date: z.string().optional().nullable(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@
<div class="flex flex-col space-y-4 whitespace-pre-line">
<div class="card px-6 py-4 bg-white flex flex-row justify-between shadow-lg">
<div class="flex flex-col space-y-2 whitespace-pre-line">
{#each Object.entries(data.compliance_assessment).filter( ([key, _]) => ['name', 'description', 'project', 'framework', 'authors', 'reviewers'].includes(key) ) as [key, value]}
{#each Object.entries(data.compliance_assessment).filter( ([key, _]) => ['name', 'description', 'project', 'framework', 'authors', 'reviewers', 'status'].includes(key) ) as [key, value]}
<div class="flex flex-col">
<div
class="text-sm font-medium text-gray-800 capitalize-first"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -204,14 +204,15 @@
</div>
<div class="container w-1/3">
<div id="name" class="text-lg font-semibold" data-testid="name-field-value">
{#if risk_assessment.is_draft}
<span class="badge bg-blue-200">{m.draft()}</span>
{/if}
{risk_assessment.project.str}/{risk_assessment.name} - {risk_assessment.version}
</div>
<br />
<div class="text-sm">
<ul>
<li class="pb-1">
<span class="font-semibold">{m.status()}:</span>
{risk_assessment.status}
</li>
<li class="pb-1">
<span class="font-semibold">{m.authors()}:</span>
<ul>
Expand Down
2 changes: 2 additions & 0 deletions frontend/tests/functional/user-route.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ test('user usual routine actions are working correctly', async ({
description: vars.description,
project: vars.projectName,
version: '1.4.2',
status: 'Done',
framework: vars.framework.name,
eta: '2025-01-01',
due_date: '2025-05-01'
Expand Down Expand Up @@ -179,6 +180,7 @@ test('user usual routine actions are working correctly', async ({
description: vars.description,
project: vars.projectName,
version: '1.4.2',
status: 'Done',
risk_matrix: vars.matrix.displayName,
eta: '2025-01-01',
due_date: '2025-05-01'
Expand Down
4 changes: 4 additions & 0 deletions frontend/tests/utils/test-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ export const test = base.extend<Fixtures>({
{ name: 'description', type: type.TEXT },
{ name: 'project', type: type.SELECT_AUTOCOMPLETE },
{ name: 'version', type: type.TEXT },
{ name: 'status', type: type.SELECT },
{ name: 'framework', type: type.SELECT_AUTOCOMPLETE },
{ name: 'eta', type: type.DATE },
{ name: 'due_date', type: type.DATE }
Expand Down Expand Up @@ -163,6 +164,7 @@ export const test = base.extend<Fixtures>({
{ name: 'description', type: type.TEXT },
{ name: 'project', type: type.SELECT_AUTOCOMPLETE },
{ name: 'version', type: type.TEXT },
{ name: 'status', type: type.SELECT },
{ name: 'risk_matrix', type: type.SELECT_AUTOCOMPLETE },
{ name: 'eta', type: type.DATE },
{ name: 'due_date', type: type.DATE }
Expand Down Expand Up @@ -448,6 +450,7 @@ export class TestContent {
name: vars.assessmentName,
description: vars.description,
project: vars.projectName,
status: 'Planned',
// version: "1.4.2",
framework: vars.framework.name
// eta: "2025-01-01",
Expand Down Expand Up @@ -491,6 +494,7 @@ export class TestContent {
description: vars.description,
project: vars.projectName,
version: '1.4.2',
status: 'Planned',
risk_matrix: vars.matrix.displayName
// eta: "2025-01-01",
// due_date: "2025-05-01"
Expand Down

0 comments on commit 57867f4

Please sign in to comment.