Add permission checks to account and QNA pages
- Add grant check (46, 'X') to password change navigation handlers - Add grant check (45, 'X') to user management save/add operations - Add grant check (64, 'X') to QNA registration - Refactor inline onClick handlers to separate methods for better maintainability - Add debug logging to checkGrant function Changes: - password-manage-wrap: Extract changeLoginPassword and changeCancelPassword methods - user-account-auth-wrap: Extract handleSave method with permission check - user-login-auth-info-wrap: Add permission check to handleSave - user-manage-wrap: Add permission check to onClickToNavigation, simplify onClick - qna/register-page: Add permission check to onClickToRegisterQna 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -1,11 +1,29 @@
|
|||||||
import { useTranslation } from 'react-i18next';
|
import { useTranslation } from 'react-i18next';
|
||||||
import { PATHS } from '@/shared/constants/paths';
|
import { PATHS } from '@/shared/constants/paths';
|
||||||
import { useNavigate } from '@/shared/lib/hooks/use-navigate';
|
import { useNavigate } from '@/shared/lib/hooks/use-navigate';
|
||||||
|
import { checkGrant } from '@/shared/lib/check-grant';
|
||||||
|
import { showAlert } from '@/widgets/show-alert';
|
||||||
|
|
||||||
export const PasswordManageWrap = () => {
|
export const PasswordManageWrap = () => {
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
const { navigate } = useNavigate();
|
const { navigate } = useNavigate();
|
||||||
|
|
||||||
|
const changeLoginPassword = () => {
|
||||||
|
if (!checkGrant(46, 'X')) {
|
||||||
|
showAlert(t('common.nopermission'));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
navigate(PATHS.account.password.modifyLoginPassword);
|
||||||
|
};
|
||||||
|
|
||||||
|
const changeCancelPassword = () => {
|
||||||
|
if (!checkGrant(46, 'X')) {
|
||||||
|
showAlert(t('common.nopermission'));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
navigate(PATHS.account.password.modifyCancelPassword);
|
||||||
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<div className="ing-list">
|
<div className="ing-list">
|
||||||
@@ -14,12 +32,12 @@ export const PasswordManageWrap = () => {
|
|||||||
<button
|
<button
|
||||||
className="btn-44 btn-white pwd-btn"
|
className="btn-44 btn-white pwd-btn"
|
||||||
type="button"
|
type="button"
|
||||||
onClick={ () => navigate(PATHS.account.password.modifyLoginPassword) }
|
onClick={changeLoginPassword}
|
||||||
>{t('account.changeLoginPassword')}</button>
|
>{t('account.changeLoginPassword')}</button>
|
||||||
<button
|
<button
|
||||||
className="btn-44 btn-white pwd-btn"
|
className="btn-44 btn-white pwd-btn"
|
||||||
type="button"
|
type="button"
|
||||||
onClick={ () => navigate(PATHS.account.password.modifyCancelPassword) }
|
onClick={changeCancelPassword}
|
||||||
>{t('account.changeCancelPassword')}</button>
|
>{t('account.changeCancelPassword')}</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -6,6 +6,8 @@ import { useUserUpdatePermissionsMutation } from '@/entities/user/api/use-user-u
|
|||||||
import { UserMenuPermissionData } from '@/entities/user/model/types';
|
import { UserMenuPermissionData } from '@/entities/user/model/types';
|
||||||
import { MenuItems } from '@/entities/common/model/constant';
|
import { MenuItems } from '@/entities/common/model/constant';
|
||||||
import { useTranslation } from 'react-i18next';
|
import { useTranslation } from 'react-i18next';
|
||||||
|
import { checkGrant } from '@/shared/lib/check-grant';
|
||||||
|
import { showAlert } from '@/widgets/show-alert';
|
||||||
|
|
||||||
export const UserAccountAuthWrap = ({
|
export const UserAccountAuthWrap = ({
|
||||||
mid,
|
mid,
|
||||||
@@ -49,6 +51,21 @@ export const UserAccountAuthWrap = ({
|
|||||||
const idCLChanged = currentIdCL !== idCL;
|
const idCLChanged = currentIdCL !== idCL;
|
||||||
setHasChanges(statusChanged || idCLChanged);
|
setHasChanges(statusChanged || idCLChanged);
|
||||||
}, [currentStatus, currentIdCL, status, idCL]);
|
}, [currentStatus, currentIdCL, status, idCL]);
|
||||||
|
|
||||||
|
const handleSave = () => {
|
||||||
|
if (!checkGrant(45, 'X')) {
|
||||||
|
showAlert(t('common.nopermission'));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
console.log('updatePermissionMutation');
|
||||||
|
updatePermissionsMutation.mutate({
|
||||||
|
mid: mid,
|
||||||
|
usrid: usrid,
|
||||||
|
idCl: currentIdCL,
|
||||||
|
status: currentStatus
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<div className="ing-list pdtop pb-86">
|
<div className="ing-list pdtop pb-86">
|
||||||
@@ -89,16 +106,7 @@ export const UserAccountAuthWrap = ({
|
|||||||
className="btn-50 btn-blue flex-1"
|
className="btn-50 btn-blue flex-1"
|
||||||
type="button"
|
type="button"
|
||||||
disabled={!hasChanges || updatePermissionsMutation.isPending}
|
disabled={!hasChanges || updatePermissionsMutation.isPending}
|
||||||
onClick={() => {
|
onClick={handleSave}
|
||||||
console.log('updatePermissionMutation');
|
|
||||||
updatePermissionsMutation.mutate(
|
|
||||||
{
|
|
||||||
mid: mid,
|
|
||||||
usrid: usrid,
|
|
||||||
idCl: currentIdCL,
|
|
||||||
status: currentStatus
|
|
||||||
});
|
|
||||||
}}
|
|
||||||
>
|
>
|
||||||
{updatePermissionsMutation.isPending ? t('common.saving') : t('common.save')}
|
{updatePermissionsMutation.isPending ? t('common.saving') : t('common.save')}
|
||||||
</button>
|
</button>
|
||||||
|
|||||||
@@ -7,6 +7,8 @@ import { UserManageAuthList } from './user-manage-auth-list';
|
|||||||
import { useUserFindMutation } from '@/entities/user/api/use-user-find-mutation';
|
import { useUserFindMutation } from '@/entities/user/api/use-user-find-mutation';
|
||||||
import { UserListItem } from '@/entities/user/model/types';
|
import { UserListItem } from '@/entities/user/model/types';
|
||||||
import { useStore } from '@/shared/model/store';
|
import { useStore } from '@/shared/model/store';
|
||||||
|
import { checkGrant } from '@/shared/lib/check-grant';
|
||||||
|
import { showAlert } from '@/widgets/show-alert';
|
||||||
|
|
||||||
export const UserManageWrap = () => {
|
export const UserManageWrap = () => {
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
@@ -33,6 +35,10 @@ export const UserManageWrap = () => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const onClickToNavigation = () => {
|
const onClickToNavigation = () => {
|
||||||
|
if (!checkGrant(45, 'X')) {
|
||||||
|
showAlert(t('common.nopermission'));
|
||||||
|
return;
|
||||||
|
}
|
||||||
navigate(PATHS.account.user.addAccount, {
|
navigate(PATHS.account.user.addAccount, {
|
||||||
state: {
|
state: {
|
||||||
mid: mid,
|
mid: mid,
|
||||||
@@ -82,7 +88,7 @@ export const UserManageWrap = () => {
|
|||||||
<div className="apply-row">
|
<div className="apply-row">
|
||||||
<button
|
<button
|
||||||
className="btn-50 btn-blue flex-1"
|
className="btn-50 btn-blue flex-1"
|
||||||
onClick={ () => onClickToNavigation() }
|
onClick={onClickToNavigation}
|
||||||
>{t('account.addUser')}</button>
|
>{t('account.addUser')}</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -3,6 +3,9 @@ import { useStore } from "../model/store";
|
|||||||
export const checkGrant = (menuId?: number, authType: string = 'R') => {
|
export const checkGrant = (menuId?: number, authType: string = 'R') => {
|
||||||
const menuGrantsByKey = useStore.getState().UserStore.menuGrantsByKey;
|
const menuGrantsByKey = useStore.getState().UserStore.menuGrantsByKey;
|
||||||
const myGrants = menuGrantsByKey['' + menuId];
|
const myGrants = menuGrantsByKey['' + menuId];
|
||||||
|
|
||||||
|
console.log('checkGrant', menuId, authType, myGrants);
|
||||||
|
|
||||||
if(myGrants?.includes(authType) || menuId === -1){
|
if(myGrants?.includes(authType) || menuId === -1){
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user