mirror of
https://github.com/solero/houdini.git
synced 2024-11-08 20:28:20 +00:00
Extra wrapper methods for creating permission handler checks
This commit is contained in:
parent
4307284092
commit
8e33779ed8
@ -1,13 +1,30 @@
|
|||||||
from houdini.handlers import check
|
from houdini.handlers import check
|
||||||
|
|
||||||
|
|
||||||
|
def check_permission(p, permission_name, check_above=True):
|
||||||
|
def check_permission_recursive(permissions, permission):
|
||||||
|
if permission in permissions:
|
||||||
|
return p.server.permissions[permission].enabled
|
||||||
|
if '.' in permission and check_above:
|
||||||
|
return check_permission_recursive(permissions, '.'.join(permission.split('.')[:-1]))
|
||||||
|
return False
|
||||||
|
|
||||||
|
return check_permission_recursive(p.permissions, permission_name)
|
||||||
|
|
||||||
|
|
||||||
def has(permission_name, check_above=True):
|
def has(permission_name, check_above=True):
|
||||||
def check_permission(_, p):
|
def has_permission(_, p):
|
||||||
def check_permission_recursive(permissions, permission):
|
return check_permission(p, permission_name, check_above)
|
||||||
if permission in permissions:
|
return check(has_permission)
|
||||||
return permissions[permission].enabled
|
|
||||||
if '.' in permission and check_above:
|
|
||||||
check_permission_recursive(permissions, '.'.join(permission.split('.')[:-1]))
|
def has_or_moderator(permission_name, check_above=True):
|
||||||
return False
|
def or_moderator(_, p):
|
||||||
return check_permission_recursive(p.permissions, permission_name)
|
return p.moderator or check_permission(p, permission_name, check_above)
|
||||||
return check(check_permission)
|
return check(or_moderator)
|
||||||
|
|
||||||
|
|
||||||
|
def has_or_mascot(permission_name, check_above=True):
|
||||||
|
def or_mascot(_, p):
|
||||||
|
return p.character or check_permission(p, permission_name, check_above)
|
||||||
|
return check(or_mascot)
|
||||||
|
Loading…
Reference in New Issue
Block a user