0
Fork 0
mirror of https://github.com/logto-io/logto.git synced 2025-01-06 20:40:08 -05:00

fix: delete custom domain (#737)

* fix: delete custom domain

* fix: use sql wrapper
This commit is contained in:
Wang Sijie 2022-05-06 10:48:34 +08:00 committed by GitHub
parent 2d9b7088a6
commit 8a48fb6225
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 14 additions and 36 deletions

View file

@ -13,7 +13,6 @@ import CardTitle from '@/components/CardTitle';
import FormField from '@/components/FormField';
import Select from '@/components/Select';
import TabNav, { TabNavLink } from '@/components/TabNav';
import TextInput from '@/components/TextInput';
import { themeStorageKey } from '@/consts';
import useApi, { RequestError } from '@/hooks/use-api';
import * as detailsStyles from '@/scss/details.module.scss';
@ -26,7 +25,6 @@ const Settings = () => {
const {
reset,
handleSubmit,
register,
control,
formState: { isSubmitting },
} = useForm<Setting>();
@ -66,9 +64,6 @@ const Settings = () => {
{data && (
<form className={detailsStyles.body} onSubmit={onSubmit}>
<div className={styles.fields}>
<FormField title="admin_console.settings.custom_domain">
<TextInput {...register('customDomain')} />
</FormField>
<FormField isRequired title="admin_console.settings.language">
<Controller
name="adminConsole.language"

View file

@ -45,7 +45,6 @@ export const mockRole: Role = {
export const mockSetting: Setting = {
id: 'foo setting',
customDomain: 'mock-logto.dev',
adminConsole: {
language: Language.English,
appearanceMode: AppearanceMode.SyncWithSystem,

View file

@ -73,10 +73,10 @@ export const createDatabaseCli = (dsn: string) => {
}
};
const seedTables = async (domain: string) => {
const seedTables = async () => {
await Promise.all([
pool.query(insertInto(managementResource, 'resources')),
pool.query(insertInto(createDefaultSetting(domain), 'settings')),
pool.query(insertInto(createDefaultSetting(), 'settings')),
pool.query(insertInto(defaultSignInExperience, 'sign_in_experiences')),
]);
console.log(`${chalk.blue('[seed-tables]')} Seed tables succeeded.`);

View file

@ -55,7 +55,7 @@ const inquireForLogtoDsn = async (key: string): Promise<[Optional<string>, boole
return [dsn, true];
};
const createPoolByEnv = async (isTest: boolean, localhostUrl: string) => {
const createPoolByEnv = async (isTest: boolean) => {
// Database connection is disabled in unit test environment
if (isTest) {
return;
@ -82,14 +82,8 @@ const createPoolByEnv = async (isTest: boolean, localhostUrl: string) => {
const cli = createDatabaseCli(dsn);
if (needsSeed) {
const domain = await inquirer.prompt({
name: 'value',
default: localhostUrl,
message: 'Enter your domain for Logto:',
});
await cli.createTables();
await cli.seedTables(domain.value);
await cli.seedTables();
}
appendDotEnv(key, dsn);

View file

@ -1,4 +1,4 @@
import { conditionalString, getEnv, Optional } from '@silverhand/essentials';
import { getEnv, Optional } from '@silverhand/essentials';
import { DatabasePool } from 'slonik';
import createPoolByEnv from './create-pool-by-env';
@ -59,10 +59,7 @@ function createEnvSet() {
load: async () => {
values = await loadEnvValues();
pool = await createPoolByEnv(
values.isTest,
`http${conditionalString(values.isHttpsEnabled && 's')}://localhost:${values.port}`
);
pool = await createPoolByEnv(values.isTest);
},
};
}

View file

@ -40,22 +40,24 @@ describe('setting query', () => {
});
it('updateSetting', async () => {
const customDomain = 'logto.io';
const { adminConsole } = mockSetting;
const expectSql = sql`
update ${table}
set ${fields.customDomain}=$1
set
${fields.adminConsole}=
coalesce("admin_console",'{}'::jsonb)|| $1
where ${fields.id}=$2
returning *
`;
mockQuery.mockImplementationOnce(async (sql, values) => {
expectSqlAssert(sql, expectSql.sql);
expect(values).toEqual([customDomain, defaultSettingId]);
expect(values).toEqual([JSON.stringify(adminConsole), defaultSettingId]);
return createMockQueryResult([dbvalue]);
});
await expect(updateSetting({ customDomain })).resolves.toEqual(dbvalue);
await expect(updateSetting({ adminConsole })).resolves.toEqual(dbvalue);
});
});

View file

@ -26,17 +26,14 @@ describe('settings routes', () => {
});
it('PATCH /settings', async () => {
const customDomain = 'silverhand-logto.io';
const { adminConsole } = mockSetting;
const response = await roleRequester.patch('/settings').send({
customDomain,
adminConsole,
});
expect(response.status).toEqual(200);
expect(response.body).toEqual({
customDomain,
adminConsole,
});
});

View file

@ -11,19 +11,16 @@ import {
export type CreateSetting = {
id: string;
customDomain?: string | null;
adminConsole: AdminConsoleConfig;
};
export type Setting = {
id: string;
customDomain: string | null;
adminConsole: AdminConsoleConfig;
};
const createGuard: Guard<CreateSetting> = z.object({
id: z.string(),
customDomain: z.string().nullable().optional(),
adminConsole: adminConsoleConfigGuard,
});
@ -32,9 +29,8 @@ export const Settings: GeneratedSchema<CreateSetting> = Object.freeze({
tableSingular: 'setting',
fields: {
id: 'id',
customDomain: 'custom_domain',
adminConsole: 'admin_console',
},
fieldKeys: ['id', 'customDomain', 'adminConsole'],
fieldKeys: ['id', 'adminConsole'],
createGuard,
});

View file

@ -5,10 +5,9 @@ import { AppearanceMode } from '../foundations';
export const defaultSettingId = 'default';
export const createDefaultSetting = (customDomain: string): Readonly<CreateSetting> =>
export const createDefaultSetting = (): Readonly<CreateSetting> =>
Object.freeze({
id: defaultSettingId,
customDomain,
adminConsole: {
language: Language.English,
appearanceMode: AppearanceMode.SyncWithSystem,

View file

@ -1,6 +1,5 @@
create table settings (
id varchar(21) not null,
custom_domain text,
admin_console jsonb /* @use AdminConsoleConfig */ not null,
primary key (id)
);