fix: funcionalityAcl
gitea/salix/pipeline/head This commit is unstable Details

This commit is contained in:
Alex Moreno 2022-10-06 15:04:27 +02:00
parent 9d482f7dfd
commit c29625f079
6 changed files with 27 additions and 15 deletions

View File

@ -29,12 +29,20 @@ module.exports = Self => {
const userId = ctx.req.accessToken.userId; const userId = ctx.req.accessToken.userId;
const models = Self.app.models; const models = Self.app.models;
const [acl] = await Self.rawSql( const acls = await models.FuncionalityAcl.find({
`SELECT f.role where: {
FROM salix.funcionalityAcl f model: model,
WHERE f.model = ? property: property
AND f.property = ?`, [model, property]); }
});
return await models.Account.hasRole(userId, acl.role); const hasPermissions = acls.filter(async acl => {
console.log('FILTER: ');
acl.role && await models.Account.hasRole(userId, acl.role);
});
console.log(hasPermissions);
if (hasPermissions)
return true;
return false;
}; };
}; };

View File

@ -53,6 +53,9 @@
"EmailUser": { "EmailUser": {
"dataSource": "vn" "dataSource": "vn"
}, },
"FuncionalityAcl": {
"dataSource": "vn"
},
"Image": { "Image": {
"dataSource": "vn" "dataSource": "vn"
}, },

View File

@ -7,7 +7,7 @@ module.exports = Self => {
require('../methods/account/change-password')(Self); require('../methods/account/change-password')(Self);
require('../methods/account/set-password')(Self); require('../methods/account/set-password')(Self);
require('../methods/account/validate-token')(Self); require('../methods/account/validate-token')(Self);
require('../methods/account/aclFunc')(Self); require('../methods/account/funcionalityAcl')(Self);
// Validations // Validations

View File

@ -1,7 +1,13 @@
CREATE TABLE `funcionalityAcl` ( CREATE TABLE `salix`.`funcionalityAcl` (
`id` int(11) NOT NULL AUTO_INCREMENT, `id` int(11) NOT NULL AUTO_INCREMENT,
`model` varchar(255) COLLATE utf8mb3_unicode_ci DEFAULT NULL, `model` varchar(255) COLLATE utf8mb3_unicode_ci DEFAULT NULL,
`property` varchar(255) COLLATE utf8mb3_unicode_ci DEFAULT NULL, `property` varchar(255) COLLATE utf8mb3_unicode_ci DEFAULT NULL,
`role` varchar(45) COLLATE utf8mb3_unicode_ci DEFAULT NULL, `role` varchar(45) COLLATE utf8mb3_unicode_ci DEFAULT NULL,
PRIMARY KEY (`id`) PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=65 DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci ) ENGINE=InnoDB AUTO_INCREMENT=65 DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci;
INSERT INTO `salix`.`funcionalityAcl` (`model`, `property`, `role`)
VALUES
('Sale', 'editTracked', 'production'),
('Sale', 'editCloned', NULL);

View File

@ -2665,11 +2665,6 @@ INSERT INTO `vn`.`ticketCollection` (`ticketFk`, `collectionFk`, `created`, `lev
VALUES VALUES
(9, 3, util.VN_NOW(), NULL, 0, NULL, NULL, NULL, NULL); (9, 3, util.VN_NOW(), NULL, 0, NULL, NULL, NULL, NULL);
INSERT INTO `salix`.`funcionalityAcl` (`model`, `property`, `role`)
VALUES
('Sale', 'editTracked', 'production'),
('Sale', 'editCloned', 'production');
INSERT INTO `vn`.`saleCloned` (`saleClonedFk`, `saleOriginalFk`) INSERT INTO `vn`.`saleCloned` (`saleClonedFk`, `saleOriginalFk`)
VALUES VALUES
('26', '25'); ('26', '25');

View File

@ -91,7 +91,7 @@ describe('sale canEdit()', () => {
it('should return true if any of the sales is cloned and has the correct role', async() => { it('should return true if any of the sales is cloned and has the correct role', async() => {
const tx = await models.Sale.beginTransaction({}); const tx = await models.Sale.beginTransaction({});
// modify?
try { try {
const options = {transaction: tx}; const options = {transaction: tx};