author | Sylvain Thénault <sylvain.thenault@logilab.fr> |
Wed, 25 Aug 2010 10:01:11 +0200 | |
changeset 6140 | 65a619eb31c4 |
parent 5426 | 0d4853a6e5ee |
child 6427 | c8a5ac2d1eaa |
permissions | -rw-r--r-- |
5421
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4835
diff
changeset
|
1 |
# copyright 2003-2010 LOGILAB S.A. (Paris, FRANCE), all rights reserved. |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4835
diff
changeset
|
2 |
# contact http://www.logilab.fr/ -- mailto:contact@logilab.fr |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4835
diff
changeset
|
3 |
# |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4835
diff
changeset
|
4 |
# This file is part of CubicWeb. |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4835
diff
changeset
|
5 |
# |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4835
diff
changeset
|
6 |
# CubicWeb is free software: you can redistribute it and/or modify it under the |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4835
diff
changeset
|
7 |
# terms of the GNU Lesser General Public License as published by the Free |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4835
diff
changeset
|
8 |
# Software Foundation, either version 2.1 of the License, or (at your option) |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4835
diff
changeset
|
9 |
# any later version. |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4835
diff
changeset
|
10 |
# |
5424
8ecbcbff9777
replace logilab-common by CubicWeb in disclaimer
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5421
diff
changeset
|
11 |
# CubicWeb is distributed in the hope that it will be useful, but WITHOUT |
5421
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4835
diff
changeset
|
12 |
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4835
diff
changeset
|
13 |
# FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4835
diff
changeset
|
14 |
# details. |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4835
diff
changeset
|
15 |
# |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4835
diff
changeset
|
16 |
# You should have received a copy of the GNU Lesser General Public License along |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4835
diff
changeset
|
17 |
# with CubicWeb. If not, see <http://www.gnu.org/licenses/>. |
1977
606923dff11b
big bunch of copyright / docstring update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
18 |
"""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
|
19 |
|
606923dff11b
big bunch of copyright / docstring update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
20 |
""" |
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
|
21 |
# 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
|
22 |
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
|
23 |
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
|
24 |
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
|
25 |
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
|
26 |
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
|
27 |
|
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 |
# 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
|
29 |
# '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
|
30 |
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
|
31 |
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
|
32 |
'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
|
33 |
'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
|
34 |
' 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
|
35 |
' 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
|
36 |
|
a50d03e7014f
move some stuff from server/__init__ to postcreate, fixing instance creation bug
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2920
diff
changeset
|
37 |
# 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
|
38 |
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
|
39 |
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
|
40 |
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
|
41 |
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
|
42 |
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
|
43 |
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
|
44 |
requiredgroups=('managers',)) |
0 | 45 |
|
46 |
# create anonymous user if all-in-one config and anonymous user has been specified |
|
47 |
if hasattr(config, 'anonymous_user'): |
|
48 |
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
|
49 |
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
|
50 |
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
|
51 |
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
|
52 |
elif anonlogin: |
4612
d6ae30c5d055
added a function to create admin/anon user during db initialization process so one get a chance to monkey patch it
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4212
diff
changeset
|
53 |
from cubicweb.server import create_user |
d6ae30c5d055
added a function to create admin/anon user during db initialization process so one get a chance to monkey patch it
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4212
diff
changeset
|
54 |
create_user(session, unicode(anonlogin), anonpwd, 'guests') |
0 | 55 |
|
2920
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2172
diff
changeset
|
56 |
# 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
|
57 |
for user in rql('Any X WHERE X is CWUser').entities(): |
4835
13b0b96d7982
[repo] enhanced security handling: deprecates unsafe_execute, in favor of explicit read/write security control using the `enabled_security` context manager. Also code executed on the repository side is now unsafe by default.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4612
diff
changeset
|
58 |
rql('SET X in_state S WHERE X eid %(x)s, S eid %(s)s', |
5174
78438ad513ca
#759035: Automate addition of eid cachekey in RQL analysis
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4835
diff
changeset
|
59 |
{'x': user.eid, 's': activated.eid}) |
0 | 60 |
|
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 |
# 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
|
62 |
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
|
63 |
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
|
64 |
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
|
65 |
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
|
66 |
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
|
67 |
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
|
68 |
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
|
69 |
# 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
|
70 |
if value != default: |
5174
78438ad513ca
#759035: Automate addition of eid cachekey in RQL analysis
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4835
diff
changeset
|
71 |
rql('INSERT CWProperty X: X pkey %(k)s, X value %(v)s', |
78438ad513ca
#759035: Automate addition of eid cachekey in RQL analysis
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4835
diff
changeset
|
72 |
{'k': key, 'v': value}) |
0 | 73 |
|
74 |
# add PERM_USE_TEMPLATE_FORMAT permission |
|
75 |
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
|
76 |
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
|
77 |
label=_('use template languages')) |
0 | 78 |
rql('SET X require_group G WHERE G name "managers", X eid %(x)s', |
5174
78438ad513ca
#759035: Automate addition of eid cachekey in RQL analysis
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4835
diff
changeset
|
79 |
{'x': usetmplperm.eid}) |