This diff has been collapsed as it changes many lines, (903 lines changed)
Show them
Hide them
|
|
@@
-51,146
+51,149
b' from rhodecode.model.meta import Base, S'
|
|
51
|
from rhodecode.model.caching_query import FromCache
|
|
51
|
from rhodecode.model.caching_query import FromCache
|
|
52
|
|
|
52
|
|
|
53
|
|
|
53
|
|
|
54
|
log = logging.getLogger(__name__)
|
|
54
|
log = logging.getLogger( __name__ )
|
|
55
|
|
|
55
|
|
|
56
|
#==============================================================================
|
|
56
|
#==============================================================================
|
|
57
|
# BASE CLASSES
|
|
57
|
# BASE CLASSES
|
|
58
|
#==============================================================================
|
|
58
|
#==============================================================================
|
|
59
|
|
|
59
|
|
|
60
|
class ModelSerializer(json.JSONEncoder):
|
|
60
|
class ModelSerializer( json.JSONEncoder ):
|
|
61
|
"""
|
|
61
|
"""
|
|
62
|
Simple Serializer for JSON,
|
|
62
|
Simple Serializer for JSON,
|
|
63
|
|
|
63
|
|
|
64
|
usage::
|
|
64
|
usage::
|
|
65
|
|
|
65
|
|
|
66
|
to make object customized for serialization implement a __json__
|
|
66
|
to make object customized for serialization implement a __json__
|
|
67
|
method that will return a dict for serialization into json
|
|
67
|
method that will return a dict for serialization into json
|
|
68
|
|
|
68
|
|
|
69
|
example::
|
|
69
|
example::
|
|
70
|
|
|
70
|
|
|
71
|
class Task(object):
|
|
71
|
class Task(object):
|
|
72
|
|
|
72
|
|
|
73
|
def __init__(self, name, value):
|
|
73
|
def __init__(self, name, value):
|
|
74
|
self.name = name
|
|
74
|
self.name = name
|
|
75
|
self.value = value
|
|
75
|
self.value = value
|
|
76
|
|
|
76
|
|
|
77
|
def __json__(self):
|
|
77
|
def __json__(self):
|
|
78
|
return dict(name=self.name,
|
|
78
|
return dict(name=self.name,
|
|
79
|
value=self.value)
|
|
79
|
value=self.value)
|
|
80
|
|
|
80
|
|
|
81
|
"""
|
|
81
|
"""
|
|
82
|
|
|
82
|
|
|
83
|
def default(self, obj):
|
|
83
|
def default( self, obj ):
|
|
84
|
|
|
84
|
|
|
85
|
if hasattr(obj, '__json__'):
|
|
85
|
if hasattr( obj, '__json__' ):
|
|
86
|
return obj.__json__()
|
|
86
|
return obj.__json__()
|
|
87
|
else:
|
|
87
|
else:
|
|
88
|
return json.JSONEncoder.default(self, obj)
|
|
88
|
return json.JSONEncoder.default( self, obj )
|
|
89
|
|
|
89
|
|
|
90
|
class BaseModel(object):
|
|
90
|
class BaseModel( object ):
|
|
91
|
"""Base Model for all classess
|
|
91
|
"""Base Model for all classess
|
|
92
|
|
|
92
|
|
|
93
|
"""
|
|
93
|
"""
|
|
94
|
|
|
94
|
|
|
95
|
@classmethod
|
|
95
|
@classmethod
|
|
96
|
def _get_keys(cls):
|
|
96
|
def _get_keys( cls ):
|
|
97
|
"""return column names for this model """
|
|
97
|
"""return column names for this model """
|
|
98
|
return class_mapper(cls).c.keys()
|
|
98
|
return class_mapper( cls ).c.keys()
|
|
99
|
|
|
99
|
|
|
100
|
def get_dict(self):
|
|
100
|
def get_dict( self ):
|
|
101
|
"""return dict with keys and values corresponding
|
|
101
|
"""return dict with keys and values corresponding
|
|
102
|
to this model data """
|
|
102
|
to this model data """
|
|
103
|
|
|
103
|
|
|
104
|
d = {}
|
|
104
|
d = {}
|
|
105
|
for k in self._get_keys():
|
|
105
|
for k in self._get_keys():
|
|
106
|
d[k] = getattr(self, k)
|
|
106
|
d[k] = getattr( self, k )
|
|
107
|
return d
|
|
107
|
return d
|
|
108
|
|
|
108
|
|
|
109
|
def get_appstruct(self):
|
|
109
|
def get_appstruct( self ):
|
|
110
|
"""return list with keys and values tupples corresponding
|
|
110
|
"""return list with keys and values tupples corresponding
|
|
111
|
to this model data """
|
|
111
|
to this model data """
|
|
112
|
|
|
112
|
|
|
113
|
l = []
|
|
113
|
l = []
|
|
114
|
for k in self._get_keys():
|
|
114
|
for k in self._get_keys():
|
|
115
|
l.append((k, getattr(self, k),))
|
|
115
|
l.append( ( k, getattr( self, k ), ) )
|
|
116
|
return l
|
|
116
|
return l
|
|
117
|
|
|
117
|
|
|
118
|
def populate_obj(self, populate_dict):
|
|
118
|
def populate_obj( self, populate_dict ):
|
|
119
|
"""populate model with data from given populate_dict"""
|
|
119
|
"""populate model with data from given populate_dict"""
|
|
120
|
|
|
120
|
|
|
121
|
for k in self._get_keys():
|
|
121
|
for k in self._get_keys():
|
|
122
|
if k in populate_dict:
|
|
122
|
if k in populate_dict:
|
|
123
|
setattr(self, k, populate_dict[k])
|
|
123
|
setattr( self, k, populate_dict[k] )
|
|
124
|
|
|
124
|
|
|
125
|
@classmethod
|
|
125
|
@classmethod
|
|
126
|
def query(cls):
|
|
126
|
def query( cls ):
|
|
127
|
return Session.query(cls)
|
|
127
|
return Session.query( cls )
|
|
128
|
|
|
128
|
|
|
129
|
@classmethod
|
|
129
|
@classmethod
|
|
130
|
def get(cls, id_):
|
|
130
|
def get( cls, id_ ):
|
|
131
|
if id_:
|
|
131
|
return cls.query().get( id_ )
|
|
132
|
return Session.query(cls).get(id_)
|
|
|
|
|
133
|
|
|
132
|
|
|
134
|
@classmethod
|
|
133
|
@classmethod
|
|
135
|
def delete(cls, id_):
|
|
134
|
def getAll( cls ):
|
|
136
|
obj = Session.query(cls).get(id_)
|
|
135
|
return cls.query().all()
|
|
137
|
Session.delete(obj)
|
|
136
|
|
|
|
|
|
137
|
@classmethod
|
|
|
|
|
138
|
def delete( cls, id_ ):
|
|
|
|
|
139
|
obj = cls.query().get( id_ )
|
|
|
|
|
140
|
Session.delete( obj )
|
|
138
|
Session.commit()
|
|
141
|
Session.commit()
|
|
139
|
|
|
142
|
|
|
140
|
|
|
143
|
|
|
141
|
class RhodeCodeSettings(Base, BaseModel):
|
|
144
|
class RhodeCodeSettings( Base, BaseModel ):
|
|
142
|
__tablename__ = 'rhodecode_settings'
|
|
145
|
__tablename__ = 'rhodecode_settings'
|
|
143
|
__table_args__ = (UniqueConstraint('app_settings_name'), {'extend_existing':True})
|
|
146
|
__table_args__ = ( UniqueConstraint( 'app_settings_name' ), {'extend_existing':True} )
|
|
144
|
app_settings_id = Column("app_settings_id", Integer(), nullable=False, unique=True, default=None, primary_key=True)
|
|
147
|
app_settings_id = Column( "app_settings_id", Integer(), nullable = False, unique = True, default = None, primary_key = True )
|
|
145
|
app_settings_name = Column("app_settings_name", String(length=255, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None)
|
|
148
|
app_settings_name = Column( "app_settings_name", String( length = 255, convert_unicode = False, assert_unicode = None ), nullable = True, unique = None, default = None )
|
|
146
|
_app_settings_value = Column("app_settings_value", String(length=255, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None)
|
|
149
|
_app_settings_value = Column( "app_settings_value", String( length = 255, convert_unicode = False, assert_unicode = None ), nullable = True, unique = None, default = None )
|
|
147
|
|
|
150
|
|
|
148
|
def __init__(self, k='', v=''):
|
|
151
|
def __init__( self, k = '', v = '' ):
|
|
149
|
self.app_settings_name = k
|
|
152
|
self.app_settings_name = k
|
|
150
|
self.app_settings_value = v
|
|
153
|
self.app_settings_value = v
|
|
151
|
|
|
154
|
|
|
152
|
|
|
155
|
|
|
153
|
@validates('_app_settings_value')
|
|
156
|
@validates( '_app_settings_value' )
|
|
154
|
def validate_settings_value(self, key, val):
|
|
157
|
def validate_settings_value( self, key, val ):
|
|
155
|
assert type(val) == unicode
|
|
158
|
assert type( val ) == unicode
|
|
156
|
return val
|
|
159
|
return val
|
|
157
|
|
|
160
|
|
|
158
|
@hybrid_property
|
|
161
|
@hybrid_property
|
|
159
|
def app_settings_value(self):
|
|
162
|
def app_settings_value( self ):
|
|
160
|
v = self._app_settings_value
|
|
163
|
v = self._app_settings_value
|
|
161
|
if v == 'ldap_active':
|
|
164
|
if v == 'ldap_active':
|
|
162
|
v = str2bool(v)
|
|
165
|
v = str2bool( v )
|
|
163
|
return v
|
|
166
|
return v
|
|
164
|
|
|
167
|
|
|
165
|
@app_settings_value.setter
|
|
168
|
@app_settings_value.setter
|
|
166
|
def app_settings_value(self,val):
|
|
169
|
def app_settings_value( self, val ):
|
|
167
|
"""
|
|
170
|
"""
|
|
168
|
Setter that will always make sure we use unicode in app_settings_value
|
|
171
|
Setter that will always make sure we use unicode in app_settings_value
|
|
169
|
|
|
172
|
|
|
170
|
:param val:
|
|
173
|
:param val:
|
|
171
|
"""
|
|
174
|
"""
|
|
172
|
self._app_settings_value = safe_unicode(val)
|
|
175
|
self._app_settings_value = safe_unicode( val )
|
|
173
|
|
|
176
|
|
|
174
|
def __repr__(self):
|
|
177
|
def __repr__( self ):
|
|
175
|
return "<%s('%s:%s')>" % (self.__class__.__name__,
|
|
178
|
return "<%s('%s:%s')>" % ( self.__class__.__name__,
|
|
176
|
self.app_settings_name, self.app_settings_value)
|
|
179
|
self.app_settings_name, self.app_settings_value )
|
|
177
|
|
|
180
|
|
|
178
|
|
|
181
|
|
|
179
|
@classmethod
|
|
182
|
@classmethod
|
|
180
|
def get_by_name(cls, ldap_key):
|
|
183
|
def get_by_name( cls, ldap_key ):
|
|
181
|
return Session.query(cls)\
|
|
184
|
return cls.query()\
|
|
182
|
.filter(cls.app_settings_name == ldap_key).scalar()
|
|
185
|
.filter( cls.app_settings_name == ldap_key ).scalar()
|
|
183
|
|
|
186
|
|
|
184
|
@classmethod
|
|
187
|
@classmethod
|
|
185
|
def get_app_settings(cls, cache=False):
|
|
188
|
def get_app_settings( cls, cache = False ):
|
|
186
|
|
|
189
|
|
|
187
|
ret = Session.query(cls)
|
|
190
|
ret = cls.query()
|
|
188
|
|
|
191
|
|
|
189
|
if cache:
|
|
192
|
if cache:
|
|
190
|
ret = ret.options(FromCache("sql_cache_short", "get_hg_settings"))
|
|
193
|
ret = ret.options( FromCache( "sql_cache_short", "get_hg_settings" ) )
|
|
191
|
|
|
194
|
|
|
192
|
if not ret:
|
|
195
|
if not ret:
|
|
193
|
raise Exception('Could not get application settings !')
|
|
196
|
raise Exception( 'Could not get application settings !' )
|
|
194
|
settings = {}
|
|
197
|
settings = {}
|
|
195
|
for each in ret:
|
|
198
|
for each in ret:
|
|
196
|
settings['rhodecode_' + each.app_settings_name] = \
|
|
199
|
settings['rhodecode_' + each.app_settings_name] = \
|
|
@@
-199,222
+202,222
b' class RhodeCodeSettings(Base, BaseModel)'
|
|
199
|
return settings
|
|
202
|
return settings
|
|
200
|
|
|
203
|
|
|
201
|
@classmethod
|
|
204
|
@classmethod
|
|
202
|
def get_ldap_settings(cls, cache=False):
|
|
205
|
def get_ldap_settings( cls, cache = False ):
|
|
203
|
ret = Session.query(cls)\
|
|
206
|
ret = cls.query()\
|
|
204
|
.filter(cls.app_settings_name.startswith('ldap_')).all()
|
|
207
|
.filter( cls.app_settings_name.startswith( 'ldap_' ) ).all()
|
|
205
|
fd = {}
|
|
208
|
fd = {}
|
|
206
|
for row in ret:
|
|
209
|
for row in ret:
|
|
207
|
fd.update({row.app_settings_name:row.app_settings_value})
|
|
210
|
fd.update( {row.app_settings_name:row.app_settings_value} )
|
|
208
|
|
|
211
|
|
|
209
|
return fd
|
|
212
|
return fd
|
|
210
|
|
|
213
|
|
|
211
|
|
|
214
|
|
|
212
|
class RhodeCodeUi(Base, BaseModel):
|
|
215
|
class RhodeCodeUi( Base, BaseModel ):
|
|
213
|
__tablename__ = 'rhodecode_ui'
|
|
216
|
__tablename__ = 'rhodecode_ui'
|
|
214
|
__table_args__ = (UniqueConstraint('ui_key'), {'extend_existing':True})
|
|
217
|
__table_args__ = ( UniqueConstraint( 'ui_key' ), {'extend_existing':True} )
|
|
215
|
|
|
218
|
|
|
216
|
HOOK_UPDATE = 'changegroup.update'
|
|
219
|
HOOK_UPDATE = 'changegroup.update'
|
|
217
|
HOOK_REPO_SIZE = 'changegroup.repo_size'
|
|
220
|
HOOK_REPO_SIZE = 'changegroup.repo_size'
|
|
218
|
HOOK_PUSH = 'pretxnchangegroup.push_logger'
|
|
221
|
HOOK_PUSH = 'pretxnchangegroup.push_logger'
|
|
219
|
HOOK_PULL = 'preoutgoing.pull_logger'
|
|
222
|
HOOK_PULL = 'preoutgoing.pull_logger'
|
|
220
|
|
|
223
|
|
|
221
|
ui_id = Column("ui_id", Integer(), nullable=False, unique=True, default=None, primary_key=True)
|
|
224
|
ui_id = Column( "ui_id", Integer(), nullable = False, unique = True, default = None, primary_key = True )
|
|
222
|
ui_section = Column("ui_section", String(length=255, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None)
|
|
225
|
ui_section = Column( "ui_section", String( length = 255, convert_unicode = False, assert_unicode = None ), nullable = True, unique = None, default = None )
|
|
223
|
ui_key = Column("ui_key", String(length=255, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None)
|
|
226
|
ui_key = Column( "ui_key", String( length = 255, convert_unicode = False, assert_unicode = None ), nullable = True, unique = None, default = None )
|
|
224
|
ui_value = Column("ui_value", String(length=255, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None)
|
|
227
|
ui_value = Column( "ui_value", String( length = 255, convert_unicode = False, assert_unicode = None ), nullable = True, unique = None, default = None )
|
|
225
|
ui_active = Column("ui_active", Boolean(), nullable=True, unique=None, default=True)
|
|
228
|
ui_active = Column( "ui_active", Boolean(), nullable = True, unique = None, default = True )
|
|
226
|
|
|
229
|
|
|
227
|
|
|
230
|
|
|
228
|
@classmethod
|
|
231
|
@classmethod
|
|
229
|
def get_by_key(cls, key):
|
|
232
|
def get_by_key( cls, key ):
|
|
230
|
return Session.query(cls).filter(cls.ui_key == key)
|
|
233
|
return cls.query().filter( cls.ui_key == key )
|
|
231
|
|
|
234
|
|
|
232
|
|
|
235
|
|
|
233
|
@classmethod
|
|
236
|
@classmethod
|
|
234
|
def get_builtin_hooks(cls):
|
|
237
|
def get_builtin_hooks( cls ):
|
|
235
|
q = cls.query()
|
|
238
|
q = cls.query()
|
|
236
|
q = q.filter(cls.ui_key.in_([cls.HOOK_UPDATE,
|
|
239
|
q = q.filter( cls.ui_key.in_( [cls.HOOK_UPDATE,
|
|
237
|
cls.HOOK_REPO_SIZE,
|
|
240
|
cls.HOOK_REPO_SIZE,
|
|
238
|
cls.HOOK_PUSH, cls.HOOK_PULL]))
|
|
241
|
cls.HOOK_PUSH, cls.HOOK_PULL] ) )
|
|
239
|
return q.all()
|
|
242
|
return q.all()
|
|
240
|
|
|
243
|
|
|
241
|
@classmethod
|
|
244
|
@classmethod
|
|
242
|
def get_custom_hooks(cls):
|
|
245
|
def get_custom_hooks( cls ):
|
|
243
|
q = cls.query()
|
|
246
|
q = cls.query()
|
|
244
|
q = q.filter(~cls.ui_key.in_([cls.HOOK_UPDATE,
|
|
247
|
q = q.filter( ~cls.ui_key.in_( [cls.HOOK_UPDATE,
|
|
245
|
cls.HOOK_REPO_SIZE,
|
|
248
|
cls.HOOK_REPO_SIZE,
|
|
246
|
cls.HOOK_PUSH, cls.HOOK_PULL]))
|
|
249
|
cls.HOOK_PUSH, cls.HOOK_PULL] ) )
|
|
247
|
q = q.filter(cls.ui_section == 'hooks')
|
|
250
|
q = q.filter( cls.ui_section == 'hooks' )
|
|
248
|
return q.all()
|
|
251
|
return q.all()
|
|
249
|
|
|
252
|
|
|
250
|
@classmethod
|
|
253
|
@classmethod
|
|
251
|
def create_or_update_hook(cls, key, val):
|
|
254
|
def create_or_update_hook( cls, key, val ):
|
|
252
|
new_ui = cls.get_by_key(key).scalar() or cls()
|
|
255
|
new_ui = cls.get_by_key( key ).scalar() or cls()
|
|
253
|
new_ui.ui_section = 'hooks'
|
|
256
|
new_ui.ui_section = 'hooks'
|
|
254
|
new_ui.ui_active = True
|
|
257
|
new_ui.ui_active = True
|
|
255
|
new_ui.ui_key = key
|
|
258
|
new_ui.ui_key = key
|
|
256
|
new_ui.ui_value = val
|
|
259
|
new_ui.ui_value = val
|
|
257
|
|
|
260
|
|
|
258
|
Session.add(new_ui)
|
|
261
|
Session.add( new_ui )
|
|
259
|
Session.commit()
|
|
262
|
Session.commit()
|
|
260
|
|
|
263
|
|
|
261
|
|
|
264
|
|
|
262
|
class User(Base, BaseModel):
|
|
265
|
class User( Base, BaseModel ):
|
|
263
|
__tablename__ = 'users'
|
|
266
|
__tablename__ = 'users'
|
|
264
|
__table_args__ = (UniqueConstraint('username'), UniqueConstraint('email'), {'extend_existing':True})
|
|
267
|
__table_args__ = ( UniqueConstraint( 'username' ), UniqueConstraint( 'email' ), {'extend_existing':True} )
|
|
265
|
user_id = Column("user_id", Integer(), nullable=False, unique=True, default=None, primary_key=True)
|
|
268
|
user_id = Column( "user_id", Integer(), nullable = False, unique = True, default = None, primary_key = True )
|
|
266
|
username = Column("username", String(length=255, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None)
|
|
269
|
username = Column( "username", String( length = 255, convert_unicode = False, assert_unicode = None ), nullable = True, unique = None, default = None )
|
|
267
|
password = Column("password", String(length=255, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None)
|
|
270
|
password = Column( "password", String( length = 255, convert_unicode = False, assert_unicode = None ), nullable = True, unique = None, default = None )
|
|
268
|
active = Column("active", Boolean(), nullable=True, unique=None, default=None)
|
|
271
|
active = Column( "active", Boolean(), nullable = True, unique = None, default = None )
|
|
269
|
admin = Column("admin", Boolean(), nullable=True, unique=None, default=False)
|
|
272
|
admin = Column( "admin", Boolean(), nullable = True, unique = None, default = False )
|
|
270
|
name = Column("name", String(length=255, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None)
|
|
273
|
name = Column( "name", String( length = 255, convert_unicode = False, assert_unicode = None ), nullable = True, unique = None, default = None )
|
|
271
|
lastname = Column("lastname", String(length=255, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None)
|
|
274
|
lastname = Column( "lastname", String( length = 255, convert_unicode = False, assert_unicode = None ), nullable = True, unique = None, default = None )
|
|
272
|
email = Column("email", String(length=255, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None)
|
|
275
|
email = Column( "email", String( length = 255, convert_unicode = False, assert_unicode = None ), nullable = True, unique = None, default = None )
|
|
273
|
last_login = Column("last_login", DateTime(timezone=False), nullable=True, unique=None, default=None)
|
|
276
|
last_login = Column( "last_login", DateTime( timezone = False ), nullable = True, unique = None, default = None )
|
|
274
|
ldap_dn = Column("ldap_dn", String(length=255, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None)
|
|
277
|
ldap_dn = Column( "ldap_dn", String( length = 255, convert_unicode = False, assert_unicode = None ), nullable = True, unique = None, default = None )
|
|
275
|
api_key = Column("api_key", String(length=255, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None)
|
|
278
|
api_key = Column( "api_key", String( length = 255, convert_unicode = False, assert_unicode = None ), nullable = True, unique = None, default = None )
|
|
276
|
|
|
279
|
|
|
277
|
user_log = relationship('UserLog', cascade='all')
|
|
280
|
user_log = relationship( 'UserLog', cascade = 'all' )
|
|
278
|
user_perms = relationship('UserToPerm', primaryjoin="User.user_id==UserToPerm.user_id", cascade='all')
|
|
281
|
user_perms = relationship( 'UserToPerm', primaryjoin = "User.user_id==UserToPerm.user_id", cascade = 'all' )
|
|
279
|
|
|
282
|
|
|
280
|
repositories = relationship('Repository')
|
|
283
|
repositories = relationship( 'Repository' )
|
|
281
|
user_followers = relationship('UserFollowing', primaryjoin='UserFollowing.follows_user_id==User.user_id', cascade='all')
|
|
284
|
user_followers = relationship( 'UserFollowing', primaryjoin = 'UserFollowing.follows_user_id==User.user_id', cascade = 'all' )
|
|
282
|
repo_to_perm = relationship('RepoToPerm', primaryjoin='RepoToPerm.user_id==User.user_id', cascade='all')
|
|
285
|
repo_to_perm = relationship( 'RepoToPerm', primaryjoin = 'RepoToPerm.user_id==User.user_id', cascade = 'all' )
|
|
283
|
|
|
286
|
|
|
284
|
group_member = relationship('UsersGroupMember', cascade='all')
|
|
287
|
group_member = relationship( 'UsersGroupMember', cascade = 'all' )
|
|
285
|
|
|
288
|
|
|
286
|
@property
|
|
289
|
@property
|
|
287
|
def full_contact(self):
|
|
290
|
def full_contact( self ):
|
|
288
|
return '%s %s <%s>' % (self.name, self.lastname, self.email)
|
|
291
|
return '%s %s <%s>' % ( self.name, self.lastname, self.email )
|
|
289
|
|
|
292
|
|
|
290
|
@property
|
|
293
|
@property
|
|
291
|
def short_contact(self):
|
|
294
|
def short_contact( self ):
|
|
292
|
return '%s %s' % (self.name, self.lastname)
|
|
295
|
return '%s %s' % ( self.name, self.lastname )
|
|
293
|
|
|
296
|
|
|
294
|
@property
|
|
297
|
@property
|
|
295
|
def is_admin(self):
|
|
298
|
def is_admin( self ):
|
|
296
|
return self.admin
|
|
299
|
return self.admin
|
|
297
|
|
|
300
|
|
|
298
|
def __repr__(self):
|
|
301
|
def __repr__( self ):
|
|
299
|
try:
|
|
302
|
try:
|
|
300
|
return "<%s('id:%s:%s')>" % (self.__class__.__name__,
|
|
303
|
return "<%s('id:%s:%s')>" % ( self.__class__.__name__,
|
|
301
|
self.user_id, self.username)
|
|
304
|
self.user_id, self.username )
|
|
302
|
except:
|
|
305
|
except:
|
|
303
|
return self.__class__.__name__
|
|
306
|
return self.__class__.__name__
|
|
304
|
|
|
307
|
|
|
305
|
@classmethod
|
|
308
|
@classmethod
|
|
306
|
def get_by_username(cls, username, case_insensitive=False):
|
|
309
|
def get_by_username( cls, username, case_insensitive = False ):
|
|
307
|
if case_insensitive:
|
|
310
|
if case_insensitive:
|
|
308
|
return Session.query(cls).filter(cls.username.ilike(username)).scalar()
|
|
311
|
return Session.query( cls ).filter( cls.username.ilike( username ) ).scalar()
|
|
309
|
else:
|
|
312
|
else:
|
|
310
|
return Session.query(cls).filter(cls.username == username).scalar()
|
|
313
|
return Session.query( cls ).filter( cls.username == username ).scalar()
|
|
311
|
|
|
314
|
|
|
312
|
@classmethod
|
|
315
|
@classmethod
|
|
313
|
def get_by_api_key(cls, api_key):
|
|
316
|
def get_by_api_key( cls, api_key ):
|
|
314
|
return Session.query(cls).filter(cls.api_key == api_key).one()
|
|
317
|
return cls.query().filter( cls.api_key == api_key ).one()
|
|
315
|
|
|
318
|
|
|
316
|
def update_lastlogin(self):
|
|
319
|
def update_lastlogin( self ):
|
|
317
|
"""Update user lastlogin"""
|
|
320
|
"""Update user lastlogin"""
|
|
318
|
|
|
321
|
|
|
319
|
self.last_login = datetime.datetime.now()
|
|
322
|
self.last_login = datetime.datetime.now()
|
|
320
|
Session.add(self)
|
|
323
|
Session.add( self )
|
|
321
|
Session.commit()
|
|
324
|
Session.commit()
|
|
322
|
log.debug('updated user %s lastlogin', self.username)
|
|
325
|
log.debug( 'updated user %s lastlogin', self.username )
|
|
323
|
|
|
326
|
|
|
324
|
@classmethod
|
|
327
|
@classmethod
|
|
325
|
def create(cls, form_data):
|
|
328
|
def create( cls, form_data ):
|
|
326
|
from rhodecode.lib.auth import get_crypt_password
|
|
329
|
from rhodecode.lib.auth import get_crypt_password
|
|
327
|
|
|
330
|
|
|
328
|
try:
|
|
331
|
try:
|
|
329
|
new_user = cls()
|
|
332
|
new_user = cls()
|
|
330
|
for k, v in form_data.items():
|
|
333
|
for k, v in form_data.items():
|
|
331
|
if k == 'password':
|
|
334
|
if k == 'password':
|
|
332
|
v = get_crypt_password(v)
|
|
335
|
v = get_crypt_password( v )
|
|
333
|
setattr(new_user, k, v)
|
|
336
|
setattr( new_user, k, v )
|
|
334
|
|
|
337
|
|
|
335
|
new_user.api_key = generate_api_key(form_data['username'])
|
|
338
|
new_user.api_key = generate_api_key( form_data['username'] )
|
|
336
|
Session.add(new_user)
|
|
339
|
Session.add( new_user )
|
|
337
|
Session.commit()
|
|
340
|
Session.commit()
|
|
338
|
return new_user
|
|
341
|
return new_user
|
|
339
|
except:
|
|
342
|
except:
|
|
340
|
log.error(traceback.format_exc())
|
|
343
|
log.error( traceback.format_exc() )
|
|
341
|
Session.rollback()
|
|
344
|
Session.rollback()
|
|
342
|
raise
|
|
345
|
raise
|
|
343
|
|
|
346
|
|
|
344
|
class UserLog(Base, BaseModel):
|
|
347
|
class UserLog( Base, BaseModel ):
|
|
345
|
__tablename__ = 'user_logs'
|
|
348
|
__tablename__ = 'user_logs'
|
|
346
|
__table_args__ = {'extend_existing':True}
|
|
349
|
__table_args__ = {'extend_existing':True}
|
|
347
|
user_log_id = Column("user_log_id", Integer(), nullable=False, unique=True, default=None, primary_key=True)
|
|
350
|
user_log_id = Column( "user_log_id", Integer(), nullable = False, unique = True, default = None, primary_key = True )
|
|
348
|
user_id = Column("user_id", Integer(), ForeignKey('users.user_id'), nullable=False, unique=None, default=None)
|
|
351
|
user_id = Column( "user_id", Integer(), ForeignKey( 'users.user_id' ), nullable = False, unique = None, default = None )
|
|
349
|
repository_id = Column("repository_id", Integer(), ForeignKey('repositories.repo_id'), nullable=False, unique=None, default=None)
|
|
352
|
repository_id = Column( "repository_id", Integer(), ForeignKey( 'repositories.repo_id' ), nullable = False, unique = None, default = None )
|
|
350
|
repository_name = Column("repository_name", String(length=255, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None)
|
|
353
|
repository_name = Column( "repository_name", String( length = 255, convert_unicode = False, assert_unicode = None ), nullable = True, unique = None, default = None )
|
|
351
|
user_ip = Column("user_ip", String(length=255, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None)
|
|
354
|
user_ip = Column( "user_ip", String( length = 255, convert_unicode = False, assert_unicode = None ), nullable = True, unique = None, default = None )
|
|
352
|
action = Column("action", UnicodeText(length=1200000, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None)
|
|
355
|
action = Column( "action", UnicodeText( length = 1200000, convert_unicode = False, assert_unicode = None ), nullable = True, unique = None, default = None )
|
|
353
|
action_date = Column("action_date", DateTime(timezone=False), nullable=True, unique=None, default=None)
|
|
356
|
action_date = Column( "action_date", DateTime( timezone = False ), nullable = True, unique = None, default = None )
|
|
354
|
|
|
357
|
|
|
355
|
@property
|
|
358
|
@property
|
|
356
|
def action_as_day(self):
|
|
359
|
def action_as_day( self ):
|
|
357
|
return date(*self.action_date.timetuple()[:3])
|
|
360
|
return date( *self.action_date.timetuple()[:3] )
|
|
358
|
|
|
361
|
|
|
359
|
user = relationship('User')
|
|
362
|
user = relationship( 'User' )
|
|
360
|
repository = relationship('Repository')
|
|
363
|
repository = relationship( 'Repository' )
|
|
361
|
|
|
364
|
|
|
362
|
|
|
365
|
|
|
363
|
class UsersGroup(Base, BaseModel):
|
|
366
|
class UsersGroup( Base, BaseModel ):
|
|
364
|
__tablename__ = 'users_groups'
|
|
367
|
__tablename__ = 'users_groups'
|
|
365
|
__table_args__ = {'extend_existing':True}
|
|
368
|
__table_args__ = {'extend_existing':True}
|
|
366
|
|
|
369
|
|
|
367
|
users_group_id = Column("users_group_id", Integer(), nullable=False, unique=True, default=None, primary_key=True)
|
|
370
|
users_group_id = Column( "users_group_id", Integer(), nullable = False, unique = True, default = None, primary_key = True )
|
|
368
|
users_group_name = Column("users_group_name", String(length=255, convert_unicode=False, assert_unicode=None), nullable=False, unique=True, default=None)
|
|
371
|
users_group_name = Column( "users_group_name", String( length = 255, convert_unicode = False, assert_unicode = None ), nullable = False, unique = True, default = None )
|
|
369
|
users_group_active = Column("users_group_active", Boolean(), nullable=True, unique=None, default=None)
|
|
372
|
users_group_active = Column( "users_group_active", Boolean(), nullable = True, unique = None, default = None )
|
|
370
|
|
|
373
|
|
|
371
|
members = relationship('UsersGroupMember', cascade="all, delete, delete-orphan", lazy="joined")
|
|
374
|
members = relationship( 'UsersGroupMember', cascade = "all, delete, delete-orphan", lazy = "joined" )
|
|
372
|
|
|
375
|
|
|
373
|
def __repr__(self):
|
|
376
|
def __repr__( self ):
|
|
374
|
return '<userGroup(%s)>' % (self.users_group_name)
|
|
377
|
return '<userGroup(%s)>' % ( self.users_group_name )
|
|
375
|
|
|
378
|
|
|
376
|
@classmethod
|
|
379
|
@classmethod
|
|
377
|
def get_by_group_name(cls, group_name, cache=False, case_insensitive=False):
|
|
380
|
def get_by_group_name( cls, group_name, cache = False, case_insensitive = False ):
|
|
378
|
if case_insensitive:
|
|
381
|
if case_insensitive:
|
|
379
|
gr = Session.query(cls)\
|
|
382
|
gr = cls.query()\
|
|
380
|
.filter(cls.users_group_name.ilike(group_name))
|
|
383
|
.filter( cls.users_group_name.ilike( group_name ) )
|
|
381
|
else:
|
|
384
|
else:
|
|
382
|
gr = Session.query(UsersGroup)\
|
|
385
|
gr = cls.query()\
|
|
383
|
.filter(UsersGroup.users_group_name == group_name)
|
|
386
|
.filter( cls.users_group_name == group_name )
|
|
384
|
if cache:
|
|
387
|
if cache:
|
|
385
|
gr = gr.options(FromCache("sql_cache_short",
|
|
388
|
gr = gr.options( FromCache( "sql_cache_short",
|
|
386
|
"get_user_%s" % group_name))
|
|
389
|
"get_user_%s" % group_name ) )
|
|
387
|
return gr.scalar()
|
|
390
|
return gr.scalar()
|
|
388
|
|
|
391
|
|
|
389
|
|
|
392
|
|
|
390
|
@classmethod
|
|
393
|
@classmethod
|
|
391
|
def get(cls, users_group_id, cache=False):
|
|
394
|
def get( cls, users_group_id, cache = False ):
|
|
392
|
users_group = Session.query(cls)
|
|
395
|
users_group = cls.query()
|
|
393
|
if cache:
|
|
396
|
if cache:
|
|
394
|
users_group = users_group.options(FromCache("sql_cache_short",
|
|
397
|
users_group = users_group.options( FromCache( "sql_cache_short",
|
|
395
|
"get_users_group_%s" % users_group_id))
|
|
398
|
"get_users_group_%s" % users_group_id ) )
|
|
396
|
return users_group.get(users_group_id)
|
|
399
|
return users_group.get( users_group_id )
|
|
397
|
|
|
400
|
|
|
398
|
@classmethod
|
|
401
|
@classmethod
|
|
399
|
def create(cls, form_data):
|
|
402
|
def create( cls, form_data ):
|
|
400
|
try:
|
|
403
|
try:
|
|
401
|
new_users_group = cls()
|
|
404
|
new_users_group = cls()
|
|
402
|
for k, v in form_data.items():
|
|
405
|
for k, v in form_data.items():
|
|
403
|
setattr(new_users_group, k, v)
|
|
406
|
setattr( new_users_group, k, v )
|
|
404
|
|
|
407
|
|
|
405
|
Session.add(new_users_group)
|
|
408
|
Session.add( new_users_group )
|
|
406
|
Session.commit()
|
|
409
|
Session.commit()
|
|
407
|
return new_users_group
|
|
410
|
return new_users_group
|
|
408
|
except:
|
|
411
|
except:
|
|
409
|
log.error(traceback.format_exc())
|
|
412
|
log.error( traceback.format_exc() )
|
|
410
|
Session.rollback()
|
|
413
|
Session.rollback()
|
|
411
|
raise
|
|
414
|
raise
|
|
412
|
|
|
415
|
|
|
413
|
@classmethod
|
|
416
|
@classmethod
|
|
414
|
def update(cls, users_group_id, form_data):
|
|
417
|
def update( cls, users_group_id, form_data ):
|
|
415
|
|
|
418
|
|
|
416
|
try:
|
|
419
|
try:
|
|
417
|
users_group = cls.get(users_group_id, cache=False)
|
|
420
|
users_group = cls.get( users_group_id, cache = False )
|
|
418
|
|
|
421
|
|
|
419
|
for k, v in form_data.items():
|
|
422
|
for k, v in form_data.items():
|
|
420
|
if k == 'users_group_members':
|
|
423
|
if k == 'users_group_members':
|
|
@@
-422,176
+425,182
b' class UsersGroup(Base, BaseModel):'
|
|
422
|
Session.flush()
|
|
425
|
Session.flush()
|
|
423
|
members_list = []
|
|
426
|
members_list = []
|
|
424
|
if v:
|
|
427
|
if v:
|
|
425
|
for u_id in set(list(v)):
|
|
428
|
for u_id in set( list( v ) ):
|
|
426
|
member = UsersGroupMember(users_group_id,u_id)
|
|
429
|
member = UsersGroupMember( users_group_id, u_id )
|
|
427
|
members_list.append(member)
|
|
430
|
members_list.append( member )
|
|
428
|
setattr(users_group, 'members', members_list)
|
|
431
|
setattr( users_group, 'members', members_list )
|
|
429
|
setattr(users_group, k, v)
|
|
432
|
setattr( users_group, k, v )
|
|
430
|
|
|
433
|
|
|
431
|
Session.add(users_group)
|
|
434
|
Session.add( users_group )
|
|
432
|
Session.commit()
|
|
435
|
Session.commit()
|
|
433
|
except:
|
|
436
|
except:
|
|
434
|
log.error(traceback.format_exc())
|
|
437
|
log.error( traceback.format_exc() )
|
|
435
|
Session.rollback()
|
|
438
|
Session.rollback()
|
|
436
|
raise
|
|
439
|
raise
|
|
437
|
|
|
440
|
|
|
438
|
@classmethod
|
|
441
|
@classmethod
|
|
439
|
def delete(cls, users_group_id):
|
|
442
|
def delete( cls, users_group_id ):
|
|
440
|
try:
|
|
443
|
try:
|
|
441
|
|
|
444
|
|
|
442
|
# check if this group is not assigned to repo
|
|
445
|
# check if this group is not assigned to repo
|
|
443
|
assigned_groups = UsersGroupRepoToPerm.query()\
|
|
446
|
assigned_groups = UsersGroupRepoToPerm.query()\
|
|
444
|
.filter(UsersGroupRepoToPerm.users_group_id ==
|
|
447
|
.filter( UsersGroupRepoToPerm.users_group_id ==
|
|
445
|
users_group_id).all()
|
|
448
|
users_group_id ).all()
|
|
446
|
|
|
449
|
|
|
447
|
if assigned_groups:
|
|
450
|
if assigned_groups:
|
|
448
|
raise UsersGroupsAssignedException('Group assigned to %s' %
|
|
451
|
raise UsersGroupsAssignedException( 'Group assigned to %s' %
|
|
449
|
assigned_groups)
|
|
452
|
assigned_groups )
|
|
450
|
|
|
453
|
|
|
451
|
users_group = cls.get(users_group_id, cache=False)
|
|
454
|
users_group = cls.get( users_group_id, cache = False )
|
|
452
|
Session.delete(users_group)
|
|
455
|
Session.delete( users_group )
|
|
453
|
Session.commit()
|
|
456
|
Session.commit()
|
|
454
|
except:
|
|
457
|
except:
|
|
455
|
log.error(traceback.format_exc())
|
|
458
|
log.error( traceback.format_exc() )
|
|
456
|
Session.rollback()
|
|
459
|
Session.rollback()
|
|
457
|
raise
|
|
460
|
raise
|
|
458
|
|
|
461
|
|
|
459
|
|
|
462
|
class UsersGroupMember( Base, BaseModel ):
|
|
460
|
class UsersGroupMember(Base, BaseModel):
|
|
|
|
|
461
|
__tablename__ = 'users_groups_members'
|
|
463
|
__tablename__ = 'users_groups_members'
|
|
462
|
__table_args__ = {'extend_existing':True}
|
|
464
|
__table_args__ = {'extend_existing':True}
|
|
463
|
|
|
465
|
|
|
464
|
users_group_member_id = Column("users_group_member_id", Integer(), nullable=False, unique=True, default=None, primary_key=True)
|
|
466
|
users_group_member_id = Column( "users_group_member_id", Integer(), nullable = False, unique = True, default = None, primary_key = True )
|
|
465
|
users_group_id = Column("users_group_id", Integer(), ForeignKey('users_groups.users_group_id'), nullable=False, unique=None, default=None)
|
|
467
|
users_group_id = Column( "users_group_id", Integer(), ForeignKey( 'users_groups.users_group_id' ), nullable = False, unique = None, default = None )
|
|
466
|
user_id = Column("user_id", Integer(), ForeignKey('users.user_id'), nullable=False, unique=None, default=None)
|
|
468
|
user_id = Column( "user_id", Integer(), ForeignKey( 'users.user_id' ), nullable = False, unique = None, default = None )
|
|
467
|
|
|
469
|
|
|
468
|
user = relationship('User', lazy='joined')
|
|
470
|
user = relationship( 'User', lazy = 'joined' )
|
|
469
|
users_group = relationship('UsersGroup')
|
|
471
|
users_group = relationship( 'UsersGroup' )
|
|
470
|
|
|
472
|
|
|
471
|
def __init__(self, gr_id='', u_id=''):
|
|
473
|
def __init__( self, gr_id = '', u_id = '' ):
|
|
472
|
self.users_group_id = gr_id
|
|
474
|
self.users_group_id = gr_id
|
|
473
|
self.user_id = u_id
|
|
475
|
self.user_id = u_id
|
|
474
|
|
|
476
|
|
|
475
|
class Repository(Base, BaseModel):
|
|
477
|
@staticmethod
|
|
|
|
|
478
|
def add_user_to_group( group, user ):
|
|
|
|
|
479
|
ugm = UsersGroupMember()
|
|
|
|
|
480
|
ugm.users_group = group
|
|
|
|
|
481
|
ugm.user = user
|
|
|
|
|
482
|
Session.add( ugm )
|
|
|
|
|
483
|
Session.commit()
|
|
|
|
|
484
|
return ugm
|
|
|
|
|
485
|
|
|
|
|
|
486
|
class Repository( Base, BaseModel ):
|
|
476
|
__tablename__ = 'repositories'
|
|
487
|
__tablename__ = 'repositories'
|
|
477
|
__table_args__ = (UniqueConstraint('repo_name'), {'extend_existing':True},)
|
|
488
|
__table_args__ = ( UniqueConstraint( 'repo_name' ), {'extend_existing':True}, )
|
|
478
|
|
|
489
|
|
|
479
|
repo_id = Column("repo_id", Integer(), nullable=False, unique=True, default=None, primary_key=True)
|
|
490
|
repo_id = Column( "repo_id", Integer(), nullable = False, unique = True, default = None, primary_key = True )
|
|
480
|
repo_name = Column("repo_name", String(length=255, convert_unicode=False, assert_unicode=None), nullable=False, unique=True, default=None)
|
|
491
|
repo_name = Column( "repo_name", String( length = 255, convert_unicode = False, assert_unicode = None ), nullable = False, unique = True, default = None )
|
|
481
|
clone_uri = Column("clone_uri", String(length=255, convert_unicode=False, assert_unicode=None), nullable=True, unique=False, default=None)
|
|
492
|
clone_uri = Column( "clone_uri", String( length = 255, convert_unicode = False, assert_unicode = None ), nullable = True, unique = False, default = None )
|
|
482
|
repo_type = Column("repo_type", String(length=255, convert_unicode=False, assert_unicode=None), nullable=False, unique=False, default='hg')
|
|
493
|
repo_type = Column( "repo_type", String( length = 255, convert_unicode = False, assert_unicode = None ), nullable = False, unique = False, default = 'hg' )
|
|
483
|
user_id = Column("user_id", Integer(), ForeignKey('users.user_id'), nullable=False, unique=False, default=None)
|
|
494
|
user_id = Column( "user_id", Integer(), ForeignKey( 'users.user_id' ), nullable = False, unique = False, default = None )
|
|
484
|
private = Column("private", Boolean(), nullable=True, unique=None, default=None)
|
|
495
|
private = Column( "private", Boolean(), nullable = True, unique = None, default = None )
|
|
485
|
enable_statistics = Column("statistics", Boolean(), nullable=True, unique=None, default=True)
|
|
496
|
enable_statistics = Column( "statistics", Boolean(), nullable = True, unique = None, default = True )
|
|
486
|
enable_downloads = Column("downloads", Boolean(), nullable=True, unique=None, default=True)
|
|
497
|
enable_downloads = Column( "downloads", Boolean(), nullable = True, unique = None, default = True )
|
|
487
|
description = Column("description", String(length=10000, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None)
|
|
498
|
description = Column( "description", String( length = 10000, convert_unicode = False, assert_unicode = None ), nullable = True, unique = None, default = None )
|
|
488
|
created_on = Column('created_on', DateTime(timezone=False), nullable=True, unique=None, default=datetime.datetime.now)
|
|
499
|
created_on = Column( 'created_on', DateTime( timezone = False ), nullable = True, unique = None, default = datetime.datetime.now )
|
|
489
|
|
|
500
|
|
|
490
|
fork_id = Column("fork_id", Integer(), ForeignKey('repositories.repo_id'), nullable=True, unique=False, default=None)
|
|
501
|
fork_id = Column( "fork_id", Integer(), ForeignKey( 'repositories.repo_id' ), nullable = True, unique = False, default = None )
|
|
491
|
group_id = Column("group_id", Integer(), ForeignKey('groups.group_id'), nullable=True, unique=False, default=None)
|
|
502
|
group_id = Column( "group_id", Integer(), ForeignKey( 'groups.group_id' ), nullable = True, unique = False, default = None )
|
|
492
|
|
|
503
|
|
|
493
|
|
|
504
|
|
|
494
|
user = relationship('User')
|
|
505
|
user = relationship( 'User' )
|
|
495
|
fork = relationship('Repository', remote_side=repo_id)
|
|
506
|
fork = relationship( 'Repository', remote_side = repo_id )
|
|
496
|
group = relationship('Group')
|
|
507
|
group = relationship( 'Group' )
|
|
497
|
repo_to_perm = relationship('RepoToPerm', cascade='all', order_by='RepoToPerm.repo_to_perm_id')
|
|
508
|
repo_to_perm = relationship( 'RepoToPerm', cascade = 'all', order_by = 'RepoToPerm.repo_to_perm_id' )
|
|
498
|
users_group_to_perm = relationship('UsersGroupRepoToPerm', cascade='all')
|
|
509
|
users_group_to_perm = relationship( 'UsersGroupRepoToPerm', cascade = 'all' )
|
|
499
|
stats = relationship('Statistics', cascade='all', uselist=False)
|
|
510
|
stats = relationship( 'Statistics', cascade = 'all', uselist = False )
|
|
500
|
|
|
511
|
|
|
501
|
followers = relationship('UserFollowing', primaryjoin='UserFollowing.follows_repo_id==Repository.repo_id', cascade='all')
|
|
512
|
followers = relationship( 'UserFollowing', primaryjoin = 'UserFollowing.follows_repo_id==Repository.repo_id', cascade = 'all' )
|
|
502
|
|
|
513
|
|
|
503
|
logs = relationship('UserLog', cascade='all')
|
|
514
|
logs = relationship( 'UserLog', cascade = 'all' )
|
|
504
|
|
|
515
|
|
|
505
|
def __repr__(self):
|
|
516
|
def __repr__( self ):
|
|
506
|
return "<%s('%s:%s')>" % (self.__class__.__name__,
|
|
517
|
return "<%s('%s:%s')>" % ( self.__class__.__name__,
|
|
507
|
self.repo_id, self.repo_name)
|
|
518
|
self.repo_id, self.repo_name )
|
|
508
|
|
|
519
|
|
|
509
|
@classmethod
|
|
520
|
@classmethod
|
|
510
|
def url_sep(cls):
|
|
521
|
def url_sep( cls ):
|
|
511
|
return '/'
|
|
522
|
return '/'
|
|
512
|
|
|
523
|
|
|
513
|
@classmethod
|
|
524
|
@classmethod
|
|
514
|
def get_by_repo_name(cls, repo_name):
|
|
525
|
def get_by_repo_name( cls, repo_name ):
|
|
515
|
q = Session.query(cls).filter(cls.repo_name == repo_name)
|
|
526
|
q = Session.query( cls ).filter( cls.repo_name == repo_name )
|
|
516
|
|
|
527
|
q = q.options( joinedload( Repository.fork ) )\
|
|
517
|
q = q.options(joinedload(Repository.fork))\
|
|
528
|
.options( joinedload( Repository.user ) )\
|
|
518
|
.options(joinedload(Repository.user))\
|
|
529
|
.options( joinedload( Repository.group ) )
|
|
519
|
.options(joinedload(Repository.group))\
|
|
|
|
|
520
|
|
|
|
|
|
521
|
return q.one()
|
|
530
|
return q.one()
|
|
522
|
|
|
531
|
|
|
523
|
@classmethod
|
|
532
|
@classmethod
|
|
524
|
def get_repo_forks(cls, repo_id):
|
|
533
|
def get_repo_forks( cls, repo_id ):
|
|
525
|
return Session.query(cls).filter(Repository.fork_id == repo_id)
|
|
534
|
return cls.query().filter( Repository.fork_id == repo_id )
|
|
526
|
|
|
535
|
|
|
527
|
@classmethod
|
|
536
|
@classmethod
|
|
528
|
def base_path(cls):
|
|
537
|
def base_path( cls ):
|
|
529
|
"""
|
|
538
|
"""
|
|
530
|
Returns base path when all repos are stored
|
|
539
|
Returns base path when all repos are stored
|
|
531
|
|
|
540
|
|
|
532
|
:param cls:
|
|
541
|
:param cls:
|
|
533
|
"""
|
|
542
|
"""
|
|
534
|
q = Session.query(RhodeCodeUi).filter(RhodeCodeUi.ui_key ==
|
|
543
|
q = Session.query( RhodeCodeUi ).filter( RhodeCodeUi.ui_key ==
|
|
535
|
cls.url_sep())
|
|
544
|
cls.url_sep() )
|
|
536
|
q.options(FromCache("sql_cache_short", "repository_repo_path"))
|
|
545
|
q.options( FromCache( "sql_cache_short", "repository_repo_path" ) )
|
|
537
|
return q.one().ui_value
|
|
546
|
return q.one().ui_value
|
|
538
|
|
|
547
|
|
|
539
|
@property
|
|
548
|
@property
|
|
540
|
def just_name(self):
|
|
549
|
def just_name( self ):
|
|
541
|
return self.repo_name.split(Repository.url_sep())[-1]
|
|
550
|
return self.repo_name.split( Repository.url_sep() )[-1]
|
|
542
|
|
|
551
|
|
|
543
|
@property
|
|
552
|
@property
|
|
544
|
def groups_with_parents(self):
|
|
553
|
def groups_with_parents( self ):
|
|
545
|
groups = []
|
|
554
|
groups = []
|
|
546
|
if self.group is None:
|
|
555
|
if self.group is None:
|
|
547
|
return groups
|
|
556
|
return groups
|
|
548
|
|
|
557
|
|
|
549
|
cur_gr = self.group
|
|
558
|
cur_gr = self.group
|
|
550
|
groups.insert(0, cur_gr)
|
|
559
|
groups.insert( 0, cur_gr )
|
|
551
|
while 1:
|
|
560
|
while 1:
|
|
552
|
gr = getattr(cur_gr, 'parent_group', None)
|
|
561
|
gr = getattr( cur_gr, 'parent_group', None )
|
|
553
|
cur_gr = cur_gr.parent_group
|
|
562
|
cur_gr = cur_gr.parent_group
|
|
554
|
if gr is None:
|
|
563
|
if gr is None:
|
|
555
|
break
|
|
564
|
break
|
|
556
|
groups.insert(0, gr)
|
|
565
|
groups.insert( 0, gr )
|
|
557
|
|
|
566
|
|
|
558
|
return groups
|
|
567
|
return groups
|
|
559
|
|
|
568
|
|
|
560
|
@property
|
|
569
|
@property
|
|
561
|
def groups_and_repo(self):
|
|
570
|
def groups_and_repo( self ):
|
|
562
|
return self.groups_with_parents, self.just_name
|
|
571
|
return self.groups_with_parents, self.just_name
|
|
563
|
|
|
572
|
|
|
564
|
@LazyProperty
|
|
573
|
@LazyProperty
|
|
565
|
def repo_path(self):
|
|
574
|
def repo_path( self ):
|
|
566
|
"""
|
|
575
|
"""
|
|
567
|
Returns base full path for that repository means where it actually
|
|
576
|
Returns base full path for that repository means where it actually
|
|
568
|
exists on a filesystem
|
|
577
|
exists on a filesystem
|
|
569
|
"""
|
|
578
|
"""
|
|
570
|
q = Session.query(RhodeCodeUi).filter(RhodeCodeUi.ui_key ==
|
|
579
|
q = Session.query( RhodeCodeUi ).filter( RhodeCodeUi.ui_key ==
|
|
571
|
Repository.url_sep())
|
|
580
|
Repository.url_sep() )
|
|
572
|
q.options(FromCache("sql_cache_short", "repository_repo_path"))
|
|
581
|
q.options( FromCache( "sql_cache_short", "repository_repo_path" ) )
|
|
573
|
return q.one().ui_value
|
|
582
|
return q.one().ui_value
|
|
574
|
|
|
583
|
|
|
575
|
@property
|
|
584
|
@property
|
|
576
|
def repo_full_path(self):
|
|
585
|
def repo_full_path( self ):
|
|
577
|
p = [self.repo_path]
|
|
586
|
p = [self.repo_path]
|
|
578
|
# we need to split the name by / since this is how we store the
|
|
587
|
# we need to split the name by / since this is how we store the
|
|
579
|
# names in the database, but that eventually needs to be converted
|
|
588
|
# names in the database, but that eventually needs to be converted
|
|
580
|
# into a valid system path
|
|
589
|
# into a valid system path
|
|
581
|
p += self.repo_name.split(Repository.url_sep())
|
|
590
|
p += self.repo_name.split( Repository.url_sep() )
|
|
582
|
return os.path.join(*p)
|
|
591
|
return os.path.join( *p )
|
|
583
|
|
|
592
|
|
|
584
|
def get_new_name(self, repo_name):
|
|
593
|
def get_new_name( self, repo_name ):
|
|
585
|
"""
|
|
594
|
"""
|
|
586
|
returns new full repository name based on assigned group and new new
|
|
595
|
returns new full repository name based on assigned group and new new
|
|
587
|
|
|
596
|
|
|
588
|
:param group_name:
|
|
597
|
:param group_name:
|
|
589
|
"""
|
|
598
|
"""
|
|
590
|
path_prefix = self.group.full_path_splitted if self.group else []
|
|
599
|
path_prefix = self.group.full_path_splitted if self.group else []
|
|
591
|
return Repository.url_sep().join(path_prefix + [repo_name])
|
|
600
|
return Repository.url_sep().join( path_prefix + [repo_name] )
|
|
592
|
|
|
601
|
|
|
593
|
@property
|
|
602
|
@property
|
|
594
|
def _ui(self):
|
|
603
|
def _ui( self ):
|
|
595
|
"""
|
|
604
|
"""
|
|
596
|
Creates an db based ui object for this repository
|
|
605
|
Creates an db based ui object for this repository
|
|
597
|
"""
|
|
606
|
"""
|
|
@@
-605,48
+614,48
b' class Repository(Base, BaseModel):'
|
|
605
|
baseui._tcfg = config.config()
|
|
614
|
baseui._tcfg = config.config()
|
|
606
|
|
|
615
|
|
|
607
|
|
|
616
|
|
|
608
|
ret = Session.query(RhodeCodeUi)\
|
|
617
|
ret = RhodeCodeUi.query()\
|
|
609
|
.options(FromCache("sql_cache_short", "repository_repo_ui")).all()
|
|
618
|
.options( FromCache( "sql_cache_short", "repository_repo_ui" ) ).all()
|
|
610
|
|
|
619
|
|
|
611
|
hg_ui = ret
|
|
620
|
hg_ui = ret
|
|
612
|
for ui_ in hg_ui:
|
|
621
|
for ui_ in hg_ui:
|
|
613
|
if ui_.ui_active:
|
|
622
|
if ui_.ui_active:
|
|
614
|
log.debug('settings ui from db[%s]%s:%s', ui_.ui_section,
|
|
623
|
log.debug( 'settings ui from db[%s]%s:%s', ui_.ui_section,
|
|
615
|
ui_.ui_key, ui_.ui_value)
|
|
624
|
ui_.ui_key, ui_.ui_value )
|
|
616
|
baseui.setconfig(ui_.ui_section, ui_.ui_key, ui_.ui_value)
|
|
625
|
baseui.setconfig( ui_.ui_section, ui_.ui_key, ui_.ui_value )
|
|
617
|
|
|
626
|
|
|
618
|
return baseui
|
|
627
|
return baseui
|
|
619
|
|
|
628
|
|
|
620
|
@classmethod
|
|
629
|
@classmethod
|
|
621
|
def is_valid(cls, repo_name):
|
|
630
|
def is_valid( cls, repo_name ):
|
|
622
|
"""
|
|
631
|
"""
|
|
623
|
returns True if given repo name is a valid filesystem repository
|
|
632
|
returns True if given repo name is a valid filesystem repository
|
|
624
|
|
|
633
|
|
|
625
|
@param cls:
|
|
634
|
@param cls:
|
|
626
|
@param repo_name:
|
|
635
|
@param repo_name:
|
|
627
|
"""
|
|
636
|
"""
|
|
628
|
from rhodecode.lib.utils import is_valid_repo
|
|
637
|
from rhodecode.lib.utils import is_valid_repo
|
|
629
|
|
|
638
|
|
|
630
|
return is_valid_repo(repo_name, cls.base_path())
|
|
639
|
return is_valid_repo( repo_name, cls.base_path() )
|
|
631
|
|
|
640
|
|
|
632
|
|
|
641
|
|
|
633
|
#==========================================================================
|
|
642
|
#==========================================================================
|
|
634
|
# SCM PROPERTIES
|
|
643
|
# SCM PROPERTIES
|
|
635
|
#==========================================================================
|
|
644
|
#==========================================================================
|
|
636
|
|
|
645
|
|
|
637
|
def get_changeset(self, rev):
|
|
646
|
def get_changeset( self, rev ):
|
|
638
|
return get_changeset_safe(self.scm_instance, rev)
|
|
647
|
return get_changeset_safe( self.scm_instance, rev )
|
|
639
|
|
|
648
|
|
|
640
|
@property
|
|
649
|
@property
|
|
641
|
def tip(self):
|
|
650
|
def tip( self ):
|
|
642
|
return self.get_changeset('tip')
|
|
651
|
return self.get_changeset( 'tip' )
|
|
643
|
|
|
652
|
|
|
644
|
@property
|
|
653
|
@property
|
|
645
|
def author(self):
|
|
654
|
def author( self ):
|
|
646
|
return self.tip.author
|
|
655
|
return self.tip.author
|
|
647
|
|
|
656
|
|
|
648
|
@property
|
|
657
|
@property
|
|
649
|
def last_change(self):
|
|
658
|
def last_change( self ):
|
|
650
|
return self.scm_instance.last_change
|
|
659
|
return self.scm_instance.last_change
|
|
651
|
|
|
660
|
|
|
652
|
#==========================================================================
|
|
661
|
#==========================================================================
|
|
@@
-654,397
+663,407
b' class Repository(Base, BaseModel):'
|
|
654
|
#==========================================================================
|
|
663
|
#==========================================================================
|
|
655
|
|
|
664
|
|
|
656
|
@property
|
|
665
|
@property
|
|
657
|
def invalidate(self):
|
|
666
|
def invalidate( self ):
|
|
658
|
"""
|
|
667
|
"""
|
|
659
|
Returns Invalidation object if this repo should be invalidated
|
|
668
|
Returns Invalidation object if this repo should be invalidated
|
|
660
|
None otherwise. `cache_active = False` means that this cache
|
|
669
|
None otherwise. `cache_active = False` means that this cache
|
|
661
|
state is not valid and needs to be invalidated
|
|
670
|
state is not valid and needs to be invalidated
|
|
662
|
"""
|
|
671
|
"""
|
|
663
|
return Session.query(CacheInvalidation)\
|
|
672
|
return CacheInvalidation.query()\
|
|
664
|
.filter(CacheInvalidation.cache_key == self.repo_name)\
|
|
673
|
.filter( CacheInvalidation.cache_key == self.repo_name )\
|
|
665
|
.filter(CacheInvalidation.cache_active == False)\
|
|
674
|
.filter( CacheInvalidation.cache_active == False )\
|
|
666
|
.scalar()
|
|
675
|
.scalar()
|
|
667
|
|
|
676
|
|
|
668
|
def set_invalidate(self):
|
|
677
|
def set_invalidate( self ):
|
|
669
|
"""
|
|
678
|
"""
|
|
670
|
set a cache for invalidation for this instance
|
|
679
|
set a cache for invalidation for this instance
|
|
671
|
"""
|
|
680
|
"""
|
|
672
|
inv = Session.query(CacheInvalidation)\
|
|
681
|
inv = CacheInvalidation.query()\
|
|
673
|
.filter(CacheInvalidation.cache_key == self.repo_name)\
|
|
682
|
.filter( CacheInvalidation.cache_key == self.repo_name )\
|
|
674
|
.scalar()
|
|
683
|
.scalar()
|
|
675
|
|
|
684
|
|
|
676
|
if inv is None:
|
|
685
|
if inv is None:
|
|
677
|
inv = CacheInvalidation(self.repo_name)
|
|
686
|
inv = CacheInvalidation( self.repo_name )
|
|
678
|
inv.cache_active = True
|
|
687
|
inv.cache_active = True
|
|
679
|
Session.add(inv)
|
|
688
|
Session.add( inv )
|
|
680
|
Session.commit()
|
|
689
|
Session.commit()
|
|
681
|
|
|
690
|
|
|
682
|
@LazyProperty
|
|
691
|
@LazyProperty
|
|
683
|
def scm_instance(self):
|
|
692
|
def scm_instance( self ):
|
|
684
|
return self.__get_instance()
|
|
693
|
return self.__get_instance()
|
|
685
|
|
|
694
|
|
|
686
|
@property
|
|
695
|
@property
|
|
687
|
def scm_instance_cached(self):
|
|
696
|
def scm_instance_cached( self ):
|
|
688
|
@cache_region('long_term')
|
|
697
|
@cache_region( 'long_term' )
|
|
689
|
def _c(repo_name):
|
|
698
|
def _c( repo_name ):
|
|
690
|
return self.__get_instance()
|
|
699
|
return self.__get_instance()
|
|
691
|
|
|
700
|
|
|
692
|
# TODO: remove this trick when beaker 1.6 is released
|
|
701
|
# TODO: remove this trick when beaker 1.6 is released
|
|
693
|
# and have fixed this issue with not supporting unicode keys
|
|
702
|
# and have fixed this issue with not supporting unicode keys
|
|
694
|
rn = safe_str(self.repo_name)
|
|
703
|
rn = safe_str( self.repo_name )
|
|
695
|
|
|
704
|
|
|
696
|
inv = self.invalidate
|
|
705
|
inv = self.invalidate
|
|
697
|
if inv is not None:
|
|
706
|
if inv is not None:
|
|
698
|
region_invalidate(_c, None, rn)
|
|
707
|
region_invalidate( _c, None, rn )
|
|
699
|
# update our cache
|
|
708
|
# update our cache
|
|
700
|
inv.cache_active = True
|
|
709
|
inv.cache_active = True
|
|
701
|
Session.add(inv)
|
|
710
|
Session.add( inv )
|
|
702
|
Session.commit()
|
|
711
|
Session.commit()
|
|
703
|
|
|
712
|
|
|
704
|
return _c(rn)
|
|
713
|
return _c( rn )
|
|
705
|
|
|
714
|
|
|
706
|
def __get_instance(self):
|
|
715
|
def __get_instance( self ):
|
|
707
|
|
|
716
|
|
|
708
|
repo_full_path = self.repo_full_path
|
|
717
|
repo_full_path = self.repo_full_path
|
|
709
|
|
|
718
|
|
|
710
|
try:
|
|
719
|
try:
|
|
711
|
alias = get_scm(repo_full_path)[0]
|
|
720
|
alias = get_scm( repo_full_path )[0]
|
|
712
|
log.debug('Creating instance of %s repository', alias)
|
|
721
|
log.debug( 'Creating instance of %s repository', alias )
|
|
713
|
backend = get_backend(alias)
|
|
722
|
backend = get_backend( alias )
|
|
714
|
except VCSError:
|
|
723
|
except VCSError:
|
|
715
|
log.error(traceback.format_exc())
|
|
724
|
log.error( traceback.format_exc() )
|
|
716
|
log.error('Perhaps this repository is in db and not in '
|
|
725
|
log.error( 'Perhaps this repository is in db and not in '
|
|
717
|
'filesystem run rescan repositories with '
|
|
726
|
'filesystem run rescan repositories with '
|
|
718
|
'"destroy old data " option from admin panel')
|
|
727
|
'"destroy old data " option from admin panel' )
|
|
719
|
return
|
|
728
|
return
|
|
720
|
|
|
729
|
|
|
721
|
if alias == 'hg':
|
|
730
|
if alias == 'hg':
|
|
722
|
|
|
731
|
|
|
723
|
repo = backend(safe_str(repo_full_path), create=False,
|
|
732
|
repo = backend( safe_str( repo_full_path ), create = False,
|
|
724
|
baseui=self._ui)
|
|
733
|
baseui = self._ui )
|
|
725
|
#skip hidden web repository
|
|
734
|
#skip hidden web repository
|
|
726
|
if repo._get_hidden():
|
|
735
|
if repo._get_hidden():
|
|
727
|
return
|
|
736
|
return
|
|
728
|
else:
|
|
737
|
else:
|
|
729
|
repo = backend(repo_full_path, create=False)
|
|
738
|
repo = backend( repo_full_path, create = False )
|
|
730
|
|
|
739
|
|
|
731
|
return repo
|
|
740
|
return repo
|
|
732
|
|
|
741
|
|
|
733
|
|
|
742
|
|
|
734
|
class Group(Base, BaseModel):
|
|
743
|
class Group( Base, BaseModel ):
|
|
735
|
__tablename__ = 'groups'
|
|
744
|
__tablename__ = 'groups'
|
|
736
|
__table_args__ = (UniqueConstraint('group_name', 'group_parent_id'),
|
|
745
|
__table_args__ = ( UniqueConstraint( 'group_name', 'group_parent_id' ),
|
|
737
|
CheckConstraint('group_id != group_parent_id'), {'extend_existing':True},)
|
|
746
|
CheckConstraint( 'group_id != group_parent_id' ), {'extend_existing':True}, )
|
|
738
|
__mapper_args__ = {'order_by':'group_name'}
|
|
747
|
__mapper_args__ = {'order_by':'group_name'}
|
|
739
|
|
|
748
|
|
|
740
|
group_id = Column("group_id", Integer(), nullable=False, unique=True, default=None, primary_key=True)
|
|
749
|
group_id = Column( "group_id", Integer(), nullable = False, unique = True, default = None, primary_key = True )
|
|
741
|
group_name = Column("group_name", String(length=255, convert_unicode=False, assert_unicode=None), nullable=False, unique=True, default=None)
|
|
750
|
group_name = Column( "group_name", String( length = 255, convert_unicode = False, assert_unicode = None ), nullable = False, unique = True, default = None )
|
|
742
|
group_parent_id = Column("group_parent_id", Integer(), ForeignKey('groups.group_id'), nullable=True, unique=None, default=None)
|
|
751
|
group_parent_id = Column( "group_parent_id", Integer(), ForeignKey( 'groups.group_id' ), nullable = True, unique = None, default = None )
|
|
743
|
group_description = Column("group_description", String(length=10000, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None)
|
|
752
|
group_description = Column( "group_description", String( length = 10000, convert_unicode = False, assert_unicode = None ), nullable = True, unique = None, default = None )
|
|
744
|
|
|
753
|
|
|
745
|
parent_group = relationship('Group', remote_side=group_id)
|
|
754
|
parent_group = relationship( 'Group', remote_side = group_id )
|
|
746
|
|
|
755
|
|
|
747
|
|
|
756
|
|
|
748
|
def __init__(self, group_name='', parent_group=None):
|
|
757
|
def __init__( self, group_name = '', parent_group = None ):
|
|
749
|
self.group_name = group_name
|
|
758
|
self.group_name = group_name
|
|
750
|
self.parent_group = parent_group
|
|
759
|
self.parent_group = parent_group
|
|
751
|
|
|
760
|
|
|
752
|
def __repr__(self):
|
|
761
|
def __repr__( self ):
|
|
753
|
return "<%s('%s:%s')>" % (self.__class__.__name__, self.group_id,
|
|
762
|
return "<%s('%s:%s')>" % ( self.__class__.__name__, self.group_id,
|
|
754
|
self.group_name)
|
|
763
|
self.group_name )
|
|
755
|
|
|
764
|
|
|
756
|
@classmethod
|
|
765
|
@classmethod
|
|
757
|
def groups_choices(cls):
|
|
766
|
def groups_choices( cls ):
|
|
758
|
from webhelpers.html import literal as _literal
|
|
767
|
from webhelpers.html import literal as _literal
|
|
759
|
repo_groups = [('', '')]
|
|
768
|
repo_groups = [( '', '' )]
|
|
760
|
sep = ' » '
|
|
769
|
sep = ' » '
|
|
761
|
_name = lambda k: _literal(sep.join(k))
|
|
770
|
_name = lambda k: _literal( sep.join( k ) )
|
|
762
|
|
|
771
|
|
|
763
|
repo_groups.extend([(x.group_id, _name(x.full_path_splitted))
|
|
772
|
repo_groups.extend( [( x.group_id, _name( x.full_path_splitted ) )
|
|
764
|
for x in cls.query().all()])
|
|
773
|
for x in cls.query().all()] )
|
|
765
|
|
|
774
|
|
|
766
|
repo_groups = sorted(repo_groups,key=lambda t: t[1].split(sep)[0])
|
|
775
|
repo_groups = sorted( repo_groups, key = lambda t: t[1].split( sep )[0] )
|
|
767
|
return repo_groups
|
|
776
|
return repo_groups
|
|
768
|
|
|
777
|
|
|
769
|
@classmethod
|
|
778
|
@classmethod
|
|
770
|
def url_sep(cls):
|
|
779
|
def url_sep( cls ):
|
|
771
|
return '/'
|
|
780
|
return '/'
|
|
772
|
|
|
781
|
|
|
773
|
@classmethod
|
|
782
|
@classmethod
|
|
774
|
def get_by_group_name(cls, group_name):
|
|
783
|
def get_by_group_name( cls, group_name, cache = False, case_insensitive = False ):
|
|
775
|
return cls.query().filter(cls.group_name == group_name).scalar()
|
|
784
|
if case_insensitive:
|
|
|
|
|
785
|
gr = cls.query()\
|
|
|
|
|
786
|
.filter( cls.group_name.ilike( group_name ) )
|
|
|
|
|
787
|
else:
|
|
|
|
|
788
|
gr = cls.query()\
|
|
|
|
|
789
|
.filter( cls.group_name == group_name )
|
|
|
|
|
790
|
if cache:
|
|
|
|
|
791
|
gr = gr.options( FromCache( "sql_cache_short",
|
|
|
|
|
792
|
"get_group_%s" % group_name ) )
|
|
|
|
|
793
|
return gr.scalar()
|
|
776
|
|
|
794
|
|
|
777
|
@property
|
|
795
|
@property
|
|
778
|
def parents(self):
|
|
796
|
def parents( self ):
|
|
779
|
parents_recursion_limit = 5
|
|
797
|
parents_recursion_limit = 5
|
|
780
|
groups = []
|
|
798
|
groups = []
|
|
781
|
if self.parent_group is None:
|
|
799
|
if self.parent_group is None:
|
|
782
|
return groups
|
|
800
|
return groups
|
|
783
|
cur_gr = self.parent_group
|
|
801
|
cur_gr = self.parent_group
|
|
784
|
groups.insert(0, cur_gr)
|
|
802
|
groups.insert( 0, cur_gr )
|
|
785
|
cnt = 0
|
|
803
|
cnt = 0
|
|
786
|
while 1:
|
|
804
|
while 1:
|
|
787
|
cnt += 1
|
|
805
|
cnt += 1
|
|
788
|
gr = getattr(cur_gr, 'parent_group', None)
|
|
806
|
gr = getattr( cur_gr, 'parent_group', None )
|
|
789
|
cur_gr = cur_gr.parent_group
|
|
807
|
cur_gr = cur_gr.parent_group
|
|
790
|
if gr is None:
|
|
808
|
if gr is None:
|
|
791
|
break
|
|
809
|
break
|
|
792
|
if cnt == parents_recursion_limit:
|
|
810
|
if cnt == parents_recursion_limit:
|
|
793
|
# this will prevent accidental infinit loops
|
|
811
|
# this will prevent accidental infinit loops
|
|
794
|
log.error('group nested more than %s' %
|
|
812
|
log.error( 'group nested more than %s' %
|
|
795
|
parents_recursion_limit)
|
|
813
|
parents_recursion_limit )
|
|
796
|
break
|
|
814
|
break
|
|
797
|
|
|
815
|
|
|
798
|
groups.insert(0, gr)
|
|
816
|
groups.insert( 0, gr )
|
|
799
|
return groups
|
|
817
|
return groups
|
|
800
|
|
|
818
|
|
|
801
|
@property
|
|
819
|
@property
|
|
802
|
def children(self):
|
|
820
|
def children( self ):
|
|
803
|
return Session.query(Group).filter(Group.parent_group == self)
|
|
821
|
return Group.query().filter( Group.parent_group == self )
|
|
804
|
|
|
822
|
|
|
805
|
@property
|
|
823
|
@property
|
|
806
|
def name(self):
|
|
824
|
def name( self ):
|
|
807
|
return self.group_name.split(Group.url_sep())[-1]
|
|
825
|
return self.group_name.split( Group.url_sep() )[-1]
|
|
808
|
|
|
826
|
|
|
809
|
@property
|
|
827
|
@property
|
|
810
|
def full_path(self):
|
|
828
|
def full_path( self ):
|
|
811
|
return self.group_name
|
|
829
|
return Group.url_sep().join( [g.group_name for g in self.parents] +
|
|
|
|
|
830
|
[self.group_name] )
|
|
812
|
|
|
831
|
|
|
813
|
@property
|
|
832
|
@property
|
|
814
|
def full_path_splitted(self):
|
|
833
|
def full_path_splitted( self ):
|
|
815
|
return self.group_name.split(Group.url_sep())
|
|
834
|
return self.group_name.split( Group.url_sep() )
|
|
816
|
|
|
835
|
|
|
817
|
@property
|
|
836
|
@property
|
|
818
|
def repositories(self):
|
|
837
|
def repositories( self ):
|
|
819
|
return Session.query(Repository).filter(Repository.group == self)
|
|
838
|
return Repository.query().filter( Repository.group == self )
|
|
820
|
|
|
839
|
|
|
821
|
@property
|
|
840
|
@property
|
|
822
|
def repositories_recursive_count(self):
|
|
841
|
def repositories_recursive_count( self ):
|
|
823
|
cnt = self.repositories.count()
|
|
842
|
cnt = self.repositories.count()
|
|
824
|
|
|
843
|
|
|
825
|
def children_count(group):
|
|
844
|
def children_count( group ):
|
|
826
|
cnt = 0
|
|
845
|
cnt = 0
|
|
827
|
for child in group.children:
|
|
846
|
for child in group.children:
|
|
828
|
cnt += child.repositories.count()
|
|
847
|
cnt += child.repositories.count()
|
|
829
|
cnt += children_count(child)
|
|
848
|
cnt += children_count( child )
|
|
830
|
return cnt
|
|
849
|
return cnt
|
|
831
|
|
|
850
|
|
|
832
|
return cnt + children_count(self)
|
|
851
|
return cnt + children_count( self )
|
|
833
|
|
|
852
|
|
|
834
|
|
|
853
|
|
|
835
|
def get_new_name(self, group_name):
|
|
854
|
def get_new_name( self, group_name ):
|
|
836
|
"""
|
|
855
|
"""
|
|
837
|
returns new full group name based on parent and new name
|
|
856
|
returns new full group name based on parent and new name
|
|
838
|
|
|
857
|
|
|
839
|
:param group_name:
|
|
858
|
:param group_name:
|
|
840
|
"""
|
|
859
|
"""
|
|
841
|
path_prefix = self.parent_group.full_path_splitted if self.parent_group else []
|
|
860
|
path_prefix = self.parent_group.full_path_splitted if self.parent_group else []
|
|
842
|
return Group.url_sep().join(path_prefix + [group_name])
|
|
861
|
return Group.url_sep().join( path_prefix + [group_name] )
|
|
843
|
|
|
862
|
|
|
844
|
|
|
863
|
|
|
845
|
class Permission(Base, BaseModel):
|
|
864
|
class Permission( Base, BaseModel ):
|
|
846
|
__tablename__ = 'permissions'
|
|
865
|
__tablename__ = 'permissions'
|
|
847
|
__table_args__ = {'extend_existing':True}
|
|
866
|
__table_args__ = {'extend_existing':True}
|
|
848
|
permission_id = Column("permission_id", Integer(), nullable=False, unique=True, default=None, primary_key=True)
|
|
867
|
permission_id = Column( "permission_id", Integer(), nullable = False, unique = True, default = None, primary_key = True )
|
|
849
|
permission_name = Column("permission_name", String(length=255, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None)
|
|
868
|
permission_name = Column( "permission_name", String( length = 255, convert_unicode = False, assert_unicode = None ), nullable = True, unique = None, default = None )
|
|
850
|
permission_longname = Column("permission_longname", String(length=255, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None)
|
|
869
|
permission_longname = Column( "permission_longname", String( length = 255, convert_unicode = False, assert_unicode = None ), nullable = True, unique = None, default = None )
|
|
851
|
|
|
870
|
|
|
852
|
def __repr__(self):
|
|
871
|
def __repr__( self ):
|
|
853
|
return "<%s('%s:%s')>" % (self.__class__.__name__,
|
|
872
|
return "<%s('%s:%s')>" % ( self.__class__.__name__,
|
|
854
|
self.permission_id, self.permission_name)
|
|
873
|
self.permission_id, self.permission_name )
|
|
855
|
|
|
874
|
|
|
856
|
@classmethod
|
|
875
|
@classmethod
|
|
857
|
def get_by_key(cls, key):
|
|
876
|
def get_by_key( cls, key ):
|
|
858
|
return Session.query(cls).filter(cls.permission_name == key).scalar()
|
|
877
|
return cls.query().filter( cls.permission_name == key ).scalar()
|
|
859
|
|
|
878
|
|
|
860
|
class RepoToPerm(Base, BaseModel):
|
|
879
|
class RepoToPerm( Base, BaseModel ):
|
|
861
|
__tablename__ = 'repo_to_perm'
|
|
880
|
__tablename__ = 'repo_to_perm'
|
|
862
|
__table_args__ = (UniqueConstraint('user_id', 'repository_id'), {'extend_existing':True})
|
|
881
|
__table_args__ = ( UniqueConstraint( 'user_id', 'repository_id' ), {'extend_existing':True} )
|
|
863
|
repo_to_perm_id = Column("repo_to_perm_id", Integer(), nullable=False, unique=True, default=None, primary_key=True)
|
|
882
|
repo_to_perm_id = Column( "repo_to_perm_id", Integer(), nullable = False, unique = True, default = None, primary_key = True )
|
|
864
|
user_id = Column("user_id", Integer(), ForeignKey('users.user_id'), nullable=False, unique=None, default=None)
|
|
883
|
user_id = Column( "user_id", Integer(), ForeignKey( 'users.user_id' ), nullable = False, unique = None, default = None )
|
|
865
|
permission_id = Column("permission_id", Integer(), ForeignKey('permissions.permission_id'), nullable=False, unique=None, default=None)
|
|
884
|
permission_id = Column( "permission_id", Integer(), ForeignKey( 'permissions.permission_id' ), nullable = False, unique = None, default = None )
|
|
866
|
repository_id = Column("repository_id", Integer(), ForeignKey('repositories.repo_id'), nullable=False, unique=None, default=None)
|
|
885
|
repository_id = Column( "repository_id", Integer(), ForeignKey( 'repositories.repo_id' ), nullable = False, unique = None, default = None )
|
|
867
|
|
|
886
|
|
|
868
|
user = relationship('User')
|
|
887
|
user = relationship( 'User' )
|
|
869
|
permission = relationship('Permission')
|
|
888
|
permission = relationship( 'Permission' )
|
|
870
|
repository = relationship('Repository')
|
|
889
|
repository = relationship( 'Repository' )
|
|
871
|
|
|
890
|
|
|
872
|
class UserToPerm(Base, BaseModel):
|
|
891
|
class UserToPerm( Base, BaseModel ):
|
|
873
|
__tablename__ = 'user_to_perm'
|
|
892
|
__tablename__ = 'user_to_perm'
|
|
874
|
__table_args__ = (UniqueConstraint('user_id', 'permission_id'), {'extend_existing':True})
|
|
893
|
__table_args__ = ( UniqueConstraint( 'user_id', 'permission_id' ), {'extend_existing':True} )
|
|
875
|
user_to_perm_id = Column("user_to_perm_id", Integer(), nullable=False, unique=True, default=None, primary_key=True)
|
|
894
|
user_to_perm_id = Column( "user_to_perm_id", Integer(), nullable = False, unique = True, default = None, primary_key = True )
|
|
876
|
user_id = Column("user_id", Integer(), ForeignKey('users.user_id'), nullable=False, unique=None, default=None)
|
|
895
|
user_id = Column( "user_id", Integer(), ForeignKey( 'users.user_id' ), nullable = False, unique = None, default = None )
|
|
877
|
permission_id = Column("permission_id", Integer(), ForeignKey('permissions.permission_id'), nullable=False, unique=None, default=None)
|
|
896
|
permission_id = Column( "permission_id", Integer(), ForeignKey( 'permissions.permission_id' ), nullable = False, unique = None, default = None )
|
|
878
|
|
|
897
|
|
|
879
|
user = relationship('User')
|
|
898
|
user = relationship( 'User' )
|
|
880
|
permission = relationship('Permission')
|
|
899
|
permission = relationship( 'Permission' )
|
|
881
|
|
|
900
|
|
|
882
|
@classmethod
|
|
901
|
@classmethod
|
|
883
|
def has_perm(cls, user_id, perm):
|
|
902
|
def has_perm( cls, user_id, perm ):
|
|
884
|
if not isinstance(perm, Permission):
|
|
903
|
if not isinstance( perm, Permission ):
|
|
885
|
raise Exception('perm needs to be an instance of Permission class')
|
|
904
|
raise Exception( 'perm needs to be an instance of Permission class' )
|
|
886
|
|
|
905
|
|
|
887
|
return Session.query(cls).filter(cls.user_id == user_id)\
|
|
906
|
return cls.query().filter( cls.user_id == user_id )\
|
|
888
|
.filter(cls.permission == perm).scalar() is not None
|
|
907
|
.filter( cls.permission == perm ).scalar() is not None
|
|
889
|
|
|
908
|
|
|
890
|
@classmethod
|
|
909
|
@classmethod
|
|
891
|
def grant_perm(cls, user_id, perm):
|
|
910
|
def grant_perm( cls, user_id, perm ):
|
|
892
|
if not isinstance(perm, Permission):
|
|
911
|
if not isinstance( perm, Permission ):
|
|
893
|
raise Exception('perm needs to be an instance of Permission class')
|
|
912
|
raise Exception( 'perm needs to be an instance of Permission class' )
|
|
894
|
|
|
913
|
|
|
895
|
new = cls()
|
|
914
|
new = cls()
|
|
896
|
new.user_id = user_id
|
|
915
|
new.user_id = user_id
|
|
897
|
new.permission = perm
|
|
916
|
new.permission = perm
|
|
898
|
try:
|
|
917
|
try:
|
|
899
|
Session.add(new)
|
|
918
|
Session.add( new )
|
|
900
|
Session.commit()
|
|
919
|
Session.commit()
|
|
901
|
except:
|
|
920
|
except:
|
|
902
|
Session.rollback()
|
|
921
|
Session.rollback()
|
|
903
|
|
|
922
|
|
|
904
|
|
|
923
|
|
|
905
|
@classmethod
|
|
924
|
@classmethod
|
|
906
|
def revoke_perm(cls, user_id, perm):
|
|
925
|
def revoke_perm( cls, user_id, perm ):
|
|
907
|
if not isinstance(perm, Permission):
|
|
926
|
if not isinstance( perm, Permission ):
|
|
908
|
raise Exception('perm needs to be an instance of Permission class')
|
|
927
|
raise Exception( 'perm needs to be an instance of Permission class' )
|
|
909
|
|
|
928
|
|
|
910
|
try:
|
|
929
|
try:
|
|
911
|
Session.query(cls).filter(cls.user_id == user_id)\
|
|
930
|
cls.query().filter( cls.user_id == user_id )\
|
|
912
|
.filter(cls.permission == perm).delete()
|
|
931
|
.filter( cls.permission == perm ).delete()
|
|
913
|
Session.commit()
|
|
932
|
Session.commit()
|
|
914
|
except:
|
|
933
|
except:
|
|
915
|
Session.rollback()
|
|
934
|
Session.rollback()
|
|
916
|
|
|
935
|
|
|
917
|
class UsersGroupRepoToPerm(Base, BaseModel):
|
|
936
|
class UsersGroupRepoToPerm( Base, BaseModel ):
|
|
918
|
__tablename__ = 'users_group_repo_to_perm'
|
|
937
|
__tablename__ = 'users_group_repo_to_perm'
|
|
919
|
__table_args__ = (UniqueConstraint('repository_id', 'users_group_id', 'permission_id'), {'extend_existing':True})
|
|
938
|
__table_args__ = ( UniqueConstraint( 'repository_id', 'users_group_id', 'permission_id' ), {'extend_existing':True} )
|
|
920
|
users_group_to_perm_id = Column("users_group_to_perm_id", Integer(), nullable=False, unique=True, default=None, primary_key=True)
|
|
939
|
users_group_to_perm_id = Column( "users_group_to_perm_id", Integer(), nullable = False, unique = True, default = None, primary_key = True )
|
|
921
|
users_group_id = Column("users_group_id", Integer(), ForeignKey('users_groups.users_group_id'), nullable=False, unique=None, default=None)
|
|
940
|
users_group_id = Column( "users_group_id", Integer(), ForeignKey( 'users_groups.users_group_id' ), nullable = False, unique = None, default = None )
|
|
922
|
permission_id = Column("permission_id", Integer(), ForeignKey('permissions.permission_id'), nullable=False, unique=None, default=None)
|
|
941
|
permission_id = Column( "permission_id", Integer(), ForeignKey( 'permissions.permission_id' ), nullable = False, unique = None, default = None )
|
|
923
|
repository_id = Column("repository_id", Integer(), ForeignKey('repositories.repo_id'), nullable=False, unique=None, default=None)
|
|
942
|
repository_id = Column( "repository_id", Integer(), ForeignKey( 'repositories.repo_id' ), nullable = False, unique = None, default = None )
|
|
924
|
|
|
943
|
|
|
925
|
users_group = relationship('UsersGroup')
|
|
944
|
users_group = relationship( 'UsersGroup' )
|
|
926
|
permission = relationship('Permission')
|
|
945
|
permission = relationship( 'Permission' )
|
|
927
|
repository = relationship('Repository')
|
|
946
|
repository = relationship( 'Repository' )
|
|
928
|
|
|
947
|
|
|
929
|
def __repr__(self):
|
|
948
|
def __repr__( self ):
|
|
930
|
return '<userGroup:%s => %s >' % (self.users_group, self.repository)
|
|
949
|
return '<userGroup:%s => %s >' % ( self.users_group, self.repository )
|
|
931
|
|
|
950
|
|
|
932
|
class UsersGroupToPerm(Base, BaseModel):
|
|
951
|
class UsersGroupToPerm( Base, BaseModel ):
|
|
933
|
__tablename__ = 'users_group_to_perm'
|
|
952
|
__tablename__ = 'users_group_to_perm'
|
|
934
|
users_group_to_perm_id = Column("users_group_to_perm_id", Integer(), nullable=False, unique=True, default=None, primary_key=True)
|
|
953
|
users_group_to_perm_id = Column( "users_group_to_perm_id", Integer(), nullable = False, unique = True, default = None, primary_key = True )
|
|
935
|
users_group_id = Column("users_group_id", Integer(), ForeignKey('users_groups.users_group_id'), nullable=False, unique=None, default=None)
|
|
954
|
users_group_id = Column( "users_group_id", Integer(), ForeignKey( 'users_groups.users_group_id' ), nullable = False, unique = None, default = None )
|
|
936
|
permission_id = Column("permission_id", Integer(), ForeignKey('permissions.permission_id'), nullable=False, unique=None, default=None)
|
|
955
|
permission_id = Column( "permission_id", Integer(), ForeignKey( 'permissions.permission_id' ), nullable = False, unique = None, default = None )
|
|
937
|
|
|
956
|
|
|
938
|
users_group = relationship('UsersGroup')
|
|
957
|
users_group = relationship( 'UsersGroup' )
|
|
939
|
permission = relationship('Permission')
|
|
958
|
permission = relationship( 'Permission' )
|
|
940
|
|
|
959
|
|
|
941
|
|
|
960
|
|
|
942
|
@classmethod
|
|
961
|
@classmethod
|
|
943
|
def has_perm(cls, users_group_id, perm):
|
|
962
|
def has_perm( cls, users_group_id, perm ):
|
|
944
|
if not isinstance(perm, Permission):
|
|
963
|
if not isinstance( perm, Permission ):
|
|
945
|
raise Exception('perm needs to be an instance of Permission class')
|
|
964
|
raise Exception( 'perm needs to be an instance of Permission class' )
|
|
946
|
|
|
965
|
|
|
947
|
return Session.query(cls).filter(cls.users_group_id ==
|
|
966
|
return cls.query().filter( cls.users_group_id ==
|
|
948
|
users_group_id)\
|
|
967
|
users_group_id )\
|
|
949
|
.filter(cls.permission == perm)\
|
|
968
|
.filter( cls.permission == perm )\
|
|
950
|
.scalar() is not None
|
|
969
|
.scalar() is not None
|
|
951
|
|
|
970
|
|
|
952
|
@classmethod
|
|
971
|
@classmethod
|
|
953
|
def grant_perm(cls, users_group_id, perm):
|
|
972
|
def grant_perm( cls, users_group_id, perm ):
|
|
954
|
if not isinstance(perm, Permission):
|
|
973
|
if not isinstance( perm, Permission ):
|
|
955
|
raise Exception('perm needs to be an instance of Permission class')
|
|
974
|
raise Exception( 'perm needs to be an instance of Permission class' )
|
|
956
|
|
|
975
|
|
|
957
|
new = cls()
|
|
976
|
new = cls()
|
|
958
|
new.users_group_id = users_group_id
|
|
977
|
new.users_group_id = users_group_id
|
|
959
|
new.permission = perm
|
|
978
|
new.permission = perm
|
|
960
|
try:
|
|
979
|
try:
|
|
961
|
Session.add(new)
|
|
980
|
Session.add( new )
|
|
962
|
Session.commit()
|
|
981
|
Session.commit()
|
|
963
|
except:
|
|
982
|
except:
|
|
964
|
Session.rollback()
|
|
983
|
Session.rollback()
|
|
965
|
|
|
984
|
|
|
966
|
|
|
985
|
|
|
967
|
@classmethod
|
|
986
|
@classmethod
|
|
968
|
def revoke_perm(cls, users_group_id, perm):
|
|
987
|
def revoke_perm( cls, users_group_id, perm ):
|
|
969
|
if not isinstance(perm, Permission):
|
|
988
|
if not isinstance( perm, Permission ):
|
|
970
|
raise Exception('perm needs to be an instance of Permission class')
|
|
989
|
raise Exception( 'perm needs to be an instance of Permission class' )
|
|
971
|
|
|
990
|
|
|
972
|
try:
|
|
991
|
try:
|
|
973
|
Session.query(cls).filter(cls.users_group_id == users_group_id)\
|
|
992
|
cls.query().filter( cls.users_group_id == users_group_id )\
|
|
974
|
.filter(cls.permission == perm).delete()
|
|
993
|
.filter( cls.permission == perm ).delete()
|
|
975
|
Session.commit()
|
|
994
|
Session.commit()
|
|
976
|
except:
|
|
995
|
except:
|
|
977
|
Session.rollback()
|
|
996
|
Session.rollback()
|
|
978
|
|
|
997
|
|
|
979
|
|
|
998
|
|
|
980
|
class GroupToPerm(Base, BaseModel):
|
|
999
|
class GroupToPerm( Base, BaseModel ):
|
|
981
|
__tablename__ = 'group_to_perm'
|
|
1000
|
__tablename__ = 'group_to_perm'
|
|
982
|
__table_args__ = (UniqueConstraint('group_id', 'permission_id'), {'extend_existing':True})
|
|
1001
|
__table_args__ = ( UniqueConstraint( 'group_id', 'permission_id' ), {'extend_existing':True} )
|
|
983
|
|
|
1002
|
|
|
984
|
group_to_perm_id = Column("group_to_perm_id", Integer(), nullable=False, unique=True, default=None, primary_key=True)
|
|
1003
|
group_to_perm_id = Column( "group_to_perm_id", Integer(), nullable = False, unique = True, default = None, primary_key = True )
|
|
985
|
user_id = Column("user_id", Integer(), ForeignKey('users.user_id'), nullable=False, unique=None, default=None)
|
|
1004
|
user_id = Column( "user_id", Integer(), ForeignKey( 'users.user_id' ), nullable = False, unique = None, default = None )
|
|
986
|
permission_id = Column("permission_id", Integer(), ForeignKey('permissions.permission_id'), nullable=False, unique=None, default=None)
|
|
1005
|
permission_id = Column( "permission_id", Integer(), ForeignKey( 'permissions.permission_id' ), nullable = False, unique = None, default = None )
|
|
987
|
group_id = Column("group_id", Integer(), ForeignKey('groups.group_id'), nullable=False, unique=None, default=None)
|
|
1006
|
group_id = Column( "group_id", Integer(), ForeignKey( 'groups.group_id' ), nullable = False, unique = None, default = None )
|
|
988
|
|
|
1007
|
|
|
989
|
user = relationship('User')
|
|
1008
|
user = relationship( 'User' )
|
|
990
|
permission = relationship('Permission')
|
|
1009
|
permission = relationship( 'Permission' )
|
|
991
|
group = relationship('Group')
|
|
1010
|
group = relationship( 'Group' )
|
|
992
|
|
|
1011
|
|
|
993
|
class Statistics(Base, BaseModel):
|
|
1012
|
class Statistics( Base, BaseModel ):
|
|
994
|
__tablename__ = 'statistics'
|
|
1013
|
__tablename__ = 'statistics'
|
|
995
|
__table_args__ = (UniqueConstraint('repository_id'), {'extend_existing':True})
|
|
1014
|
__table_args__ = ( UniqueConstraint( 'repository_id' ), {'extend_existing':True} )
|
|
996
|
stat_id = Column("stat_id", Integer(), nullable=False, unique=True, default=None, primary_key=True)
|
|
1015
|
stat_id = Column( "stat_id", Integer(), nullable = False, unique = True, default = None, primary_key = True )
|
|
997
|
repository_id = Column("repository_id", Integer(), ForeignKey('repositories.repo_id'), nullable=False, unique=True, default=None)
|
|
1016
|
repository_id = Column( "repository_id", Integer(), ForeignKey( 'repositories.repo_id' ), nullable = False, unique = True, default = None )
|
|
998
|
stat_on_revision = Column("stat_on_revision", Integer(), nullable=False)
|
|
1017
|
stat_on_revision = Column( "stat_on_revision", Integer(), nullable = False )
|
|
999
|
commit_activity = Column("commit_activity", LargeBinary(1000000), nullable=False)#JSON data
|
|
1018
|
commit_activity = Column( "commit_activity", LargeBinary( 1000000 ), nullable = False )#JSON data
|
|
1000
|
commit_activity_combined = Column("commit_activity_combined", LargeBinary(), nullable=False)#JSON data
|
|
1019
|
commit_activity_combined = Column( "commit_activity_combined", LargeBinary(), nullable = False )#JSON data
|
|
1001
|
languages = Column("languages", LargeBinary(1000000), nullable=False)#JSON data
|
|
1020
|
languages = Column( "languages", LargeBinary( 1000000 ), nullable = False )#JSON data
|
|
1002
|
|
|
1021
|
|
|
1003
|
repository = relationship('Repository', single_parent=True)
|
|
1022
|
repository = relationship( 'Repository', single_parent = True )
|
|
1004
|
|
|
1023
|
|
|
1005
|
class UserFollowing(Base, BaseModel):
|
|
1024
|
class UserFollowing( Base, BaseModel ):
|
|
1006
|
__tablename__ = 'user_followings'
|
|
1025
|
__tablename__ = 'user_followings'
|
|
1007
|
__table_args__ = (UniqueConstraint('user_id', 'follows_repository_id'),
|
|
1026
|
__table_args__ = ( UniqueConstraint( 'user_id', 'follows_repository_id' ),
|
|
1008
|
UniqueConstraint('user_id', 'follows_user_id')
|
|
1027
|
UniqueConstraint( 'user_id', 'follows_user_id' )
|
|
1009
|
, {'extend_existing':True})
|
|
1028
|
, {'extend_existing':True} )
|
|
1010
|
|
|
1029
|
|
|
1011
|
user_following_id = Column("user_following_id", Integer(), nullable=False, unique=True, default=None, primary_key=True)
|
|
1030
|
user_following_id = Column( "user_following_id", Integer(), nullable = False, unique = True, default = None, primary_key = True )
|
|
1012
|
user_id = Column("user_id", Integer(), ForeignKey('users.user_id'), nullable=False, unique=None, default=None)
|
|
1031
|
user_id = Column( "user_id", Integer(), ForeignKey( 'users.user_id' ), nullable = False, unique = None, default = None )
|
|
1013
|
follows_repo_id = Column("follows_repository_id", Integer(), ForeignKey('repositories.repo_id'), nullable=True, unique=None, default=None)
|
|
1032
|
follows_repo_id = Column( "follows_repository_id", Integer(), ForeignKey( 'repositories.repo_id' ), nullable = True, unique = None, default = None )
|
|
1014
|
follows_user_id = Column("follows_user_id", Integer(), ForeignKey('users.user_id'), nullable=True, unique=None, default=None)
|
|
1033
|
follows_user_id = Column( "follows_user_id", Integer(), ForeignKey( 'users.user_id' ), nullable = True, unique = None, default = None )
|
|
1015
|
follows_from = Column('follows_from', DateTime(timezone=False), nullable=True, unique=None, default=datetime.datetime.now)
|
|
1034
|
follows_from = Column( 'follows_from', DateTime( timezone = False ), nullable = True, unique = None, default = datetime.datetime.now )
|
|
1016
|
|
|
1035
|
|
|
1017
|
user = relationship('User', primaryjoin='User.user_id==UserFollowing.user_id')
|
|
1036
|
user = relationship( 'User', primaryjoin = 'User.user_id==UserFollowing.user_id' )
|
|
1018
|
|
|
1037
|
|
|
1019
|
follows_user = relationship('User', primaryjoin='User.user_id==UserFollowing.follows_user_id')
|
|
1038
|
follows_user = relationship( 'User', primaryjoin = 'User.user_id==UserFollowing.follows_user_id' )
|
|
1020
|
follows_repository = relationship('Repository', order_by='Repository.repo_name')
|
|
1039
|
follows_repository = relationship( 'Repository', order_by = 'Repository.repo_name' )
|
|
1021
|
|
|
1040
|
|
|
1022
|
|
|
1041
|
|
|
1023
|
@classmethod
|
|
1042
|
@classmethod
|
|
1024
|
def get_repo_followers(cls, repo_id):
|
|
1043
|
def get_repo_followers( cls, repo_id ):
|
|
1025
|
return Session.query(cls).filter(cls.follows_repo_id == repo_id)
|
|
1044
|
return cls.query().filter( cls.follows_repo_id == repo_id )
|
|
1026
|
|
|
1045
|
|
|
1027
|
class CacheInvalidation(Base, BaseModel):
|
|
1046
|
class CacheInvalidation( Base, BaseModel ):
|
|
1028
|
__tablename__ = 'cache_invalidation'
|
|
1047
|
__tablename__ = 'cache_invalidation'
|
|
1029
|
__table_args__ = (UniqueConstraint('cache_key'), {'extend_existing':True})
|
|
1048
|
__table_args__ = ( UniqueConstraint( 'cache_key' ), {'extend_existing':True} )
|
|
1030
|
cache_id = Column("cache_id", Integer(), nullable=False, unique=True, default=None, primary_key=True)
|
|
1049
|
cache_id = Column( "cache_id", Integer(), nullable = False, unique = True, default = None, primary_key = True )
|
|
1031
|
cache_key = Column("cache_key", String(length=255, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None)
|
|
1050
|
cache_key = Column( "cache_key", String( length = 255, convert_unicode = False, assert_unicode = None ), nullable = True, unique = None, default = None )
|
|
1032
|
cache_args = Column("cache_args", String(length=255, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None)
|
|
1051
|
cache_args = Column( "cache_args", String( length = 255, convert_unicode = False, assert_unicode = None ), nullable = True, unique = None, default = None )
|
|
1033
|
cache_active = Column("cache_active", Boolean(), nullable=True, unique=None, default=False)
|
|
1052
|
cache_active = Column( "cache_active", Boolean(), nullable = True, unique = None, default = False )
|
|
1034
|
|
|
1053
|
|
|
1035
|
|
|
1054
|
|
|
1036
|
def __init__(self, cache_key, cache_args=''):
|
|
1055
|
def __init__( self, cache_key, cache_args = '' ):
|
|
1037
|
self.cache_key = cache_key
|
|
1056
|
self.cache_key = cache_key
|
|
1038
|
self.cache_args = cache_args
|
|
1057
|
self.cache_args = cache_args
|
|
1039
|
self.cache_active = False
|
|
1058
|
self.cache_active = False
|
|
1040
|
|
|
1059
|
|
|
1041
|
def __repr__(self):
|
|
1060
|
def __repr__( self ):
|
|
1042
|
return "<%s('%s:%s')>" % (self.__class__.__name__,
|
|
1061
|
return "<%s('%s:%s')>" % ( self.__class__.__name__,
|
|
1043
|
self.cache_id, self.cache_key)
|
|
1062
|
self.cache_id, self.cache_key )
|
|
1044
|
|
|
1063
|
|
|
1045
|
class DbMigrateVersion(Base, BaseModel):
|
|
1064
|
class DbMigrateVersion( Base, BaseModel ):
|
|
1046
|
__tablename__ = 'db_migrate_version'
|
|
1065
|
__tablename__ = 'db_migrate_version'
|
|
1047
|
__table_args__ = {'extend_existing':True}
|
|
1066
|
__table_args__ = {'extend_existing':True}
|
|
1048
|
repository_id = Column('repository_id', String(250), primary_key=True)
|
|
1067
|
repository_id = Column( 'repository_id', String( 250 ), primary_key = True )
|
|
1049
|
repository_path = Column('repository_path', Text)
|
|
1068
|
repository_path = Column( 'repository_path', Text )
|
|
1050
|
version = Column('version', Integer)
|
|
1069
|
version = Column( 'version', Integer )
|