From a68b8431c5915ec958478f3d5112c6d4c504080d Mon Sep 17 00:00:00 2001 From: jorgep Date: Mon, 15 Apr 2024 10:21:59 +0200 Subject: [PATCH 1/6] feat: refs #6938 add scope & acls --- .../10994-wheatLaurel/00-modifyAcls.sql | 4 ++ modules/worker/back/models/worker.json | 53 +++++++++++++++++++ 2 files changed, 57 insertions(+) create mode 100644 db/versions/10994-wheatLaurel/00-modifyAcls.sql diff --git a/db/versions/10994-wheatLaurel/00-modifyAcls.sql b/db/versions/10994-wheatLaurel/00-modifyAcls.sql new file mode 100644 index 000000000..5b264482a --- /dev/null +++ b/db/versions/10994-wheatLaurel/00-modifyAcls.sql @@ -0,0 +1,4 @@ +UPDATE salix.ACL SET principalId = "hr" WHERE property IN ('find','findById','findOne') AND model = "Worker"; + +INSERT INTO salix.ACL (model, property, accessType, permission, principalType, principalId) + VALUES ('Worker', 'summary', 'READ', 'ALLOW', 'ROLE', 'employee'); \ No newline at end of file diff --git a/modules/worker/back/models/worker.json b/modules/worker/back/models/worker.json index ed430f133..4b7e4a512 100644 --- a/modules/worker/back/models/worker.json +++ b/modules/worker/back/models/worker.json @@ -92,5 +92,58 @@ "model": "WorkerTeamCollegues", "foreignKey": "workerFk" } + }, + "scopes":{ + "summary": { + "fields": [ + [ + "id", + "firstName", + "lastName", + "bossFk", + "maritalStatus", + "originCountryFk", + "educationLevelFk", + "SSN", + "mobileExtension", + "code", + "locker", + "fi", + "birth", + "isF11Allowed" + ] + + ], + "include": [ + { + "relation": "user", + "scope": { + "fields": ["email", "name", "nickname", "roleFk"], + "include": { + "relation": "role", + "scope": { + "fields": ["name"] + } + } + } + }, { + "relation": "department", + "scope": { + "include": { + "relation": "department", + "scope": { + "fields": ["name"] + } + } + } + }, { + "relation": "boss" + }, { + "relation": "client" + }, { + "relation": "sip" + } + ] + } } } From 200cbd8d74bedf95605c3b8ab260fb2155100494 Mon Sep 17 00:00:00 2001 From: jorgep Date: Mon, 15 Apr 2024 11:03:57 +0200 Subject: [PATCH 2/6] fix: refs #6938 acls & scope --- db/versions/10994-wheatLaurel/00-modifyAcls.sql | 2 +- modules/worker/back/models/worker.json | 4 +--- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/db/versions/10994-wheatLaurel/00-modifyAcls.sql b/db/versions/10994-wheatLaurel/00-modifyAcls.sql index 5b264482a..905f67aba 100644 --- a/db/versions/10994-wheatLaurel/00-modifyAcls.sql +++ b/db/versions/10994-wheatLaurel/00-modifyAcls.sql @@ -1,4 +1,4 @@ UPDATE salix.ACL SET principalId = "hr" WHERE property IN ('find','findById','findOne') AND model = "Worker"; INSERT INTO salix.ACL (model, property, accessType, permission, principalType, principalId) - VALUES ('Worker', 'summary', 'READ', 'ALLOW', 'ROLE', 'employee'); \ No newline at end of file + VALUES ('Worker', '__get__summary', 'READ', 'ALLOW', 'ROLE', 'employee'); \ No newline at end of file diff --git a/modules/worker/back/models/worker.json b/modules/worker/back/models/worker.json index 4b7e4a512..0c4f91118 100644 --- a/modules/worker/back/models/worker.json +++ b/modules/worker/back/models/worker.json @@ -96,7 +96,6 @@ "scopes":{ "summary": { "fields": [ - [ "id", "firstName", "lastName", @@ -112,8 +111,7 @@ "birth", "isF11Allowed" ] - - ], + , "include": [ { "relation": "user", From d7b06fe637ca4662cdd8672ba287ca03a2f07c76 Mon Sep 17 00:00:00 2001 From: jorgep Date: Mon, 15 Apr 2024 12:47:27 +0200 Subject: [PATCH 3/6] fix: refs #6938 scope --- modules/worker/back/models/worker.json | 67 +++++++++++++++++--------- 1 file changed, 45 insertions(+), 22 deletions(-) diff --git a/modules/worker/back/models/worker.json b/modules/worker/back/models/worker.json index 0c4f91118..10776af90 100644 --- a/modules/worker/back/models/worker.json +++ b/modules/worker/back/models/worker.json @@ -95,23 +95,6 @@ }, "scopes":{ "summary": { - "fields": [ - "id", - "firstName", - "lastName", - "bossFk", - "maritalStatus", - "originCountryFk", - "educationLevelFk", - "SSN", - "mobileExtension", - "code", - "locker", - "fi", - "birth", - "isF11Allowed" - ] - , "include": [ { "relation": "user", @@ -128,16 +111,56 @@ "relation": "department", "scope": { "include": { - "relation": "department", - "scope": { - "fields": ["name"] - } + "relation": "department" } } }, { "relation": "boss" }, { - "relation": "client" + "relation": "client", + "scope": { + "fields": [ + "id", + "name", + "fi", + "socialName", + "contact", + "street", + "city", + "postcode", + "email", + "mobile", + "isActive", + "credit", + "creditInsurance", + "iban", + "dueDay", + "isEqualizated", + "isFreezed", + "hasToInvoiceByAddress", + "hasToInvoice", + "isToBeMailed", + "hasSepaVnl", + "hasLcr", + "hasCoreVnl", + "hasCoreVnh", + "hasIncoterms", + "isTaxDataChecked", + "eypbc", + "quality", + "isVies", + "isRelevant", + "accountingAccount", + "created", + "sageTaxTypeFk", + "sageTransactionTypeFk", + "businessTypeFk", + "salesPersonFk", + "hasElectronicInvoice", + "rating", + "recommendedCredit" + ] + } }, { "relation": "sip" } From 3e1218463c03b2cda4ea390a262299b49d661fac Mon Sep 17 00:00:00 2001 From: jorgep Date: Mon, 15 Apr 2024 14:44:18 +0200 Subject: [PATCH 4/6] fix: refs #6938 filters & scope --- modules/worker/back/models/worker.json | 18 ++++++--- modules/worker/front/card/index.js | 32 ++-------------- modules/worker/front/descriptor/index.js | 36 ++--------------- modules/worker/front/summary/index.js | 49 +++--------------------- 4 files changed, 25 insertions(+), 110 deletions(-) diff --git a/modules/worker/back/models/worker.json b/modules/worker/back/models/worker.json index 10776af90..57dc80ec9 100644 --- a/modules/worker/back/models/worker.json +++ b/modules/worker/back/models/worker.json @@ -100,12 +100,20 @@ "relation": "user", "scope": { "fields": ["email", "name", "nickname", "roleFk"], - "include": { - "relation": "role", - "scope": { - "fields": ["name"] + "include": [ + { + "relation": "role", + "scope": { + "fields": ["name"] + } + }, + { + "relation": "emailUser", + "scope": { + "fields": ["email"] + } } - } + ] } }, { "relation": "department", diff --git a/modules/worker/front/card/index.js b/modules/worker/front/card/index.js index 9a40e31c2..1aa548db9 100644 --- a/modules/worker/front/card/index.js +++ b/modules/worker/front/card/index.js @@ -4,37 +4,13 @@ import ModuleCard from 'salix/components/module-card'; class Controller extends ModuleCard { reload() { const filter = { - include: [ - { - relation: 'user', - scope: { - fields: ['name', 'emailVerified'], - include: { - relation: 'emailUser', - scope: { - fields: ['email'] - } - } - } - }, { - relation: 'sip', - scope: { - fields: ['extension', 'secret'] - } - }, { - relation: 'department', - scope: { - include: { - relation: 'department' - } - } - } - ] + where: { + id: this.$params.id} }; return Promise.all([ - this.$http.get(`Workers/${this.$params.id}`, {filter}) - .then(res => this.worker = res.data), + this.$http.get(`Workers/summary`, {filter}) + .then(res => this.worker = res.data[0]), this.$http.get(`Workers/${this.$params.id}/activeContract`) .then(res => this.hasWorkCenter = res.data?.workCenterFk) ]); diff --git a/modules/worker/front/descriptor/index.js b/modules/worker/front/descriptor/index.js index d7962369c..ebf3d65ed 100644 --- a/modules/worker/front/descriptor/index.js +++ b/modules/worker/front/descriptor/index.js @@ -37,41 +37,11 @@ class Controller extends Descriptor { loadData() { const filter = { - include: [ - { - relation: 'user', - scope: { - fields: ['name', 'emailVerified'], - include: { - relation: 'emailUser', - scope: { - fields: ['email'] - } - } - } - }, { - relation: 'client', - scope: { - fields: ['fi'] - } - }, { - relation: 'sip', - scope: { - fields: ['extension'] - } - }, { - relation: 'department', - scope: { - include: { - relation: 'department' - } - } - } - ] + where: {id: this.id}, }; - return this.getData(`Workers/${this.id}`, {filter}) - .then(res => this.entity = res.data); + return this.getData(`Workers/summary`, {filter}) + .then(res => this.entity = res.data[0]); } getPassRequirements() { diff --git a/modules/worker/front/summary/index.js b/modules/worker/front/summary/index.js index 212609f58..d1a27a6d4 100644 --- a/modules/worker/front/summary/index.js +++ b/modules/worker/front/summary/index.js @@ -10,53 +10,14 @@ class Controller extends Summary { this.$.worker = null; if (!value) return; - const query = `Workers/${value.id}`; const filter = { - include: [ - { - relation: 'user', - scope: { - fields: ['name', 'roleFk'], - include: [{ - relation: 'role', - scope: { - fields: ['name'] - } - }, - { - relation: 'emailUser', - scope: { - fields: ['email'] - } - }] - } - }, - { - relation: 'client', - scope: {fields: ['fi', 'phone']} - }, - { - relation: 'boss', - scope: {fields: ['id', 'name']} - }, - { - relation: 'sip', - scope: {fields: ['extension']} - }, - { - relation: 'department', - scope: { - include: { - relation: 'department', - scope: {fields: ['id', 'code', 'name']} - } - } - } - ] + where: { + id: value.id + } }; - this.$http.get(query, {params: {filter}}).then(res => { - this.$.worker = res.data; + this.$http.get(`Workers/summary`, {filter}).then(res => { + this.$.worker = res.data[0]; }); } From 3c9ac9634b6c4ab5890bb232d2d68b9d12eb9a63 Mon Sep 17 00:00:00 2001 From: jorgep Date: Mon, 15 Apr 2024 15:02:45 +0200 Subject: [PATCH 5/6] fix: refs #6938 front tests --- modules/worker/front/descriptor/index.spec.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/modules/worker/front/descriptor/index.spec.js b/modules/worker/front/descriptor/index.spec.js index 4f7fa6a05..cee8b0def 100644 --- a/modules/worker/front/descriptor/index.spec.js +++ b/modules/worker/front/descriptor/index.spec.js @@ -14,14 +14,14 @@ describe('vnWorkerDescriptor', () => { describe('loadData()', () => { it(`should perform a get query to store the worker data into the controller`, () => { const id = 1; - const response = 'foo'; + const response = ['foo']; $httpBackend.whenGET('UserConfigs/getUserConfig').respond({}); - $httpBackend.expectRoute('GET', `Workers/${id}`).respond(response); + $httpBackend.expectRoute('GET', `Workers/summary`).respond(response); controller.id = id; $httpBackend.flush(); - expect(controller.worker).toEqual(response); + expect([controller.worker]).toEqual(response); }); }); From adb2249d2f8b4a74149e195b471963b2e317aade Mon Sep 17 00:00:00 2001 From: jorgep Date: Mon, 15 Apr 2024 15:09:41 +0200 Subject: [PATCH 6/6] fix: refs #6938 e2e tests --- e2e/paths/03-worker/01_summary.spec.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/e2e/paths/03-worker/01_summary.spec.js b/e2e/paths/03-worker/01_summary.spec.js index 51992b41d..3c6149726 100644 --- a/e2e/paths/03-worker/01_summary.spec.js +++ b/e2e/paths/03-worker/01_summary.spec.js @@ -2,7 +2,6 @@ import selectors from '../../helpers/selectors.js'; import getBrowser from '../../helpers/puppeteer'; describe('Worker summary path', () => { - const workerId = 3; let browser; let page; beforeAll(async() => { @@ -10,7 +9,7 @@ describe('Worker summary path', () => { page = browser.page; await page.loginAndModule('employee', 'worker'); const httpDataResponse = page.waitForResponse(response => { - return response.status() === 200 && response.url().includes(`Workers/${workerId}`); + return response.status() === 200 && response.url().includes(`Workers/summary`); }); await page.accessToSearchResult('agencyNick'); await httpDataResponse;