misc/migration/postcreate.py
branchtls-sprint
changeset 1398 5fe84a5f7035
parent 0 b97547f5f1fa
child 1977 606923dff11b
equal deleted inserted replaced
1397:6cbc7bc8ea6d 1398:5fe84a5f7035
     1 """cubicweb post creation script, set user's workflow"""
     1 """cubicweb post creation script, set user's workflow"""
     2 
     2 
     3 activatedeid = add_state(_('activated'), 'EUser', initial=True)
     3 activatedeid = add_state(_('activated'), 'CWUser', initial=True)
     4 deactivatedeid = add_state(_('deactivated'), 'EUser')
     4 deactivatedeid = add_state(_('deactivated'), 'CWUser')
     5 add_transition(_('deactivate'), 'EUser',
     5 add_transition(_('deactivate'), 'CWUser',
     6                (activatedeid,), deactivatedeid,
     6                (activatedeid,), deactivatedeid,
     7                requiredgroups=('managers',))
     7                requiredgroups=('managers',))
     8 add_transition(_('activate'), 'EUser',
     8 add_transition(_('activate'), 'CWUser',
     9                (deactivatedeid,), activatedeid,
     9                (deactivatedeid,), activatedeid,
    10                requiredgroups=('managers',))
    10                requiredgroups=('managers',))
    11 
    11 
    12 # need this since we already have at least one user in the database (the default admin)
    12 # need this since we already have at least one user in the database (the default admin)
    13 rql('SET X in_state S WHERE X is EUser, S eid %s' % activatedeid)
    13 rql('SET X in_state S WHERE X is CWUser, S eid %s' % activatedeid)
    14 
    14 
    15 # create anonymous user if all-in-one config and anonymous user has been specified
    15 # create anonymous user if all-in-one config and anonymous user has been specified
    16 if hasattr(config, 'anonymous_user'):
    16 if hasattr(config, 'anonymous_user'):
    17     anonlogin, anonpwd = config.anonymous_user()
    17     anonlogin, anonpwd = config.anonymous_user()
    18     if anonlogin:
    18     if anonlogin:
    19         rql('INSERT EUser X: X login %(login)s, X upassword %(pwd)s,'
    19         rql('INSERT CWUser X: X login %(login)s, X upassword %(pwd)s,'
    20             'X in_state S, X in_group G WHERE G name "guests", S name "activated"',
    20             'X in_state S, X in_group G WHERE G name "guests", S name "activated"',
    21             {'login': unicode(anonlogin), 'pwd': anonpwd})
    21             {'login': unicode(anonlogin), 'pwd': anonpwd})
    22 
    22 
    23 cfg = config.persistent_options_configuration()
    23 cfg = config.persistent_options_configuration()
    24 if interactive_mode:
    24 if interactive_mode:
    28     for optname, optdict, value in options:
    28     for optname, optdict, value in options:
    29         key = '%s.%s' % (section, optname)
    29         key = '%s.%s' % (section, optname)
    30         default = cfg.option_default(optname, optdict)
    30         default = cfg.option_default(optname, optdict)
    31         # only record values differing from default
    31         # only record values differing from default
    32         if value != default:
    32         if value != default:
    33             rql('INSERT EProperty X: X pkey %(k)s, X value %(v)s', {'k': key, 'v': value})
    33             rql('INSERT CWProperty X: X pkey %(k)s, X value %(v)s', {'k': key, 'v': value})
    34 
    34 
    35 # add PERM_USE_TEMPLATE_FORMAT permission
    35 # add PERM_USE_TEMPLATE_FORMAT permission
    36 from cubicweb.schema import PERM_USE_TEMPLATE_FORMAT
    36 from cubicweb.schema import PERM_USE_TEMPLATE_FORMAT
    37 eid = add_entity('EPermission', name=PERM_USE_TEMPLATE_FORMAT,
    37 eid = add_entity('CWPermission', name=PERM_USE_TEMPLATE_FORMAT,
    38                  label=_('use template languages'))
    38                  label=_('use template languages'))
    39 rql('SET X require_group G WHERE G name "managers", X eid %(x)s',
    39 rql('SET X require_group G WHERE G name "managers", X eid %(x)s',
    40     {'x': eid}, 'x')    
    40     {'x': eid}, 'x')