0
Fork 0
mirror of https://github.com/logto-io/logto.git synced 2025-03-31 22:51:25 -05:00

chore: remove deprecated challenge task flags (#4468)

This commit is contained in:
Xiao Yijun 2023-09-11 17:46:13 +08:00 committed by GitHub
parent 9f6fc6100d
commit 9644fa0615
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
11 changed files with 112 additions and 67 deletions

View file

@ -8,7 +8,6 @@ import { AppDataContext } from '@/contexts/AppDataProvider';
import type { Props as ButtonProps, ButtonType } from '@/ds-components/Button';
import Button from '@/ds-components/Button';
import { Tooltip } from '@/ds-components/Tip';
import useConfigs from '@/hooks/use-configs';
import * as styles from './index.module.scss';
@ -19,7 +18,6 @@ type Props = {
};
function LivePreviewButton({ size, type, isDisabled }: Props) {
const { configs, updateConfigs } = useConfigs();
const { tenantEndpoint } = useContext(AppDataContext);
const { t } = useTranslation(undefined, { keyPrefix: 'admin_console' });
@ -39,10 +37,6 @@ function LivePreviewButton({ size, type, isDisabled }: Props) {
/>
}
onClick={() => {
if (!configs?.livePreviewChecked) {
void updateConfigs({ livePreviewChecked: true });
}
window.open(new URL('/demo-app', tenantEndpoint), '_blank');
}}
/>

View file

@ -6,7 +6,6 @@ import AppLoading from '@/components/AppLoading';
import MauExceededModal from '@/components/MauExceededModal';
import PaymentOverdueModal from '@/components/PaymentOverdueModal';
import { isCloud } from '@/consts/env';
import useConfigs from '@/hooks/use-configs';
import useScroll from '@/hooks/use-scroll';
import useUserPreferences from '@/hooks/use-user-preferences';
@ -18,10 +17,7 @@ import * as styles from './index.module.scss';
import { type AppContentOutletContext } from './types';
export default function AppContent() {
const { isLoading: isPreferencesLoading } = useUserPreferences();
const { isLoading: isConfigsLoading } = useConfigs();
const isLoading = isPreferencesLoading || isConfigsLoading;
const { isLoading } = useUserPreferences();
const scrollableContent = useRef<HTMLDivElement>(null);
const { scrollTop } = useScroll(scrollableContent.current);

View file

@ -1,21 +1,16 @@
import { type ConnectorResponse } from '@logto/schemas';
import useApi, { type StaticApiProps } from './use-api';
import useConfigs from './use-configs';
const useConnectorApi = (props: Omit<StaticApiProps, 'prefixUrl' | 'resourceIndicator'> = {}) => {
const api = useApi(props);
const { updateConfigs } = useConfigs();
const createConnector = async (payload: unknown) => {
const connector = await api
const createConnector = async (payload: unknown) =>
api
.post('api/connectors', {
json: payload,
})
.json<ConnectorResponse>();
await updateConfigs({ passwordlessConfigured: true });
return connector;
};
return {
createConnector,

View file

@ -1,6 +1,5 @@
import type { Application } from '@logto/schemas';
import { ApplicationType } from '@logto/schemas';
import { conditional } from '@silverhand/essentials';
import { useContext } from 'react';
import { useController, useForm } from 'react-hook-form';
import { toast } from 'react-hot-toast';
@ -15,7 +14,6 @@ import ModalLayout from '@/ds-components/ModalLayout';
import RadioGroup, { Radio } from '@/ds-components/RadioGroup';
import TextInput from '@/ds-components/TextInput';
import useApi from '@/hooks/use-api';
import useConfigs from '@/hooks/use-configs';
import useSubscriptionPlan from '@/hooks/use-subscription-plan';
import * as modalStyles from '@/scss/modal.module.scss';
import { applicationTypeI18nKey } from '@/types/applications';
@ -42,7 +40,6 @@ function CreateForm({ defaultCreateType, defaultCreateFrameworkName, onClose }:
const { currentTenantId } = useContext(TenantsContext);
const { data: currentPlan } = useSubscriptionPlan(currentTenantId);
const isMachineToMachineDisabled = isCloud && !currentPlan?.quota.machineToMachineLimit;
const { updateConfigs } = useConfigs();
const {
handleSubmit,
control,
@ -69,12 +66,6 @@ function CreateForm({ defaultCreateType, defaultCreateFrameworkName, onClose }:
const createdApp = await api.post('api/applications', { json: data }).json<Application>();
toast.success(t('applications.application_created'));
void updateConfigs({
applicationCreated: true,
...conditional(
createdApp.type === ApplicationType.MachineToMachine && { m2mApplicationCreated: true }
),
});
onClose?.(createdApp);
})
);

View file

@ -15,7 +15,6 @@ import FormField from '@/ds-components/FormField';
import ModalLayout from '@/ds-components/ModalLayout';
import TextInput from '@/ds-components/TextInput';
import useApi from '@/hooks/use-api';
import useConfigs from '@/hooks/use-configs';
import useSubscriptionPlan from '@/hooks/use-subscription-plan';
import { trySubmitSafe } from '@/utils/form';
import { hasReachedQuotaLimit } from '@/utils/quota';
@ -46,7 +45,6 @@ function CreateRoleForm({ totalRoleCount, onClose }: Props) {
} = useForm<CreateRoleFormData>();
const api = useApi();
const { updateConfigs } = useConfigs();
const roleScopes = watch('scopes', []);
const onSubmit = handleSubmit(
@ -62,7 +60,6 @@ function CreateRoleForm({ totalRoleCount, onClose }: Props) {
};
const createdRole = await api.post('api/roles', { json: payload }).json<Role>();
await updateConfigs({ roleCreated: true });
onClose(createdRole);
})
);

View file

@ -92,14 +92,7 @@ export const mockAdminUserRole3: Role = {
};
export const mockAdminConsoleData: AdminConsoleData = {
livePreviewChecked: false,
applicationCreated: false,
signInExperienceCustomized: false,
passwordlessConfigured: false,
furtherReadingsChecked: false,
roleCreated: false,
communityChecked: false,
m2mApplicationCreated: false,
};
export const mockPasscode: Passcode = {

View file

@ -18,24 +18,27 @@ const logtoConfigs = {
const settingRoutes = await pickDefault(import('./logto-config.js'));
describe('configs routes', () => {
const roleRequester = createRequester({
const routeRequester = createRequester({
authedRoutes: settingRoutes,
tenantContext: new MockTenant(undefined, { logtoConfigs }),
});
it('GET /configs/admin-console', async () => {
const response = await roleRequester.get('/configs/admin-console');
const response = await routeRequester.get('/configs/admin-console');
expect(response.status).toEqual(200);
expect(response.body).toEqual(mockAdminConsoleData);
});
it('PATCH /configs/admin-console', async () => {
const livePreviewChecked = !mockAdminConsoleData.livePreviewChecked;
const response = await roleRequester
const signInExperienceCustomized = !mockAdminConsoleData.signInExperienceCustomized;
const response = await routeRequester
.patch('/configs/admin-console')
.send({ livePreviewChecked });
.send({ signInExperienceCustomized });
expect(response.status).toEqual(200);
expect(response.body).toEqual({ ...mockAdminConsoleData, livePreviewChecked });
expect(response.body).toEqual({
...mockAdminConsoleData,
signInExperienceCustomized,
});
});
});

View file

@ -3,14 +3,7 @@ import { type AdminConsoleData } from '@logto/schemas';
import { getAdminConsoleConfig, updateAdminConsoleConfig } from '#src/api/index.js';
const defaultAdminConsoleConfig: AdminConsoleData = {
livePreviewChecked: false,
applicationCreated: false,
signInExperienceCustomized: false,
passwordlessConfigured: false,
furtherReadingsChecked: false,
roleCreated: false,
communityChecked: false,
m2mApplicationCreated: false,
};
describe('admin console sign-in experience', () => {
@ -22,8 +15,6 @@ describe('admin console sign-in experience', () => {
it('should update admin console config successfully', async () => {
const newAdminConsoleConfig = {
m2mApplicationCreated: true,
passwordlessConfigured: true,
signInExperienceCustomized: true,
};

View file

@ -0,0 +1,100 @@
import type { DatabaseTransactionConnection } from 'slonik';
import { sql } from 'slonik';
import type { AlterationScript } from '../lib/types/alteration.js';
const adminConsoleConfigKey = 'adminConsole';
type OldAdminConsoleData = {
livePreviewChecked: boolean;
applicationCreated: boolean;
signInExperienceCustomized: boolean;
passwordlessConfigured: boolean;
furtherReadingsChecked: boolean;
roleCreated: boolean;
communityChecked: boolean;
m2mApplicationCreated: boolean;
} & Record<string, unknown>;
type OldLogtoAdminConsoleConfig = {
tenantId: string;
value: OldAdminConsoleData;
};
type NewAdminConsoleData = {
signInExperienceCustomized: boolean;
} & Record<string, unknown>;
type NewLogtoAdminConsoleConfig = {
tenantId: string;
value: NewAdminConsoleData;
};
const alterAdminConsoleData = async (
logtoConfig: OldLogtoAdminConsoleConfig,
pool: DatabaseTransactionConnection
) => {
const { tenantId, value: oldAdminConsoleConfig } = logtoConfig;
const {
livePreviewChecked,
applicationCreated,
passwordlessConfigured,
communityChecked,
furtherReadingsChecked,
roleCreated,
m2mApplicationCreated,
...others
} = oldAdminConsoleConfig;
const newAdminConsoleData: NewAdminConsoleData = {
...others,
};
await pool.query(
sql`update logto_configs set value = ${JSON.stringify(
newAdminConsoleData
)} where tenant_id = ${tenantId} and key = ${adminConsoleConfigKey}`
);
};
const rollbackAdminConsoleData = async (
logtoConfig: NewLogtoAdminConsoleConfig,
pool: DatabaseTransactionConnection
) => {
const { tenantId, value: newAdminConsoleConfig } = logtoConfig;
const oldAdminConsoleData: OldAdminConsoleData = {
...newAdminConsoleConfig,
livePreviewChecked: false,
applicationCreated: false,
passwordlessConfigured: false,
communityChecked: false,
furtherReadingsChecked: false,
roleCreated: false,
m2mApplicationCreated: false,
};
await pool.query(
sql`update logto_configs set value = ${JSON.stringify(
oldAdminConsoleData
)} where tenant_id = ${tenantId} and key = ${adminConsoleConfigKey}`
);
};
const alteration: AlterationScript = {
up: async (pool) => {
const rows = await pool.many<OldLogtoAdminConsoleConfig>(
sql`select * from logto_configs where key = ${adminConsoleConfigKey}`
);
await Promise.all(rows.map(async (row) => alterAdminConsoleData(row, pool)));
},
down: async (pool) => {
const rows = await pool.many<NewLogtoAdminConsoleConfig>(
sql`select * from logto_configs where key = ${adminConsoleConfigKey}`
);
await Promise.all(rows.map(async (row) => rollbackAdminConsoleData(row, pool)));
},
};
export default alteration;

View file

@ -15,14 +15,7 @@ export const createDefaultAdminConsoleConfig = (
tenantId: forTenantId,
key: LogtoTenantConfigKey.AdminConsole,
value: {
livePreviewChecked: false,
applicationCreated: false,
signInExperienceCustomized: false,
passwordlessConfigured: false,
furtherReadingsChecked: false,
roleCreated: false,
communityChecked: false,
m2mApplicationCreated: false,
},
} satisfies CreateLogtoConfig);

View file

@ -21,15 +21,7 @@ export const logtoOidcConfigGuard: Readonly<{
/* --- Logto tenant configs --- */
export const adminConsoleDataGuard = z.object({
// Get started challenges
livePreviewChecked: z.boolean(),
applicationCreated: z.boolean(),
signInExperienceCustomized: z.boolean(),
passwordlessConfigured: z.boolean(),
communityChecked: z.boolean(),
furtherReadingsChecked: z.boolean(),
roleCreated: z.boolean(),
m2mApplicationCreated: z.boolean(),
});
export type AdminConsoleData = z.infer<typeof adminConsoleDataGuard>;