Skip to content

Commit

Permalink
feat(schemas): add agree_to_terms_policy for sie table
Browse files Browse the repository at this point in the history
  • Loading branch information
xiaoyijun committed Jun 17, 2024
1 parent 41495a3 commit c28ec1d
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 2 deletions.
3 changes: 2 additions & 1 deletion packages/core/src/__mocks__/sign-in-experience.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import type {
SignUp,
SignIn,
} from '@logto/schemas';
import { SignInMode, SignInIdentifier, MfaPolicy } from '@logto/schemas';
import { SignInMode, SignInIdentifier, MfaPolicy, AgreeToTermsPolicy } from '@logto/schemas';

export const mockColor: Color = {
primaryColor: '#000',
Expand Down Expand Up @@ -91,6 +91,7 @@ export const mockSignInExperience: SignInExperience = {
signInMode: SignInMode.SignInAndRegister,
customCss: null,
customContent: {},
agreeToTermsPolicy: AgreeToTermsPolicy.AutoAgree,
passwordPolicy: {},
mfa: {
policy: MfaPolicy.UserControlled,
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/queries/sign-in-experience.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ describe('sign-in-experience query', () => {
it('findDefaultSignInExperience', async () => {
/* eslint-disable sql/no-unsafe-query */
const expectSql = `
select "tenant_id", "id", "color", "branding", "language_info", "terms_of_use_url", "privacy_policy_url", "sign_in", "sign_up", "social_sign_in", "social_sign_in_connector_targets", "sign_in_mode", "custom_css", "custom_content", "password_policy", "mfa", "single_sign_on_enabled"
select "tenant_id", "id", "color", "branding", "language_info", "terms_of_use_url", "privacy_policy_url", "agree_to_terms_policy", "sign_in", "sign_up", "social_sign_in", "social_sign_in_connector_targets", "sign_in_mode", "custom_css", "custom_content", "password_policy", "mfa", "single_sign_on_enabled"
from "sign_in_experiences"
where "id"=$1
`;
Expand Down
3 changes: 3 additions & 0 deletions packages/experience/src/__mocks__/logto.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import type { SignInExperience, SignIn, SsoConnectorMetadata } from '@logto/schemas';
import {
AgreeToTermsPolicy,
ConnectorPlatform,
ConnectorType,
MfaPolicy,
Expand Down Expand Up @@ -104,6 +105,7 @@ export const mockSignInExperience: SignInExperience = {
signInMode: SignInMode.SignInAndRegister,
customCss: null,
customContent: {},
agreeToTermsPolicy: AgreeToTermsPolicy.AutoAgree,
passwordPolicy: {},
mfa: {
policy: MfaPolicy.UserControlled,
Expand Down Expand Up @@ -136,6 +138,7 @@ export const mockSignInExperienceSettings: SignInExperienceResponse = {
},
customCss: null,
customContent: {},
agreeToTermsPolicy: AgreeToTermsPolicy.AutoAgree,
passwordPolicy: {},
mfa: {
policy: MfaPolicy.UserControlled,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import { yes } from '@silverhand/essentials';
import { sql } from '@silverhand/slonik';

import type { AlterationScript } from '../lib/types/alteration.js';

const isCi = yes(process.env.CI);

const alteration: AlterationScript = {
up: async (pool) => {
// Create type
await pool.query(sql`
create type agree_to_terms_policy as enum ('AutoAgree', 'RegistrationOnly', 'RegistrationAndSignIn');
`);

if (isCi) {
// Direct set default to 'AutoAgree' to align with the sql table definition
await pool.query(sql`
alter table sign_in_experiences add column agree_to_terms_policy agree_to_terms_policy not null default 'AutoAgree';
`);
} else {
// For compatibility with existing data, default to 'RegistrationOnly'
await pool.query(sql`
alter table sign_in_experiences add column agree_to_terms_policy agree_to_terms_policy not null default 'RegistrationOnly';
`);

// For new data, default to 'AutoAgree'
await pool.query(sql`
alter table sign_in_experiences alter column agree_to_terms_policy set default 'AutoAgree';
`);
}
},
down: async (pool) => {
await pool.query(sql`
alter table sign_in_experiences drop column agree_to_terms_policy;
drop type agree_to_terms_policy;
`);
},
};

export default alteration;
2 changes: 2 additions & 0 deletions packages/schemas/tables/sign_in_experiences.sql
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
create type sign_in_mode as enum ('SignIn', 'Register', 'SignInAndRegister');
create type agree_to_terms_policy as enum ('AutoAgree', 'RegistrationOnly', 'RegistrationAndSignIn');

create table sign_in_experiences (
tenant_id varchar(21) not null
Expand All @@ -9,6 +10,7 @@ create table sign_in_experiences (
language_info jsonb /* @use LanguageInfo */ not null,
terms_of_use_url varchar(2048),
privacy_policy_url varchar(2048),
agree_to_terms_policy agree_to_terms_policy not null default 'AutoAgree',
sign_in jsonb /* @use SignIn */ not null,
sign_up jsonb /* @use SignUp */ not null,
social_sign_in jsonb /* @use SocialSignIn */ not null default '{}'::jsonb,
Expand Down

0 comments on commit c28ec1d

Please sign in to comment.