Skip to content

Commit

Permalink
fix(desktop): fix operationRequest (#5161)
Browse files Browse the repository at this point in the history
  • Loading branch information
xudaotutou authored Oct 21, 2024
1 parent 2e45449 commit e2cf303
Show file tree
Hide file tree
Showing 11 changed files with 70 additions and 66 deletions.
1 change: 1 addition & 0 deletions frontend/desktop/public/locales/en/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@
"merge_account_tips2": "The account you are trying to bind has been used by another user. You can choose to merge accounts to manage your information and settings in a unified way. After the merge is completed, your private workspace may be converted into a regular workspace. Do you want to merge accounts now?",
"merge_account_title": "Account has been bound",
"message_center": "Message Center",
"modify_member": "Modify Member",
"monitor": "Monitor",
"more_apps": "More Apps",
"name": "Name",
Expand Down
1 change: 1 addition & 0 deletions frontend/desktop/public/locales/zh/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@
"merge_account_tips2": "您尝试绑定的账号已被其他用户使用。您可以选择合并账户,以统一管理您的信息和设置。 在合并完成后,个人空间有可能转化为普通的工作空间,是否现在合并账户?",
"merge_account_title": "账户已被绑定",
"message_center": "消息中心",
"modify_member": "修改权限",
"monitor": "监控",
"more_apps": "更多应用",
"name": "姓名",
Expand Down
25 changes: 12 additions & 13 deletions frontend/desktop/src/components/team/DissolveTeam.tsx
Original file line number Diff line number Diff line change
@@ -1,26 +1,25 @@
import { deleteTeamRequest } from '@/api/namespace';
import { useCustomToast } from '@/hooks/useCustomToast';
import useSessionStore from '@/stores/session';
import { ApiResp } from '@/types';
import {
Button,
Image,
ButtonProps,
Modal,
ModalBody,
ModalCloseButton,
ModalContent,
ModalHeader,
ModalOverlay,
useDisclosure,
Text,
Spinner,
ButtonProps
Text,
useDisclosure
} from '@chakra-ui/react';
import CustomInput from './Input';
import { useState } from 'react';
import { useCustomToast } from '@/hooks/useCustomToast';
import { DeleteIcon } from '@sealos/ui';
import { useMutation, useQueryClient } from '@tanstack/react-query';
import { deleteTeamRequest } from '@/api/namespace';
import useSessionStore from '@/stores/session';
import { ApiResp } from '@/types';
import { useTranslation } from 'next-i18next';
import { DeleteIcon } from '@sealos/ui';
import { useState } from 'react';
import CustomInput from './Input';
export default function DissolveTeam({
nsid,
ns_uid,
Expand Down Expand Up @@ -95,7 +94,7 @@ export default function DissolveTeam({
>
<ModalCloseButton right={'24px'} top="16px" p="0" />
<ModalHeader bg={'white'} border={'none'} p="0">
Warning
{t('common:warning')}
</ModalHeader>
{mutation.isLoading ? (
<Spinner mx="auto" />
Expand All @@ -108,7 +107,7 @@ export default function DissolveTeam({
e.preventDefault();
setTeamName(e.target.value);
}}
placeholder={t('common:name_of_team') || ''}
placeholder={t('common:team') || '' + ' ID'}
value={teamName}
/>
<Button
Expand Down
30 changes: 15 additions & 15 deletions frontend/desktop/src/components/team/ModifyRole.tsx
Original file line number Diff line number Diff line change
@@ -1,28 +1,28 @@
import { modifyRoleRequest } from '@/api/namespace';
import { useCustomToast } from '@/hooks/useCustomToast';
import { ApiResp } from '@/types';
import { ROLE_LIST, UserRole } from '@/types/team';
import {
Button,
ButtonProps,
Menu,
MenuButton,
MenuItem,
MenuList,
Modal,
ModalBody,
ModalCloseButton,
ModalContent,
ModalHeader,
ModalOverlay,
useDisclosure,
Menu,
MenuButton,
MenuList,
MenuItem,
Text,
Spinner,
ButtonProps
Text,
useDisclosure
} from '@chakra-ui/react';
import { useState } from 'react';
import { ROLE_LIST, UserRole } from '@/types/team';
import { ExpanMoreIcon } from '@sealos/ui';
import { useMutation, useQueryClient } from '@tanstack/react-query';
import { modifyRoleRequest } from '@/api/namespace';
import { useCustomToast } from '@/hooks/useCustomToast';
import { ApiResp } from '@/types';
import { useTranslation } from 'next-i18next';
import { ExpanMoreIcon } from '@sealos/ui';
import { useState } from 'react';
export default function ModifyRole({
ns_uid,
k8s_username,
Expand All @@ -39,7 +39,7 @@ export default function ModifyRole({
}) {
const { onOpen, isOpen, onClose } = useDisclosure();
const [role, setRole] = useState(currentRole);
const { t } = useTranslation();
const { t } = useTranslation(['common']);
const queryClient = useQueryClient();
const { toast } = useCustomToast({ status: 'error' });
const mutation = useMutation({
Expand Down Expand Up @@ -83,7 +83,7 @@ export default function ModifyRole({
>
<ModalCloseButton right={'24px'} top="24px" p="0" />
<ModalHeader bg={'white'} border={'none'} p="0">
modify member
{t('modify_member')}
</ModalHeader>
{mutation.isLoading ? (
<Spinner mx="auto" />
Expand Down
2 changes: 2 additions & 0 deletions frontend/desktop/src/constants/account.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,5 @@ export const GUIDE_DESKTOP_INDEX_KEY = 'frontend.guide.desktop.index';
export const LicenseFrontendKey = 'cloud.sealos.io/license-frontend';

export const templateDeployKey = 'cloud.sealos.io/deploy-on-sealos';

export const userSystemNamespace = 'user-system' as const;
31 changes: 12 additions & 19 deletions frontend/desktop/src/pages/WorkspaceInvite.tsx
Original file line number Diff line number Diff line change
@@ -1,22 +1,17 @@
import type { NextPage } from 'next';
import { useRouter } from 'next/router';
import useSessionStore from '@/stores/session';
import { Button, Flex, HStack, Image, Spinner, Text, VStack } from '@chakra-ui/react';
import { isString } from 'lodash';
import { dehydrate, QueryClient, useMutation, useQuery } from '@tanstack/react-query';
import {
getInviteCodeInfoRequest,
nsListRequest,
reciveAction,
verifyInviteCodeRequest
} from '@/api/namespace';
import { getInviteCodeInfoRequest, reciveAction, verifyInviteCodeRequest } from '@/api/namespace';
import useCallbackStore from '@/stores/callback';
import { useEffect } from 'react';
import { useTranslation } from 'next-i18next';
import { useConfigStore } from '@/stores/config';
import useSessionStore from '@/stores/session';
import { ROLE_LIST } from '@/types/team';
import { compareFirstLanguages } from '@/utils/tools';
import { Button, Flex, Image, Text, VStack } from '@chakra-ui/react';
import { dehydrate, QueryClient, useMutation, useQuery } from '@tanstack/react-query';
import { isString } from 'lodash';
import type { NextPage } from 'next';
import { useTranslation } from 'next-i18next';
import { serverSideTranslations } from 'next-i18next/serverSideTranslations';
import { useConfigStore } from '@/stores/config';
import { useRouter } from 'next/router';
import { useEffect } from 'react';

const Callback: NextPage = () => {
const router = useRouter();
Expand Down Expand Up @@ -70,17 +65,16 @@ const Callback: NextPage = () => {
return () => clearTimeout(tag);
}
}, [statusCode, isValid, router]);
const acceptHandle = async () => {
const acceptHandle = async () =>
verifyMutation
.mutateAsync({
code: inviteCode as string,
action: reciveAction.Accepte
})
.then(() => {
.finally(() => {
reset();
return;
});
};
const cancelHandle = () => {
if (!isValid) return;
reset();
Expand Down Expand Up @@ -113,7 +107,6 @@ const Callback: NextPage = () => {
color={'white'}
gap={'8px'}
>
{' '}
<Image boxSize={'34px'} borderRadius="full" src={logo} alt="logo" />
<Text fontWeight={700} fontSize={'24px'}>
Sealos
Expand Down
10 changes: 5 additions & 5 deletions frontend/desktop/src/pages/api/auth/namespace/abdicate.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { verifyAccessToken } from '@/services/backend/auth';
import { prisma } from '@/services/backend/db/init';
import { jsonRes } from '@/services/backend/response';
import { modifyWorkspaceRole } from '@/services/backend/team';
import { UserRole } from '@/types/team';
import { NextApiRequest, NextApiResponse } from 'next';
import { prisma } from '@/services/backend/db/init';
import { retrySerially } from '@/utils/tools';
import { validate as uuidValidate } from 'uuid';
import { NextApiRequest, NextApiResponse } from 'next';
import { JoinStatus, Role } from 'prisma/region/generated/client';
import { verifyAccessToken } from '@/services/backend/auth';
import { validate as uuidValidate } from 'uuid';

export default async function handler(req: NextApiRequest, res: NextApiResponse) {
try {
Expand Down Expand Up @@ -45,7 +45,7 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
// modify K8S
await modifyWorkspaceRole({
action: 'Change',
pre_k8s_username: payload.userCrUid,
pre_k8s_username: payload.userCrName,
k8s_username: target.userCr.crName,
role: UserRole.Owner,
workspaceId: target.workspace.id
Expand Down
1 change: 1 addition & 0 deletions frontend/desktop/src/services/backend/svc/mergeUser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export const mergeUserSvc =
(userUid: string, mergeUserUid: string) => async (res: NextApiResponse) => {
const user = await globalPrisma.user.findUnique({
where: {
status: UserStatus.NORMAL_USER,
uid: userUid
},
include: {
Expand Down
11 changes: 8 additions & 3 deletions frontend/desktop/src/types/team.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { userSystemNamespace } from '@/constants/account';
import { UUID, createHash } from 'crypto';
import * as yaml from 'js-yaml';
export type RoleAction = 'Grant' | 'Deprive' | 'Change' | 'Create' | 'Modify';
Expand All @@ -22,9 +23,10 @@ type CRD = {
kind: 'Operationrequest';
metadata: {
name: string;
namespace: string;
namespace: typeof userSystemNamespace;
};
spec: {
namespace: string;
user: string;
action: 'Deprive' | 'Grant' | 'Update';
role: RoleType;
Expand All @@ -38,9 +40,10 @@ export const generateRequestCrd = ({
kind: 'Operationrequest',
metadata: {
name: props.name,
namespace: props.namespace
namespace: userSystemNamespace
},
spec: {
namespace: props.namespace,
user: props.user,
action: props.action,
role: props.role
Expand All @@ -58,6 +61,7 @@ type DeleteCRD = {
kind: 'DeleteRequest';
metadata: {
name: string;
namespace: typeof userSystemNamespace;
};
spec: {
user: string;
Expand All @@ -71,7 +75,8 @@ export const deleteRequestCrd = (props: DeleteCRD['spec']) => {
apiVersion: 'user.sealos.io/v1',
kind: 'DeleteRequest',
metadata: {
name
name,
namespace: userSystemNamespace
},
spec: {
user: props.user
Expand Down
21 changes: 11 additions & 10 deletions frontend/providers/costcenter/public/locales/en/applist.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
{
"TERMINAL": "TERMINAL",
"JOB":"JOB",
"OTHER": "OTHER",
"OBJECT-STORAGE": "OBJECT-STORAGE",
"CLOUD-VM":"CLOUD-VM",
"DB": "DATABASE",
"APP": "APP",
"TERMINAL": "Terminal",
"JOB":"CronJob",
"OTHER": "Other",
"OBJECT-STORAGE": "Object Storage",
"CLOUD-VM":"Cloud Server",
"DB": "Database",
"APP": "APP Launchpad",
"All APP": "ALL APP",
"APP-STORE": "APP-STORE",
"DB-BACKUP": "DB-BACKUP",
"all_app_type": "ALL APP TYPE"
"APP-STORE": "APP Store",
"DB-BACKUP": "Database Backup",
"all_app_type": "ALL APP TYPE",
"DEV-BOX": "Devbox"
}
3 changes: 2 additions & 1 deletion frontend/providers/costcenter/public/locales/zh/applist.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,6 @@
"All APP": "所有应用",
"APP-STORE": "应用商店",
"DB-BACKUP":"数据库备份",
"all_app_type": "所有应用类型"
"all_app_type": "所有应用类型",
"DEV-BOX": "Devbox"
}

0 comments on commit e2cf303

Please sign in to comment.