Skip to content

Commit

Permalink
Merge pull request #8 from iondv/MODREGISTR-656
Browse files Browse the repository at this point in the history
MODREGISTR-656 Порционная загрузка разрешений в SecuredDataRepo
  • Loading branch information
akumidv authored May 25, 2020
2 parents 3b71aba + 0a2429f commit d21fa2d
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 11 deletions.
3 changes: 2 additions & 1 deletion config/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,8 @@
"workflow": "ion://workflows",
"meta": "ion://metaRepo",
"log": "ion://sysLog",
"calc": "lazy://calculator"
"calc": "lazy://calculator",
"resourcePortionSize": 50000
}
},
"background": {
Expand Down
31 changes: 21 additions & 10 deletions core/impl/datarepository/SecuredDataRepository.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,8 @@ function SecuredDataRepository(options) {

var rolePermissionCache = {};

const resourcePortionSize = options.resourcePortionSize || 100000;

this.init = function () {
if (options.roleMap && options.accessManager instanceof RoleAccessManager) {
/**
Expand Down Expand Up @@ -288,14 +290,17 @@ function SecuredDataRepository(options) {
*/
function itemToPermMap(item, permissions, permMap, options) {
if (item && item.getItemId()) {
permMap[item.getClassName() + '@' + item.getItemId()] = merge(true,
permMap[item.getClassName() + '@' + item.getItemId()] = merge(
permMap[item.getClassName() + '@' + item.getItemId()] || true,
permissions[itemPrefix + item.getClassName() + '@' + item.getItemId()] || {},
permissions[classPrefix + item.getClassName()] || {},
permissions[globalMarker] || {}
);

permMap[item.getClassName() + '@' + item.getItemId()].__attr =
attrPermMap(item, permissions, options, permMap[item.getClassName() + '@' + item.getItemId()]) || {};
permMap[item.getClassName() + '@' + item.getItemId()].__attr = merge(
permMap[item.getClassName() + '@' + item.getItemId()].__attr || true,
attrPermMap(item, permissions, options, permMap[item.getClassName() + '@' + item.getItemId()]) || {}
);

let props = item.getProperties();
Object.values(props).forEach((p) => {
Expand Down Expand Up @@ -339,14 +344,20 @@ function SecuredDataRepository(options) {
}
});

return aclProvider.getPermissions(options.user, resources, true)
.then((permissions) => {
let permMap = {};
list.forEach((item) => {
itemToPermMap(item, permissions, permMap, options);
let p = Promise.resolve();
let permMap = {};

for (let i = 0; i < Math.ceil(resources.length/resourcePortionSize); i++) {
const start = i*resourcePortionSize;
const portion = resources.slice(start, start + resourcePortionSize);
p = p.then(() => aclProvider.getPermissions(options.user, portion, true))
.then((permissions) => {
list.forEach((item) => {
itemToPermMap(item, permissions, permMap, options);
});
});
return permMap;
});
}
return p.then(() => permMap);
}

/**
Expand Down

0 comments on commit d21fa2d

Please sign in to comment.