annotate rhodecode/model/db.py @ 1381:a1ab3e9c7e82 beta

fixes #204, ldap active checkbox, credits goes to Matt Little.
author Marcin Kuzminski <marcin@python-works.com>
date Mon, 13 Jun 2011 18:04:42 +0200
parents 3fbc09ad1faf
children 7e221629a3e5
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
759
a7f50911a945 Models code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 734
diff changeset
1 # -*- coding: utf-8 -*-
a7f50911a945 Models code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 734
diff changeset
2 """
832
634596f81cfd new improved models with helper functions for easier data fetching
Marcin Kuzminski <marcin@python-works.com>
parents: 810
diff changeset
3 rhodecode.model.db
634596f81cfd new improved models with helper functions for easier data fetching
Marcin Kuzminski <marcin@python-works.com>
parents: 810
diff changeset
4 ~~~~~~~~~~~~~~~~~~
1203
6832ef664673 source code cleanup: remove trailing white space, normalize file endings
Marcin Kuzminski <marcin@python-works.com>
parents: 1199
diff changeset
5
834
8924ed0e4f36 added current db version into rhodecode,
Marcin Kuzminski <marcin@python-works.com>
parents: 832
diff changeset
6 Database Models for RhodeCode
1203
6832ef664673 source code cleanup: remove trailing white space, normalize file endings
Marcin Kuzminski <marcin@python-works.com>
parents: 1199
diff changeset
7
759
a7f50911a945 Models code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 734
diff changeset
8 :created_on: Apr 08, 2010
a7f50911a945 Models code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 734
diff changeset
9 :author: marcink
1203
6832ef664673 source code cleanup: remove trailing white space, normalize file endings
Marcin Kuzminski <marcin@python-works.com>
parents: 1199
diff changeset
10 :copyright: (C) 2009-2011 Marcin Kuzminski <marcin@python-works.com>
759
a7f50911a945 Models code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 734
diff changeset
11 :license: GPLv3, see COPYING for more details.
a7f50911a945 Models code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 734
diff changeset
12 """
1206
a671db5bdd58 fixed license issue #149
Marcin Kuzminski <marcin@python-works.com>
parents: 1203
diff changeset
13 # This program is free software: you can redistribute it and/or modify
a671db5bdd58 fixed license issue #149
Marcin Kuzminski <marcin@python-works.com>
parents: 1203
diff changeset
14 # it under the terms of the GNU General Public License as published by
a671db5bdd58 fixed license issue #149
Marcin Kuzminski <marcin@python-works.com>
parents: 1203
diff changeset
15 # the Free Software Foundation, either version 3 of the License, or
a671db5bdd58 fixed license issue #149
Marcin Kuzminski <marcin@python-works.com>
parents: 1203
diff changeset
16 # (at your option) any later version.
1203
6832ef664673 source code cleanup: remove trailing white space, normalize file endings
Marcin Kuzminski <marcin@python-works.com>
parents: 1199
diff changeset
17 #
759
a7f50911a945 Models code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 734
diff changeset
18 # This program is distributed in the hope that it will be useful,
a7f50911a945 Models code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 734
diff changeset
19 # but WITHOUT ANY WARRANTY; without even the implied warranty of
a7f50911a945 Models code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 734
diff changeset
20 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
a7f50911a945 Models code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 734
diff changeset
21 # GNU General Public License for more details.
1203
6832ef664673 source code cleanup: remove trailing white space, normalize file endings
Marcin Kuzminski <marcin@python-works.com>
parents: 1199
diff changeset
22 #
759
a7f50911a945 Models code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 734
diff changeset
23 # You should have received a copy of the GNU General Public License
1206
a671db5bdd58 fixed license issue #149
Marcin Kuzminski <marcin@python-works.com>
parents: 1203
diff changeset
24 # along with this program. If not, see <http://www.gnu.org/licenses/>.
1199
268fa0b6b2ef Added os.sep in models for better win support
Marcin Kuzminski <marcin@python-works.com>
parents: 1193
diff changeset
25
268fa0b6b2ef Added os.sep in models for better win support
Marcin Kuzminski <marcin@python-works.com>
parents: 1193
diff changeset
26 import os
759
a7f50911a945 Models code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 734
diff changeset
27 import logging
a7f50911a945 Models code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 734
diff changeset
28 import datetime
1366
9c0f5d558789 fixes #200, rewrote the whole caching mechanism to get rid of such problems. Now cached instances are attached
Marcin Kuzminski <marcin@python-works.com>
parents: 1360
diff changeset
29 import traceback
994
7f9d23f6a526 Added grouping by days in journal
Marcin Kuzminski <marcin@python-works.com>
parents: 991
diff changeset
30 from datetime import date
759
a7f50911a945 Models code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 734
diff changeset
31
658
4ecb2ffcc110 fixed imports
Marcin Kuzminski <marcin@python-works.com>
parents: 657
diff changeset
32 from sqlalchemy import *
759
a7f50911a945 Models code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 734
diff changeset
33 from sqlalchemy.exc import DatabaseError
1366
9c0f5d558789 fixes #200, rewrote the whole caching mechanism to get rid of such problems. Now cached instances are attached
Marcin Kuzminski <marcin@python-works.com>
parents: 1360
diff changeset
34 from sqlalchemy.orm import relationship, backref, joinedload
1081
70bf0be59653 fixed Session problems in model class functions
Marcin Kuzminski <marcin@python-works.com>
parents: 1065
diff changeset
35 from sqlalchemy.orm.interfaces import MapperExtension
759
a7f50911a945 Models code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 734
diff changeset
36
1366
9c0f5d558789 fixes #200, rewrote the whole caching mechanism to get rid of such problems. Now cached instances are attached
Marcin Kuzminski <marcin@python-works.com>
parents: 1360
diff changeset
37 from beaker.cache import cache_region, region_invalidate
9c0f5d558789 fixes #200, rewrote the whole caching mechanism to get rid of such problems. Now cached instances are attached
Marcin Kuzminski <marcin@python-works.com>
parents: 1360
diff changeset
38
9c0f5d558789 fixes #200, rewrote the whole caching mechanism to get rid of such problems. Now cached instances are attached
Marcin Kuzminski <marcin@python-works.com>
parents: 1360
diff changeset
39 from vcs import get_backend
9c0f5d558789 fixes #200, rewrote the whole caching mechanism to get rid of such problems. Now cached instances are attached
Marcin Kuzminski <marcin@python-works.com>
parents: 1360
diff changeset
40 from vcs.utils.helpers import get_scm
9c0f5d558789 fixes #200, rewrote the whole caching mechanism to get rid of such problems. Now cached instances are attached
Marcin Kuzminski <marcin@python-works.com>
parents: 1360
diff changeset
41 from vcs.exceptions import RepositoryError, VCSError
9c0f5d558789 fixes #200, rewrote the whole caching mechanism to get rid of such problems. Now cached instances are attached
Marcin Kuzminski <marcin@python-works.com>
parents: 1360
diff changeset
42 from vcs.utils.lazy import LazyProperty
9c0f5d558789 fixes #200, rewrote the whole caching mechanism to get rid of such problems. Now cached instances are attached
Marcin Kuzminski <marcin@python-works.com>
parents: 1360
diff changeset
43 from vcs.nodes import FileNode
9c0f5d558789 fixes #200, rewrote the whole caching mechanism to get rid of such problems. Now cached instances are attached
Marcin Kuzminski <marcin@python-works.com>
parents: 1360
diff changeset
44
1266
a1bcfe58a1ab Fixed #161 form saves the create repository permission.
Marcin Kuzminski <marcin@python-works.com>
parents: 1206
diff changeset
45 from rhodecode.lib import str2bool
1081
70bf0be59653 fixed Session problems in model class functions
Marcin Kuzminski <marcin@python-works.com>
parents: 1065
diff changeset
46 from rhodecode.model.meta import Base, Session
1266
a1bcfe58a1ab Fixed #161 form saves the create repository permission.
Marcin Kuzminski <marcin@python-works.com>
parents: 1206
diff changeset
47 from rhodecode.model.caching_query import FromCache
759
a7f50911a945 Models code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 734
diff changeset
48
442
d66a7fa7689b moved loged in user propagation out of forms,
Marcin Kuzminski <marcin@python-works.com>
parents: 417
diff changeset
49 log = logging.getLogger(__name__)
49
3ada2f409c1c Added sqlalchemy support
Marcin Kuzminski <marcin@python-blog.com>
parents:
diff changeset
50
1081
70bf0be59653 fixed Session problems in model class functions
Marcin Kuzminski <marcin@python-works.com>
parents: 1065
diff changeset
51 #==============================================================================
70bf0be59653 fixed Session problems in model class functions
Marcin Kuzminski <marcin@python-works.com>
parents: 1065
diff changeset
52 # MAPPER EXTENSIONS
70bf0be59653 fixed Session problems in model class functions
Marcin Kuzminski <marcin@python-works.com>
parents: 1065
diff changeset
53 #==============================================================================
70bf0be59653 fixed Session problems in model class functions
Marcin Kuzminski <marcin@python-works.com>
parents: 1065
diff changeset
54
70bf0be59653 fixed Session problems in model class functions
Marcin Kuzminski <marcin@python-works.com>
parents: 1065
diff changeset
55 class RepositoryMapper(MapperExtension):
70bf0be59653 fixed Session problems in model class functions
Marcin Kuzminski <marcin@python-works.com>
parents: 1065
diff changeset
56 def after_update(self, mapper, connection, instance):
70bf0be59653 fixed Session problems in model class functions
Marcin Kuzminski <marcin@python-works.com>
parents: 1065
diff changeset
57 pass
70bf0be59653 fixed Session problems in model class functions
Marcin Kuzminski <marcin@python-works.com>
parents: 1065
diff changeset
58
70bf0be59653 fixed Session problems in model class functions
Marcin Kuzminski <marcin@python-works.com>
parents: 1065
diff changeset
59
1065
5d676b6ab71c Moved BaseModel into base class for declarative base. Added some handy methods into
Marcin Kuzminski <marcin@python-works.com>
parents: 1039
diff changeset
60 class RhodeCodeSettings(Base):
548
b75b77ef649d renamed hg_app to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents: 547
diff changeset
61 __tablename__ = 'rhodecode_settings'
1360
1f47adeb67c2 Bumped sqlalchemy version to 0.7, replaced timerproxy with new event system for sqlalchemy.
Marcin Kuzminski <marcin@python-works.com>
parents: 1349
diff changeset
62 __table_args__ = (UniqueConstraint('app_settings_name'), {'extend_existing':True})
780
92fa9c3414d0 fixed models for compatibility with database systems
Marcin Kuzminski <marcin@python-works.com>
parents: 759
diff changeset
63 app_settings_id = Column("app_settings_id", Integer(), nullable=False, unique=True, default=None, primary_key=True)
1113
c1eda8ec4a46 added clone_uri,api_key into models. Fixed models for mysql compatibilty
Marcin Kuzminski <marcin@python-works.com>
parents: 1088
diff changeset
64 app_settings_name = Column("app_settings_name", String(length=255, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None)
c1eda8ec4a46 added clone_uri,api_key into models. Fixed models for mysql compatibilty
Marcin Kuzminski <marcin@python-works.com>
parents: 1088
diff changeset
65 app_settings_value = Column("app_settings_value", String(length=255, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None)
341
1ef52a70f3b7 Made config file free configuration based on database and capable of beeing manage via application settings + some code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 328
diff changeset
66
907
2f83756f3041 Fixed dbmigrate issues.
Marcin Kuzminski <marcin@python-works.com>
parents: 902
diff changeset
67 def __init__(self, k='', v=''):
704
26237de9b613 Added settings model, and Exceptions lib.
Marcin Kuzminski <marcin@python-works.com>
parents: 692
diff changeset
68 self.app_settings_name = k
26237de9b613 Added settings model, and Exceptions lib.
Marcin Kuzminski <marcin@python-works.com>
parents: 692
diff changeset
69 self.app_settings_value = v
26237de9b613 Added settings model, and Exceptions lib.
Marcin Kuzminski <marcin@python-works.com>
parents: 692
diff changeset
70
26237de9b613 Added settings model, and Exceptions lib.
Marcin Kuzminski <marcin@python-works.com>
parents: 692
diff changeset
71 def __repr__(self):
878
859bc9e7a15d Extended repo2db mapper with group creation via directory structures
Marcin Kuzminski <marcin@python-works.com>
parents: 836
diff changeset
72 return "<%s('%s:%s')>" % (self.__class__.__name__,
859bc9e7a15d Extended repo2db mapper with group creation via directory structures
Marcin Kuzminski <marcin@python-works.com>
parents: 836
diff changeset
73 self.app_settings_name, self.app_settings_value)
704
26237de9b613 Added settings model, and Exceptions lib.
Marcin Kuzminski <marcin@python-works.com>
parents: 692
diff changeset
74
1266
a1bcfe58a1ab Fixed #161 form saves the create repository permission.
Marcin Kuzminski <marcin@python-works.com>
parents: 1206
diff changeset
75
a1bcfe58a1ab Fixed #161 form saves the create repository permission.
Marcin Kuzminski <marcin@python-works.com>
parents: 1206
diff changeset
76 @classmethod
1292
c0335c1dee36 added some fixes to LDAP form re-submition, new simples ldap-settings getter.
Marcin Kuzminski <marcin@python-works.com>
parents: 1279
diff changeset
77 def get_by_name(cls, ldap_key):
c0335c1dee36 added some fixes to LDAP form re-submition, new simples ldap-settings getter.
Marcin Kuzminski <marcin@python-works.com>
parents: 1279
diff changeset
78 return Session.query(cls)\
c0335c1dee36 added some fixes to LDAP form re-submition, new simples ldap-settings getter.
Marcin Kuzminski <marcin@python-works.com>
parents: 1279
diff changeset
79 .filter(cls.app_settings_name == ldap_key).scalar()
c0335c1dee36 added some fixes to LDAP form re-submition, new simples ldap-settings getter.
Marcin Kuzminski <marcin@python-works.com>
parents: 1279
diff changeset
80
c0335c1dee36 added some fixes to LDAP form re-submition, new simples ldap-settings getter.
Marcin Kuzminski <marcin@python-works.com>
parents: 1279
diff changeset
81 @classmethod
1266
a1bcfe58a1ab Fixed #161 form saves the create repository permission.
Marcin Kuzminski <marcin@python-works.com>
parents: 1206
diff changeset
82 def get_app_settings(cls, cache=False):
a1bcfe58a1ab Fixed #161 form saves the create repository permission.
Marcin Kuzminski <marcin@python-works.com>
parents: 1206
diff changeset
83
a1bcfe58a1ab Fixed #161 form saves the create repository permission.
Marcin Kuzminski <marcin@python-works.com>
parents: 1206
diff changeset
84 ret = Session.query(cls)
a1bcfe58a1ab Fixed #161 form saves the create repository permission.
Marcin Kuzminski <marcin@python-works.com>
parents: 1206
diff changeset
85
a1bcfe58a1ab Fixed #161 form saves the create repository permission.
Marcin Kuzminski <marcin@python-works.com>
parents: 1206
diff changeset
86 if cache:
a1bcfe58a1ab Fixed #161 form saves the create repository permission.
Marcin Kuzminski <marcin@python-works.com>
parents: 1206
diff changeset
87 ret = ret.options(FromCache("sql_cache_short", "get_hg_settings"))
a1bcfe58a1ab Fixed #161 form saves the create repository permission.
Marcin Kuzminski <marcin@python-works.com>
parents: 1206
diff changeset
88
a1bcfe58a1ab Fixed #161 form saves the create repository permission.
Marcin Kuzminski <marcin@python-works.com>
parents: 1206
diff changeset
89 if not ret:
a1bcfe58a1ab Fixed #161 form saves the create repository permission.
Marcin Kuzminski <marcin@python-works.com>
parents: 1206
diff changeset
90 raise Exception('Could not get application settings !')
a1bcfe58a1ab Fixed #161 form saves the create repository permission.
Marcin Kuzminski <marcin@python-works.com>
parents: 1206
diff changeset
91 settings = {}
a1bcfe58a1ab Fixed #161 form saves the create repository permission.
Marcin Kuzminski <marcin@python-works.com>
parents: 1206
diff changeset
92 for each in ret:
a1bcfe58a1ab Fixed #161 form saves the create repository permission.
Marcin Kuzminski <marcin@python-works.com>
parents: 1206
diff changeset
93 settings['rhodecode_' + each.app_settings_name] = \
a1bcfe58a1ab Fixed #161 form saves the create repository permission.
Marcin Kuzminski <marcin@python-works.com>
parents: 1206
diff changeset
94 each.app_settings_value
a1bcfe58a1ab Fixed #161 form saves the create repository permission.
Marcin Kuzminski <marcin@python-works.com>
parents: 1206
diff changeset
95
a1bcfe58a1ab Fixed #161 form saves the create repository permission.
Marcin Kuzminski <marcin@python-works.com>
parents: 1206
diff changeset
96 return settings
a1bcfe58a1ab Fixed #161 form saves the create repository permission.
Marcin Kuzminski <marcin@python-works.com>
parents: 1206
diff changeset
97
a1bcfe58a1ab Fixed #161 form saves the create repository permission.
Marcin Kuzminski <marcin@python-works.com>
parents: 1206
diff changeset
98 @classmethod
a1bcfe58a1ab Fixed #161 form saves the create repository permission.
Marcin Kuzminski <marcin@python-works.com>
parents: 1206
diff changeset
99 def get_ldap_settings(cls, cache=False):
a1bcfe58a1ab Fixed #161 form saves the create repository permission.
Marcin Kuzminski <marcin@python-works.com>
parents: 1206
diff changeset
100 ret = Session.query(cls)\
a1bcfe58a1ab Fixed #161 form saves the create repository permission.
Marcin Kuzminski <marcin@python-works.com>
parents: 1206
diff changeset
101 .filter(cls.app_settings_name.startswith('ldap_'))\
a1bcfe58a1ab Fixed #161 form saves the create repository permission.
Marcin Kuzminski <marcin@python-works.com>
parents: 1206
diff changeset
102 .all()
a1bcfe58a1ab Fixed #161 form saves the create repository permission.
Marcin Kuzminski <marcin@python-works.com>
parents: 1206
diff changeset
103 fd = {}
a1bcfe58a1ab Fixed #161 form saves the create repository permission.
Marcin Kuzminski <marcin@python-works.com>
parents: 1206
diff changeset
104 for row in ret:
1292
c0335c1dee36 added some fixes to LDAP form re-submition, new simples ldap-settings getter.
Marcin Kuzminski <marcin@python-works.com>
parents: 1279
diff changeset
105 fd.update({row.app_settings_name:row.app_settings_value})
1381
a1ab3e9c7e82 fixes #204, ldap active checkbox, credits goes to Matt Little.
Marcin Kuzminski <marcin@python-works.com>
parents: 1376
diff changeset
106
a1ab3e9c7e82 fixes #204, ldap active checkbox, credits goes to Matt Little.
Marcin Kuzminski <marcin@python-works.com>
parents: 1376
diff changeset
107 fd.update({'ldap_active':str2bool(fd.get('ldap_active'))})
a1ab3e9c7e82 fixes #204, ldap active checkbox, credits goes to Matt Little.
Marcin Kuzminski <marcin@python-works.com>
parents: 1376
diff changeset
108
1266
a1bcfe58a1ab Fixed #161 form saves the create repository permission.
Marcin Kuzminski <marcin@python-works.com>
parents: 1206
diff changeset
109 return fd
a1bcfe58a1ab Fixed #161 form saves the create repository permission.
Marcin Kuzminski <marcin@python-works.com>
parents: 1206
diff changeset
110
a1bcfe58a1ab Fixed #161 form saves the create repository permission.
Marcin Kuzminski <marcin@python-works.com>
parents: 1206
diff changeset
111
1065
5d676b6ab71c Moved BaseModel into base class for declarative base. Added some handy methods into
Marcin Kuzminski <marcin@python-works.com>
parents: 1039
diff changeset
112 class RhodeCodeUi(Base):
548
b75b77ef649d renamed hg_app to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents: 547
diff changeset
113 __tablename__ = 'rhodecode_ui'
1360
1f47adeb67c2 Bumped sqlalchemy version to 0.7, replaced timerproxy with new event system for sqlalchemy.
Marcin Kuzminski <marcin@python-works.com>
parents: 1349
diff changeset
114 __table_args__ = {'extend_existing':True}
780
92fa9c3414d0 fixed models for compatibility with database systems
Marcin Kuzminski <marcin@python-works.com>
parents: 759
diff changeset
115 ui_id = Column("ui_id", Integer(), nullable=False, unique=True, default=None, primary_key=True)
1113
c1eda8ec4a46 added clone_uri,api_key into models. Fixed models for mysql compatibilty
Marcin Kuzminski <marcin@python-works.com>
parents: 1088
diff changeset
116 ui_section = Column("ui_section", String(length=255, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None)
c1eda8ec4a46 added clone_uri,api_key into models. Fixed models for mysql compatibilty
Marcin Kuzminski <marcin@python-works.com>
parents: 1088
diff changeset
117 ui_key = Column("ui_key", String(length=255, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None)
c1eda8ec4a46 added clone_uri,api_key into models. Fixed models for mysql compatibilty
Marcin Kuzminski <marcin@python-works.com>
parents: 1088
diff changeset
118 ui_value = Column("ui_value", String(length=255, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None)
780
92fa9c3414d0 fixed models for compatibility with database systems
Marcin Kuzminski <marcin@python-works.com>
parents: 759
diff changeset
119 ui_active = Column("ui_active", Boolean(), nullable=True, unique=None, default=True)
631
05528ad948c4 Hacking for git support,and new faster repo scan
Marcin Kuzminski <marcin@python-works.com>
parents: 549
diff changeset
120
05528ad948c4 Hacking for git support,and new faster repo scan
Marcin Kuzminski <marcin@python-works.com>
parents: 549
diff changeset
121
1345
3bce31f026b8 #47 implemented Adding of new repo_groups+forms+validators. Fixed sorting of repo groups by main names in multiple locations. Removed some unneeded calls to self.sa for exchange to .query() methods.
Marcin Kuzminski <marcin@python-works.com>
parents: 1343
diff changeset
122 @classmethod
3bce31f026b8 #47 implemented Adding of new repo_groups+forms+validators. Fixed sorting of repo groups by main names in multiple locations. Removed some unneeded calls to self.sa for exchange to .query() methods.
Marcin Kuzminski <marcin@python-works.com>
parents: 1343
diff changeset
123 def get_by_key(cls, key):
3bce31f026b8 #47 implemented Adding of new repo_groups+forms+validators. Fixed sorting of repo groups by main names in multiple locations. Removed some unneeded calls to self.sa for exchange to .query() methods.
Marcin Kuzminski <marcin@python-works.com>
parents: 1343
diff changeset
124 return Session.query(cls).filter(cls.ui_key == key)
3bce31f026b8 #47 implemented Adding of new repo_groups+forms+validators. Fixed sorting of repo groups by main names in multiple locations. Removed some unneeded calls to self.sa for exchange to .query() methods.
Marcin Kuzminski <marcin@python-works.com>
parents: 1343
diff changeset
125
3bce31f026b8 #47 implemented Adding of new repo_groups+forms+validators. Fixed sorting of repo groups by main names in multiple locations. Removed some unneeded calls to self.sa for exchange to .query() methods.
Marcin Kuzminski <marcin@python-works.com>
parents: 1343
diff changeset
126
1065
5d676b6ab71c Moved BaseModel into base class for declarative base. Added some handy methods into
Marcin Kuzminski <marcin@python-works.com>
parents: 1039
diff changeset
127 class User(Base):
49
3ada2f409c1c Added sqlalchemy support
Marcin Kuzminski <marcin@python-blog.com>
parents:
diff changeset
128 __tablename__ = 'users'
1360
1f47adeb67c2 Bumped sqlalchemy version to 0.7, replaced timerproxy with new event system for sqlalchemy.
Marcin Kuzminski <marcin@python-works.com>
parents: 1349
diff changeset
129 __table_args__ = (UniqueConstraint('username'), UniqueConstraint('email'), {'extend_existing':True})
780
92fa9c3414d0 fixed models for compatibility with database systems
Marcin Kuzminski <marcin@python-works.com>
parents: 759
diff changeset
130 user_id = Column("user_id", Integer(), nullable=False, unique=True, default=None, primary_key=True)
1113
c1eda8ec4a46 added clone_uri,api_key into models. Fixed models for mysql compatibilty
Marcin Kuzminski <marcin@python-works.com>
parents: 1088
diff changeset
131 username = Column("username", String(length=255, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None)
c1eda8ec4a46 added clone_uri,api_key into models. Fixed models for mysql compatibilty
Marcin Kuzminski <marcin@python-works.com>
parents: 1088
diff changeset
132 password = Column("password", String(length=255, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None)
780
92fa9c3414d0 fixed models for compatibility with database systems
Marcin Kuzminski <marcin@python-works.com>
parents: 759
diff changeset
133 active = Column("active", Boolean(), nullable=True, unique=None, default=None)
92fa9c3414d0 fixed models for compatibility with database systems
Marcin Kuzminski <marcin@python-works.com>
parents: 759
diff changeset
134 admin = Column("admin", Boolean(), nullable=True, unique=None, default=False)
1113
c1eda8ec4a46 added clone_uri,api_key into models. Fixed models for mysql compatibilty
Marcin Kuzminski <marcin@python-works.com>
parents: 1088
diff changeset
135 name = Column("name", String(length=255, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None)
c1eda8ec4a46 added clone_uri,api_key into models. Fixed models for mysql compatibilty
Marcin Kuzminski <marcin@python-works.com>
parents: 1088
diff changeset
136 lastname = Column("lastname", String(length=255, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None)
c1eda8ec4a46 added clone_uri,api_key into models. Fixed models for mysql compatibilty
Marcin Kuzminski <marcin@python-works.com>
parents: 1088
diff changeset
137 email = Column("email", String(length=255, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None)
780
92fa9c3414d0 fixed models for compatibility with database systems
Marcin Kuzminski <marcin@python-works.com>
parents: 759
diff changeset
138 last_login = Column("last_login", DateTime(timezone=False), nullable=True, unique=None, default=None)
1113
c1eda8ec4a46 added clone_uri,api_key into models. Fixed models for mysql compatibilty
Marcin Kuzminski <marcin@python-works.com>
parents: 1088
diff changeset
139 ldap_dn = Column("ldap_dn", String(length=255, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None)
c1eda8ec4a46 added clone_uri,api_key into models. Fixed models for mysql compatibilty
Marcin Kuzminski <marcin@python-works.com>
parents: 1088
diff changeset
140 api_key = Column("api_key", String(length=255, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None)
631
05528ad948c4 Hacking for git support,and new faster repo scan
Marcin Kuzminski <marcin@python-works.com>
parents: 549
diff changeset
141
972
2c8fd84935a4 #56 implemented users groups editing,
Marcin Kuzminski <marcin@python-works.com>
parents: 962
diff changeset
142 user_log = relationship('UserLog', cascade='all')
2c8fd84935a4 #56 implemented users groups editing,
Marcin Kuzminski <marcin@python-works.com>
parents: 962
diff changeset
143 user_perms = relationship('UserToPerm', primaryjoin="User.user_id==UserToPerm.user_id", cascade='all')
631
05528ad948c4 Hacking for git support,and new faster repo scan
Marcin Kuzminski <marcin@python-works.com>
parents: 549
diff changeset
144
972
2c8fd84935a4 #56 implemented users groups editing,
Marcin Kuzminski <marcin@python-works.com>
parents: 962
diff changeset
145 repositories = relationship('Repository')
2c8fd84935a4 #56 implemented users groups editing,
Marcin Kuzminski <marcin@python-works.com>
parents: 962
diff changeset
146 user_followers = relationship('UserFollowing', primaryjoin='UserFollowing.follows_user_id==User.user_id', cascade='all')
1325
89ff3e30470f fixes #188 - relationship delete of repo_to_perm entry on user removal
Marcin Kuzminski <marcin@python-works.com>
parents: 1323
diff changeset
147 repo_to_perm = relationship('RepoToPerm', primaryjoin='RepoToPerm.user_id==User.user_id', cascade='all')
713
1bb0fcdec895 fixed #72 show warning on removal when user still is owner of existing repositories
Marcin Kuzminski <marcin@python-works.com>
parents: 708
diff changeset
148
1039
51b70569c330 extended admin rescan to show what repositories was added and what removed
Marcin Kuzminski <marcin@python-works.com>
parents: 1034
diff changeset
149 group_member = relationship('UsersGroupMember', cascade='all')
1065
5d676b6ab71c Moved BaseModel into base class for declarative base. Added some handy methods into
Marcin Kuzminski <marcin@python-works.com>
parents: 1039
diff changeset
150
759
a7f50911a945 Models code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 734
diff changeset
151 @property
265
0e5455fda8fd Implemented basic repository managment. Implemented repo2db mappings, model, helpers updates and code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 242
diff changeset
152 def full_contact(self):
0e5455fda8fd Implemented basic repository managment. Implemented repo2db mappings, model, helpers updates and code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 242
diff changeset
153 return '%s %s <%s>' % (self.name, self.lastname, self.email)
631
05528ad948c4 Hacking for git support,and new faster repo scan
Marcin Kuzminski <marcin@python-works.com>
parents: 549
diff changeset
154
895
62c04c5cc971 Added some more details into user edit permissions view
Marcin Kuzminski <marcin@python-works.com>
parents: 880
diff changeset
155 @property
1088
fee472613dfa made simple global rss and atom feed
Marcin Kuzminski <marcin@python-works.com>
parents: 1081
diff changeset
156 def short_contact(self):
fee472613dfa made simple global rss and atom feed
Marcin Kuzminski <marcin@python-works.com>
parents: 1081
diff changeset
157 return '%s %s' % (self.name, self.lastname)
fee472613dfa made simple global rss and atom feed
Marcin Kuzminski <marcin@python-works.com>
parents: 1081
diff changeset
158
fee472613dfa made simple global rss and atom feed
Marcin Kuzminski <marcin@python-works.com>
parents: 1081
diff changeset
159
fee472613dfa made simple global rss and atom feed
Marcin Kuzminski <marcin@python-works.com>
parents: 1081
diff changeset
160 @property
895
62c04c5cc971 Added some more details into user edit permissions view
Marcin Kuzminski <marcin@python-works.com>
parents: 880
diff changeset
161 def is_admin(self):
62c04c5cc971 Added some more details into user edit permissions view
Marcin Kuzminski <marcin@python-works.com>
parents: 880
diff changeset
162 return self.admin
62c04c5cc971 Added some more details into user edit permissions view
Marcin Kuzminski <marcin@python-works.com>
parents: 880
diff changeset
163
232
37a832dc4a82 some beaker cache changes, and added repr to models
Marcin Kuzminski <marcin@python-works.com>
parents: 226
diff changeset
164 def __repr__(self):
878
859bc9e7a15d Extended repo2db mapper with group creation via directory structures
Marcin Kuzminski <marcin@python-works.com>
parents: 836
diff changeset
165 return "<%s('id:%s:%s')>" % (self.__class__.__name__,
859bc9e7a15d Extended repo2db mapper with group creation via directory structures
Marcin Kuzminski <marcin@python-works.com>
parents: 836
diff changeset
166 self.user_id, self.username)
631
05528ad948c4 Hacking for git support,and new faster repo scan
Marcin Kuzminski <marcin@python-works.com>
parents: 549
diff changeset
167
1065
5d676b6ab71c Moved BaseModel into base class for declarative base. Added some handy methods into
Marcin Kuzminski <marcin@python-works.com>
parents: 1039
diff changeset
168 @classmethod
5d676b6ab71c Moved BaseModel into base class for declarative base. Added some handy methods into
Marcin Kuzminski <marcin@python-works.com>
parents: 1039
diff changeset
169 def by_username(cls, username):
5d676b6ab71c Moved BaseModel into base class for declarative base. Added some handy methods into
Marcin Kuzminski <marcin@python-works.com>
parents: 1039
diff changeset
170 return Session.query(cls).filter(cls.username == username).one()
5d676b6ab71c Moved BaseModel into base class for declarative base. Added some handy methods into
Marcin Kuzminski <marcin@python-works.com>
parents: 1039
diff changeset
171
5d676b6ab71c Moved BaseModel into base class for declarative base. Added some handy methods into
Marcin Kuzminski <marcin@python-works.com>
parents: 1039
diff changeset
172
442
d66a7fa7689b moved loged in user propagation out of forms,
Marcin Kuzminski <marcin@python-works.com>
parents: 417
diff changeset
173 def update_lastlogin(self):
d66a7fa7689b moved loged in user propagation out of forms,
Marcin Kuzminski <marcin@python-works.com>
parents: 417
diff changeset
174 """Update user lastlogin"""
631
05528ad948c4 Hacking for git support,and new faster repo scan
Marcin Kuzminski <marcin@python-works.com>
parents: 549
diff changeset
175
442
d66a7fa7689b moved loged in user propagation out of forms,
Marcin Kuzminski <marcin@python-works.com>
parents: 417
diff changeset
176 try:
d66a7fa7689b moved loged in user propagation out of forms,
Marcin Kuzminski <marcin@python-works.com>
parents: 417
diff changeset
177 session = Session.object_session(self)
d66a7fa7689b moved loged in user propagation out of forms,
Marcin Kuzminski <marcin@python-works.com>
parents: 417
diff changeset
178 self.last_login = datetime.datetime.now()
d66a7fa7689b moved loged in user propagation out of forms,
Marcin Kuzminski <marcin@python-works.com>
parents: 417
diff changeset
179 session.add(self)
d66a7fa7689b moved loged in user propagation out of forms,
Marcin Kuzminski <marcin@python-works.com>
parents: 417
diff changeset
180 session.commit()
473
6b934c9607e7 Improved testing scenarios. Made test env creator
Marcin Kuzminski <marcin@python-works.com>
parents: 462
diff changeset
181 log.debug('updated user %s lastlogin', self.username)
759
a7f50911a945 Models code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 734
diff changeset
182 except (DatabaseError,):
631
05528ad948c4 Hacking for git support,and new faster repo scan
Marcin Kuzminski <marcin@python-works.com>
parents: 549
diff changeset
183 session.rollback()
05528ad948c4 Hacking for git support,and new faster repo scan
Marcin Kuzminski <marcin@python-works.com>
parents: 549
diff changeset
184
05528ad948c4 Hacking for git support,and new faster repo scan
Marcin Kuzminski <marcin@python-works.com>
parents: 549
diff changeset
185
1065
5d676b6ab71c Moved BaseModel into base class for declarative base. Added some handy methods into
Marcin Kuzminski <marcin@python-works.com>
parents: 1039
diff changeset
186 class UserLog(Base):
49
3ada2f409c1c Added sqlalchemy support
Marcin Kuzminski <marcin@python-blog.com>
parents:
diff changeset
187 __tablename__ = 'user_logs'
1360
1f47adeb67c2 Bumped sqlalchemy version to 0.7, replaced timerproxy with new event system for sqlalchemy.
Marcin Kuzminski <marcin@python-works.com>
parents: 1349
diff changeset
188 __table_args__ = {'extend_existing':True}
780
92fa9c3414d0 fixed models for compatibility with database systems
Marcin Kuzminski <marcin@python-works.com>
parents: 759
diff changeset
189 user_log_id = Column("user_log_id", Integer(), nullable=False, unique=True, default=None, primary_key=True)
880
014071a745da removed unicode from models string params
Marcin Kuzminski <marcin@python-works.com>
parents: 879
diff changeset
190 user_id = Column("user_id", Integer(), ForeignKey('users.user_id'), nullable=False, unique=None, default=None)
1360
1f47adeb67c2 Bumped sqlalchemy version to 0.7, replaced timerproxy with new event system for sqlalchemy.
Marcin Kuzminski <marcin@python-works.com>
parents: 1349
diff changeset
191 repository_id = Column("repository_id", Integer(), ForeignKey('repositories.repo_id'), nullable=False, unique=None, default=None)
1113
c1eda8ec4a46 added clone_uri,api_key into models. Fixed models for mysql compatibilty
Marcin Kuzminski <marcin@python-works.com>
parents: 1088
diff changeset
192 repository_name = Column("repository_name", String(length=255, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None)
c1eda8ec4a46 added clone_uri,api_key into models. Fixed models for mysql compatibilty
Marcin Kuzminski <marcin@python-works.com>
parents: 1088
diff changeset
193 user_ip = Column("user_ip", String(length=255, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None)
c1eda8ec4a46 added clone_uri,api_key into models. Fixed models for mysql compatibilty
Marcin Kuzminski <marcin@python-works.com>
parents: 1088
diff changeset
194 action = Column("action", UnicodeText(length=1200000, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None)
780
92fa9c3414d0 fixed models for compatibility with database systems
Marcin Kuzminski <marcin@python-works.com>
parents: 759
diff changeset
195 action_date = Column("action_date", DateTime(timezone=False), nullable=True, unique=None, default=None)
631
05528ad948c4 Hacking for git support,and new faster repo scan
Marcin Kuzminski <marcin@python-works.com>
parents: 549
diff changeset
196
994
7f9d23f6a526 Added grouping by days in journal
Marcin Kuzminski <marcin@python-works.com>
parents: 991
diff changeset
197 @property
7f9d23f6a526 Added grouping by days in journal
Marcin Kuzminski <marcin@python-works.com>
parents: 991
diff changeset
198 def action_as_day(self):
7f9d23f6a526 Added grouping by days in journal
Marcin Kuzminski <marcin@python-works.com>
parents: 991
diff changeset
199 return date(*self.action_date.timetuple()[:3])
7f9d23f6a526 Added grouping by days in journal
Marcin Kuzminski <marcin@python-works.com>
parents: 991
diff changeset
200
972
2c8fd84935a4 #56 implemented users groups editing,
Marcin Kuzminski <marcin@python-works.com>
parents: 962
diff changeset
201 user = relationship('User')
2c8fd84935a4 #56 implemented users groups editing,
Marcin Kuzminski <marcin@python-works.com>
parents: 962
diff changeset
202 repository = relationship('Repository')
631
05528ad948c4 Hacking for git support,and new faster repo scan
Marcin Kuzminski <marcin@python-works.com>
parents: 549
diff changeset
203
956
83d35d716a02 started working on issue #56
Marcin Kuzminski <marcin@python-works.com>
parents: 907
diff changeset
204
1065
5d676b6ab71c Moved BaseModel into base class for declarative base. Added some handy methods into
Marcin Kuzminski <marcin@python-works.com>
parents: 1039
diff changeset
205 class UsersGroup(Base):
956
83d35d716a02 started working on issue #56
Marcin Kuzminski <marcin@python-works.com>
parents: 907
diff changeset
206 __tablename__ = 'users_groups'
1360
1f47adeb67c2 Bumped sqlalchemy version to 0.7, replaced timerproxy with new event system for sqlalchemy.
Marcin Kuzminski <marcin@python-works.com>
parents: 1349
diff changeset
207 __table_args__ = {'extend_existing':True}
956
83d35d716a02 started working on issue #56
Marcin Kuzminski <marcin@python-works.com>
parents: 907
diff changeset
208
959
fff21c9b075c #56 fixed found bugs, implemented adding of new group + forms+validators
Marcin Kuzminski <marcin@python-works.com>
parents: 958
diff changeset
209 users_group_id = Column("users_group_id", Integer(), nullable=False, unique=True, default=None, primary_key=True)
1113
c1eda8ec4a46 added clone_uri,api_key into models. Fixed models for mysql compatibilty
Marcin Kuzminski <marcin@python-works.com>
parents: 1088
diff changeset
210 users_group_name = Column("users_group_name", String(length=255, convert_unicode=False, assert_unicode=None), nullable=False, unique=True, default=None)
959
fff21c9b075c #56 fixed found bugs, implemented adding of new group + forms+validators
Marcin Kuzminski <marcin@python-works.com>
parents: 958
diff changeset
211 users_group_active = Column("users_group_active", Boolean(), nullable=True, unique=None, default=None)
956
83d35d716a02 started working on issue #56
Marcin Kuzminski <marcin@python-works.com>
parents: 907
diff changeset
212
974
f6658c70eeeb #56 fixed relationship query behavior to speed up fetching, and
Marcin Kuzminski <marcin@python-works.com>
parents: 972
diff changeset
213 members = relationship('UsersGroupMember', cascade="all, delete, delete-orphan", lazy="joined")
956
83d35d716a02 started working on issue #56
Marcin Kuzminski <marcin@python-works.com>
parents: 907
diff changeset
214
1271
aa7e45ad0cea Fixed permissions for users groups, group can have create repo permission now.
Marcin Kuzminski <marcin@python-works.com>
parents: 1266
diff changeset
215
aa7e45ad0cea Fixed permissions for users groups, group can have create repo permission now.
Marcin Kuzminski <marcin@python-works.com>
parents: 1266
diff changeset
216 @classmethod
aa7e45ad0cea Fixed permissions for users groups, group can have create repo permission now.
Marcin Kuzminski <marcin@python-works.com>
parents: 1266
diff changeset
217 def get_by_group_name(cls, group_name, cache=False, case_insensitive=False):
aa7e45ad0cea Fixed permissions for users groups, group can have create repo permission now.
Marcin Kuzminski <marcin@python-works.com>
parents: 1266
diff changeset
218 if case_insensitive:
aa7e45ad0cea Fixed permissions for users groups, group can have create repo permission now.
Marcin Kuzminski <marcin@python-works.com>
parents: 1266
diff changeset
219 gr = Session.query(cls)\
aa7e45ad0cea Fixed permissions for users groups, group can have create repo permission now.
Marcin Kuzminski <marcin@python-works.com>
parents: 1266
diff changeset
220 .filter(cls.users_group_name.ilike(group_name))
aa7e45ad0cea Fixed permissions for users groups, group can have create repo permission now.
Marcin Kuzminski <marcin@python-works.com>
parents: 1266
diff changeset
221 else:
aa7e45ad0cea Fixed permissions for users groups, group can have create repo permission now.
Marcin Kuzminski <marcin@python-works.com>
parents: 1266
diff changeset
222 gr = Session.query(UsersGroup)\
aa7e45ad0cea Fixed permissions for users groups, group can have create repo permission now.
Marcin Kuzminski <marcin@python-works.com>
parents: 1266
diff changeset
223 .filter(UsersGroup.users_group_name == group_name)
aa7e45ad0cea Fixed permissions for users groups, group can have create repo permission now.
Marcin Kuzminski <marcin@python-works.com>
parents: 1266
diff changeset
224 if cache:
aa7e45ad0cea Fixed permissions for users groups, group can have create repo permission now.
Marcin Kuzminski <marcin@python-works.com>
parents: 1266
diff changeset
225 gr = gr.options(FromCache("sql_cache_short",
aa7e45ad0cea Fixed permissions for users groups, group can have create repo permission now.
Marcin Kuzminski <marcin@python-works.com>
parents: 1266
diff changeset
226 "get_user_%s" % group_name))
aa7e45ad0cea Fixed permissions for users groups, group can have create repo permission now.
Marcin Kuzminski <marcin@python-works.com>
parents: 1266
diff changeset
227 return gr.scalar()
aa7e45ad0cea Fixed permissions for users groups, group can have create repo permission now.
Marcin Kuzminski <marcin@python-works.com>
parents: 1266
diff changeset
228
1065
5d676b6ab71c Moved BaseModel into base class for declarative base. Added some handy methods into
Marcin Kuzminski <marcin@python-works.com>
parents: 1039
diff changeset
229 class UsersGroupMember(Base):
956
83d35d716a02 started working on issue #56
Marcin Kuzminski <marcin@python-works.com>
parents: 907
diff changeset
230 __tablename__ = 'users_groups_members'
1360
1f47adeb67c2 Bumped sqlalchemy version to 0.7, replaced timerproxy with new event system for sqlalchemy.
Marcin Kuzminski <marcin@python-works.com>
parents: 1349
diff changeset
231 __table_args__ = {'extend_existing':True}
956
83d35d716a02 started working on issue #56
Marcin Kuzminski <marcin@python-works.com>
parents: 907
diff changeset
232
959
fff21c9b075c #56 fixed found bugs, implemented adding of new group + forms+validators
Marcin Kuzminski <marcin@python-works.com>
parents: 958
diff changeset
233 users_group_member_id = Column("users_group_member_id", Integer(), nullable=False, unique=True, default=None, primary_key=True)
fff21c9b075c #56 fixed found bugs, implemented adding of new group + forms+validators
Marcin Kuzminski <marcin@python-works.com>
parents: 958
diff changeset
234 users_group_id = Column("users_group_id", Integer(), ForeignKey('users_groups.users_group_id'), nullable=False, unique=None, default=None)
956
83d35d716a02 started working on issue #56
Marcin Kuzminski <marcin@python-works.com>
parents: 907
diff changeset
235 user_id = Column("user_id", Integer(), ForeignKey('users.user_id'), nullable=False, unique=None, default=None)
83d35d716a02 started working on issue #56
Marcin Kuzminski <marcin@python-works.com>
parents: 907
diff changeset
236
974
f6658c70eeeb #56 fixed relationship query behavior to speed up fetching, and
Marcin Kuzminski <marcin@python-works.com>
parents: 972
diff changeset
237 user = relationship('User', lazy='joined')
972
2c8fd84935a4 #56 implemented users groups editing,
Marcin Kuzminski <marcin@python-works.com>
parents: 962
diff changeset
238 users_group = relationship('UsersGroup')
2c8fd84935a4 #56 implemented users groups editing,
Marcin Kuzminski <marcin@python-works.com>
parents: 962
diff changeset
239
1023
e7478ac19f9f updated db migrations to schema 3
Marcin Kuzminski <marcin@python-works.com>
parents: 1015
diff changeset
240 def __init__(self, gr_id='', u_id=''):
972
2c8fd84935a4 #56 implemented users groups editing,
Marcin Kuzminski <marcin@python-works.com>
parents: 962
diff changeset
241 self.users_group_id = gr_id
2c8fd84935a4 #56 implemented users groups editing,
Marcin Kuzminski <marcin@python-works.com>
parents: 962
diff changeset
242 self.user_id = u_id
956
83d35d716a02 started working on issue #56
Marcin Kuzminski <marcin@python-works.com>
parents: 907
diff changeset
243
1065
5d676b6ab71c Moved BaseModel into base class for declarative base. Added some handy methods into
Marcin Kuzminski <marcin@python-works.com>
parents: 1039
diff changeset
244 class Repository(Base):
234
a0116e944da1 changed naming convention for db modules.
Marcin Kuzminski <marcin@python-works.com>
parents: 232
diff changeset
245 __tablename__ = 'repositories'
1360
1f47adeb67c2 Bumped sqlalchemy version to 0.7, replaced timerproxy with new event system for sqlalchemy.
Marcin Kuzminski <marcin@python-works.com>
parents: 1349
diff changeset
246 __table_args__ = (UniqueConstraint('repo_name'), {'extend_existing':True},)
1081
70bf0be59653 fixed Session problems in model class functions
Marcin Kuzminski <marcin@python-works.com>
parents: 1065
diff changeset
247 __mapper_args__ = {'extension':RepositoryMapper()}
70bf0be59653 fixed Session problems in model class functions
Marcin Kuzminski <marcin@python-works.com>
parents: 1065
diff changeset
248
780
92fa9c3414d0 fixed models for compatibility with database systems
Marcin Kuzminski <marcin@python-works.com>
parents: 759
diff changeset
249 repo_id = Column("repo_id", Integer(), nullable=False, unique=True, default=None, primary_key=True)
1113
c1eda8ec4a46 added clone_uri,api_key into models. Fixed models for mysql compatibilty
Marcin Kuzminski <marcin@python-works.com>
parents: 1088
diff changeset
250 repo_name = Column("repo_name", String(length=255, convert_unicode=False, assert_unicode=None), nullable=False, unique=True, default=None)
c1eda8ec4a46 added clone_uri,api_key into models. Fixed models for mysql compatibilty
Marcin Kuzminski <marcin@python-works.com>
parents: 1088
diff changeset
251 clone_uri = Column("clone_uri", String(length=255, convert_unicode=False, assert_unicode=None), nullable=True, unique=False, default=None)
c1eda8ec4a46 added clone_uri,api_key into models. Fixed models for mysql compatibilty
Marcin Kuzminski <marcin@python-works.com>
parents: 1088
diff changeset
252 repo_type = Column("repo_type", String(length=255, convert_unicode=False, assert_unicode=None), nullable=False, unique=False, default='hg')
880
014071a745da removed unicode from models string params
Marcin Kuzminski <marcin@python-works.com>
parents: 879
diff changeset
253 user_id = Column("user_id", Integer(), ForeignKey('users.user_id'), nullable=False, unique=False, default=None)
780
92fa9c3414d0 fixed models for compatibility with database systems
Marcin Kuzminski <marcin@python-works.com>
parents: 759
diff changeset
254 private = Column("private", Boolean(), nullable=True, unique=None, default=None)
810
bd57d1cb9dc3 fixes #62, added option to disable statistics for each repository
Marcin Kuzminski <marcin@python-works.com>
parents: 780
diff changeset
255 enable_statistics = Column("statistics", Boolean(), nullable=True, unique=None, default=True)
962
72f008ed9b18 implemented #84 downloads can be enabled/disabled per each repository from now.
Marcin Kuzminski <marcin@python-works.com>
parents: 959
diff changeset
256 enable_downloads = Column("downloads", Boolean(), nullable=True, unique=None, default=True)
1113
c1eda8ec4a46 added clone_uri,api_key into models. Fixed models for mysql compatibilty
Marcin Kuzminski <marcin@python-works.com>
parents: 1088
diff changeset
257 description = Column("description", String(length=10000, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None)
1301
7e75af301842 Added simple forks page, resolves issue #179
Marcin Kuzminski <marcin@python-works.com>
parents: 1292
diff changeset
258 created_on = Column('created_on', DateTime(timezone=False), nullable=True, unique=None, default=datetime.datetime.now)
7e75af301842 Added simple forks page, resolves issue #179
Marcin Kuzminski <marcin@python-works.com>
parents: 1292
diff changeset
259
880
014071a745da removed unicode from models string params
Marcin Kuzminski <marcin@python-works.com>
parents: 879
diff changeset
260 fork_id = Column("fork_id", Integer(), ForeignKey('repositories.repo_id'), nullable=True, unique=False, default=None)
014071a745da removed unicode from models string params
Marcin Kuzminski <marcin@python-works.com>
parents: 879
diff changeset
261 group_id = Column("group_id", Integer(), ForeignKey('groups.group_id'), nullable=True, unique=False, default=None)
631
05528ad948c4 Hacking for git support,and new faster repo scan
Marcin Kuzminski <marcin@python-works.com>
parents: 549
diff changeset
262
1113
c1eda8ec4a46 added clone_uri,api_key into models. Fixed models for mysql compatibilty
Marcin Kuzminski <marcin@python-works.com>
parents: 1088
diff changeset
263
972
2c8fd84935a4 #56 implemented users groups editing,
Marcin Kuzminski <marcin@python-works.com>
parents: 962
diff changeset
264 user = relationship('User')
2c8fd84935a4 #56 implemented users groups editing,
Marcin Kuzminski <marcin@python-works.com>
parents: 962
diff changeset
265 fork = relationship('Repository', remote_side=repo_id)
2c8fd84935a4 #56 implemented users groups editing,
Marcin Kuzminski <marcin@python-works.com>
parents: 962
diff changeset
266 group = relationship('Group')
1033
e2ebbb27df4e fixed problem with caching
Marcin Kuzminski <marcin@python-works.com>
parents: 1023
diff changeset
267 repo_to_perm = relationship('RepoToPerm', cascade='all', order_by='RepoToPerm.repo_to_perm_id')
1271
aa7e45ad0cea Fixed permissions for users groups, group can have create repo permission now.
Marcin Kuzminski <marcin@python-works.com>
parents: 1266
diff changeset
268 users_group_to_perm = relationship('UsersGroupRepoToPerm', cascade='all')
972
2c8fd84935a4 #56 implemented users groups editing,
Marcin Kuzminski <marcin@python-works.com>
parents: 962
diff changeset
269 stats = relationship('Statistics', cascade='all', uselist=False)
667
56a8434a88cc fixes #51 deleting a repo didn't delete it's dependent db entries.
Marcin Kuzminski <marcin@python-works.com>
parents: 658
diff changeset
270
1034
9e59b16d1b48 updated config files, and changed model repo_followers to followers
Marcin Kuzminski <marcin@python-works.com>
parents: 1033
diff changeset
271 followers = relationship('UserFollowing', primaryjoin='UserFollowing.follows_repo_id==Repository.repo_id', cascade='all')
734
49eb69d78988 implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents: 713
diff changeset
272
976
de535f8b1e8b Fixed links for repository, it's optional now to pass a link without a summary
Marcin Kuzminski <marcin@python-works.com>
parents: 975
diff changeset
273 logs = relationship('UserLog', cascade='all')
970
1a5c41e4bb02 fixees for #106 relation issues on databases different than sqlite
Marcin Kuzminski <marcin@python-works.com>
parents: 962
diff changeset
274
417
3ed2d46a2ca7 permission refactoring,
Marcin Kuzminski <marcin@python-works.com>
parents: 414
diff changeset
275 def __repr__(self):
878
859bc9e7a15d Extended repo2db mapper with group creation via directory structures
Marcin Kuzminski <marcin@python-works.com>
parents: 836
diff changeset
276 return "<%s('%s:%s')>" % (self.__class__.__name__,
880
014071a745da removed unicode from models string params
Marcin Kuzminski <marcin@python-works.com>
parents: 879
diff changeset
277 self.repo_id, self.repo_name)
878
859bc9e7a15d Extended repo2db mapper with group creation via directory structures
Marcin Kuzminski <marcin@python-works.com>
parents: 836
diff changeset
278
1065
5d676b6ab71c Moved BaseModel into base class for declarative base. Added some handy methods into
Marcin Kuzminski <marcin@python-works.com>
parents: 1039
diff changeset
279 @classmethod
5d676b6ab71c Moved BaseModel into base class for declarative base. Added some handy methods into
Marcin Kuzminski <marcin@python-works.com>
parents: 1039
diff changeset
280 def by_repo_name(cls, repo_name):
1366
9c0f5d558789 fixes #200, rewrote the whole caching mechanism to get rid of such problems. Now cached instances are attached
Marcin Kuzminski <marcin@python-works.com>
parents: 1360
diff changeset
281 q = Session.query(cls).filter(cls.repo_name == repo_name)
1065
5d676b6ab71c Moved BaseModel into base class for declarative base. Added some handy methods into
Marcin Kuzminski <marcin@python-works.com>
parents: 1039
diff changeset
282
1366
9c0f5d558789 fixes #200, rewrote the whole caching mechanism to get rid of such problems. Now cached instances are attached
Marcin Kuzminski <marcin@python-works.com>
parents: 1360
diff changeset
283 q = q.options(joinedload(Repository.fork))\
9c0f5d558789 fixes #200, rewrote the whole caching mechanism to get rid of such problems. Now cached instances are attached
Marcin Kuzminski <marcin@python-works.com>
parents: 1360
diff changeset
284 .options(joinedload(Repository.user))\
9c0f5d558789 fixes #200, rewrote the whole caching mechanism to get rid of such problems. Now cached instances are attached
Marcin Kuzminski <marcin@python-works.com>
parents: 1360
diff changeset
285 .options(joinedload(Repository.group))\
9c0f5d558789 fixes #200, rewrote the whole caching mechanism to get rid of such problems. Now cached instances are attached
Marcin Kuzminski <marcin@python-works.com>
parents: 1360
diff changeset
286
9c0f5d558789 fixes #200, rewrote the whole caching mechanism to get rid of such problems. Now cached instances are attached
Marcin Kuzminski <marcin@python-works.com>
parents: 1360
diff changeset
287 return q.one()
1301
7e75af301842 Added simple forks page, resolves issue #179
Marcin Kuzminski <marcin@python-works.com>
parents: 1292
diff changeset
288
7e75af301842 Added simple forks page, resolves issue #179
Marcin Kuzminski <marcin@python-works.com>
parents: 1292
diff changeset
289 @classmethod
7e75af301842 Added simple forks page, resolves issue #179
Marcin Kuzminski <marcin@python-works.com>
parents: 1292
diff changeset
290 def get_repo_forks(cls, repo_id):
7e75af301842 Added simple forks page, resolves issue #179
Marcin Kuzminski <marcin@python-works.com>
parents: 1292
diff changeset
291 return Session.query(cls).filter(Repository.fork_id == repo_id)
7e75af301842 Added simple forks page, resolves issue #179
Marcin Kuzminski <marcin@python-works.com>
parents: 1292
diff changeset
292
1113
c1eda8ec4a46 added clone_uri,api_key into models. Fixed models for mysql compatibilty
Marcin Kuzminski <marcin@python-works.com>
parents: 1088
diff changeset
293 @property
1155
37a9421f32a0 Added handy methods to Repository model for fetching groups with parents
Marcin Kuzminski <marcin@python-works.com>
parents: 1113
diff changeset
294 def just_name(self):
1199
268fa0b6b2ef Added os.sep in models for better win support
Marcin Kuzminski <marcin@python-works.com>
parents: 1193
diff changeset
295 return self.repo_name.split(os.sep)[-1]
1155
37a9421f32a0 Added handy methods to Repository model for fetching groups with parents
Marcin Kuzminski <marcin@python-works.com>
parents: 1113
diff changeset
296
37a9421f32a0 Added handy methods to Repository model for fetching groups with parents
Marcin Kuzminski <marcin@python-works.com>
parents: 1113
diff changeset
297 @property
37a9421f32a0 Added handy methods to Repository model for fetching groups with parents
Marcin Kuzminski <marcin@python-works.com>
parents: 1113
diff changeset
298 def groups_with_parents(self):
37a9421f32a0 Added handy methods to Repository model for fetching groups with parents
Marcin Kuzminski <marcin@python-works.com>
parents: 1113
diff changeset
299 groups = []
37a9421f32a0 Added handy methods to Repository model for fetching groups with parents
Marcin Kuzminski <marcin@python-works.com>
parents: 1113
diff changeset
300 if self.group is None:
37a9421f32a0 Added handy methods to Repository model for fetching groups with parents
Marcin Kuzminski <marcin@python-works.com>
parents: 1113
diff changeset
301 return groups
37a9421f32a0 Added handy methods to Repository model for fetching groups with parents
Marcin Kuzminski <marcin@python-works.com>
parents: 1113
diff changeset
302
37a9421f32a0 Added handy methods to Repository model for fetching groups with parents
Marcin Kuzminski <marcin@python-works.com>
parents: 1113
diff changeset
303 cur_gr = self.group
37a9421f32a0 Added handy methods to Repository model for fetching groups with parents
Marcin Kuzminski <marcin@python-works.com>
parents: 1113
diff changeset
304 groups.insert(0, cur_gr)
37a9421f32a0 Added handy methods to Repository model for fetching groups with parents
Marcin Kuzminski <marcin@python-works.com>
parents: 1113
diff changeset
305 while 1:
37a9421f32a0 Added handy methods to Repository model for fetching groups with parents
Marcin Kuzminski <marcin@python-works.com>
parents: 1113
diff changeset
306 gr = getattr(cur_gr, 'parent_group', None)
37a9421f32a0 Added handy methods to Repository model for fetching groups with parents
Marcin Kuzminski <marcin@python-works.com>
parents: 1113
diff changeset
307 cur_gr = cur_gr.parent_group
37a9421f32a0 Added handy methods to Repository model for fetching groups with parents
Marcin Kuzminski <marcin@python-works.com>
parents: 1113
diff changeset
308 if gr is None:
37a9421f32a0 Added handy methods to Repository model for fetching groups with parents
Marcin Kuzminski <marcin@python-works.com>
parents: 1113
diff changeset
309 break
37a9421f32a0 Added handy methods to Repository model for fetching groups with parents
Marcin Kuzminski <marcin@python-works.com>
parents: 1113
diff changeset
310 groups.insert(0, gr)
37a9421f32a0 Added handy methods to Repository model for fetching groups with parents
Marcin Kuzminski <marcin@python-works.com>
parents: 1113
diff changeset
311
37a9421f32a0 Added handy methods to Repository model for fetching groups with parents
Marcin Kuzminski <marcin@python-works.com>
parents: 1113
diff changeset
312 return groups
37a9421f32a0 Added handy methods to Repository model for fetching groups with parents
Marcin Kuzminski <marcin@python-works.com>
parents: 1113
diff changeset
313
37a9421f32a0 Added handy methods to Repository model for fetching groups with parents
Marcin Kuzminski <marcin@python-works.com>
parents: 1113
diff changeset
314 @property
1113
c1eda8ec4a46 added clone_uri,api_key into models. Fixed models for mysql compatibilty
Marcin Kuzminski <marcin@python-works.com>
parents: 1088
diff changeset
315 def groups_and_repo(self):
1155
37a9421f32a0 Added handy methods to Repository model for fetching groups with parents
Marcin Kuzminski <marcin@python-works.com>
parents: 1113
diff changeset
316 return self.groups_with_parents, self.just_name
1113
c1eda8ec4a46 added clone_uri,api_key into models. Fixed models for mysql compatibilty
Marcin Kuzminski <marcin@python-works.com>
parents: 1088
diff changeset
317
1366
9c0f5d558789 fixes #200, rewrote the whole caching mechanism to get rid of such problems. Now cached instances are attached
Marcin Kuzminski <marcin@python-works.com>
parents: 1360
diff changeset
318 @LazyProperty
9c0f5d558789 fixes #200, rewrote the whole caching mechanism to get rid of such problems. Now cached instances are attached
Marcin Kuzminski <marcin@python-works.com>
parents: 1360
diff changeset
319 def repo_path(self):
9c0f5d558789 fixes #200, rewrote the whole caching mechanism to get rid of such problems. Now cached instances are attached
Marcin Kuzminski <marcin@python-works.com>
parents: 1360
diff changeset
320 """
9c0f5d558789 fixes #200, rewrote the whole caching mechanism to get rid of such problems. Now cached instances are attached
Marcin Kuzminski <marcin@python-works.com>
parents: 1360
diff changeset
321 Returns base full path for that repository means where it actually
9c0f5d558789 fixes #200, rewrote the whole caching mechanism to get rid of such problems. Now cached instances are attached
Marcin Kuzminski <marcin@python-works.com>
parents: 1360
diff changeset
322 exists on a filesystem
9c0f5d558789 fixes #200, rewrote the whole caching mechanism to get rid of such problems. Now cached instances are attached
Marcin Kuzminski <marcin@python-works.com>
parents: 1360
diff changeset
323 """
1368
04b43168742d adde short cache for repo_path
Marcin Kuzminski <marcin@python-works.com>
parents: 1366
diff changeset
324 q = Session.query(RhodeCodeUi).filter(RhodeCodeUi.ui_key == '/')
04b43168742d adde short cache for repo_path
Marcin Kuzminski <marcin@python-works.com>
parents: 1366
diff changeset
325 q.options(FromCache("sql_cache_short", "repository_repo_path"))
04b43168742d adde short cache for repo_path
Marcin Kuzminski <marcin@python-works.com>
parents: 1366
diff changeset
326 return q.one().ui_value
1366
9c0f5d558789 fixes #200, rewrote the whole caching mechanism to get rid of such problems. Now cached instances are attached
Marcin Kuzminski <marcin@python-works.com>
parents: 1360
diff changeset
327
9c0f5d558789 fixes #200, rewrote the whole caching mechanism to get rid of such problems. Now cached instances are attached
Marcin Kuzminski <marcin@python-works.com>
parents: 1360
diff changeset
328 @property
9c0f5d558789 fixes #200, rewrote the whole caching mechanism to get rid of such problems. Now cached instances are attached
Marcin Kuzminski <marcin@python-works.com>
parents: 1360
diff changeset
329 def repo_full_path(self):
9c0f5d558789 fixes #200, rewrote the whole caching mechanism to get rid of such problems. Now cached instances are attached
Marcin Kuzminski <marcin@python-works.com>
parents: 1360
diff changeset
330 p = [self.repo_path]
9c0f5d558789 fixes #200, rewrote the whole caching mechanism to get rid of such problems. Now cached instances are attached
Marcin Kuzminski <marcin@python-works.com>
parents: 1360
diff changeset
331 # we need to split the name by / since this is how we store the
9c0f5d558789 fixes #200, rewrote the whole caching mechanism to get rid of such problems. Now cached instances are attached
Marcin Kuzminski <marcin@python-works.com>
parents: 1360
diff changeset
332 # names in the database, but that eventually needs to be converted
9c0f5d558789 fixes #200, rewrote the whole caching mechanism to get rid of such problems. Now cached instances are attached
Marcin Kuzminski <marcin@python-works.com>
parents: 1360
diff changeset
333 # into a valid system path
9c0f5d558789 fixes #200, rewrote the whole caching mechanism to get rid of such problems. Now cached instances are attached
Marcin Kuzminski <marcin@python-works.com>
parents: 1360
diff changeset
334 p += self.repo_name.split('/')
9c0f5d558789 fixes #200, rewrote the whole caching mechanism to get rid of such problems. Now cached instances are attached
Marcin Kuzminski <marcin@python-works.com>
parents: 1360
diff changeset
335 return os.path.join(*p)
9c0f5d558789 fixes #200, rewrote the whole caching mechanism to get rid of such problems. Now cached instances are attached
Marcin Kuzminski <marcin@python-works.com>
parents: 1360
diff changeset
336
9c0f5d558789 fixes #200, rewrote the whole caching mechanism to get rid of such problems. Now cached instances are attached
Marcin Kuzminski <marcin@python-works.com>
parents: 1360
diff changeset
337 @property
9c0f5d558789 fixes #200, rewrote the whole caching mechanism to get rid of such problems. Now cached instances are attached
Marcin Kuzminski <marcin@python-works.com>
parents: 1360
diff changeset
338 def _ui(self):
9c0f5d558789 fixes #200, rewrote the whole caching mechanism to get rid of such problems. Now cached instances are attached
Marcin Kuzminski <marcin@python-works.com>
parents: 1360
diff changeset
339 """
9c0f5d558789 fixes #200, rewrote the whole caching mechanism to get rid of such problems. Now cached instances are attached
Marcin Kuzminski <marcin@python-works.com>
parents: 1360
diff changeset
340 Creates an db based ui object for this repository
9c0f5d558789 fixes #200, rewrote the whole caching mechanism to get rid of such problems. Now cached instances are attached
Marcin Kuzminski <marcin@python-works.com>
parents: 1360
diff changeset
341 """
9c0f5d558789 fixes #200, rewrote the whole caching mechanism to get rid of such problems. Now cached instances are attached
Marcin Kuzminski <marcin@python-works.com>
parents: 1360
diff changeset
342 from mercurial import ui
9c0f5d558789 fixes #200, rewrote the whole caching mechanism to get rid of such problems. Now cached instances are attached
Marcin Kuzminski <marcin@python-works.com>
parents: 1360
diff changeset
343 from mercurial import config
9c0f5d558789 fixes #200, rewrote the whole caching mechanism to get rid of such problems. Now cached instances are attached
Marcin Kuzminski <marcin@python-works.com>
parents: 1360
diff changeset
344 baseui = ui.ui()
9c0f5d558789 fixes #200, rewrote the whole caching mechanism to get rid of such problems. Now cached instances are attached
Marcin Kuzminski <marcin@python-works.com>
parents: 1360
diff changeset
345
9c0f5d558789 fixes #200, rewrote the whole caching mechanism to get rid of such problems. Now cached instances are attached
Marcin Kuzminski <marcin@python-works.com>
parents: 1360
diff changeset
346 #clean the baseui object
9c0f5d558789 fixes #200, rewrote the whole caching mechanism to get rid of such problems. Now cached instances are attached
Marcin Kuzminski <marcin@python-works.com>
parents: 1360
diff changeset
347 baseui._ocfg = config.config()
9c0f5d558789 fixes #200, rewrote the whole caching mechanism to get rid of such problems. Now cached instances are attached
Marcin Kuzminski <marcin@python-works.com>
parents: 1360
diff changeset
348 baseui._ucfg = config.config()
9c0f5d558789 fixes #200, rewrote the whole caching mechanism to get rid of such problems. Now cached instances are attached
Marcin Kuzminski <marcin@python-works.com>
parents: 1360
diff changeset
349 baseui._tcfg = config.config()
9c0f5d558789 fixes #200, rewrote the whole caching mechanism to get rid of such problems. Now cached instances are attached
Marcin Kuzminski <marcin@python-works.com>
parents: 1360
diff changeset
350
9c0f5d558789 fixes #200, rewrote the whole caching mechanism to get rid of such problems. Now cached instances are attached
Marcin Kuzminski <marcin@python-works.com>
parents: 1360
diff changeset
351
9c0f5d558789 fixes #200, rewrote the whole caching mechanism to get rid of such problems. Now cached instances are attached
Marcin Kuzminski <marcin@python-works.com>
parents: 1360
diff changeset
352 ret = Session.query(RhodeCodeUi)\
9c0f5d558789 fixes #200, rewrote the whole caching mechanism to get rid of such problems. Now cached instances are attached
Marcin Kuzminski <marcin@python-works.com>
parents: 1360
diff changeset
353 .options(FromCache("sql_cache_short",
9c0f5d558789 fixes #200, rewrote the whole caching mechanism to get rid of such problems. Now cached instances are attached
Marcin Kuzminski <marcin@python-works.com>
parents: 1360
diff changeset
354 "repository_repo_ui")).all()
9c0f5d558789 fixes #200, rewrote the whole caching mechanism to get rid of such problems. Now cached instances are attached
Marcin Kuzminski <marcin@python-works.com>
parents: 1360
diff changeset
355
9c0f5d558789 fixes #200, rewrote the whole caching mechanism to get rid of such problems. Now cached instances are attached
Marcin Kuzminski <marcin@python-works.com>
parents: 1360
diff changeset
356 hg_ui = ret
9c0f5d558789 fixes #200, rewrote the whole caching mechanism to get rid of such problems. Now cached instances are attached
Marcin Kuzminski <marcin@python-works.com>
parents: 1360
diff changeset
357 for ui_ in hg_ui:
9c0f5d558789 fixes #200, rewrote the whole caching mechanism to get rid of such problems. Now cached instances are attached
Marcin Kuzminski <marcin@python-works.com>
parents: 1360
diff changeset
358 if ui_.ui_active:
9c0f5d558789 fixes #200, rewrote the whole caching mechanism to get rid of such problems. Now cached instances are attached
Marcin Kuzminski <marcin@python-works.com>
parents: 1360
diff changeset
359 log.debug('settings ui from db[%s]%s:%s', ui_.ui_section,
9c0f5d558789 fixes #200, rewrote the whole caching mechanism to get rid of such problems. Now cached instances are attached
Marcin Kuzminski <marcin@python-works.com>
parents: 1360
diff changeset
360 ui_.ui_key, ui_.ui_value)
9c0f5d558789 fixes #200, rewrote the whole caching mechanism to get rid of such problems. Now cached instances are attached
Marcin Kuzminski <marcin@python-works.com>
parents: 1360
diff changeset
361 baseui.setconfig(ui_.ui_section, ui_.ui_key, ui_.ui_value)
9c0f5d558789 fixes #200, rewrote the whole caching mechanism to get rid of such problems. Now cached instances are attached
Marcin Kuzminski <marcin@python-works.com>
parents: 1360
diff changeset
362
9c0f5d558789 fixes #200, rewrote the whole caching mechanism to get rid of such problems. Now cached instances are attached
Marcin Kuzminski <marcin@python-works.com>
parents: 1360
diff changeset
363 return baseui
9c0f5d558789 fixes #200, rewrote the whole caching mechanism to get rid of such problems. Now cached instances are attached
Marcin Kuzminski <marcin@python-works.com>
parents: 1360
diff changeset
364
9c0f5d558789 fixes #200, rewrote the whole caching mechanism to get rid of such problems. Now cached instances are attached
Marcin Kuzminski <marcin@python-works.com>
parents: 1360
diff changeset
365 #==========================================================================
9c0f5d558789 fixes #200, rewrote the whole caching mechanism to get rid of such problems. Now cached instances are attached
Marcin Kuzminski <marcin@python-works.com>
parents: 1360
diff changeset
366 # SCM CACHE INSTANCE
9c0f5d558789 fixes #200, rewrote the whole caching mechanism to get rid of such problems. Now cached instances are attached
Marcin Kuzminski <marcin@python-works.com>
parents: 1360
diff changeset
367 #==========================================================================
9c0f5d558789 fixes #200, rewrote the whole caching mechanism to get rid of such problems. Now cached instances are attached
Marcin Kuzminski <marcin@python-works.com>
parents: 1360
diff changeset
368
9c0f5d558789 fixes #200, rewrote the whole caching mechanism to get rid of such problems. Now cached instances are attached
Marcin Kuzminski <marcin@python-works.com>
parents: 1360
diff changeset
369 @property
9c0f5d558789 fixes #200, rewrote the whole caching mechanism to get rid of such problems. Now cached instances are attached
Marcin Kuzminski <marcin@python-works.com>
parents: 1360
diff changeset
370 def invalidate(self):
9c0f5d558789 fixes #200, rewrote the whole caching mechanism to get rid of such problems. Now cached instances are attached
Marcin Kuzminski <marcin@python-works.com>
parents: 1360
diff changeset
371 """
9c0f5d558789 fixes #200, rewrote the whole caching mechanism to get rid of such problems. Now cached instances are attached
Marcin Kuzminski <marcin@python-works.com>
parents: 1360
diff changeset
372 Returns Invalidation object if this repo should be invalidated
9c0f5d558789 fixes #200, rewrote the whole caching mechanism to get rid of such problems. Now cached instances are attached
Marcin Kuzminski <marcin@python-works.com>
parents: 1360
diff changeset
373 None otherwise. `cache_active = False` means that this cache
9c0f5d558789 fixes #200, rewrote the whole caching mechanism to get rid of such problems. Now cached instances are attached
Marcin Kuzminski <marcin@python-works.com>
parents: 1360
diff changeset
374 state is not valid and needs to be invalidated
9c0f5d558789 fixes #200, rewrote the whole caching mechanism to get rid of such problems. Now cached instances are attached
Marcin Kuzminski <marcin@python-works.com>
parents: 1360
diff changeset
375 """
9c0f5d558789 fixes #200, rewrote the whole caching mechanism to get rid of such problems. Now cached instances are attached
Marcin Kuzminski <marcin@python-works.com>
parents: 1360
diff changeset
376 return Session.query(CacheInvalidation)\
9c0f5d558789 fixes #200, rewrote the whole caching mechanism to get rid of such problems. Now cached instances are attached
Marcin Kuzminski <marcin@python-works.com>
parents: 1360
diff changeset
377 .filter(CacheInvalidation.cache_key == self.repo_name)\
9c0f5d558789 fixes #200, rewrote the whole caching mechanism to get rid of such problems. Now cached instances are attached
Marcin Kuzminski <marcin@python-works.com>
parents: 1360
diff changeset
378 .filter(CacheInvalidation.cache_active == False)\
9c0f5d558789 fixes #200, rewrote the whole caching mechanism to get rid of such problems. Now cached instances are attached
Marcin Kuzminski <marcin@python-works.com>
parents: 1360
diff changeset
379 .scalar()
9c0f5d558789 fixes #200, rewrote the whole caching mechanism to get rid of such problems. Now cached instances are attached
Marcin Kuzminski <marcin@python-works.com>
parents: 1360
diff changeset
380
9c0f5d558789 fixes #200, rewrote the whole caching mechanism to get rid of such problems. Now cached instances are attached
Marcin Kuzminski <marcin@python-works.com>
parents: 1360
diff changeset
381 @property
9c0f5d558789 fixes #200, rewrote the whole caching mechanism to get rid of such problems. Now cached instances are attached
Marcin Kuzminski <marcin@python-works.com>
parents: 1360
diff changeset
382 def set_invalidate(self):
9c0f5d558789 fixes #200, rewrote the whole caching mechanism to get rid of such problems. Now cached instances are attached
Marcin Kuzminski <marcin@python-works.com>
parents: 1360
diff changeset
383 """
9c0f5d558789 fixes #200, rewrote the whole caching mechanism to get rid of such problems. Now cached instances are attached
Marcin Kuzminski <marcin@python-works.com>
parents: 1360
diff changeset
384 set a cache for invalidation for this instance
9c0f5d558789 fixes #200, rewrote the whole caching mechanism to get rid of such problems. Now cached instances are attached
Marcin Kuzminski <marcin@python-works.com>
parents: 1360
diff changeset
385 """
9c0f5d558789 fixes #200, rewrote the whole caching mechanism to get rid of such problems. Now cached instances are attached
Marcin Kuzminski <marcin@python-works.com>
parents: 1360
diff changeset
386 inv = Session.query(CacheInvalidation)\
9c0f5d558789 fixes #200, rewrote the whole caching mechanism to get rid of such problems. Now cached instances are attached
Marcin Kuzminski <marcin@python-works.com>
parents: 1360
diff changeset
387 .filter(CacheInvalidation.cache_key == self.repo_name)\
9c0f5d558789 fixes #200, rewrote the whole caching mechanism to get rid of such problems. Now cached instances are attached
Marcin Kuzminski <marcin@python-works.com>
parents: 1360
diff changeset
388 .scalar()
9c0f5d558789 fixes #200, rewrote the whole caching mechanism to get rid of such problems. Now cached instances are attached
Marcin Kuzminski <marcin@python-works.com>
parents: 1360
diff changeset
389
9c0f5d558789 fixes #200, rewrote the whole caching mechanism to get rid of such problems. Now cached instances are attached
Marcin Kuzminski <marcin@python-works.com>
parents: 1360
diff changeset
390 if inv is None:
9c0f5d558789 fixes #200, rewrote the whole caching mechanism to get rid of such problems. Now cached instances are attached
Marcin Kuzminski <marcin@python-works.com>
parents: 1360
diff changeset
391 inv = CacheInvalidation(self.repo_name)
9c0f5d558789 fixes #200, rewrote the whole caching mechanism to get rid of such problems. Now cached instances are attached
Marcin Kuzminski <marcin@python-works.com>
parents: 1360
diff changeset
392 inv.cache_active = True
9c0f5d558789 fixes #200, rewrote the whole caching mechanism to get rid of such problems. Now cached instances are attached
Marcin Kuzminski <marcin@python-works.com>
parents: 1360
diff changeset
393 Session.add(inv)
9c0f5d558789 fixes #200, rewrote the whole caching mechanism to get rid of such problems. Now cached instances are attached
Marcin Kuzminski <marcin@python-works.com>
parents: 1360
diff changeset
394 Session.commit()
9c0f5d558789 fixes #200, rewrote the whole caching mechanism to get rid of such problems. Now cached instances are attached
Marcin Kuzminski <marcin@python-works.com>
parents: 1360
diff changeset
395
9c0f5d558789 fixes #200, rewrote the whole caching mechanism to get rid of such problems. Now cached instances are attached
Marcin Kuzminski <marcin@python-works.com>
parents: 1360
diff changeset
396 @property
9c0f5d558789 fixes #200, rewrote the whole caching mechanism to get rid of such problems. Now cached instances are attached
Marcin Kuzminski <marcin@python-works.com>
parents: 1360
diff changeset
397 def scm_instance(self):
9c0f5d558789 fixes #200, rewrote the whole caching mechanism to get rid of such problems. Now cached instances are attached
Marcin Kuzminski <marcin@python-works.com>
parents: 1360
diff changeset
398 return self.__get_instance(self.repo_name)
9c0f5d558789 fixes #200, rewrote the whole caching mechanism to get rid of such problems. Now cached instances are attached
Marcin Kuzminski <marcin@python-works.com>
parents: 1360
diff changeset
399
9c0f5d558789 fixes #200, rewrote the whole caching mechanism to get rid of such problems. Now cached instances are attached
Marcin Kuzminski <marcin@python-works.com>
parents: 1360
diff changeset
400 @property
9c0f5d558789 fixes #200, rewrote the whole caching mechanism to get rid of such problems. Now cached instances are attached
Marcin Kuzminski <marcin@python-works.com>
parents: 1360
diff changeset
401 def scm_instance_cached(self):
9c0f5d558789 fixes #200, rewrote the whole caching mechanism to get rid of such problems. Now cached instances are attached
Marcin Kuzminski <marcin@python-works.com>
parents: 1360
diff changeset
402 @cache_region('long_term')
9c0f5d558789 fixes #200, rewrote the whole caching mechanism to get rid of such problems. Now cached instances are attached
Marcin Kuzminski <marcin@python-works.com>
parents: 1360
diff changeset
403 def _c(repo_name):
9c0f5d558789 fixes #200, rewrote the whole caching mechanism to get rid of such problems. Now cached instances are attached
Marcin Kuzminski <marcin@python-works.com>
parents: 1360
diff changeset
404 return self.__get_instance(repo_name)
9c0f5d558789 fixes #200, rewrote the whole caching mechanism to get rid of such problems. Now cached instances are attached
Marcin Kuzminski <marcin@python-works.com>
parents: 1360
diff changeset
405
9c0f5d558789 fixes #200, rewrote the whole caching mechanism to get rid of such problems. Now cached instances are attached
Marcin Kuzminski <marcin@python-works.com>
parents: 1360
diff changeset
406 inv = self.invalidate
9c0f5d558789 fixes #200, rewrote the whole caching mechanism to get rid of such problems. Now cached instances are attached
Marcin Kuzminski <marcin@python-works.com>
parents: 1360
diff changeset
407 if inv:
9c0f5d558789 fixes #200, rewrote the whole caching mechanism to get rid of such problems. Now cached instances are attached
Marcin Kuzminski <marcin@python-works.com>
parents: 1360
diff changeset
408 region_invalidate(_c, None, self.repo_name)
9c0f5d558789 fixes #200, rewrote the whole caching mechanism to get rid of such problems. Now cached instances are attached
Marcin Kuzminski <marcin@python-works.com>
parents: 1360
diff changeset
409 #update our cache
9c0f5d558789 fixes #200, rewrote the whole caching mechanism to get rid of such problems. Now cached instances are attached
Marcin Kuzminski <marcin@python-works.com>
parents: 1360
diff changeset
410 inv.cache_key.cache_active = True
9c0f5d558789 fixes #200, rewrote the whole caching mechanism to get rid of such problems. Now cached instances are attached
Marcin Kuzminski <marcin@python-works.com>
parents: 1360
diff changeset
411 Session.add(inv)
9c0f5d558789 fixes #200, rewrote the whole caching mechanism to get rid of such problems. Now cached instances are attached
Marcin Kuzminski <marcin@python-works.com>
parents: 1360
diff changeset
412 Session.commit()
9c0f5d558789 fixes #200, rewrote the whole caching mechanism to get rid of such problems. Now cached instances are attached
Marcin Kuzminski <marcin@python-works.com>
parents: 1360
diff changeset
413
9c0f5d558789 fixes #200, rewrote the whole caching mechanism to get rid of such problems. Now cached instances are attached
Marcin Kuzminski <marcin@python-works.com>
parents: 1360
diff changeset
414 return _c(self.repo_name)
9c0f5d558789 fixes #200, rewrote the whole caching mechanism to get rid of such problems. Now cached instances are attached
Marcin Kuzminski <marcin@python-works.com>
parents: 1360
diff changeset
415
9c0f5d558789 fixes #200, rewrote the whole caching mechanism to get rid of such problems. Now cached instances are attached
Marcin Kuzminski <marcin@python-works.com>
parents: 1360
diff changeset
416 def __get_instance(self, repo_name):
1368
04b43168742d adde short cache for repo_path
Marcin Kuzminski <marcin@python-works.com>
parents: 1366
diff changeset
417
04b43168742d adde short cache for repo_path
Marcin Kuzminski <marcin@python-works.com>
parents: 1366
diff changeset
418 repo_full_path = self.repo_full_path
04b43168742d adde short cache for repo_path
Marcin Kuzminski <marcin@python-works.com>
parents: 1366
diff changeset
419
1366
9c0f5d558789 fixes #200, rewrote the whole caching mechanism to get rid of such problems. Now cached instances are attached
Marcin Kuzminski <marcin@python-works.com>
parents: 1360
diff changeset
420 try:
1368
04b43168742d adde short cache for repo_path
Marcin Kuzminski <marcin@python-works.com>
parents: 1366
diff changeset
421 alias = get_scm(repo_full_path)[0]
1366
9c0f5d558789 fixes #200, rewrote the whole caching mechanism to get rid of such problems. Now cached instances are attached
Marcin Kuzminski <marcin@python-works.com>
parents: 1360
diff changeset
422 log.debug('Creating instance of %s repository', alias)
9c0f5d558789 fixes #200, rewrote the whole caching mechanism to get rid of such problems. Now cached instances are attached
Marcin Kuzminski <marcin@python-works.com>
parents: 1360
diff changeset
423 backend = get_backend(alias)
9c0f5d558789 fixes #200, rewrote the whole caching mechanism to get rid of such problems. Now cached instances are attached
Marcin Kuzminski <marcin@python-works.com>
parents: 1360
diff changeset
424 except VCSError:
9c0f5d558789 fixes #200, rewrote the whole caching mechanism to get rid of such problems. Now cached instances are attached
Marcin Kuzminski <marcin@python-works.com>
parents: 1360
diff changeset
425 log.error(traceback.format_exc())
9c0f5d558789 fixes #200, rewrote the whole caching mechanism to get rid of such problems. Now cached instances are attached
Marcin Kuzminski <marcin@python-works.com>
parents: 1360
diff changeset
426 log.error('Perhaps this repository is in db and not in '
9c0f5d558789 fixes #200, rewrote the whole caching mechanism to get rid of such problems. Now cached instances are attached
Marcin Kuzminski <marcin@python-works.com>
parents: 1360
diff changeset
427 'filesystem run rescan repositories with '
9c0f5d558789 fixes #200, rewrote the whole caching mechanism to get rid of such problems. Now cached instances are attached
Marcin Kuzminski <marcin@python-works.com>
parents: 1360
diff changeset
428 '"destroy old data " option from admin panel')
9c0f5d558789 fixes #200, rewrote the whole caching mechanism to get rid of such problems. Now cached instances are attached
Marcin Kuzminski <marcin@python-works.com>
parents: 1360
diff changeset
429 return
9c0f5d558789 fixes #200, rewrote the whole caching mechanism to get rid of such problems. Now cached instances are attached
Marcin Kuzminski <marcin@python-works.com>
parents: 1360
diff changeset
430
9c0f5d558789 fixes #200, rewrote the whole caching mechanism to get rid of such problems. Now cached instances are attached
Marcin Kuzminski <marcin@python-works.com>
parents: 1360
diff changeset
431 if alias == 'hg':
1368
04b43168742d adde short cache for repo_path
Marcin Kuzminski <marcin@python-works.com>
parents: 1366
diff changeset
432 repo = backend(repo_full_path, create=False,
1366
9c0f5d558789 fixes #200, rewrote the whole caching mechanism to get rid of such problems. Now cached instances are attached
Marcin Kuzminski <marcin@python-works.com>
parents: 1360
diff changeset
433 baseui=self._ui)
9c0f5d558789 fixes #200, rewrote the whole caching mechanism to get rid of such problems. Now cached instances are attached
Marcin Kuzminski <marcin@python-works.com>
parents: 1360
diff changeset
434 #skip hidden web repository
9c0f5d558789 fixes #200, rewrote the whole caching mechanism to get rid of such problems. Now cached instances are attached
Marcin Kuzminski <marcin@python-works.com>
parents: 1360
diff changeset
435 if repo._get_hidden():
9c0f5d558789 fixes #200, rewrote the whole caching mechanism to get rid of such problems. Now cached instances are attached
Marcin Kuzminski <marcin@python-works.com>
parents: 1360
diff changeset
436 return
9c0f5d558789 fixes #200, rewrote the whole caching mechanism to get rid of such problems. Now cached instances are attached
Marcin Kuzminski <marcin@python-works.com>
parents: 1360
diff changeset
437 else:
1368
04b43168742d adde short cache for repo_path
Marcin Kuzminski <marcin@python-works.com>
parents: 1366
diff changeset
438 repo = backend(repo_full_path, create=False)
1366
9c0f5d558789 fixes #200, rewrote the whole caching mechanism to get rid of such problems. Now cached instances are attached
Marcin Kuzminski <marcin@python-works.com>
parents: 1360
diff changeset
439
9c0f5d558789 fixes #200, rewrote the whole caching mechanism to get rid of such problems. Now cached instances are attached
Marcin Kuzminski <marcin@python-works.com>
parents: 1360
diff changeset
440 return repo
9c0f5d558789 fixes #200, rewrote the whole caching mechanism to get rid of such problems. Now cached instances are attached
Marcin Kuzminski <marcin@python-works.com>
parents: 1360
diff changeset
441
1065
5d676b6ab71c Moved BaseModel into base class for declarative base. Added some handy methods into
Marcin Kuzminski <marcin@python-works.com>
parents: 1039
diff changeset
442
5d676b6ab71c Moved BaseModel into base class for declarative base. Added some handy methods into
Marcin Kuzminski <marcin@python-works.com>
parents: 1039
diff changeset
443 class Group(Base):
878
859bc9e7a15d Extended repo2db mapper with group creation via directory structures
Marcin Kuzminski <marcin@python-works.com>
parents: 836
diff changeset
444 __tablename__ = 'groups'
1349
526120c77a38 #47 added editing of groups, and moving them between. Added check constraint for groups
Marcin Kuzminski <marcin@python-works.com>
parents: 1346
diff changeset
445 __table_args__ = (UniqueConstraint('group_name', 'group_parent_id'),
1360
1f47adeb67c2 Bumped sqlalchemy version to 0.7, replaced timerproxy with new event system for sqlalchemy.
Marcin Kuzminski <marcin@python-works.com>
parents: 1349
diff changeset
446 CheckConstraint('group_id != group_parent_id'), {'extend_existing':True},)
1343
a04fe5986109 #47 implemented basic gui for browsing repo groups
Marcin Kuzminski <marcin@python-works.com>
parents: 1325
diff changeset
447 __mapper_args__ = {'order_by':'group_name'}
878
859bc9e7a15d Extended repo2db mapper with group creation via directory structures
Marcin Kuzminski <marcin@python-works.com>
parents: 836
diff changeset
448
859bc9e7a15d Extended repo2db mapper with group creation via directory structures
Marcin Kuzminski <marcin@python-works.com>
parents: 836
diff changeset
449 group_id = Column("group_id", Integer(), nullable=False, unique=True, default=None, primary_key=True)
1113
c1eda8ec4a46 added clone_uri,api_key into models. Fixed models for mysql compatibilty
Marcin Kuzminski <marcin@python-works.com>
parents: 1088
diff changeset
450 group_name = Column("group_name", String(length=255, convert_unicode=False, assert_unicode=None), nullable=False, unique=True, default=None)
880
014071a745da removed unicode from models string params
Marcin Kuzminski <marcin@python-works.com>
parents: 879
diff changeset
451 group_parent_id = Column("group_parent_id", Integer(), ForeignKey('groups.group_id'), nullable=True, unique=None, default=None)
1343
a04fe5986109 #47 implemented basic gui for browsing repo groups
Marcin Kuzminski <marcin@python-works.com>
parents: 1325
diff changeset
452 group_description = Column("group_description", String(length=10000, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None)
878
859bc9e7a15d Extended repo2db mapper with group creation via directory structures
Marcin Kuzminski <marcin@python-works.com>
parents: 836
diff changeset
453
972
2c8fd84935a4 #56 implemented users groups editing,
Marcin Kuzminski <marcin@python-works.com>
parents: 962
diff changeset
454 parent_group = relationship('Group', remote_side=group_id)
878
859bc9e7a15d Extended repo2db mapper with group creation via directory structures
Marcin Kuzminski <marcin@python-works.com>
parents: 836
diff changeset
455
859bc9e7a15d Extended repo2db mapper with group creation via directory structures
Marcin Kuzminski <marcin@python-works.com>
parents: 836
diff changeset
456
859bc9e7a15d Extended repo2db mapper with group creation via directory structures
Marcin Kuzminski <marcin@python-works.com>
parents: 836
diff changeset
457 def __init__(self, group_name='', parent_group=None):
859bc9e7a15d Extended repo2db mapper with group creation via directory structures
Marcin Kuzminski <marcin@python-works.com>
parents: 836
diff changeset
458 self.group_name = group_name
859bc9e7a15d Extended repo2db mapper with group creation via directory structures
Marcin Kuzminski <marcin@python-works.com>
parents: 836
diff changeset
459 self.parent_group = parent_group
859bc9e7a15d Extended repo2db mapper with group creation via directory structures
Marcin Kuzminski <marcin@python-works.com>
parents: 836
diff changeset
460
859bc9e7a15d Extended repo2db mapper with group creation via directory structures
Marcin Kuzminski <marcin@python-works.com>
parents: 836
diff changeset
461 def __repr__(self):
859bc9e7a15d Extended repo2db mapper with group creation via directory structures
Marcin Kuzminski <marcin@python-works.com>
parents: 836
diff changeset
462 return "<%s('%s:%s')>" % (self.__class__.__name__, self.group_id,
859bc9e7a15d Extended repo2db mapper with group creation via directory structures
Marcin Kuzminski <marcin@python-works.com>
parents: 836
diff changeset
463 self.group_name)
631
05528ad948c4 Hacking for git support,and new faster repo scan
Marcin Kuzminski <marcin@python-works.com>
parents: 549
diff changeset
464
1346
cf78d302d441 #47 implemented deleting of empty groups. Fixed problem with full paths on nested groups
Marcin Kuzminski <marcin@python-works.com>
parents: 1345
diff changeset
465 @classmethod
cf78d302d441 #47 implemented deleting of empty groups. Fixed problem with full paths on nested groups
Marcin Kuzminski <marcin@python-works.com>
parents: 1345
diff changeset
466 def url_sep(cls):
cf78d302d441 #47 implemented deleting of empty groups. Fixed problem with full paths on nested groups
Marcin Kuzminski <marcin@python-works.com>
parents: 1345
diff changeset
467 return '/'
cf78d302d441 #47 implemented deleting of empty groups. Fixed problem with full paths on nested groups
Marcin Kuzminski <marcin@python-works.com>
parents: 1345
diff changeset
468
1159
187a924ed653 Changes for repo groups
Marcin Kuzminski <marcin@python-works.com>
parents: 1155
diff changeset
469 @property
187a924ed653 Changes for repo groups
Marcin Kuzminski <marcin@python-works.com>
parents: 1155
diff changeset
470 def parents(self):
1349
526120c77a38 #47 added editing of groups, and moving them between. Added check constraint for groups
Marcin Kuzminski <marcin@python-works.com>
parents: 1346
diff changeset
471 parents_limit = 5
1159
187a924ed653 Changes for repo groups
Marcin Kuzminski <marcin@python-works.com>
parents: 1155
diff changeset
472 groups = []
187a924ed653 Changes for repo groups
Marcin Kuzminski <marcin@python-works.com>
parents: 1155
diff changeset
473 if self.parent_group is None:
187a924ed653 Changes for repo groups
Marcin Kuzminski <marcin@python-works.com>
parents: 1155
diff changeset
474 return groups
187a924ed653 Changes for repo groups
Marcin Kuzminski <marcin@python-works.com>
parents: 1155
diff changeset
475 cur_gr = self.parent_group
187a924ed653 Changes for repo groups
Marcin Kuzminski <marcin@python-works.com>
parents: 1155
diff changeset
476 groups.insert(0, cur_gr)
1349
526120c77a38 #47 added editing of groups, and moving them between. Added check constraint for groups
Marcin Kuzminski <marcin@python-works.com>
parents: 1346
diff changeset
477 cnt = 0
1159
187a924ed653 Changes for repo groups
Marcin Kuzminski <marcin@python-works.com>
parents: 1155
diff changeset
478 while 1:
1349
526120c77a38 #47 added editing of groups, and moving them between. Added check constraint for groups
Marcin Kuzminski <marcin@python-works.com>
parents: 1346
diff changeset
479 cnt += 1
1159
187a924ed653 Changes for repo groups
Marcin Kuzminski <marcin@python-works.com>
parents: 1155
diff changeset
480 gr = getattr(cur_gr, 'parent_group', None)
187a924ed653 Changes for repo groups
Marcin Kuzminski <marcin@python-works.com>
parents: 1155
diff changeset
481 cur_gr = cur_gr.parent_group
187a924ed653 Changes for repo groups
Marcin Kuzminski <marcin@python-works.com>
parents: 1155
diff changeset
482 if gr is None:
187a924ed653 Changes for repo groups
Marcin Kuzminski <marcin@python-works.com>
parents: 1155
diff changeset
483 break
1349
526120c77a38 #47 added editing of groups, and moving them between. Added check constraint for groups
Marcin Kuzminski <marcin@python-works.com>
parents: 1346
diff changeset
484 if cnt == parents_limit:
526120c77a38 #47 added editing of groups, and moving them between. Added check constraint for groups
Marcin Kuzminski <marcin@python-works.com>
parents: 1346
diff changeset
485 # this will prevent accidental infinit loops
526120c77a38 #47 added editing of groups, and moving them between. Added check constraint for groups
Marcin Kuzminski <marcin@python-works.com>
parents: 1346
diff changeset
486 log.error('group nested more than %s' %
526120c77a38 #47 added editing of groups, and moving them between. Added check constraint for groups
Marcin Kuzminski <marcin@python-works.com>
parents: 1346
diff changeset
487 parents_limit)
526120c77a38 #47 added editing of groups, and moving them between. Added check constraint for groups
Marcin Kuzminski <marcin@python-works.com>
parents: 1346
diff changeset
488 break
526120c77a38 #47 added editing of groups, and moving them between. Added check constraint for groups
Marcin Kuzminski <marcin@python-works.com>
parents: 1346
diff changeset
489
1159
187a924ed653 Changes for repo groups
Marcin Kuzminski <marcin@python-works.com>
parents: 1155
diff changeset
490 groups.insert(0, gr)
187a924ed653 Changes for repo groups
Marcin Kuzminski <marcin@python-works.com>
parents: 1155
diff changeset
491 return groups
187a924ed653 Changes for repo groups
Marcin Kuzminski <marcin@python-works.com>
parents: 1155
diff changeset
492
1323
a7a772ea7b95 fixed saving settings on repositories inside groups, also fixes #187
Marcin Kuzminski <marcin@python-works.com>
parents: 1301
diff changeset
493
a7a772ea7b95 fixed saving settings on repositories inside groups, also fixes #187
Marcin Kuzminski <marcin@python-works.com>
parents: 1301
diff changeset
494 @property
a7a772ea7b95 fixed saving settings on repositories inside groups, also fixes #187
Marcin Kuzminski <marcin@python-works.com>
parents: 1301
diff changeset
495 def full_path(self):
1346
cf78d302d441 #47 implemented deleting of empty groups. Fixed problem with full paths on nested groups
Marcin Kuzminski <marcin@python-works.com>
parents: 1345
diff changeset
496 return Group.url_sep().join([g.group_name for g in self.parents] +
1323
a7a772ea7b95 fixed saving settings on repositories inside groups, also fixes #187
Marcin Kuzminski <marcin@python-works.com>
parents: 1301
diff changeset
497 [self.group_name])
a7a772ea7b95 fixed saving settings on repositories inside groups, also fixes #187
Marcin Kuzminski <marcin@python-works.com>
parents: 1301
diff changeset
498
1193
523382549c45 Added repo group page showing what reposiories are inside a group
Marcin Kuzminski <marcin@python-works.com>
parents: 1159
diff changeset
499 @property
523382549c45 Added repo group page showing what reposiories are inside a group
Marcin Kuzminski <marcin@python-works.com>
parents: 1159
diff changeset
500 def repositories(self):
1343
a04fe5986109 #47 implemented basic gui for browsing repo groups
Marcin Kuzminski <marcin@python-works.com>
parents: 1325
diff changeset
501 return Session.query(Repository).filter(Repository.group == self)
1193
523382549c45 Added repo group page showing what reposiories are inside a group
Marcin Kuzminski <marcin@python-works.com>
parents: 1159
diff changeset
502
1065
5d676b6ab71c Moved BaseModel into base class for declarative base. Added some handy methods into
Marcin Kuzminski <marcin@python-works.com>
parents: 1039
diff changeset
503 class Permission(Base):
226
c6526b7531e9 rewritten db manage script to use sqlalchemy. Fixed sqlalchemy models to more generic.
Marcin Kuzminski <marcin@python-works.com>
parents: 89
diff changeset
504 __tablename__ = 'permissions'
1360
1f47adeb67c2 Bumped sqlalchemy version to 0.7, replaced timerproxy with new event system for sqlalchemy.
Marcin Kuzminski <marcin@python-works.com>
parents: 1349
diff changeset
505 __table_args__ = {'extend_existing':True}
780
92fa9c3414d0 fixed models for compatibility with database systems
Marcin Kuzminski <marcin@python-works.com>
parents: 759
diff changeset
506 permission_id = Column("permission_id", Integer(), nullable=False, unique=True, default=None, primary_key=True)
1113
c1eda8ec4a46 added clone_uri,api_key into models. Fixed models for mysql compatibilty
Marcin Kuzminski <marcin@python-works.com>
parents: 1088
diff changeset
507 permission_name = Column("permission_name", String(length=255, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None)
c1eda8ec4a46 added clone_uri,api_key into models. Fixed models for mysql compatibilty
Marcin Kuzminski <marcin@python-works.com>
parents: 1088
diff changeset
508 permission_longname = Column("permission_longname", String(length=255, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None)
631
05528ad948c4 Hacking for git support,and new faster repo scan
Marcin Kuzminski <marcin@python-works.com>
parents: 549
diff changeset
509
232
37a832dc4a82 some beaker cache changes, and added repr to models
Marcin Kuzminski <marcin@python-works.com>
parents: 226
diff changeset
510 def __repr__(self):
878
859bc9e7a15d Extended repo2db mapper with group creation via directory structures
Marcin Kuzminski <marcin@python-works.com>
parents: 836
diff changeset
511 return "<%s('%s:%s')>" % (self.__class__.__name__,
880
014071a745da removed unicode from models string params
Marcin Kuzminski <marcin@python-works.com>
parents: 879
diff changeset
512 self.permission_id, self.permission_name)
296
29370bb76fa6 first permissions commit: added permission managment on repository edit. Changed db rmissions, validators.
Marcin Kuzminski <marcin@python-works.com>
parents: 265
diff changeset
513
1266
a1bcfe58a1ab Fixed #161 form saves the create repository permission.
Marcin Kuzminski <marcin@python-works.com>
parents: 1206
diff changeset
514 @classmethod
a1bcfe58a1ab Fixed #161 form saves the create repository permission.
Marcin Kuzminski <marcin@python-works.com>
parents: 1206
diff changeset
515 def get_by_key(cls, key):
a1bcfe58a1ab Fixed #161 form saves the create repository permission.
Marcin Kuzminski <marcin@python-works.com>
parents: 1206
diff changeset
516 return Session.query(cls).filter(cls.permission_name == key).scalar()
a1bcfe58a1ab Fixed #161 form saves the create repository permission.
Marcin Kuzminski <marcin@python-works.com>
parents: 1206
diff changeset
517
1065
5d676b6ab71c Moved BaseModel into base class for declarative base. Added some handy methods into
Marcin Kuzminski <marcin@python-works.com>
parents: 1039
diff changeset
518 class RepoToPerm(Base):
296
29370bb76fa6 first permissions commit: added permission managment on repository edit. Changed db rmissions, validators.
Marcin Kuzminski <marcin@python-works.com>
parents: 265
diff changeset
519 __tablename__ = 'repo_to_perm'
1360
1f47adeb67c2 Bumped sqlalchemy version to 0.7, replaced timerproxy with new event system for sqlalchemy.
Marcin Kuzminski <marcin@python-works.com>
parents: 1349
diff changeset
520 __table_args__ = (UniqueConstraint('user_id', 'repository_id'), {'extend_existing':True})
780
92fa9c3414d0 fixed models for compatibility with database systems
Marcin Kuzminski <marcin@python-works.com>
parents: 759
diff changeset
521 repo_to_perm_id = Column("repo_to_perm_id", Integer(), nullable=False, unique=True, default=None, primary_key=True)
880
014071a745da removed unicode from models string params
Marcin Kuzminski <marcin@python-works.com>
parents: 879
diff changeset
522 user_id = Column("user_id", Integer(), ForeignKey('users.user_id'), nullable=False, unique=None, default=None)
014071a745da removed unicode from models string params
Marcin Kuzminski <marcin@python-works.com>
parents: 879
diff changeset
523 permission_id = Column("permission_id", Integer(), ForeignKey('permissions.permission_id'), nullable=False, unique=None, default=None)
014071a745da removed unicode from models string params
Marcin Kuzminski <marcin@python-works.com>
parents: 879
diff changeset
524 repository_id = Column("repository_id", Integer(), ForeignKey('repositories.repo_id'), nullable=False, unique=None, default=None)
631
05528ad948c4 Hacking for git support,and new faster repo scan
Marcin Kuzminski <marcin@python-works.com>
parents: 549
diff changeset
525
972
2c8fd84935a4 #56 implemented users groups editing,
Marcin Kuzminski <marcin@python-works.com>
parents: 962
diff changeset
526 user = relationship('User')
2c8fd84935a4 #56 implemented users groups editing,
Marcin Kuzminski <marcin@python-works.com>
parents: 962
diff changeset
527 permission = relationship('Permission')
2c8fd84935a4 #56 implemented users groups editing,
Marcin Kuzminski <marcin@python-works.com>
parents: 962
diff changeset
528 repository = relationship('Repository')
399
f5c1eec9f376 rename repo2perm into repo_to_perm
Marcin Kuzminski <marcin@python-works.com>
parents: 392
diff changeset
529
1065
5d676b6ab71c Moved BaseModel into base class for declarative base. Added some handy methods into
Marcin Kuzminski <marcin@python-works.com>
parents: 1039
diff changeset
530 class UserToPerm(Base):
399
f5c1eec9f376 rename repo2perm into repo_to_perm
Marcin Kuzminski <marcin@python-works.com>
parents: 392
diff changeset
531 __tablename__ = 'user_to_perm'
1360
1f47adeb67c2 Bumped sqlalchemy version to 0.7, replaced timerproxy with new event system for sqlalchemy.
Marcin Kuzminski <marcin@python-works.com>
parents: 1349
diff changeset
532 __table_args__ = (UniqueConstraint('user_id', 'permission_id'), {'extend_existing':True})
780
92fa9c3414d0 fixed models for compatibility with database systems
Marcin Kuzminski <marcin@python-works.com>
parents: 759
diff changeset
533 user_to_perm_id = Column("user_to_perm_id", Integer(), nullable=False, unique=True, default=None, primary_key=True)
880
014071a745da removed unicode from models string params
Marcin Kuzminski <marcin@python-works.com>
parents: 879
diff changeset
534 user_id = Column("user_id", Integer(), ForeignKey('users.user_id'), nullable=False, unique=None, default=None)
014071a745da removed unicode from models string params
Marcin Kuzminski <marcin@python-works.com>
parents: 879
diff changeset
535 permission_id = Column("permission_id", Integer(), ForeignKey('permissions.permission_id'), nullable=False, unique=None, default=None)
631
05528ad948c4 Hacking for git support,and new faster repo scan
Marcin Kuzminski <marcin@python-works.com>
parents: 549
diff changeset
536
972
2c8fd84935a4 #56 implemented users groups editing,
Marcin Kuzminski <marcin@python-works.com>
parents: 962
diff changeset
537 user = relationship('User')
2c8fd84935a4 #56 implemented users groups editing,
Marcin Kuzminski <marcin@python-works.com>
parents: 962
diff changeset
538 permission = relationship('Permission')
399
f5c1eec9f376 rename repo2perm into repo_to_perm
Marcin Kuzminski <marcin@python-works.com>
parents: 392
diff changeset
539
1266
a1bcfe58a1ab Fixed #161 form saves the create repository permission.
Marcin Kuzminski <marcin@python-works.com>
parents: 1206
diff changeset
540 @classmethod
a1bcfe58a1ab Fixed #161 form saves the create repository permission.
Marcin Kuzminski <marcin@python-works.com>
parents: 1206
diff changeset
541 def has_perm(cls, user_id, perm):
a1bcfe58a1ab Fixed #161 form saves the create repository permission.
Marcin Kuzminski <marcin@python-works.com>
parents: 1206
diff changeset
542 if not isinstance(perm, Permission):
a1bcfe58a1ab Fixed #161 form saves the create repository permission.
Marcin Kuzminski <marcin@python-works.com>
parents: 1206
diff changeset
543 raise Exception('perm needs to be an instance of Permission class')
a1bcfe58a1ab Fixed #161 form saves the create repository permission.
Marcin Kuzminski <marcin@python-works.com>
parents: 1206
diff changeset
544
a1bcfe58a1ab Fixed #161 form saves the create repository permission.
Marcin Kuzminski <marcin@python-works.com>
parents: 1206
diff changeset
545 return Session.query(cls).filter(cls.user_id == user_id)\
a1bcfe58a1ab Fixed #161 form saves the create repository permission.
Marcin Kuzminski <marcin@python-works.com>
parents: 1206
diff changeset
546 .filter(cls.permission == perm).scalar() is not None
a1bcfe58a1ab Fixed #161 form saves the create repository permission.
Marcin Kuzminski <marcin@python-works.com>
parents: 1206
diff changeset
547
a1bcfe58a1ab Fixed #161 form saves the create repository permission.
Marcin Kuzminski <marcin@python-works.com>
parents: 1206
diff changeset
548 @classmethod
a1bcfe58a1ab Fixed #161 form saves the create repository permission.
Marcin Kuzminski <marcin@python-works.com>
parents: 1206
diff changeset
549 def grant_perm(cls, user_id, perm):
a1bcfe58a1ab Fixed #161 form saves the create repository permission.
Marcin Kuzminski <marcin@python-works.com>
parents: 1206
diff changeset
550 if not isinstance(perm, Permission):
a1bcfe58a1ab Fixed #161 form saves the create repository permission.
Marcin Kuzminski <marcin@python-works.com>
parents: 1206
diff changeset
551 raise Exception('perm needs to be an instance of Permission class')
a1bcfe58a1ab Fixed #161 form saves the create repository permission.
Marcin Kuzminski <marcin@python-works.com>
parents: 1206
diff changeset
552
a1bcfe58a1ab Fixed #161 form saves the create repository permission.
Marcin Kuzminski <marcin@python-works.com>
parents: 1206
diff changeset
553 new = cls()
a1bcfe58a1ab Fixed #161 form saves the create repository permission.
Marcin Kuzminski <marcin@python-works.com>
parents: 1206
diff changeset
554 new.user_id = user_id
a1bcfe58a1ab Fixed #161 form saves the create repository permission.
Marcin Kuzminski <marcin@python-works.com>
parents: 1206
diff changeset
555 new.permission = perm
a1bcfe58a1ab Fixed #161 form saves the create repository permission.
Marcin Kuzminski <marcin@python-works.com>
parents: 1206
diff changeset
556 try:
a1bcfe58a1ab Fixed #161 form saves the create repository permission.
Marcin Kuzminski <marcin@python-works.com>
parents: 1206
diff changeset
557 Session.add(new)
a1bcfe58a1ab Fixed #161 form saves the create repository permission.
Marcin Kuzminski <marcin@python-works.com>
parents: 1206
diff changeset
558 Session.commit()
a1bcfe58a1ab Fixed #161 form saves the create repository permission.
Marcin Kuzminski <marcin@python-works.com>
parents: 1206
diff changeset
559 except:
a1bcfe58a1ab Fixed #161 form saves the create repository permission.
Marcin Kuzminski <marcin@python-works.com>
parents: 1206
diff changeset
560 Session.rollback()
a1bcfe58a1ab Fixed #161 form saves the create repository permission.
Marcin Kuzminski <marcin@python-works.com>
parents: 1206
diff changeset
561
a1bcfe58a1ab Fixed #161 form saves the create repository permission.
Marcin Kuzminski <marcin@python-works.com>
parents: 1206
diff changeset
562
a1bcfe58a1ab Fixed #161 form saves the create repository permission.
Marcin Kuzminski <marcin@python-works.com>
parents: 1206
diff changeset
563 @classmethod
a1bcfe58a1ab Fixed #161 form saves the create repository permission.
Marcin Kuzminski <marcin@python-works.com>
parents: 1206
diff changeset
564 def revoke_perm(cls, user_id, perm):
a1bcfe58a1ab Fixed #161 form saves the create repository permission.
Marcin Kuzminski <marcin@python-works.com>
parents: 1206
diff changeset
565 if not isinstance(perm, Permission):
a1bcfe58a1ab Fixed #161 form saves the create repository permission.
Marcin Kuzminski <marcin@python-works.com>
parents: 1206
diff changeset
566 raise Exception('perm needs to be an instance of Permission class')
a1bcfe58a1ab Fixed #161 form saves the create repository permission.
Marcin Kuzminski <marcin@python-works.com>
parents: 1206
diff changeset
567
a1bcfe58a1ab Fixed #161 form saves the create repository permission.
Marcin Kuzminski <marcin@python-works.com>
parents: 1206
diff changeset
568 try:
a1bcfe58a1ab Fixed #161 form saves the create repository permission.
Marcin Kuzminski <marcin@python-works.com>
parents: 1206
diff changeset
569 Session.query(cls).filter(cls.user_id == user_id)\
a1bcfe58a1ab Fixed #161 form saves the create repository permission.
Marcin Kuzminski <marcin@python-works.com>
parents: 1206
diff changeset
570 .filter(cls.permission == perm).delete()
a1bcfe58a1ab Fixed #161 form saves the create repository permission.
Marcin Kuzminski <marcin@python-works.com>
parents: 1206
diff changeset
571 Session.commit()
a1bcfe58a1ab Fixed #161 form saves the create repository permission.
Marcin Kuzminski <marcin@python-works.com>
parents: 1206
diff changeset
572 except:
a1bcfe58a1ab Fixed #161 form saves the create repository permission.
Marcin Kuzminski <marcin@python-works.com>
parents: 1206
diff changeset
573 Session.rollback()
1014
6fdc3ff65fce #56 added assignments of users groups into repository
Marcin Kuzminski <marcin@python-works.com>
parents: 1000
diff changeset
574
1271
aa7e45ad0cea Fixed permissions for users groups, group can have create repo permission now.
Marcin Kuzminski <marcin@python-works.com>
parents: 1266
diff changeset
575 class UsersGroupRepoToPerm(Base):
aa7e45ad0cea Fixed permissions for users groups, group can have create repo permission now.
Marcin Kuzminski <marcin@python-works.com>
parents: 1266
diff changeset
576 __tablename__ = 'users_group_repo_to_perm'
1376
3fbc09ad1faf fixes issues #202, bad db constraint made impossible to attach same group more than one time.
Marcin Kuzminski <marcin@python-works.com>
parents: 1369
diff changeset
577 __table_args__ = (UniqueConstraint('repository_id', 'users_group_id', 'permission_id'), {'extend_existing':True})
958
7d1483f3170b added user group to perm table
Marcin Kuzminski <marcin@python-works.com>
parents: 956
diff changeset
578 users_group_to_perm_id = Column("users_group_to_perm_id", Integer(), nullable=False, unique=True, default=None, primary_key=True)
959
fff21c9b075c #56 fixed found bugs, implemented adding of new group + forms+validators
Marcin Kuzminski <marcin@python-works.com>
parents: 958
diff changeset
579 users_group_id = Column("users_group_id", Integer(), ForeignKey('users_groups.users_group_id'), nullable=False, unique=None, default=None)
958
7d1483f3170b added user group to perm table
Marcin Kuzminski <marcin@python-works.com>
parents: 956
diff changeset
580 permission_id = Column("permission_id", Integer(), ForeignKey('permissions.permission_id'), nullable=False, unique=None, default=None)
1014
6fdc3ff65fce #56 added assignments of users groups into repository
Marcin Kuzminski <marcin@python-works.com>
parents: 1000
diff changeset
581 repository_id = Column("repository_id", Integer(), ForeignKey('repositories.repo_id'), nullable=False, unique=None, default=None)
958
7d1483f3170b added user group to perm table
Marcin Kuzminski <marcin@python-works.com>
parents: 956
diff changeset
582
972
2c8fd84935a4 #56 implemented users groups editing,
Marcin Kuzminski <marcin@python-works.com>
parents: 962
diff changeset
583 users_group = relationship('UsersGroup')
2c8fd84935a4 #56 implemented users groups editing,
Marcin Kuzminski <marcin@python-works.com>
parents: 962
diff changeset
584 permission = relationship('Permission')
1014
6fdc3ff65fce #56 added assignments of users groups into repository
Marcin Kuzminski <marcin@python-works.com>
parents: 1000
diff changeset
585 repository = relationship('Repository')
958
7d1483f3170b added user group to perm table
Marcin Kuzminski <marcin@python-works.com>
parents: 956
diff changeset
586
1271
aa7e45ad0cea Fixed permissions for users groups, group can have create repo permission now.
Marcin Kuzminski <marcin@python-works.com>
parents: 1266
diff changeset
587
aa7e45ad0cea Fixed permissions for users groups, group can have create repo permission now.
Marcin Kuzminski <marcin@python-works.com>
parents: 1266
diff changeset
588 class UsersGroupToPerm(Base):
aa7e45ad0cea Fixed permissions for users groups, group can have create repo permission now.
Marcin Kuzminski <marcin@python-works.com>
parents: 1266
diff changeset
589 __tablename__ = 'users_group_to_perm'
aa7e45ad0cea Fixed permissions for users groups, group can have create repo permission now.
Marcin Kuzminski <marcin@python-works.com>
parents: 1266
diff changeset
590 users_group_to_perm_id = Column("users_group_to_perm_id", Integer(), nullable=False, unique=True, default=None, primary_key=True)
aa7e45ad0cea Fixed permissions for users groups, group can have create repo permission now.
Marcin Kuzminski <marcin@python-works.com>
parents: 1266
diff changeset
591 users_group_id = Column("users_group_id", Integer(), ForeignKey('users_groups.users_group_id'), nullable=False, unique=None, default=None)
aa7e45ad0cea Fixed permissions for users groups, group can have create repo permission now.
Marcin Kuzminski <marcin@python-works.com>
parents: 1266
diff changeset
592 permission_id = Column("permission_id", Integer(), ForeignKey('permissions.permission_id'), nullable=False, unique=None, default=None)
aa7e45ad0cea Fixed permissions for users groups, group can have create repo permission now.
Marcin Kuzminski <marcin@python-works.com>
parents: 1266
diff changeset
593
aa7e45ad0cea Fixed permissions for users groups, group can have create repo permission now.
Marcin Kuzminski <marcin@python-works.com>
parents: 1266
diff changeset
594 users_group = relationship('UsersGroup')
aa7e45ad0cea Fixed permissions for users groups, group can have create repo permission now.
Marcin Kuzminski <marcin@python-works.com>
parents: 1266
diff changeset
595 permission = relationship('Permission')
aa7e45ad0cea Fixed permissions for users groups, group can have create repo permission now.
Marcin Kuzminski <marcin@python-works.com>
parents: 1266
diff changeset
596
aa7e45ad0cea Fixed permissions for users groups, group can have create repo permission now.
Marcin Kuzminski <marcin@python-works.com>
parents: 1266
diff changeset
597
aa7e45ad0cea Fixed permissions for users groups, group can have create repo permission now.
Marcin Kuzminski <marcin@python-works.com>
parents: 1266
diff changeset
598 @classmethod
aa7e45ad0cea Fixed permissions for users groups, group can have create repo permission now.
Marcin Kuzminski <marcin@python-works.com>
parents: 1266
diff changeset
599 def has_perm(cls, users_group_id, perm):
aa7e45ad0cea Fixed permissions for users groups, group can have create repo permission now.
Marcin Kuzminski <marcin@python-works.com>
parents: 1266
diff changeset
600 if not isinstance(perm, Permission):
aa7e45ad0cea Fixed permissions for users groups, group can have create repo permission now.
Marcin Kuzminski <marcin@python-works.com>
parents: 1266
diff changeset
601 raise Exception('perm needs to be an instance of Permission class')
aa7e45ad0cea Fixed permissions for users groups, group can have create repo permission now.
Marcin Kuzminski <marcin@python-works.com>
parents: 1266
diff changeset
602
aa7e45ad0cea Fixed permissions for users groups, group can have create repo permission now.
Marcin Kuzminski <marcin@python-works.com>
parents: 1266
diff changeset
603 return Session.query(cls).filter(cls.users_group_id ==
aa7e45ad0cea Fixed permissions for users groups, group can have create repo permission now.
Marcin Kuzminski <marcin@python-works.com>
parents: 1266
diff changeset
604 users_group_id)\
aa7e45ad0cea Fixed permissions for users groups, group can have create repo permission now.
Marcin Kuzminski <marcin@python-works.com>
parents: 1266
diff changeset
605 .filter(cls.permission == perm)\
aa7e45ad0cea Fixed permissions for users groups, group can have create repo permission now.
Marcin Kuzminski <marcin@python-works.com>
parents: 1266
diff changeset
606 .scalar() is not None
aa7e45ad0cea Fixed permissions for users groups, group can have create repo permission now.
Marcin Kuzminski <marcin@python-works.com>
parents: 1266
diff changeset
607
aa7e45ad0cea Fixed permissions for users groups, group can have create repo permission now.
Marcin Kuzminski <marcin@python-works.com>
parents: 1266
diff changeset
608 @classmethod
aa7e45ad0cea Fixed permissions for users groups, group can have create repo permission now.
Marcin Kuzminski <marcin@python-works.com>
parents: 1266
diff changeset
609 def grant_perm(cls, users_group_id, perm):
aa7e45ad0cea Fixed permissions for users groups, group can have create repo permission now.
Marcin Kuzminski <marcin@python-works.com>
parents: 1266
diff changeset
610 if not isinstance(perm, Permission):
aa7e45ad0cea Fixed permissions for users groups, group can have create repo permission now.
Marcin Kuzminski <marcin@python-works.com>
parents: 1266
diff changeset
611 raise Exception('perm needs to be an instance of Permission class')
aa7e45ad0cea Fixed permissions for users groups, group can have create repo permission now.
Marcin Kuzminski <marcin@python-works.com>
parents: 1266
diff changeset
612
aa7e45ad0cea Fixed permissions for users groups, group can have create repo permission now.
Marcin Kuzminski <marcin@python-works.com>
parents: 1266
diff changeset
613 new = cls()
aa7e45ad0cea Fixed permissions for users groups, group can have create repo permission now.
Marcin Kuzminski <marcin@python-works.com>
parents: 1266
diff changeset
614 new.users_group_id = users_group_id
aa7e45ad0cea Fixed permissions for users groups, group can have create repo permission now.
Marcin Kuzminski <marcin@python-works.com>
parents: 1266
diff changeset
615 new.permission = perm
aa7e45ad0cea Fixed permissions for users groups, group can have create repo permission now.
Marcin Kuzminski <marcin@python-works.com>
parents: 1266
diff changeset
616 try:
aa7e45ad0cea Fixed permissions for users groups, group can have create repo permission now.
Marcin Kuzminski <marcin@python-works.com>
parents: 1266
diff changeset
617 Session.add(new)
aa7e45ad0cea Fixed permissions for users groups, group can have create repo permission now.
Marcin Kuzminski <marcin@python-works.com>
parents: 1266
diff changeset
618 Session.commit()
aa7e45ad0cea Fixed permissions for users groups, group can have create repo permission now.
Marcin Kuzminski <marcin@python-works.com>
parents: 1266
diff changeset
619 except:
aa7e45ad0cea Fixed permissions for users groups, group can have create repo permission now.
Marcin Kuzminski <marcin@python-works.com>
parents: 1266
diff changeset
620 Session.rollback()
aa7e45ad0cea Fixed permissions for users groups, group can have create repo permission now.
Marcin Kuzminski <marcin@python-works.com>
parents: 1266
diff changeset
621
aa7e45ad0cea Fixed permissions for users groups, group can have create repo permission now.
Marcin Kuzminski <marcin@python-works.com>
parents: 1266
diff changeset
622
aa7e45ad0cea Fixed permissions for users groups, group can have create repo permission now.
Marcin Kuzminski <marcin@python-works.com>
parents: 1266
diff changeset
623 @classmethod
aa7e45ad0cea Fixed permissions for users groups, group can have create repo permission now.
Marcin Kuzminski <marcin@python-works.com>
parents: 1266
diff changeset
624 def revoke_perm(cls, users_group_id, perm):
aa7e45ad0cea Fixed permissions for users groups, group can have create repo permission now.
Marcin Kuzminski <marcin@python-works.com>
parents: 1266
diff changeset
625 if not isinstance(perm, Permission):
aa7e45ad0cea Fixed permissions for users groups, group can have create repo permission now.
Marcin Kuzminski <marcin@python-works.com>
parents: 1266
diff changeset
626 raise Exception('perm needs to be an instance of Permission class')
aa7e45ad0cea Fixed permissions for users groups, group can have create repo permission now.
Marcin Kuzminski <marcin@python-works.com>
parents: 1266
diff changeset
627
aa7e45ad0cea Fixed permissions for users groups, group can have create repo permission now.
Marcin Kuzminski <marcin@python-works.com>
parents: 1266
diff changeset
628 try:
aa7e45ad0cea Fixed permissions for users groups, group can have create repo permission now.
Marcin Kuzminski <marcin@python-works.com>
parents: 1266
diff changeset
629 Session.query(cls).filter(cls.users_group_id == users_group_id)\
aa7e45ad0cea Fixed permissions for users groups, group can have create repo permission now.
Marcin Kuzminski <marcin@python-works.com>
parents: 1266
diff changeset
630 .filter(cls.permission == perm).delete()
aa7e45ad0cea Fixed permissions for users groups, group can have create repo permission now.
Marcin Kuzminski <marcin@python-works.com>
parents: 1266
diff changeset
631 Session.commit()
aa7e45ad0cea Fixed permissions for users groups, group can have create repo permission now.
Marcin Kuzminski <marcin@python-works.com>
parents: 1266
diff changeset
632 except:
aa7e45ad0cea Fixed permissions for users groups, group can have create repo permission now.
Marcin Kuzminski <marcin@python-works.com>
parents: 1266
diff changeset
633 Session.rollback()
aa7e45ad0cea Fixed permissions for users groups, group can have create repo permission now.
Marcin Kuzminski <marcin@python-works.com>
parents: 1266
diff changeset
634
aa7e45ad0cea Fixed permissions for users groups, group can have create repo permission now.
Marcin Kuzminski <marcin@python-works.com>
parents: 1266
diff changeset
635
1065
5d676b6ab71c Moved BaseModel into base class for declarative base. Added some handy methods into
Marcin Kuzminski <marcin@python-works.com>
parents: 1039
diff changeset
636 class GroupToPerm(Base):
879
b19341623d48 added group to perm mapping table
Marcin Kuzminski <marcin@python-works.com>
parents: 878
diff changeset
637 __tablename__ = 'group_to_perm'
1360
1f47adeb67c2 Bumped sqlalchemy version to 0.7, replaced timerproxy with new event system for sqlalchemy.
Marcin Kuzminski <marcin@python-works.com>
parents: 1349
diff changeset
638 __table_args__ = (UniqueConstraint('group_id', 'permission_id'), {'extend_existing':True})
879
b19341623d48 added group to perm mapping table
Marcin Kuzminski <marcin@python-works.com>
parents: 878
diff changeset
639
b19341623d48 added group to perm mapping table
Marcin Kuzminski <marcin@python-works.com>
parents: 878
diff changeset
640 group_to_perm_id = Column("group_to_perm_id", Integer(), nullable=False, unique=True, default=None, primary_key=True)
880
014071a745da removed unicode from models string params
Marcin Kuzminski <marcin@python-works.com>
parents: 879
diff changeset
641 user_id = Column("user_id", Integer(), ForeignKey('users.user_id'), nullable=False, unique=None, default=None)
014071a745da removed unicode from models string params
Marcin Kuzminski <marcin@python-works.com>
parents: 879
diff changeset
642 permission_id = Column("permission_id", Integer(), ForeignKey('permissions.permission_id'), nullable=False, unique=None, default=None)
014071a745da removed unicode from models string params
Marcin Kuzminski <marcin@python-works.com>
parents: 879
diff changeset
643 group_id = Column("group_id", Integer(), ForeignKey('groups.group_id'), nullable=False, unique=None, default=None)
879
b19341623d48 added group to perm mapping table
Marcin Kuzminski <marcin@python-works.com>
parents: 878
diff changeset
644
972
2c8fd84935a4 #56 implemented users groups editing,
Marcin Kuzminski <marcin@python-works.com>
parents: 962
diff changeset
645 user = relationship('User')
2c8fd84935a4 #56 implemented users groups editing,
Marcin Kuzminski <marcin@python-works.com>
parents: 962
diff changeset
646 permission = relationship('Permission')
2c8fd84935a4 #56 implemented users groups editing,
Marcin Kuzminski <marcin@python-works.com>
parents: 962
diff changeset
647 group = relationship('Group')
879
b19341623d48 added group to perm mapping table
Marcin Kuzminski <marcin@python-works.com>
parents: 878
diff changeset
648
1065
5d676b6ab71c Moved BaseModel into base class for declarative base. Added some handy methods into
Marcin Kuzminski <marcin@python-works.com>
parents: 1039
diff changeset
649 class Statistics(Base):
493
2256c78afe53 implemented basic autoupdating statistics fetched from database
Marcin Kuzminski <marcin@python-works.com>
parents: 473
diff changeset
650 __tablename__ = 'statistics'
1360
1f47adeb67c2 Bumped sqlalchemy version to 0.7, replaced timerproxy with new event system for sqlalchemy.
Marcin Kuzminski <marcin@python-works.com>
parents: 1349
diff changeset
651 __table_args__ = (UniqueConstraint('repository_id'), {'extend_existing':True})
780
92fa9c3414d0 fixed models for compatibility with database systems
Marcin Kuzminski <marcin@python-works.com>
parents: 759
diff changeset
652 stat_id = Column("stat_id", Integer(), nullable=False, unique=True, default=None, primary_key=True)
880
014071a745da removed unicode from models string params
Marcin Kuzminski <marcin@python-works.com>
parents: 879
diff changeset
653 repository_id = Column("repository_id", Integer(), ForeignKey('repositories.repo_id'), nullable=False, unique=True, default=None)
780
92fa9c3414d0 fixed models for compatibility with database systems
Marcin Kuzminski <marcin@python-works.com>
parents: 759
diff changeset
654 stat_on_revision = Column("stat_on_revision", Integer(), nullable=False)
1113
c1eda8ec4a46 added clone_uri,api_key into models. Fixed models for mysql compatibilty
Marcin Kuzminski <marcin@python-works.com>
parents: 1088
diff changeset
655 commit_activity = Column("commit_activity", LargeBinary(1000000), nullable=False)#JSON data
780
92fa9c3414d0 fixed models for compatibility with database systems
Marcin Kuzminski <marcin@python-works.com>
parents: 759
diff changeset
656 commit_activity_combined = Column("commit_activity_combined", LargeBinary(), nullable=False)#JSON data
1113
c1eda8ec4a46 added clone_uri,api_key into models. Fixed models for mysql compatibilty
Marcin Kuzminski <marcin@python-works.com>
parents: 1088
diff changeset
657 languages = Column("languages", LargeBinary(1000000), nullable=False)#JSON data
631
05528ad948c4 Hacking for git support,and new faster repo scan
Marcin Kuzminski <marcin@python-works.com>
parents: 549
diff changeset
658
972
2c8fd84935a4 #56 implemented users groups editing,
Marcin Kuzminski <marcin@python-works.com>
parents: 962
diff changeset
659 repository = relationship('Repository', single_parent=True)
399
f5c1eec9f376 rename repo2perm into repo_to_perm
Marcin Kuzminski <marcin@python-works.com>
parents: 392
diff changeset
660
1065
5d676b6ab71c Moved BaseModel into base class for declarative base. Added some handy methods into
Marcin Kuzminski <marcin@python-works.com>
parents: 1039
diff changeset
661 class UserFollowing(Base):
734
49eb69d78988 implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents: 713
diff changeset
662 __tablename__ = 'user_followings'
49eb69d78988 implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents: 713
diff changeset
663 __table_args__ = (UniqueConstraint('user_id', 'follows_repository_id'),
49eb69d78988 implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents: 713
diff changeset
664 UniqueConstraint('user_id', 'follows_user_id')
1360
1f47adeb67c2 Bumped sqlalchemy version to 0.7, replaced timerproxy with new event system for sqlalchemy.
Marcin Kuzminski <marcin@python-works.com>
parents: 1349
diff changeset
665 , {'extend_existing':True})
734
49eb69d78988 implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents: 713
diff changeset
666
780
92fa9c3414d0 fixed models for compatibility with database systems
Marcin Kuzminski <marcin@python-works.com>
parents: 759
diff changeset
667 user_following_id = Column("user_following_id", Integer(), nullable=False, unique=True, default=None, primary_key=True)
880
014071a745da removed unicode from models string params
Marcin Kuzminski <marcin@python-works.com>
parents: 879
diff changeset
668 user_id = Column("user_id", Integer(), ForeignKey('users.user_id'), nullable=False, unique=None, default=None)
014071a745da removed unicode from models string params
Marcin Kuzminski <marcin@python-works.com>
parents: 879
diff changeset
669 follows_repo_id = Column("follows_repository_id", Integer(), ForeignKey('repositories.repo_id'), nullable=True, unique=None, default=None)
014071a745da removed unicode from models string params
Marcin Kuzminski <marcin@python-works.com>
parents: 879
diff changeset
670 follows_user_id = Column("follows_user_id", Integer(), ForeignKey('users.user_id'), nullable=True, unique=None, default=None)
1279
cb216757a62d #179 Added followers page
Marcin Kuzminski <marcin@python-works.com>
parents: 1271
diff changeset
671 follows_from = Column('follows_from', DateTime(timezone=False), nullable=True, unique=None, default=datetime.datetime.now)
734
49eb69d78988 implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents: 713
diff changeset
672
972
2c8fd84935a4 #56 implemented users groups editing,
Marcin Kuzminski <marcin@python-works.com>
parents: 962
diff changeset
673 user = relationship('User', primaryjoin='User.user_id==UserFollowing.user_id')
734
49eb69d78988 implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents: 713
diff changeset
674
972
2c8fd84935a4 #56 implemented users groups editing,
Marcin Kuzminski <marcin@python-works.com>
parents: 962
diff changeset
675 follows_user = relationship('User', primaryjoin='User.user_id==UserFollowing.follows_user_id')
1000
229437211bef Optimized queries on journal, and added quick stop following action button in journal
Marcin Kuzminski <marcin@python-works.com>
parents: 994
diff changeset
676 follows_repository = relationship('Repository', order_by='Repository.repo_name')
734
49eb69d78988 implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents: 713
diff changeset
677
1279
cb216757a62d #179 Added followers page
Marcin Kuzminski <marcin@python-works.com>
parents: 1271
diff changeset
678
cb216757a62d #179 Added followers page
Marcin Kuzminski <marcin@python-works.com>
parents: 1271
diff changeset
679
cb216757a62d #179 Added followers page
Marcin Kuzminski <marcin@python-works.com>
parents: 1271
diff changeset
680 @classmethod
cb216757a62d #179 Added followers page
Marcin Kuzminski <marcin@python-works.com>
parents: 1271
diff changeset
681 def get_repo_followers(cls, repo_id):
cb216757a62d #179 Added followers page
Marcin Kuzminski <marcin@python-works.com>
parents: 1271
diff changeset
682 return Session.query(cls).filter(cls.follows_repo_id == repo_id)
cb216757a62d #179 Added followers page
Marcin Kuzminski <marcin@python-works.com>
parents: 1271
diff changeset
683
1065
5d676b6ab71c Moved BaseModel into base class for declarative base. Added some handy methods into
Marcin Kuzminski <marcin@python-works.com>
parents: 1039
diff changeset
684 class CacheInvalidation(Base):
670
e7c670cc03cb Adde table for cache invalidation
Marcin Kuzminski <marcin@python-works.com>
parents: 667
diff changeset
685 __tablename__ = 'cache_invalidation'
1360
1f47adeb67c2 Bumped sqlalchemy version to 0.7, replaced timerproxy with new event system for sqlalchemy.
Marcin Kuzminski <marcin@python-works.com>
parents: 1349
diff changeset
686 __table_args__ = (UniqueConstraint('cache_key'), {'extend_existing':True})
780
92fa9c3414d0 fixed models for compatibility with database systems
Marcin Kuzminski <marcin@python-works.com>
parents: 759
diff changeset
687 cache_id = Column("cache_id", Integer(), nullable=False, unique=True, default=None, primary_key=True)
1113
c1eda8ec4a46 added clone_uri,api_key into models. Fixed models for mysql compatibilty
Marcin Kuzminski <marcin@python-works.com>
parents: 1088
diff changeset
688 cache_key = Column("cache_key", String(length=255, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None)
c1eda8ec4a46 added clone_uri,api_key into models. Fixed models for mysql compatibilty
Marcin Kuzminski <marcin@python-works.com>
parents: 1088
diff changeset
689 cache_args = Column("cache_args", String(length=255, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None)
780
92fa9c3414d0 fixed models for compatibility with database systems
Marcin Kuzminski <marcin@python-works.com>
parents: 759
diff changeset
690 cache_active = Column("cache_active", Boolean(), nullable=True, unique=None, default=False)
670
e7c670cc03cb Adde table for cache invalidation
Marcin Kuzminski <marcin@python-works.com>
parents: 667
diff changeset
691
e7c670cc03cb Adde table for cache invalidation
Marcin Kuzminski <marcin@python-works.com>
parents: 667
diff changeset
692
692
cb0d9ce6ac5c #50 on point cache invalidation changes.
Marcin Kuzminski <marcin@python-works.com>
parents: 670
diff changeset
693 def __init__(self, cache_key, cache_args=''):
cb0d9ce6ac5c #50 on point cache invalidation changes.
Marcin Kuzminski <marcin@python-works.com>
parents: 670
diff changeset
694 self.cache_key = cache_key
cb0d9ce6ac5c #50 on point cache invalidation changes.
Marcin Kuzminski <marcin@python-works.com>
parents: 670
diff changeset
695 self.cache_args = cache_args
cb0d9ce6ac5c #50 on point cache invalidation changes.
Marcin Kuzminski <marcin@python-works.com>
parents: 670
diff changeset
696 self.cache_active = False
cb0d9ce6ac5c #50 on point cache invalidation changes.
Marcin Kuzminski <marcin@python-works.com>
parents: 670
diff changeset
697
cb0d9ce6ac5c #50 on point cache invalidation changes.
Marcin Kuzminski <marcin@python-works.com>
parents: 670
diff changeset
698 def __repr__(self):
878
859bc9e7a15d Extended repo2db mapper with group creation via directory structures
Marcin Kuzminski <marcin@python-works.com>
parents: 836
diff changeset
699 return "<%s('%s:%s')>" % (self.__class__.__name__,
859bc9e7a15d Extended repo2db mapper with group creation via directory structures
Marcin Kuzminski <marcin@python-works.com>
parents: 836
diff changeset
700 self.cache_id, self.cache_key)
834
8924ed0e4f36 added current db version into rhodecode,
Marcin Kuzminski <marcin@python-works.com>
parents: 832
diff changeset
701
1065
5d676b6ab71c Moved BaseModel into base class for declarative base. Added some handy methods into
Marcin Kuzminski <marcin@python-works.com>
parents: 1039
diff changeset
702 class DbMigrateVersion(Base):
834
8924ed0e4f36 added current db version into rhodecode,
Marcin Kuzminski <marcin@python-works.com>
parents: 832
diff changeset
703 __tablename__ = 'db_migrate_version'
1360
1f47adeb67c2 Bumped sqlalchemy version to 0.7, replaced timerproxy with new event system for sqlalchemy.
Marcin Kuzminski <marcin@python-works.com>
parents: 1349
diff changeset
704 __table_args__ = {'extend_existing':True}
834
8924ed0e4f36 added current db version into rhodecode,
Marcin Kuzminski <marcin@python-works.com>
parents: 832
diff changeset
705 repository_id = Column('repository_id', String(250), primary_key=True)
8924ed0e4f36 added current db version into rhodecode,
Marcin Kuzminski <marcin@python-works.com>
parents: 832
diff changeset
706 repository_path = Column('repository_path', Text)
8924ed0e4f36 added current db version into rhodecode,
Marcin Kuzminski <marcin@python-works.com>
parents: 832
diff changeset
707 version = Column('version', Integer)