Skip to content
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

Created BaseEffector class and different methods inherits from it #328

Closed
wants to merge 2 commits into from
Closed
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
46 changes: 19 additions & 27 deletions casbin/effect/default_effectors.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,62 +14,54 @@

from .effector import Effector


class AllowOverrideEffector(Effector):
class BaseEffector(Effector):
def intermediate_effect(self, effects):
"""returns a intermediate effect based on the matched effects of the enforcer"""
if Effector.ALLOW in effects:
return Effector.ALLOW
if Effector.DENY in effects:
return Effector.DENY
return Effector.INDETERMINATE

def final_effect(self, effects):
"""returns the final effect based on the matched effects of the enforcer"""
if Effector.DENY in effects:
return Effector.DENY
if Effector.ALLOW in effects:
return Effector.ALLOW
return Effector.DENY


class DenyOverrideEffector(Effector):
class AllowOverrideEffector(BaseEffector):
def intermediate_effect(self, effects):
"""returns a intermediate effect based on the matched effects of the enforcer"""
if Effector.DENY in effects:
return Effector.DENY
return Effector.INDETERMINATE
return Effector.ALLOW if Effector.ALLOW in effects else Effector.INDETERMINATE

def final_effect(self, effects):
"""returns the final effect based on the matched effects of the enforcer"""
if Effector.DENY in effects:
return Effector.DENY
return Effector.ALLOW

return Effector.ALLOW if Effector.ALLOW in effects else Effector.DENY

class AllowAndDenyEffector(Effector):
class DenyOverrideEffector(BaseEffector):
def intermediate_effect(self, effects):
"""returns a intermediate effect based on the matched effects of the enforcer"""
if Effector.DENY in effects:
return Effector.DENY
return Effector.INDETERMINATE
return Effector.DENY if Effector.DENY in effects else Effector.INDETERMINATE

def final_effect(self, effects):
"""returns the final effect based on the matched effects of the enforcer"""
if Effector.DENY in effects or Effector.ALLOW not in effects:
return Effector.DENY
return Effector.ALLOW
return Effector.DENY if Effector.DENY in effects else Effector.ALLOW

class AllowAndDenyEffector(BaseEffector):
def intermediate_effect(self, effects):
return Effector.DENY if Effector.DENY in effects else Effector.INDETERMINATE

class PriorityEffector(Effector):
def final_effect(self, effects):
return Effector.DENY if Effector.DENY in effects or Effector.ALLOW not in effects else Effector.ALLOW

class PriorityEffector(BaseEffector):
def intermediate_effect(self, effects):
"""returns a intermediate effect based on the matched effects of the enforcer"""
if Effector.ALLOW in effects:
return Effector.ALLOW
if Effector.DENY in effects:
return Effector.DENY
return Effector.INDETERMINATE

def final_effect(self, effects):
"""returns the final effect based on the matched effects of the enforcer"""
if Effector.ALLOW in effects:
return Effector.ALLOW
if Effector.DENY in effects:
return Effector.DENY
return Effector.DENY

Loading