author | Aurelien Campeas <aurelien.campeas@logilab.fr> |
Wed, 03 Feb 2010 16:19:12 +0100 | |
branch | stable |
changeset 4435 | 3e253ad89468 |
parent 4212 | ab6573088b4a |
child 4612 | d6ae30c5d055 |
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 |
4212
ab6573088b4a
update copyright: welcome 2010
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3822
diff
changeset
|
4 |
:copyright: 2001-2010 LOGILAB S.A. (Paris, FRANCE), license is LGPL v2. |
1977
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() |
|
3822
b61c7b065a66
do not fail if anon user == manager, simply emit warning that it should not be done in production.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3005
diff
changeset
|
37 |
if anonlogin == session.user.login: |
b61c7b065a66
do not fail if anon user == manager, simply emit warning that it should not be done in production.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3005
diff
changeset
|
38 |
print 'you are using a manager account as anonymous user.' |
b61c7b065a66
do not fail if anon user == manager, simply emit warning that it should not be done in production.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3005
diff
changeset
|
39 |
print 'Hopefully this is not a production instance...' |
b61c7b065a66
do not fail if anon user == manager, simply emit warning that it should not be done in production.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3005
diff
changeset
|
40 |
elif anonlogin: |
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
0
diff
changeset
|
41 |
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
|
42 |
'X in_group G WHERE G name "guests"', |
0 | 43 |
{'login': unicode(anonlogin), 'pwd': anonpwd}) |
44 |
||
2920
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2172
diff
changeset
|
45 |
# 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
|
46 |
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
|
47 |
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
|
48 |
{'x': user.eid, 's': activated.eid}, 'x') |
0 | 49 |
|
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
|
50 |
# 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
|
51 |
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
|
52 |
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
|
53 |
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
|
54 |
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
|
55 |
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
|
56 |
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
|
57 |
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
|
58 |
# 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
|
59 |
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
|
60 |
rql('INSERT CWProperty X: X pkey %(k)s, X value %(v)s', {'k': key, 'v': value}) |
0 | 61 |
|
62 |
# add PERM_USE_TEMPLATE_FORMAT permission |
|
63 |
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
|
64 |
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
|
65 |
label=_('use template languages')) |
0 | 66 |
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
|
67 |
{'x': usetmplperm.eid}, 'x') |