Changeset 5599

Show
Ignore:
Timestamp:
10/24/08 12:47:35 (3 months ago)
Author:
Gustavo
Message:

Added support for tgext.authorization in quickstarted applications, replacing tg.ext.repoze.who

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • projects/tg.devtools/trunk/devtools/commands/quickstart.py

    r5355 r5599  
    2121    paster quickstart [--version][-h|--help] 
    2222            [-p *PACKAGE*][--dry-run][-t|--templates *TEMPLATES*] 
    23             [-s|--sqlalchemy][-o|--sqlobject][-e|--elixir][-i|--identity
     23            [-s|--sqlalchemy][-o|--sqlobject][-e|--elixir][-a|--auth
    2424 
    2525.. container:: paster-usage 
     
    3939  -e, --elixir 
    4040      use Elixir as ORM 
    41   -i, --identity 
    42       provide Identity support 
     41  -a, --auth 
     42      provide authentication and authorization support 
    4343""" 
    4444 
     
    8383    sqlobject = False 
    8484    elixir = False 
    85     identity = False 
     85    auth = False 
    8686 
    8787    parser = command.Command.standard_parser(quiet=True) 
     
    9595            help="use Elixir as ORM.", action="store_true", 
    9696            dest="elixir", default = False) 
    97     parser.add_option("-i", "--identity", 
    98             help="provide Identity support", 
    99             action="store_true", dest="identity", default = False) 
     97    parser.add_option("-a", "--auth", 
     98            help="provide authentication and authorization support", 
     99            action="store_true", dest="auth", default = True) 
    100100    parser.add_option("-p", "--package", 
    101101            help="package name for the code", 
     
    140140                self.package = package 
    141141 
    142         doidentity = self.identity 
    143         while not doidentity
    144             doidentity = raw_input("Do you need Identity
    145                         "(usernames/passwords) in this project? [no] ") 
    146             doidentity = doidentity.lower() 
    147             if not doidentity or doidentity.startswith('n'): 
    148                 self.identity = Fals
     142        doauth = self.auth 
     143        while not doauth
     144            doauth = raw_input("Do you need authentication and authorization
     145                               "in this project? [yes] ") 
     146            doauth = doauth.lower() 
     147            if not doauth or doauth.startswith("y"): 
     148                doauth = Tru
    149149                break 
    150             if doidentity.startswith("y"): 
    151                 doidentity = Tru
     150            if doauth.startswith('n'): 
     151                self.auth = Fals
    152152                break 
    153153            print "Please enter y(es) or n(o)." 
    154             doidentity = None 
    155  
    156         if doidentity is True: 
    157             if self.sqlalchemy
    158                 self.identity = "sqlalchemy" 
     154            doauth = None 
     155 
     156        if doauth is True: 
     157            if self.sqlalchemy and not self.elixir
     158                self.auth = "sqlalchemy" 
    159159            else: 
    160                 self.identity = "sqlobject" 
     160                print 'You can only use authentication and authorization ' \ 
     161                      'in a new project if you use SQLAlchemy. Please check ' \ 
     162                      'the documentation of tgext.authorization to learn ' \ 
     163                      'how to implement authentication/authorization with ' \ 
     164                      'other sources.' 
     165                return 
     166                # TODO: As far as I know, SQLObject has never been supported in 
     167                # TG2 
     168                # self.auth = "sqlobject" 
    161169 
    162170        self.name = pkg_resources.safe_name(self.name) 
     
    194202        cmd_args.append("elixir=%s" % self.elixir) 
    195203        cmd_args.append("sqlobject=%s" % self.sqlobject) 
    196         cmd_args.append("identity=%s" % self.identity
     204        cmd_args.append("auth=%s" % self.auth
    197205        cmd_args.append("package=%s" % self.package) 
    198206        cmd_args.append("tgversion=%s"%self.version) 
  • projects/tg.devtools/trunk/devtools/templates/turbogears/+package+/config/app_cfg.py_tmpl

    r5166 r5599  
    2828{{endif}} 
    2929 
    30 {{if identity == "sqlalchemy"}} 
    31 #Configure the authentication backend 
     30{{if auth == "sqlalchemy"}} 
     31# Configure the authentication backend 
    3232base_config.auth_backend = 'sqlalchemy' 
    33 base_config.sa_auth = Bunch() 
    3433base_config.sa_auth.dbsession = model.DBSession 
    3534base_config.sa_auth.user_class = model.User 
    3635base_config.sa_auth.group_class = model.Group 
    3736base_config.sa_auth.permission_class = model.Permission 
    38 base_config.sa_auth.user_criterion = model.User.user_name 
    39 base_config.sa_auth.user_id_column = 'user_id' 
    4037 
    4138# override this if you would like to provide a different who plugin for  
  • projects/tg.devtools/trunk/devtools/templates/turbogears/+package+/controllers/root.py_tmpl

    r4819 r5599  
    88#from dbsprockets.saprovider import SAProvider 
    99 
    10 {{if identity == "sqlalchemy"}} 
    11 from tg.ext.repoze.who import authorize 
     10{{if auth == "sqlalchemy"}} 
     11from tgext.authorization import authorize 
    1212from {{package}}.controllers.secc import Secc 
    1313{{endif}} 
     
    1515class RootController(BaseController): 
    1616    #admin = DBMechanic(SAProvider(metadata), '/admin') 
    17     {{if identity == "sqlalchemy"}} 
     17    {{if auth == "sqlalchemy"}} 
    1818    secc = Secc() 
    1919    {{endif}} 
     
    2828 
    2929 
    30 {{if identity == "sqlalchemy"}} 
     30{{if auth == "sqlalchemy"}} 
    3131    @expose('{{package}}.templates.index') 
    3232    @authorize.require(authorize.has_permission('manage')) 
  • projects/tg.devtools/trunk/devtools/templates/turbogears/+package+/controllers/secc.py_tmpl

    r4812 r5599  
    11"""Test Secure Controller""" 
    2 {{if identity == "sqlalchemy"}} 
     2{{if auth == "sqlalchemy"}} 
    33from {{package}}.lib.base import BaseController, SecureController 
    44from tg import expose, flash 
     
    88#from dbsprockets.dbmechanic.frameworks.tg2 import DBMechanic 
    99#from dbsprockets.saprovider import SAProvider 
    10 from tg.ext.repoze.who import authorize 
     10from tgext.authorization import authorize 
    1111 
    1212 
     
    2727        return dict() 
    2828{{else}} 
    29 # This controller is only used when you activate identity. You can safely remove 
     29# This controller is only used when you activate auth. You can safely remove 
    3030# this file from your project. 
    3131{{endif}} 
  • projects/tg.devtools/trunk/devtools/templates/turbogears/+package+/lib/base.py_tmpl

    r5130 r5599  
    55from tg import TGController, tmpl_context 
    66from tg.render import render 
    7 {{if identity == "sqlalchemy"}} 
     7{{if auth == "sqlalchemy"}} 
    88from tg import request 
    99{{endif}} 
     
    3636        # available in environ['pylons.routes_dict'] 
    3737         
    38         {{if identity == "sqlalchemy"}} 
     38        {{if auth == "sqlalchemy"}} 
    3939        tmpl_context.identity = request.environ.get('repoze.who.identity') 
    4040        {{endif}} 
    4141        return TGController.__call__(self, environ, start_response) 
    4242 
    43 {{if identity == "sqlalchemy"}} 
     43{{if auth == "sqlalchemy"}} 
    4444class SecureController(BaseController): 
    45     """this is a SecureController implementation for the 
    46     tg.ext.repoze.who plugin. 
     45    """SecureController implementation for the tgext.authorization extension. 
     46     
    4747    it will permit to protect whole controllers with a single predicate 
    4848    placed at the controller level. 
  • projects/tg.devtools/trunk/devtools/templates/turbogears/+package+/model/__init__.py_tmpl

    r5354 r5599  
    7070# Import your model modules here. 
    7171 
    72 {{if identity == "sqlalchemy"}} 
    73 from identity import User, Group, Permission 
     72{{if auth == "sqlalchemy"}} 
     73from auth import User, Group, Permission 
    7474{{endif}} 
    7575 
  • projects/tg.devtools/trunk/devtools/templates/turbogears/+package+/tests/test_models.py_tmpl

    r5358 r5599  
    1212 
    1313 
    14 {{if identity == "sqlalchemy"}} 
     14{{if auth == "sqlalchemy"}} 
    1515class TestUser(TestModel): 
    1616    """Test case for the User model.""" 
  • projects/tg.devtools/trunk/devtools/templates/turbogears/+package+/websetup.py_tmpl

    r5130 r5599  
    2020    model.metadata.create_all(bind=config['pylons.app_globals'].sa_engine) 
    2121 
    22     {{if identity == "sqlalchemy"}} 
     22    {{if auth == "sqlalchemy"}} 
    2323    u = model.User() 
    2424    u.user_name = u'manager' 
  • projects/tg.devtools/trunk/devtools/templates/turbogears/test.ini_tmpl

    r5358 r5599  
    1717 
    1818[app:main] 
    19 {{if identity == "sqlalchemy"}} 
     19{{if auth == "sqlalchemy"}} 
    2020sqlalchemy.url = sqlite:///:memory: 
    2121{{endif}} 
  • projects/tg.devtools/trunk/devtools/tests/test_pastetemplate.py

    r5130 r5599  
    3131    command.args.append("sqlalchemy=%s"%True) 
    3232    command.args.append("sqlobject=%s"%False) 
    33     command.args.append("identity=%s"%False) 
     33    command.args.append("auth=%s"%False) 
    3434    print command 
    3535    command.templates = TurboGearsTemplate('TGTest') 
  • projects/tg.devtools/trunk/setup.py

    r5319 r5599  
    2828        'tw.forms>=0.9',  
    2929        'DBSprockets >=0.5dev-r380', 
    30         'tg.ext.repoze.who',  
     30        'tgext.authorization',  
    3131        'TurboJson>=1.2', 
    3232        'wsgiref==0.1.2',