@@ -22,9 +22,8 @@ export class InternalEnforcer extends CoreEnforcer {
22
22
* addPolicyInternal adds a rule to the current policy.
23
23
*/
24
24
public async addPolicyInternal ( sec : string , ptype : string , rule : string [ ] ) : Promise < boolean > {
25
- const ruleAdded = this . model . addPolicy ( sec , ptype , rule ) ;
26
- if ( ! ruleAdded ) {
27
- return ruleAdded ;
25
+ if ( this . model . hasPolicy ( sec , ptype , rule ) ) {
26
+ return false ;
28
27
}
29
28
30
29
if ( this . adapter && this . autoSave ) {
@@ -39,19 +38,18 @@ export class InternalEnforcer extends CoreEnforcer {
39
38
40
39
if ( this . watcher && this . autoNotifyWatcher ) {
41
40
// error intentionally ignored
42
- await this . watcher . update ( ) ;
41
+ this . watcher . update ( ) ;
43
42
}
44
43
45
- return ruleAdded ;
44
+ return this . model . addPolicy ( sec , ptype , rule ) ;
46
45
}
47
46
48
47
/**
49
48
* removePolicyInternal removes a rule from the current policy.
50
49
*/
51
50
public async removePolicyInternal ( sec : string , ptype : string , rule : string [ ] ) : Promise < boolean > {
52
- const ruleRemoved = this . model . removePolicy ( sec , ptype , rule ) ;
53
- if ( ! ruleRemoved ) {
54
- return ruleRemoved ;
51
+ if ( ! this . model . hasPolicy ( sec , ptype , rule ) ) {
52
+ return false ;
55
53
}
56
54
57
55
if ( this . adapter && this . autoSave ) {
@@ -66,21 +64,16 @@ export class InternalEnforcer extends CoreEnforcer {
66
64
67
65
if ( this . watcher && this . autoNotifyWatcher ) {
68
66
// error intentionally ignored
69
- await this . watcher . update ( ) ;
67
+ this . watcher . update ( ) ;
70
68
}
71
69
72
- return ruleRemoved ;
70
+ return this . model . removePolicy ( sec , ptype , rule ) ;
73
71
}
74
72
75
73
/**
76
74
* removeFilteredPolicyInternal removes rules based on field filters from the current policy.
77
75
*/
78
76
public async removeFilteredPolicyInternal ( sec : string , ptype : string , fieldIndex : number , fieldValues : string [ ] ) : Promise < boolean > {
79
- const ruleRemoved = this . model . removeFilteredPolicy ( sec , ptype , fieldIndex , ...fieldValues ) ;
80
- if ( ! ruleRemoved ) {
81
- return ruleRemoved ;
82
- }
83
-
84
77
if ( this . adapter && this . autoSave ) {
85
78
try {
86
79
await this . adapter . removeFilteredPolicy ( sec , ptype , fieldIndex , ...fieldValues ) ;
@@ -93,9 +86,9 @@ export class InternalEnforcer extends CoreEnforcer {
93
86
94
87
if ( this . watcher && this . autoNotifyWatcher ) {
95
88
// error intentionally ignored
96
- await this . watcher . update ( ) ;
89
+ this . watcher . update ( ) ;
97
90
}
98
91
99
- return ruleRemoved ;
92
+ return this . model . removeFilteredPolicy ( sec , ptype , fieldIndex , ... fieldValues ) ;
100
93
}
101
94
}
0 commit comments