From cc806cc08feaccc361a41850c9ee141696c86536 Mon Sep 17 00:00:00 2001 From: Pau Navarro Date: Wed, 18 Jan 2023 07:41:10 +0100 Subject: [PATCH] requested changes --- back/models/notificationSubscription.js | 13 +++++-------- db/dump/structure.sql | 5 +++-- 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/back/models/notificationSubscription.js b/back/models/notificationSubscription.js index eafa9d51b..674629413 100644 --- a/back/models/notificationSubscription.js +++ b/back/models/notificationSubscription.js @@ -7,9 +7,7 @@ module.exports = Self => { const user = await ctx.instance.userFk; const modifiedUser = await getUserToModify(null, user, models); - if (userId == modifiedUser.id || userId == modifiedUser.bossFk) - return; - else + if (userId != modifiedUser.id && userId != modifiedUser.bossFk) throw new UserError('You dont have permission to modify this user'); }); @@ -42,14 +40,13 @@ module.exports = Self => { const user = ctx.req.accessToken.userId; const modifiedUser = await getUserToModify(notificationId, null, models); - if (user == modifiedUser.id || modifiedUser.bossFk == user) { - await models.NotificationSubscription.destroyById(notificationId); - return; - } else + if (user != modifiedUser.id && user != modifiedUser.bossFk) throw new UserError('You dont have permission to modify this user'); + + await models.NotificationSubscription.destroyById(notificationId); }; - async function getUserToModify(notificationId = null, userFk = null, models) { + async function getUserToModify(notificationId, userFk, models) { if (notificationId != null) { const subscription = await models.NotificationSubscription.findById(notificationId); const user = await subscription.userFk; diff --git a/db/dump/structure.sql b/db/dump/structure.sql index 510a51d94..4213f918a 100644 --- a/db/dump/structure.sql +++ b/db/dump/structure.sql @@ -19726,10 +19726,11 @@ DROP TABLE IF EXISTS `notificationSubscription`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `notificationSubscription` ( - `Id` int(11) NOT NULL AUTO_INCREMENT, + `id` int(11) NOT NULL AUTO_INCREMENT, `notificationFk` int(11) NOT NULL, `userFk` int(10) unsigned NOT NULL, - PRIMARY KEY (`Id`), + PRIMARY KEY (`id`), + KEY `notificationSubscription_ibfk_1` (`notificationFk`), KEY `notificationSubscription_ibfk_2` (`userFk`), CONSTRAINT `notificationSubscription_ibfk_1` FOREIGN KEY (`notificationFk`) REFERENCES `notification` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `notificationSubscription_ibfk_2` FOREIGN KEY (`userFk`) REFERENCES `account`.`user` (`id`) ON DELETE CASCADE ON UPDATE CASCADE