-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add template tags and filters, update readme and example_project
- Loading branch information
Showing
51 changed files
with
1,184 additions
and
487 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,8 @@ | ||
.vscode/ | ||
.pytest_cache/ | ||
.pyc | ||
*.sqlite3 | ||
*.db | ||
build/ | ||
dist/ | ||
django_cancan.egg-info/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
from django.apps import apps | ||
|
||
|
||
def normalize_subject(subject): | ||
if isinstance(subject, str): | ||
try: | ||
app_label, model_name = subject.split(".") | ||
return apps.get_model(app_label, model_name) | ||
except Exception as e: | ||
pass | ||
return subject | ||
|
||
|
||
class AccessRules: | ||
def __init__(self, user): | ||
self.user = user | ||
self.rules = [] | ||
self.action_aliases = {} | ||
|
||
def allow(self, action, subject, **kwargs): | ||
rule = { | ||
"type": "can", | ||
"action": action, | ||
"subject": normalize_subject(subject), | ||
"conditions": kwargs, | ||
} | ||
self.rules.append(rule) | ||
return rule | ||
|
||
def alias_action(self, action, alias): | ||
self.action_aliases[alias] = action | ||
|
||
def alias_to_action(self, alias): | ||
return self.action_aliases.get(alias, alias) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,8 +2,4 @@ | |
|
||
|
||
class CanCanConfig(AppConfig): | ||
name = 'cancan' | ||
|
||
def ready(self): | ||
aaa() | ||
pass | ||
name = "cancan" |
Oops, something went wrong.