1 # copyright 2003-2012 LOGILAB S.A. (Paris, FRANCE), all rights reserved. |
|
2 # contact http://www.logilab.fr/ -- mailto:contact@logilab.fr |
|
3 # |
|
4 # This file is part of CubicWeb. |
|
5 # |
|
6 # CubicWeb is free software: you can redistribute it and/or modify it under the |
|
7 # terms of the GNU Lesser General Public License as published by the Free |
|
8 # Software Foundation, either version 2.1 of the License, or (at your option) |
|
9 # any later version. |
|
10 # |
|
11 # CubicWeb is distributed in the hope that it will be useful, but WITHOUT |
|
12 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
|
13 # FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more |
|
14 # details. |
|
15 # |
|
16 # You should have received a copy of the GNU Lesser General Public License along |
|
17 # with CubicWeb. If not, see <http://www.gnu.org/licenses/>. |
|
18 """cubicweb post creation script, set user's workflow""" |
|
19 from __future__ import print_function |
|
20 |
|
21 from six import text_type |
|
22 |
|
23 from cubicweb import _ |
|
24 |
|
25 |
|
26 # insert versions |
|
27 create_entity('CWProperty', pkey=u'system.version.cubicweb', |
|
28 value=text_type(config.cubicweb_version())) |
|
29 for cube in config.cubes(): |
|
30 create_entity('CWProperty', pkey=u'system.version.%s' % cube.lower(), |
|
31 value=text_type(config.cube_version(cube))) |
|
32 |
|
33 # some entities have been added before schema entities, fix the 'is' and |
|
34 # 'is_instance_of' relations |
|
35 for rtype in ('is', 'is_instance_of'): |
|
36 sql('INSERT INTO %s_relation ' |
|
37 'SELECT X.eid, ET.cw_eid FROM entities as X, cw_CWEType as ET ' |
|
38 'WHERE X.type=ET.cw_name AND NOT EXISTS(' |
|
39 ' SELECT 1 from %s_relation ' |
|
40 ' WHERE eid_from=X.eid AND eid_to=ET.cw_eid)' % (rtype, rtype)) |
|
41 |
|
42 # user workflow |
|
43 userwf = add_workflow(_('default user workflow'), 'CWUser') |
|
44 activated = userwf.add_state(_('activated'), initial=True) |
|
45 deactivated = userwf.add_state(_('deactivated')) |
|
46 userwf.add_transition(_('deactivate'), (activated,), deactivated, |
|
47 requiredgroups=(u'managers',)) |
|
48 userwf.add_transition(_('activate'), (deactivated,), activated, |
|
49 requiredgroups=(u'managers',)) |
|
50 |
|
51 # create anonymous user if all-in-one config and anonymous user has been specified |
|
52 if hasattr(config, 'anonymous_user'): |
|
53 anonlogin, anonpwd = config.anonymous_user() |
|
54 if anonlogin == session.user.login: |
|
55 print('you are using a manager account as anonymous user.') |
|
56 print('Hopefully this is not a production instance...') |
|
57 elif anonlogin: |
|
58 from cubicweb.server import create_user |
|
59 create_user(session, text_type(anonlogin), anonpwd, u'guests') |
|
60 |
|
61 # need this since we already have at least one user in the database (the default admin) |
|
62 for user in rql('Any X WHERE X is CWUser').entities(): |
|
63 rql('SET X in_state S WHERE X eid %(x)s, S eid %(s)s', |
|
64 {'x': user.eid, 's': activated.eid}) |
|
65 |
|
66 # on interactive mode, ask for level 0 persistent options |
|
67 if interactive_mode: |
|
68 cfg = config.persistent_options_configuration() |
|
69 cfg.input_config(inputlevel=0) |
|
70 for section, options in cfg.options_by_section(): |
|
71 for optname, optdict, value in options: |
|
72 key = u'%s.%s' % (section, optname) |
|
73 default = cfg.option_default(optname, optdict) |
|
74 # only record values differing from default |
|
75 if value != default: |
|
76 rql('INSERT CWProperty X: X pkey %(k)s, X value %(v)s', |
|
77 {'k': key, 'v': value}) |
|