From ac893d97079efd72fc062bc40ee7cf3f6a56cadc Mon Sep 17 00:00:00 2001 From: Ethan Paul Date: Mon, 24 Feb 2020 21:27:20 -0500 Subject: [PATCH] Fix hacked permission and access list string names Update domain access list and domain permission models to be dict-castable Update domain model to specify dict casting for access list and permission backrefs properly Remove unnecessary permission_names and access_list_names properties --- keyosk/database/domain.py | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/keyosk/database/domain.py b/keyosk/database/domain.py index c45b5b0..0b5166b 100644 --- a/keyosk/database/domain.py +++ b/keyosk/database/domain.py @@ -53,16 +53,6 @@ class Domain(KeyoskBaseModel): lifespan_access = peewee.IntegerField(null=False) lifespan_refresh = peewee.IntegerField(null=False) - @property - def access_list_names(self) -> List[str]: - """Return the list of ACL items from the backref""" - return [item.name for item in self._access_lists] - - @property - def permission_names(self) -> List[str]: - """Return the list of permission names from the backref""" - return [item.name for item in self._permissions] - @staticmethod def dict_keys() -> List[str]: return [ @@ -80,10 +70,14 @@ class Domain(KeyoskBaseModel): "enable_refresh", "lifespan_access", "lifespan_refresh", - "access_list_names", - "permission_names", + "access_lists", + "permissions", ] + @staticmethod + def foreign_backref() -> List[str]: + return ["access_lists", "permissions"] + class DomainAccessList(KeyoskBaseModel): """Access list name model definition @@ -98,6 +92,10 @@ class DomainAccessList(KeyoskBaseModel): name = peewee.CharField(null=False) domain = peewee.ForeignKeyField(Domain, backref="access_lists") + @staticmethod + def dict_keys() -> List[str]: + return ["name"] + class DomainPermission(KeyoskBaseModel): """Permission name model definition @@ -114,3 +112,7 @@ class DomainPermission(KeyoskBaseModel): name = peewee.CharField(null=False) bitindex = peewee.IntegerField(null=False) domain = peewee.ForeignKeyField(Domain, backref="permissions") + + @staticmethod + def dict_keys() -> List[str]: + return ["name", "bitindex"]