From f1f10d1367b79c62709ca7ee1ec3d9d521f7f6e2 Mon Sep 17 00:00:00 2001 From: jorgep Date: Thu, 12 Sep 2024 09:15:07 +0200 Subject: [PATCH 1/4] refactor: refs #7828 wip --- .../11227-maroonEucalyptus/00-firstScript.sql | 3 ++ .../worker-time-control-mail/getWeeklyMail.js | 34 +++++++++++++++++++ .../back/models/worker-time-control-mail.js | 1 + .../back/models/worker-time-control-mail.json | 18 +++++----- 4 files changed, 47 insertions(+), 9 deletions(-) create mode 100644 db/versions/11227-maroonEucalyptus/00-firstScript.sql create mode 100644 modules/worker/back/methods/worker-time-control-mail/getWeeklyMail.js diff --git a/db/versions/11227-maroonEucalyptus/00-firstScript.sql b/db/versions/11227-maroonEucalyptus/00-firstScript.sql new file mode 100644 index 000000000..bd4a0b681 --- /dev/null +++ b/db/versions/11227-maroonEucalyptus/00-firstScript.sql @@ -0,0 +1,3 @@ +-- Place your SQL code here +INSERT INTO salix.ACL (model, property, accessType, permission, principalType, principalId) + VALUES ('WorkerTimeControlMail', 'getWeeklyMail', 'READ', 'ALLOW', 'ROLE', '$owner'); diff --git a/modules/worker/back/methods/worker-time-control-mail/getWeeklyMail.js b/modules/worker/back/methods/worker-time-control-mail/getWeeklyMail.js new file mode 100644 index 000000000..e2253889f --- /dev/null +++ b/modules/worker/back/methods/worker-time-control-mail/getWeeklyMail.js @@ -0,0 +1,34 @@ +module.exports = Self => { + Self.remoteMethod('getWeeklyMail', { + description: 'Check an email inbox and process it', + accessType: 'READ', + accepts: [{ + arg: 'id', + type: 'number', + description: 'workerFk', + required: true, + http: {source: 'path'} + }, { + arg: 'week', + type: 'number', + required: true + }, { + arg: 'year', + type: 'number', + required: true + }], + returns: + { + type: 'Object', + root: true + }, + http: { + path: `/:id/getWeeklyMail`, + verb: 'GET' + } + }); + + Self.getWeeklyMail = async(workerFk, week, year) => { + return Self.findOne({where: {workerFk, week, year}}); + }; +}; diff --git a/modules/worker/back/models/worker-time-control-mail.js b/modules/worker/back/models/worker-time-control-mail.js index 36f3851b6..e0d385fd0 100644 --- a/modules/worker/back/models/worker-time-control-mail.js +++ b/modules/worker/back/models/worker-time-control-mail.js @@ -1,3 +1,4 @@ module.exports = Self => { require('../methods/worker-time-control-mail/checkInbox')(Self); + require('../methods/worker-time-control-mail/getWeeklyMail')(Self); }; diff --git a/modules/worker/back/models/worker-time-control-mail.json b/modules/worker/back/models/worker-time-control-mail.json index 87eae9217..285c0a7e5 100644 --- a/modules/worker/back/models/worker-time-control-mail.json +++ b/modules/worker/back/models/worker-time-control-mail.json @@ -33,12 +33,12 @@ "type": "number" } }, - "acls": [ - { - "accessType": "READ", - "principalType": "ROLE", - "principalId": "employee", - "permission": "ALLOW" - } - ] -} + "relations": { + "user": { + "type": "belongsTo", + "model": "VnUser", + "foreignKey": "workerFk" + } + }, + "acls": [] +} \ No newline at end of file From 74fafdf330af4ef25e5db58008a528841160f251 Mon Sep 17 00:00:00 2001 From: jorgep Date: Thu, 12 Sep 2024 10:27:18 +0200 Subject: [PATCH 2/4] fix: refs #7828 filter mail access --- .../00-addWorkerTimeControlMailAcl.sql | 4 + .../11227-maroonEucalyptus/00-firstScript.sql | 3 - .../worker-time-control-mail/getWeeklyMail.js | 34 --------- .../back/models/worker-time-control-mail.js | 1 - .../back/models/worker-time-control-mail.json | 10 +-- modules/worker/back/models/worker.json | 73 ++++--------------- 6 files changed, 18 insertions(+), 107 deletions(-) create mode 100644 db/versions/11227-maroonEucalyptus/00-addWorkerTimeControlMailAcl.sql delete mode 100644 db/versions/11227-maroonEucalyptus/00-firstScript.sql delete mode 100644 modules/worker/back/methods/worker-time-control-mail/getWeeklyMail.js diff --git a/db/versions/11227-maroonEucalyptus/00-addWorkerTimeControlMailAcl.sql b/db/versions/11227-maroonEucalyptus/00-addWorkerTimeControlMailAcl.sql new file mode 100644 index 000000000..330dcb839 --- /dev/null +++ b/db/versions/11227-maroonEucalyptus/00-addWorkerTimeControlMailAcl.sql @@ -0,0 +1,4 @@ +-- Place your SQL code here +INSERT INTO salix.ACL (model, property, accessType, permission, principalType, principalId) + VALUES ('WorkerTimeControlMail', 'count', 'READ', 'ALLOW', 'ROLE', 'employee'), + ('Worker', '__get__mail', 'READ', 'ALLOW', 'ROLE', 'hr'); diff --git a/db/versions/11227-maroonEucalyptus/00-firstScript.sql b/db/versions/11227-maroonEucalyptus/00-firstScript.sql deleted file mode 100644 index bd4a0b681..000000000 --- a/db/versions/11227-maroonEucalyptus/00-firstScript.sql +++ /dev/null @@ -1,3 +0,0 @@ --- Place your SQL code here -INSERT INTO salix.ACL (model, property, accessType, permission, principalType, principalId) - VALUES ('WorkerTimeControlMail', 'getWeeklyMail', 'READ', 'ALLOW', 'ROLE', '$owner'); diff --git a/modules/worker/back/methods/worker-time-control-mail/getWeeklyMail.js b/modules/worker/back/methods/worker-time-control-mail/getWeeklyMail.js deleted file mode 100644 index e2253889f..000000000 --- a/modules/worker/back/methods/worker-time-control-mail/getWeeklyMail.js +++ /dev/null @@ -1,34 +0,0 @@ -module.exports = Self => { - Self.remoteMethod('getWeeklyMail', { - description: 'Check an email inbox and process it', - accessType: 'READ', - accepts: [{ - arg: 'id', - type: 'number', - description: 'workerFk', - required: true, - http: {source: 'path'} - }, { - arg: 'week', - type: 'number', - required: true - }, { - arg: 'year', - type: 'number', - required: true - }], - returns: - { - type: 'Object', - root: true - }, - http: { - path: `/:id/getWeeklyMail`, - verb: 'GET' - } - }); - - Self.getWeeklyMail = async(workerFk, week, year) => { - return Self.findOne({where: {workerFk, week, year}}); - }; -}; diff --git a/modules/worker/back/models/worker-time-control-mail.js b/modules/worker/back/models/worker-time-control-mail.js index e0d385fd0..36f3851b6 100644 --- a/modules/worker/back/models/worker-time-control-mail.js +++ b/modules/worker/back/models/worker-time-control-mail.js @@ -1,4 +1,3 @@ module.exports = Self => { require('../methods/worker-time-control-mail/checkInbox')(Self); - require('../methods/worker-time-control-mail/getWeeklyMail')(Self); }; diff --git a/modules/worker/back/models/worker-time-control-mail.json b/modules/worker/back/models/worker-time-control-mail.json index 285c0a7e5..192178c2d 100644 --- a/modules/worker/back/models/worker-time-control-mail.json +++ b/modules/worker/back/models/worker-time-control-mail.json @@ -32,13 +32,5 @@ "sendedCounter": { "type": "number" } - }, - "relations": { - "user": { - "type": "belongsTo", - "model": "VnUser", - "foreignKey": "workerFk" - } - }, - "acls": [] + } } \ No newline at end of file diff --git a/modules/worker/back/models/worker.json b/modules/worker/back/models/worker.json index 82cd1cc2d..502c192c6 100644 --- a/modules/worker/back/models/worker.json +++ b/modules/worker/back/models/worker.json @@ -116,11 +116,6 @@ "model": "Locker", "foreignKey": "workerFk" }, - "medicalReview": { - "type": "hasMany", - "model": "MedicalReview", - "foreignKey": "workerFk" - }, "incomes": { "type": "hasMany", "model": "WorkerIncome", @@ -130,6 +125,11 @@ "type": "hasMany", "model": "TrainingCourse", "foreignKey": "workerFk" + }, + "mail": { + "type": "hasMany", + "model": "WorkerTimeControlMail", + "foreignKey": "workerFk" } }, "acls": [ @@ -139,60 +139,13 @@ "permission": "ALLOW", "principalType": "ROLE", "principalId": "$owner" + }, + { + "property": "__get__mail", + "accessType": "READ", + "permission": "ALLOW", + "principalType": "ROLE", + "principalId": "$owner" } - ], - "scopes": { - "descriptor": { - "fields": [ - "id", - "phone" - ], - "include": [ - { - "relation": "user", - "scope": { - "fields": [ - "name", - "nickname" - ], - "include": { - "relation": "emailUser", - "scope": { - "fields": [ - "email" - ] - } - } - } - }, - { - "relation": "department", - "scope": { - "fields": [ - "departmentFk" - ], - "include": [ - { - "relation": "department", - "scope": { - "fields": [ - "id", - "name" - ] - } - } - ] - } - }, - { - "relation": "sip", - "scope": { - "fields": [ - "extension" - ] - } - } - ] - } - } + ] } \ No newline at end of file From b2bc095caa10a288896e60b4838c51a54723ce14 Mon Sep 17 00:00:00 2001 From: jorgep Date: Thu, 12 Sep 2024 10:28:29 +0200 Subject: [PATCH 3/4] fix: refs #7828 rollback --- modules/worker/back/models/worker.json | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/modules/worker/back/models/worker.json b/modules/worker/back/models/worker.json index 502c192c6..67eb5cab8 100644 --- a/modules/worker/back/models/worker.json +++ b/modules/worker/back/models/worker.json @@ -116,6 +116,11 @@ "model": "Locker", "foreignKey": "workerFk" }, + "medicalReview": { + "type": "hasMany", + "model": "MedicalReview", + "foreignKey": "workerFk" + }, "incomes": { "type": "hasMany", "model": "WorkerIncome", From edccd95fa1121ee9ffd264d3599e3514040e264d Mon Sep 17 00:00:00 2001 From: jorgep Date: Thu, 12 Sep 2024 10:29:03 +0200 Subject: [PATCH 4/4] fix: refs #7828 rollback --- modules/worker/back/models/worker.json | 56 +++++++++++++++++++++++++- 1 file changed, 55 insertions(+), 1 deletion(-) diff --git a/modules/worker/back/models/worker.json b/modules/worker/back/models/worker.json index 67eb5cab8..21c5bd10f 100644 --- a/modules/worker/back/models/worker.json +++ b/modules/worker/back/models/worker.json @@ -152,5 +152,59 @@ "principalType": "ROLE", "principalId": "$owner" } - ] + ], + "scopes": { + "descriptor": { + "fields": [ + "id", + "phone" + ], + "include": [ + { + "relation": "user", + "scope": { + "fields": [ + "name", + "nickname" + ], + "include": { + "relation": "emailUser", + "scope": { + "fields": [ + "email" + ] + } + } + } + }, + { + "relation": "department", + "scope": { + "fields": [ + "departmentFk" + ], + "include": [ + { + "relation": "department", + "scope": { + "fields": [ + "id", + "name" + ] + } + } + ] + } + }, + { + "relation": "sip", + "scope": { + "fields": [ + "extension" + ] + } + } + ] + } + } } \ No newline at end of file