From 8c984b5ebe898affb7ded61a5c2f5cae957d9af8 Mon Sep 17 00:00:00 2001 From: alexm Date: Wed, 14 Sep 2022 12:32:19 +0200 Subject: [PATCH 1/3] refactor(client): change rol manager to financialBoss --- db/changes/10490-august/00-acl_financialBoss.sql | 3 +++ modules/client/back/models/client.js | 10 +++++----- modules/client/back/models/specs/client.spec.js | 6 +++--- 3 files changed, 11 insertions(+), 8 deletions(-) create mode 100644 db/changes/10490-august/00-acl_financialBoss.sql diff --git a/db/changes/10490-august/00-acl_financialBoss.sql b/db/changes/10490-august/00-acl_financialBoss.sql new file mode 100644 index 000000000..5d66e1866 --- /dev/null +++ b/db/changes/10490-august/00-acl_financialBoss.sql @@ -0,0 +1,3 @@ +DELETE FROM `account`.`roleInherit` + WHERE `role` = 30 + AND `inheritsFrom` = 20; diff --git a/modules/client/back/models/client.js b/modules/client/back/models/client.js index 746261626..c54f56367 100644 --- a/modules/client/back/models/client.js +++ b/modules/client/back/models/client.js @@ -402,8 +402,8 @@ module.exports = Self => { const models = Self.app.models; const userId = ctx.options.accessToken.userId; - const isManager = await models.Account.hasRole(userId, 'manager', ctx.options); - if (!isManager) { + const isFinancialBoss = await models.Account.hasRole(userId, 'financialBoss', ctx.options); + if (!isFinancialBoss) { const lastCredit = await models.ClientCredit.findOne({ where: { clientFk: finalState.id @@ -413,10 +413,10 @@ module.exports = Self => { const lastAmount = lastCredit && lastCredit.amount; const lastWorkerId = lastCredit && lastCredit.workerFk; - const lastWorkerIsManager = await models.Account.hasRole(lastWorkerId, 'manager', ctx.options); + const lastWorkerIsFinancialBoss = await models.Account.hasRole(lastWorkerId, 'financialBoss', ctx.options); - if (lastAmount == 0 && lastWorkerIsManager) - throw new UserError(`You can't change the credit set to zero from a manager`); + if (lastAmount == 0 && lastWorkerIsFinancialBoss) + throw new UserError(`You can't change the credit set to zero from a financialBoss`); const creditLimits = await models.ClientCreditLimit.find({ fields: ['roleFk'], diff --git a/modules/client/back/models/specs/client.spec.js b/modules/client/back/models/specs/client.spec.js index d1a6d77cb..1f7e56cdb 100644 --- a/modules/client/back/models/specs/client.spec.js +++ b/modules/client/back/models/specs/client.spec.js @@ -53,7 +53,7 @@ describe('Client Model', () => { }); describe('changeCredit()', () => { - it('should fail to change the credit as a salesAssistant set to zero by a manager', async() => { + it('should fail to change the credit as a salesAssistant set to zero by a financialBoss', async() => { const tx = await models.Client.beginTransaction({}); let error; @@ -62,7 +62,7 @@ describe('Client Model', () => { const options = {transaction: tx}; const context = {options}; - // Set credit to zero by a manager + // Set credit to zero by a financialBoss const financialBoss = await models.Account.findOne({ where: {name: 'financialBoss'} }, options); @@ -83,7 +83,7 @@ describe('Client Model', () => { await tx.rollback(); } - expect(error.message).toEqual(`You can't change the credit set to zero from a manager`); + expect(error.message).toEqual(`You can't change the credit set to zero from a financialBoss`); }); it('should fail to change to a high credit amount as a salesAssistant', async() => { -- 2.40.1 From 4f7218ab76be4061d2e5ec8625645ff2ea56b441 Mon Sep 17 00:00:00 2001 From: alexm Date: Wed, 14 Sep 2022 13:01:40 +0200 Subject: [PATCH 2/3] translation --- loopback/locale/es.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/loopback/locale/es.json b/loopback/locale/es.json index 07a00024a..e4ed3af7f 100644 --- a/loopback/locale/es.json +++ b/loopback/locale/es.json @@ -208,7 +208,7 @@ "Wasn't able to invoice the following clients": "No se han podido facturar los siguientes clientes", "Can't verify data unless the client has a business type": "No se puede verificar datos de un cliente que no tiene tipo de negocio", "You don't have enough privileges to set this credit amount": "No tienes suficientes privilegios para establecer esta cantidad de crédito", - "You can't change the credit set to zero from a manager": "No puedes cambiar el cŕedito establecido a cero por un gerente", + "You can't change the credit set to zero from a financialBoss": "No puedes cambiar el cŕedito establecido a cero por un jefe de finanzas", "Amounts do not match": "Las cantidades no coinciden", "The PDF document does not exists": "El documento PDF no existe. Prueba a regenerarlo desde la opción 'Regenerar PDF factura'", "The type of business must be filled in basic data": "El tipo de negocio debe estar rellenado en datos básicos", @@ -233,4 +233,4 @@ "Descanso diario 12h.": "Descanso diario 12h.", "Descanso semanal 36h. / 72h.": "Descanso semanal 36h. / 72h.", "Dirección incorrecta": "Dirección incorrecta" -} \ No newline at end of file +} -- 2.40.1 From 24e4a606d7f74c1bf298e3c1cc97a9e3a491c94c Mon Sep 17 00:00:00 2001 From: alexm Date: Fri, 16 Sep 2022 08:49:18 +0200 Subject: [PATCH 3/3] remove change --- db/changes/10490-august/00-acl_financialBoss.sql | 3 --- 1 file changed, 3 deletions(-) delete mode 100644 db/changes/10490-august/00-acl_financialBoss.sql diff --git a/db/changes/10490-august/00-acl_financialBoss.sql b/db/changes/10490-august/00-acl_financialBoss.sql deleted file mode 100644 index 5d66e1866..000000000 --- a/db/changes/10490-august/00-acl_financialBoss.sql +++ /dev/null @@ -1,3 +0,0 @@ -DELETE FROM `account`.`roleInherit` - WHERE `role` = 30 - AND `inheritsFrom` = 20; -- 2.40.1