From 32ea2dbda6d4cc508ace1e89c5d4066e43ed86c5 Mon Sep 17 00:00:00 2001 From: jorgebl Date: Mon, 8 Mar 2021 12:32:35 +0100 Subject: [PATCH 1/6] Added permisions from models in table salix ACL --- db/changes/10291-invoiceIn/00-ACL.sql | 4 ++++ modules/item/back/models/genus.json | 6 ------ modules/item/back/models/specie.json | 6 ------ 3 files changed, 4 insertions(+), 12 deletions(-) create mode 100644 db/changes/10291-invoiceIn/00-ACL.sql diff --git a/db/changes/10291-invoiceIn/00-ACL.sql b/db/changes/10291-invoiceIn/00-ACL.sql new file mode 100644 index 000000000..b4067d1a3 --- /dev/null +++ b/db/changes/10291-invoiceIn/00-ACL.sql @@ -0,0 +1,4 @@ +INSERT INTO `salix`.`ACL` (`model`, `property`, `accessType`, `permission`, `principalType`, `principalId`) + VALUES + ('Genus', '*', 'WRITE', 'ALLOW', 'ROLE', 'logisticBoss'), + ('Specie', '*', 'WRITE', 'ALLOW', 'ROLE', 'logisticBoss'); \ No newline at end of file diff --git a/modules/item/back/models/genus.json b/modules/item/back/models/genus.json index b675f334a..f18d8e4ae 100644 --- a/modules/item/back/models/genus.json +++ b/modules/item/back/models/genus.json @@ -22,12 +22,6 @@ "principalType": "ROLE", "principalId": "$everyone", "permission": "ALLOW" - }, - { - "accessType": "WRITE", - "principalType": "ROLE", - "principalId": "logisticBoss", - "permission": "ALLOW" } ] } \ No newline at end of file diff --git a/modules/item/back/models/specie.json b/modules/item/back/models/specie.json index 1a4435ea6..c5a1f455e 100644 --- a/modules/item/back/models/specie.json +++ b/modules/item/back/models/specie.json @@ -22,12 +22,6 @@ "principalType": "ROLE", "principalId": "$everyone", "permission": "ALLOW" - }, - { - "accessType": "WRITE", - "principalType": "ROLE", - "principalId": "logisticBoss", - "permission": "ALLOW" } ] } \ No newline at end of file From 6e08a66343986cf43c647584747861f1b73810f9 Mon Sep 17 00:00:00 2001 From: jorgebl Date: Mon, 8 Mar 2021 12:38:54 +0100 Subject: [PATCH 2/6] Added acl action for logistic boss and show the recent data added on species and genus in their fields in item botanical --- modules/item/front/botanical/index.html | 8 ++++++-- modules/item/front/botanical/index.js | 14 ++++++++++++-- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/modules/item/front/botanical/index.html b/modules/item/front/botanical/index.html index 3d1beefd7..2388f4e8f 100644 --- a/modules/item/front/botanical/index.html +++ b/modules/item/front/botanical/index.html @@ -17,7 +17,8 @@ icon="add_circle" vn-tooltip="New genus" ng-click="$ctrl.showGenus($event)" - vn-acl="logisticBoss"> + vn-acl="logisticBoss" + vn-acl-action="remove"> @@ -38,7 +39,8 @@ icon="add_circle" vn-tooltip="New species" ng-click="$ctrl.showSpecies($event)" - vn-acl="logisticBoss"> + vn-acl="logisticBoss" + vn-acl-action="remove"> @@ -61,6 +63,7 @@ @@ -80,6 +83,7 @@ diff --git a/modules/item/front/botanical/index.js b/modules/item/front/botanical/index.js index d0ff3f466..8ade0fd9d 100644 --- a/modules/item/front/botanical/index.js +++ b/modules/item/front/botanical/index.js @@ -33,6 +33,7 @@ class Controller extends Section { this.$http.post(`genera`, this.data).then(res => { this.vnApp.showMessage(this.$t('The genus has been created')); this.emit('response', {$response: res.data}); + this.onGenusResponse(res.data); }); } catch (e) { this.vnApp.showError(this.$t(e.message)); @@ -44,11 +45,12 @@ class Controller extends Section { onSpeciesAccept() { try { if (!this.data.name) - throw new Error(`The name of the specie can't be empty`); + throw new Error(`The name of the species can't be empty`); this.$http.post(`species`, this.data).then(res => { - this.vnApp.showMessage(this.$t('The specie has been created')); + this.vnApp.showMessage(this.$t('The species has been created')); this.emit('response', {$response: res.data}); + this.onSpeciesResponse(res.data); }); } catch (e) { this.vnApp.showError(this.$t(e.message)); @@ -78,6 +80,14 @@ class Controller extends Section { this.$.watcher.updateOriginalData(); }); } + + onGenusResponse(response) { + this.botanical.genusFk = response.id; + } + + onSpeciesResponse(response) { + this.botanical.specieFk = response.id; + } } ngModule.vnComponent('vnItemBotanical', { From d09e47835e6cd2359d4e4456127152c21f3818c4 Mon Sep 17 00:00:00 2001 From: jorgebl Date: Mon, 8 Mar 2021 12:40:13 +0100 Subject: [PATCH 3/6] Rename the statements for correctly description the action --- modules/item/front/botanical/index.spec.js | 31 +++++++++++++--------- modules/item/front/botanical/locale/es.yml | 2 +- 2 files changed, 20 insertions(+), 13 deletions(-) diff --git a/modules/item/front/botanical/index.spec.js b/modules/item/front/botanical/index.spec.js index f679a58f4..52aacd0f9 100644 --- a/modules/item/front/botanical/index.spec.js +++ b/modules/item/front/botanical/index.spec.js @@ -45,7 +45,7 @@ describe('vnItemBotanical', () => { expect(controller.$.genus.show).not.toHaveBeenCalledWith(); }); - it('should call preventDefault() and show() in genus field when the default is not prevented', () => { + it('should call show function in genus field when the default is not prevented', () => { const event = { defaultPrevented: false, preventDefault: () => {} @@ -76,7 +76,7 @@ describe('vnItemBotanical', () => { expect(controller.$.species.show).not.toHaveBeenCalledWith(); }); - it('should call preventDefault() and show() in species field when the default is not prevented', () => { + it('should call show function in species field when the default is not prevented', () => { const event = { defaultPrevented: false, preventDefault: () => {} @@ -93,7 +93,7 @@ describe('vnItemBotanical', () => { }); describe('onGenusAccept()', () => { - it('should throw an error if there is no name in the genus name field', () => { + it('should throw an error if genus field has not name', () => { jest.spyOn(controller.vnApp, 'showMessage'); controller.data = {}; @@ -104,10 +104,12 @@ describe('vnItemBotanical', () => { }); it('should do add the new genus', () => { - $httpBackend.whenRoute('GET', 'ItemBotanicals').respond({}); + const response = {data: 'MyResult'}; + $httpBackend.whenRoute('GET', 'ItemBotanicals').respond(response); $httpBackend.resetExpectations(); controller.data = { + id: 4, name: 'Anilius' }; @@ -115,25 +117,28 @@ describe('vnItemBotanical', () => { controller.onGenusAccept(); $httpBackend.flush(); + controller.onGenusResponse(controller.data.id); }); }); describe('onSpeciesAccept()', () => { - it('should throw an error if there is no name in the specie name field', () => { + it('should throw an error if species field has not name', () => { jest.spyOn(controller.vnApp, 'showMessage'); controller.data = {}; controller.onSpeciesAccept(); - expect(controller.vnApp.showError).toHaveBeenCalledWith(`The name of the specie can't be empty`); + expect(controller.vnApp.showError).toHaveBeenCalledWith(`The name of the species can't be empty`); }); - it('should do add the new specie', () => { - $httpBackend.whenRoute('GET', 'ItemBotanicals').respond({}); + it('should do add the new species', () => { + const response = {data: 'MyResult'}; + $httpBackend.whenRoute('GET', 'ItemBotanicals').respond(response); $httpBackend.resetExpectations(); controller.data = { + id: 2, name: 'Spasiva' }; @@ -141,12 +146,14 @@ describe('vnItemBotanical', () => { controller.onSpeciesAccept(); $httpBackend.flush(); + controller.onSpeciesResponse(controller.data.id); }); }); describe('onSubmit()', () => { - it('should make an HTTP POST request to save the genus and species data', () => { - $httpBackend.whenRoute('GET', 'ItemBotanicals').respond({}); + it('should make HTTP POST request to save the genus and species data', () => { + const response = {data: 'MyResult'}; + $httpBackend.whenRoute('GET', 'ItemBotanicals').respond(response); $httpBackend.resetExpectations(); jest.spyOn(controller.$.watcher, 'updateOriginalData'); @@ -154,7 +161,7 @@ describe('vnItemBotanical', () => { jest.spyOn(controller.$.watcher, 'notifySaved'); controller.botanical = [{itemFk: 5, genusFk: 3, specieFk: 2}]; - $httpBackend.expectPATCH('ItemBotanicals', controller.botanical).respond({}); + $httpBackend.expectPATCH('ItemBotanicals', controller.botanical).respond(); controller.onSubmit(); $httpBackend.flush(); @@ -165,7 +172,7 @@ describe('vnItemBotanical', () => { }); describe('getBotanicalData()', () => { - it('should get the item data from itemBotanical', () => { + it('should get the species and genus data references of the item', () => { const response = ['MyResult']; $httpBackend.whenRoute('GET', `ItemBotanicals`).respond(response); controller.getBotanicalData(); diff --git a/modules/item/front/botanical/locale/es.yml b/modules/item/front/botanical/locale/es.yml index e22400654..e1234bd71 100644 --- a/modules/item/front/botanical/locale/es.yml +++ b/modules/item/front/botanical/locale/es.yml @@ -1,5 +1,5 @@ The genus has been created: El genus ha sido creado -The specie has been created: La especie ha sido creada +The species has been created: La especie ha sido creada Latin species name: Nombre de la especie en latín Latin genus name: Nombre del genus en latín Species: Especie \ No newline at end of file From 27816b29e7c88e20c5e5116569fe65a848a4558b Mon Sep 17 00:00:00 2001 From: jorgebl Date: Mon, 8 Mar 2021 13:06:35 +0100 Subject: [PATCH 4/6] Removed ids on controller.data --- modules/item/front/botanical/index.spec.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/item/front/botanical/index.spec.js b/modules/item/front/botanical/index.spec.js index 52aacd0f9..c25de93da 100644 --- a/modules/item/front/botanical/index.spec.js +++ b/modules/item/front/botanical/index.spec.js @@ -117,7 +117,7 @@ describe('vnItemBotanical', () => { controller.onGenusAccept(); $httpBackend.flush(); - controller.onGenusResponse(controller.data.id); + controller.onGenusResponse(controller.data); }); }); @@ -146,7 +146,7 @@ describe('vnItemBotanical', () => { controller.onSpeciesAccept(); $httpBackend.flush(); - controller.onSpeciesResponse(controller.data.id); + controller.onSpeciesResponse(controller.data); }); }); From 5cb959f5b80fc5bfeda4029c5e66acb8c6d03281 Mon Sep 17 00:00:00 2001 From: jorgebl Date: Mon, 8 Mar 2021 13:12:13 +0100 Subject: [PATCH 5/6] removed controller.data from submit --- modules/item/front/botanical/index.spec.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/modules/item/front/botanical/index.spec.js b/modules/item/front/botanical/index.spec.js index c25de93da..6192b72e6 100644 --- a/modules/item/front/botanical/index.spec.js +++ b/modules/item/front/botanical/index.spec.js @@ -160,8 +160,7 @@ describe('vnItemBotanical', () => { jest.spyOn(controller.$.watcher, 'check'); jest.spyOn(controller.$.watcher, 'notifySaved'); - controller.botanical = [{itemFk: 5, genusFk: 3, specieFk: 2}]; - $httpBackend.expectPATCH('ItemBotanicals', controller.botanical).respond(); + $httpBackend.expectPATCH('ItemBotanicals').respond(); controller.onSubmit(); $httpBackend.flush(); From 1922280c617205d677c6c0b727a80f8086a3e9a8 Mon Sep 17 00:00:00 2001 From: jorgebl Date: Mon, 8 Mar 2021 17:49:04 +0100 Subject: [PATCH 6/6] QA rename some descriptions in test and reworked the test --- modules/item/front/botanical/index.spec.js | 32 +++++++++------------- 1 file changed, 13 insertions(+), 19 deletions(-) diff --git a/modules/item/front/botanical/index.spec.js b/modules/item/front/botanical/index.spec.js index 6192b72e6..afec83cfd 100644 --- a/modules/item/front/botanical/index.spec.js +++ b/modules/item/front/botanical/index.spec.js @@ -30,6 +30,11 @@ describe('vnItemBotanical', () => { }}; })); + beforeEach(() => { + const response = {data: 'MyResult'}; + $httpBackend.whenRoute('GET', 'ItemBotanicals').respond(response); + }); + describe('showGenus()', () => { it('should do nothing in genus field if it default is prevented', () => { const event = { @@ -93,7 +98,7 @@ describe('vnItemBotanical', () => { }); describe('onGenusAccept()', () => { - it('should throw an error if genus field has not name', () => { + it('should throw an error if the item botanical has no genus name', () => { jest.spyOn(controller.vnApp, 'showMessage'); controller.data = {}; @@ -103,11 +108,7 @@ describe('vnItemBotanical', () => { expect(controller.vnApp.showError).toHaveBeenCalledWith(`The name of the genus can't be empty`); }); - it('should do add the new genus', () => { - const response = {data: 'MyResult'}; - $httpBackend.whenRoute('GET', 'ItemBotanicals').respond(response); - $httpBackend.resetExpectations(); - + it('should add the new genus', () => { controller.data = { id: 4, name: 'Anilius' @@ -117,12 +118,15 @@ describe('vnItemBotanical', () => { controller.onGenusAccept(); $httpBackend.flush(); + controller.onGenusResponse(controller.data); + + expect(controller.botanical.genusFk).toEqual(controller.data.id); }); }); describe('onSpeciesAccept()', () => { - it('should throw an error if species field has not name', () => { + it('should throw an error if the item botanical has no species name', () => { jest.spyOn(controller.vnApp, 'showMessage'); controller.data = {}; @@ -132,11 +136,7 @@ describe('vnItemBotanical', () => { expect(controller.vnApp.showError).toHaveBeenCalledWith(`The name of the species can't be empty`); }); - it('should do add the new species', () => { - const response = {data: 'MyResult'}; - $httpBackend.whenRoute('GET', 'ItemBotanicals').respond(response); - $httpBackend.resetExpectations(); - + it('should add the new species', () => { controller.data = { id: 2, name: 'Spasiva' @@ -152,10 +152,6 @@ describe('vnItemBotanical', () => { describe('onSubmit()', () => { it('should make HTTP POST request to save the genus and species data', () => { - const response = {data: 'MyResult'}; - $httpBackend.whenRoute('GET', 'ItemBotanicals').respond(response); - $httpBackend.resetExpectations(); - jest.spyOn(controller.$.watcher, 'updateOriginalData'); jest.spyOn(controller.$.watcher, 'check'); jest.spyOn(controller.$.watcher, 'notifySaved'); @@ -172,12 +168,10 @@ describe('vnItemBotanical', () => { describe('getBotanicalData()', () => { it('should get the species and genus data references of the item', () => { - const response = ['MyResult']; - $httpBackend.whenRoute('GET', `ItemBotanicals`).respond(response); controller.getBotanicalData(); $httpBackend.flush(); - expect(controller.botanical).toEqual(response[0]); + expect(controller.botanical).toEqual(controller.$params); }); }); });