From 7a77bd6c7902d68ce07bd7af54d5f84c69f03485 Mon Sep 17 00:00:00 2001 From: Rotimi Best Date: Tue, 9 Sep 2025 13:12:56 +0100 Subject: [PATCH] chore: check permission only after org is loaded --- .vscode/settings.json | 3 ++- .../src/lib/components/CourseContainer/index.svelte | 7 ++++--- .../lib/components/Org/Settings/TeamMembers.svelte | 12 ++++++------ apps/dashboard/src/lib/utils/store/org.ts | 8 ++++++-- 4 files changed, 18 insertions(+), 12 deletions(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index 225d8f1f..be9fd438 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -20,5 +20,6 @@ "editor.formatOnSave": true, "[svelte]": { "editor.defaultFormatter": "svelte.svelte-vscode" - } + }, + "vitest.disableWorkspaceWarning": true } diff --git a/apps/dashboard/src/lib/components/CourseContainer/index.svelte b/apps/dashboard/src/lib/components/CourseContainer/index.svelte index a7f767e8..901e583a 100644 --- a/apps/dashboard/src/lib/components/CourseContainer/index.svelte +++ b/apps/dashboard/src/lib/components/CourseContainer/index.svelte @@ -52,13 +52,14 @@ $: onCourseIdChange(courseId); $: { + console.log('isOrgAdmin', $isOrgAdmin); const user = $group.people.find((person) => person.profile_id === $profile.id); if (user) { $globalStore.isStudent = user.role_id === 3; filterPollsByStatus($globalStore.isStudent); - } else if (!$isOrgAdmin && $profile.id && $group.people.length) { - // Current User doesn't have permission to view + } else if ($isOrgAdmin === false && $profile.id && $group.people.length) { + // Current User doesn't h ave permission to view isPermitted = false; } } @@ -76,7 +77,7 @@
-

+

{$t('course.not_permitted.body')}

diff --git a/apps/dashboard/src/lib/components/Org/Settings/TeamMembers.svelte b/apps/dashboard/src/lib/components/Org/Settings/TeamMembers.svelte index e2f71a7b..88412e0b 100644 --- a/apps/dashboard/src/lib/components/Org/Settings/TeamMembers.svelte +++ b/apps/dashboard/src/lib/components/Org/Settings/TeamMembers.svelte @@ -134,13 +134,13 @@ $: fetchTeam($currentOrg.id); - - + + {$t('course.navItem.people.teams.add')} -

+

{$t('course.navItem.people.teams.add_team')}

@@ -174,7 +174,7 @@
- + {$t('course.navItem.people.teams.members')} @@ -183,9 +183,9 @@ {:else} {#each $orgTeam as teamMember} -
+
-

+

{teamMember.email}

diff --git a/apps/dashboard/src/lib/utils/store/org.ts b/apps/dashboard/src/lib/utils/store/org.ts index 35015c6f..71888015 100644 --- a/apps/dashboard/src/lib/utils/store/org.ts +++ b/apps/dashboard/src/lib/utils/store/org.ts @@ -3,11 +3,11 @@ import { browser, dev } from '$app/environment'; import { derived, writable } from 'svelte/store'; import { PLAN } from 'shared/src/plans/constants'; +import { PUBLIC_IS_SELFHOSTED } from '$env/static/public'; import { ROLE } from '$lib/utils/constants/roles'; import { STEPS } from '../constants/quiz'; import type { UserLessonDataType } from '$lib/utils/types'; import type { Writable } from 'svelte/store'; -import { PUBLIC_IS_SELFHOSTED } from '$env/static/public'; // Trigger build export const defaultCurrentOrgState: CurrentOrg = { @@ -33,7 +33,11 @@ export const orgs = writable([]); export const currentOrg: Writable = writable(defaultCurrentOrgState); export const orgAudience = writable([]); export const orgTeam = writable([]); -export const isOrgAdmin = derived(currentOrg, ($currentOrg) => $currentOrg.role_id === ROLE.ADMIN); +export const isOrgAdmin = derived(currentOrg, ($currentOrg) => { + if ($currentOrg.role_id === 0) return null; + + return $currentOrg.role_id === ROLE.ADMIN; +}); const getActivePlan = (org: CurrentOrg) => { return org.organization_plan.find((p) => p.is_active);