fix: close permission review gaps
fix: harden permission-gated UI — minimum-org endpoint, modal/Popconfirm fail-closed on revocation
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import { useCallback } from 'react';
|
||||
import { useCallback, useEffect, useRef } from 'react';
|
||||
import { Modal } from 'antd';
|
||||
import api from '../api';
|
||||
import { message } from '../ui/app-message';
|
||||
@@ -9,16 +9,35 @@ import { message } from '../ui/app-message';
|
||||
*
|
||||
* @param studentId - The student whose data is being viewed
|
||||
* @param module - Audit module label (e.g. '学生管理', '学生档案')
|
||||
* @param canLog - Whether the current user has log:create; when false any
|
||||
* already-open confirm modal is destroyed.
|
||||
*/
|
||||
export function useViewSensitive(studentId: number, module: string) {
|
||||
export function useViewSensitive(studentId: number, module: string, canLog: boolean) {
|
||||
const canLogRef = useRef(canLog);
|
||||
const modalRef = useRef<ReturnType<typeof Modal.confirm> | null>(null);
|
||||
canLogRef.current = canLog;
|
||||
|
||||
useEffect(() => {
|
||||
if (!canLogRef.current && modalRef.current) {
|
||||
modalRef.current.destroy();
|
||||
modalRef.current = null;
|
||||
}
|
||||
return () => {
|
||||
modalRef.current?.destroy();
|
||||
modalRef.current = null;
|
||||
};
|
||||
}, []);
|
||||
|
||||
return useCallback(
|
||||
(field: string, value: string) => {
|
||||
Modal.confirm({
|
||||
if (!canLogRef.current) return;
|
||||
modalRef.current = Modal.confirm({
|
||||
title: '查看敏感信息',
|
||||
content: `您即将查看 "${field}" 的完整信息。此操作将被记录。`,
|
||||
okText: '确认查看',
|
||||
cancelText: '取消',
|
||||
onOk: async () => {
|
||||
if (!canLogRef.current) return;
|
||||
try {
|
||||
await api.post('/operation-logs/audit', {
|
||||
module,
|
||||
@@ -37,6 +56,9 @@ export function useViewSensitive(studentId: number, module: string) {
|
||||
okText: '关闭',
|
||||
});
|
||||
},
|
||||
afterClose: () => {
|
||||
modalRef.current = null;
|
||||
},
|
||||
});
|
||||
},
|
||||
[studentId, module],
|
||||
|
||||
Reference in New Issue
Block a user