From 600dd7a4347d40bb49a4a0e2cdecda346178f521 Mon Sep 17 00:00:00 2001 From: Pau Navarro Date: Wed, 5 Oct 2022 11:52:14 +0200 Subject: [PATCH 01/15] Created the model and UI --- .../workerDisableExclueded/checkExcluded.js | 26 +++++++++++++++++++ modules/worker/back/model-config.json | 3 +++ .../back/models/workerDisableExcluded.json | 23 ++++++++++++++++ modules/worker/front/descriptor/index.html | 10 +++++++ modules/worker/front/descriptor/index.js | 8 ++++++ 5 files changed, 70 insertions(+) create mode 100644 modules/worker/back/methods/workerDisableExclueded/checkExcluded.js create mode 100644 modules/worker/back/models/workerDisableExcluded.json diff --git a/modules/worker/back/methods/workerDisableExclueded/checkExcluded.js b/modules/worker/back/methods/workerDisableExclueded/checkExcluded.js new file mode 100644 index 000000000..32260c01f --- /dev/null +++ b/modules/worker/back/methods/workerDisableExclueded/checkExcluded.js @@ -0,0 +1,26 @@ + +module.exports = Self => { + Self.remoteMethod('workerDisableExcluded', { + description: 'Check an email inbox and process it', + accessType: 'READ', + accepts: { + arg: 'workerFk', + type: 'Number', + required: true, + description: `The worker id` + }, + returns: { + type: ['Object'], + root: true + }, + http: { + path: `/workerDisableExcluded`, + verb: 'GET' + } + }); + + Self.workerDisableExcluded = workerFk => { + console.log(workerFk); + return 'tests123'; + }; +}; diff --git a/modules/worker/back/model-config.json b/modules/worker/back/model-config.json index c155e331d..a41997908 100644 --- a/modules/worker/back/model-config.json +++ b/modules/worker/back/model-config.json @@ -64,6 +64,9 @@ }, "WorkerTimeControlMail": { "dataSource": "vn" + }, + "workerDisableExcluded": { + "dataSource": "vn" } } diff --git a/modules/worker/back/models/workerDisableExcluded.json b/modules/worker/back/models/workerDisableExcluded.json new file mode 100644 index 000000000..eeffb4b15 --- /dev/null +++ b/modules/worker/back/models/workerDisableExcluded.json @@ -0,0 +1,23 @@ +{ + "name": "workerDisableExcluded", + "base": "VnModel", + "options": { + "mysql": { + "table": "workerDisableExcluded" + } + }, + "properties": { + "id": { + "id": true, + "type": "number" + } + }, + "acls": [ + { + "accessType": "READ", + "principalType": "ROLE", + "principalId": "$everyone", + "permission": "ALLOW" + } + ] +} \ No newline at end of file diff --git a/modules/worker/front/descriptor/index.html b/modules/worker/front/descriptor/index.html index 01681ebb8..0616f179f 100644 --- a/modules/worker/front/descriptor/index.html +++ b/modules/worker/front/descriptor/index.html @@ -14,6 +14,16 @@ + + +
Date: Thu, 6 Oct 2022 10:18:08 +0200 Subject: [PATCH 02/15] feat: workerDisableExcluded update DB field --- .../methods/worker/workerDisableExcluded.js | 30 +++++++++++++ .../worker/workerExcludeFromDisable.js | 45 +++++++++++++++++++ .../workerDisableExclueded/checkExcluded.js | 26 ----------- modules/worker/back/models/worker.js | 2 + .../back/models/workerDisableExcluded.json | 5 ++- modules/worker/front/descriptor/index.html | 21 +++++---- modules/worker/front/descriptor/index.js | 24 +++++++--- 7 files changed, 112 insertions(+), 41 deletions(-) create mode 100644 modules/worker/back/methods/worker/workerDisableExcluded.js create mode 100644 modules/worker/back/methods/worker/workerExcludeFromDisable.js delete mode 100644 modules/worker/back/methods/workerDisableExclueded/checkExcluded.js diff --git a/modules/worker/back/methods/worker/workerDisableExcluded.js b/modules/worker/back/methods/worker/workerDisableExcluded.js new file mode 100644 index 000000000..017e044c2 --- /dev/null +++ b/modules/worker/back/methods/worker/workerDisableExcluded.js @@ -0,0 +1,30 @@ + +module.exports = Self => { + Self.remoteMethod('workerDisableExcluded', { + description: 'Check if the worker can be disabled', + accessType: 'READ', + accepts: { + arg: 'id', + type: 'Number', + required: true, + description: `The worker id`, + http: {source: 'path'} + }, + returns: { + type: 'boolean', + root: true + }, + http: { + path: `/workerDisableExcluded/:id`, + verb: 'GET' + } + }); + + Self.workerDisableExcluded = async id => { + let result; + const query = `Select * from vn.workerDisableExcluded where workerFk like ${id}`; + let sqlResult = await Self.rawSql(query); + sqlResult.length == 0 ? result = false : result = true; + return result; + }; +}; diff --git a/modules/worker/back/methods/worker/workerExcludeFromDisable.js b/modules/worker/back/methods/worker/workerExcludeFromDisable.js new file mode 100644 index 000000000..86d940862 --- /dev/null +++ b/modules/worker/back/methods/worker/workerExcludeFromDisable.js @@ -0,0 +1,45 @@ +module.exports = Self => { + Self.remoteMethod('workerExcludeFromDisable', { + description: 'Change the status of the worker between can be disabled and cant be disabled', + accessType: 'READ', + accepts: [{ + arg: 'id', + type: 'Number', + required: true, + description: `The worker id`, + http: {source: 'path'} + }, + { + arg: 'currValue', + type: 'Boolean', + required: true, + description: `The current value of workerDisableExcluded`, + http: {source: 'path'} + }], + returns: { + type: 'boolean', + root: true + }, + http: { + path: `/workerExcludeFromDisable/:id/:currValue`, + verb: 'GET' + } + }); + + Self.workerExcludeFromDisable = async(id, currValue) => { + const models = Self.app.models; + + if (!currValue) { + await models.WorkerDisableExcluded.create({ + workerFk: id, + dated: new Date() + }); + } else { + await models.WorkerDisableExcluded.remove({ + workerFk: id + }); + } + + return false; + }; +}; diff --git a/modules/worker/back/methods/workerDisableExclueded/checkExcluded.js b/modules/worker/back/methods/workerDisableExclueded/checkExcluded.js deleted file mode 100644 index 32260c01f..000000000 --- a/modules/worker/back/methods/workerDisableExclueded/checkExcluded.js +++ /dev/null @@ -1,26 +0,0 @@ - -module.exports = Self => { - Self.remoteMethod('workerDisableExcluded', { - description: 'Check an email inbox and process it', - accessType: 'READ', - accepts: { - arg: 'workerFk', - type: 'Number', - required: true, - description: `The worker id` - }, - returns: { - type: ['Object'], - root: true - }, - http: { - path: `/workerDisableExcluded`, - verb: 'GET' - } - }); - - Self.workerDisableExcluded = workerFk => { - console.log(workerFk); - return 'tests123'; - }; -}; diff --git a/modules/worker/back/models/worker.js b/modules/worker/back/models/worker.js index ec6c4af28..c90729779 100644 --- a/modules/worker/back/models/worker.js +++ b/modules/worker/back/models/worker.js @@ -13,4 +13,6 @@ module.exports = Self => { require('../methods/worker/contracts')(Self); require('../methods/worker/holidays')(Self); require('../methods/worker/activeContract')(Self); + require('../methods/worker/workerDisableExcluded')(Self); + require('../methods/worker/workerExcludeFromDisable')(Self); }; diff --git a/modules/worker/back/models/workerDisableExcluded.json b/modules/worker/back/models/workerDisableExcluded.json index eeffb4b15..cfa810e43 100644 --- a/modules/worker/back/models/workerDisableExcluded.json +++ b/modules/worker/back/models/workerDisableExcluded.json @@ -7,9 +7,12 @@ } }, "properties": { - "id": { + "workerFk": { "id": true, "type": "number" + }, + "dated": { + "type": "date" } }, "acls": [ diff --git a/modules/worker/front/descriptor/index.html b/modules/worker/front/descriptor/index.html index 0616f179f..d3caa78a8 100644 --- a/modules/worker/front/descriptor/index.html +++ b/modules/worker/front/descriptor/index.html @@ -15,14 +15,19 @@
- + + + Marcar para no deshabilitar + + + Marcar como deshabilitable +
diff --git a/modules/worker/front/descriptor/index.js b/modules/worker/front/descriptor/index.js index e1026382d..2f79c2d80 100644 --- a/modules/worker/front/descriptor/index.js +++ b/modules/worker/front/descriptor/index.js @@ -5,6 +5,7 @@ class Controller extends Descriptor { constructor($element, $, $rootScope) { super($element, $); this.$rootScope = $rootScope; + this.canBeExcluded(); } get worker() { @@ -15,12 +16,23 @@ class Controller extends Descriptor { this.entity = value; } - async isExcluded() { - // eslint-disable-next-line no-console - console.log(this.entity); - let excluded = await this.$http.get(`workerDisableExcluded`); - // eslint-disable-next-line no-console - console.log(excluded); + get excluded() { + return this.entity.excluded; + } + + set excluded(value) { + this.entity.excluded = value; + } + + async canBeExcluded() { + await new Promise(r => setTimeout(r, 1000)); + let data = await this.$http.get(`Workers/workerDisableExcluded/${this.entity.id}`); + this.excluded = data.data; + } + + async setExcluded() { + await this.$http.get(`Workers/workerExcludeFromDisable/${this.entity.id}/${this.entity.excluded}`); + this.canBeExcluded(); } loadData() { From 3376293d1a60e4732346c5eb2e26f81b5e20d62c Mon Sep 17 00:00:00 2001 From: Pau Navarro Date: Thu, 6 Oct 2022 11:54:14 +0200 Subject: [PATCH 03/15] Added user icon and fixed icon not updating --- modules/worker/front/descriptor/index.html | 7 +++++++ modules/worker/front/descriptor/index.js | 5 +++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/modules/worker/front/descriptor/index.html b/modules/worker/front/descriptor/index.html index d3caa78a8..c60801bb9 100644 --- a/modules/worker/front/descriptor/index.html +++ b/modules/worker/front/descriptor/index.html @@ -52,6 +52,13 @@ value="{{$ctrl.worker.sip.extension}}">
+
+ + +
diff --git a/modules/worker/front/descriptor/index.js b/modules/worker/front/descriptor/index.js index 7a3922a08..2ff032def 100644 --- a/modules/worker/front/descriptor/index.js +++ b/modules/worker/front/descriptor/index.js @@ -5,7 +5,6 @@ class Controller extends Descriptor { constructor($element, $, $rootScope) { super($element, $); this.$rootScope = $rootScope; - this.canBeExcluded(); } get worker() { @@ -14,6 +13,9 @@ class Controller extends Descriptor { set worker(value) { this.entity = value; + + if (value) + this.getIsExcluded(); } get excluded() { @@ -22,18 +24,22 @@ class Controller extends Descriptor { set excluded(value) { this.entity.excluded = value; - this.$rootScope.$apply(); } - async canBeExcluded() { - await new Promise(r => setTimeout(r, 500)); - let data = await this.$http.get(`Workers/workerDisableExcluded/${this.entity.id}`); - this.excluded = data.data; + getIsExcluded() { + this.$http.get(`workerDisableExcludeds/${this.entity.id}/exists`).then(data => { + this.excluded = data.data.exists; + }); } - async setExcluded() { - await this.$http.get(`Workers/workerExcludeFromDisable/${this.entity.id}/${this.entity.excluded}`); - this.excluded = !this.entity.excluded; + handleExcluded() { + if (this.excluded) { + this.$http.delete(`workerDisableExcludeds/${this.entity.id}`); + this.excluded = false; + } else { + this.$http.post(`workerDisableExcludeds`, {workerFk: this.entity.id, dated: new Date}); + this.excluded = true; + } } loadData() { diff --git a/modules/worker/front/locale/es.yml b/modules/worker/front/locale/es.yml index 1414d089b..672f4c52f 100644 --- a/modules/worker/front/locale/es.yml +++ b/modules/worker/front/locale/es.yml @@ -20,4 +20,7 @@ View worker: Ver trabajador Worker id: Id trabajador Workers: Trabajadores worker: trabajador -Go to the worker: Ir al trabajador \ No newline at end of file +Go to the worker: Ir al trabajador +Click to exclude the user from getting disabled: Marcar para no deshabilitar +Click to allow the user to be disabled: Marcar para deshabilitar +This user can't be disabled: Fijado para no deshabilitar \ No newline at end of file From c9e9e3545d664104d415ffc34cee1d820bc48c6c Mon Sep 17 00:00:00 2001 From: Pau Navarro Date: Tue, 18 Oct 2022 10:33:48 +0200 Subject: [PATCH 05/15] Added ACL --- .../00-ACL_workerDisableExcluded.sql | 20 +++++++++++++++++++ db/changes/10491-august/delete.keep | 0 2 files changed, 20 insertions(+) create mode 100644 db/changes/10491-august/00-ACL_workerDisableExcluded.sql delete mode 100644 db/changes/10491-august/delete.keep diff --git a/db/changes/10491-august/00-ACL_workerDisableExcluded.sql b/db/changes/10491-august/00-ACL_workerDisableExcluded.sql new file mode 100644 index 000000000..48fb4bb35 --- /dev/null +++ b/db/changes/10491-august/00-ACL_workerDisableExcluded.sql @@ -0,0 +1,20 @@ +INSERT INTO + salix.ACL ( + id, + model, + property, + accessType, + permission, + principalType, + principalId + ) +VALUES +( + 344, + 'workerDisableExcluded', + '*', + '*', + 'ALLOW', + 'ROLE', + 'employee' + ); \ No newline at end of file diff --git a/db/changes/10491-august/delete.keep b/db/changes/10491-august/delete.keep deleted file mode 100644 index e69de29bb..000000000 From f481cc3c97f2cc68f480863a97be13a7240bddc8 Mon Sep 17 00:00:00 2001 From: Pau Navarro Date: Tue, 18 Oct 2022 10:38:40 +0200 Subject: [PATCH 06/15] Capitalizar --- db/changes/10491-august/00-ACL_workerDisableExcluded.sql | 2 +- modules/worker/back/model-config.json | 2 +- modules/worker/back/models/workerDisableExcluded.json | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/db/changes/10491-august/00-ACL_workerDisableExcluded.sql b/db/changes/10491-august/00-ACL_workerDisableExcluded.sql index 48fb4bb35..3d84c751c 100644 --- a/db/changes/10491-august/00-ACL_workerDisableExcluded.sql +++ b/db/changes/10491-august/00-ACL_workerDisableExcluded.sql @@ -11,7 +11,7 @@ INSERT INTO VALUES ( 344, - 'workerDisableExcluded', + 'WorkerDisableExcluded', '*', '*', 'ALLOW', diff --git a/modules/worker/back/model-config.json b/modules/worker/back/model-config.json index a41997908..8c11c0d71 100644 --- a/modules/worker/back/model-config.json +++ b/modules/worker/back/model-config.json @@ -65,7 +65,7 @@ "WorkerTimeControlMail": { "dataSource": "vn" }, - "workerDisableExcluded": { + "WorkerDisableExcluded": { "dataSource": "vn" } } diff --git a/modules/worker/back/models/workerDisableExcluded.json b/modules/worker/back/models/workerDisableExcluded.json index cfa810e43..48083748d 100644 --- a/modules/worker/back/models/workerDisableExcluded.json +++ b/modules/worker/back/models/workerDisableExcluded.json @@ -1,5 +1,5 @@ { - "name": "workerDisableExcluded", + "name": "WorkerDisableExcluded", "base": "VnModel", "options": { "mysql": { From 81088bc4959c5173802416902847c118631a555d Mon Sep 17 00:00:00 2001 From: Pau Navarro Date: Tue, 18 Oct 2022 10:46:14 +0200 Subject: [PATCH 07/15] Fixed ACL --- .../00-ACL_workerDisableExcluded.sql | 22 ++----------------- 1 file changed, 2 insertions(+), 20 deletions(-) diff --git a/db/changes/10491-august/00-ACL_workerDisableExcluded.sql b/db/changes/10491-august/00-ACL_workerDisableExcluded.sql index 3d84c751c..7a23ca68a 100644 --- a/db/changes/10491-august/00-ACL_workerDisableExcluded.sql +++ b/db/changes/10491-august/00-ACL_workerDisableExcluded.sql @@ -1,20 +1,2 @@ -INSERT INTO - salix.ACL ( - id, - model, - property, - accessType, - permission, - principalType, - principalId - ) -VALUES -( - 344, - 'WorkerDisableExcluded', - '*', - '*', - 'ALLOW', - 'ROLE', - 'employee' - ); \ No newline at end of file +INSERT INTO `salix`.`ACL` (model,property,accessType,permission,principalId) + VALUES ('WorkerDisableExcluded','*','*','ALLOW','employee'); From 23598c993b74572e0a658d66560636197832d9b4 Mon Sep 17 00:00:00 2001 From: Pau Navarro Date: Tue, 25 Oct 2022 09:25:15 +0200 Subject: [PATCH 08/15] Change ACL from employee to hr --- db/changes/10491-august/00-ACL_workerDisableExcluded.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/db/changes/10491-august/00-ACL_workerDisableExcluded.sql b/db/changes/10491-august/00-ACL_workerDisableExcluded.sql index 7a23ca68a..2fd9e8b12 100644 --- a/db/changes/10491-august/00-ACL_workerDisableExcluded.sql +++ b/db/changes/10491-august/00-ACL_workerDisableExcluded.sql @@ -1,2 +1,2 @@ INSERT INTO `salix`.`ACL` (model,property,accessType,permission,principalId) - VALUES ('WorkerDisableExcluded','*','*','ALLOW','employee'); + VALUES ('WorkerDisableExcluded','*','*','ALLOW','hr'); \ No newline at end of file From f65d06fc7db84905be5543c7a1f7e34ebece9ce9 Mon Sep 17 00:00:00 2001 From: alexm Date: Wed, 26 Oct 2022 08:27:28 +0200 Subject: [PATCH 09/15] fixes #4073 --- back/methods/account/privileges.js | 26 +++++++++------ back/methods/account/specs/privileges.spec.js | 14 ++++---- db/changes/10490-august/00-user_hasGrant.sql | 3 ++ db/dump/fixtures.sql | 8 ++--- e2e/paths/14-account/07_ldap.spec.js | 9 ++++++ e2e/paths/14-account/08_samba.spec.js | 9 ++++++ e2e/paths/14-account/09_privileges.spec.js | 32 +++++++++++++++++-- loopback/locale/en.json | 6 ++-- loopback/locale/es.json | 6 ++-- .../account/front/privileges/locale/es.yml | 2 +- modules/client/back/models/client.js | 9 ++++-- 11 files changed, 93 insertions(+), 31 deletions(-) diff --git a/back/methods/account/privileges.js b/back/methods/account/privileges.js index df421125e..6510779f2 100644 --- a/back/methods/account/privileges.js +++ b/back/methods/account/privileges.js @@ -29,6 +29,8 @@ module.exports = Self => { }); Self.privileges = async function(ctx, id, roleFk, hasGrant, options) { + if (!(hasGrant != null || roleFk)) return; + const models = Self.app.models; const userId = ctx.req.accessToken.userId; @@ -37,22 +39,26 @@ module.exports = Self => { if (typeof options == 'object') Object.assign(myOptions, options); - const user = await models.Account.findById(userId, null, myOptions); + const user = await models.Account.findById(userId, {fields: ['hasGrant']}, myOptions); if (!user.hasGrant) - throw new UserError(`You don't have enough privileges`); + throw new UserError(`You don't have grant privilege`); - const userToUpdate = await models.Account.findById(id); + const userToUpdate = await models.Account.findById(id, ['name', 'hasGrant', 'roleFk'], myOptions); if (hasGrant != null) - return await userToUpdate.updateAttribute('hasGrant', hasGrant, myOptions); - if (!roleFk) return; + userToUpdate.hasGrant = hasGrant; - const role = await models.Role.findById(roleFk, null, myOptions); - const hasRole = await models.Account.hasRole(userId, role.name, myOptions); + if (roleFk) { + const role = await models.Role.findById(roleFk, {fields: ['name']}, myOptions); + const hasRole = await models.Account.hasRole(userId, role.name, myOptions); - if (!hasRole) - throw new UserError(`You don't have enough privileges`); + if (!hasRole) + throw new UserError(`You don't own the role and you can't assign it to another user`); - await userToUpdate.updateAttribute('roleFk', roleFk, myOptions); + userToUpdate.roleFk = roleFk; + } + + await userToUpdate.save(userToUpdate); + await models.UserAccount.sync(userToUpdate.name); }; }; diff --git a/back/methods/account/specs/privileges.spec.js b/back/methods/account/specs/privileges.spec.js index 137c08671..959130e8b 100644 --- a/back/methods/account/specs/privileges.spec.js +++ b/back/methods/account/specs/privileges.spec.js @@ -4,7 +4,7 @@ describe('account privileges()', () => { const employeeId = 1; const developerId = 9; const sysadminId = 66; - const bruceWayneId = 1101; + const clarkKent = 1103; it('should throw an error when user not has privileges', async() => { const ctx = {req: {accessToken: {userId: developerId}}}; @@ -22,7 +22,7 @@ describe('account privileges()', () => { await tx.rollback(); } - expect(error.message).toContain(`You don't have enough privileges`); + expect(error.message).toContain(`You don't have grant privilege`); }); it('should throw an error when user has privileges but not has the role', async() => { @@ -46,7 +46,7 @@ describe('account privileges()', () => { await tx.rollback(); } - expect(error.message).toContain(`You don't have enough privileges`); + expect(error.message).toContain(`You don't own the role and you can't assign it to another user`); }); it('should change role', async() => { @@ -63,8 +63,8 @@ describe('account privileges()', () => { let error; let result; try { - await models.Account.privileges(ctx, bruceWayneId, agency.id, null, options); - result = await models.Account.findById(bruceWayneId, null, options); + await models.Account.privileges(ctx, clarkKent, agency.id, null, options); + result = await models.Account.findById(clarkKent, null, options); await tx.rollback(); } catch (e) { @@ -84,8 +84,8 @@ describe('account privileges()', () => { let result; try { const options = {transaction: tx}; - await models.Account.privileges(ctx, bruceWayneId, null, true, options); - result = await models.Account.findById(bruceWayneId, null, options); + await models.Account.privileges(ctx, clarkKent, null, true, options); + result = await models.Account.findById(clarkKent, null, options); await tx.rollback(); } catch (e) { diff --git a/db/changes/10490-august/00-user_hasGrant.sql b/db/changes/10490-august/00-user_hasGrant.sql index 60d1273d8..05a09f87b 100644 --- a/db/changes/10490-august/00-user_hasGrant.sql +++ b/db/changes/10490-august/00-user_hasGrant.sql @@ -1 +1,4 @@ ALTER TABLE `account`.`user` ADD hasGrant TINYINT(1) NOT NULL; + +INSERT INTO `salix`.`ACL` (model, property, accessType, permission, principalType, principalId) + VALUES('Account', 'privileges', '*', 'ALLOW', 'ROLE', '$authenticated'); diff --git a/db/dump/fixtures.sql b/db/dump/fixtures.sql index 7e59c1a54..c4079adc0 100644 --- a/db/dump/fixtures.sql +++ b/db/dump/fixtures.sql @@ -14,10 +14,10 @@ INSERT INTO `salix`.`AccessToken` (`id`, `ttl`, `created`, `userId`) ('DEFAULT_TOKEN', '1209600', util.VN_CURDATE(), 66); INSERT INTO `salix`.`printConfig` (`id`, `itRecipient`, `incidencesEmail`) - VALUES + VALUES (1, 'it@gotamcity.com', 'incidences@gotamcity.com'); -INSERT INTO `vn`.`ticketConfig` (`id`, `scopeDays`) +INSERT INTO `vn`.`ticketConfig` (`id`, `scopeDays`) VALUES ('1', '6'); @@ -45,8 +45,8 @@ INSERT INTO `account`.`roleConfig`(`id`, `mysqlPassword`, `rolePrefix`, `userPre CALL `account`.`role_sync`; -INSERT INTO `account`.`user`(`id`,`name`, `nickname`, `password`,`role`,`active`,`email`, `lang`, `image`) - SELECT id, name, CONCAT(name, 'Nick'),MD5('nightmare'), id, 1, CONCAT(name, '@mydomain.com'), 'en', '4fa3ada0-3ac4-11eb-9ab8-27f6fc3b85fd' +INSERT INTO `account`.`user`(`id`,`name`, `nickname`, `password`,`role`,`active`,`email`, `lang`, `image`, `bcryptPassword`) + SELECT id, name, CONCAT(name, 'Nick'),MD5('nightmare'), id, 1, CONCAT(name, '@mydomain.com'), 'en', '4fa3ada0-3ac4-11eb-9ab8-27f6fc3b85fd', '$2b$10$UzQHth.9UUQ1T5aiQJ21lOU0oVlbxoqH4PFM9V8T90KNSAcg0eEL2' FROM `account`.`role` WHERE id <> 20 ORDER BY id; diff --git a/e2e/paths/14-account/07_ldap.spec.js b/e2e/paths/14-account/07_ldap.spec.js index a3b8137d3..eb22f695c 100644 --- a/e2e/paths/14-account/07_ldap.spec.js +++ b/e2e/paths/14-account/07_ldap.spec.js @@ -29,4 +29,13 @@ describe('Account LDAP path', () => { expect(message.text).toContain('Data saved!'); }); + + it('should reset data', async() => { + await page.waitToClick(selectors.accountLdap.checkEnable); + await page.waitToClick(selectors.accountLdap.save); + + const message = await page.waitForSnackbar(); + + expect(message.text).toContain('Data saved!'); + }); }); diff --git a/e2e/paths/14-account/08_samba.spec.js b/e2e/paths/14-account/08_samba.spec.js index c3db026dc..6e7ef9bbf 100644 --- a/e2e/paths/14-account/08_samba.spec.js +++ b/e2e/paths/14-account/08_samba.spec.js @@ -29,4 +29,13 @@ describe('Account Samba path', () => { expect(message.text).toContain('Data saved!'); }); + + it('should reset data', async() => { + await page.waitToClick(selectors.accountSamba.checkEnable); + await page.waitToClick(selectors.accountSamba.save); + + const message = await page.waitForSnackbar(); + + expect(message.text).toContain('Data saved!'); + }); }); diff --git a/e2e/paths/14-account/09_privileges.spec.js b/e2e/paths/14-account/09_privileges.spec.js index 71e9345a8..e4b8fb24c 100644 --- a/e2e/paths/14-account/09_privileges.spec.js +++ b/e2e/paths/14-account/09_privileges.spec.js @@ -24,7 +24,7 @@ describe('Account privileges path', () => { const message = await page.waitForSnackbar(); - expect(message.text).toContain(`You don't have enough privileges`); + expect(message.text).toContain(`You don't have grant privilege`); }); it('should throw error when change role', async() => { @@ -33,7 +33,7 @@ describe('Account privileges path', () => { const message = await page.waitForSnackbar(); - expect(message.text).toContain(`You don't have enough privileges`); + expect(message.text).toContain(`You don't have grant privilege`); }); }); @@ -56,7 +56,16 @@ describe('Account privileges path', () => { expect(result).toBe('checked'); }); - it('should change role', async() => { + it('should throw error when change role and not own role', async() => { + await page.autocompleteSearch(selectors.accountPrivileges.role, 'itBoss'); + await page.waitToClick(selectors.accountPrivileges.save); + + const message = await page.waitForSnackbar(); + + expect(message.text).toContain(`You don't own the role and you can't assign it to another user`); + }); + + it('should change role to employee', async() => { await page.autocompleteSearch(selectors.accountPrivileges.role, 'employee'); await page.waitToClick(selectors.accountPrivileges.save); const message = await page.waitForSnackbar(); @@ -67,6 +76,18 @@ describe('Account privileges path', () => { expect(message.text).toContain(`Data saved!`); expect(result).toContain('employee'); }); + + it('should return role to developer', async() => { + await page.autocompleteSearch(selectors.accountPrivileges.role, 'developer'); + await page.waitToClick(selectors.accountPrivileges.save); + const message = await page.waitForSnackbar(); + + await page.reloadSection('account.card.privileges'); + const result = await page.waitToGetProperty(selectors.accountPrivileges.role, 'value'); + + expect(message.text).toContain(`Data saved!`); + expect(result).toContain('developer'); + }); }); describe('as developer again', () => { @@ -76,7 +97,12 @@ describe('Account privileges path', () => { await page.waitToClick(selectors.accountPrivileges.checkHasGrant); await page.waitToClick(selectors.accountPrivileges.save); + const message = await page.waitForSnackbar(); + expect(message.text).toContain(`Data saved!`); + }); + + it('should logIn in developer', async() => { await page.reloadSection('account.card.privileges'); const result = await page.checkboxState(selectors.accountPrivileges.checkHasGrant); diff --git a/loopback/locale/en.json b/loopback/locale/en.json index e5a0fae32..1e151294f 100644 --- a/loopback/locale/en.json +++ b/loopback/locale/en.json @@ -133,5 +133,7 @@ "Descanso semanal 36h. / 72h.": "Weekly rest 36h. / 72h.", "Password does not meet requirements": "Password does not meet requirements", "You don't have privileges to change the zone": "You don't have privileges to change the zone or for these parameters there are more than one shipping options, talk to agencies", - "Not enough privileges to edit a client": "Not enough privileges to edit a client" -} \ No newline at end of file + "Not enough privileges to edit a client": "Not enough privileges to edit a client", + "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" +} diff --git a/loopback/locale/es.json b/loopback/locale/es.json index 67370b343..a41315dd1 100644 --- a/loopback/locale/es.json +++ b/loopback/locale/es.json @@ -235,5 +235,7 @@ "Dirección incorrecta": "Dirección incorrecta", "Modifiable user details only by an administrator": "Detalles de usuario modificables solo por un administrador", "Modifiable password only via recovery or by an administrator": "Contraseña modificable solo a través de la recuperación o por un administrador", - "Not enough privileges to edit a client": "No tienes suficientes privilegios para editar un cliente" -} \ No newline at end of file + "Not enough privileges to edit a client": "No tienes suficientes privilegios para editar un cliente", + "You don't have grant privilege": "No tienes privilegios para dar privilegios", + "You don't own the role and you can't assign it to another user": "No eres el propietario del rol y no puedes asignarlo a otro usuario" +} diff --git a/modules/account/front/privileges/locale/es.yml b/modules/account/front/privileges/locale/es.yml index f7330e1be..17f1ef29e 100644 --- a/modules/account/front/privileges/locale/es.yml +++ b/modules/account/front/privileges/locale/es.yml @@ -1,2 +1,2 @@ Privileges: Privilegios -Has grant: Tiene privilegios +Has grant: Puede dar privilegios diff --git a/modules/client/back/models/client.js b/modules/client/back/models/client.js index 3bd89eff1..e66cdb83f 100644 --- a/modules/client/back/models/client.js +++ b/modules/client/back/models/client.js @@ -425,14 +425,19 @@ module.exports = Self => { account.observe('before save', async ctx => { if (ctx.isNewInstance) return; - ctx.hookState.oldInstance = JSON.parse(JSON.stringify(ctx.currentInstance)); + if (ctx.currentInstance) + ctx.hookState.oldInstance = JSON.parse(JSON.stringify(ctx.currentInstance)); }); account.observe('after save', async ctx => { const changes = ctx.data || ctx.instance; if (!ctx.isNewInstance && changes) { const oldData = ctx.hookState.oldInstance; - const hasChanges = oldData.name != changes.name || oldData.active != changes.active; + let hasChanges; + + if (oldData) + hasChanges = oldData.name != changes.name || oldData.active != changes.active; + if (!hasChanges) return; const isClient = await Self.app.models.Client.count({id: oldData.id}); From 3ffc098b56d8ee9724edfe2c26a8e5813ab11857 Mon Sep 17 00:00:00 2001 From: alexm Date: Thu, 27 Oct 2022 09:01:09 +0200 Subject: [PATCH 10/15] feat(privileges): check if user has role from userToUpdate --- back/methods/account/privileges.js | 17 +++++++++++++++-- back/models/account.json | 7 +++++++ db/changes/10490-august/00-user_hasGrant.sql | 3 --- modules/account/front/privileges/locale/es.yml | 2 +- package.json | 2 +- 5 files changed, 24 insertions(+), 7 deletions(-) diff --git a/back/methods/account/privileges.js b/back/methods/account/privileges.js index 6510779f2..f3f500e7d 100644 --- a/back/methods/account/privileges.js +++ b/back/methods/account/privileges.js @@ -44,15 +44,28 @@ module.exports = Self => { if (!user.hasGrant) throw new UserError(`You don't have grant privilege`); - const userToUpdate = await models.Account.findById(id, ['name', 'hasGrant', 'roleFk'], myOptions); + const [userToUpdate] = await models.Account.find({ + fields: ['id', 'name', 'hasGrant', 'roleFk', 'password'], + include: { + relation: 'role', + scope: { + fields: ['name'] + } + }, + where: { + id: id + } + }, myOptions); + if (hasGrant != null) userToUpdate.hasGrant = hasGrant; if (roleFk) { const role = await models.Role.findById(roleFk, {fields: ['name']}, myOptions); const hasRole = await models.Account.hasRole(userId, role.name, myOptions); + const hasRoleFromUser = await models.Account.hasRole(userId, userToUpdate.role().name, myOptions); - if (!hasRole) + if (!hasRole || !hasRoleFromUser) throw new UserError(`You don't own the role and you can't assign it to another user`); userToUpdate.roleFk = roleFk; diff --git a/back/models/account.json b/back/models/account.json index c25cd532d..d0c17e70f 100644 --- a/back/models/account.json +++ b/back/models/account.json @@ -102,6 +102,13 @@ "principalType": "ROLE", "principalId": "$authenticated", "permission": "ALLOW" + }, + { + "property": "privileges", + "accessType": "*", + "principalType": "ROLE", + "principalId": "$authenticated", + "permission": "ALLOW" } ] } diff --git a/db/changes/10490-august/00-user_hasGrant.sql b/db/changes/10490-august/00-user_hasGrant.sql index 05a09f87b..60d1273d8 100644 --- a/db/changes/10490-august/00-user_hasGrant.sql +++ b/db/changes/10490-august/00-user_hasGrant.sql @@ -1,4 +1 @@ ALTER TABLE `account`.`user` ADD hasGrant TINYINT(1) NOT NULL; - -INSERT INTO `salix`.`ACL` (model, property, accessType, permission, principalType, principalId) - VALUES('Account', 'privileges', '*', 'ALLOW', 'ROLE', '$authenticated'); diff --git a/modules/account/front/privileges/locale/es.yml b/modules/account/front/privileges/locale/es.yml index 17f1ef29e..d66a7a6cf 100644 --- a/modules/account/front/privileges/locale/es.yml +++ b/modules/account/front/privileges/locale/es.yml @@ -1,2 +1,2 @@ Privileges: Privilegios -Has grant: Puede dar privilegios +Has grant: Puede delegar privilegios diff --git a/package.json b/package.json index 92ca13e45..573e42335 100644 --- a/package.json +++ b/package.json @@ -37,7 +37,7 @@ "node-ssh": "^11.0.0", "object-diff": "0.0.4", "object.pick": "^1.3.0", - "puppeteer": "^18.0.5", + "puppeteer": "^19.0.0", "read-chunk": "^3.2.0", "require-yaml": "0.0.1", "sharp": "^0.27.1", From 5c65314162a8e3d821cf9346ad454828306a7de1 Mon Sep 17 00:00:00 2001 From: alexm Date: Thu, 27 Oct 2022 09:27:50 +0200 Subject: [PATCH 11/15] use findById --- back/methods/account/privileges.js | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/back/methods/account/privileges.js b/back/methods/account/privileges.js index f3f500e7d..d3aa9bf59 100644 --- a/back/methods/account/privileges.js +++ b/back/methods/account/privileges.js @@ -44,16 +44,13 @@ module.exports = Self => { if (!user.hasGrant) throw new UserError(`You don't have grant privilege`); - const [userToUpdate] = await models.Account.find({ + const userToUpdate = await models.Account.findById(id, { fields: ['id', 'name', 'hasGrant', 'roleFk', 'password'], include: { relation: 'role', scope: { fields: ['name'] } - }, - where: { - id: id } }, myOptions); From ad1b429d10d1d0d66373f54fbc9c6fafbae57600 Mon Sep 17 00:00:00 2001 From: alexm Date: Fri, 28 Oct 2022 08:09:47 +0200 Subject: [PATCH 12/15] check if user has role from userToUpdate --- back/methods/account/privileges.js | 14 ++++++---- back/methods/account/specs/privileges.spec.js | 28 +++++++++++++++---- 2 files changed, 31 insertions(+), 11 deletions(-) diff --git a/back/methods/account/privileges.js b/back/methods/account/privileges.js index d3aa9bf59..5c5e7409d 100644 --- a/back/methods/account/privileges.js +++ b/back/methods/account/privileges.js @@ -41,9 +41,6 @@ module.exports = Self => { const user = await models.Account.findById(userId, {fields: ['hasGrant']}, myOptions); - if (!user.hasGrant) - throw new UserError(`You don't have grant privilege`); - const userToUpdate = await models.Account.findById(id, { fields: ['id', 'name', 'hasGrant', 'roleFk', 'password'], include: { @@ -54,15 +51,22 @@ module.exports = Self => { } }, myOptions); + if (!user.hasGrant) + throw new UserError(`You don't have grant privilege`); + + const hasRoleFromUser = await models.Account.hasRole(userId, userToUpdate.role().name, myOptions); + + if (!hasRoleFromUser) + throw new UserError(`You don't own the role and you can't assign it to another user`); + if (hasGrant != null) userToUpdate.hasGrant = hasGrant; if (roleFk) { const role = await models.Role.findById(roleFk, {fields: ['name']}, myOptions); const hasRole = await models.Account.hasRole(userId, role.name, myOptions); - const hasRoleFromUser = await models.Account.hasRole(userId, userToUpdate.role().name, myOptions); - if (!hasRole || !hasRoleFromUser) + if (!hasRole) throw new UserError(`You don't own the role and you can't assign it to another user`); userToUpdate.roleFk = roleFk; diff --git a/back/methods/account/specs/privileges.spec.js b/back/methods/account/specs/privileges.spec.js index 959130e8b..edfe0f03f 100644 --- a/back/methods/account/specs/privileges.spec.js +++ b/back/methods/account/specs/privileges.spec.js @@ -4,6 +4,8 @@ describe('account privileges()', () => { const employeeId = 1; const developerId = 9; const sysadminId = 66; + const itBossId = 104; + const rootId = 100; const clarkKent = 1103; it('should throw an error when user not has privileges', async() => { @@ -33,12 +35,26 @@ describe('account privileges()', () => { try { const options = {transaction: tx}; - const root = await models.Role.findOne({ - where: { - name: 'root' - } - }, options); - await models.Account.privileges(ctx, employeeId, root.id, null, options); + await models.Account.privileges(ctx, employeeId, rootId, null, options); + + await tx.rollback(); + } catch (e) { + error = e; + await tx.rollback(); + } + + expect(error.message).toContain(`You don't own the role and you can't assign it to another user`); + }); + + it('should throw an error when user has privileges but not has the role from user', async() => { + const ctx = {req: {accessToken: {userId: sysadminId}}}; + const tx = await models.Account.beginTransaction({}); + + let error; + try { + const options = {transaction: tx}; + + await models.Account.privileges(ctx, itBossId, developerId, null, options); await tx.rollback(); } catch (e) { From 57e74fab38f00017cd2cc41621dfa475b5724e2a Mon Sep 17 00:00:00 2001 From: alexandre Date: Fri, 28 Oct 2022 15:53:57 +0200 Subject: [PATCH 13/15] refs #4716 tipos actualizados --- print/templates/email/campaign-metrics/campaign-metrics.js | 2 +- .../templates/email/claim-pickup-order/claim-pickup-order.js | 2 +- .../email/client-debt-statement/client-debt-statement.js | 2 +- print/templates/email/client-welcome/client-welcome.js | 2 +- .../templates/email/delivery-note-link/delivery-note-link.js | 2 +- print/templates/email/delivery-note/delivery-note.js | 2 +- print/templates/email/driver-route/driver-route.js | 2 +- .../email/incoterms-authorization/incoterms-authorization.js | 4 ++-- print/templates/email/invoice/invoice.js | 2 +- print/templates/email/letter-debtor-nd/letter-debtor-nd.js | 4 ++-- print/templates/email/letter-debtor-st/letter-debtor-st.js | 4 ++-- print/templates/email/payment-update/payment-update.js | 2 +- print/templates/email/printer-setup/printer-setup.js | 2 +- print/templates/email/sepa-core/sepa-core.js | 4 ++-- .../supplier-campaign-metrics/supplier-campaign-metrics.js | 2 +- print/templates/reports/campaign-metrics/campaign-metrics.js | 2 +- .../reports/claim-pickup-order/claim-pickup-order.js | 2 +- .../reports/client-debt-statement/client-debt-statement.js | 2 +- print/templates/reports/delivery-note/delivery-note.js | 2 +- print/templates/reports/driver-route/driver-route.js | 2 +- print/templates/reports/entry-order/entry-order.js | 2 +- print/templates/reports/exportation/exportation.js | 2 +- .../incoterms-authorization/incoterms-authorization.js | 4 ++-- .../templates/reports/invoice-incoterms/invoice-incoterms.js | 2 +- print/templates/reports/letter-debtor/letter-debtor.js | 4 ++-- print/templates/reports/receipt/receipt.js | 2 +- print/templates/reports/sepa-core/sepa-core.js | 4 ++-- .../supplier-campaign-metrics/supplier-campaign-metrics.js | 2 +- print/templates/reports/zone/zone.js | 2 +- 29 files changed, 36 insertions(+), 36 deletions(-) diff --git a/print/templates/email/campaign-metrics/campaign-metrics.js b/print/templates/email/campaign-metrics/campaign-metrics.js index 0c3a01991..c3ff4a5ca 100755 --- a/print/templates/email/campaign-metrics/campaign-metrics.js +++ b/print/templates/email/campaign-metrics/campaign-metrics.js @@ -21,7 +21,7 @@ module.exports = { }, props: { id: { - type: [Number, String], + type: Number, required: true }, from: { diff --git a/print/templates/email/claim-pickup-order/claim-pickup-order.js b/print/templates/email/claim-pickup-order/claim-pickup-order.js index d3836db39..bdb338628 100755 --- a/print/templates/email/claim-pickup-order/claim-pickup-order.js +++ b/print/templates/email/claim-pickup-order/claim-pickup-order.js @@ -10,7 +10,7 @@ module.exports = { }, props: { id: { - type: [Number, String], + type: Number, required: true } } diff --git a/print/templates/email/client-debt-statement/client-debt-statement.js b/print/templates/email/client-debt-statement/client-debt-statement.js index 85b3c5cc3..06b81199b 100755 --- a/print/templates/email/client-debt-statement/client-debt-statement.js +++ b/print/templates/email/client-debt-statement/client-debt-statement.js @@ -23,7 +23,7 @@ module.exports = { }, props: { id: { - type: [Number, String], + type: Number, required: true }, from: { diff --git a/print/templates/email/client-welcome/client-welcome.js b/print/templates/email/client-welcome/client-welcome.js index 380837877..8fcba39ad 100755 --- a/print/templates/email/client-welcome/client-welcome.js +++ b/print/templates/email/client-welcome/client-welcome.js @@ -18,7 +18,7 @@ module.exports = { }, props: { id: { - type: [Number, String], + type: Number, required: true } } diff --git a/print/templates/email/delivery-note-link/delivery-note-link.js b/print/templates/email/delivery-note-link/delivery-note-link.js index 1804bf144..8df9826c2 100755 --- a/print/templates/email/delivery-note-link/delivery-note-link.js +++ b/print/templates/email/delivery-note-link/delivery-note-link.js @@ -10,7 +10,7 @@ module.exports = { }, props: { id: { - type: [Number, String], + type: Number, required: true } } diff --git a/print/templates/email/delivery-note/delivery-note.js b/print/templates/email/delivery-note/delivery-note.js index ba3d44001..672f70b18 100755 --- a/print/templates/email/delivery-note/delivery-note.js +++ b/print/templates/email/delivery-note/delivery-note.js @@ -10,7 +10,7 @@ module.exports = { }, props: { id: { - type: [Number, String], + type: Number, required: true } } diff --git a/print/templates/email/driver-route/driver-route.js b/print/templates/email/driver-route/driver-route.js index 0895ccc8c..fb459fa93 100755 --- a/print/templates/email/driver-route/driver-route.js +++ b/print/templates/email/driver-route/driver-route.js @@ -10,7 +10,7 @@ module.exports = { }, props: { id: { - type: [Number, String], + type: Number, required: true } } diff --git a/print/templates/email/incoterms-authorization/incoterms-authorization.js b/print/templates/email/incoterms-authorization/incoterms-authorization.js index b1c7286dd..1665fb580 100755 --- a/print/templates/email/incoterms-authorization/incoterms-authorization.js +++ b/print/templates/email/incoterms-authorization/incoterms-authorization.js @@ -23,12 +23,12 @@ module.exports = { }, props: { id: { - type: [Number, String], + type: Number, required: true, description: 'The client id' }, companyId: { - type: [Number, String], + type: Number, required: true } } diff --git a/print/templates/email/invoice/invoice.js b/print/templates/email/invoice/invoice.js index fe66062aa..6720e7102 100755 --- a/print/templates/email/invoice/invoice.js +++ b/print/templates/email/invoice/invoice.js @@ -18,7 +18,7 @@ module.exports = { }, props: { reference: { - type: [Number, String], + type: Number, required: true } } diff --git a/print/templates/email/letter-debtor-nd/letter-debtor-nd.js b/print/templates/email/letter-debtor-nd/letter-debtor-nd.js index cf9cc7ddd..35a7d8655 100755 --- a/print/templates/email/letter-debtor-nd/letter-debtor-nd.js +++ b/print/templates/email/letter-debtor-nd/letter-debtor-nd.js @@ -34,11 +34,11 @@ module.exports = { }, props: { id: { - type: [Number, String], + type: Number, required: true }, companyId: { - type: [Number, String], + type: Number, required: true } } diff --git a/print/templates/email/letter-debtor-st/letter-debtor-st.js b/print/templates/email/letter-debtor-st/letter-debtor-st.js index 1a6555673..0fd2b45c7 100755 --- a/print/templates/email/letter-debtor-st/letter-debtor-st.js +++ b/print/templates/email/letter-debtor-st/letter-debtor-st.js @@ -34,11 +34,11 @@ module.exports = { }, props: { id: { - type: [Number, String], + type: Number, required: true }, companyId: { - type: [Number, String], + type: Number, required: true }, } diff --git a/print/templates/email/payment-update/payment-update.js b/print/templates/email/payment-update/payment-update.js index a9d99d4ef..11ace3410 100755 --- a/print/templates/email/payment-update/payment-update.js +++ b/print/templates/email/payment-update/payment-update.js @@ -26,7 +26,7 @@ module.exports = { }, props: { id: { - type: [Number, String], + type: Number, required: true, description: 'The client id' } diff --git a/print/templates/email/printer-setup/printer-setup.js b/print/templates/email/printer-setup/printer-setup.js index a7d3c40bf..8de0fc54f 100755 --- a/print/templates/email/printer-setup/printer-setup.js +++ b/print/templates/email/printer-setup/printer-setup.js @@ -24,7 +24,7 @@ module.exports = { }, props: { id: { - type: [Number, String], + type: Number, required: true } } diff --git a/print/templates/email/sepa-core/sepa-core.js b/print/templates/email/sepa-core/sepa-core.js index 00cc527dc..33eb86bce 100755 --- a/print/templates/email/sepa-core/sepa-core.js +++ b/print/templates/email/sepa-core/sepa-core.js @@ -16,11 +16,11 @@ module.exports = { }, props: { id: { - type: [Number, String], + type: Number, required: true }, companyId: { - type: [Number, String], + type: Number, required: true } } diff --git a/print/templates/email/supplier-campaign-metrics/supplier-campaign-metrics.js b/print/templates/email/supplier-campaign-metrics/supplier-campaign-metrics.js index 9cb9210ef..dee227ea2 100755 --- a/print/templates/email/supplier-campaign-metrics/supplier-campaign-metrics.js +++ b/print/templates/email/supplier-campaign-metrics/supplier-campaign-metrics.js @@ -21,7 +21,7 @@ module.exports = { }, props: { id: { - type: [Number, String], + type: Number, required: true }, from: { diff --git a/print/templates/reports/campaign-metrics/campaign-metrics.js b/print/templates/reports/campaign-metrics/campaign-metrics.js index b60a2b7eb..7c3913549 100755 --- a/print/templates/reports/campaign-metrics/campaign-metrics.js +++ b/print/templates/reports/campaign-metrics/campaign-metrics.js @@ -25,7 +25,7 @@ module.exports = { }, props: { id: { - type: [Number, String], + type: Number, required: true, description: 'The client id' }, diff --git a/print/templates/reports/claim-pickup-order/claim-pickup-order.js b/print/templates/reports/claim-pickup-order/claim-pickup-order.js index f7d21a2d3..358adbadd 100755 --- a/print/templates/reports/claim-pickup-order/claim-pickup-order.js +++ b/print/templates/reports/claim-pickup-order/claim-pickup-order.js @@ -36,7 +36,7 @@ module.exports = { }, props: { id: { - type: [Number, String], + type: Number, required: true, description: 'The claim id' } diff --git a/print/templates/reports/client-debt-statement/client-debt-statement.js b/print/templates/reports/client-debt-statement/client-debt-statement.js index 80c83b494..81e9d7f43 100755 --- a/print/templates/reports/client-debt-statement/client-debt-statement.js +++ b/print/templates/reports/client-debt-statement/client-debt-statement.js @@ -69,7 +69,7 @@ module.exports = { }, props: { id: { - type: [Number, String], + type: Number, required: true, description: 'The client id' }, diff --git a/print/templates/reports/delivery-note/delivery-note.js b/print/templates/reports/delivery-note/delivery-note.js index 1037e5129..7045ef709 100755 --- a/print/templates/reports/delivery-note/delivery-note.js +++ b/print/templates/reports/delivery-note/delivery-note.js @@ -127,7 +127,7 @@ module.exports = { }, props: { id: { - type: [Number, String], + type: Number, required: true, description: 'The ticket id' }, diff --git a/print/templates/reports/driver-route/driver-route.js b/print/templates/reports/driver-route/driver-route.js index 2de3d5192..001537941 100755 --- a/print/templates/reports/driver-route/driver-route.js +++ b/print/templates/reports/driver-route/driver-route.js @@ -44,7 +44,7 @@ module.exports = { }, props: { id: { - type: [Number, String], + type: Number, required: true, description: 'The route id' } diff --git a/print/templates/reports/entry-order/entry-order.js b/print/templates/reports/entry-order/entry-order.js index ff4a65e0c..18fc4a5ea 100755 --- a/print/templates/reports/entry-order/entry-order.js +++ b/print/templates/reports/entry-order/entry-order.js @@ -40,7 +40,7 @@ module.exports = { }, props: { id: { - type: [Number, String], + type: Number, required: true, description: 'The entry id' } diff --git a/print/templates/reports/exportation/exportation.js b/print/templates/reports/exportation/exportation.js index 630baf421..0aab05fee 100755 --- a/print/templates/reports/exportation/exportation.js +++ b/print/templates/reports/exportation/exportation.js @@ -30,7 +30,7 @@ module.exports = { }, props: { reference: { - type: [Number, String], + type: Number, required: true, description: 'The invoice ref' } diff --git a/print/templates/reports/incoterms-authorization/incoterms-authorization.js b/print/templates/reports/incoterms-authorization/incoterms-authorization.js index 26637b8c2..3eb5b65ea 100755 --- a/print/templates/reports/incoterms-authorization/incoterms-authorization.js +++ b/print/templates/reports/incoterms-authorization/incoterms-authorization.js @@ -21,12 +21,12 @@ module.exports = { }, props: { id: { - type: [Number, String], + type: Number, required: true, description: 'The client id' }, companyId: { - type: [Number, String], + type: Number, required: true } } diff --git a/print/templates/reports/invoice-incoterms/invoice-incoterms.js b/print/templates/reports/invoice-incoterms/invoice-incoterms.js index 3dbe76ac3..ba9981373 100755 --- a/print/templates/reports/invoice-incoterms/invoice-incoterms.js +++ b/print/templates/reports/invoice-incoterms/invoice-incoterms.js @@ -32,7 +32,7 @@ module.exports = { }, props: { reference: { - type: [Number, String], + type: Number, required: true, description: 'The invoice ref' } diff --git a/print/templates/reports/letter-debtor/letter-debtor.js b/print/templates/reports/letter-debtor/letter-debtor.js index 80d4cba9b..083d9fd71 100755 --- a/print/templates/reports/letter-debtor/letter-debtor.js +++ b/print/templates/reports/letter-debtor/letter-debtor.js @@ -63,12 +63,12 @@ module.exports = { }, props: { id: { - type: [Number, String], + type: Number, required: true, description: 'The client id' }, companyId: { - type: [Number, String], + type: Number, required: true } } diff --git a/print/templates/reports/receipt/receipt.js b/print/templates/reports/receipt/receipt.js index 401aa1ef3..b368764b1 100755 --- a/print/templates/reports/receipt/receipt.js +++ b/print/templates/reports/receipt/receipt.js @@ -25,7 +25,7 @@ module.exports = { }, props: { id: { - type: [Number, String], + type: Number, required: true, description: 'Receipt id' } diff --git a/print/templates/reports/sepa-core/sepa-core.js b/print/templates/reports/sepa-core/sepa-core.js index 73e0beaaa..85121b392 100755 --- a/print/templates/reports/sepa-core/sepa-core.js +++ b/print/templates/reports/sepa-core/sepa-core.js @@ -40,12 +40,12 @@ const rptSepaCore = { }, props: { id: { - type: [Number, String], + type: Number, required: true, description: 'The client id' }, companyId: { - type: [Number, String], + type: Number, required: true } } diff --git a/print/templates/reports/supplier-campaign-metrics/supplier-campaign-metrics.js b/print/templates/reports/supplier-campaign-metrics/supplier-campaign-metrics.js index 6a58cbd0e..fee5796d2 100755 --- a/print/templates/reports/supplier-campaign-metrics/supplier-campaign-metrics.js +++ b/print/templates/reports/supplier-campaign-metrics/supplier-campaign-metrics.js @@ -49,7 +49,7 @@ module.exports = { }, props: { id: { - type: [Number, String], + type: Number, required: true, description: 'The supplier id' }, diff --git a/print/templates/reports/zone/zone.js b/print/templates/reports/zone/zone.js index bbce9df36..d237c50c0 100755 --- a/print/templates/reports/zone/zone.js +++ b/print/templates/reports/zone/zone.js @@ -13,7 +13,7 @@ module.exports = { }, props: { id: { - type: [Number, String], + type: Number, required: true, description: 'The zone id' } From 463d3e6e1292431b89fb7e4ebc5c017dcfe5cadc Mon Sep 17 00:00:00 2001 From: joan Date: Mon, 31 Oct 2022 12:39:26 +0100 Subject: [PATCH 14/15] Fixes --- modules/claim/back/models/claim-rma.json | 2 +- modules/claim/back/models/claim.json | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/modules/claim/back/models/claim-rma.json b/modules/claim/back/models/claim-rma.json index e3849422c..27c3c9729 100644 --- a/modules/claim/back/models/claim-rma.json +++ b/modules/claim/back/models/claim-rma.json @@ -8,8 +8,8 @@ }, "properties": { "id": { - "type": "number", "id": true, + "type": "number", "description": "Identifier" }, "code": { diff --git a/modules/claim/back/models/claim.json b/modules/claim/back/models/claim.json index 76125c483..14c4f3452 100644 --- a/modules/claim/back/models/claim.json +++ b/modules/claim/back/models/claim.json @@ -57,11 +57,11 @@ "model": "ClaimState", "foreignKey": "claimStateFk" }, - "claimRma": { - "type": "belongsTo", + "rmas": { + "type": "hasMany", "model": "ClaimRma", - "foreignKey": "rma", - "primaryKey": "code" + "foreignKey": "code", + "primaryKey": "rma" }, "client": { "type": "belongsTo", From ac6fbd07a9e51160d09ab0a694607e598fda740a Mon Sep 17 00:00:00 2001 From: joan Date: Mon, 31 Oct 2022 13:24:39 +0100 Subject: [PATCH 15/15] Upgraded node version --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 9caaa30a1..378a87f84 100644 --- a/Dockerfile +++ b/Dockerfile @@ -13,7 +13,7 @@ RUN apt-get update \ libgtk-3-0 libnspr4 libpango-1.0-0 libpangocairo-1.0-0 libstdc++6 libx11-6 libx11-xcb1 libxcb1 \ libxcomposite1 libxcursor1 libxdamage1 libxext6 libxfixes3 libxi6 libxrandr2 libxrender1 libxss1 \ libxtst6 ca-certificates fonts-liberation libappindicator1 libnss3 lsb-release xdg-utils wget \ - && curl -sL https://deb.nodesource.com/setup_12.x | bash - \ + && curl -sL https://deb.nodesource.com/setup_14.x | bash - \ && apt-get install -y --no-install-recommends \ nodejs \ && apt-get purge -y --auto-remove \