annotate rhodecode/model/db.py @ 1733:ac54aa4200e8 beta

fixed bug with eager deletes in notifications - added relevant tests for that
author Marcin Kuzminski <marcin@python-works.com>
date Sat, 26 Nov 2011 23:40:41 +0200
parents 31e6eb2fb4b2
children d41a115d9a39
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
759
a7f50911a945 Models code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 734
diff changeset
30
658
4ecb2ffcc110 fixed imports
Marcin Kuzminski <marcin@python-works.com>
parents: 657
diff changeset
31 from sqlalchemy import *
1546
c363267bbec7 fixes #265 ldap save fails sometimes on converting attributes to booleans, added getter and setter
Marcin Kuzminski <marcin@python-works.com>
parents: 1539
diff changeset
32 from sqlalchemy.ext.hybrid import hybrid_property
1594
9dae92a65e40 fixes #288
Marcin Kuzminski <marcin@python-works.com>
parents: 1593
diff changeset
33 from sqlalchemy.orm import relationship, joinedload, class_mapper, validates
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 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
35
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
36 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
37 from vcs.utils.helpers import get_scm
1500
256e729a94cd Extended API
Marcin Kuzminski <marcin@python-works.com>
parents: 1466
diff changeset
38 from vcs.exceptions import VCSError
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
39 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
40
1723
64e91067b996 - refactoring to overcome poor usage of global pylons config
Marcin Kuzminski <marcin@python-works.com>
parents: 1717
diff changeset
41 from rhodecode.lib import str2bool, safe_str, get_changeset_safe, safe_unicode
1436
88d13c1c6a55 removed users_group controller in replace for model methods,
Marcin Kuzminski <marcin@python-works.com>
parents: 1435
diff changeset
42 from rhodecode.lib.exceptions import UsersGroupsAssignedException
1514
87ec80c280bb fixed issues with python2.5
Marcin Kuzminski <marcin@python-works.com>
parents: 1508
diff changeset
43 from rhodecode.lib.compat import json
1669
f522f4d3bf93 moved caching query to libs
Marcin Kuzminski <marcin@python-works.com>
parents: 1665
diff changeset
44 from rhodecode.lib.caching_query import FromCache
1500
256e729a94cd Extended API
Marcin Kuzminski <marcin@python-works.com>
parents: 1466
diff changeset
45
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
1669
f522f4d3bf93 moved caching query to libs
Marcin Kuzminski <marcin@python-works.com>
parents: 1665
diff changeset
47
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
48 log = logging.getLogger(__name__)
49
3ada2f409c1c Added sqlalchemy support
Marcin Kuzminski <marcin@python-blog.com>
parents:
diff changeset
49
1081
70bf0be59653 fixed Session problems in model class functions
Marcin Kuzminski <marcin@python-works.com>
parents: 1065
diff changeset
50 #==============================================================================
1388
2029c17cc6c6 Added basic JsonSerialization into models.
Marcin Kuzminski <marcin@python-works.com>
parents: 1385
diff changeset
51 # BASE CLASSES
1081
70bf0be59653 fixed Session problems in model class functions
Marcin Kuzminski <marcin@python-works.com>
parents: 1065
diff changeset
52 #==============================================================================
70bf0be59653 fixed Session problems in model class functions
Marcin Kuzminski <marcin@python-works.com>
parents: 1065
diff changeset
53
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
54 class ModelSerializer(json.JSONEncoder):
1388
2029c17cc6c6 Added basic JsonSerialization into models.
Marcin Kuzminski <marcin@python-works.com>
parents: 1385
diff changeset
55 """
2029c17cc6c6 Added basic JsonSerialization into models.
Marcin Kuzminski <marcin@python-works.com>
parents: 1385
diff changeset
56 Simple Serializer for JSON,
1584
3338a0994472 Improve API with user/group/repo CRUD methods
Nicolas VINOT <aeris@imirhil.fr>
parents: 1508
diff changeset
57
1388
2029c17cc6c6 Added basic JsonSerialization into models.
Marcin Kuzminski <marcin@python-works.com>
parents: 1385
diff changeset
58 usage::
1584
3338a0994472 Improve API with user/group/repo CRUD methods
Nicolas VINOT <aeris@imirhil.fr>
parents: 1508
diff changeset
59
1388
2029c17cc6c6 Added basic JsonSerialization into models.
Marcin Kuzminski <marcin@python-works.com>
parents: 1385
diff changeset
60 to make object customized for serialization implement a __json__
2029c17cc6c6 Added basic JsonSerialization into models.
Marcin Kuzminski <marcin@python-works.com>
parents: 1385
diff changeset
61 method that will return a dict for serialization into json
1584
3338a0994472 Improve API with user/group/repo CRUD methods
Nicolas VINOT <aeris@imirhil.fr>
parents: 1508
diff changeset
62
1388
2029c17cc6c6 Added basic JsonSerialization into models.
Marcin Kuzminski <marcin@python-works.com>
parents: 1385
diff changeset
63 example::
1584
3338a0994472 Improve API with user/group/repo CRUD methods
Nicolas VINOT <aeris@imirhil.fr>
parents: 1508
diff changeset
64
1388
2029c17cc6c6 Added basic JsonSerialization into models.
Marcin Kuzminski <marcin@python-works.com>
parents: 1385
diff changeset
65 class Task(object):
1584
3338a0994472 Improve API with user/group/repo CRUD methods
Nicolas VINOT <aeris@imirhil.fr>
parents: 1508
diff changeset
66
1388
2029c17cc6c6 Added basic JsonSerialization into models.
Marcin Kuzminski <marcin@python-works.com>
parents: 1385
diff changeset
67 def __init__(self, name, value):
2029c17cc6c6 Added basic JsonSerialization into models.
Marcin Kuzminski <marcin@python-works.com>
parents: 1385
diff changeset
68 self.name = name
2029c17cc6c6 Added basic JsonSerialization into models.
Marcin Kuzminski <marcin@python-works.com>
parents: 1385
diff changeset
69 self.value = value
1584
3338a0994472 Improve API with user/group/repo CRUD methods
Nicolas VINOT <aeris@imirhil.fr>
parents: 1508
diff changeset
70
1388
2029c17cc6c6 Added basic JsonSerialization into models.
Marcin Kuzminski <marcin@python-works.com>
parents: 1385
diff changeset
71 def __json__(self):
2029c17cc6c6 Added basic JsonSerialization into models.
Marcin Kuzminski <marcin@python-works.com>
parents: 1385
diff changeset
72 return dict(name=self.name,
1584
3338a0994472 Improve API with user/group/repo CRUD methods
Nicolas VINOT <aeris@imirhil.fr>
parents: 1508
diff changeset
73 value=self.value)
3338a0994472 Improve API with user/group/repo CRUD methods
Nicolas VINOT <aeris@imirhil.fr>
parents: 1508
diff changeset
74
1388
2029c17cc6c6 Added basic JsonSerialization into models.
Marcin Kuzminski <marcin@python-works.com>
parents: 1385
diff changeset
75 """
2029c17cc6c6 Added basic JsonSerialization into models.
Marcin Kuzminski <marcin@python-works.com>
parents: 1385
diff changeset
76
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
77 def default(self, obj):
1388
2029c17cc6c6 Added basic JsonSerialization into models.
Marcin Kuzminski <marcin@python-works.com>
parents: 1385
diff changeset
78
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
79 if hasattr(obj, '__json__'):
1388
2029c17cc6c6 Added basic JsonSerialization into models.
Marcin Kuzminski <marcin@python-works.com>
parents: 1385
diff changeset
80 return obj.__json__()
2029c17cc6c6 Added basic JsonSerialization into models.
Marcin Kuzminski <marcin@python-works.com>
parents: 1385
diff changeset
81 else:
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
82 return json.JSONEncoder.default(self, obj)
1388
2029c17cc6c6 Added basic JsonSerialization into models.
Marcin Kuzminski <marcin@python-works.com>
parents: 1385
diff changeset
83
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
84 class BaseModel(object):
1388
2029c17cc6c6 Added basic JsonSerialization into models.
Marcin Kuzminski <marcin@python-works.com>
parents: 1385
diff changeset
85 """Base Model for all classess
2029c17cc6c6 Added basic JsonSerialization into models.
Marcin Kuzminski <marcin@python-works.com>
parents: 1385
diff changeset
86
2029c17cc6c6 Added basic JsonSerialization into models.
Marcin Kuzminski <marcin@python-works.com>
parents: 1385
diff changeset
87 """
2029c17cc6c6 Added basic JsonSerialization into models.
Marcin Kuzminski <marcin@python-works.com>
parents: 1385
diff changeset
88
2029c17cc6c6 Added basic JsonSerialization into models.
Marcin Kuzminski <marcin@python-works.com>
parents: 1385
diff changeset
89 @classmethod
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
90 def _get_keys(cls):
1388
2029c17cc6c6 Added basic JsonSerialization into models.
Marcin Kuzminski <marcin@python-works.com>
parents: 1385
diff changeset
91 """return column names for this model """
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
92 return class_mapper(cls).c.keys()
1388
2029c17cc6c6 Added basic JsonSerialization into models.
Marcin Kuzminski <marcin@python-works.com>
parents: 1385
diff changeset
93
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
94 def get_dict(self):
1388
2029c17cc6c6 Added basic JsonSerialization into models.
Marcin Kuzminski <marcin@python-works.com>
parents: 1385
diff changeset
95 """return dict with keys and values corresponding
2029c17cc6c6 Added basic JsonSerialization into models.
Marcin Kuzminski <marcin@python-works.com>
parents: 1385
diff changeset
96 to this model data """
2029c17cc6c6 Added basic JsonSerialization into models.
Marcin Kuzminski <marcin@python-works.com>
parents: 1385
diff changeset
97
2029c17cc6c6 Added basic JsonSerialization into models.
Marcin Kuzminski <marcin@python-works.com>
parents: 1385
diff changeset
98 d = {}
2029c17cc6c6 Added basic JsonSerialization into models.
Marcin Kuzminski <marcin@python-works.com>
parents: 1385
diff changeset
99 for k in self._get_keys():
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
100 d[k] = getattr(self, k)
1388
2029c17cc6c6 Added basic JsonSerialization into models.
Marcin Kuzminski <marcin@python-works.com>
parents: 1385
diff changeset
101 return d
2029c17cc6c6 Added basic JsonSerialization into models.
Marcin Kuzminski <marcin@python-works.com>
parents: 1385
diff changeset
102
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
103 def get_appstruct(self):
1388
2029c17cc6c6 Added basic JsonSerialization into models.
Marcin Kuzminski <marcin@python-works.com>
parents: 1385
diff changeset
104 """return list with keys and values tupples corresponding
2029c17cc6c6 Added basic JsonSerialization into models.
Marcin Kuzminski <marcin@python-works.com>
parents: 1385
diff changeset
105 to this model data """
2029c17cc6c6 Added basic JsonSerialization into models.
Marcin Kuzminski <marcin@python-works.com>
parents: 1385
diff changeset
106
2029c17cc6c6 Added basic JsonSerialization into models.
Marcin Kuzminski <marcin@python-works.com>
parents: 1385
diff changeset
107 l = []
2029c17cc6c6 Added basic JsonSerialization into models.
Marcin Kuzminski <marcin@python-works.com>
parents: 1385
diff changeset
108 for k in self._get_keys():
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
109 l.append((k, getattr(self, k),))
1388
2029c17cc6c6 Added basic JsonSerialization into models.
Marcin Kuzminski <marcin@python-works.com>
parents: 1385
diff changeset
110 return l
2029c17cc6c6 Added basic JsonSerialization into models.
Marcin Kuzminski <marcin@python-works.com>
parents: 1385
diff changeset
111
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
112 def populate_obj(self, populate_dict):
1388
2029c17cc6c6 Added basic JsonSerialization into models.
Marcin Kuzminski <marcin@python-works.com>
parents: 1385
diff changeset
113 """populate model with data from given populate_dict"""
2029c17cc6c6 Added basic JsonSerialization into models.
Marcin Kuzminski <marcin@python-works.com>
parents: 1385
diff changeset
114
2029c17cc6c6 Added basic JsonSerialization into models.
Marcin Kuzminski <marcin@python-works.com>
parents: 1385
diff changeset
115 for k in self._get_keys():
2029c17cc6c6 Added basic JsonSerialization into models.
Marcin Kuzminski <marcin@python-works.com>
parents: 1385
diff changeset
116 if k in populate_dict:
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
117 setattr(self, k, populate_dict[k])
1388
2029c17cc6c6 Added basic JsonSerialization into models.
Marcin Kuzminski <marcin@python-works.com>
parents: 1385
diff changeset
118
2029c17cc6c6 Added basic JsonSerialization into models.
Marcin Kuzminski <marcin@python-works.com>
parents: 1385
diff changeset
119 @classmethod
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
120 def query(cls):
1713
54687aa00724 Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents: 1712
diff changeset
121 return Session().query(cls)
1388
2029c17cc6c6 Added basic JsonSerialization into models.
Marcin Kuzminski <marcin@python-works.com>
parents: 1385
diff changeset
122
2029c17cc6c6 Added basic JsonSerialization into models.
Marcin Kuzminski <marcin@python-works.com>
parents: 1385
diff changeset
123 @classmethod
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
124 def get(cls, id_):
1594
9dae92a65e40 fixes #288
Marcin Kuzminski <marcin@python-works.com>
parents: 1593
diff changeset
125 if id_:
9dae92a65e40 fixes #288
Marcin Kuzminski <marcin@python-works.com>
parents: 1593
diff changeset
126 return cls.query().get(id_)
1466
ad5a543a9b2f Code cleanup
Marcin Kuzminski <marcin@python-works.com>
parents: 1460
diff changeset
127
1460
b50348816a80 Added more advanced hook management into rhodecode admin settings
Marcin Kuzminski <marcin@python-works.com>
parents: 1436
diff changeset
128 @classmethod
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
129 def getAll(cls):
1584
3338a0994472 Improve API with user/group/repo CRUD methods
Nicolas VINOT <aeris@imirhil.fr>
parents: 1508
diff changeset
130 return cls.query().all()
1466
ad5a543a9b2f Code cleanup
Marcin Kuzminski <marcin@python-works.com>
parents: 1460
diff changeset
131
1460
b50348816a80 Added more advanced hook management into rhodecode admin settings
Marcin Kuzminski <marcin@python-works.com>
parents: 1436
diff changeset
132 @classmethod
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
133 def delete(cls, id_):
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
134 obj = cls.query().get(id_)
1713
54687aa00724 Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents: 1712
diff changeset
135 Session().delete(obj)
1466
ad5a543a9b2f Code cleanup
Marcin Kuzminski <marcin@python-works.com>
parents: 1460
diff changeset
136
1081
70bf0be59653 fixed Session problems in model class functions
Marcin Kuzminski <marcin@python-works.com>
parents: 1065
diff changeset
137
1633
2c0d35e336b5 refactoring of models names for repoGroup permissions
Marcin Kuzminski <marcin@python-works.com>
parents: 1607
diff changeset
138 class RhodeCodeSetting(Base, BaseModel):
548
b75b77ef649d renamed hg_app to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents: 547
diff changeset
139 __tablename__ = 'rhodecode_settings'
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
140 __table_args__ = (UniqueConstraint('app_settings_name'), {'extend_existing':True})
1594
9dae92a65e40 fixes #288
Marcin Kuzminski <marcin@python-works.com>
parents: 1593
diff changeset
141 app_settings_id = Column("app_settings_id", Integer(), nullable=False, unique=True, default=None, primary_key=True)
9dae92a65e40 fixes #288
Marcin Kuzminski <marcin@python-works.com>
parents: 1593
diff changeset
142 app_settings_name = Column("app_settings_name", String(length=255, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None)
9dae92a65e40 fixes #288
Marcin Kuzminski <marcin@python-works.com>
parents: 1593
diff changeset
143 _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
144
1594
9dae92a65e40 fixes #288
Marcin Kuzminski <marcin@python-works.com>
parents: 1593
diff changeset
145 def __init__(self, k='', v=''):
704
26237de9b613 Added settings model, and Exceptions lib.
Marcin Kuzminski <marcin@python-works.com>
parents: 692
diff changeset
146 self.app_settings_name = k
26237de9b613 Added settings model, and Exceptions lib.
Marcin Kuzminski <marcin@python-works.com>
parents: 692
diff changeset
147 self.app_settings_value = v
26237de9b613 Added settings model, and Exceptions lib.
Marcin Kuzminski <marcin@python-works.com>
parents: 692
diff changeset
148
1546
c363267bbec7 fixes #265 ldap save fails sometimes on converting attributes to booleans, added getter and setter
Marcin Kuzminski <marcin@python-works.com>
parents: 1539
diff changeset
149
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
150 @validates('_app_settings_value')
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
151 def validate_settings_value(self, key, val):
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
152 assert type(val) == unicode
1561
4d841e565237 added validation of params on settings table
Marcin Kuzminski <marcin@python-works.com>
parents: 1556
diff changeset
153 return val
4d841e565237 added validation of params on settings table
Marcin Kuzminski <marcin@python-works.com>
parents: 1556
diff changeset
154
1546
c363267bbec7 fixes #265 ldap save fails sometimes on converting attributes to booleans, added getter and setter
Marcin Kuzminski <marcin@python-works.com>
parents: 1539
diff changeset
155 @hybrid_property
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
156 def app_settings_value(self):
1546
c363267bbec7 fixes #265 ldap save fails sometimes on converting attributes to booleans, added getter and setter
Marcin Kuzminski <marcin@python-works.com>
parents: 1539
diff changeset
157 v = self._app_settings_value
c363267bbec7 fixes #265 ldap save fails sometimes on converting attributes to booleans, added getter and setter
Marcin Kuzminski <marcin@python-works.com>
parents: 1539
diff changeset
158 if v == 'ldap_active':
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
159 v = str2bool(v)
1591
0b63a0d2cede Merge with upstream
Nicolas VINOT <aeris@imirhil.fr>
parents: 1576 1590
diff changeset
160 return v
1546
c363267bbec7 fixes #265 ldap save fails sometimes on converting attributes to booleans, added getter and setter
Marcin Kuzminski <marcin@python-works.com>
parents: 1539
diff changeset
161
c363267bbec7 fixes #265 ldap save fails sometimes on converting attributes to booleans, added getter and setter
Marcin Kuzminski <marcin@python-works.com>
parents: 1539
diff changeset
162 @app_settings_value.setter
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
163 def app_settings_value(self, val):
1546
c363267bbec7 fixes #265 ldap save fails sometimes on converting attributes to booleans, added getter and setter
Marcin Kuzminski <marcin@python-works.com>
parents: 1539
diff changeset
164 """
c363267bbec7 fixes #265 ldap save fails sometimes on converting attributes to booleans, added getter and setter
Marcin Kuzminski <marcin@python-works.com>
parents: 1539
diff changeset
165 Setter that will always make sure we use unicode in app_settings_value
1591
0b63a0d2cede Merge with upstream
Nicolas VINOT <aeris@imirhil.fr>
parents: 1576 1590
diff changeset
166
1546
c363267bbec7 fixes #265 ldap save fails sometimes on converting attributes to booleans, added getter and setter
Marcin Kuzminski <marcin@python-works.com>
parents: 1539
diff changeset
167 :param val:
c363267bbec7 fixes #265 ldap save fails sometimes on converting attributes to booleans, added getter and setter
Marcin Kuzminski <marcin@python-works.com>
parents: 1539
diff changeset
168 """
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
169 self._app_settings_value = safe_unicode(val)
1546
c363267bbec7 fixes #265 ldap save fails sometimes on converting attributes to booleans, added getter and setter
Marcin Kuzminski <marcin@python-works.com>
parents: 1539
diff changeset
170
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
171 def __repr__(self):
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
172 return "<%s('%s:%s')>" % (self.__class__.__name__,
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
173 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
174
1266
a1bcfe58a1ab Fixed #161 form saves the create repository permission.
Marcin Kuzminski <marcin@python-works.com>
parents: 1206
diff changeset
175
a1bcfe58a1ab Fixed #161 form saves the create repository permission.
Marcin Kuzminski <marcin@python-works.com>
parents: 1206
diff changeset
176 @classmethod
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
177 def get_by_name(cls, ldap_key):
1584
3338a0994472 Improve API with user/group/repo CRUD methods
Nicolas VINOT <aeris@imirhil.fr>
parents: 1508
diff changeset
178 return cls.query()\
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
179 .filter(cls.app_settings_name == ldap_key).scalar()
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
180
c0335c1dee36 added some fixes to LDAP form re-submition, new simples ldap-settings getter.
Marcin Kuzminski <marcin@python-works.com>
parents: 1279
diff changeset
181 @classmethod
1594
9dae92a65e40 fixes #288
Marcin Kuzminski <marcin@python-works.com>
parents: 1593
diff changeset
182 def get_app_settings(cls, cache=False):
1266
a1bcfe58a1ab Fixed #161 form saves the create repository permission.
Marcin Kuzminski <marcin@python-works.com>
parents: 1206
diff changeset
183
1584
3338a0994472 Improve API with user/group/repo CRUD methods
Nicolas VINOT <aeris@imirhil.fr>
parents: 1508
diff changeset
184 ret = cls.query()
1266
a1bcfe58a1ab Fixed #161 form saves the create repository permission.
Marcin Kuzminski <marcin@python-works.com>
parents: 1206
diff changeset
185
a1bcfe58a1ab Fixed #161 form saves the create repository permission.
Marcin Kuzminski <marcin@python-works.com>
parents: 1206
diff changeset
186 if cache:
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
187 ret = ret.options(FromCache("sql_cache_short", "get_hg_settings"))
1266
a1bcfe58a1ab Fixed #161 form saves the create repository permission.
Marcin Kuzminski <marcin@python-works.com>
parents: 1206
diff changeset
188
a1bcfe58a1ab Fixed #161 form saves the create repository permission.
Marcin Kuzminski <marcin@python-works.com>
parents: 1206
diff changeset
189 if not ret:
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
190 raise Exception('Could not get application settings !')
1266
a1bcfe58a1ab Fixed #161 form saves the create repository permission.
Marcin Kuzminski <marcin@python-works.com>
parents: 1206
diff changeset
191 settings = {}
a1bcfe58a1ab Fixed #161 form saves the create repository permission.
Marcin Kuzminski <marcin@python-works.com>
parents: 1206
diff changeset
192 for each in ret:
a1bcfe58a1ab Fixed #161 form saves the create repository permission.
Marcin Kuzminski <marcin@python-works.com>
parents: 1206
diff changeset
193 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
194 each.app_settings_value
a1bcfe58a1ab Fixed #161 form saves the create repository permission.
Marcin Kuzminski <marcin@python-works.com>
parents: 1206
diff changeset
195
a1bcfe58a1ab Fixed #161 form saves the create repository permission.
Marcin Kuzminski <marcin@python-works.com>
parents: 1206
diff changeset
196 return settings
a1bcfe58a1ab Fixed #161 form saves the create repository permission.
Marcin Kuzminski <marcin@python-works.com>
parents: 1206
diff changeset
197
a1bcfe58a1ab Fixed #161 form saves the create repository permission.
Marcin Kuzminski <marcin@python-works.com>
parents: 1206
diff changeset
198 @classmethod
1594
9dae92a65e40 fixes #288
Marcin Kuzminski <marcin@python-works.com>
parents: 1593
diff changeset
199 def get_ldap_settings(cls, cache=False):
1584
3338a0994472 Improve API with user/group/repo CRUD methods
Nicolas VINOT <aeris@imirhil.fr>
parents: 1508
diff changeset
200 ret = cls.query()\
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
201 .filter(cls.app_settings_name.startswith('ldap_')).all()
1266
a1bcfe58a1ab Fixed #161 form saves the create repository permission.
Marcin Kuzminski <marcin@python-works.com>
parents: 1206
diff changeset
202 fd = {}
a1bcfe58a1ab Fixed #161 form saves the create repository permission.
Marcin Kuzminski <marcin@python-works.com>
parents: 1206
diff changeset
203 for row in ret:
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
204 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
205
1266
a1bcfe58a1ab Fixed #161 form saves the create repository permission.
Marcin Kuzminski <marcin@python-works.com>
parents: 1206
diff changeset
206 return fd
a1bcfe58a1ab Fixed #161 form saves the create repository permission.
Marcin Kuzminski <marcin@python-works.com>
parents: 1206
diff changeset
207
a1bcfe58a1ab Fixed #161 form saves the create repository permission.
Marcin Kuzminski <marcin@python-works.com>
parents: 1206
diff changeset
208
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
209 class RhodeCodeUi(Base, BaseModel):
548
b75b77ef649d renamed hg_app to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents: 547
diff changeset
210 __tablename__ = 'rhodecode_ui'
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
211 __table_args__ = (UniqueConstraint('ui_key'), {'extend_existing':True})
1460
b50348816a80 Added more advanced hook management into rhodecode admin settings
Marcin Kuzminski <marcin@python-works.com>
parents: 1436
diff changeset
212
b50348816a80 Added more advanced hook management into rhodecode admin settings
Marcin Kuzminski <marcin@python-works.com>
parents: 1436
diff changeset
213 HOOK_UPDATE = 'changegroup.update'
b50348816a80 Added more advanced hook management into rhodecode admin settings
Marcin Kuzminski <marcin@python-works.com>
parents: 1436
diff changeset
214 HOOK_REPO_SIZE = 'changegroup.repo_size'
b50348816a80 Added more advanced hook management into rhodecode admin settings
Marcin Kuzminski <marcin@python-works.com>
parents: 1436
diff changeset
215 HOOK_PUSH = 'pretxnchangegroup.push_logger'
b50348816a80 Added more advanced hook management into rhodecode admin settings
Marcin Kuzminski <marcin@python-works.com>
parents: 1436
diff changeset
216 HOOK_PULL = 'preoutgoing.pull_logger'
b50348816a80 Added more advanced hook management into rhodecode admin settings
Marcin Kuzminski <marcin@python-works.com>
parents: 1436
diff changeset
217
1594
9dae92a65e40 fixes #288
Marcin Kuzminski <marcin@python-works.com>
parents: 1593
diff changeset
218 ui_id = Column("ui_id", Integer(), nullable=False, unique=True, default=None, primary_key=True)
9dae92a65e40 fixes #288
Marcin Kuzminski <marcin@python-works.com>
parents: 1593
diff changeset
219 ui_section = Column("ui_section", String(length=255, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None)
9dae92a65e40 fixes #288
Marcin Kuzminski <marcin@python-works.com>
parents: 1593
diff changeset
220 ui_key = Column("ui_key", String(length=255, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None)
9dae92a65e40 fixes #288
Marcin Kuzminski <marcin@python-works.com>
parents: 1593
diff changeset
221 ui_value = Column("ui_value", String(length=255, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None)
9dae92a65e40 fixes #288
Marcin Kuzminski <marcin@python-works.com>
parents: 1593
diff changeset
222 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
223
05528ad948c4 Hacking for git support,and new faster repo scan
Marcin Kuzminski <marcin@python-works.com>
parents: 549
diff changeset
224
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
225 @classmethod
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
226 def get_by_key(cls, key):
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
227 return cls.query().filter(cls.ui_key == key)
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
228
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
229
1460
b50348816a80 Added more advanced hook management into rhodecode admin settings
Marcin Kuzminski <marcin@python-works.com>
parents: 1436
diff changeset
230 @classmethod
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
231 def get_builtin_hooks(cls):
1460
b50348816a80 Added more advanced hook management into rhodecode admin settings
Marcin Kuzminski <marcin@python-works.com>
parents: 1436
diff changeset
232 q = cls.query()
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
233 q = q.filter(cls.ui_key.in_([cls.HOOK_UPDATE,
1460
b50348816a80 Added more advanced hook management into rhodecode admin settings
Marcin Kuzminski <marcin@python-works.com>
parents: 1436
diff changeset
234 cls.HOOK_REPO_SIZE,
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
235 cls.HOOK_PUSH, cls.HOOK_PULL]))
1460
b50348816a80 Added more advanced hook management into rhodecode admin settings
Marcin Kuzminski <marcin@python-works.com>
parents: 1436
diff changeset
236 return q.all()
b50348816a80 Added more advanced hook management into rhodecode admin settings
Marcin Kuzminski <marcin@python-works.com>
parents: 1436
diff changeset
237
b50348816a80 Added more advanced hook management into rhodecode admin settings
Marcin Kuzminski <marcin@python-works.com>
parents: 1436
diff changeset
238 @classmethod
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
239 def get_custom_hooks(cls):
1460
b50348816a80 Added more advanced hook management into rhodecode admin settings
Marcin Kuzminski <marcin@python-works.com>
parents: 1436
diff changeset
240 q = cls.query()
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
241 q = q.filter(~cls.ui_key.in_([cls.HOOK_UPDATE,
1460
b50348816a80 Added more advanced hook management into rhodecode admin settings
Marcin Kuzminski <marcin@python-works.com>
parents: 1436
diff changeset
242 cls.HOOK_REPO_SIZE,
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
243 cls.HOOK_PUSH, cls.HOOK_PULL]))
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
244 q = q.filter(cls.ui_section == 'hooks')
1460
b50348816a80 Added more advanced hook management into rhodecode admin settings
Marcin Kuzminski <marcin@python-works.com>
parents: 1436
diff changeset
245 return q.all()
b50348816a80 Added more advanced hook management into rhodecode admin settings
Marcin Kuzminski <marcin@python-works.com>
parents: 1436
diff changeset
246
b50348816a80 Added more advanced hook management into rhodecode admin settings
Marcin Kuzminski <marcin@python-works.com>
parents: 1436
diff changeset
247 @classmethod
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
248 def create_or_update_hook(cls, key, val):
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
249 new_ui = cls.get_by_key(key).scalar() or cls()
1460
b50348816a80 Added more advanced hook management into rhodecode admin settings
Marcin Kuzminski <marcin@python-works.com>
parents: 1436
diff changeset
250 new_ui.ui_section = 'hooks'
b50348816a80 Added more advanced hook management into rhodecode admin settings
Marcin Kuzminski <marcin@python-works.com>
parents: 1436
diff changeset
251 new_ui.ui_active = True
b50348816a80 Added more advanced hook management into rhodecode admin settings
Marcin Kuzminski <marcin@python-works.com>
parents: 1436
diff changeset
252 new_ui.ui_key = key
b50348816a80 Added more advanced hook management into rhodecode admin settings
Marcin Kuzminski <marcin@python-works.com>
parents: 1436
diff changeset
253 new_ui.ui_value = val
b50348816a80 Added more advanced hook management into rhodecode admin settings
Marcin Kuzminski <marcin@python-works.com>
parents: 1436
diff changeset
254
1713
54687aa00724 Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents: 1712
diff changeset
255 Session().add(new_ui)
54687aa00724 Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents: 1712
diff changeset
256 Session().commit()
1460
b50348816a80 Added more advanced hook management into rhodecode admin settings
Marcin Kuzminski <marcin@python-works.com>
parents: 1436
diff changeset
257
b50348816a80 Added more advanced hook management into rhodecode admin settings
Marcin Kuzminski <marcin@python-works.com>
parents: 1436
diff changeset
258
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
259 class User(Base, BaseModel):
49
3ada2f409c1c Added sqlalchemy support
Marcin Kuzminski <marcin@python-blog.com>
parents:
diff changeset
260 __tablename__ = 'users'
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
261 __table_args__ = (UniqueConstraint('username'), UniqueConstraint('email'), {'extend_existing':True})
1594
9dae92a65e40 fixes #288
Marcin Kuzminski <marcin@python-works.com>
parents: 1593
diff changeset
262 user_id = Column("user_id", Integer(), nullable=False, unique=True, default=None, primary_key=True)
9dae92a65e40 fixes #288
Marcin Kuzminski <marcin@python-works.com>
parents: 1593
diff changeset
263 username = Column("username", String(length=255, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None)
9dae92a65e40 fixes #288
Marcin Kuzminski <marcin@python-works.com>
parents: 1593
diff changeset
264 password = Column("password", String(length=255, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None)
9dae92a65e40 fixes #288
Marcin Kuzminski <marcin@python-works.com>
parents: 1593
diff changeset
265 active = Column("active", Boolean(), nullable=True, unique=None, default=None)
9dae92a65e40 fixes #288
Marcin Kuzminski <marcin@python-works.com>
parents: 1593
diff changeset
266 admin = Column("admin", Boolean(), nullable=True, unique=None, default=False)
9dae92a65e40 fixes #288
Marcin Kuzminski <marcin@python-works.com>
parents: 1593
diff changeset
267 name = Column("name", String(length=255, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None)
9dae92a65e40 fixes #288
Marcin Kuzminski <marcin@python-works.com>
parents: 1593
diff changeset
268 lastname = Column("lastname", String(length=255, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None)
9dae92a65e40 fixes #288
Marcin Kuzminski <marcin@python-works.com>
parents: 1593
diff changeset
269 email = Column("email", String(length=255, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None)
9dae92a65e40 fixes #288
Marcin Kuzminski <marcin@python-works.com>
parents: 1593
diff changeset
270 last_login = Column("last_login", DateTime(timezone=False), nullable=True, unique=None, default=None)
9dae92a65e40 fixes #288
Marcin Kuzminski <marcin@python-works.com>
parents: 1593
diff changeset
271 ldap_dn = Column("ldap_dn", String(length=255, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None)
9dae92a65e40 fixes #288
Marcin Kuzminski <marcin@python-works.com>
parents: 1593
diff changeset
272 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
273
1594
9dae92a65e40 fixes #288
Marcin Kuzminski <marcin@python-works.com>
parents: 1593
diff changeset
274 user_log = relationship('UserLog', cascade='all')
9dae92a65e40 fixes #288
Marcin Kuzminski <marcin@python-works.com>
parents: 1593
diff changeset
275 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
276
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
277 repositories = relationship('Repository')
1594
9dae92a65e40 fixes #288
Marcin Kuzminski <marcin@python-works.com>
parents: 1593
diff changeset
278 user_followers = relationship('UserFollowing', primaryjoin='UserFollowing.follows_user_id==User.user_id', cascade='all')
1633
2c0d35e336b5 refactoring of models names for repoGroup permissions
Marcin Kuzminski <marcin@python-works.com>
parents: 1607
diff changeset
279 repo_to_perm = relationship('UserRepoToPerm', primaryjoin='UserRepoToPerm.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
280
1594
9dae92a65e40 fixes #288
Marcin Kuzminski <marcin@python-works.com>
parents: 1593
diff changeset
281 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
282
1717
7ff304d3028f Notification fixes
Marcin Kuzminski <marcin@python-works.com>
parents: 1716
diff changeset
283 notifications = relationship('UserNotification',)
1702
8cb7f5c4d494 #302 - basic notification system, models+tests
Marcin Kuzminski <marcin@python-works.com>
parents: 1693
diff changeset
284
759
a7f50911a945 Models code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 734
diff changeset
285 @property
1731
31e6eb2fb4b2 implements #222 registration feedback
Marcin Kuzminski <marcin@python-works.com>
parents: 1729
diff changeset
286 def full_name(self):
31e6eb2fb4b2 implements #222 registration feedback
Marcin Kuzminski <marcin@python-works.com>
parents: 1729
diff changeset
287 return '%s %s' % (self.name, self.lastname)
31e6eb2fb4b2 implements #222 registration feedback
Marcin Kuzminski <marcin@python-works.com>
parents: 1729
diff changeset
288
31e6eb2fb4b2 implements #222 registration feedback
Marcin Kuzminski <marcin@python-works.com>
parents: 1729
diff changeset
289 @property
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
290 def full_contact(self):
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
291 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
292
895
62c04c5cc971 Added some more details into user edit permissions view
Marcin Kuzminski <marcin@python-works.com>
parents: 880
diff changeset
293 @property
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
294 def short_contact(self):
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
295 return '%s %s' % (self.name, self.lastname)
1088
fee472613dfa made simple global rss and atom feed
Marcin Kuzminski <marcin@python-works.com>
parents: 1081
diff changeset
296
fee472613dfa made simple global rss and atom feed
Marcin Kuzminski <marcin@python-works.com>
parents: 1081
diff changeset
297 @property
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
298 def is_admin(self):
895
62c04c5cc971 Added some more details into user edit permissions view
Marcin Kuzminski <marcin@python-works.com>
parents: 880
diff changeset
299 return self.admin
62c04c5cc971 Added some more details into user edit permissions view
Marcin Kuzminski <marcin@python-works.com>
parents: 880
diff changeset
300
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
301 def __repr__(self):
1712
cac5109ac3b6 Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents: 1703
diff changeset
302 return "<%s('id:%s:%s')>" % (self.__class__.__name__,
cac5109ac3b6 Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents: 1703
diff changeset
303 self.user_id, self.username)
cac5109ac3b6 Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents: 1703
diff changeset
304
631
05528ad948c4 Hacking for git support,and new faster repo scan
Marcin Kuzminski <marcin@python-works.com>
parents: 549
diff changeset
305
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
306 @classmethod
1665
36f77a46f291 Added cache options to some db getters
Marcin Kuzminski <marcin@python-works.com>
parents: 1634
diff changeset
307 def get_by_username(cls, username, case_insensitive=False, cache=False):
1400
0d7b56b97953 Simplified last_login call on user, and changed login to use User model directly
Marcin Kuzminski <marcin@python-works.com>
parents: 1388
diff changeset
308 if case_insensitive:
1665
36f77a46f291 Added cache options to some db getters
Marcin Kuzminski <marcin@python-works.com>
parents: 1634
diff changeset
309 q = cls.query().filter(cls.username.ilike(username))
1400
0d7b56b97953 Simplified last_login call on user, and changed login to use User model directly
Marcin Kuzminski <marcin@python-works.com>
parents: 1388
diff changeset
310 else:
1665
36f77a46f291 Added cache options to some db getters
Marcin Kuzminski <marcin@python-works.com>
parents: 1634
diff changeset
311 q = cls.query().filter(cls.username == username)
36f77a46f291 Added cache options to some db getters
Marcin Kuzminski <marcin@python-works.com>
parents: 1634
diff changeset
312
36f77a46f291 Added cache options to some db getters
Marcin Kuzminski <marcin@python-works.com>
parents: 1634
diff changeset
313 if cache:
36f77a46f291 Added cache options to some db getters
Marcin Kuzminski <marcin@python-works.com>
parents: 1634
diff changeset
314 q = q.options(FromCache("sql_cache_short",
36f77a46f291 Added cache options to some db getters
Marcin Kuzminski <marcin@python-works.com>
parents: 1634
diff changeset
315 "get_user_%s" % username))
36f77a46f291 Added cache options to some db getters
Marcin Kuzminski <marcin@python-works.com>
parents: 1634
diff changeset
316 return q.scalar()
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
317
1417
5875955def39 fixes #223 improve password reset form
Marcin Kuzminski <marcin@python-works.com>
parents: 1401
diff changeset
318 @classmethod
1665
36f77a46f291 Added cache options to some db getters
Marcin Kuzminski <marcin@python-works.com>
parents: 1634
diff changeset
319 def get_by_api_key(cls, api_key, cache=False):
36f77a46f291 Added cache options to some db getters
Marcin Kuzminski <marcin@python-works.com>
parents: 1634
diff changeset
320 q = cls.query().filter(cls.api_key == api_key)
36f77a46f291 Added cache options to some db getters
Marcin Kuzminski <marcin@python-works.com>
parents: 1634
diff changeset
321
36f77a46f291 Added cache options to some db getters
Marcin Kuzminski <marcin@python-works.com>
parents: 1634
diff changeset
322 if cache:
36f77a46f291 Added cache options to some db getters
Marcin Kuzminski <marcin@python-works.com>
parents: 1634
diff changeset
323 q = q.options(FromCache("sql_cache_short",
36f77a46f291 Added cache options to some db getters
Marcin Kuzminski <marcin@python-works.com>
parents: 1634
diff changeset
324 "get_api_key_%s" % api_key))
1693
60249224be04 fix for api key lookup, reuse same function in user model
Marcin Kuzminski <marcin@python-works.com>
parents: 1677
diff changeset
325 return q.scalar()
1417
5875955def39 fixes #223 improve password reset form
Marcin Kuzminski <marcin@python-works.com>
parents: 1401
diff changeset
326
1716
7d1fc253549e notification to commit author + gardening
Marcin Kuzminski <marcin@python-works.com>
parents: 1713
diff changeset
327 @classmethod
7d1fc253549e notification to commit author + gardening
Marcin Kuzminski <marcin@python-works.com>
parents: 1713
diff changeset
328 def get_by_email(cls, email, cache=False):
7d1fc253549e notification to commit author + gardening
Marcin Kuzminski <marcin@python-works.com>
parents: 1713
diff changeset
329 q = cls.query().filter(cls.email == email)
7d1fc253549e notification to commit author + gardening
Marcin Kuzminski <marcin@python-works.com>
parents: 1713
diff changeset
330
7d1fc253549e notification to commit author + gardening
Marcin Kuzminski <marcin@python-works.com>
parents: 1713
diff changeset
331 if cache:
7d1fc253549e notification to commit author + gardening
Marcin Kuzminski <marcin@python-works.com>
parents: 1713
diff changeset
332 q = q.options(FromCache("sql_cache_short",
7d1fc253549e notification to commit author + gardening
Marcin Kuzminski <marcin@python-works.com>
parents: 1713
diff changeset
333 "get_api_key_%s" % email))
7d1fc253549e notification to commit author + gardening
Marcin Kuzminski <marcin@python-works.com>
parents: 1713
diff changeset
334 return q.scalar()
7d1fc253549e notification to commit author + gardening
Marcin Kuzminski <marcin@python-works.com>
parents: 1713
diff changeset
335
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
336 def update_lastlogin(self):
442
d66a7fa7689b moved loged in user propagation out of forms,
Marcin Kuzminski <marcin@python-works.com>
parents: 417
diff changeset
337 """Update user lastlogin"""
631
05528ad948c4 Hacking for git support,and new faster repo scan
Marcin Kuzminski <marcin@python-works.com>
parents: 549
diff changeset
338
1400
0d7b56b97953 Simplified last_login call on user, and changed login to use User model directly
Marcin Kuzminski <marcin@python-works.com>
parents: 1388
diff changeset
339 self.last_login = datetime.datetime.now()
1713
54687aa00724 Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents: 1712
diff changeset
340 Session().add(self)
54687aa00724 Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents: 1712
diff changeset
341 Session().commit()
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
342 log.debug('updated user %s lastlogin', self.username)
631
05528ad948c4 Hacking for git support,and new faster repo scan
Marcin Kuzminski <marcin@python-works.com>
parents: 549
diff changeset
343
1712
cac5109ac3b6 Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents: 1703
diff changeset
344
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
345 class UserLog(Base, BaseModel):
49
3ada2f409c1c Added sqlalchemy support
Marcin Kuzminski <marcin@python-blog.com>
parents:
diff changeset
346 __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
347 __table_args__ = {'extend_existing':True}
1594
9dae92a65e40 fixes #288
Marcin Kuzminski <marcin@python-works.com>
parents: 1593
diff changeset
348 user_log_id = Column("user_log_id", Integer(), nullable=False, unique=True, default=None, primary_key=True)
9dae92a65e40 fixes #288
Marcin Kuzminski <marcin@python-works.com>
parents: 1593
diff changeset
349 user_id = Column("user_id", Integer(), ForeignKey('users.user_id'), nullable=False, unique=None, default=None)
9dae92a65e40 fixes #288
Marcin Kuzminski <marcin@python-works.com>
parents: 1593
diff changeset
350 repository_id = Column("repository_id", Integer(), ForeignKey('repositories.repo_id'), nullable=False, unique=None, default=None)
9dae92a65e40 fixes #288
Marcin Kuzminski <marcin@python-works.com>
parents: 1593
diff changeset
351 repository_name = Column("repository_name", String(length=255, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None)
9dae92a65e40 fixes #288
Marcin Kuzminski <marcin@python-works.com>
parents: 1593
diff changeset
352 user_ip = Column("user_ip", String(length=255, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None)
9dae92a65e40 fixes #288
Marcin Kuzminski <marcin@python-works.com>
parents: 1593
diff changeset
353 action = Column("action", UnicodeText(length=1200000, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None)
9dae92a65e40 fixes #288
Marcin Kuzminski <marcin@python-works.com>
parents: 1593
diff changeset
354 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
355
994
7f9d23f6a526 Added grouping by days in journal
Marcin Kuzminski <marcin@python-works.com>
parents: 991
diff changeset
356 @property
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
357 def action_as_day(self):
1723
64e91067b996 - refactoring to overcome poor usage of global pylons config
Marcin Kuzminski <marcin@python-works.com>
parents: 1717
diff changeset
358 return datetime.date(*self.action_date.timetuple()[:3])
994
7f9d23f6a526 Added grouping by days in journal
Marcin Kuzminski <marcin@python-works.com>
parents: 991
diff changeset
359
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
360 user = relationship('User')
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
361 repository = relationship('Repository')
631
05528ad948c4 Hacking for git support,and new faster repo scan
Marcin Kuzminski <marcin@python-works.com>
parents: 549
diff changeset
362
956
83d35d716a02 started working on issue #56
Marcin Kuzminski <marcin@python-works.com>
parents: 907
diff changeset
363
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
364 class UsersGroup(Base, BaseModel):
956
83d35d716a02 started working on issue #56
Marcin Kuzminski <marcin@python-works.com>
parents: 907
diff changeset
365 __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
366 __table_args__ = {'extend_existing':True}
956
83d35d716a02 started working on issue #56
Marcin Kuzminski <marcin@python-works.com>
parents: 907
diff changeset
367
1594
9dae92a65e40 fixes #288
Marcin Kuzminski <marcin@python-works.com>
parents: 1593
diff changeset
368 users_group_id = Column("users_group_id", Integer(), nullable=False, unique=True, default=None, primary_key=True)
9dae92a65e40 fixes #288
Marcin Kuzminski <marcin@python-works.com>
parents: 1593
diff changeset
369 users_group_name = Column("users_group_name", String(length=255, convert_unicode=False, assert_unicode=None), nullable=False, unique=True, default=None)
9dae92a65e40 fixes #288
Marcin Kuzminski <marcin@python-works.com>
parents: 1593
diff changeset
370 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
371
1594
9dae92a65e40 fixes #288
Marcin Kuzminski <marcin@python-works.com>
parents: 1593
diff changeset
372 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
373
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
374 def __repr__(self):
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
375 return '<userGroup(%s)>' % (self.users_group_name)
1271
aa7e45ad0cea Fixed permissions for users groups, group can have create repo permission now.
Marcin Kuzminski <marcin@python-works.com>
parents: 1266
diff changeset
376
aa7e45ad0cea Fixed permissions for users groups, group can have create repo permission now.
Marcin Kuzminski <marcin@python-works.com>
parents: 1266
diff changeset
377 @classmethod
1728
07e56179633e - fixes celery sqlalchemy session issues for async forking
Marcin Kuzminski <marcin@python-works.com>
parents: 1727
diff changeset
378 def get_by_group_name(cls, group_name, cache=False,
07e56179633e - fixes celery sqlalchemy session issues for async forking
Marcin Kuzminski <marcin@python-works.com>
parents: 1727
diff changeset
379 case_insensitive=False):
1271
aa7e45ad0cea Fixed permissions for users groups, group can have create repo permission now.
Marcin Kuzminski <marcin@python-works.com>
parents: 1266
diff changeset
380 if case_insensitive:
1728
07e56179633e - fixes celery sqlalchemy session issues for async forking
Marcin Kuzminski <marcin@python-works.com>
parents: 1727
diff changeset
381 q = cls.query().filter(cls.users_group_name.ilike(group_name))
1271
aa7e45ad0cea Fixed permissions for users groups, group can have create repo permission now.
Marcin Kuzminski <marcin@python-works.com>
parents: 1266
diff changeset
382 else:
1728
07e56179633e - fixes celery sqlalchemy session issues for async forking
Marcin Kuzminski <marcin@python-works.com>
parents: 1727
diff changeset
383 q = cls.query().filter(cls.users_group_name == group_name)
1271
aa7e45ad0cea Fixed permissions for users groups, group can have create repo permission now.
Marcin Kuzminski <marcin@python-works.com>
parents: 1266
diff changeset
384 if cache:
1728
07e56179633e - fixes celery sqlalchemy session issues for async forking
Marcin Kuzminski <marcin@python-works.com>
parents: 1727
diff changeset
385 q = q.options(FromCache("sql_cache_short",
07e56179633e - fixes celery sqlalchemy session issues for async forking
Marcin Kuzminski <marcin@python-works.com>
parents: 1727
diff changeset
386 "get_user_%s" % group_name))
07e56179633e - fixes celery sqlalchemy session issues for async forking
Marcin Kuzminski <marcin@python-works.com>
parents: 1727
diff changeset
387 return q.scalar()
1271
aa7e45ad0cea Fixed permissions for users groups, group can have create repo permission now.
Marcin Kuzminski <marcin@python-works.com>
parents: 1266
diff changeset
388
1436
88d13c1c6a55 removed users_group controller in replace for model methods,
Marcin Kuzminski <marcin@python-works.com>
parents: 1435
diff changeset
389
88d13c1c6a55 removed users_group controller in replace for model methods,
Marcin Kuzminski <marcin@python-works.com>
parents: 1435
diff changeset
390 @classmethod
1594
9dae92a65e40 fixes #288
Marcin Kuzminski <marcin@python-works.com>
parents: 1593
diff changeset
391 def get(cls, users_group_id, cache=False):
1584
3338a0994472 Improve API with user/group/repo CRUD methods
Nicolas VINOT <aeris@imirhil.fr>
parents: 1508
diff changeset
392 users_group = cls.query()
1436
88d13c1c6a55 removed users_group controller in replace for model methods,
Marcin Kuzminski <marcin@python-works.com>
parents: 1435
diff changeset
393 if cache:
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
394 users_group = users_group.options(FromCache("sql_cache_short",
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
395 "get_users_group_%s" % users_group_id))
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
396 return users_group.get(users_group_id)
1436
88d13c1c6a55 removed users_group controller in replace for model methods,
Marcin Kuzminski <marcin@python-works.com>
parents: 1435
diff changeset
397
88d13c1c6a55 removed users_group controller in replace for model methods,
Marcin Kuzminski <marcin@python-works.com>
parents: 1435
diff changeset
398 @classmethod
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
399 def create(cls, form_data):
1436
88d13c1c6a55 removed users_group controller in replace for model methods,
Marcin Kuzminski <marcin@python-works.com>
parents: 1435
diff changeset
400 try:
88d13c1c6a55 removed users_group controller in replace for model methods,
Marcin Kuzminski <marcin@python-works.com>
parents: 1435
diff changeset
401 new_users_group = cls()
88d13c1c6a55 removed users_group controller in replace for model methods,
Marcin Kuzminski <marcin@python-works.com>
parents: 1435
diff changeset
402 for k, v in form_data.items():
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
403 setattr(new_users_group, k, v)
1436
88d13c1c6a55 removed users_group controller in replace for model methods,
Marcin Kuzminski <marcin@python-works.com>
parents: 1435
diff changeset
404
1713
54687aa00724 Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents: 1712
diff changeset
405 Session().add(new_users_group)
54687aa00724 Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents: 1712
diff changeset
406 Session().commit()
1500
256e729a94cd Extended API
Marcin Kuzminski <marcin@python-works.com>
parents: 1466
diff changeset
407 return new_users_group
1436
88d13c1c6a55 removed users_group controller in replace for model methods,
Marcin Kuzminski <marcin@python-works.com>
parents: 1435
diff changeset
408 except:
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
409 log.error(traceback.format_exc())
1713
54687aa00724 Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents: 1712
diff changeset
410 Session().rollback()
1436
88d13c1c6a55 removed users_group controller in replace for model methods,
Marcin Kuzminski <marcin@python-works.com>
parents: 1435
diff changeset
411 raise
88d13c1c6a55 removed users_group controller in replace for model methods,
Marcin Kuzminski <marcin@python-works.com>
parents: 1435
diff changeset
412
88d13c1c6a55 removed users_group controller in replace for model methods,
Marcin Kuzminski <marcin@python-works.com>
parents: 1435
diff changeset
413 @classmethod
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
414 def update(cls, users_group_id, form_data):
1436
88d13c1c6a55 removed users_group controller in replace for model methods,
Marcin Kuzminski <marcin@python-works.com>
parents: 1435
diff changeset
415
88d13c1c6a55 removed users_group controller in replace for model methods,
Marcin Kuzminski <marcin@python-works.com>
parents: 1435
diff changeset
416 try:
1594
9dae92a65e40 fixes #288
Marcin Kuzminski <marcin@python-works.com>
parents: 1593
diff changeset
417 users_group = cls.get(users_group_id, cache=False)
1436
88d13c1c6a55 removed users_group controller in replace for model methods,
Marcin Kuzminski <marcin@python-works.com>
parents: 1435
diff changeset
418
88d13c1c6a55 removed users_group controller in replace for model methods,
Marcin Kuzminski <marcin@python-works.com>
parents: 1435
diff changeset
419 for k, v in form_data.items():
88d13c1c6a55 removed users_group controller in replace for model methods,
Marcin Kuzminski <marcin@python-works.com>
parents: 1435
diff changeset
420 if k == 'users_group_members':
88d13c1c6a55 removed users_group controller in replace for model methods,
Marcin Kuzminski <marcin@python-works.com>
parents: 1435
diff changeset
421 users_group.members = []
1713
54687aa00724 Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents: 1712
diff changeset
422 Session().flush()
1436
88d13c1c6a55 removed users_group controller in replace for model methods,
Marcin Kuzminski <marcin@python-works.com>
parents: 1435
diff changeset
423 members_list = []
88d13c1c6a55 removed users_group controller in replace for model methods,
Marcin Kuzminski <marcin@python-works.com>
parents: 1435
diff changeset
424 if v:
1577
534b9c0a5646 Proper patch for issue #276
Marcin Kuzminski <marcin@python-works.com>
parents: 1576
diff changeset
425 v = [v] if isinstance(v, basestring) else v
534b9c0a5646 Proper patch for issue #276
Marcin Kuzminski <marcin@python-works.com>
parents: 1576
diff changeset
426 for u_id in set(v):
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
427 member = UsersGroupMember(users_group_id, u_id)
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
428 members_list.append(member)
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
429 setattr(users_group, 'members', members_list)
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
430 setattr(users_group, k, v)
1436
88d13c1c6a55 removed users_group controller in replace for model methods,
Marcin Kuzminski <marcin@python-works.com>
parents: 1435
diff changeset
431
1713
54687aa00724 Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents: 1712
diff changeset
432 Session().add(users_group)
54687aa00724 Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents: 1712
diff changeset
433 Session().commit()
1436
88d13c1c6a55 removed users_group controller in replace for model methods,
Marcin Kuzminski <marcin@python-works.com>
parents: 1435
diff changeset
434 except:
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
435 log.error(traceback.format_exc())
1713
54687aa00724 Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents: 1712
diff changeset
436 Session().rollback()
1436
88d13c1c6a55 removed users_group controller in replace for model methods,
Marcin Kuzminski <marcin@python-works.com>
parents: 1435
diff changeset
437 raise
88d13c1c6a55 removed users_group controller in replace for model methods,
Marcin Kuzminski <marcin@python-works.com>
parents: 1435
diff changeset
438
88d13c1c6a55 removed users_group controller in replace for model methods,
Marcin Kuzminski <marcin@python-works.com>
parents: 1435
diff changeset
439 @classmethod
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
440 def delete(cls, users_group_id):
1436
88d13c1c6a55 removed users_group controller in replace for model methods,
Marcin Kuzminski <marcin@python-works.com>
parents: 1435
diff changeset
441 try:
88d13c1c6a55 removed users_group controller in replace for model methods,
Marcin Kuzminski <marcin@python-works.com>
parents: 1435
diff changeset
442
88d13c1c6a55 removed users_group controller in replace for model methods,
Marcin Kuzminski <marcin@python-works.com>
parents: 1435
diff changeset
443 # check if this group is not assigned to repo
88d13c1c6a55 removed users_group controller in replace for model methods,
Marcin Kuzminski <marcin@python-works.com>
parents: 1435
diff changeset
444 assigned_groups = UsersGroupRepoToPerm.query()\
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
445 .filter(UsersGroupRepoToPerm.users_group_id ==
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
446 users_group_id).all()
1436
88d13c1c6a55 removed users_group controller in replace for model methods,
Marcin Kuzminski <marcin@python-works.com>
parents: 1435
diff changeset
447
88d13c1c6a55 removed users_group controller in replace for model methods,
Marcin Kuzminski <marcin@python-works.com>
parents: 1435
diff changeset
448 if assigned_groups:
1633
2c0d35e336b5 refactoring of models names for repoGroup permissions
Marcin Kuzminski <marcin@python-works.com>
parents: 1607
diff changeset
449 raise UsersGroupsAssignedException('RepoGroup assigned to %s' %
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
450 assigned_groups)
1436
88d13c1c6a55 removed users_group controller in replace for model methods,
Marcin Kuzminski <marcin@python-works.com>
parents: 1435
diff changeset
451
1594
9dae92a65e40 fixes #288
Marcin Kuzminski <marcin@python-works.com>
parents: 1593
diff changeset
452 users_group = cls.get(users_group_id, cache=False)
1713
54687aa00724 Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents: 1712
diff changeset
453 Session().delete(users_group)
54687aa00724 Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents: 1712
diff changeset
454 Session().commit()
1436
88d13c1c6a55 removed users_group controller in replace for model methods,
Marcin Kuzminski <marcin@python-works.com>
parents: 1435
diff changeset
455 except:
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
456 log.error(traceback.format_exc())
1713
54687aa00724 Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents: 1712
diff changeset
457 Session().rollback()
1436
88d13c1c6a55 removed users_group controller in replace for model methods,
Marcin Kuzminski <marcin@python-works.com>
parents: 1435
diff changeset
458 raise
88d13c1c6a55 removed users_group controller in replace for model methods,
Marcin Kuzminski <marcin@python-works.com>
parents: 1435
diff changeset
459
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
460 class UsersGroupMember(Base, BaseModel):
956
83d35d716a02 started working on issue #56
Marcin Kuzminski <marcin@python-works.com>
parents: 907
diff changeset
461 __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
462 __table_args__ = {'extend_existing':True}
956
83d35d716a02 started working on issue #56
Marcin Kuzminski <marcin@python-works.com>
parents: 907
diff changeset
463
1594
9dae92a65e40 fixes #288
Marcin Kuzminski <marcin@python-works.com>
parents: 1593
diff changeset
464 users_group_member_id = Column("users_group_member_id", Integer(), nullable=False, unique=True, default=None, primary_key=True)
9dae92a65e40 fixes #288
Marcin Kuzminski <marcin@python-works.com>
parents: 1593
diff changeset
465 users_group_id = Column("users_group_id", Integer(), ForeignKey('users_groups.users_group_id'), nullable=False, unique=None, default=None)
9dae92a65e40 fixes #288
Marcin Kuzminski <marcin@python-works.com>
parents: 1593
diff changeset
466 user_id = Column("user_id", Integer(), ForeignKey('users.user_id'), nullable=False, unique=None, default=None)
956
83d35d716a02 started working on issue #56
Marcin Kuzminski <marcin@python-works.com>
parents: 907
diff changeset
467
1594
9dae92a65e40 fixes #288
Marcin Kuzminski <marcin@python-works.com>
parents: 1593
diff changeset
468 user = relationship('User', lazy='joined')
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
469 users_group = relationship('UsersGroup')
972
2c8fd84935a4 #56 implemented users groups editing,
Marcin Kuzminski <marcin@python-works.com>
parents: 962
diff changeset
470
1594
9dae92a65e40 fixes #288
Marcin Kuzminski <marcin@python-works.com>
parents: 1593
diff changeset
471 def __init__(self, gr_id='', u_id=''):
972
2c8fd84935a4 #56 implemented users groups editing,
Marcin Kuzminski <marcin@python-works.com>
parents: 962
diff changeset
472 self.users_group_id = gr_id
2c8fd84935a4 #56 implemented users groups editing,
Marcin Kuzminski <marcin@python-works.com>
parents: 962
diff changeset
473 self.user_id = u_id
956
83d35d716a02 started working on issue #56
Marcin Kuzminski <marcin@python-works.com>
parents: 907
diff changeset
474
1587
8898a79ac628 Implement all CRUD API operation for repo
Nicolas VINOT <aeris@imirhil.fr>
parents: 1586
diff changeset
475 @staticmethod
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
476 def add_user_to_group(group, user):
1587
8898a79ac628 Implement all CRUD API operation for repo
Nicolas VINOT <aeris@imirhil.fr>
parents: 1586
diff changeset
477 ugm = UsersGroupMember()
8898a79ac628 Implement all CRUD API operation for repo
Nicolas VINOT <aeris@imirhil.fr>
parents: 1586
diff changeset
478 ugm.users_group = group
8898a79ac628 Implement all CRUD API operation for repo
Nicolas VINOT <aeris@imirhil.fr>
parents: 1586
diff changeset
479 ugm.user = user
1713
54687aa00724 Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents: 1712
diff changeset
480 Session().add(ugm)
54687aa00724 Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents: 1712
diff changeset
481 Session().commit()
1587
8898a79ac628 Implement all CRUD API operation for repo
Nicolas VINOT <aeris@imirhil.fr>
parents: 1586
diff changeset
482 return ugm
8898a79ac628 Implement all CRUD API operation for repo
Nicolas VINOT <aeris@imirhil.fr>
parents: 1586
diff changeset
483
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
484 class Repository(Base, BaseModel):
234
a0116e944da1 changed naming convention for db modules.
Marcin Kuzminski <marcin@python-works.com>
parents: 232
diff changeset
485 __tablename__ = 'repositories'
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
486 __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
487
1594
9dae92a65e40 fixes #288
Marcin Kuzminski <marcin@python-works.com>
parents: 1593
diff changeset
488 repo_id = Column("repo_id", Integer(), nullable=False, unique=True, default=None, primary_key=True)
9dae92a65e40 fixes #288
Marcin Kuzminski <marcin@python-works.com>
parents: 1593
diff changeset
489 repo_name = Column("repo_name", String(length=255, convert_unicode=False, assert_unicode=None), nullable=False, unique=True, default=None)
9dae92a65e40 fixes #288
Marcin Kuzminski <marcin@python-works.com>
parents: 1593
diff changeset
490 clone_uri = Column("clone_uri", String(length=255, convert_unicode=False, assert_unicode=None), nullable=True, unique=False, default=None)
9dae92a65e40 fixes #288
Marcin Kuzminski <marcin@python-works.com>
parents: 1593
diff changeset
491 repo_type = Column("repo_type", String(length=255, convert_unicode=False, assert_unicode=None), nullable=False, unique=False, default='hg')
9dae92a65e40 fixes #288
Marcin Kuzminski <marcin@python-works.com>
parents: 1593
diff changeset
492 user_id = Column("user_id", Integer(), ForeignKey('users.user_id'), nullable=False, unique=False, default=None)
9dae92a65e40 fixes #288
Marcin Kuzminski <marcin@python-works.com>
parents: 1593
diff changeset
493 private = Column("private", Boolean(), nullable=True, unique=None, default=None)
9dae92a65e40 fixes #288
Marcin Kuzminski <marcin@python-works.com>
parents: 1593
diff changeset
494 enable_statistics = Column("statistics", Boolean(), nullable=True, unique=None, default=True)
9dae92a65e40 fixes #288
Marcin Kuzminski <marcin@python-works.com>
parents: 1593
diff changeset
495 enable_downloads = Column("downloads", Boolean(), nullable=True, unique=None, default=True)
9dae92a65e40 fixes #288
Marcin Kuzminski <marcin@python-works.com>
parents: 1593
diff changeset
496 description = Column("description", String(length=10000, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None)
9dae92a65e40 fixes #288
Marcin Kuzminski <marcin@python-works.com>
parents: 1593
diff changeset
497 created_on = Column('created_on', DateTime(timezone=False), nullable=True, unique=None, default=datetime.datetime.now)
1301
7e75af301842 Added simple forks page, resolves issue #179
Marcin Kuzminski <marcin@python-works.com>
parents: 1292
diff changeset
498
1594
9dae92a65e40 fixes #288
Marcin Kuzminski <marcin@python-works.com>
parents: 1593
diff changeset
499 fork_id = Column("fork_id", Integer(), ForeignKey('repositories.repo_id'), nullable=True, unique=False, default=None)
9dae92a65e40 fixes #288
Marcin Kuzminski <marcin@python-works.com>
parents: 1593
diff changeset
500 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
501
1113
c1eda8ec4a46 added clone_uri,api_key into models. Fixed models for mysql compatibilty
Marcin Kuzminski <marcin@python-works.com>
parents: 1088
diff changeset
502
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
503 user = relationship('User')
1594
9dae92a65e40 fixes #288
Marcin Kuzminski <marcin@python-works.com>
parents: 1593
diff changeset
504 fork = relationship('Repository', remote_side=repo_id)
1633
2c0d35e336b5 refactoring of models names for repoGroup permissions
Marcin Kuzminski <marcin@python-works.com>
parents: 1607
diff changeset
505 group = relationship('RepoGroup')
2c0d35e336b5 refactoring of models names for repoGroup permissions
Marcin Kuzminski <marcin@python-works.com>
parents: 1607
diff changeset
506 repo_to_perm = relationship('UserRepoToPerm', cascade='all', order_by='UserRepoToPerm.repo_to_perm_id')
1594
9dae92a65e40 fixes #288
Marcin Kuzminski <marcin@python-works.com>
parents: 1593
diff changeset
507 users_group_to_perm = relationship('UsersGroupRepoToPerm', cascade='all')
9dae92a65e40 fixes #288
Marcin Kuzminski <marcin@python-works.com>
parents: 1593
diff changeset
508 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
509
1594
9dae92a65e40 fixes #288
Marcin Kuzminski <marcin@python-works.com>
parents: 1593
diff changeset
510 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
511
1594
9dae92a65e40 fixes #288
Marcin Kuzminski <marcin@python-works.com>
parents: 1593
diff changeset
512 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
513
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
514 def __repr__(self):
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
515 return "<%s('%s:%s')>" % (self.__class__.__name__,
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
516 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
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 @classmethod
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
519 def url_sep(cls):
1554
e7c6341ad3cb fixes #245 Rescan of the repositories on Windows
Marcin Kuzminski <marcin@python-works.com>
parents: 1547
diff changeset
520 return '/'
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
521
1554
e7c6341ad3cb fixes #245 Rescan of the repositories on Windows
Marcin Kuzminski <marcin@python-works.com>
parents: 1547
diff changeset
522 @classmethod
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
523 def get_by_repo_name(cls, repo_name):
1713
54687aa00724 Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents: 1712
diff changeset
524 q = Session().query(cls).filter(cls.repo_name == repo_name)
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
525 q = q.options(joinedload(Repository.fork))\
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
526 .options(joinedload(Repository.user))\
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
527 .options(joinedload(Repository.group))
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
528 return q.one()
1301
7e75af301842 Added simple forks page, resolves issue #179
Marcin Kuzminski <marcin@python-works.com>
parents: 1292
diff changeset
529
7e75af301842 Added simple forks page, resolves issue #179
Marcin Kuzminski <marcin@python-works.com>
parents: 1292
diff changeset
530 @classmethod
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
531 def get_repo_forks(cls, repo_id):
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
532 return cls.query().filter(Repository.fork_id == repo_id)
1301
7e75af301842 Added simple forks page, resolves issue #179
Marcin Kuzminski <marcin@python-works.com>
parents: 1292
diff changeset
533
1508
4aba7be311e8 API added checks for a valid repository on pull command
Marcin Kuzminski <marcin@python-works.com>
parents: 1500
diff changeset
534 @classmethod
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
535 def base_path(cls):
1508
4aba7be311e8 API added checks for a valid repository on pull command
Marcin Kuzminski <marcin@python-works.com>
parents: 1500
diff changeset
536 """
4aba7be311e8 API added checks for a valid repository on pull command
Marcin Kuzminski <marcin@python-works.com>
parents: 1500
diff changeset
537 Returns base path when all repos are stored
1587
8898a79ac628 Implement all CRUD API operation for repo
Nicolas VINOT <aeris@imirhil.fr>
parents: 1586
diff changeset
538
1508
4aba7be311e8 API added checks for a valid repository on pull command
Marcin Kuzminski <marcin@python-works.com>
parents: 1500
diff changeset
539 :param cls:
4aba7be311e8 API added checks for a valid repository on pull command
Marcin Kuzminski <marcin@python-works.com>
parents: 1500
diff changeset
540 """
1728
07e56179633e - fixes celery sqlalchemy session issues for async forking
Marcin Kuzminski <marcin@python-works.com>
parents: 1727
diff changeset
541 q = Session().query(RhodeCodeUi)\
07e56179633e - fixes celery sqlalchemy session issues for async forking
Marcin Kuzminski <marcin@python-works.com>
parents: 1727
diff changeset
542 .filter(RhodeCodeUi.ui_key == cls.url_sep())
07e56179633e - fixes celery sqlalchemy session issues for async forking
Marcin Kuzminski <marcin@python-works.com>
parents: 1727
diff changeset
543 q = q.options(FromCache("sql_cache_short", "repository_repo_path"))
1508
4aba7be311e8 API added checks for a valid repository on pull command
Marcin Kuzminski <marcin@python-works.com>
parents: 1500
diff changeset
544 return q.one().ui_value
4aba7be311e8 API added checks for a valid repository on pull command
Marcin Kuzminski <marcin@python-works.com>
parents: 1500
diff changeset
545
1113
c1eda8ec4a46 added clone_uri,api_key into models. Fixed models for mysql compatibilty
Marcin Kuzminski <marcin@python-works.com>
parents: 1088
diff changeset
546 @property
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
547 def just_name(self):
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
548 return self.repo_name.split(Repository.url_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
549
37a9421f32a0 Added handy methods to Repository model for fetching groups with parents
Marcin Kuzminski <marcin@python-works.com>
parents: 1113
diff changeset
550 @property
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
551 def groups_with_parents(self):
1155
37a9421f32a0 Added handy methods to Repository model for fetching groups with parents
Marcin Kuzminski <marcin@python-works.com>
parents: 1113
diff changeset
552 groups = []
37a9421f32a0 Added handy methods to Repository model for fetching groups with parents
Marcin Kuzminski <marcin@python-works.com>
parents: 1113
diff changeset
553 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
554 return groups
37a9421f32a0 Added handy methods to Repository model for fetching groups with parents
Marcin Kuzminski <marcin@python-works.com>
parents: 1113
diff changeset
555
37a9421f32a0 Added handy methods to Repository model for fetching groups with parents
Marcin Kuzminski <marcin@python-works.com>
parents: 1113
diff changeset
556 cur_gr = self.group
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
557 groups.insert(0, cur_gr)
1155
37a9421f32a0 Added handy methods to Repository model for fetching groups with parents
Marcin Kuzminski <marcin@python-works.com>
parents: 1113
diff changeset
558 while 1:
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
559 gr = getattr(cur_gr, 'parent_group', None)
1155
37a9421f32a0 Added handy methods to Repository model for fetching groups with parents
Marcin Kuzminski <marcin@python-works.com>
parents: 1113
diff changeset
560 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
561 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
562 break
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
563 groups.insert(0, gr)
1155
37a9421f32a0 Added handy methods to Repository model for fetching groups with parents
Marcin Kuzminski <marcin@python-works.com>
parents: 1113
diff changeset
564
37a9421f32a0 Added handy methods to Repository model for fetching groups with parents
Marcin Kuzminski <marcin@python-works.com>
parents: 1113
diff changeset
565 return groups
37a9421f32a0 Added handy methods to Repository model for fetching groups with parents
Marcin Kuzminski <marcin@python-works.com>
parents: 1113
diff changeset
566
37a9421f32a0 Added handy methods to Repository model for fetching groups with parents
Marcin Kuzminski <marcin@python-works.com>
parents: 1113
diff changeset
567 @property
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
568 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
569 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
570
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
571 @LazyProperty
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
572 def repo_path(self):
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
573 """
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
574 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
575 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
576 """
1713
54687aa00724 Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents: 1712
diff changeset
577 q = Session().query(RhodeCodeUi).filter(RhodeCodeUi.ui_key ==
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
578 Repository.url_sep())
1727
8e9f51091229 fixed caching query on repos path
Marcin Kuzminski <marcin@python-works.com>
parents: 1723
diff changeset
579 q = q.options(FromCache("sql_cache_short", "repository_repo_path"))
1368
04b43168742d adde short cache for repo_path
Marcin Kuzminski <marcin@python-works.com>
parents: 1366
diff changeset
580 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
581
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
582 @property
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
583 def repo_full_path(self):
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
584 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
585 # 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
586 # 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
587 # into a valid system path
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
588 p += self.repo_name.split(Repository.url_sep())
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
589 return os.path.join(*p)
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
590
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
591 def get_new_name(self, repo_name):
1539
bd604cf75c5a fixes #260 Put repo in group, then move group to another group -> repo becomes unavailable
Marcin Kuzminski <marcin@python-works.com>
parents: 1538
diff changeset
592 """
bd604cf75c5a fixes #260 Put repo in group, then move group to another group -> repo becomes unavailable
Marcin Kuzminski <marcin@python-works.com>
parents: 1538
diff changeset
593 returns new full repository name based on assigned group and new new
1591
0b63a0d2cede Merge with upstream
Nicolas VINOT <aeris@imirhil.fr>
parents: 1576 1590
diff changeset
594
1539
bd604cf75c5a fixes #260 Put repo in group, then move group to another group -> repo becomes unavailable
Marcin Kuzminski <marcin@python-works.com>
parents: 1538
diff changeset
595 :param group_name:
bd604cf75c5a fixes #260 Put repo in group, then move group to another group -> repo becomes unavailable
Marcin Kuzminski <marcin@python-works.com>
parents: 1538
diff changeset
596 """
bd604cf75c5a fixes #260 Put repo in group, then move group to another group -> repo becomes unavailable
Marcin Kuzminski <marcin@python-works.com>
parents: 1538
diff changeset
597 path_prefix = self.group.full_path_splitted if self.group else []
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
598 return Repository.url_sep().join(path_prefix + [repo_name])
1539
bd604cf75c5a fixes #260 Put repo in group, then move group to another group -> repo becomes unavailable
Marcin Kuzminski <marcin@python-works.com>
parents: 1538
diff changeset
599
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
600 @property
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
601 def _ui(self):
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
602 """
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
603 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
604 """
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
605 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
606 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
607 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
608
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
609 #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
610 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
611 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
612 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
613
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
614
1584
3338a0994472 Improve API with user/group/repo CRUD methods
Nicolas VINOT <aeris@imirhil.fr>
parents: 1508
diff changeset
615 ret = RhodeCodeUi.query()\
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
616 .options(FromCache("sql_cache_short", "repository_repo_ui")).all()
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
617
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
618 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
619 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
620 if ui_.ui_active:
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
621 log.debug('settings ui from db[%s]%s:%s', ui_.ui_section,
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
622 ui_.ui_key, ui_.ui_value)
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
623 baseui.setconfig(ui_.ui_section, ui_.ui_key, ui_.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
624
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
625 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
626
1508
4aba7be311e8 API added checks for a valid repository on pull command
Marcin Kuzminski <marcin@python-works.com>
parents: 1500
diff changeset
627 @classmethod
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
628 def is_valid(cls, repo_name):
1508
4aba7be311e8 API added checks for a valid repository on pull command
Marcin Kuzminski <marcin@python-works.com>
parents: 1500
diff changeset
629 """
4aba7be311e8 API added checks for a valid repository on pull command
Marcin Kuzminski <marcin@python-works.com>
parents: 1500
diff changeset
630 returns True if given repo name is a valid filesystem repository
1587
8898a79ac628 Implement all CRUD API operation for repo
Nicolas VINOT <aeris@imirhil.fr>
parents: 1586
diff changeset
631
1508
4aba7be311e8 API added checks for a valid repository on pull command
Marcin Kuzminski <marcin@python-works.com>
parents: 1500
diff changeset
632 @param cls:
4aba7be311e8 API added checks for a valid repository on pull command
Marcin Kuzminski <marcin@python-works.com>
parents: 1500
diff changeset
633 @param repo_name:
4aba7be311e8 API added checks for a valid repository on pull command
Marcin Kuzminski <marcin@python-works.com>
parents: 1500
diff changeset
634 """
4aba7be311e8 API added checks for a valid repository on pull command
Marcin Kuzminski <marcin@python-works.com>
parents: 1500
diff changeset
635 from rhodecode.lib.utils import is_valid_repo
4aba7be311e8 API added checks for a valid repository on pull command
Marcin Kuzminski <marcin@python-works.com>
parents: 1500
diff changeset
636
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
637 return is_valid_repo(repo_name, cls.base_path())
1508
4aba7be311e8 API added checks for a valid repository on pull command
Marcin Kuzminski <marcin@python-works.com>
parents: 1500
diff changeset
638
4aba7be311e8 API added checks for a valid repository on pull command
Marcin Kuzminski <marcin@python-works.com>
parents: 1500
diff changeset
639
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
640 #==========================================================================
1466
ad5a543a9b2f Code cleanup
Marcin Kuzminski <marcin@python-works.com>
parents: 1460
diff changeset
641 # SCM PROPERTIES
ad5a543a9b2f Code cleanup
Marcin Kuzminski <marcin@python-works.com>
parents: 1460
diff changeset
642 #==========================================================================
ad5a543a9b2f Code cleanup
Marcin Kuzminski <marcin@python-works.com>
parents: 1460
diff changeset
643
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
644 def get_changeset(self, rev):
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
645 return get_changeset_safe(self.scm_instance, rev)
1466
ad5a543a9b2f Code cleanup
Marcin Kuzminski <marcin@python-works.com>
parents: 1460
diff changeset
646
ad5a543a9b2f Code cleanup
Marcin Kuzminski <marcin@python-works.com>
parents: 1460
diff changeset
647 @property
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
648 def tip(self):
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
649 return self.get_changeset('tip')
1466
ad5a543a9b2f Code cleanup
Marcin Kuzminski <marcin@python-works.com>
parents: 1460
diff changeset
650
ad5a543a9b2f Code cleanup
Marcin Kuzminski <marcin@python-works.com>
parents: 1460
diff changeset
651 @property
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
652 def author(self):
1466
ad5a543a9b2f Code cleanup
Marcin Kuzminski <marcin@python-works.com>
parents: 1460
diff changeset
653 return self.tip.author
ad5a543a9b2f Code cleanup
Marcin Kuzminski <marcin@python-works.com>
parents: 1460
diff changeset
654
ad5a543a9b2f Code cleanup
Marcin Kuzminski <marcin@python-works.com>
parents: 1460
diff changeset
655 @property
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
656 def last_change(self):
1466
ad5a543a9b2f Code cleanup
Marcin Kuzminski <marcin@python-works.com>
parents: 1460
diff changeset
657 return self.scm_instance.last_change
ad5a543a9b2f Code cleanup
Marcin Kuzminski <marcin@python-works.com>
parents: 1460
diff changeset
658
ad5a543a9b2f Code cleanup
Marcin Kuzminski <marcin@python-works.com>
parents: 1460
diff changeset
659 #==========================================================================
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
660 # 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
661 #==========================================================================
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
662
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
663 @property
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
664 def invalidate(self):
1607
e886f91fcb71 Cached readme generation
Marcin Kuzminski <marcin@python-works.com>
parents: 1594
diff changeset
665 return CacheInvalidation.invalidate(self.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
666
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
667 def set_invalidate(self):
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
668 """
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
669 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
670 """
1607
e886f91fcb71 Cached readme generation
Marcin Kuzminski <marcin@python-works.com>
parents: 1594
diff changeset
671 CacheInvalidation.set_invalidate(self.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
672
1466
ad5a543a9b2f Code cleanup
Marcin Kuzminski <marcin@python-works.com>
parents: 1460
diff changeset
673 @LazyProperty
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
674 def scm_instance(self):
1400
0d7b56b97953 Simplified last_login call on user, and changed login to use User model directly
Marcin Kuzminski <marcin@python-works.com>
parents: 1388
diff changeset
675 return self.__get_instance()
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
676
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
677 @property
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
678 def scm_instance_cached(self):
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
679 @cache_region('long_term')
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
680 def _c(repo_name):
1400
0d7b56b97953 Simplified last_login call on user, and changed login to use User model directly
Marcin Kuzminski <marcin@python-works.com>
parents: 1388
diff changeset
681 return self.__get_instance()
1607
e886f91fcb71 Cached readme generation
Marcin Kuzminski <marcin@python-works.com>
parents: 1594
diff changeset
682 rn = self.repo_name
1428
e5467730682b fixed some issues with cache invalidation, and simplified invalidation codes
Marcin Kuzminski <marcin@python-works.com>
parents: 1427
diff changeset
683
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
684 inv = self.invalidate
1427
ba697e2f71ff fixed a bug in cache invalidation
Marcin Kuzminski <marcin@python-works.com>
parents: 1417
diff changeset
685 if inv is not None:
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
686 region_invalidate(_c, None, rn)
1428
e5467730682b fixed some issues with cache invalidation, and simplified invalidation codes
Marcin Kuzminski <marcin@python-works.com>
parents: 1427
diff changeset
687 # update our cache
1607
e886f91fcb71 Cached readme generation
Marcin Kuzminski <marcin@python-works.com>
parents: 1594
diff changeset
688 CacheInvalidation.set_valid(inv.cache_key)
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
689 return _c(rn)
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
690
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
691 def __get_instance(self):
1368
04b43168742d adde short cache for repo_path
Marcin Kuzminski <marcin@python-works.com>
parents: 1366
diff changeset
692
04b43168742d adde short cache for repo_path
Marcin Kuzminski <marcin@python-works.com>
parents: 1366
diff changeset
693 repo_full_path = self.repo_full_path
04b43168742d adde short cache for repo_path
Marcin Kuzminski <marcin@python-works.com>
parents: 1366
diff changeset
694
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
695 try:
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
696 alias = get_scm(repo_full_path)[0]
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
697 log.debug('Creating instance of %s repository', alias)
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
698 backend = get_backend(alias)
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
699 except VCSError:
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
700 log.error(traceback.format_exc())
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
701 log.error('Perhaps this repository is in db and not in '
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
702 'filesystem run rescan repositories with '
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
703 '"destroy old data " option from admin panel')
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
704 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
705
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
706 if alias == 'hg':
1401
b7563ad4e7ee Unicode fixes, added safe_str method for global str() operations +better test sandboxing
Marcin Kuzminski <marcin@python-works.com>
parents: 1400
diff changeset
707
1594
9dae92a65e40 fixes #288
Marcin Kuzminski <marcin@python-works.com>
parents: 1593
diff changeset
708 repo = backend(safe_str(repo_full_path), create=False,
9dae92a65e40 fixes #288
Marcin Kuzminski <marcin@python-works.com>
parents: 1593
diff changeset
709 baseui=self._ui)
1607
e886f91fcb71 Cached readme generation
Marcin Kuzminski <marcin@python-works.com>
parents: 1594
diff changeset
710 # skip hidden web repository
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
711 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
712 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
713 else:
1594
9dae92a65e40 fixes #288
Marcin Kuzminski <marcin@python-works.com>
parents: 1593
diff changeset
714 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
715
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
716 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
717
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
718
1633
2c0d35e336b5 refactoring of models names for repoGroup permissions
Marcin Kuzminski <marcin@python-works.com>
parents: 1607
diff changeset
719 class RepoGroup(Base, BaseModel):
878
859bc9e7a15d Extended repo2db mapper with group creation via directory structures
Marcin Kuzminski <marcin@python-works.com>
parents: 836
diff changeset
720 __tablename__ = 'groups'
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
721 __table_args__ = (UniqueConstraint('group_name', 'group_parent_id'),
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
722 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
723 __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
724
1594
9dae92a65e40 fixes #288
Marcin Kuzminski <marcin@python-works.com>
parents: 1593
diff changeset
725 group_id = Column("group_id", Integer(), nullable=False, unique=True, default=None, primary_key=True)
9dae92a65e40 fixes #288
Marcin Kuzminski <marcin@python-works.com>
parents: 1593
diff changeset
726 group_name = Column("group_name", String(length=255, convert_unicode=False, assert_unicode=None), nullable=False, unique=True, default=None)
9dae92a65e40 fixes #288
Marcin Kuzminski <marcin@python-works.com>
parents: 1593
diff changeset
727 group_parent_id = Column("group_parent_id", Integer(), ForeignKey('groups.group_id'), nullable=True, unique=None, default=None)
9dae92a65e40 fixes #288
Marcin Kuzminski <marcin@python-works.com>
parents: 1593
diff changeset
728 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
729
1633
2c0d35e336b5 refactoring of models names for repoGroup permissions
Marcin Kuzminski <marcin@python-works.com>
parents: 1607
diff changeset
730 parent_group = relationship('RepoGroup', 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
731
859bc9e7a15d Extended repo2db mapper with group creation via directory structures
Marcin Kuzminski <marcin@python-works.com>
parents: 836
diff changeset
732
1594
9dae92a65e40 fixes #288
Marcin Kuzminski <marcin@python-works.com>
parents: 1593
diff changeset
733 def __init__(self, group_name='', parent_group=None):
878
859bc9e7a15d Extended repo2db mapper with group creation via directory structures
Marcin Kuzminski <marcin@python-works.com>
parents: 836
diff changeset
734 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
735 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
736
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
737 def __repr__(self):
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
738 return "<%s('%s:%s')>" % (self.__class__.__name__, self.group_id,
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
739 self.group_name)
631
05528ad948c4 Hacking for git support,and new faster repo scan
Marcin Kuzminski <marcin@python-works.com>
parents: 549
diff changeset
740
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
741 @classmethod
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
742 def groups_choices(cls):
1547
fbc762ae3496 unified generation of repo groups choices
Marcin Kuzminski <marcin@python-works.com>
parents: 1546
diff changeset
743 from webhelpers.html import literal as _literal
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
744 repo_groups = [('', '')]
1547
fbc762ae3496 unified generation of repo groups choices
Marcin Kuzminski <marcin@python-works.com>
parents: 1546
diff changeset
745 sep = ' &raquo; '
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
746 _name = lambda k: _literal(sep.join(k))
1547
fbc762ae3496 unified generation of repo groups choices
Marcin Kuzminski <marcin@python-works.com>
parents: 1546
diff changeset
747
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
748 repo_groups.extend([(x.group_id, _name(x.full_path_splitted))
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
749 for x in cls.query().all()])
1591
0b63a0d2cede Merge with upstream
Nicolas VINOT <aeris@imirhil.fr>
parents: 1576 1590
diff changeset
750
1594
9dae92a65e40 fixes #288
Marcin Kuzminski <marcin@python-works.com>
parents: 1593
diff changeset
751 repo_groups = sorted(repo_groups, key=lambda t: t[1].split(sep)[0])
1547
fbc762ae3496 unified generation of repo groups choices
Marcin Kuzminski <marcin@python-works.com>
parents: 1546
diff changeset
752 return repo_groups
1591
0b63a0d2cede Merge with upstream
Nicolas VINOT <aeris@imirhil.fr>
parents: 1576 1590
diff changeset
753
1547
fbc762ae3496 unified generation of repo groups choices
Marcin Kuzminski <marcin@python-works.com>
parents: 1546
diff changeset
754 @classmethod
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
755 def url_sep(cls):
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
756 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
757
1538
27be8f94c207 implements #226 repo groups available by path
Marcin Kuzminski <marcin@python-works.com>
parents: 1530
diff changeset
758 @classmethod
1594
9dae92a65e40 fixes #288
Marcin Kuzminski <marcin@python-works.com>
parents: 1593
diff changeset
759 def get_by_group_name(cls, group_name, cache=False, case_insensitive=False):
1584
3338a0994472 Improve API with user/group/repo CRUD methods
Nicolas VINOT <aeris@imirhil.fr>
parents: 1508
diff changeset
760 if case_insensitive:
3338a0994472 Improve API with user/group/repo CRUD methods
Nicolas VINOT <aeris@imirhil.fr>
parents: 1508
diff changeset
761 gr = cls.query()\
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
762 .filter(cls.group_name.ilike(group_name))
1584
3338a0994472 Improve API with user/group/repo CRUD methods
Nicolas VINOT <aeris@imirhil.fr>
parents: 1508
diff changeset
763 else:
3338a0994472 Improve API with user/group/repo CRUD methods
Nicolas VINOT <aeris@imirhil.fr>
parents: 1508
diff changeset
764 gr = cls.query()\
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
765 .filter(cls.group_name == group_name)
1584
3338a0994472 Improve API with user/group/repo CRUD methods
Nicolas VINOT <aeris@imirhil.fr>
parents: 1508
diff changeset
766 if cache:
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
767 gr = gr.options(FromCache("sql_cache_short",
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
768 "get_group_%s" % group_name))
1584
3338a0994472 Improve API with user/group/repo CRUD methods
Nicolas VINOT <aeris@imirhil.fr>
parents: 1508
diff changeset
769 return gr.scalar()
1538
27be8f94c207 implements #226 repo groups available by path
Marcin Kuzminski <marcin@python-works.com>
parents: 1530
diff changeset
770
1159
187a924ed653 Changes for repo groups
Marcin Kuzminski <marcin@python-works.com>
parents: 1155
diff changeset
771 @property
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
772 def parents(self):
1385
7e221629a3e5 #209 Added recursive count on repositories to calculate all repos within all nested groups
Marcin Kuzminski <marcin@python-works.com>
parents: 1381
diff changeset
773 parents_recursion_limit = 5
1159
187a924ed653 Changes for repo groups
Marcin Kuzminski <marcin@python-works.com>
parents: 1155
diff changeset
774 groups = []
187a924ed653 Changes for repo groups
Marcin Kuzminski <marcin@python-works.com>
parents: 1155
diff changeset
775 if self.parent_group is None:
187a924ed653 Changes for repo groups
Marcin Kuzminski <marcin@python-works.com>
parents: 1155
diff changeset
776 return groups
187a924ed653 Changes for repo groups
Marcin Kuzminski <marcin@python-works.com>
parents: 1155
diff changeset
777 cur_gr = self.parent_group
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
778 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
779 cnt = 0
1159
187a924ed653 Changes for repo groups
Marcin Kuzminski <marcin@python-works.com>
parents: 1155
diff changeset
780 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
781 cnt += 1
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
782 gr = getattr(cur_gr, 'parent_group', None)
1159
187a924ed653 Changes for repo groups
Marcin Kuzminski <marcin@python-works.com>
parents: 1155
diff changeset
783 cur_gr = cur_gr.parent_group
187a924ed653 Changes for repo groups
Marcin Kuzminski <marcin@python-works.com>
parents: 1155
diff changeset
784 if gr is None:
187a924ed653 Changes for repo groups
Marcin Kuzminski <marcin@python-works.com>
parents: 1155
diff changeset
785 break
1385
7e221629a3e5 #209 Added recursive count on repositories to calculate all repos within all nested groups
Marcin Kuzminski <marcin@python-works.com>
parents: 1381
diff changeset
786 if cnt == parents_recursion_limit:
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
787 # this will prevent accidental infinit loops
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
788 log.error('group nested more than %s' %
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
789 parents_recursion_limit)
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
790 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
791
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
792 groups.insert(0, gr)
1159
187a924ed653 Changes for repo groups
Marcin Kuzminski <marcin@python-works.com>
parents: 1155
diff changeset
793 return groups
187a924ed653 Changes for repo groups
Marcin Kuzminski <marcin@python-works.com>
parents: 1155
diff changeset
794
1385
7e221629a3e5 #209 Added recursive count on repositories to calculate all repos within all nested groups
Marcin Kuzminski <marcin@python-works.com>
parents: 1381
diff changeset
795 @property
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
796 def children(self):
1633
2c0d35e336b5 refactoring of models names for repoGroup permissions
Marcin Kuzminski <marcin@python-works.com>
parents: 1607
diff changeset
797 return RepoGroup.query().filter(RepoGroup.parent_group == self)
1323
a7a772ea7b95 fixed saving settings on repositories inside groups, also fixes #187
Marcin Kuzminski <marcin@python-works.com>
parents: 1301
diff changeset
798
a7a772ea7b95 fixed saving settings on repositories inside groups, also fixes #187
Marcin Kuzminski <marcin@python-works.com>
parents: 1301
diff changeset
799 @property
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
800 def name(self):
1633
2c0d35e336b5 refactoring of models names for repoGroup permissions
Marcin Kuzminski <marcin@python-works.com>
parents: 1607
diff changeset
801 return self.group_name.split(RepoGroup.url_sep())[-1]
1538
27be8f94c207 implements #226 repo groups available by path
Marcin Kuzminski <marcin@python-works.com>
parents: 1530
diff changeset
802
27be8f94c207 implements #226 repo groups available by path
Marcin Kuzminski <marcin@python-works.com>
parents: 1530
diff changeset
803 @property
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
804 def full_path(self):
1594
9dae92a65e40 fixes #288
Marcin Kuzminski <marcin@python-works.com>
parents: 1593
diff changeset
805 return self.group_name
1538
27be8f94c207 implements #226 repo groups available by path
Marcin Kuzminski <marcin@python-works.com>
parents: 1530
diff changeset
806
27be8f94c207 implements #226 repo groups available by path
Marcin Kuzminski <marcin@python-works.com>
parents: 1530
diff changeset
807 @property
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
808 def full_path_splitted(self):
1633
2c0d35e336b5 refactoring of models names for repoGroup permissions
Marcin Kuzminski <marcin@python-works.com>
parents: 1607
diff changeset
809 return self.group_name.split(RepoGroup.url_sep())
1323
a7a772ea7b95 fixed saving settings on repositories inside groups, also fixes #187
Marcin Kuzminski <marcin@python-works.com>
parents: 1301
diff changeset
810
1193
523382549c45 Added repo group page showing what reposiories are inside a group
Marcin Kuzminski <marcin@python-works.com>
parents: 1159
diff changeset
811 @property
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
812 def repositories(self):
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
813 return Repository.query().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
814
1385
7e221629a3e5 #209 Added recursive count on repositories to calculate all repos within all nested groups
Marcin Kuzminski <marcin@python-works.com>
parents: 1381
diff changeset
815 @property
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
816 def repositories_recursive_count(self):
1385
7e221629a3e5 #209 Added recursive count on repositories to calculate all repos within all nested groups
Marcin Kuzminski <marcin@python-works.com>
parents: 1381
diff changeset
817 cnt = self.repositories.count()
7e221629a3e5 #209 Added recursive count on repositories to calculate all repos within all nested groups
Marcin Kuzminski <marcin@python-works.com>
parents: 1381
diff changeset
818
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
819 def children_count(group):
1385
7e221629a3e5 #209 Added recursive count on repositories to calculate all repos within all nested groups
Marcin Kuzminski <marcin@python-works.com>
parents: 1381
diff changeset
820 cnt = 0
7e221629a3e5 #209 Added recursive count on repositories to calculate all repos within all nested groups
Marcin Kuzminski <marcin@python-works.com>
parents: 1381
diff changeset
821 for child in group.children:
7e221629a3e5 #209 Added recursive count on repositories to calculate all repos within all nested groups
Marcin Kuzminski <marcin@python-works.com>
parents: 1381
diff changeset
822 cnt += child.repositories.count()
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
823 cnt += children_count(child)
1385
7e221629a3e5 #209 Added recursive count on repositories to calculate all repos within all nested groups
Marcin Kuzminski <marcin@python-works.com>
parents: 1381
diff changeset
824 return cnt
7e221629a3e5 #209 Added recursive count on repositories to calculate all repos within all nested groups
Marcin Kuzminski <marcin@python-works.com>
parents: 1381
diff changeset
825
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
826 return cnt + children_count(self)
1385
7e221629a3e5 #209 Added recursive count on repositories to calculate all repos within all nested groups
Marcin Kuzminski <marcin@python-works.com>
parents: 1381
diff changeset
827
1538
27be8f94c207 implements #226 repo groups available by path
Marcin Kuzminski <marcin@python-works.com>
parents: 1530
diff changeset
828
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
829 def get_new_name(self, group_name):
1538
27be8f94c207 implements #226 repo groups available by path
Marcin Kuzminski <marcin@python-works.com>
parents: 1530
diff changeset
830 """
27be8f94c207 implements #226 repo groups available by path
Marcin Kuzminski <marcin@python-works.com>
parents: 1530
diff changeset
831 returns new full group name based on parent and new name
1591
0b63a0d2cede Merge with upstream
Nicolas VINOT <aeris@imirhil.fr>
parents: 1576 1590
diff changeset
832
1538
27be8f94c207 implements #226 repo groups available by path
Marcin Kuzminski <marcin@python-works.com>
parents: 1530
diff changeset
833 :param group_name:
27be8f94c207 implements #226 repo groups available by path
Marcin Kuzminski <marcin@python-works.com>
parents: 1530
diff changeset
834 """
1607
e886f91fcb71 Cached readme generation
Marcin Kuzminski <marcin@python-works.com>
parents: 1594
diff changeset
835 path_prefix = (self.parent_group.full_path_splitted if
1594
9dae92a65e40 fixes #288
Marcin Kuzminski <marcin@python-works.com>
parents: 1593
diff changeset
836 self.parent_group else [])
1633
2c0d35e336b5 refactoring of models names for repoGroup permissions
Marcin Kuzminski <marcin@python-works.com>
parents: 1607
diff changeset
837 return RepoGroup.url_sep().join(path_prefix + [group_name])
1538
27be8f94c207 implements #226 repo groups available by path
Marcin Kuzminski <marcin@python-works.com>
parents: 1530
diff changeset
838
27be8f94c207 implements #226 repo groups available by path
Marcin Kuzminski <marcin@python-works.com>
parents: 1530
diff changeset
839
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
840 class Permission(Base, BaseModel):
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
841 __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
842 __table_args__ = {'extend_existing':True}
1594
9dae92a65e40 fixes #288
Marcin Kuzminski <marcin@python-works.com>
parents: 1593
diff changeset
843 permission_id = Column("permission_id", Integer(), nullable=False, unique=True, default=None, primary_key=True)
9dae92a65e40 fixes #288
Marcin Kuzminski <marcin@python-works.com>
parents: 1593
diff changeset
844 permission_name = Column("permission_name", String(length=255, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None)
9dae92a65e40 fixes #288
Marcin Kuzminski <marcin@python-works.com>
parents: 1593
diff changeset
845 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
846
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
847 def __repr__(self):
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
848 return "<%s('%s:%s')>" % (self.__class__.__name__,
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
849 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
850
1266
a1bcfe58a1ab Fixed #161 form saves the create repository permission.
Marcin Kuzminski <marcin@python-works.com>
parents: 1206
diff changeset
851 @classmethod
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
852 def get_by_key(cls, key):
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
853 return cls.query().filter(cls.permission_name == key).scalar()
1266
a1bcfe58a1ab Fixed #161 form saves the create repository permission.
Marcin Kuzminski <marcin@python-works.com>
parents: 1206
diff changeset
854
1728
07e56179633e - fixes celery sqlalchemy session issues for async forking
Marcin Kuzminski <marcin@python-works.com>
parents: 1727
diff changeset
855 @classmethod
07e56179633e - fixes celery sqlalchemy session issues for async forking
Marcin Kuzminski <marcin@python-works.com>
parents: 1727
diff changeset
856 def get_default_perms(cls, default_user_id, cache=True):
07e56179633e - fixes celery sqlalchemy session issues for async forking
Marcin Kuzminski <marcin@python-works.com>
parents: 1727
diff changeset
857 q = Session().query(UserRepoToPerm, Repository, cls)\
07e56179633e - fixes celery sqlalchemy session issues for async forking
Marcin Kuzminski <marcin@python-works.com>
parents: 1727
diff changeset
858 .join((Repository, UserRepoToPerm.repository_id == Repository.repo_id))\
07e56179633e - fixes celery sqlalchemy session issues for async forking
Marcin Kuzminski <marcin@python-works.com>
parents: 1727
diff changeset
859 .join((cls, UserRepoToPerm.permission_id == cls.permission_id))\
07e56179633e - fixes celery sqlalchemy session issues for async forking
Marcin Kuzminski <marcin@python-works.com>
parents: 1727
diff changeset
860 .filter(UserRepoToPerm.user_id == default_user_id)
07e56179633e - fixes celery sqlalchemy session issues for async forking
Marcin Kuzminski <marcin@python-works.com>
parents: 1727
diff changeset
861 if cache:
07e56179633e - fixes celery sqlalchemy session issues for async forking
Marcin Kuzminski <marcin@python-works.com>
parents: 1727
diff changeset
862 q = q.options(FromCache("sql_cache_short", "get_default_perms"))
07e56179633e - fixes celery sqlalchemy session issues for async forking
Marcin Kuzminski <marcin@python-works.com>
parents: 1727
diff changeset
863
07e56179633e - fixes celery sqlalchemy session issues for async forking
Marcin Kuzminski <marcin@python-works.com>
parents: 1727
diff changeset
864 return q.all()
07e56179633e - fixes celery sqlalchemy session issues for async forking
Marcin Kuzminski <marcin@python-works.com>
parents: 1727
diff changeset
865
07e56179633e - fixes celery sqlalchemy session issues for async forking
Marcin Kuzminski <marcin@python-works.com>
parents: 1727
diff changeset
866
1633
2c0d35e336b5 refactoring of models names for repoGroup permissions
Marcin Kuzminski <marcin@python-works.com>
parents: 1607
diff changeset
867 class UserRepoToPerm(Base, BaseModel):
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
868 __tablename__ = 'repo_to_perm'
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
869 __table_args__ = (UniqueConstraint('user_id', 'repository_id'), {'extend_existing':True})
1594
9dae92a65e40 fixes #288
Marcin Kuzminski <marcin@python-works.com>
parents: 1593
diff changeset
870 repo_to_perm_id = Column("repo_to_perm_id", Integer(), nullable=False, unique=True, default=None, primary_key=True)
9dae92a65e40 fixes #288
Marcin Kuzminski <marcin@python-works.com>
parents: 1593
diff changeset
871 user_id = Column("user_id", Integer(), ForeignKey('users.user_id'), nullable=False, unique=None, default=None)
9dae92a65e40 fixes #288
Marcin Kuzminski <marcin@python-works.com>
parents: 1593
diff changeset
872 permission_id = Column("permission_id", Integer(), ForeignKey('permissions.permission_id'), nullable=False, unique=None, default=None)
9dae92a65e40 fixes #288
Marcin Kuzminski <marcin@python-works.com>
parents: 1593
diff changeset
873 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
874
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
875 user = relationship('User')
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
876 permission = relationship('Permission')
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
877 repository = relationship('Repository')
399
f5c1eec9f376 rename repo2perm into repo_to_perm
Marcin Kuzminski <marcin@python-works.com>
parents: 392
diff changeset
878
1729
da8ee2ef7f6d implements #236 forking copy permission option
Marcin Kuzminski <marcin@python-works.com>
parents: 1728
diff changeset
879 @classmethod
da8ee2ef7f6d implements #236 forking copy permission option
Marcin Kuzminski <marcin@python-works.com>
parents: 1728
diff changeset
880 def create(cls, user, repository, permission):
da8ee2ef7f6d implements #236 forking copy permission option
Marcin Kuzminski <marcin@python-works.com>
parents: 1728
diff changeset
881 n = cls()
da8ee2ef7f6d implements #236 forking copy permission option
Marcin Kuzminski <marcin@python-works.com>
parents: 1728
diff changeset
882 n.user = user
da8ee2ef7f6d implements #236 forking copy permission option
Marcin Kuzminski <marcin@python-works.com>
parents: 1728
diff changeset
883 n.repository = repository
da8ee2ef7f6d implements #236 forking copy permission option
Marcin Kuzminski <marcin@python-works.com>
parents: 1728
diff changeset
884 n.permission = permission
da8ee2ef7f6d implements #236 forking copy permission option
Marcin Kuzminski <marcin@python-works.com>
parents: 1728
diff changeset
885 Session().add(n)
da8ee2ef7f6d implements #236 forking copy permission option
Marcin Kuzminski <marcin@python-works.com>
parents: 1728
diff changeset
886 return n
da8ee2ef7f6d implements #236 forking copy permission option
Marcin Kuzminski <marcin@python-works.com>
parents: 1728
diff changeset
887
da8ee2ef7f6d implements #236 forking copy permission option
Marcin Kuzminski <marcin@python-works.com>
parents: 1728
diff changeset
888 def __repr__(self):
da8ee2ef7f6d implements #236 forking copy permission option
Marcin Kuzminski <marcin@python-works.com>
parents: 1728
diff changeset
889 return '<user:%s => %s >' % (self.user, self.repository)
da8ee2ef7f6d implements #236 forking copy permission option
Marcin Kuzminski <marcin@python-works.com>
parents: 1728
diff changeset
890
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
891 class UserToPerm(Base, BaseModel):
399
f5c1eec9f376 rename repo2perm into repo_to_perm
Marcin Kuzminski <marcin@python-works.com>
parents: 392
diff changeset
892 __tablename__ = 'user_to_perm'
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
893 __table_args__ = (UniqueConstraint('user_id', 'permission_id'), {'extend_existing':True})
1594
9dae92a65e40 fixes #288
Marcin Kuzminski <marcin@python-works.com>
parents: 1593
diff changeset
894 user_to_perm_id = Column("user_to_perm_id", Integer(), nullable=False, unique=True, default=None, primary_key=True)
9dae92a65e40 fixes #288
Marcin Kuzminski <marcin@python-works.com>
parents: 1593
diff changeset
895 user_id = Column("user_id", Integer(), ForeignKey('users.user_id'), nullable=False, unique=None, default=None)
9dae92a65e40 fixes #288
Marcin Kuzminski <marcin@python-works.com>
parents: 1593
diff changeset
896 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
897
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
898 user = relationship('User')
1728
07e56179633e - fixes celery sqlalchemy session issues for async forking
Marcin Kuzminski <marcin@python-works.com>
parents: 1727
diff changeset
899 permission = relationship('Permission', lazy='joined')
399
f5c1eec9f376 rename repo2perm into repo_to_perm
Marcin Kuzminski <marcin@python-works.com>
parents: 392
diff changeset
900
1266
a1bcfe58a1ab Fixed #161 form saves the create repository permission.
Marcin Kuzminski <marcin@python-works.com>
parents: 1206
diff changeset
901 @classmethod
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
902 def has_perm(cls, user_id, perm):
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
903 if not isinstance(perm, Permission):
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
904 raise Exception('perm needs to be an instance of Permission class')
1266
a1bcfe58a1ab Fixed #161 form saves the create repository permission.
Marcin Kuzminski <marcin@python-works.com>
parents: 1206
diff changeset
905
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
906 return cls.query().filter(cls.user_id == user_id)\
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
907 .filter(cls.permission == perm).scalar() is not None
1266
a1bcfe58a1ab Fixed #161 form saves the create repository permission.
Marcin Kuzminski <marcin@python-works.com>
parents: 1206
diff changeset
908
a1bcfe58a1ab Fixed #161 form saves the create repository permission.
Marcin Kuzminski <marcin@python-works.com>
parents: 1206
diff changeset
909 @classmethod
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
910 def grant_perm(cls, user_id, perm):
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
911 if not isinstance(perm, Permission):
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
912 raise Exception('perm needs to be an instance of Permission class')
1266
a1bcfe58a1ab Fixed #161 form saves the create repository permission.
Marcin Kuzminski <marcin@python-works.com>
parents: 1206
diff changeset
913
a1bcfe58a1ab Fixed #161 form saves the create repository permission.
Marcin Kuzminski <marcin@python-works.com>
parents: 1206
diff changeset
914 new = cls()
a1bcfe58a1ab Fixed #161 form saves the create repository permission.
Marcin Kuzminski <marcin@python-works.com>
parents: 1206
diff changeset
915 new.user_id = user_id
a1bcfe58a1ab Fixed #161 form saves the create repository permission.
Marcin Kuzminski <marcin@python-works.com>
parents: 1206
diff changeset
916 new.permission = perm
a1bcfe58a1ab Fixed #161 form saves the create repository permission.
Marcin Kuzminski <marcin@python-works.com>
parents: 1206
diff changeset
917 try:
1713
54687aa00724 Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents: 1712
diff changeset
918 Session().add(new)
54687aa00724 Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents: 1712
diff changeset
919 Session().commit()
1266
a1bcfe58a1ab Fixed #161 form saves the create repository permission.
Marcin Kuzminski <marcin@python-works.com>
parents: 1206
diff changeset
920 except:
1713
54687aa00724 Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents: 1712
diff changeset
921 Session().rollback()
1266
a1bcfe58a1ab Fixed #161 form saves the create repository permission.
Marcin Kuzminski <marcin@python-works.com>
parents: 1206
diff changeset
922
a1bcfe58a1ab Fixed #161 form saves the create repository permission.
Marcin Kuzminski <marcin@python-works.com>
parents: 1206
diff changeset
923
a1bcfe58a1ab Fixed #161 form saves the create repository permission.
Marcin Kuzminski <marcin@python-works.com>
parents: 1206
diff changeset
924 @classmethod
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
925 def revoke_perm(cls, user_id, perm):
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
926 if not isinstance(perm, Permission):
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
927 raise Exception('perm needs to be an instance of Permission class')
1266
a1bcfe58a1ab Fixed #161 form saves the create repository permission.
Marcin Kuzminski <marcin@python-works.com>
parents: 1206
diff changeset
928
a1bcfe58a1ab Fixed #161 form saves the create repository permission.
Marcin Kuzminski <marcin@python-works.com>
parents: 1206
diff changeset
929 try:
1713
54687aa00724 Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents: 1712
diff changeset
930 obj = cls.query().filter(cls.user_id == user_id)\
54687aa00724 Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents: 1712
diff changeset
931 .filter(cls.permission == perm).one()
54687aa00724 Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents: 1712
diff changeset
932 Session().delete(obj)
54687aa00724 Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents: 1712
diff changeset
933 Session().commit()
1266
a1bcfe58a1ab Fixed #161 form saves the create repository permission.
Marcin Kuzminski <marcin@python-works.com>
parents: 1206
diff changeset
934 except:
1713
54687aa00724 Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents: 1712
diff changeset
935 Session().rollback()
1014
6fdc3ff65fce #56 added assignments of users groups into repository
Marcin Kuzminski <marcin@python-works.com>
parents: 1000
diff changeset
936
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
937 class UsersGroupRepoToPerm(Base, BaseModel):
1271
aa7e45ad0cea Fixed permissions for users groups, group can have create repo permission now.
Marcin Kuzminski <marcin@python-works.com>
parents: 1266
diff changeset
938 __tablename__ = 'users_group_repo_to_perm'
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
939 __table_args__ = (UniqueConstraint('repository_id', 'users_group_id', 'permission_id'), {'extend_existing':True})
1594
9dae92a65e40 fixes #288
Marcin Kuzminski <marcin@python-works.com>
parents: 1593
diff changeset
940 users_group_to_perm_id = Column("users_group_to_perm_id", Integer(), nullable=False, unique=True, default=None, primary_key=True)
9dae92a65e40 fixes #288
Marcin Kuzminski <marcin@python-works.com>
parents: 1593
diff changeset
941 users_group_id = Column("users_group_id", Integer(), ForeignKey('users_groups.users_group_id'), nullable=False, unique=None, default=None)
9dae92a65e40 fixes #288
Marcin Kuzminski <marcin@python-works.com>
parents: 1593
diff changeset
942 permission_id = Column("permission_id", Integer(), ForeignKey('permissions.permission_id'), nullable=False, unique=None, default=None)
9dae92a65e40 fixes #288
Marcin Kuzminski <marcin@python-works.com>
parents: 1593
diff changeset
943 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
944
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
945 users_group = relationship('UsersGroup')
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
946 permission = relationship('Permission')
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
947 repository = relationship('Repository')
958
7d1483f3170b added user group to perm table
Marcin Kuzminski <marcin@python-works.com>
parents: 956
diff changeset
948
1729
da8ee2ef7f6d implements #236 forking copy permission option
Marcin Kuzminski <marcin@python-works.com>
parents: 1728
diff changeset
949 @classmethod
da8ee2ef7f6d implements #236 forking copy permission option
Marcin Kuzminski <marcin@python-works.com>
parents: 1728
diff changeset
950 def create(cls, users_group, repository, permission):
da8ee2ef7f6d implements #236 forking copy permission option
Marcin Kuzminski <marcin@python-works.com>
parents: 1728
diff changeset
951 n = cls()
da8ee2ef7f6d implements #236 forking copy permission option
Marcin Kuzminski <marcin@python-works.com>
parents: 1728
diff changeset
952 n.users_group = users_group
da8ee2ef7f6d implements #236 forking copy permission option
Marcin Kuzminski <marcin@python-works.com>
parents: 1728
diff changeset
953 n.repository = repository
da8ee2ef7f6d implements #236 forking copy permission option
Marcin Kuzminski <marcin@python-works.com>
parents: 1728
diff changeset
954 n.permission = permission
da8ee2ef7f6d implements #236 forking copy permission option
Marcin Kuzminski <marcin@python-works.com>
parents: 1728
diff changeset
955 Session().add(n)
da8ee2ef7f6d implements #236 forking copy permission option
Marcin Kuzminski <marcin@python-works.com>
parents: 1728
diff changeset
956 return n
da8ee2ef7f6d implements #236 forking copy permission option
Marcin Kuzminski <marcin@python-works.com>
parents: 1728
diff changeset
957
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
958 def __repr__(self):
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
959 return '<userGroup:%s => %s >' % (self.users_group, self.repository)
1271
aa7e45ad0cea Fixed permissions for users groups, group can have create repo permission now.
Marcin Kuzminski <marcin@python-works.com>
parents: 1266
diff changeset
960
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
961 class UsersGroupToPerm(Base, BaseModel):
1271
aa7e45ad0cea Fixed permissions for users groups, group can have create repo permission now.
Marcin Kuzminski <marcin@python-works.com>
parents: 1266
diff changeset
962 __tablename__ = 'users_group_to_perm'
1594
9dae92a65e40 fixes #288
Marcin Kuzminski <marcin@python-works.com>
parents: 1593
diff changeset
963 users_group_to_perm_id = Column("users_group_to_perm_id", Integer(), nullable=False, unique=True, default=None, primary_key=True)
9dae92a65e40 fixes #288
Marcin Kuzminski <marcin@python-works.com>
parents: 1593
diff changeset
964 users_group_id = Column("users_group_id", Integer(), ForeignKey('users_groups.users_group_id'), nullable=False, unique=None, default=None)
9dae92a65e40 fixes #288
Marcin Kuzminski <marcin@python-works.com>
parents: 1593
diff changeset
965 permission_id = Column("permission_id", Integer(), ForeignKey('permissions.permission_id'), nullable=False, unique=None, default=None)
1271
aa7e45ad0cea Fixed permissions for users groups, group can have create repo permission now.
Marcin Kuzminski <marcin@python-works.com>
parents: 1266
diff changeset
966
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
967 users_group = relationship('UsersGroup')
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
968 permission = relationship('Permission')
1271
aa7e45ad0cea Fixed permissions for users groups, group can have create repo permission now.
Marcin Kuzminski <marcin@python-works.com>
parents: 1266
diff changeset
969
aa7e45ad0cea Fixed permissions for users groups, group can have create repo permission now.
Marcin Kuzminski <marcin@python-works.com>
parents: 1266
diff changeset
970
aa7e45ad0cea Fixed permissions for users groups, group can have create repo permission now.
Marcin Kuzminski <marcin@python-works.com>
parents: 1266
diff changeset
971 @classmethod
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
972 def has_perm(cls, users_group_id, perm):
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
973 if not isinstance(perm, Permission):
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
974 raise Exception('perm needs to be an instance of Permission class')
1271
aa7e45ad0cea Fixed permissions for users groups, group can have create repo permission now.
Marcin Kuzminski <marcin@python-works.com>
parents: 1266
diff changeset
975
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
976 return cls.query().filter(cls.users_group_id ==
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
977 users_group_id)\
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
978 .filter(cls.permission == perm)\
1271
aa7e45ad0cea Fixed permissions for users groups, group can have create repo permission now.
Marcin Kuzminski <marcin@python-works.com>
parents: 1266
diff changeset
979 .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
980
aa7e45ad0cea Fixed permissions for users groups, group can have create repo permission now.
Marcin Kuzminski <marcin@python-works.com>
parents: 1266
diff changeset
981 @classmethod
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
982 def grant_perm(cls, users_group_id, perm):
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
983 if not isinstance(perm, Permission):
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
984 raise Exception('perm needs to be an instance of Permission class')
1271
aa7e45ad0cea Fixed permissions for users groups, group can have create repo permission now.
Marcin Kuzminski <marcin@python-works.com>
parents: 1266
diff changeset
985
aa7e45ad0cea Fixed permissions for users groups, group can have create repo permission now.
Marcin Kuzminski <marcin@python-works.com>
parents: 1266
diff changeset
986 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
987 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
988 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
989 try:
1713
54687aa00724 Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents: 1712
diff changeset
990 Session().add(new)
54687aa00724 Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents: 1712
diff changeset
991 Session().commit()
1271
aa7e45ad0cea Fixed permissions for users groups, group can have create repo permission now.
Marcin Kuzminski <marcin@python-works.com>
parents: 1266
diff changeset
992 except:
1713
54687aa00724 Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents: 1712
diff changeset
993 Session().rollback()
1271
aa7e45ad0cea Fixed permissions for users groups, group can have create repo permission now.
Marcin Kuzminski <marcin@python-works.com>
parents: 1266
diff changeset
994
aa7e45ad0cea Fixed permissions for users groups, group can have create repo permission now.
Marcin Kuzminski <marcin@python-works.com>
parents: 1266
diff changeset
995
aa7e45ad0cea Fixed permissions for users groups, group can have create repo permission now.
Marcin Kuzminski <marcin@python-works.com>
parents: 1266
diff changeset
996 @classmethod
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
997 def revoke_perm(cls, users_group_id, perm):
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
998 if not isinstance(perm, Permission):
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
999 raise Exception('perm needs to be an instance of Permission class')
1271
aa7e45ad0cea Fixed permissions for users groups, group can have create repo permission now.
Marcin Kuzminski <marcin@python-works.com>
parents: 1266
diff changeset
1000
aa7e45ad0cea Fixed permissions for users groups, group can have create repo permission now.
Marcin Kuzminski <marcin@python-works.com>
parents: 1266
diff changeset
1001 try:
1713
54687aa00724 Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents: 1712
diff changeset
1002 obj = cls.query().filter(cls.users_group_id == users_group_id)\
54687aa00724 Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents: 1712
diff changeset
1003 .filter(cls.permission == perm).one()
54687aa00724 Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents: 1712
diff changeset
1004 Session().delete(obj)
54687aa00724 Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents: 1712
diff changeset
1005 Session().commit()
1271
aa7e45ad0cea Fixed permissions for users groups, group can have create repo permission now.
Marcin Kuzminski <marcin@python-works.com>
parents: 1266
diff changeset
1006 except:
1713
54687aa00724 Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents: 1712
diff changeset
1007 Session().rollback()
1271
aa7e45ad0cea Fixed permissions for users groups, group can have create repo permission now.
Marcin Kuzminski <marcin@python-works.com>
parents: 1266
diff changeset
1008
aa7e45ad0cea Fixed permissions for users groups, group can have create repo permission now.
Marcin Kuzminski <marcin@python-works.com>
parents: 1266
diff changeset
1009
1633
2c0d35e336b5 refactoring of models names for repoGroup permissions
Marcin Kuzminski <marcin@python-works.com>
parents: 1607
diff changeset
1010 class UserRepoGroupToPerm(Base, BaseModel):
879
b19341623d48 added group to perm mapping table
Marcin Kuzminski <marcin@python-works.com>
parents: 878
diff changeset
1011 __tablename__ = 'group_to_perm'
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
1012 __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
1013
1594
9dae92a65e40 fixes #288
Marcin Kuzminski <marcin@python-works.com>
parents: 1593
diff changeset
1014 group_to_perm_id = Column("group_to_perm_id", Integer(), nullable=False, unique=True, default=None, primary_key=True)
9dae92a65e40 fixes #288
Marcin Kuzminski <marcin@python-works.com>
parents: 1593
diff changeset
1015 user_id = Column("user_id", Integer(), ForeignKey('users.user_id'), nullable=False, unique=None, default=None)
9dae92a65e40 fixes #288
Marcin Kuzminski <marcin@python-works.com>
parents: 1593
diff changeset
1016 permission_id = Column("permission_id", Integer(), ForeignKey('permissions.permission_id'), nullable=False, unique=None, default=None)
9dae92a65e40 fixes #288
Marcin Kuzminski <marcin@python-works.com>
parents: 1593
diff changeset
1017 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
1018
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
1019 user = relationship('User')
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
1020 permission = relationship('Permission')
1633
2c0d35e336b5 refactoring of models names for repoGroup permissions
Marcin Kuzminski <marcin@python-works.com>
parents: 1607
diff changeset
1021 group = relationship('RepoGroup')
2c0d35e336b5 refactoring of models names for repoGroup permissions
Marcin Kuzminski <marcin@python-works.com>
parents: 1607
diff changeset
1022
2c0d35e336b5 refactoring of models names for repoGroup permissions
Marcin Kuzminski <marcin@python-works.com>
parents: 1607
diff changeset
1023 class UsersGroupRepoGroupToPerm(Base, BaseModel):
2c0d35e336b5 refactoring of models names for repoGroup permissions
Marcin Kuzminski <marcin@python-works.com>
parents: 1607
diff changeset
1024 __tablename__ = 'users_group_repo_group_to_perm'
2c0d35e336b5 refactoring of models names for repoGroup permissions
Marcin Kuzminski <marcin@python-works.com>
parents: 1607
diff changeset
1025 __table_args__ = (UniqueConstraint('group_id', 'permission_id'), {'extend_existing':True})
2c0d35e336b5 refactoring of models names for repoGroup permissions
Marcin Kuzminski <marcin@python-works.com>
parents: 1607
diff changeset
1026
2c0d35e336b5 refactoring of models names for repoGroup permissions
Marcin Kuzminski <marcin@python-works.com>
parents: 1607
diff changeset
1027 users_group_repo_group_to_perm_id = Column("users_group_repo_group_to_perm_id", Integer(), nullable=False, unique=True, default=None, primary_key=True)
2c0d35e336b5 refactoring of models names for repoGroup permissions
Marcin Kuzminski <marcin@python-works.com>
parents: 1607
diff changeset
1028 users_group_id = Column("users_group_id", Integer(), ForeignKey('users_groups.users_group_id'), nullable=False, unique=None, default=None)
2c0d35e336b5 refactoring of models names for repoGroup permissions
Marcin Kuzminski <marcin@python-works.com>
parents: 1607
diff changeset
1029 permission_id = Column("permission_id", Integer(), ForeignKey('permissions.permission_id'), nullable=False, unique=None, default=None)
2c0d35e336b5 refactoring of models names for repoGroup permissions
Marcin Kuzminski <marcin@python-works.com>
parents: 1607
diff changeset
1030 group_id = Column("group_id", Integer(), ForeignKey('groups.group_id'), nullable=False, unique=None, default=None)
2c0d35e336b5 refactoring of models names for repoGroup permissions
Marcin Kuzminski <marcin@python-works.com>
parents: 1607
diff changeset
1031
2c0d35e336b5 refactoring of models names for repoGroup permissions
Marcin Kuzminski <marcin@python-works.com>
parents: 1607
diff changeset
1032 users_group = relationship('UsersGroup')
2c0d35e336b5 refactoring of models names for repoGroup permissions
Marcin Kuzminski <marcin@python-works.com>
parents: 1607
diff changeset
1033 permission = relationship('Permission')
2c0d35e336b5 refactoring of models names for repoGroup permissions
Marcin Kuzminski <marcin@python-works.com>
parents: 1607
diff changeset
1034 group = relationship('RepoGroup')
879
b19341623d48 added group to perm mapping table
Marcin Kuzminski <marcin@python-works.com>
parents: 878
diff changeset
1035
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
1036 class Statistics(Base, BaseModel):
493
2256c78afe53 implemented basic autoupdating statistics fetched from database
Marcin Kuzminski <marcin@python-works.com>
parents: 473
diff changeset
1037 __tablename__ = 'statistics'
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
1038 __table_args__ = (UniqueConstraint('repository_id'), {'extend_existing':True})
1594
9dae92a65e40 fixes #288
Marcin Kuzminski <marcin@python-works.com>
parents: 1593
diff changeset
1039 stat_id = Column("stat_id", Integer(), nullable=False, unique=True, default=None, primary_key=True)
9dae92a65e40 fixes #288
Marcin Kuzminski <marcin@python-works.com>
parents: 1593
diff changeset
1040 repository_id = Column("repository_id", Integer(), ForeignKey('repositories.repo_id'), nullable=False, unique=True, default=None)
9dae92a65e40 fixes #288
Marcin Kuzminski <marcin@python-works.com>
parents: 1593
diff changeset
1041 stat_on_revision = Column("stat_on_revision", Integer(), nullable=False)
9dae92a65e40 fixes #288
Marcin Kuzminski <marcin@python-works.com>
parents: 1593
diff changeset
1042 commit_activity = Column("commit_activity", LargeBinary(1000000), nullable=False)#JSON data
9dae92a65e40 fixes #288
Marcin Kuzminski <marcin@python-works.com>
parents: 1593
diff changeset
1043 commit_activity_combined = Column("commit_activity_combined", LargeBinary(), nullable=False)#JSON data
9dae92a65e40 fixes #288
Marcin Kuzminski <marcin@python-works.com>
parents: 1593
diff changeset
1044 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
1045
1594
9dae92a65e40 fixes #288
Marcin Kuzminski <marcin@python-works.com>
parents: 1593
diff changeset
1046 repository = relationship('Repository', single_parent=True)
399
f5c1eec9f376 rename repo2perm into repo_to_perm
Marcin Kuzminski <marcin@python-works.com>
parents: 392
diff changeset
1047
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
1048 class UserFollowing(Base, BaseModel):
734
49eb69d78988 implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents: 713
diff changeset
1049 __tablename__ = 'user_followings'
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
1050 __table_args__ = (UniqueConstraint('user_id', 'follows_repository_id'),
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
1051 UniqueConstraint('user_id', 'follows_user_id')
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
1052 , {'extend_existing':True})
734
49eb69d78988 implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents: 713
diff changeset
1053
1594
9dae92a65e40 fixes #288
Marcin Kuzminski <marcin@python-works.com>
parents: 1593
diff changeset
1054 user_following_id = Column("user_following_id", Integer(), nullable=False, unique=True, default=None, primary_key=True)
9dae92a65e40 fixes #288
Marcin Kuzminski <marcin@python-works.com>
parents: 1593
diff changeset
1055 user_id = Column("user_id", Integer(), ForeignKey('users.user_id'), nullable=False, unique=None, default=None)
9dae92a65e40 fixes #288
Marcin Kuzminski <marcin@python-works.com>
parents: 1593
diff changeset
1056 follows_repo_id = Column("follows_repository_id", Integer(), ForeignKey('repositories.repo_id'), nullable=True, unique=None, default=None)
9dae92a65e40 fixes #288
Marcin Kuzminski <marcin@python-works.com>
parents: 1593
diff changeset
1057 follows_user_id = Column("follows_user_id", Integer(), ForeignKey('users.user_id'), nullable=True, unique=None, default=None)
9dae92a65e40 fixes #288
Marcin Kuzminski <marcin@python-works.com>
parents: 1593
diff changeset
1058 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
1059
1594
9dae92a65e40 fixes #288
Marcin Kuzminski <marcin@python-works.com>
parents: 1593
diff changeset
1060 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
1061
1594
9dae92a65e40 fixes #288
Marcin Kuzminski <marcin@python-works.com>
parents: 1593
diff changeset
1062 follows_user = relationship('User', primaryjoin='User.user_id==UserFollowing.follows_user_id')
9dae92a65e40 fixes #288
Marcin Kuzminski <marcin@python-works.com>
parents: 1593
diff changeset
1063 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
1064
1279
cb216757a62d #179 Added followers page
Marcin Kuzminski <marcin@python-works.com>
parents: 1271
diff changeset
1065
cb216757a62d #179 Added followers page
Marcin Kuzminski <marcin@python-works.com>
parents: 1271
diff changeset
1066 @classmethod
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
1067 def get_repo_followers(cls, repo_id):
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
1068 return cls.query().filter(cls.follows_repo_id == repo_id)
1279
cb216757a62d #179 Added followers page
Marcin Kuzminski <marcin@python-works.com>
parents: 1271
diff changeset
1069
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
1070 class CacheInvalidation(Base, BaseModel):
670
e7c670cc03cb Adde table for cache invalidation
Marcin Kuzminski <marcin@python-works.com>
parents: 667
diff changeset
1071 __tablename__ = 'cache_invalidation'
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
1072 __table_args__ = (UniqueConstraint('cache_key'), {'extend_existing':True})
1594
9dae92a65e40 fixes #288
Marcin Kuzminski <marcin@python-works.com>
parents: 1593
diff changeset
1073 cache_id = Column("cache_id", Integer(), nullable=False, unique=True, default=None, primary_key=True)
9dae92a65e40 fixes #288
Marcin Kuzminski <marcin@python-works.com>
parents: 1593
diff changeset
1074 cache_key = Column("cache_key", String(length=255, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None)
9dae92a65e40 fixes #288
Marcin Kuzminski <marcin@python-works.com>
parents: 1593
diff changeset
1075 cache_args = Column("cache_args", String(length=255, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None)
9dae92a65e40 fixes #288
Marcin Kuzminski <marcin@python-works.com>
parents: 1593
diff changeset
1076 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
1077
e7c670cc03cb Adde table for cache invalidation
Marcin Kuzminski <marcin@python-works.com>
parents: 667
diff changeset
1078
1594
9dae92a65e40 fixes #288
Marcin Kuzminski <marcin@python-works.com>
parents: 1593
diff changeset
1079 def __init__(self, cache_key, cache_args=''):
692
cb0d9ce6ac5c #50 on point cache invalidation changes.
Marcin Kuzminski <marcin@python-works.com>
parents: 670
diff changeset
1080 self.cache_key = cache_key
cb0d9ce6ac5c #50 on point cache invalidation changes.
Marcin Kuzminski <marcin@python-works.com>
parents: 670
diff changeset
1081 self.cache_args = cache_args
cb0d9ce6ac5c #50 on point cache invalidation changes.
Marcin Kuzminski <marcin@python-works.com>
parents: 670
diff changeset
1082 self.cache_active = False
cb0d9ce6ac5c #50 on point cache invalidation changes.
Marcin Kuzminski <marcin@python-works.com>
parents: 670
diff changeset
1083
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
1084 def __repr__(self):
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
1085 return "<%s('%s:%s')>" % (self.__class__.__name__,
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
1086 self.cache_id, self.cache_key)
834
8924ed0e4f36 added current db version into rhodecode,
Marcin Kuzminski <marcin@python-works.com>
parents: 832
diff changeset
1087
1607
e886f91fcb71 Cached readme generation
Marcin Kuzminski <marcin@python-works.com>
parents: 1594
diff changeset
1088 @classmethod
e886f91fcb71 Cached readme generation
Marcin Kuzminski <marcin@python-works.com>
parents: 1594
diff changeset
1089 def invalidate(cls, key):
e886f91fcb71 Cached readme generation
Marcin Kuzminski <marcin@python-works.com>
parents: 1594
diff changeset
1090 """
e886f91fcb71 Cached readme generation
Marcin Kuzminski <marcin@python-works.com>
parents: 1594
diff changeset
1091 Returns Invalidation object if this given key should be invalidated
e886f91fcb71 Cached readme generation
Marcin Kuzminski <marcin@python-works.com>
parents: 1594
diff changeset
1092 None otherwise. `cache_active = False` means that this cache
e886f91fcb71 Cached readme generation
Marcin Kuzminski <marcin@python-works.com>
parents: 1594
diff changeset
1093 state is not valid and needs to be invalidated
e886f91fcb71 Cached readme generation
Marcin Kuzminski <marcin@python-works.com>
parents: 1594
diff changeset
1094
e886f91fcb71 Cached readme generation
Marcin Kuzminski <marcin@python-works.com>
parents: 1594
diff changeset
1095 :param key:
e886f91fcb71 Cached readme generation
Marcin Kuzminski <marcin@python-works.com>
parents: 1594
diff changeset
1096 """
e886f91fcb71 Cached readme generation
Marcin Kuzminski <marcin@python-works.com>
parents: 1594
diff changeset
1097 return cls.query()\
e886f91fcb71 Cached readme generation
Marcin Kuzminski <marcin@python-works.com>
parents: 1594
diff changeset
1098 .filter(CacheInvalidation.cache_key == key)\
e886f91fcb71 Cached readme generation
Marcin Kuzminski <marcin@python-works.com>
parents: 1594
diff changeset
1099 .filter(CacheInvalidation.cache_active == False)\
e886f91fcb71 Cached readme generation
Marcin Kuzminski <marcin@python-works.com>
parents: 1594
diff changeset
1100 .scalar()
e886f91fcb71 Cached readme generation
Marcin Kuzminski <marcin@python-works.com>
parents: 1594
diff changeset
1101
e886f91fcb71 Cached readme generation
Marcin Kuzminski <marcin@python-works.com>
parents: 1594
diff changeset
1102 @classmethod
e886f91fcb71 Cached readme generation
Marcin Kuzminski <marcin@python-works.com>
parents: 1594
diff changeset
1103 def set_invalidate(cls, key):
e886f91fcb71 Cached readme generation
Marcin Kuzminski <marcin@python-works.com>
parents: 1594
diff changeset
1104 """
e886f91fcb71 Cached readme generation
Marcin Kuzminski <marcin@python-works.com>
parents: 1594
diff changeset
1105 Mark this Cache key for invalidation
e886f91fcb71 Cached readme generation
Marcin Kuzminski <marcin@python-works.com>
parents: 1594
diff changeset
1106
e886f91fcb71 Cached readme generation
Marcin Kuzminski <marcin@python-works.com>
parents: 1594
diff changeset
1107 :param key:
e886f91fcb71 Cached readme generation
Marcin Kuzminski <marcin@python-works.com>
parents: 1594
diff changeset
1108 """
e886f91fcb71 Cached readme generation
Marcin Kuzminski <marcin@python-works.com>
parents: 1594
diff changeset
1109
e886f91fcb71 Cached readme generation
Marcin Kuzminski <marcin@python-works.com>
parents: 1594
diff changeset
1110 log.debug('marking %s for invalidation' % key)
e886f91fcb71 Cached readme generation
Marcin Kuzminski <marcin@python-works.com>
parents: 1594
diff changeset
1111 inv_obj = Session().query(cls)\
e886f91fcb71 Cached readme generation
Marcin Kuzminski <marcin@python-works.com>
parents: 1594
diff changeset
1112 .filter(cls.cache_key == key).scalar()
e886f91fcb71 Cached readme generation
Marcin Kuzminski <marcin@python-works.com>
parents: 1594
diff changeset
1113 if inv_obj:
e886f91fcb71 Cached readme generation
Marcin Kuzminski <marcin@python-works.com>
parents: 1594
diff changeset
1114 inv_obj.cache_active = False
e886f91fcb71 Cached readme generation
Marcin Kuzminski <marcin@python-works.com>
parents: 1594
diff changeset
1115 else:
e886f91fcb71 Cached readme generation
Marcin Kuzminski <marcin@python-works.com>
parents: 1594
diff changeset
1116 log.debug('cache key not found in invalidation db -> creating one')
e886f91fcb71 Cached readme generation
Marcin Kuzminski <marcin@python-works.com>
parents: 1594
diff changeset
1117 inv_obj = CacheInvalidation(key)
e886f91fcb71 Cached readme generation
Marcin Kuzminski <marcin@python-works.com>
parents: 1594
diff changeset
1118
e886f91fcb71 Cached readme generation
Marcin Kuzminski <marcin@python-works.com>
parents: 1594
diff changeset
1119 try:
1713
54687aa00724 Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents: 1712
diff changeset
1120 Session().add(inv_obj)
54687aa00724 Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents: 1712
diff changeset
1121 Session().commit()
1607
e886f91fcb71 Cached readme generation
Marcin Kuzminski <marcin@python-works.com>
parents: 1594
diff changeset
1122 except Exception:
e886f91fcb71 Cached readme generation
Marcin Kuzminski <marcin@python-works.com>
parents: 1594
diff changeset
1123 log.error(traceback.format_exc())
1713
54687aa00724 Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents: 1712
diff changeset
1124 Session().rollback()
1607
e886f91fcb71 Cached readme generation
Marcin Kuzminski <marcin@python-works.com>
parents: 1594
diff changeset
1125
e886f91fcb71 Cached readme generation
Marcin Kuzminski <marcin@python-works.com>
parents: 1594
diff changeset
1126 @classmethod
e886f91fcb71 Cached readme generation
Marcin Kuzminski <marcin@python-works.com>
parents: 1594
diff changeset
1127 def set_valid(cls, key):
e886f91fcb71 Cached readme generation
Marcin Kuzminski <marcin@python-works.com>
parents: 1594
diff changeset
1128 """
e886f91fcb71 Cached readme generation
Marcin Kuzminski <marcin@python-works.com>
parents: 1594
diff changeset
1129 Mark this cache key as active and currently cached
e886f91fcb71 Cached readme generation
Marcin Kuzminski <marcin@python-works.com>
parents: 1594
diff changeset
1130
e886f91fcb71 Cached readme generation
Marcin Kuzminski <marcin@python-works.com>
parents: 1594
diff changeset
1131 :param key:
e886f91fcb71 Cached readme generation
Marcin Kuzminski <marcin@python-works.com>
parents: 1594
diff changeset
1132 """
1713
54687aa00724 Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents: 1712
diff changeset
1133 inv_obj = CacheInvalidation.query()\
1607
e886f91fcb71 Cached readme generation
Marcin Kuzminski <marcin@python-works.com>
parents: 1594
diff changeset
1134 .filter(CacheInvalidation.cache_key == key).scalar()
e886f91fcb71 Cached readme generation
Marcin Kuzminski <marcin@python-works.com>
parents: 1594
diff changeset
1135 inv_obj.cache_active = True
1713
54687aa00724 Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents: 1712
diff changeset
1136 Session().add(inv_obj)
54687aa00724 Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents: 1712
diff changeset
1137 Session().commit()
1607
e886f91fcb71 Cached readme generation
Marcin Kuzminski <marcin@python-works.com>
parents: 1594
diff changeset
1138
1665
36f77a46f291 Added cache options to some db getters
Marcin Kuzminski <marcin@python-works.com>
parents: 1634
diff changeset
1139
1670
d2de0c2f02cd #77 code review
Marcin Kuzminski <marcin@python-works.com>
parents: 1669
diff changeset
1140 class ChangesetComment(Base, BaseModel):
d2de0c2f02cd #77 code review
Marcin Kuzminski <marcin@python-works.com>
parents: 1669
diff changeset
1141 __tablename__ = 'changeset_comments'
d2de0c2f02cd #77 code review
Marcin Kuzminski <marcin@python-works.com>
parents: 1669
diff changeset
1142 __table_args__ = ({'extend_existing':True},)
d2de0c2f02cd #77 code review
Marcin Kuzminski <marcin@python-works.com>
parents: 1669
diff changeset
1143 comment_id = Column('comment_id', Integer(), nullable=False, primary_key=True)
d2de0c2f02cd #77 code review
Marcin Kuzminski <marcin@python-works.com>
parents: 1669
diff changeset
1144 repo_id = Column('repo_id', Integer(), ForeignKey('repositories.repo_id'), nullable=False)
1675
7c487d2678c7 code refactoring
Marcin Kuzminski <marcin@python-works.com>
parents: 1670
diff changeset
1145 revision = Column('revision', String(40), nullable=False)
1677
7276b170ce8b #71 code-review
Marcin Kuzminski <marcin@python-works.com>
parents: 1675
diff changeset
1146 line_no = Column('line_no', Unicode(10), nullable=True)
7276b170ce8b #71 code-review
Marcin Kuzminski <marcin@python-works.com>
parents: 1675
diff changeset
1147 f_path = Column('f_path', Unicode(1000), nullable=True)
1670
d2de0c2f02cd #77 code review
Marcin Kuzminski <marcin@python-works.com>
parents: 1669
diff changeset
1148 user_id = Column('user_id', Integer(), ForeignKey('users.user_id'), nullable=False)
1677
7276b170ce8b #71 code-review
Marcin Kuzminski <marcin@python-works.com>
parents: 1675
diff changeset
1149 text = Column('text', Unicode(25000), nullable=False)
7276b170ce8b #71 code-review
Marcin Kuzminski <marcin@python-works.com>
parents: 1675
diff changeset
1150 modified_at = Column('modified_at', DateTime(), nullable=False, default=datetime.datetime.now)
1670
d2de0c2f02cd #77 code review
Marcin Kuzminski <marcin@python-works.com>
parents: 1669
diff changeset
1151
1703
f23828b00b21 notification fixes and improvements
Marcin Kuzminski <marcin@python-works.com>
parents: 1702
diff changeset
1152 author = relationship('User', lazy='joined')
1670
d2de0c2f02cd #77 code review
Marcin Kuzminski <marcin@python-works.com>
parents: 1669
diff changeset
1153 repo = relationship('Repository')
d2de0c2f02cd #77 code review
Marcin Kuzminski <marcin@python-works.com>
parents: 1669
diff changeset
1154
d2de0c2f02cd #77 code review
Marcin Kuzminski <marcin@python-works.com>
parents: 1669
diff changeset
1155
1703
f23828b00b21 notification fixes and improvements
Marcin Kuzminski <marcin@python-works.com>
parents: 1702
diff changeset
1156 @classmethod
f23828b00b21 notification fixes and improvements
Marcin Kuzminski <marcin@python-works.com>
parents: 1702
diff changeset
1157 def get_users(cls, revision):
f23828b00b21 notification fixes and improvements
Marcin Kuzminski <marcin@python-works.com>
parents: 1702
diff changeset
1158 """
f23828b00b21 notification fixes and improvements
Marcin Kuzminski <marcin@python-works.com>
parents: 1702
diff changeset
1159 Returns user associated with this changesetComment. ie those
f23828b00b21 notification fixes and improvements
Marcin Kuzminski <marcin@python-works.com>
parents: 1702
diff changeset
1160 who actually commented
f23828b00b21 notification fixes and improvements
Marcin Kuzminski <marcin@python-works.com>
parents: 1702
diff changeset
1161
f23828b00b21 notification fixes and improvements
Marcin Kuzminski <marcin@python-works.com>
parents: 1702
diff changeset
1162 :param cls:
f23828b00b21 notification fixes and improvements
Marcin Kuzminski <marcin@python-works.com>
parents: 1702
diff changeset
1163 :param revision:
f23828b00b21 notification fixes and improvements
Marcin Kuzminski <marcin@python-works.com>
parents: 1702
diff changeset
1164 """
1713
54687aa00724 Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents: 1712
diff changeset
1165 return Session().query(User)\
1703
f23828b00b21 notification fixes and improvements
Marcin Kuzminski <marcin@python-works.com>
parents: 1702
diff changeset
1166 .filter(cls.revision == revision)\
f23828b00b21 notification fixes and improvements
Marcin Kuzminski <marcin@python-works.com>
parents: 1702
diff changeset
1167 .join(ChangesetComment.author).all()
f23828b00b21 notification fixes and improvements
Marcin Kuzminski <marcin@python-works.com>
parents: 1702
diff changeset
1168
f23828b00b21 notification fixes and improvements
Marcin Kuzminski <marcin@python-works.com>
parents: 1702
diff changeset
1169
1702
8cb7f5c4d494 #302 - basic notification system, models+tests
Marcin Kuzminski <marcin@python-works.com>
parents: 1693
diff changeset
1170 class Notification(Base, BaseModel):
8cb7f5c4d494 #302 - basic notification system, models+tests
Marcin Kuzminski <marcin@python-works.com>
parents: 1693
diff changeset
1171 __tablename__ = 'notifications'
8cb7f5c4d494 #302 - basic notification system, models+tests
Marcin Kuzminski <marcin@python-works.com>
parents: 1693
diff changeset
1172 __table_args__ = ({'extend_existing':True})
1703
f23828b00b21 notification fixes and improvements
Marcin Kuzminski <marcin@python-works.com>
parents: 1702
diff changeset
1173
1712
cac5109ac3b6 Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents: 1703
diff changeset
1174 TYPE_CHANGESET_COMMENT = u'cs_comment'
cac5109ac3b6 Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents: 1703
diff changeset
1175 TYPE_MESSAGE = u'message'
cac5109ac3b6 Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents: 1703
diff changeset
1176 TYPE_MENTION = u'mention'
1731
31e6eb2fb4b2 implements #222 registration feedback
Marcin Kuzminski <marcin@python-works.com>
parents: 1729
diff changeset
1177 TYPE_REGISTRATION = u'registration'
1703
f23828b00b21 notification fixes and improvements
Marcin Kuzminski <marcin@python-works.com>
parents: 1702
diff changeset
1178
1702
8cb7f5c4d494 #302 - basic notification system, models+tests
Marcin Kuzminski <marcin@python-works.com>
parents: 1693
diff changeset
1179 notification_id = Column('notification_id', Integer(), nullable=False, primary_key=True)
8cb7f5c4d494 #302 - basic notification system, models+tests
Marcin Kuzminski <marcin@python-works.com>
parents: 1693
diff changeset
1180 subject = Column('subject', Unicode(512), nullable=True)
8cb7f5c4d494 #302 - basic notification system, models+tests
Marcin Kuzminski <marcin@python-works.com>
parents: 1693
diff changeset
1181 body = Column('body', Unicode(50000), nullable=True)
1703
f23828b00b21 notification fixes and improvements
Marcin Kuzminski <marcin@python-works.com>
parents: 1702
diff changeset
1182 created_by = Column("created_by", Integer(), ForeignKey('users.user_id'), nullable=True)
1702
8cb7f5c4d494 #302 - basic notification system, models+tests
Marcin Kuzminski <marcin@python-works.com>
parents: 1693
diff changeset
1183 created_on = Column('created_on', DateTime(timezone=False), nullable=False, default=datetime.datetime.now)
1703
f23828b00b21 notification fixes and improvements
Marcin Kuzminski <marcin@python-works.com>
parents: 1702
diff changeset
1184 type_ = Column('type', Unicode(256))
1702
8cb7f5c4d494 #302 - basic notification system, models+tests
Marcin Kuzminski <marcin@python-works.com>
parents: 1693
diff changeset
1185
1712
cac5109ac3b6 Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents: 1703
diff changeset
1186 created_by_user = relationship('User')
1717
7ff304d3028f Notification fixes
Marcin Kuzminski <marcin@python-works.com>
parents: 1716
diff changeset
1187 notifications_to_users = relationship('UserNotification', lazy='joined',
7ff304d3028f Notification fixes
Marcin Kuzminski <marcin@python-works.com>
parents: 1716
diff changeset
1188 cascade="all, delete, delete-orphan")
1702
8cb7f5c4d494 #302 - basic notification system, models+tests
Marcin Kuzminski <marcin@python-works.com>
parents: 1693
diff changeset
1189
8cb7f5c4d494 #302 - basic notification system, models+tests
Marcin Kuzminski <marcin@python-works.com>
parents: 1693
diff changeset
1190 @property
8cb7f5c4d494 #302 - basic notification system, models+tests
Marcin Kuzminski <marcin@python-works.com>
parents: 1693
diff changeset
1191 def recipients(self):
8cb7f5c4d494 #302 - basic notification system, models+tests
Marcin Kuzminski <marcin@python-works.com>
parents: 1693
diff changeset
1192 return [x.user for x in UserNotification.query()\
8cb7f5c4d494 #302 - basic notification system, models+tests
Marcin Kuzminski <marcin@python-works.com>
parents: 1693
diff changeset
1193 .filter(UserNotification.notification == self).all()]
8cb7f5c4d494 #302 - basic notification system, models+tests
Marcin Kuzminski <marcin@python-works.com>
parents: 1693
diff changeset
1194
8cb7f5c4d494 #302 - basic notification system, models+tests
Marcin Kuzminski <marcin@python-works.com>
parents: 1693
diff changeset
1195 @classmethod
1703
f23828b00b21 notification fixes and improvements
Marcin Kuzminski <marcin@python-works.com>
parents: 1702
diff changeset
1196 def create(cls, created_by, subject, body, recipients, type_=None):
f23828b00b21 notification fixes and improvements
Marcin Kuzminski <marcin@python-works.com>
parents: 1702
diff changeset
1197 if type_ is None:
f23828b00b21 notification fixes and improvements
Marcin Kuzminski <marcin@python-works.com>
parents: 1702
diff changeset
1198 type_ = Notification.TYPE_MESSAGE
f23828b00b21 notification fixes and improvements
Marcin Kuzminski <marcin@python-works.com>
parents: 1702
diff changeset
1199
1702
8cb7f5c4d494 #302 - basic notification system, models+tests
Marcin Kuzminski <marcin@python-works.com>
parents: 1693
diff changeset
1200 notification = cls()
1712
cac5109ac3b6 Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents: 1703
diff changeset
1201 notification.created_by_user = created_by
1702
8cb7f5c4d494 #302 - basic notification system, models+tests
Marcin Kuzminski <marcin@python-works.com>
parents: 1693
diff changeset
1202 notification.subject = subject
8cb7f5c4d494 #302 - basic notification system, models+tests
Marcin Kuzminski <marcin@python-works.com>
parents: 1693
diff changeset
1203 notification.body = body
1703
f23828b00b21 notification fixes and improvements
Marcin Kuzminski <marcin@python-works.com>
parents: 1702
diff changeset
1204 notification.type_ = type_
1717
7ff304d3028f Notification fixes
Marcin Kuzminski <marcin@python-works.com>
parents: 1716
diff changeset
1205 notification.created_on = datetime.datetime.now()
1713
54687aa00724 Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents: 1712
diff changeset
1206
1702
8cb7f5c4d494 #302 - basic notification system, models+tests
Marcin Kuzminski <marcin@python-works.com>
parents: 1693
diff changeset
1207 for u in recipients:
1713
54687aa00724 Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents: 1712
diff changeset
1208 assoc = UserNotification()
54687aa00724 Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents: 1712
diff changeset
1209 assoc.notification = notification
54687aa00724 Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents: 1712
diff changeset
1210 u.notifications.append(assoc)
54687aa00724 Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents: 1712
diff changeset
1211 Session().add(notification)
1702
8cb7f5c4d494 #302 - basic notification system, models+tests
Marcin Kuzminski <marcin@python-works.com>
parents: 1693
diff changeset
1212 return notification
8cb7f5c4d494 #302 - basic notification system, models+tests
Marcin Kuzminski <marcin@python-works.com>
parents: 1693
diff changeset
1213
1712
cac5109ac3b6 Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents: 1703
diff changeset
1214 @property
cac5109ac3b6 Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents: 1703
diff changeset
1215 def description(self):
cac5109ac3b6 Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents: 1703
diff changeset
1216 from rhodecode.model.notification import NotificationModel
cac5109ac3b6 Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents: 1703
diff changeset
1217 return NotificationModel().make_description(self)
cac5109ac3b6 Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents: 1703
diff changeset
1218
1702
8cb7f5c4d494 #302 - basic notification system, models+tests
Marcin Kuzminski <marcin@python-works.com>
parents: 1693
diff changeset
1219 class UserNotification(Base, BaseModel):
8cb7f5c4d494 #302 - basic notification system, models+tests
Marcin Kuzminski <marcin@python-works.com>
parents: 1693
diff changeset
1220 __tablename__ = 'user_to_notification'
1703
f23828b00b21 notification fixes and improvements
Marcin Kuzminski <marcin@python-works.com>
parents: 1702
diff changeset
1221 __table_args__ = (UniqueConstraint('user_id', 'notification_id'),
f23828b00b21 notification fixes and improvements
Marcin Kuzminski <marcin@python-works.com>
parents: 1702
diff changeset
1222 {'extend_existing':True})
1713
54687aa00724 Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents: 1712
diff changeset
1223 user_id = Column("user_id", Integer(), ForeignKey('users.user_id'), primary_key=True)
54687aa00724 Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents: 1712
diff changeset
1224 notification_id = Column("notification_id", Integer(), ForeignKey('notifications.notification_id'), primary_key=True)
1703
f23828b00b21 notification fixes and improvements
Marcin Kuzminski <marcin@python-works.com>
parents: 1702
diff changeset
1225 read = Column('read', Boolean, default=False)
1702
8cb7f5c4d494 #302 - basic notification system, models+tests
Marcin Kuzminski <marcin@python-works.com>
parents: 1693
diff changeset
1226 sent_on = Column('sent_on', DateTime(timezone=False), nullable=True, unique=None)
8cb7f5c4d494 #302 - basic notification system, models+tests
Marcin Kuzminski <marcin@python-works.com>
parents: 1693
diff changeset
1227
1713
54687aa00724 Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents: 1712
diff changeset
1228 user = relationship('User', lazy="joined")
1717
7ff304d3028f Notification fixes
Marcin Kuzminski <marcin@python-works.com>
parents: 1716
diff changeset
1229 notification = relationship('Notification', lazy="joined",
1733
ac54aa4200e8 fixed bug with eager deletes in notifications
Marcin Kuzminski <marcin@python-works.com>
parents: 1731
diff changeset
1230 order_by=lambda:Notification.created_on.desc(),)
1702
8cb7f5c4d494 #302 - basic notification system, models+tests
Marcin Kuzminski <marcin@python-works.com>
parents: 1693
diff changeset
1231
1712
cac5109ac3b6 Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents: 1703
diff changeset
1232 def mark_as_read(self):
cac5109ac3b6 Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents: 1703
diff changeset
1233 self.read = True
1713
54687aa00724 Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents: 1712
diff changeset
1234 Session().add(self)
1702
8cb7f5c4d494 #302 - basic notification system, models+tests
Marcin Kuzminski <marcin@python-works.com>
parents: 1693
diff changeset
1235
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
1236 class DbMigrateVersion(Base, BaseModel):
834
8924ed0e4f36 added current db version into rhodecode,
Marcin Kuzminski <marcin@python-works.com>
parents: 832
diff changeset
1237 __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
1238 __table_args__ = {'extend_existing':True}
1594
9dae92a65e40 fixes #288
Marcin Kuzminski <marcin@python-works.com>
parents: 1593
diff changeset
1239 repository_id = Column('repository_id', String(250), primary_key=True)
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
1240 repository_path = Column('repository_path', Text)
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
1241 version = Column('version', Integer)
1594
9dae92a65e40 fixes #288
Marcin Kuzminski <marcin@python-works.com>
parents: 1593
diff changeset
1242