Mercurial > kallithea
annotate rhodecode/lib/dbmigrate/schema/db_1_3_0.py @ 3417:fa6ba6727475 beta
further cleanup of UsersGroup
Renaming some names ... but trying not to change API or database scheme.
author | Mads Kiilerich <madski@unity3d.com> |
---|---|
date | Wed, 27 Feb 2013 17:18:43 +0100 |
parents | 95b4242a275e |
children | ffd45b185016 |
rev | line source |
---|---|
1632
5b2cf21b1947
Synced with latest sqlalchemy-migrate, added new upcomming migration for 1.3
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
1 # -*- coding: utf-8 -*- |
5b2cf21b1947
Synced with latest sqlalchemy-migrate, added new upcomming migration for 1.3
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
2 """ |
2214
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
3 rhodecode.model.db_1_3_0 |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
4 ~~~~~~~~~~~~~~~~~~~~~~~~ |
1632
5b2cf21b1947
Synced with latest sqlalchemy-migrate, added new upcomming migration for 1.3
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
5 |
2214
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
6 Database Models for RhodeCode <=1.3.X |
1632
5b2cf21b1947
Synced with latest sqlalchemy-migrate, added new upcomming migration for 1.3
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
7 |
5b2cf21b1947
Synced with latest sqlalchemy-migrate, added new upcomming migration for 1.3
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
8 :created_on: Apr 08, 2010 |
5b2cf21b1947
Synced with latest sqlalchemy-migrate, added new upcomming migration for 1.3
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
9 :author: marcink |
1824
89efedac4e6c
2012 copyrights
Marcin Kuzminski <marcin@python-works.com>
parents:
1818
diff
changeset
|
10 :copyright: (C) 2010-2012 Marcin Kuzminski <marcin@python-works.com> |
1632
5b2cf21b1947
Synced with latest sqlalchemy-migrate, added new upcomming migration for 1.3
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
11 :license: GPLv3, see COPYING for more details. |
5b2cf21b1947
Synced with latest sqlalchemy-migrate, added new upcomming migration for 1.3
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
12 """ |
5b2cf21b1947
Synced with latest sqlalchemy-migrate, added new upcomming migration for 1.3
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
13 # This program is free software: you can redistribute it and/or modify |
5b2cf21b1947
Synced with latest sqlalchemy-migrate, added new upcomming migration for 1.3
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
14 # it under the terms of the GNU General Public License as published by |
5b2cf21b1947
Synced with latest sqlalchemy-migrate, added new upcomming migration for 1.3
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
15 # the Free Software Foundation, either version 3 of the License, or |
5b2cf21b1947
Synced with latest sqlalchemy-migrate, added new upcomming migration for 1.3
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
16 # (at your option) any later version. |
5b2cf21b1947
Synced with latest sqlalchemy-migrate, added new upcomming migration for 1.3
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
17 # |
5b2cf21b1947
Synced with latest sqlalchemy-migrate, added new upcomming migration for 1.3
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
18 # This program is distributed in the hope that it will be useful, |
5b2cf21b1947
Synced with latest sqlalchemy-migrate, added new upcomming migration for 1.3
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
19 # but WITHOUT ANY WARRANTY; without even the implied warranty of |
5b2cf21b1947
Synced with latest sqlalchemy-migrate, added new upcomming migration for 1.3
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
20 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
5b2cf21b1947
Synced with latest sqlalchemy-migrate, added new upcomming migration for 1.3
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
21 # GNU General Public License for more details. |
5b2cf21b1947
Synced with latest sqlalchemy-migrate, added new upcomming migration for 1.3
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
22 # |
5b2cf21b1947
Synced with latest sqlalchemy-migrate, added new upcomming migration for 1.3
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
23 # You should have received a copy of the GNU General Public License |
1818
cf51bbfb120e
auto white-space removal
Marcin Kuzminski <marcin@python-works.com>
parents:
1632
diff
changeset
|
24 # along with this program. If not, see <http://www.gnu.org/licenses/>. |
2000
72c525a7e7ad
added migrations from 1.2.X to 1.3
Marcin Kuzminski <marcin@python-works.com>
parents:
1824
diff
changeset
|
25 |
2214
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
26 import os |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
27 import logging |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
28 import datetime |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
29 import traceback |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
30 from collections import defaultdict |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
31 |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
32 from sqlalchemy import * |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
33 from sqlalchemy.ext.hybrid import hybrid_property |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
34 from sqlalchemy.orm import relationship, joinedload, class_mapper, validates |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
35 from beaker.cache import cache_region, region_invalidate |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
36 |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
37 from rhodecode.lib.vcs import get_backend |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
38 from rhodecode.lib.vcs.utils.helpers import get_scm |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
39 from rhodecode.lib.vcs.exceptions import VCSError |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
40 from rhodecode.lib.vcs.utils.lazy import LazyProperty |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
41 |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
42 from rhodecode.lib.utils2 import str2bool, safe_str, get_changeset_safe, \ |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
43 safe_unicode |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
44 from rhodecode.lib.compat import json |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
45 from rhodecode.lib.caching_query import FromCache |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
46 |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
47 from rhodecode.model.meta import Base, Session |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
48 import hashlib |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
49 |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
50 |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
51 log = logging.getLogger(__name__) |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
52 |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
53 #============================================================================== |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
54 # BASE CLASSES |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
55 #============================================================================== |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
56 |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
57 _hash_key = lambda k: hashlib.md5(safe_str(k)).hexdigest() |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
58 |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
59 |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
60 class ModelSerializer(json.JSONEncoder): |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
61 """ |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
62 Simple Serializer for JSON, |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
63 |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
64 usage:: |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
65 |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
66 to make object customized for serialization implement a __json__ |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
67 method that will return a dict for serialization into json |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
68 |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
69 example:: |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
70 |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
71 class Task(object): |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
72 |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
73 def __init__(self, name, value): |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
74 self.name = name |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
75 self.value = value |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
76 |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
77 def __json__(self): |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
78 return dict(name=self.name, |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
79 value=self.value) |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
80 |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
81 """ |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
82 |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
83 def default(self, obj): |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
84 |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
85 if hasattr(obj, '__json__'): |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
86 return obj.__json__() |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
87 else: |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
88 return json.JSONEncoder.default(self, obj) |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
89 |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
90 |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
91 class BaseModel(object): |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
92 """ |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
93 Base Model for all classess |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
94 """ |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
95 |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
96 @classmethod |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
97 def _get_keys(cls): |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
98 """return column names for this model """ |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
99 return class_mapper(cls).c.keys() |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
100 |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
101 def get_dict(self): |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
102 """ |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
103 return dict with keys and values corresponding |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
104 to this model data """ |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
105 |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
106 d = {} |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
107 for k in self._get_keys(): |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
108 d[k] = getattr(self, k) |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
109 |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
110 # also use __json__() if present to get additional fields |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
111 for k, val in getattr(self, '__json__', lambda: {})().iteritems(): |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
112 d[k] = val |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
113 return d |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
114 |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
115 def get_appstruct(self): |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
116 """return list with keys and values tupples corresponding |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
117 to this model data """ |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
118 |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
119 l = [] |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
120 for k in self._get_keys(): |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
121 l.append((k, getattr(self, k),)) |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
122 return l |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
123 |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
124 def populate_obj(self, populate_dict): |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
125 """populate model with data from given populate_dict""" |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
126 |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
127 for k in self._get_keys(): |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
128 if k in populate_dict: |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
129 setattr(self, k, populate_dict[k]) |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
130 |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
131 @classmethod |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
132 def query(cls): |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
133 return Session.query(cls) |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
134 |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
135 @classmethod |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
136 def get(cls, id_): |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
137 if id_: |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
138 return cls.query().get(id_) |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
139 |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
140 @classmethod |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
141 def getAll(cls): |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
142 return cls.query().all() |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
143 |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
144 @classmethod |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
145 def delete(cls, id_): |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
146 obj = cls.query().get(id_) |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
147 Session.delete(obj) |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
148 |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
149 def __repr__(self): |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
150 if hasattr(self, '__unicode__'): |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
151 # python repr needs to return str |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
152 return safe_str(self.__unicode__()) |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
153 return '<DB:%s>' % (self.__class__.__name__) |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
154 |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
155 class RhodeCodeSetting(Base, BaseModel): |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
156 __tablename__ = 'rhodecode_settings' |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
157 __table_args__ = ( |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
158 UniqueConstraint('app_settings_name'), |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
159 {'extend_existing': True, 'mysql_engine':'InnoDB', |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
160 'mysql_charset': 'utf8'} |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
161 ) |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
162 app_settings_id = Column("app_settings_id", Integer(), nullable=False, unique=True, default=None, primary_key=True) |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
163 app_settings_name = Column("app_settings_name", String(length=255, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None) |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
164 _app_settings_value = Column("app_settings_value", String(length=255, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None) |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
165 |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
166 def __init__(self, k='', v=''): |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
167 self.app_settings_name = k |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
168 self.app_settings_value = v |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
169 |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
170 @validates('_app_settings_value') |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
171 def validate_settings_value(self, key, val): |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
172 assert type(val) == unicode |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
173 return val |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
174 |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
175 @hybrid_property |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
176 def app_settings_value(self): |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
177 v = self._app_settings_value |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
178 if self.app_settings_name == 'ldap_active': |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
179 v = str2bool(v) |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
180 return v |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
181 |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
182 @app_settings_value.setter |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
183 def app_settings_value(self, val): |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
184 """ |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
185 Setter that will always make sure we use unicode in app_settings_value |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
186 |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
187 :param val: |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
188 """ |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
189 self._app_settings_value = safe_unicode(val) |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
190 |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
191 def __unicode__(self): |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
192 return u"<%s('%s:%s')>" % ( |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
193 self.__class__.__name__, |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
194 self.app_settings_name, self.app_settings_value |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
195 ) |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
196 |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
197 @classmethod |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
198 def get_by_name(cls, ldap_key): |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
199 return cls.query()\ |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
200 .filter(cls.app_settings_name == ldap_key).scalar() |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
201 |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
202 @classmethod |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
203 def get_app_settings(cls, cache=False): |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
204 |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
205 ret = cls.query() |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
206 |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
207 if cache: |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
208 ret = ret.options(FromCache("sql_cache_short", "get_hg_settings")) |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
209 |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
210 if not ret: |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
211 raise Exception('Could not get application settings !') |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
212 settings = {} |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
213 for each in ret: |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
214 settings['rhodecode_' + each.app_settings_name] = \ |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
215 each.app_settings_value |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
216 |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
217 return settings |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
218 |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
219 @classmethod |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
220 def get_ldap_settings(cls, cache=False): |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
221 ret = cls.query()\ |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
222 .filter(cls.app_settings_name.startswith('ldap_')).all() |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
223 fd = {} |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
224 for row in ret: |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
225 fd.update({row.app_settings_name:row.app_settings_value}) |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
226 |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
227 return fd |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
228 |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
229 |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
230 class RhodeCodeUi(Base, BaseModel): |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
231 __tablename__ = 'rhodecode_ui' |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
232 __table_args__ = ( |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
233 UniqueConstraint('ui_key'), |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
234 {'extend_existing': True, 'mysql_engine':'InnoDB', |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
235 'mysql_charset': 'utf8'} |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
236 ) |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
237 |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
238 HOOK_UPDATE = 'changegroup.update' |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
239 HOOK_REPO_SIZE = 'changegroup.repo_size' |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
240 HOOK_PUSH = 'pretxnchangegroup.push_logger' |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
241 HOOK_PULL = 'preoutgoing.pull_logger' |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
242 |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
243 ui_id = Column("ui_id", Integer(), nullable=False, unique=True, default=None, primary_key=True) |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
244 ui_section = Column("ui_section", String(length=255, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None) |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
245 ui_key = Column("ui_key", String(length=255, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None) |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
246 ui_value = Column("ui_value", String(length=255, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None) |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
247 ui_active = Column("ui_active", Boolean(), nullable=True, unique=None, default=True) |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
248 |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
249 @classmethod |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
250 def get_by_key(cls, key): |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
251 return cls.query().filter(cls.ui_key == key) |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
252 |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
253 @classmethod |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
254 def get_builtin_hooks(cls): |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
255 q = cls.query() |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
256 q = q.filter(cls.ui_key.in_([cls.HOOK_UPDATE, |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
257 cls.HOOK_REPO_SIZE, |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
258 cls.HOOK_PUSH, cls.HOOK_PULL])) |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
259 return q.all() |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
260 |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
261 @classmethod |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
262 def get_custom_hooks(cls): |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
263 q = cls.query() |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
264 q = q.filter(~cls.ui_key.in_([cls.HOOK_UPDATE, |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
265 cls.HOOK_REPO_SIZE, |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
266 cls.HOOK_PUSH, cls.HOOK_PULL])) |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
267 q = q.filter(cls.ui_section == 'hooks') |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
268 return q.all() |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
269 |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
270 @classmethod |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
271 def create_or_update_hook(cls, key, val): |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
272 new_ui = cls.get_by_key(key).scalar() or cls() |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
273 new_ui.ui_section = 'hooks' |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
274 new_ui.ui_active = True |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
275 new_ui.ui_key = key |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
276 new_ui.ui_value = val |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
277 |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
278 Session.add(new_ui) |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
279 |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
280 |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
281 class User(Base, BaseModel): |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
282 __tablename__ = 'users' |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
283 __table_args__ = ( |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
284 UniqueConstraint('username'), UniqueConstraint('email'), |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
285 {'extend_existing': True, 'mysql_engine':'InnoDB', |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
286 'mysql_charset': 'utf8'} |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
287 ) |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
288 user_id = Column("user_id", Integer(), nullable=False, unique=True, default=None, primary_key=True) |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
289 username = Column("username", String(length=255, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None) |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
290 password = Column("password", String(length=255, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None) |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
291 active = Column("active", Boolean(), nullable=True, unique=None, default=None) |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
292 admin = Column("admin", Boolean(), nullable=True, unique=None, default=False) |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
293 name = Column("name", String(length=255, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None) |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
294 lastname = Column("lastname", String(length=255, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None) |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
295 _email = Column("email", String(length=255, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None) |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
296 last_login = Column("last_login", DateTime(timezone=False), nullable=True, unique=None, default=None) |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
297 ldap_dn = Column("ldap_dn", String(length=255, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None) |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
298 api_key = Column("api_key", String(length=255, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None) |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
299 |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
300 user_log = relationship('UserLog', cascade='all') |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
301 user_perms = relationship('UserToPerm', primaryjoin="User.user_id==UserToPerm.user_id", cascade='all') |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
302 |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
303 repositories = relationship('Repository') |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
304 user_followers = relationship('UserFollowing', primaryjoin='UserFollowing.follows_user_id==User.user_id', cascade='all') |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
305 repo_to_perm = relationship('UserRepoToPerm', primaryjoin='UserRepoToPerm.user_id==User.user_id', cascade='all') |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
306 repo_group_to_perm = relationship('UserRepoGroupToPerm', primaryjoin='UserRepoGroupToPerm.user_id==User.user_id', cascade='all') |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
307 |
3417
fa6ba6727475
further cleanup of UsersGroup
Mads Kiilerich <madski@unity3d.com>
parents:
3133
diff
changeset
|
308 group_member = relationship('UserGroupMember', cascade='all') |
2214
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
309 |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
310 notifications = relationship('UserNotification', cascade='all') |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
311 # notifications assigned to this user |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
312 user_created_notifications = relationship('Notification', cascade='all') |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
313 # comments created by this user |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
314 user_comments = relationship('ChangesetComment', cascade='all') |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
315 |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
316 @hybrid_property |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
317 def email(self): |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
318 return self._email |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
319 |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
320 @email.setter |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
321 def email(self, val): |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
322 self._email = val.lower() if val else None |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
323 |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
324 @property |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
325 def full_name(self): |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
326 return '%s %s' % (self.name, self.lastname) |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
327 |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
328 @property |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
329 def full_name_or_username(self): |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
330 return ('%s %s' % (self.name, self.lastname) |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
331 if (self.name and self.lastname) else self.username) |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
332 |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
333 @property |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
334 def full_contact(self): |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
335 return '%s %s <%s>' % (self.name, self.lastname, self.email) |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
336 |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
337 @property |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
338 def short_contact(self): |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
339 return '%s %s' % (self.name, self.lastname) |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
340 |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
341 @property |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
342 def is_admin(self): |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
343 return self.admin |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
344 |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
345 def __unicode__(self): |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
346 return u"<%s('id:%s:%s')>" % (self.__class__.__name__, |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
347 self.user_id, self.username) |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
348 |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
349 @classmethod |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
350 def get_by_username(cls, username, case_insensitive=False, cache=False): |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
351 if case_insensitive: |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
352 q = cls.query().filter(cls.username.ilike(username)) |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
353 else: |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
354 q = cls.query().filter(cls.username == username) |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
355 |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
356 if cache: |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
357 q = q.options(FromCache( |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
358 "sql_cache_short", |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
359 "get_user_%s" % _hash_key(username) |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
360 ) |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
361 ) |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
362 return q.scalar() |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
363 |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
364 @classmethod |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
365 def get_by_api_key(cls, api_key, cache=False): |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
366 q = cls.query().filter(cls.api_key == api_key) |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
367 |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
368 if cache: |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
369 q = q.options(FromCache("sql_cache_short", |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
370 "get_api_key_%s" % api_key)) |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
371 return q.scalar() |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
372 |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
373 @classmethod |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
374 def get_by_email(cls, email, case_insensitive=False, cache=False): |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
375 if case_insensitive: |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
376 q = cls.query().filter(cls.email.ilike(email)) |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
377 else: |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
378 q = cls.query().filter(cls.email == email) |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
379 |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
380 if cache: |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
381 q = q.options(FromCache("sql_cache_short", |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
382 "get_api_key_%s" % email)) |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
383 return q.scalar() |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
384 |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
385 def update_lastlogin(self): |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
386 """Update user lastlogin""" |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
387 self.last_login = datetime.datetime.now() |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
388 Session.add(self) |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
389 log.debug('updated user %s lastlogin' % self.username) |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
390 |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
391 def __json__(self): |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
392 return dict( |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
393 user_id=self.user_id, |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
394 first_name=self.name, |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
395 last_name=self.lastname, |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
396 email=self.email, |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
397 full_name=self.full_name, |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
398 full_name_or_username=self.full_name_or_username, |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
399 short_contact=self.short_contact, |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
400 full_contact=self.full_contact |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
401 ) |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
402 |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
403 |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
404 class UserLog(Base, BaseModel): |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
405 __tablename__ = 'user_logs' |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
406 __table_args__ = ( |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
407 {'extend_existing': True, 'mysql_engine':'InnoDB', |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
408 'mysql_charset': 'utf8'}, |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
409 ) |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
410 user_log_id = Column("user_log_id", Integer(), nullable=False, unique=True, default=None, primary_key=True) |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
411 user_id = Column("user_id", Integer(), ForeignKey('users.user_id'), nullable=False, unique=None, default=None) |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
412 repository_id = Column("repository_id", Integer(), ForeignKey('repositories.repo_id'), nullable=True) |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
413 repository_name = Column("repository_name", String(length=255, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None) |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
414 user_ip = Column("user_ip", String(length=255, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None) |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
415 action = Column("action", UnicodeText(length=1200000, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None) |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
416 action_date = Column("action_date", DateTime(timezone=False), nullable=True, unique=None, default=None) |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
417 |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
418 @property |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
419 def action_as_day(self): |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
420 return datetime.date(*self.action_date.timetuple()[:3]) |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
421 |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
422 user = relationship('User') |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
423 repository = relationship('Repository', cascade='') |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
424 |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
425 |
3417
fa6ba6727475
further cleanup of UsersGroup
Mads Kiilerich <madski@unity3d.com>
parents:
3133
diff
changeset
|
426 class UserGroup(Base, BaseModel): |
2214
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
427 __tablename__ = 'users_groups' |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
428 __table_args__ = ( |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
429 {'extend_existing': True, 'mysql_engine':'InnoDB', |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
430 'mysql_charset': 'utf8'}, |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
431 ) |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
432 |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
433 users_group_id = Column("users_group_id", Integer(), nullable=False, unique=True, default=None, primary_key=True) |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
434 users_group_name = Column("users_group_name", String(length=255, convert_unicode=False, assert_unicode=None), nullable=False, unique=True, default=None) |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
435 users_group_active = Column("users_group_active", Boolean(), nullable=True, unique=None, default=None) |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
436 |
3417
fa6ba6727475
further cleanup of UsersGroup
Mads Kiilerich <madski@unity3d.com>
parents:
3133
diff
changeset
|
437 members = relationship('UserGroupMember', cascade="all, delete, delete-orphan", lazy="joined") |
fa6ba6727475
further cleanup of UsersGroup
Mads Kiilerich <madski@unity3d.com>
parents:
3133
diff
changeset
|
438 users_group_to_perm = relationship('UserGroupToPerm', cascade='all') |
fa6ba6727475
further cleanup of UsersGroup
Mads Kiilerich <madski@unity3d.com>
parents:
3133
diff
changeset
|
439 users_group_repo_to_perm = relationship('UserGroupRepoToPerm', cascade='all') |
2214
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
440 |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
441 def __unicode__(self): |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
442 return u'<userGroup(%s)>' % (self.users_group_name) |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
443 |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
444 @classmethod |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
445 def get_by_group_name(cls, group_name, cache=False, |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
446 case_insensitive=False): |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
447 if case_insensitive: |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
448 q = cls.query().filter(cls.users_group_name.ilike(group_name)) |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
449 else: |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
450 q = cls.query().filter(cls.users_group_name == group_name) |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
451 if cache: |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
452 q = q.options(FromCache( |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
453 "sql_cache_short", |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
454 "get_user_%s" % _hash_key(group_name) |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
455 ) |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
456 ) |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
457 return q.scalar() |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
458 |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
459 @classmethod |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
460 def get(cls, users_group_id, cache=False): |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
461 users_group = cls.query() |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
462 if cache: |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
463 users_group = users_group.options(FromCache("sql_cache_short", |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
464 "get_users_group_%s" % users_group_id)) |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
465 return users_group.get(users_group_id) |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
466 |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
467 |
3417
fa6ba6727475
further cleanup of UsersGroup
Mads Kiilerich <madski@unity3d.com>
parents:
3133
diff
changeset
|
468 class UserGroupMember(Base, BaseModel): |
2214
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
469 __tablename__ = 'users_groups_members' |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
470 __table_args__ = ( |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
471 {'extend_existing': True, 'mysql_engine':'InnoDB', |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
472 'mysql_charset': 'utf8'}, |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
473 ) |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
474 |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
475 users_group_member_id = Column("users_group_member_id", Integer(), nullable=False, unique=True, default=None, primary_key=True) |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
476 users_group_id = Column("users_group_id", Integer(), ForeignKey('users_groups.users_group_id'), nullable=False, unique=None, default=None) |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
477 user_id = Column("user_id", Integer(), ForeignKey('users.user_id'), nullable=False, unique=None, default=None) |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
478 |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
479 user = relationship('User', lazy='joined') |
3417
fa6ba6727475
further cleanup of UsersGroup
Mads Kiilerich <madski@unity3d.com>
parents:
3133
diff
changeset
|
480 users_group = relationship('UserGroup') |
2214
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
481 |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
482 def __init__(self, gr_id='', u_id=''): |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
483 self.users_group_id = gr_id |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
484 self.user_id = u_id |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
485 |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
486 |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
487 class Repository(Base, BaseModel): |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
488 __tablename__ = 'repositories' |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
489 __table_args__ = ( |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
490 UniqueConstraint('repo_name'), |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
491 {'extend_existing': True, 'mysql_engine':'InnoDB', |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
492 'mysql_charset': 'utf8'}, |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
493 ) |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
494 |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
495 repo_id = Column("repo_id", Integer(), nullable=False, unique=True, default=None, primary_key=True) |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
496 repo_name = Column("repo_name", String(length=255, convert_unicode=False, assert_unicode=None), nullable=False, unique=True, default=None) |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
497 clone_uri = Column("clone_uri", String(length=255, convert_unicode=False, assert_unicode=None), nullable=True, unique=False, default=None) |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
498 repo_type = Column("repo_type", String(length=255, convert_unicode=False, assert_unicode=None), nullable=False, unique=False, default='hg') |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
499 user_id = Column("user_id", Integer(), ForeignKey('users.user_id'), nullable=False, unique=False, default=None) |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
500 private = Column("private", Boolean(), nullable=True, unique=None, default=None) |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
501 enable_statistics = Column("statistics", Boolean(), nullable=True, unique=None, default=True) |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
502 enable_downloads = Column("downloads", Boolean(), nullable=True, unique=None, default=True) |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
503 description = Column("description", String(length=10000, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None) |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
504 created_on = Column('created_on', DateTime(timezone=False), nullable=True, unique=None, default=datetime.datetime.now) |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
505 |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
506 fork_id = Column("fork_id", Integer(), ForeignKey('repositories.repo_id'), nullable=True, unique=False, default=None) |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
507 group_id = Column("group_id", Integer(), ForeignKey('groups.group_id'), nullable=True, unique=False, default=None) |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
508 |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
509 user = relationship('User') |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
510 fork = relationship('Repository', remote_side=repo_id) |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
511 group = relationship('RepoGroup') |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
512 repo_to_perm = relationship('UserRepoToPerm', cascade='all', order_by='UserRepoToPerm.repo_to_perm_id') |
3417
fa6ba6727475
further cleanup of UsersGroup
Mads Kiilerich <madski@unity3d.com>
parents:
3133
diff
changeset
|
513 users_group_to_perm = relationship('UserGroupRepoToPerm', cascade='all') |
2214
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
514 stats = relationship('Statistics', cascade='all', uselist=False) |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
515 |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
516 followers = relationship('UserFollowing', primaryjoin='UserFollowing.follows_repo_id==Repository.repo_id', cascade='all') |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
517 |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
518 logs = relationship('UserLog') |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
519 |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
520 def __unicode__(self): |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
521 return u"<%s('%s:%s')>" % (self.__class__.__name__,self.repo_id, |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
522 self.repo_name) |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
523 |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
524 @classmethod |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
525 def url_sep(cls): |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
526 return '/' |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
527 |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
528 @classmethod |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
529 def get_by_repo_name(cls, repo_name): |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
530 q = Session.query(cls).filter(cls.repo_name == repo_name) |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
531 q = q.options(joinedload(Repository.fork))\ |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
532 .options(joinedload(Repository.user))\ |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
533 .options(joinedload(Repository.group)) |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
534 return q.scalar() |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
535 |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
536 @classmethod |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
537 def get_repo_forks(cls, repo_id): |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
538 return cls.query().filter(Repository.fork_id == repo_id) |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
539 |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
540 @classmethod |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
541 def base_path(cls): |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
542 """ |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
543 Returns base path when all repos are stored |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
544 |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
545 :param cls: |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
546 """ |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
547 q = Session.query(RhodeCodeUi)\ |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
548 .filter(RhodeCodeUi.ui_key == cls.url_sep()) |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
549 q = q.options(FromCache("sql_cache_short", "repository_repo_path")) |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
550 return q.one().ui_value |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
551 |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
552 @property |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
553 def just_name(self): |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
554 return self.repo_name.split(Repository.url_sep())[-1] |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
555 |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
556 @property |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
557 def groups_with_parents(self): |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
558 groups = [] |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
559 if self.group is None: |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
560 return groups |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
561 |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
562 cur_gr = self.group |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
563 groups.insert(0, cur_gr) |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
564 while 1: |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
565 gr = getattr(cur_gr, 'parent_group', None) |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
566 cur_gr = cur_gr.parent_group |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
567 if gr is None: |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
568 break |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
569 groups.insert(0, gr) |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
570 |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
571 return groups |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
572 |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
573 @property |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
574 def groups_and_repo(self): |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
575 return self.groups_with_parents, self.just_name |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
576 |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
577 @LazyProperty |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
578 def repo_path(self): |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
579 """ |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
580 Returns base full path for that repository means where it actually |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
581 exists on a filesystem |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
582 """ |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
583 q = Session.query(RhodeCodeUi).filter(RhodeCodeUi.ui_key == |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
584 Repository.url_sep()) |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
585 q = q.options(FromCache("sql_cache_short", "repository_repo_path")) |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
586 return q.one().ui_value |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
587 |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
588 @property |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
589 def repo_full_path(self): |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
590 p = [self.repo_path] |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
591 # we need to split the name by / since this is how we store the |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
592 # names in the database, but that eventually needs to be converted |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
593 # into a valid system path |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
594 p += self.repo_name.split(Repository.url_sep()) |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
595 return os.path.join(*p) |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
596 |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
597 def get_new_name(self, repo_name): |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
598 """ |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
599 returns new full repository name based on assigned group and new new |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
600 |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
601 :param group_name: |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
602 """ |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
603 path_prefix = self.group.full_path_splitted if self.group else [] |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
604 return Repository.url_sep().join(path_prefix + [repo_name]) |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
605 |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
606 @property |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
607 def _ui(self): |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
608 """ |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
609 Creates an db based ui object for this repository |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
610 """ |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
611 from mercurial import ui |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
612 from mercurial import config |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
613 baseui = ui.ui() |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
614 |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
615 #clean the baseui object |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
616 baseui._ocfg = config.config() |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
617 baseui._ucfg = config.config() |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
618 baseui._tcfg = config.config() |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
619 |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
620 ret = RhodeCodeUi.query()\ |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
621 .options(FromCache("sql_cache_short", "repository_repo_ui")).all() |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
622 |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
623 hg_ui = ret |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
624 for ui_ in hg_ui: |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
625 if ui_.ui_active: |
3133
95b4242a275e
logging: make 'settings ui from db' look more like Mercurial ini file notation
Mads Kiilerich <madski@unity3d.com>
parents:
2815
diff
changeset
|
626 log.debug('settings ui from db: [%s] %s=%s', ui_.ui_section, |
2214
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
627 ui_.ui_key, ui_.ui_value) |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
628 baseui.setconfig(ui_.ui_section, ui_.ui_key, ui_.ui_value) |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
629 |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
630 return baseui |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
631 |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
632 @classmethod |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
633 def is_valid(cls, repo_name): |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
634 """ |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
635 returns True if given repo name is a valid filesystem repository |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
636 |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
637 :param cls: |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
638 :param repo_name: |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
639 """ |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
640 from rhodecode.lib.utils import is_valid_repo |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
641 |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
642 return is_valid_repo(repo_name, cls.base_path()) |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
643 |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
644 #========================================================================== |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
645 # SCM PROPERTIES |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
646 #========================================================================== |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
647 |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
648 def get_changeset(self, rev): |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
649 return get_changeset_safe(self.scm_instance, rev) |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
650 |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
651 @property |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
652 def tip(self): |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
653 return self.get_changeset('tip') |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
654 |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
655 @property |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
656 def author(self): |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
657 return self.tip.author |
2000
72c525a7e7ad
added migrations from 1.2.X to 1.3
Marcin Kuzminski <marcin@python-works.com>
parents:
1824
diff
changeset
|
658 |
2214
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
659 @property |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
660 def last_change(self): |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
661 return self.scm_instance.last_change |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
662 |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
663 def comments(self, revisions=None): |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
664 """ |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
665 Returns comments for this repository grouped by revisions |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
666 |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
667 :param revisions: filter query by revisions only |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
668 """ |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
669 cmts = ChangesetComment.query()\ |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
670 .filter(ChangesetComment.repo == self) |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
671 if revisions: |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
672 cmts = cmts.filter(ChangesetComment.revision.in_(revisions)) |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
673 grouped = defaultdict(list) |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
674 for cmt in cmts.all(): |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
675 grouped[cmt.revision].append(cmt) |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
676 return grouped |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
677 |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
678 #========================================================================== |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
679 # SCM CACHE INSTANCE |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
680 #========================================================================== |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
681 |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
682 @property |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
683 def invalidate(self): |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
684 return CacheInvalidation.invalidate(self.repo_name) |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
685 |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
686 def set_invalidate(self): |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
687 """ |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
688 set a cache for invalidation for this instance |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
689 """ |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
690 CacheInvalidation.set_invalidate(self.repo_name) |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
691 |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
692 @LazyProperty |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
693 def scm_instance(self): |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
694 return self.__get_instance() |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
695 |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
696 @property |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
697 def scm_instance_cached(self): |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
698 @cache_region('long_term') |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
699 def _c(repo_name): |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
700 return self.__get_instance() |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
701 rn = self.repo_name |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
702 log.debug('Getting cached instance of repo') |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
703 inv = self.invalidate |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
704 if inv is not None: |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
705 region_invalidate(_c, None, rn) |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
706 # update our cache |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
707 CacheInvalidation.set_valid(inv.cache_key) |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
708 return _c(rn) |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
709 |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
710 def __get_instance(self): |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
711 repo_full_path = self.repo_full_path |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
712 try: |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
713 alias = get_scm(repo_full_path)[0] |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
714 log.debug('Creating instance of %s repository' % alias) |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
715 backend = get_backend(alias) |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
716 except VCSError: |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
717 log.error(traceback.format_exc()) |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
718 log.error('Perhaps this repository is in db and not in ' |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
719 'filesystem run rescan repositories with ' |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
720 '"destroy old data " option from admin panel') |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
721 return |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
722 |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
723 if alias == 'hg': |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
724 |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
725 repo = backend(safe_str(repo_full_path), create=False, |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
726 baseui=self._ui) |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
727 # skip hidden web repository |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
728 if repo._get_hidden(): |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
729 return |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
730 else: |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
731 repo = backend(repo_full_path, create=False) |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
732 |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
733 return repo |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
734 |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
735 |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
736 class RepoGroup(Base, BaseModel): |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
737 __tablename__ = 'groups' |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
738 __table_args__ = ( |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
739 UniqueConstraint('group_name', 'group_parent_id'), |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
740 CheckConstraint('group_id != group_parent_id'), |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
741 {'extend_existing': True, 'mysql_engine':'InnoDB', |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
742 'mysql_charset': 'utf8'}, |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
743 ) |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
744 __mapper_args__ = {'order_by': 'group_name'} |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
745 |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
746 group_id = Column("group_id", Integer(), nullable=False, unique=True, default=None, primary_key=True) |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
747 group_name = Column("group_name", String(length=255, convert_unicode=False, assert_unicode=None), nullable=False, unique=True, default=None) |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
748 group_parent_id = Column("group_parent_id", Integer(), ForeignKey('groups.group_id'), nullable=True, unique=None, default=None) |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
749 group_description = Column("group_description", String(length=10000, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None) |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
750 |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
751 repo_group_to_perm = relationship('UserRepoGroupToPerm', cascade='all', order_by='UserRepoGroupToPerm.group_to_perm_id') |
3417
fa6ba6727475
further cleanup of UsersGroup
Mads Kiilerich <madski@unity3d.com>
parents:
3133
diff
changeset
|
752 users_group_to_perm = relationship('UserGroupRepoGroupToPerm', cascade='all') |
2214
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
753 |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
754 parent_group = relationship('RepoGroup', remote_side=group_id) |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
755 |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
756 def __init__(self, group_name='', parent_group=None): |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
757 self.group_name = group_name |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
758 self.parent_group = parent_group |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
759 |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
760 def __unicode__(self): |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
761 return u"<%s('%s:%s')>" % (self.__class__.__name__, self.group_id, |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
762 self.group_name) |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
763 |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
764 @classmethod |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
765 def groups_choices(cls): |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
766 from webhelpers.html import literal as _literal |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
767 repo_groups = [('', '')] |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
768 sep = ' » ' |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
769 _name = lambda k: _literal(sep.join(k)) |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
770 |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
771 repo_groups.extend([(x.group_id, _name(x.full_path_splitted)) |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
772 for x in cls.query().all()]) |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
773 |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
774 repo_groups = sorted(repo_groups, key=lambda t: t[1].split(sep)[0]) |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
775 return repo_groups |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
776 |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
777 @classmethod |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
778 def url_sep(cls): |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
779 return '/' |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
780 |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
781 @classmethod |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
782 def get_by_group_name(cls, group_name, cache=False, case_insensitive=False): |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
783 if case_insensitive: |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
784 gr = cls.query()\ |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
785 .filter(cls.group_name.ilike(group_name)) |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
786 else: |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
787 gr = cls.query()\ |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
788 .filter(cls.group_name == group_name) |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
789 if cache: |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
790 gr = gr.options(FromCache( |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
791 "sql_cache_short", |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
792 "get_group_%s" % _hash_key(group_name) |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
793 ) |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
794 ) |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
795 return gr.scalar() |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
796 |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
797 @property |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
798 def parents(self): |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
799 parents_recursion_limit = 5 |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
800 groups = [] |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
801 if self.parent_group is None: |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
802 return groups |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
803 cur_gr = self.parent_group |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
804 groups.insert(0, cur_gr) |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
805 cnt = 0 |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
806 while 1: |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
807 cnt += 1 |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
808 gr = getattr(cur_gr, 'parent_group', None) |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
809 cur_gr = cur_gr.parent_group |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
810 if gr is None: |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
811 break |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
812 if cnt == parents_recursion_limit: |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
813 # this will prevent accidental infinit loops |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
814 log.error('group nested more than %s' % |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
815 parents_recursion_limit) |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
816 break |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
817 |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
818 groups.insert(0, gr) |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
819 return groups |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
820 |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
821 @property |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
822 def children(self): |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
823 return RepoGroup.query().filter(RepoGroup.parent_group == self) |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
824 |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
825 @property |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
826 def name(self): |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
827 return self.group_name.split(RepoGroup.url_sep())[-1] |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
828 |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
829 @property |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
830 def full_path(self): |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
831 return self.group_name |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
832 |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
833 @property |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
834 def full_path_splitted(self): |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
835 return self.group_name.split(RepoGroup.url_sep()) |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
836 |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
837 @property |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
838 def repositories(self): |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
839 return Repository.query()\ |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
840 .filter(Repository.group == self)\ |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
841 .order_by(Repository.repo_name) |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
842 |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
843 @property |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
844 def repositories_recursive_count(self): |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
845 cnt = self.repositories.count() |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
846 |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
847 def children_count(group): |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
848 cnt = 0 |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
849 for child in group.children: |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
850 cnt += child.repositories.count() |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
851 cnt += children_count(child) |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
852 return cnt |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
853 |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
854 return cnt + children_count(self) |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
855 |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
856 def get_new_name(self, group_name): |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
857 """ |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
858 returns new full group name based on parent and new name |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
859 |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
860 :param group_name: |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
861 """ |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
862 path_prefix = (self.parent_group.full_path_splitted if |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
863 self.parent_group else []) |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
864 return RepoGroup.url_sep().join(path_prefix + [group_name]) |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
865 |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
866 |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
867 class Permission(Base, BaseModel): |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
868 __tablename__ = 'permissions' |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
869 __table_args__ = ( |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
870 {'extend_existing': True, 'mysql_engine':'InnoDB', |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
871 'mysql_charset': 'utf8'}, |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
872 ) |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
873 permission_id = Column("permission_id", Integer(), nullable=False, unique=True, default=None, primary_key=True) |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
874 permission_name = Column("permission_name", String(length=255, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None) |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
875 permission_longname = Column("permission_longname", String(length=255, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None) |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
876 |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
877 def __unicode__(self): |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
878 return u"<%s('%s:%s')>" % ( |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
879 self.__class__.__name__, self.permission_id, self.permission_name |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
880 ) |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
881 |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
882 @classmethod |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
883 def get_by_key(cls, key): |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
884 return cls.query().filter(cls.permission_name == key).scalar() |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
885 |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
886 @classmethod |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
887 def get_default_perms(cls, default_user_id): |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
888 q = Session.query(UserRepoToPerm, Repository, cls)\ |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
889 .join((Repository, UserRepoToPerm.repository_id == Repository.repo_id))\ |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
890 .join((cls, UserRepoToPerm.permission_id == cls.permission_id))\ |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
891 .filter(UserRepoToPerm.user_id == default_user_id) |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
892 |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
893 return q.all() |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
894 |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
895 @classmethod |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
896 def get_default_group_perms(cls, default_user_id): |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
897 q = Session.query(UserRepoGroupToPerm, RepoGroup, cls)\ |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
898 .join((RepoGroup, UserRepoGroupToPerm.group_id == RepoGroup.group_id))\ |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
899 .join((cls, UserRepoGroupToPerm.permission_id == cls.permission_id))\ |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
900 .filter(UserRepoGroupToPerm.user_id == default_user_id) |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
901 |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
902 return q.all() |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
903 |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
904 |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
905 class UserRepoToPerm(Base, BaseModel): |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
906 __tablename__ = 'repo_to_perm' |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
907 __table_args__ = ( |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
908 UniqueConstraint('user_id', 'repository_id', 'permission_id'), |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
909 {'extend_existing': True, 'mysql_engine':'InnoDB', |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
910 'mysql_charset': 'utf8'} |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
911 ) |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
912 repo_to_perm_id = Column("repo_to_perm_id", Integer(), nullable=False, unique=True, default=None, primary_key=True) |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
913 user_id = Column("user_id", Integer(), ForeignKey('users.user_id'), nullable=False, unique=None, default=None) |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
914 permission_id = Column("permission_id", Integer(), ForeignKey('permissions.permission_id'), nullable=False, unique=None, default=None) |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
915 repository_id = Column("repository_id", Integer(), ForeignKey('repositories.repo_id'), nullable=False, unique=None, default=None) |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
916 |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
917 user = relationship('User') |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
918 repository = relationship('Repository') |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
919 permission = relationship('Permission') |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
920 |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
921 @classmethod |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
922 def create(cls, user, repository, permission): |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
923 n = cls() |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
924 n.user = user |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
925 n.repository = repository |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
926 n.permission = permission |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
927 Session.add(n) |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
928 return n |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
929 |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
930 def __unicode__(self): |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
931 return u'<user:%s => %s >' % (self.user, self.repository) |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
932 |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
933 |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
934 class UserToPerm(Base, BaseModel): |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
935 __tablename__ = 'user_to_perm' |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
936 __table_args__ = ( |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
937 UniqueConstraint('user_id', 'permission_id'), |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
938 {'extend_existing': True, 'mysql_engine':'InnoDB', |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
939 'mysql_charset': 'utf8'} |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
940 ) |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
941 user_to_perm_id = Column("user_to_perm_id", Integer(), nullable=False, unique=True, default=None, primary_key=True) |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
942 user_id = Column("user_id", Integer(), ForeignKey('users.user_id'), nullable=False, unique=None, default=None) |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
943 permission_id = Column("permission_id", Integer(), ForeignKey('permissions.permission_id'), nullable=False, unique=None, default=None) |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
944 |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
945 user = relationship('User') |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
946 permission = relationship('Permission', lazy='joined') |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
947 |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
948 |
3417
fa6ba6727475
further cleanup of UsersGroup
Mads Kiilerich <madski@unity3d.com>
parents:
3133
diff
changeset
|
949 class UserGroupRepoToPerm(Base, BaseModel): |
2214
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
950 __tablename__ = 'users_group_repo_to_perm' |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
951 __table_args__ = ( |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
952 UniqueConstraint('repository_id', 'users_group_id', 'permission_id'), |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
953 {'extend_existing': True, 'mysql_engine':'InnoDB', |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
954 'mysql_charset': 'utf8'} |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
955 ) |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
956 users_group_to_perm_id = Column("users_group_to_perm_id", Integer(), nullable=False, unique=True, default=None, primary_key=True) |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
957 users_group_id = Column("users_group_id", Integer(), ForeignKey('users_groups.users_group_id'), nullable=False, unique=None, default=None) |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
958 permission_id = Column("permission_id", Integer(), ForeignKey('permissions.permission_id'), nullable=False, unique=None, default=None) |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
959 repository_id = Column("repository_id", Integer(), ForeignKey('repositories.repo_id'), nullable=False, unique=None, default=None) |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
960 |
3417
fa6ba6727475
further cleanup of UsersGroup
Mads Kiilerich <madski@unity3d.com>
parents:
3133
diff
changeset
|
961 users_group = relationship('UserGroup') |
2214
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
962 permission = relationship('Permission') |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
963 repository = relationship('Repository') |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
964 |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
965 @classmethod |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
966 def create(cls, users_group, repository, permission): |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
967 n = cls() |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
968 n.users_group = users_group |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
969 n.repository = repository |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
970 n.permission = permission |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
971 Session.add(n) |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
972 return n |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
973 |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
974 def __unicode__(self): |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
975 return u'<userGroup:%s => %s >' % (self.users_group, self.repository) |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
976 |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
977 |
3417
fa6ba6727475
further cleanup of UsersGroup
Mads Kiilerich <madski@unity3d.com>
parents:
3133
diff
changeset
|
978 class UserGroupToPerm(Base, BaseModel): |
2214
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
979 __tablename__ = 'users_group_to_perm' |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
980 __table_args__ = ( |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
981 UniqueConstraint('users_group_id', 'permission_id',), |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
982 {'extend_existing': True, 'mysql_engine':'InnoDB', |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
983 'mysql_charset': 'utf8'} |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
984 ) |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
985 users_group_to_perm_id = Column("users_group_to_perm_id", Integer(), nullable=False, unique=True, default=None, primary_key=True) |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
986 users_group_id = Column("users_group_id", Integer(), ForeignKey('users_groups.users_group_id'), nullable=False, unique=None, default=None) |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
987 permission_id = Column("permission_id", Integer(), ForeignKey('permissions.permission_id'), nullable=False, unique=None, default=None) |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
988 |
3417
fa6ba6727475
further cleanup of UsersGroup
Mads Kiilerich <madski@unity3d.com>
parents:
3133
diff
changeset
|
989 users_group = relationship('UserGroup') |
2214
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
990 permission = relationship('Permission') |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
991 |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
992 |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
993 class UserRepoGroupToPerm(Base, BaseModel): |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
994 __tablename__ = 'user_repo_group_to_perm' |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
995 __table_args__ = ( |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
996 UniqueConstraint('user_id', 'group_id', 'permission_id'), |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
997 {'extend_existing': True, 'mysql_engine':'InnoDB', |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
998 'mysql_charset': 'utf8'} |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
999 ) |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
1000 |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
1001 group_to_perm_id = Column("group_to_perm_id", Integer(), nullable=False, unique=True, default=None, primary_key=True) |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
1002 user_id = Column("user_id", Integer(), ForeignKey('users.user_id'), nullable=False, unique=None, default=None) |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
1003 group_id = Column("group_id", Integer(), ForeignKey('groups.group_id'), nullable=False, unique=None, default=None) |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
1004 permission_id = Column("permission_id", Integer(), ForeignKey('permissions.permission_id'), nullable=False, unique=None, default=None) |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
1005 |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
1006 user = relationship('User') |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
1007 group = relationship('RepoGroup') |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
1008 permission = relationship('Permission') |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
1009 |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
1010 |
3417
fa6ba6727475
further cleanup of UsersGroup
Mads Kiilerich <madski@unity3d.com>
parents:
3133
diff
changeset
|
1011 class UserGroupRepoGroupToPerm(Base, BaseModel): |
2214
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
1012 __tablename__ = 'users_group_repo_group_to_perm' |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
1013 __table_args__ = ( |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
1014 UniqueConstraint('users_group_id', 'group_id'), |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
1015 {'extend_existing': True, 'mysql_engine':'InnoDB', |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
1016 'mysql_charset': 'utf8'} |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
1017 ) |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
1018 |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
1019 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) |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
1020 users_group_id = Column("users_group_id", Integer(), ForeignKey('users_groups.users_group_id'), nullable=False, unique=None, default=None) |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
1021 group_id = Column("group_id", Integer(), ForeignKey('groups.group_id'), nullable=False, unique=None, default=None) |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
1022 permission_id = Column("permission_id", Integer(), ForeignKey('permissions.permission_id'), nullable=False, unique=None, default=None) |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
1023 |
3417
fa6ba6727475
further cleanup of UsersGroup
Mads Kiilerich <madski@unity3d.com>
parents:
3133
diff
changeset
|
1024 users_group = relationship('UserGroup') |
2214
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
1025 permission = relationship('Permission') |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
1026 group = relationship('RepoGroup') |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
1027 |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
1028 |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
1029 class Statistics(Base, BaseModel): |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
1030 __tablename__ = 'statistics' |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
1031 __table_args__ = ( |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
1032 UniqueConstraint('repository_id'), |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
1033 {'extend_existing': True, 'mysql_engine':'InnoDB', |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
1034 'mysql_charset': 'utf8'} |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
1035 ) |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
1036 stat_id = Column("stat_id", Integer(), nullable=False, unique=True, default=None, primary_key=True) |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
1037 repository_id = Column("repository_id", Integer(), ForeignKey('repositories.repo_id'), nullable=False, unique=True, default=None) |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
1038 stat_on_revision = Column("stat_on_revision", Integer(), nullable=False) |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
1039 commit_activity = Column("commit_activity", LargeBinary(1000000), nullable=False)#JSON data |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
1040 commit_activity_combined = Column("commit_activity_combined", LargeBinary(), nullable=False)#JSON data |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
1041 languages = Column("languages", LargeBinary(1000000), nullable=False)#JSON data |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
1042 |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
1043 repository = relationship('Repository', single_parent=True) |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
1044 |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
1045 |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
1046 class UserFollowing(Base, BaseModel): |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
1047 __tablename__ = 'user_followings' |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
1048 __table_args__ = ( |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
1049 UniqueConstraint('user_id', 'follows_repository_id'), |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
1050 UniqueConstraint('user_id', 'follows_user_id'), |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
1051 {'extend_existing': True, 'mysql_engine':'InnoDB', |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
1052 'mysql_charset': 'utf8'} |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
1053 ) |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
1054 |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
1055 user_following_id = Column("user_following_id", Integer(), nullable=False, unique=True, default=None, primary_key=True) |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
1056 user_id = Column("user_id", Integer(), ForeignKey('users.user_id'), nullable=False, unique=None, default=None) |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
1057 follows_repo_id = Column("follows_repository_id", Integer(), ForeignKey('repositories.repo_id'), nullable=True, unique=None, default=None) |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
1058 follows_user_id = Column("follows_user_id", Integer(), ForeignKey('users.user_id'), nullable=True, unique=None, default=None) |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
1059 follows_from = Column('follows_from', DateTime(timezone=False), nullable=True, unique=None, default=datetime.datetime.now) |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
1060 |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
1061 user = relationship('User', primaryjoin='User.user_id==UserFollowing.user_id') |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
1062 |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
1063 follows_user = relationship('User', primaryjoin='User.user_id==UserFollowing.follows_user_id') |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
1064 follows_repository = relationship('Repository', order_by='Repository.repo_name') |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
1065 |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
1066 @classmethod |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
1067 def get_repo_followers(cls, repo_id): |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
1068 return cls.query().filter(cls.follows_repo_id == repo_id) |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
1069 |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
1070 |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
1071 class CacheInvalidation(Base, BaseModel): |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
1072 __tablename__ = 'cache_invalidation' |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
1073 __table_args__ = ( |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
1074 UniqueConstraint('cache_key'), |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
1075 {'extend_existing': True, 'mysql_engine':'InnoDB', |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
1076 'mysql_charset': 'utf8'}, |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
1077 ) |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
1078 cache_id = Column("cache_id", Integer(), nullable=False, unique=True, default=None, primary_key=True) |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
1079 cache_key = Column("cache_key", String(length=255, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None) |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
1080 cache_args = Column("cache_args", String(length=255, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None) |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
1081 cache_active = Column("cache_active", Boolean(), nullable=True, unique=None, default=False) |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
1082 |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
1083 def __init__(self, cache_key, cache_args=''): |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
1084 self.cache_key = cache_key |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
1085 self.cache_args = cache_args |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
1086 self.cache_active = False |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
1087 |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
1088 def __unicode__(self): |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
1089 return u"<%s('%s:%s')>" % (self.__class__.__name__, |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
1090 self.cache_id, self.cache_key) |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
1091 @classmethod |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
1092 def clear_cache(cls): |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
1093 cls.query().delete() |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
1094 |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
1095 @classmethod |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
1096 def _get_key(cls, key): |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
1097 """ |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
1098 Wrapper for generating a key, together with a prefix |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
1099 |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
1100 :param key: |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
1101 """ |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
1102 import rhodecode |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
1103 prefix = '' |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
1104 iid = rhodecode.CONFIG.get('instance_id') |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
1105 if iid: |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
1106 prefix = iid |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
1107 return "%s%s" % (prefix, key), prefix, key.rstrip('_README') |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
1108 |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
1109 @classmethod |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
1110 def get_by_key(cls, key): |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
1111 return cls.query().filter(cls.cache_key == key).scalar() |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
1112 |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
1113 @classmethod |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
1114 def _get_or_create_key(cls, key, prefix, org_key): |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
1115 inv_obj = Session.query(cls).filter(cls.cache_key == key).scalar() |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
1116 if not inv_obj: |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
1117 try: |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
1118 inv_obj = CacheInvalidation(key, org_key) |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
1119 Session.add(inv_obj) |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
1120 Session.commit() |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
1121 except Exception: |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
1122 log.error(traceback.format_exc()) |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
1123 Session.rollback() |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
1124 return inv_obj |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
1125 |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
1126 @classmethod |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
1127 def invalidate(cls, key): |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
1128 """ |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
1129 Returns Invalidation object if this given key should be invalidated |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
1130 None otherwise. `cache_active = False` means that this cache |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
1131 state is not valid and needs to be invalidated |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
1132 |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
1133 :param key: |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
1134 """ |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
1135 |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
1136 key, _prefix, _org_key = cls._get_key(key) |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
1137 inv = cls._get_or_create_key(key, _prefix, _org_key) |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
1138 |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
1139 if inv and inv.cache_active is False: |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
1140 return inv |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
1141 |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
1142 @classmethod |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
1143 def set_invalidate(cls, key): |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
1144 """ |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
1145 Mark this Cache key for invalidation |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
1146 |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
1147 :param key: |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
1148 """ |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
1149 |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
1150 key, _prefix, _org_key = cls._get_key(key) |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
1151 inv_objs = Session.query(cls).filter(cls.cache_args == _org_key).all() |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
1152 log.debug('marking %s key[s] %s for invalidation' % (len(inv_objs), |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
1153 _org_key)) |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
1154 try: |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
1155 for inv_obj in inv_objs: |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
1156 if inv_obj: |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
1157 inv_obj.cache_active = False |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
1158 |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
1159 Session.add(inv_obj) |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
1160 Session.commit() |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
1161 except Exception: |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
1162 log.error(traceback.format_exc()) |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
1163 Session.rollback() |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
1164 |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
1165 @classmethod |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
1166 def set_valid(cls, key): |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
1167 """ |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
1168 Mark this cache key as active and currently cached |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
1169 |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
1170 :param key: |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
1171 """ |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
1172 inv_obj = cls.get_by_key(key) |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
1173 inv_obj.cache_active = True |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
1174 Session.add(inv_obj) |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
1175 Session.commit() |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
1176 |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
1177 |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
1178 class ChangesetComment(Base, BaseModel): |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
1179 __tablename__ = 'changeset_comments' |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
1180 __table_args__ = ( |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
1181 {'extend_existing': True, 'mysql_engine':'InnoDB', |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
1182 'mysql_charset': 'utf8'}, |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
1183 ) |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
1184 comment_id = Column('comment_id', Integer(), nullable=False, primary_key=True) |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
1185 repo_id = Column('repo_id', Integer(), ForeignKey('repositories.repo_id'), nullable=False) |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
1186 revision = Column('revision', String(40), nullable=False) |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
1187 line_no = Column('line_no', Unicode(10), nullable=True) |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
1188 f_path = Column('f_path', Unicode(1000), nullable=True) |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
1189 user_id = Column('user_id', Integer(), ForeignKey('users.user_id'), nullable=False) |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
1190 text = Column('text', Unicode(25000), nullable=False) |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
1191 modified_at = Column('modified_at', DateTime(), nullable=False, default=datetime.datetime.now) |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
1192 |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
1193 author = relationship('User', lazy='joined') |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
1194 repo = relationship('Repository') |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
1195 |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
1196 @classmethod |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
1197 def get_users(cls, revision): |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
1198 """ |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
1199 Returns user associated with this changesetComment. ie those |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
1200 who actually commented |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
1201 |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
1202 :param cls: |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
1203 :param revision: |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
1204 """ |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
1205 return Session.query(User)\ |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
1206 .filter(cls.revision == revision)\ |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
1207 .join(ChangesetComment.author).all() |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
1208 |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
1209 |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
1210 class Notification(Base, BaseModel): |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
1211 __tablename__ = 'notifications' |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
1212 __table_args__ = ( |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
1213 {'extend_existing': True, 'mysql_engine':'InnoDB', |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
1214 'mysql_charset': 'utf8'}, |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
1215 ) |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
1216 |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
1217 TYPE_CHANGESET_COMMENT = u'cs_comment' |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
1218 TYPE_MESSAGE = u'message' |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
1219 TYPE_MENTION = u'mention' |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
1220 TYPE_REGISTRATION = u'registration' |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
1221 |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
1222 notification_id = Column('notification_id', Integer(), nullable=False, primary_key=True) |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
1223 subject = Column('subject', Unicode(512), nullable=True) |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
1224 body = Column('body', Unicode(50000), nullable=True) |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
1225 created_by = Column("created_by", Integer(), ForeignKey('users.user_id'), nullable=True) |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
1226 created_on = Column('created_on', DateTime(timezone=False), nullable=False, default=datetime.datetime.now) |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
1227 type_ = Column('type', Unicode(256)) |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
1228 |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
1229 created_by_user = relationship('User') |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
1230 notifications_to_users = relationship('UserNotification', lazy='joined', |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
1231 cascade="all, delete, delete-orphan") |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
1232 |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
1233 @property |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
1234 def recipients(self): |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
1235 return [x.user for x in UserNotification.query()\ |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
1236 .filter(UserNotification.notification == self).all()] |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
1237 |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
1238 @classmethod |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
1239 def create(cls, created_by, subject, body, recipients, type_=None): |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
1240 if type_ is None: |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
1241 type_ = Notification.TYPE_MESSAGE |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
1242 |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
1243 notification = cls() |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
1244 notification.created_by_user = created_by |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
1245 notification.subject = subject |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
1246 notification.body = body |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
1247 notification.type_ = type_ |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
1248 notification.created_on = datetime.datetime.now() |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
1249 |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
1250 for u in recipients: |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
1251 assoc = UserNotification() |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
1252 assoc.notification = notification |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
1253 u.notifications.append(assoc) |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
1254 Session.add(notification) |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
1255 return notification |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
1256 |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
1257 @property |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
1258 def description(self): |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
1259 from rhodecode.model.notification import NotificationModel |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
1260 return NotificationModel().make_description(self) |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
1261 |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
1262 |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
1263 class UserNotification(Base, BaseModel): |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
1264 __tablename__ = 'user_to_notification' |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
1265 __table_args__ = ( |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
1266 UniqueConstraint('user_id', 'notification_id'), |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
1267 {'extend_existing': True, 'mysql_engine':'InnoDB', |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
1268 'mysql_charset': 'utf8'} |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
1269 ) |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
1270 user_id = Column('user_id', Integer(), ForeignKey('users.user_id'), primary_key=True) |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
1271 notification_id = Column("notification_id", Integer(), ForeignKey('notifications.notification_id'), primary_key=True) |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
1272 read = Column('read', Boolean, default=False) |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
1273 sent_on = Column('sent_on', DateTime(timezone=False), nullable=True, unique=None) |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
1274 |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
1275 user = relationship('User', lazy="joined") |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
1276 notification = relationship('Notification', lazy="joined", |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
1277 order_by=lambda: Notification.created_on.desc(),) |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
1278 |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
1279 def mark_as_read(self): |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
1280 self.read = True |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
1281 Session.add(self) |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
1282 |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
1283 |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
1284 class DbMigrateVersion(Base, BaseModel): |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
1285 __tablename__ = 'db_migrate_version' |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
1286 __table_args__ = ( |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
1287 {'extend_existing': True, 'mysql_engine':'InnoDB', |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
1288 'mysql_charset': 'utf8'}, |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
1289 ) |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
1290 repository_id = Column('repository_id', String(250), primary_key=True) |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
1291 repository_path = Column('repository_path', Text) |
2fd474e63177
Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
1292 version = Column('version', Integer) |
2765
186b1cf7f759
Step6a for migrations from 1.3.6
Marcin Kuzminski <marcin@python-works.com>
parents:
2214
diff
changeset
|
1293 |
186b1cf7f759
Step6a for migrations from 1.3.6
Marcin Kuzminski <marcin@python-works.com>
parents:
2214
diff
changeset
|
1294 ## this is migration from 1_4_0, but now it's here to overcome a problem of |
186b1cf7f759
Step6a for migrations from 1.3.6
Marcin Kuzminski <marcin@python-works.com>
parents:
2214
diff
changeset
|
1295 ## attaching a FK to this from 1_3_0 ! |
186b1cf7f759
Step6a for migrations from 1.3.6
Marcin Kuzminski <marcin@python-works.com>
parents:
2214
diff
changeset
|
1296 |
186b1cf7f759
Step6a for migrations from 1.3.6
Marcin Kuzminski <marcin@python-works.com>
parents:
2214
diff
changeset
|
1297 |
186b1cf7f759
Step6a for migrations from 1.3.6
Marcin Kuzminski <marcin@python-works.com>
parents:
2214
diff
changeset
|
1298 class PullRequest(Base, BaseModel): |
186b1cf7f759
Step6a for migrations from 1.3.6
Marcin Kuzminski <marcin@python-works.com>
parents:
2214
diff
changeset
|
1299 __tablename__ = 'pull_requests' |
186b1cf7f759
Step6a for migrations from 1.3.6
Marcin Kuzminski <marcin@python-works.com>
parents:
2214
diff
changeset
|
1300 __table_args__ = ( |
186b1cf7f759
Step6a for migrations from 1.3.6
Marcin Kuzminski <marcin@python-works.com>
parents:
2214
diff
changeset
|
1301 {'extend_existing': True, 'mysql_engine': 'InnoDB', |
186b1cf7f759
Step6a for migrations from 1.3.6
Marcin Kuzminski <marcin@python-works.com>
parents:
2214
diff
changeset
|
1302 'mysql_charset': 'utf8'}, |
186b1cf7f759
Step6a for migrations from 1.3.6
Marcin Kuzminski <marcin@python-works.com>
parents:
2214
diff
changeset
|
1303 ) |
186b1cf7f759
Step6a for migrations from 1.3.6
Marcin Kuzminski <marcin@python-works.com>
parents:
2214
diff
changeset
|
1304 |
186b1cf7f759
Step6a for migrations from 1.3.6
Marcin Kuzminski <marcin@python-works.com>
parents:
2214
diff
changeset
|
1305 STATUS_NEW = u'new' |
186b1cf7f759
Step6a for migrations from 1.3.6
Marcin Kuzminski <marcin@python-works.com>
parents:
2214
diff
changeset
|
1306 STATUS_OPEN = u'open' |
186b1cf7f759
Step6a for migrations from 1.3.6
Marcin Kuzminski <marcin@python-works.com>
parents:
2214
diff
changeset
|
1307 STATUS_CLOSED = u'closed' |
186b1cf7f759
Step6a for migrations from 1.3.6
Marcin Kuzminski <marcin@python-works.com>
parents:
2214
diff
changeset
|
1308 |
186b1cf7f759
Step6a for migrations from 1.3.6
Marcin Kuzminski <marcin@python-works.com>
parents:
2214
diff
changeset
|
1309 pull_request_id = Column('pull_request_id', Integer(), nullable=False, primary_key=True) |
186b1cf7f759
Step6a for migrations from 1.3.6
Marcin Kuzminski <marcin@python-works.com>
parents:
2214
diff
changeset
|
1310 title = Column('title', Unicode(256), nullable=True) |
186b1cf7f759
Step6a for migrations from 1.3.6
Marcin Kuzminski <marcin@python-works.com>
parents:
2214
diff
changeset
|
1311 description = Column('description', UnicodeText(10240), nullable=True) |
186b1cf7f759
Step6a for migrations from 1.3.6
Marcin Kuzminski <marcin@python-works.com>
parents:
2214
diff
changeset
|
1312 status = Column('status', Unicode(256), nullable=False, default=STATUS_NEW) |
186b1cf7f759
Step6a for migrations from 1.3.6
Marcin Kuzminski <marcin@python-works.com>
parents:
2214
diff
changeset
|
1313 created_on = Column('created_on', DateTime(timezone=False), nullable=False, default=datetime.datetime.now) |
186b1cf7f759
Step6a for migrations from 1.3.6
Marcin Kuzminski <marcin@python-works.com>
parents:
2214
diff
changeset
|
1314 updated_on = Column('updated_on', DateTime(timezone=False), nullable=False, default=datetime.datetime.now) |
186b1cf7f759
Step6a for migrations from 1.3.6
Marcin Kuzminski <marcin@python-works.com>
parents:
2214
diff
changeset
|
1315 user_id = Column("user_id", Integer(), ForeignKey('users.user_id'), nullable=False, unique=None) |
186b1cf7f759
Step6a for migrations from 1.3.6
Marcin Kuzminski <marcin@python-works.com>
parents:
2214
diff
changeset
|
1316 _revisions = Column('revisions', UnicodeText(20500)) # 500 revisions max |
186b1cf7f759
Step6a for migrations from 1.3.6
Marcin Kuzminski <marcin@python-works.com>
parents:
2214
diff
changeset
|
1317 org_repo_id = Column('org_repo_id', Integer(), ForeignKey('repositories.repo_id'), nullable=False) |
186b1cf7f759
Step6a for migrations from 1.3.6
Marcin Kuzminski <marcin@python-works.com>
parents:
2214
diff
changeset
|
1318 org_ref = Column('org_ref', Unicode(256), nullable=False) |
186b1cf7f759
Step6a for migrations from 1.3.6
Marcin Kuzminski <marcin@python-works.com>
parents:
2214
diff
changeset
|
1319 other_repo_id = Column('other_repo_id', Integer(), ForeignKey('repositories.repo_id'), nullable=False) |
2815
acc05c33cc0c
White space cleanup
Marcin Kuzminski <marcin@python-works.com>
parents:
2765
diff
changeset
|
1320 other_ref = Column('other_ref', Unicode(256), nullable=False) |