author | Sylvain Thénault <sylvain.thenault@logilab.fr> |
Wed, 23 Sep 2009 19:36:53 +0200 | |
changeset 3450 | 265331a0920c |
parent 3005 | a50d03e7014f |
child 3822 | b61c7b065a66 |
permissions | -rw-r--r-- |
1977
606923dff11b
big bunch of copyright / docstring update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
1 |
"""cubicweb post creation script, set user's workflow |
606923dff11b
big bunch of copyright / docstring update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
2 |
|
606923dff11b
big bunch of copyright / docstring update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
3 |
:organization: Logilab |
606923dff11b
big bunch of copyright / docstring update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
4 |
:copyright: 2001-2009 LOGILAB S.A. (Paris, FRANCE), license is LGPL v2. |
606923dff11b
big bunch of copyright / docstring update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
5 |
:contact: http://www.logilab.fr/ -- mailto:contact@logilab.fr |
606923dff11b
big bunch of copyright / docstring update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
6 |
:license: GNU Lesser General Public License, v2.1 - http://www.gnu.org/licenses |
606923dff11b
big bunch of copyright / docstring update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
7 |
""" |
0 | 8 |
|
3005
a50d03e7014f
move some stuff from server/__init__ to postcreate, fixing instance creation bug
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2920
diff
changeset
|
9 |
# insert versions |
a50d03e7014f
move some stuff from server/__init__ to postcreate, fixing instance creation bug
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2920
diff
changeset
|
10 |
create_entity('CWProperty', pkey=u'system.version.cubicweb', |
a50d03e7014f
move some stuff from server/__init__ to postcreate, fixing instance creation bug
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2920
diff
changeset
|
11 |
value=unicode(config.cubicweb_version())) |
a50d03e7014f
move some stuff from server/__init__ to postcreate, fixing instance creation bug
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2920
diff
changeset
|
12 |
for cube in config.cubes(): |
a50d03e7014f
move some stuff from server/__init__ to postcreate, fixing instance creation bug
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2920
diff
changeset
|
13 |
create_entity('CWProperty', pkey=u'system.version.%s' % cube.lower(), |
a50d03e7014f
move some stuff from server/__init__ to postcreate, fixing instance creation bug
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2920
diff
changeset
|
14 |
value=unicode(config.cube_version(cube))) |
a50d03e7014f
move some stuff from server/__init__ to postcreate, fixing instance creation bug
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2920
diff
changeset
|
15 |
|
a50d03e7014f
move some stuff from server/__init__ to postcreate, fixing instance creation bug
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2920
diff
changeset
|
16 |
# some entities have been added before schema entities, fix the 'is' and |
a50d03e7014f
move some stuff from server/__init__ to postcreate, fixing instance creation bug
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2920
diff
changeset
|
17 |
# 'is_instance_of' relations |
a50d03e7014f
move some stuff from server/__init__ to postcreate, fixing instance creation bug
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2920
diff
changeset
|
18 |
for rtype in ('is', 'is_instance_of'): |
a50d03e7014f
move some stuff from server/__init__ to postcreate, fixing instance creation bug
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2920
diff
changeset
|
19 |
sql('INSERT INTO %s_relation ' |
a50d03e7014f
move some stuff from server/__init__ to postcreate, fixing instance creation bug
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2920
diff
changeset
|
20 |
'SELECT X.eid, ET.cw_eid FROM entities as X, cw_CWEType as ET ' |
a50d03e7014f
move some stuff from server/__init__ to postcreate, fixing instance creation bug
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2920
diff
changeset
|
21 |
'WHERE X.type=ET.cw_name AND NOT EXISTS(' |
a50d03e7014f
move some stuff from server/__init__ to postcreate, fixing instance creation bug
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2920
diff
changeset
|
22 |
' SELECT 1 from is_relation ' |
a50d03e7014f
move some stuff from server/__init__ to postcreate, fixing instance creation bug
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2920
diff
changeset
|
23 |
' WHERE eid_from=X.eid AND eid_to=ET.cw_eid)' % rtype) |
a50d03e7014f
move some stuff from server/__init__ to postcreate, fixing instance creation bug
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2920
diff
changeset
|
24 |
|
a50d03e7014f
move some stuff from server/__init__ to postcreate, fixing instance creation bug
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2920
diff
changeset
|
25 |
# user workflow |
a50d03e7014f
move some stuff from server/__init__ to postcreate, fixing instance creation bug
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2920
diff
changeset
|
26 |
userwf = add_workflow(_('default user workflow'), 'CWUser') |
a50d03e7014f
move some stuff from server/__init__ to postcreate, fixing instance creation bug
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2920
diff
changeset
|
27 |
activated = userwf.add_state(_('activated'), initial=True) |
a50d03e7014f
move some stuff from server/__init__ to postcreate, fixing instance creation bug
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2920
diff
changeset
|
28 |
deactivated = userwf.add_state(_('deactivated')) |
a50d03e7014f
move some stuff from server/__init__ to postcreate, fixing instance creation bug
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2920
diff
changeset
|
29 |
userwf.add_transition(_('deactivate'), (activated,), deactivated, |
a50d03e7014f
move some stuff from server/__init__ to postcreate, fixing instance creation bug
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2920
diff
changeset
|
30 |
requiredgroups=('managers',)) |
a50d03e7014f
move some stuff from server/__init__ to postcreate, fixing instance creation bug
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2920
diff
changeset
|
31 |
userwf.add_transition(_('activate'), (deactivated,), activated, |
a50d03e7014f
move some stuff from server/__init__ to postcreate, fixing instance creation bug
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2920
diff
changeset
|
32 |
requiredgroups=('managers',)) |
0 | 33 |
|
34 |
# create anonymous user if all-in-one config and anonymous user has been specified |
|
35 |
if hasattr(config, 'anonymous_user'): |
|
36 |
anonlogin, anonpwd = config.anonymous_user() |
|
37 |
if anonlogin: |
|
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
0
diff
changeset
|
38 |
rql('INSERT CWUser X: X login %(login)s, X upassword %(pwd)s,' |
2920
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2172
diff
changeset
|
39 |
'X in_group G WHERE G name "guests"', |
0 | 40 |
{'login': unicode(anonlogin), 'pwd': anonpwd}) |
41 |
||
2920
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2172
diff
changeset
|
42 |
# need this since we already have at least one user in the database (the default admin) |
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2172
diff
changeset
|
43 |
for user in rql('Any X WHERE X is CWUser').entities(): |
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2172
diff
changeset
|
44 |
session.unsafe_execute('SET X in_state S WHERE X eid %(x)s, S eid %(s)s', |
3005
a50d03e7014f
move some stuff from server/__init__ to postcreate, fixing instance creation bug
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2920
diff
changeset
|
45 |
{'x': user.eid, 's': activated.eid}, 'x') |
0 | 46 |
|
3005
a50d03e7014f
move some stuff from server/__init__ to postcreate, fixing instance creation bug
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2920
diff
changeset
|
47 |
# on interactive mode, ask for level 0 persistent options |
a50d03e7014f
move some stuff from server/__init__ to postcreate, fixing instance creation bug
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2920
diff
changeset
|
48 |
if interactive_mode: |
a50d03e7014f
move some stuff from server/__init__ to postcreate, fixing instance creation bug
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2920
diff
changeset
|
49 |
cfg = config.persistent_options_configuration() |
a50d03e7014f
move some stuff from server/__init__ to postcreate, fixing instance creation bug
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2920
diff
changeset
|
50 |
cfg.input_config(inputlevel=0) |
a50d03e7014f
move some stuff from server/__init__ to postcreate, fixing instance creation bug
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2920
diff
changeset
|
51 |
for section, options in cfg.options_by_section(): |
a50d03e7014f
move some stuff from server/__init__ to postcreate, fixing instance creation bug
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2920
diff
changeset
|
52 |
for optname, optdict, value in options: |
a50d03e7014f
move some stuff from server/__init__ to postcreate, fixing instance creation bug
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2920
diff
changeset
|
53 |
key = '%s.%s' % (section, optname) |
a50d03e7014f
move some stuff from server/__init__ to postcreate, fixing instance creation bug
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2920
diff
changeset
|
54 |
default = cfg.option_default(optname, optdict) |
a50d03e7014f
move some stuff from server/__init__ to postcreate, fixing instance creation bug
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2920
diff
changeset
|
55 |
# only record values differing from default |
a50d03e7014f
move some stuff from server/__init__ to postcreate, fixing instance creation bug
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2920
diff
changeset
|
56 |
if value != default: |
a50d03e7014f
move some stuff from server/__init__ to postcreate, fixing instance creation bug
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2920
diff
changeset
|
57 |
rql('INSERT CWProperty X: X pkey %(k)s, X value %(v)s', {'k': key, 'v': value}) |
0 | 58 |
|
59 |
# add PERM_USE_TEMPLATE_FORMAT permission |
|
60 |
from cubicweb.schema import PERM_USE_TEMPLATE_FORMAT |
|
3005
a50d03e7014f
move some stuff from server/__init__ to postcreate, fixing instance creation bug
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2920
diff
changeset
|
61 |
usetmplperm = create_entity('CWPermission', name=PERM_USE_TEMPLATE_FORMAT, |
a50d03e7014f
move some stuff from server/__init__ to postcreate, fixing instance creation bug
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2920
diff
changeset
|
62 |
label=_('use template languages')) |
0 | 63 |
rql('SET X require_group G WHERE G name "managers", X eid %(x)s', |
3005
a50d03e7014f
move some stuff from server/__init__ to postcreate, fixing instance creation bug
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2920
diff
changeset
|
64 |
{'x': usetmplperm.eid}, 'x') |