From dfdf3d68bffb6ef991d85f0985c74b1a0315b696 Mon Sep 17 00:00:00 2001 From: Pau Navarro Date: Thu, 24 Nov 2022 09:36:05 +0100 Subject: [PATCH 01/26] changes needed for the worker Notification manager to work --- .../methods/notification/deleteSubcription.js | 56 +++++++++++++++++++ back/models/notificationAcl.json | 10 ++++ back/models/notificationSubscription.js | 3 + back/models/notificationSubscription.json | 1 - 4 files changed, 69 insertions(+), 1 deletion(-) create mode 100644 back/methods/notification/deleteSubcription.js create mode 100644 back/models/notificationSubscription.js diff --git a/back/methods/notification/deleteSubcription.js b/back/methods/notification/deleteSubcription.js new file mode 100644 index 000000000..9095613fe --- /dev/null +++ b/back/methods/notification/deleteSubcription.js @@ -0,0 +1,56 @@ +module.exports = Self => { + Self.remoteMethod('deleteSubscription', { + description: 'delete a notification subscription', + accessType: 'WRITE', + accepts: [ + { + arg: 'notificationId', + type: 'string', + required: true + }, + { + arg: 'userId', + type: 'string', + required: true + } + ], + returns: { + type: 'object', + root: true + }, + http: { + path: `/deleteSubscription`, + verb: 'POST' + } + }); + + Self.deleteSubscription = async(notificationId, userId, options) => { + const myOptions = {}; + let tx; + + if (typeof options == 'object') + + Object.assign(myOptions, options); + + if (!myOptions.transaction) { + tx = await Self.beginTransaction({}); + + myOptions.transaction = tx; + } + + try { + const query = `DELETE FROM util.notificationSubscription + WHERE notificationFk = ? AND userFk = ?`; + + await Self.rawSql(query, [notificationId, userId], myOptions); + + if (tx) await tx.commit(); + + return {success: true}; + } catch (error) { + if (tx) await tx.rollback(); + + throw error; + } + }; +}; diff --git a/back/models/notificationAcl.json b/back/models/notificationAcl.json index e3e97f52d..a20187961 100644 --- a/back/models/notificationAcl.json +++ b/back/models/notificationAcl.json @@ -6,6 +6,16 @@ "table": "util.notificationAcl" } }, + "properties":{ + "notificationFk": { + "id": true, + "type": "number" + }, + "roleFk":{ + "id": true, + "type": "number" + } + }, "relations": { "notification": { "type": "belongsTo", diff --git a/back/models/notificationSubscription.js b/back/models/notificationSubscription.js new file mode 100644 index 000000000..ce5d89e8b --- /dev/null +++ b/back/models/notificationSubscription.js @@ -0,0 +1,3 @@ +module.exports = Self => { + require('../methods/notification/deleteSubcription')(Self); +}; diff --git a/back/models/notificationSubscription.json b/back/models/notificationSubscription.json index 43fa6db27..11dbde6fb 100644 --- a/back/models/notificationSubscription.json +++ b/back/models/notificationSubscription.json @@ -9,7 +9,6 @@ "properties": { "notificationFk": { "type": "number", - "id": true, "description": "Identifier" }, "userFk": { From 3e08650b6f7f1210f6905861818673dd3df402a3 Mon Sep 17 00:00:00 2001 From: Pau Navarro Date: Fri, 25 Nov 2022 07:06:04 +0100 Subject: [PATCH 02/26] acls for the notifications --- db/changes/10503-november/00-acl-notifications.sql | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 db/changes/10503-november/00-acl-notifications.sql diff --git a/db/changes/10503-november/00-acl-notifications.sql b/db/changes/10503-november/00-acl-notifications.sql new file mode 100644 index 000000000..b2377393b --- /dev/null +++ b/db/changes/10503-november/00-acl-notifications.sql @@ -0,0 +1,3 @@ +INSERT INTO salix.ACL (model,property,accessType,principalId) + VALUES ('NotificationSubscription','*','*','employee'), + VALUES ('NotificationAcl','*','*','employee'); \ No newline at end of file From 074763f633bd54113d9220a2a708c9074958668b Mon Sep 17 00:00:00 2001 From: Pau Navarro Date: Fri, 25 Nov 2022 11:47:23 +0100 Subject: [PATCH 03/26] rename files --- .../{00-acl-notifications.sql => 00-acl_notifications.sql} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename db/changes/10503-november/{00-acl-notifications.sql => 00-acl_notifications.sql} (100%) diff --git a/db/changes/10503-november/00-acl-notifications.sql b/db/changes/10503-november/00-acl_notifications.sql similarity index 100% rename from db/changes/10503-november/00-acl-notifications.sql rename to db/changes/10503-november/00-acl_notifications.sql From aee7cd113ef7c6355ca51fffae9721a42ff92a04 Mon Sep 17 00:00:00 2001 From: Pau Navarro Date: Mon, 28 Nov 2022 09:33:14 +0100 Subject: [PATCH 04/26] add template strings to sql --- db/changes/10503-november/00-acl_notifications.sql | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/db/changes/10503-november/00-acl_notifications.sql b/db/changes/10503-november/00-acl_notifications.sql index b2377393b..ee2e2e345 100644 --- a/db/changes/10503-november/00-acl_notifications.sql +++ b/db/changes/10503-november/00-acl_notifications.sql @@ -1,3 +1,4 @@ -INSERT INTO salix.ACL (model,property,accessType,principalId) - VALUES ('NotificationSubscription','*','*','employee'), - VALUES ('NotificationAcl','*','*','employee'); \ No newline at end of file +INSERT INTO `salix`.`ACL` (`model`,`property`,`accessType`,`principalId`) + VALUES + ('NotificationSubscription','*','*','employee'), + ('NotificationAcl','*','*','employee'); \ No newline at end of file From ada3e6f175da8e0564866a9b3608a39fa385cb8f Mon Sep 17 00:00:00 2001 From: Pau Navarro Date: Tue, 27 Dec 2022 10:10:37 +0100 Subject: [PATCH 05/26] update sql folder --- db/changes/224903/00-acl_notifications.sql | 4 ---- db/changes/230201/00-acl_notifications.sql | 3 +++ 2 files changed, 3 insertions(+), 4 deletions(-) delete mode 100644 db/changes/224903/00-acl_notifications.sql create mode 100644 db/changes/230201/00-acl_notifications.sql diff --git a/db/changes/224903/00-acl_notifications.sql b/db/changes/224903/00-acl_notifications.sql deleted file mode 100644 index ee2e2e345..000000000 --- a/db/changes/224903/00-acl_notifications.sql +++ /dev/null @@ -1,4 +0,0 @@ -INSERT INTO `salix`.`ACL` (`model`,`property`,`accessType`,`principalId`) - VALUES - ('NotificationSubscription','*','*','employee'), - ('NotificationAcl','*','*','employee'); \ No newline at end of file diff --git a/db/changes/230201/00-acl_notifications.sql b/db/changes/230201/00-acl_notifications.sql new file mode 100644 index 000000000..ef710aca6 --- /dev/null +++ b/db/changes/230201/00-acl_notifications.sql @@ -0,0 +1,3 @@ + VALUES + ('NotificationSubscription','*','*','employee'), + ('NotificationAcl','*','*','employee'); \ No newline at end of file From 3ca1d1f4ee6e7b4853d4c8c04df17017f6e79ded Mon Sep 17 00:00:00 2001 From: Pau Navarro Date: Tue, 27 Dec 2022 10:29:15 +0100 Subject: [PATCH 06/26] remove error in fixtures --- db/dump/fixtures.sql | 4 ---- 1 file changed, 4 deletions(-) diff --git a/db/dump/fixtures.sql b/db/dump/fixtures.sql index 762e5411a..ff87b4bd0 100644 --- a/db/dump/fixtures.sql +++ b/db/dump/fixtures.sql @@ -1954,10 +1954,6 @@ INSERT INTO `vn`.`workerBusinessType` (`id`, `name`, `isFullTime`, `isPermanent` (100, 'INDEFINIDO A TIEMPO COMPLETO', 1, 1, 1), (109, 'CONVERSION DE TEMPORAL EN INDEFINIDO T.COMPLETO', 1, 1, 1); -INSERT INTO `vn`.`businessCategory` (`id`, `description`, `rate`) - VALUES - (1, 'basic employee', 1); - UPDATE `vn`.`business` b SET `rate` = 7, `workerBusinessCategoryFk` = 1, From ea7f4b7c02172517a94f4077febf5d635409f846 Mon Sep 17 00:00:00 2001 From: Pau Navarro Date: Tue, 27 Dec 2022 10:34:12 +0100 Subject: [PATCH 07/26] remove broken fixture --- db/dump/fixtures.sql | 4 ---- 1 file changed, 4 deletions(-) diff --git a/db/dump/fixtures.sql b/db/dump/fixtures.sql index ff87b4bd0..b2501c6db 100644 --- a/db/dump/fixtures.sql +++ b/db/dump/fixtures.sql @@ -2746,10 +2746,6 @@ INSERT INTO `vn`.`mdbApp` (`app`, `baselineBranchFk`, `userFk`, `locked`) VALUES ('foo', 'master', NULL, NULL), ('bar', 'test', 9, util.VN_NOW()); -INSERT INTO `vn`.`ticketLog` (`id`, `originFk`, `userFk`, `action`, `changedModel`, `oldInstance`, `newInstance`, `changedModelId`) - VALUES - (1, 1, 9, 'insert', 'Ticket', '{}', '{"clientFk":1, "nickname": "Bat cave"}', 1); - INSERT INTO `salix`.`url` (`appName`, `environment`, `url`) VALUES From ee0cd2174f78a5e4207c2026bf0218f282d9b3ae Mon Sep 17 00:00:00 2001 From: Pau Navarro Date: Tue, 27 Dec 2022 14:32:19 +0100 Subject: [PATCH 08/26] requested changes refs #4797 @2h --- .../methods/notification/deleteSubcription.js | 56 --------------- back/models/notificationSubscription.js | 72 ++++++++++++++++++- back/models/notificationSubscription.json | 1 + db/changes/230201/00-acl_notifications.sql | 14 +++- 4 files changed, 83 insertions(+), 60 deletions(-) delete mode 100644 back/methods/notification/deleteSubcription.js diff --git a/back/methods/notification/deleteSubcription.js b/back/methods/notification/deleteSubcription.js deleted file mode 100644 index 9095613fe..000000000 --- a/back/methods/notification/deleteSubcription.js +++ /dev/null @@ -1,56 +0,0 @@ -module.exports = Self => { - Self.remoteMethod('deleteSubscription', { - description: 'delete a notification subscription', - accessType: 'WRITE', - accepts: [ - { - arg: 'notificationId', - type: 'string', - required: true - }, - { - arg: 'userId', - type: 'string', - required: true - } - ], - returns: { - type: 'object', - root: true - }, - http: { - path: `/deleteSubscription`, - verb: 'POST' - } - }); - - Self.deleteSubscription = async(notificationId, userId, options) => { - const myOptions = {}; - let tx; - - if (typeof options == 'object') - - Object.assign(myOptions, options); - - if (!myOptions.transaction) { - tx = await Self.beginTransaction({}); - - myOptions.transaction = tx; - } - - try { - const query = `DELETE FROM util.notificationSubscription - WHERE notificationFk = ? AND userFk = ?`; - - await Self.rawSql(query, [notificationId, userId], myOptions); - - if (tx) await tx.commit(); - - return {success: true}; - } catch (error) { - if (tx) await tx.rollback(); - - throw error; - } - }; -}; diff --git a/back/models/notificationSubscription.js b/back/models/notificationSubscription.js index ce5d89e8b..83f52047b 100644 --- a/back/models/notificationSubscription.js +++ b/back/models/notificationSubscription.js @@ -1,3 +1,73 @@ +const UserError = require('vn-loopback/util/user-error'); + module.exports = Self => { - require('../methods/notification/deleteSubcription')(Self); + Self.observe('before save', async function(ctx) { + let models = Self.app.models; + let userId = ctx.options.accessToken.userId; + let modifiedUser = await models.Worker.findOne({ + fields: ['id', 'bossFk'], + where: { + id: ctx.instance.userFk + } + }); + + if (userId == modifiedUser.id || userId == modifiedUser.bossFk) + return; + else + throw new UserError('You dont have permission to modify this user'); + }); + + Self.remoteMethod('deleteNotification', { + description: 'Gets the current user data', + accepts: [ + { + arg: 'ctx', + type: 'object', + http: {source: 'context'} + }, + { + arg: 'userId', + type: 'string' + }, + { + arg: 'notificationId', + type: 'number' + }, + { + arg: 'authorId', + type: 'number' + } + ], + returns: { + type: 'object', + root: true + }, + http: { + verb: 'POST', + path: '/deleteNotification' + } + }); + + Self.deleteNotification = async function(ctx) { + let models = Self.app.models; + let user = await ctx.args.authorId; + let notificationId = await ctx.args.notificationId; + let userId = await ctx.args.userId; + let modifiedUser = await models.Worker.findOne({ + fields: ['id', 'bossFk'], + where: { + id: ctx.args.userId + } + }); + + if (user == modifiedUser.id || modifiedUser.bossFk == user) { + const query = `DELETE FROM util.notificationSubscription + WHERE notificationFk = ? AND userFk = ?`; + + await Self.rawSql(query, [notificationId, userId]); + + return; + } else + throw new UserError('You dont have permission to modify this user'); + }; }; diff --git a/back/models/notificationSubscription.json b/back/models/notificationSubscription.json index 11dbde6fb..43fa6db27 100644 --- a/back/models/notificationSubscription.json +++ b/back/models/notificationSubscription.json @@ -9,6 +9,7 @@ "properties": { "notificationFk": { "type": "number", + "id": true, "description": "Identifier" }, "userFk": { diff --git a/db/changes/230201/00-acl_notifications.sql b/db/changes/230201/00-acl_notifications.sql index ef710aca6..c206dd27f 100644 --- a/db/changes/230201/00-acl_notifications.sql +++ b/db/changes/230201/00-acl_notifications.sql @@ -1,3 +1,11 @@ - VALUES - ('NotificationSubscription','*','*','employee'), - ('NotificationAcl','*','*','employee'); \ No newline at end of file +INSERT INTO + `salix`.`ACL` ( + `model`, + `property`, + `accessType`, + `permission`, + `principalId` + ) +VALUES + ('NotificationSubscription', '*', '*', 'employee'), + ('NotificationAcl', '*', '*', 'employee'); \ No newline at end of file From 0a602892e6f32326bd1b6ee477e69db59b55a55f Mon Sep 17 00:00:00 2001 From: Pau Navarro Date: Tue, 27 Dec 2022 14:59:23 +0100 Subject: [PATCH 09/26] changed let to const and removed duplicate code --- back/models/notificationSubscription.js | 36 ++++++++++++------------- 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/back/models/notificationSubscription.js b/back/models/notificationSubscription.js index 83f52047b..811914634 100644 --- a/back/models/notificationSubscription.js +++ b/back/models/notificationSubscription.js @@ -2,14 +2,10 @@ const UserError = require('vn-loopback/util/user-error'); module.exports = Self => { Self.observe('before save', async function(ctx) { - let models = Self.app.models; - let userId = ctx.options.accessToken.userId; - let modifiedUser = await models.Worker.findOne({ - fields: ['id', 'bossFk'], - where: { - id: ctx.instance.userFk - } - }); + const models = Self.app.models; + const userId = ctx.options.accessToken.userId; + const user = await ctx.instance.userFk; + const modifiedUser = await getUserToModify(user, models); if (userId == modifiedUser.id || userId == modifiedUser.bossFk) return; @@ -49,16 +45,11 @@ module.exports = Self => { }); Self.deleteNotification = async function(ctx) { - let models = Self.app.models; - let user = await ctx.args.authorId; - let notificationId = await ctx.args.notificationId; - let userId = await ctx.args.userId; - let modifiedUser = await models.Worker.findOne({ - fields: ['id', 'bossFk'], - where: { - id: ctx.args.userId - } - }); + const models = Self.app.models; + const user = await ctx.args.authorId; + const notificationId = await ctx.args.notificationId; + const userId = await ctx.args.userId; + const modifiedUser = await getUserToModify(userId, models); if (user == modifiedUser.id || modifiedUser.bossFk == user) { const query = `DELETE FROM util.notificationSubscription @@ -70,4 +61,13 @@ module.exports = Self => { } else throw new UserError('You dont have permission to modify this user'); }; + + async function getUserToModify(user, models) { + return await models.Worker.findOne({ + fields: ['id', 'bossFk'], + where: { + id: user + } + }); + } }; From a55d00765581e2dd0b686c2dfdf533116b8bd420 Mon Sep 17 00:00:00 2001 From: Pau Navarro Date: Tue, 3 Jan 2023 08:12:46 +0100 Subject: [PATCH 10/26] requested changes --- back/models/notificationSubscription.js | 20 +++++++------------- db/changes/230201/00-acl_notifications.sql | 15 ++++----------- 2 files changed, 11 insertions(+), 24 deletions(-) diff --git a/back/models/notificationSubscription.js b/back/models/notificationSubscription.js index 811914634..26fcc04df 100644 --- a/back/models/notificationSubscription.js +++ b/back/models/notificationSubscription.js @@ -14,7 +14,7 @@ module.exports = Self => { }); Self.remoteMethod('deleteNotification', { - description: 'Gets the current user data', + description: 'Deletes a notification subscription', accepts: [ { arg: 'ctx', @@ -22,15 +22,11 @@ module.exports = Self => { http: {source: 'context'} }, { - arg: 'userId', + arg: 'userFk', type: 'string' }, { - arg: 'notificationId', - type: 'number' - }, - { - arg: 'authorId', + arg: 'notificationFk', type: 'number' } ], @@ -44,18 +40,16 @@ module.exports = Self => { } }); - Self.deleteNotification = async function(ctx) { + Self.deleteNotification = async function(ctx, userFk, notificationFk) { const models = Self.app.models; - const user = await ctx.args.authorId; - const notificationId = await ctx.args.notificationId; - const userId = await ctx.args.userId; - const modifiedUser = await getUserToModify(userId, models); + const user = ctx.req.accessToken.userId; + const modifiedUser = await getUserToModify(userFk, models); if (user == modifiedUser.id || modifiedUser.bossFk == user) { const query = `DELETE FROM util.notificationSubscription WHERE notificationFk = ? AND userFk = ?`; - await Self.rawSql(query, [notificationId, userId]); + await Self.rawSql(query, [notificationFk, userFk]); return; } else diff --git a/db/changes/230201/00-acl_notifications.sql b/db/changes/230201/00-acl_notifications.sql index c206dd27f..4b86e2cd0 100644 --- a/db/changes/230201/00-acl_notifications.sql +++ b/db/changes/230201/00-acl_notifications.sql @@ -1,11 +1,4 @@ -INSERT INTO - `salix`.`ACL` ( - `model`, - `property`, - `accessType`, - `permission`, - `principalId` - ) -VALUES - ('NotificationSubscription', '*', '*', 'employee'), - ('NotificationAcl', '*', '*', 'employee'); \ No newline at end of file +INSERT INTO `salix`.`ACL` (model,property,accessType,principalId) + VALUES ('NotificationSubscription','*','*','employee'); +INSERT INTO `salix`.`ACL` (model,property,accessType,principalId) + VALUES ('NotificationAcl','*','*','employee'); From 24b8b172b9d3f361414798cde012e27d2b8be131 Mon Sep 17 00:00:00 2001 From: Pau Navarro Date: Thu, 5 Jan 2023 14:13:42 +0100 Subject: [PATCH 11/26] use notification id --- back/models/notificationSubscription.js | 44 ++++++++++++----------- back/models/notificationSubscription.json | 11 +++--- db/dump/structure.sql | 3 +- 3 files changed, 33 insertions(+), 25 deletions(-) diff --git a/back/models/notificationSubscription.js b/back/models/notificationSubscription.js index 26fcc04df..77ef8ffbe 100644 --- a/back/models/notificationSubscription.js +++ b/back/models/notificationSubscription.js @@ -22,13 +22,10 @@ module.exports = Self => { http: {source: 'context'} }, { - arg: 'userFk', - type: 'string' + arg: 'notificationId', + type: 'number', + required: true }, - { - arg: 'notificationFk', - type: 'number' - } ], returns: { type: 'object', @@ -40,28 +37,35 @@ module.exports = Self => { } }); - Self.deleteNotification = async function(ctx, userFk, notificationFk) { + Self.deleteNotification = async function(ctx, notificationId) { const models = Self.app.models; const user = ctx.req.accessToken.userId; - const modifiedUser = await getUserToModify(userFk, models); + const modifiedUser = await getUserToModify(notificationId, models); if (user == modifiedUser.id || modifiedUser.bossFk == user) { - const query = `DELETE FROM util.notificationSubscription - WHERE notificationFk = ? AND userFk = ?`; - - await Self.rawSql(query, [notificationFk, userFk]); - + await models.NotificationSubscription.destroyById(notificationId); return; } else throw new UserError('You dont have permission to modify this user'); }; - async function getUserToModify(user, models) { - return await models.Worker.findOne({ - fields: ['id', 'bossFk'], - where: { - id: user - } - }); + async function getUserToModify(notificationId = null, userFk = null, models) { + if (notificationId != null) { + const subscription = await models.NotificationSubscription.findById(notificationId); + const user = await subscription.userFk; + return await models.Worker.findOne({ + fields: ['id', 'bossFk'], + where: { + id: user + } + }); + } else { + return await models.Worker.findOne({ + fields: ['id', 'bossFk'], + where: { + id: userFk + } + }); + } } }; diff --git a/back/models/notificationSubscription.json b/back/models/notificationSubscription.json index 43fa6db27..a640e0917 100644 --- a/back/models/notificationSubscription.json +++ b/back/models/notificationSubscription.json @@ -7,15 +7,18 @@ } }, "properties": { - "notificationFk": { + "id": { "type": "number", "id": true, - "description": "Identifier" + "description": "Primary key" + }, + "notificationFk": { + "type": "number", + "description": "Foreign key to Notification" }, "userFk": { "type": "number", - "id": true, - "description": "Identifier" + "description": "Foreign key to Account" } }, "relations": { diff --git a/db/dump/structure.sql b/db/dump/structure.sql index 47fdd6d74..510a51d94 100644 --- a/db/dump/structure.sql +++ b/db/dump/structure.sql @@ -19726,9 +19726,10 @@ 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, `notificationFk` int(11) NOT NULL, `userFk` int(10) unsigned NOT NULL, - PRIMARY KEY (`notificationFk`,`userFk`), + PRIMARY KEY (`Id`), 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 From 3b69d76525b604cd81a72cdaf58d9d88888f83b7 Mon Sep 17 00:00:00 2001 From: Pau Navarro Date: Mon, 9 Jan 2023 08:43:11 +0100 Subject: [PATCH 12/26] fix error preventing subscriptions --- back/models/notificationSubscription.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/back/models/notificationSubscription.js b/back/models/notificationSubscription.js index 77ef8ffbe..eafa9d51b 100644 --- a/back/models/notificationSubscription.js +++ b/back/models/notificationSubscription.js @@ -5,7 +5,7 @@ module.exports = Self => { const models = Self.app.models; const userId = ctx.options.accessToken.userId; const user = await ctx.instance.userFk; - const modifiedUser = await getUserToModify(user, models); + const modifiedUser = await getUserToModify(null, user, models); if (userId == modifiedUser.id || userId == modifiedUser.bossFk) return; @@ -40,7 +40,7 @@ module.exports = Self => { Self.deleteNotification = async function(ctx, notificationId) { const models = Self.app.models; const user = ctx.req.accessToken.userId; - const modifiedUser = await getUserToModify(notificationId, models); + const modifiedUser = await getUserToModify(notificationId, null, models); if (user == modifiedUser.id || modifiedUser.bossFk == user) { await models.NotificationSubscription.destroyById(notificationId); From cc806cc08feaccc361a41850c9ee141696c86536 Mon Sep 17 00:00:00 2001 From: Pau Navarro Date: Wed, 18 Jan 2023 07:41:10 +0100 Subject: [PATCH 13/26] 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 From a5f83021dba3848bbb009c7cd86f3b658544d681 Mon Sep 17 00:00:00 2001 From: Pau Navarro Date: Wed, 18 Jan 2023 09:06:17 +0100 Subject: [PATCH 14/26] requested changes --- back/models/notificationSubscription.js | 24 +++++++------------ .../00-uniqueKeyNotificationSubscription.sql | 4 ++++ 2 files changed, 13 insertions(+), 15 deletions(-) create mode 100644 db/changes/230201/00-uniqueKeyNotificationSubscription.sql diff --git a/back/models/notificationSubscription.js b/back/models/notificationSubscription.js index 674629413..f1b2811fa 100644 --- a/back/models/notificationSubscription.js +++ b/back/models/notificationSubscription.js @@ -47,22 +47,16 @@ module.exports = Self => { }; async function getUserToModify(notificationId, userFk, models) { - if (notificationId != null) { + let userToModify = userFk; + if (notificationId) { const subscription = await models.NotificationSubscription.findById(notificationId); - const user = await subscription.userFk; - return await models.Worker.findOne({ - fields: ['id', 'bossFk'], - where: { - id: user - } - }); - } else { - return await models.Worker.findOne({ - fields: ['id', 'bossFk'], - where: { - id: userFk - } - }); + userToModify = subscription.userFk; } + return await models.Worker.findOne({ + fields: ['id', 'bossFk'], + where: { + id: userToModify + } + }); } }; diff --git a/db/changes/230201/00-uniqueKeyNotificationSubscription.sql b/db/changes/230201/00-uniqueKeyNotificationSubscription.sql new file mode 100644 index 000000000..623ecf770 --- /dev/null +++ b/db/changes/230201/00-uniqueKeyNotificationSubscription.sql @@ -0,0 +1,4 @@ +ALTER TABLE + `util`.`notificationSubscription` +ADD + CONSTRAINT `notificationSubscription_UN` UNIQUE KEY (`notificationFk`, `userFk`); \ No newline at end of file From a425d54bf6bbcfe0294854ffb88e3a2e552728b3 Mon Sep 17 00:00:00 2001 From: Pau Navarro Date: Wed, 18 Jan 2023 12:16:47 +0100 Subject: [PATCH 15/26] add back test --- .../specs/notificationSubscription.spec.js | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 back/models/specs/notificationSubscription.spec.js diff --git a/back/models/specs/notificationSubscription.spec.js b/back/models/specs/notificationSubscription.spec.js new file mode 100644 index 000000000..bcb1db9d8 --- /dev/null +++ b/back/models/specs/notificationSubscription.spec.js @@ -0,0 +1,22 @@ +const app = require('vn-loopback/server/server'); + +describe('loopback model NotificationSubscription', () => { + it('Should fail to delete a notification if the user is not editing itself or a subordinate', async() => { + const user = 9; + const notificationSubscriptionId = 2; + const ctx = {req: {accessToken: {userId: user}}}; + const models = app.models; + const notification = await models.NotificationSubscription.findById(notificationSubscriptionId); + + let error; + + try { + await models.NotificationSubscription.deleteNotification(ctx, notification.id); + } catch (e) { + error = e; + } + + expect(error.message).toContain('You dont have permission to modify this user'); + }); +}); + From 5a19e5801f9af4a12d0f7b9cdcc3daa0c92e28a7 Mon Sep 17 00:00:00 2001 From: vicent Date: Mon, 23 Jan 2023 11:50:54 +0100 Subject: [PATCH 16/26] fix: enabled button when an error occurs --- front/core/components/smart-table/index.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/front/core/components/smart-table/index.js b/front/core/components/smart-table/index.js index 770dcdf32..24d121aac 100644 --- a/front/core/components/smart-table/index.js +++ b/front/core/components/smart-table/index.js @@ -589,7 +589,8 @@ export default class SmartTable extends Component { refresh() { this.isRefreshing = true; this.model.refresh() - .then(() => this.isRefreshing = false); + .then(() => this.isRefreshing = false) + .catch(() => this.isRefreshing = false); } } From 9eb65507b5d165f80fb39a3a798613c4137c23d9 Mon Sep 17 00:00:00 2001 From: vicent Date: Mon, 23 Jan 2023 14:43:31 +0100 Subject: [PATCH 17/26] fix: elimino this.model.refresh que siempre daba fallo --- front/core/components/smart-table/index.js | 3 --- 1 file changed, 3 deletions(-) diff --git a/front/core/components/smart-table/index.js b/front/core/components/smart-table/index.js index 24d121aac..79c5c17c8 100644 --- a/front/core/components/smart-table/index.js +++ b/front/core/components/smart-table/index.js @@ -231,7 +231,6 @@ export default class SmartTable extends Component { } this.model.order = order; - this.refresh(); } registerColumns() { @@ -479,7 +478,6 @@ export default class SmartTable extends Component { const params = {q: JSON.stringify(stateFilter)}; this.$state.go(this.$state.current.name, params, {location: 'replace'}); - this.refresh(); } applySort() { @@ -500,7 +498,6 @@ export default class SmartTable extends Component { const params = {q: JSON.stringify(stateFilter)}; this.$state.go(this.$state.current.name, params, {location: 'replace'}); - this.refresh(); } filterSanitizer(field) { From c13bffcc573817e7b4e075f7fd872b40df330ceb Mon Sep 17 00:00:00 2001 From: Pau Navarro Date: Tue, 24 Jan 2023 10:11:16 +0100 Subject: [PATCH 18/26] refs #4797 @1h requested changes --- .../specs/notificationSubscription.spec.js | 78 +++++++++++++++---- .../00-acl_notifications.sql | 0 db/changes/230401/00-alter_notSubs.sql | 10 +++ db/dump/fixtures.sql | 5 +- 4 files changed, 79 insertions(+), 14 deletions(-) rename db/changes/{230201 => 230401}/00-acl_notifications.sql (100%) create mode 100644 db/changes/230401/00-alter_notSubs.sql diff --git a/back/models/specs/notificationSubscription.spec.js b/back/models/specs/notificationSubscription.spec.js index bcb1db9d8..b1a54e0c2 100644 --- a/back/models/specs/notificationSubscription.spec.js +++ b/back/models/specs/notificationSubscription.spec.js @@ -1,22 +1,74 @@ -const app = require('vn-loopback/server/server'); +const models = require('vn-loopback/server/server').models; describe('loopback model NotificationSubscription', () => { it('Should fail to delete a notification if the user is not editing itself or a subordinate', async() => { - const user = 9; - const notificationSubscriptionId = 2; - const ctx = {req: {accessToken: {userId: user}}}; - const models = app.models; - const notification = await models.NotificationSubscription.findById(notificationSubscriptionId); - - let error; + const tx = await models.NotificationSubscription.beginTransaction({}); try { - await models.NotificationSubscription.deleteNotification(ctx, notification.id); - } catch (e) { - error = e; - } + const options = {transaction: tx}; + const user = 9; + const notificationSubscriptionId = 2; + const ctx = {req: {accessToken: {userId: user}}}; + const notification = await models.NotificationSubscription.findById(notificationSubscriptionId); - expect(error.message).toContain('You dont have permission to modify this user'); + let error; + + try { + await models.NotificationSubscription.deleteNotification(ctx, notification.id, options); + } catch (e) { + error = e; + } + + expect(error.message).toContain('You dont have permission to modify this user'); + await tx.rollback(); + } catch (e) { + await tx.rollback(); + throw e; + } + }); + + it('Should delete a notification if the user is editing itself', async() => { + const tx = await models.NotificationSubscription.beginTransaction({}); + + try { + const options = {transaction: tx}; + const user = 9; + const notificationSubscriptionId = 5; + const ctx = {req: {accessToken: {userId: user}}}; + const notification = await models.NotificationSubscription.findById(notificationSubscriptionId); + + await models.NotificationSubscription.deleteNotification(ctx, notification.id, options); + + const deletedNotification = await models.NotificationSubscription.findById(notificationSubscriptionId); + + expect(deletedNotification).toBeNull(); + await tx.rollback(); + } catch (e) { + await tx.rollback(); + throw e; + } + }); + + it('Should delete a notification if the user is editing a subordinate', async() => { + const tx = await models.NotificationSubscription.beginTransaction({}); + + try { + const options = {transaction: tx}; + const user = 9; + const notificationSubscriptionId = 6; + const ctx = {req: {accessToken: {userId: user}}}; + const notification = await models.NotificationSubscription.findById(notificationSubscriptionId); + + await models.NotificationSubscription.deleteNotification(ctx, notification.id, options); + + const deletedNotification = await models.NotificationSubscription.findById(notificationSubscriptionId); + + expect(deletedNotification).toBeNull(); + await tx.rollback(); + } catch (e) { + await tx.rollback(); + throw e; + } }); }); diff --git a/db/changes/230201/00-acl_notifications.sql b/db/changes/230401/00-acl_notifications.sql similarity index 100% rename from db/changes/230201/00-acl_notifications.sql rename to db/changes/230401/00-acl_notifications.sql diff --git a/db/changes/230401/00-alter_notSubs.sql b/db/changes/230401/00-alter_notSubs.sql new file mode 100644 index 000000000..3ead323b0 --- /dev/null +++ b/db/changes/230401/00-alter_notSubs.sql @@ -0,0 +1,10 @@ +CREATE OR REPLACE TABLE `util`.`notificationSubscription` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `notificationFk` int(11) NOT NULL, + `userFk` int(10) unsigned NOT NULL, + 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 +) ENGINE=InnoDB DEFAULT CHARSET=utf8; diff --git a/db/dump/fixtures.sql b/db/dump/fixtures.sql index 0783a06df..bb4f00ff5 100644 --- a/db/dump/fixtures.sql +++ b/db/dump/fixtures.sql @@ -2701,7 +2701,10 @@ INSERT INTO `util`.`notificationSubscription` (`notificationFk`, `userFk`) VALUES (1, 1109), (1, 1110), - (3, 1109); + (3, 1109), + (1,9), + (1,3); + INSERT INTO `vn`.`routeConfig` (`id`, `defaultWorkCenterFk`) VALUES From a2150b8b080cb62a207d05d4eb2e37c143d0fc1d Mon Sep 17 00:00:00 2001 From: Pau Navarro Date: Tue, 24 Jan 2023 10:15:32 +0100 Subject: [PATCH 19/26] change test to adhere to the fixtures --- back/models/specs/notificationSubscription.spec.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/back/models/specs/notificationSubscription.spec.js b/back/models/specs/notificationSubscription.spec.js index b1a54e0c2..c7f37abed 100644 --- a/back/models/specs/notificationSubscription.spec.js +++ b/back/models/specs/notificationSubscription.spec.js @@ -33,7 +33,7 @@ describe('loopback model NotificationSubscription', () => { try { const options = {transaction: tx}; const user = 9; - const notificationSubscriptionId = 5; + const notificationSubscriptionId = 4; const ctx = {req: {accessToken: {userId: user}}}; const notification = await models.NotificationSubscription.findById(notificationSubscriptionId); @@ -55,7 +55,7 @@ describe('loopback model NotificationSubscription', () => { try { const options = {transaction: tx}; const user = 9; - const notificationSubscriptionId = 6; + const notificationSubscriptionId = 5; const ctx = {req: {accessToken: {userId: user}}}; const notification = await models.NotificationSubscription.findById(notificationSubscriptionId); From 5a70fd4779d3c2bcd850c719b34761b8e0e32d0d Mon Sep 17 00:00:00 2001 From: vicent Date: Tue, 24 Jan 2023 14:45:35 +0100 Subject: [PATCH 20/26] fix: las peticiones no colisionan --- front/core/components/smart-table/index.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/front/core/components/smart-table/index.js b/front/core/components/smart-table/index.js index 79c5c17c8..416d24d16 100644 --- a/front/core/components/smart-table/index.js +++ b/front/core/components/smart-table/index.js @@ -231,6 +231,7 @@ export default class SmartTable extends Component { } this.model.order = order; + this.refresh(); } registerColumns() { @@ -477,7 +478,8 @@ export default class SmartTable extends Component { const params = {q: JSON.stringify(stateFilter)}; - this.$state.go(this.$state.current.name, params, {location: 'replace'}); + this.$state.go(this.$state.current.name, params, {location: 'replace'}) + .then(() => this.refresh()); } applySort() { @@ -497,7 +499,8 @@ export default class SmartTable extends Component { stateFilter.tableOrder = order; const params = {q: JSON.stringify(stateFilter)}; - this.$state.go(this.$state.current.name, params, {location: 'replace'}); + this.$state.go(this.$state.current.name, params, {location: 'replace'}) + .then(() => this.refresh()); } filterSanitizer(field) { From 51400b1c747e1cf9e1e2552c2e241de7dadb60e1 Mon Sep 17 00:00:00 2001 From: vicent Date: Thu, 26 Jan 2023 08:19:52 +0100 Subject: [PATCH 21/26] =?UTF-8?q?reactor:=20eliminado=20try=20y=20catch,?= =?UTF-8?q?=20y=20a=C3=B1adido=20finally?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- front/core/components/smart-table/index.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/front/core/components/smart-table/index.js b/front/core/components/smart-table/index.js index 416d24d16..ad9883950 100644 --- a/front/core/components/smart-table/index.js +++ b/front/core/components/smart-table/index.js @@ -589,8 +589,7 @@ export default class SmartTable extends Component { refresh() { this.isRefreshing = true; this.model.refresh() - .then(() => this.isRefreshing = false) - .catch(() => this.isRefreshing = false); + .finally(() => this.isRefreshing = false); } } From 3184dcd39d8d51974b9c62dd9e41035eb0ba891c Mon Sep 17 00:00:00 2001 From: Pau Navarro Date: Thu, 26 Jan 2023 08:41:12 +0100 Subject: [PATCH 22/26] requested changes --- db/changes/230401/00-acl_notifications.sql | 6 +++--- db/changes/230401/00-alter_notSubs.sql | 14 ++++---------- db/dump/structure.sql | 3 +-- 3 files changed, 8 insertions(+), 15 deletions(-) diff --git a/db/changes/230401/00-acl_notifications.sql b/db/changes/230401/00-acl_notifications.sql index 4b86e2cd0..ab40b16a5 100644 --- a/db/changes/230401/00-acl_notifications.sql +++ b/db/changes/230401/00-acl_notifications.sql @@ -1,4 +1,4 @@ INSERT INTO `salix`.`ACL` (model,property,accessType,principalId) - VALUES ('NotificationSubscription','*','*','employee'); -INSERT INTO `salix`.`ACL` (model,property,accessType,principalId) - VALUES ('NotificationAcl','*','*','employee'); + VALUES + ('NotificationSubscription','*','*','employee'), + ('NotificationAcl','*','READ','employee'); diff --git a/db/changes/230401/00-alter_notSubs.sql b/db/changes/230401/00-alter_notSubs.sql index 3ead323b0..a4177bba4 100644 --- a/db/changes/230401/00-alter_notSubs.sql +++ b/db/changes/230401/00-alter_notSubs.sql @@ -1,10 +1,4 @@ -CREATE OR REPLACE TABLE `util`.`notificationSubscription` ( - `id` int(11) NOT NULL AUTO_INCREMENT, - `notificationFk` int(11) NOT NULL, - `userFk` int(10) unsigned NOT NULL, - 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 -) ENGINE=InnoDB DEFAULT CHARSET=utf8; +ALTER TABLE util.notificationSubscription +ADD Id int(11) auto_increment NULL, +DROP PRIMARY KEY, +ADD CONSTRAINT PRIMARY KEY (Id); diff --git a/db/dump/structure.sql b/db/dump/structure.sql index 97d7603f6..831296bc6 100644 --- a/db/dump/structure.sql +++ b/db/dump/structure.sql @@ -19726,10 +19726,9 @@ 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, `notificationFk` int(11) NOT NULL, `userFk` int(10) unsigned NOT NULL, - PRIMARY KEY (`id`), + PRIMARY KEY (`notificationFk`,`userFk`), 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, From 650cc68f4a789e427cecb1a87941e915e581823b Mon Sep 17 00:00:00 2001 From: Pau Navarro Date: Wed, 1 Feb 2023 08:42:20 +0100 Subject: [PATCH 23/26] requested changes --- db/changes/230401/00-alter_notSubs.sql | 4 ++-- .../00-uniqueKeyNotificationSubscription.sql | 0 2 files changed, 2 insertions(+), 2 deletions(-) rename db/changes/{230201 => 230401}/00-uniqueKeyNotificationSubscription.sql (100%) diff --git a/db/changes/230401/00-alter_notSubs.sql b/db/changes/230401/00-alter_notSubs.sql index a4177bba4..992675837 100644 --- a/db/changes/230401/00-alter_notSubs.sql +++ b/db/changes/230401/00-alter_notSubs.sql @@ -1,4 +1,4 @@ ALTER TABLE util.notificationSubscription -ADD Id int(11) auto_increment NULL, +ADD id int(11) auto_increment NULL, DROP PRIMARY KEY, -ADD CONSTRAINT PRIMARY KEY (Id); +ADD CONSTRAINT PRIMARY KEY (id); diff --git a/db/changes/230201/00-uniqueKeyNotificationSubscription.sql b/db/changes/230401/00-uniqueKeyNotificationSubscription.sql similarity index 100% rename from db/changes/230201/00-uniqueKeyNotificationSubscription.sql rename to db/changes/230401/00-uniqueKeyNotificationSubscription.sql From 56f7794d87f632152bc1a6547efa21b2f6519cbb Mon Sep 17 00:00:00 2001 From: alexm Date: Wed, 1 Feb 2023 08:48:47 +0100 Subject: [PATCH 24/26] typo --- db/changes/230401/00-alter_notSubs.sql | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/db/changes/230401/00-alter_notSubs.sql b/db/changes/230401/00-alter_notSubs.sql index 992675837..9cbfcbb3c 100644 --- a/db/changes/230401/00-alter_notSubs.sql +++ b/db/changes/230401/00-alter_notSubs.sql @@ -1,4 +1,4 @@ -ALTER TABLE util.notificationSubscription -ADD id int(11) auto_increment NULL, -DROP PRIMARY KEY, -ADD CONSTRAINT PRIMARY KEY (id); +ALTER TABLE `util`.`notificationSubscription` +ADD `id` int(11) auto_increment NULL, +DROP PRIMARY KEY, +ADD CONSTRAINT PRIMARY KEY (`id`); From 39d4b538723fcd698b209d87b8cece3212ddad6c Mon Sep 17 00:00:00 2001 From: alexm Date: Wed, 1 Feb 2023 09:00:49 +0100 Subject: [PATCH 25/26] fix: sql fail in real structure... --- .../230401/{00-alter_notSubs.sql => 01-alter_notSubs.sql} | 3 +++ db/dump/structure.sql | 1 - 2 files changed, 3 insertions(+), 1 deletion(-) rename db/changes/230401/{00-alter_notSubs.sql => 01-alter_notSubs.sql} (55%) diff --git a/db/changes/230401/00-alter_notSubs.sql b/db/changes/230401/01-alter_notSubs.sql similarity index 55% rename from db/changes/230401/00-alter_notSubs.sql rename to db/changes/230401/01-alter_notSubs.sql index 9cbfcbb3c..07ea7c2bf 100644 --- a/db/changes/230401/00-alter_notSubs.sql +++ b/db/changes/230401/01-alter_notSubs.sql @@ -2,3 +2,6 @@ ALTER TABLE `util`.`notificationSubscription` ADD `id` int(11) auto_increment NULL, DROP PRIMARY KEY, ADD CONSTRAINT PRIMARY KEY (`id`); + +ALTER TABLE `util`.`notificationSubscription` +ADD KEY `notificationSubscription_ibfk_1` (`notificationFk`); diff --git a/db/dump/structure.sql b/db/dump/structure.sql index 831296bc6..772d6055d 100644 --- a/db/dump/structure.sql +++ b/db/dump/structure.sql @@ -19729,7 +19729,6 @@ CREATE TABLE `notificationSubscription` ( `notificationFk` int(11) NOT NULL, `userFk` int(10) unsigned NOT NULL, PRIMARY KEY (`notificationFk`,`userFk`), - 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 From 15429293dd19fdba7f8d9f3573679fbdc24d728a Mon Sep 17 00:00:00 2001 From: vicent Date: Thu, 2 Feb 2023 11:34:13 +0100 Subject: [PATCH 26/26] fix: frontTest --- front/core/components/smart-table/index.spec.js | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/front/core/components/smart-table/index.spec.js b/front/core/components/smart-table/index.spec.js index 5fd4c33b7..5a1be98e1 100644 --- a/front/core/components/smart-table/index.spec.js +++ b/front/core/components/smart-table/index.spec.js @@ -160,7 +160,7 @@ describe('Component smartTable', () => { describe('applySort()', () => { it('should call the $state go and model refresh without making changes on the model order', () => { controller.$state = { - go: jest.fn(), + go: jest.fn().mockReturnValue(new Promise(resolve => resolve())), current: { name: 'section' } @@ -171,13 +171,12 @@ describe('Component smartTable', () => { expect(controller.model.order).toBeUndefined(); expect(controller.$state.go).toHaveBeenCalled(); - expect(controller.refresh).toHaveBeenCalled(); }); it('should call the $state go and model refresh after setting model order according to the controller sortCriteria', () => { const orderBy = {field: 'myField', sortType: 'ASC'}; controller.$state = { - go: jest.fn(), + go: jest.fn().mockReturnValue(new Promise(resolve => resolve())), current: { name: 'section' } @@ -190,7 +189,6 @@ describe('Component smartTable', () => { expect(controller.model.order).toEqual(`${orderBy.field} ${orderBy.sortType}`); expect(controller.$state.go).toHaveBeenCalled(); - expect(controller.refresh).toHaveBeenCalled(); }); }); @@ -293,12 +291,10 @@ describe('Component smartTable', () => { controller.$inputsScope = { searchProps: {} }; - jest.spyOn(controller, 'refresh'); controller.defaultFilter(); expect(controller.model.addFilter).toHaveBeenCalled(); - expect(controller.refresh).toHaveBeenCalled(); }); });