Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ca 673 step 1.3 #1128

Closed
wants to merge 31 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
04ef58a
starting point
ab-smith Nov 29, 2024
c32cad4
Basic tile styling
ab-smith Nov 29, 2024
e3c8065
Merge branch 'main' into ebios-rm-tiles
ab-smith Nov 29, 2024
5683520
wip
ab-smith Nov 29, 2024
f15e8e0
wip
ab-smith Nov 29, 2024
8e296c6
Merge branch 'main' into ebios-rm-tiles
ab-smith Nov 30, 2024
b410a6e
Merge branch 'main' into ebios-rm-tiles
ab-smith Dec 1, 2024
ff16985
Closer to the training materials
ab-smith Dec 1, 2024
454aae0
Formatter
ab-smith Dec 1, 2024
4f9c994
workshop1: prepare step 1/2
Mohamed-Hacene Dec 2, 2024
1d44ddd
Merge remote-tracking branch 'origin/CA-660-create-base-models' into …
Mohamed-Hacene Dec 3, 2024
c3e6497
chore: remove bad imports
Mohamed-Hacene Dec 3, 2024
2b6b927
feat: add ebios rm base endpoint
Mohamed-Hacene Dec 3, 2024
25e369f
feat: manage ebios rm from front
Mohamed-Hacene Dec 3, 2024
fa9c7c6
feat: set ebios object breadcrumbs
Mohamed-Hacene Dec 3, 2024
0789977
feat: add risk matrix field in ebios rm
Mohamed-Hacene Dec 3, 2024
eac11ca
Merge remote-tracking branch 'origin/CA-660-create-base-models' into …
Mohamed-Hacene Dec 3, 2024
7e730ea
chore: remove repeated argument
Mohamed-Hacene Dec 3, 2024
b6084b4
feat: prepare step 1/2
Mohamed-Hacene Dec 3, 2024
eae82e4
Merge branch 'main' into CA-672-Step-1.1-1.2
Mohamed-Hacene Dec 3, 2024
334bf99
Fix code scanning alert no. 18: Information exposure through an excep…
Mohamed-Hacene Dec 3, 2024
e0b1521
chore: format
Mohamed-Hacene Dec 3, 2024
6d733ab
Merge branch 'CA-672-Step-1.1-1.2' of github.com:intuitem/ciso-assist…
Mohamed-Hacene Dec 3, 2024
2023fd5
chore: format serializer
Mohamed-Hacene Dec 3, 2024
4c5090b
Merge remote-tracking branch 'origin/CA-681-create-crud-endpoints-for…
Mohamed-Hacene Dec 4, 2024
4a9da32
feat: map new ebios endpoint
Mohamed-Hacene Dec 4, 2024
3ef3052
chore: format
Mohamed-Hacene Dec 4, 2024
356b552
feat: add step 1.3
Mohamed-Hacene Dec 4, 2024
3c7ec09
fix: typos
Mohamed-Hacene Dec 4, 2024
7fc9aa3
Merge branch 'CA-672-Step-1.1-1.2' into CA-673-Step-1.3
Mohamed-Hacene Dec 4, 2024
41373e5
feat: add qualifications endpoints
Mohamed-Hacene Dec 4, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions backend/core/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -705,3 +705,13 @@ class FilteringLabelWriteSerializer(BaseModelSerializer):
class Meta:
model = FilteringLabel
exclude = ["folder", "is_published"]


class QualificationReadSerializer(ReferentialSerializer):
class Meta:
model = Qualification
exclude = ["translations"]


class QualificationWriteSerializer(QualificationReadSerializer):
pass
4 changes: 4 additions & 0 deletions backend/core/startup.py
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,10 @@
"view_operationalscenario",
"change_operationalscenario",
"delete_operationalscenario",
"view_qualification",
"add_qualification",
"change_qualification",
"delete_qualification",
]

THIRD_PARTY_RESPONDENT_PERMISSIONS_LIST = [
Expand Down
5 changes: 5 additions & 0 deletions backend/core/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,11 @@
FilteringLabelViewSet,
basename="filtering-labels",
)
router.register(
r"qualifications",
QualificationViewSet,
basename="qualifications",
)

ROUTES = settings.ROUTES
MODULES = settings.MODULES.values()
Expand Down
17 changes: 16 additions & 1 deletion backend/core/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,13 @@ class AssetViewSet(BaseModelViewSet):
"""

model = Asset
filterset_fields = ["folder", "parent_assets", "type", "risk_scenarios"]
filterset_fields = [
"folder",
"parent_assets",
"type",
"risk_scenarios",
"ebios_rm_studies",
]
search_fields = ["name", "description", "business_value"]

@action(detail=False, name="Get type choices")
Expand Down Expand Up @@ -1950,6 +1956,15 @@ def post(self, request, *args, **kwargs):
return Response(status=status.HTTP_400_BAD_REQUEST)


class QualificationViewSet(BaseModelViewSet):
"""
API endpoint that allows qualifications to be viewed or edited.
"""

model = Qualification
search_fields = ["name"]


class ComplianceAssessmentViewSet(BaseModelViewSet):
"""
API endpoint that allows compliance assessments to be viewed or edited.
Expand Down
1 change: 1 addition & 0 deletions backend/ebios_rm/migrations/0001_initial.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ class Migration(migrations.Migration):
related_name="ebios_rm_studies",
to="core.riskmatrix",
verbose_name="Risk matrix",
blank=True,
),
),
],
Expand Down
1 change: 1 addition & 0 deletions backend/ebios_rm/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ class Status(models.TextChoices):
help_text=_(
"Risk matrix used as a reference for the study. Defaults to `urn:intuitem:risk:library:risk-matrix-4x4-ebios-rm`"
),
blank=True,
)
assets = models.ManyToManyField(
Asset,
Expand Down
2 changes: 1 addition & 1 deletion backend/ebios_rm/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ class Meta:


class FearedEventReadSerializer(BaseModelSerializer):
str = serializers.CharField(source="__str__")
ebios_rm_study = FieldsRelatedField()
qualifications = FieldsRelatedField(["name"], many=True)
folder = FieldsRelatedField()

class Meta:
Expand Down
4 changes: 4 additions & 0 deletions backend/ebios_rm/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,7 @@ def status(self, request):

class FearedEventViewSet(BaseModelViewSet):
model = FearedEvent

filterset_fields = [
"ebios_rm_study",
]
8 changes: 7 additions & 1 deletion frontend/messages/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -919,5 +919,11 @@
"ebiosWs5_3": "Define security measures",
"ebiosWs5_4": "Assess and document residual risks",
"ebiosWs5_5": "Establish risk monitoring framework",
"activity": "Activity"
"activity": "Activity",
"ebiosRmMatrixHelpText": "Risk matrix used as a reference for the study. Defaults to `urn:intuitem:risk:library:risk-matrix-4x4-ebios-rm`",
"activityOne": "Activity 1",
"activityTwo": "Activity 2",
"ebiosRmStudy": "Ebios RM study",
"qualifications": "Qualifications",
"impacts": "Impacts"
}
2 changes: 1 addition & 1 deletion frontend/src/lib/components/Breadcrumbs/Breadcrumbs.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
let tokenPath = '';
crumbs = tokens.map((t) => {
tokenPath += '/' + t;
if (t === $breadcrumbObject.id) {
if (t === $breadcrumbObject?.id) {
if ($breadcrumbObject.name) {
t = $breadcrumbObject.name;
} else if ($breadcrumbObject.first_name && $breadcrumbObject.last_name) {
Expand Down
6 changes: 6 additions & 0 deletions frontend/src/lib/components/Forms/ModelForm.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
import SsoSettingsForm from './ModelForm/SsoSettingForm.svelte';
import FolderForm from './ModelForm/FolderForm.svelte';
import GeneralSettingsForm from './ModelForm/GeneralSettingForm.svelte';
import EbiosRmForm from './ModelForm/EbiosRmForm.svelte';
import FearedEventForm from './ModelForm/FearedEventForm.svelte';

import AutocompleteSelect from './AutocompleteSelect.svelte';

Expand Down Expand Up @@ -254,6 +256,10 @@
<GeneralSettingsForm {form} {model} {cacheLocks} {formDataCache} {data} />
{:else if URLModel === 'filtering-labels'}
<FilteringLabelForm {form} {model} {cacheLocks} {formDataCache} />
{:else if URLModel === 'ebios-rm'}
<EbiosRmForm {form} {model} {cacheLocks} {formDataCache} {context} />
{:else if URLModel === 'feared-events'}
<FearedEventForm {form} {model} {cacheLocks} {formDataCache} {initialData} />
{/if}
<div class="flex flex-row justify-between space-x-4">
{#if closeModal}
Expand Down
110 changes: 110 additions & 0 deletions frontend/src/lib/components/Forms/ModelForm/EbiosRmForm.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
<script lang="ts">
import type { SuperValidated } from 'sveltekit-superforms';
import type { ModelInfo, CacheLock } from '$lib/utils/types';
import TextField from '$lib/components/Forms/TextField.svelte';
import AutocompleteSelect from '$lib/components/Forms/AutocompleteSelect.svelte';
import Select from '$lib/components/Forms/Select.svelte';
import * as m from '$paraglide/messages.js';
import { getOptions } from '$lib/utils/crud';
import TextArea from '../TextArea.svelte';

export let form: SuperValidated<any>;
export let model: ModelInfo;
export let cacheLocks: Record<string, CacheLock> = {};
export let formDataCache: Record<string, any> = {};
export let initialData: Record<string, any> = {};
export let context: string;
</script>

{#if context !== 'ebiosRmStudy'}
<TextField
{form}
field="version"
label={m.version()}
cacheLock={cacheLocks['version']}
bind:cachedValue={formDataCache['version']}
/>
<TextField
{form}
field="ref_id"
label={m.refId()}
cacheLock={cacheLocks['ref_id']}
bind:cachedValue={formDataCache['ref_id']}
/>
<AutocompleteSelect
{form}
options={getOptions({ objects: model.foreignKeys['folder'] })}
field="folder"
cacheLock={cacheLocks['folder']}
bind:cachedValue={formDataCache['folder']}
label={m.domain()}
hidden={initialData.folder}
/>
<AutocompleteSelect
{form}
options={getOptions({ objects: model.foreignKeys['risk_matrix'] })}
field="risk_matrix"
cacheLock={cacheLocks['risk_matrix']}
bind:cachedValue={formDataCache['risk_matrix']}
label={m.riskMatrix()}
helpText={m.ebiosRmMatrixHelpText()}
/>
{:else if context === 'ebiosRmStudy'}
<div class="relative p-2 space-y-2 border rounded-md">
<p class="absolute -top-3 bg-white font-bold">{m.activityOne()}</p>
<TextField
{form}
field="version"
label={m.version()}
cacheLock={cacheLocks['version']}
bind:cachedValue={formDataCache['version']}
/>
<TextField
{form}
required
field="ref_id"
label={m.refId()}
cacheLock={cacheLocks['ref_id']}
bind:cachedValue={formDataCache['ref_id']}
/>
<TextArea
{form}
field="observation"
label={m.observation()}
cacheLock={cacheLocks['observation']}
bind:cachedValue={formDataCache['observation']}
/>
<AutocompleteSelect
multiple
{form}
options={getOptions({ objects: model.foreignKeys['authors'], label: 'email' })}
field="authors"
cacheLock={cacheLocks['authors']}
bind:cachedValue={formDataCache['authors']}
label={m.authors()}
/>
<AutocompleteSelect
multiple
{form}
options={getOptions({ objects: model.foreignKeys['reviewers'], label: 'email' })}
field="reviewers"
cacheLock={cacheLocks['reviewers']}
bind:cachedValue={formDataCache['reviewers']}
label={m.reviewers()}
/>
</div>
<div class="relative p-2 space-y-2 border rounded-md">
<p class="absolute -top-3 bg-white font-bold">{m.activityTwo()}</p>
<AutocompleteSelect
multiple
{form}
options={getOptions({
objects: model.foreignKeys['assets'],
extra_fields: [['folder', 'str']],
label: 'auto'
})}
field="assets"
label={m.assets()}
/>
</div>
{/if}
61 changes: 61 additions & 0 deletions frontend/src/lib/components/Forms/ModelForm/FearedEventForm.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
<script lang="ts">
import type { SuperValidated } from 'sveltekit-superforms';
import type { ModelInfo, CacheLock } from '$lib/utils/types';
import TextField from '$lib/components/Forms/TextField.svelte';
import AutocompleteSelect from '$lib/components/Forms/AutocompleteSelect.svelte';
import Select from '$lib/components/Forms/Select.svelte';
import * as m from '$paraglide/messages.js';
import { getOptions } from '$lib/utils/crud';
import TextArea from '../TextArea.svelte';

export let form: SuperValidated<any>;
export let model: ModelInfo;
export let cacheLocks: Record<string, CacheLock> = {};
export let formDataCache: Record<string, any> = {};
export let initialData: Record<string, any> = {};
export let context: string;
</script>

<AutocompleteSelect
{form}
options={getOptions({ objects: model.foreignKeys['ebios_rm_study'] })}
field="ebios_rm_study"
cacheLock={cacheLocks['ebios_rm_study']}
bind:cachedValue={formDataCache['ebios_rm_study']}
label={m.ebiosRmStudy()}
hidden={initialData.ebios_rm_study}
/>
<TextField
{form}
field="ref_id"
label={m.refId()}
cacheLock={cacheLocks['ref_id']}
bind:cachedValue={formDataCache['ref_id']}
/>
<TextArea
{form}
field="justification"
label={m.justification()}
cacheLock={cacheLocks['justification']}
bind:cachedValue={formDataCache['justification']}
/>
<AutocompleteSelect
multiple
{form}
options={getOptions({
objects: model.foreignKeys['assets'],
extra_fields: [['folder', 'str']],
label: 'auto'
})}
field="assets"
label={m.assets()}
/>
<AutocompleteSelect
multiple
{form}
options={getOptions({
objects: model.foreignKeys['qualifications']
})}
field="qualifications"
label={m.qualifications()}
/>
14 changes: 11 additions & 3 deletions frontend/src/lib/utils/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,16 @@ function getEndpoint({
urlModel: string;
event: RequestEvent;
}) {
const model = getModelInfo(urlModel);
if (action === 'create') {
return `${BASE_API_URL}/${urlModel}/`;
return model.endpointUrl
? `${BASE_API_URL}/${model.endpointUrl}/`
: `${BASE_API_URL}/${urlModel}/`;
}
const id = event.params.id;
return `${BASE_API_URL}/${urlModel}/${id}/`;
return model.endpointUrl
? `${BASE_API_URL}/${model.endpointUrl}/${id}/`
: `${BASE_API_URL}/${urlModel}/${id}/`;
}

export async function handleErrorResponse({
Expand Down Expand Up @@ -199,9 +204,12 @@ export async function defaultDeleteFormAction({
const formData = await event.request.formData();
const schema = z.object({ id: z.string().uuid() });
const deleteForm = await superValidate(formData, zod(schema));
const model = getModelInfo(urlModel);

const id = deleteForm.data.id;
const endpoint = `${BASE_API_URL}/${urlModel}/${id}/`;
const endpoint = model.endpointUrl
? `${BASE_API_URL}/${model.endpointUrl}/${id}/`
: `${BASE_API_URL}/${model.urlModel}/${id}/`;

if (!deleteForm.valid) {
console.error(deleteForm.errors);
Expand Down
36 changes: 36 additions & 0 deletions frontend/src/lib/utils/crud.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ export interface ModelMapEntry {
fileFields?: string[];
filters?: SelectField[];
path?: string;
endpointUrl?: string;
}

type ModelMap = {
Expand Down Expand Up @@ -574,6 +575,41 @@ export const URL_MODEL_MAP: ModelMap = {
{ field: 'entity', urlModel: 'entities' },
{ field: 'user', urlModel: 'users' }
]
},
qualifications: {
name: 'qualification',
localName: 'qualification',
localNamePlural: 'qualifications',
verboseName: 'Qualification',
verboseNamePlural: 'Qualifications'
},
'ebios-rm': {
endpointUrl: 'ebios-rm/studies',
name: 'ebiosrmstudy',
localName: 'ebiosRMstudy',
localNamePlural: 'ebiosRMstudy',
verboseName: 'Ebios RMstudy',
verboseNamePlural: 'Ebios RMstudy',
foreignKeyFields: [
{ field: 'risk_matrix', urlModel: 'risk-matrices' },
{ field: 'assets', urlModel: 'assets' },
{ field: 'authors', urlModel: 'users', urlParams: 'is_third_party=false' },
{ field: 'reviewers', urlModel: 'users', urlParams: 'is_third_party=false' },
{ field: 'folder', urlModel: 'folders', urlParams: 'content_type=DO' }
]
},
'feared-events': {
endpointUrl: 'ebios-rm/feared-events',
name: 'fearedevent',
localName: 'fearedEvent',
localNamePlural: 'fearedEvents',
verboseName: 'Feared event',
verboseNamePlural: 'Feared events',
foreignKeyFields: [
{ field: 'ebios_rm_study', urlModel: 'ebios-rm' },
{ field: 'assets', urlModel: 'assets' },
{ field: 'qualifications', urlModel: 'qualifications' }
]
}
};

Expand Down
Loading
Loading