Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[fix]: supply allowCreateProject on CreateProjectButton #31

Merged
merged 9 commits into from
Nov 10, 2023
1 change: 1 addition & 0 deletions packages/base/src/page/Project/List/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ const ProjectList: React.FC = () => {
const dispatch = useDispatch();
const { isAdmin, isProjectManager } = useCurrentUser();
const { updateUserInfo } = useUserInfo();

const allowOperateProject = useCallback(
(projectName: string) => isAdmin || isProjectManager(projectName),
[isAdmin, isProjectManager]
Expand Down
17 changes: 14 additions & 3 deletions packages/base/src/page/Project/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,29 @@ import { ModalName } from '../../data/ModalName';
import ProjectManageModal from './Modal';
import { ProjectListStyledWrapper } from './style';
import { useCurrentUser } from '@actiontech/shared/lib/global';
import { useMemo } from 'react';
import { OpPermissionTypeUid } from '@actiontech/shared/lib/enum';

const Project: React.FC = () => {
const { t } = useTranslation();
const { isAdmin } = useCurrentUser();

const { isAdmin, managementPermissions } = useCurrentUser();
const dispatch = useDispatch();

const allowCreateProject = useMemo(() => {
return (
isAdmin ||
managementPermissions.some(
(v) => OpPermissionTypeUid['create_project'] === (v?.uid ?? '')
)
);
}, [isAdmin, managementPermissions]);

const refreshTable = () => {
EventEmitter.emit(EmitterKey.DMS_Refresh_Project_List);
};

const createProject = () => {
if (!allowCreateProject) return;
dispatch(
updateProjectModalStatus({
modalName: ModalName.DMS_Add_Project,
Expand All @@ -41,7 +52,7 @@ const Project: React.FC = () => {
</Space>
}
extra={
<EmptyBox if={isAdmin}>
<EmptyBox if={allowCreateProject}>
<BasicButton type="primary" onClick={createProject}>
{t('dmsProject.createProject.modalTitle')}
</BasicButton>
Expand Down
10 changes: 6 additions & 4 deletions packages/base/src/store/user/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,18 @@ import {
SystemRole
} from '@actiontech/shared/lib/enum';
import { createSlice, PayloadAction } from '@reduxjs/toolkit';
import { IManagementPermissionResV1 } from '@actiontech/shared/lib/types/common.type';
import { IUserBindProject } from '@actiontech/shared/lib/api/base/service/common';
import {
IUidWithName,
IUserBindProject
} from '@actiontech/shared/lib/api/base/service/common';

type UserReduxState = {
username: string;
role: SystemRole | '';
token: string;
theme: SupportTheme;
bindProjects: Array<IUserBindProject>;
managementPermissions: IManagementPermissionResV1[];
managementPermissions: IUidWithName[];
uid: string;
useInfoFetched: boolean;
};
Expand Down Expand Up @@ -72,7 +74,7 @@ const user = createSlice({
state,
{
payload: { managementPermissions }
}: PayloadAction<{ managementPermissions: IManagementPermissionResV1[] }>
}: PayloadAction<{ managementPermissions: IUidWithName[] }>
) => {
state.managementPermissions = managementPermissions;
},
Expand Down
16 changes: 16 additions & 0 deletions packages/shared/lib/enum/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,19 @@ export enum StorageKey {
DMS_Project_Catch = 'DMS_Project_Catch',
USER_UID = 'DMS_USER_UID'
}

/**
* 后端暂时无法在swagger中暴露OpPermissionType的映射,但权限对应的uid一般不会变化,因此前端先保存一份。
*/
export enum OpPermissionTypeUid {
'create_project' = '700001', // 创建项目;创建项目的用户自动拥有该项目管理权限 700001
'project_admin' = '700002', // 项目管理;拥有该权限的用户可以管理项目下的所有资源 700002
'create_workflow' = '700003', // 创建/编辑工单;拥有该权限的用户可以创建/编辑工单 700003
'audit_workflow' = '700004', // 审核/驳回工单;拥有该权限的用户可以审核/驳回工单 700004
'auth_db_service_data' = '700005', // 授权数据源数据权限;拥有该权限的用户可以授权数据源数据权限 700005
'execute_workflow' = '700006', // 上线工单;拥有该权限的用户可以上线工单 700006
'view_others_workflow' = '700007', // 查看其他工单权限 700007
'view_other_audit_plan' = '700008', // 查看其他扫描任务权限 700008
'save_audit_plan' = '700009', // 创建扫描任务权限;拥有该权限的用户可以创建/更新扫描任务 700009
'sql_query' = '700010' //SQL查询;SQL查询权限 700010
}
9 changes: 4 additions & 5 deletions packages/shared/lib/global/useCurrentUser/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@ import useCurrentUser from '.';
import { renderHook } from '@testing-library/react-hooks';
import { useSelector } from 'react-redux';
import { SupportTheme, SystemRole } from '../../enum';
import { IManagementPermissionResV1 } from '../../types/common.type';
siriuswh0327 marked this conversation as resolved.
Show resolved Hide resolved
import { useDispatch } from 'react-redux';
import { IUserBindProject } from '../../api/base/service/common';
import { IUidWithName, IUserBindProject } from '../../api/base/service/common';

export const mockBindProjects: IUserBindProject[] = [
{
Expand All @@ -19,10 +18,10 @@ export const mockBindProjects: IUserBindProject[] = [
}
];

export const mockManagementPermissions: IManagementPermissionResV1[] = [
export const mockManagementPermissions: IUidWithName[] = [
{
code: 1,
desc: '创建项目'
uid: '700001',
name: '创建项目'
}
];

Expand Down
3 changes: 1 addition & 2 deletions packages/shared/lib/global/useUserInfo/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,9 @@ const useUserInfo = () => {
})
);

//todo
dispatch(
updateManagementPermissions({
managementPermissions: []
managementPermissions: data?.op_permissions ?? []
})
);

Expand Down
4 changes: 0 additions & 4 deletions packages/sqle/src/data/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,6 @@ export enum LoginTypeEnum {
'sqle' = 'sqle'
}

export enum ManagementPermissionsEnum {
Create_Project = 1
}

export const SQLE_INSTANCE_SOURCE_NAME = 'SQLE';

export const SQLE_REDIRECT_KEY_PARAMS_NAME = 'target';
Expand Down