From a00bb133af96cda6d4d8670a01fffec0afdd84e8 Mon Sep 17 00:00:00 2001 From: Rotimi Best Date: Sat, 24 Aug 2024 20:44:16 +0100 Subject: [PATCH] chore: restrict accounts --- .../src/lib/components/Page/Restricted.svelte | 32 +++++++++++++++++++ .../src/lib/utils/services/org/index.ts | 1 + apps/dashboard/src/lib/utils/store/org.ts | 3 +- apps/dashboard/src/lib/utils/types/org.ts | 1 + apps/dashboard/src/routes/+layout.svelte | 5 ++- .../20240824193502_restrict_accounts.sql | 27 ++++++++++++++++ 6 files changed, 67 insertions(+), 2 deletions(-) create mode 100644 apps/dashboard/src/lib/components/Page/Restricted.svelte create mode 100644 supabase/migrations/20240824193502_restrict_accounts.sql diff --git a/apps/dashboard/src/lib/components/Page/Restricted.svelte b/apps/dashboard/src/lib/components/Page/Restricted.svelte new file mode 100644 index 00000000..9b69df7e --- /dev/null +++ b/apps/dashboard/src/lib/components/Page/Restricted.svelte @@ -0,0 +1,32 @@ + + +
+ +
+

Restricted Page

+

+ This organization is restricted. In the mean time, you can go back to the homepage. +

+ +
+
+ + diff --git a/apps/dashboard/src/lib/utils/services/org/index.ts b/apps/dashboard/src/lib/utils/services/org/index.ts index 18c8b544..bad4f739 100644 --- a/apps/dashboard/src/lib/utils/services/org/index.ts +++ b/apps/dashboard/src/lib/utils/services/org/index.ts @@ -228,6 +228,7 @@ export async function getCurrentOrg(siteName: string, justGet = false) { siteName, avatar_url, landingpage, + is_restricted, customization, theme, organization_plan( diff --git a/apps/dashboard/src/lib/utils/store/org.ts b/apps/dashboard/src/lib/utils/store/org.ts index 41ded3e9..2719d369 100644 --- a/apps/dashboard/src/lib/utils/store/org.ts +++ b/apps/dashboard/src/lib/utils/store/org.ts @@ -22,7 +22,8 @@ export const defaultCurrentOrgState: CurrentOrg = { dashboard: { exercise: true, community: true, bannerText: '', bannerImage: '' } }, theme: '', - organization_plan: [] + organization_plan: [], + is_restricted: false }; export const orgs = writable([]); diff --git a/apps/dashboard/src/lib/utils/types/org.ts b/apps/dashboard/src/lib/utils/types/org.ts index 4e716ba6..040f5da9 100644 --- a/apps/dashboard/src/lib/utils/types/org.ts +++ b/apps/dashboard/src/lib/utils/types/org.ts @@ -33,6 +33,7 @@ export interface CurrentOrg { plan_name: string; is_active: boolean; }[]; + is_restricted: boolean; } export interface OrgTeamMember { diff --git a/apps/dashboard/src/routes/+layout.svelte b/apps/dashboard/src/routes/+layout.svelte index 8f91797d..3b6b4ada 100644 --- a/apps/dashboard/src/routes/+layout.svelte +++ b/apps/dashboard/src/routes/+layout.svelte @@ -16,6 +16,7 @@ import LMSNavigation from '$lib/components/Navigation/lms.svelte'; import OrgLandingPage from '$lib/components/Org/LandingPage/index.svelte'; import Snackbar from '$lib/components/Snackbar/index.svelte'; + import Restricted from '$lib/components/Page/Restricted.svelte'; import Backdrop from '$lib/components/Backdrop/index.svelte'; import Apps from '$lib/components/Apps/index.svelte'; import PlayQuiz from '$lib/components/Org/Quiz/Play/index.svelte'; @@ -301,7 +302,9 @@ -{#if data.skipAuth} +{#if data.org?.is_restricted} + +{:else if data.skipAuth} {:else if data.isOrgSite && !path} diff --git a/supabase/migrations/20240824193502_restrict_accounts.sql b/supabase/migrations/20240824193502_restrict_accounts.sql new file mode 100644 index 00000000..0c23ae8e --- /dev/null +++ b/supabase/migrations/20240824193502_restrict_accounts.sql @@ -0,0 +1,27 @@ +drop function if exists "public"."convert_course_to_v2"(course_id uuid); + +alter table "public"."organization" add column "is_restricted" boolean not null default false; + +alter table "public"."profile" add column "is_restricted" boolean not null default false; + +set check_function_bodies = off; + +CREATE +OR REPLACE FUNCTION convert_course_to_v2 (course_id_arg uuid) RETURNS void AS $$ +DECLARE + new_section_id uuid; +BEGIN + UPDATE course + SET version = 'V2' + WHERE id = course_id_arg; + + INSERT INTO lesson_section (title, course_id) VALUES ('First Section [edit me]', course_id_arg) RETURNING id INTO new_section_id; + + UPDATE lesson + SET section_id = new_section_id + WHERE lesson.course_id = course_id_arg; +END; +$$ LANGUAGE plpgsql; + + +