# HG changeset patch # User Sylvain Thénault # Date 1266409416 -3600 # Node ID d6ae30c5d055bd8a9b4e22e76e155f40a3ca29c3 # Parent 599189430c0eb863502ffafcdf9e9db9978d225e added a function to create admin/anon user during db initialization process so one get a chance to monkey patch it diff -r 599189430c0e -r d6ae30c5d055 misc/migration/postcreate.py --- a/misc/migration/postcreate.py Wed Feb 17 13:16:50 2010 +0100 +++ b/misc/migration/postcreate.py Wed Feb 17 13:23:36 2010 +0100 @@ -5,7 +5,6 @@ :contact: http://www.logilab.fr/ -- mailto:contact@logilab.fr :license: GNU Lesser General Public License, v2.1 - http://www.gnu.org/licenses """ - # insert versions create_entity('CWProperty', pkey=u'system.version.cubicweb', value=unicode(config.cubicweb_version())) @@ -38,9 +37,8 @@ print 'you are using a manager account as anonymous user.' print 'Hopefully this is not a production instance...' elif anonlogin: - rql('INSERT CWUser X: X login %(login)s, X upassword %(pwd)s,' - 'X in_group G WHERE G name "guests"', - {'login': unicode(anonlogin), 'pwd': anonpwd}) + from cubicweb.server import create_user + create_user(session, unicode(anonlogin), anonpwd, 'guests') # need this since we already have at least one user in the database (the default admin) for user in rql('Any X WHERE X is CWUser').entities(): diff -r 599189430c0e -r d6ae30c5d055 server/__init__.py --- a/server/__init__.py Wed Feb 17 13:16:50 2010 +0100 +++ b/server/__init__.py Wed Feb 17 13:23:36 2010 +0100 @@ -93,6 +93,14 @@ # database initialization ###################################################### +def create_user(session, login, pwd, *groups): + # monkey patch this method if you want to customize admin/anon creation + # (that maybe necessary if you change CWUser's schema) + session.create_entity('CWUser', login=login, upassword=pwd) + for group in groups: + session.execute('SET U in_group G WHERE G name %(group)s', + {'group': group}) + def init_repository(config, interactive=True, drop=False, vreg=None): """initialise a repository database by creating tables add filling them with the minimal set of entities (ie at least the schema, base groups and @@ -161,9 +169,7 @@ for group in sorted(BASE_GROUPS): session.execute('INSERT CWGroup X: X name %(name)s', {'name': unicode(group)}) - session.execute('INSERT CWUser X: X login %(login)s, X upassword %(pwd)s', - {'login': login, 'pwd': pwd}) - session.execute('SET U in_group G WHERE G name "managers"') + create_user(session, login, pwd, 'managers') session.commit() # reloging using the admin user config._cubes = None # avoid assertion error