server/__init__.py
branchstable
changeset 4612 d6ae30c5d055
parent 4252 6c4f109c2b03
child 4634 b2a3232783f8
equal deleted inserted replaced
4611:599189430c0e 4612:d6ae30c5d055
    90             finally:
    90             finally:
    91                 set_debug(self._clevel)
    91                 set_debug(self._clevel)
    92         return wrapped
    92         return wrapped
    93 
    93 
    94 # database initialization ######################################################
    94 # database initialization ######################################################
       
    95 
       
    96 def create_user(session, login, pwd, *groups):
       
    97     # monkey patch this method if you want to customize admin/anon creation
       
    98     # (that maybe necessary if you change CWUser's schema)
       
    99     session.create_entity('CWUser', login=login, upassword=pwd)
       
   100     for group in groups:
       
   101         session.execute('SET U in_group G WHERE G name %(group)s',
       
   102                         {'group': group})
    95 
   103 
    96 def init_repository(config, interactive=True, drop=False, vreg=None):
   104 def init_repository(config, interactive=True, drop=False, vreg=None):
    97     """initialise a repository database by creating tables add filling them
   105     """initialise a repository database by creating tables add filling them
    98     with the minimal set of entities (ie at least the schema, base groups and
   106     with the minimal set of entities (ie at least the schema, base groups and
    99     a initial user)
   107     a initial user)
   159     print '-> inserting default user and default groups.'
   167     print '-> inserting default user and default groups.'
   160     # sort for eid predicatability as expected in some server tests
   168     # sort for eid predicatability as expected in some server tests
   161     for group in sorted(BASE_GROUPS):
   169     for group in sorted(BASE_GROUPS):
   162         session.execute('INSERT CWGroup X: X name %(name)s',
   170         session.execute('INSERT CWGroup X: X name %(name)s',
   163                         {'name': unicode(group)})
   171                         {'name': unicode(group)})
   164     session.execute('INSERT CWUser X: X login %(login)s, X upassword %(pwd)s',
   172     create_user(session, login, pwd, 'managers')
   165                     {'login': login, 'pwd': pwd})
       
   166     session.execute('SET U in_group G WHERE G name "managers"')
       
   167     session.commit()
   173     session.commit()
   168     # reloging using the admin user
   174     # reloging using the admin user
   169     config._cubes = None # avoid assertion error
   175     config._cubes = None # avoid assertion error
   170     repo, cnx = in_memory_cnx(config, login, password=pwd)
   176     repo, cnx = in_memory_cnx(config, login, password=pwd)
   171     # trigger vreg initialisation of entity classes
   177     # trigger vreg initialisation of entity classes