Skip to content

Commit ecec514

Browse files
committed
feat: synchronized enforcer
1 parent cb3925e commit ecec514

File tree

6 files changed

+503
-7
lines changed

6 files changed

+503
-7
lines changed

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
"typescript": "^3.7.2"
4040
},
4141
"dependencies": {
42+
"await-lock": "^2.0.1",
4243
"expression-eval": "^2.0.0",
4344
"ip": "^1.1.5",
4445
"lodash": "^4.17.15"

src/coreEnforcer.ts

+7-4
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ export class CoreEnforcer {
143143

144144
this.model.printPolicy();
145145
if (this.autoBuildRoleLinks) {
146-
await this.buildRoleLinks();
146+
await this.buildRoleLinksInternal();
147147
}
148148
}
149149

@@ -163,7 +163,7 @@ export class CoreEnforcer {
163163

164164
this.model.printPolicy();
165165
if (this.autoBuildRoleLinks) {
166-
await this.buildRoleLinks();
166+
await this.buildRoleLinksInternal();
167167
}
168168
return true;
169169
}
@@ -238,10 +238,13 @@ export class CoreEnforcer {
238238
}
239239

240240
/**
241-
* buildRoleLinks manually rebuild the
242-
* role inheritance relations.
241+
* buildRoleLinks manually rebuild the role inheritance relations.
243242
*/
244243
public async buildRoleLinks(): Promise<void> {
244+
return this.buildRoleLinksInternal();
245+
}
246+
247+
protected async buildRoleLinksInternal(): Promise<void> {
245248
await this.rm.clear();
246249
await this.model.buildRoleLinks(this.rm);
247250
}

src/index.ts

+1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import * as Util from './util';
1717
export * from './config';
1818
export * from './enforcer';
1919
export * from './cachedEnforcer';
20+
export * from './syncedEnforcer';
2021
export * from './effect';
2122
export * from './model';
2223
export * from './persist';

src/managementEnforcer.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -342,7 +342,7 @@ export class ManagementEnforcer extends InternalEnforcer {
342342
const ruleadded = await this.addPolicyInternal('g', ptype, params);
343343

344344
if (this.autoBuildRoleLinks) {
345-
await this.buildRoleLinks();
345+
await this.buildRoleLinksInternal();
346346
}
347347

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

383383
if (this.autoBuildRoleLinks) {
384-
await this.buildRoleLinks();
384+
await this.buildRoleLinksInternal();
385385
}
386386

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

402402
if (this.autoBuildRoleLinks) {
403-
await this.buildRoleLinks();
403+
await this.buildRoleLinksInternal();
404404
}
405405

406406
return ruleRemoved;

0 commit comments

Comments
 (0)