|
@@
-1,670
+1,679
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):
|
|
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.init_db()
|
|
68
|
self.init_db()
|
|
|
|
|
69
|
global ask_ok
|
|
|
|
|
70
|
|
|
|
|
|
71
|
if self.cli_args.get('force_ask') is True:
|
|
|
|
|
72
|
ask_ok = lambda *args, **kwargs: True
|
|
|
|
|
73
|
elif self.cli_args.get('force_ask') is False:
|
|
|
|
|
74
|
ask_ok = lambda *args, **kwargs: False
|
|
68
|
|
|
75
|
|
|
69
|
def init_db(self):
|
|
76
|
def init_db(self):
|
|
70
|
engine = create_engine(self.dburi, echo=self.log_sql)
|
|
77
|
engine = create_engine(self.dburi, echo=self.log_sql)
|
|
71
|
init_model(engine)
|
|
78
|
init_model(engine)
|
|
72
|
self.sa = Session()
|
|
79
|
self.sa = Session()
|
|
73
|
|
|
80
|
|
|
74
|
def create_tables(self, override=False, defaults={}):
|
|
81
|
def create_tables(self, override=False):
|
|
75
|
"""
|
|
82
|
"""
|
|
76
|
Create a auth database
|
|
83
|
Create a auth database
|
|
77
|
"""
|
|
84
|
"""
|
|
78
|
quiet = defaults.get('quiet')
|
|
85
|
|
|
79
|
log.info("Any existing database is going to be destroyed")
|
|
86
|
log.info("Any existing database is going to be destroyed")
|
|
80
|
if self.tests or quiet:
|
|
87
|
if self.tests:
|
|
81
|
destroy = True
|
|
88
|
destroy = True
|
|
82
|
else:
|
|
89
|
else:
|
|
83
|
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]')
|
|
84
|
if not destroy:
|
|
91
|
if not destroy:
|
|
85
|
sys.exit()
|
|
92
|
sys.exit('Nothing done')
|
|
86
|
if destroy:
|
|
93
|
if destroy:
|
|
87
|
Base.metadata.drop_all()
|
|
94
|
Base.metadata.drop_all()
|
|
88
|
|
|
95
|
|
|
89
|
checkfirst = not override
|
|
96
|
checkfirst = not override
|
|
90
|
Base.metadata.create_all(checkfirst=checkfirst)
|
|
97
|
Base.metadata.create_all(checkfirst=checkfirst)
|
|
91
|
log.info('Created tables for %s' % self.dbname)
|
|
98
|
log.info('Created tables for %s' % self.dbname)
|
|
92
|
|
|
99
|
|
|
93
|
def set_db_version(self):
|
|
100
|
def set_db_version(self):
|
|
94
|
ver = DbMigrateVersion()
|
|
101
|
ver = DbMigrateVersion()
|
|
95
|
ver.version = __dbversion__
|
|
102
|
ver.version = __dbversion__
|
|
96
|
ver.repository_id = 'rhodecode_db_migrations'
|
|
103
|
ver.repository_id = 'rhodecode_db_migrations'
|
|
97
|
ver.repository_path = 'versions'
|
|
104
|
ver.repository_path = 'versions'
|
|
98
|
self.sa.add(ver)
|
|
105
|
self.sa.add(ver)
|
|
99
|
log.info('db version set to: %s' % __dbversion__)
|
|
106
|
log.info('db version set to: %s' % __dbversion__)
|
|
100
|
|
|
107
|
|
|
101
|
def upgrade(self):
|
|
108
|
def upgrade(self):
|
|
102
|
"""
|
|
109
|
"""
|
|
103
|
Upgrades given database schema to given revision following
|
|
110
|
Upgrades given database schema to given revision following
|
|
104
|
all needed steps, to perform the upgrade
|
|
111
|
all needed steps, to perform the upgrade
|
|
105
|
|
|
112
|
|
|
106
|
"""
|
|
113
|
"""
|
|
107
|
|
|
114
|
|
|
108
|
from rhodecode.lib.dbmigrate.migrate.versioning import api
|
|
115
|
from rhodecode.lib.dbmigrate.migrate.versioning import api
|
|
109
|
from rhodecode.lib.dbmigrate.migrate.exceptions import \
|
|
116
|
from rhodecode.lib.dbmigrate.migrate.exceptions import \
|
|
110
|
DatabaseNotControlledError
|
|
117
|
DatabaseNotControlledError
|
|
111
|
|
|
118
|
|
|
112
|
if 'sqlite' in self.dburi:
|
|
119
|
if 'sqlite' in self.dburi:
|
|
113
|
print (
|
|
120
|
print (
|
|
114
|
'********************** WARNING **********************\n'
|
|
121
|
'********************** WARNING **********************\n'
|
|
115
|
'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'
|
|
116
|
'Earlier versions are known to fail on some migrations\n'
|
|
123
|
'Earlier versions are known to fail on some migrations\n'
|
|
117
|
'*****************************************************\n'
|
|
124
|
'*****************************************************\n'
|
|
118
|
)
|
|
125
|
)
|
|
119
|
upgrade = ask_ok('You are about to perform database upgrade, make '
|
|
126
|
upgrade = ask_ok('You are about to perform database upgrade, make '
|
|
120
|
'sure You backed up your database before. '
|
|
127
|
'sure You backed up your database before. '
|
|
121
|
'Continue ? [y/n]')
|
|
128
|
'Continue ? [y/n]')
|
|
122
|
if not upgrade:
|
|
129
|
if not upgrade:
|
|
123
|
sys.exit('Nothing done')
|
|
130
|
sys.exit('Nothing done')
|
|
124
|
|
|
131
|
|
|
125
|
repository_path = jn(dn(dn(dn(os.path.realpath(__file__)))),
|
|
132
|
repository_path = jn(dn(dn(dn(os.path.realpath(__file__)))),
|
|
126
|
'rhodecode/lib/dbmigrate')
|
|
133
|
'rhodecode/lib/dbmigrate')
|
|
127
|
db_uri = self.dburi
|
|
134
|
db_uri = self.dburi
|
|
128
|
|
|
135
|
|
|
129
|
try:
|
|
136
|
try:
|
|
130
|
curr_version = api.db_version(db_uri, repository_path)
|
|
137
|
curr_version = api.db_version(db_uri, repository_path)
|
|
131
|
msg = ('Found current database under version'
|
|
138
|
msg = ('Found current database under version'
|
|
132
|
' control with version %s' % curr_version)
|
|
139
|
' control with version %s' % curr_version)
|
|
133
|
|
|
140
|
|
|
134
|
except (RuntimeError, DatabaseNotControlledError):
|
|
141
|
except (RuntimeError, DatabaseNotControlledError):
|
|
135
|
curr_version = 1
|
|
142
|
curr_version = 1
|
|
136
|
msg = ('Current database is not under version control. Setting'
|
|
143
|
msg = ('Current database is not under version control. Setting'
|
|
137
|
' as version %s' % curr_version)
|
|
144
|
' as version %s' % curr_version)
|
|
138
|
api.version_control(db_uri, repository_path, curr_version)
|
|
145
|
api.version_control(db_uri, repository_path, curr_version)
|
|
139
|
|
|
146
|
|
|
140
|
notify(msg)
|
|
147
|
notify(msg)
|
|
141
|
|
|
148
|
|
|
142
|
if curr_version == __dbversion__:
|
|
149
|
if curr_version == __dbversion__:
|
|
143
|
sys.exit('This database is already at the newest version')
|
|
150
|
sys.exit('This database is already at the newest version')
|
|
144
|
|
|
151
|
|
|
145
|
#======================================================================
|
|
152
|
#======================================================================
|
|
146
|
# UPGRADE STEPS
|
|
153
|
# UPGRADE STEPS
|
|
147
|
#======================================================================
|
|
154
|
#======================================================================
|
|
148
|
|
|
155
|
|
|
149
|
class UpgradeSteps(object):
|
|
156
|
class UpgradeSteps(object):
|
|
150
|
"""
|
|
157
|
"""
|
|
151
|
Those steps follow schema versions so for example schema
|
|
158
|
Those steps follow schema versions so for example schema
|
|
152
|
for example schema with seq 002 == step_2 and so on.
|
|
159
|
for example schema with seq 002 == step_2 and so on.
|
|
153
|
"""
|
|
160
|
"""
|
|
154
|
|
|
161
|
|
|
155
|
def __init__(self, klass):
|
|
162
|
def __init__(self, klass):
|
|
156
|
self.klass = klass
|
|
163
|
self.klass = klass
|
|
157
|
|
|
164
|
|
|
158
|
def step_0(self):
|
|
165
|
def step_0(self):
|
|
159
|
# step 0 is the schema upgrade, and than follow proper upgrades
|
|
166
|
# step 0 is the schema upgrade, and than follow proper upgrades
|
|
160
|
notify('attempting to do database upgrade to version %s' \
|
|
167
|
notify('attempting to do database upgrade to version %s' \
|
|
161
|
% __dbversion__)
|
|
168
|
% __dbversion__)
|
|
162
|
api.upgrade(db_uri, repository_path, __dbversion__)
|
|
169
|
api.upgrade(db_uri, repository_path, __dbversion__)
|
|
163
|
notify('Schema upgrade completed')
|
|
170
|
notify('Schema upgrade completed')
|
|
164
|
|
|
171
|
|
|
165
|
def step_1(self):
|
|
172
|
def step_1(self):
|
|
166
|
pass
|
|
173
|
pass
|
|
167
|
|
|
174
|
|
|
168
|
def step_2(self):
|
|
175
|
def step_2(self):
|
|
169
|
notify('Patching repo paths for newer version of RhodeCode')
|
|
176
|
notify('Patching repo paths for newer version of RhodeCode')
|
|
170
|
self.klass.fix_repo_paths()
|
|
177
|
self.klass.fix_repo_paths()
|
|
171
|
|
|
178
|
|
|
172
|
notify('Patching default user of RhodeCode')
|
|
179
|
notify('Patching default user of RhodeCode')
|
|
173
|
self.klass.fix_default_user()
|
|
180
|
self.klass.fix_default_user()
|
|
174
|
|
|
181
|
|
|
175
|
log.info('Changing ui settings')
|
|
182
|
log.info('Changing ui settings')
|
|
176
|
self.klass.create_ui_settings()
|
|
183
|
self.klass.create_ui_settings()
|
|
177
|
|
|
184
|
|
|
178
|
def step_3(self):
|
|
185
|
def step_3(self):
|
|
179
|
notify('Adding additional settings into RhodeCode db')
|
|
186
|
notify('Adding additional settings into RhodeCode db')
|
|
180
|
self.klass.fix_settings()
|
|
187
|
self.klass.fix_settings()
|
|
181
|
notify('Adding ldap defaults')
|
|
188
|
notify('Adding ldap defaults')
|
|
182
|
self.klass.create_ldap_options(skip_existing=True)
|
|
189
|
self.klass.create_ldap_options(skip_existing=True)
|
|
183
|
|
|
190
|
|
|
184
|
def step_4(self):
|
|
191
|
def step_4(self):
|
|
185
|
notify('create permissions and fix groups')
|
|
192
|
notify('create permissions and fix groups')
|
|
186
|
self.klass.create_permissions()
|
|
193
|
self.klass.create_permissions()
|
|
187
|
self.klass.fixup_groups()
|
|
194
|
self.klass.fixup_groups()
|
|
188
|
|
|
195
|
|
|
189
|
def step_5(self):
|
|
196
|
def step_5(self):
|
|
190
|
pass
|
|
197
|
pass
|
|
191
|
|
|
198
|
|
|
192
|
def step_6(self):
|
|
199
|
def step_6(self):
|
|
193
|
|
|
200
|
|
|
194
|
notify('re-checking permissions')
|
|
201
|
notify('re-checking permissions')
|
|
195
|
self.klass.create_permissions()
|
|
202
|
self.klass.create_permissions()
|
|
196
|
|
|
203
|
|
|
197
|
notify('installing new UI options')
|
|
204
|
notify('installing new UI options')
|
|
198
|
sett4 = RhodeCodeSetting('show_public_icon', True)
|
|
205
|
sett4 = RhodeCodeSetting('show_public_icon', True)
|
|
199
|
Session().add(sett4)
|
|
206
|
Session().add(sett4)
|
|
200
|
sett5 = RhodeCodeSetting('show_private_icon', True)
|
|
207
|
sett5 = RhodeCodeSetting('show_private_icon', True)
|
|
201
|
Session().add(sett5)
|
|
208
|
Session().add(sett5)
|
|
202
|
sett6 = RhodeCodeSetting('stylify_metatags', False)
|
|
209
|
sett6 = RhodeCodeSetting('stylify_metatags', False)
|
|
203
|
Session().add(sett6)
|
|
210
|
Session().add(sett6)
|
|
204
|
|
|
211
|
|
|
205
|
notify('fixing old PULL hook')
|
|
212
|
notify('fixing old PULL hook')
|
|
206
|
_pull = RhodeCodeUi.get_by_key('preoutgoing.pull_logger')
|
|
213
|
_pull = RhodeCodeUi.get_by_key('preoutgoing.pull_logger')
|
|
207
|
if _pull:
|
|
214
|
if _pull:
|
|
208
|
_pull.ui_key = RhodeCodeUi.HOOK_PULL
|
|
215
|
_pull.ui_key = RhodeCodeUi.HOOK_PULL
|
|
209
|
Session().add(_pull)
|
|
216
|
Session().add(_pull)
|
|
210
|
|
|
217
|
|
|
211
|
notify('fixing old PUSH hook')
|
|
218
|
notify('fixing old PUSH hook')
|
|
212
|
_push = RhodeCodeUi.get_by_key('pretxnchangegroup.push_logger')
|
|
219
|
_push = RhodeCodeUi.get_by_key('pretxnchangegroup.push_logger')
|
|
213
|
if _push:
|
|
220
|
if _push:
|
|
214
|
_push.ui_key = RhodeCodeUi.HOOK_PUSH
|
|
221
|
_push.ui_key = RhodeCodeUi.HOOK_PUSH
|
|
215
|
Session().add(_push)
|
|
222
|
Session().add(_push)
|
|
216
|
|
|
223
|
|
|
217
|
notify('installing new pre-push hook')
|
|
224
|
notify('installing new pre-push hook')
|
|
218
|
hooks4 = RhodeCodeUi()
|
|
225
|
hooks4 = RhodeCodeUi()
|
|
219
|
hooks4.ui_section = 'hooks'
|
|
226
|
hooks4.ui_section = 'hooks'
|
|
220
|
hooks4.ui_key = RhodeCodeUi.HOOK_PRE_PUSH
|
|
227
|
hooks4.ui_key = RhodeCodeUi.HOOK_PRE_PUSH
|
|
221
|
hooks4.ui_value = 'python:rhodecode.lib.hooks.pre_push'
|
|
228
|
hooks4.ui_value = 'python:rhodecode.lib.hooks.pre_push'
|
|
222
|
Session().add(hooks4)
|
|
229
|
Session().add(hooks4)
|
|
223
|
|
|
230
|
|
|
224
|
notify('installing new pre-pull hook')
|
|
231
|
notify('installing new pre-pull hook')
|
|
225
|
hooks6 = RhodeCodeUi()
|
|
232
|
hooks6 = RhodeCodeUi()
|
|
226
|
hooks6.ui_section = 'hooks'
|
|
233
|
hooks6.ui_section = 'hooks'
|
|
227
|
hooks6.ui_key = RhodeCodeUi.HOOK_PRE_PULL
|
|
234
|
hooks6.ui_key = RhodeCodeUi.HOOK_PRE_PULL
|
|
228
|
hooks6.ui_value = 'python:rhodecode.lib.hooks.pre_pull'
|
|
235
|
hooks6.ui_value = 'python:rhodecode.lib.hooks.pre_pull'
|
|
229
|
Session().add(hooks6)
|
|
236
|
Session().add(hooks6)
|
|
230
|
|
|
237
|
|
|
231
|
notify('installing hgsubversion option')
|
|
238
|
notify('installing hgsubversion option')
|
|
232
|
# enable hgsubversion disabled by default
|
|
239
|
# enable hgsubversion disabled by default
|
|
233
|
hgsubversion = RhodeCodeUi()
|
|
240
|
hgsubversion = RhodeCodeUi()
|
|
234
|
hgsubversion.ui_section = 'extensions'
|
|
241
|
hgsubversion.ui_section = 'extensions'
|
|
235
|
hgsubversion.ui_key = 'hgsubversion'
|
|
242
|
hgsubversion.ui_key = 'hgsubversion'
|
|
236
|
hgsubversion.ui_value = ''
|
|
243
|
hgsubversion.ui_value = ''
|
|
237
|
hgsubversion.ui_active = False
|
|
244
|
hgsubversion.ui_active = False
|
|
238
|
Session().add(hgsubversion)
|
|
245
|
Session().add(hgsubversion)
|
|
239
|
|
|
246
|
|
|
240
|
notify('installing hg git option')
|
|
247
|
notify('installing hg git option')
|
|
241
|
# enable hggit disabled by default
|
|
248
|
# enable hggit disabled by default
|
|
242
|
hggit = RhodeCodeUi()
|
|
249
|
hggit = RhodeCodeUi()
|
|
243
|
hggit.ui_section = 'extensions'
|
|
250
|
hggit.ui_section = 'extensions'
|
|
244
|
hggit.ui_key = 'hggit'
|
|
251
|
hggit.ui_key = 'hggit'
|
|
245
|
hggit.ui_value = ''
|
|
252
|
hggit.ui_value = ''
|
|
246
|
hggit.ui_active = False
|
|
253
|
hggit.ui_active = False
|
|
247
|
Session().add(hggit)
|
|
254
|
Session().add(hggit)
|
|
248
|
|
|
255
|
|
|
249
|
notify('re-check default permissions')
|
|
256
|
notify('re-check default permissions')
|
|
250
|
default_user = User.get_by_username(User.DEFAULT_USER)
|
|
257
|
default_user = User.get_by_username(User.DEFAULT_USER)
|
|
251
|
perm = Permission.get_by_key('hg.fork.repository')
|
|
258
|
perm = Permission.get_by_key('hg.fork.repository')
|
|
252
|
reg_perm = UserToPerm()
|
|
259
|
reg_perm = UserToPerm()
|
|
253
|
reg_perm.user = default_user
|
|
260
|
reg_perm.user = default_user
|
|
254
|
reg_perm.permission = perm
|
|
261
|
reg_perm.permission = perm
|
|
255
|
Session().add(reg_perm)
|
|
262
|
Session().add(reg_perm)
|
|
256
|
|
|
263
|
|
|
257
|
def step_7(self):
|
|
264
|
def step_7(self):
|
|
258
|
perm_fixes = self.klass.reset_permissions(User.DEFAULT_USER)
|
|
265
|
perm_fixes = self.klass.reset_permissions(User.DEFAULT_USER)
|
|
259
|
Session().commit()
|
|
266
|
Session().commit()
|
|
260
|
if perm_fixes:
|
|
267
|
if perm_fixes:
|
|
261
|
notify('There was an inconsistent state of permissions '
|
|
268
|
notify('There was an inconsistent state of permissions '
|
|
262
|
'detected for default user. Permissions are now '
|
|
269
|
'detected for default user. Permissions are now '
|
|
263
|
'reset to the default value for default user. '
|
|
270
|
'reset to the default value for default user. '
|
|
264
|
'Please validate and check default permissions '
|
|
271
|
'Please validate and check default permissions '
|
|
265
|
'in admin panel')
|
|
272
|
'in admin panel')
|
|
266
|
|
|
273
|
|
|
267
|
upgrade_steps = [0] + range(curr_version + 1, __dbversion__ + 1)
|
|
274
|
upgrade_steps = [0] + range(curr_version + 1, __dbversion__ + 1)
|
|
268
|
|
|
275
|
|
|
269
|
# CALL THE PROPER ORDER OF STEPS TO PERFORM FULL UPGRADE
|
|
276
|
# CALL THE PROPER ORDER OF STEPS TO PERFORM FULL UPGRADE
|
|
270
|
_step = None
|
|
277
|
_step = None
|
|
271
|
for step in upgrade_steps:
|
|
278
|
for step in upgrade_steps:
|
|
272
|
notify('performing upgrade step %s' % step)
|
|
279
|
notify('performing upgrade step %s' % step)
|
|
273
|
getattr(UpgradeSteps(self), 'step_%s' % step)()
|
|
280
|
getattr(UpgradeSteps(self), 'step_%s' % step)()
|
|
274
|
self.sa.commit()
|
|
281
|
self.sa.commit()
|
|
275
|
_step = step
|
|
282
|
_step = step
|
|
276
|
|
|
283
|
|
|
277
|
notify('upgrade to version %s successful' % _step)
|
|
284
|
notify('upgrade to version %s successful' % _step)
|
|
278
|
|
|
285
|
|
|
279
|
def fix_repo_paths(self):
|
|
286
|
def fix_repo_paths(self):
|
|
280
|
"""
|
|
287
|
"""
|
|
281
|
Fixes a old rhodecode version path into new one without a '*'
|
|
288
|
Fixes a old rhodecode version path into new one without a '*'
|
|
282
|
"""
|
|
289
|
"""
|
|
283
|
|
|
290
|
|
|
284
|
paths = self.sa.query(RhodeCodeUi)\
|
|
291
|
paths = self.sa.query(RhodeCodeUi)\
|
|
285
|
.filter(RhodeCodeUi.ui_key == '/')\
|
|
292
|
.filter(RhodeCodeUi.ui_key == '/')\
|
|
286
|
.scalar()
|
|
293
|
.scalar()
|
|
287
|
|
|
294
|
|
|
288
|
paths.ui_value = paths.ui_value.replace('*', '')
|
|
295
|
paths.ui_value = paths.ui_value.replace('*', '')
|
|
289
|
|
|
296
|
|
|
290
|
try:
|
|
297
|
try:
|
|
291
|
self.sa.add(paths)
|
|
298
|
self.sa.add(paths)
|
|
292
|
self.sa.commit()
|
|
299
|
self.sa.commit()
|
|
293
|
except:
|
|
300
|
except:
|
|
294
|
self.sa.rollback()
|
|
301
|
self.sa.rollback()
|
|
295
|
raise
|
|
302
|
raise
|
|
296
|
|
|
303
|
|
|
297
|
def fix_default_user(self):
|
|
304
|
def fix_default_user(self):
|
|
298
|
"""
|
|
305
|
"""
|
|
299
|
Fixes a old default user with some 'nicer' default values,
|
|
306
|
Fixes a old default user with some 'nicer' default values,
|
|
300
|
used mostly for anonymous access
|
|
307
|
used mostly for anonymous access
|
|
301
|
"""
|
|
308
|
"""
|
|
302
|
def_user = self.sa.query(User)\
|
|
309
|
def_user = self.sa.query(User)\
|
|
303
|
.filter(User.username == 'default')\
|
|
310
|
.filter(User.username == 'default')\
|
|
304
|
.one()
|
|
311
|
.one()
|
|
305
|
|
|
312
|
|
|
306
|
def_user.name = 'Anonymous'
|
|
313
|
def_user.name = 'Anonymous'
|
|
307
|
def_user.lastname = 'User'
|
|
314
|
def_user.lastname = 'User'
|
|
308
|
def_user.email = 'anonymous@rhodecode.org'
|
|
315
|
def_user.email = 'anonymous@rhodecode.org'
|
|
309
|
|
|
316
|
|
|
310
|
try:
|
|
317
|
try:
|
|
311
|
self.sa.add(def_user)
|
|
318
|
self.sa.add(def_user)
|
|
312
|
self.sa.commit()
|
|
319
|
self.sa.commit()
|
|
313
|
except:
|
|
320
|
except:
|
|
314
|
self.sa.rollback()
|
|
321
|
self.sa.rollback()
|
|
315
|
raise
|
|
322
|
raise
|
|
316
|
|
|
323
|
|
|
317
|
def fix_settings(self):
|
|
324
|
def fix_settings(self):
|
|
318
|
"""
|
|
325
|
"""
|
|
319
|
Fixes rhodecode settings adds ga_code key for google analytics
|
|
326
|
Fixes rhodecode settings adds ga_code key for google analytics
|
|
320
|
"""
|
|
327
|
"""
|
|
321
|
|
|
328
|
|
|
322
|
hgsettings3 = RhodeCodeSetting('ga_code', '')
|
|
329
|
hgsettings3 = RhodeCodeSetting('ga_code', '')
|
|
323
|
|
|
330
|
|
|
324
|
try:
|
|
331
|
try:
|
|
325
|
self.sa.add(hgsettings3)
|
|
332
|
self.sa.add(hgsettings3)
|
|
326
|
self.sa.commit()
|
|
333
|
self.sa.commit()
|
|
327
|
except:
|
|
334
|
except:
|
|
328
|
self.sa.rollback()
|
|
335
|
self.sa.rollback()
|
|
329
|
raise
|
|
336
|
raise
|
|
330
|
|
|
337
|
|
|
331
|
def admin_prompt(self, second=False, defaults={}):
|
|
338
|
def admin_prompt(self, second=False):
|
|
332
|
if not self.tests:
|
|
339
|
if not self.tests:
|
|
333
|
import getpass
|
|
340
|
import getpass
|
|
334
|
|
|
341
|
|
|
335
|
# defaults
|
|
342
|
# defaults
|
|
|
|
|
343
|
defaults = self.cli_args
|
|
336
|
username = defaults.get('username')
|
|
344
|
username = defaults.get('username')
|
|
337
|
password = defaults.get('password')
|
|
345
|
password = defaults.get('password')
|
|
338
|
email = defaults.get('email')
|
|
346
|
email = defaults.get('email')
|
|
339
|
|
|
347
|
|
|
340
|
def get_password():
|
|
348
|
def get_password():
|
|
341
|
password = getpass.getpass('Specify admin password '
|
|
349
|
password = getpass.getpass('Specify admin password '
|
|
342
|
'(min 6 chars):')
|
|
350
|
'(min 6 chars):')
|
|
343
|
confirm = getpass.getpass('Confirm password:')
|
|
351
|
confirm = getpass.getpass('Confirm password:')
|
|
344
|
|
|
352
|
|
|
345
|
if password != confirm:
|
|
353
|
if password != confirm:
|
|
346
|
log.error('passwords mismatch')
|
|
354
|
log.error('passwords mismatch')
|
|
347
|
return False
|
|
355
|
return False
|
|
348
|
if len(password) < 6:
|
|
356
|
if len(password) < 6:
|
|
349
|
log.error('password is to short use at least 6 characters')
|
|
357
|
log.error('password is to short use at least 6 characters')
|
|
350
|
return False
|
|
358
|
return False
|
|
351
|
|
|
359
|
|
|
352
|
return password
|
|
360
|
return password
|
|
353
|
if username is None:
|
|
361
|
if username is None:
|
|
354
|
username = raw_input('Specify admin username:')
|
|
362
|
username = raw_input('Specify admin username:')
|
|
355
|
if password is None:
|
|
363
|
if password is None:
|
|
356
|
password = get_password()
|
|
364
|
password = get_password()
|
|
357
|
if not password:
|
|
365
|
if not password:
|
|
358
|
#second try
|
|
366
|
#second try
|
|
359
|
password = get_password()
|
|
367
|
password = get_password()
|
|
360
|
if not password:
|
|
368
|
if not password:
|
|
361
|
sys.exit()
|
|
369
|
sys.exit()
|
|
362
|
if email is None:
|
|
370
|
if email is None:
|
|
363
|
email = raw_input('Specify admin email:')
|
|
371
|
email = raw_input('Specify admin email:')
|
|
364
|
self.create_user(username, password, email, True)
|
|
372
|
self.create_user(username, password, email, True)
|
|
365
|
else:
|
|
373
|
else:
|
|
366
|
log.info('creating admin and regular test users')
|
|
374
|
log.info('creating admin and regular test users')
|
|
367
|
from rhodecode.tests import TEST_USER_ADMIN_LOGIN, \
|
|
375
|
from rhodecode.tests import TEST_USER_ADMIN_LOGIN, \
|
|
368
|
TEST_USER_ADMIN_PASS, TEST_USER_ADMIN_EMAIL, \
|
|
376
|
TEST_USER_ADMIN_PASS, TEST_USER_ADMIN_EMAIL, \
|
|
369
|
TEST_USER_REGULAR_LOGIN, TEST_USER_REGULAR_PASS, \
|
|
377
|
TEST_USER_REGULAR_LOGIN, TEST_USER_REGULAR_PASS, \
|
|
370
|
TEST_USER_REGULAR_EMAIL, TEST_USER_REGULAR2_LOGIN, \
|
|
378
|
TEST_USER_REGULAR_EMAIL, TEST_USER_REGULAR2_LOGIN, \
|
|
371
|
TEST_USER_REGULAR2_PASS, TEST_USER_REGULAR2_EMAIL
|
|
379
|
TEST_USER_REGULAR2_PASS, TEST_USER_REGULAR2_EMAIL
|
|
372
|
|
|
380
|
|
|
373
|
self.create_user(TEST_USER_ADMIN_LOGIN, TEST_USER_ADMIN_PASS,
|
|
381
|
self.create_user(TEST_USER_ADMIN_LOGIN, TEST_USER_ADMIN_PASS,
|
|
374
|
TEST_USER_ADMIN_EMAIL, True)
|
|
382
|
TEST_USER_ADMIN_EMAIL, True)
|
|
375
|
|
|
383
|
|
|
376
|
self.create_user(TEST_USER_REGULAR_LOGIN, TEST_USER_REGULAR_PASS,
|
|
384
|
self.create_user(TEST_USER_REGULAR_LOGIN, TEST_USER_REGULAR_PASS,
|
|
377
|
TEST_USER_REGULAR_EMAIL, False)
|
|
385
|
TEST_USER_REGULAR_EMAIL, False)
|
|
378
|
|
|
386
|
|
|
379
|
self.create_user(TEST_USER_REGULAR2_LOGIN, TEST_USER_REGULAR2_PASS,
|
|
387
|
self.create_user(TEST_USER_REGULAR2_LOGIN, TEST_USER_REGULAR2_PASS,
|
|
380
|
TEST_USER_REGULAR2_EMAIL, False)
|
|
388
|
TEST_USER_REGULAR2_EMAIL, False)
|
|
381
|
|
|
389
|
|
|
382
|
def create_ui_settings(self):
|
|
390
|
def create_ui_settings(self):
|
|
383
|
"""
|
|
391
|
"""
|
|
384
|
Creates ui settings, fills out hooks
|
|
392
|
Creates ui settings, fills out hooks
|
|
385
|
and disables dotencode
|
|
393
|
and disables dotencode
|
|
386
|
"""
|
|
394
|
"""
|
|
387
|
|
|
395
|
|
|
388
|
#HOOKS
|
|
396
|
#HOOKS
|
|
389
|
hooks1_key = RhodeCodeUi.HOOK_UPDATE
|
|
397
|
hooks1_key = RhodeCodeUi.HOOK_UPDATE
|
|
390
|
hooks1_ = self.sa.query(RhodeCodeUi)\
|
|
398
|
hooks1_ = self.sa.query(RhodeCodeUi)\
|
|
391
|
.filter(RhodeCodeUi.ui_key == hooks1_key).scalar()
|
|
399
|
.filter(RhodeCodeUi.ui_key == hooks1_key).scalar()
|
|
392
|
|
|
400
|
|
|
393
|
hooks1 = RhodeCodeUi() if hooks1_ is None else hooks1_
|
|
401
|
hooks1 = RhodeCodeUi() if hooks1_ is None else hooks1_
|
|
394
|
hooks1.ui_section = 'hooks'
|
|
402
|
hooks1.ui_section = 'hooks'
|
|
395
|
hooks1.ui_key = hooks1_key
|
|
403
|
hooks1.ui_key = hooks1_key
|
|
396
|
hooks1.ui_value = 'hg update >&2'
|
|
404
|
hooks1.ui_value = 'hg update >&2'
|
|
397
|
hooks1.ui_active = False
|
|
405
|
hooks1.ui_active = False
|
|
398
|
self.sa.add(hooks1)
|
|
406
|
self.sa.add(hooks1)
|
|
399
|
|
|
407
|
|
|
400
|
hooks2_key = RhodeCodeUi.HOOK_REPO_SIZE
|
|
408
|
hooks2_key = RhodeCodeUi.HOOK_REPO_SIZE
|
|
401
|
hooks2_ = self.sa.query(RhodeCodeUi)\
|
|
409
|
hooks2_ = self.sa.query(RhodeCodeUi)\
|
|
402
|
.filter(RhodeCodeUi.ui_key == hooks2_key).scalar()
|
|
410
|
.filter(RhodeCodeUi.ui_key == hooks2_key).scalar()
|
|
403
|
hooks2 = RhodeCodeUi() if hooks2_ is None else hooks2_
|
|
411
|
hooks2 = RhodeCodeUi() if hooks2_ is None else hooks2_
|
|
404
|
hooks2.ui_section = 'hooks'
|
|
412
|
hooks2.ui_section = 'hooks'
|
|
405
|
hooks2.ui_key = hooks2_key
|
|
413
|
hooks2.ui_key = hooks2_key
|
|
406
|
hooks2.ui_value = 'python:rhodecode.lib.hooks.repo_size'
|
|
414
|
hooks2.ui_value = 'python:rhodecode.lib.hooks.repo_size'
|
|
407
|
self.sa.add(hooks2)
|
|
415
|
self.sa.add(hooks2)
|
|
408
|
|
|
416
|
|
|
409
|
hooks3 = RhodeCodeUi()
|
|
417
|
hooks3 = RhodeCodeUi()
|
|
410
|
hooks3.ui_section = 'hooks'
|
|
418
|
hooks3.ui_section = 'hooks'
|
|
411
|
hooks3.ui_key = RhodeCodeUi.HOOK_PUSH
|
|
419
|
hooks3.ui_key = RhodeCodeUi.HOOK_PUSH
|
|
412
|
hooks3.ui_value = 'python:rhodecode.lib.hooks.log_push_action'
|
|
420
|
hooks3.ui_value = 'python:rhodecode.lib.hooks.log_push_action'
|
|
413
|
self.sa.add(hooks3)
|
|
421
|
self.sa.add(hooks3)
|
|
414
|
|
|
422
|
|
|
415
|
hooks4 = RhodeCodeUi()
|
|
423
|
hooks4 = RhodeCodeUi()
|
|
416
|
hooks4.ui_section = 'hooks'
|
|
424
|
hooks4.ui_section = 'hooks'
|
|
417
|
hooks4.ui_key = RhodeCodeUi.HOOK_PRE_PUSH
|
|
425
|
hooks4.ui_key = RhodeCodeUi.HOOK_PRE_PUSH
|
|
418
|
hooks4.ui_value = 'python:rhodecode.lib.hooks.pre_push'
|
|
426
|
hooks4.ui_value = 'python:rhodecode.lib.hooks.pre_push'
|
|
419
|
self.sa.add(hooks4)
|
|
427
|
self.sa.add(hooks4)
|
|
420
|
|
|
428
|
|
|
421
|
hooks5 = RhodeCodeUi()
|
|
429
|
hooks5 = RhodeCodeUi()
|
|
422
|
hooks5.ui_section = 'hooks'
|
|
430
|
hooks5.ui_section = 'hooks'
|
|
423
|
hooks5.ui_key = RhodeCodeUi.HOOK_PULL
|
|
431
|
hooks5.ui_key = RhodeCodeUi.HOOK_PULL
|
|
424
|
hooks5.ui_value = 'python:rhodecode.lib.hooks.log_pull_action'
|
|
432
|
hooks5.ui_value = 'python:rhodecode.lib.hooks.log_pull_action'
|
|
425
|
self.sa.add(hooks5)
|
|
433
|
self.sa.add(hooks5)
|
|
426
|
|
|
434
|
|
|
427
|
hooks6 = RhodeCodeUi()
|
|
435
|
hooks6 = RhodeCodeUi()
|
|
428
|
hooks6.ui_section = 'hooks'
|
|
436
|
hooks6.ui_section = 'hooks'
|
|
429
|
hooks6.ui_key = RhodeCodeUi.HOOK_PRE_PULL
|
|
437
|
hooks6.ui_key = RhodeCodeUi.HOOK_PRE_PULL
|
|
430
|
hooks6.ui_value = 'python:rhodecode.lib.hooks.pre_pull'
|
|
438
|
hooks6.ui_value = 'python:rhodecode.lib.hooks.pre_pull'
|
|
431
|
self.sa.add(hooks6)
|
|
439
|
self.sa.add(hooks6)
|
|
432
|
|
|
440
|
|
|
433
|
# enable largefiles
|
|
441
|
# enable largefiles
|
|
434
|
largefiles = RhodeCodeUi()
|
|
442
|
largefiles = RhodeCodeUi()
|
|
435
|
largefiles.ui_section = 'extensions'
|
|
443
|
largefiles.ui_section = 'extensions'
|
|
436
|
largefiles.ui_key = 'largefiles'
|
|
444
|
largefiles.ui_key = 'largefiles'
|
|
437
|
largefiles.ui_value = ''
|
|
445
|
largefiles.ui_value = ''
|
|
438
|
self.sa.add(largefiles)
|
|
446
|
self.sa.add(largefiles)
|
|
439
|
|
|
447
|
|
|
440
|
# enable hgsubversion disabled by default
|
|
448
|
# enable hgsubversion disabled by default
|
|
441
|
hgsubversion = RhodeCodeUi()
|
|
449
|
hgsubversion = RhodeCodeUi()
|
|
442
|
hgsubversion.ui_section = 'extensions'
|
|
450
|
hgsubversion.ui_section = 'extensions'
|
|
443
|
hgsubversion.ui_key = 'hgsubversion'
|
|
451
|
hgsubversion.ui_key = 'hgsubversion'
|
|
444
|
hgsubversion.ui_value = ''
|
|
452
|
hgsubversion.ui_value = ''
|
|
445
|
hgsubversion.ui_active = False
|
|
453
|
hgsubversion.ui_active = False
|
|
446
|
self.sa.add(hgsubversion)
|
|
454
|
self.sa.add(hgsubversion)
|
|
447
|
|
|
455
|
|
|
448
|
# enable hggit disabled by default
|
|
456
|
# enable hggit disabled by default
|
|
449
|
hggit = RhodeCodeUi()
|
|
457
|
hggit = RhodeCodeUi()
|
|
450
|
hggit.ui_section = 'extensions'
|
|
458
|
hggit.ui_section = 'extensions'
|
|
451
|
hggit.ui_key = 'hggit'
|
|
459
|
hggit.ui_key = 'hggit'
|
|
452
|
hggit.ui_value = ''
|
|
460
|
hggit.ui_value = ''
|
|
453
|
hggit.ui_active = False
|
|
461
|
hggit.ui_active = False
|
|
454
|
self.sa.add(hggit)
|
|
462
|
self.sa.add(hggit)
|
|
455
|
|
|
463
|
|
|
456
|
def create_ldap_options(self, skip_existing=False):
|
|
464
|
def create_ldap_options(self, skip_existing=False):
|
|
457
|
"""Creates ldap settings"""
|
|
465
|
"""Creates ldap settings"""
|
|
458
|
|
|
466
|
|
|
459
|
for k, v in [('ldap_active', 'false'), ('ldap_host', ''),
|
|
467
|
for k, v in [('ldap_active', 'false'), ('ldap_host', ''),
|
|
460
|
('ldap_port', '389'), ('ldap_tls_kind', 'PLAIN'),
|
|
468
|
('ldap_port', '389'), ('ldap_tls_kind', 'PLAIN'),
|
|
461
|
('ldap_tls_reqcert', ''), ('ldap_dn_user', ''),
|
|
469
|
('ldap_tls_reqcert', ''), ('ldap_dn_user', ''),
|
|
462
|
('ldap_dn_pass', ''), ('ldap_base_dn', ''),
|
|
470
|
('ldap_dn_pass', ''), ('ldap_base_dn', ''),
|
|
463
|
('ldap_filter', ''), ('ldap_search_scope', ''),
|
|
471
|
('ldap_filter', ''), ('ldap_search_scope', ''),
|
|
464
|
('ldap_attr_login', ''), ('ldap_attr_firstname', ''),
|
|
472
|
('ldap_attr_login', ''), ('ldap_attr_firstname', ''),
|
|
465
|
('ldap_attr_lastname', ''), ('ldap_attr_email', '')]:
|
|
473
|
('ldap_attr_lastname', ''), ('ldap_attr_email', '')]:
|
|
466
|
|
|
474
|
|
|
467
|
if skip_existing and RhodeCodeSetting.get_by_name(k) != None:
|
|
475
|
if skip_existing and RhodeCodeSetting.get_by_name(k) != None:
|
|
468
|
log.debug('Skipping option %s' % k)
|
|
476
|
log.debug('Skipping option %s' % k)
|
|
469
|
continue
|
|
477
|
continue
|
|
470
|
setting = RhodeCodeSetting(k, v)
|
|
478
|
setting = RhodeCodeSetting(k, v)
|
|
471
|
self.sa.add(setting)
|
|
479
|
self.sa.add(setting)
|
|
472
|
|
|
480
|
|
|
473
|
def fixup_groups(self):
|
|
481
|
def fixup_groups(self):
|
|
474
|
def_usr = User.get_by_username('default')
|
|
482
|
def_usr = User.get_by_username('default')
|
|
475
|
for g in RepoGroup.query().all():
|
|
483
|
for g in RepoGroup.query().all():
|
|
476
|
g.group_name = g.get_new_name(g.name)
|
|
484
|
g.group_name = g.get_new_name(g.name)
|
|
477
|
self.sa.add(g)
|
|
485
|
self.sa.add(g)
|
|
478
|
# get default perm
|
|
486
|
# get default perm
|
|
479
|
default = UserRepoGroupToPerm.query()\
|
|
487
|
default = UserRepoGroupToPerm.query()\
|
|
480
|
.filter(UserRepoGroupToPerm.group == g)\
|
|
488
|
.filter(UserRepoGroupToPerm.group == g)\
|
|
481
|
.filter(UserRepoGroupToPerm.user == def_usr)\
|
|
489
|
.filter(UserRepoGroupToPerm.user == def_usr)\
|
|
482
|
.scalar()
|
|
490
|
.scalar()
|
|
483
|
|
|
491
|
|
|
484
|
if default is None:
|
|
492
|
if default is None:
|
|
485
|
log.debug('missing default permission for group %s adding' % g)
|
|
493
|
log.debug('missing default permission for group %s adding' % g)
|
|
486
|
ReposGroupModel()._create_default_perms(g)
|
|
494
|
ReposGroupModel()._create_default_perms(g)
|
|
487
|
|
|
495
|
|
|
488
|
def reset_permissions(self, username):
|
|
496
|
def reset_permissions(self, username):
|
|
489
|
"""
|
|
497
|
"""
|
|
490
|
Resets permissions to default state, usefull when old systems had
|
|
498
|
Resets permissions to default state, usefull when old systems had
|
|
491
|
bad permissions, we must clean them up
|
|
499
|
bad permissions, we must clean them up
|
|
492
|
|
|
500
|
|
|
493
|
:param username:
|
|
501
|
:param username:
|
|
494
|
:type username:
|
|
502
|
:type username:
|
|
495
|
"""
|
|
503
|
"""
|
|
496
|
default_user = User.get_by_username(username)
|
|
504
|
default_user = User.get_by_username(username)
|
|
497
|
if not default_user:
|
|
505
|
if not default_user:
|
|
498
|
return
|
|
506
|
return
|
|
499
|
|
|
507
|
|
|
500
|
u2p = UserToPerm.query()\
|
|
508
|
u2p = UserToPerm.query()\
|
|
501
|
.filter(UserToPerm.user == default_user).all()
|
|
509
|
.filter(UserToPerm.user == default_user).all()
|
|
502
|
fixed = False
|
|
510
|
fixed = False
|
|
503
|
if len(u2p) != len(User.DEFAULT_PERMISSIONS):
|
|
511
|
if len(u2p) != len(User.DEFAULT_PERMISSIONS):
|
|
504
|
for p in u2p:
|
|
512
|
for p in u2p:
|
|
505
|
Session().delete(p)
|
|
513
|
Session().delete(p)
|
|
506
|
fixed = True
|
|
514
|
fixed = True
|
|
507
|
self.populate_default_permissions()
|
|
515
|
self.populate_default_permissions()
|
|
508
|
return fixed
|
|
516
|
return fixed
|
|
509
|
|
|
517
|
|
|
510
|
def config_prompt(self, test_repo_path='', retries=3, defaults={}):
|
|
518
|
def config_prompt(self, test_repo_path='', retries=3):
|
|
|
|
|
519
|
defaults = self.cli_args
|
|
511
|
_path = defaults.get('repos_location')
|
|
520
|
_path = defaults.get('repos_location')
|
|
512
|
if retries == 3:
|
|
521
|
if retries == 3:
|
|
513
|
log.info('Setting up repositories config')
|
|
522
|
log.info('Setting up repositories config')
|
|
514
|
|
|
523
|
|
|
515
|
if _path is not None:
|
|
524
|
if _path is not None:
|
|
516
|
path = _path
|
|
525
|
path = _path
|
|
517
|
elif not self.tests and not test_repo_path:
|
|
526
|
elif not self.tests and not test_repo_path:
|
|
518
|
path = raw_input(
|
|
527
|
path = raw_input(
|
|
519
|
'Enter a valid absolute path to store repositories. '
|
|
528
|
'Enter a valid absolute path to store repositories. '
|
|
520
|
'All repositories in that path will be added automatically:'
|
|
529
|
'All repositories in that path will be added automatically:'
|
|
521
|
)
|
|
530
|
)
|
|
522
|
else:
|
|
531
|
else:
|
|
523
|
path = test_repo_path
|
|
532
|
path = test_repo_path
|
|
524
|
path_ok = True
|
|
533
|
path_ok = True
|
|
525
|
|
|
534
|
|
|
526
|
# check proper dir
|
|
535
|
# check proper dir
|
|
527
|
if not os.path.isdir(path):
|
|
536
|
if not os.path.isdir(path):
|
|
528
|
path_ok = False
|
|
537
|
path_ok = False
|
|
529
|
log.error('Given path %s is not a valid directory' % path)
|
|
538
|
log.error('Given path %s is not a valid directory' % path)
|
|
530
|
|
|
539
|
|
|
531
|
elif not os.path.isabs(path):
|
|
540
|
elif not os.path.isabs(path):
|
|
532
|
path_ok = False
|
|
541
|
path_ok = False
|
|
533
|
log.error('Given path %s is not an absolute path' % path)
|
|
542
|
log.error('Given path %s is not an absolute path' % path)
|
|
534
|
|
|
543
|
|
|
535
|
# check write access
|
|
544
|
# check write access
|
|
536
|
elif not os.access(path, os.W_OK) and path_ok:
|
|
545
|
elif not os.access(path, os.W_OK) and path_ok:
|
|
537
|
path_ok = False
|
|
546
|
path_ok = False
|
|
538
|
log.error('No write permission to given path %s' % path)
|
|
547
|
log.error('No write permission to given path %s' % path)
|
|
539
|
|
|
548
|
|
|
540
|
if retries == 0:
|
|
549
|
if retries == 0:
|
|
541
|
sys.exit('max retries reached')
|
|
550
|
sys.exit('max retries reached')
|
|
542
|
if path_ok is False:
|
|
551
|
if path_ok is False:
|
|
543
|
retries -= 1
|
|
552
|
retries -= 1
|
|
544
|
return self.config_prompt(test_repo_path, retries)
|
|
553
|
return self.config_prompt(test_repo_path, retries)
|
|
545
|
|
|
554
|
|
|
546
|
real_path = os.path.normpath(os.path.realpath(path))
|
|
555
|
real_path = os.path.normpath(os.path.realpath(path))
|
|
547
|
|
|
556
|
|
|
548
|
if real_path != os.path.normpath(path):
|
|
557
|
if real_path != os.path.normpath(path):
|
|
549
|
if not ask_ok(('Path looks like a symlink, Rhodecode will store '
|
|
558
|
if not ask_ok(('Path looks like a symlink, Rhodecode will store '
|
|
550
|
'given path as %s ? [y/n]') % (real_path)):
|
|
559
|
'given path as %s ? [y/n]') % (real_path)):
|
|
551
|
log.error('Canceled by user')
|
|
560
|
log.error('Canceled by user')
|
|
552
|
sys.exit(-1)
|
|
561
|
sys.exit(-1)
|
|
553
|
|
|
562
|
|
|
554
|
return real_path
|
|
563
|
return real_path
|
|
555
|
|
|
564
|
|
|
556
|
def create_settings(self, path):
|
|
565
|
def create_settings(self, path):
|
|
557
|
|
|
566
|
|
|
558
|
self.create_ui_settings()
|
|
567
|
self.create_ui_settings()
|
|
559
|
|
|
568
|
|
|
560
|
#HG UI OPTIONS
|
|
569
|
#HG UI OPTIONS
|
|
561
|
web1 = RhodeCodeUi()
|
|
570
|
web1 = RhodeCodeUi()
|
|
562
|
web1.ui_section = 'web'
|
|
571
|
web1.ui_section = 'web'
|
|
563
|
web1.ui_key = 'push_ssl'
|
|
572
|
web1.ui_key = 'push_ssl'
|
|
564
|
web1.ui_value = 'false'
|
|
573
|
web1.ui_value = 'false'
|
|
565
|
|
|
574
|
|
|
566
|
web2 = RhodeCodeUi()
|
|
575
|
web2 = RhodeCodeUi()
|
|
567
|
web2.ui_section = 'web'
|
|
576
|
web2.ui_section = 'web'
|
|
568
|
web2.ui_key = 'allow_archive'
|
|
577
|
web2.ui_key = 'allow_archive'
|
|
569
|
web2.ui_value = 'gz zip bz2'
|
|
578
|
web2.ui_value = 'gz zip bz2'
|
|
570
|
|
|
579
|
|
|
571
|
web3 = RhodeCodeUi()
|
|
580
|
web3 = RhodeCodeUi()
|
|
572
|
web3.ui_section = 'web'
|
|
581
|
web3.ui_section = 'web'
|
|
573
|
web3.ui_key = 'allow_push'
|
|
582
|
web3.ui_key = 'allow_push'
|
|
574
|
web3.ui_value = '*'
|
|
583
|
web3.ui_value = '*'
|
|
575
|
|
|
584
|
|
|
576
|
web4 = RhodeCodeUi()
|
|
585
|
web4 = RhodeCodeUi()
|
|
577
|
web4.ui_section = 'web'
|
|
586
|
web4.ui_section = 'web'
|
|
578
|
web4.ui_key = 'baseurl'
|
|
587
|
web4.ui_key = 'baseurl'
|
|
579
|
web4.ui_value = '/'
|
|
588
|
web4.ui_value = '/'
|
|
580
|
|
|
589
|
|
|
581
|
paths = RhodeCodeUi()
|
|
590
|
paths = RhodeCodeUi()
|
|
582
|
paths.ui_section = 'paths'
|
|
591
|
paths.ui_section = 'paths'
|
|
583
|
paths.ui_key = '/'
|
|
592
|
paths.ui_key = '/'
|
|
584
|
paths.ui_value = path
|
|
593
|
paths.ui_value = path
|
|
585
|
|
|
594
|
|
|
586
|
phases = RhodeCodeUi()
|
|
595
|
phases = RhodeCodeUi()
|
|
587
|
phases.ui_section = 'phases'
|
|
596
|
phases.ui_section = 'phases'
|
|
588
|
phases.ui_key = 'publish'
|
|
597
|
phases.ui_key = 'publish'
|
|
589
|
phases.ui_value = False
|
|
598
|
phases.ui_value = False
|
|
590
|
|
|
599
|
|
|
591
|
sett1 = RhodeCodeSetting('realm', 'RhodeCode authentication')
|
|
600
|
sett1 = RhodeCodeSetting('realm', 'RhodeCode authentication')
|
|
592
|
sett2 = RhodeCodeSetting('title', 'RhodeCode')
|
|
601
|
sett2 = RhodeCodeSetting('title', 'RhodeCode')
|
|
593
|
sett3 = RhodeCodeSetting('ga_code', '')
|
|
602
|
sett3 = RhodeCodeSetting('ga_code', '')
|
|
594
|
|
|
603
|
|
|
595
|
sett4 = RhodeCodeSetting('show_public_icon', True)
|
|
604
|
sett4 = RhodeCodeSetting('show_public_icon', True)
|
|
596
|
sett5 = RhodeCodeSetting('show_private_icon', True)
|
|
605
|
sett5 = RhodeCodeSetting('show_private_icon', True)
|
|
597
|
sett6 = RhodeCodeSetting('stylify_metatags', False)
|
|
606
|
sett6 = RhodeCodeSetting('stylify_metatags', False)
|
|
598
|
|
|
607
|
|
|
599
|
self.sa.add(web1)
|
|
608
|
self.sa.add(web1)
|
|
600
|
self.sa.add(web2)
|
|
609
|
self.sa.add(web2)
|
|
601
|
self.sa.add(web3)
|
|
610
|
self.sa.add(web3)
|
|
602
|
self.sa.add(web4)
|
|
611
|
self.sa.add(web4)
|
|
603
|
self.sa.add(paths)
|
|
612
|
self.sa.add(paths)
|
|
604
|
self.sa.add(sett1)
|
|
613
|
self.sa.add(sett1)
|
|
605
|
self.sa.add(sett2)
|
|
614
|
self.sa.add(sett2)
|
|
606
|
self.sa.add(sett3)
|
|
615
|
self.sa.add(sett3)
|
|
607
|
self.sa.add(sett4)
|
|
616
|
self.sa.add(sett4)
|
|
608
|
self.sa.add(sett5)
|
|
617
|
self.sa.add(sett5)
|
|
609
|
self.sa.add(sett6)
|
|
618
|
self.sa.add(sett6)
|
|
610
|
|
|
619
|
|
|
611
|
self.create_ldap_options()
|
|
620
|
self.create_ldap_options()
|
|
612
|
|
|
621
|
|
|
613
|
log.info('created ui config')
|
|
622
|
log.info('created ui config')
|
|
614
|
|
|
623
|
|
|
615
|
def create_user(self, username, password, email='', admin=False):
|
|
624
|
def create_user(self, username, password, email='', admin=False):
|
|
616
|
log.info('creating user %s' % username)
|
|
625
|
log.info('creating user %s' % username)
|
|
617
|
UserModel().create_or_update(username, password, email,
|
|
626
|
UserModel().create_or_update(username, password, email,
|
|
618
|
firstname='RhodeCode', lastname='Admin',
|
|
627
|
firstname='RhodeCode', lastname='Admin',
|
|
619
|
active=True, admin=admin)
|
|
628
|
active=True, admin=admin)
|
|
620
|
|
|
629
|
|
|
621
|
def create_default_user(self):
|
|
630
|
def create_default_user(self):
|
|
622
|
log.info('creating default user')
|
|
631
|
log.info('creating default user')
|
|
623
|
# create default user for handling default permissions.
|
|
632
|
# create default user for handling default permissions.
|
|
624
|
UserModel().create_or_update(username='default',
|
|
633
|
UserModel().create_or_update(username='default',
|
|
625
|
password=str(uuid.uuid1())[:8],
|
|
634
|
password=str(uuid.uuid1())[:8],
|
|
626
|
email='anonymous@rhodecode.org',
|
|
635
|
email='anonymous@rhodecode.org',
|
|
627
|
firstname='Anonymous', lastname='User')
|
|
636
|
firstname='Anonymous', lastname='User')
|
|
628
|
|
|
637
|
|
|
629
|
def create_permissions(self):
|
|
638
|
def create_permissions(self):
|
|
630
|
# module.(access|create|change|delete)_[name]
|
|
639
|
# module.(access|create|change|delete)_[name]
|
|
631
|
# module.(none|read|write|admin)
|
|
640
|
# module.(none|read|write|admin)
|
|
632
|
|
|
641
|
|
|
633
|
for p in Permission.PERMS:
|
|
642
|
for p in Permission.PERMS:
|
|
634
|
if not Permission.get_by_key(p[0]):
|
|
643
|
if not Permission.get_by_key(p[0]):
|
|
635
|
new_perm = Permission()
|
|
644
|
new_perm = Permission()
|
|
636
|
new_perm.permission_name = p[0]
|
|
645
|
new_perm.permission_name = p[0]
|
|
637
|
new_perm.permission_longname = p[0]
|
|
646
|
new_perm.permission_longname = p[0]
|
|
638
|
self.sa.add(new_perm)
|
|
647
|
self.sa.add(new_perm)
|
|
639
|
|
|
648
|
|
|
640
|
def populate_default_permissions(self):
|
|
649
|
def populate_default_permissions(self):
|
|
641
|
log.info('creating default user permissions')
|
|
650
|
log.info('creating default user permissions')
|
|
642
|
|
|
651
|
|
|
643
|
default_user = User.get_by_username('default')
|
|
652
|
default_user = User.get_by_username('default')
|
|
644
|
|
|
653
|
|
|
645
|
for def_perm in User.DEFAULT_PERMISSIONS:
|
|
654
|
for def_perm in User.DEFAULT_PERMISSIONS:
|
|
646
|
|
|
655
|
|
|
647
|
perm = self.sa.query(Permission)\
|
|
656
|
perm = self.sa.query(Permission)\
|
|
648
|
.filter(Permission.permission_name == def_perm)\
|
|
657
|
.filter(Permission.permission_name == def_perm)\
|
|
649
|
.scalar()
|
|
658
|
.scalar()
|
|
650
|
if not perm:
|
|
659
|
if not perm:
|
|
651
|
raise Exception(
|
|
660
|
raise Exception(
|
|
652
|
'CRITICAL: permission %s not found inside database !!'
|
|
661
|
'CRITICAL: permission %s not found inside database !!'
|
|
653
|
% def_perm
|
|
662
|
% def_perm
|
|
654
|
)
|
|
663
|
)
|
|
655
|
if not UserToPerm.query()\
|
|
664
|
if not UserToPerm.query()\
|
|
656
|
.filter(UserToPerm.permission == perm)\
|
|
665
|
.filter(UserToPerm.permission == perm)\
|
|
657
|
.filter(UserToPerm.user == default_user).scalar():
|
|
666
|
.filter(UserToPerm.user == default_user).scalar():
|
|
658
|
reg_perm = UserToPerm()
|
|
667
|
reg_perm = UserToPerm()
|
|
659
|
reg_perm.user = default_user
|
|
668
|
reg_perm.user = default_user
|
|
660
|
reg_perm.permission = perm
|
|
669
|
reg_perm.permission = perm
|
|
661
|
self.sa.add(reg_perm)
|
|
670
|
self.sa.add(reg_perm)
|
|
662
|
|
|
671
|
|
|
663
|
def finish(self):
|
|
672
|
def finish(self):
|
|
664
|
"""
|
|
673
|
"""
|
|
665
|
Function executed at the end of setup
|
|
674
|
Function executed at the end of setup
|
|
666
|
"""
|
|
675
|
"""
|
|
667
|
if not __py_version__ >= (2, 6):
|
|
676
|
if not __py_version__ >= (2, 6):
|
|
668
|
notify('Python2.5 detected, please switch '
|
|
677
|
notify('Python2.5 detected, please switch '
|
|
669
|
'egg:waitress#main -> egg:Paste#http '
|
|
678
|
'egg:waitress#main -> egg:Paste#http '
|
|
670
|
'in your .ini file')
|
|
679
|
'in your .ini file')
|