author | Sylvain Thénault <sylvain.thenault@logilab.fr> |
Tue, 26 Jul 2011 16:49:10 +0200 | |
branch | stable |
changeset 7699 | d07cde311630 |
parent 6427 | c8a5ac2d1eaa |
child 7780 | a1d5365fefc1 |
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/>. |
6427
c8a5ac2d1eaa
[schema / sources] store data sources as cubicweb entities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5426
diff
changeset
|
18 |
"""cubicweb post creation script, set user's workflow""" |
1977
606923dff11b
big bunch of copyright / docstring update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
19 |
|
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
|
20 |
# 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
|
21 |
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
|
22 |
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
|
23 |
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
|
24 |
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
|
25 |
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
|
26 |
|
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 |
# 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
|
28 |
# '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
|
29 |
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
|
30 |
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
|
31 |
'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
|
32 |
'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
|
33 |
' 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
|
34 |
' 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
|
35 |
|
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 |
# 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
|
37 |
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
|
38 |
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
|
39 |
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
|
40 |
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
|
41 |
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
|
42 |
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
|
43 |
requiredgroups=('managers',)) |
0 | 44 |
|
45 |
# create anonymous user if all-in-one config and anonymous user has been specified |
|
46 |
if hasattr(config, 'anonymous_user'): |
|
47 |
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
|
48 |
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
|
49 |
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
|
50 |
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
|
51 |
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
|
52 |
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
|
53 |
create_user(session, unicode(anonlogin), anonpwd, 'guests') |
0 | 54 |
|
2920
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2172
diff
changeset
|
55 |
# 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
|
56 |
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
|
57 |
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
|
58 |
{'x': user.eid, 's': activated.eid}) |
0 | 59 |
|
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
|
60 |
# 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
|
61 |
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
|
62 |
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
|
63 |
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
|
64 |
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
|
65 |
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
|
66 |
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
|
67 |
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
|
68 |
# 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
|
69 |
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
|
70 |
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
|
71 |
{'k': key, 'v': value}) |
0 | 72 |
|
73 |
# add PERM_USE_TEMPLATE_FORMAT permission |
|
74 |
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
|
75 |
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
|
76 |
label=_('use template languages')) |
0 | 77 |
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
|
78 |
{'x': usetmplperm.eid}) |