author | Sylvain Thénault <sylvain.thenault@logilab.fr> |
Thu, 20 Aug 2009 17:44:27 +0200 | |
branch | 3.5 |
changeset 2920 | 64322aa83a1d |
parent 2172 | cf8f9180e63e |
child 3005 | a50d03e7014f |
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 |
|
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
0
diff
changeset
|
9 |
activatedeid = add_state(_('activated'), 'CWUser', initial=True) |
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
0
diff
changeset
|
10 |
deactivatedeid = add_state(_('deactivated'), 'CWUser') |
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
0
diff
changeset
|
11 |
add_transition(_('deactivate'), 'CWUser', |
0 | 12 |
(activatedeid,), deactivatedeid, |
13 |
requiredgroups=('managers',)) |
|
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
0
diff
changeset
|
14 |
add_transition(_('activate'), 'CWUser', |
0 | 15 |
(deactivatedeid,), activatedeid, |
16 |
requiredgroups=('managers',)) |
|
17 |
||
18 |
# create anonymous user if all-in-one config and anonymous user has been specified |
|
19 |
if hasattr(config, 'anonymous_user'): |
|
20 |
anonlogin, anonpwd = config.anonymous_user() |
|
21 |
if anonlogin: |
|
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
0
diff
changeset
|
22 |
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
|
23 |
'X in_group G WHERE G name "guests"', |
0 | 24 |
{'login': unicode(anonlogin), 'pwd': anonpwd}) |
25 |
||
2920
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2172
diff
changeset
|
26 |
# 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
|
27 |
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
|
28 |
session.unsafe_execute('SET X in_state S WHERE X eid %(x)s, S eid %(s)s', |
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2172
diff
changeset
|
29 |
{'x': user.eid, 's': activatedeid}, 'x') |
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2172
diff
changeset
|
30 |
|
0 | 31 |
cfg = config.persistent_options_configuration() |
32 |
if interactive_mode: |
|
33 |
cfg.input_config(inputlevel=0) |
|
34 |
||
35 |
for section, options in cfg.options_by_section(): |
|
36 |
for optname, optdict, value in options: |
|
37 |
key = '%s.%s' % (section, optname) |
|
38 |
default = cfg.option_default(optname, optdict) |
|
39 |
# only record values differing from default |
|
40 |
if value != default: |
|
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
0
diff
changeset
|
41 |
rql('INSERT CWProperty X: X pkey %(k)s, X value %(v)s', {'k': key, 'v': value}) |
0 | 42 |
|
43 |
# add PERM_USE_TEMPLATE_FORMAT permission |
|
44 |
from cubicweb.schema import PERM_USE_TEMPLATE_FORMAT |
|
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
0
diff
changeset
|
45 |
eid = add_entity('CWPermission', name=PERM_USE_TEMPLATE_FORMAT, |
0 | 46 |
label=_('use template languages')) |
47 |
rql('SET X require_group G WHERE G name "managers", X eid %(x)s', |
|
2172
cf8f9180e63e
delete-trailing-whitespace
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
1977
diff
changeset
|
48 |
{'x': eid}, 'x') |