Skip to content

Commit 480693a

Browse files
authored
feat(desktop): extract license inactive error handling to middleware (#6582)
* feat(desktop): extract license inactive error handling to middleware * add 40302 * remove licenseCheckEnabled feature and related code
1 parent 649f2e9 commit 480693a

File tree

20 files changed

+133
-160
lines changed

20 files changed

+133
-160
lines changed

frontend/desktop/data/config.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ common:
1919
apiEnabled: false
2020
rechargeEnabled: false
2121
cfSiteKey: ""
22-
licenseCheckEnabled: false
2322
database:
2423
mongodbURI: "thisismongodburi"
2524
globalCockroachdbURI: "thisisglobalcockroachdburi"

frontend/desktop/public/locales/en/common.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,6 @@
172172
"launch_various_third-party_applications_with_one_click": "Launch various third-party applications with one click",
173173
"legal_person": "Legal Representative",
174174
"license_buy": "License Buy",
175-
"license_required": "License required, please contact administrator",
176175
"link": "link",
177176
"link_to_workorder": "Submit a Ticket",
178177
"loading": "Loading",

frontend/desktop/public/locales/en/error.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"INTERNAL_SERVER_ERROR": "Internal server error",
88
"INSUFFICENT_BALANCE": "Insufficient balance",
99
"ACCOUNT_NOT_FOUND": "Account not found",
10-
"MERGET_USER_INSUFFICENT_BALANCE":"Insufficient balance in the merged account",
10+
"MERGET_USER_INSUFFICENT_BALANCE": "Insufficient balance in the merged account",
1111
"USER_CR_NOT_FOUND": "User CR not found",
1212
"OAUTHPROVIDER_NOT_FOUND": "OAuth provider not found",
1313
"PRIVATE_WORKSPACE_NOT_FOUND": "Private workspace not found",
@@ -19,5 +19,7 @@
1919
"REMAIN_TEMPLATE": "Remaining templates in current region",
2020
"REMAIN_OBJECT_STORAGE": "Remaining object storage in current region",
2121
"REMAIN_DATABASE": "Remaining databases in current region",
22-
"KUBECONFIG_NOT_FOUND": "Kubeconfig not found"
22+
"KUBECONFIG_NOT_FOUND": "Kubeconfig not found",
23+
"LICENSE_INACTIVE": "This cluster is not activated or has no valid license. Cannot create workspace/user. Please upload/activate a license in License Management and try again.",
24+
"LICENSE_USER_LIMIT_EXCEEDED": "The user limit for the current license has been reached. Cannot create new users/workspaces. Please log in as Admin and upload a license with a higher user quota in License Management, then try again."
2325
}

frontend/desktop/public/locales/zh/common.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,6 @@
167167
"launch_various_third-party_applications_with_one_click": "一键启动各种第三方应用",
168168
"legal_person": "法定代表人",
169169
"license_buy": "License 购买",
170-
"license_required": "缺少 license,请联系管理员",
171170
"link": "链接",
172171
"link_to_workorder": "提交工单",
173172
"loading": "加载中",

frontend/desktop/public/locales/zh/error.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"RESULT_SUCCESS": "响应成功",
77
"INTERNAL_SERVER_ERROR": "内部服务器错误",
88
"INSUFFICENT_BALANCE": "余额不足",
9-
"MERGET_USER_INSUFFICENT_BALANCE": "被合并的账户余额不足",
9+
"MERGET_USER_INSUFFICENT_BALANCE": "被合并的账户余额不足",
1010
"ACCOUNT_NOT_FOUND": "未找到账户",
1111
"USER_CR_NOT_FOUND": "未找到用户CR",
1212
"OAUTHPROVIDER_NOT_FOUND": "未找到OAuth提供程序",
@@ -19,5 +19,7 @@
1919
"REMAIN_TEMPLATE": "当前可用区残留模板",
2020
"REMAIN_OBJECT_STORAGE": "当前可用区残留对象存储",
2121
"REMAIN_DATABASE": "当前可用区残留数据库",
22-
"KUBECONFIG_NOT_FOUND": "未找到Kubeconfig"
22+
"KUBECONFIG_NOT_FOUND": "未找到Kubeconfig",
23+
"LICENSE_INACTIVE": "当前集群尚未激活或未绑定有效的 License,无法创建空间/用户。请使用 Admin 账号登录,进入【License 管理】页面上传/激活 License 后重试。",
24+
"LICENSE_USER_LIMIT_EXCEEDED": "当前 License 的用户数量已达上限,无法创建新用户/空间。请使用 Admin 账号登录,进入【License 管理】页面上传更大额度的 License 后重试。"
2325
}

frontend/desktop/src/api/platform.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import {
99
TNotification
1010
} from '@/types';
1111
import { AdClickData } from '@/types/adClick';
12-
import { LicenseCheckResponse } from '@/types/license';
1312
import { UserTask } from '@/types/task';
1413

1514
/**
@@ -120,6 +119,3 @@ export const getRunningApps = () => {
120119
}>
121120
>('/api/desktop/getRunningApps');
122121
};
123-
124-
export const checkLicense = () =>
125-
request.get<any, ApiResp<LicenseCheckResponse>>('/api/license/check');

frontend/desktop/src/components/AppDock/index.tsx

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@ import { MoreAppsContext } from '@/pages/index';
22
import useAppStore, { AppInfo } from '@/stores/app';
33
import { useConfigStore } from '@/stores/config';
44
import { useDesktopConfigStore } from '@/stores/desktopConfig';
5-
import { useLicenseCheck } from '@/hooks/useLicenseCheck';
6-
import useSessionStore from '@/stores/session';
75
import { APPTYPE, TApp } from '@/types';
86
import { I18nCommonKey } from '@/types/i18next';
97
import { Box, Center, Flex, Image, useBreakpointValue } from '@chakra-ui/react';
@@ -193,14 +191,10 @@ export default function AppDock() {
193191
findAppInfoById,
194192
updateOpenedAppInfo
195193
} = useAppStore();
196-
const { layoutConfig, commonConfig } = useConfigStore();
194+
const { layoutConfig } = useConfigStore();
197195
const logo = layoutConfig?.logo;
198-
const { isUserLogin } = useSessionStore();
199196
const moreAppsContent = useContext(MoreAppsContext);
200197
const { isNavbarVisible, toggleNavbarVisibility, getTransitionValue } = useDesktopConfigStore();
201-
const { hasLicense } = useLicenseCheck({
202-
enabled: isUserLogin() && !!commonConfig?.licenseCheckEnabled
203-
});
204198
const [isMouseOverDock, setIsMouseOverDock] = useState(false);
205199
const timeoutRef = useRef<number | null>(null);
206200
const isSmallScreen = useBreakpointValue({ base: true, sm: false });
@@ -264,19 +258,6 @@ export default function AppDock() {
264258
return;
265259
}
266260

267-
if (commonConfig?.licenseCheckEnabled && hasLicense === false && item.key !== 'user-license') {
268-
message({
269-
title: t('license_required'),
270-
status: 'warning',
271-
isClosable: true
272-
});
273-
const licenseApp = apps.find((app) => app.key === 'user-license');
274-
if (licenseApp) {
275-
openApp(licenseApp);
276-
}
277-
return;
278-
}
279-
280261
if (item.pid === currentAppPid && item.size !== 'minimize') {
281262
updateOpenedAppInfo({
282263
...item,

frontend/desktop/src/components/desktop_content/apps.tsx

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import useAppStore from '@/stores/app';
22
import { useConfigStore } from '@/stores/config';
3-
import { useLicenseCheck } from '@/hooks/useLicenseCheck';
43
import useSessionStore from '@/stores/session';
54
import { TApp, displayType } from '@/types';
65
import {
@@ -513,11 +512,7 @@ export default function Apps() {
513512
const { message } = useMessage();
514513
const { installedApps, openApp, openDesktopApp } = useAppStore();
515514
const { appDisplayConfigs, updateAppDisplayType } = useAppDisplayConfigStore();
516-
const { layoutConfig, commonConfig } = useConfigStore();
517-
const { isUserLogin } = useSessionStore();
518-
const { hasLicense } = useLicenseCheck({
519-
enabled: isUserLogin() && !!commonConfig?.licenseCheckEnabled
520-
});
515+
const { layoutConfig } = useConfigStore();
521516
const [draggedFromFolder, setDraggedFromFolder] = useState(false);
522517
const [isFolderOpen, setIsFolderOpen] = useState(false);
523518

@@ -608,20 +603,6 @@ export default function Apps() {
608603
const { isDriverActive } = useGuideModalStore();
609604

610605
const handleAppClick = (e: MouseEvent<HTMLDivElement>, item: TApp) => {
611-
if (commonConfig?.licenseCheckEnabled && hasLicense === false && item.key !== 'user-license') {
612-
message({
613-
title: t('license_required'),
614-
status: 'warning',
615-
isClosable: true
616-
});
617-
const licenseApp = installedApps.find((app) => app.key === 'user-license');
618-
if (licenseApp) {
619-
closeFolder();
620-
openApp(licenseApp);
621-
}
622-
return;
623-
}
624-
625606
console.log(item, 'item', isDriverActive);
626607
if (isDriverActive) {
627608
const guidedElements = [

frontend/desktop/src/components/team/CreateTeam.tsx

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@ import { useCustomToast } from '@/hooks/useCustomToast';
1717
import { ApiResp } from '@/types';
1818
import { useTranslation } from 'next-i18next';
1919
import { track } from '@sealos/gtm';
20+
import {
21+
LICENSE_INACTIVE_CODE,
22+
LICENSE_USER_LIMIT_EXCEEDED_CODE
23+
} from '@/services/backend/middleware/error';
2024

2125
export default function CreateTeam({ isOpen, onClose }: { isOpen: boolean; onClose: () => void }) {
2226
const { t } = useTranslation();
@@ -36,7 +40,23 @@ export default function CreateTeam({ isOpen, onClose }: { isOpen: boolean; onClo
3640
onClose();
3741
}
3842
},
39-
onError(error) {
43+
onError(error: any) {
44+
if (error?.code === LICENSE_INACTIVE_CODE) {
45+
return toast({
46+
description: t('error:LICENSE_INACTIVE'),
47+
status: 'error',
48+
duration: null,
49+
isClosable: true
50+
});
51+
}
52+
if (error?.code === LICENSE_USER_LIMIT_EXCEEDED_CODE) {
53+
return toast({
54+
description: t('error:LICENSE_USER_LIMIT_EXCEEDED'),
55+
status: 'error',
56+
duration: null,
57+
isClosable: true
58+
});
59+
}
4060
toast({ title: (error as ApiResp).message });
4161
}
4262
});

frontend/desktop/src/components/v2/Workspace.tsx

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@ import { SwitchRegionType } from '@/constants/account';
3131
import { I18nCloudProvidersKey } from '@/types/i18next';
3232
import { ChevronDownIcon } from '@chakra-ui/icons';
3333
import { useGuideModalStore } from '@/stores/guideModal';
34+
import {
35+
LICENSE_INACTIVE_CODE,
36+
LICENSE_USER_LIMIT_EXCEEDED_CODE
37+
} from '@/services/backend/middleware/error';
3438

3539
export default function Workspace() {
3640
const { t } = useTranslation();
@@ -92,8 +96,23 @@ export default function Workspace() {
9296
}
9397
await sessionConfig(initRegionTokenResult.data);
9498
await router.replace('/');
95-
} catch (error) {
96-
console.error(error);
99+
} catch (error: any) {
100+
if (error?.code === LICENSE_INACTIVE_CODE) {
101+
return toast({
102+
description: t('error:LICENSE_INACTIVE'),
103+
status: 'error',
104+
duration: null,
105+
isClosable: true
106+
});
107+
}
108+
if (error?.code === LICENSE_USER_LIMIT_EXCEEDED_CODE) {
109+
return toast({
110+
description: t('error:LICENSE_USER_LIMIT_EXCEEDED'),
111+
status: 'error',
112+
duration: null,
113+
isClosable: true
114+
});
115+
}
97116
toast({
98117
status: 'error',
99118
//@ts-ignore

0 commit comments

Comments
 (0)