From 32f28e91b53692df7817a8b058a501b08a91aaf0 Mon Sep 17 00:00:00 2001 From: vicent Date: Tue, 22 Nov 2022 14:29:42 +0100 Subject: [PATCH 01/10] feat: sistema de bloque para ficheros mdb --- db/changes/10503-november/00-aclMdbApp.sql | 4 ++ db/changes/10503-november/00-mdbApp.sql | 11 ++++ db/dump/fixtures.sql | 5 ++ loopback/locale/en.json | 3 +- loopback/locale/es.json | 3 +- modules/mdb/back/methods/mdbApp/lock.js | 56 +++++++++++++++++++ modules/mdb/back/methods/mdbApp/unlock.js | 55 ++++++++++++++++++ modules/mdb/back/methods/mdbVersion/upload.js | 22 +++++++- modules/mdb/back/model-config.json | 3 + modules/mdb/back/models/mdbApp.js | 4 ++ modules/mdb/back/models/mdbApp.json | 31 ++++++++++ 11 files changed, 192 insertions(+), 5 deletions(-) create mode 100644 db/changes/10503-november/00-aclMdbApp.sql create mode 100644 db/changes/10503-november/00-mdbApp.sql create mode 100644 modules/mdb/back/methods/mdbApp/lock.js create mode 100644 modules/mdb/back/methods/mdbApp/unlock.js create mode 100644 modules/mdb/back/models/mdbApp.js create mode 100644 modules/mdb/back/models/mdbApp.json diff --git a/db/changes/10503-november/00-aclMdbApp.sql b/db/changes/10503-november/00-aclMdbApp.sql new file mode 100644 index 000000000..b5b60546c --- /dev/null +++ b/db/changes/10503-november/00-aclMdbApp.sql @@ -0,0 +1,4 @@ +INSERT INTO `salix`.`ACL` (`model`, `property`, `accessType`, `permission`, `principalType`, `principalId`) + VALUES + ('MdbApp', 'lock', 'WRITE', 'ALLOW', 'ROLE', 'developer'), + ('MdbApp', 'unlock', 'WRITE', 'ALLOW', 'ROLE', 'developer'); diff --git a/db/changes/10503-november/00-mdbApp.sql b/db/changes/10503-november/00-mdbApp.sql new file mode 100644 index 000000000..3b242c9ab --- /dev/null +++ b/db/changes/10503-november/00-mdbApp.sql @@ -0,0 +1,11 @@ +CREATE TABLE `vn`.`mdbApp` ( + `app` varchar(100) COLLATE utf8mb3_unicode_ci DEFAULT NULL, + `baselineBranchFk` varchar(255) COLLATE utf8mb3_unicode_ci DEFAULT NULL, + `userFk` int(10) unsigned DEFAULT NULL, + `locked` datetime DEFAULT NULL, + UNIQUE KEY `app_UN` (`app`), + KEY `mdbApp_FK` (`userFk`), + KEY `mdbApp_FK_1` (`baselineBranchFk`), + CONSTRAINT `mdbApp_FK` FOREIGN KEY (`userFk`) REFERENCES `account`.`user` (`id`) ON DELETE SET NULL ON UPDATE CASCADE, + CONSTRAINT `mdbApp_FK_1` FOREIGN KEY (`baselineBranchFk`) REFERENCES `mdbBranch` (`name`) ON UPDATE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; diff --git a/db/dump/fixtures.sql b/db/dump/fixtures.sql index 11e1453a9..43070b990 100644 --- a/db/dump/fixtures.sql +++ b/db/dump/fixtures.sql @@ -2731,3 +2731,8 @@ UPDATE `account`.`user` INSERT INTO `vn`.`osTicketConfig` (`id`, `host`, `user`, `password`, `oldStatus`, `newStatusId`, `day`, `comment`, `hostDb`, `userDb`, `passwordDb`, `portDb`, `responseType`, `fromEmailId`, `replyTo`) VALUES (0, 'http://localhost:56596/scp', 'ostadmin', 'Admin1', 'open', 3, 60, 'Este CAU se ha cerrado automáticamente. Si el problema persiste responda a este mensaje.', 'localhost', 'osticket', 'osticket', 40003, 'reply', 1, 'all'); + +INSERT INTO `vn`.`mdbApp` (`app`, `baselineBranchFk`, `userFk`, `locked`) + VALUES + ('com', 'master', NULL, NULL), + ('ent', 'test', NULL, NULL); diff --git a/loopback/locale/en.json b/loopback/locale/en.json index 36da9f661..0fce94d36 100644 --- a/loopback/locale/en.json +++ b/loopback/locale/en.json @@ -138,5 +138,6 @@ "You don't have grant privilege": "You don't have grant privilege", "You don't own the role and you can't assign it to another user": "You don't own the role and you can't assign it to another user", "Ticket merged": "Ticket [{{id}}]({{{fullPath}}}) ({{{originDated}}}) merged with [{{tfId}}]({{{fullPathFuture}}}) ({{{futureDated}}})", - "Sale(s) blocked, please contact production": "Sale(s) blocked, please contact production" + "Sale(s) blocked, please contact production": "Sale(s) blocked, please contact production", + "App locked": "App locked by user {{userId}}" } diff --git a/loopback/locale/es.json b/loopback/locale/es.json index 747007713..801404eab 100644 --- a/loopback/locale/es.json +++ b/loopback/locale/es.json @@ -244,5 +244,6 @@ "Ticket merged": "Ticket [{{id}}]({{{fullPath}}}) ({{{originDated}}}) fusionado con [{{tfId}}]({{{fullPathFuture}}}) ({{{futureDated}}})", "Already has this status": "Ya tiene este estado", "There aren't records for this week": "No existen registros para esta semana", - "Empty data source": "Origen de datos vacio" + "Empty data source": "Origen de datos vacio", + "App locked": "Aplicación bloquada por el usuario {{userId}}" } diff --git a/modules/mdb/back/methods/mdbApp/lock.js b/modules/mdb/back/methods/mdbApp/lock.js new file mode 100644 index 000000000..5fcd0604e --- /dev/null +++ b/modules/mdb/back/methods/mdbApp/lock.js @@ -0,0 +1,56 @@ +module.exports = Self => { + Self.remoteMethodCtx('lock', { + description: 'Lock an app for the user', + accessType: 'WRITE', + accepts: [ + { + arg: 'appName', + type: 'string', + required: true, + description: 'The app name', + http: {source: 'path'} + + } + ], + returns: { + type: ['object'], + root: true + }, + http: { + path: `/:appName/lock`, + verb: 'POST' + } + }); + + Self.lock = async(ctx, appName, options) => { + const models = Self.app.models; + const userId = ctx.req.accessToken.userId; + const myOptions = {}; + + let tx; + + if (typeof options == 'object') + Object.assign(myOptions, options); + + if (!myOptions.transaction) { + tx = await Self.beginTransaction({}); + myOptions.transaction = tx; + } + + try { + const mdbApp = await models.MdbApp.findById(appName, null, myOptions); + const updatedMdbApp = await mdbApp.updateAttributes({ + userFk: userId, + locked: new Date() + }, myOptions); + + if (tx) await tx.commit(); + + return updatedMdbApp; + } catch (e) { + if (tx) await tx.rollback(); + + throw e; + } + }; +}; diff --git a/modules/mdb/back/methods/mdbApp/unlock.js b/modules/mdb/back/methods/mdbApp/unlock.js new file mode 100644 index 000000000..7c6f88ec2 --- /dev/null +++ b/modules/mdb/back/methods/mdbApp/unlock.js @@ -0,0 +1,55 @@ +module.exports = Self => { + Self.remoteMethodCtx('unlock', { + description: 'Unlock an app for the user', + accessType: 'WRITE', + accepts: [ + { + arg: 'appName', + type: 'string', + required: true, + description: 'The app name', + http: {source: 'path'} + + } + ], + returns: { + type: ['object'], + root: true + }, + http: { + path: `/:appName/unlock`, + verb: 'POST' + } + }); + + Self.unlock = async(appName, options) => { + const models = Self.app.models; + const myOptions = {}; + + let tx; + + if (typeof options == 'object') + Object.assign(myOptions, options); + + if (!myOptions.transaction) { + tx = await Self.beginTransaction({}); + myOptions.transaction = tx; + } + + try { + const mdbApp = await models.MdbApp.findById(appName, null, myOptions); + const updatedMdbApp = await mdbApp.updateAttributes({ + userFk: null, + locked: null + }, myOptions); + + if (tx) await tx.commit(); + + return updatedMdbApp; + } catch (e) { + if (tx) await tx.rollback(); + + throw e; + } + }; +}; diff --git a/modules/mdb/back/methods/mdbVersion/upload.js b/modules/mdb/back/methods/mdbVersion/upload.js index 57df35ce7..489700dd1 100644 --- a/modules/mdb/back/methods/mdbVersion/upload.js +++ b/modules/mdb/back/methods/mdbVersion/upload.js @@ -23,6 +23,12 @@ module.exports = Self => { type: 'string', required: true, description: `The branch name` + }, + { + arg: 'unlock', + type: 'boolean', + required: false, + description: `It allows unlock the app` } ], returns: { @@ -35,9 +41,11 @@ module.exports = Self => { } }); - Self.upload = async(ctx, appName, newVersion, branch, options) => { + Self.upload = async(ctx, appName, newVersion, branch, unlock, options) => { const models = Self.app.models; + const userId = ctx.req.accessToken.userId; const myOptions = {}; + const $t = ctx.req.__; // $translate const TempContainer = models.TempContainer; const AccessContainer = models.AccessContainer; @@ -55,6 +63,12 @@ module.exports = Self => { let srcFile; try { + const mdbApp = await models.MdbApp.findById(appName, null, myOptions); + const message = $t('App locked', { + userId: userId + }); + if (mdbApp.locked && mdbApp.userFk != userId) throw new UserError(message); + const tempContainer = await TempContainer.container('access'); const uploaded = await TempContainer.upload(tempContainer.name, ctx.req, ctx.result, fileOptions); const files = Object.values(uploaded.files).map(file => { @@ -79,7 +93,7 @@ module.exports = Self => { const existBranch = await models.MdbBranch.findOne({ where: {name: branch} - }); + }, myOptions); if (!existBranch) throw new UserError('Not exist this branch'); @@ -108,7 +122,9 @@ module.exports = Self => { app: appName, branchFk: branch, version: newVersion - }); + }, myOptions); + + if (unlock) await models.MdbApp.unlock(appName, myOptions); if (tx) await tx.commit(); } catch (e) { diff --git a/modules/mdb/back/model-config.json b/modules/mdb/back/model-config.json index d5be8de87..6107f8790 100644 --- a/modules/mdb/back/model-config.json +++ b/modules/mdb/back/model-config.json @@ -1,4 +1,7 @@ { + "MdbApp": { + "dataSource": "vn" + }, "MdbBranch": { "dataSource": "vn" }, diff --git a/modules/mdb/back/models/mdbApp.js b/modules/mdb/back/models/mdbApp.js new file mode 100644 index 000000000..dce715573 --- /dev/null +++ b/modules/mdb/back/models/mdbApp.js @@ -0,0 +1,4 @@ +module.exports = Self => { + require('../methods/mdbApp/lock')(Self); + require('../methods/mdbApp/unlock')(Self); +}; diff --git a/modules/mdb/back/models/mdbApp.json b/modules/mdb/back/models/mdbApp.json new file mode 100644 index 000000000..868f8c1d0 --- /dev/null +++ b/modules/mdb/back/models/mdbApp.json @@ -0,0 +1,31 @@ +{ + "name": "MdbApp", + "base": "VnModel", + "options": { + "mysql": { + "table": "mdbApp" + } + }, + "properties": { + "app": { + "type": "string", + "description": "The app name", + "id": true + }, + "locked": { + "type": "date" + } + }, + "relations": { + "branch": { + "type": "belongsTo", + "model": "MdbBranch", + "foreignKey": "baselineBranchFk" + }, + "user": { + "type": "belongsTo", + "model": "MdbBranch", + "foreignKey": "userFk" + } + } +} -- 2.40.1 From e0ba7d523c26ad4d154e291e5f814c90b4e5a67f Mon Sep 17 00:00:00 2001 From: vicent Date: Tue, 22 Nov 2022 14:43:15 +0100 Subject: [PATCH 02/10] refacfor: add ctx --- modules/mdb/back/methods/mdbApp/unlock.js | 2 +- modules/mdb/back/methods/mdbVersion/upload.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/mdb/back/methods/mdbApp/unlock.js b/modules/mdb/back/methods/mdbApp/unlock.js index 7c6f88ec2..9c0470c58 100644 --- a/modules/mdb/back/methods/mdbApp/unlock.js +++ b/modules/mdb/back/methods/mdbApp/unlock.js @@ -22,7 +22,7 @@ module.exports = Self => { } }); - Self.unlock = async(appName, options) => { + Self.unlock = async(ctx, appName, options) => { const models = Self.app.models; const myOptions = {}; diff --git a/modules/mdb/back/methods/mdbVersion/upload.js b/modules/mdb/back/methods/mdbVersion/upload.js index 489700dd1..5f163d857 100644 --- a/modules/mdb/back/methods/mdbVersion/upload.js +++ b/modules/mdb/back/methods/mdbVersion/upload.js @@ -124,7 +124,7 @@ module.exports = Self => { version: newVersion }, myOptions); - if (unlock) await models.MdbApp.unlock(appName, myOptions); + if (unlock) await models.MdbApp.unlock(ctx, appName, myOptions); if (tx) await tx.commit(); } catch (e) { -- 2.40.1 From df4acb70a362d15c5e66dee66820165435c11425 Mon Sep 17 00:00:00 2001 From: vicent Date: Tue, 22 Nov 2022 14:43:21 +0100 Subject: [PATCH 03/10] feat: add backTest --- .../back/methods/mdbApp/specs/lock.spec.js | 22 +++++++++++++++++++ .../back/methods/mdbApp/specs/unlock.spec.js | 22 +++++++++++++++++++ 2 files changed, 44 insertions(+) create mode 100644 modules/mdb/back/methods/mdbApp/specs/lock.spec.js create mode 100644 modules/mdb/back/methods/mdbApp/specs/unlock.spec.js diff --git a/modules/mdb/back/methods/mdbApp/specs/lock.spec.js b/modules/mdb/back/methods/mdbApp/specs/lock.spec.js new file mode 100644 index 000000000..c5bb305fc --- /dev/null +++ b/modules/mdb/back/methods/mdbApp/specs/lock.spec.js @@ -0,0 +1,22 @@ +const models = require('vn-loopback/server/server').models; + +describe('MdbApp lock()', () => { + it(`should lock a mdb `, async() => { + const tx = await models.MdbApp.beginTransaction({}); + + try { + const options = {transaction: tx}; + const appName = 'com'; + const developerId = 9; + const ctx = {req: {accessToken: {userId: developerId}}}; + + const result = await models.MdbApp.lock(ctx, appName, options); + + expect(result.locked).not.toBeNull(); + + await tx.rollback(); + } catch (e) { + await tx.rollback(); + } + }); +}); diff --git a/modules/mdb/back/methods/mdbApp/specs/unlock.spec.js b/modules/mdb/back/methods/mdbApp/specs/unlock.spec.js new file mode 100644 index 000000000..750bf636a --- /dev/null +++ b/modules/mdb/back/methods/mdbApp/specs/unlock.spec.js @@ -0,0 +1,22 @@ +const models = require('vn-loopback/server/server').models; + +describe('MdbApp unlock()', () => { + it(`should unlock a mdb `, async() => { + const tx = await models.MdbApp.beginTransaction({}); + + try { + const options = {transaction: tx}; + const appName = 'com'; + const developerId = 9; + const ctx = {req: {accessToken: {userId: developerId}}}; + + const result = await models.MdbApp.unlock(ctx, appName, options); + + expect(result.locked).toBeNull(); + + await tx.rollback(); + } catch (e) { + await tx.rollback(); + } + }); +}); -- 2.40.1 From 6a2af344aa0a2ac1c261b26f1e7f1ffb0e0415d8 Mon Sep 17 00:00:00 2001 From: vicent Date: Wed, 23 Nov 2022 10:41:32 +0100 Subject: [PATCH 04/10] feat: antes de bloquear comprobar que no existe un bloqueo previo --- db/dump/fixtures.sql | 2 +- modules/mdb/back/methods/mdbApp/lock.js | 9 ++++++ .../back/methods/mdbApp/specs/lock.spec.js | 29 +++++++++++++++++++ modules/mdb/back/methods/mdbVersion/upload.js | 2 +- 4 files changed, 40 insertions(+), 2 deletions(-) diff --git a/db/dump/fixtures.sql b/db/dump/fixtures.sql index e811ced94..9057ed174 100644 --- a/db/dump/fixtures.sql +++ b/db/dump/fixtures.sql @@ -2735,4 +2735,4 @@ INSERT INTO `vn`.`osTicketConfig` (`id`, `host`, `user`, `password`, `oldStatus` INSERT INTO `vn`.`mdbApp` (`app`, `baselineBranchFk`, `userFk`, `locked`) VALUES ('com', 'master', NULL, NULL), - ('ent', 'test', NULL, NULL); + ('ent', 'test', 9, util.VN_NOW()); diff --git a/modules/mdb/back/methods/mdbApp/lock.js b/modules/mdb/back/methods/mdbApp/lock.js index 5fcd0604e..6006d4fad 100644 --- a/modules/mdb/back/methods/mdbApp/lock.js +++ b/modules/mdb/back/methods/mdbApp/lock.js @@ -1,3 +1,5 @@ +const UserError = require('vn-loopback/util/user-error'); + module.exports = Self => { Self.remoteMethodCtx('lock', { description: 'Lock an app for the user', @@ -26,6 +28,7 @@ module.exports = Self => { const models = Self.app.models; const userId = ctx.req.accessToken.userId; const myOptions = {}; + const $t = ctx.req.__; // $translate let tx; @@ -39,6 +42,12 @@ module.exports = Self => { try { const mdbApp = await models.MdbApp.findById(appName, null, myOptions); + + const message = $t('App locked', { + userId: mdbApp.userFk + }); + if (mdbApp.locked) throw new UserError(message); + const updatedMdbApp = await mdbApp.updateAttributes({ userFk: userId, locked: new Date() diff --git a/modules/mdb/back/methods/mdbApp/specs/lock.spec.js b/modules/mdb/back/methods/mdbApp/specs/lock.spec.js index c5bb305fc..ffb0e49fd 100644 --- a/modules/mdb/back/methods/mdbApp/specs/lock.spec.js +++ b/modules/mdb/back/methods/mdbApp/specs/lock.spec.js @@ -1,6 +1,35 @@ const models = require('vn-loopback/server/server').models; describe('MdbApp lock()', () => { + it('should throw an error if the app is already locked', async() => { + const tx = await models.MdbApp.beginTransaction({}); + let error; + + try { + const options = {transaction: tx}; + const appName = 'ent'; + const developerId = 9; + const ctx = { + req: { + accessToken: {userId: developerId}, + __: () => {} + } + }; + + const result = await models.MdbApp.lock(ctx, appName, options); + + expect(result.locked).not.toBeNull(); + + await tx.rollback(); + } catch (e) { + error = e; + + await tx.rollback(); + } + + expect(error).toBeDefined(); + }); + it(`should lock a mdb `, async() => { const tx = await models.MdbApp.beginTransaction({}); diff --git a/modules/mdb/back/methods/mdbVersion/upload.js b/modules/mdb/back/methods/mdbVersion/upload.js index 5f163d857..adb155c06 100644 --- a/modules/mdb/back/methods/mdbVersion/upload.js +++ b/modules/mdb/back/methods/mdbVersion/upload.js @@ -65,7 +65,7 @@ module.exports = Self => { try { const mdbApp = await models.MdbApp.findById(appName, null, myOptions); const message = $t('App locked', { - userId: userId + userId: mdbApp.userFk }); if (mdbApp.locked && mdbApp.userFk != userId) throw new UserError(message); -- 2.40.1 From f313a53cde210afcb61c35d13c93c0971cce4ab2 Mon Sep 17 00:00:00 2001 From: vicent Date: Wed, 23 Nov 2022 10:56:55 +0100 Subject: [PATCH 05/10] refactor: cambiadas fixtures, backTest y traducciones --- db/changes/10503-november/00-mdbApp.sql | 6 +++--- db/dump/fixtures.sql | 4 ++-- loopback/locale/es.json | 2 +- modules/mdb/back/methods/mdbApp/specs/lock.spec.js | 4 ++-- modules/mdb/back/methods/mdbApp/specs/unlock.spec.js | 2 +- 5 files changed, 9 insertions(+), 9 deletions(-) diff --git a/db/changes/10503-november/00-mdbApp.sql b/db/changes/10503-november/00-mdbApp.sql index 3b242c9ab..3202e3f08 100644 --- a/db/changes/10503-november/00-mdbApp.sql +++ b/db/changes/10503-november/00-mdbApp.sql @@ -1,11 +1,11 @@ CREATE TABLE `vn`.`mdbApp` ( - `app` varchar(100) COLLATE utf8mb3_unicode_ci DEFAULT NULL, + `app` varchar(100) COLLATE utf8mb3_unicode_ci NOT NULL, `baselineBranchFk` varchar(255) COLLATE utf8mb3_unicode_ci DEFAULT NULL, `userFk` int(10) unsigned DEFAULT NULL, `locked` datetime DEFAULT NULL, - UNIQUE KEY `app_UN` (`app`), + PRIMARY KEY (`app`), KEY `mdbApp_FK` (`userFk`), KEY `mdbApp_FK_1` (`baselineBranchFk`), CONSTRAINT `mdbApp_FK` FOREIGN KEY (`userFk`) REFERENCES `account`.`user` (`id`) ON DELETE SET NULL ON UPDATE CASCADE, CONSTRAINT `mdbApp_FK_1` FOREIGN KEY (`baselineBranchFk`) REFERENCES `mdbBranch` (`name`) ON UPDATE CASCADE -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci diff --git a/db/dump/fixtures.sql b/db/dump/fixtures.sql index 9057ed174..4aaf62bde 100644 --- a/db/dump/fixtures.sql +++ b/db/dump/fixtures.sql @@ -2734,5 +2734,5 @@ INSERT INTO `vn`.`osTicketConfig` (`id`, `host`, `user`, `password`, `oldStatus` INSERT INTO `vn`.`mdbApp` (`app`, `baselineBranchFk`, `userFk`, `locked`) VALUES - ('com', 'master', NULL, NULL), - ('ent', 'test', 9, util.VN_NOW()); + ('foo', 'master', NULL, NULL), + ('bar', 'test', 9, util.VN_NOW()); diff --git a/loopback/locale/es.json b/loopback/locale/es.json index 801404eab..5989db187 100644 --- a/loopback/locale/es.json +++ b/loopback/locale/es.json @@ -245,5 +245,5 @@ "Already has this status": "Ya tiene este estado", "There aren't records for this week": "No existen registros para esta semana", "Empty data source": "Origen de datos vacio", - "App locked": "Aplicación bloquada por el usuario {{userId}}" + "App locked": "Aplicación bloqueada por el usuario {{userId}}" } diff --git a/modules/mdb/back/methods/mdbApp/specs/lock.spec.js b/modules/mdb/back/methods/mdbApp/specs/lock.spec.js index ffb0e49fd..162d0490a 100644 --- a/modules/mdb/back/methods/mdbApp/specs/lock.spec.js +++ b/modules/mdb/back/methods/mdbApp/specs/lock.spec.js @@ -7,7 +7,7 @@ describe('MdbApp lock()', () => { try { const options = {transaction: tx}; - const appName = 'ent'; + const appName = 'bar'; const developerId = 9; const ctx = { req: { @@ -35,7 +35,7 @@ describe('MdbApp lock()', () => { try { const options = {transaction: tx}; - const appName = 'com'; + const appName = 'foo'; const developerId = 9; const ctx = {req: {accessToken: {userId: developerId}}}; diff --git a/modules/mdb/back/methods/mdbApp/specs/unlock.spec.js b/modules/mdb/back/methods/mdbApp/specs/unlock.spec.js index 750bf636a..9f1678372 100644 --- a/modules/mdb/back/methods/mdbApp/specs/unlock.spec.js +++ b/modules/mdb/back/methods/mdbApp/specs/unlock.spec.js @@ -6,7 +6,7 @@ describe('MdbApp unlock()', () => { try { const options = {transaction: tx}; - const appName = 'com'; + const appName = 'bar'; const developerId = 9; const ctx = {req: {accessToken: {userId: developerId}}}; -- 2.40.1 From 5415338f5533fd24c855bbf2871f52b59612d4ce Mon Sep 17 00:00:00 2001 From: vicent Date: Fri, 25 Nov 2022 12:17:16 +0100 Subject: [PATCH 06/10] refactor: movidos changes sql --- db/changes/{10503-november => 10510-december}/00-aclMdbApp.sql | 0 db/changes/{10503-november => 10510-december}/00-mdbApp.sql | 0 2 files changed, 0 insertions(+), 0 deletions(-) rename db/changes/{10503-november => 10510-december}/00-aclMdbApp.sql (100%) rename db/changes/{10503-november => 10510-december}/00-mdbApp.sql (100%) diff --git a/db/changes/10503-november/00-aclMdbApp.sql b/db/changes/10510-december/00-aclMdbApp.sql similarity index 100% rename from db/changes/10503-november/00-aclMdbApp.sql rename to db/changes/10510-december/00-aclMdbApp.sql diff --git a/db/changes/10503-november/00-mdbApp.sql b/db/changes/10510-december/00-mdbApp.sql similarity index 100% rename from db/changes/10503-november/00-mdbApp.sql rename to db/changes/10510-december/00-mdbApp.sql -- 2.40.1 From 444d495b7ff662ffa4a56a24e71db85c90a29abb Mon Sep 17 00:00:00 2001 From: vicent Date: Thu, 1 Dec 2022 07:22:13 +0100 Subject: [PATCH 07/10] refactor: codigo reducido --- loopback/locale/es.json | 9 +++++---- modules/mdb/back/methods/mdbApp/lock.js | 11 ++++++----- modules/mdb/back/methods/mdbVersion/upload.js | 10 ++++++---- 3 files changed, 17 insertions(+), 13 deletions(-) diff --git a/loopback/locale/es.json b/loopback/locale/es.json index 6bf4d79e3..362df8110 100644 --- a/loopback/locale/es.json +++ b/loopback/locale/es.json @@ -248,7 +248,8 @@ "App locked": "Aplicación bloqueada por el usuario {{userId}}", "Email verify": "Correo de verificación", "Landing cannot be lesser than shipment": "Landing cannot be lesser than shipment", - "Receipt's bank was not found": "No se encontró el banco del recibo", - "This receipt was not compensated": "Este recibo no ha sido compensado", - "Client's email was not found": "No se encontró el email del cliente" -} + "Receipt's bank was not found": "No se encontró el banco del recibo", + "This receipt was not compensated": "Este recibo no ha sido compensado", + "Client's email was not found": "No se encontró el email del cliente", + "Aplicación bloqueada por el usuario 9": "Aplicación bloqueada por el usuario 9" +} \ No newline at end of file diff --git a/modules/mdb/back/methods/mdbApp/lock.js b/modules/mdb/back/methods/mdbApp/lock.js index 6006d4fad..98e61fb53 100644 --- a/modules/mdb/back/methods/mdbApp/lock.js +++ b/modules/mdb/back/methods/mdbApp/lock.js @@ -41,12 +41,13 @@ module.exports = Self => { } try { - const mdbApp = await models.MdbApp.findById(appName, null, myOptions); + const mdbApp = await models.MdbApp.findById(appName, {fields: ['app', 'locked', 'userFk']}, myOptions); - const message = $t('App locked', { - userId: mdbApp.userFk - }); - if (mdbApp.locked) throw new UserError(message); + if (mdbApp.locked) { + throw new UserError($t('App locked', { + userId: mdbApp.userFk + })); + } const updatedMdbApp = await mdbApp.updateAttributes({ userFk: userId, diff --git a/modules/mdb/back/methods/mdbVersion/upload.js b/modules/mdb/back/methods/mdbVersion/upload.js index adb155c06..5dfe5d3ef 100644 --- a/modules/mdb/back/methods/mdbVersion/upload.js +++ b/modules/mdb/back/methods/mdbVersion/upload.js @@ -64,10 +64,12 @@ module.exports = Self => { let srcFile; try { const mdbApp = await models.MdbApp.findById(appName, null, myOptions); - const message = $t('App locked', { - userId: mdbApp.userFk - }); - if (mdbApp.locked && mdbApp.userFk != userId) throw new UserError(message); + + if (mdbApp.locked && mdbApp.userFk != userId) { + throw new UserError($t('App locked', { + userId: mdbApp.userFk + })); + } const tempContainer = await TempContainer.container('access'); const uploaded = await TempContainer.upload(tempContainer.name, ctx.req, ctx.result, fileOptions); -- 2.40.1 From 859c084430aa01831353138196941d770cf870c6 Mon Sep 17 00:00:00 2001 From: vicent Date: Thu, 15 Dec 2022 07:17:13 +0100 Subject: [PATCH 08/10] refactor: movidos changes sql --- db/changes/{10510-december => 225001}/00-aclMdbApp.sql | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename db/changes/{10510-december => 225001}/00-aclMdbApp.sql (100%) diff --git a/db/changes/10510-december/00-aclMdbApp.sql b/db/changes/225001/00-aclMdbApp.sql similarity index 100% rename from db/changes/10510-december/00-aclMdbApp.sql rename to db/changes/225001/00-aclMdbApp.sql -- 2.40.1 From 4e8896202aeff7c3923d508491b7fa0dcbf62db5 Mon Sep 17 00:00:00 2001 From: vicent Date: Thu, 15 Dec 2022 07:17:26 +0100 Subject: [PATCH 09/10] =?UTF-8?q?delete:=20transacci=C3=B3n=20innecesaria?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- modules/mdb/back/methods/mdbApp/unlock.js | 5 ----- 1 file changed, 5 deletions(-) diff --git a/modules/mdb/back/methods/mdbApp/unlock.js b/modules/mdb/back/methods/mdbApp/unlock.js index 9c0470c58..bf09a4493 100644 --- a/modules/mdb/back/methods/mdbApp/unlock.js +++ b/modules/mdb/back/methods/mdbApp/unlock.js @@ -31,11 +31,6 @@ module.exports = Self => { if (typeof options == 'object') Object.assign(myOptions, options); - if (!myOptions.transaction) { - tx = await Self.beginTransaction({}); - myOptions.transaction = tx; - } - try { const mdbApp = await models.MdbApp.findById(appName, null, myOptions); const updatedMdbApp = await mdbApp.updateAttributes({ -- 2.40.1 From 1a616fa1d45b5d7d773d6257214dd4828b32ce64 Mon Sep 17 00:00:00 2001 From: vicent Date: Tue, 20 Dec 2022 09:09:21 +0100 Subject: [PATCH 10/10] refactor: delete transaction --- modules/mdb/back/methods/mdbApp/unlock.js | 22 ++++++---------------- 1 file changed, 6 insertions(+), 16 deletions(-) diff --git a/modules/mdb/back/methods/mdbApp/unlock.js b/modules/mdb/back/methods/mdbApp/unlock.js index bf09a4493..6bf67ddf4 100644 --- a/modules/mdb/back/methods/mdbApp/unlock.js +++ b/modules/mdb/back/methods/mdbApp/unlock.js @@ -26,25 +26,15 @@ module.exports = Self => { const models = Self.app.models; const myOptions = {}; - let tx; - if (typeof options == 'object') Object.assign(myOptions, options); - try { - const mdbApp = await models.MdbApp.findById(appName, null, myOptions); - const updatedMdbApp = await mdbApp.updateAttributes({ - userFk: null, - locked: null - }, myOptions); + const mdbApp = await models.MdbApp.findById(appName, null, myOptions); + const updatedMdbApp = await mdbApp.updateAttributes({ + userFk: null, + locked: null + }, myOptions); - if (tx) await tx.commit(); - - return updatedMdbApp; - } catch (e) { - if (tx) await tx.rollback(); - - throw e; - } + return updatedMdbApp; }; }; -- 2.40.1