Skip to content

Commit

Permalink
feat: added support for filtered policies
Browse files Browse the repository at this point in the history
Signed-off-by: Cameron Hurst <cahurst@cisco.com>
  • Loading branch information
Cameron Hurst committed Aug 11, 2020
1 parent 2bdfefa commit 220951b
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions casbin/core_enforcer.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def init_with_model_and_adapter(self, m, adapter=None):
self._initialize()

# Do not initialize the full policy when using a filtered adapter
if self.adapter:
if self.adapter and not self.is_filtered():
self.load_policy()

def _initialize(self):
Expand Down Expand Up @@ -147,13 +147,20 @@ def load_policy(self):

def load_filtered_policy(self, filter):
"""reloads a filtered policy from file/database."""
self.model.clear_policy()

pass
if not hasattr(self.adapter, "is_filtered"):
raise ValueError("filtered policies are not supported by this adapter")

self.adapter.load_filtered_policy(self.model, filter)
self.model.print_policy()
if self.auto_build_role_links:
self.build_role_links()

def is_filtered(self):
"""returns true if the loaded policy has been filtered."""

pass
return hasattr(self.adapter, "is_filtered") and self.adapter.is_filtered()

def save_policy(self):
if self.is_filtered():
Expand Down

0 comments on commit 220951b

Please sign in to comment.