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

feat: show guided tour on first connection #1404

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
6 changes: 5 additions & 1 deletion backend/iam/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

from ciso_assistant.settings import EMAIL_HOST, EMAIL_HOST_RESCUE

from .models import Role, RoleAssignment
from .models import Folder, Role, RoleAssignment
from .serializers import (
ChangePasswordSerializer,
LoginSerializer,
Expand Down Expand Up @@ -70,6 +70,9 @@ def get(self, request) -> Response:
{"error": "You are not logged in. Please ensure you are logged in."},
status=HTTP_401_UNAUTHORIZED,
)
accessible_domains = RoleAssignment.get_accessible_folders(
Folder.get_root_folder(), request.user, Folder.ContentType.DOMAIN
)
res_data = {
"id": request.user.id,
"email": request.user.email,
Expand All @@ -82,6 +85,7 @@ def get(self, request) -> Response:
"permissions": request.user.permissions,
"is_third_party": request.user.is_third_party,
"is_admin": request.user.is_admin(),
"accessible_domains": [str(f) for f in accessible_domains],
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Add error handling for string conversion.

The list comprehension for converting folders to strings might fail if any folder object is invalid.

-"accessible_domains": [str(f) for f in accessible_domains],
+"accessible_domains": [str(f) for f in accessible_domains if f is not None],
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
"accessible_domains": [str(f) for f in accessible_domains],
"accessible_domains": [str(f) for f in accessible_domains if f is not None],

}
return Response(res_data, status=HTTP_200_OK)

Expand Down
46 changes: 21 additions & 25 deletions frontend/src/lib/components/SideBar/SideBar.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,18 @@
import SideBarNavigation from './SideBarNavigation.svelte';
import SideBarToggle from './SideBarToggle.svelte';
import { onMount } from 'svelte';
export let open: boolean;
export let firstTime = false; // this needs to come from the db ; we also need to make room for variable about the specialized guided tours
import { driverInstance } from '$lib/utils/stores';
$: classesSidebarOpen = (open: boolean) => (open ? '' : '-ml-[14rem] pointer-events-none');

import { safeTranslate } from '$lib/utils/i18n';
import { driverInstance, firstTimeConnection } from '$lib/utils/stores';
import * as m from '$paraglide/messages';

import { driver } from 'driver.js';
import 'driver.js/dist/driver.css';
import { page } from '$app/stores';

export let open: boolean;

const user = $page.data?.user;

// id is not needed, just to help us with authoring
// this is not great, but couldn't find a way for i18n while separating the file.
const steps = [
Expand Down Expand Up @@ -173,38 +177,30 @@
}
];

function wrapStepWithTranslation(step: any) {
const { popover, ...rest } = step;

if (!popover) return step;

return {
...rest,
popover: {
...popover,
title: safeTranslate(popover.title),
description: safeTranslate(popover.description)
}
};
}
import { driver } from 'driver.js';
import 'driver.js/dist/driver.css';
import { description } from '$paraglide/messages/ro';

function triggerVisit() {
const translatedSteps = steps; //steps.map(wrapStepWithTranslation);
const translatedSteps = steps;
const driverObj = driver({
showProgress: true,
steps: translatedSteps
});
$driverInstance = driverObj;
driverObj.drive();
}

onMount(() => {
if (firstTime) {
if (displayGuidedTour) {
triggerVisit();
$firstTimeConnection = false; // This will prevent the tour from showing up again on page reload
}
});

$: classesSidebarOpen = (open: boolean) => (open ? '' : '-ml-[14rem] pointer-events-none');

$: $firstTimeConnection = $firstTimeConnection && user.accessible_domains.length === 0;

// NOTE: For now, there is only a single guided tour, which is targeted at an administrator.
// Later, we will have tours for domain managers, analysts etc.
$: displayGuidedTour = $firstTimeConnection && user.is_admin;
</script>

<aside
Expand Down
5 changes: 3 additions & 2 deletions frontend/src/lib/utils/stores.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { writable } from 'svelte/store';
import { browser } from '$app/environment';
import { persisted } from 'svelte-persisted-store';
import type { TreeViewNode } from '@skeletonlabs/skeleton';
import type { Driver } from 'driver.js';

export const showNotification = writable(
(browser && localStorage.getItem('showNotification')) || 'false'
Expand All @@ -15,6 +16,8 @@ export const clientSideToast = writable(undefined);

const requirementAssessmentsList: string[] = [];

export const firstTimeConnection = persisted('firstTimeConnection', true);

export const hideSuggestions = persisted('hideSuggestions', requirementAssessmentsList, {
storage: 'session'
});
Expand Down Expand Up @@ -51,6 +54,4 @@ export const createModalCache = {
data: {}
};

import type { Driver } from 'driver.js';

export const driverInstance = writable<Driver | null>(null);
6 changes: 6 additions & 0 deletions frontend/src/lib/utils/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@ export interface User {
last_name: string;
is_active: boolean;
date_joined: string;
user_groups: Record<string, any>[];
roles: Record<string, any>[];
permissions: Record<string, any>[];
is_third_party: boolean;
is_admin: boolean;
accessible_domains: string[];
}

export interface GlobalSettings {
Expand Down
Loading