fix(notifications): 알림 수신자 관리 비admin 사용자 권한 허용
본인 수신자 추가/제거는 모든 인증 사용자 허용, 타인 수신자 관리는 관리자만 허용하도록 변경 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -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) {
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user