This repository has been archived by the owner on Aug 26, 2022. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Creating access app for permissions-related utils, decorators and hel…
…pers.
- Loading branch information
Paul Craciunoiu
committed
Jun 2, 2010
1 parent
44b81d8
commit fc11704
Showing
8 changed files
with
62 additions
and
59 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 |
---|---|---|
@@ -0,0 +1,17 @@ | ||
from authority import get_check | ||
|
||
|
||
def has_perm_or_owns(user, perm, obj, perm_obj, | ||
field_name='creator'): | ||
""" | ||
Given a user, a permission, an object (obj) and another object to check | ||
permissions against (perm_obj), returns True if the user has perm on | ||
obj. | ||
""" | ||
if user == getattr(obj, field_name): | ||
return True | ||
|
||
check = get_check(user, perm) | ||
if not check: | ||
return False | ||
return check(perm_obj) |
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,30 @@ | ||
import authority | ||
import jinja2 | ||
from jingo import register | ||
|
||
import access | ||
|
||
|
||
@register.function | ||
@jinja2.contextfunction | ||
def has_perm(context, perm, obj): | ||
""" | ||
Check if the user has a permission on a specific object. | ||
Returns boolean. | ||
""" | ||
check = authority.get_check(context['request'].user, perm) | ||
return check(obj) | ||
|
||
|
||
@register.function | ||
@jinja2.contextfunction | ||
def has_perm_or_owns(context, perm, obj, perm_obj, field_name='creator'): | ||
""" | ||
Check if the user has a permission or owns the object. | ||
Ownership is determined by comparing perm_obj.field_name to the user in | ||
context. | ||
""" | ||
return access.has_perm_or_owns(context['request'].user, perm, obj, | ||
perm_obj, field_name) |
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
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 |
---|---|---|
|
@@ -160,6 +160,7 @@ | |
'jingo_minify', | ||
ROOT_PACKAGE, | ||
'authority', | ||
'access', | ||
'sumo', | ||
'search', | ||
'forums', | ||
|