##// END OF EJS Templates
default permissions can get duplicated after migration from 1.4.X. check and verify again it, notify user that he should re-check it.
marcink -
r3101:102ef3f1 beta
parent child Browse files
Show More
@@ -0,0 +1,28 b''
1 import logging
2 import datetime
3
4 from sqlalchemy import *
5 from sqlalchemy.exc import DatabaseError
6 from sqlalchemy.orm import relation, backref, class_mapper, joinedload
7 from sqlalchemy.orm.session import Session
8 from sqlalchemy.ext.declarative import declarative_base
9
10 from rhodecode.lib.dbmigrate.migrate import *
11 from rhodecode.lib.dbmigrate.migrate.changeset import *
12
13 from rhodecode.model.meta import Base
14 from rhodecode.model import meta
15
16 log = logging.getLogger(__name__)
17
18
19 def upgrade(migrate_engine):
20 """
21 Upgrade operations go here.
22 Don't create your own engine; bind migrate_engine to your metadata
23 """
24 pass
25
26 def downgrade(migrate_engine):
27 meta = MetaData()
28 meta.bind = migrate_engine
@@ -1,67 +1,67 b''
1 # -*- coding: utf-8 -*-
1 # -*- coding: utf-8 -*-
2 """
2 """
3 rhodecode.__init__
3 rhodecode.__init__
4 ~~~~~~~~~~~~~~~~~~
4 ~~~~~~~~~~~~~~~~~~
5
5
6 RhodeCode, a web based repository management based on pylons
6 RhodeCode, a web based repository management based on pylons
7 versioning implementation: http://www.python.org/dev/peps/pep-0386/
7 versioning implementation: http://www.python.org/dev/peps/pep-0386/
8
8
9 :created_on: Apr 9, 2010
9 :created_on: Apr 9, 2010
10 :author: marcink
10 :author: marcink
11 :copyright: (C) 2010-2012 Marcin Kuzminski <marcin@python-works.com>
11 :copyright: (C) 2010-2012 Marcin Kuzminski <marcin@python-works.com>
12 :license: GPLv3, see COPYING for more details.
12 :license: GPLv3, see COPYING for more details.
13 """
13 """
14 # This program is free software: you can redistribute it and/or modify
14 # This program is free software: you can redistribute it and/or modify
15 # it under the terms of the GNU General Public License as published by
15 # it under the terms of the GNU General Public License as published by
16 # the Free Software Foundation, either version 3 of the License, or
16 # the Free Software Foundation, either version 3 of the License, or
17 # (at your option) any later version.
17 # (at your option) any later version.
18 #
18 #
19 # This program is distributed in the hope that it will be useful,
19 # This program is distributed in the hope that it will be useful,
20 # but WITHOUT ANY WARRANTY; without even the implied warranty of
20 # but WITHOUT ANY WARRANTY; without even the implied warranty of
21 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 # GNU General Public License for more details.
22 # GNU General Public License for more details.
23 #
23 #
24 # You should have received a copy of the GNU General Public License
24 # You should have received a copy of the GNU General Public License
25 # along with this program. If not, see <http://www.gnu.org/licenses/>.
25 # along with this program. If not, see <http://www.gnu.org/licenses/>.
26 import sys
26 import sys
27 import platform
27 import platform
28
28
29 VERSION = (1, 5, 1, 'b')
29 VERSION = (1, 5, 1, 'b')
30
30
31 try:
31 try:
32 from rhodecode.lib import get_current_revision
32 from rhodecode.lib import get_current_revision
33 _rev = get_current_revision()
33 _rev = get_current_revision()
34 if _rev and len(VERSION) > 3:
34 if _rev and len(VERSION) > 3:
35 VERSION += ('dev%s' % _rev[0],)
35 VERSION += ('dev%s' % _rev[0],)
36 except ImportError:
36 except ImportError:
37 pass
37 pass
38
38
39 __version__ = ('.'.join((str(each) for each in VERSION[:3])) +
39 __version__ = ('.'.join((str(each) for each in VERSION[:3])) +
40 '.'.join(VERSION[3:]))
40 '.'.join(VERSION[3:]))
41 __dbversion__ = 8 # defines current db version for migrations
41 __dbversion__ = 9 # defines current db version for migrations
42 __platform__ = platform.system()
42 __platform__ = platform.system()
43 __license__ = 'GPLv3'
43 __license__ = 'GPLv3'
44 __py_version__ = sys.version_info
44 __py_version__ = sys.version_info
45 __author__ = 'Marcin Kuzminski'
45 __author__ = 'Marcin Kuzminski'
46 __url__ = 'http://rhodecode.org'
46 __url__ = 'http://rhodecode.org'
47
47
48 PLATFORM_WIN = ('Windows')
48 PLATFORM_WIN = ('Windows')
49 PLATFORM_OTHERS = ('Linux', 'Darwin', 'FreeBSD', 'OpenBSD', 'SunOS') #depracated
49 PLATFORM_OTHERS = ('Linux', 'Darwin', 'FreeBSD', 'OpenBSD', 'SunOS') #depracated
50
50
51 is_windows = __platform__ in PLATFORM_WIN
51 is_windows = __platform__ in PLATFORM_WIN
52 is_unix = not is_windows
52 is_unix = not is_windows
53
53
54
54
55 BACKENDS = {
55 BACKENDS = {
56 'hg': 'Mercurial repository',
56 'hg': 'Mercurial repository',
57 'git': 'Git repository',
57 'git': 'Git repository',
58 }
58 }
59
59
60 CELERY_ON = False
60 CELERY_ON = False
61 CELERY_EAGER = False
61 CELERY_EAGER = False
62
62
63 # link to config for pylons
63 # link to config for pylons
64 CONFIG = {}
64 CONFIG = {}
65
65
66 # Linked module for extensions
66 # Linked module for extensions
67 EXTENSIONS = {}
67 EXTENSIONS = {}
@@ -1,701 +1,711 b''
1 # -*- coding: utf-8 -*-
1 # -*- coding: utf-8 -*-
2 """
2 """
3 rhodecode.lib.db_manage
3 rhodecode.lib.db_manage
4 ~~~~~~~~~~~~~~~~~~~~~~~
4 ~~~~~~~~~~~~~~~~~~~~~~~
5
5
6 Database creation, and setup module for RhodeCode. Used for creation
6 Database creation, and setup module for RhodeCode. Used for creation
7 of database as well as for migration operations
7 of database as well as for migration operations
8
8
9 :created_on: Apr 10, 2010
9 :created_on: Apr 10, 2010
10 :author: marcink
10 :author: marcink
11 :copyright: (C) 2010-2012 Marcin Kuzminski <marcin@python-works.com>
11 :copyright: (C) 2010-2012 Marcin Kuzminski <marcin@python-works.com>
12 :license: GPLv3, see COPYING for more details.
12 :license: GPLv3, see COPYING for more details.
13 """
13 """
14 # This program is free software: you can redistribute it and/or modify
14 # This program is free software: you can redistribute it and/or modify
15 # it under the terms of the GNU General Public License as published by
15 # it under the terms of the GNU General Public License as published by
16 # the Free Software Foundation, either version 3 of the License, or
16 # the Free Software Foundation, either version 3 of the License, or
17 # (at your option) any later version.
17 # (at your option) any later version.
18 #
18 #
19 # This program is distributed in the hope that it will be useful,
19 # This program is distributed in the hope that it will be useful,
20 # but WITHOUT ANY WARRANTY; without even the implied warranty of
20 # but WITHOUT ANY WARRANTY; without even the implied warranty of
21 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 # GNU General Public License for more details.
22 # GNU General Public License for more details.
23 #
23 #
24 # You should have received a copy of the GNU General Public License
24 # You should have received a copy of the GNU General Public License
25 # along with this program. If not, see <http://www.gnu.org/licenses/>.
25 # along with this program. If not, see <http://www.gnu.org/licenses/>.
26
26
27 import os
27 import os
28 import sys
28 import sys
29 import uuid
29 import uuid
30 import logging
30 import logging
31 from os.path import dirname as dn, join as jn
31 from os.path import dirname as dn, join as jn
32
32
33 from rhodecode import __dbversion__, __py_version__
33 from rhodecode import __dbversion__, __py_version__
34
34
35 from rhodecode.model.user import UserModel
35 from rhodecode.model.user import UserModel
36 from rhodecode.lib.utils import ask_ok
36 from rhodecode.lib.utils import ask_ok
37 from rhodecode.model import init_model
37 from rhodecode.model import init_model
38 from rhodecode.model.db import User, Permission, RhodeCodeUi, \
38 from rhodecode.model.db import User, Permission, RhodeCodeUi, \
39 RhodeCodeSetting, UserToPerm, DbMigrateVersion, RepoGroup, \
39 RhodeCodeSetting, UserToPerm, DbMigrateVersion, RepoGroup, \
40 UserRepoGroupToPerm
40 UserRepoGroupToPerm
41
41
42 from sqlalchemy.engine import create_engine
42 from sqlalchemy.engine import create_engine
43 from rhodecode.model.repos_group import ReposGroupModel
43 from rhodecode.model.repos_group import ReposGroupModel
44 #from rhodecode.model import meta
44 #from rhodecode.model import meta
45 from rhodecode.model.meta import Session, Base
45 from rhodecode.model.meta import Session, Base
46
46
47
47
48 log = logging.getLogger(__name__)
48 log = logging.getLogger(__name__)
49
49
50
50
51 def notify(msg):
51 def notify(msg):
52 """
52 """
53 Notification for migrations messages
53 Notification for migrations messages
54 """
54 """
55 ml = len(msg) + (4 * 2)
55 ml = len(msg) + (4 * 2)
56 print >> sys.stdout, ('*** %s ***\n%s' % (msg, '*' * ml)).upper()
56 print >> sys.stdout, ('*** %s ***\n%s' % (msg, '*' * ml)).upper()
57
57
58
58
59 class DbManage(object):
59 class DbManage(object):
60 def __init__(self, log_sql, dbconf, root, tests=False, cli_args={}):
60 def __init__(self, log_sql, dbconf, root, tests=False, cli_args={}):
61 self.dbname = dbconf.split('/')[-1]
61 self.dbname = dbconf.split('/')[-1]
62 self.tests = tests
62 self.tests = tests
63 self.root = root
63 self.root = root
64 self.dburi = dbconf
64 self.dburi = dbconf
65 self.log_sql = log_sql
65 self.log_sql = log_sql
66 self.db_exists = False
66 self.db_exists = False
67 self.cli_args = cli_args
67 self.cli_args = cli_args
68 self.init_db()
68 self.init_db()
69 global ask_ok
69 global ask_ok
70
70
71 if self.cli_args.get('force_ask') is True:
71 if self.cli_args.get('force_ask') is True:
72 ask_ok = lambda *args, **kwargs: True
72 ask_ok = lambda *args, **kwargs: True
73 elif self.cli_args.get('force_ask') is False:
73 elif self.cli_args.get('force_ask') is False:
74 ask_ok = lambda *args, **kwargs: False
74 ask_ok = lambda *args, **kwargs: False
75
75
76 def init_db(self):
76 def init_db(self):
77 engine = create_engine(self.dburi, echo=self.log_sql)
77 engine = create_engine(self.dburi, echo=self.log_sql)
78 init_model(engine)
78 init_model(engine)
79 self.sa = Session()
79 self.sa = Session()
80
80
81 def create_tables(self, override=False):
81 def create_tables(self, override=False):
82 """
82 """
83 Create a auth database
83 Create a auth database
84 """
84 """
85
85
86 log.info("Any existing database is going to be destroyed")
86 log.info("Any existing database is going to be destroyed")
87 if self.tests:
87 if self.tests:
88 destroy = True
88 destroy = True
89 else:
89 else:
90 destroy = ask_ok('Are you sure to destroy old database ? [y/n]')
90 destroy = ask_ok('Are you sure to destroy old database ? [y/n]')
91 if not destroy:
91 if not destroy:
92 sys.exit('Nothing done')
92 sys.exit('Nothing done')
93 if destroy:
93 if destroy:
94 Base.metadata.drop_all()
94 Base.metadata.drop_all()
95
95
96 checkfirst = not override
96 checkfirst = not override
97 Base.metadata.create_all(checkfirst=checkfirst)
97 Base.metadata.create_all(checkfirst=checkfirst)
98 log.info('Created tables for %s' % self.dbname)
98 log.info('Created tables for %s' % self.dbname)
99
99
100 def set_db_version(self):
100 def set_db_version(self):
101 ver = DbMigrateVersion()
101 ver = DbMigrateVersion()
102 ver.version = __dbversion__
102 ver.version = __dbversion__
103 ver.repository_id = 'rhodecode_db_migrations'
103 ver.repository_id = 'rhodecode_db_migrations'
104 ver.repository_path = 'versions'
104 ver.repository_path = 'versions'
105 self.sa.add(ver)
105 self.sa.add(ver)
106 log.info('db version set to: %s' % __dbversion__)
106 log.info('db version set to: %s' % __dbversion__)
107
107
108 def upgrade(self):
108 def upgrade(self):
109 """
109 """
110 Upgrades given database schema to given revision following
110 Upgrades given database schema to given revision following
111 all needed steps, to perform the upgrade
111 all needed steps, to perform the upgrade
112
112
113 """
113 """
114
114
115 from rhodecode.lib.dbmigrate.migrate.versioning import api
115 from rhodecode.lib.dbmigrate.migrate.versioning import api
116 from rhodecode.lib.dbmigrate.migrate.exceptions import \
116 from rhodecode.lib.dbmigrate.migrate.exceptions import \
117 DatabaseNotControlledError
117 DatabaseNotControlledError
118
118
119 if 'sqlite' in self.dburi:
119 if 'sqlite' in self.dburi:
120 print (
120 print (
121 '********************** WARNING **********************\n'
121 '********************** WARNING **********************\n'
122 'Make sure your version of sqlite is at least 3.7.X. \n'
122 'Make sure your version of sqlite is at least 3.7.X. \n'
123 'Earlier versions are known to fail on some migrations\n'
123 'Earlier versions are known to fail on some migrations\n'
124 '*****************************************************\n'
124 '*****************************************************\n'
125 )
125 )
126 upgrade = ask_ok('You are about to perform database upgrade, make '
126 upgrade = ask_ok('You are about to perform database upgrade, make '
127 'sure You backed up your database before. '
127 'sure You backed up your database before. '
128 'Continue ? [y/n]')
128 'Continue ? [y/n]')
129 if not upgrade:
129 if not upgrade:
130 sys.exit('Nothing done')
130 sys.exit('Nothing done')
131
131
132 repository_path = jn(dn(dn(dn(os.path.realpath(__file__)))),
132 repository_path = jn(dn(dn(dn(os.path.realpath(__file__)))),
133 'rhodecode/lib/dbmigrate')
133 'rhodecode/lib/dbmigrate')
134 db_uri = self.dburi
134 db_uri = self.dburi
135
135
136 try:
136 try:
137 curr_version = api.db_version(db_uri, repository_path)
137 curr_version = api.db_version(db_uri, repository_path)
138 msg = ('Found current database under version'
138 msg = ('Found current database under version'
139 ' control with version %s' % curr_version)
139 ' control with version %s' % curr_version)
140
140
141 except (RuntimeError, DatabaseNotControlledError):
141 except (RuntimeError, DatabaseNotControlledError):
142 curr_version = 1
142 curr_version = 1
143 msg = ('Current database is not under version control. Setting'
143 msg = ('Current database is not under version control. Setting'
144 ' as version %s' % curr_version)
144 ' as version %s' % curr_version)
145 api.version_control(db_uri, repository_path, curr_version)
145 api.version_control(db_uri, repository_path, curr_version)
146
146
147 notify(msg)
147 notify(msg)
148
148
149 if curr_version == __dbversion__:
149 if curr_version == __dbversion__:
150 sys.exit('This database is already at the newest version')
150 sys.exit('This database is already at the newest version')
151
151
152 #======================================================================
152 #======================================================================
153 # UPGRADE STEPS
153 # UPGRADE STEPS
154 #======================================================================
154 #======================================================================
155
155
156 class UpgradeSteps(object):
156 class UpgradeSteps(object):
157 """
157 """
158 Those steps follow schema versions so for example schema
158 Those steps follow schema versions so for example schema
159 for example schema with seq 002 == step_2 and so on.
159 for example schema with seq 002 == step_2 and so on.
160 """
160 """
161
161
162 def __init__(self, klass):
162 def __init__(self, klass):
163 self.klass = klass
163 self.klass = klass
164
164
165 def step_0(self):
165 def step_0(self):
166 # step 0 is the schema upgrade, and than follow proper upgrades
166 # step 0 is the schema upgrade, and than follow proper upgrades
167 notify('attempting to do database upgrade to version %s' \
167 notify('attempting to do database upgrade to version %s' \
168 % __dbversion__)
168 % __dbversion__)
169 api.upgrade(db_uri, repository_path, __dbversion__)
169 api.upgrade(db_uri, repository_path, __dbversion__)
170 notify('Schema upgrade completed')
170 notify('Schema upgrade completed')
171
171
172 def step_1(self):
172 def step_1(self):
173 pass
173 pass
174
174
175 def step_2(self):
175 def step_2(self):
176 notify('Patching repo paths for newer version of RhodeCode')
176 notify('Patching repo paths for newer version of RhodeCode')
177 self.klass.fix_repo_paths()
177 self.klass.fix_repo_paths()
178
178
179 notify('Patching default user of RhodeCode')
179 notify('Patching default user of RhodeCode')
180 self.klass.fix_default_user()
180 self.klass.fix_default_user()
181
181
182 log.info('Changing ui settings')
182 log.info('Changing ui settings')
183 self.klass.create_ui_settings()
183 self.klass.create_ui_settings()
184
184
185 def step_3(self):
185 def step_3(self):
186 notify('Adding additional settings into RhodeCode db')
186 notify('Adding additional settings into RhodeCode db')
187 self.klass.fix_settings()
187 self.klass.fix_settings()
188 notify('Adding ldap defaults')
188 notify('Adding ldap defaults')
189 self.klass.create_ldap_options(skip_existing=True)
189 self.klass.create_ldap_options(skip_existing=True)
190
190
191 def step_4(self):
191 def step_4(self):
192 notify('create permissions and fix groups')
192 notify('create permissions and fix groups')
193 self.klass.create_permissions()
193 self.klass.create_permissions()
194 self.klass.fixup_groups()
194 self.klass.fixup_groups()
195
195
196 def step_5(self):
196 def step_5(self):
197 pass
197 pass
198
198
199 def step_6(self):
199 def step_6(self):
200
200
201 notify('re-checking permissions')
201 notify('re-checking permissions')
202 self.klass.create_permissions()
202 self.klass.create_permissions()
203
203
204 notify('installing new UI options')
204 notify('installing new UI options')
205 sett4 = RhodeCodeSetting('show_public_icon', True)
205 sett4 = RhodeCodeSetting('show_public_icon', True)
206 Session().add(sett4)
206 Session().add(sett4)
207 sett5 = RhodeCodeSetting('show_private_icon', True)
207 sett5 = RhodeCodeSetting('show_private_icon', True)
208 Session().add(sett5)
208 Session().add(sett5)
209 sett6 = RhodeCodeSetting('stylify_metatags', False)
209 sett6 = RhodeCodeSetting('stylify_metatags', False)
210 Session().add(sett6)
210 Session().add(sett6)
211
211
212 notify('fixing old PULL hook')
212 notify('fixing old PULL hook')
213 _pull = RhodeCodeUi.get_by_key('preoutgoing.pull_logger')
213 _pull = RhodeCodeUi.get_by_key('preoutgoing.pull_logger')
214 if _pull:
214 if _pull:
215 _pull.ui_key = RhodeCodeUi.HOOK_PULL
215 _pull.ui_key = RhodeCodeUi.HOOK_PULL
216 Session().add(_pull)
216 Session().add(_pull)
217
217
218 notify('fixing old PUSH hook')
218 notify('fixing old PUSH hook')
219 _push = RhodeCodeUi.get_by_key('pretxnchangegroup.push_logger')
219 _push = RhodeCodeUi.get_by_key('pretxnchangegroup.push_logger')
220 if _push:
220 if _push:
221 _push.ui_key = RhodeCodeUi.HOOK_PUSH
221 _push.ui_key = RhodeCodeUi.HOOK_PUSH
222 Session().add(_push)
222 Session().add(_push)
223
223
224 notify('installing new pre-push hook')
224 notify('installing new pre-push hook')
225 hooks4 = RhodeCodeUi()
225 hooks4 = RhodeCodeUi()
226 hooks4.ui_section = 'hooks'
226 hooks4.ui_section = 'hooks'
227 hooks4.ui_key = RhodeCodeUi.HOOK_PRE_PUSH
227 hooks4.ui_key = RhodeCodeUi.HOOK_PRE_PUSH
228 hooks4.ui_value = 'python:rhodecode.lib.hooks.pre_push'
228 hooks4.ui_value = 'python:rhodecode.lib.hooks.pre_push'
229 Session().add(hooks4)
229 Session().add(hooks4)
230
230
231 notify('installing new pre-pull hook')
231 notify('installing new pre-pull hook')
232 hooks6 = RhodeCodeUi()
232 hooks6 = RhodeCodeUi()
233 hooks6.ui_section = 'hooks'
233 hooks6.ui_section = 'hooks'
234 hooks6.ui_key = RhodeCodeUi.HOOK_PRE_PULL
234 hooks6.ui_key = RhodeCodeUi.HOOK_PRE_PULL
235 hooks6.ui_value = 'python:rhodecode.lib.hooks.pre_pull'
235 hooks6.ui_value = 'python:rhodecode.lib.hooks.pre_pull'
236 Session().add(hooks6)
236 Session().add(hooks6)
237
237
238 notify('installing hgsubversion option')
238 notify('installing hgsubversion option')
239 # enable hgsubversion disabled by default
239 # enable hgsubversion disabled by default
240 hgsubversion = RhodeCodeUi()
240 hgsubversion = RhodeCodeUi()
241 hgsubversion.ui_section = 'extensions'
241 hgsubversion.ui_section = 'extensions'
242 hgsubversion.ui_key = 'hgsubversion'
242 hgsubversion.ui_key = 'hgsubversion'
243 hgsubversion.ui_value = ''
243 hgsubversion.ui_value = ''
244 hgsubversion.ui_active = False
244 hgsubversion.ui_active = False
245 Session().add(hgsubversion)
245 Session().add(hgsubversion)
246
246
247 notify('installing hg git option')
247 notify('installing hg git option')
248 # enable hggit disabled by default
248 # enable hggit disabled by default
249 hggit = RhodeCodeUi()
249 hggit = RhodeCodeUi()
250 hggit.ui_section = 'extensions'
250 hggit.ui_section = 'extensions'
251 hggit.ui_key = 'hggit'
251 hggit.ui_key = 'hggit'
252 hggit.ui_value = ''
252 hggit.ui_value = ''
253 hggit.ui_active = False
253 hggit.ui_active = False
254 Session().add(hggit)
254 Session().add(hggit)
255
255
256 notify('re-check default permissions')
256 notify('re-check default permissions')
257 default_user = User.get_by_username(User.DEFAULT_USER)
257 default_user = User.get_by_username(User.DEFAULT_USER)
258 perm = Permission.get_by_key('hg.fork.repository')
258 perm = Permission.get_by_key('hg.fork.repository')
259 reg_perm = UserToPerm()
259 reg_perm = UserToPerm()
260 reg_perm.user = default_user
260 reg_perm.user = default_user
261 reg_perm.permission = perm
261 reg_perm.permission = perm
262 Session().add(reg_perm)
262 Session().add(reg_perm)
263
263
264 def step_7(self):
264 def step_7(self):
265 perm_fixes = self.klass.reset_permissions(User.DEFAULT_USER)
265 perm_fixes = self.klass.reset_permissions(User.DEFAULT_USER)
266 Session().commit()
266 Session().commit()
267 if perm_fixes:
267 if perm_fixes:
268 notify('There was an inconsistent state of permissions '
268 notify('There was an inconsistent state of permissions '
269 'detected for default user. Permissions are now '
269 'detected for default user. Permissions are now '
270 'reset to the default value for default user. '
270 'reset to the default value for default user. '
271 'Please validate and check default permissions '
271 'Please validate and check default permissions '
272 'in admin panel')
272 'in admin panel')
273
273
274 def step_8(self):
274 def step_8(self):
275 self.klass.populate_default_permissions()
275 self.klass.populate_default_permissions()
276 self.klass.create_default_options(skip_existing=True)
276 self.klass.create_default_options(skip_existing=True)
277 Session().commit()
277 Session().commit()
278
278
279 def step_9(self):
280 perm_fixes = self.klass.reset_permissions(User.DEFAULT_USER)
281 Session().commit()
282 if perm_fixes:
283 notify('There was an inconsistent state of permissions '
284 'detected for default user. Permissions are now '
285 'reset to the default value for default user. '
286 'Please validate and check default permissions '
287 'in admin panel')
288
279 upgrade_steps = [0] + range(curr_version + 1, __dbversion__ + 1)
289 upgrade_steps = [0] + range(curr_version + 1, __dbversion__ + 1)
280
290
281 # CALL THE PROPER ORDER OF STEPS TO PERFORM FULL UPGRADE
291 # CALL THE PROPER ORDER OF STEPS TO PERFORM FULL UPGRADE
282 _step = None
292 _step = None
283 for step in upgrade_steps:
293 for step in upgrade_steps:
284 notify('performing upgrade step %s' % step)
294 notify('performing upgrade step %s' % step)
285 getattr(UpgradeSteps(self), 'step_%s' % step)()
295 getattr(UpgradeSteps(self), 'step_%s' % step)()
286 self.sa.commit()
296 self.sa.commit()
287 _step = step
297 _step = step
288
298
289 notify('upgrade to version %s successful' % _step)
299 notify('upgrade to version %s successful' % _step)
290
300
291 def fix_repo_paths(self):
301 def fix_repo_paths(self):
292 """
302 """
293 Fixes a old rhodecode version path into new one without a '*'
303 Fixes a old rhodecode version path into new one without a '*'
294 """
304 """
295
305
296 paths = self.sa.query(RhodeCodeUi)\
306 paths = self.sa.query(RhodeCodeUi)\
297 .filter(RhodeCodeUi.ui_key == '/')\
307 .filter(RhodeCodeUi.ui_key == '/')\
298 .scalar()
308 .scalar()
299
309
300 paths.ui_value = paths.ui_value.replace('*', '')
310 paths.ui_value = paths.ui_value.replace('*', '')
301
311
302 try:
312 try:
303 self.sa.add(paths)
313 self.sa.add(paths)
304 self.sa.commit()
314 self.sa.commit()
305 except:
315 except:
306 self.sa.rollback()
316 self.sa.rollback()
307 raise
317 raise
308
318
309 def fix_default_user(self):
319 def fix_default_user(self):
310 """
320 """
311 Fixes a old default user with some 'nicer' default values,
321 Fixes a old default user with some 'nicer' default values,
312 used mostly for anonymous access
322 used mostly for anonymous access
313 """
323 """
314 def_user = self.sa.query(User)\
324 def_user = self.sa.query(User)\
315 .filter(User.username == 'default')\
325 .filter(User.username == 'default')\
316 .one()
326 .one()
317
327
318 def_user.name = 'Anonymous'
328 def_user.name = 'Anonymous'
319 def_user.lastname = 'User'
329 def_user.lastname = 'User'
320 def_user.email = 'anonymous@rhodecode.org'
330 def_user.email = 'anonymous@rhodecode.org'
321
331
322 try:
332 try:
323 self.sa.add(def_user)
333 self.sa.add(def_user)
324 self.sa.commit()
334 self.sa.commit()
325 except:
335 except:
326 self.sa.rollback()
336 self.sa.rollback()
327 raise
337 raise
328
338
329 def fix_settings(self):
339 def fix_settings(self):
330 """
340 """
331 Fixes rhodecode settings adds ga_code key for google analytics
341 Fixes rhodecode settings adds ga_code key for google analytics
332 """
342 """
333
343
334 hgsettings3 = RhodeCodeSetting('ga_code', '')
344 hgsettings3 = RhodeCodeSetting('ga_code', '')
335
345
336 try:
346 try:
337 self.sa.add(hgsettings3)
347 self.sa.add(hgsettings3)
338 self.sa.commit()
348 self.sa.commit()
339 except:
349 except:
340 self.sa.rollback()
350 self.sa.rollback()
341 raise
351 raise
342
352
343 def admin_prompt(self, second=False):
353 def admin_prompt(self, second=False):
344 if not self.tests:
354 if not self.tests:
345 import getpass
355 import getpass
346
356
347 # defaults
357 # defaults
348 defaults = self.cli_args
358 defaults = self.cli_args
349 username = defaults.get('username')
359 username = defaults.get('username')
350 password = defaults.get('password')
360 password = defaults.get('password')
351 email = defaults.get('email')
361 email = defaults.get('email')
352
362
353 def get_password():
363 def get_password():
354 password = getpass.getpass('Specify admin password '
364 password = getpass.getpass('Specify admin password '
355 '(min 6 chars):')
365 '(min 6 chars):')
356 confirm = getpass.getpass('Confirm password:')
366 confirm = getpass.getpass('Confirm password:')
357
367
358 if password != confirm:
368 if password != confirm:
359 log.error('passwords mismatch')
369 log.error('passwords mismatch')
360 return False
370 return False
361 if len(password) < 6:
371 if len(password) < 6:
362 log.error('password is to short use at least 6 characters')
372 log.error('password is to short use at least 6 characters')
363 return False
373 return False
364
374
365 return password
375 return password
366 if username is None:
376 if username is None:
367 username = raw_input('Specify admin username:')
377 username = raw_input('Specify admin username:')
368 if password is None:
378 if password is None:
369 password = get_password()
379 password = get_password()
370 if not password:
380 if not password:
371 #second try
381 #second try
372 password = get_password()
382 password = get_password()
373 if not password:
383 if not password:
374 sys.exit()
384 sys.exit()
375 if email is None:
385 if email is None:
376 email = raw_input('Specify admin email:')
386 email = raw_input('Specify admin email:')
377 self.create_user(username, password, email, True)
387 self.create_user(username, password, email, True)
378 else:
388 else:
379 log.info('creating admin and regular test users')
389 log.info('creating admin and regular test users')
380 from rhodecode.tests import TEST_USER_ADMIN_LOGIN, \
390 from rhodecode.tests import TEST_USER_ADMIN_LOGIN, \
381 TEST_USER_ADMIN_PASS, TEST_USER_ADMIN_EMAIL, \
391 TEST_USER_ADMIN_PASS, TEST_USER_ADMIN_EMAIL, \
382 TEST_USER_REGULAR_LOGIN, TEST_USER_REGULAR_PASS, \
392 TEST_USER_REGULAR_LOGIN, TEST_USER_REGULAR_PASS, \
383 TEST_USER_REGULAR_EMAIL, TEST_USER_REGULAR2_LOGIN, \
393 TEST_USER_REGULAR_EMAIL, TEST_USER_REGULAR2_LOGIN, \
384 TEST_USER_REGULAR2_PASS, TEST_USER_REGULAR2_EMAIL
394 TEST_USER_REGULAR2_PASS, TEST_USER_REGULAR2_EMAIL
385
395
386 self.create_user(TEST_USER_ADMIN_LOGIN, TEST_USER_ADMIN_PASS,
396 self.create_user(TEST_USER_ADMIN_LOGIN, TEST_USER_ADMIN_PASS,
387 TEST_USER_ADMIN_EMAIL, True)
397 TEST_USER_ADMIN_EMAIL, True)
388
398
389 self.create_user(TEST_USER_REGULAR_LOGIN, TEST_USER_REGULAR_PASS,
399 self.create_user(TEST_USER_REGULAR_LOGIN, TEST_USER_REGULAR_PASS,
390 TEST_USER_REGULAR_EMAIL, False)
400 TEST_USER_REGULAR_EMAIL, False)
391
401
392 self.create_user(TEST_USER_REGULAR2_LOGIN, TEST_USER_REGULAR2_PASS,
402 self.create_user(TEST_USER_REGULAR2_LOGIN, TEST_USER_REGULAR2_PASS,
393 TEST_USER_REGULAR2_EMAIL, False)
403 TEST_USER_REGULAR2_EMAIL, False)
394
404
395 def create_ui_settings(self):
405 def create_ui_settings(self):
396 """
406 """
397 Creates ui settings, fills out hooks
407 Creates ui settings, fills out hooks
398 and disables dotencode
408 and disables dotencode
399 """
409 """
400
410
401 #HOOKS
411 #HOOKS
402 hooks1_key = RhodeCodeUi.HOOK_UPDATE
412 hooks1_key = RhodeCodeUi.HOOK_UPDATE
403 hooks1_ = self.sa.query(RhodeCodeUi)\
413 hooks1_ = self.sa.query(RhodeCodeUi)\
404 .filter(RhodeCodeUi.ui_key == hooks1_key).scalar()
414 .filter(RhodeCodeUi.ui_key == hooks1_key).scalar()
405
415
406 hooks1 = RhodeCodeUi() if hooks1_ is None else hooks1_
416 hooks1 = RhodeCodeUi() if hooks1_ is None else hooks1_
407 hooks1.ui_section = 'hooks'
417 hooks1.ui_section = 'hooks'
408 hooks1.ui_key = hooks1_key
418 hooks1.ui_key = hooks1_key
409 hooks1.ui_value = 'hg update >&2'
419 hooks1.ui_value = 'hg update >&2'
410 hooks1.ui_active = False
420 hooks1.ui_active = False
411 self.sa.add(hooks1)
421 self.sa.add(hooks1)
412
422
413 hooks2_key = RhodeCodeUi.HOOK_REPO_SIZE
423 hooks2_key = RhodeCodeUi.HOOK_REPO_SIZE
414 hooks2_ = self.sa.query(RhodeCodeUi)\
424 hooks2_ = self.sa.query(RhodeCodeUi)\
415 .filter(RhodeCodeUi.ui_key == hooks2_key).scalar()
425 .filter(RhodeCodeUi.ui_key == hooks2_key).scalar()
416 hooks2 = RhodeCodeUi() if hooks2_ is None else hooks2_
426 hooks2 = RhodeCodeUi() if hooks2_ is None else hooks2_
417 hooks2.ui_section = 'hooks'
427 hooks2.ui_section = 'hooks'
418 hooks2.ui_key = hooks2_key
428 hooks2.ui_key = hooks2_key
419 hooks2.ui_value = 'python:rhodecode.lib.hooks.repo_size'
429 hooks2.ui_value = 'python:rhodecode.lib.hooks.repo_size'
420 self.sa.add(hooks2)
430 self.sa.add(hooks2)
421
431
422 hooks3 = RhodeCodeUi()
432 hooks3 = RhodeCodeUi()
423 hooks3.ui_section = 'hooks'
433 hooks3.ui_section = 'hooks'
424 hooks3.ui_key = RhodeCodeUi.HOOK_PUSH
434 hooks3.ui_key = RhodeCodeUi.HOOK_PUSH
425 hooks3.ui_value = 'python:rhodecode.lib.hooks.log_push_action'
435 hooks3.ui_value = 'python:rhodecode.lib.hooks.log_push_action'
426 self.sa.add(hooks3)
436 self.sa.add(hooks3)
427
437
428 hooks4 = RhodeCodeUi()
438 hooks4 = RhodeCodeUi()
429 hooks4.ui_section = 'hooks'
439 hooks4.ui_section = 'hooks'
430 hooks4.ui_key = RhodeCodeUi.HOOK_PRE_PUSH
440 hooks4.ui_key = RhodeCodeUi.HOOK_PRE_PUSH
431 hooks4.ui_value = 'python:rhodecode.lib.hooks.pre_push'
441 hooks4.ui_value = 'python:rhodecode.lib.hooks.pre_push'
432 self.sa.add(hooks4)
442 self.sa.add(hooks4)
433
443
434 hooks5 = RhodeCodeUi()
444 hooks5 = RhodeCodeUi()
435 hooks5.ui_section = 'hooks'
445 hooks5.ui_section = 'hooks'
436 hooks5.ui_key = RhodeCodeUi.HOOK_PULL
446 hooks5.ui_key = RhodeCodeUi.HOOK_PULL
437 hooks5.ui_value = 'python:rhodecode.lib.hooks.log_pull_action'
447 hooks5.ui_value = 'python:rhodecode.lib.hooks.log_pull_action'
438 self.sa.add(hooks5)
448 self.sa.add(hooks5)
439
449
440 hooks6 = RhodeCodeUi()
450 hooks6 = RhodeCodeUi()
441 hooks6.ui_section = 'hooks'
451 hooks6.ui_section = 'hooks'
442 hooks6.ui_key = RhodeCodeUi.HOOK_PRE_PULL
452 hooks6.ui_key = RhodeCodeUi.HOOK_PRE_PULL
443 hooks6.ui_value = 'python:rhodecode.lib.hooks.pre_pull'
453 hooks6.ui_value = 'python:rhodecode.lib.hooks.pre_pull'
444 self.sa.add(hooks6)
454 self.sa.add(hooks6)
445
455
446 # enable largefiles
456 # enable largefiles
447 largefiles = RhodeCodeUi()
457 largefiles = RhodeCodeUi()
448 largefiles.ui_section = 'extensions'
458 largefiles.ui_section = 'extensions'
449 largefiles.ui_key = 'largefiles'
459 largefiles.ui_key = 'largefiles'
450 largefiles.ui_value = ''
460 largefiles.ui_value = ''
451 self.sa.add(largefiles)
461 self.sa.add(largefiles)
452
462
453 # enable hgsubversion disabled by default
463 # enable hgsubversion disabled by default
454 hgsubversion = RhodeCodeUi()
464 hgsubversion = RhodeCodeUi()
455 hgsubversion.ui_section = 'extensions'
465 hgsubversion.ui_section = 'extensions'
456 hgsubversion.ui_key = 'hgsubversion'
466 hgsubversion.ui_key = 'hgsubversion'
457 hgsubversion.ui_value = ''
467 hgsubversion.ui_value = ''
458 hgsubversion.ui_active = False
468 hgsubversion.ui_active = False
459 self.sa.add(hgsubversion)
469 self.sa.add(hgsubversion)
460
470
461 # enable hggit disabled by default
471 # enable hggit disabled by default
462 hggit = RhodeCodeUi()
472 hggit = RhodeCodeUi()
463 hggit.ui_section = 'extensions'
473 hggit.ui_section = 'extensions'
464 hggit.ui_key = 'hggit'
474 hggit.ui_key = 'hggit'
465 hggit.ui_value = ''
475 hggit.ui_value = ''
466 hggit.ui_active = False
476 hggit.ui_active = False
467 self.sa.add(hggit)
477 self.sa.add(hggit)
468
478
469 def create_ldap_options(self, skip_existing=False):
479 def create_ldap_options(self, skip_existing=False):
470 """Creates ldap settings"""
480 """Creates ldap settings"""
471
481
472 for k, v in [('ldap_active', 'false'), ('ldap_host', ''),
482 for k, v in [('ldap_active', 'false'), ('ldap_host', ''),
473 ('ldap_port', '389'), ('ldap_tls_kind', 'PLAIN'),
483 ('ldap_port', '389'), ('ldap_tls_kind', 'PLAIN'),
474 ('ldap_tls_reqcert', ''), ('ldap_dn_user', ''),
484 ('ldap_tls_reqcert', ''), ('ldap_dn_user', ''),
475 ('ldap_dn_pass', ''), ('ldap_base_dn', ''),
485 ('ldap_dn_pass', ''), ('ldap_base_dn', ''),
476 ('ldap_filter', ''), ('ldap_search_scope', ''),
486 ('ldap_filter', ''), ('ldap_search_scope', ''),
477 ('ldap_attr_login', ''), ('ldap_attr_firstname', ''),
487 ('ldap_attr_login', ''), ('ldap_attr_firstname', ''),
478 ('ldap_attr_lastname', ''), ('ldap_attr_email', '')]:
488 ('ldap_attr_lastname', ''), ('ldap_attr_email', '')]:
479
489
480 if skip_existing and RhodeCodeSetting.get_by_name(k) != None:
490 if skip_existing and RhodeCodeSetting.get_by_name(k) != None:
481 log.debug('Skipping option %s' % k)
491 log.debug('Skipping option %s' % k)
482 continue
492 continue
483 setting = RhodeCodeSetting(k, v)
493 setting = RhodeCodeSetting(k, v)
484 self.sa.add(setting)
494 self.sa.add(setting)
485
495
486 def create_default_options(self, skip_existing=False):
496 def create_default_options(self, skip_existing=False):
487 """Creates default settings"""
497 """Creates default settings"""
488
498
489 for k, v in [
499 for k, v in [
490 ('default_repo_enable_locking', False),
500 ('default_repo_enable_locking', False),
491 ('default_repo_enable_downloads', False),
501 ('default_repo_enable_downloads', False),
492 ('default_repo_enable_statistics', False),
502 ('default_repo_enable_statistics', False),
493 ('default_repo_private', False),
503 ('default_repo_private', False),
494 ('default_repo_type', 'hg')]:
504 ('default_repo_type', 'hg')]:
495
505
496 if skip_existing and RhodeCodeSetting.get_by_name(k) != None:
506 if skip_existing and RhodeCodeSetting.get_by_name(k) != None:
497 log.debug('Skipping option %s' % k)
507 log.debug('Skipping option %s' % k)
498 continue
508 continue
499 setting = RhodeCodeSetting(k, v)
509 setting = RhodeCodeSetting(k, v)
500 self.sa.add(setting)
510 self.sa.add(setting)
501
511
502 def fixup_groups(self):
512 def fixup_groups(self):
503 def_usr = User.get_by_username('default')
513 def_usr = User.get_by_username('default')
504 for g in RepoGroup.query().all():
514 for g in RepoGroup.query().all():
505 g.group_name = g.get_new_name(g.name)
515 g.group_name = g.get_new_name(g.name)
506 self.sa.add(g)
516 self.sa.add(g)
507 # get default perm
517 # get default perm
508 default = UserRepoGroupToPerm.query()\
518 default = UserRepoGroupToPerm.query()\
509 .filter(UserRepoGroupToPerm.group == g)\
519 .filter(UserRepoGroupToPerm.group == g)\
510 .filter(UserRepoGroupToPerm.user == def_usr)\
520 .filter(UserRepoGroupToPerm.user == def_usr)\
511 .scalar()
521 .scalar()
512
522
513 if default is None:
523 if default is None:
514 log.debug('missing default permission for group %s adding' % g)
524 log.debug('missing default permission for group %s adding' % g)
515 ReposGroupModel()._create_default_perms(g)
525 ReposGroupModel()._create_default_perms(g)
516
526
517 def reset_permissions(self, username):
527 def reset_permissions(self, username):
518 """
528 """
519 Resets permissions to default state, usefull when old systems had
529 Resets permissions to default state, usefull when old systems had
520 bad permissions, we must clean them up
530 bad permissions, we must clean them up
521
531
522 :param username:
532 :param username:
523 :type username:
533 :type username:
524 """
534 """
525 default_user = User.get_by_username(username)
535 default_user = User.get_by_username(username)
526 if not default_user:
536 if not default_user:
527 return
537 return
528
538
529 u2p = UserToPerm.query()\
539 u2p = UserToPerm.query()\
530 .filter(UserToPerm.user == default_user).all()
540 .filter(UserToPerm.user == default_user).all()
531 fixed = False
541 fixed = False
532 if len(u2p) != len(User.DEFAULT_PERMISSIONS):
542 if len(u2p) != len(User.DEFAULT_PERMISSIONS):
533 for p in u2p:
543 for p in u2p:
534 Session().delete(p)
544 Session().delete(p)
535 fixed = True
545 fixed = True
536 self.populate_default_permissions()
546 self.populate_default_permissions()
537 return fixed
547 return fixed
538
548
539 def config_prompt(self, test_repo_path='', retries=3):
549 def config_prompt(self, test_repo_path='', retries=3):
540 defaults = self.cli_args
550 defaults = self.cli_args
541 _path = defaults.get('repos_location')
551 _path = defaults.get('repos_location')
542 if retries == 3:
552 if retries == 3:
543 log.info('Setting up repositories config')
553 log.info('Setting up repositories config')
544
554
545 if _path is not None:
555 if _path is not None:
546 path = _path
556 path = _path
547 elif not self.tests and not test_repo_path:
557 elif not self.tests and not test_repo_path:
548 path = raw_input(
558 path = raw_input(
549 'Enter a valid absolute path to store repositories. '
559 'Enter a valid absolute path to store repositories. '
550 'All repositories in that path will be added automatically:'
560 'All repositories in that path will be added automatically:'
551 )
561 )
552 else:
562 else:
553 path = test_repo_path
563 path = test_repo_path
554 path_ok = True
564 path_ok = True
555
565
556 # check proper dir
566 # check proper dir
557 if not os.path.isdir(path):
567 if not os.path.isdir(path):
558 path_ok = False
568 path_ok = False
559 log.error('Given path %s is not a valid directory' % path)
569 log.error('Given path %s is not a valid directory' % path)
560
570
561 elif not os.path.isabs(path):
571 elif not os.path.isabs(path):
562 path_ok = False
572 path_ok = False
563 log.error('Given path %s is not an absolute path' % path)
573 log.error('Given path %s is not an absolute path' % path)
564
574
565 # check write access
575 # check write access
566 elif not os.access(path, os.W_OK) and path_ok:
576 elif not os.access(path, os.W_OK) and path_ok:
567 path_ok = False
577 path_ok = False
568 log.error('No write permission to given path %s' % path)
578 log.error('No write permission to given path %s' % path)
569
579
570 if retries == 0:
580 if retries == 0:
571 sys.exit('max retries reached')
581 sys.exit('max retries reached')
572 if path_ok is False:
582 if path_ok is False:
573 retries -= 1
583 retries -= 1
574 return self.config_prompt(test_repo_path, retries)
584 return self.config_prompt(test_repo_path, retries)
575
585
576 real_path = os.path.normpath(os.path.realpath(path))
586 real_path = os.path.normpath(os.path.realpath(path))
577
587
578 if real_path != os.path.normpath(path):
588 if real_path != os.path.normpath(path):
579 if not ask_ok(('Path looks like a symlink, Rhodecode will store '
589 if not ask_ok(('Path looks like a symlink, Rhodecode will store '
580 'given path as %s ? [y/n]') % (real_path)):
590 'given path as %s ? [y/n]') % (real_path)):
581 log.error('Canceled by user')
591 log.error('Canceled by user')
582 sys.exit(-1)
592 sys.exit(-1)
583
593
584 return real_path
594 return real_path
585
595
586 def create_settings(self, path):
596 def create_settings(self, path):
587
597
588 self.create_ui_settings()
598 self.create_ui_settings()
589
599
590 #HG UI OPTIONS
600 #HG UI OPTIONS
591 web1 = RhodeCodeUi()
601 web1 = RhodeCodeUi()
592 web1.ui_section = 'web'
602 web1.ui_section = 'web'
593 web1.ui_key = 'push_ssl'
603 web1.ui_key = 'push_ssl'
594 web1.ui_value = 'false'
604 web1.ui_value = 'false'
595
605
596 web2 = RhodeCodeUi()
606 web2 = RhodeCodeUi()
597 web2.ui_section = 'web'
607 web2.ui_section = 'web'
598 web2.ui_key = 'allow_archive'
608 web2.ui_key = 'allow_archive'
599 web2.ui_value = 'gz zip bz2'
609 web2.ui_value = 'gz zip bz2'
600
610
601 web3 = RhodeCodeUi()
611 web3 = RhodeCodeUi()
602 web3.ui_section = 'web'
612 web3.ui_section = 'web'
603 web3.ui_key = 'allow_push'
613 web3.ui_key = 'allow_push'
604 web3.ui_value = '*'
614 web3.ui_value = '*'
605
615
606 web4 = RhodeCodeUi()
616 web4 = RhodeCodeUi()
607 web4.ui_section = 'web'
617 web4.ui_section = 'web'
608 web4.ui_key = 'baseurl'
618 web4.ui_key = 'baseurl'
609 web4.ui_value = '/'
619 web4.ui_value = '/'
610
620
611 paths = RhodeCodeUi()
621 paths = RhodeCodeUi()
612 paths.ui_section = 'paths'
622 paths.ui_section = 'paths'
613 paths.ui_key = '/'
623 paths.ui_key = '/'
614 paths.ui_value = path
624 paths.ui_value = path
615
625
616 phases = RhodeCodeUi()
626 phases = RhodeCodeUi()
617 phases.ui_section = 'phases'
627 phases.ui_section = 'phases'
618 phases.ui_key = 'publish'
628 phases.ui_key = 'publish'
619 phases.ui_value = False
629 phases.ui_value = False
620
630
621 sett1 = RhodeCodeSetting('realm', 'RhodeCode authentication')
631 sett1 = RhodeCodeSetting('realm', 'RhodeCode authentication')
622 sett2 = RhodeCodeSetting('title', 'RhodeCode')
632 sett2 = RhodeCodeSetting('title', 'RhodeCode')
623 sett3 = RhodeCodeSetting('ga_code', '')
633 sett3 = RhodeCodeSetting('ga_code', '')
624
634
625 sett4 = RhodeCodeSetting('show_public_icon', True)
635 sett4 = RhodeCodeSetting('show_public_icon', True)
626 sett5 = RhodeCodeSetting('show_private_icon', True)
636 sett5 = RhodeCodeSetting('show_private_icon', True)
627 sett6 = RhodeCodeSetting('stylify_metatags', False)
637 sett6 = RhodeCodeSetting('stylify_metatags', False)
628
638
629 self.sa.add(web1)
639 self.sa.add(web1)
630 self.sa.add(web2)
640 self.sa.add(web2)
631 self.sa.add(web3)
641 self.sa.add(web3)
632 self.sa.add(web4)
642 self.sa.add(web4)
633 self.sa.add(paths)
643 self.sa.add(paths)
634 self.sa.add(sett1)
644 self.sa.add(sett1)
635 self.sa.add(sett2)
645 self.sa.add(sett2)
636 self.sa.add(sett3)
646 self.sa.add(sett3)
637 self.sa.add(sett4)
647 self.sa.add(sett4)
638 self.sa.add(sett5)
648 self.sa.add(sett5)
639 self.sa.add(sett6)
649 self.sa.add(sett6)
640
650
641 self.create_ldap_options()
651 self.create_ldap_options()
642 self.create_default_options()
652 self.create_default_options()
643
653
644 log.info('created ui config')
654 log.info('created ui config')
645
655
646 def create_user(self, username, password, email='', admin=False):
656 def create_user(self, username, password, email='', admin=False):
647 log.info('creating user %s' % username)
657 log.info('creating user %s' % username)
648 UserModel().create_or_update(username, password, email,
658 UserModel().create_or_update(username, password, email,
649 firstname='RhodeCode', lastname='Admin',
659 firstname='RhodeCode', lastname='Admin',
650 active=True, admin=admin)
660 active=True, admin=admin)
651
661
652 def create_default_user(self):
662 def create_default_user(self):
653 log.info('creating default user')
663 log.info('creating default user')
654 # create default user for handling default permissions.
664 # create default user for handling default permissions.
655 UserModel().create_or_update(username='default',
665 UserModel().create_or_update(username='default',
656 password=str(uuid.uuid1())[:8],
666 password=str(uuid.uuid1())[:8],
657 email='anonymous@rhodecode.org',
667 email='anonymous@rhodecode.org',
658 firstname='Anonymous', lastname='User')
668 firstname='Anonymous', lastname='User')
659
669
660 def create_permissions(self):
670 def create_permissions(self):
661 # module.(access|create|change|delete)_[name]
671 # module.(access|create|change|delete)_[name]
662 # module.(none|read|write|admin)
672 # module.(none|read|write|admin)
663
673
664 for p in Permission.PERMS:
674 for p in Permission.PERMS:
665 if not Permission.get_by_key(p[0]):
675 if not Permission.get_by_key(p[0]):
666 new_perm = Permission()
676 new_perm = Permission()
667 new_perm.permission_name = p[0]
677 new_perm.permission_name = p[0]
668 new_perm.permission_longname = p[0]
678 new_perm.permission_longname = p[0]
669 self.sa.add(new_perm)
679 self.sa.add(new_perm)
670
680
671 def populate_default_permissions(self):
681 def populate_default_permissions(self):
672 log.info('creating default user permissions')
682 log.info('creating default user permissions')
673
683
674 default_user = User.get_by_username('default')
684 default_user = User.get_by_username('default')
675
685
676 for def_perm in User.DEFAULT_PERMISSIONS:
686 for def_perm in User.DEFAULT_PERMISSIONS:
677
687
678 perm = self.sa.query(Permission)\
688 perm = self.sa.query(Permission)\
679 .filter(Permission.permission_name == def_perm)\
689 .filter(Permission.permission_name == def_perm)\
680 .scalar()
690 .scalar()
681 if not perm:
691 if not perm:
682 raise Exception(
692 raise Exception(
683 'CRITICAL: permission %s not found inside database !!'
693 'CRITICAL: permission %s not found inside database !!'
684 % def_perm
694 % def_perm
685 )
695 )
686 if not UserToPerm.query()\
696 if not UserToPerm.query()\
687 .filter(UserToPerm.permission == perm)\
697 .filter(UserToPerm.permission == perm)\
688 .filter(UserToPerm.user == default_user).scalar():
698 .filter(UserToPerm.user == default_user).scalar():
689 reg_perm = UserToPerm()
699 reg_perm = UserToPerm()
690 reg_perm.user = default_user
700 reg_perm.user = default_user
691 reg_perm.permission = perm
701 reg_perm.permission = perm
692 self.sa.add(reg_perm)
702 self.sa.add(reg_perm)
693
703
694 def finish(self):
704 def finish(self):
695 """
705 """
696 Function executed at the end of setup
706 Function executed at the end of setup
697 """
707 """
698 if not __py_version__ >= (2, 6):
708 if not __py_version__ >= (2, 6):
699 notify('Python2.5 detected, please switch '
709 notify('Python2.5 detected, please switch '
700 'egg:waitress#main -> egg:Paste#http '
710 'egg:waitress#main -> egg:Paste#http '
701 'in your .ini file')
711 'in your .ini file')
General Comments 0
You need to be logged in to leave comments. Login now