From be24c12551f08b21b965cb7f124e229b2498f54f Mon Sep 17 00:00:00 2001 From: Hyungi Ahn Date: Fri, 13 Mar 2026 15:50:23 +0900 Subject: [PATCH] =?UTF-8?q?fix(notifications):=20=EC=95=8C=EB=A6=BC=20?= =?UTF-8?q?=EC=88=98=EC=8B=A0=EC=9E=90=20=EA=B4=80=EB=A6=AC=20=EB=B9=84adm?= =?UTF-8?q?in=20=EC=82=AC=EC=9A=A9=EC=9E=90=20=EA=B6=8C=ED=95=9C=20?= =?UTF-8?q?=ED=97=88=EC=9A=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 본인 수신자 추가/제거는 모든 인증 사용자 허용, 타인 수신자 관리는 관리자만 허용하도록 변경 Co-Authored-By: Claude Opus 4.6 --- .../controllers/notificationRecipientController.js | 12 ++++++++++-- .../api/routes/notificationRecipientRoutes.js | 8 ++++---- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/user-management/api/controllers/notificationRecipientController.js b/user-management/api/controllers/notificationRecipientController.js index 5f09356..7a42342 100644 --- a/user-management/api/controllers/notificationRecipientController.js +++ b/user-management/api/controllers/notificationRecipientController.js @@ -37,7 +37,7 @@ const notificationRecipientController = { } }, - // 수신자 추가 + // 수신자 추가 (본인: 모든 사용자, 타인: 관리자만) add: async (req, res) => { try { const { notification_type, user_id } = req.body; @@ -46,6 +46,10 @@ 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: '본인의 알림 수신 설정만 변경할 수 있습니다.' }); + } + await notificationRecipientModel.add(notification_type, user_id, req.user?.user_id); res.json({ success: true, message: '수신자가 추가되었습니다.' }); } catch (error) { @@ -54,11 +58,15 @@ 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: '본인의 알림 수신 설정만 변경할 수 있습니다.' }); + } + await notificationRecipientModel.remove(type, userId); res.json({ success: true, message: '수신자가 제거되었습니다.' }); } catch (error) { diff --git a/user-management/api/routes/notificationRecipientRoutes.js b/user-management/api/routes/notificationRecipientRoutes.js index dc9c80f..e536f94 100644 --- a/user-management/api/routes/notificationRecipientRoutes.js +++ b/user-management/api/routes/notificationRecipientRoutes.js @@ -16,13 +16,13 @@ router.get('/', controller.getAll); // 유형별 수신자 조회 router.get('/:type', controller.getByType); -// 수신자 추가 (관리자만) -router.post('/', requireAdmin, controller.add); +// 수신자 추가 (본인: 모든 사용자, 타인: 관리자만 — 컨트롤러에서 검증) +router.post('/', controller.add); // 유형별 수신자 일괄 설정 (관리자만) router.put('/:type', requireAdmin, controller.setRecipients); -// 수신자 제거 (관리자만) -router.delete('/:type/:userId', requireAdmin, controller.remove); +// 수신자 제거 (본인: 모든 사용자, 타인: 관리자만 — 컨트롤러에서 검증) +router.delete('/:type/:userId', controller.remove); module.exports = router;