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 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', { diff --git a/modules/item/front/botanical/index.spec.js b/modules/item/front/botanical/index.spec.js index f679a58f4..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 = { @@ -45,7 +50,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 +81,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 +98,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 the item botanical has no genus name', () => { jest.spyOn(controller.vnApp, 'showMessage'); controller.data = {}; @@ -103,11 +108,9 @@ describe('vnItemBotanical', () => { expect(controller.vnApp.showError).toHaveBeenCalledWith(`The name of the genus can't be empty`); }); - it('should do add the new genus', () => { - $httpBackend.whenRoute('GET', 'ItemBotanicals').respond({}); - $httpBackend.resetExpectations(); - + it('should add the new genus', () => { controller.data = { + id: 4, name: 'Anilius' }; @@ -115,25 +118,27 @@ 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 there is no name in the specie name field', () => { + it('should throw an error if the item botanical has no species 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({}); - $httpBackend.resetExpectations(); - + it('should add the new species', () => { controller.data = { + id: 2, name: 'Spasiva' }; @@ -141,20 +146,17 @@ describe('vnItemBotanical', () => { controller.onSpeciesAccept(); $httpBackend.flush(); + controller.onSpeciesResponse(controller.data); }); }); describe('onSubmit()', () => { - it('should make an HTTP POST request to save the genus and species data', () => { - $httpBackend.whenRoute('GET', 'ItemBotanicals').respond({}); - $httpBackend.resetExpectations(); - + it('should make HTTP POST request to save the genus and species data', () => { jest.spyOn(controller.$.watcher, 'updateOriginalData'); 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(); @@ -165,13 +167,11 @@ describe('vnItemBotanical', () => { }); describe('getBotanicalData()', () => { - it('should get the item data from itemBotanical', () => { - const response = ['MyResult']; - $httpBackend.whenRoute('GET', `ItemBotanicals`).respond(response); + it('should get the species and genus data references of the item', () => { controller.getBotanicalData(); $httpBackend.flush(); - expect(controller.botanical).toEqual(response[0]); + expect(controller.botanical).toEqual(controller.$params); }); }); }); 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