Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions packages/global/support/user/account/cancellation/type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@ export const TeamAccountCancellationStatusSchema = AccountCancellationStatusSche
]);
export type TeamAccountCancellationStatus = z.infer<typeof TeamAccountCancellationStatusSchema>;

export const AccountCancellationSummarySchema = z.object({
status: TeamAccountCancellationStatusSchema,
scheduledCancelAt: z.union([z.date(), z.iso.datetime({ offset: true })]).optional()
});
export type AccountCancellationSummary = z.infer<typeof AccountCancellationSummarySchema>;

export const AccountCancellationAllowedMethodSchema = z.enum(accountCancellationAllowedMethods);
export type AccountCancellationAllowedMethod = z.infer<
typeof AccountCancellationAllowedMethodSchema
Expand Down
2 changes: 2 additions & 0 deletions packages/global/support/user/type.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { AccountCancellationSummarySchema } from './account/cancellation/type';
import z from 'zod';
import { ObjectIdSchema } from '../../common/type/mongo';
import { LanguageSchema, type LangEnum } from '../../common/i18n/type';
Expand Down Expand Up @@ -38,6 +39,7 @@ export const UserSchema = z.object({
avatar: z.string().nullish(),
timezone: z.string(),
language: LanguageSchema.optional(),
accountCancellation: AccountCancellationSummarySchema.optional(),
team: TeamTmbItemSchema,
permission: z.instanceof(TeamPermission),
contact: z.string().nullish(),
Expand Down
8 changes: 7 additions & 1 deletion packages/service/support/user/controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import { ERROR_ENUM } from '@fastgpt/global/common/error/errorCode';
import { TeamPermission } from '@fastgpt/global/support/permission/user/controller';
import type { ClientSession } from '../../common/mongo';
import { getUserFallbackTeam } from './team/fallback';
import { getActiveAccountCancellationByUserId } from './account/cancellation/read';
import { formatTeamAccountCancellationSummary } from './account/cancellation/formatter';

export async function authUserExist({ userId, username }: { userId?: string; username?: string }) {
if (userId) {
Expand Down Expand Up @@ -54,6 +56,7 @@ export async function getUserDetail({
return Promise.reject(ERROR_ENUM.unAuthorization);
}

const accountCancellation = await getActiveAccountCancellationByUserId(String(user._id));
const permission = isRoot ? new TeamPermission({ isOwner: true }) : tmb.permission;
const team = {
...tmb,
Expand All @@ -69,6 +72,9 @@ export async function getUserDetail({
permission,
contact: user.contact,
language: user.language,
tags: user.tags
tags: user.tags,
...(accountCancellation
? { accountCancellation: formatTeamAccountCancellationSummary(accountCancellation) }
: {})
};
}
2 changes: 1 addition & 1 deletion pro
Submodule pro updated from e9b02b to 1ed762
2 changes: 1 addition & 1 deletion projects/app/src/components/Layout/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ const Layout = ({ children }: { children: JSX.Element }) => {
{!!userInfo && importantInforms.length > 0 && (
<ImportantInform informs={importantInforms} refetch={refetchUnRead} />
)}
<ResetExpiredPswModal />
{router.pathname !== '/account/cancel' && <ResetExpiredPswModal />}
<SupportBot />
</>
)}
Expand Down
20 changes: 15 additions & 5 deletions projects/app/src/components/support/activity/ActivityAdModal.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useCallback, useMemo } from 'react';
import React, { useCallback } from 'react';
import { useDisclosure } from '@chakra-ui/react';
import { useTranslation } from 'next-i18next';
import { getActivityAd } from '@/web/common/system/api';
Expand All @@ -17,6 +17,7 @@ import { useSystemStore } from '@/web/common/system/useSystemStore';
import { useLocalStorageState } from 'ahooks';
import { useRouter } from 'next/router';
import { useUserStore } from '@/web/support/user/useUserStore';
import { accountCancellationActiveStatuses } from '@fastgpt/global/support/user/account/cancellation/constants';

const CLOSED_AD_KEY = 'logout-activity-ad';
const CLOSED_AD_DURATION = 24 * 60 * 60 * 1000; // 24 hours
Expand All @@ -27,6 +28,15 @@ const ActivityAdModal = () => {
const { feConfigs } = useSystemStore();
const router = useRouter();
const { userInfo } = useUserStore();
const isCancellationRestricted =
!!userInfo &&
(accountCancellationActiveStatuses.includes(
userInfo.accountCancellation?.status as (typeof accountCancellationActiveStatuses)[number]
) ||
accountCancellationActiveStatuses.includes(
userInfo.team?.accountCancellation
?.status as (typeof accountCancellationActiveStatuses)[number]
));

// Check if ad was recently closed
const [closedData, setClosedData] = useLocalStorageState<string>(CLOSED_AD_KEY, {
Expand All @@ -35,7 +45,7 @@ const ActivityAdModal = () => {

const { data } = useRequest(
async () => {
if (!feConfigs?.isPlus || !userInfo) return;
if (!feConfigs?.isPlus || !userInfo || isCancellationRestricted) return;
return getActivityAd();
},
{
Expand Down Expand Up @@ -64,7 +74,7 @@ const ActivityAdModal = () => {
onOpen();
}
},
refreshDeps: [userInfo]
refreshDeps: [isCancellationRestricted, userInfo]
}
);

Expand All @@ -73,7 +83,7 @@ const ActivityAdModal = () => {
setClosedData(JSON.stringify({ timestamp: Date.now(), adId: data.id }));
}
onClose();
}, [data?.id, onClose, setClosedData]);
}, [data, onClose, setClosedData]);

const handleJoin = useCallback(() => {
if (data?.activityAdLink) {
Expand All @@ -84,7 +94,7 @@ const ActivityAdModal = () => {
window.open(data.activityAdLink, '_blank');
}
}
}, [data?.activityAdLink, handleClose, router]);
}, [data, handleClose, router]);

if (!data?.activityAdImage || !userInfo) {
return null;
Expand Down
3 changes: 2 additions & 1 deletion projects/app/src/web/support/user/loginRedirect/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ export const resolveLoginRedirectAfterLogin = async ({
lastTmbId?: string;
restoreWorkflowLocalDraft: RestoreWorkflowLocalDraft;
}) => {
const cancellationStatus = user.team?.accountCancellation?.status;
const cancellationStatus =
user.accountCancellation?.status ?? user.team?.accountCancellation?.status;
if (
accountCancellationActiveStatuses.includes(
cancellationStatus as (typeof accountCancellationActiveStatuses)[number]
Expand Down
48 changes: 48 additions & 0 deletions projects/app/test/web/support/user/loginRedirect.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,54 @@ describe('login redirect helpers', () => {
expect(restoreWorkflowLocalDraft).not.toHaveBeenCalled();
});

it('redirects a user with personal cancellation to the account cancellation page', async () => {
const route = await resolveLoginRedirectAfterLogin({
user: {
...user,
accountCancellation: {
status: 'pending'
}
} as UserType,
fallbackRoute: '/dashboard/agent',
restoreWorkflowLocalDraft: vi.fn()
});

expect(route).toBe('/account/cancel');
});

it('redirects a finalizing user with personal cancellation', async () => {
const route = await resolveLoginRedirectAfterLogin({
user: {
...user,
accountCancellation: {
status: 'finalizing'
}
} as UserType,
fallbackRoute: '/dashboard/agent',
restoreWorkflowLocalDraft: vi.fn()
});

expect(route).toBe('/account/cancel');
});

it('redirects a cancelling member without a team cancellation summary', async () => {
const route = await resolveLoginRedirectAfterLogin({
user: {
...user,
accountCancellation: {
status: 'pending'
},
team: {
...user.team
}
} as UserType,
fallbackRoute: '/dashboard/agent',
restoreWorkflowLocalDraft: vi.fn()
});

expect(route).toBe('/account/cancel');
});

afterEach(() => {
vi.useRealTimers();
});
Expand Down
Loading