1. Blaise Laflamme
  2. PylonsWikiNG

Source

PylonsWikiNG / src / authorization / tutorial / __init__.py

from repoze.bfg.security import Allow
from repoze.bfg.security import Everyone

class RootFactory(object):
    __acl__ = [ (Allow, Everyone, 'view'),
                (Allow, 'group:editors', 'edit') ]
    def __init__(self, request):
        pass


def main(global_config, **settings):
    """ This function returns a Pylons WSGI application.
    """
    from pylons.configuration import Configurator
    from tutorial.models import initialize_sql
    from repoze.bfg.authentication import AuthTktAuthenticationPolicy
    from repoze.bfg.authorization import ACLAuthorizationPolicy
    from tutorial.security import groupfinder
    db_string = settings.get('db_string')
    if db_string is None:
        raise ValueError("No 'db_string' value in application "
                         "configuration.")
    initialize_sql(db_string)
    config = Configurator(
        settings=settings,
        authentication_policy=AuthTktAuthenticationPolicy(
            'sosecret', callback=groupfinder),
        authorization_policy=ACLAuthorizationPolicy(),
        root_factory=RootFactory,
    )
    config.begin()
    config.add_static_view(
        'static',
        'tutorial:templates/static'
        )
    config.add_handler(
        'tutorial.handlers:WikiHandler',
        pattern='/',
        route_name='root',
        )
    config.add_handler(
        'tutorial.handlers:WikiHandler',
        pattern='/wiki/{pagename}/{action}',
        route_name='wiki_action'
        )
    config.scan()
    config.end()
    return config.make_wsgi_app()