mirror of
https://github.com/solero/houdini.git
synced 2024-11-12 21:58:20 +00:00
Implement basic permissions system
This commit is contained in:
parent
fb23387301
commit
1c558307fb
@ -19,3 +19,10 @@ class PermissionCrumbsCollection(BaseCrumbsCollection):
|
|||||||
inventory_key='penguin_id',
|
inventory_key='penguin_id',
|
||||||
inventory_value='permission_id',
|
inventory_value='permission_id',
|
||||||
inventory_id=inventory_id)
|
inventory_id=inventory_id)
|
||||||
|
|
||||||
|
async def register(self, permission_name):
|
||||||
|
try:
|
||||||
|
permission = await self.get(permission_name)
|
||||||
|
except KeyError:
|
||||||
|
permission = await self.set(name=permission_name)
|
||||||
|
return permission
|
||||||
|
@ -29,7 +29,6 @@ from houdini.data.stamp import StampCrumbsCollection
|
|||||||
from houdini.data.ninja import CardCrumbsCollection
|
from houdini.data.ninja import CardCrumbsCollection
|
||||||
from houdini.data.mail import PostcardCrumbsCollection
|
from houdini.data.mail import PostcardCrumbsCollection
|
||||||
from houdini.data.pet import PuffleCrumbsCollection, PuffleItemCrumbsCollection
|
from houdini.data.pet import PuffleCrumbsCollection, PuffleItemCrumbsCollection
|
||||||
|
|
||||||
from houdini.data.permission import PermissionCrumbsCollection
|
from houdini.data.permission import PermissionCrumbsCollection
|
||||||
|
|
||||||
try:
|
try:
|
||||||
@ -77,6 +76,7 @@ class HoudiniFactory:
|
|||||||
self.commands = CommandManager(self)
|
self.commands = CommandManager(self)
|
||||||
self.plugins = PluginManager(self)
|
self.plugins = PluginManager(self)
|
||||||
|
|
||||||
|
self.permissions = None
|
||||||
|
|
||||||
self.items = None
|
self.items = None
|
||||||
self.igloos = None
|
self.igloos = None
|
||||||
@ -208,6 +208,8 @@ class HoudiniFactory:
|
|||||||
self.puffle_items = await PuffleItemCrumbsCollection.get_collection()
|
self.puffle_items = await PuffleItemCrumbsCollection.get_collection()
|
||||||
self.logger.info('Loaded {} puffle care items'.format(len(self.puffle_items)))
|
self.logger.info('Loaded {} puffle care items'.format(len(self.puffle_items)))
|
||||||
|
|
||||||
|
self.permissions = await PermissionCrumbsCollection.get_collection()
|
||||||
|
|
||||||
handlers_path = './houdini{}handlers'.format(os.path.sep)
|
handlers_path = './houdini{}handlers'.format(os.path.sep)
|
||||||
plugins_path = './houdini{}plugins'.format(os.path.sep)
|
plugins_path = './houdini{}plugins'.format(os.path.sep)
|
||||||
self.configure_observers([handlers_path, ListenerFileEventHandler],
|
self.configure_observers([handlers_path, ListenerFileEventHandler],
|
||||||
|
@ -1,10 +1,12 @@
|
|||||||
from houdini.spheniscidae import Spheniscidae
|
from houdini.spheniscidae import Spheniscidae
|
||||||
|
|
||||||
|
from houdini.data.permission import PermissionCrumbsCollection
|
||||||
|
|
||||||
class Penguin(Spheniscidae):
|
class Penguin(Spheniscidae):
|
||||||
|
|
||||||
__slots__ = ['x', 'y', 'room', 'waddle', 'table', 'data', 'member',
|
__slots__ = ['x', 'y', 'room', 'waddle', 'table', 'data', 'member',
|
||||||
'membership_days', 'avatar', 'walking_puffle']
|
'membership_days', 'avatar', 'walking_puffle']
|
||||||
|
'walking_puffle', 'permissions']
|
||||||
|
|
||||||
def __init__(self, *args):
|
def __init__(self, *args):
|
||||||
super().__init__(*args)
|
super().__init__(*args)
|
||||||
@ -23,6 +25,8 @@ class Penguin(Spheniscidae):
|
|||||||
|
|
||||||
self.walking_puffle = None
|
self.walking_puffle = None
|
||||||
|
|
||||||
|
self.permissions = None
|
||||||
|
|
||||||
self.logger.debug('New penguin created')
|
self.logger.debug('New penguin created')
|
||||||
|
|
||||||
@property
|
@property
|
||||||
@ -37,6 +41,11 @@ class Penguin(Spheniscidae):
|
|||||||
def penguin_state(self):
|
def penguin_state(self):
|
||||||
return str()
|
return str()
|
||||||
|
|
||||||
|
|
||||||
|
async def load(self):
|
||||||
|
if self.data:
|
||||||
|
self.permissions = await PermissionCrumbsCollection.get_collection(self.data.id)
|
||||||
|
|
||||||
async def add_inventory(self, item):
|
async def add_inventory(self, item):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
13
houdini/permissions.py
Normal file
13
houdini/permissions.py
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
from houdini.handlers import check
|
||||||
|
|
||||||
|
|
||||||
|
def has(permission_name, check_above=True):
|
||||||
|
def check_permission(_, p):
|
||||||
|
def check_permission_recursive(permissions, permission):
|
||||||
|
if permission in permissions:
|
||||||
|
return permissions[permission].enabled
|
||||||
|
if '.' in permission and check_above:
|
||||||
|
check_permission_recursive(permissions, '.'.join(permission.split('.')[:-1]))
|
||||||
|
return False
|
||||||
|
return check_permission_recursive(p.permissions, permission_name)
|
||||||
|
return check(check_permission)
|
Loading…
Reference in New Issue
Block a user