From 4187ec357c618f2cb277efca9e1f92ebb63e0c5a Mon Sep 17 00:00:00 2001 From: Gael Pasgrimaud Date: Thu, 14 Apr 2011 17:30:54 +0200 Subject: [PATCH] improve docs --- CHANGES.txt | 6 ++++++ docs/index.txt | 20 ++++++++++++++++++++ pyramidapp/pyramidapp/security.py | 7 ++++++- pyramidapp/pyramidapp/tests.py | 4 ++++ setup.py | 6 +++--- 5 files changed, 39 insertions(+), 4 deletions(-) diff --git a/CHANGES.txt b/CHANGES.txt index fa53044..aff86a4 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -1,3 +1,9 @@ +0.2 +--- + +- Take care of permissions. You can now use an __acl__ attribute in your SA + models to restrict access + 0.1 --- diff --git a/docs/index.txt b/docs/index.txt index d2d37c9..e6fde30 100644 --- a/docs/index.txt +++ b/docs/index.txt @@ -55,6 +55,26 @@ you can override this. In this case you don't need to specify a package:: You can also change the path ``prefix`` used. pyramid_formalchemy will use ``/admin/`` by default. See :func:`~pyramid_formalchemy.configure`. +Setting permissions +=================== + +pyramid_formalchemy take care of some ``__acl__`` attributes. + +Setting permissions for the globale interface +--------------------------------------------- + +You just need to subclass the default factory in your application: + +.. literalinclude:: ../pyramidapp/pyramidapp/security.py + +Setting permissions per model +----------------------------- + +You can also add an ``__acl__`` attribute to your model class: + +.. literalinclude:: ../pyramidapp/pyramidapp/models.py + :pyobject: Bar + Api === diff --git a/pyramidapp/pyramidapp/security.py b/pyramidapp/pyramidapp/security.py index a81d704..259d8f0 100644 --- a/pyramidapp/pyramidapp/security.py +++ b/pyramidapp/pyramidapp/security.py @@ -8,6 +8,7 @@ from pyramid.security import Allow, Authenticated, ALL_PERMISSIONS from pyramidapp.models import initialize_sql class ModelsWithACL(Models): + """A factory to override the default security setting""" __acl__ = [ (Allow, 'admin', ALL_PERMISSIONS), (Allow, Authenticated, 'view'), @@ -21,16 +22,20 @@ def main(global_config, **settings): """ engine = engine_from_config(settings, 'sqlalchemy.') initialize_sql(engine) + + # configure the security stuff config = Configurator(settings=settings, authentication_policy=RemoteUserAuthenticationPolicy(), authorization_policy=ACLAuthorizationPolicy()) + config.add_static_view('static', 'pyramidapp:static') config.add_route('home', '/', view='pyramidapp.views.my_view', view_renderer='templates/mytemplate.pt') # pyramid_formalchemy's configuration config.include('pyramid_formalchemy') - config.formalchemy_admin('admin', package='pyramidapp', factory=ModelsWithACL) + config.formalchemy_admin('admin', package='pyramidapp', + factory=ModelsWithACL) # use the secure factory return config.make_wsgi_app() diff --git a/pyramidapp/pyramidapp/tests.py b/pyramidapp/pyramidapp/tests.py index 1a64bb8..af39399 100644 --- a/pyramidapp/pyramidapp/tests.py +++ b/pyramidapp/pyramidapp/tests.py @@ -30,6 +30,10 @@ class Test_1_UI(unittest.TestCase): def test_crud(self): # index + resp = self.app.get('/admin') + self.assertEqual(resp.status_int, 302) + assert '/admin/' in resp.location, resp + resp = self.app.get('/admin/') resp.mustcontain('/admin/Foo') resp = resp.click('Foo') diff --git a/setup.py b/setup.py index 727c6b2..bdbee73 100644 --- a/setup.py +++ b/setup.py @@ -6,12 +6,12 @@ here = os.path.abspath(os.path.dirname(__file__)) README = open(os.path.join(here, 'README.txt')).read() CHANGES = open(os.path.join(here, 'CHANGES.txt')).read() -requires = ['pyramid>=1.0', 'WebError', 'FormAlchemy>=1.3.5'] +requires = ['pyramid>=1.0', 'WebError', 'FormAlchemy>=1.3.7'] setup(name='pyramid_formalchemy', - version='0.1', + version='0.2', description='FormAlchemy plugins and helpers for Pyramid', - long_description=README + '\n\n' + CHANGES, + long_description=README + '\n\nCHANGES\n=======\n\n' + CHANGES, classifiers=[ "Programming Language :: Python", "Framework :: Pylons",