|
@@
-1,1986
+1,1996
|
|
1
|
# -*- coding: utf-8 -*-
|
|
1
|
# -*- coding: utf-8 -*-
|
|
2
|
"""
|
|
2
|
"""
|
|
3
|
rhodecode.model.db
|
|
3
|
rhodecode.model.db
|
|
4
|
~~~~~~~~~~~~~~~~~~
|
|
4
|
~~~~~~~~~~~~~~~~~~
|
|
5
|
|
|
5
|
|
|
6
|
Database Models for RhodeCode
|
|
6
|
Database Models for RhodeCode
|
|
7
|
|
|
7
|
|
|
8
|
:created_on: Apr 08, 2010
|
|
8
|
:created_on: Apr 08, 2010
|
|
9
|
:author: marcink
|
|
9
|
:author: marcink
|
|
10
|
:copyright: (C) 2010-2012 Marcin Kuzminski <marcin@python-works.com>
|
|
10
|
:copyright: (C) 2010-2012 Marcin Kuzminski <marcin@python-works.com>
|
|
11
|
:license: GPLv3, see COPYING for more details.
|
|
11
|
:license: GPLv3, see COPYING for more details.
|
|
12
|
"""
|
|
12
|
"""
|
|
13
|
# This program is free software: you can redistribute it and/or modify
|
|
13
|
# This program is free software: you can redistribute it and/or modify
|
|
14
|
# it under the terms of the GNU General Public License as published by
|
|
14
|
# it under the terms of the GNU General Public License as published by
|
|
15
|
# the Free Software Foundation, either version 3 of the License, or
|
|
15
|
# the Free Software Foundation, either version 3 of the License, or
|
|
16
|
# (at your option) any later version.
|
|
16
|
# (at your option) any later version.
|
|
17
|
#
|
|
17
|
#
|
|
18
|
# This program is distributed in the hope that it will be useful,
|
|
18
|
# This program is distributed in the hope that it will be useful,
|
|
19
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
19
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
20
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
20
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
21
|
# GNU General Public License for more details.
|
|
21
|
# GNU General Public License for more details.
|
|
22
|
#
|
|
22
|
#
|
|
23
|
# You should have received a copy of the GNU General Public License
|
|
23
|
# You should have received a copy of the GNU General Public License
|
|
24
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
24
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
25
|
|
|
25
|
|
|
26
|
import os
|
|
26
|
import os
|
|
27
|
import logging
|
|
27
|
import logging
|
|
28
|
import datetime
|
|
28
|
import datetime
|
|
29
|
import traceback
|
|
29
|
import traceback
|
|
30
|
import hashlib
|
|
30
|
import hashlib
|
|
31
|
import time
|
|
31
|
import time
|
|
32
|
from collections import defaultdict
|
|
32
|
from collections import defaultdict
|
|
33
|
|
|
33
|
|
|
34
|
from sqlalchemy import *
|
|
34
|
from sqlalchemy import *
|
|
35
|
from sqlalchemy.ext.hybrid import hybrid_property
|
|
35
|
from sqlalchemy.ext.hybrid import hybrid_property
|
|
36
|
from sqlalchemy.orm import relationship, joinedload, class_mapper, validates
|
|
36
|
from sqlalchemy.orm import relationship, joinedload, class_mapper, validates
|
|
37
|
from sqlalchemy.exc import DatabaseError
|
|
37
|
from sqlalchemy.exc import DatabaseError
|
|
38
|
from beaker.cache import cache_region, region_invalidate
|
|
38
|
from beaker.cache import cache_region, region_invalidate
|
|
39
|
from webob.exc import HTTPNotFound
|
|
39
|
from webob.exc import HTTPNotFound
|
|
40
|
|
|
40
|
|
|
41
|
from pylons.i18n.translation import lazy_ugettext as _
|
|
41
|
from pylons.i18n.translation import lazy_ugettext as _
|
|
42
|
|
|
42
|
|
|
43
|
from rhodecode.lib.vcs import get_backend
|
|
43
|
from rhodecode.lib.vcs import get_backend
|
|
44
|
from rhodecode.lib.vcs.utils.helpers import get_scm
|
|
44
|
from rhodecode.lib.vcs.utils.helpers import get_scm
|
|
45
|
from rhodecode.lib.vcs.exceptions import VCSError
|
|
45
|
from rhodecode.lib.vcs.exceptions import VCSError
|
|
46
|
from rhodecode.lib.vcs.utils.lazy import LazyProperty
|
|
46
|
from rhodecode.lib.vcs.utils.lazy import LazyProperty
|
|
47
|
|
|
47
|
|
|
48
|
from rhodecode.lib.utils2 import str2bool, safe_str, get_changeset_safe, \
|
|
48
|
from rhodecode.lib.utils2 import str2bool, safe_str, get_changeset_safe, \
|
|
49
|
safe_unicode, remove_suffix, remove_prefix
|
|
49
|
safe_unicode, remove_suffix, remove_prefix
|
|
50
|
from rhodecode.lib.compat import json
|
|
50
|
from rhodecode.lib.compat import json
|
|
51
|
from rhodecode.lib.caching_query import FromCache
|
|
51
|
from rhodecode.lib.caching_query import FromCache
|
|
52
|
|
|
52
|
|
|
53
|
from rhodecode.model.meta import Base, Session
|
|
53
|
from rhodecode.model.meta import Base, Session
|
|
54
|
|
|
54
|
|
|
55
|
URL_SEP = '/'
|
|
55
|
URL_SEP = '/'
|
|
56
|
log = logging.getLogger(__name__)
|
|
56
|
log = logging.getLogger(__name__)
|
|
57
|
|
|
57
|
|
|
58
|
#==============================================================================
|
|
58
|
#==============================================================================
|
|
59
|
# BASE CLASSES
|
|
59
|
# BASE CLASSES
|
|
60
|
#==============================================================================
|
|
60
|
#==============================================================================
|
|
61
|
|
|
61
|
|
|
62
|
_hash_key = lambda k: hashlib.md5(safe_str(k)).hexdigest()
|
|
62
|
_hash_key = lambda k: hashlib.md5(safe_str(k)).hexdigest()
|
|
63
|
|
|
63
|
|
|
64
|
|
|
64
|
|
|
65
|
class BaseModel(object):
|
|
65
|
class BaseModel(object):
|
|
66
|
"""
|
|
66
|
"""
|
|
67
|
Base Model for all classess
|
|
67
|
Base Model for all classess
|
|
68
|
"""
|
|
68
|
"""
|
|
69
|
|
|
69
|
|
|
70
|
@classmethod
|
|
70
|
@classmethod
|
|
71
|
def _get_keys(cls):
|
|
71
|
def _get_keys(cls):
|
|
72
|
"""return column names for this model """
|
|
72
|
"""return column names for this model """
|
|
73
|
return class_mapper(cls).c.keys()
|
|
73
|
return class_mapper(cls).c.keys()
|
|
74
|
|
|
74
|
|
|
75
|
def get_dict(self):
|
|
75
|
def get_dict(self):
|
|
76
|
"""
|
|
76
|
"""
|
|
77
|
return dict with keys and values corresponding
|
|
77
|
return dict with keys and values corresponding
|
|
78
|
to this model data """
|
|
78
|
to this model data """
|
|
79
|
|
|
79
|
|
|
80
|
d = {}
|
|
80
|
d = {}
|
|
81
|
for k in self._get_keys():
|
|
81
|
for k in self._get_keys():
|
|
82
|
d[k] = getattr(self, k)
|
|
82
|
d[k] = getattr(self, k)
|
|
83
|
|
|
83
|
|
|
84
|
# also use __json__() if present to get additional fields
|
|
84
|
# also use __json__() if present to get additional fields
|
|
85
|
_json_attr = getattr(self, '__json__', None)
|
|
85
|
_json_attr = getattr(self, '__json__', None)
|
|
86
|
if _json_attr:
|
|
86
|
if _json_attr:
|
|
87
|
# update with attributes from __json__
|
|
87
|
# update with attributes from __json__
|
|
88
|
if callable(_json_attr):
|
|
88
|
if callable(_json_attr):
|
|
89
|
_json_attr = _json_attr()
|
|
89
|
_json_attr = _json_attr()
|
|
90
|
for k, val in _json_attr.iteritems():
|
|
90
|
for k, val in _json_attr.iteritems():
|
|
91
|
d[k] = val
|
|
91
|
d[k] = val
|
|
92
|
return d
|
|
92
|
return d
|
|
93
|
|
|
93
|
|
|
94
|
def get_appstruct(self):
|
|
94
|
def get_appstruct(self):
|
|
95
|
"""return list with keys and values tupples corresponding
|
|
95
|
"""return list with keys and values tupples corresponding
|
|
96
|
to this model data """
|
|
96
|
to this model data """
|
|
97
|
|
|
97
|
|
|
98
|
l = []
|
|
98
|
l = []
|
|
99
|
for k in self._get_keys():
|
|
99
|
for k in self._get_keys():
|
|
100
|
l.append((k, getattr(self, k),))
|
|
100
|
l.append((k, getattr(self, k),))
|
|
101
|
return l
|
|
101
|
return l
|
|
102
|
|
|
102
|
|
|
103
|
def populate_obj(self, populate_dict):
|
|
103
|
def populate_obj(self, populate_dict):
|
|
104
|
"""populate model with data from given populate_dict"""
|
|
104
|
"""populate model with data from given populate_dict"""
|
|
105
|
|
|
105
|
|
|
106
|
for k in self._get_keys():
|
|
106
|
for k in self._get_keys():
|
|
107
|
if k in populate_dict:
|
|
107
|
if k in populate_dict:
|
|
108
|
setattr(self, k, populate_dict[k])
|
|
108
|
setattr(self, k, populate_dict[k])
|
|
109
|
|
|
109
|
|
|
110
|
@classmethod
|
|
110
|
@classmethod
|
|
111
|
def query(cls):
|
|
111
|
def query(cls):
|
|
112
|
return Session().query(cls)
|
|
112
|
return Session().query(cls)
|
|
113
|
|
|
113
|
|
|
114
|
@classmethod
|
|
114
|
@classmethod
|
|
115
|
def get(cls, id_):
|
|
115
|
def get(cls, id_):
|
|
116
|
if id_:
|
|
116
|
if id_:
|
|
117
|
return cls.query().get(id_)
|
|
117
|
return cls.query().get(id_)
|
|
118
|
|
|
118
|
|
|
119
|
@classmethod
|
|
119
|
@classmethod
|
|
120
|
def get_or_404(cls, id_):
|
|
120
|
def get_or_404(cls, id_):
|
|
121
|
try:
|
|
121
|
try:
|
|
122
|
id_ = int(id_)
|
|
122
|
id_ = int(id_)
|
|
123
|
except (TypeError, ValueError):
|
|
123
|
except (TypeError, ValueError):
|
|
124
|
raise HTTPNotFound
|
|
124
|
raise HTTPNotFound
|
|
125
|
|
|
125
|
|
|
126
|
res = cls.query().get(id_)
|
|
126
|
res = cls.query().get(id_)
|
|
127
|
if not res:
|
|
127
|
if not res:
|
|
128
|
raise HTTPNotFound
|
|
128
|
raise HTTPNotFound
|
|
129
|
return res
|
|
129
|
return res
|
|
130
|
|
|
130
|
|
|
131
|
@classmethod
|
|
131
|
@classmethod
|
|
132
|
def getAll(cls):
|
|
132
|
def getAll(cls):
|
|
133
|
return cls.query().all()
|
|
133
|
return cls.query().all()
|
|
134
|
|
|
134
|
|
|
135
|
@classmethod
|
|
135
|
@classmethod
|
|
136
|
def delete(cls, id_):
|
|
136
|
def delete(cls, id_):
|
|
137
|
obj = cls.query().get(id_)
|
|
137
|
obj = cls.query().get(id_)
|
|
138
|
Session().delete(obj)
|
|
138
|
Session().delete(obj)
|
|
139
|
|
|
139
|
|
|
140
|
def __repr__(self):
|
|
140
|
def __repr__(self):
|
|
141
|
if hasattr(self, '__unicode__'):
|
|
141
|
if hasattr(self, '__unicode__'):
|
|
142
|
# python repr needs to return str
|
|
142
|
# python repr needs to return str
|
|
143
|
return safe_str(self.__unicode__())
|
|
143
|
return safe_str(self.__unicode__())
|
|
144
|
return '<DB:%s>' % (self.__class__.__name__)
|
|
144
|
return '<DB:%s>' % (self.__class__.__name__)
|
|
145
|
|
|
145
|
|
|
146
|
|
|
146
|
|
|
147
|
class RhodeCodeSetting(Base, BaseModel):
|
|
147
|
class RhodeCodeSetting(Base, BaseModel):
|
|
148
|
__tablename__ = 'rhodecode_settings'
|
|
148
|
__tablename__ = 'rhodecode_settings'
|
|
149
|
__table_args__ = (
|
|
149
|
__table_args__ = (
|
|
150
|
UniqueConstraint('app_settings_name'),
|
|
150
|
UniqueConstraint('app_settings_name'),
|
|
151
|
{'extend_existing': True, 'mysql_engine': 'InnoDB',
|
|
151
|
{'extend_existing': True, 'mysql_engine': 'InnoDB',
|
|
152
|
'mysql_charset': 'utf8'}
|
|
152
|
'mysql_charset': 'utf8'}
|
|
153
|
)
|
|
153
|
)
|
|
154
|
app_settings_id = Column("app_settings_id", Integer(), nullable=False, unique=True, default=None, primary_key=True)
|
|
154
|
app_settings_id = Column("app_settings_id", Integer(), nullable=False, unique=True, default=None, primary_key=True)
|
|
155
|
app_settings_name = Column("app_settings_name", String(255, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None)
|
|
155
|
app_settings_name = Column("app_settings_name", String(255, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None)
|
|
156
|
_app_settings_value = Column("app_settings_value", String(255, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None)
|
|
156
|
_app_settings_value = Column("app_settings_value", String(255, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None)
|
|
157
|
|
|
157
|
|
|
158
|
def __init__(self, k='', v=''):
|
|
158
|
def __init__(self, k='', v=''):
|
|
159
|
self.app_settings_name = k
|
|
159
|
self.app_settings_name = k
|
|
160
|
self.app_settings_value = v
|
|
160
|
self.app_settings_value = v
|
|
161
|
|
|
161
|
|
|
162
|
@validates('_app_settings_value')
|
|
162
|
@validates('_app_settings_value')
|
|
163
|
def validate_settings_value(self, key, val):
|
|
163
|
def validate_settings_value(self, key, val):
|
|
164
|
assert type(val) == unicode
|
|
164
|
assert type(val) == unicode
|
|
165
|
return val
|
|
165
|
return val
|
|
166
|
|
|
166
|
|
|
167
|
@hybrid_property
|
|
167
|
@hybrid_property
|
|
168
|
def app_settings_value(self):
|
|
168
|
def app_settings_value(self):
|
|
169
|
v = self._app_settings_value
|
|
169
|
v = self._app_settings_value
|
|
170
|
if self.app_settings_name in ["ldap_active",
|
|
170
|
if self.app_settings_name in ["ldap_active",
|
|
171
|
"default_repo_enable_statistics",
|
|
171
|
"default_repo_enable_statistics",
|
|
172
|
"default_repo_enable_locking",
|
|
172
|
"default_repo_enable_locking",
|
|
173
|
"default_repo_private",
|
|
173
|
"default_repo_private",
|
|
174
|
"default_repo_enable_downloads"]:
|
|
174
|
"default_repo_enable_downloads"]:
|
|
175
|
v = str2bool(v)
|
|
175
|
v = str2bool(v)
|
|
176
|
return v
|
|
176
|
return v
|
|
177
|
|
|
177
|
|
|
178
|
@app_settings_value.setter
|
|
178
|
@app_settings_value.setter
|
|
179
|
def app_settings_value(self, val):
|
|
179
|
def app_settings_value(self, val):
|
|
180
|
"""
|
|
180
|
"""
|
|
181
|
Setter that will always make sure we use unicode in app_settings_value
|
|
181
|
Setter that will always make sure we use unicode in app_settings_value
|
|
182
|
|
|
182
|
|
|
183
|
:param val:
|
|
183
|
:param val:
|
|
184
|
"""
|
|
184
|
"""
|
|
185
|
self._app_settings_value = safe_unicode(val)
|
|
185
|
self._app_settings_value = safe_unicode(val)
|
|
186
|
|
|
186
|
|
|
187
|
def __unicode__(self):
|
|
187
|
def __unicode__(self):
|
|
188
|
return u"<%s('%s:%s')>" % (
|
|
188
|
return u"<%s('%s:%s')>" % (
|
|
189
|
self.__class__.__name__,
|
|
189
|
self.__class__.__name__,
|
|
190
|
self.app_settings_name, self.app_settings_value
|
|
190
|
self.app_settings_name, self.app_settings_value
|
|
191
|
)
|
|
191
|
)
|
|
192
|
|
|
192
|
|
|
193
|
@classmethod
|
|
193
|
@classmethod
|
|
194
|
def get_by_name(cls, key):
|
|
194
|
def get_by_name(cls, key):
|
|
195
|
return cls.query()\
|
|
195
|
return cls.query()\
|
|
196
|
.filter(cls.app_settings_name == key).scalar()
|
|
196
|
.filter(cls.app_settings_name == key).scalar()
|
|
197
|
|
|
197
|
|
|
198
|
@classmethod
|
|
198
|
@classmethod
|
|
199
|
def get_by_name_or_create(cls, key):
|
|
199
|
def get_by_name_or_create(cls, key):
|
|
200
|
res = cls.get_by_name(key)
|
|
200
|
res = cls.get_by_name(key)
|
|
201
|
if not res:
|
|
201
|
if not res:
|
|
202
|
res = cls(key)
|
|
202
|
res = cls(key)
|
|
203
|
return res
|
|
203
|
return res
|
|
204
|
|
|
204
|
|
|
205
|
@classmethod
|
|
205
|
@classmethod
|
|
206
|
def get_app_settings(cls, cache=False):
|
|
206
|
def get_app_settings(cls, cache=False):
|
|
207
|
|
|
207
|
|
|
208
|
ret = cls.query()
|
|
208
|
ret = cls.query()
|
|
209
|
|
|
209
|
|
|
210
|
if cache:
|
|
210
|
if cache:
|
|
211
|
ret = ret.options(FromCache("sql_cache_short", "get_hg_settings"))
|
|
211
|
ret = ret.options(FromCache("sql_cache_short", "get_hg_settings"))
|
|
212
|
|
|
212
|
|
|
213
|
if not ret:
|
|
213
|
if not ret:
|
|
214
|
raise Exception('Could not get application settings !')
|
|
214
|
raise Exception('Could not get application settings !')
|
|
215
|
settings = {}
|
|
215
|
settings = {}
|
|
216
|
for each in ret:
|
|
216
|
for each in ret:
|
|
217
|
settings['rhodecode_' + each.app_settings_name] = \
|
|
217
|
settings['rhodecode_' + each.app_settings_name] = \
|
|
218
|
each.app_settings_value
|
|
218
|
each.app_settings_value
|
|
219
|
|
|
219
|
|
|
220
|
return settings
|
|
220
|
return settings
|
|
221
|
|
|
221
|
|
|
222
|
@classmethod
|
|
222
|
@classmethod
|
|
223
|
def get_ldap_settings(cls, cache=False):
|
|
223
|
def get_ldap_settings(cls, cache=False):
|
|
224
|
ret = cls.query()\
|
|
224
|
ret = cls.query()\
|
|
225
|
.filter(cls.app_settings_name.startswith('ldap_')).all()
|
|
225
|
.filter(cls.app_settings_name.startswith('ldap_')).all()
|
|
226
|
fd = {}
|
|
226
|
fd = {}
|
|
227
|
for row in ret:
|
|
227
|
for row in ret:
|
|
228
|
fd.update({row.app_settings_name: row.app_settings_value})
|
|
228
|
fd.update({row.app_settings_name: row.app_settings_value})
|
|
229
|
|
|
229
|
|
|
230
|
return fd
|
|
230
|
return fd
|
|
231
|
|
|
231
|
|
|
232
|
@classmethod
|
|
232
|
@classmethod
|
|
233
|
def get_default_repo_settings(cls, cache=False, strip_prefix=False):
|
|
233
|
def get_default_repo_settings(cls, cache=False, strip_prefix=False):
|
|
234
|
ret = cls.query()\
|
|
234
|
ret = cls.query()\
|
|
235
|
.filter(cls.app_settings_name.startswith('default_')).all()
|
|
235
|
.filter(cls.app_settings_name.startswith('default_')).all()
|
|
236
|
fd = {}
|
|
236
|
fd = {}
|
|
237
|
for row in ret:
|
|
237
|
for row in ret:
|
|
238
|
key = row.app_settings_name
|
|
238
|
key = row.app_settings_name
|
|
239
|
if strip_prefix:
|
|
239
|
if strip_prefix:
|
|
240
|
key = remove_prefix(key, prefix='default_')
|
|
240
|
key = remove_prefix(key, prefix='default_')
|
|
241
|
fd.update({key: row.app_settings_value})
|
|
241
|
fd.update({key: row.app_settings_value})
|
|
242
|
|
|
242
|
|
|
243
|
return fd
|
|
243
|
return fd
|
|
244
|
|
|
244
|
|
|
245
|
|
|
245
|
|
|
246
|
class RhodeCodeUi(Base, BaseModel):
|
|
246
|
class RhodeCodeUi(Base, BaseModel):
|
|
247
|
__tablename__ = 'rhodecode_ui'
|
|
247
|
__tablename__ = 'rhodecode_ui'
|
|
248
|
__table_args__ = (
|
|
248
|
__table_args__ = (
|
|
249
|
UniqueConstraint('ui_key'),
|
|
249
|
UniqueConstraint('ui_key'),
|
|
250
|
{'extend_existing': True, 'mysql_engine': 'InnoDB',
|
|
250
|
{'extend_existing': True, 'mysql_engine': 'InnoDB',
|
|
251
|
'mysql_charset': 'utf8'}
|
|
251
|
'mysql_charset': 'utf8'}
|
|
252
|
)
|
|
252
|
)
|
|
253
|
|
|
253
|
|
|
254
|
HOOK_UPDATE = 'changegroup.update'
|
|
254
|
HOOK_UPDATE = 'changegroup.update'
|
|
255
|
HOOK_REPO_SIZE = 'changegroup.repo_size'
|
|
255
|
HOOK_REPO_SIZE = 'changegroup.repo_size'
|
|
256
|
HOOK_PUSH = 'changegroup.push_logger'
|
|
256
|
HOOK_PUSH = 'changegroup.push_logger'
|
|
257
|
HOOK_PRE_PUSH = 'prechangegroup.pre_push'
|
|
257
|
HOOK_PRE_PUSH = 'prechangegroup.pre_push'
|
|
258
|
HOOK_PULL = 'outgoing.pull_logger'
|
|
258
|
HOOK_PULL = 'outgoing.pull_logger'
|
|
259
|
HOOK_PRE_PULL = 'preoutgoing.pre_pull'
|
|
259
|
HOOK_PRE_PULL = 'preoutgoing.pre_pull'
|
|
260
|
|
|
260
|
|
|
261
|
ui_id = Column("ui_id", Integer(), nullable=False, unique=True, default=None, primary_key=True)
|
|
261
|
ui_id = Column("ui_id", Integer(), nullable=False, unique=True, default=None, primary_key=True)
|
|
262
|
ui_section = Column("ui_section", String(255, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None)
|
|
262
|
ui_section = Column("ui_section", String(255, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None)
|
|
263
|
ui_key = Column("ui_key", String(255, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None)
|
|
263
|
ui_key = Column("ui_key", String(255, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None)
|
|
264
|
ui_value = Column("ui_value", String(255, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None)
|
|
264
|
ui_value = Column("ui_value", String(255, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None)
|
|
265
|
ui_active = Column("ui_active", Boolean(), nullable=True, unique=None, default=True)
|
|
265
|
ui_active = Column("ui_active", Boolean(), nullable=True, unique=None, default=True)
|
|
266
|
|
|
266
|
|
|
267
|
@classmethod
|
|
267
|
@classmethod
|
|
268
|
def get_by_key(cls, key):
|
|
268
|
def get_by_key(cls, key):
|
|
269
|
return cls.query().filter(cls.ui_key == key).scalar()
|
|
269
|
return cls.query().filter(cls.ui_key == key).scalar()
|
|
270
|
|
|
270
|
|
|
271
|
@classmethod
|
|
271
|
@classmethod
|
|
272
|
def get_builtin_hooks(cls):
|
|
272
|
def get_builtin_hooks(cls):
|
|
273
|
q = cls.query()
|
|
273
|
q = cls.query()
|
|
274
|
q = q.filter(cls.ui_key.in_([cls.HOOK_UPDATE, cls.HOOK_REPO_SIZE,
|
|
274
|
q = q.filter(cls.ui_key.in_([cls.HOOK_UPDATE, cls.HOOK_REPO_SIZE,
|
|
275
|
cls.HOOK_PUSH, cls.HOOK_PRE_PUSH,
|
|
275
|
cls.HOOK_PUSH, cls.HOOK_PRE_PUSH,
|
|
276
|
cls.HOOK_PULL, cls.HOOK_PRE_PULL]))
|
|
276
|
cls.HOOK_PULL, cls.HOOK_PRE_PULL]))
|
|
277
|
return q.all()
|
|
277
|
return q.all()
|
|
278
|
|
|
278
|
|
|
279
|
@classmethod
|
|
279
|
@classmethod
|
|
280
|
def get_custom_hooks(cls):
|
|
280
|
def get_custom_hooks(cls):
|
|
281
|
q = cls.query()
|
|
281
|
q = cls.query()
|
|
282
|
q = q.filter(~cls.ui_key.in_([cls.HOOK_UPDATE, cls.HOOK_REPO_SIZE,
|
|
282
|
q = q.filter(~cls.ui_key.in_([cls.HOOK_UPDATE, cls.HOOK_REPO_SIZE,
|
|
283
|
cls.HOOK_PUSH, cls.HOOK_PRE_PUSH,
|
|
283
|
cls.HOOK_PUSH, cls.HOOK_PRE_PUSH,
|
|
284
|
cls.HOOK_PULL, cls.HOOK_PRE_PULL]))
|
|
284
|
cls.HOOK_PULL, cls.HOOK_PRE_PULL]))
|
|
285
|
q = q.filter(cls.ui_section == 'hooks')
|
|
285
|
q = q.filter(cls.ui_section == 'hooks')
|
|
286
|
return q.all()
|
|
286
|
return q.all()
|
|
287
|
|
|
287
|
|
|
288
|
@classmethod
|
|
288
|
@classmethod
|
|
289
|
def get_repos_location(cls):
|
|
289
|
def get_repos_location(cls):
|
|
290
|
return cls.get_by_key('/').ui_value
|
|
290
|
return cls.get_by_key('/').ui_value
|
|
291
|
|
|
291
|
|
|
292
|
@classmethod
|
|
292
|
@classmethod
|
|
293
|
def create_or_update_hook(cls, key, val):
|
|
293
|
def create_or_update_hook(cls, key, val):
|
|
294
|
new_ui = cls.get_by_key(key) or cls()
|
|
294
|
new_ui = cls.get_by_key(key) or cls()
|
|
295
|
new_ui.ui_section = 'hooks'
|
|
295
|
new_ui.ui_section = 'hooks'
|
|
296
|
new_ui.ui_active = True
|
|
296
|
new_ui.ui_active = True
|
|
297
|
new_ui.ui_key = key
|
|
297
|
new_ui.ui_key = key
|
|
298
|
new_ui.ui_value = val
|
|
298
|
new_ui.ui_value = val
|
|
299
|
|
|
299
|
|
|
300
|
Session().add(new_ui)
|
|
300
|
Session().add(new_ui)
|
|
301
|
|
|
301
|
|
|
302
|
def __repr__(self):
|
|
302
|
def __repr__(self):
|
|
303
|
return '<DB:%s[%s:%s]>' % (self.__class__.__name__, self.ui_key,
|
|
303
|
return '<DB:%s[%s:%s]>' % (self.__class__.__name__, self.ui_key,
|
|
304
|
self.ui_value)
|
|
304
|
self.ui_value)
|
|
305
|
|
|
305
|
|
|
306
|
|
|
306
|
|
|
307
|
class User(Base, BaseModel):
|
|
307
|
class User(Base, BaseModel):
|
|
308
|
__tablename__ = 'users'
|
|
308
|
__tablename__ = 'users'
|
|
309
|
__table_args__ = (
|
|
309
|
__table_args__ = (
|
|
310
|
UniqueConstraint('username'), UniqueConstraint('email'),
|
|
310
|
UniqueConstraint('username'), UniqueConstraint('email'),
|
|
311
|
Index('u_username_idx', 'username'),
|
|
311
|
Index('u_username_idx', 'username'),
|
|
312
|
Index('u_email_idx', 'email'),
|
|
312
|
Index('u_email_idx', 'email'),
|
|
313
|
{'extend_existing': True, 'mysql_engine': 'InnoDB',
|
|
313
|
{'extend_existing': True, 'mysql_engine': 'InnoDB',
|
|
314
|
'mysql_charset': 'utf8'}
|
|
314
|
'mysql_charset': 'utf8'}
|
|
315
|
)
|
|
315
|
)
|
|
316
|
DEFAULT_USER = 'default'
|
|
316
|
DEFAULT_USER = 'default'
|
|
317
|
DEFAULT_PERMISSIONS = [
|
|
317
|
DEFAULT_PERMISSIONS = [
|
|
318
|
'hg.register.manual_activate', 'hg.create.repository',
|
|
318
|
'hg.register.manual_activate', 'hg.create.repository',
|
|
319
|
'hg.fork.repository', 'repository.read', 'group.read'
|
|
319
|
'hg.fork.repository', 'repository.read', 'group.read'
|
|
320
|
]
|
|
320
|
]
|
|
321
|
user_id = Column("user_id", Integer(), nullable=False, unique=True, default=None, primary_key=True)
|
|
321
|
user_id = Column("user_id", Integer(), nullable=False, unique=True, default=None, primary_key=True)
|
|
322
|
username = Column("username", String(255, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None)
|
|
322
|
username = Column("username", String(255, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None)
|
|
323
|
password = Column("password", String(255, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None)
|
|
323
|
password = Column("password", String(255, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None)
|
|
324
|
active = Column("active", Boolean(), nullable=True, unique=None, default=True)
|
|
324
|
active = Column("active", Boolean(), nullable=True, unique=None, default=True)
|
|
325
|
admin = Column("admin", Boolean(), nullable=True, unique=None, default=False)
|
|
325
|
admin = Column("admin", Boolean(), nullable=True, unique=None, default=False)
|
|
326
|
name = Column("firstname", String(255, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None)
|
|
326
|
name = Column("firstname", String(255, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None)
|
|
327
|
lastname = Column("lastname", String(255, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None)
|
|
327
|
lastname = Column("lastname", String(255, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None)
|
|
328
|
_email = Column("email", String(255, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None)
|
|
328
|
_email = Column("email", String(255, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None)
|
|
329
|
last_login = Column("last_login", DateTime(timezone=False), nullable=True, unique=None, default=None)
|
|
329
|
last_login = Column("last_login", DateTime(timezone=False), nullable=True, unique=None, default=None)
|
|
330
|
ldap_dn = Column("ldap_dn", String(255, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None)
|
|
330
|
ldap_dn = Column("ldap_dn", String(255, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None)
|
|
331
|
api_key = Column("api_key", String(255, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None)
|
|
331
|
api_key = Column("api_key", String(255, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None)
|
|
332
|
inherit_default_permissions = Column("inherit_default_permissions", Boolean(), nullable=False, unique=None, default=True)
|
|
332
|
inherit_default_permissions = Column("inherit_default_permissions", Boolean(), nullable=False, unique=None, default=True)
|
|
333
|
|
|
333
|
|
|
334
|
user_log = relationship('UserLog')
|
|
334
|
user_log = relationship('UserLog')
|
|
335
|
user_perms = relationship('UserToPerm', primaryjoin="User.user_id==UserToPerm.user_id", cascade='all')
|
|
335
|
user_perms = relationship('UserToPerm', primaryjoin="User.user_id==UserToPerm.user_id", cascade='all')
|
|
336
|
|
|
336
|
|
|
337
|
repositories = relationship('Repository')
|
|
337
|
repositories = relationship('Repository')
|
|
338
|
user_followers = relationship('UserFollowing', primaryjoin='UserFollowing.follows_user_id==User.user_id', cascade='all')
|
|
338
|
user_followers = relationship('UserFollowing', primaryjoin='UserFollowing.follows_user_id==User.user_id', cascade='all')
|
|
339
|
followings = relationship('UserFollowing', primaryjoin='UserFollowing.user_id==User.user_id', cascade='all')
|
|
339
|
followings = relationship('UserFollowing', primaryjoin='UserFollowing.user_id==User.user_id', cascade='all')
|
|
340
|
|
|
340
|
|
|
341
|
repo_to_perm = relationship('UserRepoToPerm', primaryjoin='UserRepoToPerm.user_id==User.user_id', cascade='all')
|
|
341
|
repo_to_perm = relationship('UserRepoToPerm', primaryjoin='UserRepoToPerm.user_id==User.user_id', cascade='all')
|
|
342
|
repo_group_to_perm = relationship('UserRepoGroupToPerm', primaryjoin='UserRepoGroupToPerm.user_id==User.user_id', cascade='all')
|
|
342
|
repo_group_to_perm = relationship('UserRepoGroupToPerm', primaryjoin='UserRepoGroupToPerm.user_id==User.user_id', cascade='all')
|
|
343
|
|
|
343
|
|
|
344
|
group_member = relationship('UsersGroupMember', cascade='all')
|
|
344
|
group_member = relationship('UsersGroupMember', cascade='all')
|
|
345
|
|
|
345
|
|
|
346
|
notifications = relationship('UserNotification', cascade='all')
|
|
346
|
notifications = relationship('UserNotification', cascade='all')
|
|
347
|
# notifications assigned to this user
|
|
347
|
# notifications assigned to this user
|
|
348
|
user_created_notifications = relationship('Notification', cascade='all')
|
|
348
|
user_created_notifications = relationship('Notification', cascade='all')
|
|
349
|
# comments created by this user
|
|
349
|
# comments created by this user
|
|
350
|
user_comments = relationship('ChangesetComment', cascade='all')
|
|
350
|
user_comments = relationship('ChangesetComment', cascade='all')
|
|
351
|
#extra emails for this user
|
|
351
|
#extra emails for this user
|
|
352
|
user_emails = relationship('UserEmailMap', cascade='all')
|
|
352
|
user_emails = relationship('UserEmailMap', cascade='all')
|
|
353
|
|
|
353
|
|
|
354
|
@hybrid_property
|
|
354
|
@hybrid_property
|
|
355
|
def email(self):
|
|
355
|
def email(self):
|
|
356
|
return self._email
|
|
356
|
return self._email
|
|
357
|
|
|
357
|
|
|
358
|
@email.setter
|
|
358
|
@email.setter
|
|
359
|
def email(self, val):
|
|
359
|
def email(self, val):
|
|
360
|
self._email = val.lower() if val else None
|
|
360
|
self._email = val.lower() if val else None
|
|
361
|
|
|
361
|
|
|
362
|
@property
|
|
362
|
@property
|
|
363
|
def firstname(self):
|
|
363
|
def firstname(self):
|
|
364
|
# alias for future
|
|
364
|
# alias for future
|
|
365
|
return self.name
|
|
365
|
return self.name
|
|
366
|
|
|
366
|
|
|
367
|
@property
|
|
367
|
@property
|
|
368
|
def emails(self):
|
|
368
|
def emails(self):
|
|
369
|
other = UserEmailMap.query().filter(UserEmailMap.user==self).all()
|
|
369
|
other = UserEmailMap.query().filter(UserEmailMap.user==self).all()
|
|
370
|
return [self.email] + [x.email for x in other]
|
|
370
|
return [self.email] + [x.email for x in other]
|
|
371
|
|
|
371
|
|
|
372
|
@property
|
|
372
|
@property
|
|
373
|
def ip_addresses(self):
|
|
373
|
def ip_addresses(self):
|
|
374
|
ret = UserIpMap.query().filter(UserIpMap.user == self).all()
|
|
374
|
ret = UserIpMap.query().filter(UserIpMap.user == self).all()
|
|
375
|
return [x.ip_addr for x in ret]
|
|
375
|
return [x.ip_addr for x in ret]
|
|
376
|
|
|
376
|
|
|
377
|
@property
|
|
377
|
@property
|
|
378
|
def username_and_name(self):
|
|
378
|
def username_and_name(self):
|
|
379
|
return '%s (%s %s)' % (self.username, self.firstname, self.lastname)
|
|
379
|
return '%s (%s %s)' % (self.username, self.firstname, self.lastname)
|
|
380
|
|
|
380
|
|
|
381
|
@property
|
|
381
|
@property
|
|
382
|
def full_name(self):
|
|
382
|
def full_name(self):
|
|
383
|
return '%s %s' % (self.firstname, self.lastname)
|
|
383
|
return '%s %s' % (self.firstname, self.lastname)
|
|
384
|
|
|
384
|
|
|
385
|
@property
|
|
385
|
@property
|
|
386
|
def full_name_or_username(self):
|
|
386
|
def full_name_or_username(self):
|
|
387
|
return ('%s %s' % (self.firstname, self.lastname)
|
|
387
|
return ('%s %s' % (self.firstname, self.lastname)
|
|
388
|
if (self.firstname and self.lastname) else self.username)
|
|
388
|
if (self.firstname and self.lastname) else self.username)
|
|
389
|
|
|
389
|
|
|
390
|
@property
|
|
390
|
@property
|
|
391
|
def full_contact(self):
|
|
391
|
def full_contact(self):
|
|
392
|
return '%s %s <%s>' % (self.firstname, self.lastname, self.email)
|
|
392
|
return '%s %s <%s>' % (self.firstname, self.lastname, self.email)
|
|
393
|
|
|
393
|
|
|
394
|
@property
|
|
394
|
@property
|
|
395
|
def short_contact(self):
|
|
395
|
def short_contact(self):
|
|
396
|
return '%s %s' % (self.firstname, self.lastname)
|
|
396
|
return '%s %s' % (self.firstname, self.lastname)
|
|
397
|
|
|
397
|
|
|
398
|
@property
|
|
398
|
@property
|
|
399
|
def is_admin(self):
|
|
399
|
def is_admin(self):
|
|
400
|
return self.admin
|
|
400
|
return self.admin
|
|
401
|
|
|
401
|
|
|
402
|
@property
|
|
402
|
@property
|
|
403
|
def AuthUser(self):
|
|
403
|
def AuthUser(self):
|
|
404
|
"""
|
|
404
|
"""
|
|
405
|
Returns instance of AuthUser for this user
|
|
405
|
Returns instance of AuthUser for this user
|
|
406
|
"""
|
|
406
|
"""
|
|
407
|
from rhodecode.lib.auth import AuthUser
|
|
407
|
from rhodecode.lib.auth import AuthUser
|
|
408
|
return AuthUser(user_id=self.user_id, api_key=self.api_key,
|
|
408
|
return AuthUser(user_id=self.user_id, api_key=self.api_key,
|
|
409
|
username=self.username)
|
|
409
|
username=self.username)
|
|
410
|
|
|
410
|
|
|
411
|
def __unicode__(self):
|
|
411
|
def __unicode__(self):
|
|
412
|
return u"<%s('id:%s:%s')>" % (self.__class__.__name__,
|
|
412
|
return u"<%s('id:%s:%s')>" % (self.__class__.__name__,
|
|
413
|
self.user_id, self.username)
|
|
413
|
self.user_id, self.username)
|
|
414
|
|
|
414
|
|
|
415
|
@classmethod
|
|
415
|
@classmethod
|
|
416
|
def get_by_username(cls, username, case_insensitive=False, cache=False):
|
|
416
|
def get_by_username(cls, username, case_insensitive=False, cache=False):
|
|
417
|
if case_insensitive:
|
|
417
|
if case_insensitive:
|
|
418
|
q = cls.query().filter(cls.username.ilike(username))
|
|
418
|
q = cls.query().filter(cls.username.ilike(username))
|
|
419
|
else:
|
|
419
|
else:
|
|
420
|
q = cls.query().filter(cls.username == username)
|
|
420
|
q = cls.query().filter(cls.username == username)
|
|
421
|
|
|
421
|
|
|
422
|
if cache:
|
|
422
|
if cache:
|
|
423
|
q = q.options(FromCache(
|
|
423
|
q = q.options(FromCache(
|
|
424
|
"sql_cache_short",
|
|
424
|
"sql_cache_short",
|
|
425
|
"get_user_%s" % _hash_key(username)
|
|
425
|
"get_user_%s" % _hash_key(username)
|
|
426
|
)
|
|
426
|
)
|
|
427
|
)
|
|
427
|
)
|
|
428
|
return q.scalar()
|
|
428
|
return q.scalar()
|
|
429
|
|
|
429
|
|
|
430
|
@classmethod
|
|
430
|
@classmethod
|
|
431
|
def get_by_api_key(cls, api_key, cache=False):
|
|
431
|
def get_by_api_key(cls, api_key, cache=False):
|
|
432
|
q = cls.query().filter(cls.api_key == api_key)
|
|
432
|
q = cls.query().filter(cls.api_key == api_key)
|
|
433
|
|
|
433
|
|
|
434
|
if cache:
|
|
434
|
if cache:
|
|
435
|
q = q.options(FromCache("sql_cache_short",
|
|
435
|
q = q.options(FromCache("sql_cache_short",
|
|
436
|
"get_api_key_%s" % api_key))
|
|
436
|
"get_api_key_%s" % api_key))
|
|
437
|
return q.scalar()
|
|
437
|
return q.scalar()
|
|
438
|
|
|
438
|
|
|
439
|
@classmethod
|
|
439
|
@classmethod
|
|
440
|
def get_by_email(cls, email, case_insensitive=False, cache=False):
|
|
440
|
def get_by_email(cls, email, case_insensitive=False, cache=False):
|
|
441
|
if case_insensitive:
|
|
441
|
if case_insensitive:
|
|
442
|
q = cls.query().filter(cls.email.ilike(email))
|
|
442
|
q = cls.query().filter(cls.email.ilike(email))
|
|
443
|
else:
|
|
443
|
else:
|
|
444
|
q = cls.query().filter(cls.email == email)
|
|
444
|
q = cls.query().filter(cls.email == email)
|
|
445
|
|
|
445
|
|
|
446
|
if cache:
|
|
446
|
if cache:
|
|
447
|
q = q.options(FromCache("sql_cache_short",
|
|
447
|
q = q.options(FromCache("sql_cache_short",
|
|
448
|
"get_email_key_%s" % email))
|
|
448
|
"get_email_key_%s" % email))
|
|
449
|
|
|
449
|
|
|
450
|
ret = q.scalar()
|
|
450
|
ret = q.scalar()
|
|
451
|
if ret is None:
|
|
451
|
if ret is None:
|
|
452
|
q = UserEmailMap.query()
|
|
452
|
q = UserEmailMap.query()
|
|
453
|
# try fetching in alternate email map
|
|
453
|
# try fetching in alternate email map
|
|
454
|
if case_insensitive:
|
|
454
|
if case_insensitive:
|
|
455
|
q = q.filter(UserEmailMap.email.ilike(email))
|
|
455
|
q = q.filter(UserEmailMap.email.ilike(email))
|
|
456
|
else:
|
|
456
|
else:
|
|
457
|
q = q.filter(UserEmailMap.email == email)
|
|
457
|
q = q.filter(UserEmailMap.email == email)
|
|
458
|
q = q.options(joinedload(UserEmailMap.user))
|
|
458
|
q = q.options(joinedload(UserEmailMap.user))
|
|
459
|
if cache:
|
|
459
|
if cache:
|
|
460
|
q = q.options(FromCache("sql_cache_short",
|
|
460
|
q = q.options(FromCache("sql_cache_short",
|
|
461
|
"get_email_map_key_%s" % email))
|
|
461
|
"get_email_map_key_%s" % email))
|
|
462
|
ret = getattr(q.scalar(), 'user', None)
|
|
462
|
ret = getattr(q.scalar(), 'user', None)
|
|
463
|
|
|
463
|
|
|
464
|
return ret
|
|
464
|
return ret
|
|
465
|
|
|
465
|
|
|
466
|
@classmethod
|
|
466
|
@classmethod
|
|
467
|
def get_from_cs_author(cls, author):
|
|
467
|
def get_from_cs_author(cls, author):
|
|
468
|
"""
|
|
468
|
"""
|
|
469
|
Tries to get User objects out of commit author string
|
|
469
|
Tries to get User objects out of commit author string
|
|
470
|
|
|
470
|
|
|
471
|
:param author:
|
|
471
|
:param author:
|
|
472
|
"""
|
|
472
|
"""
|
|
473
|
from rhodecode.lib.helpers import email, author_name
|
|
473
|
from rhodecode.lib.helpers import email, author_name
|
|
474
|
# Valid email in the attribute passed, see if they're in the system
|
|
474
|
# Valid email in the attribute passed, see if they're in the system
|
|
475
|
_email = email(author)
|
|
475
|
_email = email(author)
|
|
476
|
if _email:
|
|
476
|
if _email:
|
|
477
|
user = cls.get_by_email(_email, case_insensitive=True)
|
|
477
|
user = cls.get_by_email(_email, case_insensitive=True)
|
|
478
|
if user:
|
|
478
|
if user:
|
|
479
|
return user
|
|
479
|
return user
|
|
480
|
# Maybe we can match by username?
|
|
480
|
# Maybe we can match by username?
|
|
481
|
_author = author_name(author)
|
|
481
|
_author = author_name(author)
|
|
482
|
user = cls.get_by_username(_author, case_insensitive=True)
|
|
482
|
user = cls.get_by_username(_author, case_insensitive=True)
|
|
483
|
if user:
|
|
483
|
if user:
|
|
484
|
return user
|
|
484
|
return user
|
|
485
|
|
|
485
|
|
|
486
|
def update_lastlogin(self):
|
|
486
|
def update_lastlogin(self):
|
|
487
|
"""Update user lastlogin"""
|
|
487
|
"""Update user lastlogin"""
|
|
488
|
self.last_login = datetime.datetime.now()
|
|
488
|
self.last_login = datetime.datetime.now()
|
|
489
|
Session().add(self)
|
|
489
|
Session().add(self)
|
|
490
|
log.debug('updated user %s lastlogin' % self.username)
|
|
490
|
log.debug('updated user %s lastlogin' % self.username)
|
|
491
|
|
|
491
|
|
|
492
|
def get_api_data(self):
|
|
492
|
def get_api_data(self):
|
|
493
|
"""
|
|
493
|
"""
|
|
494
|
Common function for generating user related data for API
|
|
494
|
Common function for generating user related data for API
|
|
495
|
"""
|
|
495
|
"""
|
|
496
|
user = self
|
|
496
|
user = self
|
|
497
|
data = dict(
|
|
497
|
data = dict(
|
|
498
|
user_id=user.user_id,
|
|
498
|
user_id=user.user_id,
|
|
499
|
username=user.username,
|
|
499
|
username=user.username,
|
|
500
|
firstname=user.name,
|
|
500
|
firstname=user.name,
|
|
501
|
lastname=user.lastname,
|
|
501
|
lastname=user.lastname,
|
|
502
|
email=user.email,
|
|
502
|
email=user.email,
|
|
503
|
emails=user.emails,
|
|
503
|
emails=user.emails,
|
|
504
|
api_key=user.api_key,
|
|
504
|
api_key=user.api_key,
|
|
505
|
active=user.active,
|
|
505
|
active=user.active,
|
|
506
|
admin=user.admin,
|
|
506
|
admin=user.admin,
|
|
507
|
ldap_dn=user.ldap_dn,
|
|
507
|
ldap_dn=user.ldap_dn,
|
|
508
|
last_login=user.last_login,
|
|
508
|
last_login=user.last_login,
|
|
509
|
ip_addresses=user.ip_addresses
|
|
509
|
ip_addresses=user.ip_addresses
|
|
510
|
)
|
|
510
|
)
|
|
511
|
return data
|
|
511
|
return data
|
|
512
|
|
|
512
|
|
|
513
|
def __json__(self):
|
|
513
|
def __json__(self):
|
|
514
|
data = dict(
|
|
514
|
data = dict(
|
|
515
|
full_name=self.full_name,
|
|
515
|
full_name=self.full_name,
|
|
516
|
full_name_or_username=self.full_name_or_username,
|
|
516
|
full_name_or_username=self.full_name_or_username,
|
|
517
|
short_contact=self.short_contact,
|
|
517
|
short_contact=self.short_contact,
|
|
518
|
full_contact=self.full_contact
|
|
518
|
full_contact=self.full_contact
|
|
519
|
)
|
|
519
|
)
|
|
520
|
data.update(self.get_api_data())
|
|
520
|
data.update(self.get_api_data())
|
|
521
|
return data
|
|
521
|
return data
|
|
522
|
|
|
522
|
|
|
523
|
|
|
523
|
|
|
524
|
class UserEmailMap(Base, BaseModel):
|
|
524
|
class UserEmailMap(Base, BaseModel):
|
|
525
|
__tablename__ = 'user_email_map'
|
|
525
|
__tablename__ = 'user_email_map'
|
|
526
|
__table_args__ = (
|
|
526
|
__table_args__ = (
|
|
527
|
Index('uem_email_idx', 'email'),
|
|
527
|
Index('uem_email_idx', 'email'),
|
|
528
|
UniqueConstraint('email'),
|
|
528
|
UniqueConstraint('email'),
|
|
529
|
{'extend_existing': True, 'mysql_engine': 'InnoDB',
|
|
529
|
{'extend_existing': True, 'mysql_engine': 'InnoDB',
|
|
530
|
'mysql_charset': 'utf8'}
|
|
530
|
'mysql_charset': 'utf8'}
|
|
531
|
)
|
|
531
|
)
|
|
532
|
__mapper_args__ = {}
|
|
532
|
__mapper_args__ = {}
|
|
533
|
|
|
533
|
|
|
534
|
email_id = Column("email_id", Integer(), nullable=False, unique=True, default=None, primary_key=True)
|
|
534
|
email_id = Column("email_id", Integer(), nullable=False, unique=True, default=None, primary_key=True)
|
|
535
|
user_id = Column("user_id", Integer(), ForeignKey('users.user_id'), nullable=True, unique=None, default=None)
|
|
535
|
user_id = Column("user_id", Integer(), ForeignKey('users.user_id'), nullable=True, unique=None, default=None)
|
|
536
|
_email = Column("email", String(255, convert_unicode=False, assert_unicode=None), nullable=True, unique=False, default=None)
|
|
536
|
_email = Column("email", String(255, convert_unicode=False, assert_unicode=None), nullable=True, unique=False, default=None)
|
|
537
|
user = relationship('User', lazy='joined')
|
|
537
|
user = relationship('User', lazy='joined')
|
|
538
|
|
|
538
|
|
|
539
|
@validates('_email')
|
|
539
|
@validates('_email')
|
|
540
|
def validate_email(self, key, email):
|
|
540
|
def validate_email(self, key, email):
|
|
541
|
# check if this email is not main one
|
|
541
|
# check if this email is not main one
|
|
542
|
main_email = Session().query(User).filter(User.email == email).scalar()
|
|
542
|
main_email = Session().query(User).filter(User.email == email).scalar()
|
|
543
|
if main_email is not None:
|
|
543
|
if main_email is not None:
|
|
544
|
raise AttributeError('email %s is present is user table' % email)
|
|
544
|
raise AttributeError('email %s is present is user table' % email)
|
|
545
|
return email
|
|
545
|
return email
|
|
546
|
|
|
546
|
|
|
547
|
@hybrid_property
|
|
547
|
@hybrid_property
|
|
548
|
def email(self):
|
|
548
|
def email(self):
|
|
549
|
return self._email
|
|
549
|
return self._email
|
|
550
|
|
|
550
|
|
|
551
|
@email.setter
|
|
551
|
@email.setter
|
|
552
|
def email(self, val):
|
|
552
|
def email(self, val):
|
|
553
|
self._email = val.lower() if val else None
|
|
553
|
self._email = val.lower() if val else None
|
|
554
|
|
|
554
|
|
|
555
|
|
|
555
|
|
|
556
|
class UserIpMap(Base, BaseModel):
|
|
556
|
class UserIpMap(Base, BaseModel):
|
|
557
|
__tablename__ = 'user_ip_map'
|
|
557
|
__tablename__ = 'user_ip_map'
|
|
558
|
__table_args__ = (
|
|
558
|
__table_args__ = (
|
|
559
|
UniqueConstraint('user_id', 'ip_addr'),
|
|
559
|
UniqueConstraint('user_id', 'ip_addr'),
|
|
560
|
{'extend_existing': True, 'mysql_engine': 'InnoDB',
|
|
560
|
{'extend_existing': True, 'mysql_engine': 'InnoDB',
|
|
561
|
'mysql_charset': 'utf8'}
|
|
561
|
'mysql_charset': 'utf8'}
|
|
562
|
)
|
|
562
|
)
|
|
563
|
__mapper_args__ = {}
|
|
563
|
__mapper_args__ = {}
|
|
564
|
|
|
564
|
|
|
565
|
ip_id = Column("ip_id", Integer(), nullable=False, unique=True, default=None, primary_key=True)
|
|
565
|
ip_id = Column("ip_id", Integer(), nullable=False, unique=True, default=None, primary_key=True)
|
|
566
|
user_id = Column("user_id", Integer(), ForeignKey('users.user_id'), nullable=True, unique=None, default=None)
|
|
566
|
user_id = Column("user_id", Integer(), ForeignKey('users.user_id'), nullable=True, unique=None, default=None)
|
|
567
|
ip_addr = Column("ip_addr", String(255, convert_unicode=False, assert_unicode=None), nullable=True, unique=False, default=None)
|
|
567
|
ip_addr = Column("ip_addr", String(255, convert_unicode=False, assert_unicode=None), nullable=True, unique=False, default=None)
|
|
568
|
active = Column("active", Boolean(), nullable=True, unique=None, default=True)
|
|
568
|
active = Column("active", Boolean(), nullable=True, unique=None, default=True)
|
|
569
|
user = relationship('User', lazy='joined')
|
|
569
|
user = relationship('User', lazy='joined')
|
|
570
|
|
|
570
|
|
|
571
|
@classmethod
|
|
571
|
@classmethod
|
|
572
|
def _get_ip_range(cls, ip_addr):
|
|
572
|
def _get_ip_range(cls, ip_addr):
|
|
573
|
from rhodecode.lib import ipaddr
|
|
573
|
from rhodecode.lib import ipaddr
|
|
574
|
net = ipaddr.IPNetwork(address=ip_addr)
|
|
574
|
net = ipaddr.IPNetwork(address=ip_addr)
|
|
575
|
return [str(net.network), str(net.broadcast)]
|
|
575
|
return [str(net.network), str(net.broadcast)]
|
|
576
|
|
|
576
|
|
|
577
|
def __json__(self):
|
|
577
|
def __json__(self):
|
|
578
|
return dict(
|
|
578
|
return dict(
|
|
579
|
ip_addr=self.ip_addr,
|
|
579
|
ip_addr=self.ip_addr,
|
|
580
|
ip_range=self._get_ip_range(self.ip_addr)
|
|
580
|
ip_range=self._get_ip_range(self.ip_addr)
|
|
581
|
)
|
|
581
|
)
|
|
582
|
|
|
582
|
|
|
583
|
|
|
583
|
|
|
584
|
class UserLog(Base, BaseModel):
|
|
584
|
class UserLog(Base, BaseModel):
|
|
585
|
__tablename__ = 'user_logs'
|
|
585
|
__tablename__ = 'user_logs'
|
|
586
|
__table_args__ = (
|
|
586
|
__table_args__ = (
|
|
587
|
{'extend_existing': True, 'mysql_engine': 'InnoDB',
|
|
587
|
{'extend_existing': True, 'mysql_engine': 'InnoDB',
|
|
588
|
'mysql_charset': 'utf8'},
|
|
588
|
'mysql_charset': 'utf8'},
|
|
589
|
)
|
|
589
|
)
|
|
590
|
user_log_id = Column("user_log_id", Integer(), nullable=False, unique=True, default=None, primary_key=True)
|
|
590
|
user_log_id = Column("user_log_id", Integer(), nullable=False, unique=True, default=None, primary_key=True)
|
|
591
|
user_id = Column("user_id", Integer(), ForeignKey('users.user_id'), nullable=True, unique=None, default=None)
|
|
591
|
user_id = Column("user_id", Integer(), ForeignKey('users.user_id'), nullable=True, unique=None, default=None)
|
|
592
|
username = Column("username", String(255, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None)
|
|
592
|
username = Column("username", String(255, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None)
|
|
593
|
repository_id = Column("repository_id", Integer(), ForeignKey('repositories.repo_id'), nullable=True)
|
|
593
|
repository_id = Column("repository_id", Integer(), ForeignKey('repositories.repo_id'), nullable=True)
|
|
594
|
repository_name = Column("repository_name", String(255, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None)
|
|
594
|
repository_name = Column("repository_name", String(255, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None)
|
|
595
|
user_ip = Column("user_ip", String(255, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None)
|
|
595
|
user_ip = Column("user_ip", String(255, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None)
|
|
596
|
action = Column("action", UnicodeText(1200000, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None)
|
|
596
|
action = Column("action", UnicodeText(1200000, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None)
|
|
597
|
action_date = Column("action_date", DateTime(timezone=False), nullable=True, unique=None, default=None)
|
|
597
|
action_date = Column("action_date", DateTime(timezone=False), nullable=True, unique=None, default=None)
|
|
598
|
|
|
598
|
|
|
599
|
@property
|
|
599
|
@property
|
|
600
|
def action_as_day(self):
|
|
600
|
def action_as_day(self):
|
|
601
|
return datetime.date(*self.action_date.timetuple()[:3])
|
|
601
|
return datetime.date(*self.action_date.timetuple()[:3])
|
|
602
|
|
|
602
|
|
|
603
|
user = relationship('User')
|
|
603
|
user = relationship('User')
|
|
604
|
repository = relationship('Repository', cascade='')
|
|
604
|
repository = relationship('Repository', cascade='')
|
|
605
|
|
|
605
|
|
|
606
|
|
|
606
|
|
|
607
|
class UsersGroup(Base, BaseModel):
|
|
607
|
class UsersGroup(Base, BaseModel):
|
|
608
|
__tablename__ = 'users_groups'
|
|
608
|
__tablename__ = 'users_groups'
|
|
609
|
__table_args__ = (
|
|
609
|
__table_args__ = (
|
|
610
|
{'extend_existing': True, 'mysql_engine': 'InnoDB',
|
|
610
|
{'extend_existing': True, 'mysql_engine': 'InnoDB',
|
|
611
|
'mysql_charset': 'utf8'},
|
|
611
|
'mysql_charset': 'utf8'},
|
|
612
|
)
|
|
612
|
)
|
|
613
|
|
|
613
|
|
|
614
|
users_group_id = Column("users_group_id", Integer(), nullable=False, unique=True, default=None, primary_key=True)
|
|
614
|
users_group_id = Column("users_group_id", Integer(), nullable=False, unique=True, default=None, primary_key=True)
|
|
615
|
users_group_name = Column("users_group_name", String(255, convert_unicode=False, assert_unicode=None), nullable=False, unique=True, default=None)
|
|
615
|
users_group_name = Column("users_group_name", String(255, convert_unicode=False, assert_unicode=None), nullable=False, unique=True, default=None)
|
|
616
|
users_group_active = Column("users_group_active", Boolean(), nullable=True, unique=None, default=None)
|
|
616
|
users_group_active = Column("users_group_active", Boolean(), nullable=True, unique=None, default=None)
|
|
617
|
inherit_default_permissions = Column("users_group_inherit_default_permissions", Boolean(), nullable=False, unique=None, default=True)
|
|
617
|
inherit_default_permissions = Column("users_group_inherit_default_permissions", Boolean(), nullable=False, unique=None, default=True)
|
|
618
|
|
|
618
|
|
|
619
|
members = relationship('UsersGroupMember', cascade="all, delete, delete-orphan", lazy="joined")
|
|
619
|
members = relationship('UsersGroupMember', cascade="all, delete, delete-orphan", lazy="joined")
|
|
620
|
users_group_to_perm = relationship('UsersGroupToPerm', cascade='all')
|
|
620
|
users_group_to_perm = relationship('UsersGroupToPerm', cascade='all')
|
|
621
|
users_group_repo_to_perm = relationship('UsersGroupRepoToPerm', cascade='all')
|
|
621
|
users_group_repo_to_perm = relationship('UsersGroupRepoToPerm', cascade='all')
|
|
622
|
|
|
622
|
|
|
623
|
def __unicode__(self):
|
|
623
|
def __unicode__(self):
|
|
624
|
return u'<userGroup(%s)>' % (self.users_group_name)
|
|
624
|
return u'<userGroup(%s)>' % (self.users_group_name)
|
|
625
|
|
|
625
|
|
|
626
|
@classmethod
|
|
626
|
@classmethod
|
|
627
|
def get_by_group_name(cls, group_name, cache=False,
|
|
627
|
def get_by_group_name(cls, group_name, cache=False,
|
|
628
|
case_insensitive=False):
|
|
628
|
case_insensitive=False):
|
|
629
|
if case_insensitive:
|
|
629
|
if case_insensitive:
|
|
630
|
q = cls.query().filter(cls.users_group_name.ilike(group_name))
|
|
630
|
q = cls.query().filter(cls.users_group_name.ilike(group_name))
|
|
631
|
else:
|
|
631
|
else:
|
|
632
|
q = cls.query().filter(cls.users_group_name == group_name)
|
|
632
|
q = cls.query().filter(cls.users_group_name == group_name)
|
|
633
|
if cache:
|
|
633
|
if cache:
|
|
634
|
q = q.options(FromCache(
|
|
634
|
q = q.options(FromCache(
|
|
635
|
"sql_cache_short",
|
|
635
|
"sql_cache_short",
|
|
636
|
"get_user_%s" % _hash_key(group_name)
|
|
636
|
"get_user_%s" % _hash_key(group_name)
|
|
637
|
)
|
|
637
|
)
|
|
638
|
)
|
|
638
|
)
|
|
639
|
return q.scalar()
|
|
639
|
return q.scalar()
|
|
640
|
|
|
640
|
|
|
641
|
@classmethod
|
|
641
|
@classmethod
|
|
642
|
def get(cls, users_group_id, cache=False):
|
|
642
|
def get(cls, users_group_id, cache=False):
|
|
643
|
users_group = cls.query()
|
|
643
|
users_group = cls.query()
|
|
644
|
if cache:
|
|
644
|
if cache:
|
|
645
|
users_group = users_group.options(FromCache("sql_cache_short",
|
|
645
|
users_group = users_group.options(FromCache("sql_cache_short",
|
|
646
|
"get_users_group_%s" % users_group_id))
|
|
646
|
"get_users_group_%s" % users_group_id))
|
|
647
|
return users_group.get(users_group_id)
|
|
647
|
return users_group.get(users_group_id)
|
|
648
|
|
|
648
|
|
|
649
|
def get_api_data(self):
|
|
649
|
def get_api_data(self):
|
|
650
|
users_group = self
|
|
650
|
users_group = self
|
|
651
|
|
|
651
|
|
|
652
|
data = dict(
|
|
652
|
data = dict(
|
|
653
|
users_group_id=users_group.users_group_id,
|
|
653
|
users_group_id=users_group.users_group_id,
|
|
654
|
group_name=users_group.users_group_name,
|
|
654
|
group_name=users_group.users_group_name,
|
|
655
|
active=users_group.users_group_active,
|
|
655
|
active=users_group.users_group_active,
|
|
656
|
)
|
|
656
|
)
|
|
657
|
|
|
657
|
|
|
658
|
return data
|
|
658
|
return data
|
|
659
|
|
|
659
|
|
|
660
|
|
|
660
|
|
|
661
|
class UsersGroupMember(Base, BaseModel):
|
|
661
|
class UsersGroupMember(Base, BaseModel):
|
|
662
|
__tablename__ = 'users_groups_members'
|
|
662
|
__tablename__ = 'users_groups_members'
|
|
663
|
__table_args__ = (
|
|
663
|
__table_args__ = (
|
|
664
|
{'extend_existing': True, 'mysql_engine': 'InnoDB',
|
|
664
|
{'extend_existing': True, 'mysql_engine': 'InnoDB',
|
|
665
|
'mysql_charset': 'utf8'},
|
|
665
|
'mysql_charset': 'utf8'},
|
|
666
|
)
|
|
666
|
)
|
|
667
|
|
|
667
|
|
|
668
|
users_group_member_id = Column("users_group_member_id", Integer(), nullable=False, unique=True, default=None, primary_key=True)
|
|
668
|
users_group_member_id = Column("users_group_member_id", Integer(), nullable=False, unique=True, default=None, primary_key=True)
|
|
669
|
users_group_id = Column("users_group_id", Integer(), ForeignKey('users_groups.users_group_id'), nullable=False, unique=None, default=None)
|
|
669
|
users_group_id = Column("users_group_id", Integer(), ForeignKey('users_groups.users_group_id'), nullable=False, unique=None, default=None)
|
|
670
|
user_id = Column("user_id", Integer(), ForeignKey('users.user_id'), nullable=False, unique=None, default=None)
|
|
670
|
user_id = Column("user_id", Integer(), ForeignKey('users.user_id'), nullable=False, unique=None, default=None)
|
|
671
|
|
|
671
|
|
|
672
|
user = relationship('User', lazy='joined')
|
|
672
|
user = relationship('User', lazy='joined')
|
|
673
|
users_group = relationship('UsersGroup')
|
|
673
|
users_group = relationship('UsersGroup')
|
|
674
|
|
|
674
|
|
|
675
|
def __init__(self, gr_id='', u_id=''):
|
|
675
|
def __init__(self, gr_id='', u_id=''):
|
|
676
|
self.users_group_id = gr_id
|
|
676
|
self.users_group_id = gr_id
|
|
677
|
self.user_id = u_id
|
|
677
|
self.user_id = u_id
|
|
678
|
|
|
678
|
|
|
679
|
|
|
679
|
|
|
680
|
class Repository(Base, BaseModel):
|
|
680
|
class Repository(Base, BaseModel):
|
|
681
|
__tablename__ = 'repositories'
|
|
681
|
__tablename__ = 'repositories'
|
|
682
|
__table_args__ = (
|
|
682
|
__table_args__ = (
|
|
683
|
UniqueConstraint('repo_name'),
|
|
683
|
UniqueConstraint('repo_name'),
|
|
684
|
Index('r_repo_name_idx', 'repo_name'),
|
|
684
|
Index('r_repo_name_idx', 'repo_name'),
|
|
685
|
{'extend_existing': True, 'mysql_engine': 'InnoDB',
|
|
685
|
{'extend_existing': True, 'mysql_engine': 'InnoDB',
|
|
686
|
'mysql_charset': 'utf8'},
|
|
686
|
'mysql_charset': 'utf8'},
|
|
687
|
)
|
|
687
|
)
|
|
688
|
|
|
688
|
|
|
689
|
repo_id = Column("repo_id", Integer(), nullable=False, unique=True, default=None, primary_key=True)
|
|
689
|
repo_id = Column("repo_id", Integer(), nullable=False, unique=True, default=None, primary_key=True)
|
|
690
|
repo_name = Column("repo_name", String(255, convert_unicode=False, assert_unicode=None), nullable=False, unique=True, default=None)
|
|
690
|
repo_name = Column("repo_name", String(255, convert_unicode=False, assert_unicode=None), nullable=False, unique=True, default=None)
|
|
691
|
clone_uri = Column("clone_uri", String(255, convert_unicode=False, assert_unicode=None), nullable=True, unique=False, default=None)
|
|
691
|
clone_uri = Column("clone_uri", String(255, convert_unicode=False, assert_unicode=None), nullable=True, unique=False, default=None)
|
|
692
|
repo_type = Column("repo_type", String(255, convert_unicode=False, assert_unicode=None), nullable=False, unique=False, default=None)
|
|
692
|
repo_type = Column("repo_type", String(255, convert_unicode=False, assert_unicode=None), nullable=False, unique=False, default=None)
|
|
693
|
user_id = Column("user_id", Integer(), ForeignKey('users.user_id'), nullable=False, unique=False, default=None)
|
|
693
|
user_id = Column("user_id", Integer(), ForeignKey('users.user_id'), nullable=False, unique=False, default=None)
|
|
694
|
private = Column("private", Boolean(), nullable=True, unique=None, default=None)
|
|
694
|
private = Column("private", Boolean(), nullable=True, unique=None, default=None)
|
|
695
|
enable_statistics = Column("statistics", Boolean(), nullable=True, unique=None, default=True)
|
|
695
|
enable_statistics = Column("statistics", Boolean(), nullable=True, unique=None, default=True)
|
|
696
|
enable_downloads = Column("downloads", Boolean(), nullable=True, unique=None, default=True)
|
|
696
|
enable_downloads = Column("downloads", Boolean(), nullable=True, unique=None, default=True)
|
|
697
|
description = Column("description", String(10000, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None)
|
|
697
|
description = Column("description", String(10000, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None)
|
|
698
|
created_on = Column('created_on', DateTime(timezone=False), nullable=True, unique=None, default=datetime.datetime.now)
|
|
698
|
created_on = Column('created_on', DateTime(timezone=False), nullable=True, unique=None, default=datetime.datetime.now)
|
|
699
|
updated_on = Column('updated_on', DateTime(timezone=False), nullable=True, unique=None, default=datetime.datetime.now)
|
|
699
|
updated_on = Column('updated_on', DateTime(timezone=False), nullable=True, unique=None, default=datetime.datetime.now)
|
|
700
|
landing_rev = Column("landing_revision", String(255, convert_unicode=False, assert_unicode=None), nullable=False, unique=False, default=None)
|
|
700
|
landing_rev = Column("landing_revision", String(255, convert_unicode=False, assert_unicode=None), nullable=False, unique=False, default=None)
|
|
701
|
enable_locking = Column("enable_locking", Boolean(), nullable=False, unique=None, default=False)
|
|
701
|
enable_locking = Column("enable_locking", Boolean(), nullable=False, unique=None, default=False)
|
|
702
|
_locked = Column("locked", String(255, convert_unicode=False, assert_unicode=None), nullable=True, unique=False, default=None)
|
|
702
|
_locked = Column("locked", String(255, convert_unicode=False, assert_unicode=None), nullable=True, unique=False, default=None)
|
|
703
|
_changeset_cache = Column("changeset_cache", LargeBinary(), nullable=True) #JSON data
|
|
703
|
_changeset_cache = Column("changeset_cache", LargeBinary(), nullable=True) #JSON data
|
|
704
|
|
|
704
|
|
|
705
|
fork_id = Column("fork_id", Integer(), ForeignKey('repositories.repo_id'), nullable=True, unique=False, default=None)
|
|
705
|
fork_id = Column("fork_id", Integer(), ForeignKey('repositories.repo_id'), nullable=True, unique=False, default=None)
|
|
706
|
group_id = Column("group_id", Integer(), ForeignKey('groups.group_id'), nullable=True, unique=False, default=None)
|
|
706
|
group_id = Column("group_id", Integer(), ForeignKey('groups.group_id'), nullable=True, unique=False, default=None)
|
|
707
|
|
|
707
|
|
|
708
|
user = relationship('User')
|
|
708
|
user = relationship('User')
|
|
709
|
fork = relationship('Repository', remote_side=repo_id)
|
|
709
|
fork = relationship('Repository', remote_side=repo_id)
|
|
710
|
group = relationship('RepoGroup')
|
|
710
|
group = relationship('RepoGroup')
|
|
711
|
repo_to_perm = relationship('UserRepoToPerm', cascade='all', order_by='UserRepoToPerm.repo_to_perm_id')
|
|
711
|
repo_to_perm = relationship('UserRepoToPerm', cascade='all', order_by='UserRepoToPerm.repo_to_perm_id')
|
|
712
|
users_group_to_perm = relationship('UsersGroupRepoToPerm', cascade='all')
|
|
712
|
users_group_to_perm = relationship('UsersGroupRepoToPerm', cascade='all')
|
|
713
|
stats = relationship('Statistics', cascade='all', uselist=False)
|
|
713
|
stats = relationship('Statistics', cascade='all', uselist=False)
|
|
714
|
|
|
714
|
|
|
715
|
followers = relationship('UserFollowing',
|
|
715
|
followers = relationship('UserFollowing',
|
|
716
|
primaryjoin='UserFollowing.follows_repo_id==Repository.repo_id',
|
|
716
|
primaryjoin='UserFollowing.follows_repo_id==Repository.repo_id',
|
|
717
|
cascade='all')
|
|
717
|
cascade='all')
|
|
718
|
|
|
718
|
|
|
719
|
logs = relationship('UserLog')
|
|
719
|
logs = relationship('UserLog')
|
|
720
|
comments = relationship('ChangesetComment', cascade="all, delete, delete-orphan")
|
|
720
|
comments = relationship('ChangesetComment', cascade="all, delete, delete-orphan")
|
|
721
|
|
|
721
|
|
|
722
|
pull_requests_org = relationship('PullRequest',
|
|
722
|
pull_requests_org = relationship('PullRequest',
|
|
723
|
primaryjoin='PullRequest.org_repo_id==Repository.repo_id',
|
|
723
|
primaryjoin='PullRequest.org_repo_id==Repository.repo_id',
|
|
724
|
cascade="all, delete, delete-orphan")
|
|
724
|
cascade="all, delete, delete-orphan")
|
|
725
|
|
|
725
|
|
|
726
|
pull_requests_other = relationship('PullRequest',
|
|
726
|
pull_requests_other = relationship('PullRequest',
|
|
727
|
primaryjoin='PullRequest.other_repo_id==Repository.repo_id',
|
|
727
|
primaryjoin='PullRequest.other_repo_id==Repository.repo_id',
|
|
728
|
cascade="all, delete, delete-orphan")
|
|
728
|
cascade="all, delete, delete-orphan")
|
|
729
|
|
|
729
|
|
|
730
|
def __unicode__(self):
|
|
730
|
def __unicode__(self):
|
|
731
|
return u"<%s('%s:%s')>" % (self.__class__.__name__, self.repo_id,
|
|
731
|
return u"<%s('%s:%s')>" % (self.__class__.__name__, self.repo_id,
|
|
732
|
self.repo_name)
|
|
732
|
self.repo_name)
|
|
733
|
|
|
733
|
|
|
734
|
@hybrid_property
|
|
734
|
@hybrid_property
|
|
735
|
def locked(self):
|
|
735
|
def locked(self):
|
|
736
|
# always should return [user_id, timelocked]
|
|
736
|
# always should return [user_id, timelocked]
|
|
737
|
if self._locked:
|
|
737
|
if self._locked:
|
|
738
|
_lock_info = self._locked.split(':')
|
|
738
|
_lock_info = self._locked.split(':')
|
|
739
|
return int(_lock_info[0]), _lock_info[1]
|
|
739
|
return int(_lock_info[0]), _lock_info[1]
|
|
740
|
return [None, None]
|
|
740
|
return [None, None]
|
|
741
|
|
|
741
|
|
|
742
|
@locked.setter
|
|
742
|
@locked.setter
|
|
743
|
def locked(self, val):
|
|
743
|
def locked(self, val):
|
|
744
|
if val and isinstance(val, (list, tuple)):
|
|
744
|
if val and isinstance(val, (list, tuple)):
|
|
745
|
self._locked = ':'.join(map(str, val))
|
|
745
|
self._locked = ':'.join(map(str, val))
|
|
746
|
else:
|
|
746
|
else:
|
|
747
|
self._locked = None
|
|
747
|
self._locked = None
|
|
748
|
|
|
748
|
|
|
749
|
@hybrid_property
|
|
749
|
@hybrid_property
|
|
750
|
def changeset_cache(self):
|
|
750
|
def changeset_cache(self):
|
|
751
|
from rhodecode.lib.vcs.backends.base import EmptyChangeset
|
|
751
|
from rhodecode.lib.vcs.backends.base import EmptyChangeset
|
|
752
|
dummy = EmptyChangeset().__json__()
|
|
752
|
dummy = EmptyChangeset().__json__()
|
|
753
|
if not self._changeset_cache:
|
|
753
|
if not self._changeset_cache:
|
|
754
|
return dummy
|
|
754
|
return dummy
|
|
755
|
try:
|
|
755
|
try:
|
|
756
|
return json.loads(self._changeset_cache)
|
|
756
|
return json.loads(self._changeset_cache)
|
|
757
|
except TypeError:
|
|
757
|
except TypeError:
|
|
758
|
return dummy
|
|
758
|
return dummy
|
|
759
|
|
|
759
|
|
|
760
|
@changeset_cache.setter
|
|
760
|
@changeset_cache.setter
|
|
761
|
def changeset_cache(self, val):
|
|
761
|
def changeset_cache(self, val):
|
|
762
|
try:
|
|
762
|
try:
|
|
763
|
self._changeset_cache = json.dumps(val)
|
|
763
|
self._changeset_cache = json.dumps(val)
|
|
764
|
except:
|
|
764
|
except:
|
|
765
|
log.error(traceback.format_exc())
|
|
765
|
log.error(traceback.format_exc())
|
|
766
|
|
|
766
|
|
|
767
|
@classmethod
|
|
767
|
@classmethod
|
|
768
|
def url_sep(cls):
|
|
768
|
def url_sep(cls):
|
|
769
|
return URL_SEP
|
|
769
|
return URL_SEP
|
|
770
|
|
|
770
|
|
|
771
|
@classmethod
|
|
771
|
@classmethod
|
|
772
|
def normalize_repo_name(cls, repo_name):
|
|
772
|
def normalize_repo_name(cls, repo_name):
|
|
773
|
"""
|
|
773
|
"""
|
|
774
|
Normalizes os specific repo_name to the format internally stored inside
|
|
774
|
Normalizes os specific repo_name to the format internally stored inside
|
|
775
|
dabatabase using URL_SEP
|
|
775
|
dabatabase using URL_SEP
|
|
776
|
|
|
776
|
|
|
777
|
:param cls:
|
|
777
|
:param cls:
|
|
778
|
:param repo_name:
|
|
778
|
:param repo_name:
|
|
779
|
"""
|
|
779
|
"""
|
|
780
|
return cls.url_sep().join(repo_name.split(os.sep))
|
|
780
|
return cls.url_sep().join(repo_name.split(os.sep))
|
|
781
|
|
|
781
|
|
|
782
|
@classmethod
|
|
782
|
@classmethod
|
|
783
|
def get_by_repo_name(cls, repo_name):
|
|
783
|
def get_by_repo_name(cls, repo_name):
|
|
784
|
q = Session().query(cls).filter(cls.repo_name == repo_name)
|
|
784
|
q = Session().query(cls).filter(cls.repo_name == repo_name)
|
|
785
|
q = q.options(joinedload(Repository.fork))\
|
|
785
|
q = q.options(joinedload(Repository.fork))\
|
|
786
|
.options(joinedload(Repository.user))\
|
|
786
|
.options(joinedload(Repository.user))\
|
|
787
|
.options(joinedload(Repository.group))
|
|
787
|
.options(joinedload(Repository.group))
|
|
788
|
return q.scalar()
|
|
788
|
return q.scalar()
|
|
789
|
|
|
789
|
|
|
790
|
@classmethod
|
|
790
|
@classmethod
|
|
791
|
def get_by_full_path(cls, repo_full_path):
|
|
791
|
def get_by_full_path(cls, repo_full_path):
|
|
792
|
repo_name = repo_full_path.split(cls.base_path(), 1)[-1]
|
|
792
|
repo_name = repo_full_path.split(cls.base_path(), 1)[-1]
|
|
793
|
repo_name = cls.normalize_repo_name(repo_name)
|
|
793
|
repo_name = cls.normalize_repo_name(repo_name)
|
|
794
|
return cls.get_by_repo_name(repo_name.strip(URL_SEP))
|
|
794
|
return cls.get_by_repo_name(repo_name.strip(URL_SEP))
|
|
795
|
|
|
795
|
|
|
796
|
@classmethod
|
|
796
|
@classmethod
|
|
797
|
def get_repo_forks(cls, repo_id):
|
|
797
|
def get_repo_forks(cls, repo_id):
|
|
798
|
return cls.query().filter(Repository.fork_id == repo_id)
|
|
798
|
return cls.query().filter(Repository.fork_id == repo_id)
|
|
799
|
|
|
799
|
|
|
800
|
@classmethod
|
|
800
|
@classmethod
|
|
801
|
def base_path(cls):
|
|
801
|
def base_path(cls):
|
|
802
|
"""
|
|
802
|
"""
|
|
803
|
Returns base path when all repos are stored
|
|
803
|
Returns base path when all repos are stored
|
|
804
|
|
|
804
|
|
|
805
|
:param cls:
|
|
805
|
:param cls:
|
|
806
|
"""
|
|
806
|
"""
|
|
807
|
q = Session().query(RhodeCodeUi)\
|
|
807
|
q = Session().query(RhodeCodeUi)\
|
|
808
|
.filter(RhodeCodeUi.ui_key == cls.url_sep())
|
|
808
|
.filter(RhodeCodeUi.ui_key == cls.url_sep())
|
|
809
|
q = q.options(FromCache("sql_cache_short", "repository_repo_path"))
|
|
809
|
q = q.options(FromCache("sql_cache_short", "repository_repo_path"))
|
|
810
|
return q.one().ui_value
|
|
810
|
return q.one().ui_value
|
|
811
|
|
|
811
|
|
|
812
|
@property
|
|
812
|
@property
|
|
813
|
def forks(self):
|
|
813
|
def forks(self):
|
|
814
|
"""
|
|
814
|
"""
|
|
815
|
Return forks of this repo
|
|
815
|
Return forks of this repo
|
|
816
|
"""
|
|
816
|
"""
|
|
817
|
return Repository.get_repo_forks(self.repo_id)
|
|
817
|
return Repository.get_repo_forks(self.repo_id)
|
|
818
|
|
|
818
|
|
|
819
|
@property
|
|
819
|
@property
|
|
820
|
def parent(self):
|
|
820
|
def parent(self):
|
|
821
|
"""
|
|
821
|
"""
|
|
822
|
Returns fork parent
|
|
822
|
Returns fork parent
|
|
823
|
"""
|
|
823
|
"""
|
|
824
|
return self.fork
|
|
824
|
return self.fork
|
|
825
|
|
|
825
|
|
|
826
|
@property
|
|
826
|
@property
|
|
827
|
def just_name(self):
|
|
827
|
def just_name(self):
|
|
828
|
return self.repo_name.split(Repository.url_sep())[-1]
|
|
828
|
return self.repo_name.split(Repository.url_sep())[-1]
|
|
829
|
|
|
829
|
|
|
830
|
@property
|
|
830
|
@property
|
|
831
|
def groups_with_parents(self):
|
|
831
|
def groups_with_parents(self):
|
|
832
|
groups = []
|
|
832
|
groups = []
|
|
833
|
if self.group is None:
|
|
833
|
if self.group is None:
|
|
834
|
return groups
|
|
834
|
return groups
|
|
835
|
|
|
835
|
|
|
836
|
cur_gr = self.group
|
|
836
|
cur_gr = self.group
|
|
837
|
groups.insert(0, cur_gr)
|
|
837
|
groups.insert(0, cur_gr)
|
|
838
|
while 1:
|
|
838
|
while 1:
|
|
839
|
gr = getattr(cur_gr, 'parent_group', None)
|
|
839
|
gr = getattr(cur_gr, 'parent_group', None)
|
|
840
|
cur_gr = cur_gr.parent_group
|
|
840
|
cur_gr = cur_gr.parent_group
|
|
841
|
if gr is None:
|
|
841
|
if gr is None:
|
|
842
|
break
|
|
842
|
break
|
|
843
|
groups.insert(0, gr)
|
|
843
|
groups.insert(0, gr)
|
|
844
|
|
|
844
|
|
|
845
|
return groups
|
|
845
|
return groups
|
|
846
|
|
|
846
|
|
|
847
|
@property
|
|
847
|
@property
|
|
848
|
def groups_and_repo(self):
|
|
848
|
def groups_and_repo(self):
|
|
849
|
return self.groups_with_parents, self.just_name
|
|
849
|
return self.groups_with_parents, self.just_name
|
|
850
|
|
|
850
|
|
|
851
|
@LazyProperty
|
|
851
|
@LazyProperty
|
|
852
|
def repo_path(self):
|
|
852
|
def repo_path(self):
|
|
853
|
"""
|
|
853
|
"""
|
|
854
|
Returns base full path for that repository means where it actually
|
|
854
|
Returns base full path for that repository means where it actually
|
|
855
|
exists on a filesystem
|
|
855
|
exists on a filesystem
|
|
856
|
"""
|
|
856
|
"""
|
|
857
|
q = Session().query(RhodeCodeUi).filter(RhodeCodeUi.ui_key ==
|
|
857
|
q = Session().query(RhodeCodeUi).filter(RhodeCodeUi.ui_key ==
|
|
858
|
Repository.url_sep())
|
|
858
|
Repository.url_sep())
|
|
859
|
q = q.options(FromCache("sql_cache_short", "repository_repo_path"))
|
|
859
|
q = q.options(FromCache("sql_cache_short", "repository_repo_path"))
|
|
860
|
return q.one().ui_value
|
|
860
|
return q.one().ui_value
|
|
861
|
|
|
861
|
|
|
862
|
@property
|
|
862
|
@property
|
|
863
|
def repo_full_path(self):
|
|
863
|
def repo_full_path(self):
|
|
864
|
p = [self.repo_path]
|
|
864
|
p = [self.repo_path]
|
|
865
|
# we need to split the name by / since this is how we store the
|
|
865
|
# we need to split the name by / since this is how we store the
|
|
866
|
# names in the database, but that eventually needs to be converted
|
|
866
|
# names in the database, but that eventually needs to be converted
|
|
867
|
# into a valid system path
|
|
867
|
# into a valid system path
|
|
868
|
p += self.repo_name.split(Repository.url_sep())
|
|
868
|
p += self.repo_name.split(Repository.url_sep())
|
|
869
|
return os.path.join(*p)
|
|
869
|
return os.path.join(*p)
|
|
870
|
|
|
870
|
|
|
871
|
@property
|
|
871
|
@property
|
|
872
|
def cache_keys(self):
|
|
872
|
def cache_keys(self):
|
|
873
|
"""
|
|
873
|
"""
|
|
874
|
Returns associated cache keys for that repo
|
|
874
|
Returns associated cache keys for that repo
|
|
875
|
"""
|
|
875
|
"""
|
|
876
|
return CacheInvalidation.query()\
|
|
876
|
return CacheInvalidation.query()\
|
|
877
|
.filter(CacheInvalidation.cache_args == self.repo_name)\
|
|
877
|
.filter(CacheInvalidation.cache_args == self.repo_name)\
|
|
878
|
.order_by(CacheInvalidation.cache_key)\
|
|
878
|
.order_by(CacheInvalidation.cache_key)\
|
|
879
|
.all()
|
|
879
|
.all()
|
|
880
|
|
|
880
|
|
|
881
|
def get_new_name(self, repo_name):
|
|
881
|
def get_new_name(self, repo_name):
|
|
882
|
"""
|
|
882
|
"""
|
|
883
|
returns new full repository name based on assigned group and new new
|
|
883
|
returns new full repository name based on assigned group and new new
|
|
884
|
|
|
884
|
|
|
885
|
:param group_name:
|
|
885
|
:param group_name:
|
|
886
|
"""
|
|
886
|
"""
|
|
887
|
path_prefix = self.group.full_path_splitted if self.group else []
|
|
887
|
path_prefix = self.group.full_path_splitted if self.group else []
|
|
888
|
return Repository.url_sep().join(path_prefix + [repo_name])
|
|
888
|
return Repository.url_sep().join(path_prefix + [repo_name])
|
|
889
|
|
|
889
|
|
|
890
|
@property
|
|
890
|
@property
|
|
891
|
def _ui(self):
|
|
891
|
def _ui(self):
|
|
892
|
"""
|
|
892
|
"""
|
|
893
|
Creates an db based ui object for this repository
|
|
893
|
Creates an db based ui object for this repository
|
|
894
|
"""
|
|
894
|
"""
|
|
895
|
from rhodecode.lib.utils import make_ui
|
|
895
|
from rhodecode.lib.utils import make_ui
|
|
896
|
return make_ui('db', clear_session=False)
|
|
896
|
return make_ui('db', clear_session=False)
|
|
897
|
|
|
897
|
|
|
898
|
@classmethod
|
|
898
|
@classmethod
|
|
899
|
def inject_ui(cls, repo, extras={}):
|
|
899
|
def inject_ui(cls, repo, extras={}):
|
|
900
|
from rhodecode.lib.vcs.backends.hg import MercurialRepository
|
|
900
|
from rhodecode.lib.vcs.backends.hg import MercurialRepository
|
|
901
|
from rhodecode.lib.vcs.backends.git import GitRepository
|
|
901
|
from rhodecode.lib.vcs.backends.git import GitRepository
|
|
902
|
required = (MercurialRepository, GitRepository)
|
|
902
|
required = (MercurialRepository, GitRepository)
|
|
903
|
if not isinstance(repo, required):
|
|
903
|
if not isinstance(repo, required):
|
|
904
|
raise Exception('repo must be instance of %s' % required)
|
|
904
|
raise Exception('repo must be instance of %s' % required)
|
|
905
|
|
|
905
|
|
|
906
|
# inject ui extra param to log this action via push logger
|
|
906
|
# inject ui extra param to log this action via push logger
|
|
907
|
for k, v in extras.items():
|
|
907
|
for k, v in extras.items():
|
|
908
|
repo._repo.ui.setconfig('rhodecode_extras', k, v)
|
|
908
|
repo._repo.ui.setconfig('rhodecode_extras', k, v)
|
|
909
|
|
|
909
|
|
|
910
|
@classmethod
|
|
910
|
@classmethod
|
|
911
|
def is_valid(cls, repo_name):
|
|
911
|
def is_valid(cls, repo_name):
|
|
912
|
"""
|
|
912
|
"""
|
|
913
|
returns True if given repo name is a valid filesystem repository
|
|
913
|
returns True if given repo name is a valid filesystem repository
|
|
914
|
|
|
914
|
|
|
915
|
:param cls:
|
|
915
|
:param cls:
|
|
916
|
:param repo_name:
|
|
916
|
:param repo_name:
|
|
917
|
"""
|
|
917
|
"""
|
|
918
|
from rhodecode.lib.utils import is_valid_repo
|
|
918
|
from rhodecode.lib.utils import is_valid_repo
|
|
919
|
|
|
919
|
|
|
920
|
return is_valid_repo(repo_name, cls.base_path())
|
|
920
|
return is_valid_repo(repo_name, cls.base_path())
|
|
921
|
|
|
921
|
|
|
922
|
def get_api_data(self):
|
|
922
|
def get_api_data(self):
|
|
923
|
"""
|
|
923
|
"""
|
|
924
|
Common function for generating repo api data
|
|
924
|
Common function for generating repo api data
|
|
925
|
|
|
925
|
|
|
926
|
"""
|
|
926
|
"""
|
|
927
|
repo = self
|
|
927
|
repo = self
|
|
928
|
data = dict(
|
|
928
|
data = dict(
|
|
929
|
repo_id=repo.repo_id,
|
|
929
|
repo_id=repo.repo_id,
|
|
930
|
repo_name=repo.repo_name,
|
|
930
|
repo_name=repo.repo_name,
|
|
931
|
repo_type=repo.repo_type,
|
|
931
|
repo_type=repo.repo_type,
|
|
932
|
clone_uri=repo.clone_uri,
|
|
932
|
clone_uri=repo.clone_uri,
|
|
933
|
private=repo.private,
|
|
933
|
private=repo.private,
|
|
934
|
created_on=repo.created_on,
|
|
934
|
created_on=repo.created_on,
|
|
935
|
description=repo.description,
|
|
935
|
description=repo.description,
|
|
936
|
landing_rev=repo.landing_rev,
|
|
936
|
landing_rev=repo.landing_rev,
|
|
937
|
owner=repo.user.username,
|
|
937
|
owner=repo.user.username,
|
|
938
|
fork_of=repo.fork.repo_name if repo.fork else None,
|
|
938
|
fork_of=repo.fork.repo_name if repo.fork else None,
|
|
939
|
enable_statistics=repo.enable_statistics,
|
|
939
|
enable_statistics=repo.enable_statistics,
|
|
940
|
enable_locking=repo.enable_locking,
|
|
940
|
enable_locking=repo.enable_locking,
|
|
941
|
enable_downloads=repo.enable_downloads,
|
|
941
|
enable_downloads=repo.enable_downloads,
|
|
942
|
last_changeset=repo.changeset_cache
|
|
942
|
last_changeset=repo.changeset_cache
|
|
943
|
)
|
|
943
|
)
|
|
944
|
|
|
944
|
|
|
945
|
return data
|
|
945
|
return data
|
|
946
|
|
|
946
|
|
|
947
|
@classmethod
|
|
947
|
@classmethod
|
|
948
|
def lock(cls, repo, user_id):
|
|
948
|
def lock(cls, repo, user_id):
|
|
949
|
repo.locked = [user_id, time.time()]
|
|
949
|
repo.locked = [user_id, time.time()]
|
|
950
|
Session().add(repo)
|
|
950
|
Session().add(repo)
|
|
951
|
Session().commit()
|
|
951
|
Session().commit()
|
|
952
|
|
|
952
|
|
|
953
|
@classmethod
|
|
953
|
@classmethod
|
|
954
|
def unlock(cls, repo):
|
|
954
|
def unlock(cls, repo):
|
|
955
|
repo.locked = None
|
|
955
|
repo.locked = None
|
|
956
|
Session().add(repo)
|
|
956
|
Session().add(repo)
|
|
957
|
Session().commit()
|
|
957
|
Session().commit()
|
|
958
|
|
|
958
|
|
|
959
|
@property
|
|
959
|
@property
|
|
960
|
def last_db_change(self):
|
|
960
|
def last_db_change(self):
|
|
961
|
return self.updated_on
|
|
961
|
return self.updated_on
|
|
962
|
|
|
962
|
|
|
963
|
def clone_url(self, **override):
|
|
963
|
def clone_url(self, **override):
|
|
964
|
from pylons import url
|
|
964
|
from pylons import url
|
|
965
|
from urlparse import urlparse
|
|
965
|
from urlparse import urlparse
|
|
966
|
import urllib
|
|
966
|
import urllib
|
|
967
|
parsed_url = urlparse(url('home', qualified=True))
|
|
967
|
parsed_url = urlparse(url('home', qualified=True))
|
|
968
|
default_clone_uri = '%(scheme)s://%(user)s%(pass)s%(netloc)s%(prefix)s%(path)s'
|
|
968
|
default_clone_uri = '%(scheme)s://%(user)s%(pass)s%(netloc)s%(prefix)s%(path)s'
|
|
969
|
decoded_path = safe_unicode(urllib.unquote(parsed_url.path))
|
|
969
|
decoded_path = safe_unicode(urllib.unquote(parsed_url.path))
|
|
970
|
args = {
|
|
970
|
args = {
|
|
971
|
'user': '',
|
|
971
|
'user': '',
|
|
972
|
'pass': '',
|
|
972
|
'pass': '',
|
|
973
|
'scheme': parsed_url.scheme,
|
|
973
|
'scheme': parsed_url.scheme,
|
|
974
|
'netloc': parsed_url.netloc,
|
|
974
|
'netloc': parsed_url.netloc,
|
|
975
|
'prefix': decoded_path,
|
|
975
|
'prefix': decoded_path,
|
|
976
|
'path': self.repo_name
|
|
976
|
'path': self.repo_name
|
|
977
|
}
|
|
977
|
}
|
|
978
|
|
|
978
|
|
|
979
|
args.update(override)
|
|
979
|
args.update(override)
|
|
980
|
return default_clone_uri % args
|
|
980
|
return default_clone_uri % args
|
|
981
|
|
|
981
|
|
|
982
|
#==========================================================================
|
|
982
|
#==========================================================================
|
|
983
|
# SCM PROPERTIES
|
|
983
|
# SCM PROPERTIES
|
|
984
|
#==========================================================================
|
|
984
|
#==========================================================================
|
|
985
|
|
|
985
|
|
|
986
|
def get_changeset(self, rev=None):
|
|
986
|
def get_changeset(self, rev=None):
|
|
987
|
return get_changeset_safe(self.scm_instance, rev)
|
|
987
|
return get_changeset_safe(self.scm_instance, rev)
|
|
988
|
|
|
988
|
|
|
989
|
def get_landing_changeset(self):
|
|
989
|
def get_landing_changeset(self):
|
|
990
|
"""
|
|
990
|
"""
|
|
991
|
Returns landing changeset, or if that doesn't exist returns the tip
|
|
991
|
Returns landing changeset, or if that doesn't exist returns the tip
|
|
992
|
"""
|
|
992
|
"""
|
|
993
|
cs = self.get_changeset(self.landing_rev) or self.get_changeset()
|
|
993
|
cs = self.get_changeset(self.landing_rev) or self.get_changeset()
|
|
994
|
return cs
|
|
994
|
return cs
|
|
995
|
|
|
995
|
|
|
996
|
def update_changeset_cache(self, cs_cache=None):
|
|
996
|
def update_changeset_cache(self, cs_cache=None):
|
|
997
|
"""
|
|
997
|
"""
|
|
998
|
Update cache of last changeset for repository, keys should be::
|
|
998
|
Update cache of last changeset for repository, keys should be::
|
|
999
|
|
|
999
|
|
|
1000
|
short_id
|
|
1000
|
short_id
|
|
1001
|
raw_id
|
|
1001
|
raw_id
|
|
1002
|
revision
|
|
1002
|
revision
|
|
1003
|
message
|
|
1003
|
message
|
|
1004
|
date
|
|
1004
|
date
|
|
1005
|
author
|
|
1005
|
author
|
|
1006
|
|
|
1006
|
|
|
1007
|
:param cs_cache:
|
|
1007
|
:param cs_cache:
|
|
1008
|
"""
|
|
1008
|
"""
|
|
1009
|
from rhodecode.lib.vcs.backends.base import BaseChangeset
|
|
1009
|
from rhodecode.lib.vcs.backends.base import BaseChangeset
|
|
1010
|
if cs_cache is None:
|
|
1010
|
if cs_cache is None:
|
|
1011
|
cs_cache = self.get_changeset()
|
|
1011
|
cs_cache = self.get_changeset()
|
|
1012
|
if isinstance(cs_cache, BaseChangeset):
|
|
1012
|
if isinstance(cs_cache, BaseChangeset):
|
|
1013
|
cs_cache = cs_cache.__json__()
|
|
1013
|
cs_cache = cs_cache.__json__()
|
|
1014
|
|
|
1014
|
|
|
1015
|
if (cs_cache != self.changeset_cache
|
|
1015
|
if (cs_cache != self.changeset_cache
|
|
1016
|
or not self.last_change
|
|
1016
|
or not self.last_change
|
|
1017
|
or not self.changeset_cache):
|
|
1017
|
or not self.changeset_cache):
|
|
1018
|
_default = datetime.datetime.fromtimestamp(0)
|
|
1018
|
_default = datetime.datetime.fromtimestamp(0)
|
|
1019
|
last_change = cs_cache.get('date') or self.last_change or _default
|
|
1019
|
last_change = cs_cache.get('date') or self.last_change or _default
|
|
1020
|
log.debug('updated repo %s with new cs cache %s' % (self, cs_cache))
|
|
1020
|
log.debug('updated repo %s with new cs cache %s' % (self, cs_cache))
|
|
1021
|
self.updated_on = last_change
|
|
1021
|
self.updated_on = last_change
|
|
1022
|
self.changeset_cache = cs_cache
|
|
1022
|
self.changeset_cache = cs_cache
|
|
1023
|
Session().add(self)
|
|
1023
|
Session().add(self)
|
|
1024
|
Session().commit()
|
|
1024
|
Session().commit()
|
|
1025
|
else:
|
|
1025
|
else:
|
|
1026
|
log.debug('Skipping repo:%s already with latest changes' % self)
|
|
1026
|
log.debug('Skipping repo:%s already with latest changes' % self)
|
|
1027
|
|
|
1027
|
|
|
1028
|
@property
|
|
1028
|
@property
|
|
1029
|
def tip(self):
|
|
1029
|
def tip(self):
|
|
1030
|
return self.get_changeset('tip')
|
|
1030
|
return self.get_changeset('tip')
|
|
1031
|
|
|
1031
|
|
|
1032
|
@property
|
|
1032
|
@property
|
|
1033
|
def author(self):
|
|
1033
|
def author(self):
|
|
1034
|
return self.tip.author
|
|
1034
|
return self.tip.author
|
|
1035
|
|
|
1035
|
|
|
1036
|
@property
|
|
1036
|
@property
|
|
1037
|
def last_change(self):
|
|
1037
|
def last_change(self):
|
|
1038
|
return self.scm_instance.last_change
|
|
1038
|
return self.scm_instance.last_change
|
|
1039
|
|
|
1039
|
|
|
1040
|
def get_comments(self, revisions=None):
|
|
1040
|
def get_comments(self, revisions=None):
|
|
1041
|
"""
|
|
1041
|
"""
|
|
1042
|
Returns comments for this repository grouped by revisions
|
|
1042
|
Returns comments for this repository grouped by revisions
|
|
1043
|
|
|
1043
|
|
|
1044
|
:param revisions: filter query by revisions only
|
|
1044
|
:param revisions: filter query by revisions only
|
|
1045
|
"""
|
|
1045
|
"""
|
|
1046
|
cmts = ChangesetComment.query()\
|
|
1046
|
cmts = ChangesetComment.query()\
|
|
1047
|
.filter(ChangesetComment.repo == self)
|
|
1047
|
.filter(ChangesetComment.repo == self)
|
|
1048
|
if revisions:
|
|
1048
|
if revisions:
|
|
1049
|
cmts = cmts.filter(ChangesetComment.revision.in_(revisions))
|
|
1049
|
cmts = cmts.filter(ChangesetComment.revision.in_(revisions))
|
|
1050
|
grouped = defaultdict(list)
|
|
1050
|
grouped = defaultdict(list)
|
|
1051
|
for cmt in cmts.all():
|
|
1051
|
for cmt in cmts.all():
|
|
1052
|
grouped[cmt.revision].append(cmt)
|
|
1052
|
grouped[cmt.revision].append(cmt)
|
|
1053
|
return grouped
|
|
1053
|
return grouped
|
|
1054
|
|
|
1054
|
|
|
1055
|
def statuses(self, revisions=None):
|
|
1055
|
def statuses(self, revisions=None):
|
|
1056
|
"""
|
|
1056
|
"""
|
|
1057
|
Returns statuses for this repository
|
|
1057
|
Returns statuses for this repository
|
|
1058
|
|
|
1058
|
|
|
1059
|
:param revisions: list of revisions to get statuses for
|
|
1059
|
:param revisions: list of revisions to get statuses for
|
|
1060
|
:type revisions: list
|
|
1060
|
:type revisions: list
|
|
1061
|
"""
|
|
1061
|
"""
|
|
1062
|
|
|
1062
|
|
|
1063
|
statuses = ChangesetStatus.query()\
|
|
1063
|
statuses = ChangesetStatus.query()\
|
|
1064
|
.filter(ChangesetStatus.repo == self)\
|
|
1064
|
.filter(ChangesetStatus.repo == self)\
|
|
1065
|
.filter(ChangesetStatus.version == 0)
|
|
1065
|
.filter(ChangesetStatus.version == 0)
|
|
1066
|
if revisions:
|
|
1066
|
if revisions:
|
|
1067
|
statuses = statuses.filter(ChangesetStatus.revision.in_(revisions))
|
|
1067
|
statuses = statuses.filter(ChangesetStatus.revision.in_(revisions))
|
|
1068
|
grouped = {}
|
|
1068
|
grouped = {}
|
|
1069
|
|
|
1069
|
|
|
1070
|
#maybe we have open new pullrequest without a status ?
|
|
1070
|
#maybe we have open new pullrequest without a status ?
|
|
1071
|
stat = ChangesetStatus.STATUS_UNDER_REVIEW
|
|
1071
|
stat = ChangesetStatus.STATUS_UNDER_REVIEW
|
|
1072
|
status_lbl = ChangesetStatus.get_status_lbl(stat)
|
|
1072
|
status_lbl = ChangesetStatus.get_status_lbl(stat)
|
|
1073
|
for pr in PullRequest.query().filter(PullRequest.org_repo == self).all():
|
|
1073
|
for pr in PullRequest.query().filter(PullRequest.org_repo == self).all():
|
|
1074
|
for rev in pr.revisions:
|
|
1074
|
for rev in pr.revisions:
|
|
1075
|
pr_id = pr.pull_request_id
|
|
1075
|
pr_id = pr.pull_request_id
|
|
1076
|
pr_repo = pr.other_repo.repo_name
|
|
1076
|
pr_repo = pr.other_repo.repo_name
|
|
1077
|
grouped[rev] = [stat, status_lbl, pr_id, pr_repo]
|
|
1077
|
grouped[rev] = [stat, status_lbl, pr_id, pr_repo]
|
|
1078
|
|
|
1078
|
|
|
1079
|
for stat in statuses.all():
|
|
1079
|
for stat in statuses.all():
|
|
1080
|
pr_id = pr_repo = None
|
|
1080
|
pr_id = pr_repo = None
|
|
1081
|
if stat.pull_request:
|
|
1081
|
if stat.pull_request:
|
|
1082
|
pr_id = stat.pull_request.pull_request_id
|
|
1082
|
pr_id = stat.pull_request.pull_request_id
|
|
1083
|
pr_repo = stat.pull_request.other_repo.repo_name
|
|
1083
|
pr_repo = stat.pull_request.other_repo.repo_name
|
|
1084
|
grouped[stat.revision] = [str(stat.status), stat.status_lbl,
|
|
1084
|
grouped[stat.revision] = [str(stat.status), stat.status_lbl,
|
|
1085
|
pr_id, pr_repo]
|
|
1085
|
pr_id, pr_repo]
|
|
1086
|
return grouped
|
|
1086
|
return grouped
|
|
1087
|
|
|
1087
|
|
|
1088
|
#==========================================================================
|
|
1088
|
#==========================================================================
|
|
1089
|
# SCM CACHE INSTANCE
|
|
1089
|
# SCM CACHE INSTANCE
|
|
1090
|
#==========================================================================
|
|
1090
|
#==========================================================================
|
|
1091
|
|
|
1091
|
|
|
1092
|
@property
|
|
1092
|
@property
|
|
1093
|
def invalidate(self):
|
|
1093
|
def invalidate(self):
|
|
1094
|
return CacheInvalidation.invalidate(self.repo_name)
|
|
1094
|
return CacheInvalidation.invalidate(self.repo_name)
|
|
1095
|
|
|
1095
|
|
|
1096
|
def set_invalidate(self):
|
|
1096
|
def set_invalidate(self):
|
|
1097
|
"""
|
|
1097
|
"""
|
|
1098
|
set a cache for invalidation for this instance
|
|
1098
|
set a cache for invalidation for this instance
|
|
1099
|
"""
|
|
1099
|
"""
|
|
1100
|
CacheInvalidation.set_invalidate(repo_name=self.repo_name)
|
|
1100
|
CacheInvalidation.set_invalidate(repo_name=self.repo_name)
|
|
1101
|
|
|
1101
|
|
|
1102
|
@LazyProperty
|
|
1102
|
@LazyProperty
|
|
1103
|
def scm_instance_no_cache(self):
|
|
1103
|
def scm_instance_no_cache(self):
|
|
1104
|
return self.__get_instance()
|
|
1104
|
return self.__get_instance()
|
|
1105
|
|
|
1105
|
|
|
1106
|
@LazyProperty
|
|
1106
|
@LazyProperty
|
|
1107
|
def scm_instance(self):
|
|
1107
|
def scm_instance(self):
|
|
1108
|
import rhodecode
|
|
1108
|
import rhodecode
|
|
1109
|
full_cache = str2bool(rhodecode.CONFIG.get('vcs_full_cache'))
|
|
1109
|
full_cache = str2bool(rhodecode.CONFIG.get('vcs_full_cache'))
|
|
1110
|
if full_cache:
|
|
1110
|
if full_cache:
|
|
1111
|
return self.scm_instance_cached()
|
|
1111
|
return self.scm_instance_cached()
|
|
1112
|
return self.__get_instance()
|
|
1112
|
return self.__get_instance()
|
|
1113
|
|
|
1113
|
|
|
1114
|
def scm_instance_cached(self, cache_map=None):
|
|
1114
|
def scm_instance_cached(self, cache_map=None):
|
|
1115
|
@cache_region('long_term')
|
|
1115
|
@cache_region('long_term')
|
|
1116
|
def _c(repo_name):
|
|
1116
|
def _c(repo_name):
|
|
1117
|
return self.__get_instance()
|
|
1117
|
return self.__get_instance()
|
|
1118
|
rn = self.repo_name
|
|
1118
|
rn = self.repo_name
|
|
1119
|
log.debug('Getting cached instance of repo')
|
|
1119
|
log.debug('Getting cached instance of repo')
|
|
1120
|
|
|
1120
|
|
|
1121
|
if cache_map:
|
|
1121
|
if cache_map:
|
|
1122
|
# get using prefilled cache_map
|
|
1122
|
# get using prefilled cache_map
|
|
1123
|
invalidate_repo = cache_map[self.repo_name]
|
|
1123
|
invalidate_repo = cache_map[self.repo_name]
|
|
1124
|
if invalidate_repo:
|
|
1124
|
if invalidate_repo:
|
|
1125
|
invalidate_repo = (None if invalidate_repo.cache_active
|
|
1125
|
invalidate_repo = (None if invalidate_repo.cache_active
|
|
1126
|
else invalidate_repo)
|
|
1126
|
else invalidate_repo)
|
|
1127
|
else:
|
|
1127
|
else:
|
|
1128
|
# get from invalidate
|
|
1128
|
# get from invalidate
|
|
1129
|
invalidate_repo = self.invalidate
|
|
1129
|
invalidate_repo = self.invalidate
|
|
1130
|
|
|
1130
|
|
|
1131
|
if invalidate_repo is not None:
|
|
1131
|
if invalidate_repo is not None:
|
|
1132
|
region_invalidate(_c, None, rn)
|
|
1132
|
region_invalidate(_c, None, rn)
|
|
1133
|
# update our cache
|
|
1133
|
# update our cache
|
|
1134
|
CacheInvalidation.set_valid(invalidate_repo.cache_key)
|
|
1134
|
CacheInvalidation.set_valid(invalidate_repo.cache_key)
|
|
1135
|
return _c(rn)
|
|
1135
|
return _c(rn)
|
|
1136
|
|
|
1136
|
|
|
1137
|
def __get_instance(self):
|
|
1137
|
def __get_instance(self):
|
|
1138
|
repo_full_path = self.repo_full_path
|
|
1138
|
repo_full_path = self.repo_full_path
|
|
1139
|
try:
|
|
1139
|
try:
|
|
1140
|
alias = get_scm(repo_full_path)[0]
|
|
1140
|
alias = get_scm(repo_full_path)[0]
|
|
1141
|
log.debug('Creating instance of %s repository' % alias)
|
|
1141
|
log.debug('Creating instance of %s repository' % alias)
|
|
1142
|
backend = get_backend(alias)
|
|
1142
|
backend = get_backend(alias)
|
|
1143
|
except VCSError:
|
|
1143
|
except VCSError:
|
|
1144
|
log.error(traceback.format_exc())
|
|
1144
|
log.error(traceback.format_exc())
|
|
1145
|
log.error('Perhaps this repository is in db and not in '
|
|
1145
|
log.error('Perhaps this repository is in db and not in '
|
|
1146
|
'filesystem run rescan repositories with '
|
|
1146
|
'filesystem run rescan repositories with '
|
|
1147
|
'"destroy old data " option from admin panel')
|
|
1147
|
'"destroy old data " option from admin panel')
|
|
1148
|
return
|
|
1148
|
return
|
|
1149
|
|
|
1149
|
|
|
1150
|
if alias == 'hg':
|
|
1150
|
if alias == 'hg':
|
|
1151
|
|
|
1151
|
|
|
1152
|
repo = backend(safe_str(repo_full_path), create=False,
|
|
1152
|
repo = backend(safe_str(repo_full_path), create=False,
|
|
1153
|
baseui=self._ui)
|
|
1153
|
baseui=self._ui)
|
|
1154
|
# skip hidden web repository
|
|
1154
|
# skip hidden web repository
|
|
1155
|
if repo._get_hidden():
|
|
1155
|
if repo._get_hidden():
|
|
1156
|
return
|
|
1156
|
return
|
|
1157
|
else:
|
|
1157
|
else:
|
|
1158
|
repo = backend(repo_full_path, create=False)
|
|
1158
|
repo = backend(repo_full_path, create=False)
|
|
1159
|
|
|
1159
|
|
|
1160
|
return repo
|
|
1160
|
return repo
|
|
1161
|
|
|
1161
|
|
|
1162
|
|
|
1162
|
|
|
1163
|
class RepoGroup(Base, BaseModel):
|
|
1163
|
class RepoGroup(Base, BaseModel):
|
|
1164
|
__tablename__ = 'groups'
|
|
1164
|
__tablename__ = 'groups'
|
|
1165
|
__table_args__ = (
|
|
1165
|
__table_args__ = (
|
|
1166
|
UniqueConstraint('group_name', 'group_parent_id'),
|
|
1166
|
UniqueConstraint('group_name', 'group_parent_id'),
|
|
1167
|
CheckConstraint('group_id != group_parent_id'),
|
|
1167
|
CheckConstraint('group_id != group_parent_id'),
|
|
1168
|
{'extend_existing': True, 'mysql_engine': 'InnoDB',
|
|
1168
|
{'extend_existing': True, 'mysql_engine': 'InnoDB',
|
|
1169
|
'mysql_charset': 'utf8'},
|
|
1169
|
'mysql_charset': 'utf8'},
|
|
1170
|
)
|
|
1170
|
)
|
|
1171
|
__mapper_args__ = {'order_by': 'group_name'}
|
|
1171
|
__mapper_args__ = {'order_by': 'group_name'}
|
|
1172
|
|
|
1172
|
|
|
1173
|
group_id = Column("group_id", Integer(), nullable=False, unique=True, default=None, primary_key=True)
|
|
1173
|
group_id = Column("group_id", Integer(), nullable=False, unique=True, default=None, primary_key=True)
|
|
1174
|
group_name = Column("group_name", String(255, convert_unicode=False, assert_unicode=None), nullable=False, unique=True, default=None)
|
|
1174
|
group_name = Column("group_name", String(255, convert_unicode=False, assert_unicode=None), nullable=False, unique=True, default=None)
|
|
1175
|
group_parent_id = Column("group_parent_id", Integer(), ForeignKey('groups.group_id'), nullable=True, unique=None, default=None)
|
|
1175
|
group_parent_id = Column("group_parent_id", Integer(), ForeignKey('groups.group_id'), nullable=True, unique=None, default=None)
|
|
1176
|
group_description = Column("group_description", String(10000, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None)
|
|
1176
|
group_description = Column("group_description", String(10000, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None)
|
|
1177
|
enable_locking = Column("enable_locking", Boolean(), nullable=False, unique=None, default=False)
|
|
1177
|
enable_locking = Column("enable_locking", Boolean(), nullable=False, unique=None, default=False)
|
|
1178
|
|
|
1178
|
|
|
1179
|
repo_group_to_perm = relationship('UserRepoGroupToPerm', cascade='all', order_by='UserRepoGroupToPerm.group_to_perm_id')
|
|
1179
|
repo_group_to_perm = relationship('UserRepoGroupToPerm', cascade='all', order_by='UserRepoGroupToPerm.group_to_perm_id')
|
|
1180
|
users_group_to_perm = relationship('UsersGroupRepoGroupToPerm', cascade='all')
|
|
1180
|
users_group_to_perm = relationship('UsersGroupRepoGroupToPerm', cascade='all')
|
|
1181
|
|
|
1181
|
|
|
1182
|
parent_group = relationship('RepoGroup', remote_side=group_id)
|
|
1182
|
parent_group = relationship('RepoGroup', remote_side=group_id)
|
|
1183
|
|
|
1183
|
|
|
1184
|
def __init__(self, group_name='', parent_group=None):
|
|
1184
|
def __init__(self, group_name='', parent_group=None):
|
|
1185
|
self.group_name = group_name
|
|
1185
|
self.group_name = group_name
|
|
1186
|
self.parent_group = parent_group
|
|
1186
|
self.parent_group = parent_group
|
|
1187
|
|
|
1187
|
|
|
1188
|
def __unicode__(self):
|
|
1188
|
def __unicode__(self):
|
|
1189
|
return u"<%s('%s:%s')>" % (self.__class__.__name__, self.group_id,
|
|
1189
|
return u"<%s('%s:%s')>" % (self.__class__.__name__, self.group_id,
|
|
1190
|
self.group_name)
|
|
1190
|
self.group_name)
|
|
1191
|
|
|
1191
|
|
|
1192
|
@classmethod
|
|
1192
|
@classmethod
|
|
1193
|
def groups_choices(cls, check_perms=False):
|
|
1193
|
def groups_choices(cls, check_perms=False):
|
|
1194
|
from webhelpers.html import literal as _literal
|
|
1194
|
from webhelpers.html import literal as _literal
|
|
1195
|
from rhodecode.model.scm import ScmModel
|
|
1195
|
from rhodecode.model.scm import ScmModel
|
|
1196
|
groups = cls.query().all()
|
|
1196
|
groups = cls.query().all()
|
|
1197
|
if check_perms:
|
|
1197
|
if check_perms:
|
|
1198
|
#filter group user have access to, it's done
|
|
1198
|
#filter group user have access to, it's done
|
|
1199
|
#magically inside ScmModel based on current user
|
|
1199
|
#magically inside ScmModel based on current user
|
|
1200
|
groups = ScmModel().get_repos_groups(groups)
|
|
1200
|
groups = ScmModel().get_repos_groups(groups)
|
|
1201
|
repo_groups = [('', '')]
|
|
1201
|
repo_groups = [('', '')]
|
|
1202
|
sep = ' » '
|
|
1202
|
sep = ' » '
|
|
1203
|
_name = lambda k: _literal(sep.join(k))
|
|
1203
|
_name = lambda k: _literal(sep.join(k))
|
|
1204
|
|
|
1204
|
|
|
1205
|
repo_groups.extend([(x.group_id, _name(x.full_path_splitted))
|
|
1205
|
repo_groups.extend([(x.group_id, _name(x.full_path_splitted))
|
|
1206
|
for x in groups])
|
|
1206
|
for x in groups])
|
|
1207
|
|
|
1207
|
|
|
1208
|
repo_groups = sorted(repo_groups, key=lambda t: t[1].split(sep)[0])
|
|
1208
|
repo_groups = sorted(repo_groups, key=lambda t: t[1].split(sep)[0])
|
|
1209
|
return repo_groups
|
|
1209
|
return repo_groups
|
|
1210
|
|
|
1210
|
|
|
1211
|
@classmethod
|
|
1211
|
@classmethod
|
|
1212
|
def url_sep(cls):
|
|
1212
|
def url_sep(cls):
|
|
1213
|
return URL_SEP
|
|
1213
|
return URL_SEP
|
|
1214
|
|
|
1214
|
|
|
1215
|
@classmethod
|
|
1215
|
@classmethod
|
|
1216
|
def get_by_group_name(cls, group_name, cache=False, case_insensitive=False):
|
|
1216
|
def get_by_group_name(cls, group_name, cache=False, case_insensitive=False):
|
|
1217
|
if case_insensitive:
|
|
1217
|
if case_insensitive:
|
|
1218
|
gr = cls.query()\
|
|
1218
|
gr = cls.query()\
|
|
1219
|
.filter(cls.group_name.ilike(group_name))
|
|
1219
|
.filter(cls.group_name.ilike(group_name))
|
|
1220
|
else:
|
|
1220
|
else:
|
|
1221
|
gr = cls.query()\
|
|
1221
|
gr = cls.query()\
|
|
1222
|
.filter(cls.group_name == group_name)
|
|
1222
|
.filter(cls.group_name == group_name)
|
|
1223
|
if cache:
|
|
1223
|
if cache:
|
|
1224
|
gr = gr.options(FromCache(
|
|
1224
|
gr = gr.options(FromCache(
|
|
1225
|
"sql_cache_short",
|
|
1225
|
"sql_cache_short",
|
|
1226
|
"get_group_%s" % _hash_key(group_name)
|
|
1226
|
"get_group_%s" % _hash_key(group_name)
|
|
1227
|
)
|
|
1227
|
)
|
|
1228
|
)
|
|
1228
|
)
|
|
1229
|
return gr.scalar()
|
|
1229
|
return gr.scalar()
|
|
1230
|
|
|
1230
|
|
|
1231
|
@property
|
|
1231
|
@property
|
|
1232
|
def parents(self):
|
|
1232
|
def parents(self):
|
|
1233
|
parents_recursion_limit = 5
|
|
1233
|
parents_recursion_limit = 5
|
|
1234
|
groups = []
|
|
1234
|
groups = []
|
|
1235
|
if self.parent_group is None:
|
|
1235
|
if self.parent_group is None:
|
|
1236
|
return groups
|
|
1236
|
return groups
|
|
1237
|
cur_gr = self.parent_group
|
|
1237
|
cur_gr = self.parent_group
|
|
1238
|
groups.insert(0, cur_gr)
|
|
1238
|
groups.insert(0, cur_gr)
|
|
1239
|
cnt = 0
|
|
1239
|
cnt = 0
|
|
1240
|
while 1:
|
|
1240
|
while 1:
|
|
1241
|
cnt += 1
|
|
1241
|
cnt += 1
|
|
1242
|
gr = getattr(cur_gr, 'parent_group', None)
|
|
1242
|
gr = getattr(cur_gr, 'parent_group', None)
|
|
1243
|
cur_gr = cur_gr.parent_group
|
|
1243
|
cur_gr = cur_gr.parent_group
|
|
1244
|
if gr is None:
|
|
1244
|
if gr is None:
|
|
1245
|
break
|
|
1245
|
break
|
|
1246
|
if cnt == parents_recursion_limit:
|
|
1246
|
if cnt == parents_recursion_limit:
|
|
1247
|
# this will prevent accidental infinit loops
|
|
1247
|
# this will prevent accidental infinit loops
|
|
1248
|
log.error('group nested more than %s' %
|
|
1248
|
log.error('group nested more than %s' %
|
|
1249
|
parents_recursion_limit)
|
|
1249
|
parents_recursion_limit)
|
|
1250
|
break
|
|
1250
|
break
|
|
1251
|
|
|
1251
|
|
|
1252
|
groups.insert(0, gr)
|
|
1252
|
groups.insert(0, gr)
|
|
1253
|
return groups
|
|
1253
|
return groups
|
|
1254
|
|
|
1254
|
|
|
1255
|
@property
|
|
1255
|
@property
|
|
1256
|
def children(self):
|
|
1256
|
def children(self):
|
|
1257
|
return RepoGroup.query().filter(RepoGroup.parent_group == self)
|
|
1257
|
return RepoGroup.query().filter(RepoGroup.parent_group == self)
|
|
1258
|
|
|
1258
|
|
|
1259
|
@property
|
|
1259
|
@property
|
|
1260
|
def name(self):
|
|
1260
|
def name(self):
|
|
1261
|
return self.group_name.split(RepoGroup.url_sep())[-1]
|
|
1261
|
return self.group_name.split(RepoGroup.url_sep())[-1]
|
|
1262
|
|
|
1262
|
|
|
1263
|
@property
|
|
1263
|
@property
|
|
1264
|
def full_path(self):
|
|
1264
|
def full_path(self):
|
|
1265
|
return self.group_name
|
|
1265
|
return self.group_name
|
|
1266
|
|
|
1266
|
|
|
1267
|
@property
|
|
1267
|
@property
|
|
1268
|
def full_path_splitted(self):
|
|
1268
|
def full_path_splitted(self):
|
|
1269
|
return self.group_name.split(RepoGroup.url_sep())
|
|
1269
|
return self.group_name.split(RepoGroup.url_sep())
|
|
1270
|
|
|
1270
|
|
|
1271
|
@property
|
|
1271
|
@property
|
|
1272
|
def repositories(self):
|
|
1272
|
def repositories(self):
|
|
1273
|
return Repository.query()\
|
|
1273
|
return Repository.query()\
|
|
1274
|
.filter(Repository.group == self)\
|
|
1274
|
.filter(Repository.group == self)\
|
|
1275
|
.order_by(Repository.repo_name)
|
|
1275
|
.order_by(Repository.repo_name)
|
|
1276
|
|
|
1276
|
|
|
1277
|
@property
|
|
1277
|
@property
|
|
1278
|
def repositories_recursive_count(self):
|
|
1278
|
def repositories_recursive_count(self):
|
|
1279
|
cnt = self.repositories.count()
|
|
1279
|
cnt = self.repositories.count()
|
|
1280
|
|
|
1280
|
|
|
1281
|
def children_count(group):
|
|
1281
|
def children_count(group):
|
|
1282
|
cnt = 0
|
|
1282
|
cnt = 0
|
|
1283
|
for child in group.children:
|
|
1283
|
for child in group.children:
|
|
1284
|
cnt += child.repositories.count()
|
|
1284
|
cnt += child.repositories.count()
|
|
1285
|
cnt += children_count(child)
|
|
1285
|
cnt += children_count(child)
|
|
1286
|
return cnt
|
|
1286
|
return cnt
|
|
1287
|
|
|
1287
|
|
|
1288
|
return cnt + children_count(self)
|
|
1288
|
return cnt + children_count(self)
|
|
1289
|
|
|
1289
|
|
|
1290
|
def recursive_groups_and_repos(self):
|
|
1290
|
def _recursive_objects(self, include_repos=True):
|
|
1291
|
"""
|
|
|
|
|
1292
|
Recursive return all groups, with repositories in those groups
|
|
|
|
|
1293
|
"""
|
|
|
|
|
1294
|
all_ = []
|
|
1291
|
all_ = []
|
|
1295
|
|
|
1292
|
|
|
1296
|
def _get_members(root_gr):
|
|
1293
|
def _get_members(root_gr):
|
|
|
|
|
1294
|
if include_repos:
|
|
1297
|
for r in root_gr.repositories:
|
|
1295
|
for r in root_gr.repositories:
|
|
1298
|
all_.append(r)
|
|
1296
|
all_.append(r)
|
|
1299
|
childs = root_gr.children.all()
|
|
1297
|
childs = root_gr.children.all()
|
|
1300
|
if childs:
|
|
1298
|
if childs:
|
|
1301
|
for gr in childs:
|
|
1299
|
for gr in childs:
|
|
1302
|
all_.append(gr)
|
|
1300
|
all_.append(gr)
|
|
1303
|
_get_members(gr)
|
|
1301
|
_get_members(gr)
|
|
1304
|
|
|
1302
|
|
|
1305
|
_get_members(self)
|
|
1303
|
_get_members(self)
|
|
1306
|
return [self] + all_
|
|
1304
|
return [self] + all_
|
|
1307
|
|
|
1305
|
|
|
|
|
|
1306
|
def recursive_groups_and_repos(self):
|
|
|
|
|
1307
|
"""
|
|
|
|
|
1308
|
Recursive return all groups, with repositories in those groups
|
|
|
|
|
1309
|
"""
|
|
|
|
|
1310
|
return self._recursive_objects()
|
|
|
|
|
1311
|
|
|
|
|
|
1312
|
def recursive_groups(self):
|
|
|
|
|
1313
|
"""
|
|
|
|
|
1314
|
Returns all children groups for this group including children of children
|
|
|
|
|
1315
|
"""
|
|
|
|
|
1316
|
return self._recursive_objects(include_repos=False)
|
|
|
|
|
1317
|
|
|
1308
|
def get_new_name(self, group_name):
|
|
1318
|
def get_new_name(self, group_name):
|
|
1309
|
"""
|
|
1319
|
"""
|
|
1310
|
returns new full group name based on parent and new name
|
|
1320
|
returns new full group name based on parent and new name
|
|
1311
|
|
|
1321
|
|
|
1312
|
:param group_name:
|
|
1322
|
:param group_name:
|
|
1313
|
"""
|
|
1323
|
"""
|
|
1314
|
path_prefix = (self.parent_group.full_path_splitted if
|
|
1324
|
path_prefix = (self.parent_group.full_path_splitted if
|
|
1315
|
self.parent_group else [])
|
|
1325
|
self.parent_group else [])
|
|
1316
|
return RepoGroup.url_sep().join(path_prefix + [group_name])
|
|
1326
|
return RepoGroup.url_sep().join(path_prefix + [group_name])
|
|
1317
|
|
|
1327
|
|
|
1318
|
|
|
1328
|
|
|
1319
|
class Permission(Base, BaseModel):
|
|
1329
|
class Permission(Base, BaseModel):
|
|
1320
|
__tablename__ = 'permissions'
|
|
1330
|
__tablename__ = 'permissions'
|
|
1321
|
__table_args__ = (
|
|
1331
|
__table_args__ = (
|
|
1322
|
Index('p_perm_name_idx', 'permission_name'),
|
|
1332
|
Index('p_perm_name_idx', 'permission_name'),
|
|
1323
|
{'extend_existing': True, 'mysql_engine': 'InnoDB',
|
|
1333
|
{'extend_existing': True, 'mysql_engine': 'InnoDB',
|
|
1324
|
'mysql_charset': 'utf8'},
|
|
1334
|
'mysql_charset': 'utf8'},
|
|
1325
|
)
|
|
1335
|
)
|
|
1326
|
PERMS = [
|
|
1336
|
PERMS = [
|
|
1327
|
('repository.none', _('Repository no access')),
|
|
1337
|
('repository.none', _('Repository no access')),
|
|
1328
|
('repository.read', _('Repository read access')),
|
|
1338
|
('repository.read', _('Repository read access')),
|
|
1329
|
('repository.write', _('Repository write access')),
|
|
1339
|
('repository.write', _('Repository write access')),
|
|
1330
|
('repository.admin', _('Repository admin access')),
|
|
1340
|
('repository.admin', _('Repository admin access')),
|
|
1331
|
|
|
1341
|
|
|
1332
|
('group.none', _('Repositories Group no access')),
|
|
1342
|
('group.none', _('Repositories Group no access')),
|
|
1333
|
('group.read', _('Repositories Group read access')),
|
|
1343
|
('group.read', _('Repositories Group read access')),
|
|
1334
|
('group.write', _('Repositories Group write access')),
|
|
1344
|
('group.write', _('Repositories Group write access')),
|
|
1335
|
('group.admin', _('Repositories Group admin access')),
|
|
1345
|
('group.admin', _('Repositories Group admin access')),
|
|
1336
|
|
|
1346
|
|
|
1337
|
('hg.admin', _('RhodeCode Administrator')),
|
|
1347
|
('hg.admin', _('RhodeCode Administrator')),
|
|
1338
|
('hg.create.none', _('Repository creation disabled')),
|
|
1348
|
('hg.create.none', _('Repository creation disabled')),
|
|
1339
|
('hg.create.repository', _('Repository creation enabled')),
|
|
1349
|
('hg.create.repository', _('Repository creation enabled')),
|
|
1340
|
('hg.fork.none', _('Repository forking disabled')),
|
|
1350
|
('hg.fork.none', _('Repository forking disabled')),
|
|
1341
|
('hg.fork.repository', _('Repository forking enabled')),
|
|
1351
|
('hg.fork.repository', _('Repository forking enabled')),
|
|
1342
|
('hg.register.none', _('Register disabled')),
|
|
1352
|
('hg.register.none', _('Register disabled')),
|
|
1343
|
('hg.register.manual_activate', _('Register new user with RhodeCode '
|
|
1353
|
('hg.register.manual_activate', _('Register new user with RhodeCode '
|
|
1344
|
'with manual activation')),
|
|
1354
|
'with manual activation')),
|
|
1345
|
|
|
1355
|
|
|
1346
|
('hg.register.auto_activate', _('Register new user with RhodeCode '
|
|
1356
|
('hg.register.auto_activate', _('Register new user with RhodeCode '
|
|
1347
|
'with auto activation')),
|
|
1357
|
'with auto activation')),
|
|
1348
|
]
|
|
1358
|
]
|
|
1349
|
|
|
1359
|
|
|
1350
|
# defines which permissions are more important higher the more important
|
|
1360
|
# defines which permissions are more important higher the more important
|
|
1351
|
PERM_WEIGHTS = {
|
|
1361
|
PERM_WEIGHTS = {
|
|
1352
|
'repository.none': 0,
|
|
1362
|
'repository.none': 0,
|
|
1353
|
'repository.read': 1,
|
|
1363
|
'repository.read': 1,
|
|
1354
|
'repository.write': 3,
|
|
1364
|
'repository.write': 3,
|
|
1355
|
'repository.admin': 4,
|
|
1365
|
'repository.admin': 4,
|
|
1356
|
|
|
1366
|
|
|
1357
|
'group.none': 0,
|
|
1367
|
'group.none': 0,
|
|
1358
|
'group.read': 1,
|
|
1368
|
'group.read': 1,
|
|
1359
|
'group.write': 3,
|
|
1369
|
'group.write': 3,
|
|
1360
|
'group.admin': 4,
|
|
1370
|
'group.admin': 4,
|
|
1361
|
|
|
1371
|
|
|
1362
|
'hg.fork.none': 0,
|
|
1372
|
'hg.fork.none': 0,
|
|
1363
|
'hg.fork.repository': 1,
|
|
1373
|
'hg.fork.repository': 1,
|
|
1364
|
'hg.create.none': 0,
|
|
1374
|
'hg.create.none': 0,
|
|
1365
|
'hg.create.repository':1
|
|
1375
|
'hg.create.repository':1
|
|
1366
|
}
|
|
1376
|
}
|
|
1367
|
|
|
1377
|
|
|
1368
|
permission_id = Column("permission_id", Integer(), nullable=False, unique=True, default=None, primary_key=True)
|
|
1378
|
permission_id = Column("permission_id", Integer(), nullable=False, unique=True, default=None, primary_key=True)
|
|
1369
|
permission_name = Column("permission_name", String(255, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None)
|
|
1379
|
permission_name = Column("permission_name", String(255, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None)
|
|
1370
|
permission_longname = Column("permission_longname", String(255, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None)
|
|
1380
|
permission_longname = Column("permission_longname", String(255, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None)
|
|
1371
|
|
|
1381
|
|
|
1372
|
def __unicode__(self):
|
|
1382
|
def __unicode__(self):
|
|
1373
|
return u"<%s('%s:%s')>" % (
|
|
1383
|
return u"<%s('%s:%s')>" % (
|
|
1374
|
self.__class__.__name__, self.permission_id, self.permission_name
|
|
1384
|
self.__class__.__name__, self.permission_id, self.permission_name
|
|
1375
|
)
|
|
1385
|
)
|
|
1376
|
|
|
1386
|
|
|
1377
|
@classmethod
|
|
1387
|
@classmethod
|
|
1378
|
def get_by_key(cls, key):
|
|
1388
|
def get_by_key(cls, key):
|
|
1379
|
return cls.query().filter(cls.permission_name == key).scalar()
|
|
1389
|
return cls.query().filter(cls.permission_name == key).scalar()
|
|
1380
|
|
|
1390
|
|
|
1381
|
@classmethod
|
|
1391
|
@classmethod
|
|
1382
|
def get_default_perms(cls, default_user_id):
|
|
1392
|
def get_default_perms(cls, default_user_id):
|
|
1383
|
q = Session().query(UserRepoToPerm, Repository, cls)\
|
|
1393
|
q = Session().query(UserRepoToPerm, Repository, cls)\
|
|
1384
|
.join((Repository, UserRepoToPerm.repository_id == Repository.repo_id))\
|
|
1394
|
.join((Repository, UserRepoToPerm.repository_id == Repository.repo_id))\
|
|
1385
|
.join((cls, UserRepoToPerm.permission_id == cls.permission_id))\
|
|
1395
|
.join((cls, UserRepoToPerm.permission_id == cls.permission_id))\
|
|
1386
|
.filter(UserRepoToPerm.user_id == default_user_id)
|
|
1396
|
.filter(UserRepoToPerm.user_id == default_user_id)
|
|
1387
|
|
|
1397
|
|
|
1388
|
return q.all()
|
|
1398
|
return q.all()
|
|
1389
|
|
|
1399
|
|
|
1390
|
@classmethod
|
|
1400
|
@classmethod
|
|
1391
|
def get_default_group_perms(cls, default_user_id):
|
|
1401
|
def get_default_group_perms(cls, default_user_id):
|
|
1392
|
q = Session().query(UserRepoGroupToPerm, RepoGroup, cls)\
|
|
1402
|
q = Session().query(UserRepoGroupToPerm, RepoGroup, cls)\
|
|
1393
|
.join((RepoGroup, UserRepoGroupToPerm.group_id == RepoGroup.group_id))\
|
|
1403
|
.join((RepoGroup, UserRepoGroupToPerm.group_id == RepoGroup.group_id))\
|
|
1394
|
.join((cls, UserRepoGroupToPerm.permission_id == cls.permission_id))\
|
|
1404
|
.join((cls, UserRepoGroupToPerm.permission_id == cls.permission_id))\
|
|
1395
|
.filter(UserRepoGroupToPerm.user_id == default_user_id)
|
|
1405
|
.filter(UserRepoGroupToPerm.user_id == default_user_id)
|
|
1396
|
|
|
1406
|
|
|
1397
|
return q.all()
|
|
1407
|
return q.all()
|
|
1398
|
|
|
1408
|
|
|
1399
|
|
|
1409
|
|
|
1400
|
class UserRepoToPerm(Base, BaseModel):
|
|
1410
|
class UserRepoToPerm(Base, BaseModel):
|
|
1401
|
__tablename__ = 'repo_to_perm'
|
|
1411
|
__tablename__ = 'repo_to_perm'
|
|
1402
|
__table_args__ = (
|
|
1412
|
__table_args__ = (
|
|
1403
|
UniqueConstraint('user_id', 'repository_id', 'permission_id'),
|
|
1413
|
UniqueConstraint('user_id', 'repository_id', 'permission_id'),
|
|
1404
|
{'extend_existing': True, 'mysql_engine': 'InnoDB',
|
|
1414
|
{'extend_existing': True, 'mysql_engine': 'InnoDB',
|
|
1405
|
'mysql_charset': 'utf8'}
|
|
1415
|
'mysql_charset': 'utf8'}
|
|
1406
|
)
|
|
1416
|
)
|
|
1407
|
repo_to_perm_id = Column("repo_to_perm_id", Integer(), nullable=False, unique=True, default=None, primary_key=True)
|
|
1417
|
repo_to_perm_id = Column("repo_to_perm_id", Integer(), nullable=False, unique=True, default=None, primary_key=True)
|
|
1408
|
user_id = Column("user_id", Integer(), ForeignKey('users.user_id'), nullable=False, unique=None, default=None)
|
|
1418
|
user_id = Column("user_id", Integer(), ForeignKey('users.user_id'), nullable=False, unique=None, default=None)
|
|
1409
|
permission_id = Column("permission_id", Integer(), ForeignKey('permissions.permission_id'), nullable=False, unique=None, default=None)
|
|
1419
|
permission_id = Column("permission_id", Integer(), ForeignKey('permissions.permission_id'), nullable=False, unique=None, default=None)
|
|
1410
|
repository_id = Column("repository_id", Integer(), ForeignKey('repositories.repo_id'), nullable=False, unique=None, default=None)
|
|
1420
|
repository_id = Column("repository_id", Integer(), ForeignKey('repositories.repo_id'), nullable=False, unique=None, default=None)
|
|
1411
|
|
|
1421
|
|
|
1412
|
user = relationship('User')
|
|
1422
|
user = relationship('User')
|
|
1413
|
repository = relationship('Repository')
|
|
1423
|
repository = relationship('Repository')
|
|
1414
|
permission = relationship('Permission')
|
|
1424
|
permission = relationship('Permission')
|
|
1415
|
|
|
1425
|
|
|
1416
|
@classmethod
|
|
1426
|
@classmethod
|
|
1417
|
def create(cls, user, repository, permission):
|
|
1427
|
def create(cls, user, repository, permission):
|
|
1418
|
n = cls()
|
|
1428
|
n = cls()
|
|
1419
|
n.user = user
|
|
1429
|
n.user = user
|
|
1420
|
n.repository = repository
|
|
1430
|
n.repository = repository
|
|
1421
|
n.permission = permission
|
|
1431
|
n.permission = permission
|
|
1422
|
Session().add(n)
|
|
1432
|
Session().add(n)
|
|
1423
|
return n
|
|
1433
|
return n
|
|
1424
|
|
|
1434
|
|
|
1425
|
def __unicode__(self):
|
|
1435
|
def __unicode__(self):
|
|
1426
|
return u'<user:%s => %s >' % (self.user, self.repository)
|
|
1436
|
return u'<user:%s => %s >' % (self.user, self.repository)
|
|
1427
|
|
|
1437
|
|
|
1428
|
|
|
1438
|
|
|
1429
|
class UserToPerm(Base, BaseModel):
|
|
1439
|
class UserToPerm(Base, BaseModel):
|
|
1430
|
__tablename__ = 'user_to_perm'
|
|
1440
|
__tablename__ = 'user_to_perm'
|
|
1431
|
__table_args__ = (
|
|
1441
|
__table_args__ = (
|
|
1432
|
UniqueConstraint('user_id', 'permission_id'),
|
|
1442
|
UniqueConstraint('user_id', 'permission_id'),
|
|
1433
|
{'extend_existing': True, 'mysql_engine': 'InnoDB',
|
|
1443
|
{'extend_existing': True, 'mysql_engine': 'InnoDB',
|
|
1434
|
'mysql_charset': 'utf8'}
|
|
1444
|
'mysql_charset': 'utf8'}
|
|
1435
|
)
|
|
1445
|
)
|
|
1436
|
user_to_perm_id = Column("user_to_perm_id", Integer(), nullable=False, unique=True, default=None, primary_key=True)
|
|
1446
|
user_to_perm_id = Column("user_to_perm_id", Integer(), nullable=False, unique=True, default=None, primary_key=True)
|
|
1437
|
user_id = Column("user_id", Integer(), ForeignKey('users.user_id'), nullable=False, unique=None, default=None)
|
|
1447
|
user_id = Column("user_id", Integer(), ForeignKey('users.user_id'), nullable=False, unique=None, default=None)
|
|
1438
|
permission_id = Column("permission_id", Integer(), ForeignKey('permissions.permission_id'), nullable=False, unique=None, default=None)
|
|
1448
|
permission_id = Column("permission_id", Integer(), ForeignKey('permissions.permission_id'), nullable=False, unique=None, default=None)
|
|
1439
|
|
|
1449
|
|
|
1440
|
user = relationship('User')
|
|
1450
|
user = relationship('User')
|
|
1441
|
permission = relationship('Permission', lazy='joined')
|
|
1451
|
permission = relationship('Permission', lazy='joined')
|
|
1442
|
|
|
1452
|
|
|
1443
|
|
|
1453
|
|
|
1444
|
class UsersGroupRepoToPerm(Base, BaseModel):
|
|
1454
|
class UsersGroupRepoToPerm(Base, BaseModel):
|
|
1445
|
__tablename__ = 'users_group_repo_to_perm'
|
|
1455
|
__tablename__ = 'users_group_repo_to_perm'
|
|
1446
|
__table_args__ = (
|
|
1456
|
__table_args__ = (
|
|
1447
|
UniqueConstraint('repository_id', 'users_group_id', 'permission_id'),
|
|
1457
|
UniqueConstraint('repository_id', 'users_group_id', 'permission_id'),
|
|
1448
|
{'extend_existing': True, 'mysql_engine': 'InnoDB',
|
|
1458
|
{'extend_existing': True, 'mysql_engine': 'InnoDB',
|
|
1449
|
'mysql_charset': 'utf8'}
|
|
1459
|
'mysql_charset': 'utf8'}
|
|
1450
|
)
|
|
1460
|
)
|
|
1451
|
users_group_to_perm_id = Column("users_group_to_perm_id", Integer(), nullable=False, unique=True, default=None, primary_key=True)
|
|
1461
|
users_group_to_perm_id = Column("users_group_to_perm_id", Integer(), nullable=False, unique=True, default=None, primary_key=True)
|
|
1452
|
users_group_id = Column("users_group_id", Integer(), ForeignKey('users_groups.users_group_id'), nullable=False, unique=None, default=None)
|
|
1462
|
users_group_id = Column("users_group_id", Integer(), ForeignKey('users_groups.users_group_id'), nullable=False, unique=None, default=None)
|
|
1453
|
permission_id = Column("permission_id", Integer(), ForeignKey('permissions.permission_id'), nullable=False, unique=None, default=None)
|
|
1463
|
permission_id = Column("permission_id", Integer(), ForeignKey('permissions.permission_id'), nullable=False, unique=None, default=None)
|
|
1454
|
repository_id = Column("repository_id", Integer(), ForeignKey('repositories.repo_id'), nullable=False, unique=None, default=None)
|
|
1464
|
repository_id = Column("repository_id", Integer(), ForeignKey('repositories.repo_id'), nullable=False, unique=None, default=None)
|
|
1455
|
|
|
1465
|
|
|
1456
|
users_group = relationship('UsersGroup')
|
|
1466
|
users_group = relationship('UsersGroup')
|
|
1457
|
permission = relationship('Permission')
|
|
1467
|
permission = relationship('Permission')
|
|
1458
|
repository = relationship('Repository')
|
|
1468
|
repository = relationship('Repository')
|
|
1459
|
|
|
1469
|
|
|
1460
|
@classmethod
|
|
1470
|
@classmethod
|
|
1461
|
def create(cls, users_group, repository, permission):
|
|
1471
|
def create(cls, users_group, repository, permission):
|
|
1462
|
n = cls()
|
|
1472
|
n = cls()
|
|
1463
|
n.users_group = users_group
|
|
1473
|
n.users_group = users_group
|
|
1464
|
n.repository = repository
|
|
1474
|
n.repository = repository
|
|
1465
|
n.permission = permission
|
|
1475
|
n.permission = permission
|
|
1466
|
Session().add(n)
|
|
1476
|
Session().add(n)
|
|
1467
|
return n
|
|
1477
|
return n
|
|
1468
|
|
|
1478
|
|
|
1469
|
def __unicode__(self):
|
|
1479
|
def __unicode__(self):
|
|
1470
|
return u'<userGroup:%s => %s >' % (self.users_group, self.repository)
|
|
1480
|
return u'<userGroup:%s => %s >' % (self.users_group, self.repository)
|
|
1471
|
|
|
1481
|
|
|
1472
|
|
|
1482
|
|
|
1473
|
class UsersGroupToPerm(Base, BaseModel):
|
|
1483
|
class UsersGroupToPerm(Base, BaseModel):
|
|
1474
|
__tablename__ = 'users_group_to_perm'
|
|
1484
|
__tablename__ = 'users_group_to_perm'
|
|
1475
|
__table_args__ = (
|
|
1485
|
__table_args__ = (
|
|
1476
|
UniqueConstraint('users_group_id', 'permission_id',),
|
|
1486
|
UniqueConstraint('users_group_id', 'permission_id',),
|
|
1477
|
{'extend_existing': True, 'mysql_engine': 'InnoDB',
|
|
1487
|
{'extend_existing': True, 'mysql_engine': 'InnoDB',
|
|
1478
|
'mysql_charset': 'utf8'}
|
|
1488
|
'mysql_charset': 'utf8'}
|
|
1479
|
)
|
|
1489
|
)
|
|
1480
|
users_group_to_perm_id = Column("users_group_to_perm_id", Integer(), nullable=False, unique=True, default=None, primary_key=True)
|
|
1490
|
users_group_to_perm_id = Column("users_group_to_perm_id", Integer(), nullable=False, unique=True, default=None, primary_key=True)
|
|
1481
|
users_group_id = Column("users_group_id", Integer(), ForeignKey('users_groups.users_group_id'), nullable=False, unique=None, default=None)
|
|
1491
|
users_group_id = Column("users_group_id", Integer(), ForeignKey('users_groups.users_group_id'), nullable=False, unique=None, default=None)
|
|
1482
|
permission_id = Column("permission_id", Integer(), ForeignKey('permissions.permission_id'), nullable=False, unique=None, default=None)
|
|
1492
|
permission_id = Column("permission_id", Integer(), ForeignKey('permissions.permission_id'), nullable=False, unique=None, default=None)
|
|
1483
|
|
|
1493
|
|
|
1484
|
users_group = relationship('UsersGroup')
|
|
1494
|
users_group = relationship('UsersGroup')
|
|
1485
|
permission = relationship('Permission')
|
|
1495
|
permission = relationship('Permission')
|
|
1486
|
|
|
1496
|
|
|
1487
|
|
|
1497
|
|
|
1488
|
class UserRepoGroupToPerm(Base, BaseModel):
|
|
1498
|
class UserRepoGroupToPerm(Base, BaseModel):
|
|
1489
|
__tablename__ = 'user_repo_group_to_perm'
|
|
1499
|
__tablename__ = 'user_repo_group_to_perm'
|
|
1490
|
__table_args__ = (
|
|
1500
|
__table_args__ = (
|
|
1491
|
UniqueConstraint('user_id', 'group_id', 'permission_id'),
|
|
1501
|
UniqueConstraint('user_id', 'group_id', 'permission_id'),
|
|
1492
|
{'extend_existing': True, 'mysql_engine': 'InnoDB',
|
|
1502
|
{'extend_existing': True, 'mysql_engine': 'InnoDB',
|
|
1493
|
'mysql_charset': 'utf8'}
|
|
1503
|
'mysql_charset': 'utf8'}
|
|
1494
|
)
|
|
1504
|
)
|
|
1495
|
|
|
1505
|
|
|
1496
|
group_to_perm_id = Column("group_to_perm_id", Integer(), nullable=False, unique=True, default=None, primary_key=True)
|
|
1506
|
group_to_perm_id = Column("group_to_perm_id", Integer(), nullable=False, unique=True, default=None, primary_key=True)
|
|
1497
|
user_id = Column("user_id", Integer(), ForeignKey('users.user_id'), nullable=False, unique=None, default=None)
|
|
1507
|
user_id = Column("user_id", Integer(), ForeignKey('users.user_id'), nullable=False, unique=None, default=None)
|
|
1498
|
group_id = Column("group_id", Integer(), ForeignKey('groups.group_id'), nullable=False, unique=None, default=None)
|
|
1508
|
group_id = Column("group_id", Integer(), ForeignKey('groups.group_id'), nullable=False, unique=None, default=None)
|
|
1499
|
permission_id = Column("permission_id", Integer(), ForeignKey('permissions.permission_id'), nullable=False, unique=None, default=None)
|
|
1509
|
permission_id = Column("permission_id", Integer(), ForeignKey('permissions.permission_id'), nullable=False, unique=None, default=None)
|
|
1500
|
|
|
1510
|
|
|
1501
|
user = relationship('User')
|
|
1511
|
user = relationship('User')
|
|
1502
|
group = relationship('RepoGroup')
|
|
1512
|
group = relationship('RepoGroup')
|
|
1503
|
permission = relationship('Permission')
|
|
1513
|
permission = relationship('Permission')
|
|
1504
|
|
|
1514
|
|
|
1505
|
|
|
1515
|
|
|
1506
|
class UsersGroupRepoGroupToPerm(Base, BaseModel):
|
|
1516
|
class UsersGroupRepoGroupToPerm(Base, BaseModel):
|
|
1507
|
__tablename__ = 'users_group_repo_group_to_perm'
|
|
1517
|
__tablename__ = 'users_group_repo_group_to_perm'
|
|
1508
|
__table_args__ = (
|
|
1518
|
__table_args__ = (
|
|
1509
|
UniqueConstraint('users_group_id', 'group_id'),
|
|
1519
|
UniqueConstraint('users_group_id', 'group_id'),
|
|
1510
|
{'extend_existing': True, 'mysql_engine': 'InnoDB',
|
|
1520
|
{'extend_existing': True, 'mysql_engine': 'InnoDB',
|
|
1511
|
'mysql_charset': 'utf8'}
|
|
1521
|
'mysql_charset': 'utf8'}
|
|
1512
|
)
|
|
1522
|
)
|
|
1513
|
|
|
1523
|
|
|
1514
|
users_group_repo_group_to_perm_id = Column("users_group_repo_group_to_perm_id", Integer(), nullable=False, unique=True, default=None, primary_key=True)
|
|
1524
|
users_group_repo_group_to_perm_id = Column("users_group_repo_group_to_perm_id", Integer(), nullable=False, unique=True, default=None, primary_key=True)
|
|
1515
|
users_group_id = Column("users_group_id", Integer(), ForeignKey('users_groups.users_group_id'), nullable=False, unique=None, default=None)
|
|
1525
|
users_group_id = Column("users_group_id", Integer(), ForeignKey('users_groups.users_group_id'), nullable=False, unique=None, default=None)
|
|
1516
|
group_id = Column("group_id", Integer(), ForeignKey('groups.group_id'), nullable=False, unique=None, default=None)
|
|
1526
|
group_id = Column("group_id", Integer(), ForeignKey('groups.group_id'), nullable=False, unique=None, default=None)
|
|
1517
|
permission_id = Column("permission_id", Integer(), ForeignKey('permissions.permission_id'), nullable=False, unique=None, default=None)
|
|
1527
|
permission_id = Column("permission_id", Integer(), ForeignKey('permissions.permission_id'), nullable=False, unique=None, default=None)
|
|
1518
|
|
|
1528
|
|
|
1519
|
users_group = relationship('UsersGroup')
|
|
1529
|
users_group = relationship('UsersGroup')
|
|
1520
|
permission = relationship('Permission')
|
|
1530
|
permission = relationship('Permission')
|
|
1521
|
group = relationship('RepoGroup')
|
|
1531
|
group = relationship('RepoGroup')
|
|
1522
|
|
|
1532
|
|
|
1523
|
|
|
1533
|
|
|
1524
|
class Statistics(Base, BaseModel):
|
|
1534
|
class Statistics(Base, BaseModel):
|
|
1525
|
__tablename__ = 'statistics'
|
|
1535
|
__tablename__ = 'statistics'
|
|
1526
|
__table_args__ = (
|
|
1536
|
__table_args__ = (
|
|
1527
|
UniqueConstraint('repository_id'),
|
|
1537
|
UniqueConstraint('repository_id'),
|
|
1528
|
{'extend_existing': True, 'mysql_engine': 'InnoDB',
|
|
1538
|
{'extend_existing': True, 'mysql_engine': 'InnoDB',
|
|
1529
|
'mysql_charset': 'utf8'}
|
|
1539
|
'mysql_charset': 'utf8'}
|
|
1530
|
)
|
|
1540
|
)
|
|
1531
|
stat_id = Column("stat_id", Integer(), nullable=False, unique=True, default=None, primary_key=True)
|
|
1541
|
stat_id = Column("stat_id", Integer(), nullable=False, unique=True, default=None, primary_key=True)
|
|
1532
|
repository_id = Column("repository_id", Integer(), ForeignKey('repositories.repo_id'), nullable=False, unique=True, default=None)
|
|
1542
|
repository_id = Column("repository_id", Integer(), ForeignKey('repositories.repo_id'), nullable=False, unique=True, default=None)
|
|
1533
|
stat_on_revision = Column("stat_on_revision", Integer(), nullable=False)
|
|
1543
|
stat_on_revision = Column("stat_on_revision", Integer(), nullable=False)
|
|
1534
|
commit_activity = Column("commit_activity", LargeBinary(1000000), nullable=False)#JSON data
|
|
1544
|
commit_activity = Column("commit_activity", LargeBinary(1000000), nullable=False)#JSON data
|
|
1535
|
commit_activity_combined = Column("commit_activity_combined", LargeBinary(), nullable=False)#JSON data
|
|
1545
|
commit_activity_combined = Column("commit_activity_combined", LargeBinary(), nullable=False)#JSON data
|
|
1536
|
languages = Column("languages", LargeBinary(1000000), nullable=False)#JSON data
|
|
1546
|
languages = Column("languages", LargeBinary(1000000), nullable=False)#JSON data
|
|
1537
|
|
|
1547
|
|
|
1538
|
repository = relationship('Repository', single_parent=True)
|
|
1548
|
repository = relationship('Repository', single_parent=True)
|
|
1539
|
|
|
1549
|
|
|
1540
|
|
|
1550
|
|
|
1541
|
class UserFollowing(Base, BaseModel):
|
|
1551
|
class UserFollowing(Base, BaseModel):
|
|
1542
|
__tablename__ = 'user_followings'
|
|
1552
|
__tablename__ = 'user_followings'
|
|
1543
|
__table_args__ = (
|
|
1553
|
__table_args__ = (
|
|
1544
|
UniqueConstraint('user_id', 'follows_repository_id'),
|
|
1554
|
UniqueConstraint('user_id', 'follows_repository_id'),
|
|
1545
|
UniqueConstraint('user_id', 'follows_user_id'),
|
|
1555
|
UniqueConstraint('user_id', 'follows_user_id'),
|
|
1546
|
{'extend_existing': True, 'mysql_engine': 'InnoDB',
|
|
1556
|
{'extend_existing': True, 'mysql_engine': 'InnoDB',
|
|
1547
|
'mysql_charset': 'utf8'}
|
|
1557
|
'mysql_charset': 'utf8'}
|
|
1548
|
)
|
|
1558
|
)
|
|
1549
|
|
|
1559
|
|
|
1550
|
user_following_id = Column("user_following_id", Integer(), nullable=False, unique=True, default=None, primary_key=True)
|
|
1560
|
user_following_id = Column("user_following_id", Integer(), nullable=False, unique=True, default=None, primary_key=True)
|
|
1551
|
user_id = Column("user_id", Integer(), ForeignKey('users.user_id'), nullable=False, unique=None, default=None)
|
|
1561
|
user_id = Column("user_id", Integer(), ForeignKey('users.user_id'), nullable=False, unique=None, default=None)
|
|
1552
|
follows_repo_id = Column("follows_repository_id", Integer(), ForeignKey('repositories.repo_id'), nullable=True, unique=None, default=None)
|
|
1562
|
follows_repo_id = Column("follows_repository_id", Integer(), ForeignKey('repositories.repo_id'), nullable=True, unique=None, default=None)
|
|
1553
|
follows_user_id = Column("follows_user_id", Integer(), ForeignKey('users.user_id'), nullable=True, unique=None, default=None)
|
|
1563
|
follows_user_id = Column("follows_user_id", Integer(), ForeignKey('users.user_id'), nullable=True, unique=None, default=None)
|
|
1554
|
follows_from = Column('follows_from', DateTime(timezone=False), nullable=True, unique=None, default=datetime.datetime.now)
|
|
1564
|
follows_from = Column('follows_from', DateTime(timezone=False), nullable=True, unique=None, default=datetime.datetime.now)
|
|
1555
|
|
|
1565
|
|
|
1556
|
user = relationship('User', primaryjoin='User.user_id==UserFollowing.user_id')
|
|
1566
|
user = relationship('User', primaryjoin='User.user_id==UserFollowing.user_id')
|
|
1557
|
|
|
1567
|
|
|
1558
|
follows_user = relationship('User', primaryjoin='User.user_id==UserFollowing.follows_user_id')
|
|
1568
|
follows_user = relationship('User', primaryjoin='User.user_id==UserFollowing.follows_user_id')
|
|
1559
|
follows_repository = relationship('Repository', order_by='Repository.repo_name')
|
|
1569
|
follows_repository = relationship('Repository', order_by='Repository.repo_name')
|
|
1560
|
|
|
1570
|
|
|
1561
|
@classmethod
|
|
1571
|
@classmethod
|
|
1562
|
def get_repo_followers(cls, repo_id):
|
|
1572
|
def get_repo_followers(cls, repo_id):
|
|
1563
|
return cls.query().filter(cls.follows_repo_id == repo_id)
|
|
1573
|
return cls.query().filter(cls.follows_repo_id == repo_id)
|
|
1564
|
|
|
1574
|
|
|
1565
|
|
|
1575
|
|
|
1566
|
class CacheInvalidation(Base, BaseModel):
|
|
1576
|
class CacheInvalidation(Base, BaseModel):
|
|
1567
|
__tablename__ = 'cache_invalidation'
|
|
1577
|
__tablename__ = 'cache_invalidation'
|
|
1568
|
__table_args__ = (
|
|
1578
|
__table_args__ = (
|
|
1569
|
UniqueConstraint('cache_key'),
|
|
1579
|
UniqueConstraint('cache_key'),
|
|
1570
|
Index('key_idx', 'cache_key'),
|
|
1580
|
Index('key_idx', 'cache_key'),
|
|
1571
|
{'extend_existing': True, 'mysql_engine': 'InnoDB',
|
|
1581
|
{'extend_existing': True, 'mysql_engine': 'InnoDB',
|
|
1572
|
'mysql_charset': 'utf8'},
|
|
1582
|
'mysql_charset': 'utf8'},
|
|
1573
|
)
|
|
1583
|
)
|
|
1574
|
cache_id = Column("cache_id", Integer(), nullable=False, unique=True, default=None, primary_key=True)
|
|
1584
|
cache_id = Column("cache_id", Integer(), nullable=False, unique=True, default=None, primary_key=True)
|
|
1575
|
cache_key = Column("cache_key", String(255, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None)
|
|
1585
|
cache_key = Column("cache_key", String(255, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None)
|
|
1576
|
cache_args = Column("cache_args", String(255, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None)
|
|
1586
|
cache_args = Column("cache_args", String(255, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None)
|
|
1577
|
cache_active = Column("cache_active", Boolean(), nullable=True, unique=None, default=False)
|
|
1587
|
cache_active = Column("cache_active", Boolean(), nullable=True, unique=None, default=False)
|
|
1578
|
|
|
1588
|
|
|
1579
|
def __init__(self, cache_key, cache_args=''):
|
|
1589
|
def __init__(self, cache_key, cache_args=''):
|
|
1580
|
self.cache_key = cache_key
|
|
1590
|
self.cache_key = cache_key
|
|
1581
|
self.cache_args = cache_args
|
|
1591
|
self.cache_args = cache_args
|
|
1582
|
self.cache_active = False
|
|
1592
|
self.cache_active = False
|
|
1583
|
|
|
1593
|
|
|
1584
|
def __unicode__(self):
|
|
1594
|
def __unicode__(self):
|
|
1585
|
return u"<%s('%s:%s')>" % (self.__class__.__name__,
|
|
1595
|
return u"<%s('%s:%s')>" % (self.__class__.__name__,
|
|
1586
|
self.cache_id, self.cache_key)
|
|
1596
|
self.cache_id, self.cache_key)
|
|
1587
|
|
|
1597
|
|
|
1588
|
@property
|
|
1598
|
@property
|
|
1589
|
def prefix(self):
|
|
1599
|
def prefix(self):
|
|
1590
|
_split = self.cache_key.split(self.cache_args, 1)
|
|
1600
|
_split = self.cache_key.split(self.cache_args, 1)
|
|
1591
|
if _split and len(_split) == 2:
|
|
1601
|
if _split and len(_split) == 2:
|
|
1592
|
return _split[0]
|
|
1602
|
return _split[0]
|
|
1593
|
return ''
|
|
1603
|
return ''
|
|
1594
|
|
|
1604
|
|
|
1595
|
@classmethod
|
|
1605
|
@classmethod
|
|
1596
|
def clear_cache(cls):
|
|
1606
|
def clear_cache(cls):
|
|
1597
|
cls.query().delete()
|
|
1607
|
cls.query().delete()
|
|
1598
|
|
|
1608
|
|
|
1599
|
@classmethod
|
|
1609
|
@classmethod
|
|
1600
|
def _get_key(cls, key):
|
|
1610
|
def _get_key(cls, key):
|
|
1601
|
"""
|
|
1611
|
"""
|
|
1602
|
Wrapper for generating a key, together with a prefix
|
|
1612
|
Wrapper for generating a key, together with a prefix
|
|
1603
|
|
|
1613
|
|
|
1604
|
:param key:
|
|
1614
|
:param key:
|
|
1605
|
"""
|
|
1615
|
"""
|
|
1606
|
import rhodecode
|
|
1616
|
import rhodecode
|
|
1607
|
prefix = ''
|
|
1617
|
prefix = ''
|
|
1608
|
org_key = key
|
|
1618
|
org_key = key
|
|
1609
|
iid = rhodecode.CONFIG.get('instance_id')
|
|
1619
|
iid = rhodecode.CONFIG.get('instance_id')
|
|
1610
|
if iid:
|
|
1620
|
if iid:
|
|
1611
|
prefix = iid
|
|
1621
|
prefix = iid
|
|
1612
|
|
|
1622
|
|
|
1613
|
return "%s%s" % (prefix, key), prefix, org_key
|
|
1623
|
return "%s%s" % (prefix, key), prefix, org_key
|
|
1614
|
|
|
1624
|
|
|
1615
|
@classmethod
|
|
1625
|
@classmethod
|
|
1616
|
def get_by_key(cls, key):
|
|
1626
|
def get_by_key(cls, key):
|
|
1617
|
return cls.query().filter(cls.cache_key == key).scalar()
|
|
1627
|
return cls.query().filter(cls.cache_key == key).scalar()
|
|
1618
|
|
|
1628
|
|
|
1619
|
@classmethod
|
|
1629
|
@classmethod
|
|
1620
|
def get_by_repo_name(cls, repo_name):
|
|
1630
|
def get_by_repo_name(cls, repo_name):
|
|
1621
|
return cls.query().filter(cls.cache_args == repo_name).all()
|
|
1631
|
return cls.query().filter(cls.cache_args == repo_name).all()
|
|
1622
|
|
|
1632
|
|
|
1623
|
@classmethod
|
|
1633
|
@classmethod
|
|
1624
|
def _get_or_create_key(cls, key, repo_name, commit=True):
|
|
1634
|
def _get_or_create_key(cls, key, repo_name, commit=True):
|
|
1625
|
inv_obj = Session().query(cls).filter(cls.cache_key == key).scalar()
|
|
1635
|
inv_obj = Session().query(cls).filter(cls.cache_key == key).scalar()
|
|
1626
|
if not inv_obj:
|
|
1636
|
if not inv_obj:
|
|
1627
|
try:
|
|
1637
|
try:
|
|
1628
|
inv_obj = CacheInvalidation(key, repo_name)
|
|
1638
|
inv_obj = CacheInvalidation(key, repo_name)
|
|
1629
|
Session().add(inv_obj)
|
|
1639
|
Session().add(inv_obj)
|
|
1630
|
if commit:
|
|
1640
|
if commit:
|
|
1631
|
Session().commit()
|
|
1641
|
Session().commit()
|
|
1632
|
except Exception:
|
|
1642
|
except Exception:
|
|
1633
|
log.error(traceback.format_exc())
|
|
1643
|
log.error(traceback.format_exc())
|
|
1634
|
Session().rollback()
|
|
1644
|
Session().rollback()
|
|
1635
|
return inv_obj
|
|
1645
|
return inv_obj
|
|
1636
|
|
|
1646
|
|
|
1637
|
@classmethod
|
|
1647
|
@classmethod
|
|
1638
|
def invalidate(cls, key):
|
|
1648
|
def invalidate(cls, key):
|
|
1639
|
"""
|
|
1649
|
"""
|
|
1640
|
Returns Invalidation object if this given key should be invalidated
|
|
1650
|
Returns Invalidation object if this given key should be invalidated
|
|
1641
|
None otherwise. `cache_active = False` means that this cache
|
|
1651
|
None otherwise. `cache_active = False` means that this cache
|
|
1642
|
state is not valid and needs to be invalidated
|
|
1652
|
state is not valid and needs to be invalidated
|
|
1643
|
|
|
1653
|
|
|
1644
|
:param key:
|
|
1654
|
:param key:
|
|
1645
|
"""
|
|
1655
|
"""
|
|
1646
|
repo_name = key
|
|
1656
|
repo_name = key
|
|
1647
|
repo_name = remove_suffix(repo_name, '_README')
|
|
1657
|
repo_name = remove_suffix(repo_name, '_README')
|
|
1648
|
repo_name = remove_suffix(repo_name, '_RSS')
|
|
1658
|
repo_name = remove_suffix(repo_name, '_RSS')
|
|
1649
|
repo_name = remove_suffix(repo_name, '_ATOM')
|
|
1659
|
repo_name = remove_suffix(repo_name, '_ATOM')
|
|
1650
|
|
|
1660
|
|
|
1651
|
# adds instance prefix
|
|
1661
|
# adds instance prefix
|
|
1652
|
key, _prefix, _org_key = cls._get_key(key)
|
|
1662
|
key, _prefix, _org_key = cls._get_key(key)
|
|
1653
|
inv = cls._get_or_create_key(key, repo_name)
|
|
1663
|
inv = cls._get_or_create_key(key, repo_name)
|
|
1654
|
|
|
1664
|
|
|
1655
|
if inv and inv.cache_active is False:
|
|
1665
|
if inv and inv.cache_active is False:
|
|
1656
|
return inv
|
|
1666
|
return inv
|
|
1657
|
|
|
1667
|
|
|
1658
|
@classmethod
|
|
1668
|
@classmethod
|
|
1659
|
def set_invalidate(cls, key=None, repo_name=None):
|
|
1669
|
def set_invalidate(cls, key=None, repo_name=None):
|
|
1660
|
"""
|
|
1670
|
"""
|
|
1661
|
Mark this Cache key for invalidation, either by key or whole
|
|
1671
|
Mark this Cache key for invalidation, either by key or whole
|
|
1662
|
cache sets based on repo_name
|
|
1672
|
cache sets based on repo_name
|
|
1663
|
|
|
1673
|
|
|
1664
|
:param key:
|
|
1674
|
:param key:
|
|
1665
|
"""
|
|
1675
|
"""
|
|
1666
|
if key:
|
|
1676
|
if key:
|
|
1667
|
key, _prefix, _org_key = cls._get_key(key)
|
|
1677
|
key, _prefix, _org_key = cls._get_key(key)
|
|
1668
|
inv_objs = Session().query(cls).filter(cls.cache_key == key).all()
|
|
1678
|
inv_objs = Session().query(cls).filter(cls.cache_key == key).all()
|
|
1669
|
elif repo_name:
|
|
1679
|
elif repo_name:
|
|
1670
|
inv_objs = Session().query(cls).filter(cls.cache_args == repo_name).all()
|
|
1680
|
inv_objs = Session().query(cls).filter(cls.cache_args == repo_name).all()
|
|
1671
|
|
|
1681
|
|
|
1672
|
log.debug('marking %s key[s] for invalidation based on key=%s,repo_name=%s'
|
|
1682
|
log.debug('marking %s key[s] for invalidation based on key=%s,repo_name=%s'
|
|
1673
|
% (len(inv_objs), key, repo_name))
|
|
1683
|
% (len(inv_objs), key, repo_name))
|
|
1674
|
try:
|
|
1684
|
try:
|
|
1675
|
for inv_obj in inv_objs:
|
|
1685
|
for inv_obj in inv_objs:
|
|
1676
|
inv_obj.cache_active = False
|
|
1686
|
inv_obj.cache_active = False
|
|
1677
|
Session().add(inv_obj)
|
|
1687
|
Session().add(inv_obj)
|
|
1678
|
Session().commit()
|
|
1688
|
Session().commit()
|
|
1679
|
except Exception:
|
|
1689
|
except Exception:
|
|
1680
|
log.error(traceback.format_exc())
|
|
1690
|
log.error(traceback.format_exc())
|
|
1681
|
Session().rollback()
|
|
1691
|
Session().rollback()
|
|
1682
|
|
|
1692
|
|
|
1683
|
@classmethod
|
|
1693
|
@classmethod
|
|
1684
|
def set_valid(cls, key):
|
|
1694
|
def set_valid(cls, key):
|
|
1685
|
"""
|
|
1695
|
"""
|
|
1686
|
Mark this cache key as active and currently cached
|
|
1696
|
Mark this cache key as active and currently cached
|
|
1687
|
|
|
1697
|
|
|
1688
|
:param key:
|
|
1698
|
:param key:
|
|
1689
|
"""
|
|
1699
|
"""
|
|
1690
|
inv_obj = cls.get_by_key(key)
|
|
1700
|
inv_obj = cls.get_by_key(key)
|
|
1691
|
inv_obj.cache_active = True
|
|
1701
|
inv_obj.cache_active = True
|
|
1692
|
Session().add(inv_obj)
|
|
1702
|
Session().add(inv_obj)
|
|
1693
|
Session().commit()
|
|
1703
|
Session().commit()
|
|
1694
|
|
|
1704
|
|
|
1695
|
@classmethod
|
|
1705
|
@classmethod
|
|
1696
|
def get_cache_map(cls):
|
|
1706
|
def get_cache_map(cls):
|
|
1697
|
|
|
1707
|
|
|
1698
|
class cachemapdict(dict):
|
|
1708
|
class cachemapdict(dict):
|
|
1699
|
|
|
1709
|
|
|
1700
|
def __init__(self, *args, **kwargs):
|
|
1710
|
def __init__(self, *args, **kwargs):
|
|
1701
|
fixkey = kwargs.get('fixkey')
|
|
1711
|
fixkey = kwargs.get('fixkey')
|
|
1702
|
if fixkey:
|
|
1712
|
if fixkey:
|
|
1703
|
del kwargs['fixkey']
|
|
1713
|
del kwargs['fixkey']
|
|
1704
|
self.fixkey = fixkey
|
|
1714
|
self.fixkey = fixkey
|
|
1705
|
super(cachemapdict, self).__init__(*args, **kwargs)
|
|
1715
|
super(cachemapdict, self).__init__(*args, **kwargs)
|
|
1706
|
|
|
1716
|
|
|
1707
|
def __getattr__(self, name):
|
|
1717
|
def __getattr__(self, name):
|
|
1708
|
key = name
|
|
1718
|
key = name
|
|
1709
|
if self.fixkey:
|
|
1719
|
if self.fixkey:
|
|
1710
|
key, _prefix, _org_key = cls._get_key(key)
|
|
1720
|
key, _prefix, _org_key = cls._get_key(key)
|
|
1711
|
if key in self.__dict__:
|
|
1721
|
if key in self.__dict__:
|
|
1712
|
return self.__dict__[key]
|
|
1722
|
return self.__dict__[key]
|
|
1713
|
else:
|
|
1723
|
else:
|
|
1714
|
return self[key]
|
|
1724
|
return self[key]
|
|
1715
|
|
|
1725
|
|
|
1716
|
def __getitem__(self, key):
|
|
1726
|
def __getitem__(self, key):
|
|
1717
|
if self.fixkey:
|
|
1727
|
if self.fixkey:
|
|
1718
|
key, _prefix, _org_key = cls._get_key(key)
|
|
1728
|
key, _prefix, _org_key = cls._get_key(key)
|
|
1719
|
try:
|
|
1729
|
try:
|
|
1720
|
return super(cachemapdict, self).__getitem__(key)
|
|
1730
|
return super(cachemapdict, self).__getitem__(key)
|
|
1721
|
except KeyError:
|
|
1731
|
except KeyError:
|
|
1722
|
return
|
|
1732
|
return
|
|
1723
|
|
|
1733
|
|
|
1724
|
cache_map = cachemapdict(fixkey=True)
|
|
1734
|
cache_map = cachemapdict(fixkey=True)
|
|
1725
|
for obj in cls.query().all():
|
|
1735
|
for obj in cls.query().all():
|
|
1726
|
cache_map[obj.cache_key] = cachemapdict(obj.get_dict())
|
|
1736
|
cache_map[obj.cache_key] = cachemapdict(obj.get_dict())
|
|
1727
|
return cache_map
|
|
1737
|
return cache_map
|
|
1728
|
|
|
1738
|
|
|
1729
|
|
|
1739
|
|
|
1730
|
class ChangesetComment(Base, BaseModel):
|
|
1740
|
class ChangesetComment(Base, BaseModel):
|
|
1731
|
__tablename__ = 'changeset_comments'
|
|
1741
|
__tablename__ = 'changeset_comments'
|
|
1732
|
__table_args__ = (
|
|
1742
|
__table_args__ = (
|
|
1733
|
Index('cc_revision_idx', 'revision'),
|
|
1743
|
Index('cc_revision_idx', 'revision'),
|
|
1734
|
{'extend_existing': True, 'mysql_engine': 'InnoDB',
|
|
1744
|
{'extend_existing': True, 'mysql_engine': 'InnoDB',
|
|
1735
|
'mysql_charset': 'utf8'},
|
|
1745
|
'mysql_charset': 'utf8'},
|
|
1736
|
)
|
|
1746
|
)
|
|
1737
|
comment_id = Column('comment_id', Integer(), nullable=False, primary_key=True)
|
|
1747
|
comment_id = Column('comment_id', Integer(), nullable=False, primary_key=True)
|
|
1738
|
repo_id = Column('repo_id', Integer(), ForeignKey('repositories.repo_id'), nullable=False)
|
|
1748
|
repo_id = Column('repo_id', Integer(), ForeignKey('repositories.repo_id'), nullable=False)
|
|
1739
|
revision = Column('revision', String(40), nullable=True)
|
|
1749
|
revision = Column('revision', String(40), nullable=True)
|
|
1740
|
pull_request_id = Column("pull_request_id", Integer(), ForeignKey('pull_requests.pull_request_id'), nullable=True)
|
|
1750
|
pull_request_id = Column("pull_request_id", Integer(), ForeignKey('pull_requests.pull_request_id'), nullable=True)
|
|
1741
|
line_no = Column('line_no', Unicode(10), nullable=True)
|
|
1751
|
line_no = Column('line_no', Unicode(10), nullable=True)
|
|
1742
|
hl_lines = Column('hl_lines', Unicode(512), nullable=True)
|
|
1752
|
hl_lines = Column('hl_lines', Unicode(512), nullable=True)
|
|
1743
|
f_path = Column('f_path', Unicode(1000), nullable=True)
|
|
1753
|
f_path = Column('f_path', Unicode(1000), nullable=True)
|
|
1744
|
user_id = Column('user_id', Integer(), ForeignKey('users.user_id'), nullable=False)
|
|
1754
|
user_id = Column('user_id', Integer(), ForeignKey('users.user_id'), nullable=False)
|
|
1745
|
text = Column('text', UnicodeText(25000), nullable=False)
|
|
1755
|
text = Column('text', UnicodeText(25000), nullable=False)
|
|
1746
|
created_on = Column('created_on', DateTime(timezone=False), nullable=False, default=datetime.datetime.now)
|
|
1756
|
created_on = Column('created_on', DateTime(timezone=False), nullable=False, default=datetime.datetime.now)
|
|
1747
|
modified_at = Column('modified_at', DateTime(timezone=False), nullable=False, default=datetime.datetime.now)
|
|
1757
|
modified_at = Column('modified_at', DateTime(timezone=False), nullable=False, default=datetime.datetime.now)
|
|
1748
|
|
|
1758
|
|
|
1749
|
author = relationship('User', lazy='joined')
|
|
1759
|
author = relationship('User', lazy='joined')
|
|
1750
|
repo = relationship('Repository')
|
|
1760
|
repo = relationship('Repository')
|
|
1751
|
status_change = relationship('ChangesetStatus', cascade="all, delete, delete-orphan")
|
|
1761
|
status_change = relationship('ChangesetStatus', cascade="all, delete, delete-orphan")
|
|
1752
|
pull_request = relationship('PullRequest', lazy='joined')
|
|
1762
|
pull_request = relationship('PullRequest', lazy='joined')
|
|
1753
|
|
|
1763
|
|
|
1754
|
@classmethod
|
|
1764
|
@classmethod
|
|
1755
|
def get_users(cls, revision=None, pull_request_id=None):
|
|
1765
|
def get_users(cls, revision=None, pull_request_id=None):
|
|
1756
|
"""
|
|
1766
|
"""
|
|
1757
|
Returns user associated with this ChangesetComment. ie those
|
|
1767
|
Returns user associated with this ChangesetComment. ie those
|
|
1758
|
who actually commented
|
|
1768
|
who actually commented
|
|
1759
|
|
|
1769
|
|
|
1760
|
:param cls:
|
|
1770
|
:param cls:
|
|
1761
|
:param revision:
|
|
1771
|
:param revision:
|
|
1762
|
"""
|
|
1772
|
"""
|
|
1763
|
q = Session().query(User)\
|
|
1773
|
q = Session().query(User)\
|
|
1764
|
.join(ChangesetComment.author)
|
|
1774
|
.join(ChangesetComment.author)
|
|
1765
|
if revision:
|
|
1775
|
if revision:
|
|
1766
|
q = q.filter(cls.revision == revision)
|
|
1776
|
q = q.filter(cls.revision == revision)
|
|
1767
|
elif pull_request_id:
|
|
1777
|
elif pull_request_id:
|
|
1768
|
q = q.filter(cls.pull_request_id == pull_request_id)
|
|
1778
|
q = q.filter(cls.pull_request_id == pull_request_id)
|
|
1769
|
return q.all()
|
|
1779
|
return q.all()
|
|
1770
|
|
|
1780
|
|
|
1771
|
|
|
1781
|
|
|
1772
|
class ChangesetStatus(Base, BaseModel):
|
|
1782
|
class ChangesetStatus(Base, BaseModel):
|
|
1773
|
__tablename__ = 'changeset_statuses'
|
|
1783
|
__tablename__ = 'changeset_statuses'
|
|
1774
|
__table_args__ = (
|
|
1784
|
__table_args__ = (
|
|
1775
|
Index('cs_revision_idx', 'revision'),
|
|
1785
|
Index('cs_revision_idx', 'revision'),
|
|
1776
|
Index('cs_version_idx', 'version'),
|
|
1786
|
Index('cs_version_idx', 'version'),
|
|
1777
|
UniqueConstraint('repo_id', 'revision', 'version'),
|
|
1787
|
UniqueConstraint('repo_id', 'revision', 'version'),
|
|
1778
|
{'extend_existing': True, 'mysql_engine': 'InnoDB',
|
|
1788
|
{'extend_existing': True, 'mysql_engine': 'InnoDB',
|
|
1779
|
'mysql_charset': 'utf8'}
|
|
1789
|
'mysql_charset': 'utf8'}
|
|
1780
|
)
|
|
1790
|
)
|
|
1781
|
STATUS_NOT_REVIEWED = DEFAULT = 'not_reviewed'
|
|
1791
|
STATUS_NOT_REVIEWED = DEFAULT = 'not_reviewed'
|
|
1782
|
STATUS_APPROVED = 'approved'
|
|
1792
|
STATUS_APPROVED = 'approved'
|
|
1783
|
STATUS_REJECTED = 'rejected'
|
|
1793
|
STATUS_REJECTED = 'rejected'
|
|
1784
|
STATUS_UNDER_REVIEW = 'under_review'
|
|
1794
|
STATUS_UNDER_REVIEW = 'under_review'
|
|
1785
|
|
|
1795
|
|
|
1786
|
STATUSES = [
|
|
1796
|
STATUSES = [
|
|
1787
|
(STATUS_NOT_REVIEWED, _("Not Reviewed")), # (no icon) and default
|
|
1797
|
(STATUS_NOT_REVIEWED, _("Not Reviewed")), # (no icon) and default
|
|
1788
|
(STATUS_APPROVED, _("Approved")),
|
|
1798
|
(STATUS_APPROVED, _("Approved")),
|
|
1789
|
(STATUS_REJECTED, _("Rejected")),
|
|
1799
|
(STATUS_REJECTED, _("Rejected")),
|
|
1790
|
(STATUS_UNDER_REVIEW, _("Under Review")),
|
|
1800
|
(STATUS_UNDER_REVIEW, _("Under Review")),
|
|
1791
|
]
|
|
1801
|
]
|
|
1792
|
|
|
1802
|
|
|
1793
|
changeset_status_id = Column('changeset_status_id', Integer(), nullable=False, primary_key=True)
|
|
1803
|
changeset_status_id = Column('changeset_status_id', Integer(), nullable=False, primary_key=True)
|
|
1794
|
repo_id = Column('repo_id', Integer(), ForeignKey('repositories.repo_id'), nullable=False)
|
|
1804
|
repo_id = Column('repo_id', Integer(), ForeignKey('repositories.repo_id'), nullable=False)
|
|
1795
|
user_id = Column("user_id", Integer(), ForeignKey('users.user_id'), nullable=False, unique=None)
|
|
1805
|
user_id = Column("user_id", Integer(), ForeignKey('users.user_id'), nullable=False, unique=None)
|
|
1796
|
revision = Column('revision', String(40), nullable=False)
|
|
1806
|
revision = Column('revision', String(40), nullable=False)
|
|
1797
|
status = Column('status', String(128), nullable=False, default=DEFAULT)
|
|
1807
|
status = Column('status', String(128), nullable=False, default=DEFAULT)
|
|
1798
|
changeset_comment_id = Column('changeset_comment_id', Integer(), ForeignKey('changeset_comments.comment_id'))
|
|
1808
|
changeset_comment_id = Column('changeset_comment_id', Integer(), ForeignKey('changeset_comments.comment_id'))
|
|
1799
|
modified_at = Column('modified_at', DateTime(), nullable=False, default=datetime.datetime.now)
|
|
1809
|
modified_at = Column('modified_at', DateTime(), nullable=False, default=datetime.datetime.now)
|
|
1800
|
version = Column('version', Integer(), nullable=False, default=0)
|
|
1810
|
version = Column('version', Integer(), nullable=False, default=0)
|
|
1801
|
pull_request_id = Column("pull_request_id", Integer(), ForeignKey('pull_requests.pull_request_id'), nullable=True)
|
|
1811
|
pull_request_id = Column("pull_request_id", Integer(), ForeignKey('pull_requests.pull_request_id'), nullable=True)
|
|
1802
|
|
|
1812
|
|
|
1803
|
author = relationship('User', lazy='joined')
|
|
1813
|
author = relationship('User', lazy='joined')
|
|
1804
|
repo = relationship('Repository')
|
|
1814
|
repo = relationship('Repository')
|
|
1805
|
comment = relationship('ChangesetComment', lazy='joined')
|
|
1815
|
comment = relationship('ChangesetComment', lazy='joined')
|
|
1806
|
pull_request = relationship('PullRequest', lazy='joined')
|
|
1816
|
pull_request = relationship('PullRequest', lazy='joined')
|
|
1807
|
|
|
1817
|
|
|
1808
|
def __unicode__(self):
|
|
1818
|
def __unicode__(self):
|
|
1809
|
return u"<%s('%s:%s')>" % (
|
|
1819
|
return u"<%s('%s:%s')>" % (
|
|
1810
|
self.__class__.__name__,
|
|
1820
|
self.__class__.__name__,
|
|
1811
|
self.status, self.author
|
|
1821
|
self.status, self.author
|
|
1812
|
)
|
|
1822
|
)
|
|
1813
|
|
|
1823
|
|
|
1814
|
@classmethod
|
|
1824
|
@classmethod
|
|
1815
|
def get_status_lbl(cls, value):
|
|
1825
|
def get_status_lbl(cls, value):
|
|
1816
|
return dict(cls.STATUSES).get(value)
|
|
1826
|
return dict(cls.STATUSES).get(value)
|
|
1817
|
|
|
1827
|
|
|
1818
|
@property
|
|
1828
|
@property
|
|
1819
|
def status_lbl(self):
|
|
1829
|
def status_lbl(self):
|
|
1820
|
return ChangesetStatus.get_status_lbl(self.status)
|
|
1830
|
return ChangesetStatus.get_status_lbl(self.status)
|
|
1821
|
|
|
1831
|
|
|
1822
|
|
|
1832
|
|
|
1823
|
class PullRequest(Base, BaseModel):
|
|
1833
|
class PullRequest(Base, BaseModel):
|
|
1824
|
__tablename__ = 'pull_requests'
|
|
1834
|
__tablename__ = 'pull_requests'
|
|
1825
|
__table_args__ = (
|
|
1835
|
__table_args__ = (
|
|
1826
|
{'extend_existing': True, 'mysql_engine': 'InnoDB',
|
|
1836
|
{'extend_existing': True, 'mysql_engine': 'InnoDB',
|
|
1827
|
'mysql_charset': 'utf8'},
|
|
1837
|
'mysql_charset': 'utf8'},
|
|
1828
|
)
|
|
1838
|
)
|
|
1829
|
|
|
1839
|
|
|
1830
|
STATUS_NEW = u'new'
|
|
1840
|
STATUS_NEW = u'new'
|
|
1831
|
STATUS_OPEN = u'open'
|
|
1841
|
STATUS_OPEN = u'open'
|
|
1832
|
STATUS_CLOSED = u'closed'
|
|
1842
|
STATUS_CLOSED = u'closed'
|
|
1833
|
|
|
1843
|
|
|
1834
|
pull_request_id = Column('pull_request_id', Integer(), nullable=False, primary_key=True)
|
|
1844
|
pull_request_id = Column('pull_request_id', Integer(), nullable=False, primary_key=True)
|
|
1835
|
title = Column('title', Unicode(256), nullable=True)
|
|
1845
|
title = Column('title', Unicode(256), nullable=True)
|
|
1836
|
description = Column('description', UnicodeText(10240), nullable=True)
|
|
1846
|
description = Column('description', UnicodeText(10240), nullable=True)
|
|
1837
|
status = Column('status', Unicode(256), nullable=False, default=STATUS_NEW)
|
|
1847
|
status = Column('status', Unicode(256), nullable=False, default=STATUS_NEW)
|
|
1838
|
created_on = Column('created_on', DateTime(timezone=False), nullable=False, default=datetime.datetime.now)
|
|
1848
|
created_on = Column('created_on', DateTime(timezone=False), nullable=False, default=datetime.datetime.now)
|
|
1839
|
updated_on = Column('updated_on', DateTime(timezone=False), nullable=False, default=datetime.datetime.now)
|
|
1849
|
updated_on = Column('updated_on', DateTime(timezone=False), nullable=False, default=datetime.datetime.now)
|
|
1840
|
user_id = Column("user_id", Integer(), ForeignKey('users.user_id'), nullable=False, unique=None)
|
|
1850
|
user_id = Column("user_id", Integer(), ForeignKey('users.user_id'), nullable=False, unique=None)
|
|
1841
|
_revisions = Column('revisions', UnicodeText(20500)) # 500 revisions max
|
|
1851
|
_revisions = Column('revisions', UnicodeText(20500)) # 500 revisions max
|
|
1842
|
org_repo_id = Column('org_repo_id', Integer(), ForeignKey('repositories.repo_id'), nullable=False)
|
|
1852
|
org_repo_id = Column('org_repo_id', Integer(), ForeignKey('repositories.repo_id'), nullable=False)
|
|
1843
|
org_ref = Column('org_ref', Unicode(256), nullable=False)
|
|
1853
|
org_ref = Column('org_ref', Unicode(256), nullable=False)
|
|
1844
|
other_repo_id = Column('other_repo_id', Integer(), ForeignKey('repositories.repo_id'), nullable=False)
|
|
1854
|
other_repo_id = Column('other_repo_id', Integer(), ForeignKey('repositories.repo_id'), nullable=False)
|
|
1845
|
other_ref = Column('other_ref', Unicode(256), nullable=False)
|
|
1855
|
other_ref = Column('other_ref', Unicode(256), nullable=False)
|
|
1846
|
|
|
1856
|
|
|
1847
|
@hybrid_property
|
|
1857
|
@hybrid_property
|
|
1848
|
def revisions(self):
|
|
1858
|
def revisions(self):
|
|
1849
|
return self._revisions.split(':')
|
|
1859
|
return self._revisions.split(':')
|
|
1850
|
|
|
1860
|
|
|
1851
|
@revisions.setter
|
|
1861
|
@revisions.setter
|
|
1852
|
def revisions(self, val):
|
|
1862
|
def revisions(self, val):
|
|
1853
|
self._revisions = ':'.join(val)
|
|
1863
|
self._revisions = ':'.join(val)
|
|
1854
|
|
|
1864
|
|
|
1855
|
@property
|
|
1865
|
@property
|
|
1856
|
def org_ref_parts(self):
|
|
1866
|
def org_ref_parts(self):
|
|
1857
|
return self.org_ref.split(':')
|
|
1867
|
return self.org_ref.split(':')
|
|
1858
|
|
|
1868
|
|
|
1859
|
@property
|
|
1869
|
@property
|
|
1860
|
def other_ref_parts(self):
|
|
1870
|
def other_ref_parts(self):
|
|
1861
|
return self.other_ref.split(':')
|
|
1871
|
return self.other_ref.split(':')
|
|
1862
|
|
|
1872
|
|
|
1863
|
author = relationship('User', lazy='joined')
|
|
1873
|
author = relationship('User', lazy='joined')
|
|
1864
|
reviewers = relationship('PullRequestReviewers',
|
|
1874
|
reviewers = relationship('PullRequestReviewers',
|
|
1865
|
cascade="all, delete, delete-orphan")
|
|
1875
|
cascade="all, delete, delete-orphan")
|
|
1866
|
org_repo = relationship('Repository', primaryjoin='PullRequest.org_repo_id==Repository.repo_id')
|
|
1876
|
org_repo = relationship('Repository', primaryjoin='PullRequest.org_repo_id==Repository.repo_id')
|
|
1867
|
other_repo = relationship('Repository', primaryjoin='PullRequest.other_repo_id==Repository.repo_id')
|
|
1877
|
other_repo = relationship('Repository', primaryjoin='PullRequest.other_repo_id==Repository.repo_id')
|
|
1868
|
statuses = relationship('ChangesetStatus')
|
|
1878
|
statuses = relationship('ChangesetStatus')
|
|
1869
|
comments = relationship('ChangesetComment',
|
|
1879
|
comments = relationship('ChangesetComment',
|
|
1870
|
cascade="all, delete, delete-orphan")
|
|
1880
|
cascade="all, delete, delete-orphan")
|
|
1871
|
|
|
1881
|
|
|
1872
|
def is_closed(self):
|
|
1882
|
def is_closed(self):
|
|
1873
|
return self.status == self.STATUS_CLOSED
|
|
1883
|
return self.status == self.STATUS_CLOSED
|
|
1874
|
|
|
1884
|
|
|
1875
|
def __json__(self):
|
|
1885
|
def __json__(self):
|
|
1876
|
return dict(
|
|
1886
|
return dict(
|
|
1877
|
revisions=self.revisions
|
|
1887
|
revisions=self.revisions
|
|
1878
|
)
|
|
1888
|
)
|
|
1879
|
|
|
1889
|
|
|
1880
|
|
|
1890
|
|
|
1881
|
class PullRequestReviewers(Base, BaseModel):
|
|
1891
|
class PullRequestReviewers(Base, BaseModel):
|
|
1882
|
__tablename__ = 'pull_request_reviewers'
|
|
1892
|
__tablename__ = 'pull_request_reviewers'
|
|
1883
|
__table_args__ = (
|
|
1893
|
__table_args__ = (
|
|
1884
|
{'extend_existing': True, 'mysql_engine': 'InnoDB',
|
|
1894
|
{'extend_existing': True, 'mysql_engine': 'InnoDB',
|
|
1885
|
'mysql_charset': 'utf8'},
|
|
1895
|
'mysql_charset': 'utf8'},
|
|
1886
|
)
|
|
1896
|
)
|
|
1887
|
|
|
1897
|
|
|
1888
|
def __init__(self, user=None, pull_request=None):
|
|
1898
|
def __init__(self, user=None, pull_request=None):
|
|
1889
|
self.user = user
|
|
1899
|
self.user = user
|
|
1890
|
self.pull_request = pull_request
|
|
1900
|
self.pull_request = pull_request
|
|
1891
|
|
|
1901
|
|
|
1892
|
pull_requests_reviewers_id = Column('pull_requests_reviewers_id', Integer(), nullable=False, primary_key=True)
|
|
1902
|
pull_requests_reviewers_id = Column('pull_requests_reviewers_id', Integer(), nullable=False, primary_key=True)
|
|
1893
|
pull_request_id = Column("pull_request_id", Integer(), ForeignKey('pull_requests.pull_request_id'), nullable=False)
|
|
1903
|
pull_request_id = Column("pull_request_id", Integer(), ForeignKey('pull_requests.pull_request_id'), nullable=False)
|
|
1894
|
user_id = Column("user_id", Integer(), ForeignKey('users.user_id'), nullable=True)
|
|
1904
|
user_id = Column("user_id", Integer(), ForeignKey('users.user_id'), nullable=True)
|
|
1895
|
|
|
1905
|
|
|
1896
|
user = relationship('User')
|
|
1906
|
user = relationship('User')
|
|
1897
|
pull_request = relationship('PullRequest')
|
|
1907
|
pull_request = relationship('PullRequest')
|
|
1898
|
|
|
1908
|
|
|
1899
|
|
|
1909
|
|
|
1900
|
class Notification(Base, BaseModel):
|
|
1910
|
class Notification(Base, BaseModel):
|
|
1901
|
__tablename__ = 'notifications'
|
|
1911
|
__tablename__ = 'notifications'
|
|
1902
|
__table_args__ = (
|
|
1912
|
__table_args__ = (
|
|
1903
|
Index('notification_type_idx', 'type'),
|
|
1913
|
Index('notification_type_idx', 'type'),
|
|
1904
|
{'extend_existing': True, 'mysql_engine': 'InnoDB',
|
|
1914
|
{'extend_existing': True, 'mysql_engine': 'InnoDB',
|
|
1905
|
'mysql_charset': 'utf8'},
|
|
1915
|
'mysql_charset': 'utf8'},
|
|
1906
|
)
|
|
1916
|
)
|
|
1907
|
|
|
1917
|
|
|
1908
|
TYPE_CHANGESET_COMMENT = u'cs_comment'
|
|
1918
|
TYPE_CHANGESET_COMMENT = u'cs_comment'
|
|
1909
|
TYPE_MESSAGE = u'message'
|
|
1919
|
TYPE_MESSAGE = u'message'
|
|
1910
|
TYPE_MENTION = u'mention'
|
|
1920
|
TYPE_MENTION = u'mention'
|
|
1911
|
TYPE_REGISTRATION = u'registration'
|
|
1921
|
TYPE_REGISTRATION = u'registration'
|
|
1912
|
TYPE_PULL_REQUEST = u'pull_request'
|
|
1922
|
TYPE_PULL_REQUEST = u'pull_request'
|
|
1913
|
TYPE_PULL_REQUEST_COMMENT = u'pull_request_comment'
|
|
1923
|
TYPE_PULL_REQUEST_COMMENT = u'pull_request_comment'
|
|
1914
|
|
|
1924
|
|
|
1915
|
notification_id = Column('notification_id', Integer(), nullable=False, primary_key=True)
|
|
1925
|
notification_id = Column('notification_id', Integer(), nullable=False, primary_key=True)
|
|
1916
|
subject = Column('subject', Unicode(512), nullable=True)
|
|
1926
|
subject = Column('subject', Unicode(512), nullable=True)
|
|
1917
|
body = Column('body', UnicodeText(50000), nullable=True)
|
|
1927
|
body = Column('body', UnicodeText(50000), nullable=True)
|
|
1918
|
created_by = Column("created_by", Integer(), ForeignKey('users.user_id'), nullable=True)
|
|
1928
|
created_by = Column("created_by", Integer(), ForeignKey('users.user_id'), nullable=True)
|
|
1919
|
created_on = Column('created_on', DateTime(timezone=False), nullable=False, default=datetime.datetime.now)
|
|
1929
|
created_on = Column('created_on', DateTime(timezone=False), nullable=False, default=datetime.datetime.now)
|
|
1920
|
type_ = Column('type', Unicode(256))
|
|
1930
|
type_ = Column('type', Unicode(256))
|
|
1921
|
|
|
1931
|
|
|
1922
|
created_by_user = relationship('User')
|
|
1932
|
created_by_user = relationship('User')
|
|
1923
|
notifications_to_users = relationship('UserNotification', lazy='joined',
|
|
1933
|
notifications_to_users = relationship('UserNotification', lazy='joined',
|
|
1924
|
cascade="all, delete, delete-orphan")
|
|
1934
|
cascade="all, delete, delete-orphan")
|
|
1925
|
|
|
1935
|
|
|
1926
|
@property
|
|
1936
|
@property
|
|
1927
|
def recipients(self):
|
|
1937
|
def recipients(self):
|
|
1928
|
return [x.user for x in UserNotification.query()\
|
|
1938
|
return [x.user for x in UserNotification.query()\
|
|
1929
|
.filter(UserNotification.notification == self)\
|
|
1939
|
.filter(UserNotification.notification == self)\
|
|
1930
|
.order_by(UserNotification.user_id.asc()).all()]
|
|
1940
|
.order_by(UserNotification.user_id.asc()).all()]
|
|
1931
|
|
|
1941
|
|
|
1932
|
@classmethod
|
|
1942
|
@classmethod
|
|
1933
|
def create(cls, created_by, subject, body, recipients, type_=None):
|
|
1943
|
def create(cls, created_by, subject, body, recipients, type_=None):
|
|
1934
|
if type_ is None:
|
|
1944
|
if type_ is None:
|
|
1935
|
type_ = Notification.TYPE_MESSAGE
|
|
1945
|
type_ = Notification.TYPE_MESSAGE
|
|
1936
|
|
|
1946
|
|
|
1937
|
notification = cls()
|
|
1947
|
notification = cls()
|
|
1938
|
notification.created_by_user = created_by
|
|
1948
|
notification.created_by_user = created_by
|
|
1939
|
notification.subject = subject
|
|
1949
|
notification.subject = subject
|
|
1940
|
notification.body = body
|
|
1950
|
notification.body = body
|
|
1941
|
notification.type_ = type_
|
|
1951
|
notification.type_ = type_
|
|
1942
|
notification.created_on = datetime.datetime.now()
|
|
1952
|
notification.created_on = datetime.datetime.now()
|
|
1943
|
|
|
1953
|
|
|
1944
|
for u in recipients:
|
|
1954
|
for u in recipients:
|
|
1945
|
assoc = UserNotification()
|
|
1955
|
assoc = UserNotification()
|
|
1946
|
assoc.notification = notification
|
|
1956
|
assoc.notification = notification
|
|
1947
|
u.notifications.append(assoc)
|
|
1957
|
u.notifications.append(assoc)
|
|
1948
|
Session().add(notification)
|
|
1958
|
Session().add(notification)
|
|
1949
|
return notification
|
|
1959
|
return notification
|
|
1950
|
|
|
1960
|
|
|
1951
|
@property
|
|
1961
|
@property
|
|
1952
|
def description(self):
|
|
1962
|
def description(self):
|
|
1953
|
from rhodecode.model.notification import NotificationModel
|
|
1963
|
from rhodecode.model.notification import NotificationModel
|
|
1954
|
return NotificationModel().make_description(self)
|
|
1964
|
return NotificationModel().make_description(self)
|
|
1955
|
|
|
1965
|
|
|
1956
|
|
|
1966
|
|
|
1957
|
class UserNotification(Base, BaseModel):
|
|
1967
|
class UserNotification(Base, BaseModel):
|
|
1958
|
__tablename__ = 'user_to_notification'
|
|
1968
|
__tablename__ = 'user_to_notification'
|
|
1959
|
__table_args__ = (
|
|
1969
|
__table_args__ = (
|
|
1960
|
UniqueConstraint('user_id', 'notification_id'),
|
|
1970
|
UniqueConstraint('user_id', 'notification_id'),
|
|
1961
|
{'extend_existing': True, 'mysql_engine': 'InnoDB',
|
|
1971
|
{'extend_existing': True, 'mysql_engine': 'InnoDB',
|
|
1962
|
'mysql_charset': 'utf8'}
|
|
1972
|
'mysql_charset': 'utf8'}
|
|
1963
|
)
|
|
1973
|
)
|
|
1964
|
user_id = Column('user_id', Integer(), ForeignKey('users.user_id'), primary_key=True)
|
|
1974
|
user_id = Column('user_id', Integer(), ForeignKey('users.user_id'), primary_key=True)
|
|
1965
|
notification_id = Column("notification_id", Integer(), ForeignKey('notifications.notification_id'), primary_key=True)
|
|
1975
|
notification_id = Column("notification_id", Integer(), ForeignKey('notifications.notification_id'), primary_key=True)
|
|
1966
|
read = Column('read', Boolean, default=False)
|
|
1976
|
read = Column('read', Boolean, default=False)
|
|
1967
|
sent_on = Column('sent_on', DateTime(timezone=False), nullable=True, unique=None)
|
|
1977
|
sent_on = Column('sent_on', DateTime(timezone=False), nullable=True, unique=None)
|
|
1968
|
|
|
1978
|
|
|
1969
|
user = relationship('User', lazy="joined")
|
|
1979
|
user = relationship('User', lazy="joined")
|
|
1970
|
notification = relationship('Notification', lazy="joined",
|
|
1980
|
notification = relationship('Notification', lazy="joined",
|
|
1971
|
order_by=lambda: Notification.created_on.desc(),)
|
|
1981
|
order_by=lambda: Notification.created_on.desc(),)
|
|
1972
|
|
|
1982
|
|
|
1973
|
def mark_as_read(self):
|
|
1983
|
def mark_as_read(self):
|
|
1974
|
self.read = True
|
|
1984
|
self.read = True
|
|
1975
|
Session().add(self)
|
|
1985
|
Session().add(self)
|
|
1976
|
|
|
1986
|
|
|
1977
|
|
|
1987
|
|
|
1978
|
class DbMigrateVersion(Base, BaseModel):
|
|
1988
|
class DbMigrateVersion(Base, BaseModel):
|
|
1979
|
__tablename__ = 'db_migrate_version'
|
|
1989
|
__tablename__ = 'db_migrate_version'
|
|
1980
|
__table_args__ = (
|
|
1990
|
__table_args__ = (
|
|
1981
|
{'extend_existing': True, 'mysql_engine': 'InnoDB',
|
|
1991
|
{'extend_existing': True, 'mysql_engine': 'InnoDB',
|
|
1982
|
'mysql_charset': 'utf8'},
|
|
1992
|
'mysql_charset': 'utf8'},
|
|
1983
|
)
|
|
1993
|
)
|
|
1984
|
repository_id = Column('repository_id', String(250), primary_key=True)
|
|
1994
|
repository_id = Column('repository_id', String(250), primary_key=True)
|
|
1985
|
repository_path = Column('repository_path', Text)
|
|
1995
|
repository_path = Column('repository_path', Text)
|
|
1986
|
version = Column('version', Integer)
|
|
1996
|
version = Column('version', Integer)
|