From ced360b7a4e52f3ccc5ce0ffde611a6c57ce7509 Mon Sep 17 00:00:00 2001 From: Darcy Ye Date: Mon, 6 Jan 2025 20:01:13 +0800 Subject: [PATCH] refactor: make SAML apps to be first party apps (#6913) --- .../src/components/ApplicationIcon/index.tsx | 5 ++-- .../src/saml-applications/routes/index.ts | 1 - ...735292380-make-saml-app-first-party-app.ts | 28 +++++++++++++++++++ packages/schemas/tables/applications.sql | 5 +--- 4 files changed, 32 insertions(+), 7 deletions(-) create mode 100644 packages/schemas/alterations/next-1735292380-make-saml-app-first-party-app.ts diff --git a/packages/console/src/components/ApplicationIcon/index.tsx b/packages/console/src/components/ApplicationIcon/index.tsx index ac5698db8..2610492e7 100644 --- a/packages/console/src/components/ApplicationIcon/index.tsx +++ b/packages/console/src/components/ApplicationIcon/index.tsx @@ -15,9 +15,10 @@ type Props = { }; const getIcon = (type: ApplicationType, isLightMode: boolean, isThirdParty?: boolean) => { - // We have ensured that SAML applications are always third party in DB schema, we use `??` here to make TypeScript happy. + // We have ensured that SAML applications are always third party in DB schema, we use `||` here to make TypeScript happy. // TODO: @darcy fix this when SAML application is ready - if (isThirdParty ?? type === ApplicationType.SAML) { + // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing + if (isThirdParty || type === ApplicationType.SAML) { return isLightMode ? thirdPartyApplicationIcon : thirdPartyApplicationIconDark; } diff --git a/packages/core/src/saml-applications/routes/index.ts b/packages/core/src/saml-applications/routes/index.ts index d4ece6372..446be17d9 100644 --- a/packages/core/src/saml-applications/routes/index.ts +++ b/packages/core/src/saml-applications/routes/index.ts @@ -66,7 +66,6 @@ export default function samlApplicationRoutes( description, customData, oidcClientMetadata: buildOidcClientMetadata(), - isThirdParty: true, type: ApplicationType.SAML, }) ); diff --git a/packages/schemas/alterations/next-1735292380-make-saml-app-first-party-app.ts b/packages/schemas/alterations/next-1735292380-make-saml-app-first-party-app.ts new file mode 100644 index 000000000..f175c70b3 --- /dev/null +++ b/packages/schemas/alterations/next-1735292380-make-saml-app-first-party-app.ts @@ -0,0 +1,28 @@ +import { sql } from '@silverhand/slonik'; + +import type { AlterationScript } from '../lib/types/alteration.js'; + +const alteration: AlterationScript = { + up: async (pool) => { + await pool.query(sql` + alter table applications drop constraint check_saml_app_third_party_consistency; + `); + await pool.query(sql` + update applications set is_third_party = false + where type = 'SAML'; + `); + }, + down: async (pool) => { + await pool.query(sql` + update applications set is_third_party = true + where type = 'SAML'; + `); + await pool.query(sql` + alter table applications + add constraint check_saml_app_third_party_consistency + check (type != 'SAML' OR (type = 'SAML' AND is_third_party = true)); + `); + }, +}; + +export default alteration; diff --git a/packages/schemas/tables/applications.sql b/packages/schemas/tables/applications.sql index 98f97ce99..6f7a7a973 100644 --- a/packages/schemas/tables/applications.sql +++ b/packages/schemas/tables/applications.sql @@ -17,10 +17,7 @@ create table applications ( custom_data jsonb /* @use JsonObject */ not null default '{}'::jsonb, is_third_party boolean not null default false, created_at timestamptz not null default(now()), - primary key (id), - constraint check_saml_app_third_party_consistency check ( - type != 'SAML' OR (type = 'SAML' AND is_third_party = true) - ) + primary key (id) ); create index applications__id