##// END OF EJS Templates
users: added SSH key management for user admin pages
marcink -
r1993:dab53d0e default
parent child Browse files
Show More
@@ -0,0 +1,173 b''
1 # -*- coding: utf-8 -*-
2
3 # Copyright (C) 2010-2017 RhodeCode GmbH
4 #
5 # This program is free software: you can redistribute it and/or modify
6 # it under the terms of the GNU Affero General Public License, version 3
7 # (only), as published by the Free Software Foundation.
8 #
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
13 #
14 # You should have received a copy of the GNU Affero General Public License
15 # along with this program. If not, see <http://www.gnu.org/licenses/>.
16 #
17 # This program is dual-licensed. If you wish to learn more about the
18 # RhodeCode Enterprise Edition, including its added features, Support services,
19 # and proprietary license terms, please see https://rhodecode.com/licenses/
20
21 import pytest
22
23 from rhodecode.model.db import User, UserSshKeys
24
25 from rhodecode.tests import TestController, assert_session_flash
26 from rhodecode.tests.fixture import Fixture
27
28 fixture = Fixture()
29
30
31 def route_path(name, params=None, **kwargs):
32 import urllib
33 from rhodecode.apps._base import ADMIN_PREFIX
34
35 base_url = {
36 'edit_user_ssh_keys':
37 ADMIN_PREFIX + '/users/{user_id}/edit/ssh_keys',
38 'edit_user_ssh_keys_generate_keypair':
39 ADMIN_PREFIX + '/users/{user_id}/edit/ssh_keys/generate',
40 'edit_user_ssh_keys_add':
41 ADMIN_PREFIX + '/users/{user_id}/edit/ssh_keys/new',
42 'edit_user_ssh_keys_delete':
43 ADMIN_PREFIX + '/users/{user_id}/edit/ssh_keys/delete',
44
45 }[name].format(**kwargs)
46
47 if params:
48 base_url = '{}?{}'.format(base_url, urllib.urlencode(params))
49 return base_url
50
51
52 class TestAdminUsersSshKeysView(TestController):
53 INVALID_KEY = """\
54 ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDk+77sjDzVeB6vevJsuZds1iNU5
55 LANOa5CU5G/9JYIA6RYsWWMO7mbsR82IUckdqOHmxSykfR1D1TdluyIpQLrwgH5kb
56 n8FkVI8zBMCKakxowvN67B0R7b1BT4PPzW2JlOXei/m9W12ZY484VTow6/B+kf2Q8
57 cP8tmCJmKWZma5Em7OTUhvjyQVNz3v7HfeY5Hq0Ci4ECJ59hepFDabJvtAXg9XrI6
58 jvdphZTc30I4fG8+hBHzpeFxUGvSGNtXPUbwaAY8j/oHYrTpMgkj6pUEFsiKfC5zP
59 qPFR5HyKTCHW0nFUJnZsbyFT5hMiF/hZkJc9A0ZbdSvJwCRQ/g3bmdL
60 your_email@example.com
61 """
62 VALID_KEY = 'ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDk+77sjDzVeB6vev' \
63 'JsuZds1iNU5LANOa5CU5G/9JYIA6RYsWWMO7mbsR82IUckdqOHmxSy' \
64 'kfR1D1TdluyIpQLrwgH5kbn8FkVI8zBMCKakxowvN67B0R7b1BT4PP' \
65 'zW2JlOXei/m9W12ZY484VTow6/B+kf2Q8cP8tmCJmKWZma5Em7OTUh' \
66 'vjyQVNz3v7HfeY5Hq0Ci4ECJ59hepFDabJvtAXg9XrI6jvdphZTc30' \
67 'I4fG8+hBHzpeFxUGvSGNtXPUbwaAY8j/oHYrTpMgkj6pUEFsiKfC5zPq' \
68 'PFR5HyKTCHW0nFUJnZsbyFT5hMiF/hZkJc9A0ZbdSvJwCRQ/g3bmdL ' \
69 'your_email@example.com'
70
71 def test_ssh_keys_default_user(self):
72 self.log_user()
73 user = User.get_default_user()
74 self.app.get(
75 route_path('edit_user_ssh_keys', user_id=user.user_id),
76 status=302)
77
78 def test_add_ssh_key_error(self, user_util):
79 self.log_user()
80 user = user_util.create_user()
81 user_id = user.user_id
82
83 key_data = self.INVALID_KEY
84
85 desc = 'MY SSH KEY'
86 response = self.app.post(
87 route_path('edit_user_ssh_keys_add', user_id=user_id),
88 {'description': desc, 'key_data': key_data,
89 'csrf_token': self.csrf_token})
90 assert_session_flash(response, 'An error occurred during ssh '
91 'key saving: Unable to decode the key')
92
93 def test_ssh_key_duplicate(self, user_util):
94 self.log_user()
95 user = user_util.create_user()
96 user_id = user.user_id
97
98 key_data = self.VALID_KEY
99
100 desc = 'MY SSH KEY'
101 response = self.app.post(
102 route_path('edit_user_ssh_keys_add', user_id=user_id),
103 {'description': desc, 'key_data': key_data,
104 'csrf_token': self.csrf_token})
105 assert_session_flash(response, 'Ssh Key successfully created')
106 response.follow() # flush session flash
107
108 # add the same key AGAIN
109 desc = 'MY SSH KEY'
110 response = self.app.post(
111 route_path('edit_user_ssh_keys_add', user_id=user_id),
112 {'description': desc, 'key_data': key_data,
113 'csrf_token': self.csrf_token})
114 assert_session_flash(response, 'An error occurred during ssh key '
115 'saving: Such key already exists, '
116 'please use a different one')
117
118 def test_add_ssh_key(self, user_util):
119 self.log_user()
120 user = user_util.create_user()
121 user_id = user.user_id
122
123 key_data = self.VALID_KEY
124
125 desc = 'MY SSH KEY'
126 response = self.app.post(
127 route_path('edit_user_ssh_keys_add', user_id=user_id),
128 {'description': desc, 'key_data': key_data,
129 'csrf_token': self.csrf_token})
130 assert_session_flash(response, 'Ssh Key successfully created')
131
132 response = response.follow()
133 response.mustcontain(desc)
134
135 def test_delete_ssh_key(self, user_util):
136 self.log_user()
137 user = user_util.create_user()
138 user_id = user.user_id
139
140 key_data = self.VALID_KEY
141
142 desc = 'MY SSH KEY'
143 response = self.app.post(
144 route_path('edit_user_ssh_keys_add', user_id=user_id),
145 {'description': desc, 'key_data': key_data,
146 'csrf_token': self.csrf_token})
147 assert_session_flash(response, 'Ssh Key successfully created')
148 response = response.follow() # flush the Session flash
149
150 # now delete our key
151 keys = UserSshKeys.query().filter(UserSshKeys.user_id == user_id).all()
152 assert 1 == len(keys)
153
154 response = self.app.post(
155 route_path('edit_user_ssh_keys_delete', user_id=user_id),
156 {'del_ssh_key': keys[0].ssh_key_id,
157 'csrf_token': self.csrf_token})
158
159 assert_session_flash(response, 'Ssh key successfully deleted')
160 keys = UserSshKeys.query().filter(UserSshKeys.user_id == user_id).all()
161 assert 0 == len(keys)
162
163 def test_generate_keypair(self, user_util):
164 self.log_user()
165 user = user_util.create_user()
166 user_id = user.user_id
167
168 response = self.app.get(
169 route_path('edit_user_ssh_keys_generate_keypair', user_id=user_id))
170
171 response.mustcontain('Private key')
172 response.mustcontain('Public key')
173 response.mustcontain('-----BEGIN RSA PRIVATE KEY-----')
This diff has been collapsed as it changes many lines, (4172 lines changed) Show them Hide them
@@ -0,0 +1,4172 b''
1 # -*- coding: utf-8 -*-
2
3 # Copyright (C) 2010-2017 RhodeCode GmbH
4 #
5 # This program is free software: you can redistribute it and/or modify
6 # it under the terms of the GNU Affero General Public License, version 3
7 # (only), as published by the Free Software Foundation.
8 #
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
13 #
14 # You should have received a copy of the GNU Affero General Public License
15 # along with this program. If not, see <http://www.gnu.org/licenses/>.
16 #
17 # This program is dual-licensed. If you wish to learn more about the
18 # RhodeCode Enterprise Edition, including its added features, Support services,
19 # and proprietary license terms, please see https://rhodecode.com/licenses/
20
21 """
22 Database Models for RhodeCode Enterprise
23 """
24
25 import re
26 import os
27 import time
28 import hashlib
29 import logging
30 import datetime
31 import warnings
32 import ipaddress
33 import functools
34 import traceback
35 import collections
36
37
38 from sqlalchemy import *
39 from sqlalchemy.ext.declarative import declared_attr
40 from sqlalchemy.ext.hybrid import hybrid_property
41 from sqlalchemy.orm import (
42 relationship, joinedload, class_mapper, validates, aliased)
43 from sqlalchemy.sql.expression import true
44 from sqlalchemy.sql.functions import coalesce, count # noqa
45 from beaker.cache import cache_region
46 from zope.cachedescriptors.property import Lazy as LazyProperty
47
48 from pyramid.threadlocal import get_current_request
49
50 from rhodecode.translation import _
51 from rhodecode.lib.vcs import get_vcs_instance
52 from rhodecode.lib.vcs.backends.base import EmptyCommit, Reference
53 from rhodecode.lib.utils2 import (
54 str2bool, safe_str, get_commit_safe, safe_unicode, md5_safe,
55 time_to_datetime, aslist, Optional, safe_int, get_clone_url, AttributeDict,
56 glob2re, StrictAttributeDict, cleaned_uri)
57 from rhodecode.lib.jsonalchemy import MutationObj, MutationList, JsonType
58 from rhodecode.lib.ext_json import json
59 from rhodecode.lib.caching_query import FromCache
60 from rhodecode.lib.encrypt import AESCipher
61
62 from rhodecode.model.meta import Base, Session
63
64 URL_SEP = '/'
65 log = logging.getLogger(__name__)
66
67 # =============================================================================
68 # BASE CLASSES
69 # =============================================================================
70
71 # this is propagated from .ini file rhodecode.encrypted_values.secret or
72 # beaker.session.secret if first is not set.
73 # and initialized at environment.py
74 ENCRYPTION_KEY = None
75
76 # used to sort permissions by types, '#' used here is not allowed to be in
77 # usernames, and it's very early in sorted string.printable table.
78 PERMISSION_TYPE_SORT = {
79 'admin': '####',
80 'write': '###',
81 'read': '##',
82 'none': '#',
83 }
84
85
86 def display_sort(obj):
87 """
88 Sort function used to sort permissions in .permissions() function of
89 Repository, RepoGroup, UserGroup. Also it put the default user in front
90 of all other resources
91 """
92
93 if obj.username == User.DEFAULT_USER:
94 return '#####'
95 prefix = PERMISSION_TYPE_SORT.get(obj.permission.split('.')[-1], '')
96 return prefix + obj.username
97
98
99 def _hash_key(k):
100 return md5_safe(k)
101
102
103 class EncryptedTextValue(TypeDecorator):
104 """
105 Special column for encrypted long text data, use like::
106
107 value = Column("encrypted_value", EncryptedValue(), nullable=False)
108
109 This column is intelligent so if value is in unencrypted form it return
110 unencrypted form, but on save it always encrypts
111 """
112 impl = Text
113
114 def process_bind_param(self, value, dialect):
115 if not value:
116 return value
117 if value.startswith('enc$aes$') or value.startswith('enc$aes_hmac$'):
118 # protect against double encrypting if someone manually starts
119 # doing
120 raise ValueError('value needs to be in unencrypted format, ie. '
121 'not starting with enc$aes')
122 return 'enc$aes_hmac$%s' % AESCipher(
123 ENCRYPTION_KEY, hmac=True).encrypt(value)
124
125 def process_result_value(self, value, dialect):
126 import rhodecode
127
128 if not value:
129 return value
130
131 parts = value.split('$', 3)
132 if not len(parts) == 3:
133 # probably not encrypted values
134 return value
135 else:
136 if parts[0] != 'enc':
137 # parts ok but without our header ?
138 return value
139 enc_strict_mode = str2bool(rhodecode.CONFIG.get(
140 'rhodecode.encrypted_values.strict') or True)
141 # at that stage we know it's our encryption
142 if parts[1] == 'aes':
143 decrypted_data = AESCipher(ENCRYPTION_KEY).decrypt(parts[2])
144 elif parts[1] == 'aes_hmac':
145 decrypted_data = AESCipher(
146 ENCRYPTION_KEY, hmac=True,
147 strict_verification=enc_strict_mode).decrypt(parts[2])
148 else:
149 raise ValueError(
150 'Encryption type part is wrong, must be `aes` '
151 'or `aes_hmac`, got `%s` instead' % (parts[1]))
152 return decrypted_data
153
154
155 class BaseModel(object):
156 """
157 Base Model for all classes
158 """
159
160 @classmethod
161 def _get_keys(cls):
162 """return column names for this model """
163 return class_mapper(cls).c.keys()
164
165 def get_dict(self):
166 """
167 return dict with keys and values corresponding
168 to this model data """
169
170 d = {}
171 for k in self._get_keys():
172 d[k] = getattr(self, k)
173
174 # also use __json__() if present to get additional fields
175 _json_attr = getattr(self, '__json__', None)
176 if _json_attr:
177 # update with attributes from __json__
178 if callable(_json_attr):
179 _json_attr = _json_attr()
180 for k, val in _json_attr.iteritems():
181 d[k] = val
182 return d
183
184 def get_appstruct(self):
185 """return list with keys and values tuples corresponding
186 to this model data """
187
188 l = []
189 for k in self._get_keys():
190 l.append((k, getattr(self, k),))
191 return l
192
193 def populate_obj(self, populate_dict):
194 """populate model with data from given populate_dict"""
195
196 for k in self._get_keys():
197 if k in populate_dict:
198 setattr(self, k, populate_dict[k])
199
200 @classmethod
201 def query(cls):
202 return Session().query(cls)
203
204 @classmethod
205 def get(cls, id_):
206 if id_:
207 return cls.query().get(id_)
208
209 @classmethod
210 def get_or_404(cls, id_):
211 from pyramid.httpexceptions import HTTPNotFound
212
213 try:
214 id_ = int(id_)
215 except (TypeError, ValueError):
216 raise HTTPNotFound()
217
218 res = cls.query().get(id_)
219 if not res:
220 raise HTTPNotFound()
221 return res
222
223 @classmethod
224 def getAll(cls):
225 # deprecated and left for backward compatibility
226 return cls.get_all()
227
228 @classmethod
229 def get_all(cls):
230 return cls.query().all()
231
232 @classmethod
233 def delete(cls, id_):
234 obj = cls.query().get(id_)
235 Session().delete(obj)
236
237 @classmethod
238 def identity_cache(cls, session, attr_name, value):
239 exist_in_session = []
240 for (item_cls, pkey), instance in session.identity_map.items():
241 if cls == item_cls and getattr(instance, attr_name) == value:
242 exist_in_session.append(instance)
243 if exist_in_session:
244 if len(exist_in_session) == 1:
245 return exist_in_session[0]
246 log.exception(
247 'multiple objects with attr %s and '
248 'value %s found with same name: %r',
249 attr_name, value, exist_in_session)
250
251 def __repr__(self):
252 if hasattr(self, '__unicode__'):
253 # python repr needs to return str
254 try:
255 return safe_str(self.__unicode__())
256 except UnicodeDecodeError:
257 pass
258 return '<DB:%s>' % (self.__class__.__name__)
259
260
261 class RhodeCodeSetting(Base, BaseModel):
262 __tablename__ = 'rhodecode_settings'
263 __table_args__ = (
264 UniqueConstraint('app_settings_name'),
265 {'extend_existing': True, 'mysql_engine': 'InnoDB',
266 'mysql_charset': 'utf8', 'sqlite_autoincrement': True}
267 )
268
269 SETTINGS_TYPES = {
270 'str': safe_str,
271 'int': safe_int,
272 'unicode': safe_unicode,
273 'bool': str2bool,
274 'list': functools.partial(aslist, sep=',')
275 }
276 DEFAULT_UPDATE_URL = 'https://rhodecode.com/api/v1/info/versions'
277 GLOBAL_CONF_KEY = 'app_settings'
278
279 app_settings_id = Column("app_settings_id", Integer(), nullable=False, unique=True, default=None, primary_key=True)
280 app_settings_name = Column("app_settings_name", String(255), nullable=True, unique=None, default=None)
281 _app_settings_value = Column("app_settings_value", String(4096), nullable=True, unique=None, default=None)
282 _app_settings_type = Column("app_settings_type", String(255), nullable=True, unique=None, default=None)
283
284 def __init__(self, key='', val='', type='unicode'):
285 self.app_settings_name = key
286 self.app_settings_type = type
287 self.app_settings_value = val
288
289 @validates('_app_settings_value')
290 def validate_settings_value(self, key, val):
291 assert type(val) == unicode
292 return val
293
294 @hybrid_property
295 def app_settings_value(self):
296 v = self._app_settings_value
297 _type = self.app_settings_type
298 if _type:
299 _type = self.app_settings_type.split('.')[0]
300 # decode the encrypted value
301 if 'encrypted' in self.app_settings_type:
302 cipher = EncryptedTextValue()
303 v = safe_unicode(cipher.process_result_value(v, None))
304
305 converter = self.SETTINGS_TYPES.get(_type) or \
306 self.SETTINGS_TYPES['unicode']
307 return converter(v)
308
309 @app_settings_value.setter
310 def app_settings_value(self, val):
311 """
312 Setter that will always make sure we use unicode in app_settings_value
313
314 :param val:
315 """
316 val = safe_unicode(val)
317 # encode the encrypted value
318 if 'encrypted' in self.app_settings_type:
319 cipher = EncryptedTextValue()
320 val = safe_unicode(cipher.process_bind_param(val, None))
321 self._app_settings_value = val
322
323 @hybrid_property
324 def app_settings_type(self):
325 return self._app_settings_type
326
327 @app_settings_type.setter
328 def app_settings_type(self, val):
329 if val.split('.')[0] not in self.SETTINGS_TYPES:
330 raise Exception('type must be one of %s got %s'
331 % (self.SETTINGS_TYPES.keys(), val))
332 self._app_settings_type = val
333
334 def __unicode__(self):
335 return u"<%s('%s:%s[%s]')>" % (
336 self.__class__.__name__,
337 self.app_settings_name, self.app_settings_value,
338 self.app_settings_type
339 )
340
341
342 class RhodeCodeUi(Base, BaseModel):
343 __tablename__ = 'rhodecode_ui'
344 __table_args__ = (
345 UniqueConstraint('ui_key'),
346 {'extend_existing': True, 'mysql_engine': 'InnoDB',
347 'mysql_charset': 'utf8', 'sqlite_autoincrement': True}
348 )
349
350 HOOK_REPO_SIZE = 'changegroup.repo_size'
351 # HG
352 HOOK_PRE_PULL = 'preoutgoing.pre_pull'
353 HOOK_PULL = 'outgoing.pull_logger'
354 HOOK_PRE_PUSH = 'prechangegroup.pre_push'
355 HOOK_PRETX_PUSH = 'pretxnchangegroup.pre_push'
356 HOOK_PUSH = 'changegroup.push_logger'
357 HOOK_PUSH_KEY = 'pushkey.key_push'
358
359 # TODO: johbo: Unify way how hooks are configured for git and hg,
360 # git part is currently hardcoded.
361
362 # SVN PATTERNS
363 SVN_BRANCH_ID = 'vcs_svn_branch'
364 SVN_TAG_ID = 'vcs_svn_tag'
365
366 ui_id = Column(
367 "ui_id", Integer(), nullable=False, unique=True, default=None,
368 primary_key=True)
369 ui_section = Column(
370 "ui_section", String(255), nullable=True, unique=None, default=None)
371 ui_key = Column(
372 "ui_key", String(255), nullable=True, unique=None, default=None)
373 ui_value = Column(
374 "ui_value", String(255), nullable=True, unique=None, default=None)
375 ui_active = Column(
376 "ui_active", Boolean(), nullable=True, unique=None, default=True)
377
378 def __repr__(self):
379 return '<%s[%s]%s=>%s]>' % (self.__class__.__name__, self.ui_section,
380 self.ui_key, self.ui_value)
381
382
383 class RepoRhodeCodeSetting(Base, BaseModel):
384 __tablename__ = 'repo_rhodecode_settings'
385 __table_args__ = (
386 UniqueConstraint(
387 'app_settings_name', 'repository_id',
388 name='uq_repo_rhodecode_setting_name_repo_id'),
389 {'extend_existing': True, 'mysql_engine': 'InnoDB',
390 'mysql_charset': 'utf8', 'sqlite_autoincrement': True}
391 )
392
393 repository_id = Column(
394 "repository_id", Integer(), ForeignKey('repositories.repo_id'),
395 nullable=False)
396 app_settings_id = Column(
397 "app_settings_id", Integer(), nullable=False, unique=True,
398 default=None, primary_key=True)
399 app_settings_name = Column(
400 "app_settings_name", String(255), nullable=True, unique=None,
401 default=None)
402 _app_settings_value = Column(
403 "app_settings_value", String(4096), nullable=True, unique=None,
404 default=None)
405 _app_settings_type = Column(
406 "app_settings_type", String(255), nullable=True, unique=None,
407 default=None)
408
409 repository = relationship('Repository')
410
411 def __init__(self, repository_id, key='', val='', type='unicode'):
412 self.repository_id = repository_id
413 self.app_settings_name = key
414 self.app_settings_type = type
415 self.app_settings_value = val
416
417 @validates('_app_settings_value')
418 def validate_settings_value(self, key, val):
419 assert type(val) == unicode
420 return val
421
422 @hybrid_property
423 def app_settings_value(self):
424 v = self._app_settings_value
425 type_ = self.app_settings_type
426 SETTINGS_TYPES = RhodeCodeSetting.SETTINGS_TYPES
427 converter = SETTINGS_TYPES.get(type_) or SETTINGS_TYPES['unicode']
428 return converter(v)
429
430 @app_settings_value.setter
431 def app_settings_value(self, val):
432 """
433 Setter that will always make sure we use unicode in app_settings_value
434
435 :param val:
436 """
437 self._app_settings_value = safe_unicode(val)
438
439 @hybrid_property
440 def app_settings_type(self):
441 return self._app_settings_type
442
443 @app_settings_type.setter
444 def app_settings_type(self, val):
445 SETTINGS_TYPES = RhodeCodeSetting.SETTINGS_TYPES
446 if val not in SETTINGS_TYPES:
447 raise Exception('type must be one of %s got %s'
448 % (SETTINGS_TYPES.keys(), val))
449 self._app_settings_type = val
450
451 def __unicode__(self):
452 return u"<%s('%s:%s:%s[%s]')>" % (
453 self.__class__.__name__, self.repository.repo_name,
454 self.app_settings_name, self.app_settings_value,
455 self.app_settings_type
456 )
457
458
459 class RepoRhodeCodeUi(Base, BaseModel):
460 __tablename__ = 'repo_rhodecode_ui'
461 __table_args__ = (
462 UniqueConstraint(
463 'repository_id', 'ui_section', 'ui_key',
464 name='uq_repo_rhodecode_ui_repository_id_section_key'),
465 {'extend_existing': True, 'mysql_engine': 'InnoDB',
466 'mysql_charset': 'utf8', 'sqlite_autoincrement': True}
467 )
468
469 repository_id = Column(
470 "repository_id", Integer(), ForeignKey('repositories.repo_id'),
471 nullable=False)
472 ui_id = Column(
473 "ui_id", Integer(), nullable=False, unique=True, default=None,
474 primary_key=True)
475 ui_section = Column(
476 "ui_section", String(255), nullable=True, unique=None, default=None)
477 ui_key = Column(
478 "ui_key", String(255), nullable=True, unique=None, default=None)
479 ui_value = Column(
480 "ui_value", String(255), nullable=True, unique=None, default=None)
481 ui_active = Column(
482 "ui_active", Boolean(), nullable=True, unique=None, default=True)
483
484 repository = relationship('Repository')
485
486 def __repr__(self):
487 return '<%s[%s:%s]%s=>%s]>' % (
488 self.__class__.__name__, self.repository.repo_name,
489 self.ui_section, self.ui_key, self.ui_value)
490
491
492 class User(Base, BaseModel):
493 __tablename__ = 'users'
494 __table_args__ = (
495 UniqueConstraint('username'), UniqueConstraint('email'),
496 Index('u_username_idx', 'username'),
497 Index('u_email_idx', 'email'),
498 {'extend_existing': True, 'mysql_engine': 'InnoDB',
499 'mysql_charset': 'utf8', 'sqlite_autoincrement': True}
500 )
501 DEFAULT_USER = 'default'
502 DEFAULT_USER_EMAIL = 'anonymous@rhodecode.org'
503 DEFAULT_GRAVATAR_URL = 'https://secure.gravatar.com/avatar/{md5email}?d=identicon&s={size}'
504
505 user_id = Column("user_id", Integer(), nullable=False, unique=True, default=None, primary_key=True)
506 username = Column("username", String(255), nullable=True, unique=None, default=None)
507 password = Column("password", String(255), nullable=True, unique=None, default=None)
508 active = Column("active", Boolean(), nullable=True, unique=None, default=True)
509 admin = Column("admin", Boolean(), nullable=True, unique=None, default=False)
510 name = Column("firstname", String(255), nullable=True, unique=None, default=None)
511 lastname = Column("lastname", String(255), nullable=True, unique=None, default=None)
512 _email = Column("email", String(255), nullable=True, unique=None, default=None)
513 last_login = Column("last_login", DateTime(timezone=False), nullable=True, unique=None, default=None)
514 last_activity = Column('last_activity', DateTime(timezone=False), nullable=True, unique=None, default=None)
515
516 extern_type = Column("extern_type", String(255), nullable=True, unique=None, default=None)
517 extern_name = Column("extern_name", String(255), nullable=True, unique=None, default=None)
518 _api_key = Column("api_key", String(255), nullable=True, unique=None, default=None)
519 inherit_default_permissions = Column("inherit_default_permissions", Boolean(), nullable=False, unique=None, default=True)
520 created_on = Column('created_on', DateTime(timezone=False), nullable=False, default=datetime.datetime.now)
521 _user_data = Column("user_data", LargeBinary(), nullable=True) # JSON data
522
523 user_log = relationship('UserLog')
524 user_perms = relationship('UserToPerm', primaryjoin="User.user_id==UserToPerm.user_id", cascade='all')
525
526 repositories = relationship('Repository')
527 repository_groups = relationship('RepoGroup')
528 user_groups = relationship('UserGroup')
529
530 user_followers = relationship('UserFollowing', primaryjoin='UserFollowing.follows_user_id==User.user_id', cascade='all')
531 followings = relationship('UserFollowing', primaryjoin='UserFollowing.user_id==User.user_id', cascade='all')
532
533 repo_to_perm = relationship('UserRepoToPerm', primaryjoin='UserRepoToPerm.user_id==User.user_id', cascade='all')
534 repo_group_to_perm = relationship('UserRepoGroupToPerm', primaryjoin='UserRepoGroupToPerm.user_id==User.user_id', cascade='all')
535 user_group_to_perm = relationship('UserUserGroupToPerm', primaryjoin='UserUserGroupToPerm.user_id==User.user_id', cascade='all')
536
537 group_member = relationship('UserGroupMember', cascade='all')
538
539 notifications = relationship('UserNotification', cascade='all')
540 # notifications assigned to this user
541 user_created_notifications = relationship('Notification', cascade='all')
542 # comments created by this user
543 user_comments = relationship('ChangesetComment', cascade='all')
544 # user profile extra info
545 user_emails = relationship('UserEmailMap', cascade='all')
546 user_ip_map = relationship('UserIpMap', cascade='all')
547 user_auth_tokens = relationship('UserApiKeys', cascade='all')
548 user_ssh_keys = relationship('UserSshKeys', cascade='all')
549
550 # gists
551 user_gists = relationship('Gist', cascade='all')
552 # user pull requests
553 user_pull_requests = relationship('PullRequest', cascade='all')
554 # external identities
555 extenal_identities = relationship(
556 'ExternalIdentity',
557 primaryjoin="User.user_id==ExternalIdentity.local_user_id",
558 cascade='all')
559
560 def __unicode__(self):
561 return u"<%s('id:%s:%s')>" % (self.__class__.__name__,
562 self.user_id, self.username)
563
564 @hybrid_property
565 def email(self):
566 return self._email
567
568 @email.setter
569 def email(self, val):
570 self._email = val.lower() if val else None
571
572 @hybrid_property
573 def first_name(self):
574 from rhodecode.lib import helpers as h
575 if self.name:
576 return h.escape(self.name)
577 return self.name
578
579 @hybrid_property
580 def last_name(self):
581 from rhodecode.lib import helpers as h
582 if self.lastname:
583 return h.escape(self.lastname)
584 return self.lastname
585
586 @hybrid_property
587 def api_key(self):
588 """
589 Fetch if exist an auth-token with role ALL connected to this user
590 """
591 user_auth_token = UserApiKeys.query()\
592 .filter(UserApiKeys.user_id == self.user_id)\
593 .filter(or_(UserApiKeys.expires == -1,
594 UserApiKeys.expires >= time.time()))\
595 .filter(UserApiKeys.role == UserApiKeys.ROLE_ALL).first()
596 if user_auth_token:
597 user_auth_token = user_auth_token.api_key
598
599 return user_auth_token
600
601 @api_key.setter
602 def api_key(self, val):
603 # don't allow to set API key this is deprecated for now
604 self._api_key = None
605
606 @property
607 def reviewer_pull_requests(self):
608 return PullRequestReviewers.query() \
609 .options(joinedload(PullRequestReviewers.pull_request)) \
610 .filter(PullRequestReviewers.user_id == self.user_id) \
611 .all()
612
613 @property
614 def firstname(self):
615 # alias for future
616 return self.name
617
618 @property
619 def emails(self):
620 other = UserEmailMap.query()\
621 .filter(UserEmailMap.user == self) \
622 .order_by(UserEmailMap.email_id.asc()) \
623 .all()
624 return [self.email] + [x.email for x in other]
625
626 @property
627 def auth_tokens(self):
628 auth_tokens = self.get_auth_tokens()
629 return [x.api_key for x in auth_tokens]
630
631 def get_auth_tokens(self):
632 return UserApiKeys.query()\
633 .filter(UserApiKeys.user == self)\
634 .order_by(UserApiKeys.user_api_key_id.asc())\
635 .all()
636
637 @property
638 def feed_token(self):
639 return self.get_feed_token()
640
641 def get_feed_token(self):
642 feed_tokens = UserApiKeys.query()\
643 .filter(UserApiKeys.user == self)\
644 .filter(UserApiKeys.role == UserApiKeys.ROLE_FEED)\
645 .all()
646 if feed_tokens:
647 return feed_tokens[0].api_key
648 return 'NO_FEED_TOKEN_AVAILABLE'
649
650 @classmethod
651 def extra_valid_auth_tokens(cls, user, role=None):
652 tokens = UserApiKeys.query().filter(UserApiKeys.user == user)\
653 .filter(or_(UserApiKeys.expires == -1,
654 UserApiKeys.expires >= time.time()))
655 if role:
656 tokens = tokens.filter(or_(UserApiKeys.role == role,
657 UserApiKeys.role == UserApiKeys.ROLE_ALL))
658 return tokens.all()
659
660 def authenticate_by_token(self, auth_token, roles=None, scope_repo_id=None):
661 from rhodecode.lib import auth
662
663 log.debug('Trying to authenticate user: %s via auth-token, '
664 'and roles: %s', self, roles)
665
666 if not auth_token:
667 return False
668
669 crypto_backend = auth.crypto_backend()
670
671 roles = (roles or []) + [UserApiKeys.ROLE_ALL]
672 tokens_q = UserApiKeys.query()\
673 .filter(UserApiKeys.user_id == self.user_id)\
674 .filter(or_(UserApiKeys.expires == -1,
675 UserApiKeys.expires >= time.time()))
676
677 tokens_q = tokens_q.filter(UserApiKeys.role.in_(roles))
678
679 plain_tokens = []
680 hash_tokens = []
681
682 for token in tokens_q.all():
683 # verify scope first
684 if token.repo_id:
685 # token has a scope, we need to verify it
686 if scope_repo_id != token.repo_id:
687 log.debug(
688 'Scope mismatch: token has a set repo scope: %s, '
689 'and calling scope is:%s, skipping further checks',
690 token.repo, scope_repo_id)
691 # token has a scope, and it doesn't match, skip token
692 continue
693
694 if token.api_key.startswith(crypto_backend.ENC_PREF):
695 hash_tokens.append(token.api_key)
696 else:
697 plain_tokens.append(token.api_key)
698
699 is_plain_match = auth_token in plain_tokens
700 if is_plain_match:
701 return True
702
703 for hashed in hash_tokens:
704 # TODO(marcink): this is expensive to calculate, but most secure
705 match = crypto_backend.hash_check(auth_token, hashed)
706 if match:
707 return True
708
709 return False
710
711 @property
712 def ip_addresses(self):
713 ret = UserIpMap.query().filter(UserIpMap.user == self).all()
714 return [x.ip_addr for x in ret]
715
716 @property
717 def username_and_name(self):
718 return '%s (%s %s)' % (self.username, self.first_name, self.last_name)
719
720 @property
721 def username_or_name_or_email(self):
722 full_name = self.full_name if self.full_name is not ' ' else None
723 return self.username or full_name or self.email
724
725 @property
726 def full_name(self):
727 return '%s %s' % (self.first_name, self.last_name)
728
729 @property
730 def full_name_or_username(self):
731 return ('%s %s' % (self.first_name, self.last_name)
732 if (self.first_name and self.last_name) else self.username)
733
734 @property
735 def full_contact(self):
736 return '%s %s <%s>' % (self.first_name, self.last_name, self.email)
737
738 @property
739 def short_contact(self):
740 return '%s %s' % (self.first_name, self.last_name)
741
742 @property
743 def is_admin(self):
744 return self.admin
745
746 @property
747 def AuthUser(self):
748 """
749 Returns instance of AuthUser for this user
750 """
751 from rhodecode.lib.auth import AuthUser
752 return AuthUser(user_id=self.user_id, username=self.username)
753
754 @hybrid_property
755 def user_data(self):
756 if not self._user_data:
757 return {}
758
759 try:
760 return json.loads(self._user_data)
761 except TypeError:
762 return {}
763
764 @user_data.setter
765 def user_data(self, val):
766 if not isinstance(val, dict):
767 raise Exception('user_data must be dict, got %s' % type(val))
768 try:
769 self._user_data = json.dumps(val)
770 except Exception:
771 log.error(traceback.format_exc())
772
773 @classmethod
774 def get_by_username(cls, username, case_insensitive=False,
775 cache=False, identity_cache=False):
776 session = Session()
777
778 if case_insensitive:
779 q = cls.query().filter(
780 func.lower(cls.username) == func.lower(username))
781 else:
782 q = cls.query().filter(cls.username == username)
783
784 if cache:
785 if identity_cache:
786 val = cls.identity_cache(session, 'username', username)
787 if val:
788 return val
789 else:
790 cache_key = "get_user_by_name_%s" % _hash_key(username)
791 q = q.options(
792 FromCache("sql_cache_short", cache_key))
793
794 return q.scalar()
795
796 @classmethod
797 def get_by_auth_token(cls, auth_token, cache=False):
798 q = UserApiKeys.query()\
799 .filter(UserApiKeys.api_key == auth_token)\
800 .filter(or_(UserApiKeys.expires == -1,
801 UserApiKeys.expires >= time.time()))
802 if cache:
803 q = q.options(
804 FromCache("sql_cache_short", "get_auth_token_%s" % auth_token))
805
806 match = q.first()
807 if match:
808 return match.user
809
810 @classmethod
811 def get_by_email(cls, email, case_insensitive=False, cache=False):
812
813 if case_insensitive:
814 q = cls.query().filter(func.lower(cls.email) == func.lower(email))
815
816 else:
817 q = cls.query().filter(cls.email == email)
818
819 email_key = _hash_key(email)
820 if cache:
821 q = q.options(
822 FromCache("sql_cache_short", "get_email_key_%s" % email_key))
823
824 ret = q.scalar()
825 if ret is None:
826 q = UserEmailMap.query()
827 # try fetching in alternate email map
828 if case_insensitive:
829 q = q.filter(func.lower(UserEmailMap.email) == func.lower(email))
830 else:
831 q = q.filter(UserEmailMap.email == email)
832 q = q.options(joinedload(UserEmailMap.user))
833 if cache:
834 q = q.options(
835 FromCache("sql_cache_short", "get_email_map_key_%s" % email_key))
836 ret = getattr(q.scalar(), 'user', None)
837
838 return ret
839
840 @classmethod
841 def get_from_cs_author(cls, author):
842 """
843 Tries to get User objects out of commit author string
844
845 :param author:
846 """
847 from rhodecode.lib.helpers import email, author_name
848 # Valid email in the attribute passed, see if they're in the system
849 _email = email(author)
850 if _email:
851 user = cls.get_by_email(_email, case_insensitive=True)
852 if user:
853 return user
854 # Maybe we can match by username?
855 _author = author_name(author)
856 user = cls.get_by_username(_author, case_insensitive=True)
857 if user:
858 return user
859
860 def update_userdata(self, **kwargs):
861 usr = self
862 old = usr.user_data
863 old.update(**kwargs)
864 usr.user_data = old
865 Session().add(usr)
866 log.debug('updated userdata with ', kwargs)
867
868 def update_lastlogin(self):
869 """Update user lastlogin"""
870 self.last_login = datetime.datetime.now()
871 Session().add(self)
872 log.debug('updated user %s lastlogin', self.username)
873
874 def update_lastactivity(self):
875 """Update user lastactivity"""
876 self.last_activity = datetime.datetime.now()
877 Session().add(self)
878 log.debug('updated user %s lastactivity', self.username)
879
880 def update_password(self, new_password):
881 from rhodecode.lib.auth import get_crypt_password
882
883 self.password = get_crypt_password(new_password)
884 Session().add(self)
885
886 @classmethod
887 def get_first_super_admin(cls):
888 user = User.query().filter(User.admin == true()).first()
889 if user is None:
890 raise Exception('FATAL: Missing administrative account!')
891 return user
892
893 @classmethod
894 def get_all_super_admins(cls):
895 """
896 Returns all admin accounts sorted by username
897 """
898 return User.query().filter(User.admin == true())\
899 .order_by(User.username.asc()).all()
900
901 @classmethod
902 def get_default_user(cls, cache=False, refresh=False):
903 user = User.get_by_username(User.DEFAULT_USER, cache=cache)
904 if user is None:
905 raise Exception('FATAL: Missing default account!')
906 if refresh:
907 # The default user might be based on outdated state which
908 # has been loaded from the cache.
909 # A call to refresh() ensures that the
910 # latest state from the database is used.
911 Session().refresh(user)
912 return user
913
914 def _get_default_perms(self, user, suffix=''):
915 from rhodecode.model.permission import PermissionModel
916 return PermissionModel().get_default_perms(user.user_perms, suffix)
917
918 def get_default_perms(self, suffix=''):
919 return self._get_default_perms(self, suffix)
920
921 def get_api_data(self, include_secrets=False, details='full'):
922 """
923 Common function for generating user related data for API
924
925 :param include_secrets: By default secrets in the API data will be replaced
926 by a placeholder value to prevent exposing this data by accident. In case
927 this data shall be exposed, set this flag to ``True``.
928
929 :param details: details can be 'basic|full' basic gives only a subset of
930 the available user information that includes user_id, name and emails.
931 """
932 user = self
933 user_data = self.user_data
934 data = {
935 'user_id': user.user_id,
936 'username': user.username,
937 'firstname': user.name,
938 'lastname': user.lastname,
939 'email': user.email,
940 'emails': user.emails,
941 }
942 if details == 'basic':
943 return data
944
945 auth_token_length = 40
946 auth_token_replacement = '*' * auth_token_length
947
948 extras = {
949 'auth_tokens': [auth_token_replacement],
950 'active': user.active,
951 'admin': user.admin,
952 'extern_type': user.extern_type,
953 'extern_name': user.extern_name,
954 'last_login': user.last_login,
955 'last_activity': user.last_activity,
956 'ip_addresses': user.ip_addresses,
957 'language': user_data.get('language')
958 }
959 data.update(extras)
960
961 if include_secrets:
962 data['auth_tokens'] = user.auth_tokens
963 return data
964
965 def __json__(self):
966 data = {
967 'full_name': self.full_name,
968 'full_name_or_username': self.full_name_or_username,
969 'short_contact': self.short_contact,
970 'full_contact': self.full_contact,
971 }
972 data.update(self.get_api_data())
973 return data
974
975
976 class UserApiKeys(Base, BaseModel):
977 __tablename__ = 'user_api_keys'
978 __table_args__ = (
979 Index('uak_api_key_idx', 'api_key', unique=True),
980 Index('uak_api_key_expires_idx', 'api_key', 'expires'),
981 {'extend_existing': True, 'mysql_engine': 'InnoDB',
982 'mysql_charset': 'utf8', 'sqlite_autoincrement': True}
983 )
984 __mapper_args__ = {}
985
986 # ApiKey role
987 ROLE_ALL = 'token_role_all'
988 ROLE_HTTP = 'token_role_http'
989 ROLE_VCS = 'token_role_vcs'
990 ROLE_API = 'token_role_api'
991 ROLE_FEED = 'token_role_feed'
992 ROLE_PASSWORD_RESET = 'token_password_reset'
993
994 ROLES = [ROLE_ALL, ROLE_HTTP, ROLE_VCS, ROLE_API, ROLE_FEED]
995
996 user_api_key_id = Column("user_api_key_id", Integer(), nullable=False, unique=True, default=None, primary_key=True)
997 user_id = Column("user_id", Integer(), ForeignKey('users.user_id'), nullable=True, unique=None, default=None)
998 api_key = Column("api_key", String(255), nullable=False, unique=True)
999 description = Column('description', UnicodeText().with_variant(UnicodeText(1024), 'mysql'))
1000 expires = Column('expires', Float(53), nullable=False)
1001 role = Column('role', String(255), nullable=True)
1002 created_on = Column('created_on', DateTime(timezone=False), nullable=False, default=datetime.datetime.now)
1003
1004 # scope columns
1005 repo_id = Column(
1006 'repo_id', Integer(), ForeignKey('repositories.repo_id'),
1007 nullable=True, unique=None, default=None)
1008 repo = relationship('Repository', lazy='joined')
1009
1010 repo_group_id = Column(
1011 'repo_group_id', Integer(), ForeignKey('groups.group_id'),
1012 nullable=True, unique=None, default=None)
1013 repo_group = relationship('RepoGroup', lazy='joined')
1014
1015 user = relationship('User', lazy='joined')
1016
1017 def __unicode__(self):
1018 return u"<%s('%s')>" % (self.__class__.__name__, self.role)
1019
1020 def __json__(self):
1021 data = {
1022 'auth_token': self.api_key,
1023 'role': self.role,
1024 'scope': self.scope_humanized,
1025 'expired': self.expired
1026 }
1027 return data
1028
1029 def get_api_data(self, include_secrets=False):
1030 data = self.__json__()
1031 if include_secrets:
1032 return data
1033 else:
1034 data['auth_token'] = self.token_obfuscated
1035 return data
1036
1037 @hybrid_property
1038 def description_safe(self):
1039 from rhodecode.lib import helpers as h
1040 return h.escape(self.description)
1041
1042 @property
1043 def expired(self):
1044 if self.expires == -1:
1045 return False
1046 return time.time() > self.expires
1047
1048 @classmethod
1049 def _get_role_name(cls, role):
1050 return {
1051 cls.ROLE_ALL: _('all'),
1052 cls.ROLE_HTTP: _('http/web interface'),
1053 cls.ROLE_VCS: _('vcs (git/hg/svn protocol)'),
1054 cls.ROLE_API: _('api calls'),
1055 cls.ROLE_FEED: _('feed access'),
1056 }.get(role, role)
1057
1058 @property
1059 def role_humanized(self):
1060 return self._get_role_name(self.role)
1061
1062 def _get_scope(self):
1063 if self.repo:
1064 return repr(self.repo)
1065 if self.repo_group:
1066 return repr(self.repo_group) + ' (recursive)'
1067 return 'global'
1068
1069 @property
1070 def scope_humanized(self):
1071 return self._get_scope()
1072
1073 @property
1074 def token_obfuscated(self):
1075 if self.api_key:
1076 return self.api_key[:4] + "****"
1077
1078
1079 class UserEmailMap(Base, BaseModel):
1080 __tablename__ = 'user_email_map'
1081 __table_args__ = (
1082 Index('uem_email_idx', 'email'),
1083 UniqueConstraint('email'),
1084 {'extend_existing': True, 'mysql_engine': 'InnoDB',
1085 'mysql_charset': 'utf8', 'sqlite_autoincrement': True}
1086 )
1087 __mapper_args__ = {}
1088
1089 email_id = Column("email_id", Integer(), nullable=False, unique=True, default=None, primary_key=True)
1090 user_id = Column("user_id", Integer(), ForeignKey('users.user_id'), nullable=True, unique=None, default=None)
1091 _email = Column("email", String(255), nullable=True, unique=False, default=None)
1092 user = relationship('User', lazy='joined')
1093
1094 @validates('_email')
1095 def validate_email(self, key, email):
1096 # check if this email is not main one
1097 main_email = Session().query(User).filter(User.email == email).scalar()
1098 if main_email is not None:
1099 raise AttributeError('email %s is present is user table' % email)
1100 return email
1101
1102 @hybrid_property
1103 def email(self):
1104 return self._email
1105
1106 @email.setter
1107 def email(self, val):
1108 self._email = val.lower() if val else None
1109
1110
1111 class UserIpMap(Base, BaseModel):
1112 __tablename__ = 'user_ip_map'
1113 __table_args__ = (
1114 UniqueConstraint('user_id', 'ip_addr'),
1115 {'extend_existing': True, 'mysql_engine': 'InnoDB',
1116 'mysql_charset': 'utf8', 'sqlite_autoincrement': True}
1117 )
1118 __mapper_args__ = {}
1119
1120 ip_id = Column("ip_id", Integer(), nullable=False, unique=True, default=None, primary_key=True)
1121 user_id = Column("user_id", Integer(), ForeignKey('users.user_id'), nullable=True, unique=None, default=None)
1122 ip_addr = Column("ip_addr", String(255), nullable=True, unique=False, default=None)
1123 active = Column("active", Boolean(), nullable=True, unique=None, default=True)
1124 description = Column("description", String(10000), nullable=True, unique=None, default=None)
1125 user = relationship('User', lazy='joined')
1126
1127 @hybrid_property
1128 def description_safe(self):
1129 from rhodecode.lib import helpers as h
1130 return h.escape(self.description)
1131
1132 @classmethod
1133 def _get_ip_range(cls, ip_addr):
1134 net = ipaddress.ip_network(safe_unicode(ip_addr), strict=False)
1135 return [str(net.network_address), str(net.broadcast_address)]
1136
1137 def __json__(self):
1138 return {
1139 'ip_addr': self.ip_addr,
1140 'ip_range': self._get_ip_range(self.ip_addr),
1141 }
1142
1143 def __unicode__(self):
1144 return u"<%s('user_id:%s=>%s')>" % (self.__class__.__name__,
1145 self.user_id, self.ip_addr)
1146
1147
1148 class UserSshKeys(Base, BaseModel):
1149 __tablename__ = 'user_ssh_keys'
1150 __table_args__ = (
1151 Index('usk_ssh_key_fingerprint_idx', 'ssh_key_fingerprint'),
1152 UniqueConstraint('ssh_key_fingerprint'),
1153
1154 {'extend_existing': True, 'mysql_engine': 'InnoDB',
1155 'mysql_charset': 'utf8', 'sqlite_autoincrement': True}
1156 )
1157 __mapper_args__ = {}
1158
1159 ssh_key_id = Column('ssh_key_id', Integer(), nullable=False, unique=True, default=None, primary_key=True)
1160 ssh_key_data = Column('ssh_key_data', String(10240), nullable=False, unique=None, default=None)
1161 ssh_key_fingerprint = Column('ssh_key_fingerprint', String(1024), nullable=False, unique=None, default=None)
1162
1163 description = Column('description', UnicodeText().with_variant(UnicodeText(1024), 'mysql'))
1164
1165 created_on = Column('created_on', DateTime(timezone=False), nullable=False, default=datetime.datetime.now)
1166 accessed_on = Column('accessed_on', DateTime(timezone=False), nullable=True, default=None)
1167 user_id = Column('user_id', Integer(), ForeignKey('users.user_id'), nullable=True, unique=None, default=None)
1168
1169 user = relationship('User', lazy='joined')
1170
1171 def __json__(self):
1172 data = {
1173 'ssh_fingerprint': self.ssh_key_fingerprint,
1174 'description': self.description,
1175 'created_on': self.created_on
1176 }
1177 return data
1178
1179 def get_api_data(self):
1180 data = self.__json__()
1181 return data
1182
1183
1184 class UserLog(Base, BaseModel):
1185 __tablename__ = 'user_logs'
1186 __table_args__ = (
1187 {'extend_existing': True, 'mysql_engine': 'InnoDB',
1188 'mysql_charset': 'utf8', 'sqlite_autoincrement': True},
1189 )
1190 VERSION_1 = 'v1'
1191 VERSION_2 = 'v2'
1192 VERSIONS = [VERSION_1, VERSION_2]
1193
1194 user_log_id = Column("user_log_id", Integer(), nullable=False, unique=True, default=None, primary_key=True)
1195 user_id = Column("user_id", Integer(), ForeignKey('users.user_id'), nullable=True, unique=None, default=None)
1196 username = Column("username", String(255), nullable=True, unique=None, default=None)
1197 repository_id = Column("repository_id", Integer(), ForeignKey('repositories.repo_id'), nullable=True)
1198 repository_name = Column("repository_name", String(255), nullable=True, unique=None, default=None)
1199 user_ip = Column("user_ip", String(255), nullable=True, unique=None, default=None)
1200 action = Column("action", Text().with_variant(Text(1200000), 'mysql'), nullable=True, unique=None, default=None)
1201 action_date = Column("action_date", DateTime(timezone=False), nullable=True, unique=None, default=None)
1202
1203 version = Column("version", String(255), nullable=True, default=VERSION_1)
1204 user_data = Column('user_data_json', MutationObj.as_mutable(JsonType(dialect_map=dict(mysql=UnicodeText(16384)))))
1205 action_data = Column('action_data_json', MutationObj.as_mutable(JsonType(dialect_map=dict(mysql=UnicodeText(16384)))))
1206
1207 def __unicode__(self):
1208 return u"<%s('id:%s:%s')>" % (
1209 self.__class__.__name__, self.repository_name, self.action)
1210
1211 def __json__(self):
1212 return {
1213 'user_id': self.user_id,
1214 'username': self.username,
1215 'repository_id': self.repository_id,
1216 'repository_name': self.repository_name,
1217 'user_ip': self.user_ip,
1218 'action_date': self.action_date,
1219 'action': self.action,
1220 }
1221
1222 @property
1223 def action_as_day(self):
1224 return datetime.date(*self.action_date.timetuple()[:3])
1225
1226 user = relationship('User')
1227 repository = relationship('Repository', cascade='')
1228
1229
1230 class UserGroup(Base, BaseModel):
1231 __tablename__ = 'users_groups'
1232 __table_args__ = (
1233 {'extend_existing': True, 'mysql_engine': 'InnoDB',
1234 'mysql_charset': 'utf8', 'sqlite_autoincrement': True},
1235 )
1236
1237 users_group_id = Column("users_group_id", Integer(), nullable=False, unique=True, default=None, primary_key=True)
1238 users_group_name = Column("users_group_name", String(255), nullable=False, unique=True, default=None)
1239 user_group_description = Column("user_group_description", String(10000), nullable=True, unique=None, default=None)
1240 users_group_active = Column("users_group_active", Boolean(), nullable=True, unique=None, default=None)
1241 inherit_default_permissions = Column("users_group_inherit_default_permissions", Boolean(), nullable=False, unique=None, default=True)
1242 user_id = Column("user_id", Integer(), ForeignKey('users.user_id'), nullable=False, unique=False, default=None)
1243 created_on = Column('created_on', DateTime(timezone=False), nullable=False, default=datetime.datetime.now)
1244 _group_data = Column("group_data", LargeBinary(), nullable=True) # JSON data
1245
1246 members = relationship('UserGroupMember', cascade="all, delete, delete-orphan", lazy="joined")
1247 users_group_to_perm = relationship('UserGroupToPerm', cascade='all')
1248 users_group_repo_to_perm = relationship('UserGroupRepoToPerm', cascade='all')
1249 users_group_repo_group_to_perm = relationship('UserGroupRepoGroupToPerm', cascade='all')
1250 user_user_group_to_perm = relationship('UserUserGroupToPerm', cascade='all')
1251 user_group_user_group_to_perm = relationship('UserGroupUserGroupToPerm ', primaryjoin="UserGroupUserGroupToPerm.target_user_group_id==UserGroup.users_group_id", cascade='all')
1252
1253 user = relationship('User', primaryjoin="User.user_id==UserGroup.user_id")
1254
1255 @classmethod
1256 def _load_group_data(cls, column):
1257 if not column:
1258 return {}
1259
1260 try:
1261 return json.loads(column) or {}
1262 except TypeError:
1263 return {}
1264
1265 @hybrid_property
1266 def description_safe(self):
1267 from rhodecode.lib import helpers as h
1268 return h.escape(self.description)
1269
1270 @hybrid_property
1271 def group_data(self):
1272 return self._load_group_data(self._group_data)
1273
1274 @group_data.expression
1275 def group_data(self, **kwargs):
1276 return self._group_data
1277
1278 @group_data.setter
1279 def group_data(self, val):
1280 try:
1281 self._group_data = json.dumps(val)
1282 except Exception:
1283 log.error(traceback.format_exc())
1284
1285 def __unicode__(self):
1286 return u"<%s('id:%s:%s')>" % (self.__class__.__name__,
1287 self.users_group_id,
1288 self.users_group_name)
1289
1290 @classmethod
1291 def get_by_group_name(cls, group_name, cache=False,
1292 case_insensitive=False):
1293 if case_insensitive:
1294 q = cls.query().filter(func.lower(cls.users_group_name) ==
1295 func.lower(group_name))
1296
1297 else:
1298 q = cls.query().filter(cls.users_group_name == group_name)
1299 if cache:
1300 q = q.options(
1301 FromCache("sql_cache_short", "get_group_%s" % _hash_key(group_name)))
1302 return q.scalar()
1303
1304 @classmethod
1305 def get(cls, user_group_id, cache=False):
1306 user_group = cls.query()
1307 if cache:
1308 user_group = user_group.options(
1309 FromCache("sql_cache_short", "get_users_group_%s" % user_group_id))
1310 return user_group.get(user_group_id)
1311
1312 def permissions(self, with_admins=True, with_owner=True):
1313 q = UserUserGroupToPerm.query().filter(UserUserGroupToPerm.user_group == self)
1314 q = q.options(joinedload(UserUserGroupToPerm.user_group),
1315 joinedload(UserUserGroupToPerm.user),
1316 joinedload(UserUserGroupToPerm.permission),)
1317
1318 # get owners and admins and permissions. We do a trick of re-writing
1319 # objects from sqlalchemy to named-tuples due to sqlalchemy session
1320 # has a global reference and changing one object propagates to all
1321 # others. This means if admin is also an owner admin_row that change
1322 # would propagate to both objects
1323 perm_rows = []
1324 for _usr in q.all():
1325 usr = AttributeDict(_usr.user.get_dict())
1326 usr.permission = _usr.permission.permission_name
1327 perm_rows.append(usr)
1328
1329 # filter the perm rows by 'default' first and then sort them by
1330 # admin,write,read,none permissions sorted again alphabetically in
1331 # each group
1332 perm_rows = sorted(perm_rows, key=display_sort)
1333
1334 _admin_perm = 'usergroup.admin'
1335 owner_row = []
1336 if with_owner:
1337 usr = AttributeDict(self.user.get_dict())
1338 usr.owner_row = True
1339 usr.permission = _admin_perm
1340 owner_row.append(usr)
1341
1342 super_admin_rows = []
1343 if with_admins:
1344 for usr in User.get_all_super_admins():
1345 # if this admin is also owner, don't double the record
1346 if usr.user_id == owner_row[0].user_id:
1347 owner_row[0].admin_row = True
1348 else:
1349 usr = AttributeDict(usr.get_dict())
1350 usr.admin_row = True
1351 usr.permission = _admin_perm
1352 super_admin_rows.append(usr)
1353
1354 return super_admin_rows + owner_row + perm_rows
1355
1356 def permission_user_groups(self):
1357 q = UserGroupUserGroupToPerm.query().filter(UserGroupUserGroupToPerm.target_user_group == self)
1358 q = q.options(joinedload(UserGroupUserGroupToPerm.user_group),
1359 joinedload(UserGroupUserGroupToPerm.target_user_group),
1360 joinedload(UserGroupUserGroupToPerm.permission),)
1361
1362 perm_rows = []
1363 for _user_group in q.all():
1364 usr = AttributeDict(_user_group.user_group.get_dict())
1365 usr.permission = _user_group.permission.permission_name
1366 perm_rows.append(usr)
1367
1368 return perm_rows
1369
1370 def _get_default_perms(self, user_group, suffix=''):
1371 from rhodecode.model.permission import PermissionModel
1372 return PermissionModel().get_default_perms(user_group.users_group_to_perm, suffix)
1373
1374 def get_default_perms(self, suffix=''):
1375 return self._get_default_perms(self, suffix)
1376
1377 def get_api_data(self, with_group_members=True, include_secrets=False):
1378 """
1379 :param include_secrets: See :meth:`User.get_api_data`, this parameter is
1380 basically forwarded.
1381
1382 """
1383 user_group = self
1384 data = {
1385 'users_group_id': user_group.users_group_id,
1386 'group_name': user_group.users_group_name,
1387 'group_description': user_group.user_group_description,
1388 'active': user_group.users_group_active,
1389 'owner': user_group.user.username,
1390 'owner_email': user_group.user.email,
1391 }
1392
1393 if with_group_members:
1394 users = []
1395 for user in user_group.members:
1396 user = user.user
1397 users.append(user.get_api_data(include_secrets=include_secrets))
1398 data['users'] = users
1399
1400 return data
1401
1402
1403 class UserGroupMember(Base, BaseModel):
1404 __tablename__ = 'users_groups_members'
1405 __table_args__ = (
1406 {'extend_existing': True, 'mysql_engine': 'InnoDB',
1407 'mysql_charset': 'utf8', 'sqlite_autoincrement': True},
1408 )
1409
1410 users_group_member_id = Column("users_group_member_id", Integer(), nullable=False, unique=True, default=None, primary_key=True)
1411 users_group_id = Column("users_group_id", Integer(), ForeignKey('users_groups.users_group_id'), nullable=False, unique=None, default=None)
1412 user_id = Column("user_id", Integer(), ForeignKey('users.user_id'), nullable=False, unique=None, default=None)
1413
1414 user = relationship('User', lazy='joined')
1415 users_group = relationship('UserGroup')
1416
1417 def __init__(self, gr_id='', u_id=''):
1418 self.users_group_id = gr_id
1419 self.user_id = u_id
1420
1421
1422 class RepositoryField(Base, BaseModel):
1423 __tablename__ = 'repositories_fields'
1424 __table_args__ = (
1425 UniqueConstraint('repository_id', 'field_key'), # no-multi field
1426 {'extend_existing': True, 'mysql_engine': 'InnoDB',
1427 'mysql_charset': 'utf8', 'sqlite_autoincrement': True},
1428 )
1429 PREFIX = 'ex_' # prefix used in form to not conflict with already existing fields
1430
1431 repo_field_id = Column("repo_field_id", Integer(), nullable=False, unique=True, default=None, primary_key=True)
1432 repository_id = Column("repository_id", Integer(), ForeignKey('repositories.repo_id'), nullable=False, unique=None, default=None)
1433 field_key = Column("field_key", String(250))
1434 field_label = Column("field_label", String(1024), nullable=False)
1435 field_value = Column("field_value", String(10000), nullable=False)
1436 field_desc = Column("field_desc", String(1024), nullable=False)
1437 field_type = Column("field_type", String(255), nullable=False, unique=None)
1438 created_on = Column('created_on', DateTime(timezone=False), nullable=False, default=datetime.datetime.now)
1439
1440 repository = relationship('Repository')
1441
1442 @property
1443 def field_key_prefixed(self):
1444 return 'ex_%s' % self.field_key
1445
1446 @classmethod
1447 def un_prefix_key(cls, key):
1448 if key.startswith(cls.PREFIX):
1449 return key[len(cls.PREFIX):]
1450 return key
1451
1452 @classmethod
1453 def get_by_key_name(cls, key, repo):
1454 row = cls.query()\
1455 .filter(cls.repository == repo)\
1456 .filter(cls.field_key == key).scalar()
1457 return row
1458
1459
1460 class Repository(Base, BaseModel):
1461 __tablename__ = 'repositories'
1462 __table_args__ = (
1463 Index('r_repo_name_idx', 'repo_name', mysql_length=255),
1464 {'extend_existing': True, 'mysql_engine': 'InnoDB',
1465 'mysql_charset': 'utf8', 'sqlite_autoincrement': True},
1466 )
1467 DEFAULT_CLONE_URI = '{scheme}://{user}@{netloc}/{repo}'
1468 DEFAULT_CLONE_URI_ID = '{scheme}://{user}@{netloc}/_{repoid}'
1469
1470 STATE_CREATED = 'repo_state_created'
1471 STATE_PENDING = 'repo_state_pending'
1472 STATE_ERROR = 'repo_state_error'
1473
1474 LOCK_AUTOMATIC = 'lock_auto'
1475 LOCK_API = 'lock_api'
1476 LOCK_WEB = 'lock_web'
1477 LOCK_PULL = 'lock_pull'
1478
1479 NAME_SEP = URL_SEP
1480
1481 repo_id = Column(
1482 "repo_id", Integer(), nullable=False, unique=True, default=None,
1483 primary_key=True)
1484 _repo_name = Column(
1485 "repo_name", Text(), nullable=False, default=None)
1486 _repo_name_hash = Column(
1487 "repo_name_hash", String(255), nullable=False, unique=True)
1488 repo_state = Column("repo_state", String(255), nullable=True)
1489
1490 clone_uri = Column(
1491 "clone_uri", EncryptedTextValue(), nullable=True, unique=False,
1492 default=None)
1493 repo_type = Column(
1494 "repo_type", String(255), nullable=False, unique=False, default=None)
1495 user_id = Column(
1496 "user_id", Integer(), ForeignKey('users.user_id'), nullable=False,
1497 unique=False, default=None)
1498 private = Column(
1499 "private", Boolean(), nullable=True, unique=None, default=None)
1500 enable_statistics = Column(
1501 "statistics", Boolean(), nullable=True, unique=None, default=True)
1502 enable_downloads = Column(
1503 "downloads", Boolean(), nullable=True, unique=None, default=True)
1504 description = Column(
1505 "description", String(10000), nullable=True, unique=None, default=None)
1506 created_on = Column(
1507 'created_on', DateTime(timezone=False), nullable=True, unique=None,
1508 default=datetime.datetime.now)
1509 updated_on = Column(
1510 'updated_on', DateTime(timezone=False), nullable=True, unique=None,
1511 default=datetime.datetime.now)
1512 _landing_revision = Column(
1513 "landing_revision", String(255), nullable=False, unique=False,
1514 default=None)
1515 enable_locking = Column(
1516 "enable_locking", Boolean(), nullable=False, unique=None,
1517 default=False)
1518 _locked = Column(
1519 "locked", String(255), nullable=True, unique=False, default=None)
1520 _changeset_cache = Column(
1521 "changeset_cache", LargeBinary(), nullable=True) # JSON data
1522
1523 fork_id = Column(
1524 "fork_id", Integer(), ForeignKey('repositories.repo_id'),
1525 nullable=True, unique=False, default=None)
1526 group_id = Column(
1527 "group_id", Integer(), ForeignKey('groups.group_id'), nullable=True,
1528 unique=False, default=None)
1529
1530 user = relationship('User', lazy='joined')
1531 fork = relationship('Repository', remote_side=repo_id, lazy='joined')
1532 group = relationship('RepoGroup', lazy='joined')
1533 repo_to_perm = relationship(
1534 'UserRepoToPerm', cascade='all',
1535 order_by='UserRepoToPerm.repo_to_perm_id')
1536 users_group_to_perm = relationship('UserGroupRepoToPerm', cascade='all')
1537 stats = relationship('Statistics', cascade='all', uselist=False)
1538
1539 followers = relationship(
1540 'UserFollowing',
1541 primaryjoin='UserFollowing.follows_repo_id==Repository.repo_id',
1542 cascade='all')
1543 extra_fields = relationship(
1544 'RepositoryField', cascade="all, delete, delete-orphan")
1545 logs = relationship('UserLog')
1546 comments = relationship(
1547 'ChangesetComment', cascade="all, delete, delete-orphan")
1548 pull_requests_source = relationship(
1549 'PullRequest',
1550 primaryjoin='PullRequest.source_repo_id==Repository.repo_id',
1551 cascade="all, delete, delete-orphan")
1552 pull_requests_target = relationship(
1553 'PullRequest',
1554 primaryjoin='PullRequest.target_repo_id==Repository.repo_id',
1555 cascade="all, delete, delete-orphan")
1556 ui = relationship('RepoRhodeCodeUi', cascade="all")
1557 settings = relationship('RepoRhodeCodeSetting', cascade="all")
1558 integrations = relationship('Integration',
1559 cascade="all, delete, delete-orphan")
1560
1561 def __unicode__(self):
1562 return u"<%s('%s:%s')>" % (self.__class__.__name__, self.repo_id,
1563 safe_unicode(self.repo_name))
1564
1565 @hybrid_property
1566 def description_safe(self):
1567 from rhodecode.lib import helpers as h
1568 return h.escape(self.description)
1569
1570 @hybrid_property
1571 def landing_rev(self):
1572 # always should return [rev_type, rev]
1573 if self._landing_revision:
1574 _rev_info = self._landing_revision.split(':')
1575 if len(_rev_info) < 2:
1576 _rev_info.insert(0, 'rev')
1577 return [_rev_info[0], _rev_info[1]]
1578 return [None, None]
1579
1580 @landing_rev.setter
1581 def landing_rev(self, val):
1582 if ':' not in val:
1583 raise ValueError('value must be delimited with `:` and consist '
1584 'of <rev_type>:<rev>, got %s instead' % val)
1585 self._landing_revision = val
1586
1587 @hybrid_property
1588 def locked(self):
1589 if self._locked:
1590 user_id, timelocked, reason = self._locked.split(':')
1591 lock_values = int(user_id), timelocked, reason
1592 else:
1593 lock_values = [None, None, None]
1594 return lock_values
1595
1596 @locked.setter
1597 def locked(self, val):
1598 if val and isinstance(val, (list, tuple)):
1599 self._locked = ':'.join(map(str, val))
1600 else:
1601 self._locked = None
1602
1603 @hybrid_property
1604 def changeset_cache(self):
1605 from rhodecode.lib.vcs.backends.base import EmptyCommit
1606 dummy = EmptyCommit().__json__()
1607 if not self._changeset_cache:
1608 return dummy
1609 try:
1610 return json.loads(self._changeset_cache)
1611 except TypeError:
1612 return dummy
1613 except Exception:
1614 log.error(traceback.format_exc())
1615 return dummy
1616
1617 @changeset_cache.setter
1618 def changeset_cache(self, val):
1619 try:
1620 self._changeset_cache = json.dumps(val)
1621 except Exception:
1622 log.error(traceback.format_exc())
1623
1624 @hybrid_property
1625 def repo_name(self):
1626 return self._repo_name
1627
1628 @repo_name.setter
1629 def repo_name(self, value):
1630 self._repo_name = value
1631 self._repo_name_hash = hashlib.sha1(safe_str(value)).hexdigest()
1632
1633 @classmethod
1634 def normalize_repo_name(cls, repo_name):
1635 """
1636 Normalizes os specific repo_name to the format internally stored inside
1637 database using URL_SEP
1638
1639 :param cls:
1640 :param repo_name:
1641 """
1642 return cls.NAME_SEP.join(repo_name.split(os.sep))
1643
1644 @classmethod
1645 def get_by_repo_name(cls, repo_name, cache=False, identity_cache=False):
1646 session = Session()
1647 q = session.query(cls).filter(cls.repo_name == repo_name)
1648
1649 if cache:
1650 if identity_cache:
1651 val = cls.identity_cache(session, 'repo_name', repo_name)
1652 if val:
1653 return val
1654 else:
1655 cache_key = "get_repo_by_name_%s" % _hash_key(repo_name)
1656 q = q.options(
1657 FromCache("sql_cache_short", cache_key))
1658
1659 return q.scalar()
1660
1661 @classmethod
1662 def get_by_full_path(cls, repo_full_path):
1663 repo_name = repo_full_path.split(cls.base_path(), 1)[-1]
1664 repo_name = cls.normalize_repo_name(repo_name)
1665 return cls.get_by_repo_name(repo_name.strip(URL_SEP))
1666
1667 @classmethod
1668 def get_repo_forks(cls, repo_id):
1669 return cls.query().filter(Repository.fork_id == repo_id)
1670
1671 @classmethod
1672 def base_path(cls):
1673 """
1674 Returns base path when all repos are stored
1675
1676 :param cls:
1677 """
1678 q = Session().query(RhodeCodeUi)\
1679 .filter(RhodeCodeUi.ui_key == cls.NAME_SEP)
1680 q = q.options(FromCache("sql_cache_short", "repository_repo_path"))
1681 return q.one().ui_value
1682
1683 @classmethod
1684 def is_valid(cls, repo_name):
1685 """
1686 returns True if given repo name is a valid filesystem repository
1687
1688 :param cls:
1689 :param repo_name:
1690 """
1691 from rhodecode.lib.utils import is_valid_repo
1692
1693 return is_valid_repo(repo_name, cls.base_path())
1694
1695 @classmethod
1696 def get_all_repos(cls, user_id=Optional(None), group_id=Optional(None),
1697 case_insensitive=True):
1698 q = Repository.query()
1699
1700 if not isinstance(user_id, Optional):
1701 q = q.filter(Repository.user_id == user_id)
1702
1703 if not isinstance(group_id, Optional):
1704 q = q.filter(Repository.group_id == group_id)
1705
1706 if case_insensitive:
1707 q = q.order_by(func.lower(Repository.repo_name))
1708 else:
1709 q = q.order_by(Repository.repo_name)
1710 return q.all()
1711
1712 @property
1713 def forks(self):
1714 """
1715 Return forks of this repo
1716 """
1717 return Repository.get_repo_forks(self.repo_id)
1718
1719 @property
1720 def parent(self):
1721 """
1722 Returns fork parent
1723 """
1724 return self.fork
1725
1726 @property
1727 def just_name(self):
1728 return self.repo_name.split(self.NAME_SEP)[-1]
1729
1730 @property
1731 def groups_with_parents(self):
1732 groups = []
1733 if self.group is None:
1734 return groups
1735
1736 cur_gr = self.group
1737 groups.insert(0, cur_gr)
1738 while 1:
1739 gr = getattr(cur_gr, 'parent_group', None)
1740 cur_gr = cur_gr.parent_group
1741 if gr is None:
1742 break
1743 groups.insert(0, gr)
1744
1745 return groups
1746
1747 @property
1748 def groups_and_repo(self):
1749 return self.groups_with_parents, self
1750
1751 @LazyProperty
1752 def repo_path(self):
1753 """
1754 Returns base full path for that repository means where it actually
1755 exists on a filesystem
1756 """
1757 q = Session().query(RhodeCodeUi).filter(
1758 RhodeCodeUi.ui_key == self.NAME_SEP)
1759 q = q.options(FromCache("sql_cache_short", "repository_repo_path"))
1760 return q.one().ui_value
1761
1762 @property
1763 def repo_full_path(self):
1764 p = [self.repo_path]
1765 # we need to split the name by / since this is how we store the
1766 # names in the database, but that eventually needs to be converted
1767 # into a valid system path
1768 p += self.repo_name.split(self.NAME_SEP)
1769 return os.path.join(*map(safe_unicode, p))
1770
1771 @property
1772 def cache_keys(self):
1773 """
1774 Returns associated cache keys for that repo
1775 """
1776 return CacheKey.query()\
1777 .filter(CacheKey.cache_args == self.repo_name)\
1778 .order_by(CacheKey.cache_key)\
1779 .all()
1780
1781 def get_new_name(self, repo_name):
1782 """
1783 returns new full repository name based on assigned group and new new
1784
1785 :param group_name:
1786 """
1787 path_prefix = self.group.full_path_splitted if self.group else []
1788 return self.NAME_SEP.join(path_prefix + [repo_name])
1789
1790 @property
1791 def _config(self):
1792 """
1793 Returns db based config object.
1794 """
1795 from rhodecode.lib.utils import make_db_config
1796 return make_db_config(clear_session=False, repo=self)
1797
1798 def permissions(self, with_admins=True, with_owner=True):
1799 q = UserRepoToPerm.query().filter(UserRepoToPerm.repository == self)
1800 q = q.options(joinedload(UserRepoToPerm.repository),
1801 joinedload(UserRepoToPerm.user),
1802 joinedload(UserRepoToPerm.permission),)
1803
1804 # get owners and admins and permissions. We do a trick of re-writing
1805 # objects from sqlalchemy to named-tuples due to sqlalchemy session
1806 # has a global reference and changing one object propagates to all
1807 # others. This means if admin is also an owner admin_row that change
1808 # would propagate to both objects
1809 perm_rows = []
1810 for _usr in q.all():
1811 usr = AttributeDict(_usr.user.get_dict())
1812 usr.permission = _usr.permission.permission_name
1813 perm_rows.append(usr)
1814
1815 # filter the perm rows by 'default' first and then sort them by
1816 # admin,write,read,none permissions sorted again alphabetically in
1817 # each group
1818 perm_rows = sorted(perm_rows, key=display_sort)
1819
1820 _admin_perm = 'repository.admin'
1821 owner_row = []
1822 if with_owner:
1823 usr = AttributeDict(self.user.get_dict())
1824 usr.owner_row = True
1825 usr.permission = _admin_perm
1826 owner_row.append(usr)
1827
1828 super_admin_rows = []
1829 if with_admins:
1830 for usr in User.get_all_super_admins():
1831 # if this admin is also owner, don't double the record
1832 if usr.user_id == owner_row[0].user_id:
1833 owner_row[0].admin_row = True
1834 else:
1835 usr = AttributeDict(usr.get_dict())
1836 usr.admin_row = True
1837 usr.permission = _admin_perm
1838 super_admin_rows.append(usr)
1839
1840 return super_admin_rows + owner_row + perm_rows
1841
1842 def permission_user_groups(self):
1843 q = UserGroupRepoToPerm.query().filter(
1844 UserGroupRepoToPerm.repository == self)
1845 q = q.options(joinedload(UserGroupRepoToPerm.repository),
1846 joinedload(UserGroupRepoToPerm.users_group),
1847 joinedload(UserGroupRepoToPerm.permission),)
1848
1849 perm_rows = []
1850 for _user_group in q.all():
1851 usr = AttributeDict(_user_group.users_group.get_dict())
1852 usr.permission = _user_group.permission.permission_name
1853 perm_rows.append(usr)
1854
1855 return perm_rows
1856
1857 def get_api_data(self, include_secrets=False):
1858 """
1859 Common function for generating repo api data
1860
1861 :param include_secrets: See :meth:`User.get_api_data`.
1862
1863 """
1864 # TODO: mikhail: Here there is an anti-pattern, we probably need to
1865 # move this methods on models level.
1866 from rhodecode.model.settings import SettingsModel
1867 from rhodecode.model.repo import RepoModel
1868
1869 repo = self
1870 _user_id, _time, _reason = self.locked
1871
1872 data = {
1873 'repo_id': repo.repo_id,
1874 'repo_name': repo.repo_name,
1875 'repo_type': repo.repo_type,
1876 'clone_uri': repo.clone_uri or '',
1877 'url': RepoModel().get_url(self),
1878 'private': repo.private,
1879 'created_on': repo.created_on,
1880 'description': repo.description_safe,
1881 'landing_rev': repo.landing_rev,
1882 'owner': repo.user.username,
1883 'fork_of': repo.fork.repo_name if repo.fork else None,
1884 'fork_of_id': repo.fork.repo_id if repo.fork else None,
1885 'enable_statistics': repo.enable_statistics,
1886 'enable_locking': repo.enable_locking,
1887 'enable_downloads': repo.enable_downloads,
1888 'last_changeset': repo.changeset_cache,
1889 'locked_by': User.get(_user_id).get_api_data(
1890 include_secrets=include_secrets) if _user_id else None,
1891 'locked_date': time_to_datetime(_time) if _time else None,
1892 'lock_reason': _reason if _reason else None,
1893 }
1894
1895 # TODO: mikhail: should be per-repo settings here
1896 rc_config = SettingsModel().get_all_settings()
1897 repository_fields = str2bool(
1898 rc_config.get('rhodecode_repository_fields'))
1899 if repository_fields:
1900 for f in self.extra_fields:
1901 data[f.field_key_prefixed] = f.field_value
1902
1903 return data
1904
1905 @classmethod
1906 def lock(cls, repo, user_id, lock_time=None, lock_reason=None):
1907 if not lock_time:
1908 lock_time = time.time()
1909 if not lock_reason:
1910 lock_reason = cls.LOCK_AUTOMATIC
1911 repo.locked = [user_id, lock_time, lock_reason]
1912 Session().add(repo)
1913 Session().commit()
1914
1915 @classmethod
1916 def unlock(cls, repo):
1917 repo.locked = None
1918 Session().add(repo)
1919 Session().commit()
1920
1921 @classmethod
1922 def getlock(cls, repo):
1923 return repo.locked
1924
1925 def is_user_lock(self, user_id):
1926 if self.lock[0]:
1927 lock_user_id = safe_int(self.lock[0])
1928 user_id = safe_int(user_id)
1929 # both are ints, and they are equal
1930 return all([lock_user_id, user_id]) and lock_user_id == user_id
1931
1932 return False
1933
1934 def get_locking_state(self, action, user_id, only_when_enabled=True):
1935 """
1936 Checks locking on this repository, if locking is enabled and lock is
1937 present returns a tuple of make_lock, locked, locked_by.
1938 make_lock can have 3 states None (do nothing) True, make lock
1939 False release lock, This value is later propagated to hooks, which
1940 do the locking. Think about this as signals passed to hooks what to do.
1941
1942 """
1943 # TODO: johbo: This is part of the business logic and should be moved
1944 # into the RepositoryModel.
1945
1946 if action not in ('push', 'pull'):
1947 raise ValueError("Invalid action value: %s" % repr(action))
1948
1949 # defines if locked error should be thrown to user
1950 currently_locked = False
1951 # defines if new lock should be made, tri-state
1952 make_lock = None
1953 repo = self
1954 user = User.get(user_id)
1955
1956 lock_info = repo.locked
1957
1958 if repo and (repo.enable_locking or not only_when_enabled):
1959 if action == 'push':
1960 # check if it's already locked !, if it is compare users
1961 locked_by_user_id = lock_info[0]
1962 if user.user_id == locked_by_user_id:
1963 log.debug(
1964 'Got `push` action from user %s, now unlocking', user)
1965 # unlock if we have push from user who locked
1966 make_lock = False
1967 else:
1968 # we're not the same user who locked, ban with
1969 # code defined in settings (default is 423 HTTP Locked) !
1970 log.debug('Repo %s is currently locked by %s', repo, user)
1971 currently_locked = True
1972 elif action == 'pull':
1973 # [0] user [1] date
1974 if lock_info[0] and lock_info[1]:
1975 log.debug('Repo %s is currently locked by %s', repo, user)
1976 currently_locked = True
1977 else:
1978 log.debug('Setting lock on repo %s by %s', repo, user)
1979 make_lock = True
1980
1981 else:
1982 log.debug('Repository %s do not have locking enabled', repo)
1983
1984 log.debug('FINAL locking values make_lock:%s,locked:%s,locked_by:%s',
1985 make_lock, currently_locked, lock_info)
1986
1987 from rhodecode.lib.auth import HasRepoPermissionAny
1988 perm_check = HasRepoPermissionAny('repository.write', 'repository.admin')
1989 if make_lock and not perm_check(repo_name=repo.repo_name, user=user):
1990 # if we don't have at least write permission we cannot make a lock
1991 log.debug('lock state reset back to FALSE due to lack '
1992 'of at least read permission')
1993 make_lock = False
1994
1995 return make_lock, currently_locked, lock_info
1996
1997 @property
1998 def last_db_change(self):
1999 return self.updated_on
2000
2001 @property
2002 def clone_uri_hidden(self):
2003 clone_uri = self.clone_uri
2004 if clone_uri:
2005 import urlobject
2006 url_obj = urlobject.URLObject(cleaned_uri(clone_uri))
2007 if url_obj.password:
2008 clone_uri = url_obj.with_password('*****')
2009 return clone_uri
2010
2011 def clone_url(self, **override):
2012 from rhodecode.model.settings import SettingsModel
2013
2014 uri_tmpl = None
2015 if 'with_id' in override:
2016 uri_tmpl = self.DEFAULT_CLONE_URI_ID
2017 del override['with_id']
2018
2019 if 'uri_tmpl' in override:
2020 uri_tmpl = override['uri_tmpl']
2021 del override['uri_tmpl']
2022
2023 # we didn't override our tmpl from **overrides
2024 if not uri_tmpl:
2025 rc_config = SettingsModel().get_all_settings(cache=True)
2026 uri_tmpl = rc_config.get(
2027 'rhodecode_clone_uri_tmpl') or self.DEFAULT_CLONE_URI
2028
2029 request = get_current_request()
2030 return get_clone_url(request=request,
2031 uri_tmpl=uri_tmpl,
2032 repo_name=self.repo_name,
2033 repo_id=self.repo_id, **override)
2034
2035 def set_state(self, state):
2036 self.repo_state = state
2037 Session().add(self)
2038 #==========================================================================
2039 # SCM PROPERTIES
2040 #==========================================================================
2041
2042 def get_commit(self, commit_id=None, commit_idx=None, pre_load=None):
2043 return get_commit_safe(
2044 self.scm_instance(), commit_id, commit_idx, pre_load=pre_load)
2045
2046 def get_changeset(self, rev=None, pre_load=None):
2047 warnings.warn("Use get_commit", DeprecationWarning)
2048 commit_id = None
2049 commit_idx = None
2050 if isinstance(rev, basestring):
2051 commit_id = rev
2052 else:
2053 commit_idx = rev
2054 return self.get_commit(commit_id=commit_id, commit_idx=commit_idx,
2055 pre_load=pre_load)
2056
2057 def get_landing_commit(self):
2058 """
2059 Returns landing commit, or if that doesn't exist returns the tip
2060 """
2061 _rev_type, _rev = self.landing_rev
2062 commit = self.get_commit(_rev)
2063 if isinstance(commit, EmptyCommit):
2064 return self.get_commit()
2065 return commit
2066
2067 def update_commit_cache(self, cs_cache=None, config=None):
2068 """
2069 Update cache of last changeset for repository, keys should be::
2070
2071 short_id
2072 raw_id
2073 revision
2074 parents
2075 message
2076 date
2077 author
2078
2079 :param cs_cache:
2080 """
2081 from rhodecode.lib.vcs.backends.base import BaseChangeset
2082 if cs_cache is None:
2083 # use no-cache version here
2084 scm_repo = self.scm_instance(cache=False, config=config)
2085 if scm_repo:
2086 cs_cache = scm_repo.get_commit(
2087 pre_load=["author", "date", "message", "parents"])
2088 else:
2089 cs_cache = EmptyCommit()
2090
2091 if isinstance(cs_cache, BaseChangeset):
2092 cs_cache = cs_cache.__json__()
2093
2094 def is_outdated(new_cs_cache):
2095 if (new_cs_cache['raw_id'] != self.changeset_cache['raw_id'] or
2096 new_cs_cache['revision'] != self.changeset_cache['revision']):
2097 return True
2098 return False
2099
2100 # check if we have maybe already latest cached revision
2101 if is_outdated(cs_cache) or not self.changeset_cache:
2102 _default = datetime.datetime.fromtimestamp(0)
2103 last_change = cs_cache.get('date') or _default
2104 log.debug('updated repo %s with new cs cache %s',
2105 self.repo_name, cs_cache)
2106 self.updated_on = last_change
2107 self.changeset_cache = cs_cache
2108 Session().add(self)
2109 Session().commit()
2110 else:
2111 log.debug('Skipping update_commit_cache for repo:`%s` '
2112 'commit already with latest changes', self.repo_name)
2113
2114 @property
2115 def tip(self):
2116 return self.get_commit('tip')
2117
2118 @property
2119 def author(self):
2120 return self.tip.author
2121
2122 @property
2123 def last_change(self):
2124 return self.scm_instance().last_change
2125
2126 def get_comments(self, revisions=None):
2127 """
2128 Returns comments for this repository grouped by revisions
2129
2130 :param revisions: filter query by revisions only
2131 """
2132 cmts = ChangesetComment.query()\
2133 .filter(ChangesetComment.repo == self)
2134 if revisions:
2135 cmts = cmts.filter(ChangesetComment.revision.in_(revisions))
2136 grouped = collections.defaultdict(list)
2137 for cmt in cmts.all():
2138 grouped[cmt.revision].append(cmt)
2139 return grouped
2140
2141 def statuses(self, revisions=None):
2142 """
2143 Returns statuses for this repository
2144
2145 :param revisions: list of revisions to get statuses for
2146 """
2147 statuses = ChangesetStatus.query()\
2148 .filter(ChangesetStatus.repo == self)\
2149 .filter(ChangesetStatus.version == 0)
2150
2151 if revisions:
2152 # Try doing the filtering in chunks to avoid hitting limits
2153 size = 500
2154 status_results = []
2155 for chunk in xrange(0, len(revisions), size):
2156 status_results += statuses.filter(
2157 ChangesetStatus.revision.in_(
2158 revisions[chunk: chunk+size])
2159 ).all()
2160 else:
2161 status_results = statuses.all()
2162
2163 grouped = {}
2164
2165 # maybe we have open new pullrequest without a status?
2166 stat = ChangesetStatus.STATUS_UNDER_REVIEW
2167 status_lbl = ChangesetStatus.get_status_lbl(stat)
2168 for pr in PullRequest.query().filter(PullRequest.source_repo == self).all():
2169 for rev in pr.revisions:
2170 pr_id = pr.pull_request_id
2171 pr_repo = pr.target_repo.repo_name
2172 grouped[rev] = [stat, status_lbl, pr_id, pr_repo]
2173
2174 for stat in status_results:
2175 pr_id = pr_repo = None
2176 if stat.pull_request:
2177 pr_id = stat.pull_request.pull_request_id
2178 pr_repo = stat.pull_request.target_repo.repo_name
2179 grouped[stat.revision] = [str(stat.status), stat.status_lbl,
2180 pr_id, pr_repo]
2181 return grouped
2182
2183 # ==========================================================================
2184 # SCM CACHE INSTANCE
2185 # ==========================================================================
2186
2187 def scm_instance(self, **kwargs):
2188 import rhodecode
2189
2190 # Passing a config will not hit the cache currently only used
2191 # for repo2dbmapper
2192 config = kwargs.pop('config', None)
2193 cache = kwargs.pop('cache', None)
2194 full_cache = str2bool(rhodecode.CONFIG.get('vcs_full_cache'))
2195 # if cache is NOT defined use default global, else we have a full
2196 # control over cache behaviour
2197 if cache is None and full_cache and not config:
2198 return self._get_instance_cached()
2199 return self._get_instance(cache=bool(cache), config=config)
2200
2201 def _get_instance_cached(self):
2202 @cache_region('long_term')
2203 def _get_repo(cache_key):
2204 return self._get_instance()
2205
2206 invalidator_context = CacheKey.repo_context_cache(
2207 _get_repo, self.repo_name, None, thread_scoped=True)
2208
2209 with invalidator_context as context:
2210 context.invalidate()
2211 repo = context.compute()
2212
2213 return repo
2214
2215 def _get_instance(self, cache=True, config=None):
2216 config = config or self._config
2217 custom_wire = {
2218 'cache': cache # controls the vcs.remote cache
2219 }
2220 repo = get_vcs_instance(
2221 repo_path=safe_str(self.repo_full_path),
2222 config=config,
2223 with_wire=custom_wire,
2224 create=False,
2225 _vcs_alias=self.repo_type)
2226
2227 return repo
2228
2229 def __json__(self):
2230 return {'landing_rev': self.landing_rev}
2231
2232 def get_dict(self):
2233
2234 # Since we transformed `repo_name` to a hybrid property, we need to
2235 # keep compatibility with the code which uses `repo_name` field.
2236
2237 result = super(Repository, self).get_dict()
2238 result['repo_name'] = result.pop('_repo_name', None)
2239 return result
2240
2241
2242 class RepoGroup(Base, BaseModel):
2243 __tablename__ = 'groups'
2244 __table_args__ = (
2245 UniqueConstraint('group_name', 'group_parent_id'),
2246 CheckConstraint('group_id != group_parent_id'),
2247 {'extend_existing': True, 'mysql_engine': 'InnoDB',
2248 'mysql_charset': 'utf8', 'sqlite_autoincrement': True},
2249 )
2250 __mapper_args__ = {'order_by': 'group_name'}
2251
2252 CHOICES_SEPARATOR = '/' # used to generate select2 choices for nested groups
2253
2254 group_id = Column("group_id", Integer(), nullable=False, unique=True, default=None, primary_key=True)
2255 group_name = Column("group_name", String(255), nullable=False, unique=True, default=None)
2256 group_parent_id = Column("group_parent_id", Integer(), ForeignKey('groups.group_id'), nullable=True, unique=None, default=None)
2257 group_description = Column("group_description", String(10000), nullable=True, unique=None, default=None)
2258 enable_locking = Column("enable_locking", Boolean(), nullable=False, unique=None, default=False)
2259 user_id = Column("user_id", Integer(), ForeignKey('users.user_id'), nullable=False, unique=False, default=None)
2260 created_on = Column('created_on', DateTime(timezone=False), nullable=False, default=datetime.datetime.now)
2261 updated_on = Column('updated_on', DateTime(timezone=False), nullable=True, unique=None, default=datetime.datetime.now)
2262 personal = Column('personal', Boolean(), nullable=True, unique=None, default=None)
2263
2264 repo_group_to_perm = relationship('UserRepoGroupToPerm', cascade='all', order_by='UserRepoGroupToPerm.group_to_perm_id')
2265 users_group_to_perm = relationship('UserGroupRepoGroupToPerm', cascade='all')
2266 parent_group = relationship('RepoGroup', remote_side=group_id)
2267 user = relationship('User')
2268 integrations = relationship('Integration',
2269 cascade="all, delete, delete-orphan")
2270
2271 def __init__(self, group_name='', parent_group=None):
2272 self.group_name = group_name
2273 self.parent_group = parent_group
2274
2275 def __unicode__(self):
2276 return u"<%s('id:%s:%s')>" % (
2277 self.__class__.__name__, self.group_id, self.group_name)
2278
2279 @hybrid_property
2280 def description_safe(self):
2281 from rhodecode.lib import helpers as h
2282 return h.escape(self.group_description)
2283
2284 @classmethod
2285 def _generate_choice(cls, repo_group):
2286 from webhelpers.html import literal as _literal
2287 _name = lambda k: _literal(cls.CHOICES_SEPARATOR.join(k))
2288 return repo_group.group_id, _name(repo_group.full_path_splitted)
2289
2290 @classmethod
2291 def groups_choices(cls, groups=None, show_empty_group=True):
2292 if not groups:
2293 groups = cls.query().all()
2294
2295 repo_groups = []
2296 if show_empty_group:
2297 repo_groups = [(-1, u'-- %s --' % _('No parent'))]
2298
2299 repo_groups.extend([cls._generate_choice(x) for x in groups])
2300
2301 repo_groups = sorted(
2302 repo_groups, key=lambda t: t[1].split(cls.CHOICES_SEPARATOR)[0])
2303 return repo_groups
2304
2305 @classmethod
2306 def url_sep(cls):
2307 return URL_SEP
2308
2309 @classmethod
2310 def get_by_group_name(cls, group_name, cache=False, case_insensitive=False):
2311 if case_insensitive:
2312 gr = cls.query().filter(func.lower(cls.group_name)
2313 == func.lower(group_name))
2314 else:
2315 gr = cls.query().filter(cls.group_name == group_name)
2316 if cache:
2317 name_key = _hash_key(group_name)
2318 gr = gr.options(
2319 FromCache("sql_cache_short", "get_group_%s" % name_key))
2320 return gr.scalar()
2321
2322 @classmethod
2323 def get_user_personal_repo_group(cls, user_id):
2324 user = User.get(user_id)
2325 if user.username == User.DEFAULT_USER:
2326 return None
2327
2328 return cls.query()\
2329 .filter(cls.personal == true()) \
2330 .filter(cls.user == user).scalar()
2331
2332 @classmethod
2333 def get_all_repo_groups(cls, user_id=Optional(None), group_id=Optional(None),
2334 case_insensitive=True):
2335 q = RepoGroup.query()
2336
2337 if not isinstance(user_id, Optional):
2338 q = q.filter(RepoGroup.user_id == user_id)
2339
2340 if not isinstance(group_id, Optional):
2341 q = q.filter(RepoGroup.group_parent_id == group_id)
2342
2343 if case_insensitive:
2344 q = q.order_by(func.lower(RepoGroup.group_name))
2345 else:
2346 q = q.order_by(RepoGroup.group_name)
2347 return q.all()
2348
2349 @property
2350 def parents(self):
2351 parents_recursion_limit = 10
2352 groups = []
2353 if self.parent_group is None:
2354 return groups
2355 cur_gr = self.parent_group
2356 groups.insert(0, cur_gr)
2357 cnt = 0
2358 while 1:
2359 cnt += 1
2360 gr = getattr(cur_gr, 'parent_group', None)
2361 cur_gr = cur_gr.parent_group
2362 if gr is None:
2363 break
2364 if cnt == parents_recursion_limit:
2365 # this will prevent accidental infinit loops
2366 log.error(('more than %s parents found for group %s, stopping '
2367 'recursive parent fetching' % (parents_recursion_limit, self)))
2368 break
2369
2370 groups.insert(0, gr)
2371 return groups
2372
2373 @property
2374 def last_db_change(self):
2375 return self.updated_on
2376
2377 @property
2378 def children(self):
2379 return RepoGroup.query().filter(RepoGroup.parent_group == self)
2380
2381 @property
2382 def name(self):
2383 return self.group_name.split(RepoGroup.url_sep())[-1]
2384
2385 @property
2386 def full_path(self):
2387 return self.group_name
2388
2389 @property
2390 def full_path_splitted(self):
2391 return self.group_name.split(RepoGroup.url_sep())
2392
2393 @property
2394 def repositories(self):
2395 return Repository.query()\
2396 .filter(Repository.group == self)\
2397 .order_by(Repository.repo_name)
2398
2399 @property
2400 def repositories_recursive_count(self):
2401 cnt = self.repositories.count()
2402
2403 def children_count(group):
2404 cnt = 0
2405 for child in group.children:
2406 cnt += child.repositories.count()
2407 cnt += children_count(child)
2408 return cnt
2409
2410 return cnt + children_count(self)
2411
2412 def _recursive_objects(self, include_repos=True):
2413 all_ = []
2414
2415 def _get_members(root_gr):
2416 if include_repos:
2417 for r in root_gr.repositories:
2418 all_.append(r)
2419 childs = root_gr.children.all()
2420 if childs:
2421 for gr in childs:
2422 all_.append(gr)
2423 _get_members(gr)
2424
2425 _get_members(self)
2426 return [self] + all_
2427
2428 def recursive_groups_and_repos(self):
2429 """
2430 Recursive return all groups, with repositories in those groups
2431 """
2432 return self._recursive_objects()
2433
2434 def recursive_groups(self):
2435 """
2436 Returns all children groups for this group including children of children
2437 """
2438 return self._recursive_objects(include_repos=False)
2439
2440 def get_new_name(self, group_name):
2441 """
2442 returns new full group name based on parent and new name
2443
2444 :param group_name:
2445 """
2446 path_prefix = (self.parent_group.full_path_splitted if
2447 self.parent_group else [])
2448 return RepoGroup.url_sep().join(path_prefix + [group_name])
2449
2450 def permissions(self, with_admins=True, with_owner=True):
2451 q = UserRepoGroupToPerm.query().filter(UserRepoGroupToPerm.group == self)
2452 q = q.options(joinedload(UserRepoGroupToPerm.group),
2453 joinedload(UserRepoGroupToPerm.user),
2454 joinedload(UserRepoGroupToPerm.permission),)
2455
2456 # get owners and admins and permissions. We do a trick of re-writing
2457 # objects from sqlalchemy to named-tuples due to sqlalchemy session
2458 # has a global reference and changing one object propagates to all
2459 # others. This means if admin is also an owner admin_row that change
2460 # would propagate to both objects
2461 perm_rows = []
2462 for _usr in q.all():
2463 usr = AttributeDict(_usr.user.get_dict())
2464 usr.permission = _usr.permission.permission_name
2465 perm_rows.append(usr)
2466
2467 # filter the perm rows by 'default' first and then sort them by
2468 # admin,write,read,none permissions sorted again alphabetically in
2469 # each group
2470 perm_rows = sorted(perm_rows, key=display_sort)
2471
2472 _admin_perm = 'group.admin'
2473 owner_row = []
2474 if with_owner:
2475 usr = AttributeDict(self.user.get_dict())
2476 usr.owner_row = True
2477 usr.permission = _admin_perm
2478 owner_row.append(usr)
2479
2480 super_admin_rows = []
2481 if with_admins:
2482 for usr in User.get_all_super_admins():
2483 # if this admin is also owner, don't double the record
2484 if usr.user_id == owner_row[0].user_id:
2485 owner_row[0].admin_row = True
2486 else:
2487 usr = AttributeDict(usr.get_dict())
2488 usr.admin_row = True
2489 usr.permission = _admin_perm
2490 super_admin_rows.append(usr)
2491
2492 return super_admin_rows + owner_row + perm_rows
2493
2494 def permission_user_groups(self):
2495 q = UserGroupRepoGroupToPerm.query().filter(UserGroupRepoGroupToPerm.group == self)
2496 q = q.options(joinedload(UserGroupRepoGroupToPerm.group),
2497 joinedload(UserGroupRepoGroupToPerm.users_group),
2498 joinedload(UserGroupRepoGroupToPerm.permission),)
2499
2500 perm_rows = []
2501 for _user_group in q.all():
2502 usr = AttributeDict(_user_group.users_group.get_dict())
2503 usr.permission = _user_group.permission.permission_name
2504 perm_rows.append(usr)
2505
2506 return perm_rows
2507
2508 def get_api_data(self):
2509 """
2510 Common function for generating api data
2511
2512 """
2513 group = self
2514 data = {
2515 'group_id': group.group_id,
2516 'group_name': group.group_name,
2517 'group_description': group.description_safe,
2518 'parent_group': group.parent_group.group_name if group.parent_group else None,
2519 'repositories': [x.repo_name for x in group.repositories],
2520 'owner': group.user.username,
2521 }
2522 return data
2523
2524
2525 class Permission(Base, BaseModel):
2526 __tablename__ = 'permissions'
2527 __table_args__ = (
2528 Index('p_perm_name_idx', 'permission_name'),
2529 {'extend_existing': True, 'mysql_engine': 'InnoDB',
2530 'mysql_charset': 'utf8', 'sqlite_autoincrement': True},
2531 )
2532 PERMS = [
2533 ('hg.admin', _('RhodeCode Super Administrator')),
2534
2535 ('repository.none', _('Repository no access')),
2536 ('repository.read', _('Repository read access')),
2537 ('repository.write', _('Repository write access')),
2538 ('repository.admin', _('Repository admin access')),
2539
2540 ('group.none', _('Repository group no access')),
2541 ('group.read', _('Repository group read access')),
2542 ('group.write', _('Repository group write access')),
2543 ('group.admin', _('Repository group admin access')),
2544
2545 ('usergroup.none', _('User group no access')),
2546 ('usergroup.read', _('User group read access')),
2547 ('usergroup.write', _('User group write access')),
2548 ('usergroup.admin', _('User group admin access')),
2549
2550 ('hg.repogroup.create.false', _('Repository Group creation disabled')),
2551 ('hg.repogroup.create.true', _('Repository Group creation enabled')),
2552
2553 ('hg.usergroup.create.false', _('User Group creation disabled')),
2554 ('hg.usergroup.create.true', _('User Group creation enabled')),
2555
2556 ('hg.create.none', _('Repository creation disabled')),
2557 ('hg.create.repository', _('Repository creation enabled')),
2558 ('hg.create.write_on_repogroup.true', _('Repository creation enabled with write permission to a repository group')),
2559 ('hg.create.write_on_repogroup.false', _('Repository creation disabled with write permission to a repository group')),
2560
2561 ('hg.fork.none', _('Repository forking disabled')),
2562 ('hg.fork.repository', _('Repository forking enabled')),
2563
2564 ('hg.register.none', _('Registration disabled')),
2565 ('hg.register.manual_activate', _('User Registration with manual account activation')),
2566 ('hg.register.auto_activate', _('User Registration with automatic account activation')),
2567
2568 ('hg.password_reset.enabled', _('Password reset enabled')),
2569 ('hg.password_reset.hidden', _('Password reset hidden')),
2570 ('hg.password_reset.disabled', _('Password reset disabled')),
2571
2572 ('hg.extern_activate.manual', _('Manual activation of external account')),
2573 ('hg.extern_activate.auto', _('Automatic activation of external account')),
2574
2575 ('hg.inherit_default_perms.false', _('Inherit object permissions from default user disabled')),
2576 ('hg.inherit_default_perms.true', _('Inherit object permissions from default user enabled')),
2577 ]
2578
2579 # definition of system default permissions for DEFAULT user
2580 DEFAULT_USER_PERMISSIONS = [
2581 'repository.read',
2582 'group.read',
2583 'usergroup.read',
2584 'hg.create.repository',
2585 'hg.repogroup.create.false',
2586 'hg.usergroup.create.false',
2587 'hg.create.write_on_repogroup.true',
2588 'hg.fork.repository',
2589 'hg.register.manual_activate',
2590 'hg.password_reset.enabled',
2591 'hg.extern_activate.auto',
2592 'hg.inherit_default_perms.true',
2593 ]
2594
2595 # defines which permissions are more important higher the more important
2596 # Weight defines which permissions are more important.
2597 # The higher number the more important.
2598 PERM_WEIGHTS = {
2599 'repository.none': 0,
2600 'repository.read': 1,
2601 'repository.write': 3,
2602 'repository.admin': 4,
2603
2604 'group.none': 0,
2605 'group.read': 1,
2606 'group.write': 3,
2607 'group.admin': 4,
2608
2609 'usergroup.none': 0,
2610 'usergroup.read': 1,
2611 'usergroup.write': 3,
2612 'usergroup.admin': 4,
2613
2614 'hg.repogroup.create.false': 0,
2615 'hg.repogroup.create.true': 1,
2616
2617 'hg.usergroup.create.false': 0,
2618 'hg.usergroup.create.true': 1,
2619
2620 'hg.fork.none': 0,
2621 'hg.fork.repository': 1,
2622 'hg.create.none': 0,
2623 'hg.create.repository': 1
2624 }
2625
2626 permission_id = Column("permission_id", Integer(), nullable=False, unique=True, default=None, primary_key=True)
2627 permission_name = Column("permission_name", String(255), nullable=True, unique=None, default=None)
2628 permission_longname = Column("permission_longname", String(255), nullable=True, unique=None, default=None)
2629
2630 def __unicode__(self):
2631 return u"<%s('%s:%s')>" % (
2632 self.__class__.__name__, self.permission_id, self.permission_name
2633 )
2634
2635 @classmethod
2636 def get_by_key(cls, key):
2637 return cls.query().filter(cls.permission_name == key).scalar()
2638
2639 @classmethod
2640 def get_default_repo_perms(cls, user_id, repo_id=None):
2641 q = Session().query(UserRepoToPerm, Repository, Permission)\
2642 .join((Permission, UserRepoToPerm.permission_id == Permission.permission_id))\
2643 .join((Repository, UserRepoToPerm.repository_id == Repository.repo_id))\
2644 .filter(UserRepoToPerm.user_id == user_id)
2645 if repo_id:
2646 q = q.filter(UserRepoToPerm.repository_id == repo_id)
2647 return q.all()
2648
2649 @classmethod
2650 def get_default_repo_perms_from_user_group(cls, user_id, repo_id=None):
2651 q = Session().query(UserGroupRepoToPerm, Repository, Permission)\
2652 .join(
2653 Permission,
2654 UserGroupRepoToPerm.permission_id == Permission.permission_id)\
2655 .join(
2656 Repository,
2657 UserGroupRepoToPerm.repository_id == Repository.repo_id)\
2658 .join(
2659 UserGroup,
2660 UserGroupRepoToPerm.users_group_id ==
2661 UserGroup.users_group_id)\
2662 .join(
2663 UserGroupMember,
2664 UserGroupRepoToPerm.users_group_id ==
2665 UserGroupMember.users_group_id)\
2666 .filter(
2667 UserGroupMember.user_id == user_id,
2668 UserGroup.users_group_active == true())
2669 if repo_id:
2670 q = q.filter(UserGroupRepoToPerm.repository_id == repo_id)
2671 return q.all()
2672
2673 @classmethod
2674 def get_default_group_perms(cls, user_id, repo_group_id=None):
2675 q = Session().query(UserRepoGroupToPerm, RepoGroup, Permission)\
2676 .join((Permission, UserRepoGroupToPerm.permission_id == Permission.permission_id))\
2677 .join((RepoGroup, UserRepoGroupToPerm.group_id == RepoGroup.group_id))\
2678 .filter(UserRepoGroupToPerm.user_id == user_id)
2679 if repo_group_id:
2680 q = q.filter(UserRepoGroupToPerm.group_id == repo_group_id)
2681 return q.all()
2682
2683 @classmethod
2684 def get_default_group_perms_from_user_group(
2685 cls, user_id, repo_group_id=None):
2686 q = Session().query(UserGroupRepoGroupToPerm, RepoGroup, Permission)\
2687 .join(
2688 Permission,
2689 UserGroupRepoGroupToPerm.permission_id ==
2690 Permission.permission_id)\
2691 .join(
2692 RepoGroup,
2693 UserGroupRepoGroupToPerm.group_id == RepoGroup.group_id)\
2694 .join(
2695 UserGroup,
2696 UserGroupRepoGroupToPerm.users_group_id ==
2697 UserGroup.users_group_id)\
2698 .join(
2699 UserGroupMember,
2700 UserGroupRepoGroupToPerm.users_group_id ==
2701 UserGroupMember.users_group_id)\
2702 .filter(
2703 UserGroupMember.user_id == user_id,
2704 UserGroup.users_group_active == true())
2705 if repo_group_id:
2706 q = q.filter(UserGroupRepoGroupToPerm.group_id == repo_group_id)
2707 return q.all()
2708
2709 @classmethod
2710 def get_default_user_group_perms(cls, user_id, user_group_id=None):
2711 q = Session().query(UserUserGroupToPerm, UserGroup, Permission)\
2712 .join((Permission, UserUserGroupToPerm.permission_id == Permission.permission_id))\
2713 .join((UserGroup, UserUserGroupToPerm.user_group_id == UserGroup.users_group_id))\
2714 .filter(UserUserGroupToPerm.user_id == user_id)
2715 if user_group_id:
2716 q = q.filter(UserUserGroupToPerm.user_group_id == user_group_id)
2717 return q.all()
2718
2719 @classmethod
2720 def get_default_user_group_perms_from_user_group(
2721 cls, user_id, user_group_id=None):
2722 TargetUserGroup = aliased(UserGroup, name='target_user_group')
2723 q = Session().query(UserGroupUserGroupToPerm, UserGroup, Permission)\
2724 .join(
2725 Permission,
2726 UserGroupUserGroupToPerm.permission_id ==
2727 Permission.permission_id)\
2728 .join(
2729 TargetUserGroup,
2730 UserGroupUserGroupToPerm.target_user_group_id ==
2731 TargetUserGroup.users_group_id)\
2732 .join(
2733 UserGroup,
2734 UserGroupUserGroupToPerm.user_group_id ==
2735 UserGroup.users_group_id)\
2736 .join(
2737 UserGroupMember,
2738 UserGroupUserGroupToPerm.user_group_id ==
2739 UserGroupMember.users_group_id)\
2740 .filter(
2741 UserGroupMember.user_id == user_id,
2742 UserGroup.users_group_active == true())
2743 if user_group_id:
2744 q = q.filter(
2745 UserGroupUserGroupToPerm.user_group_id == user_group_id)
2746
2747 return q.all()
2748
2749
2750 class UserRepoToPerm(Base, BaseModel):
2751 __tablename__ = 'repo_to_perm'
2752 __table_args__ = (
2753 UniqueConstraint('user_id', 'repository_id', 'permission_id'),
2754 {'extend_existing': True, 'mysql_engine': 'InnoDB',
2755 'mysql_charset': 'utf8', 'sqlite_autoincrement': True}
2756 )
2757 repo_to_perm_id = Column("repo_to_perm_id", Integer(), nullable=False, unique=True, default=None, primary_key=True)
2758 user_id = Column("user_id", Integer(), ForeignKey('users.user_id'), nullable=False, unique=None, default=None)
2759 permission_id = Column("permission_id", Integer(), ForeignKey('permissions.permission_id'), nullable=False, unique=None, default=None)
2760 repository_id = Column("repository_id", Integer(), ForeignKey('repositories.repo_id'), nullable=False, unique=None, default=None)
2761
2762 user = relationship('User')
2763 repository = relationship('Repository')
2764 permission = relationship('Permission')
2765
2766 @classmethod
2767 def create(cls, user, repository, permission):
2768 n = cls()
2769 n.user = user
2770 n.repository = repository
2771 n.permission = permission
2772 Session().add(n)
2773 return n
2774
2775 def __unicode__(self):
2776 return u'<%s => %s >' % (self.user, self.repository)
2777
2778
2779 class UserUserGroupToPerm(Base, BaseModel):
2780 __tablename__ = 'user_user_group_to_perm'
2781 __table_args__ = (
2782 UniqueConstraint('user_id', 'user_group_id', 'permission_id'),
2783 {'extend_existing': True, 'mysql_engine': 'InnoDB',
2784 'mysql_charset': 'utf8', 'sqlite_autoincrement': True}
2785 )
2786 user_user_group_to_perm_id = Column("user_user_group_to_perm_id", Integer(), nullable=False, unique=True, default=None, primary_key=True)
2787 user_id = Column("user_id", Integer(), ForeignKey('users.user_id'), nullable=False, unique=None, default=None)
2788 permission_id = Column("permission_id", Integer(), ForeignKey('permissions.permission_id'), nullable=False, unique=None, default=None)
2789 user_group_id = Column("user_group_id", Integer(), ForeignKey('users_groups.users_group_id'), nullable=False, unique=None, default=None)
2790
2791 user = relationship('User')
2792 user_group = relationship('UserGroup')
2793 permission = relationship('Permission')
2794
2795 @classmethod
2796 def create(cls, user, user_group, permission):
2797 n = cls()
2798 n.user = user
2799 n.user_group = user_group
2800 n.permission = permission
2801 Session().add(n)
2802 return n
2803
2804 def __unicode__(self):
2805 return u'<%s => %s >' % (self.user, self.user_group)
2806
2807
2808 class UserToPerm(Base, BaseModel):
2809 __tablename__ = 'user_to_perm'
2810 __table_args__ = (
2811 UniqueConstraint('user_id', 'permission_id'),
2812 {'extend_existing': True, 'mysql_engine': 'InnoDB',
2813 'mysql_charset': 'utf8', 'sqlite_autoincrement': True}
2814 )
2815 user_to_perm_id = Column("user_to_perm_id", Integer(), nullable=False, unique=True, default=None, primary_key=True)
2816 user_id = Column("user_id", Integer(), ForeignKey('users.user_id'), nullable=False, unique=None, default=None)
2817 permission_id = Column("permission_id", Integer(), ForeignKey('permissions.permission_id'), nullable=False, unique=None, default=None)
2818
2819 user = relationship('User')
2820 permission = relationship('Permission', lazy='joined')
2821
2822 def __unicode__(self):
2823 return u'<%s => %s >' % (self.user, self.permission)
2824
2825
2826 class UserGroupRepoToPerm(Base, BaseModel):
2827 __tablename__ = 'users_group_repo_to_perm'
2828 __table_args__ = (
2829 UniqueConstraint('repository_id', 'users_group_id', 'permission_id'),
2830 {'extend_existing': True, 'mysql_engine': 'InnoDB',
2831 'mysql_charset': 'utf8', 'sqlite_autoincrement': True}
2832 )
2833 users_group_to_perm_id = Column("users_group_to_perm_id", Integer(), nullable=False, unique=True, default=None, primary_key=True)
2834 users_group_id = Column("users_group_id", Integer(), ForeignKey('users_groups.users_group_id'), nullable=False, unique=None, default=None)
2835 permission_id = Column("permission_id", Integer(), ForeignKey('permissions.permission_id'), nullable=False, unique=None, default=None)
2836 repository_id = Column("repository_id", Integer(), ForeignKey('repositories.repo_id'), nullable=False, unique=None, default=None)
2837
2838 users_group = relationship('UserGroup')
2839 permission = relationship('Permission')
2840 repository = relationship('Repository')
2841
2842 @classmethod
2843 def create(cls, users_group, repository, permission):
2844 n = cls()
2845 n.users_group = users_group
2846 n.repository = repository
2847 n.permission = permission
2848 Session().add(n)
2849 return n
2850
2851 def __unicode__(self):
2852 return u'<UserGroupRepoToPerm:%s => %s >' % (self.users_group, self.repository)
2853
2854
2855 class UserGroupUserGroupToPerm(Base, BaseModel):
2856 __tablename__ = 'user_group_user_group_to_perm'
2857 __table_args__ = (
2858 UniqueConstraint('target_user_group_id', 'user_group_id', 'permission_id'),
2859 CheckConstraint('target_user_group_id != user_group_id'),
2860 {'extend_existing': True, 'mysql_engine': 'InnoDB',
2861 'mysql_charset': 'utf8', 'sqlite_autoincrement': True}
2862 )
2863 user_group_user_group_to_perm_id = Column("user_group_user_group_to_perm_id", Integer(), nullable=False, unique=True, default=None, primary_key=True)
2864 target_user_group_id = Column("target_user_group_id", Integer(), ForeignKey('users_groups.users_group_id'), nullable=False, unique=None, default=None)
2865 permission_id = Column("permission_id", Integer(), ForeignKey('permissions.permission_id'), nullable=False, unique=None, default=None)
2866 user_group_id = Column("user_group_id", Integer(), ForeignKey('users_groups.users_group_id'), nullable=False, unique=None, default=None)
2867
2868 target_user_group = relationship('UserGroup', primaryjoin='UserGroupUserGroupToPerm.target_user_group_id==UserGroup.users_group_id')
2869 user_group = relationship('UserGroup', primaryjoin='UserGroupUserGroupToPerm.user_group_id==UserGroup.users_group_id')
2870 permission = relationship('Permission')
2871
2872 @classmethod
2873 def create(cls, target_user_group, user_group, permission):
2874 n = cls()
2875 n.target_user_group = target_user_group
2876 n.user_group = user_group
2877 n.permission = permission
2878 Session().add(n)
2879 return n
2880
2881 def __unicode__(self):
2882 return u'<UserGroupUserGroup:%s => %s >' % (self.target_user_group, self.user_group)
2883
2884
2885 class UserGroupToPerm(Base, BaseModel):
2886 __tablename__ = 'users_group_to_perm'
2887 __table_args__ = (
2888 UniqueConstraint('users_group_id', 'permission_id',),
2889 {'extend_existing': True, 'mysql_engine': 'InnoDB',
2890 'mysql_charset': 'utf8', 'sqlite_autoincrement': True}
2891 )
2892 users_group_to_perm_id = Column("users_group_to_perm_id", Integer(), nullable=False, unique=True, default=None, primary_key=True)
2893 users_group_id = Column("users_group_id", Integer(), ForeignKey('users_groups.users_group_id'), nullable=False, unique=None, default=None)
2894 permission_id = Column("permission_id", Integer(), ForeignKey('permissions.permission_id'), nullable=False, unique=None, default=None)
2895
2896 users_group = relationship('UserGroup')
2897 permission = relationship('Permission')
2898
2899
2900 class UserRepoGroupToPerm(Base, BaseModel):
2901 __tablename__ = 'user_repo_group_to_perm'
2902 __table_args__ = (
2903 UniqueConstraint('user_id', 'group_id', 'permission_id'),
2904 {'extend_existing': True, 'mysql_engine': 'InnoDB',
2905 'mysql_charset': 'utf8', 'sqlite_autoincrement': True}
2906 )
2907
2908 group_to_perm_id = Column("group_to_perm_id", Integer(), nullable=False, unique=True, default=None, primary_key=True)
2909 user_id = Column("user_id", Integer(), ForeignKey('users.user_id'), nullable=False, unique=None, default=None)
2910 group_id = Column("group_id", Integer(), ForeignKey('groups.group_id'), nullable=False, unique=None, default=None)
2911 permission_id = Column("permission_id", Integer(), ForeignKey('permissions.permission_id'), nullable=False, unique=None, default=None)
2912
2913 user = relationship('User')
2914 group = relationship('RepoGroup')
2915 permission = relationship('Permission')
2916
2917 @classmethod
2918 def create(cls, user, repository_group, permission):
2919 n = cls()
2920 n.user = user
2921 n.group = repository_group
2922 n.permission = permission
2923 Session().add(n)
2924 return n
2925
2926
2927 class UserGroupRepoGroupToPerm(Base, BaseModel):
2928 __tablename__ = 'users_group_repo_group_to_perm'
2929 __table_args__ = (
2930 UniqueConstraint('users_group_id', 'group_id'),
2931 {'extend_existing': True, 'mysql_engine': 'InnoDB',
2932 'mysql_charset': 'utf8', 'sqlite_autoincrement': True}
2933 )
2934
2935 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)
2936 users_group_id = Column("users_group_id", Integer(), ForeignKey('users_groups.users_group_id'), nullable=False, unique=None, default=None)
2937 group_id = Column("group_id", Integer(), ForeignKey('groups.group_id'), nullable=False, unique=None, default=None)
2938 permission_id = Column("permission_id", Integer(), ForeignKey('permissions.permission_id'), nullable=False, unique=None, default=None)
2939
2940 users_group = relationship('UserGroup')
2941 permission = relationship('Permission')
2942 group = relationship('RepoGroup')
2943
2944 @classmethod
2945 def create(cls, user_group, repository_group, permission):
2946 n = cls()
2947 n.users_group = user_group
2948 n.group = repository_group
2949 n.permission = permission
2950 Session().add(n)
2951 return n
2952
2953 def __unicode__(self):
2954 return u'<UserGroupRepoGroupToPerm:%s => %s >' % (self.users_group, self.group)
2955
2956
2957 class Statistics(Base, BaseModel):
2958 __tablename__ = 'statistics'
2959 __table_args__ = (
2960 {'extend_existing': True, 'mysql_engine': 'InnoDB',
2961 'mysql_charset': 'utf8', 'sqlite_autoincrement': True}
2962 )
2963 stat_id = Column("stat_id", Integer(), nullable=False, unique=True, default=None, primary_key=True)
2964 repository_id = Column("repository_id", Integer(), ForeignKey('repositories.repo_id'), nullable=False, unique=True, default=None)
2965 stat_on_revision = Column("stat_on_revision", Integer(), nullable=False)
2966 commit_activity = Column("commit_activity", LargeBinary(1000000), nullable=False)#JSON data
2967 commit_activity_combined = Column("commit_activity_combined", LargeBinary(), nullable=False)#JSON data
2968 languages = Column("languages", LargeBinary(1000000), nullable=False)#JSON data
2969
2970 repository = relationship('Repository', single_parent=True)
2971
2972
2973 class UserFollowing(Base, BaseModel):
2974 __tablename__ = 'user_followings'
2975 __table_args__ = (
2976 UniqueConstraint('user_id', 'follows_repository_id'),
2977 UniqueConstraint('user_id', 'follows_user_id'),
2978 {'extend_existing': True, 'mysql_engine': 'InnoDB',
2979 'mysql_charset': 'utf8', 'sqlite_autoincrement': True}
2980 )
2981
2982 user_following_id = Column("user_following_id", Integer(), nullable=False, unique=True, default=None, primary_key=True)
2983 user_id = Column("user_id", Integer(), ForeignKey('users.user_id'), nullable=False, unique=None, default=None)
2984 follows_repo_id = Column("follows_repository_id", Integer(), ForeignKey('repositories.repo_id'), nullable=True, unique=None, default=None)
2985 follows_user_id = Column("follows_user_id", Integer(), ForeignKey('users.user_id'), nullable=True, unique=None, default=None)
2986 follows_from = Column('follows_from', DateTime(timezone=False), nullable=True, unique=None, default=datetime.datetime.now)
2987
2988 user = relationship('User', primaryjoin='User.user_id==UserFollowing.user_id')
2989
2990 follows_user = relationship('User', primaryjoin='User.user_id==UserFollowing.follows_user_id')
2991 follows_repository = relationship('Repository', order_by='Repository.repo_name')
2992
2993 @classmethod
2994 def get_repo_followers(cls, repo_id):
2995 return cls.query().filter(cls.follows_repo_id == repo_id)
2996
2997
2998 class CacheKey(Base, BaseModel):
2999 __tablename__ = 'cache_invalidation'
3000 __table_args__ = (
3001 UniqueConstraint('cache_key'),
3002 Index('key_idx', 'cache_key'),
3003 {'extend_existing': True, 'mysql_engine': 'InnoDB',
3004 'mysql_charset': 'utf8', 'sqlite_autoincrement': True},
3005 )
3006 CACHE_TYPE_ATOM = 'ATOM'
3007 CACHE_TYPE_RSS = 'RSS'
3008 CACHE_TYPE_README = 'README'
3009
3010 cache_id = Column("cache_id", Integer(), nullable=False, unique=True, default=None, primary_key=True)
3011 cache_key = Column("cache_key", String(255), nullable=True, unique=None, default=None)
3012 cache_args = Column("cache_args", String(255), nullable=True, unique=None, default=None)
3013 cache_active = Column("cache_active", Boolean(), nullable=True, unique=None, default=False)
3014
3015 def __init__(self, cache_key, cache_args=''):
3016 self.cache_key = cache_key
3017 self.cache_args = cache_args
3018 self.cache_active = False
3019
3020 def __unicode__(self):
3021 return u"<%s('%s:%s[%s]')>" % (
3022 self.__class__.__name__,
3023 self.cache_id, self.cache_key, self.cache_active)
3024
3025 def _cache_key_partition(self):
3026 prefix, repo_name, suffix = self.cache_key.partition(self.cache_args)
3027 return prefix, repo_name, suffix
3028
3029 def get_prefix(self):
3030 """
3031 Try to extract prefix from existing cache key. The key could consist
3032 of prefix, repo_name, suffix
3033 """
3034 # this returns prefix, repo_name, suffix
3035 return self._cache_key_partition()[0]
3036
3037 def get_suffix(self):
3038 """
3039 get suffix that might have been used in _get_cache_key to
3040 generate self.cache_key. Only used for informational purposes
3041 in repo_edit.mako.
3042 """
3043 # prefix, repo_name, suffix
3044 return self._cache_key_partition()[2]
3045
3046 @classmethod
3047 def delete_all_cache(cls):
3048 """
3049 Delete all cache keys from database.
3050 Should only be run when all instances are down and all entries
3051 thus stale.
3052 """
3053 cls.query().delete()
3054 Session().commit()
3055
3056 @classmethod
3057 def get_cache_key(cls, repo_name, cache_type):
3058 """
3059
3060 Generate a cache key for this process of RhodeCode instance.
3061 Prefix most likely will be process id or maybe explicitly set
3062 instance_id from .ini file.
3063 """
3064 import rhodecode
3065 prefix = safe_unicode(rhodecode.CONFIG.get('instance_id') or '')
3066
3067 repo_as_unicode = safe_unicode(repo_name)
3068 key = u'{}_{}'.format(repo_as_unicode, cache_type) \
3069 if cache_type else repo_as_unicode
3070
3071 return u'{}{}'.format(prefix, key)
3072
3073 @classmethod
3074 def set_invalidate(cls, repo_name, delete=False):
3075 """
3076 Mark all caches of a repo as invalid in the database.
3077 """
3078
3079 try:
3080 qry = Session().query(cls).filter(cls.cache_args == repo_name)
3081 if delete:
3082 log.debug('cache objects deleted for repo %s',
3083 safe_str(repo_name))
3084 qry.delete()
3085 else:
3086 log.debug('cache objects marked as invalid for repo %s',
3087 safe_str(repo_name))
3088 qry.update({"cache_active": False})
3089
3090 Session().commit()
3091 except Exception:
3092 log.exception(
3093 'Cache key invalidation failed for repository %s',
3094 safe_str(repo_name))
3095 Session().rollback()
3096
3097 @classmethod
3098 def get_active_cache(cls, cache_key):
3099 inv_obj = cls.query().filter(cls.cache_key == cache_key).scalar()
3100 if inv_obj:
3101 return inv_obj
3102 return None
3103
3104 @classmethod
3105 def repo_context_cache(cls, compute_func, repo_name, cache_type,
3106 thread_scoped=False):
3107 """
3108 @cache_region('long_term')
3109 def _heavy_calculation(cache_key):
3110 return 'result'
3111
3112 cache_context = CacheKey.repo_context_cache(
3113 _heavy_calculation, repo_name, cache_type)
3114
3115 with cache_context as context:
3116 context.invalidate()
3117 computed = context.compute()
3118
3119 assert computed == 'result'
3120 """
3121 from rhodecode.lib import caches
3122 return caches.InvalidationContext(
3123 compute_func, repo_name, cache_type, thread_scoped=thread_scoped)
3124
3125
3126 class ChangesetComment(Base, BaseModel):
3127 __tablename__ = 'changeset_comments'
3128 __table_args__ = (
3129 Index('cc_revision_idx', 'revision'),
3130 {'extend_existing': True, 'mysql_engine': 'InnoDB',
3131 'mysql_charset': 'utf8', 'sqlite_autoincrement': True},
3132 )
3133
3134 COMMENT_OUTDATED = u'comment_outdated'
3135 COMMENT_TYPE_NOTE = u'note'
3136 COMMENT_TYPE_TODO = u'todo'
3137 COMMENT_TYPES = [COMMENT_TYPE_NOTE, COMMENT_TYPE_TODO]
3138
3139 comment_id = Column('comment_id', Integer(), nullable=False, primary_key=True)
3140 repo_id = Column('repo_id', Integer(), ForeignKey('repositories.repo_id'), nullable=False)
3141 revision = Column('revision', String(40), nullable=True)
3142 pull_request_id = Column("pull_request_id", Integer(), ForeignKey('pull_requests.pull_request_id'), nullable=True)
3143 pull_request_version_id = Column("pull_request_version_id", Integer(), ForeignKey('pull_request_versions.pull_request_version_id'), nullable=True)
3144 line_no = Column('line_no', Unicode(10), nullable=True)
3145 hl_lines = Column('hl_lines', Unicode(512), nullable=True)
3146 f_path = Column('f_path', Unicode(1000), nullable=True)
3147 user_id = Column('user_id', Integer(), ForeignKey('users.user_id'), nullable=False)
3148 text = Column('text', UnicodeText().with_variant(UnicodeText(25000), 'mysql'), nullable=False)
3149 created_on = Column('created_on', DateTime(timezone=False), nullable=False, default=datetime.datetime.now)
3150 modified_at = Column('modified_at', DateTime(timezone=False), nullable=False, default=datetime.datetime.now)
3151 renderer = Column('renderer', Unicode(64), nullable=True)
3152 display_state = Column('display_state', Unicode(128), nullable=True)
3153
3154 comment_type = Column('comment_type', Unicode(128), nullable=True, default=COMMENT_TYPE_NOTE)
3155 resolved_comment_id = Column('resolved_comment_id', Integer(), ForeignKey('changeset_comments.comment_id'), nullable=True)
3156 resolved_comment = relationship('ChangesetComment', remote_side=comment_id, backref='resolved_by')
3157 author = relationship('User', lazy='joined')
3158 repo = relationship('Repository')
3159 status_change = relationship('ChangesetStatus', cascade="all, delete, delete-orphan", lazy='joined')
3160 pull_request = relationship('PullRequest', lazy='joined')
3161 pull_request_version = relationship('PullRequestVersion')
3162
3163 @classmethod
3164 def get_users(cls, revision=None, pull_request_id=None):
3165 """
3166 Returns user associated with this ChangesetComment. ie those
3167 who actually commented
3168
3169 :param cls:
3170 :param revision:
3171 """
3172 q = Session().query(User)\
3173 .join(ChangesetComment.author)
3174 if revision:
3175 q = q.filter(cls.revision == revision)
3176 elif pull_request_id:
3177 q = q.filter(cls.pull_request_id == pull_request_id)
3178 return q.all()
3179
3180 @classmethod
3181 def get_index_from_version(cls, pr_version, versions):
3182 num_versions = [x.pull_request_version_id for x in versions]
3183 try:
3184 return num_versions.index(pr_version) +1
3185 except (IndexError, ValueError):
3186 return
3187
3188 @property
3189 def outdated(self):
3190 return self.display_state == self.COMMENT_OUTDATED
3191
3192 def outdated_at_version(self, version):
3193 """
3194 Checks if comment is outdated for given pull request version
3195 """
3196 return self.outdated and self.pull_request_version_id != version
3197
3198 def older_than_version(self, version):
3199 """
3200 Checks if comment is made from previous version than given
3201 """
3202 if version is None:
3203 return self.pull_request_version_id is not None
3204
3205 return self.pull_request_version_id < version
3206
3207 @property
3208 def resolved(self):
3209 return self.resolved_by[0] if self.resolved_by else None
3210
3211 @property
3212 def is_todo(self):
3213 return self.comment_type == self.COMMENT_TYPE_TODO
3214
3215 @property
3216 def is_inline(self):
3217 return self.line_no and self.f_path
3218
3219 def get_index_version(self, versions):
3220 return self.get_index_from_version(
3221 self.pull_request_version_id, versions)
3222
3223 def __repr__(self):
3224 if self.comment_id:
3225 return '<DB:Comment #%s>' % self.comment_id
3226 else:
3227 return '<DB:Comment at %#x>' % id(self)
3228
3229 def get_api_data(self):
3230 comment = self
3231 data = {
3232 'comment_id': comment.comment_id,
3233 'comment_type': comment.comment_type,
3234 'comment_text': comment.text,
3235 'comment_status': comment.status_change,
3236 'comment_f_path': comment.f_path,
3237 'comment_lineno': comment.line_no,
3238 'comment_author': comment.author,
3239 'comment_created_on': comment.created_on
3240 }
3241 return data
3242
3243 def __json__(self):
3244 data = dict()
3245 data.update(self.get_api_data())
3246 return data
3247
3248
3249 class ChangesetStatus(Base, BaseModel):
3250 __tablename__ = 'changeset_statuses'
3251 __table_args__ = (
3252 Index('cs_revision_idx', 'revision'),
3253 Index('cs_version_idx', 'version'),
3254 UniqueConstraint('repo_id', 'revision', 'version'),
3255 {'extend_existing': True, 'mysql_engine': 'InnoDB',
3256 'mysql_charset': 'utf8', 'sqlite_autoincrement': True}
3257 )
3258 STATUS_NOT_REVIEWED = DEFAULT = 'not_reviewed'
3259 STATUS_APPROVED = 'approved'
3260 STATUS_REJECTED = 'rejected'
3261 STATUS_UNDER_REVIEW = 'under_review'
3262
3263 STATUSES = [
3264 (STATUS_NOT_REVIEWED, _("Not Reviewed")), # (no icon) and default
3265 (STATUS_APPROVED, _("Approved")),
3266 (STATUS_REJECTED, _("Rejected")),
3267 (STATUS_UNDER_REVIEW, _("Under Review")),
3268 ]
3269
3270 changeset_status_id = Column('changeset_status_id', Integer(), nullable=False, primary_key=True)
3271 repo_id = Column('repo_id', Integer(), ForeignKey('repositories.repo_id'), nullable=False)
3272 user_id = Column("user_id", Integer(), ForeignKey('users.user_id'), nullable=False, unique=None)
3273 revision = Column('revision', String(40), nullable=False)
3274 status = Column('status', String(128), nullable=False, default=DEFAULT)
3275 changeset_comment_id = Column('changeset_comment_id', Integer(), ForeignKey('changeset_comments.comment_id'))
3276 modified_at = Column('modified_at', DateTime(), nullable=False, default=datetime.datetime.now)
3277 version = Column('version', Integer(), nullable=False, default=0)
3278 pull_request_id = Column("pull_request_id", Integer(), ForeignKey('pull_requests.pull_request_id'), nullable=True)
3279
3280 author = relationship('User', lazy='joined')
3281 repo = relationship('Repository')
3282 comment = relationship('ChangesetComment', lazy='joined')
3283 pull_request = relationship('PullRequest', lazy='joined')
3284
3285 def __unicode__(self):
3286 return u"<%s('%s[v%s]:%s')>" % (
3287 self.__class__.__name__,
3288 self.status, self.version, self.author
3289 )
3290
3291 @classmethod
3292 def get_status_lbl(cls, value):
3293 return dict(cls.STATUSES).get(value)
3294
3295 @property
3296 def status_lbl(self):
3297 return ChangesetStatus.get_status_lbl(self.status)
3298
3299 def get_api_data(self):
3300 status = self
3301 data = {
3302 'status_id': status.changeset_status_id,
3303 'status': status.status,
3304 }
3305 return data
3306
3307 def __json__(self):
3308 data = dict()
3309 data.update(self.get_api_data())
3310 return data
3311
3312
3313 class _PullRequestBase(BaseModel):
3314 """
3315 Common attributes of pull request and version entries.
3316 """
3317
3318 # .status values
3319 STATUS_NEW = u'new'
3320 STATUS_OPEN = u'open'
3321 STATUS_CLOSED = u'closed'
3322
3323 title = Column('title', Unicode(255), nullable=True)
3324 description = Column(
3325 'description', UnicodeText().with_variant(UnicodeText(10240), 'mysql'),
3326 nullable=True)
3327 # new/open/closed status of pull request (not approve/reject/etc)
3328 status = Column('status', Unicode(255), nullable=False, default=STATUS_NEW)
3329 created_on = Column(
3330 'created_on', DateTime(timezone=False), nullable=False,
3331 default=datetime.datetime.now)
3332 updated_on = Column(
3333 'updated_on', DateTime(timezone=False), nullable=False,
3334 default=datetime.datetime.now)
3335
3336 @declared_attr
3337 def user_id(cls):
3338 return Column(
3339 "user_id", Integer(), ForeignKey('users.user_id'), nullable=False,
3340 unique=None)
3341
3342 # 500 revisions max
3343 _revisions = Column(
3344 'revisions', UnicodeText().with_variant(UnicodeText(20500), 'mysql'))
3345
3346 @declared_attr
3347 def source_repo_id(cls):
3348 # TODO: dan: rename column to source_repo_id
3349 return Column(
3350 'org_repo_id', Integer(), ForeignKey('repositories.repo_id'),
3351 nullable=False)
3352
3353 source_ref = Column('org_ref', Unicode(255), nullable=False)
3354
3355 @declared_attr
3356 def target_repo_id(cls):
3357 # TODO: dan: rename column to target_repo_id
3358 return Column(
3359 'other_repo_id', Integer(), ForeignKey('repositories.repo_id'),
3360 nullable=False)
3361
3362 target_ref = Column('other_ref', Unicode(255), nullable=False)
3363 _shadow_merge_ref = Column('shadow_merge_ref', Unicode(255), nullable=True)
3364
3365 # TODO: dan: rename column to last_merge_source_rev
3366 _last_merge_source_rev = Column(
3367 'last_merge_org_rev', String(40), nullable=True)
3368 # TODO: dan: rename column to last_merge_target_rev
3369 _last_merge_target_rev = Column(
3370 'last_merge_other_rev', String(40), nullable=True)
3371 _last_merge_status = Column('merge_status', Integer(), nullable=True)
3372 merge_rev = Column('merge_rev', String(40), nullable=True)
3373
3374 reviewer_data = Column(
3375 'reviewer_data_json', MutationObj.as_mutable(
3376 JsonType(dialect_map=dict(mysql=UnicodeText(16384)))))
3377
3378 @property
3379 def reviewer_data_json(self):
3380 return json.dumps(self.reviewer_data)
3381
3382 @hybrid_property
3383 def description_safe(self):
3384 from rhodecode.lib import helpers as h
3385 return h.escape(self.description)
3386
3387 @hybrid_property
3388 def revisions(self):
3389 return self._revisions.split(':') if self._revisions else []
3390
3391 @revisions.setter
3392 def revisions(self, val):
3393 self._revisions = ':'.join(val)
3394
3395 @hybrid_property
3396 def last_merge_status(self):
3397 return safe_int(self._last_merge_status)
3398
3399 @last_merge_status.setter
3400 def last_merge_status(self, val):
3401 self._last_merge_status = val
3402
3403 @declared_attr
3404 def author(cls):
3405 return relationship('User', lazy='joined')
3406
3407 @declared_attr
3408 def source_repo(cls):
3409 return relationship(
3410 'Repository',
3411 primaryjoin='%s.source_repo_id==Repository.repo_id' % cls.__name__)
3412
3413 @property
3414 def source_ref_parts(self):
3415 return self.unicode_to_reference(self.source_ref)
3416
3417 @declared_attr
3418 def target_repo(cls):
3419 return relationship(
3420 'Repository',
3421 primaryjoin='%s.target_repo_id==Repository.repo_id' % cls.__name__)
3422
3423 @property
3424 def target_ref_parts(self):
3425 return self.unicode_to_reference(self.target_ref)
3426
3427 @property
3428 def shadow_merge_ref(self):
3429 return self.unicode_to_reference(self._shadow_merge_ref)
3430
3431 @shadow_merge_ref.setter
3432 def shadow_merge_ref(self, ref):
3433 self._shadow_merge_ref = self.reference_to_unicode(ref)
3434
3435 def unicode_to_reference(self, raw):
3436 """
3437 Convert a unicode (or string) to a reference object.
3438 If unicode evaluates to False it returns None.
3439 """
3440 if raw:
3441 refs = raw.split(':')
3442 return Reference(*refs)
3443 else:
3444 return None
3445
3446 def reference_to_unicode(self, ref):
3447 """
3448 Convert a reference object to unicode.
3449 If reference is None it returns None.
3450 """
3451 if ref:
3452 return u':'.join(ref)
3453 else:
3454 return None
3455
3456 def get_api_data(self, with_merge_state=True):
3457 from rhodecode.model.pull_request import PullRequestModel
3458
3459 pull_request = self
3460 if with_merge_state:
3461 merge_status = PullRequestModel().merge_status(pull_request)
3462 merge_state = {
3463 'status': merge_status[0],
3464 'message': safe_unicode(merge_status[1]),
3465 }
3466 else:
3467 merge_state = {'status': 'not_available',
3468 'message': 'not_available'}
3469
3470 merge_data = {
3471 'clone_url': PullRequestModel().get_shadow_clone_url(pull_request),
3472 'reference': (
3473 pull_request.shadow_merge_ref._asdict()
3474 if pull_request.shadow_merge_ref else None),
3475 }
3476
3477 data = {
3478 'pull_request_id': pull_request.pull_request_id,
3479 'url': PullRequestModel().get_url(pull_request),
3480 'title': pull_request.title,
3481 'description': pull_request.description,
3482 'status': pull_request.status,
3483 'created_on': pull_request.created_on,
3484 'updated_on': pull_request.updated_on,
3485 'commit_ids': pull_request.revisions,
3486 'review_status': pull_request.calculated_review_status(),
3487 'mergeable': merge_state,
3488 'source': {
3489 'clone_url': pull_request.source_repo.clone_url(),
3490 'repository': pull_request.source_repo.repo_name,
3491 'reference': {
3492 'name': pull_request.source_ref_parts.name,
3493 'type': pull_request.source_ref_parts.type,
3494 'commit_id': pull_request.source_ref_parts.commit_id,
3495 },
3496 },
3497 'target': {
3498 'clone_url': pull_request.target_repo.clone_url(),
3499 'repository': pull_request.target_repo.repo_name,
3500 'reference': {
3501 'name': pull_request.target_ref_parts.name,
3502 'type': pull_request.target_ref_parts.type,
3503 'commit_id': pull_request.target_ref_parts.commit_id,
3504 },
3505 },
3506 'merge': merge_data,
3507 'author': pull_request.author.get_api_data(include_secrets=False,
3508 details='basic'),
3509 'reviewers': [
3510 {
3511 'user': reviewer.get_api_data(include_secrets=False,
3512 details='basic'),
3513 'reasons': reasons,
3514 'review_status': st[0][1].status if st else 'not_reviewed',
3515 }
3516 for reviewer, reasons, mandatory, st in
3517 pull_request.reviewers_statuses()
3518 ]
3519 }
3520
3521 return data
3522
3523
3524 class PullRequest(Base, _PullRequestBase):
3525 __tablename__ = 'pull_requests'
3526 __table_args__ = (
3527 {'extend_existing': True, 'mysql_engine': 'InnoDB',
3528 'mysql_charset': 'utf8', 'sqlite_autoincrement': True},
3529 )
3530
3531 pull_request_id = Column(
3532 'pull_request_id', Integer(), nullable=False, primary_key=True)
3533
3534 def __repr__(self):
3535 if self.pull_request_id:
3536 return '<DB:PullRequest #%s>' % self.pull_request_id
3537 else:
3538 return '<DB:PullRequest at %#x>' % id(self)
3539
3540 reviewers = relationship('PullRequestReviewers',
3541 cascade="all, delete, delete-orphan")
3542 statuses = relationship('ChangesetStatus',
3543 cascade="all, delete, delete-orphan")
3544 comments = relationship('ChangesetComment',
3545 cascade="all, delete, delete-orphan")
3546 versions = relationship('PullRequestVersion',
3547 cascade="all, delete, delete-orphan",
3548 lazy='dynamic')
3549
3550 @classmethod
3551 def get_pr_display_object(cls, pull_request_obj, org_pull_request_obj,
3552 internal_methods=None):
3553
3554 class PullRequestDisplay(object):
3555 """
3556 Special object wrapper for showing PullRequest data via Versions
3557 It mimics PR object as close as possible. This is read only object
3558 just for display
3559 """
3560
3561 def __init__(self, attrs, internal=None):
3562 self.attrs = attrs
3563 # internal have priority over the given ones via attrs
3564 self.internal = internal or ['versions']
3565
3566 def __getattr__(self, item):
3567 if item in self.internal:
3568 return getattr(self, item)
3569 try:
3570 return self.attrs[item]
3571 except KeyError:
3572 raise AttributeError(
3573 '%s object has no attribute %s' % (self, item))
3574
3575 def __repr__(self):
3576 return '<DB:PullRequestDisplay #%s>' % self.attrs.get('pull_request_id')
3577
3578 def versions(self):
3579 return pull_request_obj.versions.order_by(
3580 PullRequestVersion.pull_request_version_id).all()
3581
3582 def is_closed(self):
3583 return pull_request_obj.is_closed()
3584
3585 @property
3586 def pull_request_version_id(self):
3587 return getattr(pull_request_obj, 'pull_request_version_id', None)
3588
3589 attrs = StrictAttributeDict(pull_request_obj.get_api_data())
3590
3591 attrs.author = StrictAttributeDict(
3592 pull_request_obj.author.get_api_data())
3593 if pull_request_obj.target_repo:
3594 attrs.target_repo = StrictAttributeDict(
3595 pull_request_obj.target_repo.get_api_data())
3596 attrs.target_repo.clone_url = pull_request_obj.target_repo.clone_url
3597
3598 if pull_request_obj.source_repo:
3599 attrs.source_repo = StrictAttributeDict(
3600 pull_request_obj.source_repo.get_api_data())
3601 attrs.source_repo.clone_url = pull_request_obj.source_repo.clone_url
3602
3603 attrs.source_ref_parts = pull_request_obj.source_ref_parts
3604 attrs.target_ref_parts = pull_request_obj.target_ref_parts
3605 attrs.revisions = pull_request_obj.revisions
3606
3607 attrs.shadow_merge_ref = org_pull_request_obj.shadow_merge_ref
3608 attrs.reviewer_data = org_pull_request_obj.reviewer_data
3609 attrs.reviewer_data_json = org_pull_request_obj.reviewer_data_json
3610
3611 return PullRequestDisplay(attrs, internal=internal_methods)
3612
3613 def is_closed(self):
3614 return self.status == self.STATUS_CLOSED
3615
3616 def __json__(self):
3617 return {
3618 'revisions': self.revisions,
3619 }
3620
3621 def calculated_review_status(self):
3622 from rhodecode.model.changeset_status import ChangesetStatusModel
3623 return ChangesetStatusModel().calculated_review_status(self)
3624
3625 def reviewers_statuses(self):
3626 from rhodecode.model.changeset_status import ChangesetStatusModel
3627 return ChangesetStatusModel().reviewers_statuses(self)
3628
3629 @property
3630 def workspace_id(self):
3631 from rhodecode.model.pull_request import PullRequestModel
3632 return PullRequestModel()._workspace_id(self)
3633
3634 def get_shadow_repo(self):
3635 workspace_id = self.workspace_id
3636 vcs_obj = self.target_repo.scm_instance()
3637 shadow_repository_path = vcs_obj._get_shadow_repository_path(
3638 workspace_id)
3639 return vcs_obj._get_shadow_instance(shadow_repository_path)
3640
3641
3642 class PullRequestVersion(Base, _PullRequestBase):
3643 __tablename__ = 'pull_request_versions'
3644 __table_args__ = (
3645 {'extend_existing': True, 'mysql_engine': 'InnoDB',
3646 'mysql_charset': 'utf8', 'sqlite_autoincrement': True},
3647 )
3648
3649 pull_request_version_id = Column(
3650 'pull_request_version_id', Integer(), nullable=False, primary_key=True)
3651 pull_request_id = Column(
3652 'pull_request_id', Integer(),
3653 ForeignKey('pull_requests.pull_request_id'), nullable=False)
3654 pull_request = relationship('PullRequest')
3655
3656 def __repr__(self):
3657 if self.pull_request_version_id:
3658 return '<DB:PullRequestVersion #%s>' % self.pull_request_version_id
3659 else:
3660 return '<DB:PullRequestVersion at %#x>' % id(self)
3661
3662 @property
3663 def reviewers(self):
3664 return self.pull_request.reviewers
3665
3666 @property
3667 def versions(self):
3668 return self.pull_request.versions
3669
3670 def is_closed(self):
3671 # calculate from original
3672 return self.pull_request.status == self.STATUS_CLOSED
3673
3674 def calculated_review_status(self):
3675 return self.pull_request.calculated_review_status()
3676
3677 def reviewers_statuses(self):
3678 return self.pull_request.reviewers_statuses()
3679
3680
3681 class PullRequestReviewers(Base, BaseModel):
3682 __tablename__ = 'pull_request_reviewers'
3683 __table_args__ = (
3684 {'extend_existing': True, 'mysql_engine': 'InnoDB',
3685 'mysql_charset': 'utf8', 'sqlite_autoincrement': True},
3686 )
3687
3688 @hybrid_property
3689 def reasons(self):
3690 if not self._reasons:
3691 return []
3692 return self._reasons
3693
3694 @reasons.setter
3695 def reasons(self, val):
3696 val = val or []
3697 if any(not isinstance(x, basestring) for x in val):
3698 raise Exception('invalid reasons type, must be list of strings')
3699 self._reasons = val
3700
3701 pull_requests_reviewers_id = Column(
3702 'pull_requests_reviewers_id', Integer(), nullable=False,
3703 primary_key=True)
3704 pull_request_id = Column(
3705 "pull_request_id", Integer(),
3706 ForeignKey('pull_requests.pull_request_id'), nullable=False)
3707 user_id = Column(
3708 "user_id", Integer(), ForeignKey('users.user_id'), nullable=True)
3709 _reasons = Column(
3710 'reason', MutationList.as_mutable(
3711 JsonType('list', dialect_map=dict(mysql=UnicodeText(16384)))))
3712 mandatory = Column("mandatory", Boolean(), nullable=False, default=False)
3713 user = relationship('User')
3714 pull_request = relationship('PullRequest')
3715
3716
3717 class Notification(Base, BaseModel):
3718 __tablename__ = 'notifications'
3719 __table_args__ = (
3720 Index('notification_type_idx', 'type'),
3721 {'extend_existing': True, 'mysql_engine': 'InnoDB',
3722 'mysql_charset': 'utf8', 'sqlite_autoincrement': True},
3723 )
3724
3725 TYPE_CHANGESET_COMMENT = u'cs_comment'
3726 TYPE_MESSAGE = u'message'
3727 TYPE_MENTION = u'mention'
3728 TYPE_REGISTRATION = u'registration'
3729 TYPE_PULL_REQUEST = u'pull_request'
3730 TYPE_PULL_REQUEST_COMMENT = u'pull_request_comment'
3731
3732 notification_id = Column('notification_id', Integer(), nullable=False, primary_key=True)
3733 subject = Column('subject', Unicode(512), nullable=True)
3734 body = Column('body', UnicodeText().with_variant(UnicodeText(50000), 'mysql'), nullable=True)
3735 created_by = Column("created_by", Integer(), ForeignKey('users.user_id'), nullable=True)
3736 created_on = Column('created_on', DateTime(timezone=False), nullable=False, default=datetime.datetime.now)
3737 type_ = Column('type', Unicode(255))
3738
3739 created_by_user = relationship('User')
3740 notifications_to_users = relationship('UserNotification', lazy='joined',
3741 cascade="all, delete, delete-orphan")
3742
3743 @property
3744 def recipients(self):
3745 return [x.user for x in UserNotification.query()\
3746 .filter(UserNotification.notification == self)\
3747 .order_by(UserNotification.user_id.asc()).all()]
3748
3749 @classmethod
3750 def create(cls, created_by, subject, body, recipients, type_=None):
3751 if type_ is None:
3752 type_ = Notification.TYPE_MESSAGE
3753
3754 notification = cls()
3755 notification.created_by_user = created_by
3756 notification.subject = subject
3757 notification.body = body
3758 notification.type_ = type_
3759 notification.created_on = datetime.datetime.now()
3760
3761 for u in recipients:
3762 assoc = UserNotification()
3763 assoc.notification = notification
3764
3765 # if created_by is inside recipients mark his notification
3766 # as read
3767 if u.user_id == created_by.user_id:
3768 assoc.read = True
3769
3770 u.notifications.append(assoc)
3771 Session().add(notification)
3772
3773 return notification
3774
3775
3776 class UserNotification(Base, BaseModel):
3777 __tablename__ = 'user_to_notification'
3778 __table_args__ = (
3779 UniqueConstraint('user_id', 'notification_id'),
3780 {'extend_existing': True, 'mysql_engine': 'InnoDB',
3781 'mysql_charset': 'utf8', 'sqlite_autoincrement': True}
3782 )
3783 user_id = Column('user_id', Integer(), ForeignKey('users.user_id'), primary_key=True)
3784 notification_id = Column("notification_id", Integer(), ForeignKey('notifications.notification_id'), primary_key=True)
3785 read = Column('read', Boolean, default=False)
3786 sent_on = Column('sent_on', DateTime(timezone=False), nullable=True, unique=None)
3787
3788 user = relationship('User', lazy="joined")
3789 notification = relationship('Notification', lazy="joined",
3790 order_by=lambda: Notification.created_on.desc(),)
3791
3792 def mark_as_read(self):
3793 self.read = True
3794 Session().add(self)
3795
3796
3797 class Gist(Base, BaseModel):
3798 __tablename__ = 'gists'
3799 __table_args__ = (
3800 Index('g_gist_access_id_idx', 'gist_access_id'),
3801 Index('g_created_on_idx', 'created_on'),
3802 {'extend_existing': True, 'mysql_engine': 'InnoDB',
3803 'mysql_charset': 'utf8', 'sqlite_autoincrement': True}
3804 )
3805 GIST_PUBLIC = u'public'
3806 GIST_PRIVATE = u'private'
3807 DEFAULT_FILENAME = u'gistfile1.txt'
3808
3809 ACL_LEVEL_PUBLIC = u'acl_public'
3810 ACL_LEVEL_PRIVATE = u'acl_private'
3811
3812 gist_id = Column('gist_id', Integer(), primary_key=True)
3813 gist_access_id = Column('gist_access_id', Unicode(250))
3814 gist_description = Column('gist_description', UnicodeText().with_variant(UnicodeText(1024), 'mysql'))
3815 gist_owner = Column('user_id', Integer(), ForeignKey('users.user_id'), nullable=True)
3816 gist_expires = Column('gist_expires', Float(53), nullable=False)
3817 gist_type = Column('gist_type', Unicode(128), nullable=False)
3818 created_on = Column('created_on', DateTime(timezone=False), nullable=False, default=datetime.datetime.now)
3819 modified_at = Column('modified_at', DateTime(timezone=False), nullable=False, default=datetime.datetime.now)
3820 acl_level = Column('acl_level', Unicode(128), nullable=True)
3821
3822 owner = relationship('User')
3823
3824 def __repr__(self):
3825 return '<Gist:[%s]%s>' % (self.gist_type, self.gist_access_id)
3826
3827 @hybrid_property
3828 def description_safe(self):
3829 from rhodecode.lib import helpers as h
3830 return h.escape(self.gist_description)
3831
3832 @classmethod
3833 def get_or_404(cls, id_):
3834 from pyramid.httpexceptions import HTTPNotFound
3835
3836 res = cls.query().filter(cls.gist_access_id == id_).scalar()
3837 if not res:
3838 raise HTTPNotFound()
3839 return res
3840
3841 @classmethod
3842 def get_by_access_id(cls, gist_access_id):
3843 return cls.query().filter(cls.gist_access_id == gist_access_id).scalar()
3844
3845 def gist_url(self):
3846 from rhodecode.model.gist import GistModel
3847 return GistModel().get_url(self)
3848
3849 @classmethod
3850 def base_path(cls):
3851 """
3852 Returns base path when all gists are stored
3853
3854 :param cls:
3855 """
3856 from rhodecode.model.gist import GIST_STORE_LOC
3857 q = Session().query(RhodeCodeUi)\
3858 .filter(RhodeCodeUi.ui_key == URL_SEP)
3859 q = q.options(FromCache("sql_cache_short", "repository_repo_path"))
3860 return os.path.join(q.one().ui_value, GIST_STORE_LOC)
3861
3862 def get_api_data(self):
3863 """
3864 Common function for generating gist related data for API
3865 """
3866 gist = self
3867 data = {
3868 'gist_id': gist.gist_id,
3869 'type': gist.gist_type,
3870 'access_id': gist.gist_access_id,
3871 'description': gist.gist_description,
3872 'url': gist.gist_url(),
3873 'expires': gist.gist_expires,
3874 'created_on': gist.created_on,
3875 'modified_at': gist.modified_at,
3876 'content': None,
3877 'acl_level': gist.acl_level,
3878 }
3879 return data
3880
3881 def __json__(self):
3882 data = dict(
3883 )
3884 data.update(self.get_api_data())
3885 return data
3886 # SCM functions
3887
3888 def scm_instance(self, **kwargs):
3889 full_repo_path = os.path.join(self.base_path(), self.gist_access_id)
3890 return get_vcs_instance(
3891 repo_path=safe_str(full_repo_path), create=False)
3892
3893
3894 class ExternalIdentity(Base, BaseModel):
3895 __tablename__ = 'external_identities'
3896 __table_args__ = (
3897 Index('local_user_id_idx', 'local_user_id'),
3898 Index('external_id_idx', 'external_id'),
3899 {'extend_existing': True, 'mysql_engine': 'InnoDB',
3900 'mysql_charset': 'utf8'})
3901
3902 external_id = Column('external_id', Unicode(255), default=u'',
3903 primary_key=True)
3904 external_username = Column('external_username', Unicode(1024), default=u'')
3905 local_user_id = Column('local_user_id', Integer(),
3906 ForeignKey('users.user_id'), primary_key=True)
3907 provider_name = Column('provider_name', Unicode(255), default=u'',
3908 primary_key=True)
3909 access_token = Column('access_token', String(1024), default=u'')
3910 alt_token = Column('alt_token', String(1024), default=u'')
3911 token_secret = Column('token_secret', String(1024), default=u'')
3912
3913 @classmethod
3914 def by_external_id_and_provider(cls, external_id, provider_name,
3915 local_user_id=None):
3916 """
3917 Returns ExternalIdentity instance based on search params
3918
3919 :param external_id:
3920 :param provider_name:
3921 :return: ExternalIdentity
3922 """
3923 query = cls.query()
3924 query = query.filter(cls.external_id == external_id)
3925 query = query.filter(cls.provider_name == provider_name)
3926 if local_user_id:
3927 query = query.filter(cls.local_user_id == local_user_id)
3928 return query.first()
3929
3930 @classmethod
3931 def user_by_external_id_and_provider(cls, external_id, provider_name):
3932 """
3933 Returns User instance based on search params
3934
3935 :param external_id:
3936 :param provider_name:
3937 :return: User
3938 """
3939 query = User.query()
3940 query = query.filter(cls.external_id == external_id)
3941 query = query.filter(cls.provider_name == provider_name)
3942 query = query.filter(User.user_id == cls.local_user_id)
3943 return query.first()
3944
3945 @classmethod
3946 def by_local_user_id(cls, local_user_id):
3947 """
3948 Returns all tokens for user
3949
3950 :param local_user_id:
3951 :return: ExternalIdentity
3952 """
3953 query = cls.query()
3954 query = query.filter(cls.local_user_id == local_user_id)
3955 return query
3956
3957
3958 class Integration(Base, BaseModel):
3959 __tablename__ = 'integrations'
3960 __table_args__ = (
3961 {'extend_existing': True, 'mysql_engine': 'InnoDB',
3962 'mysql_charset': 'utf8', 'sqlite_autoincrement': True}
3963 )
3964
3965 integration_id = Column('integration_id', Integer(), primary_key=True)
3966 integration_type = Column('integration_type', String(255))
3967 enabled = Column('enabled', Boolean(), nullable=False)
3968 name = Column('name', String(255), nullable=False)
3969 child_repos_only = Column('child_repos_only', Boolean(), nullable=False,
3970 default=False)
3971
3972 settings = Column(
3973 'settings_json', MutationObj.as_mutable(
3974 JsonType(dialect_map=dict(mysql=UnicodeText(16384)))))
3975 repo_id = Column(
3976 'repo_id', Integer(), ForeignKey('repositories.repo_id'),
3977 nullable=True, unique=None, default=None)
3978 repo = relationship('Repository', lazy='joined')
3979
3980 repo_group_id = Column(
3981 'repo_group_id', Integer(), ForeignKey('groups.group_id'),
3982 nullable=True, unique=None, default=None)
3983 repo_group = relationship('RepoGroup', lazy='joined')
3984
3985 @property
3986 def scope(self):
3987 if self.repo:
3988 return repr(self.repo)
3989 if self.repo_group:
3990 if self.child_repos_only:
3991 return repr(self.repo_group) + ' (child repos only)'
3992 else:
3993 return repr(self.repo_group) + ' (recursive)'
3994 if self.child_repos_only:
3995 return 'root_repos'
3996 return 'global'
3997
3998 def __repr__(self):
3999 return '<Integration(%r, %r)>' % (self.integration_type, self.scope)
4000
4001
4002 class RepoReviewRuleUser(Base, BaseModel):
4003 __tablename__ = 'repo_review_rules_users'
4004 __table_args__ = (
4005 {'extend_existing': True, 'mysql_engine': 'InnoDB',
4006 'mysql_charset': 'utf8', 'sqlite_autoincrement': True,}
4007 )
4008 repo_review_rule_user_id = Column('repo_review_rule_user_id', Integer(), primary_key=True)
4009 repo_review_rule_id = Column("repo_review_rule_id", Integer(), ForeignKey('repo_review_rules.repo_review_rule_id'))
4010 user_id = Column("user_id", Integer(), ForeignKey('users.user_id'), nullable=False)
4011 mandatory = Column("mandatory", Boolean(), nullable=False, default=False)
4012 user = relationship('User')
4013
4014 def rule_data(self):
4015 return {
4016 'mandatory': self.mandatory
4017 }
4018
4019
4020 class RepoReviewRuleUserGroup(Base, BaseModel):
4021 __tablename__ = 'repo_review_rules_users_groups'
4022 __table_args__ = (
4023 {'extend_existing': True, 'mysql_engine': 'InnoDB',
4024 'mysql_charset': 'utf8', 'sqlite_autoincrement': True,}
4025 )
4026 repo_review_rule_users_group_id = Column('repo_review_rule_users_group_id', Integer(), primary_key=True)
4027 repo_review_rule_id = Column("repo_review_rule_id", Integer(), ForeignKey('repo_review_rules.repo_review_rule_id'))
4028 users_group_id = Column("users_group_id", Integer(),ForeignKey('users_groups.users_group_id'), nullable=False)
4029 mandatory = Column("mandatory", Boolean(), nullable=False, default=False)
4030 users_group = relationship('UserGroup')
4031
4032 def rule_data(self):
4033 return {
4034 'mandatory': self.mandatory
4035 }
4036
4037
4038 class RepoReviewRule(Base, BaseModel):
4039 __tablename__ = 'repo_review_rules'
4040 __table_args__ = (
4041 {'extend_existing': True, 'mysql_engine': 'InnoDB',
4042 'mysql_charset': 'utf8', 'sqlite_autoincrement': True,}
4043 )
4044
4045 repo_review_rule_id = Column(
4046 'repo_review_rule_id', Integer(), primary_key=True)
4047 repo_id = Column(
4048 "repo_id", Integer(), ForeignKey('repositories.repo_id'))
4049 repo = relationship('Repository', backref='review_rules')
4050
4051 _branch_pattern = Column("branch_pattern", UnicodeText().with_variant(UnicodeText(255), 'mysql'), default=u'*') # glob
4052 _file_pattern = Column("file_pattern", UnicodeText().with_variant(UnicodeText(255), 'mysql'), default=u'*') # glob
4053
4054 use_authors_for_review = Column("use_authors_for_review", Boolean(), nullable=False, default=False)
4055 forbid_author_to_review = Column("forbid_author_to_review", Boolean(), nullable=False, default=False)
4056 forbid_commit_author_to_review = Column("forbid_commit_author_to_review", Boolean(), nullable=False, default=False)
4057 forbid_adding_reviewers = Column("forbid_adding_reviewers", Boolean(), nullable=False, default=False)
4058
4059 rule_users = relationship('RepoReviewRuleUser')
4060 rule_user_groups = relationship('RepoReviewRuleUserGroup')
4061
4062 @hybrid_property
4063 def branch_pattern(self):
4064 return self._branch_pattern or '*'
4065
4066 def _validate_glob(self, value):
4067 re.compile('^' + glob2re(value) + '$')
4068
4069 @branch_pattern.setter
4070 def branch_pattern(self, value):
4071 self._validate_glob(value)
4072 self._branch_pattern = value or '*'
4073
4074 @hybrid_property
4075 def file_pattern(self):
4076 return self._file_pattern or '*'
4077
4078 @file_pattern.setter
4079 def file_pattern(self, value):
4080 self._validate_glob(value)
4081 self._file_pattern = value or '*'
4082
4083 def matches(self, branch, files_changed):
4084 """
4085 Check if this review rule matches a branch/files in a pull request
4086
4087 :param branch: branch name for the commit
4088 :param files_changed: list of file paths changed in the pull request
4089 """
4090
4091 branch = branch or ''
4092 files_changed = files_changed or []
4093
4094 branch_matches = True
4095 if branch:
4096 branch_regex = re.compile('^' + glob2re(self.branch_pattern) + '$')
4097 branch_matches = bool(branch_regex.search(branch))
4098
4099 files_matches = True
4100 if self.file_pattern != '*':
4101 files_matches = False
4102 file_regex = re.compile(glob2re(self.file_pattern))
4103 for filename in files_changed:
4104 if file_regex.search(filename):
4105 files_matches = True
4106 break
4107
4108 return branch_matches and files_matches
4109
4110 @property
4111 def review_users(self):
4112 """ Returns the users which this rule applies to """
4113
4114 users = collections.OrderedDict()
4115
4116 for rule_user in self.rule_users:
4117 if rule_user.user.active:
4118 if rule_user.user not in users:
4119 users[rule_user.user.username] = {
4120 'user': rule_user.user,
4121 'source': 'user',
4122 'source_data': {},
4123 'data': rule_user.rule_data()
4124 }
4125
4126 for rule_user_group in self.rule_user_groups:
4127 source_data = {
4128 'name': rule_user_group.users_group.users_group_name,
4129 'members': len(rule_user_group.users_group.members)
4130 }
4131 for member in rule_user_group.users_group.members:
4132 if member.user.active:
4133 users[member.user.username] = {
4134 'user': member.user,
4135 'source': 'user_group',
4136 'source_data': source_data,
4137 'data': rule_user_group.rule_data()
4138 }
4139
4140 return users
4141
4142 def __repr__(self):
4143 return '<RepoReviewerRule(id=%r, repo=%r)>' % (
4144 self.repo_review_rule_id, self.repo)
4145
4146
4147 class DbMigrateVersion(Base, BaseModel):
4148 __tablename__ = 'db_migrate_version'
4149 __table_args__ = (
4150 {'extend_existing': True, 'mysql_engine': 'InnoDB',
4151 'mysql_charset': 'utf8', 'sqlite_autoincrement': True},
4152 )
4153 repository_id = Column('repository_id', String(250), primary_key=True)
4154 repository_path = Column('repository_path', Text)
4155 version = Column('version', Integer)
4156
4157
4158 class DbSession(Base, BaseModel):
4159 __tablename__ = 'db_session'
4160 __table_args__ = (
4161 {'extend_existing': True, 'mysql_engine': 'InnoDB',
4162 'mysql_charset': 'utf8', 'sqlite_autoincrement': True},
4163 )
4164
4165 def __repr__(self):
4166 return '<DB:DbSession({})>'.format(self.id)
4167
4168 id = Column('id', Integer())
4169 namespace = Column('namespace', String(255), primary_key=True)
4170 accessed = Column('accessed', DateTime, nullable=False)
4171 created = Column('created', DateTime, nullable=False)
4172 data = Column('data', PickleType, nullable=False)
@@ -0,0 +1,29 b''
1 import logging
2
3 from sqlalchemy import *
4 from rhodecode.model import meta
5 from rhodecode.lib.dbmigrate.versions import _reset_base, notify
6
7 log = logging.getLogger(__name__)
8
9
10 def upgrade(migrate_engine):
11 """
12 Upgrade operations go here.
13 Don't create your own engine; bind migrate_engine to your metadata
14 """
15 _reset_base(migrate_engine)
16 from rhodecode.lib.dbmigrate.schema import db_4_9_0_0 as db
17
18 db.UserSshKeys.__table__.create()
19
20 fixups(db, meta.Session)
21
22
23 def downgrade(migrate_engine):
24 meta = MetaData()
25 meta.bind = migrate_engine
26
27
28 def fixups(models, _SESSION):
29 pass
@@ -0,0 +1,123 b''
1 # -*- coding: utf-8 -*-
2
3 # Copyright (C) 2013-2017 RhodeCode GmbH
4 #
5 # This program is free software: you can redistribute it and/or modify
6 # it under the terms of the GNU Affero General Public License, version 3
7 # (only), as published by the Free Software Foundation.
8 #
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
13 #
14 # You should have received a copy of the GNU Affero General Public License
15 # along with this program. If not, see <http://www.gnu.org/licenses/>.
16 #
17 # This program is dual-licensed. If you wish to learn more about the
18 # RhodeCode Enterprise Edition, including its added features, Support services,
19 # and proprietary license terms, please see https://rhodecode.com/licenses/
20
21 import logging
22 import traceback
23
24 import sshpubkeys
25 import sshpubkeys.exceptions
26
27 from rhodecode.model import BaseModel
28 from rhodecode.model.db import UserSshKeys
29 from rhodecode.model.meta import Session
30
31 log = logging.getLogger(__name__)
32
33
34 class SshKeyModel(BaseModel):
35 cls = UserSshKeys
36
37 def parse_key(self, key_data):
38 """
39 print(ssh.bits) # 768
40 print(ssh.hash_md5()) # 56:84:1e:90:08:3b:60:c7:29:70:5f:5e:25:a6:3b:86
41 print(ssh.hash_sha256()) # SHA256:xk3IEJIdIoR9MmSRXTP98rjDdZocmXJje/28ohMQEwM
42 print(ssh.hash_sha512()) # SHA512:1C3lNBhjpDVQe39hnyy+xvlZYU3IPwzqK1rVneGavy6O3/ebjEQSFvmeWoyMTplIanmUK1hmr9nA8Skmj516HA
43 print(ssh.comment) # ojar@ojar-laptop
44 print(ssh.options_raw) # None (string of optional options at the beginning of public key)
45 print(ssh.options) # None (options as a dictionary, parsed and validated)
46
47 :param key_data:
48 :return:
49 """
50 ssh = sshpubkeys.SSHKey(strict_mode=True)
51 try:
52 ssh.parse(key_data)
53 return ssh
54 except sshpubkeys.exceptions.InvalidKeyException as err:
55 log.error("Invalid key: %s", err)
56 raise
57 except NotImplementedError as err:
58 log.error("Invalid key type: %s", err)
59 raise
60 except Exception as err:
61 log.error("Key Parse error: %s", err)
62 raise
63
64 def generate_keypair(self, comment=None):
65 from Crypto.PublicKey import RSA
66
67 key = RSA.generate(2048)
68 private = key.exportKey('PEM')
69
70 pubkey = key.publickey()
71 public = pubkey.exportKey('OpenSSH')
72 if comment:
73 public = public + " " + comment
74 return private, public
75
76 def create(self, user, fingerprint, key_data, description):
77 """
78 """
79 user = self._get_user(user)
80
81 new_ssh_key = UserSshKeys()
82 new_ssh_key.ssh_key_fingerprint = fingerprint
83 new_ssh_key.ssh_key_data = key_data
84 new_ssh_key.user_id = user.user_id
85 new_ssh_key.description = description
86
87 Session().add(new_ssh_key)
88
89 return new_ssh_key
90
91 def delete(self, ssh_key_id, user=None):
92 """
93 Deletes given api_key, if user is set it also filters the object for
94 deletion by given user.
95 """
96 ssh_key = UserSshKeys.query().filter(
97 UserSshKeys.ssh_key_id == ssh_key_id)
98
99 if user:
100 user = self._get_user(user)
101 ssh_key = ssh_key.filter(UserSshKeys.user_id == user.user_id)
102 ssh_key = ssh_key.scalar()
103
104 if ssh_key:
105 try:
106 Session().delete(ssh_key)
107 except Exception:
108 log.error(traceback.format_exc())
109 raise
110
111 def get_ssh_keys(self, user):
112 user = self._get_user(user)
113 user_ssh_keys = UserSshKeys.query()\
114 .filter(UserSshKeys.user_id == user.user_id)
115 user_ssh_keys = user_ssh_keys.order_by(UserSshKeys.ssh_key_id)
116 return user_ssh_keys
117
118 def get_ssh_key_by_fingerprint(self, ssh_key_fingerprint):
119 user_ssh_key = UserSshKeys.query()\
120 .filter(UserSshKeys.ssh_key_fingerprint == ssh_key_fingerprint)\
121 .first()
122
123 return user_ssh_key
@@ -0,0 +1,78 b''
1 <div class="panel panel-default">
2 <div class="panel-heading">
3 <h3 class="panel-title">${_('SSH Keys')}</h3>
4 </div>
5 <div class="panel-body">
6 <div class="sshkeys_wrap">
7 <table class="rctable ssh_keys">
8 <tr>
9 <th>${_('Fingerprint')}</th>
10 <th>${_('Description')}</th>
11 <th>${_('Created')}</th>
12 <th>${_('Action')}</th>
13 </tr>
14 %if c.user_ssh_keys:
15 %for ssh_key in c.user_ssh_keys:
16 <tr class="">
17 <td class="">
18 <code>${ssh_key.ssh_key_fingerprint}</code>
19 </td>
20 <td class="td-wrap">${ssh_key.description}</td>
21 <td class="td-tags">${h.format_date(ssh_key.created_on)}</td>
22
23 <td class="td-action">
24 ${h.secure_form(h.route_path('edit_user_ssh_keys_delete', user_id=c.user.user_id), method='POST', request=request)}
25 ${h.hidden('del_ssh_key', ssh_key.ssh_key_id)}
26 <button class="btn btn-link btn-danger" type="submit"
27 onclick="return confirm('${_('Confirm to remove ssh key %s') % ssh_key.ssh_key_fingerprint}');">
28 ${_('Delete')}
29 </button>
30 ${h.end_form()}
31 </td>
32 </tr>
33 %endfor
34 %else:
35 <tr><td><div class="ip">${_('No additional ssh keys specified')}</div></td></tr>
36 %endif
37 </table>
38 </div>
39
40 <div class="user_ssh_keys">
41 ${h.secure_form(h.route_path('edit_user_ssh_keys_add', user_id=c.user.user_id), method='POST', request=request)}
42 <div class="form form-vertical">
43 <!-- fields -->
44 <div class="fields">
45 <div class="field">
46 <div class="label">
47 <label for="new_email">${_('New ssh key')}:</label>
48 </div>
49 <div class="input">
50 ${h.text('description', class_='medium', placeholder=_('Description'))}
51 <a href="${h.route_path('edit_user_ssh_keys_generate_keypair', user_id=c.user.user_id)}">${_('Generate random RSA key')}</a>
52 </div>
53 </div>
54
55 <div class="field">
56 <div class="textarea text-area editor">
57 ${h.textarea('key_data',c.default_key, size=30, placeholder=_("Public key, begins with 'ssh-rsa', 'ssh-dss', 'ssh-ed25519', 'ecdsa-sha2-nistp256', 'ecdsa-sha2-nistp384', or 'ecdsa-sha2-nistp521'"))}
58 </div>
59 </div>
60
61 <div class="buttons">
62 ${h.submit('save',_('Add'),class_="btn")}
63 ${h.reset('reset',_('Reset'),class_="btn")}
64 </div>
65 </div>
66 </div>
67 ${h.end_form()}
68 </div>
69 </div>
70 </div>
71
72 <script>
73
74 $(document).ready(function(){
75
76
77 });
78 </script>
@@ -0,0 +1,45 b''
1 <div class="panel panel-default">
2 <div class="panel-heading">
3 <h3 class="panel-title">${_('New SSH Key generated')}</h3>
4 </div>
5 <div class="panel-body">
6 <p>
7 ${_('Below is a 2048 bit generated SSH RSA key. You can use it to access RhodeCode via the SSH wrapper.')}
8 </p>
9 <h4>${_('Private key')}</h4>
10 <pre>
11 # Save the content as
12 ~/.ssh/id_rsa_rhodecode_access_priv.key
13 # Change permissions
14 chmod 0600 ~/.ssh/id_rsa_rhodecode_access_priv.key
15 </pre>
16
17 <div>
18 <textarea style="height: 300px">${c.private}</textarea>
19 </div>
20 <br/>
21
22
23 <h4>${_('Public key')}</h4>
24 <pre>
25 # Save the content as
26 ~/.ssh/id_rsa_rhodecode_access_pub.key
27 # Change permissions
28 chmod 0600 ~/.ssh/id_rsa_rhodecode_access_pub.key
29 </pre>
30
31 <input type="text" value="${c.public}" class="large text" size="100"/>
32 <p>
33 <a href="${h.route_path('edit_user_ssh_keys', user_id=c.user.user_id, _query=dict(default_key=c.public))}">${_('Add this generated key')}</a>
34 </p>
35
36 </div>
37 </div>
38
39 <script>
40
41 $(document).ready(function(){
42
43
44 });
45 </script>
@@ -1,2086 +1,2086 b''
1 1 # Generated by pip2nix 0.4.0
2 2 # See https://github.com/johbo/pip2nix
3 3
4 4 {
5 5 Babel = super.buildPythonPackage {
6 6 name = "Babel-1.3";
7 7 buildInputs = with self; [];
8 8 doCheck = false;
9 9 propagatedBuildInputs = with self; [pytz];
10 10 src = fetchurl {
11 11 url = "https://pypi.python.org/packages/33/27/e3978243a03a76398c384c83f7ca879bc6e8f1511233a621fcada135606e/Babel-1.3.tar.gz";
12 12 md5 = "5264ceb02717843cbc9ffce8e6e06bdb";
13 13 };
14 14 meta = {
15 15 license = [ pkgs.lib.licenses.bsdOriginal ];
16 16 };
17 17 };
18 18 Beaker = super.buildPythonPackage {
19 19 name = "Beaker-1.9.0";
20 20 buildInputs = with self; [];
21 21 doCheck = false;
22 22 propagatedBuildInputs = with self; [funcsigs];
23 23 src = fetchurl {
24 24 url = "https://pypi.python.org/packages/93/b2/12de6937b06e9615dbb3cb3a1c9af17f133f435bdef59f4ad42032b6eb49/Beaker-1.9.0.tar.gz";
25 25 md5 = "38b3fcdfa24faf97c6cf66991eb54e9c";
26 26 };
27 27 meta = {
28 28 license = [ pkgs.lib.licenses.bsdOriginal ];
29 29 };
30 30 };
31 31 CProfileV = super.buildPythonPackage {
32 32 name = "CProfileV-1.0.7";
33 33 buildInputs = with self; [];
34 34 doCheck = false;
35 35 propagatedBuildInputs = with self; [bottle];
36 36 src = fetchurl {
37 37 url = "https://pypi.python.org/packages/df/50/d8c1ada7d537c64b0f76453fa31dedb6af6e27b82fcf0331e5f71a4cf98b/CProfileV-1.0.7.tar.gz";
38 38 md5 = "db4c7640438aa3d8887e194c81c7a019";
39 39 };
40 40 meta = {
41 41 license = [ pkgs.lib.licenses.mit ];
42 42 };
43 43 };
44 44 Chameleon = super.buildPythonPackage {
45 45 name = "Chameleon-2.24";
46 46 buildInputs = with self; [];
47 47 doCheck = false;
48 48 propagatedBuildInputs = with self; [];
49 49 src = fetchurl {
50 50 url = "https://pypi.python.org/packages/5a/9e/637379ffa13c5172b5c0e704833ffea6bf51cec7567f93fd6e903d53ed74/Chameleon-2.24.tar.gz";
51 51 md5 = "1b01f1f6533a8a11d0d2f2366dec5342";
52 52 };
53 53 meta = {
54 54 license = [ { fullName = "BSD-like (http://repoze.org/license.html)"; } ];
55 55 };
56 56 };
57 57 FormEncode = super.buildPythonPackage {
58 58 name = "FormEncode-1.2.4";
59 59 buildInputs = with self; [];
60 60 doCheck = false;
61 61 propagatedBuildInputs = with self; [];
62 62 src = fetchurl {
63 63 url = "https://pypi.python.org/packages/8e/59/0174271a6f004512e0201188593e6d319db139d14cb7490e488bbb078015/FormEncode-1.2.4.tar.gz";
64 64 md5 = "6bc17fb9aed8aea198975e888e2077f4";
65 65 };
66 66 meta = {
67 67 license = [ pkgs.lib.licenses.psfl ];
68 68 };
69 69 };
70 70 Jinja2 = super.buildPythonPackage {
71 71 name = "Jinja2-2.7.3";
72 72 buildInputs = with self; [];
73 73 doCheck = false;
74 74 propagatedBuildInputs = with self; [MarkupSafe];
75 75 src = fetchurl {
76 76 url = "https://pypi.python.org/packages/b0/73/eab0bca302d6d6a0b5c402f47ad1760dc9cb2dd14bbc1873ad48db258e4d/Jinja2-2.7.3.tar.gz";
77 77 md5 = "b9dffd2f3b43d673802fe857c8445b1a";
78 78 };
79 79 meta = {
80 80 license = [ pkgs.lib.licenses.bsdOriginal ];
81 81 };
82 82 };
83 83 Mako = super.buildPythonPackage {
84 84 name = "Mako-1.0.6";
85 85 buildInputs = with self; [];
86 86 doCheck = false;
87 87 propagatedBuildInputs = with self; [MarkupSafe];
88 88 src = fetchurl {
89 89 url = "https://pypi.python.org/packages/56/4b/cb75836863a6382199aefb3d3809937e21fa4cb0db15a4f4ba0ecc2e7e8e/Mako-1.0.6.tar.gz";
90 90 md5 = "a28e22a339080316b2acc352b9ee631c";
91 91 };
92 92 meta = {
93 93 license = [ pkgs.lib.licenses.mit ];
94 94 };
95 95 };
96 96 Markdown = super.buildPythonPackage {
97 97 name = "Markdown-2.6.8";
98 98 buildInputs = with self; [];
99 99 doCheck = false;
100 100 propagatedBuildInputs = with self; [];
101 101 src = fetchurl {
102 102 url = "https://pypi.python.org/packages/1d/25/3f6d2cb31ec42ca5bd3bfbea99b63892b735d76e26f20dd2dcc34ffe4f0d/Markdown-2.6.8.tar.gz";
103 103 md5 = "d9ef057a5bd185f6f536400a31fc5d45";
104 104 };
105 105 meta = {
106 106 license = [ pkgs.lib.licenses.bsdOriginal ];
107 107 };
108 108 };
109 109 MarkupSafe = super.buildPythonPackage {
110 110 name = "MarkupSafe-0.23";
111 111 buildInputs = with self; [];
112 112 doCheck = false;
113 113 propagatedBuildInputs = with self; [];
114 114 src = fetchurl {
115 115 url = "https://pypi.python.org/packages/c0/41/bae1254e0396c0cc8cf1751cb7d9afc90a602353695af5952530482c963f/MarkupSafe-0.23.tar.gz";
116 116 md5 = "f5ab3deee4c37cd6a922fb81e730da6e";
117 117 };
118 118 meta = {
119 119 license = [ pkgs.lib.licenses.bsdOriginal ];
120 120 };
121 121 };
122 122 MySQL-python = super.buildPythonPackage {
123 123 name = "MySQL-python-1.2.5";
124 124 buildInputs = with self; [];
125 125 doCheck = false;
126 126 propagatedBuildInputs = with self; [];
127 127 src = fetchurl {
128 128 url = "https://pypi.python.org/packages/a5/e9/51b544da85a36a68debe7a7091f068d802fc515a3a202652828c73453cad/MySQL-python-1.2.5.zip";
129 129 md5 = "654f75b302db6ed8dc5a898c625e030c";
130 130 };
131 131 meta = {
132 132 license = [ pkgs.lib.licenses.gpl1 ];
133 133 };
134 134 };
135 135 Paste = super.buildPythonPackage {
136 136 name = "Paste-2.0.3";
137 137 buildInputs = with self; [];
138 138 doCheck = false;
139 139 propagatedBuildInputs = with self; [six];
140 140 src = fetchurl {
141 141 url = "https://pypi.python.org/packages/30/c3/5c2f7c7a02e4f58d4454353fa1c32c94f79fa4e36d07a67c0ac295ea369e/Paste-2.0.3.tar.gz";
142 142 md5 = "1231e14eae62fa7ed76e9130b04bc61e";
143 143 };
144 144 meta = {
145 145 license = [ pkgs.lib.licenses.mit ];
146 146 };
147 147 };
148 148 PasteDeploy = super.buildPythonPackage {
149 149 name = "PasteDeploy-1.5.2";
150 150 buildInputs = with self; [];
151 151 doCheck = false;
152 152 propagatedBuildInputs = with self; [];
153 153 src = fetchurl {
154 154 url = "https://pypi.python.org/packages/0f/90/8e20cdae206c543ea10793cbf4136eb9a8b3f417e04e40a29d72d9922cbd/PasteDeploy-1.5.2.tar.gz";
155 155 md5 = "352b7205c78c8de4987578d19431af3b";
156 156 };
157 157 meta = {
158 158 license = [ pkgs.lib.licenses.mit ];
159 159 };
160 160 };
161 161 PasteScript = super.buildPythonPackage {
162 162 name = "PasteScript-1.7.5";
163 163 buildInputs = with self; [];
164 164 doCheck = false;
165 165 propagatedBuildInputs = with self; [Paste PasteDeploy];
166 166 src = fetchurl {
167 167 url = "https://pypi.python.org/packages/a5/05/fc60efa7c2f17a1dbaeccb2a903a1e90902d92b9d00eebabe3095829d806/PasteScript-1.7.5.tar.gz";
168 168 md5 = "4c72d78dcb6bb993f30536842c16af4d";
169 169 };
170 170 meta = {
171 171 license = [ pkgs.lib.licenses.mit ];
172 172 };
173 173 };
174 174 Pygments = super.buildPythonPackage {
175 175 name = "Pygments-2.2.0";
176 176 buildInputs = with self; [];
177 177 doCheck = false;
178 178 propagatedBuildInputs = with self; [];
179 179 src = fetchurl {
180 180 url = "https://pypi.python.org/packages/71/2a/2e4e77803a8bd6408a2903340ac498cb0a2181811af7c9ec92cb70b0308a/Pygments-2.2.0.tar.gz";
181 181 md5 = "13037baca42f16917cbd5ad2fab50844";
182 182 };
183 183 meta = {
184 184 license = [ pkgs.lib.licenses.bsdOriginal ];
185 185 };
186 186 };
187 187 Pylons = super.buildPythonPackage {
188 188 name = "Pylons-1.0.2.dev20170630";
189 189 buildInputs = with self; [];
190 190 doCheck = false;
191 191 propagatedBuildInputs = with self; [Routes WebHelpers Beaker Paste PasteDeploy PasteScript FormEncode simplejson decorator nose Mako WebError WebTest Tempita MarkupSafe WebOb];
192 192 src = fetchurl {
193 193 url = "https://code.rhodecode.com/upstream/pylons/archive/707354ee4261b9c10450404fc9852ccea4fd667d.tar.gz?md5=f26633726fa2cd3a340316ee6a5d218f";
194 194 md5 = "f26633726fa2cd3a340316ee6a5d218f";
195 195 };
196 196 meta = {
197 197 license = [ pkgs.lib.licenses.bsdOriginal ];
198 198 };
199 199 };
200 200 Routes = super.buildPythonPackage {
201 201 name = "Routes-1.13";
202 202 buildInputs = with self; [];
203 203 doCheck = false;
204 204 propagatedBuildInputs = with self; [repoze.lru];
205 205 src = fetchurl {
206 206 url = "https://pypi.python.org/packages/88/d3/259c3b3cde8837eb9441ab5f574a660e8a4acea8f54a078441d4d2acac1c/Routes-1.13.tar.gz";
207 207 md5 = "d527b0ab7dd9172b1275a41f97448783";
208 208 };
209 209 meta = {
210 210 license = [ pkgs.lib.licenses.bsdOriginal ];
211 211 };
212 212 };
213 213 SQLAlchemy = super.buildPythonPackage {
214 214 name = "SQLAlchemy-1.1.11";
215 215 buildInputs = with self; [];
216 216 doCheck = false;
217 217 propagatedBuildInputs = with self; [];
218 218 src = fetchurl {
219 219 url = "https://pypi.python.org/packages/59/f1/28f2205c3175e6bf32300c0f30f9d91dbc9eb910debbff3ffecb88d18528/SQLAlchemy-1.1.11.tar.gz";
220 220 md5 = "3de387eddb4012083a4562928c511e43";
221 221 };
222 222 meta = {
223 223 license = [ pkgs.lib.licenses.mit ];
224 224 };
225 225 };
226 226 Sphinx = super.buildPythonPackage {
227 227 name = "Sphinx-1.2.2";
228 228 buildInputs = with self; [];
229 229 doCheck = false;
230 230 propagatedBuildInputs = with self; [Pygments docutils Jinja2];
231 231 src = fetchurl {
232 232 url = "https://pypi.python.org/packages/0a/50/34017e6efcd372893a416aba14b84a1a149fc7074537b0e9cb6ca7b7abe9/Sphinx-1.2.2.tar.gz";
233 233 md5 = "3dc73ccaa8d0bfb2d62fb671b1f7e8a4";
234 234 };
235 235 meta = {
236 236 license = [ pkgs.lib.licenses.bsdOriginal ];
237 237 };
238 238 };
239 239 Tempita = super.buildPythonPackage {
240 240 name = "Tempita-0.5.2";
241 241 buildInputs = with self; [];
242 242 doCheck = false;
243 243 propagatedBuildInputs = with self; [];
244 244 src = fetchurl {
245 245 url = "https://pypi.python.org/packages/56/c8/8ed6eee83dbddf7b0fc64dd5d4454bc05e6ccaafff47991f73f2894d9ff4/Tempita-0.5.2.tar.gz";
246 246 md5 = "4c2f17bb9d481821c41b6fbee904cea1";
247 247 };
248 248 meta = {
249 249 license = [ pkgs.lib.licenses.mit ];
250 250 };
251 251 };
252 252 URLObject = super.buildPythonPackage {
253 253 name = "URLObject-2.4.0";
254 254 buildInputs = with self; [];
255 255 doCheck = false;
256 256 propagatedBuildInputs = with self; [];
257 257 src = fetchurl {
258 258 url = "https://pypi.python.org/packages/cb/b6/e25e58500f9caef85d664bec71ec67c116897bfebf8622c32cb75d1ca199/URLObject-2.4.0.tar.gz";
259 259 md5 = "2ed819738a9f0a3051f31dc9924e3065";
260 260 };
261 261 meta = {
262 262 license = [ ];
263 263 };
264 264 };
265 265 WebError = super.buildPythonPackage {
266 266 name = "WebError-0.10.3";
267 267 buildInputs = with self; [];
268 268 doCheck = false;
269 269 propagatedBuildInputs = with self; [WebOb Tempita Pygments Paste];
270 270 src = fetchurl {
271 271 url = "https://pypi.python.org/packages/35/76/e7e5c2ce7e9c7f31b54c1ff295a495886d1279a002557d74dd8957346a79/WebError-0.10.3.tar.gz";
272 272 md5 = "84b9990b0baae6fd440b1e60cdd06f9a";
273 273 };
274 274 meta = {
275 275 license = [ pkgs.lib.licenses.mit ];
276 276 };
277 277 };
278 278 WebHelpers = super.buildPythonPackage {
279 279 name = "WebHelpers-1.3";
280 280 buildInputs = with self; [];
281 281 doCheck = false;
282 282 propagatedBuildInputs = with self; [MarkupSafe];
283 283 src = fetchurl {
284 284 url = "https://pypi.python.org/packages/ee/68/4d07672821d514184357f1552f2dad923324f597e722de3b016ca4f7844f/WebHelpers-1.3.tar.gz";
285 285 md5 = "32749ffadfc40fea51075a7def32588b";
286 286 };
287 287 meta = {
288 288 license = [ pkgs.lib.licenses.bsdOriginal ];
289 289 };
290 290 };
291 291 WebHelpers2 = super.buildPythonPackage {
292 292 name = "WebHelpers2-2.0";
293 293 buildInputs = with self; [];
294 294 doCheck = false;
295 295 propagatedBuildInputs = with self; [MarkupSafe six];
296 296 src = fetchurl {
297 297 url = "https://pypi.python.org/packages/ff/30/56342c6ea522439e3662427c8d7b5e5b390dff4ff2dc92d8afcb8ab68b75/WebHelpers2-2.0.tar.gz";
298 298 md5 = "0f6b68d70c12ee0aed48c00b24da13d3";
299 299 };
300 300 meta = {
301 301 license = [ pkgs.lib.licenses.mit ];
302 302 };
303 303 };
304 304 WebOb = super.buildPythonPackage {
305 305 name = "WebOb-1.7.3";
306 306 buildInputs = with self; [];
307 307 doCheck = false;
308 308 propagatedBuildInputs = with self; [];
309 309 src = fetchurl {
310 310 url = "https://pypi.python.org/packages/46/87/2f96d8d43b2078fae6e1d33fa86b95c228cebed060f4e3c7576cc44ea83b/WebOb-1.7.3.tar.gz";
311 311 md5 = "350028baffc508e3d23c078118e35316";
312 312 };
313 313 meta = {
314 314 license = [ pkgs.lib.licenses.mit ];
315 315 };
316 316 };
317 317 WebTest = super.buildPythonPackage {
318 318 name = "WebTest-2.0.27";
319 319 buildInputs = with self; [];
320 320 doCheck = false;
321 321 propagatedBuildInputs = with self; [six WebOb waitress beautifulsoup4];
322 322 src = fetchurl {
323 323 url = "https://pypi.python.org/packages/80/fa/ca3a759985c72e3a124cbca3e1f8a2e931a07ffd31fd45d8f7bf21cb95cf/WebTest-2.0.27.tar.gz";
324 324 md5 = "54e6515ac71c51b6fc90179483c749ad";
325 325 };
326 326 meta = {
327 327 license = [ pkgs.lib.licenses.mit ];
328 328 };
329 329 };
330 330 Whoosh = super.buildPythonPackage {
331 331 name = "Whoosh-2.7.4";
332 332 buildInputs = with self; [];
333 333 doCheck = false;
334 334 propagatedBuildInputs = with self; [];
335 335 src = fetchurl {
336 336 url = "https://pypi.python.org/packages/25/2b/6beed2107b148edc1321da0d489afc4617b9ed317ef7b72d4993cad9b684/Whoosh-2.7.4.tar.gz";
337 337 md5 = "c2710105f20b3e29936bd2357383c325";
338 338 };
339 339 meta = {
340 340 license = [ pkgs.lib.licenses.bsdOriginal pkgs.lib.licenses.bsd2 ];
341 341 };
342 342 };
343 343 alembic = super.buildPythonPackage {
344 344 name = "alembic-0.9.2";
345 345 buildInputs = with self; [];
346 346 doCheck = false;
347 347 propagatedBuildInputs = with self; [SQLAlchemy Mako python-editor python-dateutil];
348 348 src = fetchurl {
349 349 url = "https://pypi.python.org/packages/78/48/b5b26e7218b415f40b60b92c53853d242e5456c0f19f6c66101d98ff5f2a/alembic-0.9.2.tar.gz";
350 350 md5 = "40daf8bae50969beea40efaaf0839ff4";
351 351 };
352 352 meta = {
353 353 license = [ pkgs.lib.licenses.mit ];
354 354 };
355 355 };
356 356 amqplib = super.buildPythonPackage {
357 357 name = "amqplib-1.0.2";
358 358 buildInputs = with self; [];
359 359 doCheck = false;
360 360 propagatedBuildInputs = with self; [];
361 361 src = fetchurl {
362 362 url = "https://pypi.python.org/packages/75/b7/8c2429bf8d92354a0118614f9a4d15e53bc69ebedce534284111de5a0102/amqplib-1.0.2.tgz";
363 363 md5 = "5c92f17fbedd99b2b4a836d4352d1e2f";
364 364 };
365 365 meta = {
366 366 license = [ { fullName = "LGPL"; } { fullName = "GNU Library or Lesser General Public License (LGPL)"; } ];
367 367 };
368 368 };
369 369 anyjson = super.buildPythonPackage {
370 370 name = "anyjson-0.3.3";
371 371 buildInputs = with self; [];
372 372 doCheck = false;
373 373 propagatedBuildInputs = with self; [];
374 374 src = fetchurl {
375 375 url = "https://pypi.python.org/packages/c3/4d/d4089e1a3dd25b46bebdb55a992b0797cff657b4477bc32ce28038fdecbc/anyjson-0.3.3.tar.gz";
376 376 md5 = "2ea28d6ec311aeeebaf993cb3008b27c";
377 377 };
378 378 meta = {
379 379 license = [ pkgs.lib.licenses.bsdOriginal ];
380 380 };
381 381 };
382 382 appenlight-client = super.buildPythonPackage {
383 383 name = "appenlight-client-0.6.21";
384 384 buildInputs = with self; [];
385 385 doCheck = false;
386 386 propagatedBuildInputs = with self; [WebOb requests six];
387 387 src = fetchurl {
388 388 url = "https://pypi.python.org/packages/c9/23/91b66cfa0b963662c10b2a06ccaadf3f3a4848a7a2aa16255cb43d5160ec/appenlight_client-0.6.21.tar.gz";
389 389 md5 = "273999ac854fdaefa8d0fb61965a4ed9";
390 390 };
391 391 meta = {
392 392 license = [ pkgs.lib.licenses.bsdOriginal ];
393 393 };
394 394 };
395 395 authomatic = super.buildPythonPackage {
396 396 name = "authomatic-0.1.0.post1";
397 397 buildInputs = with self; [];
398 398 doCheck = false;
399 399 propagatedBuildInputs = with self; [];
400 400 src = fetchurl {
401 401 url = "https://pypi.python.org/packages/08/1a/8a930461e604c2d5a7a871e1ac59fa82ccf994c32e807230c8d2fb07815a/Authomatic-0.1.0.post1.tar.gz";
402 402 md5 = "be3f3ce08747d776aae6d6cc8dcb49a9";
403 403 };
404 404 meta = {
405 405 license = [ pkgs.lib.licenses.mit ];
406 406 };
407 407 };
408 408 backports.shutil-get-terminal-size = super.buildPythonPackage {
409 409 name = "backports.shutil-get-terminal-size-1.0.0";
410 410 buildInputs = with self; [];
411 411 doCheck = false;
412 412 propagatedBuildInputs = with self; [];
413 413 src = fetchurl {
414 414 url = "https://pypi.python.org/packages/ec/9c/368086faa9c016efce5da3e0e13ba392c9db79e3ab740b763fe28620b18b/backports.shutil_get_terminal_size-1.0.0.tar.gz";
415 415 md5 = "03267762480bd86b50580dc19dff3c66";
416 416 };
417 417 meta = {
418 418 license = [ pkgs.lib.licenses.mit ];
419 419 };
420 420 };
421 421 beautifulsoup4 = super.buildPythonPackage {
422 422 name = "beautifulsoup4-4.6.0";
423 423 buildInputs = with self; [];
424 424 doCheck = false;
425 425 propagatedBuildInputs = with self; [];
426 426 src = fetchurl {
427 427 url = "https://pypi.python.org/packages/fa/8d/1d14391fdaed5abada4e0f63543fef49b8331a34ca60c88bd521bcf7f782/beautifulsoup4-4.6.0.tar.gz";
428 428 md5 = "c17714d0f91a23b708a592cb3c697728";
429 429 };
430 430 meta = {
431 431 license = [ pkgs.lib.licenses.mit ];
432 432 };
433 433 };
434 434 bleach = super.buildPythonPackage {
435 435 name = "bleach-1.5.0";
436 436 buildInputs = with self; [];
437 437 doCheck = false;
438 438 propagatedBuildInputs = with self; [six html5lib];
439 439 src = fetchurl {
440 440 url = "https://pypi.python.org/packages/99/00/25a8fce4de102bf6e3cc76bc4ea60685b2fee33bde1b34830c70cacc26a7/bleach-1.5.0.tar.gz";
441 441 md5 = "b663300efdf421b3b727b19d7be9c7e7";
442 442 };
443 443 meta = {
444 444 license = [ pkgs.lib.licenses.asl20 ];
445 445 };
446 446 };
447 447 bottle = super.buildPythonPackage {
448 448 name = "bottle-0.12.8";
449 449 buildInputs = with self; [];
450 450 doCheck = false;
451 451 propagatedBuildInputs = with self; [];
452 452 src = fetchurl {
453 453 url = "https://pypi.python.org/packages/52/df/e4a408f3a7af396d186d4ecd3b389dd764f0f943b4fa8d257bfe7b49d343/bottle-0.12.8.tar.gz";
454 454 md5 = "13132c0a8f607bf860810a6ee9064c5b";
455 455 };
456 456 meta = {
457 457 license = [ pkgs.lib.licenses.mit ];
458 458 };
459 459 };
460 460 bumpversion = super.buildPythonPackage {
461 461 name = "bumpversion-0.5.3";
462 462 buildInputs = with self; [];
463 463 doCheck = false;
464 464 propagatedBuildInputs = with self; [];
465 465 src = fetchurl {
466 466 url = "https://pypi.python.org/packages/14/41/8c9da3549f8e00c84f0432c3a8cf8ed6898374714676aab91501d48760db/bumpversion-0.5.3.tar.gz";
467 467 md5 = "c66a3492eafcf5ad4b024be9fca29820";
468 468 };
469 469 meta = {
470 470 license = [ pkgs.lib.licenses.mit ];
471 471 };
472 472 };
473 473 celery = super.buildPythonPackage {
474 474 name = "celery-2.2.10";
475 475 buildInputs = with self; [];
476 476 doCheck = false;
477 477 propagatedBuildInputs = with self; [python-dateutil anyjson kombu pyparsing];
478 478 src = fetchurl {
479 479 url = "https://pypi.python.org/packages/b1/64/860fd50e45844c83442e7953effcddeff66b2851d90b2d784f7201c111b8/celery-2.2.10.tar.gz";
480 480 md5 = "898bc87e54f278055b561316ba73e222";
481 481 };
482 482 meta = {
483 483 license = [ pkgs.lib.licenses.bsdOriginal ];
484 484 };
485 485 };
486 486 channelstream = super.buildPythonPackage {
487 487 name = "channelstream-0.5.2";
488 488 buildInputs = with self; [];
489 489 doCheck = false;
490 490 propagatedBuildInputs = with self; [gevent ws4py pyramid pyramid-jinja2 itsdangerous requests six];
491 491 src = fetchurl {
492 492 url = "https://pypi.python.org/packages/2b/31/29a8e085cf5bf97fa88e7b947adabfc581a18a3463adf77fb6dada34a65f/channelstream-0.5.2.tar.gz";
493 493 md5 = "1c5eb2a8a405be6f1073da94da6d81d3";
494 494 };
495 495 meta = {
496 496 license = [ pkgs.lib.licenses.bsdOriginal ];
497 497 };
498 498 };
499 499 click = super.buildPythonPackage {
500 500 name = "click-5.1";
501 501 buildInputs = with self; [];
502 502 doCheck = false;
503 503 propagatedBuildInputs = with self; [];
504 504 src = fetchurl {
505 505 url = "https://pypi.python.org/packages/b7/34/a496632c4fb6c1ee76efedf77bb8d28b29363d839953d95095b12defe791/click-5.1.tar.gz";
506 506 md5 = "9c5323008cccfe232a8b161fc8196d41";
507 507 };
508 508 meta = {
509 509 license = [ pkgs.lib.licenses.bsdOriginal ];
510 510 };
511 511 };
512 512 colander = super.buildPythonPackage {
513 513 name = "colander-1.3.3";
514 514 buildInputs = with self; [];
515 515 doCheck = false;
516 516 propagatedBuildInputs = with self; [translationstring iso8601];
517 517 src = fetchurl {
518 518 url = "https://pypi.python.org/packages/54/a9/9862a561e015b2c7b56404c0b13828a8bdc51e05ab3703bd792cec064487/colander-1.3.3.tar.gz";
519 519 md5 = "f5d783768c51d73695f49bbe95778ab4";
520 520 };
521 521 meta = {
522 522 license = [ { fullName = "BSD-derived (http://www.repoze.org/LICENSE.txt)"; } ];
523 523 };
524 524 };
525 525 configobj = super.buildPythonPackage {
526 526 name = "configobj-5.0.6";
527 527 buildInputs = with self; [];
528 528 doCheck = false;
529 529 propagatedBuildInputs = with self; [six];
530 530 src = fetchurl {
531 531 url = "https://pypi.python.org/packages/64/61/079eb60459c44929e684fa7d9e2fdca403f67d64dd9dbac27296be2e0fab/configobj-5.0.6.tar.gz";
532 532 md5 = "e472a3a1c2a67bb0ec9b5d54c13a47d6";
533 533 };
534 534 meta = {
535 535 license = [ pkgs.lib.licenses.bsdOriginal ];
536 536 };
537 537 };
538 538 configparser = super.buildPythonPackage {
539 539 name = "configparser-3.5.0";
540 540 buildInputs = with self; [];
541 541 doCheck = false;
542 542 propagatedBuildInputs = with self; [];
543 543 src = fetchurl {
544 544 url = "https://pypi.python.org/packages/7c/69/c2ce7e91c89dc073eb1aa74c0621c3eefbffe8216b3f9af9d3885265c01c/configparser-3.5.0.tar.gz";
545 545 md5 = "cfdd915a5b7a6c09917a64a573140538";
546 546 };
547 547 meta = {
548 548 license = [ pkgs.lib.licenses.mit ];
549 549 };
550 550 };
551 551 cov-core = super.buildPythonPackage {
552 552 name = "cov-core-1.15.0";
553 553 buildInputs = with self; [];
554 554 doCheck = false;
555 555 propagatedBuildInputs = with self; [coverage];
556 556 src = fetchurl {
557 557 url = "https://pypi.python.org/packages/4b/87/13e75a47b4ba1be06f29f6d807ca99638bedc6b57fa491cd3de891ca2923/cov-core-1.15.0.tar.gz";
558 558 md5 = "f519d4cb4c4e52856afb14af52919fe6";
559 559 };
560 560 meta = {
561 561 license = [ pkgs.lib.licenses.mit ];
562 562 };
563 563 };
564 564 coverage = super.buildPythonPackage {
565 565 name = "coverage-3.7.1";
566 566 buildInputs = with self; [];
567 567 doCheck = false;
568 568 propagatedBuildInputs = with self; [];
569 569 src = fetchurl {
570 570 url = "https://pypi.python.org/packages/09/4f/89b06c7fdc09687bca507dc411c342556ef9c5a3b26756137a4878ff19bf/coverage-3.7.1.tar.gz";
571 571 md5 = "c47b36ceb17eaff3ecfab3bcd347d0df";
572 572 };
573 573 meta = {
574 574 license = [ pkgs.lib.licenses.bsdOriginal ];
575 575 };
576 576 };
577 577 cssselect = super.buildPythonPackage {
578 578 name = "cssselect-1.0.1";
579 579 buildInputs = with self; [];
580 580 doCheck = false;
581 581 propagatedBuildInputs = with self; [];
582 582 src = fetchurl {
583 583 url = "https://pypi.python.org/packages/77/ff/9c865275cd19290feba56344eba570e719efb7ca5b34d67ed12b22ebbb0d/cssselect-1.0.1.tar.gz";
584 584 md5 = "3fa03bf82a9f0b1223c0f1eb1369e139";
585 585 };
586 586 meta = {
587 587 license = [ pkgs.lib.licenses.bsdOriginal ];
588 588 };
589 589 };
590 590 decorator = super.buildPythonPackage {
591 591 name = "decorator-4.0.11";
592 592 buildInputs = with self; [];
593 593 doCheck = false;
594 594 propagatedBuildInputs = with self; [];
595 595 src = fetchurl {
596 596 url = "https://pypi.python.org/packages/cc/ac/5a16f1fc0506ff72fcc8fd4e858e3a1c231f224ab79bb7c4c9b2094cc570/decorator-4.0.11.tar.gz";
597 597 md5 = "73644c8f0bd4983d1b6a34b49adec0ae";
598 598 };
599 599 meta = {
600 600 license = [ pkgs.lib.licenses.bsdOriginal { fullName = "new BSD License"; } ];
601 601 };
602 602 };
603 603 deform = super.buildPythonPackage {
604 604 name = "deform-2.0.4";
605 605 buildInputs = with self; [];
606 606 doCheck = false;
607 607 propagatedBuildInputs = with self; [Chameleon colander iso8601 peppercorn translationstring zope.deprecation];
608 608 src = fetchurl {
609 609 url = "https://pypi.python.org/packages/66/3b/eefcb07abcab7a97f6665aa2d0cf1af741d9d6e78a2e4657fd2b89f89880/deform-2.0.4.tar.gz";
610 610 md5 = "34756e42cf50dd4b4430809116c4ec0a";
611 611 };
612 612 meta = {
613 613 license = [ { fullName = "BSD-derived (http://www.repoze.org/LICENSE.txt)"; } ];
614 614 };
615 615 };
616 616 docutils = super.buildPythonPackage {
617 617 name = "docutils-0.13.1";
618 618 buildInputs = with self; [];
619 619 doCheck = false;
620 620 propagatedBuildInputs = with self; [];
621 621 src = fetchurl {
622 622 url = "https://pypi.python.org/packages/05/25/7b5484aca5d46915493f1fd4ecb63c38c333bd32aa9ad6e19da8d08895ae/docutils-0.13.1.tar.gz";
623 623 md5 = "ea4a893c633c788be9b8078b6b305d53";
624 624 };
625 625 meta = {
626 626 license = [ pkgs.lib.licenses.bsdOriginal pkgs.lib.licenses.publicDomain pkgs.lib.licenses.gpl1 { fullName = "public domain, Python, 2-Clause BSD, GPL 3 (see COPYING.txt)"; } pkgs.lib.licenses.psfl ];
627 627 };
628 628 };
629 629 dogpile.cache = super.buildPythonPackage {
630 630 name = "dogpile.cache-0.6.4";
631 631 buildInputs = with self; [];
632 632 doCheck = false;
633 633 propagatedBuildInputs = with self; [];
634 634 src = fetchurl {
635 635 url = "https://pypi.python.org/packages/b6/3d/35c05ca01c070bb70d9d422f2c4858ecb021b05b21af438fec5ccd7b945c/dogpile.cache-0.6.4.tar.gz";
636 636 md5 = "66e0a6cae6c08cb1ea25f89d0eadfeb0";
637 637 };
638 638 meta = {
639 639 license = [ pkgs.lib.licenses.bsdOriginal ];
640 640 };
641 641 };
642 642 dogpile.core = super.buildPythonPackage {
643 643 name = "dogpile.core-0.4.1";
644 644 buildInputs = with self; [];
645 645 doCheck = false;
646 646 propagatedBuildInputs = with self; [];
647 647 src = fetchurl {
648 648 url = "https://pypi.python.org/packages/0e/77/e72abc04c22aedf874301861e5c1e761231c288b5de369c18be8f4b5c9bb/dogpile.core-0.4.1.tar.gz";
649 649 md5 = "01cb19f52bba3e95c9b560f39341f045";
650 650 };
651 651 meta = {
652 652 license = [ pkgs.lib.licenses.bsdOriginal ];
653 653 };
654 654 };
655 655 ecdsa = super.buildPythonPackage {
656 name = "ecdsa-0.11";
656 name = "ecdsa-0.13";
657 657 buildInputs = with self; [];
658 658 doCheck = false;
659 659 propagatedBuildInputs = with self; [];
660 660 src = fetchurl {
661 url = "https://pypi.python.org/packages/6c/3f/92fe5dcdcaa7bd117be21e5520c9a54375112b66ec000d209e9e9519fad1/ecdsa-0.11.tar.gz";
662 md5 = "8ef586fe4dbb156697d756900cb41d7c";
661 url = "https://pypi.python.org/packages/f9/e5/99ebb176e47f150ac115ffeda5fedb6a3dbb3c00c74a59fd84ddf12f5857/ecdsa-0.13.tar.gz";
662 md5 = "1f60eda9cb5c46722856db41a3ae6670";
663 663 };
664 664 meta = {
665 665 license = [ pkgs.lib.licenses.mit ];
666 666 };
667 667 };
668 668 elasticsearch = super.buildPythonPackage {
669 669 name = "elasticsearch-2.3.0";
670 670 buildInputs = with self; [];
671 671 doCheck = false;
672 672 propagatedBuildInputs = with self; [urllib3];
673 673 src = fetchurl {
674 674 url = "https://pypi.python.org/packages/10/35/5fd52c5f0b0ee405ed4b5195e8bce44c5e041787680dc7b94b8071cac600/elasticsearch-2.3.0.tar.gz";
675 675 md5 = "2550f3b51629cf1ef9636608af92c340";
676 676 };
677 677 meta = {
678 678 license = [ pkgs.lib.licenses.asl20 ];
679 679 };
680 680 };
681 681 elasticsearch-dsl = super.buildPythonPackage {
682 682 name = "elasticsearch-dsl-2.2.0";
683 683 buildInputs = with self; [];
684 684 doCheck = false;
685 685 propagatedBuildInputs = with self; [six python-dateutil elasticsearch];
686 686 src = fetchurl {
687 687 url = "https://pypi.python.org/packages/66/2f/52a086968788e58461641570f45c3207a52d46ebbe9b77dc22b6a8ffda66/elasticsearch-dsl-2.2.0.tar.gz";
688 688 md5 = "fa6bd3c87ea3caa8f0f051bc37c53221";
689 689 };
690 690 meta = {
691 691 license = [ pkgs.lib.licenses.asl20 ];
692 692 };
693 693 };
694 694 entrypoints = super.buildPythonPackage {
695 695 name = "entrypoints-0.2.2";
696 696 buildInputs = with self; [];
697 697 doCheck = false;
698 698 propagatedBuildInputs = with self; [configparser];
699 699 src = fetchurl {
700 700 url = "https://code.rhodecode.com/upstream/entrypoints/archive/96e6d645684e1af3d7df5b5272f3fe85a546b233.tar.gz?md5=7db37771aea9ac9fefe093e5d6987313";
701 701 md5 = "7db37771aea9ac9fefe093e5d6987313";
702 702 };
703 703 meta = {
704 704 license = [ pkgs.lib.licenses.mit ];
705 705 };
706 706 };
707 707 enum34 = super.buildPythonPackage {
708 708 name = "enum34-1.1.6";
709 709 buildInputs = with self; [];
710 710 doCheck = false;
711 711 propagatedBuildInputs = with self; [];
712 712 src = fetchurl {
713 713 url = "https://pypi.python.org/packages/bf/3e/31d502c25302814a7c2f1d3959d2a3b3f78e509002ba91aea64993936876/enum34-1.1.6.tar.gz";
714 714 md5 = "5f13a0841a61f7fc295c514490d120d0";
715 715 };
716 716 meta = {
717 717 license = [ pkgs.lib.licenses.bsdOriginal ];
718 718 };
719 719 };
720 720 funcsigs = super.buildPythonPackage {
721 721 name = "funcsigs-1.0.2";
722 722 buildInputs = with self; [];
723 723 doCheck = false;
724 724 propagatedBuildInputs = with self; [];
725 725 src = fetchurl {
726 726 url = "https://pypi.python.org/packages/94/4a/db842e7a0545de1cdb0439bb80e6e42dfe82aaeaadd4072f2263a4fbed23/funcsigs-1.0.2.tar.gz";
727 727 md5 = "7e583285b1fb8a76305d6d68f4ccc14e";
728 728 };
729 729 meta = {
730 730 license = [ { fullName = "ASL"; } pkgs.lib.licenses.asl20 ];
731 731 };
732 732 };
733 733 functools32 = super.buildPythonPackage {
734 734 name = "functools32-3.2.3.post2";
735 735 buildInputs = with self; [];
736 736 doCheck = false;
737 737 propagatedBuildInputs = with self; [];
738 738 src = fetchurl {
739 739 url = "https://pypi.python.org/packages/5e/1a/0aa2c8195a204a9f51284018562dea77e25511f02fe924fac202fc012172/functools32-3.2.3-2.zip";
740 740 md5 = "d55232eb132ec779e6893c902a0bc5ad";
741 741 };
742 742 meta = {
743 743 license = [ pkgs.lib.licenses.psfl ];
744 744 };
745 745 };
746 746 future = super.buildPythonPackage {
747 747 name = "future-0.14.3";
748 748 buildInputs = with self; [];
749 749 doCheck = false;
750 750 propagatedBuildInputs = with self; [];
751 751 src = fetchurl {
752 752 url = "https://pypi.python.org/packages/83/80/8ef3a11a15f8eaafafa0937b20c1b3f73527e69ab6b3fa1cf94a5a96aabb/future-0.14.3.tar.gz";
753 753 md5 = "e94079b0bd1fc054929e8769fc0f6083";
754 754 };
755 755 meta = {
756 756 license = [ { fullName = "OSI Approved"; } pkgs.lib.licenses.mit ];
757 757 };
758 758 };
759 759 futures = super.buildPythonPackage {
760 760 name = "futures-3.0.2";
761 761 buildInputs = with self; [];
762 762 doCheck = false;
763 763 propagatedBuildInputs = with self; [];
764 764 src = fetchurl {
765 765 url = "https://pypi.python.org/packages/f8/e7/fc0fcbeb9193ba2d4de00b065e7fd5aecd0679e93ce95a07322b2b1434f4/futures-3.0.2.tar.gz";
766 766 md5 = "42aaf1e4de48d6e871d77dc1f9d96d5a";
767 767 };
768 768 meta = {
769 769 license = [ pkgs.lib.licenses.bsdOriginal ];
770 770 };
771 771 };
772 772 gevent = super.buildPythonPackage {
773 773 name = "gevent-1.2.2";
774 774 buildInputs = with self; [];
775 775 doCheck = false;
776 776 propagatedBuildInputs = with self; [greenlet];
777 777 src = fetchurl {
778 778 url = "https://pypi.python.org/packages/1b/92/b111f76e54d2be11375b47b213b56687214f258fd9dae703546d30b837be/gevent-1.2.2.tar.gz";
779 779 md5 = "7f0baf355384fe5ff2ecf66853422554";
780 780 };
781 781 meta = {
782 782 license = [ pkgs.lib.licenses.mit ];
783 783 };
784 784 };
785 785 gnureadline = super.buildPythonPackage {
786 786 name = "gnureadline-6.3.3";
787 787 buildInputs = with self; [];
788 788 doCheck = false;
789 789 propagatedBuildInputs = with self; [];
790 790 src = fetchurl {
791 791 url = "https://pypi.python.org/packages/3a/ee/2c3f568b0a74974791ac590ec742ef6133e2fbd287a074ba72a53fa5e97c/gnureadline-6.3.3.tar.gz";
792 792 md5 = "c4af83c9a3fbeac8f2da9b5a7c60e51c";
793 793 };
794 794 meta = {
795 795 license = [ pkgs.lib.licenses.gpl1 ];
796 796 };
797 797 };
798 798 gprof2dot = super.buildPythonPackage {
799 799 name = "gprof2dot-2016.10.13";
800 800 buildInputs = with self; [];
801 801 doCheck = false;
802 802 propagatedBuildInputs = with self; [];
803 803 src = fetchurl {
804 804 url = "https://pypi.python.org/packages/a0/e0/73c71baed306f0402a00a94ffc7b2be94ad1296dfcb8b46912655b93154c/gprof2dot-2016.10.13.tar.gz";
805 805 md5 = "0125401f15fd2afe1df686a76c64a4fd";
806 806 };
807 807 meta = {
808 808 license = [ { fullName = "LGPL"; } ];
809 809 };
810 810 };
811 811 graphviz = super.buildPythonPackage {
812 812 name = "graphviz-0.8";
813 813 buildInputs = with self; [];
814 814 doCheck = false;
815 815 propagatedBuildInputs = with self; [];
816 816 src = fetchurl {
817 817 url = "https://pypi.python.org/packages/da/84/0e997520323d6b01124eb01c68d5c101814d0aab53083cd62bd75a90f70b/graphviz-0.8.zip";
818 818 md5 = "9486a885360a5ee54a81eb2950470c71";
819 819 };
820 820 meta = {
821 821 license = [ pkgs.lib.licenses.mit ];
822 822 };
823 823 };
824 824 greenlet = super.buildPythonPackage {
825 825 name = "greenlet-0.4.12";
826 826 buildInputs = with self; [];
827 827 doCheck = false;
828 828 propagatedBuildInputs = with self; [];
829 829 src = fetchurl {
830 830 url = "https://pypi.python.org/packages/be/76/82af375d98724054b7e273b5d9369346937324f9bcc20980b45b068ef0b0/greenlet-0.4.12.tar.gz";
831 831 md5 = "e8637647d58a26c4a1f51ca393e53c00";
832 832 };
833 833 meta = {
834 834 license = [ pkgs.lib.licenses.mit ];
835 835 };
836 836 };
837 837 gunicorn = super.buildPythonPackage {
838 838 name = "gunicorn-19.7.1";
839 839 buildInputs = with self; [];
840 840 doCheck = false;
841 841 propagatedBuildInputs = with self; [];
842 842 src = fetchurl {
843 843 url = "https://pypi.python.org/packages/30/3a/10bb213cede0cc4d13ac2263316c872a64bf4c819000c8ccd801f1d5f822/gunicorn-19.7.1.tar.gz";
844 844 md5 = "174d3c3cd670a5be0404d84c484e590c";
845 845 };
846 846 meta = {
847 847 license = [ pkgs.lib.licenses.mit ];
848 848 };
849 849 };
850 850 html5lib = super.buildPythonPackage {
851 851 name = "html5lib-0.9999999";
852 852 buildInputs = with self; [];
853 853 doCheck = false;
854 854 propagatedBuildInputs = with self; [six];
855 855 src = fetchurl {
856 856 url = "https://pypi.python.org/packages/ae/ae/bcb60402c60932b32dfaf19bb53870b29eda2cd17551ba5639219fb5ebf9/html5lib-0.9999999.tar.gz";
857 857 md5 = "ef43cb05e9e799f25d65d1135838a96f";
858 858 };
859 859 meta = {
860 860 license = [ pkgs.lib.licenses.mit ];
861 861 };
862 862 };
863 863 hupper = super.buildPythonPackage {
864 864 name = "hupper-1.0";
865 865 buildInputs = with self; [];
866 866 doCheck = false;
867 867 propagatedBuildInputs = with self; [];
868 868 src = fetchurl {
869 869 url = "https://pypi.python.org/packages/2e/07/df892c564dc09bb3cf6f6deb976c26adf9117db75ba218cb4353dbc9d826/hupper-1.0.tar.gz";
870 870 md5 = "26e77da7d5ac5858f59af050d1a6eb5a";
871 871 };
872 872 meta = {
873 873 license = [ pkgs.lib.licenses.mit ];
874 874 };
875 875 };
876 876 infrae.cache = super.buildPythonPackage {
877 877 name = "infrae.cache-1.0.1";
878 878 buildInputs = with self; [];
879 879 doCheck = false;
880 880 propagatedBuildInputs = with self; [Beaker repoze.lru];
881 881 src = fetchurl {
882 882 url = "https://pypi.python.org/packages/bb/f0/e7d5e984cf6592fd2807dc7bc44a93f9d18e04e6a61f87fdfb2622422d74/infrae.cache-1.0.1.tar.gz";
883 883 md5 = "b09076a766747e6ed2a755cc62088e32";
884 884 };
885 885 meta = {
886 886 license = [ pkgs.lib.licenses.zpt21 ];
887 887 };
888 888 };
889 889 invoke = super.buildPythonPackage {
890 890 name = "invoke-0.13.0";
891 891 buildInputs = with self; [];
892 892 doCheck = false;
893 893 propagatedBuildInputs = with self; [];
894 894 src = fetchurl {
895 895 url = "https://pypi.python.org/packages/47/bf/d07ef52fa1ac645468858bbac7cb95b246a972a045e821493d17d89c81be/invoke-0.13.0.tar.gz";
896 896 md5 = "c0d1ed4bfb34eaab551662d8cfee6540";
897 897 };
898 898 meta = {
899 899 license = [ pkgs.lib.licenses.bsdOriginal ];
900 900 };
901 901 };
902 902 ipaddress = super.buildPythonPackage {
903 903 name = "ipaddress-1.0.18";
904 904 buildInputs = with self; [];
905 905 doCheck = false;
906 906 propagatedBuildInputs = with self; [];
907 907 src = fetchurl {
908 908 url = "https://pypi.python.org/packages/4e/13/774faf38b445d0b3a844b65747175b2e0500164b7c28d78e34987a5bfe06/ipaddress-1.0.18.tar.gz";
909 909 md5 = "310c2dfd64eb6f0df44aa8c59f2334a7";
910 910 };
911 911 meta = {
912 912 license = [ pkgs.lib.licenses.psfl ];
913 913 };
914 914 };
915 915 ipdb = super.buildPythonPackage {
916 916 name = "ipdb-0.10.3";
917 917 buildInputs = with self; [];
918 918 doCheck = false;
919 919 propagatedBuildInputs = with self; [setuptools ipython];
920 920 src = fetchurl {
921 921 url = "https://pypi.python.org/packages/ad/cc/0e7298e1fbf2efd52667c9354a12aa69fb6f796ce230cca03525051718ef/ipdb-0.10.3.tar.gz";
922 922 md5 = "def1f6ac075d54bdee07e6501263d4fa";
923 923 };
924 924 meta = {
925 925 license = [ pkgs.lib.licenses.bsdOriginal ];
926 926 };
927 927 };
928 928 ipython = super.buildPythonPackage {
929 929 name = "ipython-5.1.0";
930 930 buildInputs = with self; [];
931 931 doCheck = false;
932 932 propagatedBuildInputs = with self; [setuptools decorator pickleshare simplegeneric traitlets prompt-toolkit Pygments pexpect backports.shutil-get-terminal-size pathlib2 pexpect];
933 933 src = fetchurl {
934 934 url = "https://pypi.python.org/packages/89/63/a9292f7cd9d0090a0f995e1167f3f17d5889dcbc9a175261719c513b9848/ipython-5.1.0.tar.gz";
935 935 md5 = "47c8122420f65b58784cb4b9b4af35e3";
936 936 };
937 937 meta = {
938 938 license = [ pkgs.lib.licenses.bsdOriginal ];
939 939 };
940 940 };
941 941 ipython-genutils = super.buildPythonPackage {
942 942 name = "ipython-genutils-0.2.0";
943 943 buildInputs = with self; [];
944 944 doCheck = false;
945 945 propagatedBuildInputs = with self; [];
946 946 src = fetchurl {
947 947 url = "https://pypi.python.org/packages/e8/69/fbeffffc05236398ebfcfb512b6d2511c622871dca1746361006da310399/ipython_genutils-0.2.0.tar.gz";
948 948 md5 = "5a4f9781f78466da0ea1a648f3e1f79f";
949 949 };
950 950 meta = {
951 951 license = [ pkgs.lib.licenses.bsdOriginal ];
952 952 };
953 953 };
954 954 iso8601 = super.buildPythonPackage {
955 955 name = "iso8601-0.1.11";
956 956 buildInputs = with self; [];
957 957 doCheck = false;
958 958 propagatedBuildInputs = with self; [];
959 959 src = fetchurl {
960 960 url = "https://pypi.python.org/packages/c0/75/c9209ee4d1b5975eb8c2cba4428bde6b61bd55664a98290dd015cdb18e98/iso8601-0.1.11.tar.gz";
961 961 md5 = "b06d11cd14a64096f907086044f0fe38";
962 962 };
963 963 meta = {
964 964 license = [ pkgs.lib.licenses.mit ];
965 965 };
966 966 };
967 967 itsdangerous = super.buildPythonPackage {
968 968 name = "itsdangerous-0.24";
969 969 buildInputs = with self; [];
970 970 doCheck = false;
971 971 propagatedBuildInputs = with self; [];
972 972 src = fetchurl {
973 973 url = "https://pypi.python.org/packages/dc/b4/a60bcdba945c00f6d608d8975131ab3f25b22f2bcfe1dab221165194b2d4/itsdangerous-0.24.tar.gz";
974 974 md5 = "a3d55aa79369aef5345c036a8a26307f";
975 975 };
976 976 meta = {
977 977 license = [ pkgs.lib.licenses.bsdOriginal ];
978 978 };
979 979 };
980 980 jsonschema = super.buildPythonPackage {
981 981 name = "jsonschema-2.6.0";
982 982 buildInputs = with self; [];
983 983 doCheck = false;
984 984 propagatedBuildInputs = with self; [functools32];
985 985 src = fetchurl {
986 986 url = "https://pypi.python.org/packages/58/b9/171dbb07e18c6346090a37f03c7e74410a1a56123f847efed59af260a298/jsonschema-2.6.0.tar.gz";
987 987 md5 = "50c6b69a373a8b55ff1e0ec6e78f13f4";
988 988 };
989 989 meta = {
990 990 license = [ pkgs.lib.licenses.mit ];
991 991 };
992 992 };
993 993 jupyter-client = super.buildPythonPackage {
994 994 name = "jupyter-client-5.0.0";
995 995 buildInputs = with self; [];
996 996 doCheck = false;
997 997 propagatedBuildInputs = with self; [traitlets jupyter-core pyzmq python-dateutil];
998 998 src = fetchurl {
999 999 url = "https://pypi.python.org/packages/e5/6f/65412ed462202b90134b7e761b0b7e7f949e07a549c1755475333727b3d0/jupyter_client-5.0.0.tar.gz";
1000 1000 md5 = "1acd331b5c9fb4d79dae9939e79f2426";
1001 1001 };
1002 1002 meta = {
1003 1003 license = [ pkgs.lib.licenses.bsdOriginal ];
1004 1004 };
1005 1005 };
1006 1006 jupyter-core = super.buildPythonPackage {
1007 1007 name = "jupyter-core-4.3.0";
1008 1008 buildInputs = with self; [];
1009 1009 doCheck = false;
1010 1010 propagatedBuildInputs = with self; [traitlets];
1011 1011 src = fetchurl {
1012 1012 url = "https://pypi.python.org/packages/2f/39/5138f975100ce14d150938df48a83cd852a3fd8e24b1244f4113848e69e2/jupyter_core-4.3.0.tar.gz";
1013 1013 md5 = "18819511a809afdeed9a995a9c27bcfb";
1014 1014 };
1015 1015 meta = {
1016 1016 license = [ pkgs.lib.licenses.bsdOriginal ];
1017 1017 };
1018 1018 };
1019 1019 kombu = super.buildPythonPackage {
1020 1020 name = "kombu-1.5.1";
1021 1021 buildInputs = with self; [];
1022 1022 doCheck = false;
1023 1023 propagatedBuildInputs = with self; [anyjson amqplib];
1024 1024 src = fetchurl {
1025 1025 url = "https://pypi.python.org/packages/19/53/74bf2a624644b45f0850a638752514fc10a8e1cbd738f10804951a6df3f5/kombu-1.5.1.tar.gz";
1026 1026 md5 = "50662f3c7e9395b3d0721fb75d100b63";
1027 1027 };
1028 1028 meta = {
1029 1029 license = [ pkgs.lib.licenses.bsdOriginal ];
1030 1030 };
1031 1031 };
1032 1032 lxml = super.buildPythonPackage {
1033 1033 name = "lxml-3.7.3";
1034 1034 buildInputs = with self; [];
1035 1035 doCheck = false;
1036 1036 propagatedBuildInputs = with self; [];
1037 1037 src = fetchurl {
1038 1038 url = "https://pypi.python.org/packages/39/e8/a8e0b1fa65dd021d48fe21464f71783655f39a41f218293c1c590d54eb82/lxml-3.7.3.tar.gz";
1039 1039 md5 = "075692ce442e69bbd604d44e21c02753";
1040 1040 };
1041 1041 meta = {
1042 1042 license = [ pkgs.lib.licenses.bsdOriginal ];
1043 1043 };
1044 1044 };
1045 1045 meld3 = super.buildPythonPackage {
1046 1046 name = "meld3-1.0.2";
1047 1047 buildInputs = with self; [];
1048 1048 doCheck = false;
1049 1049 propagatedBuildInputs = with self; [];
1050 1050 src = fetchurl {
1051 1051 url = "https://pypi.python.org/packages/45/a0/317c6422b26c12fe0161e936fc35f36552069ba8e6f7ecbd99bbffe32a5f/meld3-1.0.2.tar.gz";
1052 1052 md5 = "3ccc78cd79cffd63a751ad7684c02c91";
1053 1053 };
1054 1054 meta = {
1055 1055 license = [ { fullName = "BSD-derived (http://www.repoze.org/LICENSE.txt)"; } ];
1056 1056 };
1057 1057 };
1058 1058 mistune = super.buildPythonPackage {
1059 1059 name = "mistune-0.7.4";
1060 1060 buildInputs = with self; [];
1061 1061 doCheck = false;
1062 1062 propagatedBuildInputs = with self; [];
1063 1063 src = fetchurl {
1064 1064 url = "https://pypi.python.org/packages/25/a4/12a584c0c59c9fed529f8b3c47ca8217c0cf8bcc5e1089d3256410cfbdbc/mistune-0.7.4.tar.gz";
1065 1065 md5 = "92d01cb717e9e74429e9bde9d29ac43b";
1066 1066 };
1067 1067 meta = {
1068 1068 license = [ pkgs.lib.licenses.bsdOriginal ];
1069 1069 };
1070 1070 };
1071 1071 mock = super.buildPythonPackage {
1072 1072 name = "mock-1.0.1";
1073 1073 buildInputs = with self; [];
1074 1074 doCheck = false;
1075 1075 propagatedBuildInputs = with self; [];
1076 1076 src = fetchurl {
1077 1077 url = "https://pypi.python.org/packages/15/45/30273ee91feb60dabb8fbb2da7868520525f02cf910279b3047182feed80/mock-1.0.1.zip";
1078 1078 md5 = "869f08d003c289a97c1a6610faf5e913";
1079 1079 };
1080 1080 meta = {
1081 1081 license = [ pkgs.lib.licenses.bsdOriginal ];
1082 1082 };
1083 1083 };
1084 1084 msgpack-python = super.buildPythonPackage {
1085 1085 name = "msgpack-python-0.4.8";
1086 1086 buildInputs = with self; [];
1087 1087 doCheck = false;
1088 1088 propagatedBuildInputs = with self; [];
1089 1089 src = fetchurl {
1090 1090 url = "https://pypi.python.org/packages/21/27/8a1d82041c7a2a51fcc73675875a5f9ea06c2663e02fcfeb708be1d081a0/msgpack-python-0.4.8.tar.gz";
1091 1091 md5 = "dcd854fb41ee7584ebbf35e049e6be98";
1092 1092 };
1093 1093 meta = {
1094 1094 license = [ pkgs.lib.licenses.asl20 ];
1095 1095 };
1096 1096 };
1097 1097 nbconvert = super.buildPythonPackage {
1098 1098 name = "nbconvert-5.1.1";
1099 1099 buildInputs = with self; [];
1100 1100 doCheck = false;
1101 1101 propagatedBuildInputs = with self; [mistune Jinja2 Pygments traitlets jupyter-core nbformat entrypoints bleach pandocfilters testpath];
1102 1102 src = fetchurl {
1103 1103 url = "https://pypi.python.org/packages/95/58/df1c91f1658ee5df19097f915a1e71c91fc824a708d82d2b2e35f8b80e9a/nbconvert-5.1.1.tar.gz";
1104 1104 md5 = "d0263fb03a44db2f94eea09a608ed813";
1105 1105 };
1106 1106 meta = {
1107 1107 license = [ pkgs.lib.licenses.bsdOriginal ];
1108 1108 };
1109 1109 };
1110 1110 nbformat = super.buildPythonPackage {
1111 1111 name = "nbformat-4.3.0";
1112 1112 buildInputs = with self; [];
1113 1113 doCheck = false;
1114 1114 propagatedBuildInputs = with self; [ipython-genutils traitlets jsonschema jupyter-core];
1115 1115 src = fetchurl {
1116 1116 url = "https://pypi.python.org/packages/f9/c5/89df4abf906f766727f976e170caa85b4f1c1d1feb1f45d716016e68e19f/nbformat-4.3.0.tar.gz";
1117 1117 md5 = "9a00d20425914cd5ba5f97769d9963ca";
1118 1118 };
1119 1119 meta = {
1120 1120 license = [ pkgs.lib.licenses.bsdOriginal ];
1121 1121 };
1122 1122 };
1123 1123 nose = super.buildPythonPackage {
1124 1124 name = "nose-1.3.6";
1125 1125 buildInputs = with self; [];
1126 1126 doCheck = false;
1127 1127 propagatedBuildInputs = with self; [];
1128 1128 src = fetchurl {
1129 1129 url = "https://pypi.python.org/packages/70/c7/469e68148d17a0d3db5ed49150242fd70a74a8147b8f3f8b87776e028d99/nose-1.3.6.tar.gz";
1130 1130 md5 = "0ca546d81ca8309080fc80cb389e7a16";
1131 1131 };
1132 1132 meta = {
1133 1133 license = [ { fullName = "GNU Library or Lesser General Public License (LGPL)"; } { fullName = "GNU LGPL"; } ];
1134 1134 };
1135 1135 };
1136 1136 objgraph = super.buildPythonPackage {
1137 1137 name = "objgraph-3.1.0";
1138 1138 buildInputs = with self; [];
1139 1139 doCheck = false;
1140 1140 propagatedBuildInputs = with self; [graphviz];
1141 1141 src = fetchurl {
1142 1142 url = "https://pypi.python.org/packages/f4/b3/082e54e62094cb2ec84f8d5a49e0142cef99016491cecba83309cff920ae/objgraph-3.1.0.tar.gz";
1143 1143 md5 = "eddbd96039796bfbd13eee403701e64a";
1144 1144 };
1145 1145 meta = {
1146 1146 license = [ pkgs.lib.licenses.mit ];
1147 1147 };
1148 1148 };
1149 1149 packaging = super.buildPythonPackage {
1150 1150 name = "packaging-15.2";
1151 1151 buildInputs = with self; [];
1152 1152 doCheck = false;
1153 1153 propagatedBuildInputs = with self; [];
1154 1154 src = fetchurl {
1155 1155 url = "https://pypi.python.org/packages/24/c4/185da1304f07047dc9e0c46c31db75c0351bd73458ac3efad7da3dbcfbe1/packaging-15.2.tar.gz";
1156 1156 md5 = "c16093476f6ced42128bf610e5db3784";
1157 1157 };
1158 1158 meta = {
1159 1159 license = [ pkgs.lib.licenses.asl20 ];
1160 1160 };
1161 1161 };
1162 1162 pandocfilters = super.buildPythonPackage {
1163 1163 name = "pandocfilters-1.4.1";
1164 1164 buildInputs = with self; [];
1165 1165 doCheck = false;
1166 1166 propagatedBuildInputs = with self; [];
1167 1167 src = fetchurl {
1168 1168 url = "https://pypi.python.org/packages/e3/1f/21d1b7e8ca571e80b796c758d361fdf5554335ff138158654684bc5401d8/pandocfilters-1.4.1.tar.gz";
1169 1169 md5 = "7680d9f9ec07397dd17f380ee3818b9d";
1170 1170 };
1171 1171 meta = {
1172 1172 license = [ pkgs.lib.licenses.bsdOriginal ];
1173 1173 };
1174 1174 };
1175 paramiko = super.buildPythonPackage {
1176 name = "paramiko-1.15.1";
1177 buildInputs = with self; [];
1178 doCheck = false;
1179 propagatedBuildInputs = with self; [pycrypto ecdsa];
1180 src = fetchurl {
1181 url = "https://pypi.python.org/packages/04/2b/a22d2a560c1951abbbf95a0628e245945565f70dc082d9e784666887222c/paramiko-1.15.1.tar.gz";
1182 md5 = "48c274c3f9b1282932567b21f6acf3b5";
1183 };
1184 meta = {
1185 license = [ { fullName = "LGPL"; } { fullName = "GNU Library or Lesser General Public License (LGPL)"; } ];
1186 };
1187 };
1188 1175 pathlib2 = super.buildPythonPackage {
1189 1176 name = "pathlib2-2.3.0";
1190 1177 buildInputs = with self; [];
1191 1178 doCheck = false;
1192 1179 propagatedBuildInputs = with self; [six scandir];
1193 1180 src = fetchurl {
1194 1181 url = "https://pypi.python.org/packages/a1/14/df0deb867c2733f7d857523c10942b3d6612a1b222502fdffa9439943dfb/pathlib2-2.3.0.tar.gz";
1195 1182 md5 = "89c90409d11fd5947966b6a30a47d18c";
1196 1183 };
1197 1184 meta = {
1198 1185 license = [ pkgs.lib.licenses.mit ];
1199 1186 };
1200 1187 };
1201 1188 peppercorn = super.buildPythonPackage {
1202 1189 name = "peppercorn-0.5";
1203 1190 buildInputs = with self; [];
1204 1191 doCheck = false;
1205 1192 propagatedBuildInputs = with self; [];
1206 1193 src = fetchurl {
1207 1194 url = "https://pypi.python.org/packages/45/ec/a62ec317d1324a01567c5221b420742f094f05ee48097e5157d32be3755c/peppercorn-0.5.tar.gz";
1208 1195 md5 = "f08efbca5790019ab45d76b7244abd40";
1209 1196 };
1210 1197 meta = {
1211 1198 license = [ { fullName = "BSD-derived (http://www.repoze.org/LICENSE.txt)"; } ];
1212 1199 };
1213 1200 };
1214 1201 pexpect = super.buildPythonPackage {
1215 1202 name = "pexpect-4.2.1";
1216 1203 buildInputs = with self; [];
1217 1204 doCheck = false;
1218 1205 propagatedBuildInputs = with self; [ptyprocess];
1219 1206 src = fetchurl {
1220 1207 url = "https://pypi.python.org/packages/e8/13/d0b0599099d6cd23663043a2a0bb7c61e58c6ba359b2656e6fb000ef5b98/pexpect-4.2.1.tar.gz";
1221 1208 md5 = "3694410001a99dff83f0b500a1ca1c95";
1222 1209 };
1223 1210 meta = {
1224 1211 license = [ pkgs.lib.licenses.isc { fullName = "ISC License (ISCL)"; } ];
1225 1212 };
1226 1213 };
1227 1214 pickleshare = super.buildPythonPackage {
1228 1215 name = "pickleshare-0.7.4";
1229 1216 buildInputs = with self; [];
1230 1217 doCheck = false;
1231 1218 propagatedBuildInputs = with self; [pathlib2];
1232 1219 src = fetchurl {
1233 1220 url = "https://pypi.python.org/packages/69/fe/dd137d84daa0fd13a709e448138e310d9ea93070620c9db5454e234af525/pickleshare-0.7.4.tar.gz";
1234 1221 md5 = "6a9e5dd8dfc023031f6b7b3f824cab12";
1235 1222 };
1236 1223 meta = {
1237 1224 license = [ pkgs.lib.licenses.mit ];
1238 1225 };
1239 1226 };
1240 1227 plaster = super.buildPythonPackage {
1241 1228 name = "plaster-0.5";
1242 1229 buildInputs = with self; [];
1243 1230 doCheck = false;
1244 1231 propagatedBuildInputs = with self; [setuptools];
1245 1232 src = fetchurl {
1246 1233 url = "https://pypi.python.org/packages/99/b3/d7ca1fe31d2b56dba68a238721fda6820770f9c2a3de17a582d4b5b2edcc/plaster-0.5.tar.gz";
1247 1234 md5 = "c59345a67a860cfcaa1bd6a81451399d";
1248 1235 };
1249 1236 meta = {
1250 1237 license = [ pkgs.lib.licenses.mit ];
1251 1238 };
1252 1239 };
1253 1240 plaster-pastedeploy = super.buildPythonPackage {
1254 1241 name = "plaster-pastedeploy-0.4.1";
1255 1242 buildInputs = with self; [];
1256 1243 doCheck = false;
1257 1244 propagatedBuildInputs = with self; [PasteDeploy plaster];
1258 1245 src = fetchurl {
1259 1246 url = "https://pypi.python.org/packages/9d/6e/f8be01ed41c94e6c54ac97cf2eb142a702aae0c8cce31c846f785e525b40/plaster_pastedeploy-0.4.1.tar.gz";
1260 1247 md5 = "f48d5344b922e56c4978eebf1cd2e0d3";
1261 1248 };
1262 1249 meta = {
1263 1250 license = [ pkgs.lib.licenses.mit ];
1264 1251 };
1265 1252 };
1266 1253 prompt-toolkit = super.buildPythonPackage {
1267 1254 name = "prompt-toolkit-1.0.14";
1268 1255 buildInputs = with self; [];
1269 1256 doCheck = false;
1270 1257 propagatedBuildInputs = with self; [six wcwidth];
1271 1258 src = fetchurl {
1272 1259 url = "https://pypi.python.org/packages/55/56/8c39509b614bda53e638b7500f12577d663ac1b868aef53426fc6a26c3f5/prompt_toolkit-1.0.14.tar.gz";
1273 1260 md5 = "f24061ae133ed32c6b764e92bd48c496";
1274 1261 };
1275 1262 meta = {
1276 1263 license = [ pkgs.lib.licenses.bsdOriginal ];
1277 1264 };
1278 1265 };
1279 1266 psutil = super.buildPythonPackage {
1280 1267 name = "psutil-4.3.1";
1281 1268 buildInputs = with self; [];
1282 1269 doCheck = false;
1283 1270 propagatedBuildInputs = with self; [];
1284 1271 src = fetchurl {
1285 1272 url = "https://pypi.python.org/packages/78/cc/f267a1371f229bf16db6a4e604428c3b032b823b83155bd33cef45e49a53/psutil-4.3.1.tar.gz";
1286 1273 md5 = "199a366dba829c88bddaf5b41d19ddc0";
1287 1274 };
1288 1275 meta = {
1289 1276 license = [ pkgs.lib.licenses.bsdOriginal ];
1290 1277 };
1291 1278 };
1292 1279 psycopg2 = super.buildPythonPackage {
1293 1280 name = "psycopg2-2.7.1";
1294 1281 buildInputs = with self; [];
1295 1282 doCheck = false;
1296 1283 propagatedBuildInputs = with self; [];
1297 1284 src = fetchurl {
1298 1285 url = "https://pypi.python.org/packages/f8/e9/5793369ce8a41bf5467623ded8d59a434dfef9c136351aca4e70c2657ba0/psycopg2-2.7.1.tar.gz";
1299 1286 md5 = "67848ac33af88336046802f6ef7081f3";
1300 1287 };
1301 1288 meta = {
1302 1289 license = [ pkgs.lib.licenses.zpt21 { fullName = "GNU Library or Lesser General Public License (LGPL)"; } { fullName = "LGPL with exceptions or ZPL"; } ];
1303 1290 };
1304 1291 };
1305 1292 ptyprocess = super.buildPythonPackage {
1306 1293 name = "ptyprocess-0.5.2";
1307 1294 buildInputs = with self; [];
1308 1295 doCheck = false;
1309 1296 propagatedBuildInputs = with self; [];
1310 1297 src = fetchurl {
1311 1298 url = "https://pypi.python.org/packages/51/83/5d07dc35534640b06f9d9f1a1d2bc2513fb9cc7595a1b0e28ae5477056ce/ptyprocess-0.5.2.tar.gz";
1312 1299 md5 = "d3b8febae1b8c53b054bd818d0bb8665";
1313 1300 };
1314 1301 meta = {
1315 1302 license = [ ];
1316 1303 };
1317 1304 };
1318 1305 py = super.buildPythonPackage {
1319 1306 name = "py-1.4.34";
1320 1307 buildInputs = with self; [];
1321 1308 doCheck = false;
1322 1309 propagatedBuildInputs = with self; [];
1323 1310 src = fetchurl {
1324 1311 url = "https://pypi.python.org/packages/68/35/58572278f1c097b403879c1e9369069633d1cbad5239b9057944bb764782/py-1.4.34.tar.gz";
1325 1312 md5 = "d9c3d8f734b0819ff48e355d77bf1730";
1326 1313 };
1327 1314 meta = {
1328 1315 license = [ pkgs.lib.licenses.mit ];
1329 1316 };
1330 1317 };
1331 1318 py-bcrypt = super.buildPythonPackage {
1332 1319 name = "py-bcrypt-0.4";
1333 1320 buildInputs = with self; [];
1334 1321 doCheck = false;
1335 1322 propagatedBuildInputs = with self; [];
1336 1323 src = fetchurl {
1337 1324 url = "https://pypi.python.org/packages/68/b1/1c3068c5c4d2e35c48b38dcc865301ebfdf45f54507086ac65ced1fd3b3d/py-bcrypt-0.4.tar.gz";
1338 1325 md5 = "dd8b367d6b716a2ea2e72392525f4e36";
1339 1326 };
1340 1327 meta = {
1341 1328 license = [ pkgs.lib.licenses.bsdOriginal ];
1342 1329 };
1343 1330 };
1344 1331 py-gfm = super.buildPythonPackage {
1345 1332 name = "py-gfm-0.1.3";
1346 1333 buildInputs = with self; [];
1347 1334 doCheck = false;
1348 1335 propagatedBuildInputs = with self; [setuptools Markdown];
1349 1336 src = fetchurl {
1350 1337 url = "https://code.rhodecode.com/upstream/py-gfm/archive/0d66a19bc16e3d49de273c0f797d4e4781e8c0f2.tar.gz?md5=0d0d5385bfb629eea636a80b9c2bfd16";
1351 1338 md5 = "0d0d5385bfb629eea636a80b9c2bfd16";
1352 1339 };
1353 1340 meta = {
1354 1341 license = [ pkgs.lib.licenses.bsdOriginal ];
1355 1342 };
1356 1343 };
1357 1344 pycrypto = super.buildPythonPackage {
1358 1345 name = "pycrypto-2.6.1";
1359 1346 buildInputs = with self; [];
1360 1347 doCheck = false;
1361 1348 propagatedBuildInputs = with self; [];
1362 1349 src = fetchurl {
1363 1350 url = "https://pypi.python.org/packages/60/db/645aa9af249f059cc3a368b118de33889219e0362141e75d4eaf6f80f163/pycrypto-2.6.1.tar.gz";
1364 1351 md5 = "55a61a054aa66812daf5161a0d5d7eda";
1365 1352 };
1366 1353 meta = {
1367 1354 license = [ pkgs.lib.licenses.publicDomain ];
1368 1355 };
1369 1356 };
1370 1357 pycurl = super.buildPythonPackage {
1371 1358 name = "pycurl-7.19.5";
1372 1359 buildInputs = with self; [];
1373 1360 doCheck = false;
1374 1361 propagatedBuildInputs = with self; [];
1375 1362 src = fetchurl {
1376 1363 url = "https://pypi.python.org/packages/6c/48/13bad289ef6f4869b1d8fc11ae54de8cfb3cc4a2eb9f7419c506f763be46/pycurl-7.19.5.tar.gz";
1377 1364 md5 = "47b4eac84118e2606658122104e62072";
1378 1365 };
1379 1366 meta = {
1380 1367 license = [ pkgs.lib.licenses.mit { fullName = "LGPL/MIT"; } { fullName = "GNU Library or Lesser General Public License (LGPL)"; } ];
1381 1368 };
1382 1369 };
1383 1370 pyflakes = super.buildPythonPackage {
1384 1371 name = "pyflakes-0.8.1";
1385 1372 buildInputs = with self; [];
1386 1373 doCheck = false;
1387 1374 propagatedBuildInputs = with self; [];
1388 1375 src = fetchurl {
1389 1376 url = "https://pypi.python.org/packages/75/22/a90ec0252f4f87f3ffb6336504de71fe16a49d69c4538dae2f12b9360a38/pyflakes-0.8.1.tar.gz";
1390 1377 md5 = "905fe91ad14b912807e8fdc2ac2e2c23";
1391 1378 };
1392 1379 meta = {
1393 1380 license = [ pkgs.lib.licenses.mit ];
1394 1381 };
1395 1382 };
1396 1383 pygments-markdown-lexer = super.buildPythonPackage {
1397 1384 name = "pygments-markdown-lexer-0.1.0.dev39";
1398 1385 buildInputs = with self; [];
1399 1386 doCheck = false;
1400 1387 propagatedBuildInputs = with self; [Pygments];
1401 1388 src = fetchurl {
1402 1389 url = "https://pypi.python.org/packages/c3/12/674cdee66635d638cedb2c5d9c85ce507b7b2f91bdba29e482f1b1160ff6/pygments-markdown-lexer-0.1.0.dev39.zip";
1403 1390 md5 = "6360fe0f6d1f896e35b7a0142ce6459c";
1404 1391 };
1405 1392 meta = {
1406 1393 license = [ pkgs.lib.licenses.asl20 ];
1407 1394 };
1408 1395 };
1409 1396 pyparsing = super.buildPythonPackage {
1410 1397 name = "pyparsing-1.5.7";
1411 1398 buildInputs = with self; [];
1412 1399 doCheck = false;
1413 1400 propagatedBuildInputs = with self; [];
1414 1401 src = fetchurl {
1415 1402 url = "https://pypi.python.org/packages/2e/26/e8fb5b4256a5f5036be7ce115ef8db8d06bc537becfbdc46c6af008314ee/pyparsing-1.5.7.zip";
1416 1403 md5 = "b86854857a368d6ccb4d5b6e76d0637f";
1417 1404 };
1418 1405 meta = {
1419 1406 license = [ pkgs.lib.licenses.mit ];
1420 1407 };
1421 1408 };
1422 1409 pyramid = super.buildPythonPackage {
1423 1410 name = "pyramid-1.9";
1424 1411 buildInputs = with self; [];
1425 1412 doCheck = false;
1426 1413 propagatedBuildInputs = with self; [setuptools WebOb repoze.lru zope.interface zope.deprecation venusian translationstring PasteDeploy plaster plaster-pastedeploy hupper];
1427 1414 src = fetchurl {
1428 1415 url = "https://pypi.python.org/packages/b0/73/715321e129334f3e41430bede877620175a63ed075fd5d1fd2c25b7cb121/pyramid-1.9.tar.gz";
1429 1416 md5 = "aa6c7c568f83151af51eb053ac633bc4";
1430 1417 };
1431 1418 meta = {
1432 1419 license = [ { fullName = "Repoze Public License"; } { fullName = "BSD-derived (http://www.repoze.org/LICENSE.txt)"; } ];
1433 1420 };
1434 1421 };
1435 1422 pyramid-beaker = super.buildPythonPackage {
1436 1423 name = "pyramid-beaker-0.8";
1437 1424 buildInputs = with self; [];
1438 1425 doCheck = false;
1439 1426 propagatedBuildInputs = with self; [pyramid Beaker];
1440 1427 src = fetchurl {
1441 1428 url = "https://pypi.python.org/packages/d9/6e/b85426e00fd3d57f4545f74e1c3828552d8700f13ededeef9233f7bca8be/pyramid_beaker-0.8.tar.gz";
1442 1429 md5 = "22f14be31b06549f80890e2c63a93834";
1443 1430 };
1444 1431 meta = {
1445 1432 license = [ { fullName = "BSD-derived (http://www.repoze.org/LICENSE.txt)"; } ];
1446 1433 };
1447 1434 };
1448 1435 pyramid-debugtoolbar = super.buildPythonPackage {
1449 1436 name = "pyramid-debugtoolbar-4.2.1";
1450 1437 buildInputs = with self; [];
1451 1438 doCheck = false;
1452 1439 propagatedBuildInputs = with self; [pyramid pyramid-mako repoze.lru Pygments ipaddress];
1453 1440 src = fetchurl {
1454 1441 url = "https://pypi.python.org/packages/db/26/94620b7752936e2cd74838263ff366db9b454f7394bfb62d1eb2f84b29c1/pyramid_debugtoolbar-4.2.1.tar.gz";
1455 1442 md5 = "3dfaced2fab1644ff5284017be9d92b9";
1456 1443 };
1457 1444 meta = {
1458 1445 license = [ { fullName = "Repoze Public License"; } pkgs.lib.licenses.bsdOriginal ];
1459 1446 };
1460 1447 };
1461 1448 pyramid-jinja2 = super.buildPythonPackage {
1462 1449 name = "pyramid-jinja2-2.5";
1463 1450 buildInputs = with self; [];
1464 1451 doCheck = false;
1465 1452 propagatedBuildInputs = with self; [pyramid zope.deprecation Jinja2 MarkupSafe];
1466 1453 src = fetchurl {
1467 1454 url = "https://pypi.python.org/packages/a1/80/595e26ffab7deba7208676b6936b7e5a721875710f982e59899013cae1ed/pyramid_jinja2-2.5.tar.gz";
1468 1455 md5 = "07cb6547204ac5e6f0b22a954ccee928";
1469 1456 };
1470 1457 meta = {
1471 1458 license = [ { fullName = "Repoze Public License"; } { fullName = "BSD-derived (http://www.repoze.org/LICENSE.txt)"; } ];
1472 1459 };
1473 1460 };
1474 1461 pyramid-mako = super.buildPythonPackage {
1475 1462 name = "pyramid-mako-1.0.2";
1476 1463 buildInputs = with self; [];
1477 1464 doCheck = false;
1478 1465 propagatedBuildInputs = with self; [pyramid Mako];
1479 1466 src = fetchurl {
1480 1467 url = "https://pypi.python.org/packages/f1/92/7e69bcf09676d286a71cb3bbb887b16595b96f9ba7adbdc239ffdd4b1eb9/pyramid_mako-1.0.2.tar.gz";
1481 1468 md5 = "ee25343a97eb76bd90abdc2a774eb48a";
1482 1469 };
1483 1470 meta = {
1484 1471 license = [ { fullName = "Repoze Public License"; } { fullName = "BSD-derived (http://www.repoze.org/LICENSE.txt)"; } ];
1485 1472 };
1486 1473 };
1487 1474 pysqlite = super.buildPythonPackage {
1488 1475 name = "pysqlite-2.8.3";
1489 1476 buildInputs = with self; [];
1490 1477 doCheck = false;
1491 1478 propagatedBuildInputs = with self; [];
1492 1479 src = fetchurl {
1493 1480 url = "https://pypi.python.org/packages/42/02/981b6703e3c83c5b25a829c6e77aad059f9481b0bbacb47e6e8ca12bd731/pysqlite-2.8.3.tar.gz";
1494 1481 md5 = "033f17b8644577715aee55e8832ac9fc";
1495 1482 };
1496 1483 meta = {
1497 1484 license = [ { fullName = "zlib/libpng License"; } { fullName = "zlib/libpng license"; } ];
1498 1485 };
1499 1486 };
1500 1487 pytest = super.buildPythonPackage {
1501 1488 name = "pytest-3.1.2";
1502 1489 buildInputs = with self; [];
1503 1490 doCheck = false;
1504 1491 propagatedBuildInputs = with self; [py setuptools];
1505 1492 src = fetchurl {
1506 1493 url = "https://pypi.python.org/packages/72/2b/2d3155e01f45a5a04427857352ee88220ee39550b2bc078f9db3190aea46/pytest-3.1.2.tar.gz";
1507 1494 md5 = "c4d179f89043cc925e1c169d03128e02";
1508 1495 };
1509 1496 meta = {
1510 1497 license = [ pkgs.lib.licenses.mit ];
1511 1498 };
1512 1499 };
1513 1500 pytest-catchlog = super.buildPythonPackage {
1514 1501 name = "pytest-catchlog-1.2.2";
1515 1502 buildInputs = with self; [];
1516 1503 doCheck = false;
1517 1504 propagatedBuildInputs = with self; [py pytest];
1518 1505 src = fetchurl {
1519 1506 url = "https://pypi.python.org/packages/f2/2b/2faccdb1a978fab9dd0bf31cca9f6847fbe9184a0bdcc3011ac41dd44191/pytest-catchlog-1.2.2.zip";
1520 1507 md5 = "09d890c54c7456c818102b7ff8c182c8";
1521 1508 };
1522 1509 meta = {
1523 1510 license = [ pkgs.lib.licenses.mit ];
1524 1511 };
1525 1512 };
1526 1513 pytest-cov = super.buildPythonPackage {
1527 1514 name = "pytest-cov-2.5.1";
1528 1515 buildInputs = with self; [];
1529 1516 doCheck = false;
1530 1517 propagatedBuildInputs = with self; [pytest coverage];
1531 1518 src = fetchurl {
1532 1519 url = "https://pypi.python.org/packages/24/b4/7290d65b2f3633db51393bdf8ae66309b37620bc3ec116c5e357e3e37238/pytest-cov-2.5.1.tar.gz";
1533 1520 md5 = "5acf38d4909e19819eb5c1754fbfc0ac";
1534 1521 };
1535 1522 meta = {
1536 1523 license = [ pkgs.lib.licenses.bsdOriginal pkgs.lib.licenses.mit ];
1537 1524 };
1538 1525 };
1539 1526 pytest-profiling = super.buildPythonPackage {
1540 1527 name = "pytest-profiling-1.2.6";
1541 1528 buildInputs = with self; [];
1542 1529 doCheck = false;
1543 1530 propagatedBuildInputs = with self; [six pytest gprof2dot];
1544 1531 src = fetchurl {
1545 1532 url = "https://pypi.python.org/packages/f9/0d/df67fb9ce16c2cef201693da956321b1bccfbf9a4ead39748b9f9d1d74cb/pytest-profiling-1.2.6.tar.gz";
1546 1533 md5 = "50eb4c66c3762a2f1a49669bedc0b894";
1547 1534 };
1548 1535 meta = {
1549 1536 license = [ pkgs.lib.licenses.mit ];
1550 1537 };
1551 1538 };
1552 1539 pytest-runner = super.buildPythonPackage {
1553 1540 name = "pytest-runner-2.11.1";
1554 1541 buildInputs = with self; [];
1555 1542 doCheck = false;
1556 1543 propagatedBuildInputs = with self; [];
1557 1544 src = fetchurl {
1558 1545 url = "https://pypi.python.org/packages/9e/4d/08889e5e27a9f5d6096b9ad257f4dea1faabb03c5ded8f665ead448f5d8a/pytest-runner-2.11.1.tar.gz";
1559 1546 md5 = "bdb73eb18eca2727944a2dcf963c5a81";
1560 1547 };
1561 1548 meta = {
1562 1549 license = [ pkgs.lib.licenses.mit ];
1563 1550 };
1564 1551 };
1565 1552 pytest-sugar = super.buildPythonPackage {
1566 1553 name = "pytest-sugar-0.8.0";
1567 1554 buildInputs = with self; [];
1568 1555 doCheck = false;
1569 1556 propagatedBuildInputs = with self; [pytest termcolor];
1570 1557 src = fetchurl {
1571 1558 url = "https://pypi.python.org/packages/a5/b0/b2773dee078f17773a5bf2dfad49b0be57b6354bbd84bbefe4313e509d87/pytest-sugar-0.8.0.tar.gz";
1572 1559 md5 = "8cafbdad648068e0e44b8fc5f9faae42";
1573 1560 };
1574 1561 meta = {
1575 1562 license = [ pkgs.lib.licenses.bsdOriginal ];
1576 1563 };
1577 1564 };
1578 1565 pytest-timeout = super.buildPythonPackage {
1579 1566 name = "pytest-timeout-1.2.0";
1580 1567 buildInputs = with self; [];
1581 1568 doCheck = false;
1582 1569 propagatedBuildInputs = with self; [pytest];
1583 1570 src = fetchurl {
1584 1571 url = "https://pypi.python.org/packages/cc/b7/b2a61365ea6b6d2e8881360ae7ed8dad0327ad2df89f2f0be4a02304deb2/pytest-timeout-1.2.0.tar.gz";
1585 1572 md5 = "83607d91aa163562c7ee835da57d061d";
1586 1573 };
1587 1574 meta = {
1588 1575 license = [ pkgs.lib.licenses.mit { fullName = "DFSG approved"; } ];
1589 1576 };
1590 1577 };
1591 1578 python-dateutil = super.buildPythonPackage {
1592 1579 name = "python-dateutil-2.1";
1593 1580 buildInputs = with self; [];
1594 1581 doCheck = false;
1595 1582 propagatedBuildInputs = with self; [six];
1596 1583 src = fetchurl {
1597 1584 url = "https://pypi.python.org/packages/65/52/9c18dac21f174ad31b65e22d24297864a954e6fe65876eba3f5773d2da43/python-dateutil-2.1.tar.gz";
1598 1585 md5 = "1534bb15cf311f07afaa3aacba1c028b";
1599 1586 };
1600 1587 meta = {
1601 1588 license = [ { fullName = "Simplified BSD"; } ];
1602 1589 };
1603 1590 };
1604 1591 python-editor = super.buildPythonPackage {
1605 1592 name = "python-editor-1.0.3";
1606 1593 buildInputs = with self; [];
1607 1594 doCheck = false;
1608 1595 propagatedBuildInputs = with self; [];
1609 1596 src = fetchurl {
1610 1597 url = "https://pypi.python.org/packages/65/1e/adf6e000ea5dc909aa420352d6ba37f16434c8a3c2fa030445411a1ed545/python-editor-1.0.3.tar.gz";
1611 1598 md5 = "0aca5f2ef176ce68e98a5b7e31372835";
1612 1599 };
1613 1600 meta = {
1614 1601 license = [ pkgs.lib.licenses.asl20 { fullName = "Apache"; } ];
1615 1602 };
1616 1603 };
1617 1604 python-ldap = super.buildPythonPackage {
1618 1605 name = "python-ldap-2.4.40";
1619 1606 buildInputs = with self; [];
1620 1607 doCheck = false;
1621 1608 propagatedBuildInputs = with self; [setuptools];
1622 1609 src = fetchurl {
1623 1610 url = "https://pypi.python.org/packages/4a/d8/7d70a7469058a3987d224061a81d778951ac2b48220bdcc511e4b1b37176/python-ldap-2.4.40.tar.gz";
1624 1611 md5 = "aea0233f7d39b0c7549fcd310deeb0e5";
1625 1612 };
1626 1613 meta = {
1627 1614 license = [ pkgs.lib.licenses.psfl ];
1628 1615 };
1629 1616 };
1630 1617 python-memcached = super.buildPythonPackage {
1631 1618 name = "python-memcached-1.58";
1632 1619 buildInputs = with self; [];
1633 1620 doCheck = false;
1634 1621 propagatedBuildInputs = with self; [six];
1635 1622 src = fetchurl {
1636 1623 url = "https://pypi.python.org/packages/f7/62/14b2448cfb04427366f24104c9da97cf8ea380d7258a3233f066a951a8d8/python-memcached-1.58.tar.gz";
1637 1624 md5 = "23b258105013d14d899828d334e6b044";
1638 1625 };
1639 1626 meta = {
1640 1627 license = [ pkgs.lib.licenses.psfl ];
1641 1628 };
1642 1629 };
1643 1630 python-pam = super.buildPythonPackage {
1644 1631 name = "python-pam-1.8.2";
1645 1632 buildInputs = with self; [];
1646 1633 doCheck = false;
1647 1634 propagatedBuildInputs = with self; [];
1648 1635 src = fetchurl {
1649 1636 url = "https://pypi.python.org/packages/de/8c/f8f5d38b4f26893af267ea0b39023d4951705ab0413a39e0cf7cf4900505/python-pam-1.8.2.tar.gz";
1650 1637 md5 = "db71b6b999246fb05d78ecfbe166629d";
1651 1638 };
1652 1639 meta = {
1653 1640 license = [ { fullName = "License :: OSI Approved :: MIT License"; } pkgs.lib.licenses.mit ];
1654 1641 };
1655 1642 };
1656 1643 pytz = super.buildPythonPackage {
1657 1644 name = "pytz-2015.4";
1658 1645 buildInputs = with self; [];
1659 1646 doCheck = false;
1660 1647 propagatedBuildInputs = with self; [];
1661 1648 src = fetchurl {
1662 1649 url = "https://pypi.python.org/packages/7e/1a/f43b5c92df7b156822030fed151327ea096bcf417e45acc23bd1df43472f/pytz-2015.4.zip";
1663 1650 md5 = "233f2a2b370d03f9b5911700cc9ebf3c";
1664 1651 };
1665 1652 meta = {
1666 1653 license = [ pkgs.lib.licenses.mit ];
1667 1654 };
1668 1655 };
1669 1656 pyzmq = super.buildPythonPackage {
1670 1657 name = "pyzmq-14.6.0";
1671 1658 buildInputs = with self; [];
1672 1659 doCheck = false;
1673 1660 propagatedBuildInputs = with self; [];
1674 1661 src = fetchurl {
1675 1662 url = "https://pypi.python.org/packages/8a/3b/5463d5a9d712cd8bbdac335daece0d69f6a6792da4e3dd89956c0db4e4e6/pyzmq-14.6.0.tar.gz";
1676 1663 md5 = "395b5de95a931afa5b14c9349a5b8024";
1677 1664 };
1678 1665 meta = {
1679 1666 license = [ pkgs.lib.licenses.bsdOriginal { fullName = "LGPL+BSD"; } { fullName = "GNU Library or Lesser General Public License (LGPL)"; } ];
1680 1667 };
1681 1668 };
1682 1669 recaptcha-client = super.buildPythonPackage {
1683 1670 name = "recaptcha-client-1.0.6";
1684 1671 buildInputs = with self; [];
1685 1672 doCheck = false;
1686 1673 propagatedBuildInputs = with self; [];
1687 1674 src = fetchurl {
1688 1675 url = "https://pypi.python.org/packages/0a/ea/5f2fbbfd894bdac1c68ef8d92019066cfcf9fbff5fe3d728d2b5c25c8db4/recaptcha-client-1.0.6.tar.gz";
1689 1676 md5 = "74228180f7e1fb76c4d7089160b0d919";
1690 1677 };
1691 1678 meta = {
1692 1679 license = [ { fullName = "MIT/X11"; } ];
1693 1680 };
1694 1681 };
1695 1682 repoze.lru = super.buildPythonPackage {
1696 1683 name = "repoze.lru-0.6";
1697 1684 buildInputs = with self; [];
1698 1685 doCheck = false;
1699 1686 propagatedBuildInputs = with self; [];
1700 1687 src = fetchurl {
1701 1688 url = "https://pypi.python.org/packages/6e/1e/aa15cc90217e086dc8769872c8778b409812ff036bf021b15795638939e4/repoze.lru-0.6.tar.gz";
1702 1689 md5 = "2c3b64b17a8e18b405f55d46173e14dd";
1703 1690 };
1704 1691 meta = {
1705 1692 license = [ { fullName = "Repoze Public License"; } { fullName = "BSD-derived (http://www.repoze.org/LICENSE.txt)"; } ];
1706 1693 };
1707 1694 };
1708 1695 requests = super.buildPythonPackage {
1709 1696 name = "requests-2.9.1";
1710 1697 buildInputs = with self; [];
1711 1698 doCheck = false;
1712 1699 propagatedBuildInputs = with self; [];
1713 1700 src = fetchurl {
1714 1701 url = "https://pypi.python.org/packages/f9/6d/07c44fb1ebe04d069459a189e7dab9e4abfe9432adcd4477367c25332748/requests-2.9.1.tar.gz";
1715 1702 md5 = "0b7f480d19012ec52bab78292efd976d";
1716 1703 };
1717 1704 meta = {
1718 1705 license = [ pkgs.lib.licenses.asl20 ];
1719 1706 };
1720 1707 };
1721 1708 rhodecode-enterprise-ce = super.buildPythonPackage {
1722 1709 name = "rhodecode-enterprise-ce-4.9.0";
1723 1710 buildInputs = with self; [pytest py pytest-cov pytest-sugar pytest-runner pytest-catchlog pytest-profiling gprof2dot pytest-timeout mock WebTest cov-core coverage configobj];
1724 1711 doCheck = true;
1725 propagatedBuildInputs = with self; [Babel Beaker FormEncode Mako Markdown MarkupSafe MySQL-python Paste PasteDeploy PasteScript Pygments pygments-markdown-lexer Pylons Routes SQLAlchemy Tempita URLObject WebError WebHelpers WebHelpers2 WebOb WebTest Whoosh alembic amqplib anyjson appenlight-client authomatic cssselect celery channelstream colander decorator deform docutils gevent gunicorn infrae.cache ipython iso8601 kombu lxml msgpack-python nbconvert packaging psycopg2 py-gfm pycrypto pycurl pyparsing pyramid pyramid-debugtoolbar pyramid-mako pyramid-beaker pysqlite python-dateutil python-ldap python-memcached python-pam recaptcha-client repoze.lru requests simplejson subprocess32 waitress zope.cachedescriptors dogpile.cache dogpile.core psutil py-bcrypt];
1712 propagatedBuildInputs = with self; [Babel Beaker FormEncode Mako Markdown MarkupSafe MySQL-python Paste PasteDeploy PasteScript Pygments pygments-markdown-lexer Pylons Routes SQLAlchemy Tempita URLObject WebError WebHelpers WebHelpers2 WebOb WebTest Whoosh alembic amqplib anyjson appenlight-client authomatic cssselect celery channelstream colander decorator deform docutils gevent gunicorn infrae.cache ipython iso8601 kombu lxml msgpack-python nbconvert packaging psycopg2 py-gfm pycrypto pycurl pyparsing pyramid pyramid-debugtoolbar pyramid-mako pyramid-beaker pysqlite python-dateutil python-ldap python-memcached python-pam recaptcha-client repoze.lru requests simplejson sshpubkeys subprocess32 waitress zope.cachedescriptors dogpile.cache dogpile.core psutil py-bcrypt];
1726 1713 src = ./.;
1727 1714 meta = {
1728 1715 license = [ { fullName = "Affero GNU General Public License v3 or later (AGPLv3+)"; } { fullName = "AGPLv3, and Commercial License"; } ];
1729 1716 };
1730 1717 };
1731 1718 rhodecode-tools = super.buildPythonPackage {
1732 1719 name = "rhodecode-tools-0.12.0";
1733 1720 buildInputs = with self; [];
1734 1721 doCheck = false;
1735 1722 propagatedBuildInputs = with self; [click future six Mako MarkupSafe requests elasticsearch elasticsearch-dsl urllib3 Whoosh];
1736 1723 src = fetchurl {
1737 1724 url = "https://code.rhodecode.com/rhodecode-tools-ce/archive/v0.12.0.tar.gz?md5=9ca040356fa7e38d3f64529a4cffdca4";
1738 1725 md5 = "9ca040356fa7e38d3f64529a4cffdca4";
1739 1726 };
1740 1727 meta = {
1741 1728 license = [ { fullName = "AGPLv3 and Proprietary"; } ];
1742 1729 };
1743 1730 };
1744 1731 scandir = super.buildPythonPackage {
1745 1732 name = "scandir-1.5";
1746 1733 buildInputs = with self; [];
1747 1734 doCheck = false;
1748 1735 propagatedBuildInputs = with self; [];
1749 1736 src = fetchurl {
1750 1737 url = "https://pypi.python.org/packages/bd/f4/3143e0289faf0883228017dbc6387a66d0b468df646645e29e1eb89ea10e/scandir-1.5.tar.gz";
1751 1738 md5 = "a2713043de681bba6b084be42e7a8a44";
1752 1739 };
1753 1740 meta = {
1754 1741 license = [ pkgs.lib.licenses.bsdOriginal { fullName = "New BSD License"; } ];
1755 1742 };
1756 1743 };
1757 1744 setproctitle = super.buildPythonPackage {
1758 1745 name = "setproctitle-1.1.8";
1759 1746 buildInputs = with self; [];
1760 1747 doCheck = false;
1761 1748 propagatedBuildInputs = with self; [];
1762 1749 src = fetchurl {
1763 1750 url = "https://pypi.python.org/packages/33/c3/ad367a4f4f1ca90468863ae727ac62f6edb558fc09a003d344a02cfc6ea6/setproctitle-1.1.8.tar.gz";
1764 1751 md5 = "728f4c8c6031bbe56083a48594027edd";
1765 1752 };
1766 1753 meta = {
1767 1754 license = [ pkgs.lib.licenses.bsdOriginal ];
1768 1755 };
1769 1756 };
1770 1757 setuptools = super.buildPythonPackage {
1771 1758 name = "setuptools-30.1.0";
1772 1759 buildInputs = with self; [];
1773 1760 doCheck = false;
1774 1761 propagatedBuildInputs = with self; [];
1775 1762 src = fetchurl {
1776 1763 url = "https://pypi.python.org/packages/1e/43/002c8616db9a3e7be23c2556e39b90a32bb40ba0dc652de1999d5334d372/setuptools-30.1.0.tar.gz";
1777 1764 md5 = "cac497f42e5096ac8df29e38d3f81c3e";
1778 1765 };
1779 1766 meta = {
1780 1767 license = [ pkgs.lib.licenses.mit ];
1781 1768 };
1782 1769 };
1783 1770 setuptools-scm = super.buildPythonPackage {
1784 1771 name = "setuptools-scm-1.15.0";
1785 1772 buildInputs = with self; [];
1786 1773 doCheck = false;
1787 1774 propagatedBuildInputs = with self; [];
1788 1775 src = fetchurl {
1789 1776 url = "https://pypi.python.org/packages/80/b7/31b6ae5fcb188e37f7e31abe75f9be90490a5456a72860fa6e643f8a3cbc/setuptools_scm-1.15.0.tar.gz";
1790 1777 md5 = "b6916c78ed6253d6602444fad4279c5b";
1791 1778 };
1792 1779 meta = {
1793 1780 license = [ pkgs.lib.licenses.mit ];
1794 1781 };
1795 1782 };
1796 1783 simplegeneric = super.buildPythonPackage {
1797 1784 name = "simplegeneric-0.8.1";
1798 1785 buildInputs = with self; [];
1799 1786 doCheck = false;
1800 1787 propagatedBuildInputs = with self; [];
1801 1788 src = fetchurl {
1802 1789 url = "https://pypi.python.org/packages/3d/57/4d9c9e3ae9a255cd4e1106bb57e24056d3d0709fc01b2e3e345898e49d5b/simplegeneric-0.8.1.zip";
1803 1790 md5 = "f9c1fab00fd981be588fc32759f474e3";
1804 1791 };
1805 1792 meta = {
1806 1793 license = [ pkgs.lib.licenses.zpt21 ];
1807 1794 };
1808 1795 };
1809 1796 simplejson = super.buildPythonPackage {
1810 1797 name = "simplejson-3.11.1";
1811 1798 buildInputs = with self; [];
1812 1799 doCheck = false;
1813 1800 propagatedBuildInputs = with self; [];
1814 1801 src = fetchurl {
1815 1802 url = "https://pypi.python.org/packages/08/48/c97b668d6da7d7bebe7ea1817a6f76394b0ec959cb04214ca833c34359df/simplejson-3.11.1.tar.gz";
1816 1803 md5 = "6e2f1bd5fb0a926facf5d89d217a7183";
1817 1804 };
1818 1805 meta = {
1819 1806 license = [ { fullName = "Academic Free License (AFL)"; } pkgs.lib.licenses.mit ];
1820 1807 };
1821 1808 };
1822 1809 six = super.buildPythonPackage {
1823 1810 name = "six-1.9.0";
1824 1811 buildInputs = with self; [];
1825 1812 doCheck = false;
1826 1813 propagatedBuildInputs = with self; [];
1827 1814 src = fetchurl {
1828 1815 url = "https://pypi.python.org/packages/16/64/1dc5e5976b17466fd7d712e59cbe9fb1e18bec153109e5ba3ed6c9102f1a/six-1.9.0.tar.gz";
1829 1816 md5 = "476881ef4012262dfc8adc645ee786c4";
1830 1817 };
1831 1818 meta = {
1832 1819 license = [ pkgs.lib.licenses.mit ];
1833 1820 };
1834 1821 };
1822 sshpubkeys = super.buildPythonPackage {
1823 name = "sshpubkeys-2.2.0";
1824 buildInputs = with self; [];
1825 doCheck = false;
1826 propagatedBuildInputs = with self; [pycrypto ecdsa];
1827 src = fetchurl {
1828 url = "https://pypi.python.org/packages/27/da/337fabeb3dca6b62039a93ceaa636f25065e0ae92b575b1235342076cf0a/sshpubkeys-2.2.0.tar.gz";
1829 md5 = "458e45f6b92b1afa84f0ffe1f1c90935";
1830 };
1831 meta = {
1832 license = [ pkgs.lib.licenses.bsdOriginal ];
1833 };
1834 };
1835 1835 subprocess32 = super.buildPythonPackage {
1836 1836 name = "subprocess32-3.2.7";
1837 1837 buildInputs = with self; [];
1838 1838 doCheck = false;
1839 1839 propagatedBuildInputs = with self; [];
1840 1840 src = fetchurl {
1841 1841 url = "https://pypi.python.org/packages/b8/2f/49e53b0d0e94611a2dc624a1ad24d41b6d94d0f1b0a078443407ea2214c2/subprocess32-3.2.7.tar.gz";
1842 1842 md5 = "824c801e479d3e916879aae3e9c15e16";
1843 1843 };
1844 1844 meta = {
1845 1845 license = [ pkgs.lib.licenses.psfl ];
1846 1846 };
1847 1847 };
1848 1848 supervisor = super.buildPythonPackage {
1849 1849 name = "supervisor-3.3.2";
1850 1850 buildInputs = with self; [];
1851 1851 doCheck = false;
1852 1852 propagatedBuildInputs = with self; [meld3];
1853 1853 src = fetchurl {
1854 1854 url = "https://pypi.python.org/packages/7b/17/88adf8cb25f80e2bc0d18e094fcd7ab300632ea00b601cbbbb84c2419eae/supervisor-3.3.2.tar.gz";
1855 1855 md5 = "04766d62864da13d6a12f7429e75314f";
1856 1856 };
1857 1857 meta = {
1858 1858 license = [ { fullName = "BSD-derived (http://www.repoze.org/LICENSE.txt)"; } ];
1859 1859 };
1860 1860 };
1861 1861 termcolor = super.buildPythonPackage {
1862 1862 name = "termcolor-1.1.0";
1863 1863 buildInputs = with self; [];
1864 1864 doCheck = false;
1865 1865 propagatedBuildInputs = with self; [];
1866 1866 src = fetchurl {
1867 1867 url = "https://pypi.python.org/packages/8a/48/a76be51647d0eb9f10e2a4511bf3ffb8cc1e6b14e9e4fab46173aa79f981/termcolor-1.1.0.tar.gz";
1868 1868 md5 = "043e89644f8909d462fbbfa511c768df";
1869 1869 };
1870 1870 meta = {
1871 1871 license = [ pkgs.lib.licenses.mit ];
1872 1872 };
1873 1873 };
1874 1874 testpath = super.buildPythonPackage {
1875 1875 name = "testpath-0.3.1";
1876 1876 buildInputs = with self; [];
1877 1877 doCheck = false;
1878 1878 propagatedBuildInputs = with self; [];
1879 1879 src = fetchurl {
1880 1880 url = "https://pypi.python.org/packages/f4/8b/b71e9ee10e5f751e9d959bc750ab122ba04187f5aa52aabdc4e63b0e31a7/testpath-0.3.1.tar.gz";
1881 1881 md5 = "2cd5ed5522fda781bb497c9d80ae2fc9";
1882 1882 };
1883 1883 meta = {
1884 1884 license = [ pkgs.lib.licenses.mit ];
1885 1885 };
1886 1886 };
1887 1887 traitlets = super.buildPythonPackage {
1888 1888 name = "traitlets-4.3.2";
1889 1889 buildInputs = with self; [];
1890 1890 doCheck = false;
1891 1891 propagatedBuildInputs = with self; [ipython-genutils six decorator enum34];
1892 1892 src = fetchurl {
1893 1893 url = "https://pypi.python.org/packages/a5/98/7f5ef2fe9e9e071813aaf9cb91d1a732e0a68b6c44a32b38cb8e14c3f069/traitlets-4.3.2.tar.gz";
1894 1894 md5 = "3068663f2f38fd939a9eb3a500ccc154";
1895 1895 };
1896 1896 meta = {
1897 1897 license = [ pkgs.lib.licenses.bsdOriginal ];
1898 1898 };
1899 1899 };
1900 1900 transifex-client = super.buildPythonPackage {
1901 1901 name = "transifex-client-0.10";
1902 1902 buildInputs = with self; [];
1903 1903 doCheck = false;
1904 1904 propagatedBuildInputs = with self; [];
1905 1905 src = fetchurl {
1906 1906 url = "https://pypi.python.org/packages/f3/4e/7b925192aee656fb3e04fa6381c8b3dc40198047c3b4a356f6cfd642c809/transifex-client-0.10.tar.gz";
1907 1907 md5 = "5549538d84b8eede6b254cd81ae024fa";
1908 1908 };
1909 1909 meta = {
1910 1910 license = [ pkgs.lib.licenses.gpl2 ];
1911 1911 };
1912 1912 };
1913 1913 translationstring = super.buildPythonPackage {
1914 1914 name = "translationstring-1.3";
1915 1915 buildInputs = with self; [];
1916 1916 doCheck = false;
1917 1917 propagatedBuildInputs = with self; [];
1918 1918 src = fetchurl {
1919 1919 url = "https://pypi.python.org/packages/5e/eb/bee578cc150b44c653b63f5ebe258b5d0d812ddac12497e5f80fcad5d0b4/translationstring-1.3.tar.gz";
1920 1920 md5 = "a4b62e0f3c189c783a1685b3027f7c90";
1921 1921 };
1922 1922 meta = {
1923 1923 license = [ { fullName = "BSD-like (http://repoze.org/license.html)"; } ];
1924 1924 };
1925 1925 };
1926 1926 trollius = super.buildPythonPackage {
1927 1927 name = "trollius-1.0.4";
1928 1928 buildInputs = with self; [];
1929 1929 doCheck = false;
1930 1930 propagatedBuildInputs = with self; [futures];
1931 1931 src = fetchurl {
1932 1932 url = "https://pypi.python.org/packages/aa/e6/4141db437f55e6ee7a3fb69663239e3fde7841a811b4bef293145ad6c836/trollius-1.0.4.tar.gz";
1933 1933 md5 = "3631a464d49d0cbfd30ab2918ef2b783";
1934 1934 };
1935 1935 meta = {
1936 1936 license = [ pkgs.lib.licenses.asl20 ];
1937 1937 };
1938 1938 };
1939 1939 uWSGI = super.buildPythonPackage {
1940 1940 name = "uWSGI-2.0.15";
1941 1941 buildInputs = with self; [];
1942 1942 doCheck = false;
1943 1943 propagatedBuildInputs = with self; [];
1944 1944 src = fetchurl {
1945 1945 url = "https://pypi.python.org/packages/bb/0a/45e5aa80dc135889594bb371c082d20fb7ee7303b174874c996888cc8511/uwsgi-2.0.15.tar.gz";
1946 1946 md5 = "fc50bd9e83b7602fa474b032167010a7";
1947 1947 };
1948 1948 meta = {
1949 1949 license = [ pkgs.lib.licenses.gpl2 ];
1950 1950 };
1951 1951 };
1952 1952 urllib3 = super.buildPythonPackage {
1953 1953 name = "urllib3-1.16";
1954 1954 buildInputs = with self; [];
1955 1955 doCheck = false;
1956 1956 propagatedBuildInputs = with self; [];
1957 1957 src = fetchurl {
1958 1958 url = "https://pypi.python.org/packages/3b/f0/e763169124e3f5db0926bc3dbfcd580a105f9ca44cf5d8e6c7a803c9f6b5/urllib3-1.16.tar.gz";
1959 1959 md5 = "fcaab1c5385c57deeb7053d3d7d81d59";
1960 1960 };
1961 1961 meta = {
1962 1962 license = [ pkgs.lib.licenses.mit ];
1963 1963 };
1964 1964 };
1965 1965 venusian = super.buildPythonPackage {
1966 1966 name = "venusian-1.1.0";
1967 1967 buildInputs = with self; [];
1968 1968 doCheck = false;
1969 1969 propagatedBuildInputs = with self; [];
1970 1970 src = fetchurl {
1971 1971 url = "https://pypi.python.org/packages/38/24/b4b470ab9e0a2e2e9b9030c7735828c8934b4c6b45befd1bb713ec2aeb2d/venusian-1.1.0.tar.gz";
1972 1972 md5 = "56bc5e6756e4bda37bcdb94f74a72b8f";
1973 1973 };
1974 1974 meta = {
1975 1975 license = [ { fullName = "BSD-derived (http://www.repoze.org/LICENSE.txt)"; } ];
1976 1976 };
1977 1977 };
1978 1978 waitress = super.buildPythonPackage {
1979 1979 name = "waitress-1.0.2";
1980 1980 buildInputs = with self; [];
1981 1981 doCheck = false;
1982 1982 propagatedBuildInputs = with self; [];
1983 1983 src = fetchurl {
1984 1984 url = "https://pypi.python.org/packages/cd/f4/400d00863afa1e03618e31fd7e2092479a71b8c9718b00eb1eeb603746c6/waitress-1.0.2.tar.gz";
1985 1985 md5 = "b968f39e95d609f6194c6e50425d4bb7";
1986 1986 };
1987 1987 meta = {
1988 1988 license = [ pkgs.lib.licenses.zpt21 ];
1989 1989 };
1990 1990 };
1991 1991 wcwidth = super.buildPythonPackage {
1992 1992 name = "wcwidth-0.1.7";
1993 1993 buildInputs = with self; [];
1994 1994 doCheck = false;
1995 1995 propagatedBuildInputs = with self; [];
1996 1996 src = fetchurl {
1997 1997 url = "https://pypi.python.org/packages/55/11/e4a2bb08bb450fdbd42cc709dd40de4ed2c472cf0ccb9e64af22279c5495/wcwidth-0.1.7.tar.gz";
1998 1998 md5 = "b3b6a0a08f0c8a34d1de8cf44150a4ad";
1999 1999 };
2000 2000 meta = {
2001 2001 license = [ pkgs.lib.licenses.mit ];
2002 2002 };
2003 2003 };
2004 2004 ws4py = super.buildPythonPackage {
2005 2005 name = "ws4py-0.3.5";
2006 2006 buildInputs = with self; [];
2007 2007 doCheck = false;
2008 2008 propagatedBuildInputs = with self; [];
2009 2009 src = fetchurl {
2010 2010 url = "https://pypi.python.org/packages/b6/4f/34af703be86939629479e74d6e650e39f3bd73b3b09212c34e5125764cbc/ws4py-0.3.5.zip";
2011 2011 md5 = "a261b75c20b980e55ce7451a3576a867";
2012 2012 };
2013 2013 meta = {
2014 2014 license = [ pkgs.lib.licenses.bsdOriginal ];
2015 2015 };
2016 2016 };
2017 2017 wsgiref = super.buildPythonPackage {
2018 2018 name = "wsgiref-0.1.2";
2019 2019 buildInputs = with self; [];
2020 2020 doCheck = false;
2021 2021 propagatedBuildInputs = with self; [];
2022 2022 src = fetchurl {
2023 2023 url = "https://pypi.python.org/packages/41/9e/309259ce8dff8c596e8c26df86dbc4e848b9249fd36797fd60be456f03fc/wsgiref-0.1.2.zip";
2024 2024 md5 = "29b146e6ebd0f9fb119fe321f7bcf6cb";
2025 2025 };
2026 2026 meta = {
2027 2027 license = [ { fullName = "PSF or ZPL"; } ];
2028 2028 };
2029 2029 };
2030 2030 zope.cachedescriptors = super.buildPythonPackage {
2031 2031 name = "zope.cachedescriptors-4.0.0";
2032 2032 buildInputs = with self; [];
2033 2033 doCheck = false;
2034 2034 propagatedBuildInputs = with self; [setuptools];
2035 2035 src = fetchurl {
2036 2036 url = "https://pypi.python.org/packages/40/33/694b6644c37f28553f4b9f20b3c3a20fb709a22574dff20b5bdffb09ecd5/zope.cachedescriptors-4.0.0.tar.gz";
2037 2037 md5 = "8d308de8c936792c8e758058fcb7d0f0";
2038 2038 };
2039 2039 meta = {
2040 2040 license = [ pkgs.lib.licenses.zpt21 ];
2041 2041 };
2042 2042 };
2043 2043 zope.deprecation = super.buildPythonPackage {
2044 2044 name = "zope.deprecation-4.1.2";
2045 2045 buildInputs = with self; [];
2046 2046 doCheck = false;
2047 2047 propagatedBuildInputs = with self; [setuptools];
2048 2048 src = fetchurl {
2049 2049 url = "https://pypi.python.org/packages/c1/d3/3919492d5e57d8dd01b36f30b34fc8404a30577392b1eb817c303499ad20/zope.deprecation-4.1.2.tar.gz";
2050 2050 md5 = "e9a663ded58f4f9f7881beb56cae2782";
2051 2051 };
2052 2052 meta = {
2053 2053 license = [ pkgs.lib.licenses.zpt21 ];
2054 2054 };
2055 2055 };
2056 2056 zope.event = super.buildPythonPackage {
2057 2057 name = "zope.event-4.0.3";
2058 2058 buildInputs = with self; [];
2059 2059 doCheck = false;
2060 2060 propagatedBuildInputs = with self; [setuptools];
2061 2061 src = fetchurl {
2062 2062 url = "https://pypi.python.org/packages/c1/29/91ba884d7d6d96691df592e9e9c2bfa57a47040ec1ff47eff18c85137152/zope.event-4.0.3.tar.gz";
2063 2063 md5 = "9a3780916332b18b8b85f522bcc3e249";
2064 2064 };
2065 2065 meta = {
2066 2066 license = [ pkgs.lib.licenses.zpt21 ];
2067 2067 };
2068 2068 };
2069 2069 zope.interface = super.buildPythonPackage {
2070 2070 name = "zope.interface-4.1.3";
2071 2071 buildInputs = with self; [];
2072 2072 doCheck = false;
2073 2073 propagatedBuildInputs = with self; [setuptools];
2074 2074 src = fetchurl {
2075 2075 url = "https://pypi.python.org/packages/9d/81/2509ca3c6f59080123c1a8a97125eb48414022618cec0e64eb1313727bfe/zope.interface-4.1.3.tar.gz";
2076 2076 md5 = "9ae3d24c0c7415deb249dd1a132f0f79";
2077 2077 };
2078 2078 meta = {
2079 2079 license = [ pkgs.lib.licenses.zpt21 ];
2080 2080 };
2081 2081 };
2082 2082
2083 2083 ### Test requirements
2084 2084
2085 2085
2086 2086 }
@@ -1,135 +1,135 b''
1 1 ## core
2 2 setuptools==30.1.0
3 3 setuptools-scm==1.15.0
4 4
5 5 amqplib==1.0.2
6 6 anyjson==0.3.3
7 7 authomatic==0.1.0.post1
8 8 Babel==1.3
9 9 Beaker==1.9.0
10 10 celery==2.2.10
11 11 Chameleon==2.24
12 12 channelstream==0.5.2
13 13 click==5.1
14 14 colander==1.3.3
15 15 configobj==5.0.6
16 16 cssselect==1.0.1
17 17 decorator==4.0.11
18 18 deform==2.0.4
19 19 docutils==0.13.1
20 20 dogpile.cache==0.6.4
21 21 dogpile.core==0.4.1
22 ecdsa==0.11
22 ecdsa==0.13
23 23 FormEncode==1.2.4
24 24 future==0.14.3
25 25 futures==3.0.2
26 26 gnureadline==6.3.3
27 27 infrae.cache==1.0.1
28 28 iso8601==0.1.11
29 29 itsdangerous==0.24
30 30 Jinja2==2.7.3
31 31 kombu==1.5.1
32 32 lxml==3.7.3
33 33 Mako==1.0.6
34 34 Markdown==2.6.8
35 35 MarkupSafe==0.23
36 36 meld3==1.0.2
37 37 msgpack-python==0.4.8
38 38 MySQL-python==1.2.5
39 39 nose==1.3.6
40 40 objgraph==3.1.0
41 41 packaging==15.2
42 paramiko==1.15.1
43 42 Paste==2.0.3
44 43 PasteDeploy==1.5.2
45 44 PasteScript==1.7.5
46 45 pathlib2==2.3.0
47 46 psutil==4.3.1
48 47 psycopg2==2.7.1
49 48 py-bcrypt==0.4
50 49 pycrypto==2.6.1
51 50 pycurl==7.19.5
52 51 pyflakes==0.8.1
53 52 pygments-markdown-lexer==0.1.0.dev39
54 53 Pygments==2.2.0
55 54 pyparsing==1.5.7
56 55 pyramid-beaker==0.8
57 56 pyramid-debugtoolbar==4.2.1
58 57 pyramid-jinja2==2.5
59 58 pyramid-mako==1.0.2
60 59 pyramid==1.9.0
61 60 pysqlite==2.8.3
62 61 python-dateutil==2.1
63 62 python-ldap==2.4.40
64 63 python-memcached==1.58
65 64 python-pam==1.8.2
66 65 pytz==2015.4
67 66 pyzmq==14.6.0
68 67 recaptcha-client==1.0.6
69 68 repoze.lru==0.6
70 69 requests==2.9.1
71 70 Routes==1.13
72 71 setproctitle==1.1.8
73 72 simplejson==3.11.1
74 73 six==1.9.0
75 74 Sphinx==1.2.2
76 75 SQLAlchemy==1.1.11
76 sshpubkeys==2.2.0
77 77 subprocess32==3.2.7
78 78 supervisor==3.3.2
79 79 Tempita==0.5.2
80 80 translationstring==1.3
81 81 trollius==1.0.4
82 82 urllib3==1.16
83 83 URLObject==2.4.0
84 84 venusian==1.1.0
85 85 WebError==0.10.3
86 86 WebHelpers2==2.0
87 87 WebHelpers==1.3
88 88 WebOb==1.7.3
89 89 Whoosh==2.7.4
90 90 wsgiref==0.1.2
91 91 zope.cachedescriptors==4.0.0
92 92 zope.deprecation==4.1.2
93 93 zope.event==4.0.3
94 94 zope.interface==4.1.3
95 95
96 96 ## customized/patched libs
97 97 # our patched version of Pylons==1.0.2
98 98 https://code.rhodecode.com/upstream/pylons/archive/707354ee4261b9c10450404fc9852ccea4fd667d.tar.gz?md5=f26633726fa2cd3a340316ee6a5d218f#egg=Pylons==1.0.2.rhodecode-patch-1
99 99 # not released py-gfm==0.1.3
100 100 https://code.rhodecode.com/upstream/py-gfm/archive/0d66a19bc16e3d49de273c0f797d4e4781e8c0f2.tar.gz?md5=0d0d5385bfb629eea636a80b9c2bfd16#egg=py-gfm==0.1.3.rhodecode-upstream1
101 101
102 102 # IPYTHON RENDERING
103 103 # entrypoints backport, pypi version doesn't support egg installs
104 104 https://code.rhodecode.com/upstream/entrypoints/archive/96e6d645684e1af3d7df5b5272f3fe85a546b233.tar.gz?md5=7db37771aea9ac9fefe093e5d6987313#egg=entrypoints==0.2.2.rhodecode-upstream1
105 105 nbconvert==5.1.1
106 106 nbformat==4.3.0
107 107 jupyter_client==5.0.0
108 108
109 109 ## cli tools
110 110 alembic==0.9.2
111 111 invoke==0.13.0
112 112 bumpversion==0.5.3
113 113 transifex-client==0.10
114 114
115 115 ## http servers
116 116 gevent==1.2.2
117 117 greenlet==0.4.12
118 118 gunicorn==19.7.1
119 119 waitress==1.0.2
120 120 uWSGI==2.0.15
121 121
122 122 ## debug
123 123 ipdb==0.10.3
124 124 ipython==5.1.0
125 125 CProfileV==1.0.7
126 126 bottle==0.12.8
127 127
128 128 ## rhodecode-tools, special case
129 129 https://code.rhodecode.com/rhodecode-tools-ce/archive/v0.12.0.tar.gz?md5=9ca040356fa7e38d3f64529a4cffdca4#egg=rhodecode-tools==0.12.0
130 130
131 131 ## appenlight
132 132 appenlight-client==0.6.21
133 133
134 134 ## test related requirements
135 135 -r requirements_test.txt
@@ -1,63 +1,63 b''
1 1 # -*- coding: utf-8 -*-
2 2
3 3 # Copyright (C) 2010-2017 RhodeCode GmbH
4 4 #
5 5 # This program is free software: you can redistribute it and/or modify
6 6 # it under the terms of the GNU Affero General Public License, version 3
7 7 # (only), as published by the Free Software Foundation.
8 8 #
9 9 # This program is distributed in the hope that it will be useful,
10 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 12 # GNU General Public License for more details.
13 13 #
14 14 # You should have received a copy of the GNU Affero General Public License
15 15 # along with this program. If not, see <http://www.gnu.org/licenses/>.
16 16 #
17 17 # This program is dual-licensed. If you wish to learn more about the
18 18 # RhodeCode Enterprise Edition, including its added features, Support services,
19 19 # and proprietary license terms, please see https://rhodecode.com/licenses/
20 20
21 21 """
22 22
23 23 RhodeCode, a web based repository management software
24 24 versioning implementation: http://www.python.org/dev/peps/pep-0386/
25 25 """
26 26
27 27 import os
28 28 import sys
29 29 import platform
30 30
31 31 VERSION = tuple(open(os.path.join(
32 32 os.path.dirname(__file__), 'VERSION')).read().split('.'))
33 33
34 34 BACKENDS = {
35 35 'hg': 'Mercurial repository',
36 36 'git': 'Git repository',
37 37 'svn': 'Subversion repository',
38 38 }
39 39
40 40 CELERY_ENABLED = False
41 41 CELERY_EAGER = False
42 42
43 43 # link to config for pylons
44 44 CONFIG = {}
45 45
46 46 # Populated with the settings dictionary from application init in
47 47 # rhodecode.conf.environment.load_pyramid_environment
48 48 PYRAMID_SETTINGS = {}
49 49
50 50 # Linked module for extensions
51 51 EXTENSIONS = {}
52 52
53 53 __version__ = ('.'.join((str(each) for each in VERSION[:3])))
54 __dbversion__ = 79 # defines current db version for migrations
54 __dbversion__ = 80 # defines current db version for migrations
55 55 __platform__ = platform.system()
56 56 __license__ = 'AGPLv3, and Commercial License'
57 57 __author__ = 'RhodeCode GmbH'
58 58 __url__ = 'https://code.rhodecode.com'
59 59
60 60 is_windows = __platform__ in ['Windows']
61 61 is_unix = not is_windows
62 62 is_test = False
63 63 disable_error_handler = False
@@ -1,192 +1,206 b''
1 1 # -*- coding: utf-8 -*-
2 2
3 3 # Copyright (C) 2016-2017 RhodeCode GmbH
4 4 #
5 5 # This program is free software: you can redistribute it and/or modify
6 6 # it under the terms of the GNU Affero General Public License, version 3
7 7 # (only), as published by the Free Software Foundation.
8 8 #
9 9 # This program is distributed in the hope that it will be useful,
10 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 12 # GNU General Public License for more details.
13 13 #
14 14 # You should have received a copy of the GNU Affero General Public License
15 15 # along with this program. If not, see <http://www.gnu.org/licenses/>.
16 16 #
17 17 # This program is dual-licensed. If you wish to learn more about the
18 18 # RhodeCode Enterprise Edition, including its added features, Support services,
19 19 # and proprietary license terms, please see https://rhodecode.com/licenses/
20 20
21 21
22 22 from rhodecode.apps.admin.navigation import NavigationRegistry
23 23 from rhodecode.config.routing import ADMIN_PREFIX
24 24 from rhodecode.lib.utils2 import str2bool
25 25
26 26
27 27 def admin_routes(config):
28 28 """
29 29 Admin prefixed routes
30 30 """
31 31
32 32 config.add_route(
33 33 name='admin_audit_logs',
34 34 pattern='/audit_logs')
35 35
36 36 config.add_route(
37 37 name='pull_requests_global_0', # backward compat
38 38 pattern='/pull_requests/{pull_request_id:\d+}')
39 39 config.add_route(
40 40 name='pull_requests_global_1', # backward compat
41 41 pattern='/pull-requests/{pull_request_id:\d+}')
42 42 config.add_route(
43 43 name='pull_requests_global',
44 44 pattern='/pull-request/{pull_request_id:\d+}')
45 45
46 46 config.add_route(
47 47 name='admin_settings_open_source',
48 48 pattern='/settings/open_source')
49 49 config.add_route(
50 50 name='admin_settings_vcs_svn_generate_cfg',
51 51 pattern='/settings/vcs/svn_generate_cfg')
52 52
53 53 config.add_route(
54 54 name='admin_settings_system',
55 55 pattern='/settings/system')
56 56 config.add_route(
57 57 name='admin_settings_system_update',
58 58 pattern='/settings/system/updates')
59 59
60 60 config.add_route(
61 61 name='admin_settings_sessions',
62 62 pattern='/settings/sessions')
63 63 config.add_route(
64 64 name='admin_settings_sessions_cleanup',
65 65 pattern='/settings/sessions/cleanup')
66 66
67 67 config.add_route(
68 68 name='admin_settings_process_management',
69 69 pattern='/settings/process_management')
70 70 config.add_route(
71 71 name='admin_settings_process_management_signal',
72 72 pattern='/settings/process_management/signal')
73 73
74 74 # global permissions
75 75
76 76 config.add_route(
77 77 name='admin_permissions_application',
78 78 pattern='/permissions/application')
79 79 config.add_route(
80 80 name='admin_permissions_application_update',
81 81 pattern='/permissions/application/update')
82 82
83 83 config.add_route(
84 84 name='admin_permissions_global',
85 85 pattern='/permissions/global')
86 86 config.add_route(
87 87 name='admin_permissions_global_update',
88 88 pattern='/permissions/global/update')
89 89
90 90 config.add_route(
91 91 name='admin_permissions_object',
92 92 pattern='/permissions/object')
93 93 config.add_route(
94 94 name='admin_permissions_object_update',
95 95 pattern='/permissions/object/update')
96 96
97 97 config.add_route(
98 98 name='admin_permissions_ips',
99 99 pattern='/permissions/ips')
100 100
101 101 config.add_route(
102 102 name='admin_permissions_overview',
103 103 pattern='/permissions/overview')
104 104
105 105 config.add_route(
106 106 name='admin_permissions_auth_token_access',
107 107 pattern='/permissions/auth_token_access')
108 108
109 109 # users admin
110 110 config.add_route(
111 111 name='users',
112 112 pattern='/users')
113 113
114 114 config.add_route(
115 115 name='users_data',
116 116 pattern='/users_data')
117 117
118 118 # user auth tokens
119 119 config.add_route(
120 120 name='edit_user_auth_tokens',
121 121 pattern='/users/{user_id:\d+}/edit/auth_tokens')
122 122 config.add_route(
123 123 name='edit_user_auth_tokens_add',
124 124 pattern='/users/{user_id:\d+}/edit/auth_tokens/new')
125 125 config.add_route(
126 126 name='edit_user_auth_tokens_delete',
127 127 pattern='/users/{user_id:\d+}/edit/auth_tokens/delete')
128 128
129 # user ssh keys
130 config.add_route(
131 name='edit_user_ssh_keys',
132 pattern='/users/{user_id:\d+}/edit/ssh_keys')
133 config.add_route(
134 name='edit_user_ssh_keys_generate_keypair',
135 pattern='/users/{user_id:\d+}/edit/ssh_keys/generate')
136 config.add_route(
137 name='edit_user_ssh_keys_add',
138 pattern='/users/{user_id:\d+}/edit/ssh_keys/new')
139 config.add_route(
140 name='edit_user_ssh_keys_delete',
141 pattern='/users/{user_id:\d+}/edit/ssh_keys/delete')
142
129 143 # user emails
130 144 config.add_route(
131 145 name='edit_user_emails',
132 146 pattern='/users/{user_id:\d+}/edit/emails')
133 147 config.add_route(
134 148 name='edit_user_emails_add',
135 149 pattern='/users/{user_id:\d+}/edit/emails/new')
136 150 config.add_route(
137 151 name='edit_user_emails_delete',
138 152 pattern='/users/{user_id:\d+}/edit/emails/delete')
139 153
140 154 # user IPs
141 155 config.add_route(
142 156 name='edit_user_ips',
143 157 pattern='/users/{user_id:\d+}/edit/ips')
144 158 config.add_route(
145 159 name='edit_user_ips_add',
146 160 pattern='/users/{user_id:\d+}/edit/ips/new')
147 161 config.add_route(
148 162 name='edit_user_ips_delete',
149 163 pattern='/users/{user_id:\d+}/edit/ips/delete')
150 164
151 165 # user groups management
152 166 config.add_route(
153 167 name='edit_user_groups_management',
154 168 pattern='/users/{user_id:\d+}/edit/groups_management')
155 169
156 170 config.add_route(
157 171 name='edit_user_groups_management_updates',
158 172 pattern='/users/{user_id:\d+}/edit/edit_user_groups_management/updates')
159 173
160 174 # user audit logs
161 175 config.add_route(
162 176 name='edit_user_audit_logs',
163 177 pattern='/users/{user_id:\d+}/edit/audit')
164 178
165 179 # user groups admin
166 180 config.add_route(
167 181 name='user_groups',
168 182 pattern='/user_groups')
169 183
170 184 config.add_route(
171 185 name='user_groups_data',
172 186 pattern='/user_groups_data')
173 187
174 188 config.add_route(
175 189 name='user_group_members_data',
176 190 pattern='/user_groups/{user_group_id:\d+}/members')
177 191
178 192
179 193 def includeme(config):
180 194 settings = config.get_settings()
181 195
182 196 # Create admin navigation registry and add it to the pyramid registry.
183 197 labs_active = str2bool(settings.get('labs_settings_active', False))
184 198 navigation_registry = NavigationRegistry(labs_active=labs_active)
185 199 config.registry.registerUtility(navigation_registry)
186 200
187 201 # main admin routes
188 202 config.add_route(name='admin_home', pattern=ADMIN_PREFIX)
189 203 config.include(admin_routes, route_prefix=ADMIN_PREFIX)
190 204
191 205 # Scan module for configuration decorators.
192 206 config.scan('.views', ignore='.tests')
@@ -1,510 +1,630 b''
1 1 # -*- coding: utf-8 -*-
2 2
3 3 # Copyright (C) 2016-2017 RhodeCode GmbH
4 4 #
5 5 # This program is free software: you can redistribute it and/or modify
6 6 # it under the terms of the GNU Affero General Public License, version 3
7 7 # (only), as published by the Free Software Foundation.
8 8 #
9 9 # This program is distributed in the hope that it will be useful,
10 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 12 # GNU General Public License for more details.
13 13 #
14 14 # You should have received a copy of the GNU Affero General Public License
15 15 # along with this program. If not, see <http://www.gnu.org/licenses/>.
16 16 #
17 17 # This program is dual-licensed. If you wish to learn more about the
18 18 # RhodeCode Enterprise Edition, including its added features, Support services,
19 19 # and proprietary license terms, please see https://rhodecode.com/licenses/
20 20
21 21 import logging
22 22 import datetime
23 23 import formencode
24 24
25 25 from pyramid.httpexceptions import HTTPFound
26 26 from pyramid.view import view_config
27 27 from sqlalchemy.sql.functions import coalesce
28 from sqlalchemy.exc import IntegrityError
28 29
29 30 from rhodecode.apps._base import BaseAppView, DataGridAppView
30 31
31 32 from rhodecode.lib import audit_logger
32 33 from rhodecode.lib.ext_json import json
33 34 from rhodecode.lib.auth import (
34 35 LoginRequired, HasPermissionAllDecorator, CSRFRequired)
35 36 from rhodecode.lib import helpers as h
36 37 from rhodecode.lib.utils2 import safe_int, safe_unicode
37 38 from rhodecode.model.auth_token import AuthTokenModel
39 from rhodecode.model.ssh_key import SshKeyModel
38 40 from rhodecode.model.user import UserModel
39 41 from rhodecode.model.user_group import UserGroupModel
40 from rhodecode.model.db import User, or_, UserIpMap, UserEmailMap, UserApiKeys
42 from rhodecode.model.db import (
43 or_, User, UserIpMap, UserEmailMap, UserApiKeys, UserSshKeys)
41 44 from rhodecode.model.meta import Session
42 45
43 46 log = logging.getLogger(__name__)
44 47
45 48
46 49 class AdminUsersView(BaseAppView, DataGridAppView):
47 50 ALLOW_SCOPED_TOKENS = False
48 51 """
49 52 This view has alternative version inside EE, if modified please take a look
50 53 in there as well.
51 54 """
52 55
53 56 def load_default_context(self):
54 57 c = self._get_local_tmpl_context()
55 58 c.allow_scoped_tokens = self.ALLOW_SCOPED_TOKENS
56 59 self._register_global_c(c)
57 60 return c
58 61
59 62 def _redirect_for_default_user(self, username):
60 63 _ = self.request.translate
61 64 if username == User.DEFAULT_USER:
62 65 h.flash(_("You can't edit this user"), category='warning')
63 66 # TODO(marcink): redirect to 'users' admin panel once this
64 67 # is a pyramid view
65 68 raise HTTPFound('/')
66 69
67 70 @HasPermissionAllDecorator('hg.admin')
68 71 @view_config(
69 72 route_name='users', request_method='GET',
70 73 renderer='rhodecode:templates/admin/users/users.mako')
71 74 def users_list(self):
72 75 c = self.load_default_context()
73 76 return self._get_template_context(c)
74 77
75 78 @HasPermissionAllDecorator('hg.admin')
76 79 @view_config(
77 80 # renderer defined below
78 81 route_name='users_data', request_method='GET',
79 82 renderer='json_ext', xhr=True)
80 83 def users_list_data(self):
81 84 column_map = {
82 85 'first_name': 'name',
83 86 'last_name': 'lastname',
84 87 }
85 88 draw, start, limit = self._extract_chunk(self.request)
86 89 search_q, order_by, order_dir = self._extract_ordering(
87 90 self.request, column_map=column_map)
88 91
89 92 _render = self.request.get_partial_renderer(
90 93 'data_table/_dt_elements.mako')
91 94
92 95 def user_actions(user_id, username):
93 96 return _render("user_actions", user_id, username)
94 97
95 98 users_data_total_count = User.query()\
96 99 .filter(User.username != User.DEFAULT_USER) \
97 100 .count()
98 101
99 102 # json generate
100 103 base_q = User.query().filter(User.username != User.DEFAULT_USER)
101 104
102 105 if search_q:
103 106 like_expression = u'%{}%'.format(safe_unicode(search_q))
104 107 base_q = base_q.filter(or_(
105 108 User.username.ilike(like_expression),
106 109 User._email.ilike(like_expression),
107 110 User.name.ilike(like_expression),
108 111 User.lastname.ilike(like_expression),
109 112 ))
110 113
111 114 users_data_total_filtered_count = base_q.count()
112 115
113 116 sort_col = getattr(User, order_by, None)
114 117 if sort_col:
115 118 if order_dir == 'asc':
116 119 # handle null values properly to order by NULL last
117 120 if order_by in ['last_activity']:
118 121 sort_col = coalesce(sort_col, datetime.date.max)
119 122 sort_col = sort_col.asc()
120 123 else:
121 124 # handle null values properly to order by NULL last
122 125 if order_by in ['last_activity']:
123 126 sort_col = coalesce(sort_col, datetime.date.min)
124 127 sort_col = sort_col.desc()
125 128
126 129 base_q = base_q.order_by(sort_col)
127 130 base_q = base_q.offset(start).limit(limit)
128 131
129 132 users_list = base_q.all()
130 133
131 134 users_data = []
132 135 for user in users_list:
133 136 users_data.append({
134 137 "username": h.gravatar_with_user(self.request, user.username),
135 138 "email": user.email,
136 139 "first_name": user.first_name,
137 140 "last_name": user.last_name,
138 141 "last_login": h.format_date(user.last_login),
139 142 "last_activity": h.format_date(user.last_activity),
140 143 "active": h.bool2icon(user.active),
141 144 "active_raw": user.active,
142 145 "admin": h.bool2icon(user.admin),
143 146 "extern_type": user.extern_type,
144 147 "extern_name": user.extern_name,
145 148 "action": user_actions(user.user_id, user.username),
146 149 })
147 150
148 151 data = ({
149 152 'draw': draw,
150 153 'data': users_data,
151 154 'recordsTotal': users_data_total_count,
152 155 'recordsFiltered': users_data_total_filtered_count,
153 156 })
154 157
155 158 return data
156 159
157 160 @LoginRequired()
158 161 @HasPermissionAllDecorator('hg.admin')
159 162 @view_config(
160 163 route_name='edit_user_auth_tokens', request_method='GET',
161 164 renderer='rhodecode:templates/admin/users/user_edit.mako')
162 165 def auth_tokens(self):
163 166 _ = self.request.translate
164 167 c = self.load_default_context()
165 168
166 169 user_id = self.request.matchdict.get('user_id')
167 170 c.user = User.get_or_404(user_id)
168 171 self._redirect_for_default_user(c.user.username)
169 172
170 173 c.active = 'auth_tokens'
171 174
172 175 c.lifetime_values = [
173 176 (str(-1), _('forever')),
174 177 (str(5), _('5 minutes')),
175 178 (str(60), _('1 hour')),
176 179 (str(60 * 24), _('1 day')),
177 180 (str(60 * 24 * 30), _('1 month')),
178 181 ]
179 182 c.lifetime_options = [(c.lifetime_values, _("Lifetime"))]
180 183 c.role_values = [
181 184 (x, AuthTokenModel.cls._get_role_name(x))
182 185 for x in AuthTokenModel.cls.ROLES]
183 186 c.role_options = [(c.role_values, _("Role"))]
184 187 c.user_auth_tokens = AuthTokenModel().get_auth_tokens(
185 188 c.user.user_id, show_expired=True)
186 189 return self._get_template_context(c)
187 190
188 191 def maybe_attach_token_scope(self, token):
189 192 # implemented in EE edition
190 193 pass
191 194
192 195 @LoginRequired()
193 196 @HasPermissionAllDecorator('hg.admin')
194 197 @CSRFRequired()
195 198 @view_config(
196 199 route_name='edit_user_auth_tokens_add', request_method='POST')
197 200 def auth_tokens_add(self):
198 201 _ = self.request.translate
199 202 c = self.load_default_context()
200 203
201 204 user_id = self.request.matchdict.get('user_id')
202 205 c.user = User.get_or_404(user_id)
203 206
204 207 self._redirect_for_default_user(c.user.username)
205 208
206 209 user_data = c.user.get_api_data()
207 210 lifetime = safe_int(self.request.POST.get('lifetime'), -1)
208 211 description = self.request.POST.get('description')
209 212 role = self.request.POST.get('role')
210 213
211 214 token = AuthTokenModel().create(
212 215 c.user.user_id, description, lifetime, role)
213 216 token_data = token.get_api_data()
214 217
215 218 self.maybe_attach_token_scope(token)
216 219 audit_logger.store_web(
217 220 'user.edit.token.add', action_data={
218 221 'data': {'token': token_data, 'user': user_data}},
219 222 user=self._rhodecode_user, )
220 223 Session().commit()
221 224
222 225 h.flash(_("Auth token successfully created"), category='success')
223 226 return HTTPFound(h.route_path('edit_user_auth_tokens', user_id=user_id))
224 227
225 228 @LoginRequired()
226 229 @HasPermissionAllDecorator('hg.admin')
227 230 @CSRFRequired()
228 231 @view_config(
229 232 route_name='edit_user_auth_tokens_delete', request_method='POST')
230 233 def auth_tokens_delete(self):
231 234 _ = self.request.translate
232 235 c = self.load_default_context()
233 236
234 237 user_id = self.request.matchdict.get('user_id')
235 238 c.user = User.get_or_404(user_id)
236 239 self._redirect_for_default_user(c.user.username)
237 240 user_data = c.user.get_api_data()
238 241
239 242 del_auth_token = self.request.POST.get('del_auth_token')
240 243
241 244 if del_auth_token:
242 245 token = UserApiKeys.get_or_404(del_auth_token)
243 246 token_data = token.get_api_data()
244 247
245 248 AuthTokenModel().delete(del_auth_token, c.user.user_id)
246 249 audit_logger.store_web(
247 250 'user.edit.token.delete', action_data={
248 251 'data': {'token': token_data, 'user': user_data}},
249 252 user=self._rhodecode_user,)
250 253 Session().commit()
251 254 h.flash(_("Auth token successfully deleted"), category='success')
252 255
253 256 return HTTPFound(h.route_path('edit_user_auth_tokens', user_id=user_id))
254 257
255 258 @LoginRequired()
256 259 @HasPermissionAllDecorator('hg.admin')
257 260 @view_config(
261 route_name='edit_user_ssh_keys', request_method='GET',
262 renderer='rhodecode:templates/admin/users/user_edit.mako')
263 def ssh_keys(self):
264 _ = self.request.translate
265 c = self.load_default_context()
266
267 user_id = self.request.matchdict.get('user_id')
268 c.user = User.get_or_404(user_id)
269 self._redirect_for_default_user(c.user.username)
270
271 c.active = 'ssh_keys'
272 c.default_key = self.request.GET.get('default_key')
273 c.user_ssh_keys = SshKeyModel().get_ssh_keys(c.user.user_id)
274 return self._get_template_context(c)
275
276 @LoginRequired()
277 @HasPermissionAllDecorator('hg.admin')
278 @view_config(
279 route_name='edit_user_ssh_keys_generate_keypair', request_method='GET',
280 renderer='rhodecode:templates/admin/users/user_edit.mako')
281 def ssh_keys_generate_keypair(self):
282 _ = self.request.translate
283 c = self.load_default_context()
284
285 user_id = self.request.matchdict.get('user_id')
286 c.user = User.get_or_404(user_id)
287 self._redirect_for_default_user(c.user.username)
288
289 c.active = 'ssh_keys_generate'
290 comment = 'RhodeCode-SSH {}'.format(c.user.email or '')
291 c.private, c.public = SshKeyModel().generate_keypair(comment=comment)
292
293 return self._get_template_context(c)
294
295 @LoginRequired()
296 @HasPermissionAllDecorator('hg.admin')
297 @CSRFRequired()
298 @view_config(
299 route_name='edit_user_ssh_keys_add', request_method='POST')
300 def ssh_keys_add(self):
301 _ = self.request.translate
302 c = self.load_default_context()
303
304 user_id = self.request.matchdict.get('user_id')
305 c.user = User.get_or_404(user_id)
306
307 self._redirect_for_default_user(c.user.username)
308
309 user_data = c.user.get_api_data()
310 key_data = self.request.POST.get('key_data')
311 description = self.request.POST.get('description')
312
313 try:
314 if not key_data:
315 raise ValueError('Please add a valid public key')
316
317 key = SshKeyModel().parse_key(key_data.strip())
318 fingerprint = key.hash_md5()
319
320 ssh_key = SshKeyModel().create(
321 c.user.user_id, fingerprint, key_data, description)
322 ssh_key_data = ssh_key.get_api_data()
323
324 audit_logger.store_web(
325 'user.edit.ssh_key.add', action_data={
326 'data': {'ssh_key': ssh_key_data, 'user': user_data}},
327 user=self._rhodecode_user, )
328 Session().commit()
329
330 h.flash(_("Ssh Key successfully created"), category='success')
331
332 except IntegrityError:
333 log.exception("Exception during ssh key saving")
334 h.flash(_('An error occurred during ssh key saving: {}').format(
335 'Such key already exists, please use a different one'),
336 category='error')
337 except Exception as e:
338 log.exception("Exception during ssh key saving")
339 h.flash(_('An error occurred during ssh key saving: {}').format(e),
340 category='error')
341
342 return HTTPFound(
343 h.route_path('edit_user_ssh_keys', user_id=user_id))
344
345 @LoginRequired()
346 @HasPermissionAllDecorator('hg.admin')
347 @CSRFRequired()
348 @view_config(
349 route_name='edit_user_ssh_keys_delete', request_method='POST')
350 def ssh_keys_delete(self):
351 _ = self.request.translate
352 c = self.load_default_context()
353
354 user_id = self.request.matchdict.get('user_id')
355 c.user = User.get_or_404(user_id)
356 self._redirect_for_default_user(c.user.username)
357 user_data = c.user.get_api_data()
358
359 del_ssh_key = self.request.POST.get('del_ssh_key')
360
361 if del_ssh_key:
362 ssh_key = UserSshKeys.get_or_404(del_ssh_key)
363 ssh_key_data = ssh_key.get_api_data()
364
365 SshKeyModel().delete(del_ssh_key, c.user.user_id)
366 audit_logger.store_web(
367 'user.edit.ssh_key.delete', action_data={
368 'data': {'ssh_key': ssh_key_data, 'user': user_data}},
369 user=self._rhodecode_user,)
370 Session().commit()
371 h.flash(_("Ssh key successfully deleted"), category='success')
372
373 return HTTPFound(h.route_path('edit_user_ssh_keys', user_id=user_id))
374
375 @LoginRequired()
376 @HasPermissionAllDecorator('hg.admin')
377 @view_config(
258 378 route_name='edit_user_emails', request_method='GET',
259 379 renderer='rhodecode:templates/admin/users/user_edit.mako')
260 380 def emails(self):
261 381 _ = self.request.translate
262 382 c = self.load_default_context()
263 383
264 384 user_id = self.request.matchdict.get('user_id')
265 385 c.user = User.get_or_404(user_id)
266 386 self._redirect_for_default_user(c.user.username)
267 387
268 388 c.active = 'emails'
269 389 c.user_email_map = UserEmailMap.query() \
270 390 .filter(UserEmailMap.user == c.user).all()
271 391
272 392 return self._get_template_context(c)
273 393
274 394 @LoginRequired()
275 395 @HasPermissionAllDecorator('hg.admin')
276 396 @CSRFRequired()
277 397 @view_config(
278 398 route_name='edit_user_emails_add', request_method='POST')
279 399 def emails_add(self):
280 400 _ = self.request.translate
281 401 c = self.load_default_context()
282 402
283 403 user_id = self.request.matchdict.get('user_id')
284 404 c.user = User.get_or_404(user_id)
285 405 self._redirect_for_default_user(c.user.username)
286 406
287 407 email = self.request.POST.get('new_email')
288 408 user_data = c.user.get_api_data()
289 409 try:
290 410 UserModel().add_extra_email(c.user.user_id, email)
291 411 audit_logger.store_web(
292 412 'user.edit.email.add', action_data={'email': email, 'user': user_data},
293 413 user=self._rhodecode_user)
294 414 Session().commit()
295 415 h.flash(_("Added new email address `%s` for user account") % email,
296 416 category='success')
297 417 except formencode.Invalid as error:
298 418 h.flash(h.escape(error.error_dict['email']), category='error')
299 419 except Exception:
300 420 log.exception("Exception during email saving")
301 421 h.flash(_('An error occurred during email saving'),
302 422 category='error')
303 423 raise HTTPFound(h.route_path('edit_user_emails', user_id=user_id))
304 424
305 425 @LoginRequired()
306 426 @HasPermissionAllDecorator('hg.admin')
307 427 @CSRFRequired()
308 428 @view_config(
309 429 route_name='edit_user_emails_delete', request_method='POST')
310 430 def emails_delete(self):
311 431 _ = self.request.translate
312 432 c = self.load_default_context()
313 433
314 434 user_id = self.request.matchdict.get('user_id')
315 435 c.user = User.get_or_404(user_id)
316 436 self._redirect_for_default_user(c.user.username)
317 437
318 438 email_id = self.request.POST.get('del_email_id')
319 439 user_model = UserModel()
320 440
321 441 email = UserEmailMap.query().get(email_id).email
322 442 user_data = c.user.get_api_data()
323 443 user_model.delete_extra_email(c.user.user_id, email_id)
324 444 audit_logger.store_web(
325 445 'user.edit.email.delete', action_data={'email': email, 'user': user_data},
326 446 user=self._rhodecode_user)
327 447 Session().commit()
328 448 h.flash(_("Removed email address from user account"),
329 449 category='success')
330 450 raise HTTPFound(h.route_path('edit_user_emails', user_id=user_id))
331 451
332 452 @LoginRequired()
333 453 @HasPermissionAllDecorator('hg.admin')
334 454 @view_config(
335 455 route_name='edit_user_ips', request_method='GET',
336 456 renderer='rhodecode:templates/admin/users/user_edit.mako')
337 457 def ips(self):
338 458 _ = self.request.translate
339 459 c = self.load_default_context()
340 460
341 461 user_id = self.request.matchdict.get('user_id')
342 462 c.user = User.get_or_404(user_id)
343 463 self._redirect_for_default_user(c.user.username)
344 464
345 465 c.active = 'ips'
346 466 c.user_ip_map = UserIpMap.query() \
347 467 .filter(UserIpMap.user == c.user).all()
348 468
349 469 c.inherit_default_ips = c.user.inherit_default_permissions
350 470 c.default_user_ip_map = UserIpMap.query() \
351 471 .filter(UserIpMap.user == User.get_default_user()).all()
352 472
353 473 return self._get_template_context(c)
354 474
355 475 @LoginRequired()
356 476 @HasPermissionAllDecorator('hg.admin')
357 477 @CSRFRequired()
358 478 @view_config(
359 479 route_name='edit_user_ips_add', request_method='POST')
360 480 def ips_add(self):
361 481 _ = self.request.translate
362 482 c = self.load_default_context()
363 483
364 484 user_id = self.request.matchdict.get('user_id')
365 485 c.user = User.get_or_404(user_id)
366 486 # NOTE(marcink): this view is allowed for default users, as we can
367 487 # edit their IP white list
368 488
369 489 user_model = UserModel()
370 490 desc = self.request.POST.get('description')
371 491 try:
372 492 ip_list = user_model.parse_ip_range(
373 493 self.request.POST.get('new_ip'))
374 494 except Exception as e:
375 495 ip_list = []
376 496 log.exception("Exception during ip saving")
377 497 h.flash(_('An error occurred during ip saving:%s' % (e,)),
378 498 category='error')
379 499 added = []
380 500 user_data = c.user.get_api_data()
381 501 for ip in ip_list:
382 502 try:
383 503 user_model.add_extra_ip(c.user.user_id, ip, desc)
384 504 audit_logger.store_web(
385 505 'user.edit.ip.add', action_data={'ip': ip, 'user': user_data},
386 506 user=self._rhodecode_user)
387 507 Session().commit()
388 508 added.append(ip)
389 509 except formencode.Invalid as error:
390 510 msg = error.error_dict['ip']
391 511 h.flash(msg, category='error')
392 512 except Exception:
393 513 log.exception("Exception during ip saving")
394 514 h.flash(_('An error occurred during ip saving'),
395 515 category='error')
396 516 if added:
397 517 h.flash(
398 518 _("Added ips %s to user whitelist") % (', '.join(ip_list), ),
399 519 category='success')
400 520 if 'default_user' in self.request.POST:
401 521 # case for editing global IP list we do it for 'DEFAULT' user
402 522 raise HTTPFound(h.route_path('admin_permissions_ips'))
403 523 raise HTTPFound(h.route_path('edit_user_ips', user_id=user_id))
404 524
405 525 @LoginRequired()
406 526 @HasPermissionAllDecorator('hg.admin')
407 527 @CSRFRequired()
408 528 @view_config(
409 529 route_name='edit_user_ips_delete', request_method='POST')
410 530 def ips_delete(self):
411 531 _ = self.request.translate
412 532 c = self.load_default_context()
413 533
414 534 user_id = self.request.matchdict.get('user_id')
415 535 c.user = User.get_or_404(user_id)
416 536 # NOTE(marcink): this view is allowed for default users, as we can
417 537 # edit their IP white list
418 538
419 539 ip_id = self.request.POST.get('del_ip_id')
420 540 user_model = UserModel()
421 541 user_data = c.user.get_api_data()
422 542 ip = UserIpMap.query().get(ip_id).ip_addr
423 543 user_model.delete_extra_ip(c.user.user_id, ip_id)
424 544 audit_logger.store_web(
425 545 'user.edit.ip.delete', action_data={'ip': ip, 'user': user_data},
426 546 user=self._rhodecode_user)
427 547 Session().commit()
428 548 h.flash(_("Removed ip address from user whitelist"), category='success')
429 549
430 550 if 'default_user' in self.request.POST:
431 551 # case for editing global IP list we do it for 'DEFAULT' user
432 552 raise HTTPFound(h.route_path('admin_permissions_ips'))
433 553 raise HTTPFound(h.route_path('edit_user_ips', user_id=user_id))
434 554
435 555 @LoginRequired()
436 556 @HasPermissionAllDecorator('hg.admin')
437 557 @view_config(
438 558 route_name='edit_user_groups_management', request_method='GET',
439 559 renderer='rhodecode:templates/admin/users/user_edit.mako')
440 560 def groups_management(self):
441 561 c = self.load_default_context()
442 562
443 563 user_id = self.request.matchdict.get('user_id')
444 564 c.user = User.get_or_404(user_id)
445 565 c.data = c.user.group_member
446 566 self._redirect_for_default_user(c.user.username)
447 567 groups = [UserGroupModel.get_user_groups_as_dict(group.users_group)
448 568 for group in c.user.group_member]
449 569 c.groups = json.dumps(groups)
450 570 c.active = 'groups'
451 571
452 572 return self._get_template_context(c)
453 573
454 574 @LoginRequired()
455 575 @HasPermissionAllDecorator('hg.admin')
456 576 @CSRFRequired()
457 577 @view_config(
458 578 route_name='edit_user_groups_management_updates', request_method='POST')
459 579 def groups_management_updates(self):
460 580 _ = self.request.translate
461 581 c = self.load_default_context()
462 582
463 583 user_id = self.request.matchdict.get('user_id')
464 584 c.user = User.get_or_404(user_id)
465 585 self._redirect_for_default_user(c.user.username)
466 586
467 587 users_groups = set(self.request.POST.getall('users_group_id'))
468 588 users_groups_model = []
469 589
470 590 for ugid in users_groups:
471 591 users_groups_model.append(UserGroupModel().get_group(safe_int(ugid)))
472 592 user_group_model = UserGroupModel()
473 593 user_group_model.change_groups(c.user, users_groups_model)
474 594
475 595 Session().commit()
476 596 c.active = 'user_groups_management'
477 597 h.flash(_("Groups successfully changed"), category='success')
478 598
479 599 return HTTPFound(h.route_path(
480 600 'edit_user_groups_management', user_id=user_id))
481 601
482 602 @LoginRequired()
483 603 @HasPermissionAllDecorator('hg.admin')
484 604 @view_config(
485 605 route_name='edit_user_audit_logs', request_method='GET',
486 606 renderer='rhodecode:templates/admin/users/user_edit.mako')
487 607 def user_audit_logs(self):
488 608 _ = self.request.translate
489 609 c = self.load_default_context()
490 610
491 611 user_id = self.request.matchdict.get('user_id')
492 612 c.user = User.get_or_404(user_id)
493 613 self._redirect_for_default_user(c.user.username)
494 614 c.active = 'audit'
495 615
496 616 p = safe_int(self.request.GET.get('page', 1), 1)
497 617
498 618 filter_term = self.request.GET.get('filter')
499 619 user_log = UserModel().get_user_log(c.user, filter_term)
500 620
501 621 def url_generator(**kw):
502 622 if filter_term:
503 623 kw['filter'] = filter_term
504 624 return self.request.current_route_path(_query=kw)
505 625
506 626 c.audit_logs = h.Page(
507 627 user_log, page=p, items_per_page=10, url=url_generator)
508 628 c.filter_term = filter_term
509 629 return self._get_template_context(c)
510 630
@@ -1,255 +1,257 b''
1 1 # -*- coding: utf-8 -*-
2 2
3 3 # Copyright (C) 2017-2017 RhodeCode GmbH
4 4 #
5 5 # This program is free software: you can redistribute it and/or modify
6 6 # it under the terms of the GNU Affero General Public License, version 3
7 7 # (only), as published by the Free Software Foundation.
8 8 #
9 9 # This program is distributed in the hope that it will be useful,
10 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 12 # GNU General Public License for more details.
13 13 #
14 14 # You should have received a copy of the GNU Affero General Public License
15 15 # along with this program. If not, see <http://www.gnu.org/licenses/>.
16 16 #
17 17 # This program is dual-licensed. If you wish to learn more about the
18 18 # RhodeCode Enterprise Edition, including its added features, Support services,
19 19 # and proprietary license terms, please see https://rhodecode.com/licenses/
20 20
21 21 import logging
22 22 import datetime
23 23
24 24 from rhodecode.model import meta
25 25 from rhodecode.model.db import User, UserLog, Repository
26 26
27 27
28 28 log = logging.getLogger(__name__)
29 29
30 30 # action as key, and expected action_data as value
31 31 ACTIONS_V1 = {
32 32 'user.login.success': {'user_agent': ''},
33 33 'user.login.failure': {'user_agent': ''},
34 34 'user.logout': {'user_agent': ''},
35 35 'user.password.reset_request': {},
36 36 'user.push': {'user_agent': '', 'commit_ids': []},
37 37 'user.pull': {'user_agent': ''},
38 38
39 39 'user.create': {'data': {}},
40 40 'user.delete': {'old_data': {}},
41 41 'user.edit': {'old_data': {}},
42 42 'user.edit.permissions': {},
43 43 'user.edit.ip.add': {'ip': {}, 'user': {}},
44 44 'user.edit.ip.delete': {'ip': {}, 'user': {}},
45 45 'user.edit.token.add': {'token': {}, 'user': {}},
46 46 'user.edit.token.delete': {'token': {}, 'user': {}},
47 47 'user.edit.email.add': {'email': ''},
48 48 'user.edit.email.delete': {'email': ''},
49 'user.edit.ssh_key.add': {'token': {}, 'user': {}},
50 'user.edit.ssh_key.delete': {'token': {}, 'user': {}},
49 51 'user.edit.password_reset.enabled': {},
50 52 'user.edit.password_reset.disabled': {},
51 53
52 54 'user_group.create': {'data': {}},
53 55 'user_group.delete': {'old_data': {}},
54 56 'user_group.edit': {'old_data': {}},
55 57 'user_group.edit.permissions': {},
56 58 'user_group.edit.member.add': {'user': {}},
57 59 'user_group.edit.member.delete': {'user': {}},
58 60
59 61 'repo.create': {'data': {}},
60 62 'repo.fork': {'data': {}},
61 63 'repo.edit': {'old_data': {}},
62 64 'repo.edit.permissions': {},
63 65 'repo.delete': {'old_data': {}},
64 66 'repo.commit.strip': {'commit_id': ''},
65 67 'repo.archive.download': {'user_agent': '', 'archive_name': '',
66 68 'archive_spec': '', 'archive_cached': ''},
67 69 'repo.pull_request.create': '',
68 70 'repo.pull_request.edit': '',
69 71 'repo.pull_request.delete': '',
70 72 'repo.pull_request.close': '',
71 73 'repo.pull_request.merge': '',
72 74 'repo.pull_request.vote': '',
73 75 'repo.pull_request.comment.create': '',
74 76 'repo.pull_request.comment.delete': '',
75 77
76 78 'repo.pull_request.reviewer.add': '',
77 79 'repo.pull_request.reviewer.delete': '',
78 80
79 81 'repo.commit.comment.create': {'data': {}},
80 82 'repo.commit.comment.delete': {'data': {}},
81 83 'repo.commit.vote': '',
82 84
83 85 'repo_group.create': {'data': {}},
84 86 'repo_group.edit': {'old_data': {}},
85 87 'repo_group.edit.permissions': {},
86 88 'repo_group.delete': {'old_data': {}},
87 89 }
88 90 ACTIONS = ACTIONS_V1
89 91
90 92 SOURCE_WEB = 'source_web'
91 93 SOURCE_API = 'source_api'
92 94
93 95
94 96 class UserWrap(object):
95 97 """
96 98 Fake object used to imitate AuthUser
97 99 """
98 100
99 101 def __init__(self, user_id=None, username=None, ip_addr=None):
100 102 self.user_id = user_id
101 103 self.username = username
102 104 self.ip_addr = ip_addr
103 105
104 106
105 107 class RepoWrap(object):
106 108 """
107 109 Fake object used to imitate RepoObject that audit logger requires
108 110 """
109 111
110 112 def __init__(self, repo_id=None, repo_name=None):
111 113 self.repo_id = repo_id
112 114 self.repo_name = repo_name
113 115
114 116
115 117 def _store_log(action_name, action_data, user_id, username, user_data,
116 118 ip_address, repository_id, repository_name):
117 119 user_log = UserLog()
118 120 user_log.version = UserLog.VERSION_2
119 121
120 122 user_log.action = action_name
121 123 user_log.action_data = action_data
122 124
123 125 user_log.user_ip = ip_address
124 126
125 127 user_log.user_id = user_id
126 128 user_log.username = username
127 129 user_log.user_data = user_data
128 130
129 131 user_log.repository_id = repository_id
130 132 user_log.repository_name = repository_name
131 133
132 134 user_log.action_date = datetime.datetime.now()
133 135
134 136 log.info('AUDIT: Logging action: `%s` by user:id:%s[%s] ip:%s',
135 137 action_name, user_id, username, ip_address)
136 138
137 139 return user_log
138 140
139 141
140 142 def store_web(*args, **kwargs):
141 143 if 'action_data' not in kwargs:
142 144 kwargs['action_data'] = {}
143 145 kwargs['action_data'].update({
144 146 'source': SOURCE_WEB
145 147 })
146 148 return store(*args, **kwargs)
147 149
148 150
149 151 def store_api(*args, **kwargs):
150 152 if 'action_data' not in kwargs:
151 153 kwargs['action_data'] = {}
152 154 kwargs['action_data'].update({
153 155 'source': SOURCE_API
154 156 })
155 157 return store(*args, **kwargs)
156 158
157 159
158 160 def store(action, user, action_data=None, user_data=None, ip_addr=None,
159 161 repo=None, sa_session=None, commit=False):
160 162 """
161 163 Audit logger for various actions made by users, typically this
162 164 results in a call such::
163 165
164 166 from rhodecode.lib import audit_logger
165 167
166 168 audit_logger.store(
167 169 'repo.edit', user=self._rhodecode_user)
168 170 audit_logger.store(
169 171 'repo.delete', action_data={'data': repo_data},
170 172 user=audit_logger.UserWrap(username='itried-login', ip_addr='8.8.8.8'))
171 173
172 174 # repo action
173 175 audit_logger.store(
174 176 'repo.delete',
175 177 user=audit_logger.UserWrap(username='itried-login', ip_addr='8.8.8.8'),
176 178 repo=audit_logger.RepoWrap(repo_name='some-repo'))
177 179
178 180 # repo action, when we know and have the repository object already
179 181 audit_logger.store(
180 182 'repo.delete', action_data={'source': audit_logger.SOURCE_WEB, },
181 183 user=self._rhodecode_user,
182 184 repo=repo_object)
183 185
184 186 # alternative wrapper to the above
185 187 audit_logger.store_web(
186 188 'repo.delete', action_data={},
187 189 user=self._rhodecode_user,
188 190 repo=repo_object)
189 191
190 192 # without an user ?
191 193 audit_logger.store(
192 194 'user.login.failure',
193 195 user=audit_logger.UserWrap(
194 196 username=self.request.params.get('username'),
195 197 ip_addr=self.request.remote_addr))
196 198
197 199 """
198 200 from rhodecode.lib.utils2 import safe_unicode
199 201 from rhodecode.lib.auth import AuthUser
200 202
201 203 action_spec = ACTIONS.get(action, None)
202 204 if action_spec is None:
203 205 raise ValueError('Action `{}` is not supported'.format(action))
204 206
205 207 if not sa_session:
206 208 sa_session = meta.Session()
207 209
208 210 try:
209 211 username = getattr(user, 'username', None)
210 212 if not username:
211 213 pass
212 214
213 215 user_id = getattr(user, 'user_id', None)
214 216 if not user_id:
215 217 # maybe we have username ? Try to figure user_id from username
216 218 if username:
217 219 user_id = getattr(
218 220 User.get_by_username(username), 'user_id', None)
219 221
220 222 ip_addr = ip_addr or getattr(user, 'ip_addr', None)
221 223 if not ip_addr:
222 224 pass
223 225
224 226 if not user_data:
225 227 # try to get this from the auth user
226 228 if isinstance(user, AuthUser):
227 229 user_data = {
228 230 'username': user.username,
229 231 'email': user.email,
230 232 }
231 233
232 234 repository_name = getattr(repo, 'repo_name', None)
233 235 repository_id = getattr(repo, 'repo_id', None)
234 236 if not repository_id:
235 237 # maybe we have repo_name ? Try to figure repo_id from repo_name
236 238 if repository_name:
237 239 repository_id = getattr(
238 240 Repository.get_by_repo_name(repository_name), 'repo_id', None)
239 241
240 242 user_log = _store_log(
241 243 action_name=safe_unicode(action),
242 244 action_data=action_data or {},
243 245 user_id=user_id,
244 246 username=username,
245 247 user_data=user_data or {},
246 248 ip_address=safe_unicode(ip_addr),
247 249 repository_id=repository_id,
248 250 repository_name=repository_name
249 251 )
250 252 sa_session.add(user_log)
251 253 if commit:
252 254 sa_session.commit()
253 255
254 256 except Exception:
255 257 log.exception('AUDIT: failed to store audit log')
@@ -1,4134 +1,4173 b''
1 1 # -*- coding: utf-8 -*-
2 2
3 3 # Copyright (C) 2010-2017 RhodeCode GmbH
4 4 #
5 5 # This program is free software: you can redistribute it and/or modify
6 6 # it under the terms of the GNU Affero General Public License, version 3
7 7 # (only), as published by the Free Software Foundation.
8 8 #
9 9 # This program is distributed in the hope that it will be useful,
10 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 12 # GNU General Public License for more details.
13 13 #
14 14 # You should have received a copy of the GNU Affero General Public License
15 15 # along with this program. If not, see <http://www.gnu.org/licenses/>.
16 16 #
17 17 # This program is dual-licensed. If you wish to learn more about the
18 18 # RhodeCode Enterprise Edition, including its added features, Support services,
19 19 # and proprietary license terms, please see https://rhodecode.com/licenses/
20 20
21 21 """
22 22 Database Models for RhodeCode Enterprise
23 23 """
24 24
25 25 import re
26 26 import os
27 27 import time
28 28 import hashlib
29 29 import logging
30 30 import datetime
31 31 import warnings
32 32 import ipaddress
33 33 import functools
34 34 import traceback
35 35 import collections
36 36
37 37
38 38 from sqlalchemy import *
39 39 from sqlalchemy.ext.declarative import declared_attr
40 40 from sqlalchemy.ext.hybrid import hybrid_property
41 41 from sqlalchemy.orm import (
42 42 relationship, joinedload, class_mapper, validates, aliased)
43 43 from sqlalchemy.sql.expression import true
44 44 from sqlalchemy.sql.functions import coalesce, count # noqa
45 45 from beaker.cache import cache_region
46 46 from zope.cachedescriptors.property import Lazy as LazyProperty
47 47
48 48 from pyramid.threadlocal import get_current_request
49 49
50 50 from rhodecode.translation import _
51 51 from rhodecode.lib.vcs import get_vcs_instance
52 52 from rhodecode.lib.vcs.backends.base import EmptyCommit, Reference
53 53 from rhodecode.lib.utils2 import (
54 54 str2bool, safe_str, get_commit_safe, safe_unicode, md5_safe,
55 55 time_to_datetime, aslist, Optional, safe_int, get_clone_url, AttributeDict,
56 56 glob2re, StrictAttributeDict, cleaned_uri)
57 57 from rhodecode.lib.jsonalchemy import MutationObj, MutationList, JsonType
58 58 from rhodecode.lib.ext_json import json
59 59 from rhodecode.lib.caching_query import FromCache
60 60 from rhodecode.lib.encrypt import AESCipher
61 61
62 62 from rhodecode.model.meta import Base, Session
63 63
64 64 URL_SEP = '/'
65 65 log = logging.getLogger(__name__)
66 66
67 67 # =============================================================================
68 68 # BASE CLASSES
69 69 # =============================================================================
70 70
71 71 # this is propagated from .ini file rhodecode.encrypted_values.secret or
72 72 # beaker.session.secret if first is not set.
73 73 # and initialized at environment.py
74 74 ENCRYPTION_KEY = None
75 75
76 76 # used to sort permissions by types, '#' used here is not allowed to be in
77 77 # usernames, and it's very early in sorted string.printable table.
78 78 PERMISSION_TYPE_SORT = {
79 79 'admin': '####',
80 80 'write': '###',
81 81 'read': '##',
82 82 'none': '#',
83 83 }
84 84
85 85
86 86 def display_sort(obj):
87 87 """
88 88 Sort function used to sort permissions in .permissions() function of
89 89 Repository, RepoGroup, UserGroup. Also it put the default user in front
90 90 of all other resources
91 91 """
92 92
93 93 if obj.username == User.DEFAULT_USER:
94 94 return '#####'
95 95 prefix = PERMISSION_TYPE_SORT.get(obj.permission.split('.')[-1], '')
96 96 return prefix + obj.username
97 97
98 98
99 99 def _hash_key(k):
100 100 return md5_safe(k)
101 101
102 102
103 103 class EncryptedTextValue(TypeDecorator):
104 104 """
105 105 Special column for encrypted long text data, use like::
106 106
107 107 value = Column("encrypted_value", EncryptedValue(), nullable=False)
108 108
109 109 This column is intelligent so if value is in unencrypted form it return
110 110 unencrypted form, but on save it always encrypts
111 111 """
112 112 impl = Text
113 113
114 114 def process_bind_param(self, value, dialect):
115 115 if not value:
116 116 return value
117 117 if value.startswith('enc$aes$') or value.startswith('enc$aes_hmac$'):
118 118 # protect against double encrypting if someone manually starts
119 119 # doing
120 120 raise ValueError('value needs to be in unencrypted format, ie. '
121 121 'not starting with enc$aes')
122 122 return 'enc$aes_hmac$%s' % AESCipher(
123 123 ENCRYPTION_KEY, hmac=True).encrypt(value)
124 124
125 125 def process_result_value(self, value, dialect):
126 126 import rhodecode
127 127
128 128 if not value:
129 129 return value
130 130
131 131 parts = value.split('$', 3)
132 132 if not len(parts) == 3:
133 133 # probably not encrypted values
134 134 return value
135 135 else:
136 136 if parts[0] != 'enc':
137 137 # parts ok but without our header ?
138 138 return value
139 139 enc_strict_mode = str2bool(rhodecode.CONFIG.get(
140 140 'rhodecode.encrypted_values.strict') or True)
141 141 # at that stage we know it's our encryption
142 142 if parts[1] == 'aes':
143 143 decrypted_data = AESCipher(ENCRYPTION_KEY).decrypt(parts[2])
144 144 elif parts[1] == 'aes_hmac':
145 145 decrypted_data = AESCipher(
146 146 ENCRYPTION_KEY, hmac=True,
147 147 strict_verification=enc_strict_mode).decrypt(parts[2])
148 148 else:
149 149 raise ValueError(
150 150 'Encryption type part is wrong, must be `aes` '
151 151 'or `aes_hmac`, got `%s` instead' % (parts[1]))
152 152 return decrypted_data
153 153
154 154
155 155 class BaseModel(object):
156 156 """
157 157 Base Model for all classes
158 158 """
159 159
160 160 @classmethod
161 161 def _get_keys(cls):
162 162 """return column names for this model """
163 163 return class_mapper(cls).c.keys()
164 164
165 165 def get_dict(self):
166 166 """
167 167 return dict with keys and values corresponding
168 168 to this model data """
169 169
170 170 d = {}
171 171 for k in self._get_keys():
172 172 d[k] = getattr(self, k)
173 173
174 174 # also use __json__() if present to get additional fields
175 175 _json_attr = getattr(self, '__json__', None)
176 176 if _json_attr:
177 177 # update with attributes from __json__
178 178 if callable(_json_attr):
179 179 _json_attr = _json_attr()
180 180 for k, val in _json_attr.iteritems():
181 181 d[k] = val
182 182 return d
183 183
184 184 def get_appstruct(self):
185 185 """return list with keys and values tuples corresponding
186 186 to this model data """
187 187
188 188 l = []
189 189 for k in self._get_keys():
190 190 l.append((k, getattr(self, k),))
191 191 return l
192 192
193 193 def populate_obj(self, populate_dict):
194 194 """populate model with data from given populate_dict"""
195 195
196 196 for k in self._get_keys():
197 197 if k in populate_dict:
198 198 setattr(self, k, populate_dict[k])
199 199
200 200 @classmethod
201 201 def query(cls):
202 202 return Session().query(cls)
203 203
204 204 @classmethod
205 205 def get(cls, id_):
206 206 if id_:
207 207 return cls.query().get(id_)
208 208
209 209 @classmethod
210 210 def get_or_404(cls, id_):
211 211 from pyramid.httpexceptions import HTTPNotFound
212 212
213 213 try:
214 214 id_ = int(id_)
215 215 except (TypeError, ValueError):
216 216 raise HTTPNotFound()
217 217
218 218 res = cls.query().get(id_)
219 219 if not res:
220 220 raise HTTPNotFound()
221 221 return res
222 222
223 223 @classmethod
224 224 def getAll(cls):
225 225 # deprecated and left for backward compatibility
226 226 return cls.get_all()
227 227
228 228 @classmethod
229 229 def get_all(cls):
230 230 return cls.query().all()
231 231
232 232 @classmethod
233 233 def delete(cls, id_):
234 234 obj = cls.query().get(id_)
235 235 Session().delete(obj)
236 236
237 237 @classmethod
238 238 def identity_cache(cls, session, attr_name, value):
239 239 exist_in_session = []
240 240 for (item_cls, pkey), instance in session.identity_map.items():
241 241 if cls == item_cls and getattr(instance, attr_name) == value:
242 242 exist_in_session.append(instance)
243 243 if exist_in_session:
244 244 if len(exist_in_session) == 1:
245 245 return exist_in_session[0]
246 246 log.exception(
247 247 'multiple objects with attr %s and '
248 248 'value %s found with same name: %r',
249 249 attr_name, value, exist_in_session)
250 250
251 251 def __repr__(self):
252 252 if hasattr(self, '__unicode__'):
253 253 # python repr needs to return str
254 254 try:
255 255 return safe_str(self.__unicode__())
256 256 except UnicodeDecodeError:
257 257 pass
258 258 return '<DB:%s>' % (self.__class__.__name__)
259 259
260 260
261 261 class RhodeCodeSetting(Base, BaseModel):
262 262 __tablename__ = 'rhodecode_settings'
263 263 __table_args__ = (
264 264 UniqueConstraint('app_settings_name'),
265 265 {'extend_existing': True, 'mysql_engine': 'InnoDB',
266 266 'mysql_charset': 'utf8', 'sqlite_autoincrement': True}
267 267 )
268 268
269 269 SETTINGS_TYPES = {
270 270 'str': safe_str,
271 271 'int': safe_int,
272 272 'unicode': safe_unicode,
273 273 'bool': str2bool,
274 274 'list': functools.partial(aslist, sep=',')
275 275 }
276 276 DEFAULT_UPDATE_URL = 'https://rhodecode.com/api/v1/info/versions'
277 277 GLOBAL_CONF_KEY = 'app_settings'
278 278
279 279 app_settings_id = Column("app_settings_id", Integer(), nullable=False, unique=True, default=None, primary_key=True)
280 280 app_settings_name = Column("app_settings_name", String(255), nullable=True, unique=None, default=None)
281 281 _app_settings_value = Column("app_settings_value", String(4096), nullable=True, unique=None, default=None)
282 282 _app_settings_type = Column("app_settings_type", String(255), nullable=True, unique=None, default=None)
283 283
284 284 def __init__(self, key='', val='', type='unicode'):
285 285 self.app_settings_name = key
286 286 self.app_settings_type = type
287 287 self.app_settings_value = val
288 288
289 289 @validates('_app_settings_value')
290 290 def validate_settings_value(self, key, val):
291 291 assert type(val) == unicode
292 292 return val
293 293
294 294 @hybrid_property
295 295 def app_settings_value(self):
296 296 v = self._app_settings_value
297 297 _type = self.app_settings_type
298 298 if _type:
299 299 _type = self.app_settings_type.split('.')[0]
300 300 # decode the encrypted value
301 301 if 'encrypted' in self.app_settings_type:
302 302 cipher = EncryptedTextValue()
303 303 v = safe_unicode(cipher.process_result_value(v, None))
304 304
305 305 converter = self.SETTINGS_TYPES.get(_type) or \
306 306 self.SETTINGS_TYPES['unicode']
307 307 return converter(v)
308 308
309 309 @app_settings_value.setter
310 310 def app_settings_value(self, val):
311 311 """
312 312 Setter that will always make sure we use unicode in app_settings_value
313 313
314 314 :param val:
315 315 """
316 316 val = safe_unicode(val)
317 317 # encode the encrypted value
318 318 if 'encrypted' in self.app_settings_type:
319 319 cipher = EncryptedTextValue()
320 320 val = safe_unicode(cipher.process_bind_param(val, None))
321 321 self._app_settings_value = val
322 322
323 323 @hybrid_property
324 324 def app_settings_type(self):
325 325 return self._app_settings_type
326 326
327 327 @app_settings_type.setter
328 328 def app_settings_type(self, val):
329 329 if val.split('.')[0] not in self.SETTINGS_TYPES:
330 330 raise Exception('type must be one of %s got %s'
331 331 % (self.SETTINGS_TYPES.keys(), val))
332 332 self._app_settings_type = val
333 333
334 334 def __unicode__(self):
335 335 return u"<%s('%s:%s[%s]')>" % (
336 336 self.__class__.__name__,
337 337 self.app_settings_name, self.app_settings_value,
338 338 self.app_settings_type
339 339 )
340 340
341 341
342 342 class RhodeCodeUi(Base, BaseModel):
343 343 __tablename__ = 'rhodecode_ui'
344 344 __table_args__ = (
345 345 UniqueConstraint('ui_key'),
346 346 {'extend_existing': True, 'mysql_engine': 'InnoDB',
347 347 'mysql_charset': 'utf8', 'sqlite_autoincrement': True}
348 348 )
349 349
350 350 HOOK_REPO_SIZE = 'changegroup.repo_size'
351 351 # HG
352 352 HOOK_PRE_PULL = 'preoutgoing.pre_pull'
353 353 HOOK_PULL = 'outgoing.pull_logger'
354 354 HOOK_PRE_PUSH = 'prechangegroup.pre_push'
355 355 HOOK_PRETX_PUSH = 'pretxnchangegroup.pre_push'
356 356 HOOK_PUSH = 'changegroup.push_logger'
357 357 HOOK_PUSH_KEY = 'pushkey.key_push'
358 358
359 359 # TODO: johbo: Unify way how hooks are configured for git and hg,
360 360 # git part is currently hardcoded.
361 361
362 362 # SVN PATTERNS
363 363 SVN_BRANCH_ID = 'vcs_svn_branch'
364 364 SVN_TAG_ID = 'vcs_svn_tag'
365 365
366 366 ui_id = Column(
367 367 "ui_id", Integer(), nullable=False, unique=True, default=None,
368 368 primary_key=True)
369 369 ui_section = Column(
370 370 "ui_section", String(255), nullable=True, unique=None, default=None)
371 371 ui_key = Column(
372 372 "ui_key", String(255), nullable=True, unique=None, default=None)
373 373 ui_value = Column(
374 374 "ui_value", String(255), nullable=True, unique=None, default=None)
375 375 ui_active = Column(
376 376 "ui_active", Boolean(), nullable=True, unique=None, default=True)
377 377
378 378 def __repr__(self):
379 379 return '<%s[%s]%s=>%s]>' % (self.__class__.__name__, self.ui_section,
380 380 self.ui_key, self.ui_value)
381 381
382 382
383 383 class RepoRhodeCodeSetting(Base, BaseModel):
384 384 __tablename__ = 'repo_rhodecode_settings'
385 385 __table_args__ = (
386 386 UniqueConstraint(
387 387 'app_settings_name', 'repository_id',
388 388 name='uq_repo_rhodecode_setting_name_repo_id'),
389 389 {'extend_existing': True, 'mysql_engine': 'InnoDB',
390 390 'mysql_charset': 'utf8', 'sqlite_autoincrement': True}
391 391 )
392 392
393 393 repository_id = Column(
394 394 "repository_id", Integer(), ForeignKey('repositories.repo_id'),
395 395 nullable=False)
396 396 app_settings_id = Column(
397 397 "app_settings_id", Integer(), nullable=False, unique=True,
398 398 default=None, primary_key=True)
399 399 app_settings_name = Column(
400 400 "app_settings_name", String(255), nullable=True, unique=None,
401 401 default=None)
402 402 _app_settings_value = Column(
403 403 "app_settings_value", String(4096), nullable=True, unique=None,
404 404 default=None)
405 405 _app_settings_type = Column(
406 406 "app_settings_type", String(255), nullable=True, unique=None,
407 407 default=None)
408 408
409 409 repository = relationship('Repository')
410 410
411 411 def __init__(self, repository_id, key='', val='', type='unicode'):
412 412 self.repository_id = repository_id
413 413 self.app_settings_name = key
414 414 self.app_settings_type = type
415 415 self.app_settings_value = val
416 416
417 417 @validates('_app_settings_value')
418 418 def validate_settings_value(self, key, val):
419 419 assert type(val) == unicode
420 420 return val
421 421
422 422 @hybrid_property
423 423 def app_settings_value(self):
424 424 v = self._app_settings_value
425 425 type_ = self.app_settings_type
426 426 SETTINGS_TYPES = RhodeCodeSetting.SETTINGS_TYPES
427 427 converter = SETTINGS_TYPES.get(type_) or SETTINGS_TYPES['unicode']
428 428 return converter(v)
429 429
430 430 @app_settings_value.setter
431 431 def app_settings_value(self, val):
432 432 """
433 433 Setter that will always make sure we use unicode in app_settings_value
434 434
435 435 :param val:
436 436 """
437 437 self._app_settings_value = safe_unicode(val)
438 438
439 439 @hybrid_property
440 440 def app_settings_type(self):
441 441 return self._app_settings_type
442 442
443 443 @app_settings_type.setter
444 444 def app_settings_type(self, val):
445 445 SETTINGS_TYPES = RhodeCodeSetting.SETTINGS_TYPES
446 446 if val not in SETTINGS_TYPES:
447 447 raise Exception('type must be one of %s got %s'
448 448 % (SETTINGS_TYPES.keys(), val))
449 449 self._app_settings_type = val
450 450
451 451 def __unicode__(self):
452 452 return u"<%s('%s:%s:%s[%s]')>" % (
453 453 self.__class__.__name__, self.repository.repo_name,
454 454 self.app_settings_name, self.app_settings_value,
455 455 self.app_settings_type
456 456 )
457 457
458 458
459 459 class RepoRhodeCodeUi(Base, BaseModel):
460 460 __tablename__ = 'repo_rhodecode_ui'
461 461 __table_args__ = (
462 462 UniqueConstraint(
463 463 'repository_id', 'ui_section', 'ui_key',
464 464 name='uq_repo_rhodecode_ui_repository_id_section_key'),
465 465 {'extend_existing': True, 'mysql_engine': 'InnoDB',
466 466 'mysql_charset': 'utf8', 'sqlite_autoincrement': True}
467 467 )
468 468
469 469 repository_id = Column(
470 470 "repository_id", Integer(), ForeignKey('repositories.repo_id'),
471 471 nullable=False)
472 472 ui_id = Column(
473 473 "ui_id", Integer(), nullable=False, unique=True, default=None,
474 474 primary_key=True)
475 475 ui_section = Column(
476 476 "ui_section", String(255), nullable=True, unique=None, default=None)
477 477 ui_key = Column(
478 478 "ui_key", String(255), nullable=True, unique=None, default=None)
479 479 ui_value = Column(
480 480 "ui_value", String(255), nullable=True, unique=None, default=None)
481 481 ui_active = Column(
482 482 "ui_active", Boolean(), nullable=True, unique=None, default=True)
483 483
484 484 repository = relationship('Repository')
485 485
486 486 def __repr__(self):
487 487 return '<%s[%s:%s]%s=>%s]>' % (
488 488 self.__class__.__name__, self.repository.repo_name,
489 489 self.ui_section, self.ui_key, self.ui_value)
490 490
491 491
492 492 class User(Base, BaseModel):
493 493 __tablename__ = 'users'
494 494 __table_args__ = (
495 495 UniqueConstraint('username'), UniqueConstraint('email'),
496 496 Index('u_username_idx', 'username'),
497 497 Index('u_email_idx', 'email'),
498 498 {'extend_existing': True, 'mysql_engine': 'InnoDB',
499 499 'mysql_charset': 'utf8', 'sqlite_autoincrement': True}
500 500 )
501 501 DEFAULT_USER = 'default'
502 502 DEFAULT_USER_EMAIL = 'anonymous@rhodecode.org'
503 503 DEFAULT_GRAVATAR_URL = 'https://secure.gravatar.com/avatar/{md5email}?d=identicon&s={size}'
504 504
505 505 user_id = Column("user_id", Integer(), nullable=False, unique=True, default=None, primary_key=True)
506 506 username = Column("username", String(255), nullable=True, unique=None, default=None)
507 507 password = Column("password", String(255), nullable=True, unique=None, default=None)
508 508 active = Column("active", Boolean(), nullable=True, unique=None, default=True)
509 509 admin = Column("admin", Boolean(), nullable=True, unique=None, default=False)
510 510 name = Column("firstname", String(255), nullable=True, unique=None, default=None)
511 511 lastname = Column("lastname", String(255), nullable=True, unique=None, default=None)
512 512 _email = Column("email", String(255), nullable=True, unique=None, default=None)
513 513 last_login = Column("last_login", DateTime(timezone=False), nullable=True, unique=None, default=None)
514 514 last_activity = Column('last_activity', DateTime(timezone=False), nullable=True, unique=None, default=None)
515 515
516 516 extern_type = Column("extern_type", String(255), nullable=True, unique=None, default=None)
517 517 extern_name = Column("extern_name", String(255), nullable=True, unique=None, default=None)
518 518 _api_key = Column("api_key", String(255), nullable=True, unique=None, default=None)
519 519 inherit_default_permissions = Column("inherit_default_permissions", Boolean(), nullable=False, unique=None, default=True)
520 520 created_on = Column('created_on', DateTime(timezone=False), nullable=False, default=datetime.datetime.now)
521 521 _user_data = Column("user_data", LargeBinary(), nullable=True) # JSON data
522 522
523 523 user_log = relationship('UserLog')
524 524 user_perms = relationship('UserToPerm', primaryjoin="User.user_id==UserToPerm.user_id", cascade='all')
525 525
526 526 repositories = relationship('Repository')
527 527 repository_groups = relationship('RepoGroup')
528 528 user_groups = relationship('UserGroup')
529 529
530 530 user_followers = relationship('UserFollowing', primaryjoin='UserFollowing.follows_user_id==User.user_id', cascade='all')
531 531 followings = relationship('UserFollowing', primaryjoin='UserFollowing.user_id==User.user_id', cascade='all')
532 532
533 533 repo_to_perm = relationship('UserRepoToPerm', primaryjoin='UserRepoToPerm.user_id==User.user_id', cascade='all')
534 534 repo_group_to_perm = relationship('UserRepoGroupToPerm', primaryjoin='UserRepoGroupToPerm.user_id==User.user_id', cascade='all')
535 535 user_group_to_perm = relationship('UserUserGroupToPerm', primaryjoin='UserUserGroupToPerm.user_id==User.user_id', cascade='all')
536 536
537 537 group_member = relationship('UserGroupMember', cascade='all')
538 538
539 539 notifications = relationship('UserNotification', cascade='all')
540 540 # notifications assigned to this user
541 541 user_created_notifications = relationship('Notification', cascade='all')
542 542 # comments created by this user
543 543 user_comments = relationship('ChangesetComment', cascade='all')
544 544 # user profile extra info
545 545 user_emails = relationship('UserEmailMap', cascade='all')
546 546 user_ip_map = relationship('UserIpMap', cascade='all')
547 547 user_auth_tokens = relationship('UserApiKeys', cascade='all')
548 user_ssh_keys = relationship('UserSshKeys', cascade='all')
549
548 550 # gists
549 551 user_gists = relationship('Gist', cascade='all')
550 552 # user pull requests
551 553 user_pull_requests = relationship('PullRequest', cascade='all')
552 554 # external identities
553 555 extenal_identities = relationship(
554 556 'ExternalIdentity',
555 557 primaryjoin="User.user_id==ExternalIdentity.local_user_id",
556 558 cascade='all')
557 559
558 560 def __unicode__(self):
559 561 return u"<%s('id:%s:%s')>" % (self.__class__.__name__,
560 562 self.user_id, self.username)
561 563
562 564 @hybrid_property
563 565 def email(self):
564 566 return self._email
565 567
566 568 @email.setter
567 569 def email(self, val):
568 570 self._email = val.lower() if val else None
569 571
570 572 @hybrid_property
571 573 def first_name(self):
572 574 from rhodecode.lib import helpers as h
573 575 if self.name:
574 576 return h.escape(self.name)
575 577 return self.name
576 578
577 579 @hybrid_property
578 580 def last_name(self):
579 581 from rhodecode.lib import helpers as h
580 582 if self.lastname:
581 583 return h.escape(self.lastname)
582 584 return self.lastname
583 585
584 586 @hybrid_property
585 587 def api_key(self):
586 588 """
587 589 Fetch if exist an auth-token with role ALL connected to this user
588 590 """
589 591 user_auth_token = UserApiKeys.query()\
590 592 .filter(UserApiKeys.user_id == self.user_id)\
591 593 .filter(or_(UserApiKeys.expires == -1,
592 594 UserApiKeys.expires >= time.time()))\
593 595 .filter(UserApiKeys.role == UserApiKeys.ROLE_ALL).first()
594 596 if user_auth_token:
595 597 user_auth_token = user_auth_token.api_key
596 598
597 599 return user_auth_token
598 600
599 601 @api_key.setter
600 602 def api_key(self, val):
601 603 # don't allow to set API key this is deprecated for now
602 604 self._api_key = None
603 605
604 606 @property
605 607 def reviewer_pull_requests(self):
606 608 return PullRequestReviewers.query() \
607 609 .options(joinedload(PullRequestReviewers.pull_request)) \
608 610 .filter(PullRequestReviewers.user_id == self.user_id) \
609 611 .all()
610 612
611 613 @property
612 614 def firstname(self):
613 615 # alias for future
614 616 return self.name
615 617
616 618 @property
617 619 def emails(self):
618 620 other = UserEmailMap.query()\
619 621 .filter(UserEmailMap.user == self) \
620 622 .order_by(UserEmailMap.email_id.asc()) \
621 623 .all()
622 624 return [self.email] + [x.email for x in other]
623 625
624 626 @property
625 627 def auth_tokens(self):
626 628 auth_tokens = self.get_auth_tokens()
627 629 return [x.api_key for x in auth_tokens]
628 630
629 631 def get_auth_tokens(self):
630 632 return UserApiKeys.query()\
631 633 .filter(UserApiKeys.user == self)\
632 634 .order_by(UserApiKeys.user_api_key_id.asc())\
633 635 .all()
634 636
635 637 @property
636 638 def feed_token(self):
637 639 return self.get_feed_token()
638 640
639 641 def get_feed_token(self):
640 642 feed_tokens = UserApiKeys.query()\
641 643 .filter(UserApiKeys.user == self)\
642 644 .filter(UserApiKeys.role == UserApiKeys.ROLE_FEED)\
643 645 .all()
644 646 if feed_tokens:
645 647 return feed_tokens[0].api_key
646 648 return 'NO_FEED_TOKEN_AVAILABLE'
647 649
648 650 @classmethod
649 651 def extra_valid_auth_tokens(cls, user, role=None):
650 652 tokens = UserApiKeys.query().filter(UserApiKeys.user == user)\
651 653 .filter(or_(UserApiKeys.expires == -1,
652 654 UserApiKeys.expires >= time.time()))
653 655 if role:
654 656 tokens = tokens.filter(or_(UserApiKeys.role == role,
655 657 UserApiKeys.role == UserApiKeys.ROLE_ALL))
656 658 return tokens.all()
657 659
658 660 def authenticate_by_token(self, auth_token, roles=None, scope_repo_id=None):
659 661 from rhodecode.lib import auth
660 662
661 663 log.debug('Trying to authenticate user: %s via auth-token, '
662 664 'and roles: %s', self, roles)
663 665
664 666 if not auth_token:
665 667 return False
666 668
667 669 crypto_backend = auth.crypto_backend()
668 670
669 671 roles = (roles or []) + [UserApiKeys.ROLE_ALL]
670 672 tokens_q = UserApiKeys.query()\
671 673 .filter(UserApiKeys.user_id == self.user_id)\
672 674 .filter(or_(UserApiKeys.expires == -1,
673 675 UserApiKeys.expires >= time.time()))
674 676
675 677 tokens_q = tokens_q.filter(UserApiKeys.role.in_(roles))
676 678
677 679 plain_tokens = []
678 680 hash_tokens = []
679 681
680 682 for token in tokens_q.all():
681 683 # verify scope first
682 684 if token.repo_id:
683 685 # token has a scope, we need to verify it
684 686 if scope_repo_id != token.repo_id:
685 687 log.debug(
686 688 'Scope mismatch: token has a set repo scope: %s, '
687 689 'and calling scope is:%s, skipping further checks',
688 690 token.repo, scope_repo_id)
689 691 # token has a scope, and it doesn't match, skip token
690 692 continue
691 693
692 694 if token.api_key.startswith(crypto_backend.ENC_PREF):
693 695 hash_tokens.append(token.api_key)
694 696 else:
695 697 plain_tokens.append(token.api_key)
696 698
697 699 is_plain_match = auth_token in plain_tokens
698 700 if is_plain_match:
699 701 return True
700 702
701 703 for hashed in hash_tokens:
702 704 # TODO(marcink): this is expensive to calculate, but most secure
703 705 match = crypto_backend.hash_check(auth_token, hashed)
704 706 if match:
705 707 return True
706 708
707 709 return False
708 710
709 711 @property
710 712 def ip_addresses(self):
711 713 ret = UserIpMap.query().filter(UserIpMap.user == self).all()
712 714 return [x.ip_addr for x in ret]
713 715
714 716 @property
715 717 def username_and_name(self):
716 718 return '%s (%s %s)' % (self.username, self.first_name, self.last_name)
717 719
718 720 @property
719 721 def username_or_name_or_email(self):
720 722 full_name = self.full_name if self.full_name is not ' ' else None
721 723 return self.username or full_name or self.email
722 724
723 725 @property
724 726 def full_name(self):
725 727 return '%s %s' % (self.first_name, self.last_name)
726 728
727 729 @property
728 730 def full_name_or_username(self):
729 731 return ('%s %s' % (self.first_name, self.last_name)
730 732 if (self.first_name and self.last_name) else self.username)
731 733
732 734 @property
733 735 def full_contact(self):
734 736 return '%s %s <%s>' % (self.first_name, self.last_name, self.email)
735 737
736 738 @property
737 739 def short_contact(self):
738 740 return '%s %s' % (self.first_name, self.last_name)
739 741
740 742 @property
741 743 def is_admin(self):
742 744 return self.admin
743 745
744 746 @property
745 747 def AuthUser(self):
746 748 """
747 749 Returns instance of AuthUser for this user
748 750 """
749 751 from rhodecode.lib.auth import AuthUser
750 752 return AuthUser(user_id=self.user_id, username=self.username)
751 753
752 754 @hybrid_property
753 755 def user_data(self):
754 756 if not self._user_data:
755 757 return {}
756 758
757 759 try:
758 760 return json.loads(self._user_data)
759 761 except TypeError:
760 762 return {}
761 763
762 764 @user_data.setter
763 765 def user_data(self, val):
764 766 if not isinstance(val, dict):
765 767 raise Exception('user_data must be dict, got %s' % type(val))
766 768 try:
767 769 self._user_data = json.dumps(val)
768 770 except Exception:
769 771 log.error(traceback.format_exc())
770 772
771 773 @classmethod
772 774 def get_by_username(cls, username, case_insensitive=False,
773 775 cache=False, identity_cache=False):
774 776 session = Session()
775 777
776 778 if case_insensitive:
777 779 q = cls.query().filter(
778 780 func.lower(cls.username) == func.lower(username))
779 781 else:
780 782 q = cls.query().filter(cls.username == username)
781 783
782 784 if cache:
783 785 if identity_cache:
784 786 val = cls.identity_cache(session, 'username', username)
785 787 if val:
786 788 return val
787 789 else:
788 790 cache_key = "get_user_by_name_%s" % _hash_key(username)
789 791 q = q.options(
790 792 FromCache("sql_cache_short", cache_key))
791 793
792 794 return q.scalar()
793 795
794 796 @classmethod
795 797 def get_by_auth_token(cls, auth_token, cache=False):
796 798 q = UserApiKeys.query()\
797 799 .filter(UserApiKeys.api_key == auth_token)\
798 800 .filter(or_(UserApiKeys.expires == -1,
799 801 UserApiKeys.expires >= time.time()))
800 802 if cache:
801 803 q = q.options(
802 804 FromCache("sql_cache_short", "get_auth_token_%s" % auth_token))
803 805
804 806 match = q.first()
805 807 if match:
806 808 return match.user
807 809
808 810 @classmethod
809 811 def get_by_email(cls, email, case_insensitive=False, cache=False):
810 812
811 813 if case_insensitive:
812 814 q = cls.query().filter(func.lower(cls.email) == func.lower(email))
813 815
814 816 else:
815 817 q = cls.query().filter(cls.email == email)
816 818
817 819 email_key = _hash_key(email)
818 820 if cache:
819 821 q = q.options(
820 822 FromCache("sql_cache_short", "get_email_key_%s" % email_key))
821 823
822 824 ret = q.scalar()
823 825 if ret is None:
824 826 q = UserEmailMap.query()
825 827 # try fetching in alternate email map
826 828 if case_insensitive:
827 829 q = q.filter(func.lower(UserEmailMap.email) == func.lower(email))
828 830 else:
829 831 q = q.filter(UserEmailMap.email == email)
830 832 q = q.options(joinedload(UserEmailMap.user))
831 833 if cache:
832 834 q = q.options(
833 835 FromCache("sql_cache_short", "get_email_map_key_%s" % email_key))
834 836 ret = getattr(q.scalar(), 'user', None)
835 837
836 838 return ret
837 839
838 840 @classmethod
839 841 def get_from_cs_author(cls, author):
840 842 """
841 843 Tries to get User objects out of commit author string
842 844
843 845 :param author:
844 846 """
845 847 from rhodecode.lib.helpers import email, author_name
846 848 # Valid email in the attribute passed, see if they're in the system
847 849 _email = email(author)
848 850 if _email:
849 851 user = cls.get_by_email(_email, case_insensitive=True)
850 852 if user:
851 853 return user
852 854 # Maybe we can match by username?
853 855 _author = author_name(author)
854 856 user = cls.get_by_username(_author, case_insensitive=True)
855 857 if user:
856 858 return user
857 859
858 860 def update_userdata(self, **kwargs):
859 861 usr = self
860 862 old = usr.user_data
861 863 old.update(**kwargs)
862 864 usr.user_data = old
863 865 Session().add(usr)
864 866 log.debug('updated userdata with ', kwargs)
865 867
866 868 def update_lastlogin(self):
867 869 """Update user lastlogin"""
868 870 self.last_login = datetime.datetime.now()
869 871 Session().add(self)
870 872 log.debug('updated user %s lastlogin', self.username)
871 873
872 874 def update_lastactivity(self):
873 875 """Update user lastactivity"""
874 876 self.last_activity = datetime.datetime.now()
875 877 Session().add(self)
876 878 log.debug('updated user %s lastactivity', self.username)
877 879
878 880 def update_password(self, new_password):
879 881 from rhodecode.lib.auth import get_crypt_password
880 882
881 883 self.password = get_crypt_password(new_password)
882 884 Session().add(self)
883 885
884 886 @classmethod
885 887 def get_first_super_admin(cls):
886 888 user = User.query().filter(User.admin == true()).first()
887 889 if user is None:
888 890 raise Exception('FATAL: Missing administrative account!')
889 891 return user
890 892
891 893 @classmethod
892 894 def get_all_super_admins(cls):
893 895 """
894 896 Returns all admin accounts sorted by username
895 897 """
896 898 return User.query().filter(User.admin == true())\
897 899 .order_by(User.username.asc()).all()
898 900
899 901 @classmethod
900 902 def get_default_user(cls, cache=False, refresh=False):
901 903 user = User.get_by_username(User.DEFAULT_USER, cache=cache)
902 904 if user is None:
903 905 raise Exception('FATAL: Missing default account!')
904 906 if refresh:
905 907 # The default user might be based on outdated state which
906 908 # has been loaded from the cache.
907 909 # A call to refresh() ensures that the
908 910 # latest state from the database is used.
909 911 Session().refresh(user)
910 912 return user
911 913
912 914 def _get_default_perms(self, user, suffix=''):
913 915 from rhodecode.model.permission import PermissionModel
914 916 return PermissionModel().get_default_perms(user.user_perms, suffix)
915 917
916 918 def get_default_perms(self, suffix=''):
917 919 return self._get_default_perms(self, suffix)
918 920
919 921 def get_api_data(self, include_secrets=False, details='full'):
920 922 """
921 923 Common function for generating user related data for API
922 924
923 925 :param include_secrets: By default secrets in the API data will be replaced
924 926 by a placeholder value to prevent exposing this data by accident. In case
925 927 this data shall be exposed, set this flag to ``True``.
926 928
927 929 :param details: details can be 'basic|full' basic gives only a subset of
928 930 the available user information that includes user_id, name and emails.
929 931 """
930 932 user = self
931 933 user_data = self.user_data
932 934 data = {
933 935 'user_id': user.user_id,
934 936 'username': user.username,
935 937 'firstname': user.name,
936 938 'lastname': user.lastname,
937 939 'email': user.email,
938 940 'emails': user.emails,
939 941 }
940 942 if details == 'basic':
941 943 return data
942 944
943 945 auth_token_length = 40
944 946 auth_token_replacement = '*' * auth_token_length
945 947
946 948 extras = {
947 949 'auth_tokens': [auth_token_replacement],
948 950 'active': user.active,
949 951 'admin': user.admin,
950 952 'extern_type': user.extern_type,
951 953 'extern_name': user.extern_name,
952 954 'last_login': user.last_login,
953 955 'last_activity': user.last_activity,
954 956 'ip_addresses': user.ip_addresses,
955 957 'language': user_data.get('language')
956 958 }
957 959 data.update(extras)
958 960
959 961 if include_secrets:
960 962 data['auth_tokens'] = user.auth_tokens
961 963 return data
962 964
963 965 def __json__(self):
964 966 data = {
965 967 'full_name': self.full_name,
966 968 'full_name_or_username': self.full_name_or_username,
967 969 'short_contact': self.short_contact,
968 970 'full_contact': self.full_contact,
969 971 }
970 972 data.update(self.get_api_data())
971 973 return data
972 974
973 975
974 976 class UserApiKeys(Base, BaseModel):
975 977 __tablename__ = 'user_api_keys'
976 978 __table_args__ = (
977 979 Index('uak_api_key_idx', 'api_key', unique=True),
978 980 Index('uak_api_key_expires_idx', 'api_key', 'expires'),
979 981 {'extend_existing': True, 'mysql_engine': 'InnoDB',
980 982 'mysql_charset': 'utf8', 'sqlite_autoincrement': True}
981 983 )
982 984 __mapper_args__ = {}
983 985
984 986 # ApiKey role
985 987 ROLE_ALL = 'token_role_all'
986 988 ROLE_HTTP = 'token_role_http'
987 989 ROLE_VCS = 'token_role_vcs'
988 990 ROLE_API = 'token_role_api'
989 991 ROLE_FEED = 'token_role_feed'
990 992 ROLE_PASSWORD_RESET = 'token_password_reset'
991 993
992 994 ROLES = [ROLE_ALL, ROLE_HTTP, ROLE_VCS, ROLE_API, ROLE_FEED]
993 995
994 996 user_api_key_id = Column("user_api_key_id", Integer(), nullable=False, unique=True, default=None, primary_key=True)
995 997 user_id = Column("user_id", Integer(), ForeignKey('users.user_id'), nullable=True, unique=None, default=None)
996 998 api_key = Column("api_key", String(255), nullable=False, unique=True)
997 999 description = Column('description', UnicodeText().with_variant(UnicodeText(1024), 'mysql'))
998 1000 expires = Column('expires', Float(53), nullable=False)
999 1001 role = Column('role', String(255), nullable=True)
1000 1002 created_on = Column('created_on', DateTime(timezone=False), nullable=False, default=datetime.datetime.now)
1001 1003
1002 1004 # scope columns
1003 1005 repo_id = Column(
1004 1006 'repo_id', Integer(), ForeignKey('repositories.repo_id'),
1005 1007 nullable=True, unique=None, default=None)
1006 1008 repo = relationship('Repository', lazy='joined')
1007 1009
1008 1010 repo_group_id = Column(
1009 1011 'repo_group_id', Integer(), ForeignKey('groups.group_id'),
1010 1012 nullable=True, unique=None, default=None)
1011 1013 repo_group = relationship('RepoGroup', lazy='joined')
1012 1014
1013 1015 user = relationship('User', lazy='joined')
1014 1016
1015 1017 def __unicode__(self):
1016 1018 return u"<%s('%s')>" % (self.__class__.__name__, self.role)
1017 1019
1018 1020 def __json__(self):
1019 1021 data = {
1020 1022 'auth_token': self.api_key,
1021 1023 'role': self.role,
1022 1024 'scope': self.scope_humanized,
1023 1025 'expired': self.expired
1024 1026 }
1025 1027 return data
1026 1028
1027 1029 def get_api_data(self, include_secrets=False):
1028 1030 data = self.__json__()
1029 1031 if include_secrets:
1030 1032 return data
1031 1033 else:
1032 1034 data['auth_token'] = self.token_obfuscated
1033 1035 return data
1034 1036
1035 1037 @hybrid_property
1036 1038 def description_safe(self):
1037 1039 from rhodecode.lib import helpers as h
1038 1040 return h.escape(self.description)
1039 1041
1040 1042 @property
1041 1043 def expired(self):
1042 1044 if self.expires == -1:
1043 1045 return False
1044 1046 return time.time() > self.expires
1045 1047
1046 1048 @classmethod
1047 1049 def _get_role_name(cls, role):
1048 1050 return {
1049 1051 cls.ROLE_ALL: _('all'),
1050 1052 cls.ROLE_HTTP: _('http/web interface'),
1051 1053 cls.ROLE_VCS: _('vcs (git/hg/svn protocol)'),
1052 1054 cls.ROLE_API: _('api calls'),
1053 1055 cls.ROLE_FEED: _('feed access'),
1054 1056 }.get(role, role)
1055 1057
1056 1058 @property
1057 1059 def role_humanized(self):
1058 1060 return self._get_role_name(self.role)
1059 1061
1060 1062 def _get_scope(self):
1061 1063 if self.repo:
1062 1064 return repr(self.repo)
1063 1065 if self.repo_group:
1064 1066 return repr(self.repo_group) + ' (recursive)'
1065 1067 return 'global'
1066 1068
1067 1069 @property
1068 1070 def scope_humanized(self):
1069 1071 return self._get_scope()
1070 1072
1071 1073 @property
1072 1074 def token_obfuscated(self):
1073 1075 if self.api_key:
1074 1076 return self.api_key[:4] + "****"
1075 1077
1076 1078
1077 1079 class UserEmailMap(Base, BaseModel):
1078 1080 __tablename__ = 'user_email_map'
1079 1081 __table_args__ = (
1080 1082 Index('uem_email_idx', 'email'),
1081 1083 UniqueConstraint('email'),
1082 1084 {'extend_existing': True, 'mysql_engine': 'InnoDB',
1083 1085 'mysql_charset': 'utf8', 'sqlite_autoincrement': True}
1084 1086 )
1085 1087 __mapper_args__ = {}
1086 1088
1087 1089 email_id = Column("email_id", Integer(), nullable=False, unique=True, default=None, primary_key=True)
1088 1090 user_id = Column("user_id", Integer(), ForeignKey('users.user_id'), nullable=True, unique=None, default=None)
1089 1091 _email = Column("email", String(255), nullable=True, unique=False, default=None)
1090 1092 user = relationship('User', lazy='joined')
1091 1093
1092 1094 @validates('_email')
1093 1095 def validate_email(self, key, email):
1094 1096 # check if this email is not main one
1095 1097 main_email = Session().query(User).filter(User.email == email).scalar()
1096 1098 if main_email is not None:
1097 1099 raise AttributeError('email %s is present is user table' % email)
1098 1100 return email
1099 1101
1100 1102 @hybrid_property
1101 1103 def email(self):
1102 1104 return self._email
1103 1105
1104 1106 @email.setter
1105 1107 def email(self, val):
1106 1108 self._email = val.lower() if val else None
1107 1109
1108 1110
1109 1111 class UserIpMap(Base, BaseModel):
1110 1112 __tablename__ = 'user_ip_map'
1111 1113 __table_args__ = (
1112 1114 UniqueConstraint('user_id', 'ip_addr'),
1113 1115 {'extend_existing': True, 'mysql_engine': 'InnoDB',
1114 1116 'mysql_charset': 'utf8', 'sqlite_autoincrement': True}
1115 1117 )
1116 1118 __mapper_args__ = {}
1117 1119
1118 1120 ip_id = Column("ip_id", Integer(), nullable=False, unique=True, default=None, primary_key=True)
1119 1121 user_id = Column("user_id", Integer(), ForeignKey('users.user_id'), nullable=True, unique=None, default=None)
1120 1122 ip_addr = Column("ip_addr", String(255), nullable=True, unique=False, default=None)
1121 1123 active = Column("active", Boolean(), nullable=True, unique=None, default=True)
1122 1124 description = Column("description", String(10000), nullable=True, unique=None, default=None)
1123 1125 user = relationship('User', lazy='joined')
1124 1126
1125 1127 @hybrid_property
1126 1128 def description_safe(self):
1127 1129 from rhodecode.lib import helpers as h
1128 1130 return h.escape(self.description)
1129 1131
1130 1132 @classmethod
1131 1133 def _get_ip_range(cls, ip_addr):
1132 1134 net = ipaddress.ip_network(safe_unicode(ip_addr), strict=False)
1133 1135 return [str(net.network_address), str(net.broadcast_address)]
1134 1136
1135 1137 def __json__(self):
1136 1138 return {
1137 1139 'ip_addr': self.ip_addr,
1138 1140 'ip_range': self._get_ip_range(self.ip_addr),
1139 1141 }
1140 1142
1141 1143 def __unicode__(self):
1142 1144 return u"<%s('user_id:%s=>%s')>" % (self.__class__.__name__,
1143 1145 self.user_id, self.ip_addr)
1144 1146
1145 1147
1148 class UserSshKeys(Base, BaseModel):
1149 __tablename__ = 'user_ssh_keys'
1150 __table_args__ = (
1151 Index('usk_ssh_key_fingerprint_idx', 'ssh_key_fingerprint'),
1152
1153 UniqueConstraint('ssh_key_fingerprint'),
1154
1155 {'extend_existing': True, 'mysql_engine': 'InnoDB',
1156 'mysql_charset': 'utf8', 'sqlite_autoincrement': True}
1157 )
1158 __mapper_args__ = {}
1159
1160 ssh_key_id = Column('ssh_key_id', Integer(), nullable=False, unique=True, default=None, primary_key=True)
1161 ssh_key_data = Column('ssh_key_data', String(10240), nullable=False, unique=None, default=None)
1162 ssh_key_fingerprint = Column('ssh_key_fingerprint', String(1024), nullable=False, unique=None, default=None)
1163
1164 description = Column('description', UnicodeText().with_variant(UnicodeText(1024), 'mysql'))
1165
1166 created_on = Column('created_on', DateTime(timezone=False), nullable=False, default=datetime.datetime.now)
1167 accessed_on = Column('accessed_on', DateTime(timezone=False), nullable=True, default=None)
1168 user_id = Column('user_id', Integer(), ForeignKey('users.user_id'), nullable=True, unique=None, default=None)
1169
1170 user = relationship('User', lazy='joined')
1171
1172 def __json__(self):
1173 data = {
1174 'ssh_fingerprint': self.ssh_key_fingerprint,
1175 'description': self.description,
1176 'created_on': self.created_on
1177 }
1178 return data
1179
1180 def get_api_data(self):
1181 data = self.__json__()
1182 return data
1183
1184
1146 1185 class UserLog(Base, BaseModel):
1147 1186 __tablename__ = 'user_logs'
1148 1187 __table_args__ = (
1149 1188 {'extend_existing': True, 'mysql_engine': 'InnoDB',
1150 1189 'mysql_charset': 'utf8', 'sqlite_autoincrement': True},
1151 1190 )
1152 1191 VERSION_1 = 'v1'
1153 1192 VERSION_2 = 'v2'
1154 1193 VERSIONS = [VERSION_1, VERSION_2]
1155 1194
1156 1195 user_log_id = Column("user_log_id", Integer(), nullable=False, unique=True, default=None, primary_key=True)
1157 1196 user_id = Column("user_id", Integer(), ForeignKey('users.user_id'), nullable=True, unique=None, default=None)
1158 1197 username = Column("username", String(255), nullable=True, unique=None, default=None)
1159 1198 repository_id = Column("repository_id", Integer(), ForeignKey('repositories.repo_id'), nullable=True)
1160 1199 repository_name = Column("repository_name", String(255), nullable=True, unique=None, default=None)
1161 1200 user_ip = Column("user_ip", String(255), nullable=True, unique=None, default=None)
1162 1201 action = Column("action", Text().with_variant(Text(1200000), 'mysql'), nullable=True, unique=None, default=None)
1163 1202 action_date = Column("action_date", DateTime(timezone=False), nullable=True, unique=None, default=None)
1164 1203
1165 1204 version = Column("version", String(255), nullable=True, default=VERSION_1)
1166 1205 user_data = Column('user_data_json', MutationObj.as_mutable(JsonType(dialect_map=dict(mysql=UnicodeText(16384)))))
1167 1206 action_data = Column('action_data_json', MutationObj.as_mutable(JsonType(dialect_map=dict(mysql=UnicodeText(16384)))))
1168 1207
1169 1208 def __unicode__(self):
1170 1209 return u"<%s('id:%s:%s')>" % (
1171 1210 self.__class__.__name__, self.repository_name, self.action)
1172 1211
1173 1212 def __json__(self):
1174 1213 return {
1175 1214 'user_id': self.user_id,
1176 1215 'username': self.username,
1177 1216 'repository_id': self.repository_id,
1178 1217 'repository_name': self.repository_name,
1179 1218 'user_ip': self.user_ip,
1180 1219 'action_date': self.action_date,
1181 1220 'action': self.action,
1182 1221 }
1183 1222
1184 1223 @property
1185 1224 def action_as_day(self):
1186 1225 return datetime.date(*self.action_date.timetuple()[:3])
1187 1226
1188 1227 user = relationship('User')
1189 1228 repository = relationship('Repository', cascade='')
1190 1229
1191 1230
1192 1231 class UserGroup(Base, BaseModel):
1193 1232 __tablename__ = 'users_groups'
1194 1233 __table_args__ = (
1195 1234 {'extend_existing': True, 'mysql_engine': 'InnoDB',
1196 1235 'mysql_charset': 'utf8', 'sqlite_autoincrement': True},
1197 1236 )
1198 1237
1199 1238 users_group_id = Column("users_group_id", Integer(), nullable=False, unique=True, default=None, primary_key=True)
1200 1239 users_group_name = Column("users_group_name", String(255), nullable=False, unique=True, default=None)
1201 1240 user_group_description = Column("user_group_description", String(10000), nullable=True, unique=None, default=None)
1202 1241 users_group_active = Column("users_group_active", Boolean(), nullable=True, unique=None, default=None)
1203 1242 inherit_default_permissions = Column("users_group_inherit_default_permissions", Boolean(), nullable=False, unique=None, default=True)
1204 1243 user_id = Column("user_id", Integer(), ForeignKey('users.user_id'), nullable=False, unique=False, default=None)
1205 1244 created_on = Column('created_on', DateTime(timezone=False), nullable=False, default=datetime.datetime.now)
1206 1245 _group_data = Column("group_data", LargeBinary(), nullable=True) # JSON data
1207 1246
1208 1247 members = relationship('UserGroupMember', cascade="all, delete, delete-orphan", lazy="joined")
1209 1248 users_group_to_perm = relationship('UserGroupToPerm', cascade='all')
1210 1249 users_group_repo_to_perm = relationship('UserGroupRepoToPerm', cascade='all')
1211 1250 users_group_repo_group_to_perm = relationship('UserGroupRepoGroupToPerm', cascade='all')
1212 1251 user_user_group_to_perm = relationship('UserUserGroupToPerm', cascade='all')
1213 1252 user_group_user_group_to_perm = relationship('UserGroupUserGroupToPerm ', primaryjoin="UserGroupUserGroupToPerm.target_user_group_id==UserGroup.users_group_id", cascade='all')
1214 1253
1215 1254 user = relationship('User', primaryjoin="User.user_id==UserGroup.user_id")
1216 1255
1217 1256 @classmethod
1218 1257 def _load_group_data(cls, column):
1219 1258 if not column:
1220 1259 return {}
1221 1260
1222 1261 try:
1223 1262 return json.loads(column) or {}
1224 1263 except TypeError:
1225 1264 return {}
1226 1265
1227 1266 @hybrid_property
1228 1267 def description_safe(self):
1229 1268 from rhodecode.lib import helpers as h
1230 1269 return h.escape(self.description)
1231 1270
1232 1271 @hybrid_property
1233 1272 def group_data(self):
1234 1273 return self._load_group_data(self._group_data)
1235 1274
1236 1275 @group_data.expression
1237 1276 def group_data(self, **kwargs):
1238 1277 return self._group_data
1239 1278
1240 1279 @group_data.setter
1241 1280 def group_data(self, val):
1242 1281 try:
1243 1282 self._group_data = json.dumps(val)
1244 1283 except Exception:
1245 1284 log.error(traceback.format_exc())
1246 1285
1247 1286 def __unicode__(self):
1248 1287 return u"<%s('id:%s:%s')>" % (self.__class__.__name__,
1249 1288 self.users_group_id,
1250 1289 self.users_group_name)
1251 1290
1252 1291 @classmethod
1253 1292 def get_by_group_name(cls, group_name, cache=False,
1254 1293 case_insensitive=False):
1255 1294 if case_insensitive:
1256 1295 q = cls.query().filter(func.lower(cls.users_group_name) ==
1257 1296 func.lower(group_name))
1258 1297
1259 1298 else:
1260 1299 q = cls.query().filter(cls.users_group_name == group_name)
1261 1300 if cache:
1262 1301 q = q.options(
1263 1302 FromCache("sql_cache_short", "get_group_%s" % _hash_key(group_name)))
1264 1303 return q.scalar()
1265 1304
1266 1305 @classmethod
1267 1306 def get(cls, user_group_id, cache=False):
1268 1307 user_group = cls.query()
1269 1308 if cache:
1270 1309 user_group = user_group.options(
1271 1310 FromCache("sql_cache_short", "get_users_group_%s" % user_group_id))
1272 1311 return user_group.get(user_group_id)
1273 1312
1274 1313 def permissions(self, with_admins=True, with_owner=True):
1275 1314 q = UserUserGroupToPerm.query().filter(UserUserGroupToPerm.user_group == self)
1276 1315 q = q.options(joinedload(UserUserGroupToPerm.user_group),
1277 1316 joinedload(UserUserGroupToPerm.user),
1278 1317 joinedload(UserUserGroupToPerm.permission),)
1279 1318
1280 1319 # get owners and admins and permissions. We do a trick of re-writing
1281 1320 # objects from sqlalchemy to named-tuples due to sqlalchemy session
1282 1321 # has a global reference and changing one object propagates to all
1283 1322 # others. This means if admin is also an owner admin_row that change
1284 1323 # would propagate to both objects
1285 1324 perm_rows = []
1286 1325 for _usr in q.all():
1287 1326 usr = AttributeDict(_usr.user.get_dict())
1288 1327 usr.permission = _usr.permission.permission_name
1289 1328 perm_rows.append(usr)
1290 1329
1291 1330 # filter the perm rows by 'default' first and then sort them by
1292 1331 # admin,write,read,none permissions sorted again alphabetically in
1293 1332 # each group
1294 1333 perm_rows = sorted(perm_rows, key=display_sort)
1295 1334
1296 1335 _admin_perm = 'usergroup.admin'
1297 1336 owner_row = []
1298 1337 if with_owner:
1299 1338 usr = AttributeDict(self.user.get_dict())
1300 1339 usr.owner_row = True
1301 1340 usr.permission = _admin_perm
1302 1341 owner_row.append(usr)
1303 1342
1304 1343 super_admin_rows = []
1305 1344 if with_admins:
1306 1345 for usr in User.get_all_super_admins():
1307 1346 # if this admin is also owner, don't double the record
1308 1347 if usr.user_id == owner_row[0].user_id:
1309 1348 owner_row[0].admin_row = True
1310 1349 else:
1311 1350 usr = AttributeDict(usr.get_dict())
1312 1351 usr.admin_row = True
1313 1352 usr.permission = _admin_perm
1314 1353 super_admin_rows.append(usr)
1315 1354
1316 1355 return super_admin_rows + owner_row + perm_rows
1317 1356
1318 1357 def permission_user_groups(self):
1319 1358 q = UserGroupUserGroupToPerm.query().filter(UserGroupUserGroupToPerm.target_user_group == self)
1320 1359 q = q.options(joinedload(UserGroupUserGroupToPerm.user_group),
1321 1360 joinedload(UserGroupUserGroupToPerm.target_user_group),
1322 1361 joinedload(UserGroupUserGroupToPerm.permission),)
1323 1362
1324 1363 perm_rows = []
1325 1364 for _user_group in q.all():
1326 1365 usr = AttributeDict(_user_group.user_group.get_dict())
1327 1366 usr.permission = _user_group.permission.permission_name
1328 1367 perm_rows.append(usr)
1329 1368
1330 1369 return perm_rows
1331 1370
1332 1371 def _get_default_perms(self, user_group, suffix=''):
1333 1372 from rhodecode.model.permission import PermissionModel
1334 1373 return PermissionModel().get_default_perms(user_group.users_group_to_perm, suffix)
1335 1374
1336 1375 def get_default_perms(self, suffix=''):
1337 1376 return self._get_default_perms(self, suffix)
1338 1377
1339 1378 def get_api_data(self, with_group_members=True, include_secrets=False):
1340 1379 """
1341 1380 :param include_secrets: See :meth:`User.get_api_data`, this parameter is
1342 1381 basically forwarded.
1343 1382
1344 1383 """
1345 1384 user_group = self
1346 1385 data = {
1347 1386 'users_group_id': user_group.users_group_id,
1348 1387 'group_name': user_group.users_group_name,
1349 1388 'group_description': user_group.user_group_description,
1350 1389 'active': user_group.users_group_active,
1351 1390 'owner': user_group.user.username,
1352 1391 'owner_email': user_group.user.email,
1353 1392 }
1354 1393
1355 1394 if with_group_members:
1356 1395 users = []
1357 1396 for user in user_group.members:
1358 1397 user = user.user
1359 1398 users.append(user.get_api_data(include_secrets=include_secrets))
1360 1399 data['users'] = users
1361 1400
1362 1401 return data
1363 1402
1364 1403
1365 1404 class UserGroupMember(Base, BaseModel):
1366 1405 __tablename__ = 'users_groups_members'
1367 1406 __table_args__ = (
1368 1407 {'extend_existing': True, 'mysql_engine': 'InnoDB',
1369 1408 'mysql_charset': 'utf8', 'sqlite_autoincrement': True},
1370 1409 )
1371 1410
1372 1411 users_group_member_id = Column("users_group_member_id", Integer(), nullable=False, unique=True, default=None, primary_key=True)
1373 1412 users_group_id = Column("users_group_id", Integer(), ForeignKey('users_groups.users_group_id'), nullable=False, unique=None, default=None)
1374 1413 user_id = Column("user_id", Integer(), ForeignKey('users.user_id'), nullable=False, unique=None, default=None)
1375 1414
1376 1415 user = relationship('User', lazy='joined')
1377 1416 users_group = relationship('UserGroup')
1378 1417
1379 1418 def __init__(self, gr_id='', u_id=''):
1380 1419 self.users_group_id = gr_id
1381 1420 self.user_id = u_id
1382 1421
1383 1422
1384 1423 class RepositoryField(Base, BaseModel):
1385 1424 __tablename__ = 'repositories_fields'
1386 1425 __table_args__ = (
1387 1426 UniqueConstraint('repository_id', 'field_key'), # no-multi field
1388 1427 {'extend_existing': True, 'mysql_engine': 'InnoDB',
1389 1428 'mysql_charset': 'utf8', 'sqlite_autoincrement': True},
1390 1429 )
1391 1430 PREFIX = 'ex_' # prefix used in form to not conflict with already existing fields
1392 1431
1393 1432 repo_field_id = Column("repo_field_id", Integer(), nullable=False, unique=True, default=None, primary_key=True)
1394 1433 repository_id = Column("repository_id", Integer(), ForeignKey('repositories.repo_id'), nullable=False, unique=None, default=None)
1395 1434 field_key = Column("field_key", String(250))
1396 1435 field_label = Column("field_label", String(1024), nullable=False)
1397 1436 field_value = Column("field_value", String(10000), nullable=False)
1398 1437 field_desc = Column("field_desc", String(1024), nullable=False)
1399 1438 field_type = Column("field_type", String(255), nullable=False, unique=None)
1400 1439 created_on = Column('created_on', DateTime(timezone=False), nullable=False, default=datetime.datetime.now)
1401 1440
1402 1441 repository = relationship('Repository')
1403 1442
1404 1443 @property
1405 1444 def field_key_prefixed(self):
1406 1445 return 'ex_%s' % self.field_key
1407 1446
1408 1447 @classmethod
1409 1448 def un_prefix_key(cls, key):
1410 1449 if key.startswith(cls.PREFIX):
1411 1450 return key[len(cls.PREFIX):]
1412 1451 return key
1413 1452
1414 1453 @classmethod
1415 1454 def get_by_key_name(cls, key, repo):
1416 1455 row = cls.query()\
1417 1456 .filter(cls.repository == repo)\
1418 1457 .filter(cls.field_key == key).scalar()
1419 1458 return row
1420 1459
1421 1460
1422 1461 class Repository(Base, BaseModel):
1423 1462 __tablename__ = 'repositories'
1424 1463 __table_args__ = (
1425 1464 Index('r_repo_name_idx', 'repo_name', mysql_length=255),
1426 1465 {'extend_existing': True, 'mysql_engine': 'InnoDB',
1427 1466 'mysql_charset': 'utf8', 'sqlite_autoincrement': True},
1428 1467 )
1429 1468 DEFAULT_CLONE_URI = '{scheme}://{user}@{netloc}/{repo}'
1430 1469 DEFAULT_CLONE_URI_ID = '{scheme}://{user}@{netloc}/_{repoid}'
1431 1470
1432 1471 STATE_CREATED = 'repo_state_created'
1433 1472 STATE_PENDING = 'repo_state_pending'
1434 1473 STATE_ERROR = 'repo_state_error'
1435 1474
1436 1475 LOCK_AUTOMATIC = 'lock_auto'
1437 1476 LOCK_API = 'lock_api'
1438 1477 LOCK_WEB = 'lock_web'
1439 1478 LOCK_PULL = 'lock_pull'
1440 1479
1441 1480 NAME_SEP = URL_SEP
1442 1481
1443 1482 repo_id = Column(
1444 1483 "repo_id", Integer(), nullable=False, unique=True, default=None,
1445 1484 primary_key=True)
1446 1485 _repo_name = Column(
1447 1486 "repo_name", Text(), nullable=False, default=None)
1448 1487 _repo_name_hash = Column(
1449 1488 "repo_name_hash", String(255), nullable=False, unique=True)
1450 1489 repo_state = Column("repo_state", String(255), nullable=True)
1451 1490
1452 1491 clone_uri = Column(
1453 1492 "clone_uri", EncryptedTextValue(), nullable=True, unique=False,
1454 1493 default=None)
1455 1494 repo_type = Column(
1456 1495 "repo_type", String(255), nullable=False, unique=False, default=None)
1457 1496 user_id = Column(
1458 1497 "user_id", Integer(), ForeignKey('users.user_id'), nullable=False,
1459 1498 unique=False, default=None)
1460 1499 private = Column(
1461 1500 "private", Boolean(), nullable=True, unique=None, default=None)
1462 1501 enable_statistics = Column(
1463 1502 "statistics", Boolean(), nullable=True, unique=None, default=True)
1464 1503 enable_downloads = Column(
1465 1504 "downloads", Boolean(), nullable=True, unique=None, default=True)
1466 1505 description = Column(
1467 1506 "description", String(10000), nullable=True, unique=None, default=None)
1468 1507 created_on = Column(
1469 1508 'created_on', DateTime(timezone=False), nullable=True, unique=None,
1470 1509 default=datetime.datetime.now)
1471 1510 updated_on = Column(
1472 1511 'updated_on', DateTime(timezone=False), nullable=True, unique=None,
1473 1512 default=datetime.datetime.now)
1474 1513 _landing_revision = Column(
1475 1514 "landing_revision", String(255), nullable=False, unique=False,
1476 1515 default=None)
1477 1516 enable_locking = Column(
1478 1517 "enable_locking", Boolean(), nullable=False, unique=None,
1479 1518 default=False)
1480 1519 _locked = Column(
1481 1520 "locked", String(255), nullable=True, unique=False, default=None)
1482 1521 _changeset_cache = Column(
1483 1522 "changeset_cache", LargeBinary(), nullable=True) # JSON data
1484 1523
1485 1524 fork_id = Column(
1486 1525 "fork_id", Integer(), ForeignKey('repositories.repo_id'),
1487 1526 nullable=True, unique=False, default=None)
1488 1527 group_id = Column(
1489 1528 "group_id", Integer(), ForeignKey('groups.group_id'), nullable=True,
1490 1529 unique=False, default=None)
1491 1530
1492 1531 user = relationship('User', lazy='joined')
1493 1532 fork = relationship('Repository', remote_side=repo_id, lazy='joined')
1494 1533 group = relationship('RepoGroup', lazy='joined')
1495 1534 repo_to_perm = relationship(
1496 1535 'UserRepoToPerm', cascade='all',
1497 1536 order_by='UserRepoToPerm.repo_to_perm_id')
1498 1537 users_group_to_perm = relationship('UserGroupRepoToPerm', cascade='all')
1499 1538 stats = relationship('Statistics', cascade='all', uselist=False)
1500 1539
1501 1540 followers = relationship(
1502 1541 'UserFollowing',
1503 1542 primaryjoin='UserFollowing.follows_repo_id==Repository.repo_id',
1504 1543 cascade='all')
1505 1544 extra_fields = relationship(
1506 1545 'RepositoryField', cascade="all, delete, delete-orphan")
1507 1546 logs = relationship('UserLog')
1508 1547 comments = relationship(
1509 1548 'ChangesetComment', cascade="all, delete, delete-orphan")
1510 1549 pull_requests_source = relationship(
1511 1550 'PullRequest',
1512 1551 primaryjoin='PullRequest.source_repo_id==Repository.repo_id',
1513 1552 cascade="all, delete, delete-orphan")
1514 1553 pull_requests_target = relationship(
1515 1554 'PullRequest',
1516 1555 primaryjoin='PullRequest.target_repo_id==Repository.repo_id',
1517 1556 cascade="all, delete, delete-orphan")
1518 1557 ui = relationship('RepoRhodeCodeUi', cascade="all")
1519 1558 settings = relationship('RepoRhodeCodeSetting', cascade="all")
1520 1559 integrations = relationship('Integration',
1521 1560 cascade="all, delete, delete-orphan")
1522 1561
1523 1562 def __unicode__(self):
1524 1563 return u"<%s('%s:%s')>" % (self.__class__.__name__, self.repo_id,
1525 1564 safe_unicode(self.repo_name))
1526 1565
1527 1566 @hybrid_property
1528 1567 def description_safe(self):
1529 1568 from rhodecode.lib import helpers as h
1530 1569 return h.escape(self.description)
1531 1570
1532 1571 @hybrid_property
1533 1572 def landing_rev(self):
1534 1573 # always should return [rev_type, rev]
1535 1574 if self._landing_revision:
1536 1575 _rev_info = self._landing_revision.split(':')
1537 1576 if len(_rev_info) < 2:
1538 1577 _rev_info.insert(0, 'rev')
1539 1578 return [_rev_info[0], _rev_info[1]]
1540 1579 return [None, None]
1541 1580
1542 1581 @landing_rev.setter
1543 1582 def landing_rev(self, val):
1544 1583 if ':' not in val:
1545 1584 raise ValueError('value must be delimited with `:` and consist '
1546 1585 'of <rev_type>:<rev>, got %s instead' % val)
1547 1586 self._landing_revision = val
1548 1587
1549 1588 @hybrid_property
1550 1589 def locked(self):
1551 1590 if self._locked:
1552 1591 user_id, timelocked, reason = self._locked.split(':')
1553 1592 lock_values = int(user_id), timelocked, reason
1554 1593 else:
1555 1594 lock_values = [None, None, None]
1556 1595 return lock_values
1557 1596
1558 1597 @locked.setter
1559 1598 def locked(self, val):
1560 1599 if val and isinstance(val, (list, tuple)):
1561 1600 self._locked = ':'.join(map(str, val))
1562 1601 else:
1563 1602 self._locked = None
1564 1603
1565 1604 @hybrid_property
1566 1605 def changeset_cache(self):
1567 1606 from rhodecode.lib.vcs.backends.base import EmptyCommit
1568 1607 dummy = EmptyCommit().__json__()
1569 1608 if not self._changeset_cache:
1570 1609 return dummy
1571 1610 try:
1572 1611 return json.loads(self._changeset_cache)
1573 1612 except TypeError:
1574 1613 return dummy
1575 1614 except Exception:
1576 1615 log.error(traceback.format_exc())
1577 1616 return dummy
1578 1617
1579 1618 @changeset_cache.setter
1580 1619 def changeset_cache(self, val):
1581 1620 try:
1582 1621 self._changeset_cache = json.dumps(val)
1583 1622 except Exception:
1584 1623 log.error(traceback.format_exc())
1585 1624
1586 1625 @hybrid_property
1587 1626 def repo_name(self):
1588 1627 return self._repo_name
1589 1628
1590 1629 @repo_name.setter
1591 1630 def repo_name(self, value):
1592 1631 self._repo_name = value
1593 1632 self._repo_name_hash = hashlib.sha1(safe_str(value)).hexdigest()
1594 1633
1595 1634 @classmethod
1596 1635 def normalize_repo_name(cls, repo_name):
1597 1636 """
1598 1637 Normalizes os specific repo_name to the format internally stored inside
1599 1638 database using URL_SEP
1600 1639
1601 1640 :param cls:
1602 1641 :param repo_name:
1603 1642 """
1604 1643 return cls.NAME_SEP.join(repo_name.split(os.sep))
1605 1644
1606 1645 @classmethod
1607 1646 def get_by_repo_name(cls, repo_name, cache=False, identity_cache=False):
1608 1647 session = Session()
1609 1648 q = session.query(cls).filter(cls.repo_name == repo_name)
1610 1649
1611 1650 if cache:
1612 1651 if identity_cache:
1613 1652 val = cls.identity_cache(session, 'repo_name', repo_name)
1614 1653 if val:
1615 1654 return val
1616 1655 else:
1617 1656 cache_key = "get_repo_by_name_%s" % _hash_key(repo_name)
1618 1657 q = q.options(
1619 1658 FromCache("sql_cache_short", cache_key))
1620 1659
1621 1660 return q.scalar()
1622 1661
1623 1662 @classmethod
1624 1663 def get_by_full_path(cls, repo_full_path):
1625 1664 repo_name = repo_full_path.split(cls.base_path(), 1)[-1]
1626 1665 repo_name = cls.normalize_repo_name(repo_name)
1627 1666 return cls.get_by_repo_name(repo_name.strip(URL_SEP))
1628 1667
1629 1668 @classmethod
1630 1669 def get_repo_forks(cls, repo_id):
1631 1670 return cls.query().filter(Repository.fork_id == repo_id)
1632 1671
1633 1672 @classmethod
1634 1673 def base_path(cls):
1635 1674 """
1636 1675 Returns base path when all repos are stored
1637 1676
1638 1677 :param cls:
1639 1678 """
1640 1679 q = Session().query(RhodeCodeUi)\
1641 1680 .filter(RhodeCodeUi.ui_key == cls.NAME_SEP)
1642 1681 q = q.options(FromCache("sql_cache_short", "repository_repo_path"))
1643 1682 return q.one().ui_value
1644 1683
1645 1684 @classmethod
1646 1685 def is_valid(cls, repo_name):
1647 1686 """
1648 1687 returns True if given repo name is a valid filesystem repository
1649 1688
1650 1689 :param cls:
1651 1690 :param repo_name:
1652 1691 """
1653 1692 from rhodecode.lib.utils import is_valid_repo
1654 1693
1655 1694 return is_valid_repo(repo_name, cls.base_path())
1656 1695
1657 1696 @classmethod
1658 1697 def get_all_repos(cls, user_id=Optional(None), group_id=Optional(None),
1659 1698 case_insensitive=True):
1660 1699 q = Repository.query()
1661 1700
1662 1701 if not isinstance(user_id, Optional):
1663 1702 q = q.filter(Repository.user_id == user_id)
1664 1703
1665 1704 if not isinstance(group_id, Optional):
1666 1705 q = q.filter(Repository.group_id == group_id)
1667 1706
1668 1707 if case_insensitive:
1669 1708 q = q.order_by(func.lower(Repository.repo_name))
1670 1709 else:
1671 1710 q = q.order_by(Repository.repo_name)
1672 1711 return q.all()
1673 1712
1674 1713 @property
1675 1714 def forks(self):
1676 1715 """
1677 1716 Return forks of this repo
1678 1717 """
1679 1718 return Repository.get_repo_forks(self.repo_id)
1680 1719
1681 1720 @property
1682 1721 def parent(self):
1683 1722 """
1684 1723 Returns fork parent
1685 1724 """
1686 1725 return self.fork
1687 1726
1688 1727 @property
1689 1728 def just_name(self):
1690 1729 return self.repo_name.split(self.NAME_SEP)[-1]
1691 1730
1692 1731 @property
1693 1732 def groups_with_parents(self):
1694 1733 groups = []
1695 1734 if self.group is None:
1696 1735 return groups
1697 1736
1698 1737 cur_gr = self.group
1699 1738 groups.insert(0, cur_gr)
1700 1739 while 1:
1701 1740 gr = getattr(cur_gr, 'parent_group', None)
1702 1741 cur_gr = cur_gr.parent_group
1703 1742 if gr is None:
1704 1743 break
1705 1744 groups.insert(0, gr)
1706 1745
1707 1746 return groups
1708 1747
1709 1748 @property
1710 1749 def groups_and_repo(self):
1711 1750 return self.groups_with_parents, self
1712 1751
1713 1752 @LazyProperty
1714 1753 def repo_path(self):
1715 1754 """
1716 1755 Returns base full path for that repository means where it actually
1717 1756 exists on a filesystem
1718 1757 """
1719 1758 q = Session().query(RhodeCodeUi).filter(
1720 1759 RhodeCodeUi.ui_key == self.NAME_SEP)
1721 1760 q = q.options(FromCache("sql_cache_short", "repository_repo_path"))
1722 1761 return q.one().ui_value
1723 1762
1724 1763 @property
1725 1764 def repo_full_path(self):
1726 1765 p = [self.repo_path]
1727 1766 # we need to split the name by / since this is how we store the
1728 1767 # names in the database, but that eventually needs to be converted
1729 1768 # into a valid system path
1730 1769 p += self.repo_name.split(self.NAME_SEP)
1731 1770 return os.path.join(*map(safe_unicode, p))
1732 1771
1733 1772 @property
1734 1773 def cache_keys(self):
1735 1774 """
1736 1775 Returns associated cache keys for that repo
1737 1776 """
1738 1777 return CacheKey.query()\
1739 1778 .filter(CacheKey.cache_args == self.repo_name)\
1740 1779 .order_by(CacheKey.cache_key)\
1741 1780 .all()
1742 1781
1743 1782 def get_new_name(self, repo_name):
1744 1783 """
1745 1784 returns new full repository name based on assigned group and new new
1746 1785
1747 1786 :param group_name:
1748 1787 """
1749 1788 path_prefix = self.group.full_path_splitted if self.group else []
1750 1789 return self.NAME_SEP.join(path_prefix + [repo_name])
1751 1790
1752 1791 @property
1753 1792 def _config(self):
1754 1793 """
1755 1794 Returns db based config object.
1756 1795 """
1757 1796 from rhodecode.lib.utils import make_db_config
1758 1797 return make_db_config(clear_session=False, repo=self)
1759 1798
1760 1799 def permissions(self, with_admins=True, with_owner=True):
1761 1800 q = UserRepoToPerm.query().filter(UserRepoToPerm.repository == self)
1762 1801 q = q.options(joinedload(UserRepoToPerm.repository),
1763 1802 joinedload(UserRepoToPerm.user),
1764 1803 joinedload(UserRepoToPerm.permission),)
1765 1804
1766 1805 # get owners and admins and permissions. We do a trick of re-writing
1767 1806 # objects from sqlalchemy to named-tuples due to sqlalchemy session
1768 1807 # has a global reference and changing one object propagates to all
1769 1808 # others. This means if admin is also an owner admin_row that change
1770 1809 # would propagate to both objects
1771 1810 perm_rows = []
1772 1811 for _usr in q.all():
1773 1812 usr = AttributeDict(_usr.user.get_dict())
1774 1813 usr.permission = _usr.permission.permission_name
1775 1814 perm_rows.append(usr)
1776 1815
1777 1816 # filter the perm rows by 'default' first and then sort them by
1778 1817 # admin,write,read,none permissions sorted again alphabetically in
1779 1818 # each group
1780 1819 perm_rows = sorted(perm_rows, key=display_sort)
1781 1820
1782 1821 _admin_perm = 'repository.admin'
1783 1822 owner_row = []
1784 1823 if with_owner:
1785 1824 usr = AttributeDict(self.user.get_dict())
1786 1825 usr.owner_row = True
1787 1826 usr.permission = _admin_perm
1788 1827 owner_row.append(usr)
1789 1828
1790 1829 super_admin_rows = []
1791 1830 if with_admins:
1792 1831 for usr in User.get_all_super_admins():
1793 1832 # if this admin is also owner, don't double the record
1794 1833 if usr.user_id == owner_row[0].user_id:
1795 1834 owner_row[0].admin_row = True
1796 1835 else:
1797 1836 usr = AttributeDict(usr.get_dict())
1798 1837 usr.admin_row = True
1799 1838 usr.permission = _admin_perm
1800 1839 super_admin_rows.append(usr)
1801 1840
1802 1841 return super_admin_rows + owner_row + perm_rows
1803 1842
1804 1843 def permission_user_groups(self):
1805 1844 q = UserGroupRepoToPerm.query().filter(
1806 1845 UserGroupRepoToPerm.repository == self)
1807 1846 q = q.options(joinedload(UserGroupRepoToPerm.repository),
1808 1847 joinedload(UserGroupRepoToPerm.users_group),
1809 1848 joinedload(UserGroupRepoToPerm.permission),)
1810 1849
1811 1850 perm_rows = []
1812 1851 for _user_group in q.all():
1813 1852 usr = AttributeDict(_user_group.users_group.get_dict())
1814 1853 usr.permission = _user_group.permission.permission_name
1815 1854 perm_rows.append(usr)
1816 1855
1817 1856 return perm_rows
1818 1857
1819 1858 def get_api_data(self, include_secrets=False):
1820 1859 """
1821 1860 Common function for generating repo api data
1822 1861
1823 1862 :param include_secrets: See :meth:`User.get_api_data`.
1824 1863
1825 1864 """
1826 1865 # TODO: mikhail: Here there is an anti-pattern, we probably need to
1827 1866 # move this methods on models level.
1828 1867 from rhodecode.model.settings import SettingsModel
1829 1868 from rhodecode.model.repo import RepoModel
1830 1869
1831 1870 repo = self
1832 1871 _user_id, _time, _reason = self.locked
1833 1872
1834 1873 data = {
1835 1874 'repo_id': repo.repo_id,
1836 1875 'repo_name': repo.repo_name,
1837 1876 'repo_type': repo.repo_type,
1838 1877 'clone_uri': repo.clone_uri or '',
1839 1878 'url': RepoModel().get_url(self),
1840 1879 'private': repo.private,
1841 1880 'created_on': repo.created_on,
1842 1881 'description': repo.description_safe,
1843 1882 'landing_rev': repo.landing_rev,
1844 1883 'owner': repo.user.username,
1845 1884 'fork_of': repo.fork.repo_name if repo.fork else None,
1846 1885 'fork_of_id': repo.fork.repo_id if repo.fork else None,
1847 1886 'enable_statistics': repo.enable_statistics,
1848 1887 'enable_locking': repo.enable_locking,
1849 1888 'enable_downloads': repo.enable_downloads,
1850 1889 'last_changeset': repo.changeset_cache,
1851 1890 'locked_by': User.get(_user_id).get_api_data(
1852 1891 include_secrets=include_secrets) if _user_id else None,
1853 1892 'locked_date': time_to_datetime(_time) if _time else None,
1854 1893 'lock_reason': _reason if _reason else None,
1855 1894 }
1856 1895
1857 1896 # TODO: mikhail: should be per-repo settings here
1858 1897 rc_config = SettingsModel().get_all_settings()
1859 1898 repository_fields = str2bool(
1860 1899 rc_config.get('rhodecode_repository_fields'))
1861 1900 if repository_fields:
1862 1901 for f in self.extra_fields:
1863 1902 data[f.field_key_prefixed] = f.field_value
1864 1903
1865 1904 return data
1866 1905
1867 1906 @classmethod
1868 1907 def lock(cls, repo, user_id, lock_time=None, lock_reason=None):
1869 1908 if not lock_time:
1870 1909 lock_time = time.time()
1871 1910 if not lock_reason:
1872 1911 lock_reason = cls.LOCK_AUTOMATIC
1873 1912 repo.locked = [user_id, lock_time, lock_reason]
1874 1913 Session().add(repo)
1875 1914 Session().commit()
1876 1915
1877 1916 @classmethod
1878 1917 def unlock(cls, repo):
1879 1918 repo.locked = None
1880 1919 Session().add(repo)
1881 1920 Session().commit()
1882 1921
1883 1922 @classmethod
1884 1923 def getlock(cls, repo):
1885 1924 return repo.locked
1886 1925
1887 1926 def is_user_lock(self, user_id):
1888 1927 if self.lock[0]:
1889 1928 lock_user_id = safe_int(self.lock[0])
1890 1929 user_id = safe_int(user_id)
1891 1930 # both are ints, and they are equal
1892 1931 return all([lock_user_id, user_id]) and lock_user_id == user_id
1893 1932
1894 1933 return False
1895 1934
1896 1935 def get_locking_state(self, action, user_id, only_when_enabled=True):
1897 1936 """
1898 1937 Checks locking on this repository, if locking is enabled and lock is
1899 1938 present returns a tuple of make_lock, locked, locked_by.
1900 1939 make_lock can have 3 states None (do nothing) True, make lock
1901 1940 False release lock, This value is later propagated to hooks, which
1902 1941 do the locking. Think about this as signals passed to hooks what to do.
1903 1942
1904 1943 """
1905 1944 # TODO: johbo: This is part of the business logic and should be moved
1906 1945 # into the RepositoryModel.
1907 1946
1908 1947 if action not in ('push', 'pull'):
1909 1948 raise ValueError("Invalid action value: %s" % repr(action))
1910 1949
1911 1950 # defines if locked error should be thrown to user
1912 1951 currently_locked = False
1913 1952 # defines if new lock should be made, tri-state
1914 1953 make_lock = None
1915 1954 repo = self
1916 1955 user = User.get(user_id)
1917 1956
1918 1957 lock_info = repo.locked
1919 1958
1920 1959 if repo and (repo.enable_locking or not only_when_enabled):
1921 1960 if action == 'push':
1922 1961 # check if it's already locked !, if it is compare users
1923 1962 locked_by_user_id = lock_info[0]
1924 1963 if user.user_id == locked_by_user_id:
1925 1964 log.debug(
1926 1965 'Got `push` action from user %s, now unlocking', user)
1927 1966 # unlock if we have push from user who locked
1928 1967 make_lock = False
1929 1968 else:
1930 1969 # we're not the same user who locked, ban with
1931 1970 # code defined in settings (default is 423 HTTP Locked) !
1932 1971 log.debug('Repo %s is currently locked by %s', repo, user)
1933 1972 currently_locked = True
1934 1973 elif action == 'pull':
1935 1974 # [0] user [1] date
1936 1975 if lock_info[0] and lock_info[1]:
1937 1976 log.debug('Repo %s is currently locked by %s', repo, user)
1938 1977 currently_locked = True
1939 1978 else:
1940 1979 log.debug('Setting lock on repo %s by %s', repo, user)
1941 1980 make_lock = True
1942 1981
1943 1982 else:
1944 1983 log.debug('Repository %s do not have locking enabled', repo)
1945 1984
1946 1985 log.debug('FINAL locking values make_lock:%s,locked:%s,locked_by:%s',
1947 1986 make_lock, currently_locked, lock_info)
1948 1987
1949 1988 from rhodecode.lib.auth import HasRepoPermissionAny
1950 1989 perm_check = HasRepoPermissionAny('repository.write', 'repository.admin')
1951 1990 if make_lock and not perm_check(repo_name=repo.repo_name, user=user):
1952 1991 # if we don't have at least write permission we cannot make a lock
1953 1992 log.debug('lock state reset back to FALSE due to lack '
1954 1993 'of at least read permission')
1955 1994 make_lock = False
1956 1995
1957 1996 return make_lock, currently_locked, lock_info
1958 1997
1959 1998 @property
1960 1999 def last_db_change(self):
1961 2000 return self.updated_on
1962 2001
1963 2002 @property
1964 2003 def clone_uri_hidden(self):
1965 2004 clone_uri = self.clone_uri
1966 2005 if clone_uri:
1967 2006 import urlobject
1968 2007 url_obj = urlobject.URLObject(cleaned_uri(clone_uri))
1969 2008 if url_obj.password:
1970 2009 clone_uri = url_obj.with_password('*****')
1971 2010 return clone_uri
1972 2011
1973 2012 def clone_url(self, **override):
1974 2013 from rhodecode.model.settings import SettingsModel
1975 2014
1976 2015 uri_tmpl = None
1977 2016 if 'with_id' in override:
1978 2017 uri_tmpl = self.DEFAULT_CLONE_URI_ID
1979 2018 del override['with_id']
1980 2019
1981 2020 if 'uri_tmpl' in override:
1982 2021 uri_tmpl = override['uri_tmpl']
1983 2022 del override['uri_tmpl']
1984 2023
1985 2024 # we didn't override our tmpl from **overrides
1986 2025 if not uri_tmpl:
1987 2026 rc_config = SettingsModel().get_all_settings(cache=True)
1988 2027 uri_tmpl = rc_config.get(
1989 2028 'rhodecode_clone_uri_tmpl') or self.DEFAULT_CLONE_URI
1990 2029
1991 2030 request = get_current_request()
1992 2031 return get_clone_url(request=request,
1993 2032 uri_tmpl=uri_tmpl,
1994 2033 repo_name=self.repo_name,
1995 2034 repo_id=self.repo_id, **override)
1996 2035
1997 2036 def set_state(self, state):
1998 2037 self.repo_state = state
1999 2038 Session().add(self)
2000 2039 #==========================================================================
2001 2040 # SCM PROPERTIES
2002 2041 #==========================================================================
2003 2042
2004 2043 def get_commit(self, commit_id=None, commit_idx=None, pre_load=None):
2005 2044 return get_commit_safe(
2006 2045 self.scm_instance(), commit_id, commit_idx, pre_load=pre_load)
2007 2046
2008 2047 def get_changeset(self, rev=None, pre_load=None):
2009 2048 warnings.warn("Use get_commit", DeprecationWarning)
2010 2049 commit_id = None
2011 2050 commit_idx = None
2012 2051 if isinstance(rev, basestring):
2013 2052 commit_id = rev
2014 2053 else:
2015 2054 commit_idx = rev
2016 2055 return self.get_commit(commit_id=commit_id, commit_idx=commit_idx,
2017 2056 pre_load=pre_load)
2018 2057
2019 2058 def get_landing_commit(self):
2020 2059 """
2021 2060 Returns landing commit, or if that doesn't exist returns the tip
2022 2061 """
2023 2062 _rev_type, _rev = self.landing_rev
2024 2063 commit = self.get_commit(_rev)
2025 2064 if isinstance(commit, EmptyCommit):
2026 2065 return self.get_commit()
2027 2066 return commit
2028 2067
2029 2068 def update_commit_cache(self, cs_cache=None, config=None):
2030 2069 """
2031 2070 Update cache of last changeset for repository, keys should be::
2032 2071
2033 2072 short_id
2034 2073 raw_id
2035 2074 revision
2036 2075 parents
2037 2076 message
2038 2077 date
2039 2078 author
2040 2079
2041 2080 :param cs_cache:
2042 2081 """
2043 2082 from rhodecode.lib.vcs.backends.base import BaseChangeset
2044 2083 if cs_cache is None:
2045 2084 # use no-cache version here
2046 2085 scm_repo = self.scm_instance(cache=False, config=config)
2047 2086 if scm_repo:
2048 2087 cs_cache = scm_repo.get_commit(
2049 2088 pre_load=["author", "date", "message", "parents"])
2050 2089 else:
2051 2090 cs_cache = EmptyCommit()
2052 2091
2053 2092 if isinstance(cs_cache, BaseChangeset):
2054 2093 cs_cache = cs_cache.__json__()
2055 2094
2056 2095 def is_outdated(new_cs_cache):
2057 2096 if (new_cs_cache['raw_id'] != self.changeset_cache['raw_id'] or
2058 2097 new_cs_cache['revision'] != self.changeset_cache['revision']):
2059 2098 return True
2060 2099 return False
2061 2100
2062 2101 # check if we have maybe already latest cached revision
2063 2102 if is_outdated(cs_cache) or not self.changeset_cache:
2064 2103 _default = datetime.datetime.fromtimestamp(0)
2065 2104 last_change = cs_cache.get('date') or _default
2066 2105 log.debug('updated repo %s with new cs cache %s',
2067 2106 self.repo_name, cs_cache)
2068 2107 self.updated_on = last_change
2069 2108 self.changeset_cache = cs_cache
2070 2109 Session().add(self)
2071 2110 Session().commit()
2072 2111 else:
2073 2112 log.debug('Skipping update_commit_cache for repo:`%s` '
2074 2113 'commit already with latest changes', self.repo_name)
2075 2114
2076 2115 @property
2077 2116 def tip(self):
2078 2117 return self.get_commit('tip')
2079 2118
2080 2119 @property
2081 2120 def author(self):
2082 2121 return self.tip.author
2083 2122
2084 2123 @property
2085 2124 def last_change(self):
2086 2125 return self.scm_instance().last_change
2087 2126
2088 2127 def get_comments(self, revisions=None):
2089 2128 """
2090 2129 Returns comments for this repository grouped by revisions
2091 2130
2092 2131 :param revisions: filter query by revisions only
2093 2132 """
2094 2133 cmts = ChangesetComment.query()\
2095 2134 .filter(ChangesetComment.repo == self)
2096 2135 if revisions:
2097 2136 cmts = cmts.filter(ChangesetComment.revision.in_(revisions))
2098 2137 grouped = collections.defaultdict(list)
2099 2138 for cmt in cmts.all():
2100 2139 grouped[cmt.revision].append(cmt)
2101 2140 return grouped
2102 2141
2103 2142 def statuses(self, revisions=None):
2104 2143 """
2105 2144 Returns statuses for this repository
2106 2145
2107 2146 :param revisions: list of revisions to get statuses for
2108 2147 """
2109 2148 statuses = ChangesetStatus.query()\
2110 2149 .filter(ChangesetStatus.repo == self)\
2111 2150 .filter(ChangesetStatus.version == 0)
2112 2151
2113 2152 if revisions:
2114 2153 # Try doing the filtering in chunks to avoid hitting limits
2115 2154 size = 500
2116 2155 status_results = []
2117 2156 for chunk in xrange(0, len(revisions), size):
2118 2157 status_results += statuses.filter(
2119 2158 ChangesetStatus.revision.in_(
2120 2159 revisions[chunk: chunk+size])
2121 2160 ).all()
2122 2161 else:
2123 2162 status_results = statuses.all()
2124 2163
2125 2164 grouped = {}
2126 2165
2127 2166 # maybe we have open new pullrequest without a status?
2128 2167 stat = ChangesetStatus.STATUS_UNDER_REVIEW
2129 2168 status_lbl = ChangesetStatus.get_status_lbl(stat)
2130 2169 for pr in PullRequest.query().filter(PullRequest.source_repo == self).all():
2131 2170 for rev in pr.revisions:
2132 2171 pr_id = pr.pull_request_id
2133 2172 pr_repo = pr.target_repo.repo_name
2134 2173 grouped[rev] = [stat, status_lbl, pr_id, pr_repo]
2135 2174
2136 2175 for stat in status_results:
2137 2176 pr_id = pr_repo = None
2138 2177 if stat.pull_request:
2139 2178 pr_id = stat.pull_request.pull_request_id
2140 2179 pr_repo = stat.pull_request.target_repo.repo_name
2141 2180 grouped[stat.revision] = [str(stat.status), stat.status_lbl,
2142 2181 pr_id, pr_repo]
2143 2182 return grouped
2144 2183
2145 2184 # ==========================================================================
2146 2185 # SCM CACHE INSTANCE
2147 2186 # ==========================================================================
2148 2187
2149 2188 def scm_instance(self, **kwargs):
2150 2189 import rhodecode
2151 2190
2152 2191 # Passing a config will not hit the cache currently only used
2153 2192 # for repo2dbmapper
2154 2193 config = kwargs.pop('config', None)
2155 2194 cache = kwargs.pop('cache', None)
2156 2195 full_cache = str2bool(rhodecode.CONFIG.get('vcs_full_cache'))
2157 2196 # if cache is NOT defined use default global, else we have a full
2158 2197 # control over cache behaviour
2159 2198 if cache is None and full_cache and not config:
2160 2199 return self._get_instance_cached()
2161 2200 return self._get_instance(cache=bool(cache), config=config)
2162 2201
2163 2202 def _get_instance_cached(self):
2164 2203 @cache_region('long_term')
2165 2204 def _get_repo(cache_key):
2166 2205 return self._get_instance()
2167 2206
2168 2207 invalidator_context = CacheKey.repo_context_cache(
2169 2208 _get_repo, self.repo_name, None, thread_scoped=True)
2170 2209
2171 2210 with invalidator_context as context:
2172 2211 context.invalidate()
2173 2212 repo = context.compute()
2174 2213
2175 2214 return repo
2176 2215
2177 2216 def _get_instance(self, cache=True, config=None):
2178 2217 config = config or self._config
2179 2218 custom_wire = {
2180 2219 'cache': cache # controls the vcs.remote cache
2181 2220 }
2182 2221 repo = get_vcs_instance(
2183 2222 repo_path=safe_str(self.repo_full_path),
2184 2223 config=config,
2185 2224 with_wire=custom_wire,
2186 2225 create=False,
2187 2226 _vcs_alias=self.repo_type)
2188 2227
2189 2228 return repo
2190 2229
2191 2230 def __json__(self):
2192 2231 return {'landing_rev': self.landing_rev}
2193 2232
2194 2233 def get_dict(self):
2195 2234
2196 2235 # Since we transformed `repo_name` to a hybrid property, we need to
2197 2236 # keep compatibility with the code which uses `repo_name` field.
2198 2237
2199 2238 result = super(Repository, self).get_dict()
2200 2239 result['repo_name'] = result.pop('_repo_name', None)
2201 2240 return result
2202 2241
2203 2242
2204 2243 class RepoGroup(Base, BaseModel):
2205 2244 __tablename__ = 'groups'
2206 2245 __table_args__ = (
2207 2246 UniqueConstraint('group_name', 'group_parent_id'),
2208 2247 CheckConstraint('group_id != group_parent_id'),
2209 2248 {'extend_existing': True, 'mysql_engine': 'InnoDB',
2210 2249 'mysql_charset': 'utf8', 'sqlite_autoincrement': True},
2211 2250 )
2212 2251 __mapper_args__ = {'order_by': 'group_name'}
2213 2252
2214 2253 CHOICES_SEPARATOR = '/' # used to generate select2 choices for nested groups
2215 2254
2216 2255 group_id = Column("group_id", Integer(), nullable=False, unique=True, default=None, primary_key=True)
2217 2256 group_name = Column("group_name", String(255), nullable=False, unique=True, default=None)
2218 2257 group_parent_id = Column("group_parent_id", Integer(), ForeignKey('groups.group_id'), nullable=True, unique=None, default=None)
2219 2258 group_description = Column("group_description", String(10000), nullable=True, unique=None, default=None)
2220 2259 enable_locking = Column("enable_locking", Boolean(), nullable=False, unique=None, default=False)
2221 2260 user_id = Column("user_id", Integer(), ForeignKey('users.user_id'), nullable=False, unique=False, default=None)
2222 2261 created_on = Column('created_on', DateTime(timezone=False), nullable=False, default=datetime.datetime.now)
2223 2262 updated_on = Column('updated_on', DateTime(timezone=False), nullable=True, unique=None, default=datetime.datetime.now)
2224 2263 personal = Column('personal', Boolean(), nullable=True, unique=None, default=None)
2225 2264
2226 2265 repo_group_to_perm = relationship('UserRepoGroupToPerm', cascade='all', order_by='UserRepoGroupToPerm.group_to_perm_id')
2227 2266 users_group_to_perm = relationship('UserGroupRepoGroupToPerm', cascade='all')
2228 2267 parent_group = relationship('RepoGroup', remote_side=group_id)
2229 2268 user = relationship('User')
2230 2269 integrations = relationship('Integration',
2231 2270 cascade="all, delete, delete-orphan")
2232 2271
2233 2272 def __init__(self, group_name='', parent_group=None):
2234 2273 self.group_name = group_name
2235 2274 self.parent_group = parent_group
2236 2275
2237 2276 def __unicode__(self):
2238 2277 return u"<%s('id:%s:%s')>" % (
2239 2278 self.__class__.__name__, self.group_id, self.group_name)
2240 2279
2241 2280 @hybrid_property
2242 2281 def description_safe(self):
2243 2282 from rhodecode.lib import helpers as h
2244 2283 return h.escape(self.group_description)
2245 2284
2246 2285 @classmethod
2247 2286 def _generate_choice(cls, repo_group):
2248 2287 from webhelpers.html import literal as _literal
2249 2288 _name = lambda k: _literal(cls.CHOICES_SEPARATOR.join(k))
2250 2289 return repo_group.group_id, _name(repo_group.full_path_splitted)
2251 2290
2252 2291 @classmethod
2253 2292 def groups_choices(cls, groups=None, show_empty_group=True):
2254 2293 if not groups:
2255 2294 groups = cls.query().all()
2256 2295
2257 2296 repo_groups = []
2258 2297 if show_empty_group:
2259 2298 repo_groups = [(-1, u'-- %s --' % _('No parent'))]
2260 2299
2261 2300 repo_groups.extend([cls._generate_choice(x) for x in groups])
2262 2301
2263 2302 repo_groups = sorted(
2264 2303 repo_groups, key=lambda t: t[1].split(cls.CHOICES_SEPARATOR)[0])
2265 2304 return repo_groups
2266 2305
2267 2306 @classmethod
2268 2307 def url_sep(cls):
2269 2308 return URL_SEP
2270 2309
2271 2310 @classmethod
2272 2311 def get_by_group_name(cls, group_name, cache=False, case_insensitive=False):
2273 2312 if case_insensitive:
2274 2313 gr = cls.query().filter(func.lower(cls.group_name)
2275 2314 == func.lower(group_name))
2276 2315 else:
2277 2316 gr = cls.query().filter(cls.group_name == group_name)
2278 2317 if cache:
2279 2318 name_key = _hash_key(group_name)
2280 2319 gr = gr.options(
2281 2320 FromCache("sql_cache_short", "get_group_%s" % name_key))
2282 2321 return gr.scalar()
2283 2322
2284 2323 @classmethod
2285 2324 def get_user_personal_repo_group(cls, user_id):
2286 2325 user = User.get(user_id)
2287 2326 if user.username == User.DEFAULT_USER:
2288 2327 return None
2289 2328
2290 2329 return cls.query()\
2291 2330 .filter(cls.personal == true()) \
2292 2331 .filter(cls.user == user).scalar()
2293 2332
2294 2333 @classmethod
2295 2334 def get_all_repo_groups(cls, user_id=Optional(None), group_id=Optional(None),
2296 2335 case_insensitive=True):
2297 2336 q = RepoGroup.query()
2298 2337
2299 2338 if not isinstance(user_id, Optional):
2300 2339 q = q.filter(RepoGroup.user_id == user_id)
2301 2340
2302 2341 if not isinstance(group_id, Optional):
2303 2342 q = q.filter(RepoGroup.group_parent_id == group_id)
2304 2343
2305 2344 if case_insensitive:
2306 2345 q = q.order_by(func.lower(RepoGroup.group_name))
2307 2346 else:
2308 2347 q = q.order_by(RepoGroup.group_name)
2309 2348 return q.all()
2310 2349
2311 2350 @property
2312 2351 def parents(self):
2313 2352 parents_recursion_limit = 10
2314 2353 groups = []
2315 2354 if self.parent_group is None:
2316 2355 return groups
2317 2356 cur_gr = self.parent_group
2318 2357 groups.insert(0, cur_gr)
2319 2358 cnt = 0
2320 2359 while 1:
2321 2360 cnt += 1
2322 2361 gr = getattr(cur_gr, 'parent_group', None)
2323 2362 cur_gr = cur_gr.parent_group
2324 2363 if gr is None:
2325 2364 break
2326 2365 if cnt == parents_recursion_limit:
2327 2366 # this will prevent accidental infinit loops
2328 2367 log.error(('more than %s parents found for group %s, stopping '
2329 2368 'recursive parent fetching' % (parents_recursion_limit, self)))
2330 2369 break
2331 2370
2332 2371 groups.insert(0, gr)
2333 2372 return groups
2334 2373
2335 2374 @property
2336 2375 def last_db_change(self):
2337 2376 return self.updated_on
2338 2377
2339 2378 @property
2340 2379 def children(self):
2341 2380 return RepoGroup.query().filter(RepoGroup.parent_group == self)
2342 2381
2343 2382 @property
2344 2383 def name(self):
2345 2384 return self.group_name.split(RepoGroup.url_sep())[-1]
2346 2385
2347 2386 @property
2348 2387 def full_path(self):
2349 2388 return self.group_name
2350 2389
2351 2390 @property
2352 2391 def full_path_splitted(self):
2353 2392 return self.group_name.split(RepoGroup.url_sep())
2354 2393
2355 2394 @property
2356 2395 def repositories(self):
2357 2396 return Repository.query()\
2358 2397 .filter(Repository.group == self)\
2359 2398 .order_by(Repository.repo_name)
2360 2399
2361 2400 @property
2362 2401 def repositories_recursive_count(self):
2363 2402 cnt = self.repositories.count()
2364 2403
2365 2404 def children_count(group):
2366 2405 cnt = 0
2367 2406 for child in group.children:
2368 2407 cnt += child.repositories.count()
2369 2408 cnt += children_count(child)
2370 2409 return cnt
2371 2410
2372 2411 return cnt + children_count(self)
2373 2412
2374 2413 def _recursive_objects(self, include_repos=True):
2375 2414 all_ = []
2376 2415
2377 2416 def _get_members(root_gr):
2378 2417 if include_repos:
2379 2418 for r in root_gr.repositories:
2380 2419 all_.append(r)
2381 2420 childs = root_gr.children.all()
2382 2421 if childs:
2383 2422 for gr in childs:
2384 2423 all_.append(gr)
2385 2424 _get_members(gr)
2386 2425
2387 2426 _get_members(self)
2388 2427 return [self] + all_
2389 2428
2390 2429 def recursive_groups_and_repos(self):
2391 2430 """
2392 2431 Recursive return all groups, with repositories in those groups
2393 2432 """
2394 2433 return self._recursive_objects()
2395 2434
2396 2435 def recursive_groups(self):
2397 2436 """
2398 2437 Returns all children groups for this group including children of children
2399 2438 """
2400 2439 return self._recursive_objects(include_repos=False)
2401 2440
2402 2441 def get_new_name(self, group_name):
2403 2442 """
2404 2443 returns new full group name based on parent and new name
2405 2444
2406 2445 :param group_name:
2407 2446 """
2408 2447 path_prefix = (self.parent_group.full_path_splitted if
2409 2448 self.parent_group else [])
2410 2449 return RepoGroup.url_sep().join(path_prefix + [group_name])
2411 2450
2412 2451 def permissions(self, with_admins=True, with_owner=True):
2413 2452 q = UserRepoGroupToPerm.query().filter(UserRepoGroupToPerm.group == self)
2414 2453 q = q.options(joinedload(UserRepoGroupToPerm.group),
2415 2454 joinedload(UserRepoGroupToPerm.user),
2416 2455 joinedload(UserRepoGroupToPerm.permission),)
2417 2456
2418 2457 # get owners and admins and permissions. We do a trick of re-writing
2419 2458 # objects from sqlalchemy to named-tuples due to sqlalchemy session
2420 2459 # has a global reference and changing one object propagates to all
2421 2460 # others. This means if admin is also an owner admin_row that change
2422 2461 # would propagate to both objects
2423 2462 perm_rows = []
2424 2463 for _usr in q.all():
2425 2464 usr = AttributeDict(_usr.user.get_dict())
2426 2465 usr.permission = _usr.permission.permission_name
2427 2466 perm_rows.append(usr)
2428 2467
2429 2468 # filter the perm rows by 'default' first and then sort them by
2430 2469 # admin,write,read,none permissions sorted again alphabetically in
2431 2470 # each group
2432 2471 perm_rows = sorted(perm_rows, key=display_sort)
2433 2472
2434 2473 _admin_perm = 'group.admin'
2435 2474 owner_row = []
2436 2475 if with_owner:
2437 2476 usr = AttributeDict(self.user.get_dict())
2438 2477 usr.owner_row = True
2439 2478 usr.permission = _admin_perm
2440 2479 owner_row.append(usr)
2441 2480
2442 2481 super_admin_rows = []
2443 2482 if with_admins:
2444 2483 for usr in User.get_all_super_admins():
2445 2484 # if this admin is also owner, don't double the record
2446 2485 if usr.user_id == owner_row[0].user_id:
2447 2486 owner_row[0].admin_row = True
2448 2487 else:
2449 2488 usr = AttributeDict(usr.get_dict())
2450 2489 usr.admin_row = True
2451 2490 usr.permission = _admin_perm
2452 2491 super_admin_rows.append(usr)
2453 2492
2454 2493 return super_admin_rows + owner_row + perm_rows
2455 2494
2456 2495 def permission_user_groups(self):
2457 2496 q = UserGroupRepoGroupToPerm.query().filter(UserGroupRepoGroupToPerm.group == self)
2458 2497 q = q.options(joinedload(UserGroupRepoGroupToPerm.group),
2459 2498 joinedload(UserGroupRepoGroupToPerm.users_group),
2460 2499 joinedload(UserGroupRepoGroupToPerm.permission),)
2461 2500
2462 2501 perm_rows = []
2463 2502 for _user_group in q.all():
2464 2503 usr = AttributeDict(_user_group.users_group.get_dict())
2465 2504 usr.permission = _user_group.permission.permission_name
2466 2505 perm_rows.append(usr)
2467 2506
2468 2507 return perm_rows
2469 2508
2470 2509 def get_api_data(self):
2471 2510 """
2472 2511 Common function for generating api data
2473 2512
2474 2513 """
2475 2514 group = self
2476 2515 data = {
2477 2516 'group_id': group.group_id,
2478 2517 'group_name': group.group_name,
2479 2518 'group_description': group.description_safe,
2480 2519 'parent_group': group.parent_group.group_name if group.parent_group else None,
2481 2520 'repositories': [x.repo_name for x in group.repositories],
2482 2521 'owner': group.user.username,
2483 2522 }
2484 2523 return data
2485 2524
2486 2525
2487 2526 class Permission(Base, BaseModel):
2488 2527 __tablename__ = 'permissions'
2489 2528 __table_args__ = (
2490 2529 Index('p_perm_name_idx', 'permission_name'),
2491 2530 {'extend_existing': True, 'mysql_engine': 'InnoDB',
2492 2531 'mysql_charset': 'utf8', 'sqlite_autoincrement': True},
2493 2532 )
2494 2533 PERMS = [
2495 2534 ('hg.admin', _('RhodeCode Super Administrator')),
2496 2535
2497 2536 ('repository.none', _('Repository no access')),
2498 2537 ('repository.read', _('Repository read access')),
2499 2538 ('repository.write', _('Repository write access')),
2500 2539 ('repository.admin', _('Repository admin access')),
2501 2540
2502 2541 ('group.none', _('Repository group no access')),
2503 2542 ('group.read', _('Repository group read access')),
2504 2543 ('group.write', _('Repository group write access')),
2505 2544 ('group.admin', _('Repository group admin access')),
2506 2545
2507 2546 ('usergroup.none', _('User group no access')),
2508 2547 ('usergroup.read', _('User group read access')),
2509 2548 ('usergroup.write', _('User group write access')),
2510 2549 ('usergroup.admin', _('User group admin access')),
2511 2550
2512 2551 ('hg.repogroup.create.false', _('Repository Group creation disabled')),
2513 2552 ('hg.repogroup.create.true', _('Repository Group creation enabled')),
2514 2553
2515 2554 ('hg.usergroup.create.false', _('User Group creation disabled')),
2516 2555 ('hg.usergroup.create.true', _('User Group creation enabled')),
2517 2556
2518 2557 ('hg.create.none', _('Repository creation disabled')),
2519 2558 ('hg.create.repository', _('Repository creation enabled')),
2520 2559 ('hg.create.write_on_repogroup.true', _('Repository creation enabled with write permission to a repository group')),
2521 2560 ('hg.create.write_on_repogroup.false', _('Repository creation disabled with write permission to a repository group')),
2522 2561
2523 2562 ('hg.fork.none', _('Repository forking disabled')),
2524 2563 ('hg.fork.repository', _('Repository forking enabled')),
2525 2564
2526 2565 ('hg.register.none', _('Registration disabled')),
2527 2566 ('hg.register.manual_activate', _('User Registration with manual account activation')),
2528 2567 ('hg.register.auto_activate', _('User Registration with automatic account activation')),
2529 2568
2530 2569 ('hg.password_reset.enabled', _('Password reset enabled')),
2531 2570 ('hg.password_reset.hidden', _('Password reset hidden')),
2532 2571 ('hg.password_reset.disabled', _('Password reset disabled')),
2533 2572
2534 2573 ('hg.extern_activate.manual', _('Manual activation of external account')),
2535 2574 ('hg.extern_activate.auto', _('Automatic activation of external account')),
2536 2575
2537 2576 ('hg.inherit_default_perms.false', _('Inherit object permissions from default user disabled')),
2538 2577 ('hg.inherit_default_perms.true', _('Inherit object permissions from default user enabled')),
2539 2578 ]
2540 2579
2541 2580 # definition of system default permissions for DEFAULT user
2542 2581 DEFAULT_USER_PERMISSIONS = [
2543 2582 'repository.read',
2544 2583 'group.read',
2545 2584 'usergroup.read',
2546 2585 'hg.create.repository',
2547 2586 'hg.repogroup.create.false',
2548 2587 'hg.usergroup.create.false',
2549 2588 'hg.create.write_on_repogroup.true',
2550 2589 'hg.fork.repository',
2551 2590 'hg.register.manual_activate',
2552 2591 'hg.password_reset.enabled',
2553 2592 'hg.extern_activate.auto',
2554 2593 'hg.inherit_default_perms.true',
2555 2594 ]
2556 2595
2557 2596 # defines which permissions are more important higher the more important
2558 2597 # Weight defines which permissions are more important.
2559 2598 # The higher number the more important.
2560 2599 PERM_WEIGHTS = {
2561 2600 'repository.none': 0,
2562 2601 'repository.read': 1,
2563 2602 'repository.write': 3,
2564 2603 'repository.admin': 4,
2565 2604
2566 2605 'group.none': 0,
2567 2606 'group.read': 1,
2568 2607 'group.write': 3,
2569 2608 'group.admin': 4,
2570 2609
2571 2610 'usergroup.none': 0,
2572 2611 'usergroup.read': 1,
2573 2612 'usergroup.write': 3,
2574 2613 'usergroup.admin': 4,
2575 2614
2576 2615 'hg.repogroup.create.false': 0,
2577 2616 'hg.repogroup.create.true': 1,
2578 2617
2579 2618 'hg.usergroup.create.false': 0,
2580 2619 'hg.usergroup.create.true': 1,
2581 2620
2582 2621 'hg.fork.none': 0,
2583 2622 'hg.fork.repository': 1,
2584 2623 'hg.create.none': 0,
2585 2624 'hg.create.repository': 1
2586 2625 }
2587 2626
2588 2627 permission_id = Column("permission_id", Integer(), nullable=False, unique=True, default=None, primary_key=True)
2589 2628 permission_name = Column("permission_name", String(255), nullable=True, unique=None, default=None)
2590 2629 permission_longname = Column("permission_longname", String(255), nullable=True, unique=None, default=None)
2591 2630
2592 2631 def __unicode__(self):
2593 2632 return u"<%s('%s:%s')>" % (
2594 2633 self.__class__.__name__, self.permission_id, self.permission_name
2595 2634 )
2596 2635
2597 2636 @classmethod
2598 2637 def get_by_key(cls, key):
2599 2638 return cls.query().filter(cls.permission_name == key).scalar()
2600 2639
2601 2640 @classmethod
2602 2641 def get_default_repo_perms(cls, user_id, repo_id=None):
2603 2642 q = Session().query(UserRepoToPerm, Repository, Permission)\
2604 2643 .join((Permission, UserRepoToPerm.permission_id == Permission.permission_id))\
2605 2644 .join((Repository, UserRepoToPerm.repository_id == Repository.repo_id))\
2606 2645 .filter(UserRepoToPerm.user_id == user_id)
2607 2646 if repo_id:
2608 2647 q = q.filter(UserRepoToPerm.repository_id == repo_id)
2609 2648 return q.all()
2610 2649
2611 2650 @classmethod
2612 2651 def get_default_repo_perms_from_user_group(cls, user_id, repo_id=None):
2613 2652 q = Session().query(UserGroupRepoToPerm, Repository, Permission)\
2614 2653 .join(
2615 2654 Permission,
2616 2655 UserGroupRepoToPerm.permission_id == Permission.permission_id)\
2617 2656 .join(
2618 2657 Repository,
2619 2658 UserGroupRepoToPerm.repository_id == Repository.repo_id)\
2620 2659 .join(
2621 2660 UserGroup,
2622 2661 UserGroupRepoToPerm.users_group_id ==
2623 2662 UserGroup.users_group_id)\
2624 2663 .join(
2625 2664 UserGroupMember,
2626 2665 UserGroupRepoToPerm.users_group_id ==
2627 2666 UserGroupMember.users_group_id)\
2628 2667 .filter(
2629 2668 UserGroupMember.user_id == user_id,
2630 2669 UserGroup.users_group_active == true())
2631 2670 if repo_id:
2632 2671 q = q.filter(UserGroupRepoToPerm.repository_id == repo_id)
2633 2672 return q.all()
2634 2673
2635 2674 @classmethod
2636 2675 def get_default_group_perms(cls, user_id, repo_group_id=None):
2637 2676 q = Session().query(UserRepoGroupToPerm, RepoGroup, Permission)\
2638 2677 .join((Permission, UserRepoGroupToPerm.permission_id == Permission.permission_id))\
2639 2678 .join((RepoGroup, UserRepoGroupToPerm.group_id == RepoGroup.group_id))\
2640 2679 .filter(UserRepoGroupToPerm.user_id == user_id)
2641 2680 if repo_group_id:
2642 2681 q = q.filter(UserRepoGroupToPerm.group_id == repo_group_id)
2643 2682 return q.all()
2644 2683
2645 2684 @classmethod
2646 2685 def get_default_group_perms_from_user_group(
2647 2686 cls, user_id, repo_group_id=None):
2648 2687 q = Session().query(UserGroupRepoGroupToPerm, RepoGroup, Permission)\
2649 2688 .join(
2650 2689 Permission,
2651 2690 UserGroupRepoGroupToPerm.permission_id ==
2652 2691 Permission.permission_id)\
2653 2692 .join(
2654 2693 RepoGroup,
2655 2694 UserGroupRepoGroupToPerm.group_id == RepoGroup.group_id)\
2656 2695 .join(
2657 2696 UserGroup,
2658 2697 UserGroupRepoGroupToPerm.users_group_id ==
2659 2698 UserGroup.users_group_id)\
2660 2699 .join(
2661 2700 UserGroupMember,
2662 2701 UserGroupRepoGroupToPerm.users_group_id ==
2663 2702 UserGroupMember.users_group_id)\
2664 2703 .filter(
2665 2704 UserGroupMember.user_id == user_id,
2666 2705 UserGroup.users_group_active == true())
2667 2706 if repo_group_id:
2668 2707 q = q.filter(UserGroupRepoGroupToPerm.group_id == repo_group_id)
2669 2708 return q.all()
2670 2709
2671 2710 @classmethod
2672 2711 def get_default_user_group_perms(cls, user_id, user_group_id=None):
2673 2712 q = Session().query(UserUserGroupToPerm, UserGroup, Permission)\
2674 2713 .join((Permission, UserUserGroupToPerm.permission_id == Permission.permission_id))\
2675 2714 .join((UserGroup, UserUserGroupToPerm.user_group_id == UserGroup.users_group_id))\
2676 2715 .filter(UserUserGroupToPerm.user_id == user_id)
2677 2716 if user_group_id:
2678 2717 q = q.filter(UserUserGroupToPerm.user_group_id == user_group_id)
2679 2718 return q.all()
2680 2719
2681 2720 @classmethod
2682 2721 def get_default_user_group_perms_from_user_group(
2683 2722 cls, user_id, user_group_id=None):
2684 2723 TargetUserGroup = aliased(UserGroup, name='target_user_group')
2685 2724 q = Session().query(UserGroupUserGroupToPerm, UserGroup, Permission)\
2686 2725 .join(
2687 2726 Permission,
2688 2727 UserGroupUserGroupToPerm.permission_id ==
2689 2728 Permission.permission_id)\
2690 2729 .join(
2691 2730 TargetUserGroup,
2692 2731 UserGroupUserGroupToPerm.target_user_group_id ==
2693 2732 TargetUserGroup.users_group_id)\
2694 2733 .join(
2695 2734 UserGroup,
2696 2735 UserGroupUserGroupToPerm.user_group_id ==
2697 2736 UserGroup.users_group_id)\
2698 2737 .join(
2699 2738 UserGroupMember,
2700 2739 UserGroupUserGroupToPerm.user_group_id ==
2701 2740 UserGroupMember.users_group_id)\
2702 2741 .filter(
2703 2742 UserGroupMember.user_id == user_id,
2704 2743 UserGroup.users_group_active == true())
2705 2744 if user_group_id:
2706 2745 q = q.filter(
2707 2746 UserGroupUserGroupToPerm.user_group_id == user_group_id)
2708 2747
2709 2748 return q.all()
2710 2749
2711 2750
2712 2751 class UserRepoToPerm(Base, BaseModel):
2713 2752 __tablename__ = 'repo_to_perm'
2714 2753 __table_args__ = (
2715 2754 UniqueConstraint('user_id', 'repository_id', 'permission_id'),
2716 2755 {'extend_existing': True, 'mysql_engine': 'InnoDB',
2717 2756 'mysql_charset': 'utf8', 'sqlite_autoincrement': True}
2718 2757 )
2719 2758 repo_to_perm_id = Column("repo_to_perm_id", Integer(), nullable=False, unique=True, default=None, primary_key=True)
2720 2759 user_id = Column("user_id", Integer(), ForeignKey('users.user_id'), nullable=False, unique=None, default=None)
2721 2760 permission_id = Column("permission_id", Integer(), ForeignKey('permissions.permission_id'), nullable=False, unique=None, default=None)
2722 2761 repository_id = Column("repository_id", Integer(), ForeignKey('repositories.repo_id'), nullable=False, unique=None, default=None)
2723 2762
2724 2763 user = relationship('User')
2725 2764 repository = relationship('Repository')
2726 2765 permission = relationship('Permission')
2727 2766
2728 2767 @classmethod
2729 2768 def create(cls, user, repository, permission):
2730 2769 n = cls()
2731 2770 n.user = user
2732 2771 n.repository = repository
2733 2772 n.permission = permission
2734 2773 Session().add(n)
2735 2774 return n
2736 2775
2737 2776 def __unicode__(self):
2738 2777 return u'<%s => %s >' % (self.user, self.repository)
2739 2778
2740 2779
2741 2780 class UserUserGroupToPerm(Base, BaseModel):
2742 2781 __tablename__ = 'user_user_group_to_perm'
2743 2782 __table_args__ = (
2744 2783 UniqueConstraint('user_id', 'user_group_id', 'permission_id'),
2745 2784 {'extend_existing': True, 'mysql_engine': 'InnoDB',
2746 2785 'mysql_charset': 'utf8', 'sqlite_autoincrement': True}
2747 2786 )
2748 2787 user_user_group_to_perm_id = Column("user_user_group_to_perm_id", Integer(), nullable=False, unique=True, default=None, primary_key=True)
2749 2788 user_id = Column("user_id", Integer(), ForeignKey('users.user_id'), nullable=False, unique=None, default=None)
2750 2789 permission_id = Column("permission_id", Integer(), ForeignKey('permissions.permission_id'), nullable=False, unique=None, default=None)
2751 2790 user_group_id = Column("user_group_id", Integer(), ForeignKey('users_groups.users_group_id'), nullable=False, unique=None, default=None)
2752 2791
2753 2792 user = relationship('User')
2754 2793 user_group = relationship('UserGroup')
2755 2794 permission = relationship('Permission')
2756 2795
2757 2796 @classmethod
2758 2797 def create(cls, user, user_group, permission):
2759 2798 n = cls()
2760 2799 n.user = user
2761 2800 n.user_group = user_group
2762 2801 n.permission = permission
2763 2802 Session().add(n)
2764 2803 return n
2765 2804
2766 2805 def __unicode__(self):
2767 2806 return u'<%s => %s >' % (self.user, self.user_group)
2768 2807
2769 2808
2770 2809 class UserToPerm(Base, BaseModel):
2771 2810 __tablename__ = 'user_to_perm'
2772 2811 __table_args__ = (
2773 2812 UniqueConstraint('user_id', 'permission_id'),
2774 2813 {'extend_existing': True, 'mysql_engine': 'InnoDB',
2775 2814 'mysql_charset': 'utf8', 'sqlite_autoincrement': True}
2776 2815 )
2777 2816 user_to_perm_id = Column("user_to_perm_id", Integer(), nullable=False, unique=True, default=None, primary_key=True)
2778 2817 user_id = Column("user_id", Integer(), ForeignKey('users.user_id'), nullable=False, unique=None, default=None)
2779 2818 permission_id = Column("permission_id", Integer(), ForeignKey('permissions.permission_id'), nullable=False, unique=None, default=None)
2780 2819
2781 2820 user = relationship('User')
2782 2821 permission = relationship('Permission', lazy='joined')
2783 2822
2784 2823 def __unicode__(self):
2785 2824 return u'<%s => %s >' % (self.user, self.permission)
2786 2825
2787 2826
2788 2827 class UserGroupRepoToPerm(Base, BaseModel):
2789 2828 __tablename__ = 'users_group_repo_to_perm'
2790 2829 __table_args__ = (
2791 2830 UniqueConstraint('repository_id', 'users_group_id', 'permission_id'),
2792 2831 {'extend_existing': True, 'mysql_engine': 'InnoDB',
2793 2832 'mysql_charset': 'utf8', 'sqlite_autoincrement': True}
2794 2833 )
2795 2834 users_group_to_perm_id = Column("users_group_to_perm_id", Integer(), nullable=False, unique=True, default=None, primary_key=True)
2796 2835 users_group_id = Column("users_group_id", Integer(), ForeignKey('users_groups.users_group_id'), nullable=False, unique=None, default=None)
2797 2836 permission_id = Column("permission_id", Integer(), ForeignKey('permissions.permission_id'), nullable=False, unique=None, default=None)
2798 2837 repository_id = Column("repository_id", Integer(), ForeignKey('repositories.repo_id'), nullable=False, unique=None, default=None)
2799 2838
2800 2839 users_group = relationship('UserGroup')
2801 2840 permission = relationship('Permission')
2802 2841 repository = relationship('Repository')
2803 2842
2804 2843 @classmethod
2805 2844 def create(cls, users_group, repository, permission):
2806 2845 n = cls()
2807 2846 n.users_group = users_group
2808 2847 n.repository = repository
2809 2848 n.permission = permission
2810 2849 Session().add(n)
2811 2850 return n
2812 2851
2813 2852 def __unicode__(self):
2814 2853 return u'<UserGroupRepoToPerm:%s => %s >' % (self.users_group, self.repository)
2815 2854
2816 2855
2817 2856 class UserGroupUserGroupToPerm(Base, BaseModel):
2818 2857 __tablename__ = 'user_group_user_group_to_perm'
2819 2858 __table_args__ = (
2820 2859 UniqueConstraint('target_user_group_id', 'user_group_id', 'permission_id'),
2821 2860 CheckConstraint('target_user_group_id != user_group_id'),
2822 2861 {'extend_existing': True, 'mysql_engine': 'InnoDB',
2823 2862 'mysql_charset': 'utf8', 'sqlite_autoincrement': True}
2824 2863 )
2825 2864 user_group_user_group_to_perm_id = Column("user_group_user_group_to_perm_id", Integer(), nullable=False, unique=True, default=None, primary_key=True)
2826 2865 target_user_group_id = Column("target_user_group_id", Integer(), ForeignKey('users_groups.users_group_id'), nullable=False, unique=None, default=None)
2827 2866 permission_id = Column("permission_id", Integer(), ForeignKey('permissions.permission_id'), nullable=False, unique=None, default=None)
2828 2867 user_group_id = Column("user_group_id", Integer(), ForeignKey('users_groups.users_group_id'), nullable=False, unique=None, default=None)
2829 2868
2830 2869 target_user_group = relationship('UserGroup', primaryjoin='UserGroupUserGroupToPerm.target_user_group_id==UserGroup.users_group_id')
2831 2870 user_group = relationship('UserGroup', primaryjoin='UserGroupUserGroupToPerm.user_group_id==UserGroup.users_group_id')
2832 2871 permission = relationship('Permission')
2833 2872
2834 2873 @classmethod
2835 2874 def create(cls, target_user_group, user_group, permission):
2836 2875 n = cls()
2837 2876 n.target_user_group = target_user_group
2838 2877 n.user_group = user_group
2839 2878 n.permission = permission
2840 2879 Session().add(n)
2841 2880 return n
2842 2881
2843 2882 def __unicode__(self):
2844 2883 return u'<UserGroupUserGroup:%s => %s >' % (self.target_user_group, self.user_group)
2845 2884
2846 2885
2847 2886 class UserGroupToPerm(Base, BaseModel):
2848 2887 __tablename__ = 'users_group_to_perm'
2849 2888 __table_args__ = (
2850 2889 UniqueConstraint('users_group_id', 'permission_id',),
2851 2890 {'extend_existing': True, 'mysql_engine': 'InnoDB',
2852 2891 'mysql_charset': 'utf8', 'sqlite_autoincrement': True}
2853 2892 )
2854 2893 users_group_to_perm_id = Column("users_group_to_perm_id", Integer(), nullable=False, unique=True, default=None, primary_key=True)
2855 2894 users_group_id = Column("users_group_id", Integer(), ForeignKey('users_groups.users_group_id'), nullable=False, unique=None, default=None)
2856 2895 permission_id = Column("permission_id", Integer(), ForeignKey('permissions.permission_id'), nullable=False, unique=None, default=None)
2857 2896
2858 2897 users_group = relationship('UserGroup')
2859 2898 permission = relationship('Permission')
2860 2899
2861 2900
2862 2901 class UserRepoGroupToPerm(Base, BaseModel):
2863 2902 __tablename__ = 'user_repo_group_to_perm'
2864 2903 __table_args__ = (
2865 2904 UniqueConstraint('user_id', 'group_id', 'permission_id'),
2866 2905 {'extend_existing': True, 'mysql_engine': 'InnoDB',
2867 2906 'mysql_charset': 'utf8', 'sqlite_autoincrement': True}
2868 2907 )
2869 2908
2870 2909 group_to_perm_id = Column("group_to_perm_id", Integer(), nullable=False, unique=True, default=None, primary_key=True)
2871 2910 user_id = Column("user_id", Integer(), ForeignKey('users.user_id'), nullable=False, unique=None, default=None)
2872 2911 group_id = Column("group_id", Integer(), ForeignKey('groups.group_id'), nullable=False, unique=None, default=None)
2873 2912 permission_id = Column("permission_id", Integer(), ForeignKey('permissions.permission_id'), nullable=False, unique=None, default=None)
2874 2913
2875 2914 user = relationship('User')
2876 2915 group = relationship('RepoGroup')
2877 2916 permission = relationship('Permission')
2878 2917
2879 2918 @classmethod
2880 2919 def create(cls, user, repository_group, permission):
2881 2920 n = cls()
2882 2921 n.user = user
2883 2922 n.group = repository_group
2884 2923 n.permission = permission
2885 2924 Session().add(n)
2886 2925 return n
2887 2926
2888 2927
2889 2928 class UserGroupRepoGroupToPerm(Base, BaseModel):
2890 2929 __tablename__ = 'users_group_repo_group_to_perm'
2891 2930 __table_args__ = (
2892 2931 UniqueConstraint('users_group_id', 'group_id'),
2893 2932 {'extend_existing': True, 'mysql_engine': 'InnoDB',
2894 2933 'mysql_charset': 'utf8', 'sqlite_autoincrement': True}
2895 2934 )
2896 2935
2897 2936 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)
2898 2937 users_group_id = Column("users_group_id", Integer(), ForeignKey('users_groups.users_group_id'), nullable=False, unique=None, default=None)
2899 2938 group_id = Column("group_id", Integer(), ForeignKey('groups.group_id'), nullable=False, unique=None, default=None)
2900 2939 permission_id = Column("permission_id", Integer(), ForeignKey('permissions.permission_id'), nullable=False, unique=None, default=None)
2901 2940
2902 2941 users_group = relationship('UserGroup')
2903 2942 permission = relationship('Permission')
2904 2943 group = relationship('RepoGroup')
2905 2944
2906 2945 @classmethod
2907 2946 def create(cls, user_group, repository_group, permission):
2908 2947 n = cls()
2909 2948 n.users_group = user_group
2910 2949 n.group = repository_group
2911 2950 n.permission = permission
2912 2951 Session().add(n)
2913 2952 return n
2914 2953
2915 2954 def __unicode__(self):
2916 2955 return u'<UserGroupRepoGroupToPerm:%s => %s >' % (self.users_group, self.group)
2917 2956
2918 2957
2919 2958 class Statistics(Base, BaseModel):
2920 2959 __tablename__ = 'statistics'
2921 2960 __table_args__ = (
2922 2961 {'extend_existing': True, 'mysql_engine': 'InnoDB',
2923 2962 'mysql_charset': 'utf8', 'sqlite_autoincrement': True}
2924 2963 )
2925 2964 stat_id = Column("stat_id", Integer(), nullable=False, unique=True, default=None, primary_key=True)
2926 2965 repository_id = Column("repository_id", Integer(), ForeignKey('repositories.repo_id'), nullable=False, unique=True, default=None)
2927 2966 stat_on_revision = Column("stat_on_revision", Integer(), nullable=False)
2928 2967 commit_activity = Column("commit_activity", LargeBinary(1000000), nullable=False)#JSON data
2929 2968 commit_activity_combined = Column("commit_activity_combined", LargeBinary(), nullable=False)#JSON data
2930 2969 languages = Column("languages", LargeBinary(1000000), nullable=False)#JSON data
2931 2970
2932 2971 repository = relationship('Repository', single_parent=True)
2933 2972
2934 2973
2935 2974 class UserFollowing(Base, BaseModel):
2936 2975 __tablename__ = 'user_followings'
2937 2976 __table_args__ = (
2938 2977 UniqueConstraint('user_id', 'follows_repository_id'),
2939 2978 UniqueConstraint('user_id', 'follows_user_id'),
2940 2979 {'extend_existing': True, 'mysql_engine': 'InnoDB',
2941 2980 'mysql_charset': 'utf8', 'sqlite_autoincrement': True}
2942 2981 )
2943 2982
2944 2983 user_following_id = Column("user_following_id", Integer(), nullable=False, unique=True, default=None, primary_key=True)
2945 2984 user_id = Column("user_id", Integer(), ForeignKey('users.user_id'), nullable=False, unique=None, default=None)
2946 2985 follows_repo_id = Column("follows_repository_id", Integer(), ForeignKey('repositories.repo_id'), nullable=True, unique=None, default=None)
2947 2986 follows_user_id = Column("follows_user_id", Integer(), ForeignKey('users.user_id'), nullable=True, unique=None, default=None)
2948 2987 follows_from = Column('follows_from', DateTime(timezone=False), nullable=True, unique=None, default=datetime.datetime.now)
2949 2988
2950 2989 user = relationship('User', primaryjoin='User.user_id==UserFollowing.user_id')
2951 2990
2952 2991 follows_user = relationship('User', primaryjoin='User.user_id==UserFollowing.follows_user_id')
2953 2992 follows_repository = relationship('Repository', order_by='Repository.repo_name')
2954 2993
2955 2994 @classmethod
2956 2995 def get_repo_followers(cls, repo_id):
2957 2996 return cls.query().filter(cls.follows_repo_id == repo_id)
2958 2997
2959 2998
2960 2999 class CacheKey(Base, BaseModel):
2961 3000 __tablename__ = 'cache_invalidation'
2962 3001 __table_args__ = (
2963 3002 UniqueConstraint('cache_key'),
2964 3003 Index('key_idx', 'cache_key'),
2965 3004 {'extend_existing': True, 'mysql_engine': 'InnoDB',
2966 3005 'mysql_charset': 'utf8', 'sqlite_autoincrement': True},
2967 3006 )
2968 3007 CACHE_TYPE_ATOM = 'ATOM'
2969 3008 CACHE_TYPE_RSS = 'RSS'
2970 3009 CACHE_TYPE_README = 'README'
2971 3010
2972 3011 cache_id = Column("cache_id", Integer(), nullable=False, unique=True, default=None, primary_key=True)
2973 3012 cache_key = Column("cache_key", String(255), nullable=True, unique=None, default=None)
2974 3013 cache_args = Column("cache_args", String(255), nullable=True, unique=None, default=None)
2975 3014 cache_active = Column("cache_active", Boolean(), nullable=True, unique=None, default=False)
2976 3015
2977 3016 def __init__(self, cache_key, cache_args=''):
2978 3017 self.cache_key = cache_key
2979 3018 self.cache_args = cache_args
2980 3019 self.cache_active = False
2981 3020
2982 3021 def __unicode__(self):
2983 3022 return u"<%s('%s:%s[%s]')>" % (
2984 3023 self.__class__.__name__,
2985 3024 self.cache_id, self.cache_key, self.cache_active)
2986 3025
2987 3026 def _cache_key_partition(self):
2988 3027 prefix, repo_name, suffix = self.cache_key.partition(self.cache_args)
2989 3028 return prefix, repo_name, suffix
2990 3029
2991 3030 def get_prefix(self):
2992 3031 """
2993 3032 Try to extract prefix from existing cache key. The key could consist
2994 3033 of prefix, repo_name, suffix
2995 3034 """
2996 3035 # this returns prefix, repo_name, suffix
2997 3036 return self._cache_key_partition()[0]
2998 3037
2999 3038 def get_suffix(self):
3000 3039 """
3001 3040 get suffix that might have been used in _get_cache_key to
3002 3041 generate self.cache_key. Only used for informational purposes
3003 3042 in repo_edit.mako.
3004 3043 """
3005 3044 # prefix, repo_name, suffix
3006 3045 return self._cache_key_partition()[2]
3007 3046
3008 3047 @classmethod
3009 3048 def delete_all_cache(cls):
3010 3049 """
3011 3050 Delete all cache keys from database.
3012 3051 Should only be run when all instances are down and all entries
3013 3052 thus stale.
3014 3053 """
3015 3054 cls.query().delete()
3016 3055 Session().commit()
3017 3056
3018 3057 @classmethod
3019 3058 def get_cache_key(cls, repo_name, cache_type):
3020 3059 """
3021 3060
3022 3061 Generate a cache key for this process of RhodeCode instance.
3023 3062 Prefix most likely will be process id or maybe explicitly set
3024 3063 instance_id from .ini file.
3025 3064 """
3026 3065 import rhodecode
3027 3066 prefix = safe_unicode(rhodecode.CONFIG.get('instance_id') or '')
3028 3067
3029 3068 repo_as_unicode = safe_unicode(repo_name)
3030 3069 key = u'{}_{}'.format(repo_as_unicode, cache_type) \
3031 3070 if cache_type else repo_as_unicode
3032 3071
3033 3072 return u'{}{}'.format(prefix, key)
3034 3073
3035 3074 @classmethod
3036 3075 def set_invalidate(cls, repo_name, delete=False):
3037 3076 """
3038 3077 Mark all caches of a repo as invalid in the database.
3039 3078 """
3040 3079
3041 3080 try:
3042 3081 qry = Session().query(cls).filter(cls.cache_args == repo_name)
3043 3082 if delete:
3044 3083 log.debug('cache objects deleted for repo %s',
3045 3084 safe_str(repo_name))
3046 3085 qry.delete()
3047 3086 else:
3048 3087 log.debug('cache objects marked as invalid for repo %s',
3049 3088 safe_str(repo_name))
3050 3089 qry.update({"cache_active": False})
3051 3090
3052 3091 Session().commit()
3053 3092 except Exception:
3054 3093 log.exception(
3055 3094 'Cache key invalidation failed for repository %s',
3056 3095 safe_str(repo_name))
3057 3096 Session().rollback()
3058 3097
3059 3098 @classmethod
3060 3099 def get_active_cache(cls, cache_key):
3061 3100 inv_obj = cls.query().filter(cls.cache_key == cache_key).scalar()
3062 3101 if inv_obj:
3063 3102 return inv_obj
3064 3103 return None
3065 3104
3066 3105 @classmethod
3067 3106 def repo_context_cache(cls, compute_func, repo_name, cache_type,
3068 3107 thread_scoped=False):
3069 3108 """
3070 3109 @cache_region('long_term')
3071 3110 def _heavy_calculation(cache_key):
3072 3111 return 'result'
3073 3112
3074 3113 cache_context = CacheKey.repo_context_cache(
3075 3114 _heavy_calculation, repo_name, cache_type)
3076 3115
3077 3116 with cache_context as context:
3078 3117 context.invalidate()
3079 3118 computed = context.compute()
3080 3119
3081 3120 assert computed == 'result'
3082 3121 """
3083 3122 from rhodecode.lib import caches
3084 3123 return caches.InvalidationContext(
3085 3124 compute_func, repo_name, cache_type, thread_scoped=thread_scoped)
3086 3125
3087 3126
3088 3127 class ChangesetComment(Base, BaseModel):
3089 3128 __tablename__ = 'changeset_comments'
3090 3129 __table_args__ = (
3091 3130 Index('cc_revision_idx', 'revision'),
3092 3131 {'extend_existing': True, 'mysql_engine': 'InnoDB',
3093 3132 'mysql_charset': 'utf8', 'sqlite_autoincrement': True},
3094 3133 )
3095 3134
3096 3135 COMMENT_OUTDATED = u'comment_outdated'
3097 3136 COMMENT_TYPE_NOTE = u'note'
3098 3137 COMMENT_TYPE_TODO = u'todo'
3099 3138 COMMENT_TYPES = [COMMENT_TYPE_NOTE, COMMENT_TYPE_TODO]
3100 3139
3101 3140 comment_id = Column('comment_id', Integer(), nullable=False, primary_key=True)
3102 3141 repo_id = Column('repo_id', Integer(), ForeignKey('repositories.repo_id'), nullable=False)
3103 3142 revision = Column('revision', String(40), nullable=True)
3104 3143 pull_request_id = Column("pull_request_id", Integer(), ForeignKey('pull_requests.pull_request_id'), nullable=True)
3105 3144 pull_request_version_id = Column("pull_request_version_id", Integer(), ForeignKey('pull_request_versions.pull_request_version_id'), nullable=True)
3106 3145 line_no = Column('line_no', Unicode(10), nullable=True)
3107 3146 hl_lines = Column('hl_lines', Unicode(512), nullable=True)
3108 3147 f_path = Column('f_path', Unicode(1000), nullable=True)
3109 3148 user_id = Column('user_id', Integer(), ForeignKey('users.user_id'), nullable=False)
3110 3149 text = Column('text', UnicodeText().with_variant(UnicodeText(25000), 'mysql'), nullable=False)
3111 3150 created_on = Column('created_on', DateTime(timezone=False), nullable=False, default=datetime.datetime.now)
3112 3151 modified_at = Column('modified_at', DateTime(timezone=False), nullable=False, default=datetime.datetime.now)
3113 3152 renderer = Column('renderer', Unicode(64), nullable=True)
3114 3153 display_state = Column('display_state', Unicode(128), nullable=True)
3115 3154
3116 3155 comment_type = Column('comment_type', Unicode(128), nullable=True, default=COMMENT_TYPE_NOTE)
3117 3156 resolved_comment_id = Column('resolved_comment_id', Integer(), ForeignKey('changeset_comments.comment_id'), nullable=True)
3118 3157 resolved_comment = relationship('ChangesetComment', remote_side=comment_id, backref='resolved_by')
3119 3158 author = relationship('User', lazy='joined')
3120 3159 repo = relationship('Repository')
3121 3160 status_change = relationship('ChangesetStatus', cascade="all, delete, delete-orphan", lazy='joined')
3122 3161 pull_request = relationship('PullRequest', lazy='joined')
3123 3162 pull_request_version = relationship('PullRequestVersion')
3124 3163
3125 3164 @classmethod
3126 3165 def get_users(cls, revision=None, pull_request_id=None):
3127 3166 """
3128 3167 Returns user associated with this ChangesetComment. ie those
3129 3168 who actually commented
3130 3169
3131 3170 :param cls:
3132 3171 :param revision:
3133 3172 """
3134 3173 q = Session().query(User)\
3135 3174 .join(ChangesetComment.author)
3136 3175 if revision:
3137 3176 q = q.filter(cls.revision == revision)
3138 3177 elif pull_request_id:
3139 3178 q = q.filter(cls.pull_request_id == pull_request_id)
3140 3179 return q.all()
3141 3180
3142 3181 @classmethod
3143 3182 def get_index_from_version(cls, pr_version, versions):
3144 3183 num_versions = [x.pull_request_version_id for x in versions]
3145 3184 try:
3146 3185 return num_versions.index(pr_version) +1
3147 3186 except (IndexError, ValueError):
3148 3187 return
3149 3188
3150 3189 @property
3151 3190 def outdated(self):
3152 3191 return self.display_state == self.COMMENT_OUTDATED
3153 3192
3154 3193 def outdated_at_version(self, version):
3155 3194 """
3156 3195 Checks if comment is outdated for given pull request version
3157 3196 """
3158 3197 return self.outdated and self.pull_request_version_id != version
3159 3198
3160 3199 def older_than_version(self, version):
3161 3200 """
3162 3201 Checks if comment is made from previous version than given
3163 3202 """
3164 3203 if version is None:
3165 3204 return self.pull_request_version_id is not None
3166 3205
3167 3206 return self.pull_request_version_id < version
3168 3207
3169 3208 @property
3170 3209 def resolved(self):
3171 3210 return self.resolved_by[0] if self.resolved_by else None
3172 3211
3173 3212 @property
3174 3213 def is_todo(self):
3175 3214 return self.comment_type == self.COMMENT_TYPE_TODO
3176 3215
3177 3216 @property
3178 3217 def is_inline(self):
3179 3218 return self.line_no and self.f_path
3180 3219
3181 3220 def get_index_version(self, versions):
3182 3221 return self.get_index_from_version(
3183 3222 self.pull_request_version_id, versions)
3184 3223
3185 3224 def __repr__(self):
3186 3225 if self.comment_id:
3187 3226 return '<DB:Comment #%s>' % self.comment_id
3188 3227 else:
3189 3228 return '<DB:Comment at %#x>' % id(self)
3190 3229
3191 3230 def get_api_data(self):
3192 3231 comment = self
3193 3232 data = {
3194 3233 'comment_id': comment.comment_id,
3195 3234 'comment_type': comment.comment_type,
3196 3235 'comment_text': comment.text,
3197 3236 'comment_status': comment.status_change,
3198 3237 'comment_f_path': comment.f_path,
3199 3238 'comment_lineno': comment.line_no,
3200 3239 'comment_author': comment.author,
3201 3240 'comment_created_on': comment.created_on
3202 3241 }
3203 3242 return data
3204 3243
3205 3244 def __json__(self):
3206 3245 data = dict()
3207 3246 data.update(self.get_api_data())
3208 3247 return data
3209 3248
3210 3249
3211 3250 class ChangesetStatus(Base, BaseModel):
3212 3251 __tablename__ = 'changeset_statuses'
3213 3252 __table_args__ = (
3214 3253 Index('cs_revision_idx', 'revision'),
3215 3254 Index('cs_version_idx', 'version'),
3216 3255 UniqueConstraint('repo_id', 'revision', 'version'),
3217 3256 {'extend_existing': True, 'mysql_engine': 'InnoDB',
3218 3257 'mysql_charset': 'utf8', 'sqlite_autoincrement': True}
3219 3258 )
3220 3259 STATUS_NOT_REVIEWED = DEFAULT = 'not_reviewed'
3221 3260 STATUS_APPROVED = 'approved'
3222 3261 STATUS_REJECTED = 'rejected'
3223 3262 STATUS_UNDER_REVIEW = 'under_review'
3224 3263
3225 3264 STATUSES = [
3226 3265 (STATUS_NOT_REVIEWED, _("Not Reviewed")), # (no icon) and default
3227 3266 (STATUS_APPROVED, _("Approved")),
3228 3267 (STATUS_REJECTED, _("Rejected")),
3229 3268 (STATUS_UNDER_REVIEW, _("Under Review")),
3230 3269 ]
3231 3270
3232 3271 changeset_status_id = Column('changeset_status_id', Integer(), nullable=False, primary_key=True)
3233 3272 repo_id = Column('repo_id', Integer(), ForeignKey('repositories.repo_id'), nullable=False)
3234 3273 user_id = Column("user_id", Integer(), ForeignKey('users.user_id'), nullable=False, unique=None)
3235 3274 revision = Column('revision', String(40), nullable=False)
3236 3275 status = Column('status', String(128), nullable=False, default=DEFAULT)
3237 3276 changeset_comment_id = Column('changeset_comment_id', Integer(), ForeignKey('changeset_comments.comment_id'))
3238 3277 modified_at = Column('modified_at', DateTime(), nullable=False, default=datetime.datetime.now)
3239 3278 version = Column('version', Integer(), nullable=False, default=0)
3240 3279 pull_request_id = Column("pull_request_id", Integer(), ForeignKey('pull_requests.pull_request_id'), nullable=True)
3241 3280
3242 3281 author = relationship('User', lazy='joined')
3243 3282 repo = relationship('Repository')
3244 3283 comment = relationship('ChangesetComment', lazy='joined')
3245 3284 pull_request = relationship('PullRequest', lazy='joined')
3246 3285
3247 3286 def __unicode__(self):
3248 3287 return u"<%s('%s[v%s]:%s')>" % (
3249 3288 self.__class__.__name__,
3250 3289 self.status, self.version, self.author
3251 3290 )
3252 3291
3253 3292 @classmethod
3254 3293 def get_status_lbl(cls, value):
3255 3294 return dict(cls.STATUSES).get(value)
3256 3295
3257 3296 @property
3258 3297 def status_lbl(self):
3259 3298 return ChangesetStatus.get_status_lbl(self.status)
3260 3299
3261 3300 def get_api_data(self):
3262 3301 status = self
3263 3302 data = {
3264 3303 'status_id': status.changeset_status_id,
3265 3304 'status': status.status,
3266 3305 }
3267 3306 return data
3268 3307
3269 3308 def __json__(self):
3270 3309 data = dict()
3271 3310 data.update(self.get_api_data())
3272 3311 return data
3273 3312
3274 3313
3275 3314 class _PullRequestBase(BaseModel):
3276 3315 """
3277 3316 Common attributes of pull request and version entries.
3278 3317 """
3279 3318
3280 3319 # .status values
3281 3320 STATUS_NEW = u'new'
3282 3321 STATUS_OPEN = u'open'
3283 3322 STATUS_CLOSED = u'closed'
3284 3323
3285 3324 title = Column('title', Unicode(255), nullable=True)
3286 3325 description = Column(
3287 3326 'description', UnicodeText().with_variant(UnicodeText(10240), 'mysql'),
3288 3327 nullable=True)
3289 3328 # new/open/closed status of pull request (not approve/reject/etc)
3290 3329 status = Column('status', Unicode(255), nullable=False, default=STATUS_NEW)
3291 3330 created_on = Column(
3292 3331 'created_on', DateTime(timezone=False), nullable=False,
3293 3332 default=datetime.datetime.now)
3294 3333 updated_on = Column(
3295 3334 'updated_on', DateTime(timezone=False), nullable=False,
3296 3335 default=datetime.datetime.now)
3297 3336
3298 3337 @declared_attr
3299 3338 def user_id(cls):
3300 3339 return Column(
3301 3340 "user_id", Integer(), ForeignKey('users.user_id'), nullable=False,
3302 3341 unique=None)
3303 3342
3304 3343 # 500 revisions max
3305 3344 _revisions = Column(
3306 3345 'revisions', UnicodeText().with_variant(UnicodeText(20500), 'mysql'))
3307 3346
3308 3347 @declared_attr
3309 3348 def source_repo_id(cls):
3310 3349 # TODO: dan: rename column to source_repo_id
3311 3350 return Column(
3312 3351 'org_repo_id', Integer(), ForeignKey('repositories.repo_id'),
3313 3352 nullable=False)
3314 3353
3315 3354 source_ref = Column('org_ref', Unicode(255), nullable=False)
3316 3355
3317 3356 @declared_attr
3318 3357 def target_repo_id(cls):
3319 3358 # TODO: dan: rename column to target_repo_id
3320 3359 return Column(
3321 3360 'other_repo_id', Integer(), ForeignKey('repositories.repo_id'),
3322 3361 nullable=False)
3323 3362
3324 3363 target_ref = Column('other_ref', Unicode(255), nullable=False)
3325 3364 _shadow_merge_ref = Column('shadow_merge_ref', Unicode(255), nullable=True)
3326 3365
3327 3366 # TODO: dan: rename column to last_merge_source_rev
3328 3367 _last_merge_source_rev = Column(
3329 3368 'last_merge_org_rev', String(40), nullable=True)
3330 3369 # TODO: dan: rename column to last_merge_target_rev
3331 3370 _last_merge_target_rev = Column(
3332 3371 'last_merge_other_rev', String(40), nullable=True)
3333 3372 _last_merge_status = Column('merge_status', Integer(), nullable=True)
3334 3373 merge_rev = Column('merge_rev', String(40), nullable=True)
3335 3374
3336 3375 reviewer_data = Column(
3337 3376 'reviewer_data_json', MutationObj.as_mutable(
3338 3377 JsonType(dialect_map=dict(mysql=UnicodeText(16384)))))
3339 3378
3340 3379 @property
3341 3380 def reviewer_data_json(self):
3342 3381 return json.dumps(self.reviewer_data)
3343 3382
3344 3383 @hybrid_property
3345 3384 def description_safe(self):
3346 3385 from rhodecode.lib import helpers as h
3347 3386 return h.escape(self.description)
3348 3387
3349 3388 @hybrid_property
3350 3389 def revisions(self):
3351 3390 return self._revisions.split(':') if self._revisions else []
3352 3391
3353 3392 @revisions.setter
3354 3393 def revisions(self, val):
3355 3394 self._revisions = ':'.join(val)
3356 3395
3357 3396 @hybrid_property
3358 3397 def last_merge_status(self):
3359 3398 return safe_int(self._last_merge_status)
3360 3399
3361 3400 @last_merge_status.setter
3362 3401 def last_merge_status(self, val):
3363 3402 self._last_merge_status = val
3364 3403
3365 3404 @declared_attr
3366 3405 def author(cls):
3367 3406 return relationship('User', lazy='joined')
3368 3407
3369 3408 @declared_attr
3370 3409 def source_repo(cls):
3371 3410 return relationship(
3372 3411 'Repository',
3373 3412 primaryjoin='%s.source_repo_id==Repository.repo_id' % cls.__name__)
3374 3413
3375 3414 @property
3376 3415 def source_ref_parts(self):
3377 3416 return self.unicode_to_reference(self.source_ref)
3378 3417
3379 3418 @declared_attr
3380 3419 def target_repo(cls):
3381 3420 return relationship(
3382 3421 'Repository',
3383 3422 primaryjoin='%s.target_repo_id==Repository.repo_id' % cls.__name__)
3384 3423
3385 3424 @property
3386 3425 def target_ref_parts(self):
3387 3426 return self.unicode_to_reference(self.target_ref)
3388 3427
3389 3428 @property
3390 3429 def shadow_merge_ref(self):
3391 3430 return self.unicode_to_reference(self._shadow_merge_ref)
3392 3431
3393 3432 @shadow_merge_ref.setter
3394 3433 def shadow_merge_ref(self, ref):
3395 3434 self._shadow_merge_ref = self.reference_to_unicode(ref)
3396 3435
3397 3436 def unicode_to_reference(self, raw):
3398 3437 """
3399 3438 Convert a unicode (or string) to a reference object.
3400 3439 If unicode evaluates to False it returns None.
3401 3440 """
3402 3441 if raw:
3403 3442 refs = raw.split(':')
3404 3443 return Reference(*refs)
3405 3444 else:
3406 3445 return None
3407 3446
3408 3447 def reference_to_unicode(self, ref):
3409 3448 """
3410 3449 Convert a reference object to unicode.
3411 3450 If reference is None it returns None.
3412 3451 """
3413 3452 if ref:
3414 3453 return u':'.join(ref)
3415 3454 else:
3416 3455 return None
3417 3456
3418 3457 def get_api_data(self, with_merge_state=True):
3419 3458 from rhodecode.model.pull_request import PullRequestModel
3420 3459
3421 3460 pull_request = self
3422 3461 if with_merge_state:
3423 3462 merge_status = PullRequestModel().merge_status(pull_request)
3424 3463 merge_state = {
3425 3464 'status': merge_status[0],
3426 3465 'message': safe_unicode(merge_status[1]),
3427 3466 }
3428 3467 else:
3429 3468 merge_state = {'status': 'not_available',
3430 3469 'message': 'not_available'}
3431 3470
3432 3471 merge_data = {
3433 3472 'clone_url': PullRequestModel().get_shadow_clone_url(pull_request),
3434 3473 'reference': (
3435 3474 pull_request.shadow_merge_ref._asdict()
3436 3475 if pull_request.shadow_merge_ref else None),
3437 3476 }
3438 3477
3439 3478 data = {
3440 3479 'pull_request_id': pull_request.pull_request_id,
3441 3480 'url': PullRequestModel().get_url(pull_request),
3442 3481 'title': pull_request.title,
3443 3482 'description': pull_request.description,
3444 3483 'status': pull_request.status,
3445 3484 'created_on': pull_request.created_on,
3446 3485 'updated_on': pull_request.updated_on,
3447 3486 'commit_ids': pull_request.revisions,
3448 3487 'review_status': pull_request.calculated_review_status(),
3449 3488 'mergeable': merge_state,
3450 3489 'source': {
3451 3490 'clone_url': pull_request.source_repo.clone_url(),
3452 3491 'repository': pull_request.source_repo.repo_name,
3453 3492 'reference': {
3454 3493 'name': pull_request.source_ref_parts.name,
3455 3494 'type': pull_request.source_ref_parts.type,
3456 3495 'commit_id': pull_request.source_ref_parts.commit_id,
3457 3496 },
3458 3497 },
3459 3498 'target': {
3460 3499 'clone_url': pull_request.target_repo.clone_url(),
3461 3500 'repository': pull_request.target_repo.repo_name,
3462 3501 'reference': {
3463 3502 'name': pull_request.target_ref_parts.name,
3464 3503 'type': pull_request.target_ref_parts.type,
3465 3504 'commit_id': pull_request.target_ref_parts.commit_id,
3466 3505 },
3467 3506 },
3468 3507 'merge': merge_data,
3469 3508 'author': pull_request.author.get_api_data(include_secrets=False,
3470 3509 details='basic'),
3471 3510 'reviewers': [
3472 3511 {
3473 3512 'user': reviewer.get_api_data(include_secrets=False,
3474 3513 details='basic'),
3475 3514 'reasons': reasons,
3476 3515 'review_status': st[0][1].status if st else 'not_reviewed',
3477 3516 }
3478 3517 for reviewer, reasons, mandatory, st in
3479 3518 pull_request.reviewers_statuses()
3480 3519 ]
3481 3520 }
3482 3521
3483 3522 return data
3484 3523
3485 3524
3486 3525 class PullRequest(Base, _PullRequestBase):
3487 3526 __tablename__ = 'pull_requests'
3488 3527 __table_args__ = (
3489 3528 {'extend_existing': True, 'mysql_engine': 'InnoDB',
3490 3529 'mysql_charset': 'utf8', 'sqlite_autoincrement': True},
3491 3530 )
3492 3531
3493 3532 pull_request_id = Column(
3494 3533 'pull_request_id', Integer(), nullable=False, primary_key=True)
3495 3534
3496 3535 def __repr__(self):
3497 3536 if self.pull_request_id:
3498 3537 return '<DB:PullRequest #%s>' % self.pull_request_id
3499 3538 else:
3500 3539 return '<DB:PullRequest at %#x>' % id(self)
3501 3540
3502 3541 reviewers = relationship('PullRequestReviewers',
3503 3542 cascade="all, delete, delete-orphan")
3504 3543 statuses = relationship('ChangesetStatus',
3505 3544 cascade="all, delete, delete-orphan")
3506 3545 comments = relationship('ChangesetComment',
3507 3546 cascade="all, delete, delete-orphan")
3508 3547 versions = relationship('PullRequestVersion',
3509 3548 cascade="all, delete, delete-orphan",
3510 3549 lazy='dynamic')
3511 3550
3512 3551 @classmethod
3513 3552 def get_pr_display_object(cls, pull_request_obj, org_pull_request_obj,
3514 3553 internal_methods=None):
3515 3554
3516 3555 class PullRequestDisplay(object):
3517 3556 """
3518 3557 Special object wrapper for showing PullRequest data via Versions
3519 3558 It mimics PR object as close as possible. This is read only object
3520 3559 just for display
3521 3560 """
3522 3561
3523 3562 def __init__(self, attrs, internal=None):
3524 3563 self.attrs = attrs
3525 3564 # internal have priority over the given ones via attrs
3526 3565 self.internal = internal or ['versions']
3527 3566
3528 3567 def __getattr__(self, item):
3529 3568 if item in self.internal:
3530 3569 return getattr(self, item)
3531 3570 try:
3532 3571 return self.attrs[item]
3533 3572 except KeyError:
3534 3573 raise AttributeError(
3535 3574 '%s object has no attribute %s' % (self, item))
3536 3575
3537 3576 def __repr__(self):
3538 3577 return '<DB:PullRequestDisplay #%s>' % self.attrs.get('pull_request_id')
3539 3578
3540 3579 def versions(self):
3541 3580 return pull_request_obj.versions.order_by(
3542 3581 PullRequestVersion.pull_request_version_id).all()
3543 3582
3544 3583 def is_closed(self):
3545 3584 return pull_request_obj.is_closed()
3546 3585
3547 3586 @property
3548 3587 def pull_request_version_id(self):
3549 3588 return getattr(pull_request_obj, 'pull_request_version_id', None)
3550 3589
3551 3590 attrs = StrictAttributeDict(pull_request_obj.get_api_data())
3552 3591
3553 3592 attrs.author = StrictAttributeDict(
3554 3593 pull_request_obj.author.get_api_data())
3555 3594 if pull_request_obj.target_repo:
3556 3595 attrs.target_repo = StrictAttributeDict(
3557 3596 pull_request_obj.target_repo.get_api_data())
3558 3597 attrs.target_repo.clone_url = pull_request_obj.target_repo.clone_url
3559 3598
3560 3599 if pull_request_obj.source_repo:
3561 3600 attrs.source_repo = StrictAttributeDict(
3562 3601 pull_request_obj.source_repo.get_api_data())
3563 3602 attrs.source_repo.clone_url = pull_request_obj.source_repo.clone_url
3564 3603
3565 3604 attrs.source_ref_parts = pull_request_obj.source_ref_parts
3566 3605 attrs.target_ref_parts = pull_request_obj.target_ref_parts
3567 3606 attrs.revisions = pull_request_obj.revisions
3568 3607
3569 3608 attrs.shadow_merge_ref = org_pull_request_obj.shadow_merge_ref
3570 3609 attrs.reviewer_data = org_pull_request_obj.reviewer_data
3571 3610 attrs.reviewer_data_json = org_pull_request_obj.reviewer_data_json
3572 3611
3573 3612 return PullRequestDisplay(attrs, internal=internal_methods)
3574 3613
3575 3614 def is_closed(self):
3576 3615 return self.status == self.STATUS_CLOSED
3577 3616
3578 3617 def __json__(self):
3579 3618 return {
3580 3619 'revisions': self.revisions,
3581 3620 }
3582 3621
3583 3622 def calculated_review_status(self):
3584 3623 from rhodecode.model.changeset_status import ChangesetStatusModel
3585 3624 return ChangesetStatusModel().calculated_review_status(self)
3586 3625
3587 3626 def reviewers_statuses(self):
3588 3627 from rhodecode.model.changeset_status import ChangesetStatusModel
3589 3628 return ChangesetStatusModel().reviewers_statuses(self)
3590 3629
3591 3630 @property
3592 3631 def workspace_id(self):
3593 3632 from rhodecode.model.pull_request import PullRequestModel
3594 3633 return PullRequestModel()._workspace_id(self)
3595 3634
3596 3635 def get_shadow_repo(self):
3597 3636 workspace_id = self.workspace_id
3598 3637 vcs_obj = self.target_repo.scm_instance()
3599 3638 shadow_repository_path = vcs_obj._get_shadow_repository_path(
3600 3639 workspace_id)
3601 3640 return vcs_obj._get_shadow_instance(shadow_repository_path)
3602 3641
3603 3642
3604 3643 class PullRequestVersion(Base, _PullRequestBase):
3605 3644 __tablename__ = 'pull_request_versions'
3606 3645 __table_args__ = (
3607 3646 {'extend_existing': True, 'mysql_engine': 'InnoDB',
3608 3647 'mysql_charset': 'utf8', 'sqlite_autoincrement': True},
3609 3648 )
3610 3649
3611 3650 pull_request_version_id = Column(
3612 3651 'pull_request_version_id', Integer(), nullable=False, primary_key=True)
3613 3652 pull_request_id = Column(
3614 3653 'pull_request_id', Integer(),
3615 3654 ForeignKey('pull_requests.pull_request_id'), nullable=False)
3616 3655 pull_request = relationship('PullRequest')
3617 3656
3618 3657 def __repr__(self):
3619 3658 if self.pull_request_version_id:
3620 3659 return '<DB:PullRequestVersion #%s>' % self.pull_request_version_id
3621 3660 else:
3622 3661 return '<DB:PullRequestVersion at %#x>' % id(self)
3623 3662
3624 3663 @property
3625 3664 def reviewers(self):
3626 3665 return self.pull_request.reviewers
3627 3666
3628 3667 @property
3629 3668 def versions(self):
3630 3669 return self.pull_request.versions
3631 3670
3632 3671 def is_closed(self):
3633 3672 # calculate from original
3634 3673 return self.pull_request.status == self.STATUS_CLOSED
3635 3674
3636 3675 def calculated_review_status(self):
3637 3676 return self.pull_request.calculated_review_status()
3638 3677
3639 3678 def reviewers_statuses(self):
3640 3679 return self.pull_request.reviewers_statuses()
3641 3680
3642 3681
3643 3682 class PullRequestReviewers(Base, BaseModel):
3644 3683 __tablename__ = 'pull_request_reviewers'
3645 3684 __table_args__ = (
3646 3685 {'extend_existing': True, 'mysql_engine': 'InnoDB',
3647 3686 'mysql_charset': 'utf8', 'sqlite_autoincrement': True},
3648 3687 )
3649 3688
3650 3689 @hybrid_property
3651 3690 def reasons(self):
3652 3691 if not self._reasons:
3653 3692 return []
3654 3693 return self._reasons
3655 3694
3656 3695 @reasons.setter
3657 3696 def reasons(self, val):
3658 3697 val = val or []
3659 3698 if any(not isinstance(x, basestring) for x in val):
3660 3699 raise Exception('invalid reasons type, must be list of strings')
3661 3700 self._reasons = val
3662 3701
3663 3702 pull_requests_reviewers_id = Column(
3664 3703 'pull_requests_reviewers_id', Integer(), nullable=False,
3665 3704 primary_key=True)
3666 3705 pull_request_id = Column(
3667 3706 "pull_request_id", Integer(),
3668 3707 ForeignKey('pull_requests.pull_request_id'), nullable=False)
3669 3708 user_id = Column(
3670 3709 "user_id", Integer(), ForeignKey('users.user_id'), nullable=True)
3671 3710 _reasons = Column(
3672 3711 'reason', MutationList.as_mutable(
3673 3712 JsonType('list', dialect_map=dict(mysql=UnicodeText(16384)))))
3674 3713 mandatory = Column("mandatory", Boolean(), nullable=False, default=False)
3675 3714 user = relationship('User')
3676 3715 pull_request = relationship('PullRequest')
3677 3716
3678 3717
3679 3718 class Notification(Base, BaseModel):
3680 3719 __tablename__ = 'notifications'
3681 3720 __table_args__ = (
3682 3721 Index('notification_type_idx', 'type'),
3683 3722 {'extend_existing': True, 'mysql_engine': 'InnoDB',
3684 3723 'mysql_charset': 'utf8', 'sqlite_autoincrement': True},
3685 3724 )
3686 3725
3687 3726 TYPE_CHANGESET_COMMENT = u'cs_comment'
3688 3727 TYPE_MESSAGE = u'message'
3689 3728 TYPE_MENTION = u'mention'
3690 3729 TYPE_REGISTRATION = u'registration'
3691 3730 TYPE_PULL_REQUEST = u'pull_request'
3692 3731 TYPE_PULL_REQUEST_COMMENT = u'pull_request_comment'
3693 3732
3694 3733 notification_id = Column('notification_id', Integer(), nullable=False, primary_key=True)
3695 3734 subject = Column('subject', Unicode(512), nullable=True)
3696 3735 body = Column('body', UnicodeText().with_variant(UnicodeText(50000), 'mysql'), nullable=True)
3697 3736 created_by = Column("created_by", Integer(), ForeignKey('users.user_id'), nullable=True)
3698 3737 created_on = Column('created_on', DateTime(timezone=False), nullable=False, default=datetime.datetime.now)
3699 3738 type_ = Column('type', Unicode(255))
3700 3739
3701 3740 created_by_user = relationship('User')
3702 3741 notifications_to_users = relationship('UserNotification', lazy='joined',
3703 3742 cascade="all, delete, delete-orphan")
3704 3743
3705 3744 @property
3706 3745 def recipients(self):
3707 3746 return [x.user for x in UserNotification.query()\
3708 3747 .filter(UserNotification.notification == self)\
3709 3748 .order_by(UserNotification.user_id.asc()).all()]
3710 3749
3711 3750 @classmethod
3712 3751 def create(cls, created_by, subject, body, recipients, type_=None):
3713 3752 if type_ is None:
3714 3753 type_ = Notification.TYPE_MESSAGE
3715 3754
3716 3755 notification = cls()
3717 3756 notification.created_by_user = created_by
3718 3757 notification.subject = subject
3719 3758 notification.body = body
3720 3759 notification.type_ = type_
3721 3760 notification.created_on = datetime.datetime.now()
3722 3761
3723 3762 for u in recipients:
3724 3763 assoc = UserNotification()
3725 3764 assoc.notification = notification
3726 3765
3727 3766 # if created_by is inside recipients mark his notification
3728 3767 # as read
3729 3768 if u.user_id == created_by.user_id:
3730 3769 assoc.read = True
3731 3770
3732 3771 u.notifications.append(assoc)
3733 3772 Session().add(notification)
3734 3773
3735 3774 return notification
3736 3775
3737 3776
3738 3777 class UserNotification(Base, BaseModel):
3739 3778 __tablename__ = 'user_to_notification'
3740 3779 __table_args__ = (
3741 3780 UniqueConstraint('user_id', 'notification_id'),
3742 3781 {'extend_existing': True, 'mysql_engine': 'InnoDB',
3743 3782 'mysql_charset': 'utf8', 'sqlite_autoincrement': True}
3744 3783 )
3745 3784 user_id = Column('user_id', Integer(), ForeignKey('users.user_id'), primary_key=True)
3746 3785 notification_id = Column("notification_id", Integer(), ForeignKey('notifications.notification_id'), primary_key=True)
3747 3786 read = Column('read', Boolean, default=False)
3748 3787 sent_on = Column('sent_on', DateTime(timezone=False), nullable=True, unique=None)
3749 3788
3750 3789 user = relationship('User', lazy="joined")
3751 3790 notification = relationship('Notification', lazy="joined",
3752 3791 order_by=lambda: Notification.created_on.desc(),)
3753 3792
3754 3793 def mark_as_read(self):
3755 3794 self.read = True
3756 3795 Session().add(self)
3757 3796
3758 3797
3759 3798 class Gist(Base, BaseModel):
3760 3799 __tablename__ = 'gists'
3761 3800 __table_args__ = (
3762 3801 Index('g_gist_access_id_idx', 'gist_access_id'),
3763 3802 Index('g_created_on_idx', 'created_on'),
3764 3803 {'extend_existing': True, 'mysql_engine': 'InnoDB',
3765 3804 'mysql_charset': 'utf8', 'sqlite_autoincrement': True}
3766 3805 )
3767 3806 GIST_PUBLIC = u'public'
3768 3807 GIST_PRIVATE = u'private'
3769 3808 DEFAULT_FILENAME = u'gistfile1.txt'
3770 3809
3771 3810 ACL_LEVEL_PUBLIC = u'acl_public'
3772 3811 ACL_LEVEL_PRIVATE = u'acl_private'
3773 3812
3774 3813 gist_id = Column('gist_id', Integer(), primary_key=True)
3775 3814 gist_access_id = Column('gist_access_id', Unicode(250))
3776 3815 gist_description = Column('gist_description', UnicodeText().with_variant(UnicodeText(1024), 'mysql'))
3777 3816 gist_owner = Column('user_id', Integer(), ForeignKey('users.user_id'), nullable=True)
3778 3817 gist_expires = Column('gist_expires', Float(53), nullable=False)
3779 3818 gist_type = Column('gist_type', Unicode(128), nullable=False)
3780 3819 created_on = Column('created_on', DateTime(timezone=False), nullable=False, default=datetime.datetime.now)
3781 3820 modified_at = Column('modified_at', DateTime(timezone=False), nullable=False, default=datetime.datetime.now)
3782 3821 acl_level = Column('acl_level', Unicode(128), nullable=True)
3783 3822
3784 3823 owner = relationship('User')
3785 3824
3786 3825 def __repr__(self):
3787 3826 return '<Gist:[%s]%s>' % (self.gist_type, self.gist_access_id)
3788 3827
3789 3828 @hybrid_property
3790 3829 def description_safe(self):
3791 3830 from rhodecode.lib import helpers as h
3792 3831 return h.escape(self.gist_description)
3793 3832
3794 3833 @classmethod
3795 3834 def get_or_404(cls, id_):
3796 3835 from pyramid.httpexceptions import HTTPNotFound
3797 3836
3798 3837 res = cls.query().filter(cls.gist_access_id == id_).scalar()
3799 3838 if not res:
3800 3839 raise HTTPNotFound()
3801 3840 return res
3802 3841
3803 3842 @classmethod
3804 3843 def get_by_access_id(cls, gist_access_id):
3805 3844 return cls.query().filter(cls.gist_access_id == gist_access_id).scalar()
3806 3845
3807 3846 def gist_url(self):
3808 3847 from rhodecode.model.gist import GistModel
3809 3848 return GistModel().get_url(self)
3810 3849
3811 3850 @classmethod
3812 3851 def base_path(cls):
3813 3852 """
3814 3853 Returns base path when all gists are stored
3815 3854
3816 3855 :param cls:
3817 3856 """
3818 3857 from rhodecode.model.gist import GIST_STORE_LOC
3819 3858 q = Session().query(RhodeCodeUi)\
3820 3859 .filter(RhodeCodeUi.ui_key == URL_SEP)
3821 3860 q = q.options(FromCache("sql_cache_short", "repository_repo_path"))
3822 3861 return os.path.join(q.one().ui_value, GIST_STORE_LOC)
3823 3862
3824 3863 def get_api_data(self):
3825 3864 """
3826 3865 Common function for generating gist related data for API
3827 3866 """
3828 3867 gist = self
3829 3868 data = {
3830 3869 'gist_id': gist.gist_id,
3831 3870 'type': gist.gist_type,
3832 3871 'access_id': gist.gist_access_id,
3833 3872 'description': gist.gist_description,
3834 3873 'url': gist.gist_url(),
3835 3874 'expires': gist.gist_expires,
3836 3875 'created_on': gist.created_on,
3837 3876 'modified_at': gist.modified_at,
3838 3877 'content': None,
3839 3878 'acl_level': gist.acl_level,
3840 3879 }
3841 3880 return data
3842 3881
3843 3882 def __json__(self):
3844 3883 data = dict(
3845 3884 )
3846 3885 data.update(self.get_api_data())
3847 3886 return data
3848 3887 # SCM functions
3849 3888
3850 3889 def scm_instance(self, **kwargs):
3851 3890 full_repo_path = os.path.join(self.base_path(), self.gist_access_id)
3852 3891 return get_vcs_instance(
3853 3892 repo_path=safe_str(full_repo_path), create=False)
3854 3893
3855 3894
3856 3895 class ExternalIdentity(Base, BaseModel):
3857 3896 __tablename__ = 'external_identities'
3858 3897 __table_args__ = (
3859 3898 Index('local_user_id_idx', 'local_user_id'),
3860 3899 Index('external_id_idx', 'external_id'),
3861 3900 {'extend_existing': True, 'mysql_engine': 'InnoDB',
3862 3901 'mysql_charset': 'utf8'})
3863 3902
3864 3903 external_id = Column('external_id', Unicode(255), default=u'',
3865 3904 primary_key=True)
3866 3905 external_username = Column('external_username', Unicode(1024), default=u'')
3867 3906 local_user_id = Column('local_user_id', Integer(),
3868 3907 ForeignKey('users.user_id'), primary_key=True)
3869 3908 provider_name = Column('provider_name', Unicode(255), default=u'',
3870 3909 primary_key=True)
3871 3910 access_token = Column('access_token', String(1024), default=u'')
3872 3911 alt_token = Column('alt_token', String(1024), default=u'')
3873 3912 token_secret = Column('token_secret', String(1024), default=u'')
3874 3913
3875 3914 @classmethod
3876 3915 def by_external_id_and_provider(cls, external_id, provider_name,
3877 3916 local_user_id=None):
3878 3917 """
3879 3918 Returns ExternalIdentity instance based on search params
3880 3919
3881 3920 :param external_id:
3882 3921 :param provider_name:
3883 3922 :return: ExternalIdentity
3884 3923 """
3885 3924 query = cls.query()
3886 3925 query = query.filter(cls.external_id == external_id)
3887 3926 query = query.filter(cls.provider_name == provider_name)
3888 3927 if local_user_id:
3889 3928 query = query.filter(cls.local_user_id == local_user_id)
3890 3929 return query.first()
3891 3930
3892 3931 @classmethod
3893 3932 def user_by_external_id_and_provider(cls, external_id, provider_name):
3894 3933 """
3895 3934 Returns User instance based on search params
3896 3935
3897 3936 :param external_id:
3898 3937 :param provider_name:
3899 3938 :return: User
3900 3939 """
3901 3940 query = User.query()
3902 3941 query = query.filter(cls.external_id == external_id)
3903 3942 query = query.filter(cls.provider_name == provider_name)
3904 3943 query = query.filter(User.user_id == cls.local_user_id)
3905 3944 return query.first()
3906 3945
3907 3946 @classmethod
3908 3947 def by_local_user_id(cls, local_user_id):
3909 3948 """
3910 3949 Returns all tokens for user
3911 3950
3912 3951 :param local_user_id:
3913 3952 :return: ExternalIdentity
3914 3953 """
3915 3954 query = cls.query()
3916 3955 query = query.filter(cls.local_user_id == local_user_id)
3917 3956 return query
3918 3957
3919 3958
3920 3959 class Integration(Base, BaseModel):
3921 3960 __tablename__ = 'integrations'
3922 3961 __table_args__ = (
3923 3962 {'extend_existing': True, 'mysql_engine': 'InnoDB',
3924 3963 'mysql_charset': 'utf8', 'sqlite_autoincrement': True}
3925 3964 )
3926 3965
3927 3966 integration_id = Column('integration_id', Integer(), primary_key=True)
3928 3967 integration_type = Column('integration_type', String(255))
3929 3968 enabled = Column('enabled', Boolean(), nullable=False)
3930 3969 name = Column('name', String(255), nullable=False)
3931 3970 child_repos_only = Column('child_repos_only', Boolean(), nullable=False,
3932 3971 default=False)
3933 3972
3934 3973 settings = Column(
3935 3974 'settings_json', MutationObj.as_mutable(
3936 3975 JsonType(dialect_map=dict(mysql=UnicodeText(16384)))))
3937 3976 repo_id = Column(
3938 3977 'repo_id', Integer(), ForeignKey('repositories.repo_id'),
3939 3978 nullable=True, unique=None, default=None)
3940 3979 repo = relationship('Repository', lazy='joined')
3941 3980
3942 3981 repo_group_id = Column(
3943 3982 'repo_group_id', Integer(), ForeignKey('groups.group_id'),
3944 3983 nullable=True, unique=None, default=None)
3945 3984 repo_group = relationship('RepoGroup', lazy='joined')
3946 3985
3947 3986 @property
3948 3987 def scope(self):
3949 3988 if self.repo:
3950 3989 return repr(self.repo)
3951 3990 if self.repo_group:
3952 3991 if self.child_repos_only:
3953 3992 return repr(self.repo_group) + ' (child repos only)'
3954 3993 else:
3955 3994 return repr(self.repo_group) + ' (recursive)'
3956 3995 if self.child_repos_only:
3957 3996 return 'root_repos'
3958 3997 return 'global'
3959 3998
3960 3999 def __repr__(self):
3961 4000 return '<Integration(%r, %r)>' % (self.integration_type, self.scope)
3962 4001
3963 4002
3964 4003 class RepoReviewRuleUser(Base, BaseModel):
3965 4004 __tablename__ = 'repo_review_rules_users'
3966 4005 __table_args__ = (
3967 4006 {'extend_existing': True, 'mysql_engine': 'InnoDB',
3968 4007 'mysql_charset': 'utf8', 'sqlite_autoincrement': True,}
3969 4008 )
3970 4009 repo_review_rule_user_id = Column('repo_review_rule_user_id', Integer(), primary_key=True)
3971 4010 repo_review_rule_id = Column("repo_review_rule_id", Integer(), ForeignKey('repo_review_rules.repo_review_rule_id'))
3972 4011 user_id = Column("user_id", Integer(), ForeignKey('users.user_id'), nullable=False)
3973 4012 mandatory = Column("mandatory", Boolean(), nullable=False, default=False)
3974 4013 user = relationship('User')
3975 4014
3976 4015 def rule_data(self):
3977 4016 return {
3978 4017 'mandatory': self.mandatory
3979 4018 }
3980 4019
3981 4020
3982 4021 class RepoReviewRuleUserGroup(Base, BaseModel):
3983 4022 __tablename__ = 'repo_review_rules_users_groups'
3984 4023 __table_args__ = (
3985 4024 {'extend_existing': True, 'mysql_engine': 'InnoDB',
3986 4025 'mysql_charset': 'utf8', 'sqlite_autoincrement': True,}
3987 4026 )
3988 4027 repo_review_rule_users_group_id = Column('repo_review_rule_users_group_id', Integer(), primary_key=True)
3989 4028 repo_review_rule_id = Column("repo_review_rule_id", Integer(), ForeignKey('repo_review_rules.repo_review_rule_id'))
3990 4029 users_group_id = Column("users_group_id", Integer(),ForeignKey('users_groups.users_group_id'), nullable=False)
3991 4030 mandatory = Column("mandatory", Boolean(), nullable=False, default=False)
3992 4031 users_group = relationship('UserGroup')
3993 4032
3994 4033 def rule_data(self):
3995 4034 return {
3996 4035 'mandatory': self.mandatory
3997 4036 }
3998 4037
3999 4038
4000 4039 class RepoReviewRule(Base, BaseModel):
4001 4040 __tablename__ = 'repo_review_rules'
4002 4041 __table_args__ = (
4003 4042 {'extend_existing': True, 'mysql_engine': 'InnoDB',
4004 4043 'mysql_charset': 'utf8', 'sqlite_autoincrement': True,}
4005 4044 )
4006 4045
4007 4046 repo_review_rule_id = Column(
4008 4047 'repo_review_rule_id', Integer(), primary_key=True)
4009 4048 repo_id = Column(
4010 4049 "repo_id", Integer(), ForeignKey('repositories.repo_id'))
4011 4050 repo = relationship('Repository', backref='review_rules')
4012 4051
4013 4052 _branch_pattern = Column("branch_pattern", UnicodeText().with_variant(UnicodeText(255), 'mysql'), default=u'*') # glob
4014 4053 _file_pattern = Column("file_pattern", UnicodeText().with_variant(UnicodeText(255), 'mysql'), default=u'*') # glob
4015 4054
4016 4055 use_authors_for_review = Column("use_authors_for_review", Boolean(), nullable=False, default=False)
4017 4056 forbid_author_to_review = Column("forbid_author_to_review", Boolean(), nullable=False, default=False)
4018 4057 forbid_commit_author_to_review = Column("forbid_commit_author_to_review", Boolean(), nullable=False, default=False)
4019 4058 forbid_adding_reviewers = Column("forbid_adding_reviewers", Boolean(), nullable=False, default=False)
4020 4059
4021 4060 rule_users = relationship('RepoReviewRuleUser')
4022 4061 rule_user_groups = relationship('RepoReviewRuleUserGroup')
4023 4062
4024 4063 @hybrid_property
4025 4064 def branch_pattern(self):
4026 4065 return self._branch_pattern or '*'
4027 4066
4028 4067 def _validate_glob(self, value):
4029 4068 re.compile('^' + glob2re(value) + '$')
4030 4069
4031 4070 @branch_pattern.setter
4032 4071 def branch_pattern(self, value):
4033 4072 self._validate_glob(value)
4034 4073 self._branch_pattern = value or '*'
4035 4074
4036 4075 @hybrid_property
4037 4076 def file_pattern(self):
4038 4077 return self._file_pattern or '*'
4039 4078
4040 4079 @file_pattern.setter
4041 4080 def file_pattern(self, value):
4042 4081 self._validate_glob(value)
4043 4082 self._file_pattern = value or '*'
4044 4083
4045 4084 def matches(self, branch, files_changed):
4046 4085 """
4047 4086 Check if this review rule matches a branch/files in a pull request
4048 4087
4049 4088 :param branch: branch name for the commit
4050 4089 :param files_changed: list of file paths changed in the pull request
4051 4090 """
4052 4091
4053 4092 branch = branch or ''
4054 4093 files_changed = files_changed or []
4055 4094
4056 4095 branch_matches = True
4057 4096 if branch:
4058 4097 branch_regex = re.compile('^' + glob2re(self.branch_pattern) + '$')
4059 4098 branch_matches = bool(branch_regex.search(branch))
4060 4099
4061 4100 files_matches = True
4062 4101 if self.file_pattern != '*':
4063 4102 files_matches = False
4064 4103 file_regex = re.compile(glob2re(self.file_pattern))
4065 4104 for filename in files_changed:
4066 4105 if file_regex.search(filename):
4067 4106 files_matches = True
4068 4107 break
4069 4108
4070 4109 return branch_matches and files_matches
4071 4110
4072 4111 @property
4073 4112 def review_users(self):
4074 4113 """ Returns the users which this rule applies to """
4075 4114
4076 4115 users = collections.OrderedDict()
4077 4116
4078 4117 for rule_user in self.rule_users:
4079 4118 if rule_user.user.active:
4080 4119 if rule_user.user not in users:
4081 4120 users[rule_user.user.username] = {
4082 4121 'user': rule_user.user,
4083 4122 'source': 'user',
4084 4123 'source_data': {},
4085 4124 'data': rule_user.rule_data()
4086 4125 }
4087 4126
4088 4127 for rule_user_group in self.rule_user_groups:
4089 4128 source_data = {
4090 4129 'name': rule_user_group.users_group.users_group_name,
4091 4130 'members': len(rule_user_group.users_group.members)
4092 4131 }
4093 4132 for member in rule_user_group.users_group.members:
4094 4133 if member.user.active:
4095 4134 users[member.user.username] = {
4096 4135 'user': member.user,
4097 4136 'source': 'user_group',
4098 4137 'source_data': source_data,
4099 4138 'data': rule_user_group.rule_data()
4100 4139 }
4101 4140
4102 4141 return users
4103 4142
4104 4143 def __repr__(self):
4105 4144 return '<RepoReviewerRule(id=%r, repo=%r)>' % (
4106 4145 self.repo_review_rule_id, self.repo)
4107 4146
4108 4147
4109 4148 class DbMigrateVersion(Base, BaseModel):
4110 4149 __tablename__ = 'db_migrate_version'
4111 4150 __table_args__ = (
4112 4151 {'extend_existing': True, 'mysql_engine': 'InnoDB',
4113 4152 'mysql_charset': 'utf8', 'sqlite_autoincrement': True},
4114 4153 )
4115 4154 repository_id = Column('repository_id', String(250), primary_key=True)
4116 4155 repository_path = Column('repository_path', Text)
4117 4156 version = Column('version', Integer)
4118 4157
4119 4158
4120 4159 class DbSession(Base, BaseModel):
4121 4160 __tablename__ = 'db_session'
4122 4161 __table_args__ = (
4123 4162 {'extend_existing': True, 'mysql_engine': 'InnoDB',
4124 4163 'mysql_charset': 'utf8', 'sqlite_autoincrement': True},
4125 4164 )
4126 4165
4127 4166 def __repr__(self):
4128 4167 return '<DB:DbSession({})>'.format(self.id)
4129 4168
4130 4169 id = Column('id', Integer())
4131 4170 namespace = Column('namespace', String(255), primary_key=True)
4132 4171 accessed = Column('accessed', DateTime, nullable=False)
4133 4172 created = Column('created', DateTime, nullable=False)
4134 4173 data = Column('data', PickleType, nullable=False)
@@ -1,226 +1,230 b''
1 1
2 2 /******************************************************************************
3 3 * *
4 4 * DO NOT CHANGE THIS FILE MANUALLY *
5 5 * *
6 6 * *
7 7 * This file is automatically generated when the app starts up with *
8 8 * generate_js_files = true *
9 9 * *
10 10 * To add a route here pass jsroute=True to the route definition in the app *
11 11 * *
12 12 ******************************************************************************/
13 13 function registerRCRoutes() {
14 14 // routes registration
15 15 pyroutes.register('new_repo', '/_admin/create_repository', []);
16 16 pyroutes.register('edit_user', '/_admin/users/%(user_id)s/edit', ['user_id']);
17 17 pyroutes.register('favicon', '/favicon.ico', []);
18 18 pyroutes.register('robots', '/robots.txt', []);
19 19 pyroutes.register('auth_home', '/_admin/auth*traverse', []);
20 20 pyroutes.register('global_integrations_new', '/_admin/integrations/new', []);
21 21 pyroutes.register('global_integrations_home', '/_admin/integrations', []);
22 22 pyroutes.register('global_integrations_list', '/_admin/integrations/%(integration)s', ['integration']);
23 23 pyroutes.register('global_integrations_create', '/_admin/integrations/%(integration)s/new', ['integration']);
24 24 pyroutes.register('global_integrations_edit', '/_admin/integrations/%(integration)s/%(integration_id)s', ['integration', 'integration_id']);
25 25 pyroutes.register('repo_group_integrations_home', '/%(repo_group_name)s/settings/integrations', ['repo_group_name']);
26 26 pyroutes.register('repo_group_integrations_new', '/%(repo_group_name)s/settings/integrations/new', ['repo_group_name']);
27 27 pyroutes.register('repo_group_integrations_list', '/%(repo_group_name)s/settings/integrations/%(integration)s', ['repo_group_name', 'integration']);
28 28 pyroutes.register('repo_group_integrations_create', '/%(repo_group_name)s/settings/integrations/%(integration)s/new', ['repo_group_name', 'integration']);
29 29 pyroutes.register('repo_group_integrations_edit', '/%(repo_group_name)s/settings/integrations/%(integration)s/%(integration_id)s', ['repo_group_name', 'integration', 'integration_id']);
30 30 pyroutes.register('repo_integrations_home', '/%(repo_name)s/settings/integrations', ['repo_name']);
31 31 pyroutes.register('repo_integrations_new', '/%(repo_name)s/settings/integrations/new', ['repo_name']);
32 32 pyroutes.register('repo_integrations_list', '/%(repo_name)s/settings/integrations/%(integration)s', ['repo_name', 'integration']);
33 33 pyroutes.register('repo_integrations_create', '/%(repo_name)s/settings/integrations/%(integration)s/new', ['repo_name', 'integration']);
34 34 pyroutes.register('repo_integrations_edit', '/%(repo_name)s/settings/integrations/%(integration)s/%(integration_id)s', ['repo_name', 'integration', 'integration_id']);
35 35 pyroutes.register('ops_ping', '/_admin/ops/ping', []);
36 36 pyroutes.register('ops_error_test', '/_admin/ops/error', []);
37 37 pyroutes.register('ops_redirect_test', '/_admin/ops/redirect', []);
38 38 pyroutes.register('admin_home', '/_admin', []);
39 39 pyroutes.register('admin_audit_logs', '/_admin/audit_logs', []);
40 40 pyroutes.register('pull_requests_global_0', '/_admin/pull_requests/%(pull_request_id)s', ['pull_request_id']);
41 41 pyroutes.register('pull_requests_global_1', '/_admin/pull-requests/%(pull_request_id)s', ['pull_request_id']);
42 42 pyroutes.register('pull_requests_global', '/_admin/pull-request/%(pull_request_id)s', ['pull_request_id']);
43 43 pyroutes.register('admin_settings_open_source', '/_admin/settings/open_source', []);
44 44 pyroutes.register('admin_settings_vcs_svn_generate_cfg', '/_admin/settings/vcs/svn_generate_cfg', []);
45 45 pyroutes.register('admin_settings_system', '/_admin/settings/system', []);
46 46 pyroutes.register('admin_settings_system_update', '/_admin/settings/system/updates', []);
47 47 pyroutes.register('admin_settings_sessions', '/_admin/settings/sessions', []);
48 48 pyroutes.register('admin_settings_sessions_cleanup', '/_admin/settings/sessions/cleanup', []);
49 49 pyroutes.register('admin_settings_process_management', '/_admin/settings/process_management', []);
50 50 pyroutes.register('admin_settings_process_management_signal', '/_admin/settings/process_management/signal', []);
51 51 pyroutes.register('admin_permissions_application', '/_admin/permissions/application', []);
52 52 pyroutes.register('admin_permissions_application_update', '/_admin/permissions/application/update', []);
53 53 pyroutes.register('admin_permissions_global', '/_admin/permissions/global', []);
54 54 pyroutes.register('admin_permissions_global_update', '/_admin/permissions/global/update', []);
55 55 pyroutes.register('admin_permissions_object', '/_admin/permissions/object', []);
56 56 pyroutes.register('admin_permissions_object_update', '/_admin/permissions/object/update', []);
57 57 pyroutes.register('admin_permissions_ips', '/_admin/permissions/ips', []);
58 58 pyroutes.register('admin_permissions_overview', '/_admin/permissions/overview', []);
59 59 pyroutes.register('admin_permissions_auth_token_access', '/_admin/permissions/auth_token_access', []);
60 60 pyroutes.register('users', '/_admin/users', []);
61 61 pyroutes.register('users_data', '/_admin/users_data', []);
62 62 pyroutes.register('edit_user_auth_tokens', '/_admin/users/%(user_id)s/edit/auth_tokens', ['user_id']);
63 63 pyroutes.register('edit_user_auth_tokens_add', '/_admin/users/%(user_id)s/edit/auth_tokens/new', ['user_id']);
64 64 pyroutes.register('edit_user_auth_tokens_delete', '/_admin/users/%(user_id)s/edit/auth_tokens/delete', ['user_id']);
65 pyroutes.register('edit_user_ssh_keys', '/_admin/users/%(user_id)s/edit/ssh_keys', ['user_id']);
66 pyroutes.register('edit_user_ssh_keys_generate_keypair', '/_admin/users/%(user_id)s/edit/ssh_keys/generate', ['user_id']);
67 pyroutes.register('edit_user_ssh_keys_add', '/_admin/users/%(user_id)s/edit/ssh_keys/new', ['user_id']);
68 pyroutes.register('edit_user_ssh_keys_delete', '/_admin/users/%(user_id)s/edit/ssh_keys/delete', ['user_id']);
65 69 pyroutes.register('edit_user_emails', '/_admin/users/%(user_id)s/edit/emails', ['user_id']);
66 70 pyroutes.register('edit_user_emails_add', '/_admin/users/%(user_id)s/edit/emails/new', ['user_id']);
67 71 pyroutes.register('edit_user_emails_delete', '/_admin/users/%(user_id)s/edit/emails/delete', ['user_id']);
68 72 pyroutes.register('edit_user_ips', '/_admin/users/%(user_id)s/edit/ips', ['user_id']);
69 73 pyroutes.register('edit_user_ips_add', '/_admin/users/%(user_id)s/edit/ips/new', ['user_id']);
70 74 pyroutes.register('edit_user_ips_delete', '/_admin/users/%(user_id)s/edit/ips/delete', ['user_id']);
71 75 pyroutes.register('edit_user_groups_management', '/_admin/users/%(user_id)s/edit/groups_management', ['user_id']);
72 76 pyroutes.register('edit_user_groups_management_updates', '/_admin/users/%(user_id)s/edit/edit_user_groups_management/updates', ['user_id']);
73 77 pyroutes.register('edit_user_audit_logs', '/_admin/users/%(user_id)s/edit/audit', ['user_id']);
74 78 pyroutes.register('user_groups', '/_admin/user_groups', []);
75 79 pyroutes.register('user_groups_data', '/_admin/user_groups_data', []);
76 80 pyroutes.register('user_group_members_data', '/_admin/user_groups/%(user_group_id)s/members', ['user_group_id']);
77 81 pyroutes.register('channelstream_connect', '/_admin/channelstream/connect', []);
78 82 pyroutes.register('channelstream_subscribe', '/_admin/channelstream/subscribe', []);
79 83 pyroutes.register('channelstream_proxy', '/_channelstream', []);
80 84 pyroutes.register('login', '/_admin/login', []);
81 85 pyroutes.register('logout', '/_admin/logout', []);
82 86 pyroutes.register('register', '/_admin/register', []);
83 87 pyroutes.register('reset_password', '/_admin/password_reset', []);
84 88 pyroutes.register('reset_password_confirmation', '/_admin/password_reset_confirmation', []);
85 89 pyroutes.register('home', '/', []);
86 90 pyroutes.register('user_autocomplete_data', '/_users', []);
87 91 pyroutes.register('user_group_autocomplete_data', '/_user_groups', []);
88 92 pyroutes.register('repo_list_data', '/_repos', []);
89 93 pyroutes.register('goto_switcher_data', '/_goto_data', []);
90 94 pyroutes.register('journal', '/_admin/journal', []);
91 95 pyroutes.register('journal_rss', '/_admin/journal/rss', []);
92 96 pyroutes.register('journal_atom', '/_admin/journal/atom', []);
93 97 pyroutes.register('journal_public', '/_admin/public_journal', []);
94 98 pyroutes.register('journal_public_atom', '/_admin/public_journal/atom', []);
95 99 pyroutes.register('journal_public_atom_old', '/_admin/public_journal_atom', []);
96 100 pyroutes.register('journal_public_rss', '/_admin/public_journal/rss', []);
97 101 pyroutes.register('journal_public_rss_old', '/_admin/public_journal_rss', []);
98 102 pyroutes.register('toggle_following', '/_admin/toggle_following', []);
99 103 pyroutes.register('repo_creating', '/%(repo_name)s/repo_creating', ['repo_name']);
100 104 pyroutes.register('repo_creating_check', '/%(repo_name)s/repo_creating_check', ['repo_name']);
101 105 pyroutes.register('repo_summary_explicit', '/%(repo_name)s/summary', ['repo_name']);
102 106 pyroutes.register('repo_summary_commits', '/%(repo_name)s/summary-commits', ['repo_name']);
103 107 pyroutes.register('repo_commit', '/%(repo_name)s/changeset/%(commit_id)s', ['repo_name', 'commit_id']);
104 108 pyroutes.register('repo_commit_children', '/%(repo_name)s/changeset_children/%(commit_id)s', ['repo_name', 'commit_id']);
105 109 pyroutes.register('repo_commit_parents', '/%(repo_name)s/changeset_parents/%(commit_id)s', ['repo_name', 'commit_id']);
106 110 pyroutes.register('repo_commit_raw', '/%(repo_name)s/changeset-diff/%(commit_id)s', ['repo_name', 'commit_id']);
107 111 pyroutes.register('repo_commit_patch', '/%(repo_name)s/changeset-patch/%(commit_id)s', ['repo_name', 'commit_id']);
108 112 pyroutes.register('repo_commit_download', '/%(repo_name)s/changeset-download/%(commit_id)s', ['repo_name', 'commit_id']);
109 113 pyroutes.register('repo_commit_data', '/%(repo_name)s/changeset-data/%(commit_id)s', ['repo_name', 'commit_id']);
110 114 pyroutes.register('repo_commit_comment_create', '/%(repo_name)s/changeset/%(commit_id)s/comment/create', ['repo_name', 'commit_id']);
111 115 pyroutes.register('repo_commit_comment_preview', '/%(repo_name)s/changeset/%(commit_id)s/comment/preview', ['repo_name', 'commit_id']);
112 116 pyroutes.register('repo_commit_comment_delete', '/%(repo_name)s/changeset/%(commit_id)s/comment/%(comment_id)s/delete', ['repo_name', 'commit_id', 'comment_id']);
113 117 pyroutes.register('repo_commit_raw_deprecated', '/%(repo_name)s/raw-changeset/%(commit_id)s', ['repo_name', 'commit_id']);
114 118 pyroutes.register('repo_archivefile', '/%(repo_name)s/archive/%(fname)s', ['repo_name', 'fname']);
115 119 pyroutes.register('repo_files_diff', '/%(repo_name)s/diff/%(f_path)s', ['repo_name', 'f_path']);
116 120 pyroutes.register('repo_files_diff_2way_redirect', '/%(repo_name)s/diff-2way/%(f_path)s', ['repo_name', 'f_path']);
117 121 pyroutes.register('repo_files', '/%(repo_name)s/files/%(commit_id)s/%(f_path)s', ['repo_name', 'commit_id', 'f_path']);
118 122 pyroutes.register('repo_files:default_path', '/%(repo_name)s/files/%(commit_id)s/', ['repo_name', 'commit_id']);
119 123 pyroutes.register('repo_files:default_commit', '/%(repo_name)s/files', ['repo_name']);
120 124 pyroutes.register('repo_files:rendered', '/%(repo_name)s/render/%(commit_id)s/%(f_path)s', ['repo_name', 'commit_id', 'f_path']);
121 125 pyroutes.register('repo_files:annotated', '/%(repo_name)s/annotate/%(commit_id)s/%(f_path)s', ['repo_name', 'commit_id', 'f_path']);
122 126 pyroutes.register('repo_files:annotated_previous', '/%(repo_name)s/annotate-previous/%(commit_id)s/%(f_path)s', ['repo_name', 'commit_id', 'f_path']);
123 127 pyroutes.register('repo_nodetree_full', '/%(repo_name)s/nodetree_full/%(commit_id)s/%(f_path)s', ['repo_name', 'commit_id', 'f_path']);
124 128 pyroutes.register('repo_nodetree_full:default_path', '/%(repo_name)s/nodetree_full/%(commit_id)s/', ['repo_name', 'commit_id']);
125 129 pyroutes.register('repo_files_nodelist', '/%(repo_name)s/nodelist/%(commit_id)s/%(f_path)s', ['repo_name', 'commit_id', 'f_path']);
126 130 pyroutes.register('repo_file_raw', '/%(repo_name)s/raw/%(commit_id)s/%(f_path)s', ['repo_name', 'commit_id', 'f_path']);
127 131 pyroutes.register('repo_file_download', '/%(repo_name)s/download/%(commit_id)s/%(f_path)s', ['repo_name', 'commit_id', 'f_path']);
128 132 pyroutes.register('repo_file_download:legacy', '/%(repo_name)s/rawfile/%(commit_id)s/%(f_path)s', ['repo_name', 'commit_id', 'f_path']);
129 133 pyroutes.register('repo_file_history', '/%(repo_name)s/history/%(commit_id)s/%(f_path)s', ['repo_name', 'commit_id', 'f_path']);
130 134 pyroutes.register('repo_file_authors', '/%(repo_name)s/authors/%(commit_id)s/%(f_path)s', ['repo_name', 'commit_id', 'f_path']);
131 135 pyroutes.register('repo_files_remove_file', '/%(repo_name)s/remove_file/%(commit_id)s/%(f_path)s', ['repo_name', 'commit_id', 'f_path']);
132 136 pyroutes.register('repo_files_delete_file', '/%(repo_name)s/delete_file/%(commit_id)s/%(f_path)s', ['repo_name', 'commit_id', 'f_path']);
133 137 pyroutes.register('repo_files_edit_file', '/%(repo_name)s/edit_file/%(commit_id)s/%(f_path)s', ['repo_name', 'commit_id', 'f_path']);
134 138 pyroutes.register('repo_files_update_file', '/%(repo_name)s/update_file/%(commit_id)s/%(f_path)s', ['repo_name', 'commit_id', 'f_path']);
135 139 pyroutes.register('repo_files_add_file', '/%(repo_name)s/add_file/%(commit_id)s/%(f_path)s', ['repo_name', 'commit_id', 'f_path']);
136 140 pyroutes.register('repo_files_create_file', '/%(repo_name)s/create_file/%(commit_id)s/%(f_path)s', ['repo_name', 'commit_id', 'f_path']);
137 141 pyroutes.register('repo_refs_data', '/%(repo_name)s/refs-data', ['repo_name']);
138 142 pyroutes.register('repo_refs_changelog_data', '/%(repo_name)s/refs-data-changelog', ['repo_name']);
139 143 pyroutes.register('repo_stats', '/%(repo_name)s/repo_stats/%(commit_id)s', ['repo_name', 'commit_id']);
140 144 pyroutes.register('repo_changelog', '/%(repo_name)s/changelog', ['repo_name']);
141 145 pyroutes.register('repo_changelog_file', '/%(repo_name)s/changelog/%(commit_id)s/%(f_path)s', ['repo_name', 'commit_id', 'f_path']);
142 146 pyroutes.register('repo_changelog_elements', '/%(repo_name)s/changelog_elements', ['repo_name']);
143 147 pyroutes.register('repo_compare_select', '/%(repo_name)s/compare', ['repo_name']);
144 148 pyroutes.register('repo_compare', '/%(repo_name)s/compare/%(source_ref_type)s@%(source_ref)s...%(target_ref_type)s@%(target_ref)s', ['repo_name', 'source_ref_type', 'source_ref', 'target_ref_type', 'target_ref']);
145 149 pyroutes.register('tags_home', '/%(repo_name)s/tags', ['repo_name']);
146 150 pyroutes.register('branches_home', '/%(repo_name)s/branches', ['repo_name']);
147 151 pyroutes.register('bookmarks_home', '/%(repo_name)s/bookmarks', ['repo_name']);
148 152 pyroutes.register('repo_fork_new', '/%(repo_name)s/fork', ['repo_name']);
149 153 pyroutes.register('repo_fork_create', '/%(repo_name)s/fork/create', ['repo_name']);
150 154 pyroutes.register('repo_forks_show_all', '/%(repo_name)s/forks', ['repo_name']);
151 155 pyroutes.register('repo_forks_data', '/%(repo_name)s/forks/data', ['repo_name']);
152 156 pyroutes.register('pullrequest_show', '/%(repo_name)s/pull-request/%(pull_request_id)s', ['repo_name', 'pull_request_id']);
153 157 pyroutes.register('pullrequest_show_all', '/%(repo_name)s/pull-request', ['repo_name']);
154 158 pyroutes.register('pullrequest_show_all_data', '/%(repo_name)s/pull-request-data', ['repo_name']);
155 159 pyroutes.register('pullrequest_repo_refs', '/%(repo_name)s/pull-request/refs/%(target_repo_name)s', ['repo_name', 'target_repo_name']);
156 160 pyroutes.register('pullrequest_repo_destinations', '/%(repo_name)s/pull-request/repo-destinations', ['repo_name']);
157 161 pyroutes.register('pullrequest_new', '/%(repo_name)s/pull-request/new', ['repo_name']);
158 162 pyroutes.register('pullrequest_create', '/%(repo_name)s/pull-request/create', ['repo_name']);
159 163 pyroutes.register('pullrequest_update', '/%(repo_name)s/pull-request/%(pull_request_id)s/update', ['repo_name', 'pull_request_id']);
160 164 pyroutes.register('pullrequest_merge', '/%(repo_name)s/pull-request/%(pull_request_id)s/merge', ['repo_name', 'pull_request_id']);
161 165 pyroutes.register('pullrequest_delete', '/%(repo_name)s/pull-request/%(pull_request_id)s/delete', ['repo_name', 'pull_request_id']);
162 166 pyroutes.register('pullrequest_comment_create', '/%(repo_name)s/pull-request/%(pull_request_id)s/comment', ['repo_name', 'pull_request_id']);
163 167 pyroutes.register('pullrequest_comment_delete', '/%(repo_name)s/pull-request/%(pull_request_id)s/comment/%(comment_id)s/delete', ['repo_name', 'pull_request_id', 'comment_id']);
164 168 pyroutes.register('edit_repo', '/%(repo_name)s/settings', ['repo_name']);
165 169 pyroutes.register('edit_repo_advanced', '/%(repo_name)s/settings/advanced', ['repo_name']);
166 170 pyroutes.register('edit_repo_advanced_delete', '/%(repo_name)s/settings/advanced/delete', ['repo_name']);
167 171 pyroutes.register('edit_repo_advanced_locking', '/%(repo_name)s/settings/advanced/locking', ['repo_name']);
168 172 pyroutes.register('edit_repo_advanced_journal', '/%(repo_name)s/settings/advanced/journal', ['repo_name']);
169 173 pyroutes.register('edit_repo_advanced_fork', '/%(repo_name)s/settings/advanced/fork', ['repo_name']);
170 174 pyroutes.register('edit_repo_caches', '/%(repo_name)s/settings/caches', ['repo_name']);
171 175 pyroutes.register('edit_repo_perms', '/%(repo_name)s/settings/permissions', ['repo_name']);
172 176 pyroutes.register('repo_reviewers', '/%(repo_name)s/settings/review/rules', ['repo_name']);
173 177 pyroutes.register('repo_default_reviewers_data', '/%(repo_name)s/settings/review/default-reviewers', ['repo_name']);
174 178 pyroutes.register('repo_maintenance', '/%(repo_name)s/settings/maintenance', ['repo_name']);
175 179 pyroutes.register('repo_maintenance_execute', '/%(repo_name)s/settings/maintenance/execute', ['repo_name']);
176 180 pyroutes.register('strip', '/%(repo_name)s/settings/strip', ['repo_name']);
177 181 pyroutes.register('strip_check', '/%(repo_name)s/settings/strip_check', ['repo_name']);
178 182 pyroutes.register('strip_execute', '/%(repo_name)s/settings/strip_execute', ['repo_name']);
179 183 pyroutes.register('rss_feed_home', '/%(repo_name)s/feed/rss', ['repo_name']);
180 184 pyroutes.register('atom_feed_home', '/%(repo_name)s/feed/atom', ['repo_name']);
181 185 pyroutes.register('repo_summary', '/%(repo_name)s', ['repo_name']);
182 186 pyroutes.register('repo_summary_slash', '/%(repo_name)s/', ['repo_name']);
183 187 pyroutes.register('repo_group_home', '/%(repo_group_name)s', ['repo_group_name']);
184 188 pyroutes.register('repo_group_home_slash', '/%(repo_group_name)s/', ['repo_group_name']);
185 189 pyroutes.register('search', '/_admin/search', []);
186 190 pyroutes.register('search_repo', '/%(repo_name)s/search', ['repo_name']);
187 191 pyroutes.register('user_profile', '/_profiles/%(username)s', ['username']);
188 192 pyroutes.register('my_account_profile', '/_admin/my_account/profile', []);
189 193 pyroutes.register('my_account_edit', '/_admin/my_account/edit', []);
190 194 pyroutes.register('my_account_update', '/_admin/my_account/update', []);
191 195 pyroutes.register('my_account_password', '/_admin/my_account/password', []);
192 196 pyroutes.register('my_account_password_update', '/_admin/my_account/password/update', []);
193 197 pyroutes.register('my_account_auth_tokens', '/_admin/my_account/auth_tokens', []);
194 198 pyroutes.register('my_account_auth_tokens_add', '/_admin/my_account/auth_tokens/new', []);
195 199 pyroutes.register('my_account_auth_tokens_delete', '/_admin/my_account/auth_tokens/delete', []);
196 200 pyroutes.register('my_account_emails', '/_admin/my_account/emails', []);
197 201 pyroutes.register('my_account_emails_add', '/_admin/my_account/emails/new', []);
198 202 pyroutes.register('my_account_emails_delete', '/_admin/my_account/emails/delete', []);
199 203 pyroutes.register('my_account_repos', '/_admin/my_account/repos', []);
200 204 pyroutes.register('my_account_watched', '/_admin/my_account/watched', []);
201 205 pyroutes.register('my_account_perms', '/_admin/my_account/perms', []);
202 206 pyroutes.register('my_account_notifications', '/_admin/my_account/notifications', []);
203 207 pyroutes.register('my_account_notifications_toggle_visibility', '/_admin/my_account/toggle_visibility', []);
204 208 pyroutes.register('my_account_pullrequests', '/_admin/my_account/pull_requests', []);
205 209 pyroutes.register('my_account_pullrequests_data', '/_admin/my_account/pull_requests/data', []);
206 210 pyroutes.register('notifications_show_all', '/_admin/notifications', []);
207 211 pyroutes.register('notifications_mark_all_read', '/_admin/notifications/mark_all_read', []);
208 212 pyroutes.register('notifications_show', '/_admin/notifications/%(notification_id)s', ['notification_id']);
209 213 pyroutes.register('notifications_update', '/_admin/notifications/%(notification_id)s/update', ['notification_id']);
210 214 pyroutes.register('notifications_delete', '/_admin/notifications/%(notification_id)s/delete', ['notification_id']);
211 215 pyroutes.register('my_account_notifications_test_channelstream', '/_admin/my_account/test_channelstream', []);
212 216 pyroutes.register('gists_show', '/_admin/gists', []);
213 217 pyroutes.register('gists_new', '/_admin/gists/new', []);
214 218 pyroutes.register('gists_create', '/_admin/gists/create', []);
215 219 pyroutes.register('gist_show', '/_admin/gists/%(gist_id)s', ['gist_id']);
216 220 pyroutes.register('gist_delete', '/_admin/gists/%(gist_id)s/delete', ['gist_id']);
217 221 pyroutes.register('gist_edit', '/_admin/gists/%(gist_id)s/edit', ['gist_id']);
218 222 pyroutes.register('gist_edit_check_revision', '/_admin/gists/%(gist_id)s/edit/check_revision', ['gist_id']);
219 223 pyroutes.register('gist_update', '/_admin/gists/%(gist_id)s/update', ['gist_id']);
220 224 pyroutes.register('gist_show_rev', '/_admin/gists/%(gist_id)s/%(revision)s', ['gist_id', 'revision']);
221 225 pyroutes.register('gist_show_formatted', '/_admin/gists/%(gist_id)s/%(revision)s/%(format)s', ['gist_id', 'revision', 'format']);
222 226 pyroutes.register('gist_show_formatted_path', '/_admin/gists/%(gist_id)s/%(revision)s/%(format)s/%(f_path)s', ['gist_id', 'revision', 'format', 'f_path']);
223 227 pyroutes.register('debug_style_home', '/_admin/debug_style', []);
224 228 pyroutes.register('debug_style_template', '/_admin/debug_style/t/%(t_path)s', ['t_path']);
225 229 pyroutes.register('apiv2', '/_admin/api', []);
226 230 }
@@ -1,56 +1,57 b''
1 1 ## -*- coding: utf-8 -*-
2 2 <%inherit file="/base/base.mako"/>
3 3
4 4 <%def name="title()">
5 5 ${_('%s user settings') % c.user.username}
6 6 %if c.rhodecode_name:
7 7 &middot; ${h.branding(c.rhodecode_name)}
8 8 %endif
9 9 </%def>
10 10
11 11 <%def name="breadcrumbs_links()">
12 12 ${h.link_to(_('Admin'),h.route_path('admin_home'))}
13 13 &raquo;
14 14 ${h.link_to(_('Users'),h.route_path('users'))}
15 15 &raquo;
16 16 % if c.user.active:
17 17 ${c.user.username}
18 18 % else:
19 19 <strike title="${_('This user is set as disabled')}">${c.user.username}</strike>
20 20 % endif
21 21
22 22 </%def>
23 23
24 24 <%def name="menu_bar_nav()">
25 25 ${self.menu_items(active='admin')}
26 26 </%def>
27 27
28 28 <%def name="main()">
29 29 <div class="box user_settings">
30 30 <div class="title">
31 31 ${self.breadcrumbs()}
32 32 </div>
33 33
34 34 ##main
35 35 <div class="sidebar-col-wrapper">
36 36 <div class="sidebar">
37 37 <ul class="nav nav-pills nav-stacked">
38 38 <li class="${'active' if c.active=='profile' else ''}"><a href="${h.url('edit_user', user_id=c.user.user_id)}">${_('User Profile')}</a></li>
39 39 <li class="${'active' if c.active=='auth_tokens' else ''}"><a href="${h.route_path('edit_user_auth_tokens', user_id=c.user.user_id)}">${_('Auth tokens')}</a></li>
40 <li class="${'active' if c.active in ['ssh_keys','ssh_keys_generate'] else ''}"><a href="${h.route_path('edit_user_ssh_keys', user_id=c.user.user_id)}">${_('SSH Keys')}</a></li>
40 41 <li class="${'active' if c.active=='advanced' else ''}"><a href="${h.url('edit_user_advanced', user_id=c.user.user_id)}">${_('Advanced')}</a></li>
41 42 <li class="${'active' if c.active=='global_perms' else ''}"><a href="${h.url('edit_user_global_perms', user_id=c.user.user_id)}">${_('Global permissions')}</a></li>
42 43 <li class="${'active' if c.active=='perms_summary' else ''}"><a href="${h.url('edit_user_perms_summary', user_id=c.user.user_id)}">${_('Permissions summary')}</a></li>
43 44 <li class="${'active' if c.active=='emails' else ''}"><a href="${h.route_path('edit_user_emails', user_id=c.user.user_id)}">${_('Emails')}</a></li>
44 45 <li class="${'active' if c.active=='ips' else ''}"><a href="${h.route_path('edit_user_ips', user_id=c.user.user_id)}">${_('Ip Whitelist')}</a></li>
45 46 <li class="${'active' if c.active=='groups' else ''}"><a href="${h.route_path('edit_user_groups_management', user_id=c.user.user_id)}">${_('User Groups Management')}</a></li>
46 47 <li class="${'active' if c.active=='audit' else ''}"><a href="${h.route_path('edit_user_audit_logs', user_id=c.user.user_id)}">${_('User audit')}</a></li>
47 48 </ul>
48 49 </div>
49 50
50 51 <div class="main-content-full-width">
51 52 <%include file="/admin/users/user_edit_${c.active}.mako"/>
52 53 </div>
53 54 </div>
54 55 </div>
55 56
56 57 </%def>
@@ -1,254 +1,255 b''
1 1 # -*- coding: utf-8 -*-
2 2
3 3 # Copyright (C) 2010-2017 RhodeCode GmbH
4 4 #
5 5 # This program is free software: you can redistribute it and/or modify
6 6 # it under the terms of the GNU Affero General Public License, version 3
7 7 # (only), as published by the Free Software Foundation.
8 8 #
9 9 # This program is distributed in the hope that it will be useful,
10 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 12 # GNU General Public License for more details.
13 13 #
14 14 # You should have received a copy of the GNU Affero General Public License
15 15 # along with this program. If not, see <http://www.gnu.org/licenses/>.
16 16 #
17 17 # This program is dual-licensed. If you wish to learn more about the
18 18 # RhodeCode Enterprise Edition, including its added features, Support services,
19 19 # and proprietary license terms, please see https://rhodecode.com/licenses/
20 20
21 21 # Import early to make sure things are patched up properly
22 22 from setuptools import setup, find_packages
23 23
24 24 import os
25 25 import sys
26 26 import pkgutil
27 27 import platform
28 28
29 29 from pip.download import PipSession
30 30 from pip.req import parse_requirements
31 31
32 32 from codecs import open
33 33
34 34
35 35 if sys.version_info < (2, 7):
36 36 raise Exception('RhodeCode requires Python 2.7 or later')
37 37
38 38 here = os.path.abspath(os.path.dirname(__file__))
39 39
40 40 # defines current platform
41 41 __platform__ = platform.system()
42 42 __license__ = 'AGPLv3, and Commercial License'
43 43 __author__ = 'RhodeCode GmbH'
44 44 __url__ = 'https://code.rhodecode.com'
45 45 is_windows = __platform__ in ('Windows',)
46 46
47 47
48 48 def _get_requirements(req_filename, exclude=None, extras=None):
49 49 extras = extras or []
50 50 exclude = exclude or []
51 51
52 52 try:
53 53 parsed = parse_requirements(
54 54 os.path.join(here, req_filename), session=PipSession())
55 55 except TypeError:
56 56 # try pip < 6.0.0, that doesn't support session
57 57 parsed = parse_requirements(os.path.join(here, req_filename))
58 58
59 59 requirements = []
60 60 for ir in parsed:
61 61 if ir.req and ir.name not in exclude:
62 62 requirements.append(str(ir.req))
63 63 return requirements + extras
64 64
65 65
66 66 # requirements extract
67 67 setup_requirements = ['PasteScript', 'pytest-runner']
68 68 install_requirements = _get_requirements(
69 69 'requirements.txt', exclude=['setuptools'])
70 70 test_requirements = _get_requirements(
71 71 'requirements_test.txt', extras=['configobj'])
72 72
73 73 install_requirements = [
74 74 'Babel',
75 75 'Beaker',
76 76 'FormEncode',
77 77 'Mako',
78 78 'Markdown',
79 79 'MarkupSafe',
80 80 'MySQL-python',
81 81 'Paste',
82 82 'PasteDeploy',
83 83 'PasteScript',
84 84 'Pygments',
85 85 'pygments-markdown-lexer',
86 86 'Pylons',
87 87 'Routes',
88 88 'SQLAlchemy',
89 89 'Tempita',
90 90 'URLObject',
91 91 'WebError',
92 92 'WebHelpers',
93 93 'WebHelpers2',
94 94 'WebOb',
95 95 'WebTest',
96 96 'Whoosh',
97 97 'alembic',
98 98 'amqplib',
99 99 'anyjson',
100 100 'appenlight-client',
101 101 'authomatic',
102 102 'cssselect',
103 103 'celery',
104 104 'channelstream',
105 105 'colander',
106 106 'decorator',
107 107 'deform',
108 108 'docutils',
109 109 'gevent',
110 110 'gunicorn',
111 111 'infrae.cache',
112 112 'ipython',
113 113 'iso8601',
114 114 'kombu',
115 115 'lxml',
116 116 'msgpack-python',
117 117 'nbconvert',
118 118 'packaging',
119 119 'psycopg2',
120 120 'py-gfm',
121 121 'pycrypto',
122 122 'pycurl',
123 123 'pyparsing',
124 124 'pyramid',
125 125 'pyramid-debugtoolbar',
126 126 'pyramid-mako',
127 127 'pyramid-beaker',
128 128 'pysqlite',
129 129 'python-dateutil',
130 130 'python-ldap',
131 131 'python-memcached',
132 132 'python-pam',
133 133 'recaptcha-client',
134 134 'repoze.lru',
135 135 'requests',
136 136 'simplejson',
137 'sshpubkeys',
137 138 'subprocess32',
138 139 'waitress',
139 140 'zope.cachedescriptors',
140 141 'dogpile.cache',
141 142 'dogpile.core',
142 143 'psutil',
143 144 'py-bcrypt',
144 145 ]
145 146
146 147
147 148 def get_version():
148 149 version = pkgutil.get_data('rhodecode', 'VERSION')
149 150 return version.strip()
150 151
151 152
152 153 # additional files that goes into package itself
153 154 package_data = {
154 155 '': ['*.txt', '*.rst'],
155 156 'configs': ['*.ini'],
156 157 'rhodecode': ['VERSION', 'i18n/*/LC_MESSAGES/*.mo', ],
157 158 }
158 159
159 160 description = 'Source Code Management Platform'
160 161 keywords = ' '.join([
161 162 'rhodecode', 'mercurial', 'git', 'svn',
162 163 'code review',
163 164 'repo groups', 'ldap', 'repository management', 'hgweb',
164 165 'hgwebdir', 'gitweb', 'serving hgweb',
165 166 ])
166 167
167 168
168 169 # README/DESCRIPTION generation
169 170 readme_file = 'README.rst'
170 171 changelog_file = 'CHANGES.rst'
171 172 try:
172 173 long_description = open(readme_file).read() + '\n\n' + \
173 174 open(changelog_file).read()
174 175 except IOError as err:
175 176 sys.stderr.write(
176 177 "[WARNING] Cannot find file specified as long_description (%s)\n "
177 178 "or changelog (%s) skipping that file" % (readme_file, changelog_file))
178 179 long_description = description
179 180
180 181
181 182 setup(
182 183 name='rhodecode-enterprise-ce',
183 184 version=get_version(),
184 185 description=description,
185 186 long_description=long_description,
186 187 keywords=keywords,
187 188 license=__license__,
188 189 author=__author__,
189 190 author_email='marcin@rhodecode.com',
190 191 url=__url__,
191 192 setup_requires=setup_requirements,
192 193 install_requires=install_requirements,
193 194 tests_require=test_requirements,
194 195 zip_safe=False,
195 196 packages=find_packages(exclude=["docs", "tests*"]),
196 197 package_data=package_data,
197 198 include_package_data=True,
198 199 classifiers=[
199 200 'Development Status :: 6 - Mature',
200 201 'Environment :: Web Environment',
201 202 'Intended Audience :: Developers',
202 203 'Operating System :: OS Independent',
203 204 'Topic :: Software Development :: Version Control',
204 205 'License :: OSI Approved :: Affero GNU General Public License v3 or later (AGPLv3+)',
205 206 'Programming Language :: Python :: 2.7',
206 207 ],
207 208 message_extractors={
208 209 'rhodecode': [
209 210 ('**.py', 'python', None),
210 211 ('**.js', 'javascript', None),
211 212 ('templates/**.mako', 'mako', {'input_encoding': 'utf-8'}),
212 213 ('templates/**.html', 'mako', {'input_encoding': 'utf-8'}),
213 214 ('public/**', 'ignore', None),
214 215 ]
215 216 },
216 217 paster_plugins=['PasteScript', 'Pylons'],
217 218 entry_points={
218 219 'enterprise.plugins1': [
219 220 'crowd=rhodecode.authentication.plugins.auth_crowd:plugin_factory',
220 221 'headers=rhodecode.authentication.plugins.auth_headers:plugin_factory',
221 222 'jasig_cas=rhodecode.authentication.plugins.auth_jasig_cas:plugin_factory',
222 223 'ldap=rhodecode.authentication.plugins.auth_ldap:plugin_factory',
223 224 'pam=rhodecode.authentication.plugins.auth_pam:plugin_factory',
224 225 'rhodecode=rhodecode.authentication.plugins.auth_rhodecode:plugin_factory',
225 226 'token=rhodecode.authentication.plugins.auth_token:plugin_factory',
226 227 ],
227 228 'paste.app_factory': [
228 229 'main=rhodecode.config.middleware:make_pyramid_app',
229 230 'pylons=rhodecode.config.middleware:make_app',
230 231 ],
231 232 'paste.app_install': [
232 233 'main=pylons.util:PylonsInstaller',
233 234 'pylons=pylons.util:PylonsInstaller',
234 235 ],
235 236 'paste.global_paster_command': [
236 237 'make-config=rhodecode.lib.paster_commands.make_config:Command',
237 238 'setup-rhodecode=rhodecode.lib.paster_commands.setup_rhodecode:Command',
238 239 'ishell=rhodecode.lib.paster_commands.ishell:Command',
239 240 'upgrade-db=rhodecode.lib.dbmigrate:UpgradeDb',
240 241 'celeryd=rhodecode.lib.celerypylons.commands:CeleryDaemonCommand',
241 242 ],
242 243 'pytest11': [
243 244 'pylons=rhodecode.tests.pylons_plugin',
244 245 'enterprise=rhodecode.tests.plugin',
245 246 ],
246 247 'console_scripts': [
247 248 'rcserver=rhodecode.rcserver:main',
248 249 ],
249 250 'beaker.backends': [
250 251 'memorylru_base=rhodecode.lib.memory_lru_debug:MemoryLRUNamespaceManagerBase',
251 252 'memorylru_debug=rhodecode.lib.memory_lru_debug:MemoryLRUNamespaceManagerDebug'
252 253 ]
253 254 },
254 255 )
General Comments 0
You need to be logged in to leave comments. Login now