Skip to content

Commit

Permalink
Merge branch 'main' into hotfix/missing-translations
Browse files Browse the repository at this point in the history
  • Loading branch information
eric-intuitem committed Mar 8, 2024
2 parents b964cda + 686f670 commit f647f7a
Show file tree
Hide file tree
Showing 14 changed files with 79 additions and 18 deletions.
1 change: 1 addition & 0 deletions backend/core/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -453,6 +453,7 @@ class Project(NameDescriptionMixin, FolderMixin):
choices=PRJ_LC_STATUS,
verbose_name=_("Status"),
)
fields_to_check = ["name"]

class Meta:
verbose_name = _("Project")
Expand Down
12 changes: 4 additions & 8 deletions backend/library/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@
from .serializers import LibrarySerializer, LibraryUploadSerializer
from .utils import get_available_libraries, get_library, import_library_view


class LibraryViewSet(BaseModelViewSet):
serializer_class = LibrarySerializer
parser_classes = [FileUploadParser]

# solve issue with URN containing dot, see https://stackoverflow.com/questions/27963899/django-rest-framework-using-dot-in-url
lookup_value_regex = r"[\w.:-]+"
Expand Down Expand Up @@ -127,15 +127,11 @@ def import_library(self, request, pk=None):
status=HTTP_422_UNPROCESSABLE_ENTITY,
)


class UploadLibraryView(APIView):
parser_classes = (FileUploadParser,)
serializer_class = LibraryUploadSerializer

def post(self, request):
@action(detail=False, methods=["post"], url_path="upload")
def upload_library(self, request):
if not request.data:
return HttpResponse(
json.dumps({"error": "No file detected !"}), status=HTTP_400_BAD_REQUEST
json.dumps({"error": "noFileDetected"}), status=HTTP_400_BAD_REQUEST
)

try:
Expand Down
Empty file added documentation/architecture.md
Empty file.
4 changes: 3 additions & 1 deletion frontend/messages/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
"roleAssignments": "Role assignments",
"xRays": "X-rays",
"scoringAssistant": "Scoring assistant",
"scoringAssistantNoMatrixError": "Please import a risk matrix from the libraries store to get access to this page",
"libraries": "Libraries",
"backupRestore": "Backup & restore",
"myProfile": "My profile",
Expand Down Expand Up @@ -444,5 +445,6 @@
"associatedRequirements": "Associated requirements",
"isPublished": "Is published",
"suggestedReferenceControls": "Suggested reference controls",
"threatsCovered": "Threats covered"
"threatsCovered": "Threats covered",
"noFileDetected": "Error: no file detected"
}
4 changes: 3 additions & 1 deletion frontend/messages/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
"roleAssignments": "Affectations de rôle",
"xRays": "X-rays",
"scoringAssistant": "Assistant d'évaluation",
"scoringAssistantNoMatrixError": "Veuillez importer une matrice de risque depuis le magasin de bibliothèques pour pouvoir accéder à cette page",
"libraries": "Bibliothèques",
"backupRestore": "Sauvegarde et restauration",
"myProfile": "Mon profil",
Expand Down Expand Up @@ -444,5 +445,6 @@
"associatedRequirements": "Exigences associées",
"isPublished": "Publié",
"suggestedReferenceControls": "Mesures de référence suggérés",
"threatsCovered": "Menaces couvertes"
"threatsCovered": "Menaces couvertes",
"noFileDetected": "Erreur: aucun fichier détecté"
}
36 changes: 36 additions & 0 deletions frontend/src/lib/components/SideBar/SideBarItem.svelte
Original file line number Diff line number Diff line change
@@ -1,13 +1,48 @@
<script lang="ts">
import { page } from '$app/stores';
import type { ModalSettings } from '@skeletonlabs/skeleton';
import { getModalStore } from '@skeletonlabs/skeleton';
import { localItems } from '$lib/utils/locales';
import { languageTag } from '$paraglide/runtime';
import * as m from '$paraglide/messages';
export let item: any; // TODO: type this
const modalStore = getModalStore();
$: classesActive = (href: string) =>
href === $page.url.pathname
? 'bg-primary-100 text-primary-800'
: 'hover:bg-primary-50 text-gray-800 ';
async function onClickScoringAssistant(event) {
const req = await fetch(`/risk-matrices`);
const risk_matrices = await req.json();
if (risk_matrices.length === 0) {
const modal: ModalSettings = {
type: 'component',
component: 'displayJSONModal',
title: m.scoringAssistantNoMatrixError(),
body: JSON.stringify({})
};
modalStore.trigger(modal);
} else {
const clickEvent = new MouseEvent('click', {
bubbles: true,
cancelable: false
});
event.target.dispatchEvent(clickEvent);
}
}
function onClick(event,item) {
if (item.name === "scoringAssistant") {
if (!event.cancelable) { return; }
event.preventDefault();
return onClickScoringAssistant(event);
}
}
</script>

{#each item as item}
Expand All @@ -17,6 +52,7 @@
item.href ?? ''
)}"
data-testid={'accordion-item-' + item.href.substring(1)}
on:click={(event) => onClick(event,item)}
>
<span class="px-4 flex items-center w-full space-x-2 text-xs">
<i class="{item.fa_icon} w-1/12" />
Expand Down
3 changes: 2 additions & 1 deletion frontend/src/lib/utils/locales.ts
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,8 @@ export function localItems(languageTag: string): LocalItems {
domainManager: m.domainManager({ languageTag: languageTag }),
authors: m.authors({ languageTag: languageTag }),
reviewers: m.reviewers({ languageTag: languageTag }),
isPublished: m.isPublished({ languageTag: languageTag })
isPublished: m.isPublished({ languageTag: languageTag }),
noFileDetected: m.noFileDetected({ languageTag: languageTag }),

};
return LOCAL_ITEMS;
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/lib/utils/schemas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export const RiskMatrixSchema = baseNamedObject({
});

export const LibraryUploadSchema = z.object({
file: z.string()
file: z.string().optional()
});

export const RiskAssessmentSchema = baseNamedObject({
Expand Down
4 changes: 3 additions & 1 deletion frontend/src/routes/(app)/libraries/+page.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import { z } from 'zod';
import { tableSourceMapper } from '@skeletonlabs/skeleton';
import { listViewFields } from '$lib/utils/table';
import type { Library, urlModel } from '$lib/utils/types';
import { localItems } from '$lib/utils/locales';
import { languageTag } from '$paraglide/runtime';

export const load = (async ({ fetch }) => {
const endpoint = `${BASE_API_URL}/libraries/`;
Expand Down Expand Up @@ -94,7 +96,7 @@ export const actions: Actions = {
if (!req.ok) {
const response = await req.json();
console.error(response);
setFlash({ type: 'error', message: `Error: ${response.error}` }, event);
setFlash({ type: 'error', message: localItems(languageTag())[response.error] }, event);
return fail(400, { form });
}
setFlash({ type: 'success', message: 'Library successfully imported !' }, event);
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/routes/(app)/libraries/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@
<button
class="btn variant-filled-primary font-semibold w-full"
data-testid="save-button"
type="submit">{m.save()}</button
type="submit">{m.upload()}</button
>
</SuperForm>
{:catch err}
Expand Down
14 changes: 14 additions & 0 deletions frontend/src/routes/(app)/risk-matrices/[id=uuid]/+server.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { BASE_API_URL } from "$lib/utils/constants";
import type { RequestHandler } from './$types';

export const GET: RequestHandler = async ({ fetch }) => {
const req = await fetch(`${BASE_API_URL}/risk-matrices/`);
const data = await req.json();

return new Response(JSON.stringify(data), {
headers: {
'Content-Type': 'application/json'
}
});
}

9 changes: 8 additions & 1 deletion frontend/tests/functional/nav.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,14 @@ test('sidebar navigation tests', async ({ logedPage, analyticsPage, sideBar, pag
for await (const [key, value] of sideBar.items) {
for await (const item of value) {
if (item.href !== '/role-assignments') {
await sideBar.click(key, item.href);
await sideBar.click(key, item.href, false);
if (item.href === '/scoring-assistant' && await logedPage.modalTitle.isVisible()) {
await expect(logedPage.modalTitle).toBeVisible();
await expect(logedPage.modalTitle).toHaveText('Please import a risk matrix from the library to get access to this page');
await page.mouse.click(20, 20); // click outside the modal to close it
await expect(logedPage.modalTitle).not.toBeVisible();
continue;
}
await expect(page).toHaveURL(item.href);

Check failure on line 27 in frontend/tests/functional/nav.test.ts

View workflow job for this annotation

GitHub Actions / functional-tests (3.11)

[firefox] › functional/nav.test.ts:5:1 › sidebar navigation tests

1) [firefox] › functional/nav.test.ts:5:1 › sidebar navigation tests › navigation link are working properly Error: Timed out 10000ms waiting for expect(locator).toHaveURL(expected) Locator: locator(':root') Expected string: "http://localhost:4173/libraries" Received string: "http://localhost:4173/scoring-assistant" Call log: - expect.toHaveURL with timeout 10000ms - waiting for locator(':root') - locator resolved to <html lang="en">…</html> - unexpected value "http://localhost:4173/scoring-assistant" - locator resolved to <html lang="en">…</html> - unexpected value "http://localhost:4173/scoring-assistant" - locator resolved to <html lang="en">…</html> - unexpected value "http://localhost:4173/scoring-assistant" - locator resolved to <html lang="en">…</html> - unexpected value "http://localhost:4173/scoring-assistant" - locator resolved to <html lang="en">…</html> - unexpected value "http://localhost:4173/scoring-assistant" - locator resolved to <html lang="en">…</html> - unexpected value "http://localhost:4173/scoring-assistant" - locator resolved to <html lang="en">…</html> - unexpected value "http://localhost:4173/scoring-assistant" - locator resolved to <html lang="en">…</html> - unexpected value "http://localhost:4173/scoring-assistant" - locator resolved to <html lang="en">…</html> - unexpected value "http://localhost:4173/scoring-assistant" - locator resolved to <html lang="en">…</html> - unexpected value "http://localhost:4173/scoring-assistant" - locator resolved to <html lang="en">…</html> - unexpected value "http://localhost:4173/scoring-assistant" - locator resolved to <html lang="en">…</html> - unexpected value "http://localhost:4173/scoring-assistant" - locator resolved to <html lang="en">…</html> - unexpected value "http://localhost:4173/scoring-assistant" - locator resolved to <html lang="en">…</html> - unexpected value "http://localhost:4173/scoring-assistant" 25 | continue; 26 | } > 27 | await expect(page).toHaveURL(item.href); | ^ 28 | await logedPage.hasTitle(locals[item.name]); 29 | await logedPage.hasBreadcrumbPath([locals[item.name]]); 30 | } at /home/runner/work/ciso-assistant-community/ciso-assistant-community/frontend/tests/functional/nav.test.ts:27:25 at /home/runner/work/ciso-assistant-community/ciso-assistant-community/frontend/tests/functional/nav.test.ts:14:5

Check failure on line 27 in frontend/tests/functional/nav.test.ts

View workflow job for this annotation

GitHub Actions / functional-tests (3.11)

[firefox] › functional/nav.test.ts:5:1 › sidebar navigation tests

1) [firefox] › functional/nav.test.ts:5:1 › sidebar navigation tests › navigation link are working properly Retry #1 ─────────────────────────────────────────────────────────────────────────────────────── Error: Timed out 10000ms waiting for expect(locator).toHaveURL(expected) Locator: locator(':root') Expected string: "http://localhost:4173/libraries" Received string: "http://localhost:4173/scoring-assistant" Call log: - expect.toHaveURL with timeout 10000ms - waiting for locator(':root') - locator resolved to <html lang="en">…</html> - unexpected value "http://localhost:4173/scoring-assistant" - locator resolved to <html lang="en">…</html> - unexpected value "http://localhost:4173/scoring-assistant" - locator resolved to <html lang="en">…</html> - unexpected value "http://localhost:4173/scoring-assistant" - locator resolved to <html lang="en">…</html> - unexpected value "http://localhost:4173/scoring-assistant" - locator resolved to <html lang="en">…</html> - unexpected value "http://localhost:4173/scoring-assistant" - locator resolved to <html lang="en">…</html> - unexpected value "http://localhost:4173/scoring-assistant" - locator resolved to <html lang="en">…</html> - unexpected value "http://localhost:4173/scoring-assistant" - locator resolved to <html lang="en">…</html> - unexpected value "http://localhost:4173/scoring-assistant" - locator resolved to <html lang="en">…</html> - unexpected value "http://localhost:4173/scoring-assistant" - locator resolved to <html lang="en">…</html> - unexpected value "http://localhost:4173/scoring-assistant" - locator resolved to <html lang="en">…</html> - unexpected value "http://localhost:4173/scoring-assistant" - locator resolved to <html lang="en">…</html> - unexpected value "http://localhost:4173/scoring-assistant" - locator resolved to <html lang="en">…</html> - unexpected value "http://localhost:4173/scoring-assistant" - locator resolved to <html lang="en">…</html> - unexpected value "http://localhost:4173/scoring-assistant" 25 | continue; 26 | } > 27 | await expect(page).toHaveURL(item.href); | ^ 28 | await logedPage.hasTitle(locals[item.name]); 29 | await logedPage.hasBreadcrumbPath([locals[item.name]]); 30 | } at /home/runner/work/ciso-assistant-community/ciso-assistant-community/frontend/tests/functional/nav.test.ts:27:25 at /home/runner/work/ciso-assistant-community/ciso-assistant-community/frontend/tests/functional/nav.test.ts:14:5
await logedPage.hasTitle(locals[item.name]);
await logedPage.hasBreadcrumbPath([locals[item.name]]);
Expand Down
2 changes: 1 addition & 1 deletion frontend/tests/functional/user-route.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ test('user usual routine actions are working correctly', async ({
//TODO assert that the reference control data are displayed in the table
});

await test.step('user can create a applied control', async () => {
await test.step('user can create an applied control', async () => {
await sideBar.click('Context', pages.appliedControlsPage.url);
await pages.appliedControlsPage.hasUrl();
await pages.appliedControlsPage.hasTitle();
Expand Down
4 changes: 2 additions & 2 deletions frontend/tests/utils/sidebar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,13 @@ export class SideBar {
this.toggleButton = this.page.getByTestId('sidebar-toggle-btn');
}

async click(parent: string, tab: string) {
async click(parent: string, tab: string, waitForURL: boolean = true) {
if (!(await this.page.getByTestId('accordion-item-' + tab.substring(1)).isVisible())) {
await this.page.locator('#' + parent.toLowerCase().replace(' ', '-')).click();
}
await expect(this.page.getByTestId('accordion-item-' + tab.substring(1))).toBeVisible();
await this.page.getByTestId('accordion-item-' + tab.substring(1)).click();
await this.page.waitForURL(tab);
waitForURL ? await this.page.waitForURL(tab) : null;
}

async goto(page: PageContent) {
Expand Down

0 comments on commit f647f7a

Please sign in to comment.