Skip to content

Commit

Permalink
Merge branch 'main' into CA-545-add-ref-id-to-all-editable-objects
Browse files Browse the repository at this point in the history
  • Loading branch information
eric-intuitem committed Nov 27, 2024
2 parents 0713bc8 + 1293b5a commit 3756838
Show file tree
Hide file tree
Showing 22 changed files with 154 additions and 68 deletions.
78 changes: 59 additions & 19 deletions backend/core/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -2788,48 +2788,71 @@ def compute_requirement_assessments_results(
) -> list["RequirementAssessment"]:
requirement_assessments: list[RequirementAssessment] = []
result_order = (
RequirementAssessment.Result.NOT_ASSESSED,
RequirementAssessment.Result.NOT_APPLICABLE,
RequirementAssessment.Result.NON_COMPLIANT,
RequirementAssessment.Result.PARTIALLY_COMPLIANT,
RequirementAssessment.Result.COMPLIANT,
)

def assign_attributes(target, attributes):
"""
Helper function to assign attributes to a target object.
Only assigns if the attribute is not None.
"""
keys = ["result", "status", "score", "is_scored", "observation"]
for key, value in zip(keys, attributes):
if value is not None:
setattr(target, key, value)

for requirement_assessment in self.requirement_assessments.all():
mappings = mapping_set.mappings.filter(
target_requirement=requirement_assessment.requirement
)
inferences = []
refs = []

# Filter for full coverage relationships if applicable
if mappings.filter(
relationship__in=RequirementMapping.FULL_COVERAGE_RELATIONSHIPS
).exists():
mappings = mappings.filter(
relationship__in=RequirementMapping.FULL_COVERAGE_RELATIONSHIPS
)

for mapping in mappings:
source_requirement_assessment = RequirementAssessment.objects.get(
compliance_assessment=source_assessment,
requirement=mapping.source_requirement,
)
inferred_result, inferred_status = requirement_assessment.infer_result(
inferred_result = requirement_assessment.infer_result(
mapping=mapping,
source_requirement_assessment=source_requirement_assessment,
)
if inferred_result in result_order:
inferences.append((inferred_result, inferred_status))
if inferred_result.get("result") in result_order:
inferences.append(
(
inferred_result.get("result"),
inferred_result.get("status"),
inferred_result.get("score"),
inferred_result.get("is_scored"),
inferred_result.get("observation"),
)
)
refs.append(source_requirement_assessment)

if inferences:
if len(inferences) == 1:
requirement_assessment.result = inferences[0][0]
if inferences[0][1]:
requirement_assessment.status = inferences[0][1]
selected_inference = inferences[0]
ref = refs[0]
else:
lowest_result = min(
selected_inference = min(
inferences, key=lambda x: result_order.index(x[0])
)
requirement_assessment.result = lowest_result[0]
if lowest_result[1]:
requirement_assessment.status = lowest_result[1]
ref = refs[inferences.index(lowest_result)]
ref = refs[inferences.index(selected_inference)]

assign_attributes(requirement_assessment, selected_inference)

requirement_assessment.mapping_inference = {
"result": requirement_assessment.result,
"source_requirement_assessment": {
Expand All @@ -2839,7 +2862,9 @@ def compute_requirement_assessments_results(
},
# "mappings": [mapping.id for mapping in mappings],
}

requirement_assessments.append(requirement_assessment)

return requirement_assessments

def progress(self) -> int:
Expand Down Expand Up @@ -2937,24 +2962,39 @@ def get_requirement_description(self) -> str:

def infer_result(
self, mapping: RequirementMapping, source_requirement_assessment: Self
) -> str | None:
) -> dict | None:
if mapping.coverage == RequirementMapping.Coverage.FULL:
return (
source_requirement_assessment.result,
source_requirement_assessment.status,
)
if (
source_requirement_assessment.compliance_assessment.min_score
== self.compliance_assessment.min_score
and source_requirement_assessment.compliance_assessment.max_score
== self.compliance_assessment.max_score
):
return {
"result": source_requirement_assessment.result,
"status": source_requirement_assessment.status,
"score": source_requirement_assessment.score,
"is_scored": source_requirement_assessment.is_scored,
"observation": source_requirement_assessment.observation,
}
else:
return {
"result": source_requirement_assessment.result,
"status": source_requirement_assessment.status,
"observation": source_requirement_assessment.observation,
}
if mapping.coverage == RequirementMapping.Coverage.PARTIAL:
if source_requirement_assessment.result in (
RequirementAssessment.Result.COMPLIANT,
RequirementAssessment.Result.PARTIALLY_COMPLIANT,
):
return (RequirementAssessment.Result.PARTIALLY_COMPLIANT, None)
return {"result": RequirementAssessment.Result.PARTIALLY_COMPLIANT}
if (
source_requirement_assessment.result
== RequirementAssessment.Result.NON_COMPLIANT
):
return (RequirementAssessment.Result.NON_COMPLIANT, None)
return (None, None)
return {"result": RequirementAssessment.Result.NON_COMPLIANT}
return {}

def create_applied_controls_from_suggestions(self) -> list[AppliedControl]:
applied_controls: list[AppliedControl] = []
Expand Down
17 changes: 12 additions & 5 deletions enterprise/frontend/src/routes/(app)/+layout.svelte
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<script lang="ts">
// Most of your app wide CSS should be put in this file
import { safeTranslate } from '$lib/utils/i18n';
import { AppBar, AppShell } from '@skeletonlabs/skeleton';
import '../../app.postcss';
Expand Down Expand Up @@ -37,6 +36,12 @@
});
}
}
const licenseExpirationNotifyDays = data.LICENSE_EXPIRATION_NOTIFY_DAYS;
const licenseStatus: Record<string, any> = data.licenseStatus;
const licenseAboutToExpire =
licenseStatus?.status === 'active' && licenseStatus?.days_left <= licenseExpirationNotifyDays;
</script>

<!-- App Shell -->
Expand All @@ -48,11 +53,13 @@
<SideBar bind:open={sidebarOpen} />
</svelte:fragment>
<svelte:fragment slot="pageHeader">
{#if data.licenseStatus.status === 'expired'}
<aside class="variant-soft-warning text-center w-full items-center py-2">
<aside class="variant-soft-warning text-center w-full items-center py-2">
{#if data.licenseStatus.status === 'expired'}
{m.licenseExpiredMessage()}
</aside>
{/if}
{:else if licenseAboutToExpire}
{m.licenseAboutToExpireWarning({ days_left: licenseStatus.days_left })}
{/if}
</aside>
<AppBar background="bg-white" padding="py-2 px-4">
<span
class="text-2xl font-bold pb-1 bg-gradient-to-r from-pink-500 to-violet-600 bg-clip-text text-transparent"
Expand Down
6 changes: 5 additions & 1 deletion enterprise/frontend/src/routes/+layout.server.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import type { LayoutServerLoad } from './$types';
import type { GlobalSettings } from '$lib/utils/types';
import { BASE_API_URL } from '$lib/utils/constants';
import { env } from '$env/dynamic/public';

export const load: LayoutServerLoad = async ({ fetch, locals }) => {
let clientSettings: GlobalSettings;
Expand All @@ -16,5 +17,8 @@ export const load: LayoutServerLoad = async ({ fetch, locals }) => {
clientSettings.settings.favicon_hash = '';
clientSettings.settings.name = '';
}
return { featureFlags: locals.featureFlags, clientSettings, licenseStatus };
const LICENSE_EXPIRATION_NOTIFY_DAYS = Object.hasOwn(env, 'PUBLIC_LICENSE_EXPIRATION_NOTIFY_DAYS')
? env.PUBLIC_LICENSE_EXPIRATION_NOTIFY_DAYS
: 7;
return { featureFlags: locals.featureFlags, clientSettings, licenseStatus, LICENSE_EXPIRATION_NOTIFY_DAYS };
};
4 changes: 3 additions & 1 deletion frontend/messages/ar.json
Original file line number Diff line number Diff line change
Expand Up @@ -857,5 +857,7 @@
"tags": "العلامات",
"addTag": "إضافة علامة",
"tagsHelpText": "تُستخدم العلامات لتصنيف العناصر وتصفيتها. يمكنك إضافة علامات في قسم \"إضافي\"",
"forgotPassword": "هل نسيت كلمة السر"
"forgotPassword": "هل نسيت كلمة السر",
"scoreSemiColon": "نتيجة:",
"mappingInferenceHelpText": "هذه المتغيرات ثابتة ولن تتغير اعتمادًا على المصدر."
}
4 changes: 3 additions & 1 deletion frontend/messages/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -856,5 +856,7 @@
"tags": "Schlagwörter",
"addTag": "Tag hinzufügen",
"tagsHelpText": "Tags werden zum Kategorisieren und Filtern der Elemente verwendet. Sie können Tags im Abschnitt Extra hinzufügen",
"forgotPassword": "Passwort vergessen"
"forgotPassword": "Passwort vergessen",
"scoreSemiColon": "Punktzahl:",
"mappingInferenceHelpText": "Diese Variablen sind fest und ändern sich je nach Quelle nicht."
}
3 changes: 3 additions & 0 deletions frontend/messages/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -789,6 +789,7 @@
"questionPlural": "Questions",
"fillMetadataURL": "Option 1: Fill the metadata url",
"fillSSOSLOURLx509cert": "Option 2: Fill the SSO URL, SLO URL and x509cert",
"licenseAboutToExpireWarning": "You have only {days_left} days before the end of your license.",
"proof": "Proof",
"privacy": "Privacy",
"safety": "Safety",
Expand Down Expand Up @@ -886,6 +887,8 @@
"youCanSetPasswordHere": "You can set your password here",
"forgotPassword": "Forgot password",
"ssoSettingsUpdated": "SSO settings updated",
"scoreSemiColon": "Score:",
"mappingInferenceHelpText": "These variables are fixed and will not change depending on the source.",
"priority": "Priority",
"p1": "P1",
"p2": "P2",
Expand Down
4 changes: 3 additions & 1 deletion frontend/messages/es.json
Original file line number Diff line number Diff line change
Expand Up @@ -856,5 +856,7 @@
"tags": "Etiquetas",
"addTag": "Agregar etiqueta",
"tagsHelpText": "Las etiquetas se utilizan para categorizar y filtrar los elementos. Puedes agregar etiquetas en la sección Extra",
"forgotPassword": "Has olvidado tu contraseña"
"forgotPassword": "Has olvidado tu contraseña",
"scoreSemiColon": "Puntaje:",
"mappingInferenceHelpText": "Estas variables son fijas y no cambiarán dependiendo de la fuente."
}
5 changes: 4 additions & 1 deletion frontend/messages/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -789,6 +789,7 @@
"questionPlural": "Questions",
"fillMetadataURL": "Option 1 : Remplissez l'URL des métadonnées",
"fillSSOSLOURLx509cert": "Option 2 : Remplissez l'URL SSO, l'URL SLO et le certificat x509",
"licenseAboutToExpireWarning": "Il reste {days_left} jours avant l'expiration de votre licence.",
"noExpirationDateSet": "Aucune date d'expiration définie",
"sumpageTotal": "total",
"sumpageActive": "actif",
Expand Down Expand Up @@ -863,5 +864,7 @@
"existingMeasures": "Mesures existantes",
"youCanSetPasswordHere": "Vous pouvez définir votre mot de passe ici",
"forgotPassword": "Mot de passe oublié",
"ssoSettingsUpdated": "Paramètres SSO mis à jour"
"ssoSettingsUpdated": "Paramètres SSO mis à jour",
"scoreSemiColon": "Score:",
"mappingInferenceHelpText": "Ces variables sont fixes et ne changeront pas en fonction de la source."
}
4 changes: 3 additions & 1 deletion frontend/messages/hi.json
Original file line number Diff line number Diff line change
Expand Up @@ -856,5 +856,7 @@
"tags": "टैग",
"addTag": "टैग जोड़ें",
"tagsHelpText": "टैग का उपयोग आइटम को वर्गीकृत और फ़िल्टर करने के लिए किया जाता है। आप अतिरिक्त अनुभाग में टैग जोड़ सकते हैं",
"forgotPassword": "पासवर्ड भूल गए"
"forgotPassword": "पासवर्ड भूल गए",
"scoreSemiColon": "अंक:",
"mappingInferenceHelpText": "ये चर निश्चित हैं और स्रोत के आधार पर परिवर्तित नहीं होंगे।"
}
4 changes: 3 additions & 1 deletion frontend/messages/it.json
Original file line number Diff line number Diff line change
Expand Up @@ -856,5 +856,7 @@
"tags": "Etichette",
"addTag": "Aggiungi tag",
"tagsHelpText": "I tag vengono utilizzati per categorizzare e filtrare gli elementi. Puoi aggiungere tag nella sezione Extra",
"forgotPassword": "Ha dimenticato la password"
"forgotPassword": "Ha dimenticato la password",
"scoreSemiColon": "Punto:",
"mappingInferenceHelpText": "Queste variabili sono fisse e non cambiano a seconda della fonte."
}
4 changes: 3 additions & 1 deletion frontend/messages/nl.json
Original file line number Diff line number Diff line change
Expand Up @@ -856,5 +856,7 @@
"tags": "Labels",
"addTag": "Tag toevoegen",
"tagsHelpText": "Tags worden gebruikt om de items te categoriseren en te filteren. U kunt tags toevoegen in de sectie Extra",
"forgotPassword": "Wachtwoord vergeten"
"forgotPassword": "Wachtwoord vergeten",
"scoreSemiColon": "Punt:",
"mappingInferenceHelpText": "Deze variabelen zijn vast en veranderen niet, afhankelijk van de bron."
}
4 changes: 3 additions & 1 deletion frontend/messages/pl.json
Original file line number Diff line number Diff line change
Expand Up @@ -856,5 +856,7 @@
"tags": "Tagi",
"addTag": "Dodaj tag",
"tagsHelpText": "Tagi służą do kategoryzowania i filtrowania elementów. Możesz dodać tagi w sekcji Extra",
"forgotPassword": "Zapomniałem hasła"
"forgotPassword": "Zapomniałem hasła",
"scoreSemiColon": "Wynik:",
"mappingInferenceHelpText": "Te zmienne są stałe i nie zmieniają się w zależności od źródła."
}
4 changes: 3 additions & 1 deletion frontend/messages/pt.json
Original file line number Diff line number Diff line change
Expand Up @@ -856,5 +856,7 @@
"tags": "Etiquetas",
"addTag": "Adicionar etiqueta",
"tagsHelpText": "As tags são usadas para categorizar e filtrar os itens. Você pode adicionar tags na seção Extra",
"forgotPassword": "Esqueceu sua senha"
"forgotPassword": "Esqueceu sua senha",
"scoreSemiColon": "Pontuação:",
"mappingInferenceHelpText": "Essas variáveis são fixas e não mudarão dependendo da fonte."
}
4 changes: 3 additions & 1 deletion frontend/messages/ro.json
Original file line number Diff line number Diff line change
Expand Up @@ -856,5 +856,7 @@
"tags": "Etichete",
"addTag": "Adăugați etichetă",
"tagsHelpText": "Etichetele sunt folosite pentru a clasifica și filtra articolele. Puteți adăuga etichete în secțiunea Extra",
"forgotPassword": "Aţi uitat parola"
"forgotPassword": "Aţi uitat parola",
"scoreSemiColon": "Scor:",
"mappingInferenceHelpText": "Aceste variabile sunt fixe și nu se vor modifica în funcție de sursă."
}
4 changes: 3 additions & 1 deletion frontend/messages/sv.json
Original file line number Diff line number Diff line change
Expand Up @@ -860,5 +860,7 @@
"existingMeasures": "Befintliga kontroller",
"youCanSetPasswordHere": "Du kan ställa in ditt lösenord här",
"forgotPassword": "Glömt lösenord",
"ssoSettingsUpdated": "SSO-inställningar uppdaterade"
"ssoSettingsUpdated": "SSO-inställningar uppdaterade",
"scoreSemiColon": "Göra:",
"mappingInferenceHelpText": "Dessa variabler är fasta och kommer inte att ändras beroende på källan."
}
4 changes: 3 additions & 1 deletion frontend/messages/ur.json
Original file line number Diff line number Diff line change
Expand Up @@ -856,5 +856,7 @@
"tags": "ٹیگز",
"addTag": "ٹیگ شامل کریں۔",
"tagsHelpText": "ٹیگز اشیاء کی درجہ بندی اور فلٹر کرنے کے لیے استعمال ہوتے ہیں۔ آپ اضافی سیکشن میں ٹیگ شامل کر سکتے ہیں۔",
"forgotPassword": "پاس ورڈ بھول گئے۔"
"forgotPassword": "پاس ورڈ بھول گئے۔",
"scoreSemiColon": "سکور:",
"mappingInferenceHelpText": "یہ متغیرات طے شدہ ہیں اور ماخذ کے لحاظ سے تبدیل نہیں ہوں گے۔"
}
2 changes: 1 addition & 1 deletion frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
"@svelte-put/qr": "^1.2.1",
"@sveltejs/adapter-auto": "^3.3.1",
"@sveltejs/adapter-node": "^5.2.9",
"@sveltejs/kit": "^2.7.4",
"@sveltejs/kit": "^2.8.3",
"@sveltejs/vite-plugin-svelte": "^3.1.2",
"@tailwindcss/forms": "^0.5.9",
"@tailwindcss/typography": "^0.5.15",
Expand Down
Loading

0 comments on commit 3756838

Please sign in to comment.