From 4a562c311022261165a1246b99d98610abb744bb Mon Sep 17 00:00:00 2001 From: jgallego Date: Tue, 7 Feb 2023 15:40:03 +0100 Subject: [PATCH 1/7] unificado todo a claimState isEditable --- db/changes/230601/00-acl_claim.sql | 6 ++++ db/dump/fixtures.sql | 8 ++--- .../{claim => claim-state}/isEditable.js | 29 +++++++------------ .../specs/isEditable.spec.js | 16 +++++----- .../claim/back/methods/claim/getSummary.js | 13 +++++---- .../claim/back/methods/claim/updateClaim.js | 22 +++----------- modules/claim/back/models/claim-beginning.js | 22 +++++++++++++- modules/claim/back/models/claim-state.js | 3 ++ modules/claim/back/models/claim.js | 1 - modules/claim/front/detail/index.js | 2 +- 10 files changed, 65 insertions(+), 57 deletions(-) create mode 100644 db/changes/230601/00-acl_claim.sql rename modules/claim/back/methods/{claim => claim-state}/isEditable.js (52%) rename modules/claim/back/methods/{claim => claim-state}/specs/isEditable.spec.js (76%) create mode 100644 modules/claim/back/models/claim-state.js diff --git a/db/changes/230601/00-acl_claim.sql b/db/changes/230601/00-acl_claim.sql new file mode 100644 index 0000000000..ea96e130a6 --- /dev/null +++ b/db/changes/230601/00-acl_claim.sql @@ -0,0 +1,6 @@ +INSERT INTO salix.ACL (model, property, accessType, permission, principalType, principalId) + VALUES('ClaimBeginning', 'isEditable', 'READ', 'ALLOW', 'ROLE', 'employee'); + +DELETE FROM salix.ACL + WHERE model='Claim' AND property='isEditable'; + diff --git a/db/dump/fixtures.sql b/db/dump/fixtures.sql index 5c7bbf192e..94b815107c 100644 --- a/db/dump/fixtures.sql +++ b/db/dump/fixtures.sql @@ -1766,12 +1766,12 @@ INSERT INTO `vn`.`clientSample`(`id`, `clientFk`, `typeFk`, `created`, `workerFk INSERT INTO `vn`.`claimState`(`id`, `code`, `description`, `roleFk`, `priority`, `hasToNotify`) VALUES ( 1, 'pending', 'Pendiente', 1, 1, 0), - ( 2, 'managed', 'Gestionado', 1, 5, 0), + ( 2, 'managed', 'Gestionado', 72, 5, 0), ( 3, 'resolved', 'Resuelto', 72, 7, 0), ( 4, 'canceled', 'Anulado', 72, 6, 1), - ( 5, 'incomplete', 'Incompleta', 72, 3, 1), - ( 6, 'mana', 'Mana', 1, 4, 0), - ( 7, 'lack', 'Faltas', 1, 2, 0); + ( 5, 'incomplete', 'Incompleta', 1, 3, 1), + ( 6, 'mana', 'Mana', 72, 4, 0), + ( 7, 'lack', 'Faltas', 72, 2, 0); INSERT INTO `vn`.`claim`(`id`, `ticketCreated`, `claimStateFk`, `clientFk`, `workerFk`, `responsibility`, `isChargedToMana`, `created`, `packages`, `rma`) VALUES diff --git a/modules/claim/back/methods/claim/isEditable.js b/modules/claim/back/methods/claim-state/isEditable.js similarity index 52% rename from modules/claim/back/methods/claim/isEditable.js rename to modules/claim/back/methods/claim-state/isEditable.js index cd14d70c78..b144f0a53e 100644 --- a/modules/claim/back/methods/claim/isEditable.js +++ b/modules/claim/back/methods/claim-state/isEditable.js @@ -1,12 +1,12 @@ module.exports = Self => { Self.remoteMethodCtx('isEditable', { - description: 'Check if a claim is editable', + description: 'Check if an state is editable', accessType: 'READ', accepts: [{ arg: 'id', type: 'number', required: true, - description: 'the claim id', + description: 'the st id', http: {source: 'path'} }], returns: { @@ -21,25 +21,18 @@ module.exports = Self => { Self.isEditable = async(ctx, id, options) => { const userId = ctx.req.accessToken.userId; + const models = Self.app.models; const myOptions = {}; if (typeof options == 'object') Object.assign(myOptions, options); - - const isClaimManager = await Self.app.models.Account.hasRole(userId, 'claimManager', myOptions); - - const claim = await Self.app.models.Claim.findById(id, { - fields: ['claimStateFk'], - include: [{ - relation: 'claimState' - }] - }, myOptions); - - const isClaimResolved = claim && claim.claimState().code == 'resolved'; - - if (!claim || (isClaimResolved && !isClaimManager)) - return false; - - return true; + + const state = await models.ClaimState.findById(id, { + include: { + relation: 'writeRole' + } + }, myOptions); + const roleWithGrants = state && state.writeRole().name; + return await models.Account.hasRole(userId, roleWithGrants, myOptions); }; }; diff --git a/modules/claim/back/methods/claim/specs/isEditable.spec.js b/modules/claim/back/methods/claim-state/specs/isEditable.spec.js similarity index 76% rename from modules/claim/back/methods/claim/specs/isEditable.spec.js rename to modules/claim/back/methods/claim-state/specs/isEditable.spec.js index 3afea78434..4ce7af1c22 100644 --- a/modules/claim/back/methods/claim/specs/isEditable.spec.js +++ b/modules/claim/back/methods/claim-state/specs/isEditable.spec.js @@ -1,7 +1,7 @@ const app = require('vn-loopback/server/server'); -describe('claim isEditable()', () => { - const salesPerdonId = 18; +describe('claimstate isEditable()', () => { + const salesPersonId = 18; const claimManagerId = 72; it('should return false if the given claim does not exist', async() => { const tx = await app.models.Claim.beginTransaction({}); @@ -10,7 +10,7 @@ describe('claim isEditable()', () => { const options = {transaction: tx}; const ctx = {req: {accessToken: {userId: claimManagerId}}}; - const result = await app.models.Claim.isEditable(ctx, 99999, options); + const result = await app.models.ClaimState.isEditable(ctx, 9999, options); expect(result).toEqual(false); @@ -27,8 +27,8 @@ describe('claim isEditable()', () => { try { const options = {transaction: tx}; - const ctx = {req: {accessToken: {userId: salesPerdonId}}}; - const result = await app.models.Claim.isEditable(ctx, 4, options); + const ctx = {req: {accessToken: {userId: salesPersonId}}}; + const result = await app.models.ClaimState.isEditable(ctx, 3, options); expect(result).toEqual(false); @@ -46,7 +46,7 @@ describe('claim isEditable()', () => { const options = {transaction: tx}; const ctx = {req: {accessToken: {userId: claimManagerId}}}; - const result = await app.models.Claim.isEditable(ctx, 4, options); + const result = await app.models.ClaimState.isEditable(ctx, 3, options); expect(result).toEqual(true); @@ -63,8 +63,8 @@ describe('claim isEditable()', () => { try { const options = {transaction: tx}; - const ctx = {req: {accessToken: {userId: salesPerdonId}}}; - const result = await app.models.Claim.isEditable(ctx, 1, options); + const ctx = {req: {accessToken: {userId: claimManagerId}}}; + const result = await app.models.ClaimState.isEditable(ctx, 7, options); expect(result).toEqual(true); diff --git a/modules/claim/back/methods/claim/getSummary.js b/modules/claim/back/methods/claim/getSummary.js index ca376f8533..d384f7ebb0 100644 --- a/modules/claim/back/methods/claim/getSummary.js +++ b/modules/claim/back/methods/claim/getSummary.js @@ -65,7 +65,8 @@ module.exports = Self => { ] }; - promises.push(Self.app.models.Claim.find(filter, myOptions)); + const models = Self.app.models; + promises.push(models.Claim.find(filter, myOptions)); // Claim detail filter = { @@ -82,7 +83,7 @@ module.exports = Self => { } ] }; - promises.push(Self.app.models.ClaimBeginning.find(filter, myOptions)); + promises.push(models.ClaimBeginning.find(filter, myOptions)); // Claim observations filter = { @@ -96,7 +97,7 @@ module.exports = Self => { } ] }; - promises.push(Self.app.models.ClaimObservation.find(filter, myOptions)); + promises.push(models.ClaimObservation.find(filter, myOptions)); // Claim developments filter = { @@ -128,7 +129,7 @@ module.exports = Self => { } ] }; - promises.push(Self.app.models.ClaimDevelopment.find(filter, myOptions)); + promises.push(models.ClaimDevelopment.find(filter, myOptions)); // Claim action filter = { @@ -145,11 +146,11 @@ module.exports = Self => { {relation: 'claimBeggining'} ] }; - promises.push(Self.app.models.ClaimEnd.find(filter, myOptions)); + promises.push(models.ClaimEnd.find(filter, myOptions)); const res = await Promise.all(promises); - summary.isEditable = await Self.isEditable(ctx, id, myOptions); + summary.isEditable = await models.ClaimState.isEditable(ctx, res[0][0].claimStateFk, myOptions); [summary.claim] = res[0]; summary.salesClaimed = res[1]; summary.observations = res[2]; diff --git a/modules/claim/back/methods/claim/updateClaim.js b/modules/claim/back/methods/claim/updateClaim.js index cc9937c194..5271136d6b 100644 --- a/modules/claim/back/methods/claim/updateClaim.js +++ b/modules/claim/back/methods/claim/updateClaim.js @@ -2,6 +2,7 @@ const UserError = require('vn-loopback/util/user-error'); module.exports = Self => { Self.remoteMethod('updateClaim', { description: 'Update a claim with privileges', + accessType: 'WRITE', accepts: [{ arg: 'ctx', type: 'object', @@ -78,11 +79,11 @@ module.exports = Self => { // Validate when claimState has been changed if (args.claimStateFk) { - const canUpdate = await canChangeState(ctx, claim.claimStateFk, myOptions); - const hasRights = await canChangeState(ctx, args.claimStateFk, myOptions); + const canEditOldState = await models.ClaimState.isEditable(ctx, claim.claimStateFk, myOptions); + const canEditNewState = await models.ClaimState.isEditable(ctx, args.claimStateFk, myOptions); const isClaimManager = await models.Account.hasRole(userId, 'claimManager', myOptions); - if (!canUpdate || !hasRights || changedHasToPickUp && !isClaimManager) + if (!canEditOldState || !canEditNewState || changedHasToPickUp && !isClaimManager) throw new UserError(`You don't have enough privileges to change that field`); } @@ -113,21 +114,6 @@ module.exports = Self => { } }; - async function canChangeState(ctx, id, options) { - let models = Self.app.models; - let userId = ctx.req.accessToken.userId; - - let state = await models.ClaimState.findById(id, { - include: { - relation: 'writeRole' - } - }, options); - let stateRole = state.writeRole().name; - let canUpdate = await models.Account.hasRole(userId, stateRole, options); - - return canUpdate; - } - async function notifyStateChange(ctx, workerId, claim, state) { const models = Self.app.models; const origin = ctx.req.headers.origin; diff --git a/modules/claim/back/models/claim-beginning.js b/modules/claim/back/models/claim-beginning.js index 681aaebc7f..4283e37e25 100644 --- a/modules/claim/back/models/claim-beginning.js +++ b/modules/claim/back/models/claim-beginning.js @@ -22,8 +22,28 @@ module.exports = Self => { async function claimIsEditable(ctx) { const loopBackContext = LoopBackContext.getCurrentContext(); const httpCtx = {req: loopBackContext.active}; + const models = Self.app.models; + const myOptions = {}; + + if (ctx.options && ctx.options.transaction) + myOptions.transaction = ctx.options.transaction; + const claimBeginning = await Self.findById(ctx.where.id); - const isEditable = await Self.app.models.Claim.isEditable(httpCtx, claimBeginning.claimFk); + + const filter = { + where: {id: claimBeginning.claimFk}, + include: [ + { + relation: 'claimState', + scope: { + fields: ['id', 'code', 'description'] + } + } + ] + }; + + const [claim] = await models.Claim.find(filter, myOptions); + const isEditable = await models.ClaimState.isEditable(httpCtx, claim.ClaimState()); if (!isEditable) throw new UserError(`The current claim can't be modified`); diff --git a/modules/claim/back/models/claim-state.js b/modules/claim/back/models/claim-state.js new file mode 100644 index 0000000000..e0df5ac4d0 --- /dev/null +++ b/modules/claim/back/models/claim-state.js @@ -0,0 +1,3 @@ +module.exports = Self => { + require('../methods/claim-state/isEditable')(Self); +}; diff --git a/modules/claim/back/models/claim.js b/modules/claim/back/models/claim.js index c9d7ee7d43..5989b44cc7 100644 --- a/modules/claim/back/models/claim.js +++ b/modules/claim/back/models/claim.js @@ -6,7 +6,6 @@ module.exports = Self => { require('../methods/claim/regularizeClaim')(Self); require('../methods/claim/uploadFile')(Self); require('../methods/claim/updateClaimAction')(Self); - require('../methods/claim/isEditable')(Self); require('../methods/claim/updateClaimDestination')(Self); require('../methods/claim/downloadFile')(Self); require('../methods/claim/claimPickupPdf')(Self); diff --git a/modules/claim/front/detail/index.js b/modules/claim/front/detail/index.js index 7c3c04f448..33ce1a5816 100644 --- a/modules/claim/front/detail/index.js +++ b/modules/claim/front/detail/index.js @@ -151,7 +151,7 @@ class Controller extends Section { isClaimEditable() { if (!this.claim) return; - this.$http.get(`Claims/${this.claim.id}/isEditable`).then(res => { + this.$http.get(`ClaimStates/${this.claim.id}/isEditable`).then(res => { this.isRewritable = res.data; }); } From 780572a9f2649e309a0f4ec084033512b7a50a5c Mon Sep 17 00:00:00 2001 From: jgallego Date: Mon, 6 Mar 2023 08:14:26 +0100 Subject: [PATCH 2/7] test fixed --- loopback/locale/en.json | 8 +++++--- modules/claim/back/methods/claim-state/isEditable.js | 2 +- .../back/methods/claim-state/specs/isEditable.spec.js | 2 +- modules/claim/front/detail/index.spec.js | 2 +- 4 files changed, 8 insertions(+), 6 deletions(-) diff --git a/loopback/locale/en.json b/loopback/locale/en.json index eeb25f75dd..dbe25dea30 100644 --- a/loopback/locale/en.json +++ b/loopback/locale/en.json @@ -147,8 +147,10 @@ "Receipt's bank was not found": "Receipt's bank was not found", "This receipt was not compensated": "This receipt was not compensated", "Client's email was not found": "Client's email was not found", - "Tickets with associated refunds": "Tickets with associated refunds can't be deleted. This ticket is associated with refund Nº {{id}}", + "Tickets with associated refunds": "Tickets with associated refunds can't be deleted. This ticket is associated with refund Nº {{id}}", "It is not possible to modify tracked sales": "It is not possible to modify tracked sales", "It is not possible to modify sales that their articles are from Floramondo": "It is not possible to modify sales that their articles are from Floramondo", - "It is not possible to modify cloned sales": "It is not possible to modify cloned sales" -} + "It is not possible to modify cloned sales": "It is not possible to modify cloned sales", + "Valid priorities: 1,2,3": "Valid priorities: 1,2,3", + "Tickets with associated refunds can't be deleted. This ticket is associated with refund Nº 2": "Tickets with associated refunds can't be deleted. This ticket is associated with refund Nº 2" +} \ No newline at end of file diff --git a/modules/claim/back/methods/claim-state/isEditable.js b/modules/claim/back/methods/claim-state/isEditable.js index b144f0a53e..2d0a8dc448 100644 --- a/modules/claim/back/methods/claim-state/isEditable.js +++ b/modules/claim/back/methods/claim-state/isEditable.js @@ -6,7 +6,7 @@ module.exports = Self => { arg: 'id', type: 'number', required: true, - description: 'the st id', + description: 'the state id', http: {source: 'path'} }], returns: { diff --git a/modules/claim/back/methods/claim-state/specs/isEditable.spec.js b/modules/claim/back/methods/claim-state/specs/isEditable.spec.js index 4ce7af1c22..1fb8e15366 100644 --- a/modules/claim/back/methods/claim-state/specs/isEditable.spec.js +++ b/modules/claim/back/methods/claim-state/specs/isEditable.spec.js @@ -3,7 +3,7 @@ const app = require('vn-loopback/server/server'); describe('claimstate isEditable()', () => { const salesPersonId = 18; const claimManagerId = 72; - it('should return false if the given claim does not exist', async() => { + it('should return false if the given state does not exist', async() => { const tx = await app.models.Claim.beginTransaction({}); try { diff --git a/modules/claim/front/detail/index.spec.js b/modules/claim/front/detail/index.spec.js index b36f3a1727..a2b177281c 100644 --- a/modules/claim/front/detail/index.spec.js +++ b/modules/claim/front/detail/index.spec.js @@ -17,7 +17,7 @@ describe('claim', () => { $httpBackend = _$httpBackend_; $httpBackend.whenGET('Claims/ClaimBeginnings').respond({}); $httpBackend.whenGET(`Tickets/1/isEditable`).respond(true); - $httpBackend.whenGET(`Claims/2/isEditable`).respond(true); + $httpBackend.whenGET(`ClaimStates/2/isEditable`).respond(true); const $element = angular.element(''); controller = $componentController('vnClaimDetail', {$element, $scope}); controller.claim = { From 4a32c164a6f6adfe9992a321b919b0011507154a Mon Sep 17 00:00:00 2001 From: jgallego Date: Tue, 7 Mar 2023 07:34:08 +0100 Subject: [PATCH 3/7] template string --- db/changes/230601/00-acl_claim.sql | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/db/changes/230601/00-acl_claim.sql b/db/changes/230601/00-acl_claim.sql index ea96e130a6..4e680eb4fd 100644 --- a/db/changes/230601/00-acl_claim.sql +++ b/db/changes/230601/00-acl_claim.sql @@ -1,6 +1,6 @@ -INSERT INTO salix.ACL (model, property, accessType, permission, principalType, principalId) +INSERT INTO `salix`.`ACL` (model, property, accessType, permission, principalType, principalId) VALUES('ClaimBeginning', 'isEditable', 'READ', 'ALLOW', 'ROLE', 'employee'); -DELETE FROM salix.ACL +DELETE FROM `salix`.`ACL` WHERE model='Claim' AND property='isEditable'; From c0ff6bea57f60e3a7102070bba8a407286871f54 Mon Sep 17 00:00:00 2001 From: joan Date: Tue, 7 Mar 2023 07:47:30 +0100 Subject: [PATCH 4/7] fix(smartTable): fixed filtering with an intermediate check Refs: #5177 --- front/core/components/check/index.js | 2 +- front/core/components/smart-table/index.js | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/front/core/components/check/index.js b/front/core/components/check/index.js index 78b1807a5a..25ec506ad2 100644 --- a/front/core/components/check/index.js +++ b/front/core/components/check/index.js @@ -40,7 +40,7 @@ export default class Check extends Toggle { set tripleState(value) { this._tripleState = value; - this.field = this.field; + this.field = value; } get tripleState() { diff --git a/front/core/components/smart-table/index.js b/front/core/components/smart-table/index.js index ad98839503..b2380a62f8 100644 --- a/front/core/components/smart-table/index.js +++ b/front/core/components/smart-table/index.js @@ -436,6 +436,7 @@ export default class SmartTable extends Component { if (filters && filters.userFilter) this.model.userFilter = filters.userFilter; + this.addFilter(field, this.$inputsScope.searchProps[field]); } @@ -451,7 +452,7 @@ export default class SmartTable extends Component { } addFilter(field, value) { - if (value == '') value = null; + if (value === '') value = null; let stateFilter = {tableQ: {}}; if (this.$params.q) { @@ -462,7 +463,7 @@ export default class SmartTable extends Component { } const whereParams = {[field]: value}; - if (value) { + if (value !== '' && value !== null && value !== undefined) { let where = {[field]: value}; if (this.exprBuilder) { where = buildFilter(whereParams, (param, value) => From e8e8392e5da24a34d1c86edc9b5517ed7bea0b0c Mon Sep 17 00:00:00 2001 From: joan Date: Tue, 7 Mar 2023 07:58:08 +0100 Subject: [PATCH 5/7] Updated changelog --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index bff0feed76..1cfc7e610d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,7 +14,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - ### Fixed -- +- (Clientes -> Listado extendido) Resuelto error al filtrar por clientes inactivos desde la columna "Activo" ## [2308.01] - 2023-03-09 From 0d2339686cc13b39fd7b26c9f3fc67968568a482 Mon Sep 17 00:00:00 2001 From: joan Date: Tue, 7 Mar 2023 08:10:52 +0100 Subject: [PATCH 6/7] Updated changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1cfc7e610d..cf7d8465a4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Fixed - (Clientes -> Listado extendido) Resuelto error al filtrar por clientes inactivos desde la columna "Activo" +- (General) Al pasar el ratón por encima del icono de "Borrar" en un campo, se hacía más grande afectando a la interfaz ## [2308.01] - 2023-03-09 From 14a5c7830398d609a1757d97e7b5aa3973f5416a Mon Sep 17 00:00:00 2001 From: joan Date: Tue, 7 Mar 2023 08:13:07 +0100 Subject: [PATCH 7/7] Updated unit test --- front/core/components/check/index.spec.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/front/core/components/check/index.spec.js b/front/core/components/check/index.spec.js index c9d50cab21..7ec0f12a06 100644 --- a/front/core/components/check/index.spec.js +++ b/front/core/components/check/index.spec.js @@ -45,8 +45,8 @@ describe('Component vnCheck', () => { }); it(`should set value to null and change to true when clicked`, () => { - controller.field = null; controller.tripleState = true; + controller.field = null; element.click(); expect(controller.field).toEqual(true);