fix(notifications): 알림 수신자 관리 본인 검증을 권한 검증으로 교체
본인 검증이 타인 수신자 추가/제거를 차단하는 문제 수정. permissionModel.checkAccess로 tkuser.notification_recipients 권한 확인. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -1,5 +1,13 @@
|
||||
// controllers/notificationRecipientController.js
|
||||
const notificationRecipientModel = require('../models/notificationRecipientModel');
|
||||
const permissionModel = require('../models/permissionModel');
|
||||
|
||||
async function checkNrPermission(user) {
|
||||
const role = (user.role || '').toLowerCase();
|
||||
if (['admin', 'system'].includes(role)) return true;
|
||||
const access = await permissionModel.checkAccess(user.user_id, 'tkuser.notification_recipients');
|
||||
return access.can_access;
|
||||
}
|
||||
|
||||
const notificationRecipientController = {
|
||||
// 알림 유형 목록
|
||||
@@ -37,7 +45,7 @@ const notificationRecipientController = {
|
||||
}
|
||||
},
|
||||
|
||||
// 수신자 추가 (본인: 모든 사용자, 타인: 관리자만)
|
||||
// 수신자 추가 (권한 보유 사용자)
|
||||
add: async (req, res) => {
|
||||
try {
|
||||
const { notification_type, user_id } = req.body;
|
||||
@@ -46,8 +54,8 @@ const notificationRecipientController = {
|
||||
return res.status(400).json({ success: false, error: '알림 유형과 사용자 ID가 필요합니다.' });
|
||||
}
|
||||
|
||||
if (Number(user_id) !== Number(req.user.user_id) && !['admin', 'system'].includes((req.user.role || '').toLowerCase())) {
|
||||
return res.status(403).json({ success: false, error: '본인의 알림 수신 설정만 변경할 수 있습니다.' });
|
||||
if (!await checkNrPermission(req.user)) {
|
||||
return res.status(403).json({ success: false, error: '알림 수신자 관리 권한이 없습니다.' });
|
||||
}
|
||||
|
||||
await notificationRecipientModel.add(notification_type, user_id, req.user?.user_id);
|
||||
@@ -58,13 +66,13 @@ const notificationRecipientController = {
|
||||
}
|
||||
},
|
||||
|
||||
// 수신자 제거 (본인: 모든 사용자, 타인: 관리자만)
|
||||
// 수신자 제거 (권한 보유 사용자)
|
||||
remove: async (req, res) => {
|
||||
try {
|
||||
const { type, userId } = req.params;
|
||||
|
||||
if (Number(userId) !== Number(req.user.user_id) && !['admin', 'system'].includes((req.user.role || '').toLowerCase())) {
|
||||
return res.status(403).json({ success: false, error: '본인의 알림 수신 설정만 변경할 수 있습니다.' });
|
||||
if (!await checkNrPermission(req.user)) {
|
||||
return res.status(403).json({ success: false, error: '알림 수신자 관리 권한이 없습니다.' });
|
||||
}
|
||||
|
||||
await notificationRecipientModel.remove(type, userId);
|
||||
|
||||
Reference in New Issue
Block a user