Skip to content

Commit

Permalink
Merge pull request #25 from uralbash/path-5
Browse files Browse the repository at this point in the history
Change header in configuration.rst
  • Loading branch information
ergo committed Sep 10, 2015
2 parents d55e1fd + 288875e commit 2ff58a2
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 50 deletions.
8 changes: 0 additions & 8 deletions docs/api/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,3 @@ Contents:

models
services

Indices and tables
==================

* :ref:`genindex`
* :ref:`modindex`
* :ref:`search`

6 changes: 3 additions & 3 deletions docs/api/models.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
=================
======
Models
=================
======


.. autoclass:: ziggurat_foundations.models.user.UserMixin
Expand Down Expand Up @@ -42,4 +42,4 @@ Models


.. autoclass:: ziggurat_foundations.models.base.BaseModel
:members:
:members:
4 changes: 2 additions & 2 deletions docs/api/services.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
=================
========
Services
=================
========


.. autoclass:: ziggurat_foundations.models.services.user.UserService
Expand Down
62 changes: 26 additions & 36 deletions docs/configuration.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
================================
################################
Configuring Ziggurat Foundations
================================
################################

Installation and initial migration
==================================
Expand Down Expand Up @@ -117,7 +117,7 @@ file to extend your existing models (if following the basic pyramid tutorial):
# Base is sqlalchemy's Base = declarative_base() from your project
class Group(GroupMixin, Base):
pass
pass
class GroupPermission(GroupPermissionMixin, Base):
pass
Expand Down Expand Up @@ -155,20 +155,15 @@ file to extend your existing models (if following the basic pyramid tutorial):
cryptacular compatible password manager to ziggurat_model_init, it will be used
instead of creating default one.






Configure Ziggurat with Pyramid Framework
=========================================

Examples of permission system building
---------------------------------------

Root context factories for pyramid provide customizable permissions for specific views
inside your appplication. It is a good idea to keep the root factory inside your models
file (if following the basic pyramid tutorial). This root factory can be used to allow
inside your appplication. It is a good idea to keep the root factory inside your models
file (if following the basic pyramid tutorial). This root factory can be used to allow
only authenticated users to view:

.. code-block:: python
Expand Down Expand Up @@ -215,7 +210,6 @@ resources, you can configure your view to expect "edit" or "delete" permissions:
Ziggurat Foundations can provide some shortcuts that help build pyramid
applications faster.

-------------------------------
Automatic user sign in/sign out
-------------------------------

Expand All @@ -226,7 +220,7 @@ This extension registers basic views for user authentication using
against supplied password.

Extension setup
---------------
~~~~~~~~~~~~~~~

To enable this extension it needs to be included via pyramid include mechanism
for example in your ini configuration file:
Expand Down Expand Up @@ -273,7 +267,7 @@ Additional config options for extensions include in your ini file:
# name of POST key that will be used to supply user password
ziggurat_foundations.sign_in.password_key = password
# name of POST key that will be used to provide additional value that can be used to redirect
# name of POST key that will be used to provide additional value that can be used to redirect
# user back to area that required authentication/authorization)
ziggurat_foundations.sign_in.came_from_key = came_from
Expand All @@ -292,7 +286,7 @@ you can do:
return request.db_session
Configuring your application views
-----------------------------------
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

First you need to make a form used for user authentication and send info to one
of views registered by extension:
Expand All @@ -319,7 +313,7 @@ context objects that extension can return upon form submission/ logout request:


Required imports for all 3 views
................................
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

::

Expand All @@ -330,7 +324,7 @@ Required imports for all 3 views


ZigguratSignInSuccess context view example
..........................................
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

::

Expand All @@ -347,7 +341,7 @@ ZigguratSignInSuccess context view example
headers=request.context.headers)

ZigguratSignInBadAuth context view example
..........................................
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

::

Expand All @@ -359,7 +353,7 @@ ZigguratSignInBadAuth context view example


ZigguratSignOut context view example
..........................................
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

::

Expand All @@ -369,20 +363,19 @@ ZigguratSignOut context view example
headers=request.context.headers)


--------------------------------------------
Configuring groupfinder and session factorys
--------------------------------------------
Cofiguring groupfinder and session factorys
-------------------------------------------

Now, next up we need to import and include the groupfinder and session factory
inside ourapplication configuration, first off in our ini file we need to add
Now, next up we need to import and include the groupfinder and session factory
inside ourapplication configuration, first off in our ini file we need to add
a session secret:

.. code-block:: ini
# replace "sUpersecret" with a secure secret
session.secret = sUpersecret
Now, we need to configure the groupdiner and authn and authz policy inside the
Now, we need to configure the groupdiner and authn and authz policy inside the
main __init__.py file of our application, like so:

.. code-block:: python
Expand All @@ -396,25 +389,24 @@ main __init__.py file of our application, like so:
settings['session.secret'],
)
authn_policy = AuthTktAuthenticationPolicy(settings['session.secret'],
authn_policy = AuthTktAuthenticationPolicy(settings['session.secret'],
callback=groupfinder)
authz_policy = ACLAuthorizationPolicy()
# Tie it all together
# Tie it all together
config = Configurator(settings=settings,
root_factory='intranet.models.RootFactory',
authentication_policy=authn_policy,
authorization_policy=authz_policy)
-----------------------------------------------
Modify request to return Ziggurat User() Object
-----------------------------------------------

We provide a method to modify the pyramid request and return a Ziggurat User()
object (if present) in each request. E.g. once a user is logged in, their details
are held in the request (in the form of a userid), if we enable the below function,
we can easily access all user attributes in our code, to include this feature,
we can easily access all user attributes in our code, to include this feature,
enable it by adding the following to your applications __init__.py configurator file:

.. code-block:: python
Expand All @@ -429,14 +421,14 @@ Or in your ini configuration file (both methods yeild the same result):
ziggurat_foundations.ext.pyramid.get_user
Then inside each pyramid view that contains a request, you can access user information
with (the code behind this is as described in the offical pyramid cookbook, but
with (the code behind this is as described in the offical pyramid cookbook, but
we include in within Ziggurat to make your life easier):

.. code-block:: python
@view_config(route_name='edit_note', renderer='templates/edit_note.jinja2',
@view_config(route_name='edit_note', renderer='templates/edit_note.jinja2',
permission='edit')
def edit_note(request):
def edit_note(request):
user = request.user
# user is now a Ziggurat/SQLAlchemy object that you can access
# Example for user Joe
Expand All @@ -445,8 +437,6 @@ we include in within Ziggurat to make your life easier):
.. tip::

Congratulations, your application is now fully configured to use Ziggurat
Foundations, take a look at the Usage Examples for a guide (next page) on how to start taking
Congratulations, your application is now fully configured to use Ziggurat
Foundations, take a look at the Usage Examples for a guide (next page) on how to start taking
advantage of all the features that Ziggurat has to offer!


2 changes: 1 addition & 1 deletion ziggurat_foundations/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@

def groupfinder(userid, request):
if userid and hasattr(request, 'user') and request.user:
groups = ['group:%s' % g.group_name for g in request.user.groups]
groups = ['group:%s' % g.id for g in request.user.groups]
return groups
return []

0 comments on commit 2ff58a2

Please sign in to comment.