Skip to content

Commit a5c1904

Browse files
authored
Merge pull request #694 from actiontech/fix/issue-2439
[fix](SqlManagement): SQL operations can be performed when the user is assignees
2 parents ce73ef0 + 7295af7 commit a5c1904

File tree

4 files changed

+163
-63
lines changed

4 files changed

+163
-63
lines changed

packages/sqle/src/page/SqlManagement/component/SQLEEIndex/__snapshots__/index.test.tsx.snap

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12962,7 +12962,7 @@ exports[`page/SqlManagement/SQLEEIndex render table with permissions 2`] = `
1296212962
style="width: 200px;"
1296312963
/>
1296412964
<col
12965-
style="width: 110px;"
12965+
style="width: 246px;"
1296612966
/>
1296712967
</colgroup>
1296812968
<tbody
@@ -14098,7 +14098,7 @@ exports[`page/SqlManagement/SQLEEIndex render table with permissions 3`] = `
1409814098
style="width: 200px;"
1409914099
/>
1410014100
<col
14101-
style="width: 110px;"
14101+
style="width: 246px;"
1410214102
/>
1410314103
</colgroup>
1410414104
<tbody

packages/sqle/src/page/SqlManagement/component/SQLEEIndex/actions.tsx

Lines changed: 77 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,14 @@ import { ModalName } from '../../../../data/ModalName';
33
import { ISqlManage } from '@actiontech/shared/lib/api/sqle/service/common';
44
import { SupportLanguage } from '@actiontech/shared/lib/enum';
55
import {
6-
ActiontechTableActionsWithPermissions,
76
PERMISSIONS,
8-
PermissionsConstantType,
9-
ActiontechTableToolbarActionWithPermissions
7+
PermissionsConstantType
108
} from '@actiontech/shared/lib/features';
119
import { ACTIONTECH_TABLE_ACTION_BUTTON_WIDTH } from '@actiontech/shared/lib/components/ActiontechTable/hooks/useTableAction';
10+
import {
11+
ActiontechTableActionsConfig,
12+
ActiontechTableToolbarActionMeta
13+
} from '@actiontech/shared';
1214

1315
export const SqlManagementRowAction = (
1416
openModal: (name: ModalName, row?: ISqlManage) => void,
@@ -19,19 +21,13 @@ export const SqlManagementRowAction = (
1921
checkActionPermission: (
2022
requiredPermission: PermissionsConstantType
2123
) => boolean,
22-
onPushToCoding: (batch: boolean, record?: ISqlManage) => void
23-
): ActiontechTableActionsWithPermissions<ISqlManage> => {
24+
onPushToCoding: (batch: boolean, record?: ISqlManage) => void,
25+
username: string
26+
): ActiontechTableActionsConfig<ISqlManage> => {
2427
const getWidth = () => {
25-
if (
26-
checkActionPermission(
27-
PERMISSIONS.ACTIONS.SQLE.SQL_MANAGEMENT.ACTION_LAYOUT
28-
)
29-
) {
30-
return language === SupportLanguage.enUS
31-
? 350
32-
: ACTIONTECH_TABLE_ACTION_BUTTON_WIDTH * 3;
33-
}
34-
return 110;
28+
return language === SupportLanguage.enUS
29+
? 350
30+
: ACTIONTECH_TABLE_ACTION_BUTTON_WIDTH * 3;
3531
};
3632

3733
return {
@@ -47,7 +43,15 @@ export const SqlManagementRowAction = (
4743
}
4844
};
4945
},
50-
permissions: PERMISSIONS.ACTIONS.SQLE.SQL_MANAGEMENT.ASSIGNMENT
46+
permissions: (record) => {
47+
return (
48+
(checkActionPermission(
49+
PERMISSIONS.ACTIONS.SQLE.SQL_MANAGEMENT.ASSIGNMENT
50+
) ||
51+
record?.assignees?.includes(username)) ??
52+
false
53+
);
54+
}
5155
},
5256
{
5357
text: t('sqlManagement.table.action.single.updateStatus.triggerText'),
@@ -59,7 +63,15 @@ export const SqlManagementRowAction = (
5963
}
6064
};
6165
},
62-
permissions: PERMISSIONS.ACTIONS.SQLE.SQL_MANAGEMENT.UPDATE_STATUS
66+
permissions: (record) => {
67+
return (
68+
(checkActionPermission(
69+
PERMISSIONS.ACTIONS.SQLE.SQL_MANAGEMENT.UPDATE_STATUS
70+
) ||
71+
record?.assignees?.includes(username)) ??
72+
false
73+
);
74+
}
6375
}
6476
],
6577
moreButtons: [
@@ -69,7 +81,15 @@ export const SqlManagementRowAction = (
6981
onClick: (record) => {
7082
openModal(ModalName.Change_SQL_Priority, record);
7183
},
72-
permissions: PERMISSIONS.ACTIONS.SQLE.SQL_MANAGEMENT.UPDATE_PRIORITY
84+
permissions: (record) => {
85+
return (
86+
(checkActionPermission(
87+
PERMISSIONS.ACTIONS.SQLE.SQL_MANAGEMENT.UPDATE_PRIORITY
88+
) ||
89+
record?.assignees?.includes(username)) ??
90+
false
91+
);
92+
}
7393
},
7494
{
7595
text: t('sqlManagement.table.action.analyze'),
@@ -84,22 +104,35 @@ export const SqlManagementRowAction = (
84104
onClick: (record) => {
85105
openCreateSqlManagementExceptionModal(record);
86106
},
87-
permissions:
88-
PERMISSIONS.ACTIONS.SQLE.SQL_MANAGEMENT.CREATE_SQL_EXCEPTION
107+
permissions: () =>
108+
checkActionPermission(
109+
PERMISSIONS.ACTIONS.SQLE.SQL_MANAGEMENT.CREATE_SQL_EXCEPTION
110+
)
89111
},
90112
{
91113
text: t('sqlManagement.table.action.createWhitelist'),
92114
key: 'create-whitelist',
93115
onClick: (record) => {
94116
onCreateWhitelist(record);
95117
},
96-
permissions: PERMISSIONS.ACTIONS.SQLE.SQL_MANAGEMENT.CREATE_WHITE_LIST
118+
permissions: () =>
119+
checkActionPermission(
120+
PERMISSIONS.ACTIONS.SQLE.SQL_MANAGEMENT.CREATE_WHITE_LIST
121+
)
97122
},
98123
{
99124
key: 'push-to-coding',
100125
text: t('sqlManagement.table.action.batch.pushToCoding'),
101126
onClick: (record) => onPushToCoding(false, record),
102-
permissions: PERMISSIONS.ACTIONS.SQLE.SQL_MANAGEMENT.PUSH_TO_CODING
127+
permissions: (record) => {
128+
return (
129+
(checkActionPermission(
130+
PERMISSIONS.ACTIONS.SQLE.SQL_MANAGEMENT.PUSH_TO_CODING
131+
) ||
132+
record?.assignees?.includes(username)) ??
133+
false
134+
);
135+
}
103136
}
104137
]
105138
};
@@ -116,8 +149,12 @@ export const SqlManagementTableToolbarActions = (
116149
isHighPriority: boolean,
117150
setAssigneeSelf: (value: boolean) => void,
118151
setIsHighPriority: (value: boolean) => void,
119-
onPushToCoding: (batch: boolean, record?: ISqlManage) => void
120-
): ActiontechTableToolbarActionWithPermissions => {
152+
onPushToCoding: (batch: boolean, record?: ISqlManage) => void,
153+
isCertainAssignees: boolean,
154+
checkActionPermission: (
155+
requiredPermission: PermissionsConstantType
156+
) => boolean
157+
): ActiontechTableToolbarActionMeta[] => {
121158
return [
122159
{
123160
key: 'is-high-priority',
@@ -148,7 +185,10 @@ export const SqlManagementTableToolbarActions = (
148185
onBatchAssignment();
149186
}
150187
},
151-
permissions: PERMISSIONS.ACTIONS.SQLE.SQL_MANAGEMENT.BATCH_ASSIGNMENT
188+
permissions:
189+
checkActionPermission(
190+
PERMISSIONS.ACTIONS.SQLE.SQL_MANAGEMENT.BATCH_ASSIGNMENT
191+
) || isCertainAssignees
152192
},
153193
{
154194
key: 'batch-solve',
@@ -163,7 +203,10 @@ export const SqlManagementTableToolbarActions = (
163203
disabled: batchSolveLoading
164204
}
165205
},
166-
permissions: PERMISSIONS.ACTIONS.SQLE.SQL_MANAGEMENT.BATCH_RESOLVE
206+
permissions:
207+
checkActionPermission(
208+
PERMISSIONS.ACTIONS.SQLE.SQL_MANAGEMENT.BATCH_RESOLVE
209+
) || isCertainAssignees
167210
},
168211
{
169212
key: 'batch-ignore',
@@ -178,7 +221,10 @@ export const SqlManagementTableToolbarActions = (
178221
disabled: batchIgnoreLoading
179222
}
180223
},
181-
permissions: PERMISSIONS.ACTIONS.SQLE.SQL_MANAGEMENT.BATCH_IGNORE
224+
permissions:
225+
checkActionPermission(
226+
PERMISSIONS.ACTIONS.SQLE.SQL_MANAGEMENT.BATCH_IGNORE
227+
) || isCertainAssignees
182228
},
183229
{
184230
key: 'push-to-coding',
@@ -187,7 +233,10 @@ export const SqlManagementTableToolbarActions = (
187233
disabled,
188234
onClick: () => onPushToCoding(true)
189235
},
190-
permissions: PERMISSIONS.ACTIONS.SQLE.SQL_MANAGEMENT.PUSH_TO_CODING
236+
permissions:
237+
checkActionPermission(
238+
PERMISSIONS.ACTIONS.SQLE.SQL_MANAGEMENT.PUSH_TO_CODING
239+
) || isCertainAssignees
191240
}
192241
];
193242
};

packages/sqle/src/page/SqlManagement/component/SQLEEIndex/index.test.tsx

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -840,4 +840,43 @@ describe('page/SqlManagement/SQLEEIndex', () => {
840840
expect(getBySelector('.ant-alert-warning')).toBeInTheDocument();
841841
expect(baseElement.querySelector('.ant-alert-warning')).toMatchSnapshot();
842842
});
843+
844+
it('render table actions when user not have permission but is assignee', async () => {
845+
mockUseCurrentUser({
846+
...mockCurrentUserReturn,
847+
userRoles: {
848+
...mockCurrentUserReturn.userRoles,
849+
[SystemRole.admin]: false,
850+
[SystemRole.systemAdministrator]: false
851+
},
852+
bindProjects: [
853+
{
854+
is_manager: false,
855+
project_name: mockProjectInfo.projectName,
856+
project_id: mockProjectInfo.projectID,
857+
archived: false
858+
}
859+
]
860+
});
861+
sqlManage.getSqlManageList().mockImplementation(() =>
862+
createSpySuccessResponse({
863+
data: [
864+
{
865+
...sqlManageListData.data[0],
866+
assignees: [mockCurrentUserReturn.username]
867+
}
868+
]
869+
})
870+
);
871+
sqleSuperRender(<SQLEEIndex />);
872+
await act(async () => jest.advanceTimersByTime(3000));
873+
expect(screen.getByText('指派负责人')).toBeInTheDocument();
874+
expect(screen.getByText('变更状态')).toBeInTheDocument();
875+
expect(screen.getByText('批量指派')).toBeInTheDocument();
876+
expect(screen.getByText('批量解决').closest('button')).toBeDisabled();
877+
const batchCheckbox = getBySelector('.ant-table-thead .ant-checkbox-input');
878+
fireEvent.click(batchCheckbox);
879+
await act(async () => jest.advanceTimersByTime(0));
880+
expect(screen.getByText('批量解决').closest('button')).not.toBeDisabled();
881+
});
843882
});

packages/sqle/src/page/SqlManagement/component/SQLEEIndex/index.tsx

Lines changed: 45 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -63,18 +63,15 @@ import dayjs from 'dayjs';
6363
import AbnormalInstance from './AbnormalInstance';
6464
import { formatTime } from '@actiontech/shared/lib/utils/Common';
6565
import { AbnormalInstanceStatusCodeEnum } from './index.data';
66+
import { PERMISSIONS } from '@actiontech/shared/lib/features/usePermission/permissions';
6667

6768
const SQLEEIndex = () => {
6869
const { t } = useTranslation();
6970

7071
const extractQueries = useTypedQuery();
7172

7273
const [messageApi, messageContextHolder] = message.useMessage();
73-
const {
74-
parse2TableActionPermissions,
75-
parse2TableToolbarActionPermissions,
76-
checkActionPermission
77-
} = usePermission();
74+
const { checkActionPermission } = usePermission();
7875
// api
7976
const { projectID, projectName } = useCurrentProject();
8077
const { username, userId, language } = useCurrentUser();
@@ -290,26 +287,25 @@ const SQLEEIndex = () => {
290287
);
291288

292289
const actions = useMemo(() => {
293-
return parse2TableActionPermissions(
294-
SqlManagementRowAction(
295-
openModal,
296-
jumpToAnalyze,
297-
onCreateSqlManagementException,
298-
onCreateWhitelist,
299-
language,
300-
checkActionPermission,
301-
onPushToCoding
302-
)
290+
return SqlManagementRowAction(
291+
openModal,
292+
jumpToAnalyze,
293+
onCreateSqlManagementException,
294+
onCreateWhitelist,
295+
language,
296+
checkActionPermission,
297+
onPushToCoding,
298+
username
303299
);
304300
}, [
305301
jumpToAnalyze,
306302
openModal,
307303
onCreateSqlManagementException,
308304
onCreateWhitelist,
309305
language,
310-
parse2TableActionPermissions,
311306
checkActionPermission,
312-
onPushToCoding
307+
onPushToCoding,
308+
username
313309
]);
314310

315311
const updateRemarkProtect = useRef(false);
@@ -440,32 +436,48 @@ const SQLEEIndex = () => {
440436
}, [selectedRowData, updateModalStatus, setBatchSelectData]);
441437

442438
const getTableToolbarActions = useMemo(() => {
443-
return parse2TableToolbarActionPermissions(
444-
SqlManagementTableToolbarActions(
445-
selectedRowKeys?.length === 0,
446-
batchSolveLoading,
447-
batchIgnoreLoading,
448-
onBatchAssignment,
449-
onBatchSolve,
450-
onBatchIgnore,
451-
isAssigneeSelf,
452-
isHighPriority,
453-
setAssigneeSelf,
454-
setIsHighPriority,
455-
onPushToCoding
456-
)
439+
// 当前用户不是admin 系统管理员 项目管理员 则根据用户是否是sql负责判断是否有操作权限
440+
// 因为批量操作的权限一致 所以这里取其中一个判断
441+
const hasPermission = checkActionPermission(
442+
PERMISSIONS.ACTIONS.SQLE.SQL_MANAGEMENT.BATCH_ASSIGNMENT
443+
);
444+
const isAssignees = selectedRowData.every((item) =>
445+
item?.assignees?.includes(username)
446+
);
447+
const isDisabled =
448+
selectedRowData?.length === 0 || (!hasPermission && !isAssignees);
449+
// 用户为某条sql的负责人才会显示批量操作按钮
450+
const isCertainAssignees =
451+
sqlList?.list?.some((item) => item?.assignees?.includes(username)) ??
452+
false;
453+
return SqlManagementTableToolbarActions(
454+
isDisabled,
455+
batchSolveLoading,
456+
batchIgnoreLoading,
457+
onBatchAssignment,
458+
onBatchSolve,
459+
onBatchIgnore,
460+
isAssigneeSelf,
461+
isHighPriority,
462+
setAssigneeSelf,
463+
setIsHighPriority,
464+
onPushToCoding,
465+
isCertainAssignees,
466+
checkActionPermission
457467
);
458468
}, [
459469
batchIgnoreLoading,
460470
batchSolveLoading,
461-
selectedRowKeys?.length,
471+
selectedRowData,
462472
isAssigneeSelf,
463473
isHighPriority,
464474
onBatchAssignment,
465475
onBatchIgnore,
466476
onBatchSolve,
467477
onPushToCoding,
468-
parse2TableToolbarActionPermissions
478+
username,
479+
checkActionPermission,
480+
sqlList
469481
]);
470482

471483
const loading = useMemo(

0 commit comments

Comments
 (0)