From 60919af875889b11dd679599edd34edf0719b33c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daphn=C3=A9=20Popin?= Date: Mon, 30 Dec 2024 16:48:52 +0100 Subject: [PATCH] =?UTF-8?q?Pok=C3=A9:=20display=20list=20of=20blacklisted?= =?UTF-8?q?=20domains=20in=20the=20extension?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- front/components/poke/workspace/table.tsx | 16 +++++++++++++++- .../workspaces/extension_blacklist_domains.ts | 15 +++------------ front/pages/poke/[wId]/index.tsx | 9 +++++++++ 3 files changed, 27 insertions(+), 13 deletions(-) diff --git a/front/components/poke/workspace/table.tsx b/front/components/poke/workspace/table.tsx index e4b1c9552c0e..4cf2acbf4c2c 100644 --- a/front/components/poke/workspace/table.tsx +++ b/front/components/poke/workspace/table.tsx @@ -1,4 +1,8 @@ -import type { WorkspaceDomain, WorkspaceType } from "@dust-tt/types"; +import type { + ExtensionConfigurationType, + WorkspaceDomain, + WorkspaceType, +} from "@dust-tt/types"; import { PokeTable, @@ -12,10 +16,12 @@ export function WorkspaceInfoTable({ owner, workspaceVerifiedDomain, worspaceCreationDay, + extensionConfig, }: { owner: WorkspaceType; workspaceVerifiedDomain: WorkspaceDomain | null; worspaceCreationDay: string; + extensionConfig: ExtensionConfigurationType | null; }) { return (
@@ -48,6 +54,14 @@ export function WorkspaceInfoTable({ {workspaceVerifiedDomain?.domain} + + Extension blacklisted domains + + {extensionConfig?.blacklistedDomains.length + ? extensionConfig.blacklistedDomains.join(", ") + : "None"} + +
diff --git a/front/lib/api/poke/plugins/workspaces/extension_blacklist_domains.ts b/front/lib/api/poke/plugins/workspaces/extension_blacklist_domains.ts index fbaca61aa341..1d29b0b2aa05 100644 --- a/front/lib/api/poke/plugins/workspaces/extension_blacklist_domains.ts +++ b/front/lib/api/poke/plugins/workspaces/extension_blacklist_domains.ts @@ -2,6 +2,7 @@ import { Err, Ok } from "@dust-tt/types"; import { createPlugin } from "@app/lib/api/poke/types"; import { updateExtensionConfiguration } from "@app/lib/api/workspace"; +import { isDomain } from "@app/lib/utils"; export const extensionBlacklistDomains = createPlugin( { @@ -14,7 +15,7 @@ export const extensionBlacklistDomains = createPlugin( type: "string", label: "Blacklisted domains", description: - "Comma-separated list of domains to blacklist for the extension.", + "Comma-separated list of domains to blacklist for the extension. This will override the existing list (if any).", }, }, }, @@ -51,21 +52,11 @@ function areDomainsValid(domains: string[]): boolean { return true; // Empty domains array is valid } - // Regular expression for domain validation - // - Starts with alphanumeric or hyphen - // - Can contain alphanumeric, hyphens - // - Must have at least one dot - // - TLD must be at least 2 characters - // - Cannot start or end with hyphen - // - Cannot have consecutive hyphens - const domainRegex = - /^(?!-)[A-Za-z0-9-]+(?:\.[A-Za-z0-9-]+)*\.[A-Za-z]{2,}(?!-)$/; - return domains.every((domain) => { if (domain.length > 253) { return false; } - if (!domainRegex.test(domain)) { + if (!isDomain(domain)) { return false; } const labels = domain.split("."); diff --git a/front/pages/poke/[wId]/index.tsx b/front/pages/poke/[wId]/index.tsx index 6f0c44417803..e65e2f62d2b0 100644 --- a/front/pages/poke/[wId]/index.tsx +++ b/front/pages/poke/[wId]/index.tsx @@ -10,6 +10,7 @@ import { } from "@dust-tt/sparkle"; import type { DataSourceType, + ExtensionConfigurationType, SubscriptionType, WhitelistableFeature, WorkspaceDomain, @@ -46,6 +47,7 @@ import { Plan, Subscription } from "@app/lib/models/plan"; import { FREE_NO_PLAN_CODE } from "@app/lib/plans/plan_codes"; import { renderSubscriptionFromModels } from "@app/lib/plans/renderers"; import { DustProdActionRegistry } from "@app/lib/registry"; +import { ExtensionConfigurationResource } from "@app/lib/resources/extension"; export const getServerSideProps = withSuperUserAuthRequirements<{ owner: WorkspaceType; @@ -56,6 +58,7 @@ export const getServerSideProps = withSuperUserAuthRequirements<{ registry: typeof DustProdActionRegistry; workspaceVerifiedDomain: WorkspaceDomain | null; worspaceCreationDay: string; + extensionConfig: ExtensionConfigurationType | null; baseUrl: string; }>(async (context, auth) => { const owner = auth.workspace(); @@ -93,6 +96,9 @@ export const getServerSideProps = withSuperUserAuthRequirements<{ const workspaceVerifiedDomain = await getWorkspaceVerifiedDomain(owner); const worspaceCreationDate = await getWorkspaceCreationDate(owner.sId); + const extensionConfig = + await ExtensionConfigurationResource.fetchForWorkspace(auth); + return { props: { owner, @@ -106,6 +112,7 @@ export const getServerSideProps = withSuperUserAuthRequirements<{ registry: DustProdActionRegistry, workspaceVerifiedDomain, worspaceCreationDay: format(worspaceCreationDate, "yyyy-MM-dd"), + extensionConfig: extensionConfig?.toJSON() ?? null, baseUrl: config.getClientFacingUrl(), }, }; @@ -120,6 +127,7 @@ const WorkspacePage = ({ registry, workspaceVerifiedDomain, worspaceCreationDay, + extensionConfig, baseUrl, }: InferGetServerSidePropsType) => { const router = useRouter(); @@ -241,6 +249,7 @@ const WorkspacePage = ({ owner={owner} workspaceVerifiedDomain={workspaceVerifiedDomain} worspaceCreationDay={worspaceCreationDay} + extensionConfig={extensionConfig} />