From 3bfe633260763cc890457727c5c3f98cfa8031d4 Mon Sep 17 00:00:00 2001 From: Holger Frey Date: Wed, 27 Sep 2017 11:49:47 +0200 Subject: [PATCH] added Account resource --- ordr2/resources/__init__.py | 13 +++++++++++-- ordr2/resources/account.py | 15 +++++++++++++++ ordr2/resources/base.py | 19 +++++++++++++++++++ 3 files changed, 45 insertions(+), 2 deletions(-) create mode 100644 ordr2/resources/account.py create mode 100644 ordr2/resources/base.py diff --git a/ordr2/resources/__init__.py b/ordr2/resources/__init__.py index 3c24dd3..fea0e0a 100644 --- a/ordr2/resources/__init__.py +++ b/ordr2/resources/__init__.py @@ -1,12 +1,18 @@ from pyramid.security import Allow, Everyone -class Root(object): +from .account import Account +from .base import BaseResource + + +class Root(BaseResource): ''' Root resource ''' __name__ = None __parent__ = None - nav_highlight = None + _nodes = [ + 'account': Account + ] def __init__(self, request): self._request = request @@ -14,6 +20,9 @@ class Root(object): def __acl__(self): return [ (Allow, Everyone, 'view') ] + def __getitem__(self, key): + klass = self._nodes[key] + return klass(key, self) def includeme(config): diff --git a/ordr2/resources/account.py b/ordr2/resources/account.py new file mode 100644 index 0000000..9ad2888 --- /dev/null +++ b/ordr2/resources/account.py @@ -0,0 +1,15 @@ +from pyramid.security import Allow, Authenticated, Deny, Everyone + +from .base import BaseResource + + +class Account(BaseResource): + + def __acl__(self): + return [ + (Allow, Everyone, 'login'), + (Allow, Everyone, 'logout'), + (Deny, Authenticated, 'register'), + (Allow, Everyone, 'register'), + (Allow, Authenticated, 'settings'), + ] diff --git a/ordr2/resources/base.py b/ordr2/resources/base.py new file mode 100644 index 0000000..dc7c32e --- /dev/null +++ b/ordr2/resources/base.py @@ -0,0 +1,19 @@ +from pyramid.security import DENY_ALL + + +class BaseResource(object): + + __parent__ = None + __name__ = None + + _request = None + + nav_highlight = None + + def __init__(self, name, parent): + self.__name__ = name + self.__parent__ = parent + self._request = parent._request + + def __acl__(self): + return [ DENY_ALL ]