Skip to content

Commit

Permalink
feat: extra settings to enable mail notifications and matrix aggregat…
Browse files Browse the repository at this point in the history
…ion (#1434)
  • Loading branch information
ab-smith authored Jan 27, 2025
1 parent 1130357 commit 5af0a26
Show file tree
Hide file tree
Showing 8 changed files with 72 additions and 6 deletions.
2 changes: 2 additions & 0 deletions backend/global_settings/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
"ebios_radar_green_zone_radius",
"ebios_radar_yellow_zone_radius",
"ebios_radar_red_zone_radius",
"interface_agg_scenario_matrix",
"notifications_enable_mailing",
]


Expand Down
20 changes: 20 additions & 0 deletions backend/global_settings/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ def object(self, request, pk=None):
"ebios_radar_green_zone_radius": 0.2,
"ebios_radar_yellow_zone_radius": 0.9,
"ebios_radar_red_zone_radius": 2.5,
"notifications_enable_mailing": False,
"interface_agg_scenario_matrix": False,
}

settings, created = GlobalSettings.objects.get_or_create(name="general")
Expand Down Expand Up @@ -102,6 +104,24 @@ def ebios_radar_parameters(self, request):
}
return Response(ebios_rm_parameters)

@action(detail=True, name="Get notifications settings")
def notifications_settings(self, request):
notifications_settings = {
"notifications_enable_mailing": self.get_object().value.get(
"notifications_enable_mailing"
),
}
return Response(notifications_settings)

@action(detail=True, name="Get interface settings")
def interface_settings(self, request):
interface_settings = {
"interface_agg_scenario_matrix": self.get_object().value.get(
"interface_agg_scenario_matrix"
),
}
return Response(interface_settings)


@api_view(["GET"])
@permission_classes([permissions.AllowAny])
Expand Down
4 changes: 4 additions & 0 deletions frontend/messages/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -606,6 +606,10 @@
"secret": "Secret",
"key": "Key",
"settings": "Settings",
"settingsInterface": "Interface",
"settingsAggregateMatrix": "Aggregate scenarios on risk matrices",
"settingsNotifications": "Notifications settings",
"settingsNotificationsMail": "Enable email notifications",
"identityProvider": "Identity provider",
"identityProviders": "Identity providers",
"clientIDHelpText": "App ID, or consumer key",
Expand Down
4 changes: 4 additions & 0 deletions frontend/messages/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -606,6 +606,10 @@
"secret": "Secret",
"key": "Clé",
"settings": "Paramètres",
"settingsInterface": "Interface",
"settingsAggregateMatrix": "Agréger les scénarios sur les matrices",
"settingsNotifications": "Paramètres de notifications",
"settingsNotificationsMail": "Activer les emails",
"identityProvider": "Fournisseur d'identité",
"identityProviders": "Fournisseurs d'identité",
"clientIDHelpText": "ID d'application ou clé consommateur",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import type { CacheLock, ModelInfo } from '$lib/utils/types';
import type { SuperForm } from 'sveltekit-superforms';
import { Accordion, AccordionItem } from '@skeletonlabs/skeleton';
import Checkbox from '$lib/components/Forms/Checkbox.svelte';
export let form: SuperForm<any>;
export let model: ModelInfo;
export let cacheLocks: Record<string, CacheLock> = {};
Expand All @@ -14,7 +14,36 @@

<Accordion regionControl="font-bold">
<AccordionItem open>
<svelte:fragment slot="summary"><i class="fa-solid fa-gem mr-2"></i>{m.asset()}</svelte:fragment
<svelte:fragment slot="summary"
><i class="fa-solid fa-bell mr-2"></i>{m.settingsNotifications()}</svelte:fragment
>
<svelte:fragment slot="content">
<div class="p-4">
<Checkbox
{form}
field="notifications_enable_mailing"
label={m.settingsNotificationsMail()}
/>
</div>
</svelte:fragment>
</AccordionItem>
<AccordionItem open>
<svelte:fragment slot="summary">
<i class="fa-solid fa-asterisk mr-2" />{m.settingsInterface()}
</svelte:fragment>
<svelte:fragment slot="content">
<div class="p-4">
<Checkbox
{form}
field="interface_agg_scenario_matrix"
label={m.settingsAggregateMatrix()}
/>
</div>
</svelte:fragment>
</AccordionItem>
<AccordionItem>
<svelte:fragment slot="summary"
><i class="fa-solid fa-gem mr-2"></i>{m.assets()}</svelte:fragment
>
<svelte:fragment slot="content">
<Select
Expand All @@ -28,7 +57,7 @@
/>
</svelte:fragment>
</AccordionItem>
<AccordionItem open>
<AccordionItem>
<svelte:fragment slot="summary"
><i class="fa-solid fa-gopuram mr-2"></i>{m.ebiosRadarParameters()}</svelte:fragment
>
Expand Down
4 changes: 3 additions & 1 deletion frontend/src/lib/utils/schemas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,9 @@ export const GeneralSettingsSchema = z.object({
ebios_radar_max: z.number(),
ebios_radar_green_zone_radius: z.number(),
ebios_radar_yellow_zone_radius: z.number(),
ebios_radar_red_zone_radius: z.number()
ebios_radar_red_zone_radius: z.number(),
notifications_enable_mailing: z.boolean().optional(),
interface_agg_scenario_matrix: z.boolean().optional()
});

export const SSOSettingsSchema = z.object({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ export const load: LayoutServerLoad = async ({ fetch, params }) => {
`${BASE_API_URL}/risk-matrices/${risk_assessment.risk_matrix.id}/`
).then((res) => res.json());

const interface_settings = await fetch(`${BASE_API_URL}/settings/general/object`).then((res) =>
res.json()
);

const headFields = [
'ref_id',
'name',
Expand Down Expand Up @@ -146,6 +150,7 @@ export const load: LayoutServerLoad = async ({ fetch, params }) => {
scenarioCreateForm,
riskAssessmentDuplicateForm,
riskAssessmentModel,
title: risk_assessment.str
title: risk_assessment.str,
useBubbles: interface_settings.interface_agg_scenario_matrix
};
};
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
export let data;
const showRisks = true;
const useBubbles = true;
const useBubbles = data.useBubbles;
const risk_assessment = data.risk_assessment;
const modalStore: ModalStore = getModalStore();
Expand Down

0 comments on commit 5af0a26

Please sign in to comment.