Skip to content

Commit

Permalink
feat: synchronized enforcer
Browse files Browse the repository at this point in the history
  • Loading branch information
nodece committed Feb 13, 2020
1 parent cb3925e commit ecec514
Show file tree
Hide file tree
Showing 6 changed files with 503 additions and 7 deletions.
1 change: 1 addition & 0 deletions package.json
Expand Up @@ -39,6 +39,7 @@
"typescript": "^3.7.2"
},
"dependencies": {
"await-lock": "^2.0.1",
"expression-eval": "^2.0.0",
"ip": "^1.1.5",
"lodash": "^4.17.15"
Expand Down
11 changes: 7 additions & 4 deletions src/coreEnforcer.ts
Expand Up @@ -143,7 +143,7 @@ export class CoreEnforcer {

this.model.printPolicy();
if (this.autoBuildRoleLinks) {
await this.buildRoleLinks();
await this.buildRoleLinksInternal();
}
}

Expand All @@ -163,7 +163,7 @@ export class CoreEnforcer {

this.model.printPolicy();
if (this.autoBuildRoleLinks) {
await this.buildRoleLinks();
await this.buildRoleLinksInternal();
}
return true;
}
Expand Down Expand Up @@ -238,10 +238,13 @@ export class CoreEnforcer {
}

/**
* buildRoleLinks manually rebuild the
* role inheritance relations.
* buildRoleLinks manually rebuild the role inheritance relations.
*/
public async buildRoleLinks(): Promise<void> {
return this.buildRoleLinksInternal();
}

protected async buildRoleLinksInternal(): Promise<void> {
await this.rm.clear();
await this.model.buildRoleLinks(this.rm);
}
Expand Down
1 change: 1 addition & 0 deletions src/index.ts
Expand Up @@ -17,6 +17,7 @@ import * as Util from './util';
export * from './config';
export * from './enforcer';
export * from './cachedEnforcer';
export * from './syncedEnforcer';
export * from './effect';
export * from './model';
export * from './persist';
Expand Down
6 changes: 3 additions & 3 deletions src/managementEnforcer.ts
Expand Up @@ -342,7 +342,7 @@ export class ManagementEnforcer extends InternalEnforcer {
const ruleadded = await this.addPolicyInternal('g', ptype, params);

if (this.autoBuildRoleLinks) {
await this.buildRoleLinks();
await this.buildRoleLinksInternal();
}

return ruleadded;
Expand Down Expand Up @@ -381,7 +381,7 @@ export class ManagementEnforcer extends InternalEnforcer {
const ruleRemoved = await this.removePolicyInternal('g', ptype, params);

if (this.autoBuildRoleLinks) {
await this.buildRoleLinks();
await this.buildRoleLinksInternal();
}

return ruleRemoved;
Expand All @@ -400,7 +400,7 @@ export class ManagementEnforcer extends InternalEnforcer {
const ruleRemoved = await this.removeFilteredPolicyInternal('g', ptype, fieldIndex, fieldValues);

if (this.autoBuildRoleLinks) {
await this.buildRoleLinks();
await this.buildRoleLinksInternal();
}

return ruleRemoved;
Expand Down

0 comments on commit ecec514

Please sign in to comment.