8000 feat: controls whether to automatically notify Watcher by nodece · Pull Request #366 · casbin/casbin · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

feat: controls whether to automatically notify Watcher #366

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 24, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions enforcer.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ type Enforcer struct {
enabled bool
autoSave bool
autoBuildRoleLinks bool
autoNotifyWatcher bool
}

// NewEnforcer creates an enforcer via file or DB.
Expand Down Expand Up @@ -171,6 +172,7 @@ func (e *Enforcer) initialize() {
e.enabled = true
e.autoSave = true
e.autoBuildRoleLinks = true
e.autoNotifyWatcher = true
}

// LoadModel reloads the model from the model CONF file.
Expand Down Expand Up @@ -316,6 +318,11 @@ func (e *Enforcer) EnableLog(enable bool) {
log.GetLogger().EnableLog(enable)
}

// EnableAutoNotifyWatcher controls whether to save a policy rule automatically notify the Watcher when it is added or removed.
func (e *Enforcer) EnableAutoNotifyWatcher(enable bool) {
e.autoNotifyWatcher = enable
}

// EnableAutoSave controls whether to save a policy rule automatically to the adapter when it is added or removed.
func (e *Enforcer) EnableAutoSave(autoSave bool) {
e.autoSave = autoSave
Expand Down
32 changes: 17 additions & 15 deletions internal_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,12 @@ func (e *Enforcer) addPolicy(sec string, ptype string, rule []string) (bool, err
return ruleAdded, err
}
}
}

if e.watcher != nil {
err := e.watcher.Update()
if err != nil {
return ruleAdded, err
}
if e.watcher !=nil && e.autoNotifyWatcher {
err := e.watcher.Update()
if err != nil {
return ruleAdded, err
}
}

Expand All @@ -56,11 +56,12 @@ func (e *Enforcer) removePolicy(sec string, ptype string, rule []string) (bool,
return ruleRemoved, err
}
}
if e.watcher != nil {
err := e.watcher.Update()
if err != nil {
return ruleRemoved, err
}
}

if e.watcher !=nil && e.autoNotifyWatcher {
err := e.watcher.Update()
if err != nil {
return ruleRemoved, err
}
}

Expand All @@ -80,11 +81,12 @@ func (e *Enforcer) removeFilteredPolicy(sec string, ptype string, fieldIndex int
return ruleRemoved, err
}
}
if e.watcher != nil {
err := e.watcher.Update()
if err != nil {
return ruleRemoved, err
}
}

if e.watcher !=nil && e.autoNotifyWatcher {
err := e.watcher.Update()
if err != nil {
return ruleRemoved, err
}
}

Expand Down
0