Mercurial > kallithea
annotate rhodecode/model/db.py @ 3416:5706f6ab60cf beta
follow-up on texts missing from 'users groups'/'repositories group' cleanup
author | Mads Kiilerich <madski@unity3d.com> |
---|---|
date | Wed, 27 Feb 2013 17:18:41 +0100 |
parents | fdb0f59b2189 |
children | fa6ba6727475 |
rev | line source |
---|---|
759
a7f50911a945
Models code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
734
diff
changeset
|
1 # -*- coding: utf-8 -*- |
a7f50911a945
Models code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
734
diff
changeset
|
2 """ |
832
634596f81cfd
new improved models with helper functions for easier data fetching
Marcin Kuzminski <marcin@python-works.com>
parents:
810
diff
changeset
|
3 rhodecode.model.db |
634596f81cfd
new improved models with helper functions for easier data fetching
Marcin Kuzminski <marcin@python-works.com>
parents:
810
diff
changeset
|
4 ~~~~~~~~~~~~~~~~~~ |
1203
6832ef664673
source code cleanup: remove trailing white space, normalize file endings
Marcin Kuzminski <marcin@python-works.com>
parents:
1199
diff
changeset
|
5 |
834
8924ed0e4f36
added current db version into rhodecode,
Marcin Kuzminski <marcin@python-works.com>
parents:
832
diff
changeset
|
6 Database Models for RhodeCode |
1203
6832ef664673
source code cleanup: remove trailing white space, normalize file endings
Marcin Kuzminski <marcin@python-works.com>
parents:
1199
diff
changeset
|
7 |
759
a7f50911a945
Models code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
734
diff
changeset
|
8 :created_on: Apr 08, 2010 |
a7f50911a945
Models code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
734
diff
changeset
|
9 :author: marcink |
1824
89efedac4e6c
2012 copyrights
Marcin Kuzminski <marcin@python-works.com>
parents:
1819
diff
changeset
|
10 :copyright: (C) 2010-2012 Marcin Kuzminski <marcin@python-works.com> |
759
a7f50911a945
Models code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
734
diff
changeset
|
11 :license: GPLv3, see COPYING for more details. |
a7f50911a945
Models code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
734
diff
changeset
|
12 """ |
1206
a671db5bdd58
fixed license issue #149
Marcin Kuzminski <marcin@python-works.com>
parents:
1203
diff
changeset
|
13 # This program is free software: you can redistribute it and/or modify |
a671db5bdd58
fixed license issue #149
Marcin Kuzminski <marcin@python-works.com>
parents:
1203
diff
changeset
|
14 # it under the terms of the GNU General Public License as published by |
a671db5bdd58
fixed license issue #149
Marcin Kuzminski <marcin@python-works.com>
parents:
1203
diff
changeset
|
15 # the Free Software Foundation, either version 3 of the License, or |
a671db5bdd58
fixed license issue #149
Marcin Kuzminski <marcin@python-works.com>
parents:
1203
diff
changeset
|
16 # (at your option) any later version. |
1203
6832ef664673
source code cleanup: remove trailing white space, normalize file endings
Marcin Kuzminski <marcin@python-works.com>
parents:
1199
diff
changeset
|
17 # |
759
a7f50911a945
Models code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
734
diff
changeset
|
18 # This program is distributed in the hope that it will be useful, |
a7f50911a945
Models code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
734
diff
changeset
|
19 # but WITHOUT ANY WARRANTY; without even the implied warranty of |
a7f50911a945
Models code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
734
diff
changeset
|
20 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
a7f50911a945
Models code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
734
diff
changeset
|
21 # GNU General Public License for more details. |
1203
6832ef664673
source code cleanup: remove trailing white space, normalize file endings
Marcin Kuzminski <marcin@python-works.com>
parents:
1199
diff
changeset
|
22 # |
759
a7f50911a945
Models code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
734
diff
changeset
|
23 # You should have received a copy of the GNU General Public License |
1206
a671db5bdd58
fixed license issue #149
Marcin Kuzminski <marcin@python-works.com>
parents:
1203
diff
changeset
|
24 # along with this program. If not, see <http://www.gnu.org/licenses/>. |
1199
268fa0b6b2ef
Added os.sep in models for better win support
Marcin Kuzminski <marcin@python-works.com>
parents:
1193
diff
changeset
|
25 |
268fa0b6b2ef
Added os.sep in models for better win support
Marcin Kuzminski <marcin@python-works.com>
parents:
1193
diff
changeset
|
26 import os |
759
a7f50911a945
Models code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
734
diff
changeset
|
27 import logging |
a7f50911a945
Models code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
734
diff
changeset
|
28 import datetime |
1366
9c0f5d558789
fixes #200, rewrote the whole caching mechanism to get rid of such problems. Now cached instances are attached
Marcin Kuzminski <marcin@python-works.com>
parents:
1360
diff
changeset
|
29 import traceback |
2356
2da7b5984ae5
typo fix + code garden
Marcin Kuzminski <marcin@python-works.com>
parents:
2352
diff
changeset
|
30 import hashlib |
2726
aa17c7a1b8a5
Implemented basic locking functionality.
Marcin Kuzminski <marcin@python-works.com>
parents:
2724
diff
changeset
|
31 import time |
1884
0614862a20ec
Added number of comments in changelog for each changeset
Marcin Kuzminski <marcin@python-works.com>
parents:
1824
diff
changeset
|
32 from collections import defaultdict |
759
a7f50911a945
Models code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
734
diff
changeset
|
33 |
658 | 34 from sqlalchemy import * |
1546
c363267bbec7
fixes #265 ldap save fails sometimes on converting attributes to booleans, added getter and setter
Marcin Kuzminski <marcin@python-works.com>
parents:
1539
diff
changeset
|
35 from sqlalchemy.ext.hybrid import hybrid_property |
1594 | 36 from sqlalchemy.orm import relationship, joinedload, class_mapper, validates |
2357 | 37 from sqlalchemy.exc import DatabaseError |
1366
9c0f5d558789
fixes #200, rewrote the whole caching mechanism to get rid of such problems. Now cached instances are attached
Marcin Kuzminski <marcin@python-works.com>
parents:
1360
diff
changeset
|
38 from beaker.cache import cache_region, region_invalidate |
2496
fddd8e3fc157
use get_or_404 where possible
Marcin Kuzminski <marcin@python-works.com>
parents:
2481
diff
changeset
|
39 from webob.exc import HTTPNotFound |
1366
9c0f5d558789
fixes #200, rewrote the whole caching mechanism to get rid of such problems. Now cached instances are attached
Marcin Kuzminski <marcin@python-works.com>
parents:
1360
diff
changeset
|
40 |
2218
6e5d686084f1
fixed translation function for models
Marcin Kuzminski <marcin@python-works.com>
parents:
2217
diff
changeset
|
41 from pylons.i18n.translation import lazy_ugettext as _ |
2215
2c2bdaeca912
code-review initial
Marcin Kuzminski <marcin@python-works.com>
parents:
2161
diff
changeset
|
42 |
2007
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
43 from rhodecode.lib.vcs import get_backend |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
44 from rhodecode.lib.vcs.utils.helpers import get_scm |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
45 from rhodecode.lib.vcs.exceptions import VCSError |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
2000
diff
changeset
|
46 from rhodecode.lib.vcs.utils.lazy import LazyProperty |
1366
9c0f5d558789
fixes #200, rewrote the whole caching mechanism to get rid of such problems. Now cached instances are attached
Marcin Kuzminski <marcin@python-works.com>
parents:
1360
diff
changeset
|
47 |
2109 | 48 from rhodecode.lib.utils2 import str2bool, safe_str, get_changeset_safe, \ |
3056
6104dfd35b16
Implemented #379 defaults settings page for creation of repositories
Marcin Kuzminski <marcin@python-works.com>
parents:
3052
diff
changeset
|
49 safe_unicode, remove_suffix, remove_prefix |
1514
87ec80c280bb
fixed issues with python2.5
Marcin Kuzminski <marcin@python-works.com>
parents:
1508
diff
changeset
|
50 from rhodecode.lib.compat import json |
1669
f522f4d3bf93
moved caching query to libs
Marcin Kuzminski <marcin@python-works.com>
parents:
1665
diff
changeset
|
51 from rhodecode.lib.caching_query import FromCache |
1500 | 52 |
2356
2da7b5984ae5
typo fix + code garden
Marcin Kuzminski <marcin@python-works.com>
parents:
2352
diff
changeset
|
53 from rhodecode.model.meta import Base, Session |
1500 | 54 |
2339
79b3c9c66c54
Added optional repo_name into issue tracker url to get just the name of repo without group prefix
Marcin Kuzminski <marcin@python-works.com>
parents:
2251
diff
changeset
|
55 URL_SEP = '/' |
1593 | 56 log = logging.getLogger(__name__) |
49
3ada2f409c1c
Added sqlalchemy support
Marcin Kuzminski <marcin@python-blog.com>
parents:
diff
changeset
|
57 |
1081
70bf0be59653
fixed Session problems in model class functions
Marcin Kuzminski <marcin@python-works.com>
parents:
1065
diff
changeset
|
58 #============================================================================== |
1388
2029c17cc6c6
Added basic JsonSerialization into models.
Marcin Kuzminski <marcin@python-works.com>
parents:
1385
diff
changeset
|
59 # BASE CLASSES |
1081
70bf0be59653
fixed Session problems in model class functions
Marcin Kuzminski <marcin@python-works.com>
parents:
1065
diff
changeset
|
60 #============================================================================== |
70bf0be59653
fixed Session problems in model class functions
Marcin Kuzminski <marcin@python-works.com>
parents:
1065
diff
changeset
|
61 |
2062
bf8ed0adbc66
fixes #371 fixed issues with beaker/sqlalchemy and non-ascii cache keys
Marcin Kuzminski <marcin@python-works.com>
parents:
2058
diff
changeset
|
62 _hash_key = lambda k: hashlib.md5(safe_str(k)).hexdigest() |
bf8ed0adbc66
fixes #371 fixed issues with beaker/sqlalchemy and non-ascii cache keys
Marcin Kuzminski <marcin@python-works.com>
parents:
2058
diff
changeset
|
63 |
1800 | 64 |
1593 | 65 class BaseModel(object): |
1758
a87aa385f21c
fixed repo_create permission by adding missing commit statements
Marcin Kuzminski <marcin@python-works.com>
parents:
1757
diff
changeset
|
66 """ |
a87aa385f21c
fixed repo_create permission by adding missing commit statements
Marcin Kuzminski <marcin@python-works.com>
parents:
1757
diff
changeset
|
67 Base Model for all classess |
1388
2029c17cc6c6
Added basic JsonSerialization into models.
Marcin Kuzminski <marcin@python-works.com>
parents:
1385
diff
changeset
|
68 """ |
2029c17cc6c6
Added basic JsonSerialization into models.
Marcin Kuzminski <marcin@python-works.com>
parents:
1385
diff
changeset
|
69 |
2029c17cc6c6
Added basic JsonSerialization into models.
Marcin Kuzminski <marcin@python-works.com>
parents:
1385
diff
changeset
|
70 @classmethod |
1593 | 71 def _get_keys(cls): |
1388
2029c17cc6c6
Added basic JsonSerialization into models.
Marcin Kuzminski <marcin@python-works.com>
parents:
1385
diff
changeset
|
72 """return column names for this model """ |
1593 | 73 return class_mapper(cls).c.keys() |
1388
2029c17cc6c6
Added basic JsonSerialization into models.
Marcin Kuzminski <marcin@python-works.com>
parents:
1385
diff
changeset
|
74 |
1948
4582e6b9e2f6
get_dict function garden
Marcin Kuzminski <marcin@python-works.com>
parents:
1886
diff
changeset
|
75 def get_dict(self): |
1758
a87aa385f21c
fixed repo_create permission by adding missing commit statements
Marcin Kuzminski <marcin@python-works.com>
parents:
1757
diff
changeset
|
76 """ |
a87aa385f21c
fixed repo_create permission by adding missing commit statements
Marcin Kuzminski <marcin@python-works.com>
parents:
1757
diff
changeset
|
77 return dict with keys and values corresponding |
1948
4582e6b9e2f6
get_dict function garden
Marcin Kuzminski <marcin@python-works.com>
parents:
1886
diff
changeset
|
78 to this model data """ |
1388
2029c17cc6c6
Added basic JsonSerialization into models.
Marcin Kuzminski <marcin@python-works.com>
parents:
1385
diff
changeset
|
79 |
2029c17cc6c6
Added basic JsonSerialization into models.
Marcin Kuzminski <marcin@python-works.com>
parents:
1385
diff
changeset
|
80 d = {} |
2029c17cc6c6
Added basic JsonSerialization into models.
Marcin Kuzminski <marcin@python-works.com>
parents:
1385
diff
changeset
|
81 for k in self._get_keys(): |
1593 | 82 d[k] = getattr(self, k) |
1800 | 83 |
1758
a87aa385f21c
fixed repo_create permission by adding missing commit statements
Marcin Kuzminski <marcin@python-works.com>
parents:
1757
diff
changeset
|
84 # also use __json__() if present to get additional fields |
2588
32dd6896abcf
added status column to pull request + some small refactoring of models
Marcin Kuzminski <marcin@python-works.com>
parents:
2585
diff
changeset
|
85 _json_attr = getattr(self, '__json__', None) |
32dd6896abcf
added status column to pull request + some small refactoring of models
Marcin Kuzminski <marcin@python-works.com>
parents:
2585
diff
changeset
|
86 if _json_attr: |
32dd6896abcf
added status column to pull request + some small refactoring of models
Marcin Kuzminski <marcin@python-works.com>
parents:
2585
diff
changeset
|
87 # update with attributes from __json__ |
32dd6896abcf
added status column to pull request + some small refactoring of models
Marcin Kuzminski <marcin@python-works.com>
parents:
2585
diff
changeset
|
88 if callable(_json_attr): |
32dd6896abcf
added status column to pull request + some small refactoring of models
Marcin Kuzminski <marcin@python-works.com>
parents:
2585
diff
changeset
|
89 _json_attr = _json_attr() |
32dd6896abcf
added status column to pull request + some small refactoring of models
Marcin Kuzminski <marcin@python-works.com>
parents:
2585
diff
changeset
|
90 for k, val in _json_attr.iteritems(): |
32dd6896abcf
added status column to pull request + some small refactoring of models
Marcin Kuzminski <marcin@python-works.com>
parents:
2585
diff
changeset
|
91 d[k] = val |
1388
2029c17cc6c6
Added basic JsonSerialization into models.
Marcin Kuzminski <marcin@python-works.com>
parents:
1385
diff
changeset
|
92 return d |
2029c17cc6c6
Added basic JsonSerialization into models.
Marcin Kuzminski <marcin@python-works.com>
parents:
1385
diff
changeset
|
93 |
1593 | 94 def get_appstruct(self): |
1388
2029c17cc6c6
Added basic JsonSerialization into models.
Marcin Kuzminski <marcin@python-works.com>
parents:
1385
diff
changeset
|
95 """return list with keys and values tupples corresponding |
2029c17cc6c6
Added basic JsonSerialization into models.
Marcin Kuzminski <marcin@python-works.com>
parents:
1385
diff
changeset
|
96 to this model data """ |
2029c17cc6c6
Added basic JsonSerialization into models.
Marcin Kuzminski <marcin@python-works.com>
parents:
1385
diff
changeset
|
97 |
2029c17cc6c6
Added basic JsonSerialization into models.
Marcin Kuzminski <marcin@python-works.com>
parents:
1385
diff
changeset
|
98 l = [] |
2029c17cc6c6
Added basic JsonSerialization into models.
Marcin Kuzminski <marcin@python-works.com>
parents:
1385
diff
changeset
|
99 for k in self._get_keys(): |
1593 | 100 l.append((k, getattr(self, k),)) |
1388
2029c17cc6c6
Added basic JsonSerialization into models.
Marcin Kuzminski <marcin@python-works.com>
parents:
1385
diff
changeset
|
101 return l |
2029c17cc6c6
Added basic JsonSerialization into models.
Marcin Kuzminski <marcin@python-works.com>
parents:
1385
diff
changeset
|
102 |
1593 | 103 def populate_obj(self, populate_dict): |
1388
2029c17cc6c6
Added basic JsonSerialization into models.
Marcin Kuzminski <marcin@python-works.com>
parents:
1385
diff
changeset
|
104 """populate model with data from given populate_dict""" |
2029c17cc6c6
Added basic JsonSerialization into models.
Marcin Kuzminski <marcin@python-works.com>
parents:
1385
diff
changeset
|
105 |
2029c17cc6c6
Added basic JsonSerialization into models.
Marcin Kuzminski <marcin@python-works.com>
parents:
1385
diff
changeset
|
106 for k in self._get_keys(): |
2029c17cc6c6
Added basic JsonSerialization into models.
Marcin Kuzminski <marcin@python-works.com>
parents:
1385
diff
changeset
|
107 if k in populate_dict: |
1593 | 108 setattr(self, k, populate_dict[k]) |
1388
2029c17cc6c6
Added basic JsonSerialization into models.
Marcin Kuzminski <marcin@python-works.com>
parents:
1385
diff
changeset
|
109 |
2029c17cc6c6
Added basic JsonSerialization into models.
Marcin Kuzminski <marcin@python-works.com>
parents:
1385
diff
changeset
|
110 @classmethod |
1593 | 111 def query(cls): |
2520
a1e156503afe
Fixed calls to Session in db model
Marcin Kuzminski <marcin@python-works.com>
parents:
2510
diff
changeset
|
112 return Session().query(cls) |
1388
2029c17cc6c6
Added basic JsonSerialization into models.
Marcin Kuzminski <marcin@python-works.com>
parents:
1385
diff
changeset
|
113 |
2029c17cc6c6
Added basic JsonSerialization into models.
Marcin Kuzminski <marcin@python-works.com>
parents:
1385
diff
changeset
|
114 @classmethod |
1593 | 115 def get(cls, id_): |
1594 | 116 if id_: |
117 return cls.query().get(id_) | |
1466 | 118 |
1460
b50348816a80
Added more advanced hook management into rhodecode admin settings
Marcin Kuzminski <marcin@python-works.com>
parents:
1436
diff
changeset
|
119 @classmethod |
2496
fddd8e3fc157
use get_or_404 where possible
Marcin Kuzminski <marcin@python-works.com>
parents:
2481
diff
changeset
|
120 def get_or_404(cls, id_): |
2942
f53faff4487e
get_or_404 method does validation for ID beeing an INT
Marcin Kuzminski <marcin@python-works.com>
parents:
2937
diff
changeset
|
121 try: |
f53faff4487e
get_or_404 method does validation for ID beeing an INT
Marcin Kuzminski <marcin@python-works.com>
parents:
2937
diff
changeset
|
122 id_ = int(id_) |
f53faff4487e
get_or_404 method does validation for ID beeing an INT
Marcin Kuzminski <marcin@python-works.com>
parents:
2937
diff
changeset
|
123 except (TypeError, ValueError): |
f53faff4487e
get_or_404 method does validation for ID beeing an INT
Marcin Kuzminski <marcin@python-works.com>
parents:
2937
diff
changeset
|
124 raise HTTPNotFound |
f53faff4487e
get_or_404 method does validation for ID beeing an INT
Marcin Kuzminski <marcin@python-works.com>
parents:
2937
diff
changeset
|
125 |
f53faff4487e
get_or_404 method does validation for ID beeing an INT
Marcin Kuzminski <marcin@python-works.com>
parents:
2937
diff
changeset
|
126 res = cls.query().get(id_) |
f53faff4487e
get_or_404 method does validation for ID beeing an INT
Marcin Kuzminski <marcin@python-works.com>
parents:
2937
diff
changeset
|
127 if not res: |
f53faff4487e
get_or_404 method does validation for ID beeing an INT
Marcin Kuzminski <marcin@python-works.com>
parents:
2937
diff
changeset
|
128 raise HTTPNotFound |
f53faff4487e
get_or_404 method does validation for ID beeing an INT
Marcin Kuzminski <marcin@python-works.com>
parents:
2937
diff
changeset
|
129 return res |
2496
fddd8e3fc157
use get_or_404 where possible
Marcin Kuzminski <marcin@python-works.com>
parents:
2481
diff
changeset
|
130 |
fddd8e3fc157
use get_or_404 where possible
Marcin Kuzminski <marcin@python-works.com>
parents:
2481
diff
changeset
|
131 @classmethod |
1593 | 132 def getAll(cls): |
1584
3338a0994472
Improve API with user/group/repo CRUD methods
Nicolas VINOT <aeris@imirhil.fr>
parents:
1508
diff
changeset
|
133 return cls.query().all() |
1466 | 134 |
1460
b50348816a80
Added more advanced hook management into rhodecode admin settings
Marcin Kuzminski <marcin@python-works.com>
parents:
1436
diff
changeset
|
135 @classmethod |
1593 | 136 def delete(cls, id_): |
137 obj = cls.query().get(id_) | |
2520
a1e156503afe
Fixed calls to Session in db model
Marcin Kuzminski <marcin@python-works.com>
parents:
2510
diff
changeset
|
138 Session().delete(obj) |
2161
e8c016815ab9
added hidden fulldiff GET param for disabling big diff cut off limit.
Marcin Kuzminski <marcin@python-works.com>
parents:
2157
diff
changeset
|
139 |
2156
a27e4d44237e
Use __unicode__ instead of __repr__ in models.
Marcin Kuzminski <marcin@python-works.com>
parents:
2152
diff
changeset
|
140 def __repr__(self): |
a27e4d44237e
Use __unicode__ instead of __repr__ in models.
Marcin Kuzminski <marcin@python-works.com>
parents:
2152
diff
changeset
|
141 if hasattr(self, '__unicode__'): |
a27e4d44237e
Use __unicode__ instead of __repr__ in models.
Marcin Kuzminski <marcin@python-works.com>
parents:
2152
diff
changeset
|
142 # python repr needs to return str |
a27e4d44237e
Use __unicode__ instead of __repr__ in models.
Marcin Kuzminski <marcin@python-works.com>
parents:
2152
diff
changeset
|
143 return safe_str(self.__unicode__()) |
a27e4d44237e
Use __unicode__ instead of __repr__ in models.
Marcin Kuzminski <marcin@python-works.com>
parents:
2152
diff
changeset
|
144 return '<DB:%s>' % (self.__class__.__name__) |
1081
70bf0be59653
fixed Session problems in model class functions
Marcin Kuzminski <marcin@python-works.com>
parents:
1065
diff
changeset
|
145 |
2356
2da7b5984ae5
typo fix + code garden
Marcin Kuzminski <marcin@python-works.com>
parents:
2352
diff
changeset
|
146 |
1633
2c0d35e336b5
refactoring of models names for repoGroup permissions
Marcin Kuzminski <marcin@python-works.com>
parents:
1607
diff
changeset
|
147 class RhodeCodeSetting(Base, BaseModel): |
548
b75b77ef649d
renamed hg_app to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
547
diff
changeset
|
148 __tablename__ = 'rhodecode_settings' |
1958
7e4b3d3a9c5c
renamed repo groups table
Marcin Kuzminski <marcin@python-works.com>
parents:
1950
diff
changeset
|
149 __table_args__ = ( |
7e4b3d3a9c5c
renamed repo groups table
Marcin Kuzminski <marcin@python-works.com>
parents:
1950
diff
changeset
|
150 UniqueConstraint('app_settings_name'), |
2356
2da7b5984ae5
typo fix + code garden
Marcin Kuzminski <marcin@python-works.com>
parents:
2352
diff
changeset
|
151 {'extend_existing': True, 'mysql_engine': 'InnoDB', |
2149 | 152 'mysql_charset': 'utf8'} |
1958
7e4b3d3a9c5c
renamed repo groups table
Marcin Kuzminski <marcin@python-works.com>
parents:
1950
diff
changeset
|
153 ) |
1594 | 154 app_settings_id = Column("app_settings_id", Integer(), nullable=False, unique=True, default=None, primary_key=True) |
2588
32dd6896abcf
added status column to pull request + some small refactoring of models
Marcin Kuzminski <marcin@python-works.com>
parents:
2585
diff
changeset
|
155 app_settings_name = Column("app_settings_name", String(255, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None) |
32dd6896abcf
added status column to pull request + some small refactoring of models
Marcin Kuzminski <marcin@python-works.com>
parents:
2585
diff
changeset
|
156 _app_settings_value = Column("app_settings_value", String(255, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None) |
341
1ef52a70f3b7
Made config file free configuration based on database and capable of beeing manage via application settings + some code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
328
diff
changeset
|
157 |
1594 | 158 def __init__(self, k='', v=''): |
704
26237de9b613
Added settings model, and Exceptions lib.
Marcin Kuzminski <marcin@python-works.com>
parents:
692
diff
changeset
|
159 self.app_settings_name = k |
26237de9b613
Added settings model, and Exceptions lib.
Marcin Kuzminski <marcin@python-works.com>
parents:
692
diff
changeset
|
160 self.app_settings_value = v |
26237de9b613
Added settings model, and Exceptions lib.
Marcin Kuzminski <marcin@python-works.com>
parents:
692
diff
changeset
|
161 |
1593 | 162 @validates('_app_settings_value') |
163 def validate_settings_value(self, key, val): | |
164 assert type(val) == unicode | |
1561
4d841e565237
added validation of params on settings table
Marcin Kuzminski <marcin@python-works.com>
parents:
1556
diff
changeset
|
165 return val |
4d841e565237
added validation of params on settings table
Marcin Kuzminski <marcin@python-works.com>
parents:
1556
diff
changeset
|
166 |
1546
c363267bbec7
fixes #265 ldap save fails sometimes on converting attributes to booleans, added getter and setter
Marcin Kuzminski <marcin@python-works.com>
parents:
1539
diff
changeset
|
167 @hybrid_property |
1593 | 168 def app_settings_value(self): |
1546
c363267bbec7
fixes #265 ldap save fails sometimes on converting attributes to booleans, added getter and setter
Marcin Kuzminski <marcin@python-works.com>
parents:
1539
diff
changeset
|
169 v = self._app_settings_value |
3056
6104dfd35b16
Implemented #379 defaults settings page for creation of repositories
Marcin Kuzminski <marcin@python-works.com>
parents:
3052
diff
changeset
|
170 if self.app_settings_name in ["ldap_active", |
6104dfd35b16
Implemented #379 defaults settings page for creation of repositories
Marcin Kuzminski <marcin@python-works.com>
parents:
3052
diff
changeset
|
171 "default_repo_enable_statistics", |
6104dfd35b16
Implemented #379 defaults settings page for creation of repositories
Marcin Kuzminski <marcin@python-works.com>
parents:
3052
diff
changeset
|
172 "default_repo_enable_locking", |
6104dfd35b16
Implemented #379 defaults settings page for creation of repositories
Marcin Kuzminski <marcin@python-works.com>
parents:
3052
diff
changeset
|
173 "default_repo_private", |
6104dfd35b16
Implemented #379 defaults settings page for creation of repositories
Marcin Kuzminski <marcin@python-works.com>
parents:
3052
diff
changeset
|
174 "default_repo_enable_downloads"]: |
1593 | 175 v = str2bool(v) |
1591 | 176 return v |
1546
c363267bbec7
fixes #265 ldap save fails sometimes on converting attributes to booleans, added getter and setter
Marcin Kuzminski <marcin@python-works.com>
parents:
1539
diff
changeset
|
177 |
c363267bbec7
fixes #265 ldap save fails sometimes on converting attributes to booleans, added getter and setter
Marcin Kuzminski <marcin@python-works.com>
parents:
1539
diff
changeset
|
178 @app_settings_value.setter |
1593 | 179 def app_settings_value(self, val): |
1546
c363267bbec7
fixes #265 ldap save fails sometimes on converting attributes to booleans, added getter and setter
Marcin Kuzminski <marcin@python-works.com>
parents:
1539
diff
changeset
|
180 """ |
c363267bbec7
fixes #265 ldap save fails sometimes on converting attributes to booleans, added getter and setter
Marcin Kuzminski <marcin@python-works.com>
parents:
1539
diff
changeset
|
181 Setter that will always make sure we use unicode in app_settings_value |
1591 | 182 |
1546
c363267bbec7
fixes #265 ldap save fails sometimes on converting attributes to booleans, added getter and setter
Marcin Kuzminski <marcin@python-works.com>
parents:
1539
diff
changeset
|
183 :param val: |
c363267bbec7
fixes #265 ldap save fails sometimes on converting attributes to booleans, added getter and setter
Marcin Kuzminski <marcin@python-works.com>
parents:
1539
diff
changeset
|
184 """ |
1593 | 185 self._app_settings_value = safe_unicode(val) |
1546
c363267bbec7
fixes #265 ldap save fails sometimes on converting attributes to booleans, added getter and setter
Marcin Kuzminski <marcin@python-works.com>
parents:
1539
diff
changeset
|
186 |
2156
a27e4d44237e
Use __unicode__ instead of __repr__ in models.
Marcin Kuzminski <marcin@python-works.com>
parents:
2152
diff
changeset
|
187 def __unicode__(self): |
a27e4d44237e
Use __unicode__ instead of __repr__ in models.
Marcin Kuzminski <marcin@python-works.com>
parents:
2152
diff
changeset
|
188 return u"<%s('%s:%s')>" % ( |
1958
7e4b3d3a9c5c
renamed repo groups table
Marcin Kuzminski <marcin@python-works.com>
parents:
1950
diff
changeset
|
189 self.__class__.__name__, |
7e4b3d3a9c5c
renamed repo groups table
Marcin Kuzminski <marcin@python-works.com>
parents:
1950
diff
changeset
|
190 self.app_settings_name, self.app_settings_value |
7e4b3d3a9c5c
renamed repo groups table
Marcin Kuzminski <marcin@python-works.com>
parents:
1950
diff
changeset
|
191 ) |
704
26237de9b613
Added settings model, and Exceptions lib.
Marcin Kuzminski <marcin@python-works.com>
parents:
692
diff
changeset
|
192 |
1266
a1bcfe58a1ab
Fixed #161 form saves the create repository permission.
Marcin Kuzminski <marcin@python-works.com>
parents:
1206
diff
changeset
|
193 @classmethod |
2674
a221706dab50
merged + fixed pull request #62: Implemented metatags and visualisation options.
Marcin Kuzminski <marcin@python-works.com>
parents:
2668
diff
changeset
|
194 def get_by_name(cls, key): |
1584
3338a0994472
Improve API with user/group/repo CRUD methods
Nicolas VINOT <aeris@imirhil.fr>
parents:
1508
diff
changeset
|
195 return cls.query()\ |
2674
a221706dab50
merged + fixed pull request #62: Implemented metatags and visualisation options.
Marcin Kuzminski <marcin@python-works.com>
parents:
2668
diff
changeset
|
196 .filter(cls.app_settings_name == key).scalar() |
a221706dab50
merged + fixed pull request #62: Implemented metatags and visualisation options.
Marcin Kuzminski <marcin@python-works.com>
parents:
2668
diff
changeset
|
197 |
a221706dab50
merged + fixed pull request #62: Implemented metatags and visualisation options.
Marcin Kuzminski <marcin@python-works.com>
parents:
2668
diff
changeset
|
198 @classmethod |
a221706dab50
merged + fixed pull request #62: Implemented metatags and visualisation options.
Marcin Kuzminski <marcin@python-works.com>
parents:
2668
diff
changeset
|
199 def get_by_name_or_create(cls, key): |
a221706dab50
merged + fixed pull request #62: Implemented metatags and visualisation options.
Marcin Kuzminski <marcin@python-works.com>
parents:
2668
diff
changeset
|
200 res = cls.get_by_name(key) |
a221706dab50
merged + fixed pull request #62: Implemented metatags and visualisation options.
Marcin Kuzminski <marcin@python-works.com>
parents:
2668
diff
changeset
|
201 if not res: |
a221706dab50
merged + fixed pull request #62: Implemented metatags and visualisation options.
Marcin Kuzminski <marcin@python-works.com>
parents:
2668
diff
changeset
|
202 res = cls(key) |
a221706dab50
merged + fixed pull request #62: Implemented metatags and visualisation options.
Marcin Kuzminski <marcin@python-works.com>
parents:
2668
diff
changeset
|
203 return res |
1292
c0335c1dee36
added some fixes to LDAP form re-submition, new simples ldap-settings getter.
Marcin Kuzminski <marcin@python-works.com>
parents:
1279
diff
changeset
|
204 |
c0335c1dee36
added some fixes to LDAP form re-submition, new simples ldap-settings getter.
Marcin Kuzminski <marcin@python-works.com>
parents:
1279
diff
changeset
|
205 @classmethod |
1594 | 206 def get_app_settings(cls, cache=False): |
1266
a1bcfe58a1ab
Fixed #161 form saves the create repository permission.
Marcin Kuzminski <marcin@python-works.com>
parents:
1206
diff
changeset
|
207 |
1584
3338a0994472
Improve API with user/group/repo CRUD methods
Nicolas VINOT <aeris@imirhil.fr>
parents:
1508
diff
changeset
|
208 ret = cls.query() |
1266
a1bcfe58a1ab
Fixed #161 form saves the create repository permission.
Marcin Kuzminski <marcin@python-works.com>
parents:
1206
diff
changeset
|
209 |
a1bcfe58a1ab
Fixed #161 form saves the create repository permission.
Marcin Kuzminski <marcin@python-works.com>
parents:
1206
diff
changeset
|
210 if cache: |
1593 | 211 ret = ret.options(FromCache("sql_cache_short", "get_hg_settings")) |
1266
a1bcfe58a1ab
Fixed #161 form saves the create repository permission.
Marcin Kuzminski <marcin@python-works.com>
parents:
1206
diff
changeset
|
212 |
a1bcfe58a1ab
Fixed #161 form saves the create repository permission.
Marcin Kuzminski <marcin@python-works.com>
parents:
1206
diff
changeset
|
213 if not ret: |
1593 | 214 raise Exception('Could not get application settings !') |
1266
a1bcfe58a1ab
Fixed #161 form saves the create repository permission.
Marcin Kuzminski <marcin@python-works.com>
parents:
1206
diff
changeset
|
215 settings = {} |
a1bcfe58a1ab
Fixed #161 form saves the create repository permission.
Marcin Kuzminski <marcin@python-works.com>
parents:
1206
diff
changeset
|
216 for each in ret: |
a1bcfe58a1ab
Fixed #161 form saves the create repository permission.
Marcin Kuzminski <marcin@python-works.com>
parents:
1206
diff
changeset
|
217 settings['rhodecode_' + each.app_settings_name] = \ |
a1bcfe58a1ab
Fixed #161 form saves the create repository permission.
Marcin Kuzminski <marcin@python-works.com>
parents:
1206
diff
changeset
|
218 each.app_settings_value |
a1bcfe58a1ab
Fixed #161 form saves the create repository permission.
Marcin Kuzminski <marcin@python-works.com>
parents:
1206
diff
changeset
|
219 |
a1bcfe58a1ab
Fixed #161 form saves the create repository permission.
Marcin Kuzminski <marcin@python-works.com>
parents:
1206
diff
changeset
|
220 return settings |
a1bcfe58a1ab
Fixed #161 form saves the create repository permission.
Marcin Kuzminski <marcin@python-works.com>
parents:
1206
diff
changeset
|
221 |
a1bcfe58a1ab
Fixed #161 form saves the create repository permission.
Marcin Kuzminski <marcin@python-works.com>
parents:
1206
diff
changeset
|
222 @classmethod |
1594 | 223 def get_ldap_settings(cls, cache=False): |
1584
3338a0994472
Improve API with user/group/repo CRUD methods
Nicolas VINOT <aeris@imirhil.fr>
parents:
1508
diff
changeset
|
224 ret = cls.query()\ |
1593 | 225 .filter(cls.app_settings_name.startswith('ldap_')).all() |
1266
a1bcfe58a1ab
Fixed #161 form saves the create repository permission.
Marcin Kuzminski <marcin@python-works.com>
parents:
1206
diff
changeset
|
226 fd = {} |
a1bcfe58a1ab
Fixed #161 form saves the create repository permission.
Marcin Kuzminski <marcin@python-works.com>
parents:
1206
diff
changeset
|
227 for row in ret: |
2356
2da7b5984ae5
typo fix + code garden
Marcin Kuzminski <marcin@python-works.com>
parents:
2352
diff
changeset
|
228 fd.update({row.app_settings_name: row.app_settings_value}) |
1381
a1ab3e9c7e82
fixes #204, ldap active checkbox, credits goes to Matt Little.
Marcin Kuzminski <marcin@python-works.com>
parents:
1376
diff
changeset
|
229 |
1266
a1bcfe58a1ab
Fixed #161 form saves the create repository permission.
Marcin Kuzminski <marcin@python-works.com>
parents:
1206
diff
changeset
|
230 return fd |
a1bcfe58a1ab
Fixed #161 form saves the create repository permission.
Marcin Kuzminski <marcin@python-works.com>
parents:
1206
diff
changeset
|
231 |
3056
6104dfd35b16
Implemented #379 defaults settings page for creation of repositories
Marcin Kuzminski <marcin@python-works.com>
parents:
3052
diff
changeset
|
232 @classmethod |
6104dfd35b16
Implemented #379 defaults settings page for creation of repositories
Marcin Kuzminski <marcin@python-works.com>
parents:
3052
diff
changeset
|
233 def get_default_repo_settings(cls, cache=False, strip_prefix=False): |
6104dfd35b16
Implemented #379 defaults settings page for creation of repositories
Marcin Kuzminski <marcin@python-works.com>
parents:
3052
diff
changeset
|
234 ret = cls.query()\ |
6104dfd35b16
Implemented #379 defaults settings page for creation of repositories
Marcin Kuzminski <marcin@python-works.com>
parents:
3052
diff
changeset
|
235 .filter(cls.app_settings_name.startswith('default_')).all() |
6104dfd35b16
Implemented #379 defaults settings page for creation of repositories
Marcin Kuzminski <marcin@python-works.com>
parents:
3052
diff
changeset
|
236 fd = {} |
6104dfd35b16
Implemented #379 defaults settings page for creation of repositories
Marcin Kuzminski <marcin@python-works.com>
parents:
3052
diff
changeset
|
237 for row in ret: |
6104dfd35b16
Implemented #379 defaults settings page for creation of repositories
Marcin Kuzminski <marcin@python-works.com>
parents:
3052
diff
changeset
|
238 key = row.app_settings_name |
6104dfd35b16
Implemented #379 defaults settings page for creation of repositories
Marcin Kuzminski <marcin@python-works.com>
parents:
3052
diff
changeset
|
239 if strip_prefix: |
6104dfd35b16
Implemented #379 defaults settings page for creation of repositories
Marcin Kuzminski <marcin@python-works.com>
parents:
3052
diff
changeset
|
240 key = remove_prefix(key, prefix='default_') |
6104dfd35b16
Implemented #379 defaults settings page for creation of repositories
Marcin Kuzminski <marcin@python-works.com>
parents:
3052
diff
changeset
|
241 fd.update({key: row.app_settings_value}) |
6104dfd35b16
Implemented #379 defaults settings page for creation of repositories
Marcin Kuzminski <marcin@python-works.com>
parents:
3052
diff
changeset
|
242 |
6104dfd35b16
Implemented #379 defaults settings page for creation of repositories
Marcin Kuzminski <marcin@python-works.com>
parents:
3052
diff
changeset
|
243 return fd |
6104dfd35b16
Implemented #379 defaults settings page for creation of repositories
Marcin Kuzminski <marcin@python-works.com>
parents:
3052
diff
changeset
|
244 |
1266
a1bcfe58a1ab
Fixed #161 form saves the create repository permission.
Marcin Kuzminski <marcin@python-works.com>
parents:
1206
diff
changeset
|
245 |
1593 | 246 class RhodeCodeUi(Base, BaseModel): |
548
b75b77ef649d
renamed hg_app to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
547
diff
changeset
|
247 __tablename__ = 'rhodecode_ui' |
1958
7e4b3d3a9c5c
renamed repo groups table
Marcin Kuzminski <marcin@python-works.com>
parents:
1950
diff
changeset
|
248 __table_args__ = ( |
1963
9bbde54232dc
white space cleanup
Marcin Kuzminski <marcin@python-works.com>
parents:
1960
diff
changeset
|
249 UniqueConstraint('ui_key'), |
2356
2da7b5984ae5
typo fix + code garden
Marcin Kuzminski <marcin@python-works.com>
parents:
2352
diff
changeset
|
250 {'extend_existing': True, 'mysql_engine': 'InnoDB', |
2149 | 251 'mysql_charset': 'utf8'} |
1958
7e4b3d3a9c5c
renamed repo groups table
Marcin Kuzminski <marcin@python-works.com>
parents:
1950
diff
changeset
|
252 ) |
1460
b50348816a80
Added more advanced hook management into rhodecode admin settings
Marcin Kuzminski <marcin@python-works.com>
parents:
1436
diff
changeset
|
253 |
b50348816a80
Added more advanced hook management into rhodecode admin settings
Marcin Kuzminski <marcin@python-works.com>
parents:
1436
diff
changeset
|
254 HOOK_UPDATE = 'changegroup.update' |
b50348816a80
Added more advanced hook management into rhodecode admin settings
Marcin Kuzminski <marcin@python-works.com>
parents:
1436
diff
changeset
|
255 HOOK_REPO_SIZE = 'changegroup.repo_size' |
2407
8a68e0292232
Change git & hg hooks to post. They shouldn't block as they are used just for logging actions. Futhermore post hooks have access to changesets, so it's much better flexible
Marcin Kuzminski <marcin@python-works.com>
parents:
2401
diff
changeset
|
256 HOOK_PUSH = 'changegroup.push_logger' |
2726
aa17c7a1b8a5
Implemented basic locking functionality.
Marcin Kuzminski <marcin@python-works.com>
parents:
2724
diff
changeset
|
257 HOOK_PRE_PUSH = 'prechangegroup.pre_push' |
aa17c7a1b8a5
Implemented basic locking functionality.
Marcin Kuzminski <marcin@python-works.com>
parents:
2724
diff
changeset
|
258 HOOK_PULL = 'outgoing.pull_logger' |
aa17c7a1b8a5
Implemented basic locking functionality.
Marcin Kuzminski <marcin@python-works.com>
parents:
2724
diff
changeset
|
259 HOOK_PRE_PULL = 'preoutgoing.pre_pull' |
1460
b50348816a80
Added more advanced hook management into rhodecode admin settings
Marcin Kuzminski <marcin@python-works.com>
parents:
1436
diff
changeset
|
260 |
1594 | 261 ui_id = Column("ui_id", Integer(), nullable=False, unique=True, default=None, primary_key=True) |
2588
32dd6896abcf
added status column to pull request + some small refactoring of models
Marcin Kuzminski <marcin@python-works.com>
parents:
2585
diff
changeset
|
262 ui_section = Column("ui_section", String(255, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None) |
32dd6896abcf
added status column to pull request + some small refactoring of models
Marcin Kuzminski <marcin@python-works.com>
parents:
2585
diff
changeset
|
263 ui_key = Column("ui_key", String(255, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None) |
32dd6896abcf
added status column to pull request + some small refactoring of models
Marcin Kuzminski <marcin@python-works.com>
parents:
2585
diff
changeset
|
264 ui_value = Column("ui_value", String(255, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None) |
1594 | 265 ui_active = Column("ui_active", Boolean(), nullable=True, unique=None, default=True) |
631
05528ad948c4
Hacking for git support,and new faster repo scan
Marcin Kuzminski <marcin@python-works.com>
parents:
549
diff
changeset
|
266 |
1345
3bce31f026b8
#47 implemented Adding of new repo_groups+forms+validators. Fixed sorting of repo groups by main names in multiple locations. Removed some unneeded calls to self.sa for exchange to .query() methods.
Marcin Kuzminski <marcin@python-works.com>
parents:
1343
diff
changeset
|
267 @classmethod |
1593 | 268 def get_by_key(cls, key): |
2708
9bce679a3f49
Added form for controlling mercurial extensions
Marcin Kuzminski <marcin@python-works.com>
parents:
2689
diff
changeset
|
269 return cls.query().filter(cls.ui_key == key).scalar() |
1345
3bce31f026b8
#47 implemented Adding of new repo_groups+forms+validators. Fixed sorting of repo groups by main names in multiple locations. Removed some unneeded calls to self.sa for exchange to .query() methods.
Marcin Kuzminski <marcin@python-works.com>
parents:
1343
diff
changeset
|
270 |
1460
b50348816a80
Added more advanced hook management into rhodecode admin settings
Marcin Kuzminski <marcin@python-works.com>
parents:
1436
diff
changeset
|
271 @classmethod |
1593 | 272 def get_builtin_hooks(cls): |
1460
b50348816a80
Added more advanced hook management into rhodecode admin settings
Marcin Kuzminski <marcin@python-works.com>
parents:
1436
diff
changeset
|
273 q = cls.query() |
2726
aa17c7a1b8a5
Implemented basic locking functionality.
Marcin Kuzminski <marcin@python-works.com>
parents:
2724
diff
changeset
|
274 q = q.filter(cls.ui_key.in_([cls.HOOK_UPDATE, cls.HOOK_REPO_SIZE, |
aa17c7a1b8a5
Implemented basic locking functionality.
Marcin Kuzminski <marcin@python-works.com>
parents:
2724
diff
changeset
|
275 cls.HOOK_PUSH, cls.HOOK_PRE_PUSH, |
aa17c7a1b8a5
Implemented basic locking functionality.
Marcin Kuzminski <marcin@python-works.com>
parents:
2724
diff
changeset
|
276 cls.HOOK_PULL, cls.HOOK_PRE_PULL])) |
1460
b50348816a80
Added more advanced hook management into rhodecode admin settings
Marcin Kuzminski <marcin@python-works.com>
parents:
1436
diff
changeset
|
277 return q.all() |
b50348816a80
Added more advanced hook management into rhodecode admin settings
Marcin Kuzminski <marcin@python-works.com>
parents:
1436
diff
changeset
|
278 |
b50348816a80
Added more advanced hook management into rhodecode admin settings
Marcin Kuzminski <marcin@python-works.com>
parents:
1436
diff
changeset
|
279 @classmethod |
1593 | 280 def get_custom_hooks(cls): |
1460
b50348816a80
Added more advanced hook management into rhodecode admin settings
Marcin Kuzminski <marcin@python-works.com>
parents:
1436
diff
changeset
|
281 q = cls.query() |
2726
aa17c7a1b8a5
Implemented basic locking functionality.
Marcin Kuzminski <marcin@python-works.com>
parents:
2724
diff
changeset
|
282 q = q.filter(~cls.ui_key.in_([cls.HOOK_UPDATE, cls.HOOK_REPO_SIZE, |
aa17c7a1b8a5
Implemented basic locking functionality.
Marcin Kuzminski <marcin@python-works.com>
parents:
2724
diff
changeset
|
283 cls.HOOK_PUSH, cls.HOOK_PRE_PUSH, |
aa17c7a1b8a5
Implemented basic locking functionality.
Marcin Kuzminski <marcin@python-works.com>
parents:
2724
diff
changeset
|
284 cls.HOOK_PULL, cls.HOOK_PRE_PULL])) |
1593 | 285 q = q.filter(cls.ui_section == 'hooks') |
1460
b50348816a80
Added more advanced hook management into rhodecode admin settings
Marcin Kuzminski <marcin@python-works.com>
parents:
1436
diff
changeset
|
286 return q.all() |
b50348816a80
Added more advanced hook management into rhodecode admin settings
Marcin Kuzminski <marcin@python-works.com>
parents:
1436
diff
changeset
|
287 |
b50348816a80
Added more advanced hook management into rhodecode admin settings
Marcin Kuzminski <marcin@python-works.com>
parents:
1436
diff
changeset
|
288 @classmethod |
2401
e2af60e480ce
Removed hardcoded hooks names from settings.
Marcin Kuzminski <marcin@python-works.com>
parents:
2400
diff
changeset
|
289 def get_repos_location(cls): |
2708
9bce679a3f49
Added form for controlling mercurial extensions
Marcin Kuzminski <marcin@python-works.com>
parents:
2689
diff
changeset
|
290 return cls.get_by_key('/').ui_value |
2401
e2af60e480ce
Removed hardcoded hooks names from settings.
Marcin Kuzminski <marcin@python-works.com>
parents:
2400
diff
changeset
|
291 |
e2af60e480ce
Removed hardcoded hooks names from settings.
Marcin Kuzminski <marcin@python-works.com>
parents:
2400
diff
changeset
|
292 @classmethod |
1593 | 293 def create_or_update_hook(cls, key, val): |
2708
9bce679a3f49
Added form for controlling mercurial extensions
Marcin Kuzminski <marcin@python-works.com>
parents:
2689
diff
changeset
|
294 new_ui = cls.get_by_key(key) or cls() |
1460
b50348816a80
Added more advanced hook management into rhodecode admin settings
Marcin Kuzminski <marcin@python-works.com>
parents:
1436
diff
changeset
|
295 new_ui.ui_section = 'hooks' |
b50348816a80
Added more advanced hook management into rhodecode admin settings
Marcin Kuzminski <marcin@python-works.com>
parents:
1436
diff
changeset
|
296 new_ui.ui_active = True |
b50348816a80
Added more advanced hook management into rhodecode admin settings
Marcin Kuzminski <marcin@python-works.com>
parents:
1436
diff
changeset
|
297 new_ui.ui_key = key |
b50348816a80
Added more advanced hook management into rhodecode admin settings
Marcin Kuzminski <marcin@python-works.com>
parents:
1436
diff
changeset
|
298 new_ui.ui_value = val |
b50348816a80
Added more advanced hook management into rhodecode admin settings
Marcin Kuzminski <marcin@python-works.com>
parents:
1436
diff
changeset
|
299 |
2520
a1e156503afe
Fixed calls to Session in db model
Marcin Kuzminski <marcin@python-works.com>
parents:
2510
diff
changeset
|
300 Session().add(new_ui) |
1460
b50348816a80
Added more advanced hook management into rhodecode admin settings
Marcin Kuzminski <marcin@python-works.com>
parents:
1436
diff
changeset
|
301 |
2821
9c90be87ae05
fixed issue #560 require push ssl checkbox wasn't shown when option was enabled
Marcin Kuzminski <marcin@python-works.com>
parents:
2809
diff
changeset
|
302 def __repr__(self): |
9c90be87ae05
fixed issue #560 require push ssl checkbox wasn't shown when option was enabled
Marcin Kuzminski <marcin@python-works.com>
parents:
2809
diff
changeset
|
303 return '<DB:%s[%s:%s]>' % (self.__class__.__name__, self.ui_key, |
9c90be87ae05
fixed issue #560 require push ssl checkbox wasn't shown when option was enabled
Marcin Kuzminski <marcin@python-works.com>
parents:
2809
diff
changeset
|
304 self.ui_value) |
9c90be87ae05
fixed issue #560 require push ssl checkbox wasn't shown when option was enabled
Marcin Kuzminski <marcin@python-works.com>
parents:
2809
diff
changeset
|
305 |
1460
b50348816a80
Added more advanced hook management into rhodecode admin settings
Marcin Kuzminski <marcin@python-works.com>
parents:
1436
diff
changeset
|
306 |
1593 | 307 class User(Base, BaseModel): |
49
3ada2f409c1c
Added sqlalchemy support
Marcin Kuzminski <marcin@python-blog.com>
parents:
diff
changeset
|
308 __tablename__ = 'users' |
1958
7e4b3d3a9c5c
renamed repo groups table
Marcin Kuzminski <marcin@python-works.com>
parents:
1950
diff
changeset
|
309 __table_args__ = ( |
1963
9bbde54232dc
white space cleanup
Marcin Kuzminski <marcin@python-works.com>
parents:
1960
diff
changeset
|
310 UniqueConstraint('username'), UniqueConstraint('email'), |
2726
aa17c7a1b8a5
Implemented basic locking functionality.
Marcin Kuzminski <marcin@python-works.com>
parents:
2724
diff
changeset
|
311 Index('u_username_idx', 'username'), |
aa17c7a1b8a5
Implemented basic locking functionality.
Marcin Kuzminski <marcin@python-works.com>
parents:
2724
diff
changeset
|
312 Index('u_email_idx', 'email'), |
2356
2da7b5984ae5
typo fix + code garden
Marcin Kuzminski <marcin@python-works.com>
parents:
2352
diff
changeset
|
313 {'extend_existing': True, 'mysql_engine': 'InnoDB', |
2149 | 314 'mysql_charset': 'utf8'} |
1958
7e4b3d3a9c5c
renamed repo groups table
Marcin Kuzminski <marcin@python-works.com>
parents:
1950
diff
changeset
|
315 ) |
2726
aa17c7a1b8a5
Implemented basic locking functionality.
Marcin Kuzminski <marcin@python-works.com>
parents:
2724
diff
changeset
|
316 DEFAULT_USER = 'default' |
2798
091e99b29fd4
auto-healing of permissions for default user after upgrading from some old versions.
Marcin Kuzminski <marcin@python-works.com>
parents:
2797
diff
changeset
|
317 DEFAULT_PERMISSIONS = [ |
091e99b29fd4
auto-healing of permissions for default user after upgrading from some old versions.
Marcin Kuzminski <marcin@python-works.com>
parents:
2797
diff
changeset
|
318 'hg.register.manual_activate', 'hg.create.repository', |
3052
d3200c58764e
implemented #663 Admin/permission: specify default repogroup perms
Marcin Kuzminski <marcin@python-works.com>
parents:
3025
diff
changeset
|
319 'hg.fork.repository', 'repository.read', 'group.read' |
2798
091e99b29fd4
auto-healing of permissions for default user after upgrading from some old versions.
Marcin Kuzminski <marcin@python-works.com>
parents:
2797
diff
changeset
|
320 ] |
1594 | 321 user_id = Column("user_id", Integer(), nullable=False, unique=True, default=None, primary_key=True) |
2588
32dd6896abcf
added status column to pull request + some small refactoring of models
Marcin Kuzminski <marcin@python-works.com>
parents:
2585
diff
changeset
|
322 username = Column("username", String(255, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None) |
32dd6896abcf
added status column to pull request + some small refactoring of models
Marcin Kuzminski <marcin@python-works.com>
parents:
2585
diff
changeset
|
323 password = Column("password", String(255, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None) |
2480
cb9e73b29a87
User active flag should be default to True
Marcin Kuzminski <marcin@python-works.com>
parents:
2463
diff
changeset
|
324 active = Column("active", Boolean(), nullable=True, unique=None, default=True) |
1594 | 325 admin = Column("admin", Boolean(), nullable=True, unique=None, default=False) |
2588
32dd6896abcf
added status column to pull request + some small refactoring of models
Marcin Kuzminski <marcin@python-works.com>
parents:
2585
diff
changeset
|
326 name = Column("firstname", String(255, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None) |
32dd6896abcf
added status column to pull request + some small refactoring of models
Marcin Kuzminski <marcin@python-works.com>
parents:
2585
diff
changeset
|
327 lastname = Column("lastname", String(255, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None) |
32dd6896abcf
added status column to pull request + some small refactoring of models
Marcin Kuzminski <marcin@python-works.com>
parents:
2585
diff
changeset
|
328 _email = Column("email", String(255, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None) |
1594 | 329 last_login = Column("last_login", DateTime(timezone=False), nullable=True, unique=None, default=None) |
2588
32dd6896abcf
added status column to pull request + some small refactoring of models
Marcin Kuzminski <marcin@python-works.com>
parents:
2585
diff
changeset
|
330 ldap_dn = Column("ldap_dn", String(255, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None) |
32dd6896abcf
added status column to pull request + some small refactoring of models
Marcin Kuzminski <marcin@python-works.com>
parents:
2585
diff
changeset
|
331 api_key = Column("api_key", String(255, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None) |
2709
d2d35cf2b351
RhodeCode now has a option to explicitly set forking permissions. ref #508
Marcin Kuzminski <marcin@python-works.com>
parents:
2708
diff
changeset
|
332 inherit_default_permissions = Column("inherit_default_permissions", Boolean(), nullable=False, unique=None, default=True) |
631
05528ad948c4
Hacking for git support,and new faster repo scan
Marcin Kuzminski <marcin@python-works.com>
parents:
549
diff
changeset
|
333 |
3065
09e8623362ef
remove not null from user_id column for users log archiving
Marcin Kuzminski <marcin@python-works.com>
parents:
3063
diff
changeset
|
334 user_log = relationship('UserLog') |
1594 | 335 user_perms = relationship('UserToPerm', primaryjoin="User.user_id==UserToPerm.user_id", cascade='all') |
631
05528ad948c4
Hacking for git support,and new faster repo scan
Marcin Kuzminski <marcin@python-works.com>
parents:
549
diff
changeset
|
336 |
1593 | 337 repositories = relationship('Repository') |
1594 | 338 user_followers = relationship('UserFollowing', primaryjoin='UserFollowing.follows_user_id==User.user_id', cascade='all') |
3067
9b0636e9b16b
fixed issue with cascade deleting of following entries
Marcin Kuzminski <marcin@python-works.com>
parents:
3065
diff
changeset
|
339 followings = relationship('UserFollowing', primaryjoin='UserFollowing.user_id==User.user_id', cascade='all') |
9b0636e9b16b
fixed issue with cascade deleting of following entries
Marcin Kuzminski <marcin@python-works.com>
parents:
3065
diff
changeset
|
340 |
1633
2c0d35e336b5
refactoring of models names for repoGroup permissions
Marcin Kuzminski <marcin@python-works.com>
parents:
1607
diff
changeset
|
341 repo_to_perm = relationship('UserRepoToPerm', primaryjoin='UserRepoToPerm.user_id==User.user_id', cascade='all') |
2149 | 342 repo_group_to_perm = relationship('UserRepoGroupToPerm', primaryjoin='UserRepoGroupToPerm.user_id==User.user_id', cascade='all') |
2150
a8c9c0094ddf
White space cleanup
Marcin Kuzminski <marcin@python-works.com>
parents:
2149
diff
changeset
|
343 |
1594 | 344 group_member = relationship('UsersGroupMember', cascade='all') |
1065
5d676b6ab71c
Moved BaseModel into base class for declarative base. Added some handy methods into
Marcin Kuzminski <marcin@python-works.com>
parents:
1039
diff
changeset
|
345 |
2157
6a2c0cfb018d
Cascade delete comments and notifications when removing user.
Marcin Kuzminski <marcin@python-works.com>
parents:
2156
diff
changeset
|
346 notifications = relationship('UserNotification', cascade='all') |
6a2c0cfb018d
Cascade delete comments and notifications when removing user.
Marcin Kuzminski <marcin@python-works.com>
parents:
2156
diff
changeset
|
347 # notifications assigned to this user |
6a2c0cfb018d
Cascade delete comments and notifications when removing user.
Marcin Kuzminski <marcin@python-works.com>
parents:
2156
diff
changeset
|
348 user_created_notifications = relationship('Notification', cascade='all') |
6a2c0cfb018d
Cascade delete comments and notifications when removing user.
Marcin Kuzminski <marcin@python-works.com>
parents:
2156
diff
changeset
|
349 # comments created by this user |
6a2c0cfb018d
Cascade delete comments and notifications when removing user.
Marcin Kuzminski <marcin@python-works.com>
parents:
2156
diff
changeset
|
350 user_comments = relationship('ChangesetComment', cascade='all') |
2562
78f96d7bb23b
cascade delete extra emails on user delete
Marcin Kuzminski <marcin@python-works.com>
parents:
2544
diff
changeset
|
351 #extra emails for this user |
78f96d7bb23b
cascade delete extra emails on user delete
Marcin Kuzminski <marcin@python-works.com>
parents:
2544
diff
changeset
|
352 user_emails = relationship('UserEmailMap', cascade='all') |
1702
8cb7f5c4d494
#302 - basic notification system, models+tests
Marcin Kuzminski <marcin@python-works.com>
parents:
1693
diff
changeset
|
353 |
1757
2aa7f454204e
fixes #298, ldap email addresses created by rhodecode automatically during first login didn't get converted to lower case, which lead to lookup failures and than wrong checks for uniqueness. Fixed that by putting a setter on db model column that will enforce converting to lowercase.
Marcin Kuzminski <marcin@python-works.com>
parents:
1749
diff
changeset
|
354 @hybrid_property |
2aa7f454204e
fixes #298, ldap email addresses created by rhodecode automatically during first login didn't get converted to lower case, which lead to lookup failures and than wrong checks for uniqueness. Fixed that by putting a setter on db model column that will enforce converting to lowercase.
Marcin Kuzminski <marcin@python-works.com>
parents:
1749
diff
changeset
|
355 def email(self): |
2aa7f454204e
fixes #298, ldap email addresses created by rhodecode automatically during first login didn't get converted to lower case, which lead to lookup failures and than wrong checks for uniqueness. Fixed that by putting a setter on db model column that will enforce converting to lowercase.
Marcin Kuzminski <marcin@python-works.com>
parents:
1749
diff
changeset
|
356 return self._email |
2aa7f454204e
fixes #298, ldap email addresses created by rhodecode automatically during first login didn't get converted to lower case, which lead to lookup failures and than wrong checks for uniqueness. Fixed that by putting a setter on db model column that will enforce converting to lowercase.
Marcin Kuzminski <marcin@python-works.com>
parents:
1749
diff
changeset
|
357 |
2aa7f454204e
fixes #298, ldap email addresses created by rhodecode automatically during first login didn't get converted to lower case, which lead to lookup failures and than wrong checks for uniqueness. Fixed that by putting a setter on db model column that will enforce converting to lowercase.
Marcin Kuzminski <marcin@python-works.com>
parents:
1749
diff
changeset
|
358 @email.setter |
2aa7f454204e
fixes #298, ldap email addresses created by rhodecode automatically during first login didn't get converted to lower case, which lead to lookup failures and than wrong checks for uniqueness. Fixed that by putting a setter on db model column that will enforce converting to lowercase.
Marcin Kuzminski <marcin@python-works.com>
parents:
1749
diff
changeset
|
359 def email(self, val): |
2aa7f454204e
fixes #298, ldap email addresses created by rhodecode automatically during first login didn't get converted to lower case, which lead to lookup failures and than wrong checks for uniqueness. Fixed that by putting a setter on db model column that will enforce converting to lowercase.
Marcin Kuzminski <marcin@python-works.com>
parents:
1749
diff
changeset
|
360 self._email = val.lower() if val else None |
2aa7f454204e
fixes #298, ldap email addresses created by rhodecode automatically during first login didn't get converted to lower case, which lead to lookup failures and than wrong checks for uniqueness. Fixed that by putting a setter on db model column that will enforce converting to lowercase.
Marcin Kuzminski <marcin@python-works.com>
parents:
1749
diff
changeset
|
361 |
759
a7f50911a945
Models code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
734
diff
changeset
|
362 @property |
2731
09d8fec02954
Implemented #532.
Marcin Kuzminski <marcin@python-works.com>
parents:
2726
diff
changeset
|
363 def firstname(self): |
09d8fec02954
Implemented #532.
Marcin Kuzminski <marcin@python-works.com>
parents:
2726
diff
changeset
|
364 # alias for future |
09d8fec02954
Implemented #532.
Marcin Kuzminski <marcin@python-works.com>
parents:
2726
diff
changeset
|
365 return self.name |
09d8fec02954
Implemented #532.
Marcin Kuzminski <marcin@python-works.com>
parents:
2726
diff
changeset
|
366 |
09d8fec02954
Implemented #532.
Marcin Kuzminski <marcin@python-works.com>
parents:
2726
diff
changeset
|
367 @property |
2506
7e3e9d0c5575
Add list of all emails that user may have into get_user call
Marcin Kuzminski <marcin@python-works.com>
parents:
2496
diff
changeset
|
368 def emails(self): |
7e3e9d0c5575
Add list of all emails that user may have into get_user call
Marcin Kuzminski <marcin@python-works.com>
parents:
2496
diff
changeset
|
369 other = UserEmailMap.query().filter(UserEmailMap.user==self).all() |
7e3e9d0c5575
Add list of all emails that user may have into get_user call
Marcin Kuzminski <marcin@python-works.com>
parents:
2496
diff
changeset
|
370 return [self.email] + [x.email for x in other] |
7e3e9d0c5575
Add list of all emails that user may have into get_user call
Marcin Kuzminski <marcin@python-works.com>
parents:
2496
diff
changeset
|
371 |
7e3e9d0c5575
Add list of all emails that user may have into get_user call
Marcin Kuzminski <marcin@python-works.com>
parents:
2496
diff
changeset
|
372 @property |
3127
71ce052f8b6b
add ipaddresses to repo data on API calls
Marcin Kuzminski <marcin@python-works.com>
parents:
3125
diff
changeset
|
373 def ip_addresses(self): |
71ce052f8b6b
add ipaddresses to repo data on API calls
Marcin Kuzminski <marcin@python-works.com>
parents:
3125
diff
changeset
|
374 ret = UserIpMap.query().filter(UserIpMap.user == self).all() |
71ce052f8b6b
add ipaddresses to repo data on API calls
Marcin Kuzminski <marcin@python-works.com>
parents:
3125
diff
changeset
|
375 return [x.ip_addr for x in ret] |
71ce052f8b6b
add ipaddresses to repo data on API calls
Marcin Kuzminski <marcin@python-works.com>
parents:
3125
diff
changeset
|
376 |
71ce052f8b6b
add ipaddresses to repo data on API calls
Marcin Kuzminski <marcin@python-works.com>
parents:
3125
diff
changeset
|
377 @property |
2731
09d8fec02954
Implemented #532.
Marcin Kuzminski <marcin@python-works.com>
parents:
2726
diff
changeset
|
378 def username_and_name(self): |
09d8fec02954
Implemented #532.
Marcin Kuzminski <marcin@python-works.com>
parents:
2726
diff
changeset
|
379 return '%s (%s %s)' % (self.username, self.firstname, self.lastname) |
09d8fec02954
Implemented #532.
Marcin Kuzminski <marcin@python-works.com>
parents:
2726
diff
changeset
|
380 |
09d8fec02954
Implemented #532.
Marcin Kuzminski <marcin@python-works.com>
parents:
2726
diff
changeset
|
381 @property |
1731
31e6eb2fb4b2
implements #222 registration feedback
Marcin Kuzminski <marcin@python-works.com>
parents:
1729
diff
changeset
|
382 def full_name(self): |
2731
09d8fec02954
Implemented #532.
Marcin Kuzminski <marcin@python-works.com>
parents:
2726
diff
changeset
|
383 return '%s %s' % (self.firstname, self.lastname) |
1731
31e6eb2fb4b2
implements #222 registration feedback
Marcin Kuzminski <marcin@python-works.com>
parents:
1729
diff
changeset
|
384 |
31e6eb2fb4b2
implements #222 registration feedback
Marcin Kuzminski <marcin@python-works.com>
parents:
1729
diff
changeset
|
385 @property |
1950
4ae17f819ee8
#344 optional firstname lastname on user creation
Marcin Kuzminski <marcin@python-works.com>
parents:
1948
diff
changeset
|
386 def full_name_or_username(self): |
2731
09d8fec02954
Implemented #532.
Marcin Kuzminski <marcin@python-works.com>
parents:
2726
diff
changeset
|
387 return ('%s %s' % (self.firstname, self.lastname) |
09d8fec02954
Implemented #532.
Marcin Kuzminski <marcin@python-works.com>
parents:
2726
diff
changeset
|
388 if (self.firstname and self.lastname) else self.username) |
1950
4ae17f819ee8
#344 optional firstname lastname on user creation
Marcin Kuzminski <marcin@python-works.com>
parents:
1948
diff
changeset
|
389 |
4ae17f819ee8
#344 optional firstname lastname on user creation
Marcin Kuzminski <marcin@python-works.com>
parents:
1948
diff
changeset
|
390 @property |
1593 | 391 def full_contact(self): |
2731
09d8fec02954
Implemented #532.
Marcin Kuzminski <marcin@python-works.com>
parents:
2726
diff
changeset
|
392 return '%s %s <%s>' % (self.firstname, self.lastname, self.email) |
631
05528ad948c4
Hacking for git support,and new faster repo scan
Marcin Kuzminski <marcin@python-works.com>
parents:
549
diff
changeset
|
393 |
895
62c04c5cc971
Added some more details into user edit permissions view
Marcin Kuzminski <marcin@python-works.com>
parents:
880
diff
changeset
|
394 @property |
1593 | 395 def short_contact(self): |
2731
09d8fec02954
Implemented #532.
Marcin Kuzminski <marcin@python-works.com>
parents:
2726
diff
changeset
|
396 return '%s %s' % (self.firstname, self.lastname) |
1088
fee472613dfa
made simple global rss and atom feed
Marcin Kuzminski <marcin@python-works.com>
parents:
1081
diff
changeset
|
397 |
fee472613dfa
made simple global rss and atom feed
Marcin Kuzminski <marcin@python-works.com>
parents:
1081
diff
changeset
|
398 @property |
1593 | 399 def is_admin(self): |
895
62c04c5cc971
Added some more details into user edit permissions view
Marcin Kuzminski <marcin@python-works.com>
parents:
880
diff
changeset
|
400 return self.admin |
62c04c5cc971
Added some more details into user edit permissions view
Marcin Kuzminski <marcin@python-works.com>
parents:
880
diff
changeset
|
401 |
3370
fdb0f59b2189
fixes #762, LDAP and container created users are now activated based on
Marcin Kuzminski <marcin@python-works.com>
parents:
3361
diff
changeset
|
402 @property |
fdb0f59b2189
fixes #762, LDAP and container created users are now activated based on
Marcin Kuzminski <marcin@python-works.com>
parents:
3361
diff
changeset
|
403 def AuthUser(self): |
fdb0f59b2189
fixes #762, LDAP and container created users are now activated based on
Marcin Kuzminski <marcin@python-works.com>
parents:
3361
diff
changeset
|
404 """ |
fdb0f59b2189
fixes #762, LDAP and container created users are now activated based on
Marcin Kuzminski <marcin@python-works.com>
parents:
3361
diff
changeset
|
405 Returns instance of AuthUser for this user |
fdb0f59b2189
fixes #762, LDAP and container created users are now activated based on
Marcin Kuzminski <marcin@python-works.com>
parents:
3361
diff
changeset
|
406 """ |
fdb0f59b2189
fixes #762, LDAP and container created users are now activated based on
Marcin Kuzminski <marcin@python-works.com>
parents:
3361
diff
changeset
|
407 from rhodecode.lib.auth import AuthUser |
fdb0f59b2189
fixes #762, LDAP and container created users are now activated based on
Marcin Kuzminski <marcin@python-works.com>
parents:
3361
diff
changeset
|
408 return AuthUser(user_id=self.user_id, api_key=self.api_key, |
fdb0f59b2189
fixes #762, LDAP and container created users are now activated based on
Marcin Kuzminski <marcin@python-works.com>
parents:
3361
diff
changeset
|
409 username=self.username) |
fdb0f59b2189
fixes #762, LDAP and container created users are now activated based on
Marcin Kuzminski <marcin@python-works.com>
parents:
3361
diff
changeset
|
410 |
2156
a27e4d44237e
Use __unicode__ instead of __repr__ in models.
Marcin Kuzminski <marcin@python-works.com>
parents:
2152
diff
changeset
|
411 def __unicode__(self): |
a27e4d44237e
Use __unicode__ instead of __repr__ in models.
Marcin Kuzminski <marcin@python-works.com>
parents:
2152
diff
changeset
|
412 return u"<%s('id:%s:%s')>" % (self.__class__.__name__, |
1712
cac5109ac3b6
Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents:
1703
diff
changeset
|
413 self.user_id, self.username) |
cac5109ac3b6
Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents:
1703
diff
changeset
|
414 |
1065
5d676b6ab71c
Moved BaseModel into base class for declarative base. Added some handy methods into
Marcin Kuzminski <marcin@python-works.com>
parents:
1039
diff
changeset
|
415 @classmethod |
1665
36f77a46f291
Added cache options to some db getters
Marcin Kuzminski <marcin@python-works.com>
parents:
1634
diff
changeset
|
416 def get_by_username(cls, username, case_insensitive=False, cache=False): |
1400
0d7b56b97953
Simplified last_login call on user, and changed login to use User model directly
Marcin Kuzminski <marcin@python-works.com>
parents:
1388
diff
changeset
|
417 if case_insensitive: |
1665
36f77a46f291
Added cache options to some db getters
Marcin Kuzminski <marcin@python-works.com>
parents:
1634
diff
changeset
|
418 q = cls.query().filter(cls.username.ilike(username)) |
1400
0d7b56b97953
Simplified last_login call on user, and changed login to use User model directly
Marcin Kuzminski <marcin@python-works.com>
parents:
1388
diff
changeset
|
419 else: |
1665
36f77a46f291
Added cache options to some db getters
Marcin Kuzminski <marcin@python-works.com>
parents:
1634
diff
changeset
|
420 q = cls.query().filter(cls.username == username) |
36f77a46f291
Added cache options to some db getters
Marcin Kuzminski <marcin@python-works.com>
parents:
1634
diff
changeset
|
421 |
36f77a46f291
Added cache options to some db getters
Marcin Kuzminski <marcin@python-works.com>
parents:
1634
diff
changeset
|
422 if cache: |
2062
bf8ed0adbc66
fixes #371 fixed issues with beaker/sqlalchemy and non-ascii cache keys
Marcin Kuzminski <marcin@python-works.com>
parents:
2058
diff
changeset
|
423 q = q.options(FromCache( |
bf8ed0adbc66
fixes #371 fixed issues with beaker/sqlalchemy and non-ascii cache keys
Marcin Kuzminski <marcin@python-works.com>
parents:
2058
diff
changeset
|
424 "sql_cache_short", |
bf8ed0adbc66
fixes #371 fixed issues with beaker/sqlalchemy and non-ascii cache keys
Marcin Kuzminski <marcin@python-works.com>
parents:
2058
diff
changeset
|
425 "get_user_%s" % _hash_key(username) |
bf8ed0adbc66
fixes #371 fixed issues with beaker/sqlalchemy and non-ascii cache keys
Marcin Kuzminski <marcin@python-works.com>
parents:
2058
diff
changeset
|
426 ) |
bf8ed0adbc66
fixes #371 fixed issues with beaker/sqlalchemy and non-ascii cache keys
Marcin Kuzminski <marcin@python-works.com>
parents:
2058
diff
changeset
|
427 ) |
1665
36f77a46f291
Added cache options to some db getters
Marcin Kuzminski <marcin@python-works.com>
parents:
1634
diff
changeset
|
428 return q.scalar() |
1065
5d676b6ab71c
Moved BaseModel into base class for declarative base. Added some handy methods into
Marcin Kuzminski <marcin@python-works.com>
parents:
1039
diff
changeset
|
429 |
1417
5875955def39
fixes #223 improve password reset form
Marcin Kuzminski <marcin@python-works.com>
parents:
1401
diff
changeset
|
430 @classmethod |
1665
36f77a46f291
Added cache options to some db getters
Marcin Kuzminski <marcin@python-works.com>
parents:
1634
diff
changeset
|
431 def get_by_api_key(cls, api_key, cache=False): |
36f77a46f291
Added cache options to some db getters
Marcin Kuzminski <marcin@python-works.com>
parents:
1634
diff
changeset
|
432 q = cls.query().filter(cls.api_key == api_key) |
36f77a46f291
Added cache options to some db getters
Marcin Kuzminski <marcin@python-works.com>
parents:
1634
diff
changeset
|
433 |
36f77a46f291
Added cache options to some db getters
Marcin Kuzminski <marcin@python-works.com>
parents:
1634
diff
changeset
|
434 if cache: |
36f77a46f291
Added cache options to some db getters
Marcin Kuzminski <marcin@python-works.com>
parents:
1634
diff
changeset
|
435 q = q.options(FromCache("sql_cache_short", |
36f77a46f291
Added cache options to some db getters
Marcin Kuzminski <marcin@python-works.com>
parents:
1634
diff
changeset
|
436 "get_api_key_%s" % api_key)) |
1693
60249224be04
fix for api key lookup, reuse same function in user model
Marcin Kuzminski <marcin@python-works.com>
parents:
1677
diff
changeset
|
437 return q.scalar() |
1417
5875955def39
fixes #223 improve password reset form
Marcin Kuzminski <marcin@python-works.com>
parents:
1401
diff
changeset
|
438 |
1716
7d1fc253549e
notification to commit author + gardening
Marcin Kuzminski <marcin@python-works.com>
parents:
1713
diff
changeset
|
439 @classmethod |
1757
2aa7f454204e
fixes #298, ldap email addresses created by rhodecode automatically during first login didn't get converted to lower case, which lead to lookup failures and than wrong checks for uniqueness. Fixed that by putting a setter on db model column that will enforce converting to lowercase.
Marcin Kuzminski <marcin@python-works.com>
parents:
1749
diff
changeset
|
440 def get_by_email(cls, email, case_insensitive=False, cache=False): |
2aa7f454204e
fixes #298, ldap email addresses created by rhodecode automatically during first login didn't get converted to lower case, which lead to lookup failures and than wrong checks for uniqueness. Fixed that by putting a setter on db model column that will enforce converting to lowercase.
Marcin Kuzminski <marcin@python-works.com>
parents:
1749
diff
changeset
|
441 if case_insensitive: |
2aa7f454204e
fixes #298, ldap email addresses created by rhodecode automatically during first login didn't get converted to lower case, which lead to lookup failures and than wrong checks for uniqueness. Fixed that by putting a setter on db model column that will enforce converting to lowercase.
Marcin Kuzminski <marcin@python-works.com>
parents:
1749
diff
changeset
|
442 q = cls.query().filter(cls.email.ilike(email)) |
2aa7f454204e
fixes #298, ldap email addresses created by rhodecode automatically during first login didn't get converted to lower case, which lead to lookup failures and than wrong checks for uniqueness. Fixed that by putting a setter on db model column that will enforce converting to lowercase.
Marcin Kuzminski <marcin@python-works.com>
parents:
1749
diff
changeset
|
443 else: |
2aa7f454204e
fixes #298, ldap email addresses created by rhodecode automatically during first login didn't get converted to lower case, which lead to lookup failures and than wrong checks for uniqueness. Fixed that by putting a setter on db model column that will enforce converting to lowercase.
Marcin Kuzminski <marcin@python-works.com>
parents:
1749
diff
changeset
|
444 q = cls.query().filter(cls.email == email) |
1716
7d1fc253549e
notification to commit author + gardening
Marcin Kuzminski <marcin@python-works.com>
parents:
1713
diff
changeset
|
445 |
7d1fc253549e
notification to commit author + gardening
Marcin Kuzminski <marcin@python-works.com>
parents:
1713
diff
changeset
|
446 if cache: |
7d1fc253549e
notification to commit author + gardening
Marcin Kuzminski <marcin@python-works.com>
parents:
1713
diff
changeset
|
447 q = q.options(FromCache("sql_cache_short", |
2329
20e307d5250f
Added email-map for alternative email addresses for users
Marcin Kuzminski <marcin@python-works.com>
parents:
2296
diff
changeset
|
448 "get_email_key_%s" % email)) |
20e307d5250f
Added email-map for alternative email addresses for users
Marcin Kuzminski <marcin@python-works.com>
parents:
2296
diff
changeset
|
449 |
20e307d5250f
Added email-map for alternative email addresses for users
Marcin Kuzminski <marcin@python-works.com>
parents:
2296
diff
changeset
|
450 ret = q.scalar() |
20e307d5250f
Added email-map for alternative email addresses for users
Marcin Kuzminski <marcin@python-works.com>
parents:
2296
diff
changeset
|
451 if ret is None: |
20e307d5250f
Added email-map for alternative email addresses for users
Marcin Kuzminski <marcin@python-works.com>
parents:
2296
diff
changeset
|
452 q = UserEmailMap.query() |
20e307d5250f
Added email-map for alternative email addresses for users
Marcin Kuzminski <marcin@python-works.com>
parents:
2296
diff
changeset
|
453 # try fetching in alternate email map |
20e307d5250f
Added email-map for alternative email addresses for users
Marcin Kuzminski <marcin@python-works.com>
parents:
2296
diff
changeset
|
454 if case_insensitive: |
20e307d5250f
Added email-map for alternative email addresses for users
Marcin Kuzminski <marcin@python-works.com>
parents:
2296
diff
changeset
|
455 q = q.filter(UserEmailMap.email.ilike(email)) |
20e307d5250f
Added email-map for alternative email addresses for users
Marcin Kuzminski <marcin@python-works.com>
parents:
2296
diff
changeset
|
456 else: |
20e307d5250f
Added email-map for alternative email addresses for users
Marcin Kuzminski <marcin@python-works.com>
parents:
2296
diff
changeset
|
457 q = q.filter(UserEmailMap.email == email) |
20e307d5250f
Added email-map for alternative email addresses for users
Marcin Kuzminski <marcin@python-works.com>
parents:
2296
diff
changeset
|
458 q = q.options(joinedload(UserEmailMap.user)) |
20e307d5250f
Added email-map for alternative email addresses for users
Marcin Kuzminski <marcin@python-works.com>
parents:
2296
diff
changeset
|
459 if cache: |
20e307d5250f
Added email-map for alternative email addresses for users
Marcin Kuzminski <marcin@python-works.com>
parents:
2296
diff
changeset
|
460 q = q.options(FromCache("sql_cache_short", |
20e307d5250f
Added email-map for alternative email addresses for users
Marcin Kuzminski <marcin@python-works.com>
parents:
2296
diff
changeset
|
461 "get_email_map_key_%s" % email)) |
20e307d5250f
Added email-map for alternative email addresses for users
Marcin Kuzminski <marcin@python-works.com>
parents:
2296
diff
changeset
|
462 ret = getattr(q.scalar(), 'user', None) |
20e307d5250f
Added email-map for alternative email addresses for users
Marcin Kuzminski <marcin@python-works.com>
parents:
2296
diff
changeset
|
463 |
20e307d5250f
Added email-map for alternative email addresses for users
Marcin Kuzminski <marcin@python-works.com>
parents:
2296
diff
changeset
|
464 return ret |
1716
7d1fc253549e
notification to commit author + gardening
Marcin Kuzminski <marcin@python-works.com>
parents:
1713
diff
changeset
|
465 |
3185
a665d8cdd351
improved extraction of user from changeset when sending notification.
Marcin Kuzminski <marcin@python-works.com>
parents:
3174
diff
changeset
|
466 @classmethod |
a665d8cdd351
improved extraction of user from changeset when sending notification.
Marcin Kuzminski <marcin@python-works.com>
parents:
3174
diff
changeset
|
467 def get_from_cs_author(cls, author): |
a665d8cdd351
improved extraction of user from changeset when sending notification.
Marcin Kuzminski <marcin@python-works.com>
parents:
3174
diff
changeset
|
468 """ |
a665d8cdd351
improved extraction of user from changeset when sending notification.
Marcin Kuzminski <marcin@python-works.com>
parents:
3174
diff
changeset
|
469 Tries to get User objects out of commit author string |
a665d8cdd351
improved extraction of user from changeset when sending notification.
Marcin Kuzminski <marcin@python-works.com>
parents:
3174
diff
changeset
|
470 |
a665d8cdd351
improved extraction of user from changeset when sending notification.
Marcin Kuzminski <marcin@python-works.com>
parents:
3174
diff
changeset
|
471 :param author: |
a665d8cdd351
improved extraction of user from changeset when sending notification.
Marcin Kuzminski <marcin@python-works.com>
parents:
3174
diff
changeset
|
472 """ |
a665d8cdd351
improved extraction of user from changeset when sending notification.
Marcin Kuzminski <marcin@python-works.com>
parents:
3174
diff
changeset
|
473 from rhodecode.lib.helpers import email, author_name |
a665d8cdd351
improved extraction of user from changeset when sending notification.
Marcin Kuzminski <marcin@python-works.com>
parents:
3174
diff
changeset
|
474 # Valid email in the attribute passed, see if they're in the system |
a665d8cdd351
improved extraction of user from changeset when sending notification.
Marcin Kuzminski <marcin@python-works.com>
parents:
3174
diff
changeset
|
475 _email = email(author) |
a665d8cdd351
improved extraction of user from changeset when sending notification.
Marcin Kuzminski <marcin@python-works.com>
parents:
3174
diff
changeset
|
476 if _email: |
a665d8cdd351
improved extraction of user from changeset when sending notification.
Marcin Kuzminski <marcin@python-works.com>
parents:
3174
diff
changeset
|
477 user = cls.get_by_email(_email, case_insensitive=True) |
a665d8cdd351
improved extraction of user from changeset when sending notification.
Marcin Kuzminski <marcin@python-works.com>
parents:
3174
diff
changeset
|
478 if user: |
a665d8cdd351
improved extraction of user from changeset when sending notification.
Marcin Kuzminski <marcin@python-works.com>
parents:
3174
diff
changeset
|
479 return user |
a665d8cdd351
improved extraction of user from changeset when sending notification.
Marcin Kuzminski <marcin@python-works.com>
parents:
3174
diff
changeset
|
480 # Maybe we can match by username? |
a665d8cdd351
improved extraction of user from changeset when sending notification.
Marcin Kuzminski <marcin@python-works.com>
parents:
3174
diff
changeset
|
481 _author = author_name(author) |
a665d8cdd351
improved extraction of user from changeset when sending notification.
Marcin Kuzminski <marcin@python-works.com>
parents:
3174
diff
changeset
|
482 user = cls.get_by_username(_author, case_insensitive=True) |
a665d8cdd351
improved extraction of user from changeset when sending notification.
Marcin Kuzminski <marcin@python-works.com>
parents:
3174
diff
changeset
|
483 if user: |
a665d8cdd351
improved extraction of user from changeset when sending notification.
Marcin Kuzminski <marcin@python-works.com>
parents:
3174
diff
changeset
|
484 return user |
a665d8cdd351
improved extraction of user from changeset when sending notification.
Marcin Kuzminski <marcin@python-works.com>
parents:
3174
diff
changeset
|
485 |
1593 | 486 def update_lastlogin(self): |
442
d66a7fa7689b
moved loged in user propagation out of forms,
Marcin Kuzminski <marcin@python-works.com>
parents:
417
diff
changeset
|
487 """Update user lastlogin""" |
1400
0d7b56b97953
Simplified last_login call on user, and changed login to use User model directly
Marcin Kuzminski <marcin@python-works.com>
parents:
1388
diff
changeset
|
488 self.last_login = datetime.datetime.now() |
2520
a1e156503afe
Fixed calls to Session in db model
Marcin Kuzminski <marcin@python-works.com>
parents:
2510
diff
changeset
|
489 Session().add(self) |
1976 | 490 log.debug('updated user %s lastlogin' % self.username) |
631
05528ad948c4
Hacking for git support,and new faster repo scan
Marcin Kuzminski <marcin@python-works.com>
parents:
549
diff
changeset
|
491 |
2508
43cb5b6047fd
Added functions for getting API data to repo and user models
Marcin Kuzminski <marcin@python-works.com>
parents:
2506
diff
changeset
|
492 def get_api_data(self): |
43cb5b6047fd
Added functions for getting API data to repo and user models
Marcin Kuzminski <marcin@python-works.com>
parents:
2506
diff
changeset
|
493 """ |
43cb5b6047fd
Added functions for getting API data to repo and user models
Marcin Kuzminski <marcin@python-works.com>
parents:
2506
diff
changeset
|
494 Common function for generating user related data for API |
43cb5b6047fd
Added functions for getting API data to repo and user models
Marcin Kuzminski <marcin@python-works.com>
parents:
2506
diff
changeset
|
495 """ |
43cb5b6047fd
Added functions for getting API data to repo and user models
Marcin Kuzminski <marcin@python-works.com>
parents:
2506
diff
changeset
|
496 user = self |
43cb5b6047fd
Added functions for getting API data to repo and user models
Marcin Kuzminski <marcin@python-works.com>
parents:
2506
diff
changeset
|
497 data = dict( |
2510
9059b2d91303
Change return paremeters for get_api_data in user and repo
Marcin Kuzminski <marcin@python-works.com>
parents:
2508
diff
changeset
|
498 user_id=user.user_id, |
2508
43cb5b6047fd
Added functions for getting API data to repo and user models
Marcin Kuzminski <marcin@python-works.com>
parents:
2506
diff
changeset
|
499 username=user.username, |
43cb5b6047fd
Added functions for getting API data to repo and user models
Marcin Kuzminski <marcin@python-works.com>
parents:
2506
diff
changeset
|
500 firstname=user.name, |
43cb5b6047fd
Added functions for getting API data to repo and user models
Marcin Kuzminski <marcin@python-works.com>
parents:
2506
diff
changeset
|
501 lastname=user.lastname, |
43cb5b6047fd
Added functions for getting API data to repo and user models
Marcin Kuzminski <marcin@python-works.com>
parents:
2506
diff
changeset
|
502 email=user.email, |
43cb5b6047fd
Added functions for getting API data to repo and user models
Marcin Kuzminski <marcin@python-works.com>
parents:
2506
diff
changeset
|
503 emails=user.emails, |
2510
9059b2d91303
Change return paremeters for get_api_data in user and repo
Marcin Kuzminski <marcin@python-works.com>
parents:
2508
diff
changeset
|
504 api_key=user.api_key, |
2508
43cb5b6047fd
Added functions for getting API data to repo and user models
Marcin Kuzminski <marcin@python-works.com>
parents:
2506
diff
changeset
|
505 active=user.active, |
43cb5b6047fd
Added functions for getting API data to repo and user models
Marcin Kuzminski <marcin@python-works.com>
parents:
2506
diff
changeset
|
506 admin=user.admin, |
43cb5b6047fd
Added functions for getting API data to repo and user models
Marcin Kuzminski <marcin@python-works.com>
parents:
2506
diff
changeset
|
507 ldap_dn=user.ldap_dn, |
43cb5b6047fd
Added functions for getting API data to repo and user models
Marcin Kuzminski <marcin@python-works.com>
parents:
2506
diff
changeset
|
508 last_login=user.last_login, |
3127
71ce052f8b6b
add ipaddresses to repo data on API calls
Marcin Kuzminski <marcin@python-works.com>
parents:
3125
diff
changeset
|
509 ip_addresses=user.ip_addresses |
2508
43cb5b6047fd
Added functions for getting API data to repo and user models
Marcin Kuzminski <marcin@python-works.com>
parents:
2506
diff
changeset
|
510 ) |
43cb5b6047fd
Added functions for getting API data to repo and user models
Marcin Kuzminski <marcin@python-works.com>
parents:
2506
diff
changeset
|
511 return data |
43cb5b6047fd
Added functions for getting API data to repo and user models
Marcin Kuzminski <marcin@python-works.com>
parents:
2506
diff
changeset
|
512 |
1758
a87aa385f21c
fixed repo_create permission by adding missing commit statements
Marcin Kuzminski <marcin@python-works.com>
parents:
1757
diff
changeset
|
513 def __json__(self): |
2544
6ce3387bf0ce
Renamed name to firstname in forms
Marcin Kuzminski <marcin@python-works.com>
parents:
2542
diff
changeset
|
514 data = dict( |
1950
4ae17f819ee8
#344 optional firstname lastname on user creation
Marcin Kuzminski <marcin@python-works.com>
parents:
1948
diff
changeset
|
515 full_name=self.full_name, |
4ae17f819ee8
#344 optional firstname lastname on user creation
Marcin Kuzminski <marcin@python-works.com>
parents:
1948
diff
changeset
|
516 full_name_or_username=self.full_name_or_username, |
4ae17f819ee8
#344 optional firstname lastname on user creation
Marcin Kuzminski <marcin@python-works.com>
parents:
1948
diff
changeset
|
517 short_contact=self.short_contact, |
4ae17f819ee8
#344 optional firstname lastname on user creation
Marcin Kuzminski <marcin@python-works.com>
parents:
1948
diff
changeset
|
518 full_contact=self.full_contact |
4ae17f819ee8
#344 optional firstname lastname on user creation
Marcin Kuzminski <marcin@python-works.com>
parents:
1948
diff
changeset
|
519 ) |
2544
6ce3387bf0ce
Renamed name to firstname in forms
Marcin Kuzminski <marcin@python-works.com>
parents:
2542
diff
changeset
|
520 data.update(self.get_api_data()) |
6ce3387bf0ce
Renamed name to firstname in forms
Marcin Kuzminski <marcin@python-works.com>
parents:
2542
diff
changeset
|
521 return data |
1758
a87aa385f21c
fixed repo_create permission by adding missing commit statements
Marcin Kuzminski <marcin@python-works.com>
parents:
1757
diff
changeset
|
522 |
a87aa385f21c
fixed repo_create permission by adding missing commit statements
Marcin Kuzminski <marcin@python-works.com>
parents:
1757
diff
changeset
|
523 |
2329
20e307d5250f
Added email-map for alternative email addresses for users
Marcin Kuzminski <marcin@python-works.com>
parents:
2296
diff
changeset
|
524 class UserEmailMap(Base, BaseModel): |
20e307d5250f
Added email-map for alternative email addresses for users
Marcin Kuzminski <marcin@python-works.com>
parents:
2296
diff
changeset
|
525 __tablename__ = 'user_email_map' |
20e307d5250f
Added email-map for alternative email addresses for users
Marcin Kuzminski <marcin@python-works.com>
parents:
2296
diff
changeset
|
526 __table_args__ = ( |
2463
b426ecc30319
Added some DB indexes to optimize queries
Marcin Kuzminski <marcin@python-works.com>
parents:
2462
diff
changeset
|
527 Index('uem_email_idx', 'email'), |
2329
20e307d5250f
Added email-map for alternative email addresses for users
Marcin Kuzminski <marcin@python-works.com>
parents:
2296
diff
changeset
|
528 UniqueConstraint('email'), |
2463
b426ecc30319
Added some DB indexes to optimize queries
Marcin Kuzminski <marcin@python-works.com>
parents:
2462
diff
changeset
|
529 {'extend_existing': True, 'mysql_engine': 'InnoDB', |
2329
20e307d5250f
Added email-map for alternative email addresses for users
Marcin Kuzminski <marcin@python-works.com>
parents:
2296
diff
changeset
|
530 'mysql_charset': 'utf8'} |
20e307d5250f
Added email-map for alternative email addresses for users
Marcin Kuzminski <marcin@python-works.com>
parents:
2296
diff
changeset
|
531 ) |
20e307d5250f
Added email-map for alternative email addresses for users
Marcin Kuzminski <marcin@python-works.com>
parents:
2296
diff
changeset
|
532 __mapper_args__ = {} |
20e307d5250f
Added email-map for alternative email addresses for users
Marcin Kuzminski <marcin@python-works.com>
parents:
2296
diff
changeset
|
533 |
20e307d5250f
Added email-map for alternative email addresses for users
Marcin Kuzminski <marcin@python-works.com>
parents:
2296
diff
changeset
|
534 email_id = Column("email_id", Integer(), nullable=False, unique=True, default=None, primary_key=True) |
20e307d5250f
Added email-map for alternative email addresses for users
Marcin Kuzminski <marcin@python-works.com>
parents:
2296
diff
changeset
|
535 user_id = Column("user_id", Integer(), ForeignKey('users.user_id'), nullable=True, unique=None, default=None) |
2588
32dd6896abcf
added status column to pull request + some small refactoring of models
Marcin Kuzminski <marcin@python-works.com>
parents:
2585
diff
changeset
|
536 _email = Column("email", String(255, convert_unicode=False, assert_unicode=None), nullable=True, unique=False, default=None) |
2463
b426ecc30319
Added some DB indexes to optimize queries
Marcin Kuzminski <marcin@python-works.com>
parents:
2462
diff
changeset
|
537 user = relationship('User', lazy='joined') |
2329
20e307d5250f
Added email-map for alternative email addresses for users
Marcin Kuzminski <marcin@python-works.com>
parents:
2296
diff
changeset
|
538 |
20e307d5250f
Added email-map for alternative email addresses for users
Marcin Kuzminski <marcin@python-works.com>
parents:
2296
diff
changeset
|
539 @validates('_email') |
20e307d5250f
Added email-map for alternative email addresses for users
Marcin Kuzminski <marcin@python-works.com>
parents:
2296
diff
changeset
|
540 def validate_email(self, key, email): |
20e307d5250f
Added email-map for alternative email addresses for users
Marcin Kuzminski <marcin@python-works.com>
parents:
2296
diff
changeset
|
541 # check if this email is not main one |
2520
a1e156503afe
Fixed calls to Session in db model
Marcin Kuzminski <marcin@python-works.com>
parents:
2510
diff
changeset
|
542 main_email = Session().query(User).filter(User.email == email).scalar() |
2329
20e307d5250f
Added email-map for alternative email addresses for users
Marcin Kuzminski <marcin@python-works.com>
parents:
2296
diff
changeset
|
543 if main_email is not None: |
20e307d5250f
Added email-map for alternative email addresses for users
Marcin Kuzminski <marcin@python-works.com>
parents:
2296
diff
changeset
|
544 raise AttributeError('email %s is present is user table' % email) |
20e307d5250f
Added email-map for alternative email addresses for users
Marcin Kuzminski <marcin@python-works.com>
parents:
2296
diff
changeset
|
545 return email |
20e307d5250f
Added email-map for alternative email addresses for users
Marcin Kuzminski <marcin@python-works.com>
parents:
2296
diff
changeset
|
546 |
20e307d5250f
Added email-map for alternative email addresses for users
Marcin Kuzminski <marcin@python-works.com>
parents:
2296
diff
changeset
|
547 @hybrid_property |
20e307d5250f
Added email-map for alternative email addresses for users
Marcin Kuzminski <marcin@python-works.com>
parents:
2296
diff
changeset
|
548 def email(self): |
20e307d5250f
Added email-map for alternative email addresses for users
Marcin Kuzminski <marcin@python-works.com>
parents:
2296
diff
changeset
|
549 return self._email |
20e307d5250f
Added email-map for alternative email addresses for users
Marcin Kuzminski <marcin@python-works.com>
parents:
2296
diff
changeset
|
550 |
20e307d5250f
Added email-map for alternative email addresses for users
Marcin Kuzminski <marcin@python-works.com>
parents:
2296
diff
changeset
|
551 @email.setter |
20e307d5250f
Added email-map for alternative email addresses for users
Marcin Kuzminski <marcin@python-works.com>
parents:
2296
diff
changeset
|
552 def email(self, val): |
20e307d5250f
Added email-map for alternative email addresses for users
Marcin Kuzminski <marcin@python-works.com>
parents:
2296
diff
changeset
|
553 self._email = val.lower() if val else None |
20e307d5250f
Added email-map for alternative email addresses for users
Marcin Kuzminski <marcin@python-works.com>
parents:
2296
diff
changeset
|
554 |
20e307d5250f
Added email-map for alternative email addresses for users
Marcin Kuzminski <marcin@python-works.com>
parents:
2296
diff
changeset
|
555 |
3125
9b92cf5a0cca
Added UserIpMap interface for allowed IP addresses and IP restriction access
Marcin Kuzminski <marcin@python-works.com>
parents:
3115
diff
changeset
|
556 class UserIpMap(Base, BaseModel): |
9b92cf5a0cca
Added UserIpMap interface for allowed IP addresses and IP restriction access
Marcin Kuzminski <marcin@python-works.com>
parents:
3115
diff
changeset
|
557 __tablename__ = 'user_ip_map' |
9b92cf5a0cca
Added UserIpMap interface for allowed IP addresses and IP restriction access
Marcin Kuzminski <marcin@python-works.com>
parents:
3115
diff
changeset
|
558 __table_args__ = ( |
9b92cf5a0cca
Added UserIpMap interface for allowed IP addresses and IP restriction access
Marcin Kuzminski <marcin@python-works.com>
parents:
3115
diff
changeset
|
559 UniqueConstraint('user_id', 'ip_addr'), |
9b92cf5a0cca
Added UserIpMap interface for allowed IP addresses and IP restriction access
Marcin Kuzminski <marcin@python-works.com>
parents:
3115
diff
changeset
|
560 {'extend_existing': True, 'mysql_engine': 'InnoDB', |
9b92cf5a0cca
Added UserIpMap interface for allowed IP addresses and IP restriction access
Marcin Kuzminski <marcin@python-works.com>
parents:
3115
diff
changeset
|
561 'mysql_charset': 'utf8'} |
9b92cf5a0cca
Added UserIpMap interface for allowed IP addresses and IP restriction access
Marcin Kuzminski <marcin@python-works.com>
parents:
3115
diff
changeset
|
562 ) |
9b92cf5a0cca
Added UserIpMap interface for allowed IP addresses and IP restriction access
Marcin Kuzminski <marcin@python-works.com>
parents:
3115
diff
changeset
|
563 __mapper_args__ = {} |
9b92cf5a0cca
Added UserIpMap interface for allowed IP addresses and IP restriction access
Marcin Kuzminski <marcin@python-works.com>
parents:
3115
diff
changeset
|
564 |
9b92cf5a0cca
Added UserIpMap interface for allowed IP addresses and IP restriction access
Marcin Kuzminski <marcin@python-works.com>
parents:
3115
diff
changeset
|
565 ip_id = Column("ip_id", Integer(), nullable=False, unique=True, default=None, primary_key=True) |
9b92cf5a0cca
Added UserIpMap interface for allowed IP addresses and IP restriction access
Marcin Kuzminski <marcin@python-works.com>
parents:
3115
diff
changeset
|
566 user_id = Column("user_id", Integer(), ForeignKey('users.user_id'), nullable=True, unique=None, default=None) |
9b92cf5a0cca
Added UserIpMap interface for allowed IP addresses and IP restriction access
Marcin Kuzminski <marcin@python-works.com>
parents:
3115
diff
changeset
|
567 ip_addr = Column("ip_addr", String(255, convert_unicode=False, assert_unicode=None), nullable=True, unique=False, default=None) |
3146
c5169e445fb8
Full IP restrictions enabled
Marcin Kuzminski <marcin@python-works.com>
parents:
3127
diff
changeset
|
568 active = Column("active", Boolean(), nullable=True, unique=None, default=True) |
3125
9b92cf5a0cca
Added UserIpMap interface for allowed IP addresses and IP restriction access
Marcin Kuzminski <marcin@python-works.com>
parents:
3115
diff
changeset
|
569 user = relationship('User', lazy='joined') |
9b92cf5a0cca
Added UserIpMap interface for allowed IP addresses and IP restriction access
Marcin Kuzminski <marcin@python-works.com>
parents:
3115
diff
changeset
|
570 |
9b92cf5a0cca
Added UserIpMap interface for allowed IP addresses and IP restriction access
Marcin Kuzminski <marcin@python-works.com>
parents:
3115
diff
changeset
|
571 @classmethod |
9b92cf5a0cca
Added UserIpMap interface for allowed IP addresses and IP restriction access
Marcin Kuzminski <marcin@python-works.com>
parents:
3115
diff
changeset
|
572 def _get_ip_range(cls, ip_addr): |
9b92cf5a0cca
Added UserIpMap interface for allowed IP addresses and IP restriction access
Marcin Kuzminski <marcin@python-works.com>
parents:
3115
diff
changeset
|
573 from rhodecode.lib import ipaddr |
3212
6c28533d122c
IP restrictions now also enabled for IPv6
Marcin Kuzminski <marcin@python-works.com>
parents:
3185
diff
changeset
|
574 net = ipaddr.IPNetwork(address=ip_addr) |
3125
9b92cf5a0cca
Added UserIpMap interface for allowed IP addresses and IP restriction access
Marcin Kuzminski <marcin@python-works.com>
parents:
3115
diff
changeset
|
575 return [str(net.network), str(net.broadcast)] |
9b92cf5a0cca
Added UserIpMap interface for allowed IP addresses and IP restriction access
Marcin Kuzminski <marcin@python-works.com>
parents:
3115
diff
changeset
|
576 |
9b92cf5a0cca
Added UserIpMap interface for allowed IP addresses and IP restriction access
Marcin Kuzminski <marcin@python-works.com>
parents:
3115
diff
changeset
|
577 def __json__(self): |
9b92cf5a0cca
Added UserIpMap interface for allowed IP addresses and IP restriction access
Marcin Kuzminski <marcin@python-works.com>
parents:
3115
diff
changeset
|
578 return dict( |
9b92cf5a0cca
Added UserIpMap interface for allowed IP addresses and IP restriction access
Marcin Kuzminski <marcin@python-works.com>
parents:
3115
diff
changeset
|
579 ip_addr=self.ip_addr, |
9b92cf5a0cca
Added UserIpMap interface for allowed IP addresses and IP restriction access
Marcin Kuzminski <marcin@python-works.com>
parents:
3115
diff
changeset
|
580 ip_range=self._get_ip_range(self.ip_addr) |
9b92cf5a0cca
Added UserIpMap interface for allowed IP addresses and IP restriction access
Marcin Kuzminski <marcin@python-works.com>
parents:
3115
diff
changeset
|
581 ) |
9b92cf5a0cca
Added UserIpMap interface for allowed IP addresses and IP restriction access
Marcin Kuzminski <marcin@python-works.com>
parents:
3115
diff
changeset
|
582 |
9b92cf5a0cca
Added UserIpMap interface for allowed IP addresses and IP restriction access
Marcin Kuzminski <marcin@python-works.com>
parents:
3115
diff
changeset
|
583 |
1593 | 584 class UserLog(Base, BaseModel): |
49
3ada2f409c1c
Added sqlalchemy support
Marcin Kuzminski <marcin@python-blog.com>
parents:
diff
changeset
|
585 __tablename__ = 'user_logs' |
2149 | 586 __table_args__ = ( |
2356
2da7b5984ae5
typo fix + code garden
Marcin Kuzminski <marcin@python-works.com>
parents:
2352
diff
changeset
|
587 {'extend_existing': True, 'mysql_engine': 'InnoDB', |
2149 | 588 'mysql_charset': 'utf8'}, |
589 ) | |
1594 | 590 user_log_id = Column("user_log_id", Integer(), nullable=False, unique=True, default=None, primary_key=True) |
3065
09e8623362ef
remove not null from user_id column for users log archiving
Marcin Kuzminski <marcin@python-works.com>
parents:
3063
diff
changeset
|
591 user_id = Column("user_id", Integer(), ForeignKey('users.user_id'), nullable=True, unique=None, default=None) |
3063
ca2b21819dfd
Implemented better support for Wildcard queries
Marcin Kuzminski <marcin@python-works.com>
parents:
3056
diff
changeset
|
592 username = Column("username", String(255, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None) |
1747
8804715404c9
implements #193 journal stores information about deleting of repos
Marcin Kuzminski <marcin@python-works.com>
parents:
1744
diff
changeset
|
593 repository_id = Column("repository_id", Integer(), ForeignKey('repositories.repo_id'), nullable=True) |
2588
32dd6896abcf
added status column to pull request + some small refactoring of models
Marcin Kuzminski <marcin@python-works.com>
parents:
2585
diff
changeset
|
594 repository_name = Column("repository_name", String(255, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None) |
32dd6896abcf
added status column to pull request + some small refactoring of models
Marcin Kuzminski <marcin@python-works.com>
parents:
2585
diff
changeset
|
595 user_ip = Column("user_ip", String(255, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None) |
32dd6896abcf
added status column to pull request + some small refactoring of models
Marcin Kuzminski <marcin@python-works.com>
parents:
2585
diff
changeset
|
596 action = Column("action", UnicodeText(1200000, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None) |
1594 | 597 action_date = Column("action_date", DateTime(timezone=False), nullable=True, unique=None, default=None) |
631
05528ad948c4
Hacking for git support,and new faster repo scan
Marcin Kuzminski <marcin@python-works.com>
parents:
549
diff
changeset
|
598 |
994
7f9d23f6a526
Added grouping by days in journal
Marcin Kuzminski <marcin@python-works.com>
parents:
991
diff
changeset
|
599 @property |
1593 | 600 def action_as_day(self): |
1723
64e91067b996
- refactoring to overcome poor usage of global pylons config
Marcin Kuzminski <marcin@python-works.com>
parents:
1717
diff
changeset
|
601 return datetime.date(*self.action_date.timetuple()[:3]) |
994
7f9d23f6a526
Added grouping by days in journal
Marcin Kuzminski <marcin@python-works.com>
parents:
991
diff
changeset
|
602 |
1593 | 603 user = relationship('User') |
2063
d9ba58526712
fixed #373 missing cascade drop on user_group_to_perm table
Marcin Kuzminski <marcin@python-works.com>
parents:
2062
diff
changeset
|
604 repository = relationship('Repository', cascade='') |
631
05528ad948c4
Hacking for git support,and new faster repo scan
Marcin Kuzminski <marcin@python-works.com>
parents:
549
diff
changeset
|
605 |
956
83d35d716a02
started working on issue #56
Marcin Kuzminski <marcin@python-works.com>
parents:
907
diff
changeset
|
606 |
1593 | 607 class UsersGroup(Base, BaseModel): |
956
83d35d716a02
started working on issue #56
Marcin Kuzminski <marcin@python-works.com>
parents:
907
diff
changeset
|
608 __tablename__ = 'users_groups' |
2149 | 609 __table_args__ = ( |
2356
2da7b5984ae5
typo fix + code garden
Marcin Kuzminski <marcin@python-works.com>
parents:
2352
diff
changeset
|
610 {'extend_existing': True, 'mysql_engine': 'InnoDB', |
2149 | 611 'mysql_charset': 'utf8'}, |
612 ) | |
956
83d35d716a02
started working on issue #56
Marcin Kuzminski <marcin@python-works.com>
parents:
907
diff
changeset
|
613 |
1594 | 614 users_group_id = Column("users_group_id", Integer(), nullable=False, unique=True, default=None, primary_key=True) |
2588
32dd6896abcf
added status column to pull request + some small refactoring of models
Marcin Kuzminski <marcin@python-works.com>
parents:
2585
diff
changeset
|
615 users_group_name = Column("users_group_name", String(255, convert_unicode=False, assert_unicode=None), nullable=False, unique=True, default=None) |
1594 | 616 users_group_active = Column("users_group_active", Boolean(), nullable=True, unique=None, default=None) |
2709
d2d35cf2b351
RhodeCode now has a option to explicitly set forking permissions. ref #508
Marcin Kuzminski <marcin@python-works.com>
parents:
2708
diff
changeset
|
617 inherit_default_permissions = Column("users_group_inherit_default_permissions", Boolean(), nullable=False, unique=None, default=True) |
956
83d35d716a02
started working on issue #56
Marcin Kuzminski <marcin@python-works.com>
parents:
907
diff
changeset
|
618 |
1594 | 619 members = relationship('UsersGroupMember', cascade="all, delete, delete-orphan", lazy="joined") |
2063
d9ba58526712
fixed #373 missing cascade drop on user_group_to_perm table
Marcin Kuzminski <marcin@python-works.com>
parents:
2062
diff
changeset
|
620 users_group_to_perm = relationship('UsersGroupToPerm', cascade='all') |
2149 | 621 users_group_repo_to_perm = relationship('UsersGroupRepoToPerm', cascade='all') |
956
83d35d716a02
started working on issue #56
Marcin Kuzminski <marcin@python-works.com>
parents:
907
diff
changeset
|
622 |
2156
a27e4d44237e
Use __unicode__ instead of __repr__ in models.
Marcin Kuzminski <marcin@python-works.com>
parents:
2152
diff
changeset
|
623 def __unicode__(self): |
a27e4d44237e
Use __unicode__ instead of __repr__ in models.
Marcin Kuzminski <marcin@python-works.com>
parents:
2152
diff
changeset
|
624 return u'<userGroup(%s)>' % (self.users_group_name) |
1271
aa7e45ad0cea
Fixed permissions for users groups, group can have create repo permission now.
Marcin Kuzminski <marcin@python-works.com>
parents:
1266
diff
changeset
|
625 |
aa7e45ad0cea
Fixed permissions for users groups, group can have create repo permission now.
Marcin Kuzminski <marcin@python-works.com>
parents:
1266
diff
changeset
|
626 @classmethod |
1728
07e56179633e
- fixes celery sqlalchemy session issues for async forking
Marcin Kuzminski <marcin@python-works.com>
parents:
1727
diff
changeset
|
627 def get_by_group_name(cls, group_name, cache=False, |
07e56179633e
- fixes celery sqlalchemy session issues for async forking
Marcin Kuzminski <marcin@python-works.com>
parents:
1727
diff
changeset
|
628 case_insensitive=False): |
1271
aa7e45ad0cea
Fixed permissions for users groups, group can have create repo permission now.
Marcin Kuzminski <marcin@python-works.com>
parents:
1266
diff
changeset
|
629 if case_insensitive: |
1728
07e56179633e
- fixes celery sqlalchemy session issues for async forking
Marcin Kuzminski <marcin@python-works.com>
parents:
1727
diff
changeset
|
630 q = cls.query().filter(cls.users_group_name.ilike(group_name)) |
1271
aa7e45ad0cea
Fixed permissions for users groups, group can have create repo permission now.
Marcin Kuzminski <marcin@python-works.com>
parents:
1266
diff
changeset
|
631 else: |
1728
07e56179633e
- fixes celery sqlalchemy session issues for async forking
Marcin Kuzminski <marcin@python-works.com>
parents:
1727
diff
changeset
|
632 q = cls.query().filter(cls.users_group_name == group_name) |
1271
aa7e45ad0cea
Fixed permissions for users groups, group can have create repo permission now.
Marcin Kuzminski <marcin@python-works.com>
parents:
1266
diff
changeset
|
633 if cache: |
2062
bf8ed0adbc66
fixes #371 fixed issues with beaker/sqlalchemy and non-ascii cache keys
Marcin Kuzminski <marcin@python-works.com>
parents:
2058
diff
changeset
|
634 q = q.options(FromCache( |
bf8ed0adbc66
fixes #371 fixed issues with beaker/sqlalchemy and non-ascii cache keys
Marcin Kuzminski <marcin@python-works.com>
parents:
2058
diff
changeset
|
635 "sql_cache_short", |
bf8ed0adbc66
fixes #371 fixed issues with beaker/sqlalchemy and non-ascii cache keys
Marcin Kuzminski <marcin@python-works.com>
parents:
2058
diff
changeset
|
636 "get_user_%s" % _hash_key(group_name) |
bf8ed0adbc66
fixes #371 fixed issues with beaker/sqlalchemy and non-ascii cache keys
Marcin Kuzminski <marcin@python-works.com>
parents:
2058
diff
changeset
|
637 ) |
bf8ed0adbc66
fixes #371 fixed issues with beaker/sqlalchemy and non-ascii cache keys
Marcin Kuzminski <marcin@python-works.com>
parents:
2058
diff
changeset
|
638 ) |
1728
07e56179633e
- fixes celery sqlalchemy session issues for async forking
Marcin Kuzminski <marcin@python-works.com>
parents:
1727
diff
changeset
|
639 return q.scalar() |
1271
aa7e45ad0cea
Fixed permissions for users groups, group can have create repo permission now.
Marcin Kuzminski <marcin@python-works.com>
parents:
1266
diff
changeset
|
640 |
1436
88d13c1c6a55
removed users_group controller in replace for model methods,
Marcin Kuzminski <marcin@python-works.com>
parents:
1435
diff
changeset
|
641 @classmethod |
1594 | 642 def get(cls, users_group_id, cache=False): |
1584
3338a0994472
Improve API with user/group/repo CRUD methods
Nicolas VINOT <aeris@imirhil.fr>
parents:
1508
diff
changeset
|
643 users_group = cls.query() |
1436
88d13c1c6a55
removed users_group controller in replace for model methods,
Marcin Kuzminski <marcin@python-works.com>
parents:
1435
diff
changeset
|
644 if cache: |
1593 | 645 users_group = users_group.options(FromCache("sql_cache_short", |
646 "get_users_group_%s" % users_group_id)) | |
647 return users_group.get(users_group_id) | |
1436
88d13c1c6a55
removed users_group controller in replace for model methods,
Marcin Kuzminski <marcin@python-works.com>
parents:
1435
diff
changeset
|
648 |
2523
788ae4f7d8df
added get_api_data into UsersGroup
Marcin Kuzminski <marcin@python-works.com>
parents:
2520
diff
changeset
|
649 def get_api_data(self): |
788ae4f7d8df
added get_api_data into UsersGroup
Marcin Kuzminski <marcin@python-works.com>
parents:
2520
diff
changeset
|
650 users_group = self |
788ae4f7d8df
added get_api_data into UsersGroup
Marcin Kuzminski <marcin@python-works.com>
parents:
2520
diff
changeset
|
651 |
788ae4f7d8df
added get_api_data into UsersGroup
Marcin Kuzminski <marcin@python-works.com>
parents:
2520
diff
changeset
|
652 data = dict( |
2531
d80a68e2ebcc
return proper id from users_group
Marcin Kuzminski <marcin@python-works.com>
parents:
2523
diff
changeset
|
653 users_group_id=users_group.users_group_id, |
2523
788ae4f7d8df
added get_api_data into UsersGroup
Marcin Kuzminski <marcin@python-works.com>
parents:
2520
diff
changeset
|
654 group_name=users_group.users_group_name, |
788ae4f7d8df
added get_api_data into UsersGroup
Marcin Kuzminski <marcin@python-works.com>
parents:
2520
diff
changeset
|
655 active=users_group.users_group_active, |
788ae4f7d8df
added get_api_data into UsersGroup
Marcin Kuzminski <marcin@python-works.com>
parents:
2520
diff
changeset
|
656 ) |
788ae4f7d8df
added get_api_data into UsersGroup
Marcin Kuzminski <marcin@python-works.com>
parents:
2520
diff
changeset
|
657 |
788ae4f7d8df
added get_api_data into UsersGroup
Marcin Kuzminski <marcin@python-works.com>
parents:
2520
diff
changeset
|
658 return data |
788ae4f7d8df
added get_api_data into UsersGroup
Marcin Kuzminski <marcin@python-works.com>
parents:
2520
diff
changeset
|
659 |
1800 | 660 |
1593 | 661 class UsersGroupMember(Base, BaseModel): |
956
83d35d716a02
started working on issue #56
Marcin Kuzminski <marcin@python-works.com>
parents:
907
diff
changeset
|
662 __tablename__ = 'users_groups_members' |
2149 | 663 __table_args__ = ( |
2356
2da7b5984ae5
typo fix + code garden
Marcin Kuzminski <marcin@python-works.com>
parents:
2352
diff
changeset
|
664 {'extend_existing': True, 'mysql_engine': 'InnoDB', |
2149 | 665 'mysql_charset': 'utf8'}, |
666 ) | |
956
83d35d716a02
started working on issue #56
Marcin Kuzminski <marcin@python-works.com>
parents:
907
diff
changeset
|
667 |
1594 | 668 users_group_member_id = Column("users_group_member_id", Integer(), nullable=False, unique=True, default=None, primary_key=True) |
669 users_group_id = Column("users_group_id", Integer(), ForeignKey('users_groups.users_group_id'), nullable=False, unique=None, default=None) | |
670 user_id = Column("user_id", Integer(), ForeignKey('users.user_id'), nullable=False, unique=None, default=None) | |
956
83d35d716a02
started working on issue #56
Marcin Kuzminski <marcin@python-works.com>
parents:
907
diff
changeset
|
671 |
1594 | 672 user = relationship('User', lazy='joined') |
1593 | 673 users_group = relationship('UsersGroup') |
972
2c8fd84935a4
#56 implemented users groups editing,
Marcin Kuzminski <marcin@python-works.com>
parents:
962
diff
changeset
|
674 |
1594 | 675 def __init__(self, gr_id='', u_id=''): |
972
2c8fd84935a4
#56 implemented users groups editing,
Marcin Kuzminski <marcin@python-works.com>
parents:
962
diff
changeset
|
676 self.users_group_id = gr_id |
2c8fd84935a4
#56 implemented users groups editing,
Marcin Kuzminski <marcin@python-works.com>
parents:
962
diff
changeset
|
677 self.user_id = u_id |
956
83d35d716a02
started working on issue #56
Marcin Kuzminski <marcin@python-works.com>
parents:
907
diff
changeset
|
678 |
2013
8530c3cd9d04
fixed issue with hybrid property for ldap_active
Marcin Kuzminski <marcin@python-works.com>
parents:
2007
diff
changeset
|
679 |
3308
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3278
diff
changeset
|
680 class RepositoryField(Base, BaseModel): |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3278
diff
changeset
|
681 __tablename__ = 'repositories_fields' |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3278
diff
changeset
|
682 __table_args__ = ( |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3278
diff
changeset
|
683 UniqueConstraint('repository_id', 'field_key'), # no-multi field |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3278
diff
changeset
|
684 {'extend_existing': True, 'mysql_engine': 'InnoDB', |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3278
diff
changeset
|
685 'mysql_charset': 'utf8'}, |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3278
diff
changeset
|
686 ) |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3278
diff
changeset
|
687 PREFIX = 'ex_' # prefix used in form to not conflict with already existing fields |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3278
diff
changeset
|
688 |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3278
diff
changeset
|
689 repo_field_id = Column("repo_field_id", Integer(), nullable=False, unique=True, default=None, primary_key=True) |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3278
diff
changeset
|
690 repository_id = Column("repository_id", Integer(), ForeignKey('repositories.repo_id'), nullable=False, unique=None, default=None) |
3361
14556b463177
mysql indexed keys cannot be larger thatn 256 chars, but 250 is enough for this purpose
Marcin Kuzminski <marcin@python-works.com>
parents:
3308
diff
changeset
|
691 field_key = Column("field_key", String(250, convert_unicode=False, assert_unicode=None)) |
3308
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3278
diff
changeset
|
692 field_label = Column("field_label", String(1024, convert_unicode=False, assert_unicode=None), nullable=False) |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3278
diff
changeset
|
693 field_value = Column("field_value", String(10000, convert_unicode=False, assert_unicode=None), nullable=False) |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3278
diff
changeset
|
694 field_desc = Column("field_desc", String(1024, convert_unicode=False, assert_unicode=None), nullable=False) |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3278
diff
changeset
|
695 field_type = Column("field_type", String(256), nullable=False, unique=None) |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3278
diff
changeset
|
696 created_on = Column('created_on', DateTime(timezone=False), nullable=False, default=datetime.datetime.now) |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3278
diff
changeset
|
697 |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3278
diff
changeset
|
698 repository = relationship('Repository') |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3278
diff
changeset
|
699 |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3278
diff
changeset
|
700 @property |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3278
diff
changeset
|
701 def field_key_prefixed(self): |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3278
diff
changeset
|
702 return 'ex_%s' % self.field_key |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3278
diff
changeset
|
703 |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3278
diff
changeset
|
704 @classmethod |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3278
diff
changeset
|
705 def un_prefix_key(cls, key): |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3278
diff
changeset
|
706 if key.startswith(cls.PREFIX): |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3278
diff
changeset
|
707 return key[len(cls.PREFIX):] |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3278
diff
changeset
|
708 return key |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3278
diff
changeset
|
709 |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3278
diff
changeset
|
710 @classmethod |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3278
diff
changeset
|
711 def get_by_key_name(cls, key, repo): |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3278
diff
changeset
|
712 row = cls.query()\ |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3278
diff
changeset
|
713 .filter(cls.repository == repo)\ |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3278
diff
changeset
|
714 .filter(cls.field_key == key).scalar() |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3278
diff
changeset
|
715 return row |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3278
diff
changeset
|
716 |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3278
diff
changeset
|
717 |
1593 | 718 class Repository(Base, BaseModel): |
234
a0116e944da1
changed naming convention for db modules.
Marcin Kuzminski <marcin@python-works.com>
parents:
232
diff
changeset
|
719 __tablename__ = 'repositories' |
1958
7e4b3d3a9c5c
renamed repo groups table
Marcin Kuzminski <marcin@python-works.com>
parents:
1950
diff
changeset
|
720 __table_args__ = ( |
1963
9bbde54232dc
white space cleanup
Marcin Kuzminski <marcin@python-works.com>
parents:
1960
diff
changeset
|
721 UniqueConstraint('repo_name'), |
2726
aa17c7a1b8a5
Implemented basic locking functionality.
Marcin Kuzminski <marcin@python-works.com>
parents:
2724
diff
changeset
|
722 Index('r_repo_name_idx', 'repo_name'), |
2356
2da7b5984ae5
typo fix + code garden
Marcin Kuzminski <marcin@python-works.com>
parents:
2352
diff
changeset
|
723 {'extend_existing': True, 'mysql_engine': 'InnoDB', |
2149 | 724 'mysql_charset': 'utf8'}, |
1958
7e4b3d3a9c5c
renamed repo groups table
Marcin Kuzminski <marcin@python-works.com>
parents:
1950
diff
changeset
|
725 ) |
1081
70bf0be59653
fixed Session problems in model class functions
Marcin Kuzminski <marcin@python-works.com>
parents:
1065
diff
changeset
|
726 |
1594 | 727 repo_id = Column("repo_id", Integer(), nullable=False, unique=True, default=None, primary_key=True) |
2588
32dd6896abcf
added status column to pull request + some small refactoring of models
Marcin Kuzminski <marcin@python-works.com>
parents:
2585
diff
changeset
|
728 repo_name = Column("repo_name", String(255, convert_unicode=False, assert_unicode=None), nullable=False, unique=True, default=None) |
32dd6896abcf
added status column to pull request + some small refactoring of models
Marcin Kuzminski <marcin@python-works.com>
parents:
2585
diff
changeset
|
729 clone_uri = Column("clone_uri", String(255, convert_unicode=False, assert_unicode=None), nullable=True, unique=False, default=None) |
32dd6896abcf
added status column to pull request + some small refactoring of models
Marcin Kuzminski <marcin@python-works.com>
parents:
2585
diff
changeset
|
730 repo_type = Column("repo_type", String(255, convert_unicode=False, assert_unicode=None), nullable=False, unique=False, default=None) |
1594 | 731 user_id = Column("user_id", Integer(), ForeignKey('users.user_id'), nullable=False, unique=False, default=None) |
732 private = Column("private", Boolean(), nullable=True, unique=None, default=None) | |
733 enable_statistics = Column("statistics", Boolean(), nullable=True, unique=None, default=True) | |
734 enable_downloads = Column("downloads", Boolean(), nullable=True, unique=None, default=True) | |
2588
32dd6896abcf
added status column to pull request + some small refactoring of models
Marcin Kuzminski <marcin@python-works.com>
parents:
2585
diff
changeset
|
735 description = Column("description", String(10000, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None) |
1594 | 736 created_on = Column('created_on', DateTime(timezone=False), nullable=True, unique=None, default=datetime.datetime.now) |
2797
c9baaacb670a
Remove null from revision column as for comments inside pull requests to work properly
Marcin Kuzminski <marcin@python-works.com>
parents:
2791
diff
changeset
|
737 updated_on = Column('updated_on', DateTime(timezone=False), nullable=True, unique=None, default=datetime.datetime.now) |
2588
32dd6896abcf
added status column to pull request + some small refactoring of models
Marcin Kuzminski <marcin@python-works.com>
parents:
2585
diff
changeset
|
738 landing_rev = Column("landing_revision", String(255, convert_unicode=False, assert_unicode=None), nullable=False, unique=False, default=None) |
2726
aa17c7a1b8a5
Implemented basic locking functionality.
Marcin Kuzminski <marcin@python-works.com>
parents:
2724
diff
changeset
|
739 enable_locking = Column("enable_locking", Boolean(), nullable=False, unique=None, default=False) |
aa17c7a1b8a5
Implemented basic locking functionality.
Marcin Kuzminski <marcin@python-works.com>
parents:
2724
diff
changeset
|
740 _locked = Column("locked", String(255, convert_unicode=False, assert_unicode=None), nullable=True, unique=False, default=None) |
3147
8182ebed2922
Added full last changeset info to lightweight dashboard
Marcin Kuzminski <marcin@python-works.com>
parents:
3146
diff
changeset
|
741 _changeset_cache = Column("changeset_cache", LargeBinary(), nullable=True) #JSON data |
1301
7e75af301842
Added simple forks page, resolves issue #179
Marcin Kuzminski <marcin@python-works.com>
parents:
1292
diff
changeset
|
742 |
1594 | 743 fork_id = Column("fork_id", Integer(), ForeignKey('repositories.repo_id'), nullable=True, unique=False, default=None) |
744 group_id = Column("group_id", Integer(), ForeignKey('groups.group_id'), nullable=True, unique=False, default=None) | |
631
05528ad948c4
Hacking for git support,and new faster repo scan
Marcin Kuzminski <marcin@python-works.com>
parents:
549
diff
changeset
|
745 |
1593 | 746 user = relationship('User') |
1594 | 747 fork = relationship('Repository', remote_side=repo_id) |
1633
2c0d35e336b5
refactoring of models names for repoGroup permissions
Marcin Kuzminski <marcin@python-works.com>
parents:
1607
diff
changeset
|
748 group = relationship('RepoGroup') |
2c0d35e336b5
refactoring of models names for repoGroup permissions
Marcin Kuzminski <marcin@python-works.com>
parents:
1607
diff
changeset
|
749 repo_to_perm = relationship('UserRepoToPerm', cascade='all', order_by='UserRepoToPerm.repo_to_perm_id') |
1594 | 750 users_group_to_perm = relationship('UsersGroupRepoToPerm', cascade='all') |
751 stats = relationship('Statistics', cascade='all', uselist=False) | |
667
56a8434a88cc
fixes #51 deleting a repo didn't delete it's dependent db entries.
Marcin Kuzminski <marcin@python-works.com>
parents:
658
diff
changeset
|
752 |
2674
a221706dab50
merged + fixed pull request #62: Implemented metatags and visualisation options.
Marcin Kuzminski <marcin@python-works.com>
parents:
2668
diff
changeset
|
753 followers = relationship('UserFollowing', |
a221706dab50
merged + fixed pull request #62: Implemented metatags and visualisation options.
Marcin Kuzminski <marcin@python-works.com>
parents:
2668
diff
changeset
|
754 primaryjoin='UserFollowing.follows_repo_id==Repository.repo_id', |
2666
c51fb1da6df2
cascade fixes for comments/pull-requests/reviewers
Marcin Kuzminski <marcin@python-works.com>
parents:
2665
diff
changeset
|
755 cascade='all') |
3308
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3278
diff
changeset
|
756 extra_fields = relationship('RepositoryField', |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3278
diff
changeset
|
757 cascade="all, delete, delete-orphan") |
734
49eb69d78988
implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents:
713
diff
changeset
|
758 |
1747
8804715404c9
implements #193 journal stores information about deleting of repos
Marcin Kuzminski <marcin@python-works.com>
parents:
1744
diff
changeset
|
759 logs = relationship('UserLog') |
2665
81a17ef4afc0
cascade delete comments when deleting repo, else it's a error preventing deletion
Marcin Kuzminski <marcin@python-works.com>
parents:
2639
diff
changeset
|
760 comments = relationship('ChangesetComment', cascade="all, delete, delete-orphan") |
970
1a5c41e4bb02
fixees for #106 relation issues on databases different than sqlite
Marcin Kuzminski <marcin@python-works.com>
parents:
962
diff
changeset
|
761 |
2666
c51fb1da6df2
cascade fixes for comments/pull-requests/reviewers
Marcin Kuzminski <marcin@python-works.com>
parents:
2665
diff
changeset
|
762 pull_requests_org = relationship('PullRequest', |
c51fb1da6df2
cascade fixes for comments/pull-requests/reviewers
Marcin Kuzminski <marcin@python-works.com>
parents:
2665
diff
changeset
|
763 primaryjoin='PullRequest.org_repo_id==Repository.repo_id', |
c51fb1da6df2
cascade fixes for comments/pull-requests/reviewers
Marcin Kuzminski <marcin@python-works.com>
parents:
2665
diff
changeset
|
764 cascade="all, delete, delete-orphan") |
c51fb1da6df2
cascade fixes for comments/pull-requests/reviewers
Marcin Kuzminski <marcin@python-works.com>
parents:
2665
diff
changeset
|
765 |
c51fb1da6df2
cascade fixes for comments/pull-requests/reviewers
Marcin Kuzminski <marcin@python-works.com>
parents:
2665
diff
changeset
|
766 pull_requests_other = relationship('PullRequest', |
c51fb1da6df2
cascade fixes for comments/pull-requests/reviewers
Marcin Kuzminski <marcin@python-works.com>
parents:
2665
diff
changeset
|
767 primaryjoin='PullRequest.other_repo_id==Repository.repo_id', |
c51fb1da6df2
cascade fixes for comments/pull-requests/reviewers
Marcin Kuzminski <marcin@python-works.com>
parents:
2665
diff
changeset
|
768 cascade="all, delete, delete-orphan") |
c51fb1da6df2
cascade fixes for comments/pull-requests/reviewers
Marcin Kuzminski <marcin@python-works.com>
parents:
2665
diff
changeset
|
769 |
2156
a27e4d44237e
Use __unicode__ instead of __repr__ in models.
Marcin Kuzminski <marcin@python-works.com>
parents:
2152
diff
changeset
|
770 def __unicode__(self): |
2459
9492ab68331f
Initial version of landing revisions ref #483
Marcin Kuzminski <marcin@python-works.com>
parents:
2407
diff
changeset
|
771 return u"<%s('%s:%s')>" % (self.__class__.__name__, self.repo_id, |
2156
a27e4d44237e
Use __unicode__ instead of __repr__ in models.
Marcin Kuzminski <marcin@python-works.com>
parents:
2152
diff
changeset
|
772 self.repo_name) |
878
859bc9e7a15d
Extended repo2db mapper with group creation via directory structures
Marcin Kuzminski <marcin@python-works.com>
parents:
836
diff
changeset
|
773 |
2726
aa17c7a1b8a5
Implemented basic locking functionality.
Marcin Kuzminski <marcin@python-works.com>
parents:
2724
diff
changeset
|
774 @hybrid_property |
aa17c7a1b8a5
Implemented basic locking functionality.
Marcin Kuzminski <marcin@python-works.com>
parents:
2724
diff
changeset
|
775 def locked(self): |
aa17c7a1b8a5
Implemented basic locking functionality.
Marcin Kuzminski <marcin@python-works.com>
parents:
2724
diff
changeset
|
776 # always should return [user_id, timelocked] |
aa17c7a1b8a5
Implemented basic locking functionality.
Marcin Kuzminski <marcin@python-works.com>
parents:
2724
diff
changeset
|
777 if self._locked: |
aa17c7a1b8a5
Implemented basic locking functionality.
Marcin Kuzminski <marcin@python-works.com>
parents:
2724
diff
changeset
|
778 _lock_info = self._locked.split(':') |
aa17c7a1b8a5
Implemented basic locking functionality.
Marcin Kuzminski <marcin@python-works.com>
parents:
2724
diff
changeset
|
779 return int(_lock_info[0]), _lock_info[1] |
aa17c7a1b8a5
Implemented basic locking functionality.
Marcin Kuzminski <marcin@python-works.com>
parents:
2724
diff
changeset
|
780 return [None, None] |
aa17c7a1b8a5
Implemented basic locking functionality.
Marcin Kuzminski <marcin@python-works.com>
parents:
2724
diff
changeset
|
781 |
aa17c7a1b8a5
Implemented basic locking functionality.
Marcin Kuzminski <marcin@python-works.com>
parents:
2724
diff
changeset
|
782 @locked.setter |
aa17c7a1b8a5
Implemented basic locking functionality.
Marcin Kuzminski <marcin@python-works.com>
parents:
2724
diff
changeset
|
783 def locked(self, val): |
aa17c7a1b8a5
Implemented basic locking functionality.
Marcin Kuzminski <marcin@python-works.com>
parents:
2724
diff
changeset
|
784 if val and isinstance(val, (list, tuple)): |
aa17c7a1b8a5
Implemented basic locking functionality.
Marcin Kuzminski <marcin@python-works.com>
parents:
2724
diff
changeset
|
785 self._locked = ':'.join(map(str, val)) |
aa17c7a1b8a5
Implemented basic locking functionality.
Marcin Kuzminski <marcin@python-works.com>
parents:
2724
diff
changeset
|
786 else: |
aa17c7a1b8a5
Implemented basic locking functionality.
Marcin Kuzminski <marcin@python-works.com>
parents:
2724
diff
changeset
|
787 self._locked = None |
aa17c7a1b8a5
Implemented basic locking functionality.
Marcin Kuzminski <marcin@python-works.com>
parents:
2724
diff
changeset
|
788 |
3147
8182ebed2922
Added full last changeset info to lightweight dashboard
Marcin Kuzminski <marcin@python-works.com>
parents:
3146
diff
changeset
|
789 @hybrid_property |
8182ebed2922
Added full last changeset info to lightweight dashboard
Marcin Kuzminski <marcin@python-works.com>
parents:
3146
diff
changeset
|
790 def changeset_cache(self): |
8182ebed2922
Added full last changeset info to lightweight dashboard
Marcin Kuzminski <marcin@python-works.com>
parents:
3146
diff
changeset
|
791 from rhodecode.lib.vcs.backends.base import EmptyChangeset |
8182ebed2922
Added full last changeset info to lightweight dashboard
Marcin Kuzminski <marcin@python-works.com>
parents:
3146
diff
changeset
|
792 dummy = EmptyChangeset().__json__() |
8182ebed2922
Added full last changeset info to lightweight dashboard
Marcin Kuzminski <marcin@python-works.com>
parents:
3146
diff
changeset
|
793 if not self._changeset_cache: |
8182ebed2922
Added full last changeset info to lightweight dashboard
Marcin Kuzminski <marcin@python-works.com>
parents:
3146
diff
changeset
|
794 return dummy |
8182ebed2922
Added full last changeset info to lightweight dashboard
Marcin Kuzminski <marcin@python-works.com>
parents:
3146
diff
changeset
|
795 try: |
8182ebed2922
Added full last changeset info to lightweight dashboard
Marcin Kuzminski <marcin@python-works.com>
parents:
3146
diff
changeset
|
796 return json.loads(self._changeset_cache) |
8182ebed2922
Added full last changeset info to lightweight dashboard
Marcin Kuzminski <marcin@python-works.com>
parents:
3146
diff
changeset
|
797 except TypeError: |
8182ebed2922
Added full last changeset info to lightweight dashboard
Marcin Kuzminski <marcin@python-works.com>
parents:
3146
diff
changeset
|
798 return dummy |
8182ebed2922
Added full last changeset info to lightweight dashboard
Marcin Kuzminski <marcin@python-works.com>
parents:
3146
diff
changeset
|
799 |
8182ebed2922
Added full last changeset info to lightweight dashboard
Marcin Kuzminski <marcin@python-works.com>
parents:
3146
diff
changeset
|
800 @changeset_cache.setter |
8182ebed2922
Added full last changeset info to lightweight dashboard
Marcin Kuzminski <marcin@python-works.com>
parents:
3146
diff
changeset
|
801 def changeset_cache(self, val): |
8182ebed2922
Added full last changeset info to lightweight dashboard
Marcin Kuzminski <marcin@python-works.com>
parents:
3146
diff
changeset
|
802 try: |
8182ebed2922
Added full last changeset info to lightweight dashboard
Marcin Kuzminski <marcin@python-works.com>
parents:
3146
diff
changeset
|
803 self._changeset_cache = json.dumps(val) |
8182ebed2922
Added full last changeset info to lightweight dashboard
Marcin Kuzminski <marcin@python-works.com>
parents:
3146
diff
changeset
|
804 except: |
8182ebed2922
Added full last changeset info to lightweight dashboard
Marcin Kuzminski <marcin@python-works.com>
parents:
3146
diff
changeset
|
805 log.error(traceback.format_exc()) |
8182ebed2922
Added full last changeset info to lightweight dashboard
Marcin Kuzminski <marcin@python-works.com>
parents:
3146
diff
changeset
|
806 |
1065
5d676b6ab71c
Moved BaseModel into base class for declarative base. Added some handy methods into
Marcin Kuzminski <marcin@python-works.com>
parents:
1039
diff
changeset
|
807 @classmethod |
1593 | 808 def url_sep(cls): |
2339
79b3c9c66c54
Added optional repo_name into issue tracker url to get just the name of repo without group prefix
Marcin Kuzminski <marcin@python-works.com>
parents:
2251
diff
changeset
|
809 return URL_SEP |
1065
5d676b6ab71c
Moved BaseModel into base class for declarative base. Added some handy methods into
Marcin Kuzminski <marcin@python-works.com>
parents:
1039
diff
changeset
|
810 |
1554
e7c6341ad3cb
fixes #245 Rescan of the repositories on Windows
Marcin Kuzminski <marcin@python-works.com>
parents:
1547
diff
changeset
|
811 @classmethod |
3152
46234d2d388f
fixed issues with getting repos by path on windows
Marcin Kuzminski <marcin@python-works.com>
parents:
3147
diff
changeset
|
812 def normalize_repo_name(cls, repo_name): |
46234d2d388f
fixed issues with getting repos by path on windows
Marcin Kuzminski <marcin@python-works.com>
parents:
3147
diff
changeset
|
813 """ |
46234d2d388f
fixed issues with getting repos by path on windows
Marcin Kuzminski <marcin@python-works.com>
parents:
3147
diff
changeset
|
814 Normalizes os specific repo_name to the format internally stored inside |
46234d2d388f
fixed issues with getting repos by path on windows
Marcin Kuzminski <marcin@python-works.com>
parents:
3147
diff
changeset
|
815 dabatabase using URL_SEP |
46234d2d388f
fixed issues with getting repos by path on windows
Marcin Kuzminski <marcin@python-works.com>
parents:
3147
diff
changeset
|
816 |
46234d2d388f
fixed issues with getting repos by path on windows
Marcin Kuzminski <marcin@python-works.com>
parents:
3147
diff
changeset
|
817 :param cls: |
46234d2d388f
fixed issues with getting repos by path on windows
Marcin Kuzminski <marcin@python-works.com>
parents:
3147
diff
changeset
|
818 :param repo_name: |
46234d2d388f
fixed issues with getting repos by path on windows
Marcin Kuzminski <marcin@python-works.com>
parents:
3147
diff
changeset
|
819 """ |
46234d2d388f
fixed issues with getting repos by path on windows
Marcin Kuzminski <marcin@python-works.com>
parents:
3147
diff
changeset
|
820 return cls.url_sep().join(repo_name.split(os.sep)) |
46234d2d388f
fixed issues with getting repos by path on windows
Marcin Kuzminski <marcin@python-works.com>
parents:
3147
diff
changeset
|
821 |
46234d2d388f
fixed issues with getting repos by path on windows
Marcin Kuzminski <marcin@python-works.com>
parents:
3147
diff
changeset
|
822 @classmethod |
1593 | 823 def get_by_repo_name(cls, repo_name): |
2520
a1e156503afe
Fixed calls to Session in db model
Marcin Kuzminski <marcin@python-works.com>
parents:
2510
diff
changeset
|
824 q = Session().query(cls).filter(cls.repo_name == repo_name) |
1593 | 825 q = q.options(joinedload(Repository.fork))\ |
826 .options(joinedload(Repository.user))\ | |
827 .options(joinedload(Repository.group)) | |
1749
8ecc6b8229a5
commit less models
Marcin Kuzminski <marcin@python-works.com>
parents:
1747
diff
changeset
|
828 return q.scalar() |
1301
7e75af301842
Added simple forks page, resolves issue #179
Marcin Kuzminski <marcin@python-works.com>
parents:
1292
diff
changeset
|
829 |
7e75af301842
Added simple forks page, resolves issue #179
Marcin Kuzminski <marcin@python-works.com>
parents:
1292
diff
changeset
|
830 @classmethod |
2400
e87c6aa9c5e7
Add method for fetching repos by full path
Marcin Kuzminski <marcin@python-works.com>
parents:
2356
diff
changeset
|
831 def get_by_full_path(cls, repo_full_path): |
e87c6aa9c5e7
Add method for fetching repos by full path
Marcin Kuzminski <marcin@python-works.com>
parents:
2356
diff
changeset
|
832 repo_name = repo_full_path.split(cls.base_path(), 1)[-1] |
3152
46234d2d388f
fixed issues with getting repos by path on windows
Marcin Kuzminski <marcin@python-works.com>
parents:
3147
diff
changeset
|
833 repo_name = cls.normalize_repo_name(repo_name) |
2400
e87c6aa9c5e7
Add method for fetching repos by full path
Marcin Kuzminski <marcin@python-works.com>
parents:
2356
diff
changeset
|
834 return cls.get_by_repo_name(repo_name.strip(URL_SEP)) |
e87c6aa9c5e7
Add method for fetching repos by full path
Marcin Kuzminski <marcin@python-works.com>
parents:
2356
diff
changeset
|
835 |
e87c6aa9c5e7
Add method for fetching repos by full path
Marcin Kuzminski <marcin@python-works.com>
parents:
2356
diff
changeset
|
836 @classmethod |
1593 | 837 def get_repo_forks(cls, repo_id): |
838 return cls.query().filter(Repository.fork_id == repo_id) | |
1301
7e75af301842
Added simple forks page, resolves issue #179
Marcin Kuzminski <marcin@python-works.com>
parents:
1292
diff
changeset
|
839 |
1508
4aba7be311e8
API added checks for a valid repository on pull command
Marcin Kuzminski <marcin@python-works.com>
parents:
1500
diff
changeset
|
840 @classmethod |
1593 | 841 def base_path(cls): |
1508
4aba7be311e8
API added checks for a valid repository on pull command
Marcin Kuzminski <marcin@python-works.com>
parents:
1500
diff
changeset
|
842 """ |
4aba7be311e8
API added checks for a valid repository on pull command
Marcin Kuzminski <marcin@python-works.com>
parents:
1500
diff
changeset
|
843 Returns base path when all repos are stored |
1587
8898a79ac628
Implement all CRUD API operation for repo
Nicolas VINOT <aeris@imirhil.fr>
parents:
1586
diff
changeset
|
844 |
1508
4aba7be311e8
API added checks for a valid repository on pull command
Marcin Kuzminski <marcin@python-works.com>
parents:
1500
diff
changeset
|
845 :param cls: |
4aba7be311e8
API added checks for a valid repository on pull command
Marcin Kuzminski <marcin@python-works.com>
parents:
1500
diff
changeset
|
846 """ |
2520
a1e156503afe
Fixed calls to Session in db model
Marcin Kuzminski <marcin@python-works.com>
parents:
2510
diff
changeset
|
847 q = Session().query(RhodeCodeUi)\ |
1728
07e56179633e
- fixes celery sqlalchemy session issues for async forking
Marcin Kuzminski <marcin@python-works.com>
parents:
1727
diff
changeset
|
848 .filter(RhodeCodeUi.ui_key == cls.url_sep()) |
07e56179633e
- fixes celery sqlalchemy session issues for async forking
Marcin Kuzminski <marcin@python-works.com>
parents:
1727
diff
changeset
|
849 q = q.options(FromCache("sql_cache_short", "repository_repo_path")) |
1508
4aba7be311e8
API added checks for a valid repository on pull command
Marcin Kuzminski <marcin@python-works.com>
parents:
1500
diff
changeset
|
850 return q.one().ui_value |
4aba7be311e8
API added checks for a valid repository on pull command
Marcin Kuzminski <marcin@python-works.com>
parents:
1500
diff
changeset
|
851 |
1113
c1eda8ec4a46
added clone_uri,api_key into models. Fixed models for mysql compatibilty
Marcin Kuzminski <marcin@python-works.com>
parents:
1088
diff
changeset
|
852 @property |
2395
b262e349a7a5
created pull-request overview
Marcin Kuzminski <marcin@python-works.com>
parents:
2392
diff
changeset
|
853 def forks(self): |
b262e349a7a5
created pull-request overview
Marcin Kuzminski <marcin@python-works.com>
parents:
2392
diff
changeset
|
854 """ |
b262e349a7a5
created pull-request overview
Marcin Kuzminski <marcin@python-works.com>
parents:
2392
diff
changeset
|
855 Return forks of this repo |
b262e349a7a5
created pull-request overview
Marcin Kuzminski <marcin@python-works.com>
parents:
2392
diff
changeset
|
856 """ |
b262e349a7a5
created pull-request overview
Marcin Kuzminski <marcin@python-works.com>
parents:
2392
diff
changeset
|
857 return Repository.get_repo_forks(self.repo_id) |
b262e349a7a5
created pull-request overview
Marcin Kuzminski <marcin@python-works.com>
parents:
2392
diff
changeset
|
858 |
b262e349a7a5
created pull-request overview
Marcin Kuzminski <marcin@python-works.com>
parents:
2392
diff
changeset
|
859 @property |
b262e349a7a5
created pull-request overview
Marcin Kuzminski <marcin@python-works.com>
parents:
2392
diff
changeset
|
860 def parent(self): |
b262e349a7a5
created pull-request overview
Marcin Kuzminski <marcin@python-works.com>
parents:
2392
diff
changeset
|
861 """ |
b262e349a7a5
created pull-request overview
Marcin Kuzminski <marcin@python-works.com>
parents:
2392
diff
changeset
|
862 Returns fork parent |
b262e349a7a5
created pull-request overview
Marcin Kuzminski <marcin@python-works.com>
parents:
2392
diff
changeset
|
863 """ |
b262e349a7a5
created pull-request overview
Marcin Kuzminski <marcin@python-works.com>
parents:
2392
diff
changeset
|
864 return self.fork |
b262e349a7a5
created pull-request overview
Marcin Kuzminski <marcin@python-works.com>
parents:
2392
diff
changeset
|
865 |
b262e349a7a5
created pull-request overview
Marcin Kuzminski <marcin@python-works.com>
parents:
2392
diff
changeset
|
866 @property |
1593 | 867 def just_name(self): |
868 return self.repo_name.split(Repository.url_sep())[-1] | |
1155
37a9421f32a0
Added handy methods to Repository model for fetching groups with parents
Marcin Kuzminski <marcin@python-works.com>
parents:
1113
diff
changeset
|
869 |
37a9421f32a0
Added handy methods to Repository model for fetching groups with parents
Marcin Kuzminski <marcin@python-works.com>
parents:
1113
diff
changeset
|
870 @property |
1593 | 871 def groups_with_parents(self): |
1155
37a9421f32a0
Added handy methods to Repository model for fetching groups with parents
Marcin Kuzminski <marcin@python-works.com>
parents:
1113
diff
changeset
|
872 groups = [] |
37a9421f32a0
Added handy methods to Repository model for fetching groups with parents
Marcin Kuzminski <marcin@python-works.com>
parents:
1113
diff
changeset
|
873 if self.group is None: |
37a9421f32a0
Added handy methods to Repository model for fetching groups with parents
Marcin Kuzminski <marcin@python-works.com>
parents:
1113
diff
changeset
|
874 return groups |
37a9421f32a0
Added handy methods to Repository model for fetching groups with parents
Marcin Kuzminski <marcin@python-works.com>
parents:
1113
diff
changeset
|
875 |
37a9421f32a0
Added handy methods to Repository model for fetching groups with parents
Marcin Kuzminski <marcin@python-works.com>
parents:
1113
diff
changeset
|
876 cur_gr = self.group |
1593 | 877 groups.insert(0, cur_gr) |
1155
37a9421f32a0
Added handy methods to Repository model for fetching groups with parents
Marcin Kuzminski <marcin@python-works.com>
parents:
1113
diff
changeset
|
878 while 1: |
1593 | 879 gr = getattr(cur_gr, 'parent_group', None) |
1155
37a9421f32a0
Added handy methods to Repository model for fetching groups with parents
Marcin Kuzminski <marcin@python-works.com>
parents:
1113
diff
changeset
|
880 cur_gr = cur_gr.parent_group |
37a9421f32a0
Added handy methods to Repository model for fetching groups with parents
Marcin Kuzminski <marcin@python-works.com>
parents:
1113
diff
changeset
|
881 if gr is None: |
37a9421f32a0
Added handy methods to Repository model for fetching groups with parents
Marcin Kuzminski <marcin@python-works.com>
parents:
1113
diff
changeset
|
882 break |
1593 | 883 groups.insert(0, gr) |
1155
37a9421f32a0
Added handy methods to Repository model for fetching groups with parents
Marcin Kuzminski <marcin@python-works.com>
parents:
1113
diff
changeset
|
884 |
37a9421f32a0
Added handy methods to Repository model for fetching groups with parents
Marcin Kuzminski <marcin@python-works.com>
parents:
1113
diff
changeset
|
885 return groups |
37a9421f32a0
Added handy methods to Repository model for fetching groups with parents
Marcin Kuzminski <marcin@python-works.com>
parents:
1113
diff
changeset
|
886 |
37a9421f32a0
Added handy methods to Repository model for fetching groups with parents
Marcin Kuzminski <marcin@python-works.com>
parents:
1113
diff
changeset
|
887 @property |
1593 | 888 def groups_and_repo(self): |
1155
37a9421f32a0
Added handy methods to Repository model for fetching groups with parents
Marcin Kuzminski <marcin@python-works.com>
parents:
1113
diff
changeset
|
889 return self.groups_with_parents, self.just_name |
1113
c1eda8ec4a46
added clone_uri,api_key into models. Fixed models for mysql compatibilty
Marcin Kuzminski <marcin@python-works.com>
parents:
1088
diff
changeset
|
890 |
1366
9c0f5d558789
fixes #200, rewrote the whole caching mechanism to get rid of such problems. Now cached instances are attached
Marcin Kuzminski <marcin@python-works.com>
parents:
1360
diff
changeset
|
891 @LazyProperty |
1593 | 892 def repo_path(self): |
1366
9c0f5d558789
fixes #200, rewrote the whole caching mechanism to get rid of such problems. Now cached instances are attached
Marcin Kuzminski <marcin@python-works.com>
parents:
1360
diff
changeset
|
893 """ |
9c0f5d558789
fixes #200, rewrote the whole caching mechanism to get rid of such problems. Now cached instances are attached
Marcin Kuzminski <marcin@python-works.com>
parents:
1360
diff
changeset
|
894 Returns base full path for that repository means where it actually |
9c0f5d558789
fixes #200, rewrote the whole caching mechanism to get rid of such problems. Now cached instances are attached
Marcin Kuzminski <marcin@python-works.com>
parents:
1360
diff
changeset
|
895 exists on a filesystem |
9c0f5d558789
fixes #200, rewrote the whole caching mechanism to get rid of such problems. Now cached instances are attached
Marcin Kuzminski <marcin@python-works.com>
parents:
1360
diff
changeset
|
896 """ |
2520
a1e156503afe
Fixed calls to Session in db model
Marcin Kuzminski <marcin@python-works.com>
parents:
2510
diff
changeset
|
897 q = Session().query(RhodeCodeUi).filter(RhodeCodeUi.ui_key == |
1593 | 898 Repository.url_sep()) |
1727
8e9f51091229
fixed caching query on repos path
Marcin Kuzminski <marcin@python-works.com>
parents:
1723
diff
changeset
|
899 q = q.options(FromCache("sql_cache_short", "repository_repo_path")) |
1368
04b43168742d
adde short cache for repo_path
Marcin Kuzminski <marcin@python-works.com>
parents:
1366
diff
changeset
|
900 return q.one().ui_value |
1366
9c0f5d558789
fixes #200, rewrote the whole caching mechanism to get rid of such problems. Now cached instances are attached
Marcin Kuzminski <marcin@python-works.com>
parents:
1360
diff
changeset
|
901 |
9c0f5d558789
fixes #200, rewrote the whole caching mechanism to get rid of such problems. Now cached instances are attached
Marcin Kuzminski <marcin@python-works.com>
parents:
1360
diff
changeset
|
902 @property |
1593 | 903 def repo_full_path(self): |
1366
9c0f5d558789
fixes #200, rewrote the whole caching mechanism to get rid of such problems. Now cached instances are attached
Marcin Kuzminski <marcin@python-works.com>
parents:
1360
diff
changeset
|
904 p = [self.repo_path] |
9c0f5d558789
fixes #200, rewrote the whole caching mechanism to get rid of such problems. Now cached instances are attached
Marcin Kuzminski <marcin@python-works.com>
parents:
1360
diff
changeset
|
905 # we need to split the name by / since this is how we store the |
9c0f5d558789
fixes #200, rewrote the whole caching mechanism to get rid of such problems. Now cached instances are attached
Marcin Kuzminski <marcin@python-works.com>
parents:
1360
diff
changeset
|
906 # names in the database, but that eventually needs to be converted |
9c0f5d558789
fixes #200, rewrote the whole caching mechanism to get rid of such problems. Now cached instances are attached
Marcin Kuzminski <marcin@python-works.com>
parents:
1360
diff
changeset
|
907 # into a valid system path |
1593 | 908 p += self.repo_name.split(Repository.url_sep()) |
909 return os.path.join(*p) | |
1366
9c0f5d558789
fixes #200, rewrote the whole caching mechanism to get rid of such problems. Now cached instances are attached
Marcin Kuzminski <marcin@python-works.com>
parents:
1360
diff
changeset
|
910 |
2809
070d2eacd48b
Show cache keys in admin settings of repository
Marcin Kuzminski <marcin@python-works.com>
parents:
2808
diff
changeset
|
911 @property |
070d2eacd48b
Show cache keys in admin settings of repository
Marcin Kuzminski <marcin@python-works.com>
parents:
2808
diff
changeset
|
912 def cache_keys(self): |
070d2eacd48b
Show cache keys in admin settings of repository
Marcin Kuzminski <marcin@python-works.com>
parents:
2808
diff
changeset
|
913 """ |
070d2eacd48b
Show cache keys in admin settings of repository
Marcin Kuzminski <marcin@python-works.com>
parents:
2808
diff
changeset
|
914 Returns associated cache keys for that repo |
070d2eacd48b
Show cache keys in admin settings of repository
Marcin Kuzminski <marcin@python-works.com>
parents:
2808
diff
changeset
|
915 """ |
070d2eacd48b
Show cache keys in admin settings of repository
Marcin Kuzminski <marcin@python-works.com>
parents:
2808
diff
changeset
|
916 return CacheInvalidation.query()\ |
070d2eacd48b
Show cache keys in admin settings of repository
Marcin Kuzminski <marcin@python-works.com>
parents:
2808
diff
changeset
|
917 .filter(CacheInvalidation.cache_args == self.repo_name)\ |
070d2eacd48b
Show cache keys in admin settings of repository
Marcin Kuzminski <marcin@python-works.com>
parents:
2808
diff
changeset
|
918 .order_by(CacheInvalidation.cache_key)\ |
070d2eacd48b
Show cache keys in admin settings of repository
Marcin Kuzminski <marcin@python-works.com>
parents:
2808
diff
changeset
|
919 .all() |
070d2eacd48b
Show cache keys in admin settings of repository
Marcin Kuzminski <marcin@python-works.com>
parents:
2808
diff
changeset
|
920 |
1593 | 921 def get_new_name(self, repo_name): |
1539
bd604cf75c5a
fixes #260 Put repo in group, then move group to another group -> repo becomes unavailable
Marcin Kuzminski <marcin@python-works.com>
parents:
1538
diff
changeset
|
922 """ |
bd604cf75c5a
fixes #260 Put repo in group, then move group to another group -> repo becomes unavailable
Marcin Kuzminski <marcin@python-works.com>
parents:
1538
diff
changeset
|
923 returns new full repository name based on assigned group and new new |
1591 | 924 |
1539
bd604cf75c5a
fixes #260 Put repo in group, then move group to another group -> repo becomes unavailable
Marcin Kuzminski <marcin@python-works.com>
parents:
1538
diff
changeset
|
925 :param group_name: |
bd604cf75c5a
fixes #260 Put repo in group, then move group to another group -> repo becomes unavailable
Marcin Kuzminski <marcin@python-works.com>
parents:
1538
diff
changeset
|
926 """ |
bd604cf75c5a
fixes #260 Put repo in group, then move group to another group -> repo becomes unavailable
Marcin Kuzminski <marcin@python-works.com>
parents:
1538
diff
changeset
|
927 path_prefix = self.group.full_path_splitted if self.group else [] |
1593 | 928 return Repository.url_sep().join(path_prefix + [repo_name]) |
1539
bd604cf75c5a
fixes #260 Put repo in group, then move group to another group -> repo becomes unavailable
Marcin Kuzminski <marcin@python-works.com>
parents:
1538
diff
changeset
|
929 |
1366
9c0f5d558789
fixes #200, rewrote the whole caching mechanism to get rid of such problems. Now cached instances are attached
Marcin Kuzminski <marcin@python-works.com>
parents:
1360
diff
changeset
|
930 @property |
1593 | 931 def _ui(self): |
1366
9c0f5d558789
fixes #200, rewrote the whole caching mechanism to get rid of such problems. Now cached instances are attached
Marcin Kuzminski <marcin@python-works.com>
parents:
1360
diff
changeset
|
932 """ |
9c0f5d558789
fixes #200, rewrote the whole caching mechanism to get rid of such problems. Now cached instances are attached
Marcin Kuzminski <marcin@python-works.com>
parents:
1360
diff
changeset
|
933 Creates an db based ui object for this repository |
9c0f5d558789
fixes #200, rewrote the whole caching mechanism to get rid of such problems. Now cached instances are attached
Marcin Kuzminski <marcin@python-works.com>
parents:
1360
diff
changeset
|
934 """ |
2982
78227b65a358
remove duplicated code for generating UI objects
Marcin Kuzminski <marcin@python-works.com>
parents:
2942
diff
changeset
|
935 from rhodecode.lib.utils import make_ui |
78227b65a358
remove duplicated code for generating UI objects
Marcin Kuzminski <marcin@python-works.com>
parents:
2942
diff
changeset
|
936 return make_ui('db', clear_session=False) |
1366
9c0f5d558789
fixes #200, rewrote the whole caching mechanism to get rid of such problems. Now cached instances are attached
Marcin Kuzminski <marcin@python-works.com>
parents:
1360
diff
changeset
|
937 |
1508
4aba7be311e8
API added checks for a valid repository on pull command
Marcin Kuzminski <marcin@python-works.com>
parents:
1500
diff
changeset
|
938 @classmethod |
2520
a1e156503afe
Fixed calls to Session in db model
Marcin Kuzminski <marcin@python-works.com>
parents:
2510
diff
changeset
|
939 def inject_ui(cls, repo, extras={}): |
a1e156503afe
Fixed calls to Session in db model
Marcin Kuzminski <marcin@python-works.com>
parents:
2510
diff
changeset
|
940 from rhodecode.lib.vcs.backends.hg import MercurialRepository |
a1e156503afe
Fixed calls to Session in db model
Marcin Kuzminski <marcin@python-works.com>
parents:
2510
diff
changeset
|
941 from rhodecode.lib.vcs.backends.git import GitRepository |
a1e156503afe
Fixed calls to Session in db model
Marcin Kuzminski <marcin@python-works.com>
parents:
2510
diff
changeset
|
942 required = (MercurialRepository, GitRepository) |
a1e156503afe
Fixed calls to Session in db model
Marcin Kuzminski <marcin@python-works.com>
parents:
2510
diff
changeset
|
943 if not isinstance(repo, required): |
a1e156503afe
Fixed calls to Session in db model
Marcin Kuzminski <marcin@python-works.com>
parents:
2510
diff
changeset
|
944 raise Exception('repo must be instance of %s' % required) |
a1e156503afe
Fixed calls to Session in db model
Marcin Kuzminski <marcin@python-works.com>
parents:
2510
diff
changeset
|
945 |
a1e156503afe
Fixed calls to Session in db model
Marcin Kuzminski <marcin@python-works.com>
parents:
2510
diff
changeset
|
946 # inject ui extra param to log this action via push logger |
a1e156503afe
Fixed calls to Session in db model
Marcin Kuzminski <marcin@python-works.com>
parents:
2510
diff
changeset
|
947 for k, v in extras.items(): |
a1e156503afe
Fixed calls to Session in db model
Marcin Kuzminski <marcin@python-works.com>
parents:
2510
diff
changeset
|
948 repo._repo.ui.setconfig('rhodecode_extras', k, v) |
a1e156503afe
Fixed calls to Session in db model
Marcin Kuzminski <marcin@python-works.com>
parents:
2510
diff
changeset
|
949 |
a1e156503afe
Fixed calls to Session in db model
Marcin Kuzminski <marcin@python-works.com>
parents:
2510
diff
changeset
|
950 @classmethod |
1593 | 951 def is_valid(cls, repo_name): |
1508
4aba7be311e8
API added checks for a valid repository on pull command
Marcin Kuzminski <marcin@python-works.com>
parents:
1500
diff
changeset
|
952 """ |
4aba7be311e8
API added checks for a valid repository on pull command
Marcin Kuzminski <marcin@python-works.com>
parents:
1500
diff
changeset
|
953 returns True if given repo name is a valid filesystem repository |
1587
8898a79ac628
Implement all CRUD API operation for repo
Nicolas VINOT <aeris@imirhil.fr>
parents:
1586
diff
changeset
|
954 |
1819
9451a569aee5
sphinx doc cleanup
Marcin Kuzminski <marcin@python-works.com>
parents:
1818
diff
changeset
|
955 :param cls: |
9451a569aee5
sphinx doc cleanup
Marcin Kuzminski <marcin@python-works.com>
parents:
1818
diff
changeset
|
956 :param repo_name: |
1508
4aba7be311e8
API added checks for a valid repository on pull command
Marcin Kuzminski <marcin@python-works.com>
parents:
1500
diff
changeset
|
957 """ |
4aba7be311e8
API added checks for a valid repository on pull command
Marcin Kuzminski <marcin@python-works.com>
parents:
1500
diff
changeset
|
958 from rhodecode.lib.utils import is_valid_repo |
4aba7be311e8
API added checks for a valid repository on pull command
Marcin Kuzminski <marcin@python-works.com>
parents:
1500
diff
changeset
|
959 |
1593 | 960 return is_valid_repo(repo_name, cls.base_path()) |
1508
4aba7be311e8
API added checks for a valid repository on pull command
Marcin Kuzminski <marcin@python-works.com>
parents:
1500
diff
changeset
|
961 |
2508
43cb5b6047fd
Added functions for getting API data to repo and user models
Marcin Kuzminski <marcin@python-works.com>
parents:
2506
diff
changeset
|
962 def get_api_data(self): |
43cb5b6047fd
Added functions for getting API data to repo and user models
Marcin Kuzminski <marcin@python-works.com>
parents:
2506
diff
changeset
|
963 """ |
43cb5b6047fd
Added functions for getting API data to repo and user models
Marcin Kuzminski <marcin@python-works.com>
parents:
2506
diff
changeset
|
964 Common function for generating repo api data |
43cb5b6047fd
Added functions for getting API data to repo and user models
Marcin Kuzminski <marcin@python-works.com>
parents:
2506
diff
changeset
|
965 |
43cb5b6047fd
Added functions for getting API data to repo and user models
Marcin Kuzminski <marcin@python-works.com>
parents:
2506
diff
changeset
|
966 """ |
43cb5b6047fd
Added functions for getting API data to repo and user models
Marcin Kuzminski <marcin@python-works.com>
parents:
2506
diff
changeset
|
967 repo = self |
43cb5b6047fd
Added functions for getting API data to repo and user models
Marcin Kuzminski <marcin@python-works.com>
parents:
2506
diff
changeset
|
968 data = dict( |
2510
9059b2d91303
Change return paremeters for get_api_data in user and repo
Marcin Kuzminski <marcin@python-works.com>
parents:
2508
diff
changeset
|
969 repo_id=repo.repo_id, |
2508
43cb5b6047fd
Added functions for getting API data to repo and user models
Marcin Kuzminski <marcin@python-works.com>
parents:
2506
diff
changeset
|
970 repo_name=repo.repo_name, |
43cb5b6047fd
Added functions for getting API data to repo and user models
Marcin Kuzminski <marcin@python-works.com>
parents:
2506
diff
changeset
|
971 repo_type=repo.repo_type, |
43cb5b6047fd
Added functions for getting API data to repo and user models
Marcin Kuzminski <marcin@python-works.com>
parents:
2506
diff
changeset
|
972 clone_uri=repo.clone_uri, |
43cb5b6047fd
Added functions for getting API data to repo and user models
Marcin Kuzminski <marcin@python-works.com>
parents:
2506
diff
changeset
|
973 private=repo.private, |
43cb5b6047fd
Added functions for getting API data to repo and user models
Marcin Kuzminski <marcin@python-works.com>
parents:
2506
diff
changeset
|
974 created_on=repo.created_on, |
43cb5b6047fd
Added functions for getting API data to repo and user models
Marcin Kuzminski <marcin@python-works.com>
parents:
2506
diff
changeset
|
975 description=repo.description, |
43cb5b6047fd
Added functions for getting API data to repo and user models
Marcin Kuzminski <marcin@python-works.com>
parents:
2506
diff
changeset
|
976 landing_rev=repo.landing_rev, |
43cb5b6047fd
Added functions for getting API data to repo and user models
Marcin Kuzminski <marcin@python-works.com>
parents:
2506
diff
changeset
|
977 owner=repo.user.username, |
3115
ebd76deee70d
Default parameters are now also used for creating repos using API calls, and initial repo scanner
Marcin Kuzminski <marcin@python-works.com>
parents:
3067
diff
changeset
|
978 fork_of=repo.fork.repo_name if repo.fork else None, |
ebd76deee70d
Default parameters are now also used for creating repos using API calls, and initial repo scanner
Marcin Kuzminski <marcin@python-works.com>
parents:
3067
diff
changeset
|
979 enable_statistics=repo.enable_statistics, |
ebd76deee70d
Default parameters are now also used for creating repos using API calls, and initial repo scanner
Marcin Kuzminski <marcin@python-works.com>
parents:
3067
diff
changeset
|
980 enable_locking=repo.enable_locking, |
3174
37c0ac5fe42f
added last_changeset information in get_repo API function
Marcin Kuzminski <marcin@python-works.com>
parents:
3170
diff
changeset
|
981 enable_downloads=repo.enable_downloads, |
37c0ac5fe42f
added last_changeset information in get_repo API function
Marcin Kuzminski <marcin@python-works.com>
parents:
3170
diff
changeset
|
982 last_changeset=repo.changeset_cache |
2508
43cb5b6047fd
Added functions for getting API data to repo and user models
Marcin Kuzminski <marcin@python-works.com>
parents:
2506
diff
changeset
|
983 ) |
3308
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3278
diff
changeset
|
984 rc_config = RhodeCodeSetting.get_app_settings() |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3278
diff
changeset
|
985 repository_fields = str2bool(rc_config.get('rhodecode_repository_fields')) |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3278
diff
changeset
|
986 if repository_fields: |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3278
diff
changeset
|
987 for f in self.extra_fields: |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3278
diff
changeset
|
988 data[f.field_key_prefixed] = f.field_value |
2508
43cb5b6047fd
Added functions for getting API data to repo and user models
Marcin Kuzminski <marcin@python-works.com>
parents:
2506
diff
changeset
|
989 |
43cb5b6047fd
Added functions for getting API data to repo and user models
Marcin Kuzminski <marcin@python-works.com>
parents:
2506
diff
changeset
|
990 return data |
43cb5b6047fd
Added functions for getting API data to repo and user models
Marcin Kuzminski <marcin@python-works.com>
parents:
2506
diff
changeset
|
991 |
2726
aa17c7a1b8a5
Implemented basic locking functionality.
Marcin Kuzminski <marcin@python-works.com>
parents:
2724
diff
changeset
|
992 @classmethod |
aa17c7a1b8a5
Implemented basic locking functionality.
Marcin Kuzminski <marcin@python-works.com>
parents:
2724
diff
changeset
|
993 def lock(cls, repo, user_id): |
aa17c7a1b8a5
Implemented basic locking functionality.
Marcin Kuzminski <marcin@python-works.com>
parents:
2724
diff
changeset
|
994 repo.locked = [user_id, time.time()] |
aa17c7a1b8a5
Implemented basic locking functionality.
Marcin Kuzminski <marcin@python-works.com>
parents:
2724
diff
changeset
|
995 Session().add(repo) |
aa17c7a1b8a5
Implemented basic locking functionality.
Marcin Kuzminski <marcin@python-works.com>
parents:
2724
diff
changeset
|
996 Session().commit() |
aa17c7a1b8a5
Implemented basic locking functionality.
Marcin Kuzminski <marcin@python-works.com>
parents:
2724
diff
changeset
|
997 |
aa17c7a1b8a5
Implemented basic locking functionality.
Marcin Kuzminski <marcin@python-works.com>
parents:
2724
diff
changeset
|
998 @classmethod |
aa17c7a1b8a5
Implemented basic locking functionality.
Marcin Kuzminski <marcin@python-works.com>
parents:
2724
diff
changeset
|
999 def unlock(cls, repo): |
aa17c7a1b8a5
Implemented basic locking functionality.
Marcin Kuzminski <marcin@python-works.com>
parents:
2724
diff
changeset
|
1000 repo.locked = None |
aa17c7a1b8a5
Implemented basic locking functionality.
Marcin Kuzminski <marcin@python-works.com>
parents:
2724
diff
changeset
|
1001 Session().add(repo) |
aa17c7a1b8a5
Implemented basic locking functionality.
Marcin Kuzminski <marcin@python-works.com>
parents:
2724
diff
changeset
|
1002 Session().commit() |
aa17c7a1b8a5
Implemented basic locking functionality.
Marcin Kuzminski <marcin@python-works.com>
parents:
2724
diff
changeset
|
1003 |
2936
62e493c7f436
Added lightweight dashboard option. ref #500
Marcin Kuzminski <marcin@python-works.com>
parents:
2835
diff
changeset
|
1004 @property |
62e493c7f436
Added lightweight dashboard option. ref #500
Marcin Kuzminski <marcin@python-works.com>
parents:
2835
diff
changeset
|
1005 def last_db_change(self): |
62e493c7f436
Added lightweight dashboard option. ref #500
Marcin Kuzminski <marcin@python-works.com>
parents:
2835
diff
changeset
|
1006 return self.updated_on |
62e493c7f436
Added lightweight dashboard option. ref #500
Marcin Kuzminski <marcin@python-works.com>
parents:
2835
diff
changeset
|
1007 |
3170
2ab2eed4a70a
implemented #725 Pull Request View - Show origin repo URL
Marcin Kuzminski <marcin@python-works.com>
parents:
3152
diff
changeset
|
1008 def clone_url(self, **override): |
2ab2eed4a70a
implemented #725 Pull Request View - Show origin repo URL
Marcin Kuzminski <marcin@python-works.com>
parents:
3152
diff
changeset
|
1009 from pylons import url |
2ab2eed4a70a
implemented #725 Pull Request View - Show origin repo URL
Marcin Kuzminski <marcin@python-works.com>
parents:
3152
diff
changeset
|
1010 from urlparse import urlparse |
2ab2eed4a70a
implemented #725 Pull Request View - Show origin repo URL
Marcin Kuzminski <marcin@python-works.com>
parents:
3152
diff
changeset
|
1011 import urllib |
2ab2eed4a70a
implemented #725 Pull Request View - Show origin repo URL
Marcin Kuzminski <marcin@python-works.com>
parents:
3152
diff
changeset
|
1012 parsed_url = urlparse(url('home', qualified=True)) |
2ab2eed4a70a
implemented #725 Pull Request View - Show origin repo URL
Marcin Kuzminski <marcin@python-works.com>
parents:
3152
diff
changeset
|
1013 default_clone_uri = '%(scheme)s://%(user)s%(pass)s%(netloc)s%(prefix)s%(path)s' |
2ab2eed4a70a
implemented #725 Pull Request View - Show origin repo URL
Marcin Kuzminski <marcin@python-works.com>
parents:
3152
diff
changeset
|
1014 decoded_path = safe_unicode(urllib.unquote(parsed_url.path)) |
2ab2eed4a70a
implemented #725 Pull Request View - Show origin repo URL
Marcin Kuzminski <marcin@python-works.com>
parents:
3152
diff
changeset
|
1015 args = { |
2ab2eed4a70a
implemented #725 Pull Request View - Show origin repo URL
Marcin Kuzminski <marcin@python-works.com>
parents:
3152
diff
changeset
|
1016 'user': '', |
2ab2eed4a70a
implemented #725 Pull Request View - Show origin repo URL
Marcin Kuzminski <marcin@python-works.com>
parents:
3152
diff
changeset
|
1017 'pass': '', |
2ab2eed4a70a
implemented #725 Pull Request View - Show origin repo URL
Marcin Kuzminski <marcin@python-works.com>
parents:
3152
diff
changeset
|
1018 'scheme': parsed_url.scheme, |
2ab2eed4a70a
implemented #725 Pull Request View - Show origin repo URL
Marcin Kuzminski <marcin@python-works.com>
parents:
3152
diff
changeset
|
1019 'netloc': parsed_url.netloc, |
2ab2eed4a70a
implemented #725 Pull Request View - Show origin repo URL
Marcin Kuzminski <marcin@python-works.com>
parents:
3152
diff
changeset
|
1020 'prefix': decoded_path, |
2ab2eed4a70a
implemented #725 Pull Request View - Show origin repo URL
Marcin Kuzminski <marcin@python-works.com>
parents:
3152
diff
changeset
|
1021 'path': self.repo_name |
2ab2eed4a70a
implemented #725 Pull Request View - Show origin repo URL
Marcin Kuzminski <marcin@python-works.com>
parents:
3152
diff
changeset
|
1022 } |
2ab2eed4a70a
implemented #725 Pull Request View - Show origin repo URL
Marcin Kuzminski <marcin@python-works.com>
parents:
3152
diff
changeset
|
1023 |
2ab2eed4a70a
implemented #725 Pull Request View - Show origin repo URL
Marcin Kuzminski <marcin@python-works.com>
parents:
3152
diff
changeset
|
1024 args.update(override) |
2ab2eed4a70a
implemented #725 Pull Request View - Show origin repo URL
Marcin Kuzminski <marcin@python-works.com>
parents:
3152
diff
changeset
|
1025 return default_clone_uri % args |
2ab2eed4a70a
implemented #725 Pull Request View - Show origin repo URL
Marcin Kuzminski <marcin@python-works.com>
parents:
3152
diff
changeset
|
1026 |
1366
9c0f5d558789
fixes #200, rewrote the whole caching mechanism to get rid of such problems. Now cached instances are attached
Marcin Kuzminski <marcin@python-works.com>
parents:
1360
diff
changeset
|
1027 #========================================================================== |
1466 | 1028 # SCM PROPERTIES |
1029 #========================================================================== | |
1030 | |
2251
986430cde505
fixed issue with getting README files from git repositories
Marcin Kuzminski <marcin@python-works.com>
parents:
2248
diff
changeset
|
1031 def get_changeset(self, rev=None): |
1593 | 1032 return get_changeset_safe(self.scm_instance, rev) |
1466 | 1033 |
2603
370ed7829168
Readme renderer now uses landing_rev parameter to render the readme based on
Marcin Kuzminski <marcin@python-works.com>
parents:
2588
diff
changeset
|
1034 def get_landing_changeset(self): |
370ed7829168
Readme renderer now uses landing_rev parameter to render the readme based on
Marcin Kuzminski <marcin@python-works.com>
parents:
2588
diff
changeset
|
1035 """ |
370ed7829168
Readme renderer now uses landing_rev parameter to render the readme based on
Marcin Kuzminski <marcin@python-works.com>
parents:
2588
diff
changeset
|
1036 Returns landing changeset, or if that doesn't exist returns the tip |
370ed7829168
Readme renderer now uses landing_rev parameter to render the readme based on
Marcin Kuzminski <marcin@python-works.com>
parents:
2588
diff
changeset
|
1037 """ |
370ed7829168
Readme renderer now uses landing_rev parameter to render the readme based on
Marcin Kuzminski <marcin@python-works.com>
parents:
2588
diff
changeset
|
1038 cs = self.get_changeset(self.landing_rev) or self.get_changeset() |
370ed7829168
Readme renderer now uses landing_rev parameter to render the readme based on
Marcin Kuzminski <marcin@python-works.com>
parents:
2588
diff
changeset
|
1039 return cs |
370ed7829168
Readme renderer now uses landing_rev parameter to render the readme based on
Marcin Kuzminski <marcin@python-works.com>
parents:
2588
diff
changeset
|
1040 |
3147
8182ebed2922
Added full last changeset info to lightweight dashboard
Marcin Kuzminski <marcin@python-works.com>
parents:
3146
diff
changeset
|
1041 def update_changeset_cache(self, cs_cache=None): |
8182ebed2922
Added full last changeset info to lightweight dashboard
Marcin Kuzminski <marcin@python-works.com>
parents:
3146
diff
changeset
|
1042 """ |
8182ebed2922
Added full last changeset info to lightweight dashboard
Marcin Kuzminski <marcin@python-works.com>
parents:
3146
diff
changeset
|
1043 Update cache of last changeset for repository, keys should be:: |
8182ebed2922
Added full last changeset info to lightweight dashboard
Marcin Kuzminski <marcin@python-works.com>
parents:
3146
diff
changeset
|
1044 |
8182ebed2922
Added full last changeset info to lightweight dashboard
Marcin Kuzminski <marcin@python-works.com>
parents:
3146
diff
changeset
|
1045 short_id |
8182ebed2922
Added full last changeset info to lightweight dashboard
Marcin Kuzminski <marcin@python-works.com>
parents:
3146
diff
changeset
|
1046 raw_id |
8182ebed2922
Added full last changeset info to lightweight dashboard
Marcin Kuzminski <marcin@python-works.com>
parents:
3146
diff
changeset
|
1047 revision |
8182ebed2922
Added full last changeset info to lightweight dashboard
Marcin Kuzminski <marcin@python-works.com>
parents:
3146
diff
changeset
|
1048 message |
8182ebed2922
Added full last changeset info to lightweight dashboard
Marcin Kuzminski <marcin@python-works.com>
parents:
3146
diff
changeset
|
1049 date |
8182ebed2922
Added full last changeset info to lightweight dashboard
Marcin Kuzminski <marcin@python-works.com>
parents:
3146
diff
changeset
|
1050 author |
8182ebed2922
Added full last changeset info to lightweight dashboard
Marcin Kuzminski <marcin@python-works.com>
parents:
3146
diff
changeset
|
1051 |
8182ebed2922
Added full last changeset info to lightweight dashboard
Marcin Kuzminski <marcin@python-works.com>
parents:
3146
diff
changeset
|
1052 :param cs_cache: |
8182ebed2922
Added full last changeset info to lightweight dashboard
Marcin Kuzminski <marcin@python-works.com>
parents:
3146
diff
changeset
|
1053 """ |
8182ebed2922
Added full last changeset info to lightweight dashboard
Marcin Kuzminski <marcin@python-works.com>
parents:
3146
diff
changeset
|
1054 from rhodecode.lib.vcs.backends.base import BaseChangeset |
8182ebed2922
Added full last changeset info to lightweight dashboard
Marcin Kuzminski <marcin@python-works.com>
parents:
3146
diff
changeset
|
1055 if cs_cache is None: |
8182ebed2922
Added full last changeset info to lightweight dashboard
Marcin Kuzminski <marcin@python-works.com>
parents:
3146
diff
changeset
|
1056 cs_cache = self.get_changeset() |
8182ebed2922
Added full last changeset info to lightweight dashboard
Marcin Kuzminski <marcin@python-works.com>
parents:
3146
diff
changeset
|
1057 if isinstance(cs_cache, BaseChangeset): |
8182ebed2922
Added full last changeset info to lightweight dashboard
Marcin Kuzminski <marcin@python-works.com>
parents:
3146
diff
changeset
|
1058 cs_cache = cs_cache.__json__() |
8182ebed2922
Added full last changeset info to lightweight dashboard
Marcin Kuzminski <marcin@python-works.com>
parents:
3146
diff
changeset
|
1059 |
3227
99ce5d097a09
fixes for issue #731, update-repoinfo sometimes failed to update data when changesets
Marcin Kuzminski <marcin@python-works.com>
parents:
3226
diff
changeset
|
1060 if (cs_cache != self.changeset_cache |
99ce5d097a09
fixes for issue #731, update-repoinfo sometimes failed to update data when changesets
Marcin Kuzminski <marcin@python-works.com>
parents:
3226
diff
changeset
|
1061 or not self.last_change |
99ce5d097a09
fixes for issue #731, update-repoinfo sometimes failed to update data when changesets
Marcin Kuzminski <marcin@python-works.com>
parents:
3226
diff
changeset
|
1062 or not self.changeset_cache): |
3226
226013bac971
update repo-info shouldn't allow setting empty values NEVER !
Marcin Kuzminski <marcin@python-works.com>
parents:
3222
diff
changeset
|
1063 _default = datetime.datetime.fromtimestamp(0) |
226013bac971
update repo-info shouldn't allow setting empty values NEVER !
Marcin Kuzminski <marcin@python-works.com>
parents:
3222
diff
changeset
|
1064 last_change = cs_cache.get('date') or self.last_change or _default |
3147
8182ebed2922
Added full last changeset info to lightweight dashboard
Marcin Kuzminski <marcin@python-works.com>
parents:
3146
diff
changeset
|
1065 log.debug('updated repo %s with new cs cache %s' % (self, cs_cache)) |
2937
d439d408b415
Update last_change from VCS data on request.
Marcin Kuzminski <marcin@python-works.com>
parents:
2936
diff
changeset
|
1066 self.updated_on = last_change |
3147
8182ebed2922
Added full last changeset info to lightweight dashboard
Marcin Kuzminski <marcin@python-works.com>
parents:
3146
diff
changeset
|
1067 self.changeset_cache = cs_cache |
2937
d439d408b415
Update last_change from VCS data on request.
Marcin Kuzminski <marcin@python-works.com>
parents:
2936
diff
changeset
|
1068 Session().add(self) |
d439d408b415
Update last_change from VCS data on request.
Marcin Kuzminski <marcin@python-works.com>
parents:
2936
diff
changeset
|
1069 Session().commit() |
3227
99ce5d097a09
fixes for issue #731, update-repoinfo sometimes failed to update data when changesets
Marcin Kuzminski <marcin@python-works.com>
parents:
3226
diff
changeset
|
1070 else: |
99ce5d097a09
fixes for issue #731, update-repoinfo sometimes failed to update data when changesets
Marcin Kuzminski <marcin@python-works.com>
parents:
3226
diff
changeset
|
1071 log.debug('Skipping repo:%s already with latest changes' % self) |
2937
d439d408b415
Update last_change from VCS data on request.
Marcin Kuzminski <marcin@python-works.com>
parents:
2936
diff
changeset
|
1072 |
1466 | 1073 @property |
1593 | 1074 def tip(self): |
1075 return self.get_changeset('tip') | |
1466 | 1076 |
1077 @property | |
1593 | 1078 def author(self): |
1466 | 1079 return self.tip.author |
1080 | |
1081 @property | |
1593 | 1082 def last_change(self): |
1466 | 1083 return self.scm_instance.last_change |
1084 | |
2520
a1e156503afe
Fixed calls to Session in db model
Marcin Kuzminski <marcin@python-works.com>
parents:
2510
diff
changeset
|
1085 def get_comments(self, revisions=None): |
1884
0614862a20ec
Added number of comments in changelog for each changeset
Marcin Kuzminski <marcin@python-works.com>
parents:
1824
diff
changeset
|
1086 """ |
0614862a20ec
Added number of comments in changelog for each changeset
Marcin Kuzminski <marcin@python-works.com>
parents:
1824
diff
changeset
|
1087 Returns comments for this repository grouped by revisions |
0614862a20ec
Added number of comments in changelog for each changeset
Marcin Kuzminski <marcin@python-works.com>
parents:
1824
diff
changeset
|
1088 |
0614862a20ec
Added number of comments in changelog for each changeset
Marcin Kuzminski <marcin@python-works.com>
parents:
1824
diff
changeset
|
1089 :param revisions: filter query by revisions only |
0614862a20ec
Added number of comments in changelog for each changeset
Marcin Kuzminski <marcin@python-works.com>
parents:
1824
diff
changeset
|
1090 """ |
0614862a20ec
Added number of comments in changelog for each changeset
Marcin Kuzminski <marcin@python-works.com>
parents:
1824
diff
changeset
|
1091 cmts = ChangesetComment.query()\ |
0614862a20ec
Added number of comments in changelog for each changeset
Marcin Kuzminski <marcin@python-works.com>
parents:
1824
diff
changeset
|
1092 .filter(ChangesetComment.repo == self) |
0614862a20ec
Added number of comments in changelog for each changeset
Marcin Kuzminski <marcin@python-works.com>
parents:
1824
diff
changeset
|
1093 if revisions: |
0614862a20ec
Added number of comments in changelog for each changeset
Marcin Kuzminski <marcin@python-works.com>
parents:
1824
diff
changeset
|
1094 cmts = cmts.filter(ChangesetComment.revision.in_(revisions)) |
0614862a20ec
Added number of comments in changelog for each changeset
Marcin Kuzminski <marcin@python-works.com>
parents:
1824
diff
changeset
|
1095 grouped = defaultdict(list) |
0614862a20ec
Added number of comments in changelog for each changeset
Marcin Kuzminski <marcin@python-works.com>
parents:
1824
diff
changeset
|
1096 for cmt in cmts.all(): |
0614862a20ec
Added number of comments in changelog for each changeset
Marcin Kuzminski <marcin@python-works.com>
parents:
1824
diff
changeset
|
1097 grouped[cmt.revision].append(cmt) |
0614862a20ec
Added number of comments in changelog for each changeset
Marcin Kuzminski <marcin@python-works.com>
parents:
1824
diff
changeset
|
1098 return grouped |
0614862a20ec
Added number of comments in changelog for each changeset
Marcin Kuzminski <marcin@python-works.com>
parents:
1824
diff
changeset
|
1099 |
2215
2c2bdaeca912
code-review initial
Marcin Kuzminski <marcin@python-works.com>
parents:
2161
diff
changeset
|
1100 def statuses(self, revisions=None): |
2c2bdaeca912
code-review initial
Marcin Kuzminski <marcin@python-works.com>
parents:
2161
diff
changeset
|
1101 """ |
2c2bdaeca912
code-review initial
Marcin Kuzminski <marcin@python-works.com>
parents:
2161
diff
changeset
|
1102 Returns statuses for this repository |
2217
76947224bf27
Implemented initial code-review status of changesets
Marcin Kuzminski <marcin@python-works.com>
parents:
2215
diff
changeset
|
1103 |
2215
2c2bdaeca912
code-review initial
Marcin Kuzminski <marcin@python-works.com>
parents:
2161
diff
changeset
|
1104 :param revisions: list of revisions to get statuses for |
2c2bdaeca912
code-review initial
Marcin Kuzminski <marcin@python-works.com>
parents:
2161
diff
changeset
|
1105 :type revisions: list |
2c2bdaeca912
code-review initial
Marcin Kuzminski <marcin@python-works.com>
parents:
2161
diff
changeset
|
1106 """ |
2c2bdaeca912
code-review initial
Marcin Kuzminski <marcin@python-works.com>
parents:
2161
diff
changeset
|
1107 |
2c2bdaeca912
code-review initial
Marcin Kuzminski <marcin@python-works.com>
parents:
2161
diff
changeset
|
1108 statuses = ChangesetStatus.query()\ |
2287
8447d35b674e
Added simple versioning for changeset status
Marcin Kuzminski <marcin@python-works.com>
parents:
2286
diff
changeset
|
1109 .filter(ChangesetStatus.repo == self)\ |
8447d35b674e
Added simple versioning for changeset status
Marcin Kuzminski <marcin@python-works.com>
parents:
2286
diff
changeset
|
1110 .filter(ChangesetStatus.version == 0) |
2215
2c2bdaeca912
code-review initial
Marcin Kuzminski <marcin@python-works.com>
parents:
2161
diff
changeset
|
1111 if revisions: |
2c2bdaeca912
code-review initial
Marcin Kuzminski <marcin@python-works.com>
parents:
2161
diff
changeset
|
1112 statuses = statuses.filter(ChangesetStatus.revision.in_(revisions)) |
2217
76947224bf27
Implemented initial code-review status of changesets
Marcin Kuzminski <marcin@python-works.com>
parents:
2215
diff
changeset
|
1113 grouped = {} |
2542
4496d3119627
mock changeset status(to under review) if there's opened pull request but not yet with a status
Marcin Kuzminski <marcin@python-works.com>
parents:
2532
diff
changeset
|
1114 |
4496d3119627
mock changeset status(to under review) if there's opened pull request but not yet with a status
Marcin Kuzminski <marcin@python-works.com>
parents:
2532
diff
changeset
|
1115 #maybe we have open new pullrequest without a status ? |
4496d3119627
mock changeset status(to under review) if there's opened pull request but not yet with a status
Marcin Kuzminski <marcin@python-works.com>
parents:
2532
diff
changeset
|
1116 stat = ChangesetStatus.STATUS_UNDER_REVIEW |
4496d3119627
mock changeset status(to under review) if there's opened pull request but not yet with a status
Marcin Kuzminski <marcin@python-works.com>
parents:
2532
diff
changeset
|
1117 status_lbl = ChangesetStatus.get_status_lbl(stat) |
4496d3119627
mock changeset status(to under review) if there's opened pull request but not yet with a status
Marcin Kuzminski <marcin@python-works.com>
parents:
2532
diff
changeset
|
1118 for pr in PullRequest.query().filter(PullRequest.org_repo == self).all(): |
4496d3119627
mock changeset status(to under review) if there's opened pull request but not yet with a status
Marcin Kuzminski <marcin@python-works.com>
parents:
2532
diff
changeset
|
1119 for rev in pr.revisions: |
4496d3119627
mock changeset status(to under review) if there's opened pull request but not yet with a status
Marcin Kuzminski <marcin@python-works.com>
parents:
2532
diff
changeset
|
1120 pr_id = pr.pull_request_id |
4496d3119627
mock changeset status(to under review) if there's opened pull request but not yet with a status
Marcin Kuzminski <marcin@python-works.com>
parents:
2532
diff
changeset
|
1121 pr_repo = pr.other_repo.repo_name |
4496d3119627
mock changeset status(to under review) if there's opened pull request but not yet with a status
Marcin Kuzminski <marcin@python-works.com>
parents:
2532
diff
changeset
|
1122 grouped[rev] = [stat, status_lbl, pr_id, pr_repo] |
4496d3119627
mock changeset status(to under review) if there's opened pull request but not yet with a status
Marcin Kuzminski <marcin@python-works.com>
parents:
2532
diff
changeset
|
1123 |
2215
2c2bdaeca912
code-review initial
Marcin Kuzminski <marcin@python-works.com>
parents:
2161
diff
changeset
|
1124 for stat in statuses.all(): |
2443
fd0a822481ec
- added commenting to pull requests
Marcin Kuzminski <marcin@python-works.com>
parents:
2440
diff
changeset
|
1125 pr_id = pr_repo = None |
fd0a822481ec
- added commenting to pull requests
Marcin Kuzminski <marcin@python-works.com>
parents:
2440
diff
changeset
|
1126 if stat.pull_request: |
fd0a822481ec
- added commenting to pull requests
Marcin Kuzminski <marcin@python-works.com>
parents:
2440
diff
changeset
|
1127 pr_id = stat.pull_request.pull_request_id |
fd0a822481ec
- added commenting to pull requests
Marcin Kuzminski <marcin@python-works.com>
parents:
2440
diff
changeset
|
1128 pr_repo = stat.pull_request.other_repo.repo_name |
fd0a822481ec
- added commenting to pull requests
Marcin Kuzminski <marcin@python-works.com>
parents:
2440
diff
changeset
|
1129 grouped[stat.revision] = [str(stat.status), stat.status_lbl, |
fd0a822481ec
- added commenting to pull requests
Marcin Kuzminski <marcin@python-works.com>
parents:
2440
diff
changeset
|
1130 pr_id, pr_repo] |
2215
2c2bdaeca912
code-review initial
Marcin Kuzminski <marcin@python-works.com>
parents:
2161
diff
changeset
|
1131 return grouped |
2c2bdaeca912
code-review initial
Marcin Kuzminski <marcin@python-works.com>
parents:
2161
diff
changeset
|
1132 |
3246
b9ba0d4d3abf
implemented #83 show repo size on summary page
Marcin Kuzminski <marcin@python-works.com>
parents:
3239
diff
changeset
|
1133 def _repo_size(self): |
b9ba0d4d3abf
implemented #83 show repo size on summary page
Marcin Kuzminski <marcin@python-works.com>
parents:
3239
diff
changeset
|
1134 from rhodecode.lib import helpers as h |
b9ba0d4d3abf
implemented #83 show repo size on summary page
Marcin Kuzminski <marcin@python-works.com>
parents:
3239
diff
changeset
|
1135 log.debug('calculating repository size...') |
b9ba0d4d3abf
implemented #83 show repo size on summary page
Marcin Kuzminski <marcin@python-works.com>
parents:
3239
diff
changeset
|
1136 return h.format_byte_size(self.scm_instance.size) |
b9ba0d4d3abf
implemented #83 show repo size on summary page
Marcin Kuzminski <marcin@python-works.com>
parents:
3239
diff
changeset
|
1137 |
1466 | 1138 #========================================================================== |
1366
9c0f5d558789
fixes #200, rewrote the whole caching mechanism to get rid of such problems. Now cached instances are attached
Marcin Kuzminski <marcin@python-works.com>
parents:
1360
diff
changeset
|
1139 # SCM CACHE INSTANCE |
9c0f5d558789
fixes #200, rewrote the whole caching mechanism to get rid of such problems. Now cached instances are attached
Marcin Kuzminski <marcin@python-works.com>
parents:
1360
diff
changeset
|
1140 #========================================================================== |
9c0f5d558789
fixes #200, rewrote the whole caching mechanism to get rid of such problems. Now cached instances are attached
Marcin Kuzminski <marcin@python-works.com>
parents:
1360
diff
changeset
|
1141 |
9c0f5d558789
fixes #200, rewrote the whole caching mechanism to get rid of such problems. Now cached instances are attached
Marcin Kuzminski <marcin@python-works.com>
parents:
1360
diff
changeset
|
1142 @property |
1593 | 1143 def invalidate(self): |
1607
e886f91fcb71
Cached readme generation
Marcin Kuzminski <marcin@python-works.com>
parents:
1594
diff
changeset
|
1144 return CacheInvalidation.invalidate(self.repo_name) |
1366
9c0f5d558789
fixes #200, rewrote the whole caching mechanism to get rid of such problems. Now cached instances are attached
Marcin Kuzminski <marcin@python-works.com>
parents:
1360
diff
changeset
|
1145 |
1593 | 1146 def set_invalidate(self): |
1366
9c0f5d558789
fixes #200, rewrote the whole caching mechanism to get rid of such problems. Now cached instances are attached
Marcin Kuzminski <marcin@python-works.com>
parents:
1360
diff
changeset
|
1147 """ |
9c0f5d558789
fixes #200, rewrote the whole caching mechanism to get rid of such problems. Now cached instances are attached
Marcin Kuzminski <marcin@python-works.com>
parents:
1360
diff
changeset
|
1148 set a cache for invalidation for this instance |
9c0f5d558789
fixes #200, rewrote the whole caching mechanism to get rid of such problems. Now cached instances are attached
Marcin Kuzminski <marcin@python-works.com>
parents:
1360
diff
changeset
|
1149 """ |
3020
00498b3e4c88
Cleaned the way cache keys are invalidated
Marcin Kuzminski <marcin@python-works.com>
parents:
3018
diff
changeset
|
1150 CacheInvalidation.set_invalidate(repo_name=self.repo_name) |
1366
9c0f5d558789
fixes #200, rewrote the whole caching mechanism to get rid of such problems. Now cached instances are attached
Marcin Kuzminski <marcin@python-works.com>
parents:
1360
diff
changeset
|
1151 |
1466 | 1152 @LazyProperty |
3278
c2bf0fa7b3cb
git hook handler shouldn't ever use cache instances
Marcin Kuzminski <marcin@python-works.com>
parents:
3274
diff
changeset
|
1153 def scm_instance_no_cache(self): |
c2bf0fa7b3cb
git hook handler shouldn't ever use cache instances
Marcin Kuzminski <marcin@python-works.com>
parents:
3274
diff
changeset
|
1154 return self.__get_instance() |
c2bf0fa7b3cb
git hook handler shouldn't ever use cache instances
Marcin Kuzminski <marcin@python-works.com>
parents:
3274
diff
changeset
|
1155 |
c2bf0fa7b3cb
git hook handler shouldn't ever use cache instances
Marcin Kuzminski <marcin@python-works.com>
parents:
3274
diff
changeset
|
1156 @LazyProperty |
1593 | 1157 def scm_instance(self): |
3025
f61adead3520
Added option to ini files for controlling full cache of VCS instances.
Marcin Kuzminski <marcin@python-works.com>
parents:
3024
diff
changeset
|
1158 import rhodecode |
f61adead3520
Added option to ini files for controlling full cache of VCS instances.
Marcin Kuzminski <marcin@python-works.com>
parents:
3024
diff
changeset
|
1159 full_cache = str2bool(rhodecode.CONFIG.get('vcs_full_cache')) |
f61adead3520
Added option to ini files for controlling full cache of VCS instances.
Marcin Kuzminski <marcin@python-works.com>
parents:
3024
diff
changeset
|
1160 if full_cache: |
f61adead3520
Added option to ini files for controlling full cache of VCS instances.
Marcin Kuzminski <marcin@python-works.com>
parents:
3024
diff
changeset
|
1161 return self.scm_instance_cached() |
1400
0d7b56b97953
Simplified last_login call on user, and changed login to use User model directly
Marcin Kuzminski <marcin@python-works.com>
parents:
1388
diff
changeset
|
1162 return self.__get_instance() |
1366
9c0f5d558789
fixes #200, rewrote the whole caching mechanism to get rid of such problems. Now cached instances are attached
Marcin Kuzminski <marcin@python-works.com>
parents:
1360
diff
changeset
|
1163 |
2352
90e06f53af8c
Implemented cache-map on main page to save executing select
Marcin Kuzminski <marcin@python-works.com>
parents:
2339
diff
changeset
|
1164 def scm_instance_cached(self, cache_map=None): |
1593 | 1165 @cache_region('long_term') |
1166 def _c(repo_name): | |
1400
0d7b56b97953
Simplified last_login call on user, and changed login to use User model directly
Marcin Kuzminski <marcin@python-works.com>
parents:
1388
diff
changeset
|
1167 return self.__get_instance() |
1607
e886f91fcb71
Cached readme generation
Marcin Kuzminski <marcin@python-works.com>
parents:
1594
diff
changeset
|
1168 rn = self.repo_name |
1744
d41a115d9a39
remove cache from default perms. In some cases of concurrent repo removal it crashed.
Marcin Kuzminski <marcin@python-works.com>
parents:
1733
diff
changeset
|
1169 log.debug('Getting cached instance of repo') |
2352
90e06f53af8c
Implemented cache-map on main page to save executing select
Marcin Kuzminski <marcin@python-works.com>
parents:
2339
diff
changeset
|
1170 |
90e06f53af8c
Implemented cache-map on main page to save executing select
Marcin Kuzminski <marcin@python-works.com>
parents:
2339
diff
changeset
|
1171 if cache_map: |
90e06f53af8c
Implemented cache-map on main page to save executing select
Marcin Kuzminski <marcin@python-works.com>
parents:
2339
diff
changeset
|
1172 # get using prefilled cache_map |
90e06f53af8c
Implemented cache-map on main page to save executing select
Marcin Kuzminski <marcin@python-works.com>
parents:
2339
diff
changeset
|
1173 invalidate_repo = cache_map[self.repo_name] |
90e06f53af8c
Implemented cache-map on main page to save executing select
Marcin Kuzminski <marcin@python-works.com>
parents:
2339
diff
changeset
|
1174 if invalidate_repo: |
2356
2da7b5984ae5
typo fix + code garden
Marcin Kuzminski <marcin@python-works.com>
parents:
2352
diff
changeset
|
1175 invalidate_repo = (None if invalidate_repo.cache_active |
2352
90e06f53af8c
Implemented cache-map on main page to save executing select
Marcin Kuzminski <marcin@python-works.com>
parents:
2339
diff
changeset
|
1176 else invalidate_repo) |
90e06f53af8c
Implemented cache-map on main page to save executing select
Marcin Kuzminski <marcin@python-works.com>
parents:
2339
diff
changeset
|
1177 else: |
90e06f53af8c
Implemented cache-map on main page to save executing select
Marcin Kuzminski <marcin@python-works.com>
parents:
2339
diff
changeset
|
1178 # get from invalidate |
90e06f53af8c
Implemented cache-map on main page to save executing select
Marcin Kuzminski <marcin@python-works.com>
parents:
2339
diff
changeset
|
1179 invalidate_repo = self.invalidate |
90e06f53af8c
Implemented cache-map on main page to save executing select
Marcin Kuzminski <marcin@python-works.com>
parents:
2339
diff
changeset
|
1180 |
90e06f53af8c
Implemented cache-map on main page to save executing select
Marcin Kuzminski <marcin@python-works.com>
parents:
2339
diff
changeset
|
1181 if invalidate_repo is not None: |
1593 | 1182 region_invalidate(_c, None, rn) |
1428
e5467730682b
fixed some issues with cache invalidation, and simplified invalidation codes
Marcin Kuzminski <marcin@python-works.com>
parents:
1427
diff
changeset
|
1183 # update our cache |
2352
90e06f53af8c
Implemented cache-map on main page to save executing select
Marcin Kuzminski <marcin@python-works.com>
parents:
2339
diff
changeset
|
1184 CacheInvalidation.set_valid(invalidate_repo.cache_key) |
1593 | 1185 return _c(rn) |
1366
9c0f5d558789
fixes #200, rewrote the whole caching mechanism to get rid of such problems. Now cached instances are attached
Marcin Kuzminski <marcin@python-works.com>
parents:
1360
diff
changeset
|
1186 |
1593 | 1187 def __get_instance(self): |
1368
04b43168742d
adde short cache for repo_path
Marcin Kuzminski <marcin@python-works.com>
parents:
1366
diff
changeset
|
1188 repo_full_path = self.repo_full_path |
1366
9c0f5d558789
fixes #200, rewrote the whole caching mechanism to get rid of such problems. Now cached instances are attached
Marcin Kuzminski <marcin@python-works.com>
parents:
1360
diff
changeset
|
1189 try: |
1593 | 1190 alias = get_scm(repo_full_path)[0] |
1976 | 1191 log.debug('Creating instance of %s repository' % alias) |
1593 | 1192 backend = get_backend(alias) |
1366
9c0f5d558789
fixes #200, rewrote the whole caching mechanism to get rid of such problems. Now cached instances are attached
Marcin Kuzminski <marcin@python-works.com>
parents:
1360
diff
changeset
|
1193 except VCSError: |
1593 | 1194 log.error(traceback.format_exc()) |
1195 log.error('Perhaps this repository is in db and not in ' | |
1366
9c0f5d558789
fixes #200, rewrote the whole caching mechanism to get rid of such problems. Now cached instances are attached
Marcin Kuzminski <marcin@python-works.com>
parents:
1360
diff
changeset
|
1196 'filesystem run rescan repositories with ' |
1593 | 1197 '"destroy old data " option from admin panel') |
1366
9c0f5d558789
fixes #200, rewrote the whole caching mechanism to get rid of such problems. Now cached instances are attached
Marcin Kuzminski <marcin@python-works.com>
parents:
1360
diff
changeset
|
1198 return |
9c0f5d558789
fixes #200, rewrote the whole caching mechanism to get rid of such problems. Now cached instances are attached
Marcin Kuzminski <marcin@python-works.com>
parents:
1360
diff
changeset
|
1199 |
9c0f5d558789
fixes #200, rewrote the whole caching mechanism to get rid of such problems. Now cached instances are attached
Marcin Kuzminski <marcin@python-works.com>
parents:
1360
diff
changeset
|
1200 if alias == 'hg': |
2000
72c525a7e7ad
added migrations from 1.2.X to 1.3
Marcin Kuzminski <marcin@python-works.com>
parents:
1990
diff
changeset
|
1201 |
1594 | 1202 repo = backend(safe_str(repo_full_path), create=False, |
1203 baseui=self._ui) | |
1607
e886f91fcb71
Cached readme generation
Marcin Kuzminski <marcin@python-works.com>
parents:
1594
diff
changeset
|
1204 # skip hidden web repository |
1366
9c0f5d558789
fixes #200, rewrote the whole caching mechanism to get rid of such problems. Now cached instances are attached
Marcin Kuzminski <marcin@python-works.com>
parents:
1360
diff
changeset
|
1205 if repo._get_hidden(): |
9c0f5d558789
fixes #200, rewrote the whole caching mechanism to get rid of such problems. Now cached instances are attached
Marcin Kuzminski <marcin@python-works.com>
parents:
1360
diff
changeset
|
1206 return |
9c0f5d558789
fixes #200, rewrote the whole caching mechanism to get rid of such problems. Now cached instances are attached
Marcin Kuzminski <marcin@python-works.com>
parents:
1360
diff
changeset
|
1207 else: |
1594 | 1208 repo = backend(repo_full_path, create=False) |
1366
9c0f5d558789
fixes #200, rewrote the whole caching mechanism to get rid of such problems. Now cached instances are attached
Marcin Kuzminski <marcin@python-works.com>
parents:
1360
diff
changeset
|
1209 |
9c0f5d558789
fixes #200, rewrote the whole caching mechanism to get rid of such problems. Now cached instances are attached
Marcin Kuzminski <marcin@python-works.com>
parents:
1360
diff
changeset
|
1210 return repo |
9c0f5d558789
fixes #200, rewrote the whole caching mechanism to get rid of such problems. Now cached instances are attached
Marcin Kuzminski <marcin@python-works.com>
parents:
1360
diff
changeset
|
1211 |
1065
5d676b6ab71c
Moved BaseModel into base class for declarative base. Added some handy methods into
Marcin Kuzminski <marcin@python-works.com>
parents:
1039
diff
changeset
|
1212 |
1633
2c0d35e336b5
refactoring of models names for repoGroup permissions
Marcin Kuzminski <marcin@python-works.com>
parents:
1607
diff
changeset
|
1213 class RepoGroup(Base, BaseModel): |
878
859bc9e7a15d
Extended repo2db mapper with group creation via directory structures
Marcin Kuzminski <marcin@python-works.com>
parents:
836
diff
changeset
|
1214 __tablename__ = 'groups' |
1958
7e4b3d3a9c5c
renamed repo groups table
Marcin Kuzminski <marcin@python-works.com>
parents:
1950
diff
changeset
|
1215 __table_args__ = ( |
7e4b3d3a9c5c
renamed repo groups table
Marcin Kuzminski <marcin@python-works.com>
parents:
1950
diff
changeset
|
1216 UniqueConstraint('group_name', 'group_parent_id'), |
1963
9bbde54232dc
white space cleanup
Marcin Kuzminski <marcin@python-works.com>
parents:
1960
diff
changeset
|
1217 CheckConstraint('group_id != group_parent_id'), |
2356
2da7b5984ae5
typo fix + code garden
Marcin Kuzminski <marcin@python-works.com>
parents:
2352
diff
changeset
|
1218 {'extend_existing': True, 'mysql_engine': 'InnoDB', |
2149 | 1219 'mysql_charset': 'utf8'}, |
1958
7e4b3d3a9c5c
renamed repo groups table
Marcin Kuzminski <marcin@python-works.com>
parents:
1950
diff
changeset
|
1220 ) |
7e4b3d3a9c5c
renamed repo groups table
Marcin Kuzminski <marcin@python-works.com>
parents:
1950
diff
changeset
|
1221 __mapper_args__ = {'order_by': 'group_name'} |
878
859bc9e7a15d
Extended repo2db mapper with group creation via directory structures
Marcin Kuzminski <marcin@python-works.com>
parents:
836
diff
changeset
|
1222 |
1594 | 1223 group_id = Column("group_id", Integer(), nullable=False, unique=True, default=None, primary_key=True) |
2588
32dd6896abcf
added status column to pull request + some small refactoring of models
Marcin Kuzminski <marcin@python-works.com>
parents:
2585
diff
changeset
|
1224 group_name = Column("group_name", String(255, convert_unicode=False, assert_unicode=None), nullable=False, unique=True, default=None) |
1594 | 1225 group_parent_id = Column("group_parent_id", Integer(), ForeignKey('groups.group_id'), nullable=True, unique=None, default=None) |
2588
32dd6896abcf
added status column to pull request + some small refactoring of models
Marcin Kuzminski <marcin@python-works.com>
parents:
2585
diff
changeset
|
1226 group_description = Column("group_description", String(10000, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None) |
2749
3ed4dae499d0
Recursive set locking on all children of a group.
Marcin Kuzminski <marcin@python-works.com>
parents:
2731
diff
changeset
|
1227 enable_locking = Column("enable_locking", Boolean(), nullable=False, unique=None, default=False) |
878
859bc9e7a15d
Extended repo2db mapper with group creation via directory structures
Marcin Kuzminski <marcin@python-works.com>
parents:
836
diff
changeset
|
1228 |
1982
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1976
diff
changeset
|
1229 repo_group_to_perm = relationship('UserRepoGroupToPerm', cascade='all', order_by='UserRepoGroupToPerm.group_to_perm_id') |
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1976
diff
changeset
|
1230 users_group_to_perm = relationship('UsersGroupRepoGroupToPerm', cascade='all') |
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1976
diff
changeset
|
1231 |
1633
2c0d35e336b5
refactoring of models names for repoGroup permissions
Marcin Kuzminski <marcin@python-works.com>
parents:
1607
diff
changeset
|
1232 parent_group = relationship('RepoGroup', remote_side=group_id) |
878
859bc9e7a15d
Extended repo2db mapper with group creation via directory structures
Marcin Kuzminski <marcin@python-works.com>
parents:
836
diff
changeset
|
1233 |
1594 | 1234 def __init__(self, group_name='', parent_group=None): |
878
859bc9e7a15d
Extended repo2db mapper with group creation via directory structures
Marcin Kuzminski <marcin@python-works.com>
parents:
836
diff
changeset
|
1235 self.group_name = group_name |
859bc9e7a15d
Extended repo2db mapper with group creation via directory structures
Marcin Kuzminski <marcin@python-works.com>
parents:
836
diff
changeset
|
1236 self.parent_group = parent_group |
859bc9e7a15d
Extended repo2db mapper with group creation via directory structures
Marcin Kuzminski <marcin@python-works.com>
parents:
836
diff
changeset
|
1237 |
2156
a27e4d44237e
Use __unicode__ instead of __repr__ in models.
Marcin Kuzminski <marcin@python-works.com>
parents:
2152
diff
changeset
|
1238 def __unicode__(self): |
a27e4d44237e
Use __unicode__ instead of __repr__ in models.
Marcin Kuzminski <marcin@python-works.com>
parents:
2152
diff
changeset
|
1239 return u"<%s('%s:%s')>" % (self.__class__.__name__, self.group_id, |
1593 | 1240 self.group_name) |
631
05528ad948c4
Hacking for git support,and new faster repo scan
Marcin Kuzminski <marcin@python-works.com>
parents:
549
diff
changeset
|
1241 |
1346
cf78d302d441
#47 implemented deleting of empty groups. Fixed problem with full paths on nested groups
Marcin Kuzminski <marcin@python-works.com>
parents:
1345
diff
changeset
|
1242 @classmethod |
3239
a9565b8b429b
filter out repo groups choices to only ones that you have write+ access to. Before it was read+ access and you got proper
Marcin Kuzminski <marcin@python-works.com>
parents:
3234
diff
changeset
|
1243 def groups_choices(cls, groups=None, show_empty_group=True): |
1547
fbc762ae3496
unified generation of repo groups choices
Marcin Kuzminski <marcin@python-works.com>
parents:
1546
diff
changeset
|
1244 from webhelpers.html import literal as _literal |
3222
b4daef4cc26d
Group management delegation:
Marcin Kuzminski <marcin@python-works.com>
parents:
3212
diff
changeset
|
1245 if not groups: |
b4daef4cc26d
Group management delegation:
Marcin Kuzminski <marcin@python-works.com>
parents:
3212
diff
changeset
|
1246 groups = cls.query().all() |
3239
a9565b8b429b
filter out repo groups choices to only ones that you have write+ access to. Before it was read+ access and you got proper
Marcin Kuzminski <marcin@python-works.com>
parents:
3234
diff
changeset
|
1247 |
3222
b4daef4cc26d
Group management delegation:
Marcin Kuzminski <marcin@python-works.com>
parents:
3212
diff
changeset
|
1248 repo_groups = [] |
b4daef4cc26d
Group management delegation:
Marcin Kuzminski <marcin@python-works.com>
parents:
3212
diff
changeset
|
1249 if show_empty_group: |
b4daef4cc26d
Group management delegation:
Marcin Kuzminski <marcin@python-works.com>
parents:
3212
diff
changeset
|
1250 repo_groups = [('-1', '-- no parent --')] |
1547
fbc762ae3496
unified generation of repo groups choices
Marcin Kuzminski <marcin@python-works.com>
parents:
1546
diff
changeset
|
1251 sep = ' » ' |
1593 | 1252 _name = lambda k: _literal(sep.join(k)) |
1547
fbc762ae3496
unified generation of repo groups choices
Marcin Kuzminski <marcin@python-works.com>
parents:
1546
diff
changeset
|
1253 |
1593 | 1254 repo_groups.extend([(x.group_id, _name(x.full_path_splitted)) |
2835
faffec4abbda
Implemented permissions for writing to repo
Marcin Kuzminski <marcin@python-works.com>
parents:
2821
diff
changeset
|
1255 for x in groups]) |
1591 | 1256 |
1594 | 1257 repo_groups = sorted(repo_groups, key=lambda t: t[1].split(sep)[0]) |
1547
fbc762ae3496
unified generation of repo groups choices
Marcin Kuzminski <marcin@python-works.com>
parents:
1546
diff
changeset
|
1258 return repo_groups |
1591 | 1259 |
1547
fbc762ae3496
unified generation of repo groups choices
Marcin Kuzminski <marcin@python-works.com>
parents:
1546
diff
changeset
|
1260 @classmethod |
1593 | 1261 def url_sep(cls): |
2339
79b3c9c66c54
Added optional repo_name into issue tracker url to get just the name of repo without group prefix
Marcin Kuzminski <marcin@python-works.com>
parents:
2251
diff
changeset
|
1262 return URL_SEP |
1346
cf78d302d441
#47 implemented deleting of empty groups. Fixed problem with full paths on nested groups
Marcin Kuzminski <marcin@python-works.com>
parents:
1345
diff
changeset
|
1263 |
1538
27be8f94c207
implements #226 repo groups available by path
Marcin Kuzminski <marcin@python-works.com>
parents:
1530
diff
changeset
|
1264 @classmethod |
1594 | 1265 def get_by_group_name(cls, group_name, cache=False, case_insensitive=False): |
1584
3338a0994472
Improve API with user/group/repo CRUD methods
Nicolas VINOT <aeris@imirhil.fr>
parents:
1508
diff
changeset
|
1266 if case_insensitive: |
3338a0994472
Improve API with user/group/repo CRUD methods
Nicolas VINOT <aeris@imirhil.fr>
parents:
1508
diff
changeset
|
1267 gr = cls.query()\ |
1593 | 1268 .filter(cls.group_name.ilike(group_name)) |
1584
3338a0994472
Improve API with user/group/repo CRUD methods
Nicolas VINOT <aeris@imirhil.fr>
parents:
1508
diff
changeset
|
1269 else: |
3338a0994472
Improve API with user/group/repo CRUD methods
Nicolas VINOT <aeris@imirhil.fr>
parents:
1508
diff
changeset
|
1270 gr = cls.query()\ |
1593 | 1271 .filter(cls.group_name == group_name) |
1584
3338a0994472
Improve API with user/group/repo CRUD methods
Nicolas VINOT <aeris@imirhil.fr>
parents:
1508
diff
changeset
|
1272 if cache: |
2062
bf8ed0adbc66
fixes #371 fixed issues with beaker/sqlalchemy and non-ascii cache keys
Marcin Kuzminski <marcin@python-works.com>
parents:
2058
diff
changeset
|
1273 gr = gr.options(FromCache( |
bf8ed0adbc66
fixes #371 fixed issues with beaker/sqlalchemy and non-ascii cache keys
Marcin Kuzminski <marcin@python-works.com>
parents:
2058
diff
changeset
|
1274 "sql_cache_short", |
bf8ed0adbc66
fixes #371 fixed issues with beaker/sqlalchemy and non-ascii cache keys
Marcin Kuzminski <marcin@python-works.com>
parents:
2058
diff
changeset
|
1275 "get_group_%s" % _hash_key(group_name) |
bf8ed0adbc66
fixes #371 fixed issues with beaker/sqlalchemy and non-ascii cache keys
Marcin Kuzminski <marcin@python-works.com>
parents:
2058
diff
changeset
|
1276 ) |
bf8ed0adbc66
fixes #371 fixed issues with beaker/sqlalchemy and non-ascii cache keys
Marcin Kuzminski <marcin@python-works.com>
parents:
2058
diff
changeset
|
1277 ) |
1584
3338a0994472
Improve API with user/group/repo CRUD methods
Nicolas VINOT <aeris@imirhil.fr>
parents:
1508
diff
changeset
|
1278 return gr.scalar() |
1538
27be8f94c207
implements #226 repo groups available by path
Marcin Kuzminski <marcin@python-works.com>
parents:
1530
diff
changeset
|
1279 |
1159
187a924ed653
Changes for repo groups
Marcin Kuzminski <marcin@python-works.com>
parents:
1155
diff
changeset
|
1280 @property |
1593 | 1281 def parents(self): |
1385
7e221629a3e5
#209 Added recursive count on repositories to calculate all repos within all nested groups
Marcin Kuzminski <marcin@python-works.com>
parents:
1381
diff
changeset
|
1282 parents_recursion_limit = 5 |
1159
187a924ed653
Changes for repo groups
Marcin Kuzminski <marcin@python-works.com>
parents:
1155
diff
changeset
|
1283 groups = [] |
187a924ed653
Changes for repo groups
Marcin Kuzminski <marcin@python-works.com>
parents:
1155
diff
changeset
|
1284 if self.parent_group is None: |
187a924ed653
Changes for repo groups
Marcin Kuzminski <marcin@python-works.com>
parents:
1155
diff
changeset
|
1285 return groups |
187a924ed653
Changes for repo groups
Marcin Kuzminski <marcin@python-works.com>
parents:
1155
diff
changeset
|
1286 cur_gr = self.parent_group |
1593 | 1287 groups.insert(0, cur_gr) |
1349
526120c77a38
#47 added editing of groups, and moving them between. Added check constraint for groups
Marcin Kuzminski <marcin@python-works.com>
parents:
1346
diff
changeset
|
1288 cnt = 0 |
1159
187a924ed653
Changes for repo groups
Marcin Kuzminski <marcin@python-works.com>
parents:
1155
diff
changeset
|
1289 while 1: |
1349
526120c77a38
#47 added editing of groups, and moving them between. Added check constraint for groups
Marcin Kuzminski <marcin@python-works.com>
parents:
1346
diff
changeset
|
1290 cnt += 1 |
1593 | 1291 gr = getattr(cur_gr, 'parent_group', None) |
1159
187a924ed653
Changes for repo groups
Marcin Kuzminski <marcin@python-works.com>
parents:
1155
diff
changeset
|
1292 cur_gr = cur_gr.parent_group |
187a924ed653
Changes for repo groups
Marcin Kuzminski <marcin@python-works.com>
parents:
1155
diff
changeset
|
1293 if gr is None: |
187a924ed653
Changes for repo groups
Marcin Kuzminski <marcin@python-works.com>
parents:
1155
diff
changeset
|
1294 break |
1385
7e221629a3e5
#209 Added recursive count on repositories to calculate all repos within all nested groups
Marcin Kuzminski <marcin@python-works.com>
parents:
1381
diff
changeset
|
1295 if cnt == parents_recursion_limit: |
1349
526120c77a38
#47 added editing of groups, and moving them between. Added check constraint for groups
Marcin Kuzminski <marcin@python-works.com>
parents:
1346
diff
changeset
|
1296 # this will prevent accidental infinit loops |
1593 | 1297 log.error('group nested more than %s' % |
1298 parents_recursion_limit) | |
1349
526120c77a38
#47 added editing of groups, and moving them between. Added check constraint for groups
Marcin Kuzminski <marcin@python-works.com>
parents:
1346
diff
changeset
|
1299 break |
526120c77a38
#47 added editing of groups, and moving them between. Added check constraint for groups
Marcin Kuzminski <marcin@python-works.com>
parents:
1346
diff
changeset
|
1300 |
1593 | 1301 groups.insert(0, gr) |
1159
187a924ed653
Changes for repo groups
Marcin Kuzminski <marcin@python-works.com>
parents:
1155
diff
changeset
|
1302 return groups |
187a924ed653
Changes for repo groups
Marcin Kuzminski <marcin@python-works.com>
parents:
1155
diff
changeset
|
1303 |
1385
7e221629a3e5
#209 Added recursive count on repositories to calculate all repos within all nested groups
Marcin Kuzminski <marcin@python-works.com>
parents:
1381
diff
changeset
|
1304 @property |
1593 | 1305 def children(self): |
1633
2c0d35e336b5
refactoring of models names for repoGroup permissions
Marcin Kuzminski <marcin@python-works.com>
parents:
1607
diff
changeset
|
1306 return RepoGroup.query().filter(RepoGroup.parent_group == self) |
1323
a7a772ea7b95
fixed saving settings on repositories inside groups, also fixes #187
Marcin Kuzminski <marcin@python-works.com>
parents:
1301
diff
changeset
|
1307 |
a7a772ea7b95
fixed saving settings on repositories inside groups, also fixes #187
Marcin Kuzminski <marcin@python-works.com>
parents:
1301
diff
changeset
|
1308 @property |
1593 | 1309 def name(self): |
1633
2c0d35e336b5
refactoring of models names for repoGroup permissions
Marcin Kuzminski <marcin@python-works.com>
parents:
1607
diff
changeset
|
1310 return self.group_name.split(RepoGroup.url_sep())[-1] |
1538
27be8f94c207
implements #226 repo groups available by path
Marcin Kuzminski <marcin@python-works.com>
parents:
1530
diff
changeset
|
1311 |
27be8f94c207
implements #226 repo groups available by path
Marcin Kuzminski <marcin@python-works.com>
parents:
1530
diff
changeset
|
1312 @property |
1593 | 1313 def full_path(self): |
1594 | 1314 return self.group_name |
1538
27be8f94c207
implements #226 repo groups available by path
Marcin Kuzminski <marcin@python-works.com>
parents:
1530
diff
changeset
|
1315 |
27be8f94c207
implements #226 repo groups available by path
Marcin Kuzminski <marcin@python-works.com>
parents:
1530
diff
changeset
|
1316 @property |
1593 | 1317 def full_path_splitted(self): |
1633
2c0d35e336b5
refactoring of models names for repoGroup permissions
Marcin Kuzminski <marcin@python-works.com>
parents:
1607
diff
changeset
|
1318 return self.group_name.split(RepoGroup.url_sep()) |
1323
a7a772ea7b95
fixed saving settings on repositories inside groups, also fixes #187
Marcin Kuzminski <marcin@python-works.com>
parents:
1301
diff
changeset
|
1319 |
1193
523382549c45
Added repo group page showing what reposiories are inside a group
Marcin Kuzminski <marcin@python-works.com>
parents:
1159
diff
changeset
|
1320 @property |
1593 | 1321 def repositories(self): |
2079
477fe54b8af8
fixed sorting of repos in group
Marcin Kuzminski <marcin@python-works.com>
parents:
2063
diff
changeset
|
1322 return Repository.query()\ |
477fe54b8af8
fixed sorting of repos in group
Marcin Kuzminski <marcin@python-works.com>
parents:
2063
diff
changeset
|
1323 .filter(Repository.group == self)\ |
477fe54b8af8
fixed sorting of repos in group
Marcin Kuzminski <marcin@python-works.com>
parents:
2063
diff
changeset
|
1324 .order_by(Repository.repo_name) |
1193
523382549c45
Added repo group page showing what reposiories are inside a group
Marcin Kuzminski <marcin@python-works.com>
parents:
1159
diff
changeset
|
1325 |
1385
7e221629a3e5
#209 Added recursive count on repositories to calculate all repos within all nested groups
Marcin Kuzminski <marcin@python-works.com>
parents:
1381
diff
changeset
|
1326 @property |
1593 | 1327 def repositories_recursive_count(self): |
1385
7e221629a3e5
#209 Added recursive count on repositories to calculate all repos within all nested groups
Marcin Kuzminski <marcin@python-works.com>
parents:
1381
diff
changeset
|
1328 cnt = self.repositories.count() |
7e221629a3e5
#209 Added recursive count on repositories to calculate all repos within all nested groups
Marcin Kuzminski <marcin@python-works.com>
parents:
1381
diff
changeset
|
1329 |
1593 | 1330 def children_count(group): |
1385
7e221629a3e5
#209 Added recursive count on repositories to calculate all repos within all nested groups
Marcin Kuzminski <marcin@python-works.com>
parents:
1381
diff
changeset
|
1331 cnt = 0 |
7e221629a3e5
#209 Added recursive count on repositories to calculate all repos within all nested groups
Marcin Kuzminski <marcin@python-works.com>
parents:
1381
diff
changeset
|
1332 for child in group.children: |
7e221629a3e5
#209 Added recursive count on repositories to calculate all repos within all nested groups
Marcin Kuzminski <marcin@python-works.com>
parents:
1381
diff
changeset
|
1333 cnt += child.repositories.count() |
1593 | 1334 cnt += children_count(child) |
1385
7e221629a3e5
#209 Added recursive count on repositories to calculate all repos within all nested groups
Marcin Kuzminski <marcin@python-works.com>
parents:
1381
diff
changeset
|
1335 return cnt |
7e221629a3e5
#209 Added recursive count on repositories to calculate all repos within all nested groups
Marcin Kuzminski <marcin@python-works.com>
parents:
1381
diff
changeset
|
1336 |
1593 | 1337 return cnt + children_count(self) |
1385
7e221629a3e5
#209 Added recursive count on repositories to calculate all repos within all nested groups
Marcin Kuzminski <marcin@python-works.com>
parents:
1381
diff
changeset
|
1338 |
2749
3ed4dae499d0
Recursive set locking on all children of a group.
Marcin Kuzminski <marcin@python-works.com>
parents:
2731
diff
changeset
|
1339 def recursive_groups_and_repos(self): |
3ed4dae499d0
Recursive set locking on all children of a group.
Marcin Kuzminski <marcin@python-works.com>
parents:
2731
diff
changeset
|
1340 """ |
3ed4dae499d0
Recursive set locking on all children of a group.
Marcin Kuzminski <marcin@python-works.com>
parents:
2731
diff
changeset
|
1341 Recursive return all groups, with repositories in those groups |
3ed4dae499d0
Recursive set locking on all children of a group.
Marcin Kuzminski <marcin@python-works.com>
parents:
2731
diff
changeset
|
1342 """ |
3ed4dae499d0
Recursive set locking on all children of a group.
Marcin Kuzminski <marcin@python-works.com>
parents:
2731
diff
changeset
|
1343 all_ = [] |
3ed4dae499d0
Recursive set locking on all children of a group.
Marcin Kuzminski <marcin@python-works.com>
parents:
2731
diff
changeset
|
1344 |
3ed4dae499d0
Recursive set locking on all children of a group.
Marcin Kuzminski <marcin@python-works.com>
parents:
2731
diff
changeset
|
1345 def _get_members(root_gr): |
3ed4dae499d0
Recursive set locking on all children of a group.
Marcin Kuzminski <marcin@python-works.com>
parents:
2731
diff
changeset
|
1346 for r in root_gr.repositories: |
3ed4dae499d0
Recursive set locking on all children of a group.
Marcin Kuzminski <marcin@python-works.com>
parents:
2731
diff
changeset
|
1347 all_.append(r) |
3ed4dae499d0
Recursive set locking on all children of a group.
Marcin Kuzminski <marcin@python-works.com>
parents:
2731
diff
changeset
|
1348 childs = root_gr.children.all() |
3ed4dae499d0
Recursive set locking on all children of a group.
Marcin Kuzminski <marcin@python-works.com>
parents:
2731
diff
changeset
|
1349 if childs: |
3ed4dae499d0
Recursive set locking on all children of a group.
Marcin Kuzminski <marcin@python-works.com>
parents:
2731
diff
changeset
|
1350 for gr in childs: |
3ed4dae499d0
Recursive set locking on all children of a group.
Marcin Kuzminski <marcin@python-works.com>
parents:
2731
diff
changeset
|
1351 all_.append(gr) |
3ed4dae499d0
Recursive set locking on all children of a group.
Marcin Kuzminski <marcin@python-works.com>
parents:
2731
diff
changeset
|
1352 _get_members(gr) |
3ed4dae499d0
Recursive set locking on all children of a group.
Marcin Kuzminski <marcin@python-works.com>
parents:
2731
diff
changeset
|
1353 |
3ed4dae499d0
Recursive set locking on all children of a group.
Marcin Kuzminski <marcin@python-works.com>
parents:
2731
diff
changeset
|
1354 _get_members(self) |
3ed4dae499d0
Recursive set locking on all children of a group.
Marcin Kuzminski <marcin@python-works.com>
parents:
2731
diff
changeset
|
1355 return [self] + all_ |
3ed4dae499d0
Recursive set locking on all children of a group.
Marcin Kuzminski <marcin@python-works.com>
parents:
2731
diff
changeset
|
1356 |
1593 | 1357 def get_new_name(self, group_name): |
1538
27be8f94c207
implements #226 repo groups available by path
Marcin Kuzminski <marcin@python-works.com>
parents:
1530
diff
changeset
|
1358 """ |
27be8f94c207
implements #226 repo groups available by path
Marcin Kuzminski <marcin@python-works.com>
parents:
1530
diff
changeset
|
1359 returns new full group name based on parent and new name |
1591 | 1360 |
1538
27be8f94c207
implements #226 repo groups available by path
Marcin Kuzminski <marcin@python-works.com>
parents:
1530
diff
changeset
|
1361 :param group_name: |
27be8f94c207
implements #226 repo groups available by path
Marcin Kuzminski <marcin@python-works.com>
parents:
1530
diff
changeset
|
1362 """ |
1607
e886f91fcb71
Cached readme generation
Marcin Kuzminski <marcin@python-works.com>
parents:
1594
diff
changeset
|
1363 path_prefix = (self.parent_group.full_path_splitted if |
1594 | 1364 self.parent_group else []) |
1633
2c0d35e336b5
refactoring of models names for repoGroup permissions
Marcin Kuzminski <marcin@python-works.com>
parents:
1607
diff
changeset
|
1365 return RepoGroup.url_sep().join(path_prefix + [group_name]) |
1538
27be8f94c207
implements #226 repo groups available by path
Marcin Kuzminski <marcin@python-works.com>
parents:
1530
diff
changeset
|
1366 |
27be8f94c207
implements #226 repo groups available by path
Marcin Kuzminski <marcin@python-works.com>
parents:
1530
diff
changeset
|
1367 |
1593 | 1368 class Permission(Base, BaseModel): |
226
c6526b7531e9
rewritten db manage script to use sqlalchemy. Fixed sqlalchemy models to more generic.
Marcin Kuzminski <marcin@python-works.com>
parents:
89
diff
changeset
|
1369 __tablename__ = 'permissions' |
2149 | 1370 __table_args__ = ( |
2463
b426ecc30319
Added some DB indexes to optimize queries
Marcin Kuzminski <marcin@python-works.com>
parents:
2462
diff
changeset
|
1371 Index('p_perm_name_idx', 'permission_name'), |
2356
2da7b5984ae5
typo fix + code garden
Marcin Kuzminski <marcin@python-works.com>
parents:
2352
diff
changeset
|
1372 {'extend_existing': True, 'mysql_engine': 'InnoDB', |
2149 | 1373 'mysql_charset': 'utf8'}, |
1374 ) | |
2532
19de74e33fb0
Better descriptions of given permission overview in edit user view
Marcin Kuzminski <marcin@python-works.com>
parents:
2531
diff
changeset
|
1375 PERMS = [ |
19de74e33fb0
Better descriptions of given permission overview in edit user view
Marcin Kuzminski <marcin@python-works.com>
parents:
2531
diff
changeset
|
1376 ('repository.none', _('Repository no access')), |
19de74e33fb0
Better descriptions of given permission overview in edit user view
Marcin Kuzminski <marcin@python-works.com>
parents:
2531
diff
changeset
|
1377 ('repository.read', _('Repository read access')), |
19de74e33fb0
Better descriptions of given permission overview in edit user view
Marcin Kuzminski <marcin@python-works.com>
parents:
2531
diff
changeset
|
1378 ('repository.write', _('Repository write access')), |
19de74e33fb0
Better descriptions of given permission overview in edit user view
Marcin Kuzminski <marcin@python-works.com>
parents:
2531
diff
changeset
|
1379 ('repository.admin', _('Repository admin access')), |
19de74e33fb0
Better descriptions of given permission overview in edit user view
Marcin Kuzminski <marcin@python-works.com>
parents:
2531
diff
changeset
|
1380 |
3416
5706f6ab60cf
follow-up on texts missing from 'users groups'/'repositories group' cleanup
Mads Kiilerich <madski@unity3d.com>
parents:
3370
diff
changeset
|
1381 ('group.none', _('Repository group no access')), |
5706f6ab60cf
follow-up on texts missing from 'users groups'/'repositories group' cleanup
Mads Kiilerich <madski@unity3d.com>
parents:
3370
diff
changeset
|
1382 ('group.read', _('Repository group read access')), |
5706f6ab60cf
follow-up on texts missing from 'users groups'/'repositories group' cleanup
Mads Kiilerich <madski@unity3d.com>
parents:
3370
diff
changeset
|
1383 ('group.write', _('Repository group write access')), |
5706f6ab60cf
follow-up on texts missing from 'users groups'/'repositories group' cleanup
Mads Kiilerich <madski@unity3d.com>
parents:
3370
diff
changeset
|
1384 ('group.admin', _('Repository group admin access')), |
2532
19de74e33fb0
Better descriptions of given permission overview in edit user view
Marcin Kuzminski <marcin@python-works.com>
parents:
2531
diff
changeset
|
1385 |
19de74e33fb0
Better descriptions of given permission overview in edit user view
Marcin Kuzminski <marcin@python-works.com>
parents:
2531
diff
changeset
|
1386 ('hg.admin', _('RhodeCode Administrator')), |
19de74e33fb0
Better descriptions of given permission overview in edit user view
Marcin Kuzminski <marcin@python-works.com>
parents:
2531
diff
changeset
|
1387 ('hg.create.none', _('Repository creation disabled')), |
19de74e33fb0
Better descriptions of given permission overview in edit user view
Marcin Kuzminski <marcin@python-works.com>
parents:
2531
diff
changeset
|
1388 ('hg.create.repository', _('Repository creation enabled')), |
2709
d2d35cf2b351
RhodeCode now has a option to explicitly set forking permissions. ref #508
Marcin Kuzminski <marcin@python-works.com>
parents:
2708
diff
changeset
|
1389 ('hg.fork.none', _('Repository forking disabled')), |
d2d35cf2b351
RhodeCode now has a option to explicitly set forking permissions. ref #508
Marcin Kuzminski <marcin@python-works.com>
parents:
2708
diff
changeset
|
1390 ('hg.fork.repository', _('Repository forking enabled')), |
2532
19de74e33fb0
Better descriptions of given permission overview in edit user view
Marcin Kuzminski <marcin@python-works.com>
parents:
2531
diff
changeset
|
1391 ('hg.register.none', _('Register disabled')), |
19de74e33fb0
Better descriptions of given permission overview in edit user view
Marcin Kuzminski <marcin@python-works.com>
parents:
2531
diff
changeset
|
1392 ('hg.register.manual_activate', _('Register new user with RhodeCode ' |
19de74e33fb0
Better descriptions of given permission overview in edit user view
Marcin Kuzminski <marcin@python-works.com>
parents:
2531
diff
changeset
|
1393 'with manual activation')), |
19de74e33fb0
Better descriptions of given permission overview in edit user view
Marcin Kuzminski <marcin@python-works.com>
parents:
2531
diff
changeset
|
1394 |
19de74e33fb0
Better descriptions of given permission overview in edit user view
Marcin Kuzminski <marcin@python-works.com>
parents:
2531
diff
changeset
|
1395 ('hg.register.auto_activate', _('Register new user with RhodeCode ' |
19de74e33fb0
Better descriptions of given permission overview in edit user view
Marcin Kuzminski <marcin@python-works.com>
parents:
2531
diff
changeset
|
1396 'with auto activation')), |
19de74e33fb0
Better descriptions of given permission overview in edit user view
Marcin Kuzminski <marcin@python-works.com>
parents:
2531
diff
changeset
|
1397 ] |
19de74e33fb0
Better descriptions of given permission overview in edit user view
Marcin Kuzminski <marcin@python-works.com>
parents:
2531
diff
changeset
|
1398 |
2709
d2d35cf2b351
RhodeCode now has a option to explicitly set forking permissions. ref #508
Marcin Kuzminski <marcin@python-works.com>
parents:
2708
diff
changeset
|
1399 # defines which permissions are more important higher the more important |
d2d35cf2b351
RhodeCode now has a option to explicitly set forking permissions. ref #508
Marcin Kuzminski <marcin@python-works.com>
parents:
2708
diff
changeset
|
1400 PERM_WEIGHTS = { |
d2d35cf2b351
RhodeCode now has a option to explicitly set forking permissions. ref #508
Marcin Kuzminski <marcin@python-works.com>
parents:
2708
diff
changeset
|
1401 'repository.none': 0, |
d2d35cf2b351
RhodeCode now has a option to explicitly set forking permissions. ref #508
Marcin Kuzminski <marcin@python-works.com>
parents:
2708
diff
changeset
|
1402 'repository.read': 1, |
d2d35cf2b351
RhodeCode now has a option to explicitly set forking permissions. ref #508
Marcin Kuzminski <marcin@python-works.com>
parents:
2708
diff
changeset
|
1403 'repository.write': 3, |
d2d35cf2b351
RhodeCode now has a option to explicitly set forking permissions. ref #508
Marcin Kuzminski <marcin@python-works.com>
parents:
2708
diff
changeset
|
1404 'repository.admin': 4, |
d2d35cf2b351
RhodeCode now has a option to explicitly set forking permissions. ref #508
Marcin Kuzminski <marcin@python-works.com>
parents:
2708
diff
changeset
|
1405 |
d2d35cf2b351
RhodeCode now has a option to explicitly set forking permissions. ref #508
Marcin Kuzminski <marcin@python-works.com>
parents:
2708
diff
changeset
|
1406 'group.none': 0, |
d2d35cf2b351
RhodeCode now has a option to explicitly set forking permissions. ref #508
Marcin Kuzminski <marcin@python-works.com>
parents:
2708
diff
changeset
|
1407 'group.read': 1, |
d2d35cf2b351
RhodeCode now has a option to explicitly set forking permissions. ref #508
Marcin Kuzminski <marcin@python-works.com>
parents:
2708
diff
changeset
|
1408 'group.write': 3, |
d2d35cf2b351
RhodeCode now has a option to explicitly set forking permissions. ref #508
Marcin Kuzminski <marcin@python-works.com>
parents:
2708
diff
changeset
|
1409 'group.admin': 4, |
d2d35cf2b351
RhodeCode now has a option to explicitly set forking permissions. ref #508
Marcin Kuzminski <marcin@python-works.com>
parents:
2708
diff
changeset
|
1410 |
d2d35cf2b351
RhodeCode now has a option to explicitly set forking permissions. ref #508
Marcin Kuzminski <marcin@python-works.com>
parents:
2708
diff
changeset
|
1411 'hg.fork.none': 0, |
d2d35cf2b351
RhodeCode now has a option to explicitly set forking permissions. ref #508
Marcin Kuzminski <marcin@python-works.com>
parents:
2708
diff
changeset
|
1412 'hg.fork.repository': 1, |
d2d35cf2b351
RhodeCode now has a option to explicitly set forking permissions. ref #508
Marcin Kuzminski <marcin@python-works.com>
parents:
2708
diff
changeset
|
1413 'hg.create.none': 0, |
d2d35cf2b351
RhodeCode now has a option to explicitly set forking permissions. ref #508
Marcin Kuzminski <marcin@python-works.com>
parents:
2708
diff
changeset
|
1414 'hg.create.repository':1 |
d2d35cf2b351
RhodeCode now has a option to explicitly set forking permissions. ref #508
Marcin Kuzminski <marcin@python-works.com>
parents:
2708
diff
changeset
|
1415 } |
d2d35cf2b351
RhodeCode now has a option to explicitly set forking permissions. ref #508
Marcin Kuzminski <marcin@python-works.com>
parents:
2708
diff
changeset
|
1416 |
1594 | 1417 permission_id = Column("permission_id", Integer(), nullable=False, unique=True, default=None, primary_key=True) |
2588
32dd6896abcf
added status column to pull request + some small refactoring of models
Marcin Kuzminski <marcin@python-works.com>
parents:
2585
diff
changeset
|
1418 permission_name = Column("permission_name", String(255, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None) |
32dd6896abcf
added status column to pull request + some small refactoring of models
Marcin Kuzminski <marcin@python-works.com>
parents:
2585
diff
changeset
|
1419 permission_longname = Column("permission_longname", String(255, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None) |
631
05528ad948c4
Hacking for git support,and new faster repo scan
Marcin Kuzminski <marcin@python-works.com>
parents:
549
diff
changeset
|
1420 |
2156
a27e4d44237e
Use __unicode__ instead of __repr__ in models.
Marcin Kuzminski <marcin@python-works.com>
parents:
2152
diff
changeset
|
1421 def __unicode__(self): |
a27e4d44237e
Use __unicode__ instead of __repr__ in models.
Marcin Kuzminski <marcin@python-works.com>
parents:
2152
diff
changeset
|
1422 return u"<%s('%s:%s')>" % ( |
1982
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1976
diff
changeset
|
1423 self.__class__.__name__, self.permission_id, self.permission_name |
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1976
diff
changeset
|
1424 ) |
296
29370bb76fa6
first permissions commit: added permission managment on repository edit. Changed db rmissions, validators.
Marcin Kuzminski <marcin@python-works.com>
parents:
265
diff
changeset
|
1425 |
1266
a1bcfe58a1ab
Fixed #161 form saves the create repository permission.
Marcin Kuzminski <marcin@python-works.com>
parents:
1206
diff
changeset
|
1426 @classmethod |
1593 | 1427 def get_by_key(cls, key): |
1428 return cls.query().filter(cls.permission_name == key).scalar() | |
1266
a1bcfe58a1ab
Fixed #161 form saves the create repository permission.
Marcin Kuzminski <marcin@python-works.com>
parents:
1206
diff
changeset
|
1429 |
1728
07e56179633e
- fixes celery sqlalchemy session issues for async forking
Marcin Kuzminski <marcin@python-works.com>
parents:
1727
diff
changeset
|
1430 @classmethod |
1744
d41a115d9a39
remove cache from default perms. In some cases of concurrent repo removal it crashed.
Marcin Kuzminski <marcin@python-works.com>
parents:
1733
diff
changeset
|
1431 def get_default_perms(cls, default_user_id): |
2520
a1e156503afe
Fixed calls to Session in db model
Marcin Kuzminski <marcin@python-works.com>
parents:
2510
diff
changeset
|
1432 q = Session().query(UserRepoToPerm, Repository, cls)\ |
1982
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1976
diff
changeset
|
1433 .join((Repository, UserRepoToPerm.repository_id == Repository.repo_id))\ |
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1976
diff
changeset
|
1434 .join((cls, UserRepoToPerm.permission_id == cls.permission_id))\ |
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1976
diff
changeset
|
1435 .filter(UserRepoToPerm.user_id == default_user_id) |
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1976
diff
changeset
|
1436 |
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1976
diff
changeset
|
1437 return q.all() |
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1976
diff
changeset
|
1438 |
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1976
diff
changeset
|
1439 @classmethod |
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1976
diff
changeset
|
1440 def get_default_group_perms(cls, default_user_id): |
2520
a1e156503afe
Fixed calls to Session in db model
Marcin Kuzminski <marcin@python-works.com>
parents:
2510
diff
changeset
|
1441 q = Session().query(UserRepoGroupToPerm, RepoGroup, cls)\ |
1982
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1976
diff
changeset
|
1442 .join((RepoGroup, UserRepoGroupToPerm.group_id == RepoGroup.group_id))\ |
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1976
diff
changeset
|
1443 .join((cls, UserRepoGroupToPerm.permission_id == cls.permission_id))\ |
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1976
diff
changeset
|
1444 .filter(UserRepoGroupToPerm.user_id == default_user_id) |
1728
07e56179633e
- fixes celery sqlalchemy session issues for async forking
Marcin Kuzminski <marcin@python-works.com>
parents:
1727
diff
changeset
|
1445 |
07e56179633e
- fixes celery sqlalchemy session issues for async forking
Marcin Kuzminski <marcin@python-works.com>
parents:
1727
diff
changeset
|
1446 return q.all() |
07e56179633e
- fixes celery sqlalchemy session issues for async forking
Marcin Kuzminski <marcin@python-works.com>
parents:
1727
diff
changeset
|
1447 |
07e56179633e
- fixes celery sqlalchemy session issues for async forking
Marcin Kuzminski <marcin@python-works.com>
parents:
1727
diff
changeset
|
1448 |
1633
2c0d35e336b5
refactoring of models names for repoGroup permissions
Marcin Kuzminski <marcin@python-works.com>
parents:
1607
diff
changeset
|
1449 class UserRepoToPerm(Base, BaseModel): |
296
29370bb76fa6
first permissions commit: added permission managment on repository edit. Changed db rmissions, validators.
Marcin Kuzminski <marcin@python-works.com>
parents:
265
diff
changeset
|
1450 __tablename__ = 'repo_to_perm' |
1958
7e4b3d3a9c5c
renamed repo groups table
Marcin Kuzminski <marcin@python-works.com>
parents:
1950
diff
changeset
|
1451 __table_args__ = ( |
2000
72c525a7e7ad
added migrations from 1.2.X to 1.3
Marcin Kuzminski <marcin@python-works.com>
parents:
1990
diff
changeset
|
1452 UniqueConstraint('user_id', 'repository_id', 'permission_id'), |
2356
2da7b5984ae5
typo fix + code garden
Marcin Kuzminski <marcin@python-works.com>
parents:
2352
diff
changeset
|
1453 {'extend_existing': True, 'mysql_engine': 'InnoDB', |
2149 | 1454 'mysql_charset': 'utf8'} |
1958
7e4b3d3a9c5c
renamed repo groups table
Marcin Kuzminski <marcin@python-works.com>
parents:
1950
diff
changeset
|
1455 ) |
1594 | 1456 repo_to_perm_id = Column("repo_to_perm_id", Integer(), nullable=False, unique=True, default=None, primary_key=True) |
1457 user_id = Column("user_id", Integer(), ForeignKey('users.user_id'), nullable=False, unique=None, default=None) | |
1458 permission_id = Column("permission_id", Integer(), ForeignKey('permissions.permission_id'), nullable=False, unique=None, default=None) | |
1459 repository_id = Column("repository_id", Integer(), ForeignKey('repositories.repo_id'), nullable=False, unique=None, default=None) | |
631
05528ad948c4
Hacking for git support,and new faster repo scan
Marcin Kuzminski <marcin@python-works.com>
parents:
549
diff
changeset
|
1460 |
1593 | 1461 user = relationship('User') |
2000
72c525a7e7ad
added migrations from 1.2.X to 1.3
Marcin Kuzminski <marcin@python-works.com>
parents:
1990
diff
changeset
|
1462 repository = relationship('Repository') |
1593 | 1463 permission = relationship('Permission') |
399
f5c1eec9f376
rename repo2perm into repo_to_perm
Marcin Kuzminski <marcin@python-works.com>
parents:
392
diff
changeset
|
1464 |
1729
da8ee2ef7f6d
implements #236 forking copy permission option
Marcin Kuzminski <marcin@python-works.com>
parents:
1728
diff
changeset
|
1465 @classmethod |
da8ee2ef7f6d
implements #236 forking copy permission option
Marcin Kuzminski <marcin@python-works.com>
parents:
1728
diff
changeset
|
1466 def create(cls, user, repository, permission): |
da8ee2ef7f6d
implements #236 forking copy permission option
Marcin Kuzminski <marcin@python-works.com>
parents:
1728
diff
changeset
|
1467 n = cls() |
da8ee2ef7f6d
implements #236 forking copy permission option
Marcin Kuzminski <marcin@python-works.com>
parents:
1728
diff
changeset
|
1468 n.user = user |
da8ee2ef7f6d
implements #236 forking copy permission option
Marcin Kuzminski <marcin@python-works.com>
parents:
1728
diff
changeset
|
1469 n.repository = repository |
da8ee2ef7f6d
implements #236 forking copy permission option
Marcin Kuzminski <marcin@python-works.com>
parents:
1728
diff
changeset
|
1470 n.permission = permission |
2520
a1e156503afe
Fixed calls to Session in db model
Marcin Kuzminski <marcin@python-works.com>
parents:
2510
diff
changeset
|
1471 Session().add(n) |
1729
da8ee2ef7f6d
implements #236 forking copy permission option
Marcin Kuzminski <marcin@python-works.com>
parents:
1728
diff
changeset
|
1472 return n |
da8ee2ef7f6d
implements #236 forking copy permission option
Marcin Kuzminski <marcin@python-works.com>
parents:
1728
diff
changeset
|
1473 |
2156
a27e4d44237e
Use __unicode__ instead of __repr__ in models.
Marcin Kuzminski <marcin@python-works.com>
parents:
2152
diff
changeset
|
1474 def __unicode__(self): |
a27e4d44237e
Use __unicode__ instead of __repr__ in models.
Marcin Kuzminski <marcin@python-works.com>
parents:
2152
diff
changeset
|
1475 return u'<user:%s => %s >' % (self.user, self.repository) |
1729
da8ee2ef7f6d
implements #236 forking copy permission option
Marcin Kuzminski <marcin@python-works.com>
parents:
1728
diff
changeset
|
1476 |
1800 | 1477 |
1593 | 1478 class UserToPerm(Base, BaseModel): |
399
f5c1eec9f376
rename repo2perm into repo_to_perm
Marcin Kuzminski <marcin@python-works.com>
parents:
392
diff
changeset
|
1479 __tablename__ = 'user_to_perm' |
1988
5eae67552695
db unique constraints fixes
Marcin Kuzminski <marcin@python-works.com>
parents:
1982
diff
changeset
|
1480 __table_args__ = ( |
5eae67552695
db unique constraints fixes
Marcin Kuzminski <marcin@python-works.com>
parents:
1982
diff
changeset
|
1481 UniqueConstraint('user_id', 'permission_id'), |
2356
2da7b5984ae5
typo fix + code garden
Marcin Kuzminski <marcin@python-works.com>
parents:
2352
diff
changeset
|
1482 {'extend_existing': True, 'mysql_engine': 'InnoDB', |
2149 | 1483 'mysql_charset': 'utf8'} |
1988
5eae67552695
db unique constraints fixes
Marcin Kuzminski <marcin@python-works.com>
parents:
1982
diff
changeset
|
1484 ) |
1594 | 1485 user_to_perm_id = Column("user_to_perm_id", Integer(), nullable=False, unique=True, default=None, primary_key=True) |
1486 user_id = Column("user_id", Integer(), ForeignKey('users.user_id'), nullable=False, unique=None, default=None) | |
1487 permission_id = Column("permission_id", Integer(), ForeignKey('permissions.permission_id'), nullable=False, unique=None, default=None) | |
631
05528ad948c4
Hacking for git support,and new faster repo scan
Marcin Kuzminski <marcin@python-works.com>
parents:
549
diff
changeset
|
1488 |
1593 | 1489 user = relationship('User') |
1728
07e56179633e
- fixes celery sqlalchemy session issues for async forking
Marcin Kuzminski <marcin@python-works.com>
parents:
1727
diff
changeset
|
1490 permission = relationship('Permission', lazy='joined') |
399
f5c1eec9f376
rename repo2perm into repo_to_perm
Marcin Kuzminski <marcin@python-works.com>
parents:
392
diff
changeset
|
1491 |
1014
6fdc3ff65fce
#56 added assignments of users groups into repository
Marcin Kuzminski <marcin@python-works.com>
parents:
1000
diff
changeset
|
1492 |
1593 | 1493 class UsersGroupRepoToPerm(Base, BaseModel): |
1271
aa7e45ad0cea
Fixed permissions for users groups, group can have create repo permission now.
Marcin Kuzminski <marcin@python-works.com>
parents:
1266
diff
changeset
|
1494 __tablename__ = 'users_group_repo_to_perm' |
1958
7e4b3d3a9c5c
renamed repo groups table
Marcin Kuzminski <marcin@python-works.com>
parents:
1950
diff
changeset
|
1495 __table_args__ = ( |
2000
72c525a7e7ad
added migrations from 1.2.X to 1.3
Marcin Kuzminski <marcin@python-works.com>
parents:
1990
diff
changeset
|
1496 UniqueConstraint('repository_id', 'users_group_id', 'permission_id'), |
2356
2da7b5984ae5
typo fix + code garden
Marcin Kuzminski <marcin@python-works.com>
parents:
2352
diff
changeset
|
1497 {'extend_existing': True, 'mysql_engine': 'InnoDB', |
2149 | 1498 'mysql_charset': 'utf8'} |
1958
7e4b3d3a9c5c
renamed repo groups table
Marcin Kuzminski <marcin@python-works.com>
parents:
1950
diff
changeset
|
1499 ) |
1594 | 1500 users_group_to_perm_id = Column("users_group_to_perm_id", Integer(), nullable=False, unique=True, default=None, primary_key=True) |
1501 users_group_id = Column("users_group_id", Integer(), ForeignKey('users_groups.users_group_id'), nullable=False, unique=None, default=None) | |
1502 permission_id = Column("permission_id", Integer(), ForeignKey('permissions.permission_id'), nullable=False, unique=None, default=None) | |
1503 repository_id = Column("repository_id", Integer(), ForeignKey('repositories.repo_id'), nullable=False, unique=None, default=None) | |
958
7d1483f3170b
added user group to perm table
Marcin Kuzminski <marcin@python-works.com>
parents:
956
diff
changeset
|
1504 |
1593 | 1505 users_group = relationship('UsersGroup') |
1506 permission = relationship('Permission') | |
1507 repository = relationship('Repository') | |
958
7d1483f3170b
added user group to perm table
Marcin Kuzminski <marcin@python-works.com>
parents:
956
diff
changeset
|
1508 |
1729
da8ee2ef7f6d
implements #236 forking copy permission option
Marcin Kuzminski <marcin@python-works.com>
parents:
1728
diff
changeset
|
1509 @classmethod |
da8ee2ef7f6d
implements #236 forking copy permission option
Marcin Kuzminski <marcin@python-works.com>
parents:
1728
diff
changeset
|
1510 def create(cls, users_group, repository, permission): |
da8ee2ef7f6d
implements #236 forking copy permission option
Marcin Kuzminski <marcin@python-works.com>
parents:
1728
diff
changeset
|
1511 n = cls() |
da8ee2ef7f6d
implements #236 forking copy permission option
Marcin Kuzminski <marcin@python-works.com>
parents:
1728
diff
changeset
|
1512 n.users_group = users_group |
da8ee2ef7f6d
implements #236 forking copy permission option
Marcin Kuzminski <marcin@python-works.com>
parents:
1728
diff
changeset
|
1513 n.repository = repository |
da8ee2ef7f6d
implements #236 forking copy permission option
Marcin Kuzminski <marcin@python-works.com>
parents:
1728
diff
changeset
|
1514 n.permission = permission |
2520
a1e156503afe
Fixed calls to Session in db model
Marcin Kuzminski <marcin@python-works.com>
parents:
2510
diff
changeset
|
1515 Session().add(n) |
1729
da8ee2ef7f6d
implements #236 forking copy permission option
Marcin Kuzminski <marcin@python-works.com>
parents:
1728
diff
changeset
|
1516 return n |
da8ee2ef7f6d
implements #236 forking copy permission option
Marcin Kuzminski <marcin@python-works.com>
parents:
1728
diff
changeset
|
1517 |
2156
a27e4d44237e
Use __unicode__ instead of __repr__ in models.
Marcin Kuzminski <marcin@python-works.com>
parents:
2152
diff
changeset
|
1518 def __unicode__(self): |
a27e4d44237e
Use __unicode__ instead of __repr__ in models.
Marcin Kuzminski <marcin@python-works.com>
parents:
2152
diff
changeset
|
1519 return u'<userGroup:%s => %s >' % (self.users_group, self.repository) |
1271
aa7e45ad0cea
Fixed permissions for users groups, group can have create repo permission now.
Marcin Kuzminski <marcin@python-works.com>
parents:
1266
diff
changeset
|
1520 |
1800 | 1521 |
1593 | 1522 class UsersGroupToPerm(Base, BaseModel): |
1271
aa7e45ad0cea
Fixed permissions for users groups, group can have create repo permission now.
Marcin Kuzminski <marcin@python-works.com>
parents:
1266
diff
changeset
|
1523 __tablename__ = 'users_group_to_perm' |
1988
5eae67552695
db unique constraints fixes
Marcin Kuzminski <marcin@python-works.com>
parents:
1982
diff
changeset
|
1524 __table_args__ = ( |
5eae67552695
db unique constraints fixes
Marcin Kuzminski <marcin@python-works.com>
parents:
1982
diff
changeset
|
1525 UniqueConstraint('users_group_id', 'permission_id',), |
2356
2da7b5984ae5
typo fix + code garden
Marcin Kuzminski <marcin@python-works.com>
parents:
2352
diff
changeset
|
1526 {'extend_existing': True, 'mysql_engine': 'InnoDB', |
2149 | 1527 'mysql_charset': 'utf8'} |
1988
5eae67552695
db unique constraints fixes
Marcin Kuzminski <marcin@python-works.com>
parents:
1982
diff
changeset
|
1528 ) |
1594 | 1529 users_group_to_perm_id = Column("users_group_to_perm_id", Integer(), nullable=False, unique=True, default=None, primary_key=True) |
1530 users_group_id = Column("users_group_id", Integer(), ForeignKey('users_groups.users_group_id'), nullable=False, unique=None, default=None) | |
1531 permission_id = Column("permission_id", Integer(), ForeignKey('permissions.permission_id'), nullable=False, unique=None, default=None) | |
1271
aa7e45ad0cea
Fixed permissions for users groups, group can have create repo permission now.
Marcin Kuzminski <marcin@python-works.com>
parents:
1266
diff
changeset
|
1532 |
1593 | 1533 users_group = relationship('UsersGroup') |
1534 permission = relationship('Permission') | |
1271
aa7e45ad0cea
Fixed permissions for users groups, group can have create repo permission now.
Marcin Kuzminski <marcin@python-works.com>
parents:
1266
diff
changeset
|
1535 |
aa7e45ad0cea
Fixed permissions for users groups, group can have create repo permission now.
Marcin Kuzminski <marcin@python-works.com>
parents:
1266
diff
changeset
|
1536 |
1633
2c0d35e336b5
refactoring of models names for repoGroup permissions
Marcin Kuzminski <marcin@python-works.com>
parents:
1607
diff
changeset
|
1537 class UserRepoGroupToPerm(Base, BaseModel): |
1958
7e4b3d3a9c5c
renamed repo groups table
Marcin Kuzminski <marcin@python-works.com>
parents:
1950
diff
changeset
|
1538 __tablename__ = 'user_repo_group_to_perm' |
7e4b3d3a9c5c
renamed repo groups table
Marcin Kuzminski <marcin@python-works.com>
parents:
1950
diff
changeset
|
1539 __table_args__ = ( |
2000
72c525a7e7ad
added migrations from 1.2.X to 1.3
Marcin Kuzminski <marcin@python-works.com>
parents:
1990
diff
changeset
|
1540 UniqueConstraint('user_id', 'group_id', 'permission_id'), |
2356
2da7b5984ae5
typo fix + code garden
Marcin Kuzminski <marcin@python-works.com>
parents:
2352
diff
changeset
|
1541 {'extend_existing': True, 'mysql_engine': 'InnoDB', |
2149 | 1542 'mysql_charset': 'utf8'} |
1958
7e4b3d3a9c5c
renamed repo groups table
Marcin Kuzminski <marcin@python-works.com>
parents:
1950
diff
changeset
|
1543 ) |
879
b19341623d48
added group to perm mapping table
Marcin Kuzminski <marcin@python-works.com>
parents:
878
diff
changeset
|
1544 |
1594 | 1545 group_to_perm_id = Column("group_to_perm_id", Integer(), nullable=False, unique=True, default=None, primary_key=True) |
1546 user_id = Column("user_id", Integer(), ForeignKey('users.user_id'), nullable=False, unique=None, default=None) | |
1958
7e4b3d3a9c5c
renamed repo groups table
Marcin Kuzminski <marcin@python-works.com>
parents:
1950
diff
changeset
|
1547 group_id = Column("group_id", Integer(), ForeignKey('groups.group_id'), nullable=False, unique=None, default=None) |
1594 | 1548 permission_id = Column("permission_id", Integer(), ForeignKey('permissions.permission_id'), nullable=False, unique=None, default=None) |
879
b19341623d48
added group to perm mapping table
Marcin Kuzminski <marcin@python-works.com>
parents:
878
diff
changeset
|
1549 |
1593 | 1550 user = relationship('User') |
2000
72c525a7e7ad
added migrations from 1.2.X to 1.3
Marcin Kuzminski <marcin@python-works.com>
parents:
1990
diff
changeset
|
1551 group = relationship('RepoGroup') |
1593 | 1552 permission = relationship('Permission') |
1633
2c0d35e336b5
refactoring of models names for repoGroup permissions
Marcin Kuzminski <marcin@python-works.com>
parents:
1607
diff
changeset
|
1553 |
1800 | 1554 |
1633
2c0d35e336b5
refactoring of models names for repoGroup permissions
Marcin Kuzminski <marcin@python-works.com>
parents:
1607
diff
changeset
|
1555 class UsersGroupRepoGroupToPerm(Base, BaseModel): |
2c0d35e336b5
refactoring of models names for repoGroup permissions
Marcin Kuzminski <marcin@python-works.com>
parents:
1607
diff
changeset
|
1556 __tablename__ = 'users_group_repo_group_to_perm' |
1958
7e4b3d3a9c5c
renamed repo groups table
Marcin Kuzminski <marcin@python-works.com>
parents:
1950
diff
changeset
|
1557 __table_args__ = ( |
1988
5eae67552695
db unique constraints fixes
Marcin Kuzminski <marcin@python-works.com>
parents:
1982
diff
changeset
|
1558 UniqueConstraint('users_group_id', 'group_id'), |
2356
2da7b5984ae5
typo fix + code garden
Marcin Kuzminski <marcin@python-works.com>
parents:
2352
diff
changeset
|
1559 {'extend_existing': True, 'mysql_engine': 'InnoDB', |
2149 | 1560 'mysql_charset': 'utf8'} |
1958
7e4b3d3a9c5c
renamed repo groups table
Marcin Kuzminski <marcin@python-works.com>
parents:
1950
diff
changeset
|
1561 ) |
1633
2c0d35e336b5
refactoring of models names for repoGroup permissions
Marcin Kuzminski <marcin@python-works.com>
parents:
1607
diff
changeset
|
1562 |
2c0d35e336b5
refactoring of models names for repoGroup permissions
Marcin Kuzminski <marcin@python-works.com>
parents:
1607
diff
changeset
|
1563 users_group_repo_group_to_perm_id = Column("users_group_repo_group_to_perm_id", Integer(), nullable=False, unique=True, default=None, primary_key=True) |
2c0d35e336b5
refactoring of models names for repoGroup permissions
Marcin Kuzminski <marcin@python-works.com>
parents:
1607
diff
changeset
|
1564 users_group_id = Column("users_group_id", Integer(), ForeignKey('users_groups.users_group_id'), nullable=False, unique=None, default=None) |
1988
5eae67552695
db unique constraints fixes
Marcin Kuzminski <marcin@python-works.com>
parents:
1982
diff
changeset
|
1565 group_id = Column("group_id", Integer(), ForeignKey('groups.group_id'), nullable=False, unique=None, default=None) |
1633
2c0d35e336b5
refactoring of models names for repoGroup permissions
Marcin Kuzminski <marcin@python-works.com>
parents:
1607
diff
changeset
|
1566 permission_id = Column("permission_id", Integer(), ForeignKey('permissions.permission_id'), nullable=False, unique=None, default=None) |
2c0d35e336b5
refactoring of models names for repoGroup permissions
Marcin Kuzminski <marcin@python-works.com>
parents:
1607
diff
changeset
|
1567 |
2c0d35e336b5
refactoring of models names for repoGroup permissions
Marcin Kuzminski <marcin@python-works.com>
parents:
1607
diff
changeset
|
1568 users_group = relationship('UsersGroup') |
2c0d35e336b5
refactoring of models names for repoGroup permissions
Marcin Kuzminski <marcin@python-works.com>
parents:
1607
diff
changeset
|
1569 permission = relationship('Permission') |
2c0d35e336b5
refactoring of models names for repoGroup permissions
Marcin Kuzminski <marcin@python-works.com>
parents:
1607
diff
changeset
|
1570 group = relationship('RepoGroup') |
879
b19341623d48
added group to perm mapping table
Marcin Kuzminski <marcin@python-works.com>
parents:
878
diff
changeset
|
1571 |
1800 | 1572 |
1593 | 1573 class Statistics(Base, BaseModel): |
493
2256c78afe53
implemented basic autoupdating statistics fetched from database
Marcin Kuzminski <marcin@python-works.com>
parents:
473
diff
changeset
|
1574 __tablename__ = 'statistics' |
2149 | 1575 __table_args__ = ( |
2150
a8c9c0094ddf
White space cleanup
Marcin Kuzminski <marcin@python-works.com>
parents:
2149
diff
changeset
|
1576 UniqueConstraint('repository_id'), |
2356
2da7b5984ae5
typo fix + code garden
Marcin Kuzminski <marcin@python-works.com>
parents:
2352
diff
changeset
|
1577 {'extend_existing': True, 'mysql_engine': 'InnoDB', |
2149 | 1578 'mysql_charset': 'utf8'} |
1579 ) | |
1594 | 1580 stat_id = Column("stat_id", Integer(), nullable=False, unique=True, default=None, primary_key=True) |
1581 repository_id = Column("repository_id", Integer(), ForeignKey('repositories.repo_id'), nullable=False, unique=True, default=None) | |
1582 stat_on_revision = Column("stat_on_revision", Integer(), nullable=False) | |
1583 commit_activity = Column("commit_activity", LargeBinary(1000000), nullable=False)#JSON data | |
1584 commit_activity_combined = Column("commit_activity_combined", LargeBinary(), nullable=False)#JSON data | |
1585 languages = Column("languages", LargeBinary(1000000), nullable=False)#JSON data | |
631
05528ad948c4
Hacking for git support,and new faster repo scan
Marcin Kuzminski <marcin@python-works.com>
parents:
549
diff
changeset
|
1586 |
1594 | 1587 repository = relationship('Repository', single_parent=True) |
399
f5c1eec9f376
rename repo2perm into repo_to_perm
Marcin Kuzminski <marcin@python-works.com>
parents:
392
diff
changeset
|
1588 |
1800 | 1589 |
1593 | 1590 class UserFollowing(Base, BaseModel): |
734
49eb69d78988
implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents:
713
diff
changeset
|
1591 __tablename__ = 'user_followings' |
1958
7e4b3d3a9c5c
renamed repo groups table
Marcin Kuzminski <marcin@python-works.com>
parents:
1950
diff
changeset
|
1592 __table_args__ = ( |
7e4b3d3a9c5c
renamed repo groups table
Marcin Kuzminski <marcin@python-works.com>
parents:
1950
diff
changeset
|
1593 UniqueConstraint('user_id', 'follows_repository_id'), |
7e4b3d3a9c5c
renamed repo groups table
Marcin Kuzminski <marcin@python-works.com>
parents:
1950
diff
changeset
|
1594 UniqueConstraint('user_id', 'follows_user_id'), |
2356
2da7b5984ae5
typo fix + code garden
Marcin Kuzminski <marcin@python-works.com>
parents:
2352
diff
changeset
|
1595 {'extend_existing': True, 'mysql_engine': 'InnoDB', |
2149 | 1596 'mysql_charset': 'utf8'} |
1958
7e4b3d3a9c5c
renamed repo groups table
Marcin Kuzminski <marcin@python-works.com>
parents:
1950
diff
changeset
|
1597 ) |
734
49eb69d78988
implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents:
713
diff
changeset
|
1598 |
1594 | 1599 user_following_id = Column("user_following_id", Integer(), nullable=False, unique=True, default=None, primary_key=True) |
1600 user_id = Column("user_id", Integer(), ForeignKey('users.user_id'), nullable=False, unique=None, default=None) | |
1601 follows_repo_id = Column("follows_repository_id", Integer(), ForeignKey('repositories.repo_id'), nullable=True, unique=None, default=None) | |
1602 follows_user_id = Column("follows_user_id", Integer(), ForeignKey('users.user_id'), nullable=True, unique=None, default=None) | |
1603 follows_from = Column('follows_from', DateTime(timezone=False), nullable=True, unique=None, default=datetime.datetime.now) | |
734
49eb69d78988
implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents:
713
diff
changeset
|
1604 |
1594 | 1605 user = relationship('User', primaryjoin='User.user_id==UserFollowing.user_id') |
734
49eb69d78988
implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents:
713
diff
changeset
|
1606 |
1594 | 1607 follows_user = relationship('User', primaryjoin='User.user_id==UserFollowing.follows_user_id') |
1608 follows_repository = relationship('Repository', order_by='Repository.repo_name') | |
734
49eb69d78988
implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents:
713
diff
changeset
|
1609 |
1279
cb216757a62d
#179 Added followers page
Marcin Kuzminski <marcin@python-works.com>
parents:
1271
diff
changeset
|
1610 @classmethod |
1593 | 1611 def get_repo_followers(cls, repo_id): |
1612 return cls.query().filter(cls.follows_repo_id == repo_id) | |
1279
cb216757a62d
#179 Added followers page
Marcin Kuzminski <marcin@python-works.com>
parents:
1271
diff
changeset
|
1613 |
1800 | 1614 |
1593 | 1615 class CacheInvalidation(Base, BaseModel): |
670
e7c670cc03cb
Adde table for cache invalidation
Marcin Kuzminski <marcin@python-works.com>
parents:
667
diff
changeset
|
1616 __tablename__ = 'cache_invalidation' |
2149 | 1617 __table_args__ = ( |
1618 UniqueConstraint('cache_key'), | |
2352
90e06f53af8c
Implemented cache-map on main page to save executing select
Marcin Kuzminski <marcin@python-works.com>
parents:
2339
diff
changeset
|
1619 Index('key_idx', 'cache_key'), |
2356
2da7b5984ae5
typo fix + code garden
Marcin Kuzminski <marcin@python-works.com>
parents:
2352
diff
changeset
|
1620 {'extend_existing': True, 'mysql_engine': 'InnoDB', |
2149 | 1621 'mysql_charset': 'utf8'}, |
1622 ) | |
1594 | 1623 cache_id = Column("cache_id", Integer(), nullable=False, unique=True, default=None, primary_key=True) |
2588
32dd6896abcf
added status column to pull request + some small refactoring of models
Marcin Kuzminski <marcin@python-works.com>
parents:
2585
diff
changeset
|
1624 cache_key = Column("cache_key", String(255, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None) |
32dd6896abcf
added status column to pull request + some small refactoring of models
Marcin Kuzminski <marcin@python-works.com>
parents:
2585
diff
changeset
|
1625 cache_args = Column("cache_args", String(255, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None) |
1594 | 1626 cache_active = Column("cache_active", Boolean(), nullable=True, unique=None, default=False) |
670
e7c670cc03cb
Adde table for cache invalidation
Marcin Kuzminski <marcin@python-works.com>
parents:
667
diff
changeset
|
1627 |
1594 | 1628 def __init__(self, cache_key, cache_args=''): |
692
cb0d9ce6ac5c
#50 on point cache invalidation changes.
Marcin Kuzminski <marcin@python-works.com>
parents:
670
diff
changeset
|
1629 self.cache_key = cache_key |
cb0d9ce6ac5c
#50 on point cache invalidation changes.
Marcin Kuzminski <marcin@python-works.com>
parents:
670
diff
changeset
|
1630 self.cache_args = cache_args |
cb0d9ce6ac5c
#50 on point cache invalidation changes.
Marcin Kuzminski <marcin@python-works.com>
parents:
670
diff
changeset
|
1631 self.cache_active = False |
cb0d9ce6ac5c
#50 on point cache invalidation changes.
Marcin Kuzminski <marcin@python-works.com>
parents:
670
diff
changeset
|
1632 |
2156
a27e4d44237e
Use __unicode__ instead of __repr__ in models.
Marcin Kuzminski <marcin@python-works.com>
parents:
2152
diff
changeset
|
1633 def __unicode__(self): |
a27e4d44237e
Use __unicode__ instead of __repr__ in models.
Marcin Kuzminski <marcin@python-works.com>
parents:
2152
diff
changeset
|
1634 return u"<%s('%s:%s')>" % (self.__class__.__name__, |
1593 | 1635 self.cache_id, self.cache_key) |
2352
90e06f53af8c
Implemented cache-map on main page to save executing select
Marcin Kuzminski <marcin@python-works.com>
parents:
2339
diff
changeset
|
1636 |
2809
070d2eacd48b
Show cache keys in admin settings of repository
Marcin Kuzminski <marcin@python-works.com>
parents:
2808
diff
changeset
|
1637 @property |
070d2eacd48b
Show cache keys in admin settings of repository
Marcin Kuzminski <marcin@python-works.com>
parents:
2808
diff
changeset
|
1638 def prefix(self): |
070d2eacd48b
Show cache keys in admin settings of repository
Marcin Kuzminski <marcin@python-works.com>
parents:
2808
diff
changeset
|
1639 _split = self.cache_key.split(self.cache_args, 1) |
070d2eacd48b
Show cache keys in admin settings of repository
Marcin Kuzminski <marcin@python-works.com>
parents:
2808
diff
changeset
|
1640 if _split and len(_split) == 2: |
070d2eacd48b
Show cache keys in admin settings of repository
Marcin Kuzminski <marcin@python-works.com>
parents:
2808
diff
changeset
|
1641 return _split[0] |
070d2eacd48b
Show cache keys in admin settings of repository
Marcin Kuzminski <marcin@python-works.com>
parents:
2808
diff
changeset
|
1642 return '' |
070d2eacd48b
Show cache keys in admin settings of repository
Marcin Kuzminski <marcin@python-works.com>
parents:
2808
diff
changeset
|
1643 |
2147
d25bd432bc3e
- #347 when running multiple RhodeCode instances, properly invalidates cache
Marcin Kuzminski <marcin@python-works.com>
parents:
2109
diff
changeset
|
1644 @classmethod |
d25bd432bc3e
- #347 when running multiple RhodeCode instances, properly invalidates cache
Marcin Kuzminski <marcin@python-works.com>
parents:
2109
diff
changeset
|
1645 def clear_cache(cls): |
d25bd432bc3e
- #347 when running multiple RhodeCode instances, properly invalidates cache
Marcin Kuzminski <marcin@python-works.com>
parents:
2109
diff
changeset
|
1646 cls.query().delete() |
834
8924ed0e4f36
added current db version into rhodecode,
Marcin Kuzminski <marcin@python-works.com>
parents:
832
diff
changeset
|
1647 |
1607
e886f91fcb71
Cached readme generation
Marcin Kuzminski <marcin@python-works.com>
parents:
1594
diff
changeset
|
1648 @classmethod |
2013
8530c3cd9d04
fixed issue with hybrid property for ldap_active
Marcin Kuzminski <marcin@python-works.com>
parents:
2007
diff
changeset
|
1649 def _get_key(cls, key): |
8530c3cd9d04
fixed issue with hybrid property for ldap_active
Marcin Kuzminski <marcin@python-works.com>
parents:
2007
diff
changeset
|
1650 """ |
2147
d25bd432bc3e
- #347 when running multiple RhodeCode instances, properly invalidates cache
Marcin Kuzminski <marcin@python-works.com>
parents:
2109
diff
changeset
|
1651 Wrapper for generating a key, together with a prefix |
2013
8530c3cd9d04
fixed issue with hybrid property for ldap_active
Marcin Kuzminski <marcin@python-works.com>
parents:
2007
diff
changeset
|
1652 |
8530c3cd9d04
fixed issue with hybrid property for ldap_active
Marcin Kuzminski <marcin@python-works.com>
parents:
2007
diff
changeset
|
1653 :param key: |
8530c3cd9d04
fixed issue with hybrid property for ldap_active
Marcin Kuzminski <marcin@python-works.com>
parents:
2007
diff
changeset
|
1654 """ |
2016
6020e3884a58
implements #212 moved default encoding variable into rhodecode-config. It's now possible to change
Marcin Kuzminski <marcin@python-works.com>
parents:
2013
diff
changeset
|
1655 import rhodecode |
6020e3884a58
implements #212 moved default encoding variable into rhodecode-config. It's now possible to change
Marcin Kuzminski <marcin@python-works.com>
parents:
2013
diff
changeset
|
1656 prefix = '' |
3020
00498b3e4c88
Cleaned the way cache keys are invalidated
Marcin Kuzminski <marcin@python-works.com>
parents:
3018
diff
changeset
|
1657 org_key = key |
2016
6020e3884a58
implements #212 moved default encoding variable into rhodecode-config. It's now possible to change
Marcin Kuzminski <marcin@python-works.com>
parents:
2013
diff
changeset
|
1658 iid = rhodecode.CONFIG.get('instance_id') |
6020e3884a58
implements #212 moved default encoding variable into rhodecode-config. It's now possible to change
Marcin Kuzminski <marcin@python-works.com>
parents:
2013
diff
changeset
|
1659 if iid: |
2058
fb51a6fc10ae
updated CONTRIBUTORS
Marcin Kuzminski <marcin@python-works.com>
parents:
2016
diff
changeset
|
1660 prefix = iid |
3020
00498b3e4c88
Cleaned the way cache keys are invalidated
Marcin Kuzminski <marcin@python-works.com>
parents:
3018
diff
changeset
|
1661 |
00498b3e4c88
Cleaned the way cache keys are invalidated
Marcin Kuzminski <marcin@python-works.com>
parents:
3018
diff
changeset
|
1662 return "%s%s" % (prefix, key), prefix, org_key |
2013
8530c3cd9d04
fixed issue with hybrid property for ldap_active
Marcin Kuzminski <marcin@python-works.com>
parents:
2007
diff
changeset
|
1663 |
8530c3cd9d04
fixed issue with hybrid property for ldap_active
Marcin Kuzminski <marcin@python-works.com>
parents:
2007
diff
changeset
|
1664 @classmethod |
8530c3cd9d04
fixed issue with hybrid property for ldap_active
Marcin Kuzminski <marcin@python-works.com>
parents:
2007
diff
changeset
|
1665 def get_by_key(cls, key): |
8530c3cd9d04
fixed issue with hybrid property for ldap_active
Marcin Kuzminski <marcin@python-works.com>
parents:
2007
diff
changeset
|
1666 return cls.query().filter(cls.cache_key == key).scalar() |
2149 | 1667 |
2147
d25bd432bc3e
- #347 when running multiple RhodeCode instances, properly invalidates cache
Marcin Kuzminski <marcin@python-works.com>
parents:
2109
diff
changeset
|
1668 @classmethod |
3020
00498b3e4c88
Cleaned the way cache keys are invalidated
Marcin Kuzminski <marcin@python-works.com>
parents:
3018
diff
changeset
|
1669 def get_by_repo_name(cls, repo_name): |
00498b3e4c88
Cleaned the way cache keys are invalidated
Marcin Kuzminski <marcin@python-works.com>
parents:
3018
diff
changeset
|
1670 return cls.query().filter(cls.cache_args == repo_name).all() |
00498b3e4c88
Cleaned the way cache keys are invalidated
Marcin Kuzminski <marcin@python-works.com>
parents:
3018
diff
changeset
|
1671 |
00498b3e4c88
Cleaned the way cache keys are invalidated
Marcin Kuzminski <marcin@python-works.com>
parents:
3018
diff
changeset
|
1672 @classmethod |
00498b3e4c88
Cleaned the way cache keys are invalidated
Marcin Kuzminski <marcin@python-works.com>
parents:
3018
diff
changeset
|
1673 def _get_or_create_key(cls, key, repo_name, commit=True): |
2520
a1e156503afe
Fixed calls to Session in db model
Marcin Kuzminski <marcin@python-works.com>
parents:
2510
diff
changeset
|
1674 inv_obj = Session().query(cls).filter(cls.cache_key == key).scalar() |
2147
d25bd432bc3e
- #347 when running multiple RhodeCode instances, properly invalidates cache
Marcin Kuzminski <marcin@python-works.com>
parents:
2109
diff
changeset
|
1675 if not inv_obj: |
d25bd432bc3e
- #347 when running multiple RhodeCode instances, properly invalidates cache
Marcin Kuzminski <marcin@python-works.com>
parents:
2109
diff
changeset
|
1676 try: |
3020
00498b3e4c88
Cleaned the way cache keys are invalidated
Marcin Kuzminski <marcin@python-works.com>
parents:
3018
diff
changeset
|
1677 inv_obj = CacheInvalidation(key, repo_name) |
2520
a1e156503afe
Fixed calls to Session in db model
Marcin Kuzminski <marcin@python-works.com>
parents:
2510
diff
changeset
|
1678 Session().add(inv_obj) |
2808
3a007d806f0f
Fixing issues of cache invalidation for multiple instances running in rhodecode.
Marcin Kuzminski <marcin@python-works.com>
parents:
2798
diff
changeset
|
1679 if commit: |
3a007d806f0f
Fixing issues of cache invalidation for multiple instances running in rhodecode.
Marcin Kuzminski <marcin@python-works.com>
parents:
2798
diff
changeset
|
1680 Session().commit() |
2147
d25bd432bc3e
- #347 when running multiple RhodeCode instances, properly invalidates cache
Marcin Kuzminski <marcin@python-works.com>
parents:
2109
diff
changeset
|
1681 except Exception: |
d25bd432bc3e
- #347 when running multiple RhodeCode instances, properly invalidates cache
Marcin Kuzminski <marcin@python-works.com>
parents:
2109
diff
changeset
|
1682 log.error(traceback.format_exc()) |
2520
a1e156503afe
Fixed calls to Session in db model
Marcin Kuzminski <marcin@python-works.com>
parents:
2510
diff
changeset
|
1683 Session().rollback() |
2147
d25bd432bc3e
- #347 when running multiple RhodeCode instances, properly invalidates cache
Marcin Kuzminski <marcin@python-works.com>
parents:
2109
diff
changeset
|
1684 return inv_obj |
2149 | 1685 |
2013
8530c3cd9d04
fixed issue with hybrid property for ldap_active
Marcin Kuzminski <marcin@python-works.com>
parents:
2007
diff
changeset
|
1686 @classmethod |
1607
e886f91fcb71
Cached readme generation
Marcin Kuzminski <marcin@python-works.com>
parents:
1594
diff
changeset
|
1687 def invalidate(cls, key): |
e886f91fcb71
Cached readme generation
Marcin Kuzminski <marcin@python-works.com>
parents:
1594
diff
changeset
|
1688 """ |
e886f91fcb71
Cached readme generation
Marcin Kuzminski <marcin@python-works.com>
parents:
1594
diff
changeset
|
1689 Returns Invalidation object if this given key should be invalidated |
e886f91fcb71
Cached readme generation
Marcin Kuzminski <marcin@python-works.com>
parents:
1594
diff
changeset
|
1690 None otherwise. `cache_active = False` means that this cache |
e886f91fcb71
Cached readme generation
Marcin Kuzminski <marcin@python-works.com>
parents:
1594
diff
changeset
|
1691 state is not valid and needs to be invalidated |
1818
cf51bbfb120e
auto white-space removal
Marcin Kuzminski <marcin@python-works.com>
parents:
1800
diff
changeset
|
1692 |
1607
e886f91fcb71
Cached readme generation
Marcin Kuzminski <marcin@python-works.com>
parents:
1594
diff
changeset
|
1693 :param key: |
e886f91fcb71
Cached readme generation
Marcin Kuzminski <marcin@python-works.com>
parents:
1594
diff
changeset
|
1694 """ |
3020
00498b3e4c88
Cleaned the way cache keys are invalidated
Marcin Kuzminski <marcin@python-works.com>
parents:
3018
diff
changeset
|
1695 repo_name = key |
00498b3e4c88
Cleaned the way cache keys are invalidated
Marcin Kuzminski <marcin@python-works.com>
parents:
3018
diff
changeset
|
1696 repo_name = remove_suffix(repo_name, '_README') |
00498b3e4c88
Cleaned the way cache keys are invalidated
Marcin Kuzminski <marcin@python-works.com>
parents:
3018
diff
changeset
|
1697 repo_name = remove_suffix(repo_name, '_RSS') |
00498b3e4c88
Cleaned the way cache keys are invalidated
Marcin Kuzminski <marcin@python-works.com>
parents:
3018
diff
changeset
|
1698 repo_name = remove_suffix(repo_name, '_ATOM') |
2149 | 1699 |
3020
00498b3e4c88
Cleaned the way cache keys are invalidated
Marcin Kuzminski <marcin@python-works.com>
parents:
3018
diff
changeset
|
1700 # adds instance prefix |
2147
d25bd432bc3e
- #347 when running multiple RhodeCode instances, properly invalidates cache
Marcin Kuzminski <marcin@python-works.com>
parents:
2109
diff
changeset
|
1701 key, _prefix, _org_key = cls._get_key(key) |
3020
00498b3e4c88
Cleaned the way cache keys are invalidated
Marcin Kuzminski <marcin@python-works.com>
parents:
3018
diff
changeset
|
1702 inv = cls._get_or_create_key(key, repo_name) |
2147
d25bd432bc3e
- #347 when running multiple RhodeCode instances, properly invalidates cache
Marcin Kuzminski <marcin@python-works.com>
parents:
2109
diff
changeset
|
1703 |
d25bd432bc3e
- #347 when running multiple RhodeCode instances, properly invalidates cache
Marcin Kuzminski <marcin@python-works.com>
parents:
2109
diff
changeset
|
1704 if inv and inv.cache_active is False: |
d25bd432bc3e
- #347 when running multiple RhodeCode instances, properly invalidates cache
Marcin Kuzminski <marcin@python-works.com>
parents:
2109
diff
changeset
|
1705 return inv |
1607
e886f91fcb71
Cached readme generation
Marcin Kuzminski <marcin@python-works.com>
parents:
1594
diff
changeset
|
1706 |
e886f91fcb71
Cached readme generation
Marcin Kuzminski <marcin@python-works.com>
parents:
1594
diff
changeset
|
1707 @classmethod |
3020
00498b3e4c88
Cleaned the way cache keys are invalidated
Marcin Kuzminski <marcin@python-works.com>
parents:
3018
diff
changeset
|
1708 def set_invalidate(cls, key=None, repo_name=None): |
1607
e886f91fcb71
Cached readme generation
Marcin Kuzminski <marcin@python-works.com>
parents:
1594
diff
changeset
|
1709 """ |
3020
00498b3e4c88
Cleaned the way cache keys are invalidated
Marcin Kuzminski <marcin@python-works.com>
parents:
3018
diff
changeset
|
1710 Mark this Cache key for invalidation, either by key or whole |
00498b3e4c88
Cleaned the way cache keys are invalidated
Marcin Kuzminski <marcin@python-works.com>
parents:
3018
diff
changeset
|
1711 cache sets based on repo_name |
1818
cf51bbfb120e
auto white-space removal
Marcin Kuzminski <marcin@python-works.com>
parents:
1800
diff
changeset
|
1712 |
1607
e886f91fcb71
Cached readme generation
Marcin Kuzminski <marcin@python-works.com>
parents:
1594
diff
changeset
|
1713 :param key: |
e886f91fcb71
Cached readme generation
Marcin Kuzminski <marcin@python-works.com>
parents:
1594
diff
changeset
|
1714 """ |
3234
21cccfea18bf
Return a list of invlidated keys on mark_for_invalidation func
Marcin Kuzminski <marcin@python-works.com>
parents:
3227
diff
changeset
|
1715 invalidated_keys = [] |
3020
00498b3e4c88
Cleaned the way cache keys are invalidated
Marcin Kuzminski <marcin@python-works.com>
parents:
3018
diff
changeset
|
1716 if key: |
00498b3e4c88
Cleaned the way cache keys are invalidated
Marcin Kuzminski <marcin@python-works.com>
parents:
3018
diff
changeset
|
1717 key, _prefix, _org_key = cls._get_key(key) |
00498b3e4c88
Cleaned the way cache keys are invalidated
Marcin Kuzminski <marcin@python-works.com>
parents:
3018
diff
changeset
|
1718 inv_objs = Session().query(cls).filter(cls.cache_key == key).all() |
00498b3e4c88
Cleaned the way cache keys are invalidated
Marcin Kuzminski <marcin@python-works.com>
parents:
3018
diff
changeset
|
1719 elif repo_name: |
00498b3e4c88
Cleaned the way cache keys are invalidated
Marcin Kuzminski <marcin@python-works.com>
parents:
3018
diff
changeset
|
1720 inv_objs = Session().query(cls).filter(cls.cache_args == repo_name).all() |
1607
e886f91fcb71
Cached readme generation
Marcin Kuzminski <marcin@python-works.com>
parents:
1594
diff
changeset
|
1721 |
2147
d25bd432bc3e
- #347 when running multiple RhodeCode instances, properly invalidates cache
Marcin Kuzminski <marcin@python-works.com>
parents:
2109
diff
changeset
|
1722 try: |
d25bd432bc3e
- #347 when running multiple RhodeCode instances, properly invalidates cache
Marcin Kuzminski <marcin@python-works.com>
parents:
2109
diff
changeset
|
1723 for inv_obj in inv_objs: |
3020
00498b3e4c88
Cleaned the way cache keys are invalidated
Marcin Kuzminski <marcin@python-works.com>
parents:
3018
diff
changeset
|
1724 inv_obj.cache_active = False |
3234
21cccfea18bf
Return a list of invlidated keys on mark_for_invalidation func
Marcin Kuzminski <marcin@python-works.com>
parents:
3227
diff
changeset
|
1725 log.debug('marking %s key for invalidation based on key=%s,repo_name=%s' |
21cccfea18bf
Return a list of invlidated keys on mark_for_invalidation func
Marcin Kuzminski <marcin@python-works.com>
parents:
3227
diff
changeset
|
1726 % (inv_obj, key, repo_name)) |
21cccfea18bf
Return a list of invlidated keys on mark_for_invalidation func
Marcin Kuzminski <marcin@python-works.com>
parents:
3227
diff
changeset
|
1727 invalidated_keys.append(inv_obj.cache_key) |
2520
a1e156503afe
Fixed calls to Session in db model
Marcin Kuzminski <marcin@python-works.com>
parents:
2510
diff
changeset
|
1728 Session().add(inv_obj) |
a1e156503afe
Fixed calls to Session in db model
Marcin Kuzminski <marcin@python-works.com>
parents:
2510
diff
changeset
|
1729 Session().commit() |
1607
e886f91fcb71
Cached readme generation
Marcin Kuzminski <marcin@python-works.com>
parents:
1594
diff
changeset
|
1730 except Exception: |
e886f91fcb71
Cached readme generation
Marcin Kuzminski <marcin@python-works.com>
parents:
1594
diff
changeset
|
1731 log.error(traceback.format_exc()) |
2520
a1e156503afe
Fixed calls to Session in db model
Marcin Kuzminski <marcin@python-works.com>
parents:
2510
diff
changeset
|
1732 Session().rollback() |
3234
21cccfea18bf
Return a list of invlidated keys on mark_for_invalidation func
Marcin Kuzminski <marcin@python-works.com>
parents:
3227
diff
changeset
|
1733 return invalidated_keys |
1607
e886f91fcb71
Cached readme generation
Marcin Kuzminski <marcin@python-works.com>
parents:
1594
diff
changeset
|
1734 |
e886f91fcb71
Cached readme generation
Marcin Kuzminski <marcin@python-works.com>
parents:
1594
diff
changeset
|
1735 @classmethod |
e886f91fcb71
Cached readme generation
Marcin Kuzminski <marcin@python-works.com>
parents:
1594
diff
changeset
|
1736 def set_valid(cls, key): |
e886f91fcb71
Cached readme generation
Marcin Kuzminski <marcin@python-works.com>
parents:
1594
diff
changeset
|
1737 """ |
e886f91fcb71
Cached readme generation
Marcin Kuzminski <marcin@python-works.com>
parents:
1594
diff
changeset
|
1738 Mark this cache key as active and currently cached |
1818
cf51bbfb120e
auto white-space removal
Marcin Kuzminski <marcin@python-works.com>
parents:
1800
diff
changeset
|
1739 |
1607
e886f91fcb71
Cached readme generation
Marcin Kuzminski <marcin@python-works.com>
parents:
1594
diff
changeset
|
1740 :param key: |
e886f91fcb71
Cached readme generation
Marcin Kuzminski <marcin@python-works.com>
parents:
1594
diff
changeset
|
1741 """ |
2013
8530c3cd9d04
fixed issue with hybrid property for ldap_active
Marcin Kuzminski <marcin@python-works.com>
parents:
2007
diff
changeset
|
1742 inv_obj = cls.get_by_key(key) |
1607
e886f91fcb71
Cached readme generation
Marcin Kuzminski <marcin@python-works.com>
parents:
1594
diff
changeset
|
1743 inv_obj.cache_active = True |
2520
a1e156503afe
Fixed calls to Session in db model
Marcin Kuzminski <marcin@python-works.com>
parents:
2510
diff
changeset
|
1744 Session().add(inv_obj) |
a1e156503afe
Fixed calls to Session in db model
Marcin Kuzminski <marcin@python-works.com>
parents:
2510
diff
changeset
|
1745 Session().commit() |
1607
e886f91fcb71
Cached readme generation
Marcin Kuzminski <marcin@python-works.com>
parents:
1594
diff
changeset
|
1746 |
2352
90e06f53af8c
Implemented cache-map on main page to save executing select
Marcin Kuzminski <marcin@python-works.com>
parents:
2339
diff
changeset
|
1747 @classmethod |
90e06f53af8c
Implemented cache-map on main page to save executing select
Marcin Kuzminski <marcin@python-works.com>
parents:
2339
diff
changeset
|
1748 def get_cache_map(cls): |
90e06f53af8c
Implemented cache-map on main page to save executing select
Marcin Kuzminski <marcin@python-works.com>
parents:
2339
diff
changeset
|
1749 |
90e06f53af8c
Implemented cache-map on main page to save executing select
Marcin Kuzminski <marcin@python-works.com>
parents:
2339
diff
changeset
|
1750 class cachemapdict(dict): |
90e06f53af8c
Implemented cache-map on main page to save executing select
Marcin Kuzminski <marcin@python-works.com>
parents:
2339
diff
changeset
|
1751 |
90e06f53af8c
Implemented cache-map on main page to save executing select
Marcin Kuzminski <marcin@python-works.com>
parents:
2339
diff
changeset
|
1752 def __init__(self, *args, **kwargs): |
90e06f53af8c
Implemented cache-map on main page to save executing select
Marcin Kuzminski <marcin@python-works.com>
parents:
2339
diff
changeset
|
1753 fixkey = kwargs.get('fixkey') |
90e06f53af8c
Implemented cache-map on main page to save executing select
Marcin Kuzminski <marcin@python-works.com>
parents:
2339
diff
changeset
|
1754 if fixkey: |
90e06f53af8c
Implemented cache-map on main page to save executing select
Marcin Kuzminski <marcin@python-works.com>
parents:
2339
diff
changeset
|
1755 del kwargs['fixkey'] |
2356
2da7b5984ae5
typo fix + code garden
Marcin Kuzminski <marcin@python-works.com>
parents:
2352
diff
changeset
|
1756 self.fixkey = fixkey |
2352
90e06f53af8c
Implemented cache-map on main page to save executing select
Marcin Kuzminski <marcin@python-works.com>
parents:
2339
diff
changeset
|
1757 super(cachemapdict, self).__init__(*args, **kwargs) |
90e06f53af8c
Implemented cache-map on main page to save executing select
Marcin Kuzminski <marcin@python-works.com>
parents:
2339
diff
changeset
|
1758 |
90e06f53af8c
Implemented cache-map on main page to save executing select
Marcin Kuzminski <marcin@python-works.com>
parents:
2339
diff
changeset
|
1759 def __getattr__(self, name): |
90e06f53af8c
Implemented cache-map on main page to save executing select
Marcin Kuzminski <marcin@python-works.com>
parents:
2339
diff
changeset
|
1760 key = name |
90e06f53af8c
Implemented cache-map on main page to save executing select
Marcin Kuzminski <marcin@python-works.com>
parents:
2339
diff
changeset
|
1761 if self.fixkey: |
90e06f53af8c
Implemented cache-map on main page to save executing select
Marcin Kuzminski <marcin@python-works.com>
parents:
2339
diff
changeset
|
1762 key, _prefix, _org_key = cls._get_key(key) |
90e06f53af8c
Implemented cache-map on main page to save executing select
Marcin Kuzminski <marcin@python-works.com>
parents:
2339
diff
changeset
|
1763 if key in self.__dict__: |
90e06f53af8c
Implemented cache-map on main page to save executing select
Marcin Kuzminski <marcin@python-works.com>
parents:
2339
diff
changeset
|
1764 return self.__dict__[key] |
90e06f53af8c
Implemented cache-map on main page to save executing select
Marcin Kuzminski <marcin@python-works.com>
parents:
2339
diff
changeset
|
1765 else: |
90e06f53af8c
Implemented cache-map on main page to save executing select
Marcin Kuzminski <marcin@python-works.com>
parents:
2339
diff
changeset
|
1766 return self[key] |
90e06f53af8c
Implemented cache-map on main page to save executing select
Marcin Kuzminski <marcin@python-works.com>
parents:
2339
diff
changeset
|
1767 |
90e06f53af8c
Implemented cache-map on main page to save executing select
Marcin Kuzminski <marcin@python-works.com>
parents:
2339
diff
changeset
|
1768 def __getitem__(self, key): |
90e06f53af8c
Implemented cache-map on main page to save executing select
Marcin Kuzminski <marcin@python-works.com>
parents:
2339
diff
changeset
|
1769 if self.fixkey: |
90e06f53af8c
Implemented cache-map on main page to save executing select
Marcin Kuzminski <marcin@python-works.com>
parents:
2339
diff
changeset
|
1770 key, _prefix, _org_key = cls._get_key(key) |
90e06f53af8c
Implemented cache-map on main page to save executing select
Marcin Kuzminski <marcin@python-works.com>
parents:
2339
diff
changeset
|
1771 try: |
90e06f53af8c
Implemented cache-map on main page to save executing select
Marcin Kuzminski <marcin@python-works.com>
parents:
2339
diff
changeset
|
1772 return super(cachemapdict, self).__getitem__(key) |
90e06f53af8c
Implemented cache-map on main page to save executing select
Marcin Kuzminski <marcin@python-works.com>
parents:
2339
diff
changeset
|
1773 except KeyError: |
90e06f53af8c
Implemented cache-map on main page to save executing select
Marcin Kuzminski <marcin@python-works.com>
parents:
2339
diff
changeset
|
1774 return |
90e06f53af8c
Implemented cache-map on main page to save executing select
Marcin Kuzminski <marcin@python-works.com>
parents:
2339
diff
changeset
|
1775 |
90e06f53af8c
Implemented cache-map on main page to save executing select
Marcin Kuzminski <marcin@python-works.com>
parents:
2339
diff
changeset
|
1776 cache_map = cachemapdict(fixkey=True) |
90e06f53af8c
Implemented cache-map on main page to save executing select
Marcin Kuzminski <marcin@python-works.com>
parents:
2339
diff
changeset
|
1777 for obj in cls.query().all(): |
90e06f53af8c
Implemented cache-map on main page to save executing select
Marcin Kuzminski <marcin@python-works.com>
parents:
2339
diff
changeset
|
1778 cache_map[obj.cache_key] = cachemapdict(obj.get_dict()) |
90e06f53af8c
Implemented cache-map on main page to save executing select
Marcin Kuzminski <marcin@python-works.com>
parents:
2339
diff
changeset
|
1779 return cache_map |
90e06f53af8c
Implemented cache-map on main page to save executing select
Marcin Kuzminski <marcin@python-works.com>
parents:
2339
diff
changeset
|
1780 |
1665
36f77a46f291
Added cache options to some db getters
Marcin Kuzminski <marcin@python-works.com>
parents:
1634
diff
changeset
|
1781 |
1670
d2de0c2f02cd
#77 code review
Marcin Kuzminski <marcin@python-works.com>
parents:
1669
diff
changeset
|
1782 class ChangesetComment(Base, BaseModel): |
d2de0c2f02cd
#77 code review
Marcin Kuzminski <marcin@python-works.com>
parents:
1669
diff
changeset
|
1783 __tablename__ = 'changeset_comments' |
2149 | 1784 __table_args__ = ( |
2463
b426ecc30319
Added some DB indexes to optimize queries
Marcin Kuzminski <marcin@python-works.com>
parents:
2462
diff
changeset
|
1785 Index('cc_revision_idx', 'revision'), |
2356
2da7b5984ae5
typo fix + code garden
Marcin Kuzminski <marcin@python-works.com>
parents:
2352
diff
changeset
|
1786 {'extend_existing': True, 'mysql_engine': 'InnoDB', |
2149 | 1787 'mysql_charset': 'utf8'}, |
1788 ) | |
1670
d2de0c2f02cd
#77 code review
Marcin Kuzminski <marcin@python-works.com>
parents:
1669
diff
changeset
|
1789 comment_id = Column('comment_id', Integer(), nullable=False, primary_key=True) |
d2de0c2f02cd
#77 code review
Marcin Kuzminski <marcin@python-works.com>
parents:
1669
diff
changeset
|
1790 repo_id = Column('repo_id', Integer(), ForeignKey('repositories.repo_id'), nullable=False) |
2440
1bc579bcd67a
- pull request generates overview based on it's params
Marcin Kuzminski <marcin@python-works.com>
parents:
2434
diff
changeset
|
1791 revision = Column('revision', String(40), nullable=True) |
1bc579bcd67a
- pull request generates overview based on it's params
Marcin Kuzminski <marcin@python-works.com>
parents:
2434
diff
changeset
|
1792 pull_request_id = Column("pull_request_id", Integer(), ForeignKey('pull_requests.pull_request_id'), nullable=True) |
1677
7276b170ce8b
#71 code-review
Marcin Kuzminski <marcin@python-works.com>
parents:
1675
diff
changeset
|
1793 line_no = Column('line_no', Unicode(10), nullable=True) |
2724
29db53a79ab2
added highlight lines field in ChangesetComments, will be used
Marcin Kuzminski <marcin@python-works.com>
parents:
2709
diff
changeset
|
1794 hl_lines = Column('hl_lines', Unicode(512), nullable=True) |
1677
7276b170ce8b
#71 code-review
Marcin Kuzminski <marcin@python-works.com>
parents:
1675
diff
changeset
|
1795 f_path = Column('f_path', Unicode(1000), nullable=True) |
1670
d2de0c2f02cd
#77 code review
Marcin Kuzminski <marcin@python-works.com>
parents:
1669
diff
changeset
|
1796 user_id = Column('user_id', Integer(), ForeignKey('users.user_id'), nullable=False) |
2791
85bb0866d444
UnicodeText make mysql more happy
Marcin Kuzminski <marcin@python-works.com>
parents:
2766
diff
changeset
|
1797 text = Column('text', UnicodeText(25000), nullable=False) |
2639
f3e039e4dc49
Added created_on column to changeset comments for proper ordering.
Marcin Kuzminski <marcin@python-works.com>
parents:
2608
diff
changeset
|
1798 created_on = Column('created_on', DateTime(timezone=False), nullable=False, default=datetime.datetime.now) |
f3e039e4dc49
Added created_on column to changeset comments for proper ordering.
Marcin Kuzminski <marcin@python-works.com>
parents:
2608
diff
changeset
|
1799 modified_at = Column('modified_at', DateTime(timezone=False), nullable=False, default=datetime.datetime.now) |
1670
d2de0c2f02cd
#77 code review
Marcin Kuzminski <marcin@python-works.com>
parents:
1669
diff
changeset
|
1800 |
1703
f23828b00b21
notification fixes and improvements
Marcin Kuzminski <marcin@python-works.com>
parents:
1702
diff
changeset
|
1801 author = relationship('User', lazy='joined') |
1670
d2de0c2f02cd
#77 code review
Marcin Kuzminski <marcin@python-works.com>
parents:
1669
diff
changeset
|
1802 repo = relationship('Repository') |
2677
4fbbc65e8cd5
Forbid changing changset status when it is associated with a closed pull request
Marcin Kuzminski <marcin@python-works.com>
parents:
2674
diff
changeset
|
1803 status_change = relationship('ChangesetStatus', cascade="all, delete, delete-orphan") |
2440
1bc579bcd67a
- pull request generates overview based on it's params
Marcin Kuzminski <marcin@python-works.com>
parents:
2434
diff
changeset
|
1804 pull_request = relationship('PullRequest', lazy='joined') |
1670
d2de0c2f02cd
#77 code review
Marcin Kuzminski <marcin@python-works.com>
parents:
1669
diff
changeset
|
1805 |
1703
f23828b00b21
notification fixes and improvements
Marcin Kuzminski <marcin@python-works.com>
parents:
1702
diff
changeset
|
1806 @classmethod |
2443
fd0a822481ec
- added commenting to pull requests
Marcin Kuzminski <marcin@python-works.com>
parents:
2440
diff
changeset
|
1807 def get_users(cls, revision=None, pull_request_id=None): |
1703
f23828b00b21
notification fixes and improvements
Marcin Kuzminski <marcin@python-works.com>
parents:
1702
diff
changeset
|
1808 """ |
2443
fd0a822481ec
- added commenting to pull requests
Marcin Kuzminski <marcin@python-works.com>
parents:
2440
diff
changeset
|
1809 Returns user associated with this ChangesetComment. ie those |
1703
f23828b00b21
notification fixes and improvements
Marcin Kuzminski <marcin@python-works.com>
parents:
1702
diff
changeset
|
1810 who actually commented |
1818
cf51bbfb120e
auto white-space removal
Marcin Kuzminski <marcin@python-works.com>
parents:
1800
diff
changeset
|
1811 |
1703
f23828b00b21
notification fixes and improvements
Marcin Kuzminski <marcin@python-works.com>
parents:
1702
diff
changeset
|
1812 :param cls: |
f23828b00b21
notification fixes and improvements
Marcin Kuzminski <marcin@python-works.com>
parents:
1702
diff
changeset
|
1813 :param revision: |
f23828b00b21
notification fixes and improvements
Marcin Kuzminski <marcin@python-works.com>
parents:
1702
diff
changeset
|
1814 """ |
2520
a1e156503afe
Fixed calls to Session in db model
Marcin Kuzminski <marcin@python-works.com>
parents:
2510
diff
changeset
|
1815 q = Session().query(User)\ |
2443
fd0a822481ec
- added commenting to pull requests
Marcin Kuzminski <marcin@python-works.com>
parents:
2440
diff
changeset
|
1816 .join(ChangesetComment.author) |
fd0a822481ec
- added commenting to pull requests
Marcin Kuzminski <marcin@python-works.com>
parents:
2440
diff
changeset
|
1817 if revision: |
fd0a822481ec
- added commenting to pull requests
Marcin Kuzminski <marcin@python-works.com>
parents:
2440
diff
changeset
|
1818 q = q.filter(cls.revision == revision) |
fd0a822481ec
- added commenting to pull requests
Marcin Kuzminski <marcin@python-works.com>
parents:
2440
diff
changeset
|
1819 elif pull_request_id: |
fd0a822481ec
- added commenting to pull requests
Marcin Kuzminski <marcin@python-works.com>
parents:
2440
diff
changeset
|
1820 q = q.filter(cls.pull_request_id == pull_request_id) |
fd0a822481ec
- added commenting to pull requests
Marcin Kuzminski <marcin@python-works.com>
parents:
2440
diff
changeset
|
1821 return q.all() |
1886 | 1822 |
1703
f23828b00b21
notification fixes and improvements
Marcin Kuzminski <marcin@python-works.com>
parents:
1702
diff
changeset
|
1823 |
2215
2c2bdaeca912
code-review initial
Marcin Kuzminski <marcin@python-works.com>
parents:
2161
diff
changeset
|
1824 class ChangesetStatus(Base, BaseModel): |
2c2bdaeca912
code-review initial
Marcin Kuzminski <marcin@python-works.com>
parents:
2161
diff
changeset
|
1825 __tablename__ = 'changeset_statuses' |
2c2bdaeca912
code-review initial
Marcin Kuzminski <marcin@python-works.com>
parents:
2161
diff
changeset
|
1826 __table_args__ = ( |
2463
b426ecc30319
Added some DB indexes to optimize queries
Marcin Kuzminski <marcin@python-works.com>
parents:
2462
diff
changeset
|
1827 Index('cs_revision_idx', 'revision'), |
b426ecc30319
Added some DB indexes to optimize queries
Marcin Kuzminski <marcin@python-works.com>
parents:
2462
diff
changeset
|
1828 Index('cs_version_idx', 'version'), |
2287
8447d35b674e
Added simple versioning for changeset status
Marcin Kuzminski <marcin@python-works.com>
parents:
2286
diff
changeset
|
1829 UniqueConstraint('repo_id', 'revision', 'version'), |
2215
2c2bdaeca912
code-review initial
Marcin Kuzminski <marcin@python-works.com>
parents:
2161
diff
changeset
|
1830 {'extend_existing': True, 'mysql_engine': 'InnoDB', |
2c2bdaeca912
code-review initial
Marcin Kuzminski <marcin@python-works.com>
parents:
2161
diff
changeset
|
1831 'mysql_charset': 'utf8'} |
2c2bdaeca912
code-review initial
Marcin Kuzminski <marcin@python-works.com>
parents:
2161
diff
changeset
|
1832 ) |
2481
4d3032431d4f
Adde pull request voting recalculation
Marcin Kuzminski <marcin@python-works.com>
parents:
2480
diff
changeset
|
1833 STATUS_NOT_REVIEWED = DEFAULT = 'not_reviewed' |
4d3032431d4f
Adde pull request voting recalculation
Marcin Kuzminski <marcin@python-works.com>
parents:
2480
diff
changeset
|
1834 STATUS_APPROVED = 'approved' |
4d3032431d4f
Adde pull request voting recalculation
Marcin Kuzminski <marcin@python-works.com>
parents:
2480
diff
changeset
|
1835 STATUS_REJECTED = 'rejected' |
4d3032431d4f
Adde pull request voting recalculation
Marcin Kuzminski <marcin@python-works.com>
parents:
2480
diff
changeset
|
1836 STATUS_UNDER_REVIEW = 'under_review' |
2215
2c2bdaeca912
code-review initial
Marcin Kuzminski <marcin@python-works.com>
parents:
2161
diff
changeset
|
1837 |
2c2bdaeca912
code-review initial
Marcin Kuzminski <marcin@python-works.com>
parents:
2161
diff
changeset
|
1838 STATUSES = [ |
2481
4d3032431d4f
Adde pull request voting recalculation
Marcin Kuzminski <marcin@python-works.com>
parents:
2480
diff
changeset
|
1839 (STATUS_NOT_REVIEWED, _("Not Reviewed")), # (no icon) and default |
4d3032431d4f
Adde pull request voting recalculation
Marcin Kuzminski <marcin@python-works.com>
parents:
2480
diff
changeset
|
1840 (STATUS_APPROVED, _("Approved")), |
4d3032431d4f
Adde pull request voting recalculation
Marcin Kuzminski <marcin@python-works.com>
parents:
2480
diff
changeset
|
1841 (STATUS_REJECTED, _("Rejected")), |
4d3032431d4f
Adde pull request voting recalculation
Marcin Kuzminski <marcin@python-works.com>
parents:
2480
diff
changeset
|
1842 (STATUS_UNDER_REVIEW, _("Under Review")), |
2215
2c2bdaeca912
code-review initial
Marcin Kuzminski <marcin@python-works.com>
parents:
2161
diff
changeset
|
1843 ] |
2c2bdaeca912
code-review initial
Marcin Kuzminski <marcin@python-works.com>
parents:
2161
diff
changeset
|
1844 |
2c2bdaeca912
code-review initial
Marcin Kuzminski <marcin@python-works.com>
parents:
2161
diff
changeset
|
1845 changeset_status_id = Column('changeset_status_id', Integer(), nullable=False, primary_key=True) |
2c2bdaeca912
code-review initial
Marcin Kuzminski <marcin@python-works.com>
parents:
2161
diff
changeset
|
1846 repo_id = Column('repo_id', Integer(), ForeignKey('repositories.repo_id'), nullable=False) |
2c2bdaeca912
code-review initial
Marcin Kuzminski <marcin@python-works.com>
parents:
2161
diff
changeset
|
1847 user_id = Column("user_id", Integer(), ForeignKey('users.user_id'), nullable=False, unique=None) |
2c2bdaeca912
code-review initial
Marcin Kuzminski <marcin@python-works.com>
parents:
2161
diff
changeset
|
1848 revision = Column('revision', String(40), nullable=False) |
2217
76947224bf27
Implemented initial code-review status of changesets
Marcin Kuzminski <marcin@python-works.com>
parents:
2215
diff
changeset
|
1849 status = Column('status', String(128), nullable=False, default=DEFAULT) |
2286
9265958e33bb
Show changes of status inside comments
Marcin Kuzminski <marcin@python-works.com>
parents:
2280
diff
changeset
|
1850 changeset_comment_id = Column('changeset_comment_id', Integer(), ForeignKey('changeset_comments.comment_id')) |
2215
2c2bdaeca912
code-review initial
Marcin Kuzminski <marcin@python-works.com>
parents:
2161
diff
changeset
|
1851 modified_at = Column('modified_at', DateTime(), nullable=False, default=datetime.datetime.now) |
2287
8447d35b674e
Added simple versioning for changeset status
Marcin Kuzminski <marcin@python-works.com>
parents:
2286
diff
changeset
|
1852 version = Column('version', Integer(), nullable=False, default=0) |
2434
f29469677319
Added basic models for saving open pull requests
Marcin Kuzminski <marcin@python-works.com>
parents:
2430
diff
changeset
|
1853 pull_request_id = Column("pull_request_id", Integer(), ForeignKey('pull_requests.pull_request_id'), nullable=True) |
f29469677319
Added basic models for saving open pull requests
Marcin Kuzminski <marcin@python-works.com>
parents:
2430
diff
changeset
|
1854 |
2215
2c2bdaeca912
code-review initial
Marcin Kuzminski <marcin@python-works.com>
parents:
2161
diff
changeset
|
1855 author = relationship('User', lazy='joined') |
2c2bdaeca912
code-review initial
Marcin Kuzminski <marcin@python-works.com>
parents:
2161
diff
changeset
|
1856 repo = relationship('Repository') |
2286
9265958e33bb
Show changes of status inside comments
Marcin Kuzminski <marcin@python-works.com>
parents:
2280
diff
changeset
|
1857 comment = relationship('ChangesetComment', lazy='joined') |
2434
f29469677319
Added basic models for saving open pull requests
Marcin Kuzminski <marcin@python-works.com>
parents:
2430
diff
changeset
|
1858 pull_request = relationship('PullRequest', lazy='joined') |
2215
2c2bdaeca912
code-review initial
Marcin Kuzminski <marcin@python-works.com>
parents:
2161
diff
changeset
|
1859 |
2481
4d3032431d4f
Adde pull request voting recalculation
Marcin Kuzminski <marcin@python-works.com>
parents:
2480
diff
changeset
|
1860 def __unicode__(self): |
4d3032431d4f
Adde pull request voting recalculation
Marcin Kuzminski <marcin@python-works.com>
parents:
2480
diff
changeset
|
1861 return u"<%s('%s:%s')>" % ( |
4d3032431d4f
Adde pull request voting recalculation
Marcin Kuzminski <marcin@python-works.com>
parents:
2480
diff
changeset
|
1862 self.__class__.__name__, |
4d3032431d4f
Adde pull request voting recalculation
Marcin Kuzminski <marcin@python-works.com>
parents:
2480
diff
changeset
|
1863 self.status, self.author |
4d3032431d4f
Adde pull request voting recalculation
Marcin Kuzminski <marcin@python-works.com>
parents:
2480
diff
changeset
|
1864 ) |
4d3032431d4f
Adde pull request voting recalculation
Marcin Kuzminski <marcin@python-works.com>
parents:
2480
diff
changeset
|
1865 |
2296
e5c0f201ca0b
Add changeset status change into emails
Marcin Kuzminski <marcin@python-works.com>
parents:
2287
diff
changeset
|
1866 @classmethod |
e5c0f201ca0b
Add changeset status change into emails
Marcin Kuzminski <marcin@python-works.com>
parents:
2287
diff
changeset
|
1867 def get_status_lbl(cls, value): |
e5c0f201ca0b
Add changeset status change into emails
Marcin Kuzminski <marcin@python-works.com>
parents:
2287
diff
changeset
|
1868 return dict(cls.STATUSES).get(value) |
e5c0f201ca0b
Add changeset status change into emails
Marcin Kuzminski <marcin@python-works.com>
parents:
2287
diff
changeset
|
1869 |
2217
76947224bf27
Implemented initial code-review status of changesets
Marcin Kuzminski <marcin@python-works.com>
parents:
2215
diff
changeset
|
1870 @property |
76947224bf27
Implemented initial code-review status of changesets
Marcin Kuzminski <marcin@python-works.com>
parents:
2215
diff
changeset
|
1871 def status_lbl(self): |
2296
e5c0f201ca0b
Add changeset status change into emails
Marcin Kuzminski <marcin@python-works.com>
parents:
2287
diff
changeset
|
1872 return ChangesetStatus.get_status_lbl(self.status) |
2217
76947224bf27
Implemented initial code-review status of changesets
Marcin Kuzminski <marcin@python-works.com>
parents:
2215
diff
changeset
|
1873 |
2215
2c2bdaeca912
code-review initial
Marcin Kuzminski <marcin@python-works.com>
parents:
2161
diff
changeset
|
1874 |
2434
f29469677319
Added basic models for saving open pull requests
Marcin Kuzminski <marcin@python-works.com>
parents:
2430
diff
changeset
|
1875 class PullRequest(Base, BaseModel): |
f29469677319
Added basic models for saving open pull requests
Marcin Kuzminski <marcin@python-works.com>
parents:
2430
diff
changeset
|
1876 __tablename__ = 'pull_requests' |
f29469677319
Added basic models for saving open pull requests
Marcin Kuzminski <marcin@python-works.com>
parents:
2430
diff
changeset
|
1877 __table_args__ = ( |
f29469677319
Added basic models for saving open pull requests
Marcin Kuzminski <marcin@python-works.com>
parents:
2430
diff
changeset
|
1878 {'extend_existing': True, 'mysql_engine': 'InnoDB', |
f29469677319
Added basic models for saving open pull requests
Marcin Kuzminski <marcin@python-works.com>
parents:
2430
diff
changeset
|
1879 'mysql_charset': 'utf8'}, |
f29469677319
Added basic models for saving open pull requests
Marcin Kuzminski <marcin@python-works.com>
parents:
2430
diff
changeset
|
1880 ) |
f29469677319
Added basic models for saving open pull requests
Marcin Kuzminski <marcin@python-works.com>
parents:
2430
diff
changeset
|
1881 |
2588
32dd6896abcf
added status column to pull request + some small refactoring of models
Marcin Kuzminski <marcin@python-works.com>
parents:
2585
diff
changeset
|
1882 STATUS_NEW = u'new' |
32dd6896abcf
added status column to pull request + some small refactoring of models
Marcin Kuzminski <marcin@python-works.com>
parents:
2585
diff
changeset
|
1883 STATUS_OPEN = u'open' |
32dd6896abcf
added status column to pull request + some small refactoring of models
Marcin Kuzminski <marcin@python-works.com>
parents:
2585
diff
changeset
|
1884 STATUS_CLOSED = u'closed' |
32dd6896abcf
added status column to pull request + some small refactoring of models
Marcin Kuzminski <marcin@python-works.com>
parents:
2585
diff
changeset
|
1885 |
2434
f29469677319
Added basic models for saving open pull requests
Marcin Kuzminski <marcin@python-works.com>
parents:
2430
diff
changeset
|
1886 pull_request_id = Column('pull_request_id', Integer(), nullable=False, primary_key=True) |
f29469677319
Added basic models for saving open pull requests
Marcin Kuzminski <marcin@python-works.com>
parents:
2430
diff
changeset
|
1887 title = Column('title', Unicode(256), nullable=True) |
2588
32dd6896abcf
added status column to pull request + some small refactoring of models
Marcin Kuzminski <marcin@python-works.com>
parents:
2585
diff
changeset
|
1888 description = Column('description', UnicodeText(10240), nullable=True) |
32dd6896abcf
added status column to pull request + some small refactoring of models
Marcin Kuzminski <marcin@python-works.com>
parents:
2585
diff
changeset
|
1889 status = Column('status', Unicode(256), nullable=False, default=STATUS_NEW) |
2440
1bc579bcd67a
- pull request generates overview based on it's params
Marcin Kuzminski <marcin@python-works.com>
parents:
2434
diff
changeset
|
1890 created_on = Column('created_on', DateTime(timezone=False), nullable=False, default=datetime.datetime.now) |
2608
58c529332e7e
Added option to close pull requests, in future that will be close & merge
Marcin Kuzminski <marcin@python-works.com>
parents:
2603
diff
changeset
|
1891 updated_on = Column('updated_on', DateTime(timezone=False), nullable=False, default=datetime.datetime.now) |
2440
1bc579bcd67a
- pull request generates overview based on it's params
Marcin Kuzminski <marcin@python-works.com>
parents:
2434
diff
changeset
|
1892 user_id = Column("user_id", Integer(), ForeignKey('users.user_id'), nullable=False, unique=None) |
2434
f29469677319
Added basic models for saving open pull requests
Marcin Kuzminski <marcin@python-works.com>
parents:
2430
diff
changeset
|
1893 _revisions = Column('revisions', UnicodeText(20500)) # 500 revisions max |
f29469677319
Added basic models for saving open pull requests
Marcin Kuzminski <marcin@python-works.com>
parents:
2430
diff
changeset
|
1894 org_repo_id = Column('org_repo_id', Integer(), ForeignKey('repositories.repo_id'), nullable=False) |
f29469677319
Added basic models for saving open pull requests
Marcin Kuzminski <marcin@python-works.com>
parents:
2430
diff
changeset
|
1895 org_ref = Column('org_ref', Unicode(256), nullable=False) |
f29469677319
Added basic models for saving open pull requests
Marcin Kuzminski <marcin@python-works.com>
parents:
2430
diff
changeset
|
1896 other_repo_id = Column('other_repo_id', Integer(), ForeignKey('repositories.repo_id'), nullable=False) |
f29469677319
Added basic models for saving open pull requests
Marcin Kuzminski <marcin@python-works.com>
parents:
2430
diff
changeset
|
1897 other_ref = Column('other_ref', Unicode(256), nullable=False) |
f29469677319
Added basic models for saving open pull requests
Marcin Kuzminski <marcin@python-works.com>
parents:
2430
diff
changeset
|
1898 |
f29469677319
Added basic models for saving open pull requests
Marcin Kuzminski <marcin@python-works.com>
parents:
2430
diff
changeset
|
1899 @hybrid_property |
f29469677319
Added basic models for saving open pull requests
Marcin Kuzminski <marcin@python-works.com>
parents:
2430
diff
changeset
|
1900 def revisions(self): |
f29469677319
Added basic models for saving open pull requests
Marcin Kuzminski <marcin@python-works.com>
parents:
2430
diff
changeset
|
1901 return self._revisions.split(':') |
f29469677319
Added basic models for saving open pull requests
Marcin Kuzminski <marcin@python-works.com>
parents:
2430
diff
changeset
|
1902 |
f29469677319
Added basic models for saving open pull requests
Marcin Kuzminski <marcin@python-works.com>
parents:
2430
diff
changeset
|
1903 @revisions.setter |
f29469677319
Added basic models for saving open pull requests
Marcin Kuzminski <marcin@python-works.com>
parents:
2430
diff
changeset
|
1904 def revisions(self, val): |
f29469677319
Added basic models for saving open pull requests
Marcin Kuzminski <marcin@python-works.com>
parents:
2430
diff
changeset
|
1905 self._revisions = ':'.join(val) |
f29469677319
Added basic models for saving open pull requests
Marcin Kuzminski <marcin@python-works.com>
parents:
2430
diff
changeset
|
1906 |
3170
2ab2eed4a70a
implemented #725 Pull Request View - Show origin repo URL
Marcin Kuzminski <marcin@python-works.com>
parents:
3152
diff
changeset
|
1907 @property |
2ab2eed4a70a
implemented #725 Pull Request View - Show origin repo URL
Marcin Kuzminski <marcin@python-works.com>
parents:
3152
diff
changeset
|
1908 def org_ref_parts(self): |
2ab2eed4a70a
implemented #725 Pull Request View - Show origin repo URL
Marcin Kuzminski <marcin@python-works.com>
parents:
3152
diff
changeset
|
1909 return self.org_ref.split(':') |
2ab2eed4a70a
implemented #725 Pull Request View - Show origin repo URL
Marcin Kuzminski <marcin@python-works.com>
parents:
3152
diff
changeset
|
1910 |
2ab2eed4a70a
implemented #725 Pull Request View - Show origin repo URL
Marcin Kuzminski <marcin@python-works.com>
parents:
3152
diff
changeset
|
1911 @property |
2ab2eed4a70a
implemented #725 Pull Request View - Show origin repo URL
Marcin Kuzminski <marcin@python-works.com>
parents:
3152
diff
changeset
|
1912 def other_ref_parts(self): |
2ab2eed4a70a
implemented #725 Pull Request View - Show origin repo URL
Marcin Kuzminski <marcin@python-works.com>
parents:
3152
diff
changeset
|
1913 return self.other_ref.split(':') |
2ab2eed4a70a
implemented #725 Pull Request View - Show origin repo URL
Marcin Kuzminski <marcin@python-works.com>
parents:
3152
diff
changeset
|
1914 |
2440
1bc579bcd67a
- pull request generates overview based on it's params
Marcin Kuzminski <marcin@python-works.com>
parents:
2434
diff
changeset
|
1915 author = relationship('User', lazy='joined') |
2674
a221706dab50
merged + fixed pull request #62: Implemented metatags and visualisation options.
Marcin Kuzminski <marcin@python-works.com>
parents:
2668
diff
changeset
|
1916 reviewers = relationship('PullRequestReviewers', |
2666
c51fb1da6df2
cascade fixes for comments/pull-requests/reviewers
Marcin Kuzminski <marcin@python-works.com>
parents:
2665
diff
changeset
|
1917 cascade="all, delete, delete-orphan") |
2434
f29469677319
Added basic models for saving open pull requests
Marcin Kuzminski <marcin@python-works.com>
parents:
2430
diff
changeset
|
1918 org_repo = relationship('Repository', primaryjoin='PullRequest.org_repo_id==Repository.repo_id') |
f29469677319
Added basic models for saving open pull requests
Marcin Kuzminski <marcin@python-works.com>
parents:
2430
diff
changeset
|
1919 other_repo = relationship('Repository', primaryjoin='PullRequest.other_repo_id==Repository.repo_id') |
2666
c51fb1da6df2
cascade fixes for comments/pull-requests/reviewers
Marcin Kuzminski <marcin@python-works.com>
parents:
2665
diff
changeset
|
1920 statuses = relationship('ChangesetStatus') |
c51fb1da6df2
cascade fixes for comments/pull-requests/reviewers
Marcin Kuzminski <marcin@python-works.com>
parents:
2665
diff
changeset
|
1921 comments = relationship('ChangesetComment', |
c51fb1da6df2
cascade fixes for comments/pull-requests/reviewers
Marcin Kuzminski <marcin@python-works.com>
parents:
2665
diff
changeset
|
1922 cascade="all, delete, delete-orphan") |
2434
f29469677319
Added basic models for saving open pull requests
Marcin Kuzminski <marcin@python-works.com>
parents:
2430
diff
changeset
|
1923 |
2608
58c529332e7e
Added option to close pull requests, in future that will be close & merge
Marcin Kuzminski <marcin@python-works.com>
parents:
2603
diff
changeset
|
1924 def is_closed(self): |
58c529332e7e
Added option to close pull requests, in future that will be close & merge
Marcin Kuzminski <marcin@python-works.com>
parents:
2603
diff
changeset
|
1925 return self.status == self.STATUS_CLOSED |
58c529332e7e
Added option to close pull requests, in future that will be close & merge
Marcin Kuzminski <marcin@python-works.com>
parents:
2603
diff
changeset
|
1926 |
3264
565806c66c4d
Add new attr to pull request
Marcin Kuzminski <marcin@python-works.com>
parents:
3246
diff
changeset
|
1927 @property |
565806c66c4d
Add new attr to pull request
Marcin Kuzminski <marcin@python-works.com>
parents:
3246
diff
changeset
|
1928 def last_review_status(self): |
3274
567207469e95
laste_review status should only return if there are any statuses
Marcin Kuzminski <marcin@python-works.com>
parents:
3267
diff
changeset
|
1929 return self.statuses[-1].status if self.statuses else '' |
3264
565806c66c4d
Add new attr to pull request
Marcin Kuzminski <marcin@python-works.com>
parents:
3246
diff
changeset
|
1930 |
2434
f29469677319
Added basic models for saving open pull requests
Marcin Kuzminski <marcin@python-works.com>
parents:
2430
diff
changeset
|
1931 def __json__(self): |
f29469677319
Added basic models for saving open pull requests
Marcin Kuzminski <marcin@python-works.com>
parents:
2430
diff
changeset
|
1932 return dict( |
f29469677319
Added basic models for saving open pull requests
Marcin Kuzminski <marcin@python-works.com>
parents:
2430
diff
changeset
|
1933 revisions=self.revisions |
f29469677319
Added basic models for saving open pull requests
Marcin Kuzminski <marcin@python-works.com>
parents:
2430
diff
changeset
|
1934 ) |
f29469677319
Added basic models for saving open pull requests
Marcin Kuzminski <marcin@python-works.com>
parents:
2430
diff
changeset
|
1935 |
f29469677319
Added basic models for saving open pull requests
Marcin Kuzminski <marcin@python-works.com>
parents:
2430
diff
changeset
|
1936 |
f29469677319
Added basic models for saving open pull requests
Marcin Kuzminski <marcin@python-works.com>
parents:
2430
diff
changeset
|
1937 class PullRequestReviewers(Base, BaseModel): |
f29469677319
Added basic models for saving open pull requests
Marcin Kuzminski <marcin@python-works.com>
parents:
2430
diff
changeset
|
1938 __tablename__ = 'pull_request_reviewers' |
f29469677319
Added basic models for saving open pull requests
Marcin Kuzminski <marcin@python-works.com>
parents:
2430
diff
changeset
|
1939 __table_args__ = ( |
f29469677319
Added basic models for saving open pull requests
Marcin Kuzminski <marcin@python-works.com>
parents:
2430
diff
changeset
|
1940 {'extend_existing': True, 'mysql_engine': 'InnoDB', |
f29469677319
Added basic models for saving open pull requests
Marcin Kuzminski <marcin@python-works.com>
parents:
2430
diff
changeset
|
1941 'mysql_charset': 'utf8'}, |
f29469677319
Added basic models for saving open pull requests
Marcin Kuzminski <marcin@python-works.com>
parents:
2430
diff
changeset
|
1942 ) |
f29469677319
Added basic models for saving open pull requests
Marcin Kuzminski <marcin@python-works.com>
parents:
2430
diff
changeset
|
1943 |
f29469677319
Added basic models for saving open pull requests
Marcin Kuzminski <marcin@python-works.com>
parents:
2430
diff
changeset
|
1944 def __init__(self, user=None, pull_request=None): |
f29469677319
Added basic models for saving open pull requests
Marcin Kuzminski <marcin@python-works.com>
parents:
2430
diff
changeset
|
1945 self.user = user |
f29469677319
Added basic models for saving open pull requests
Marcin Kuzminski <marcin@python-works.com>
parents:
2430
diff
changeset
|
1946 self.pull_request = pull_request |
f29469677319
Added basic models for saving open pull requests
Marcin Kuzminski <marcin@python-works.com>
parents:
2430
diff
changeset
|
1947 |
f29469677319
Added basic models for saving open pull requests
Marcin Kuzminski <marcin@python-works.com>
parents:
2430
diff
changeset
|
1948 pull_requests_reviewers_id = Column('pull_requests_reviewers_id', Integer(), nullable=False, primary_key=True) |
f29469677319
Added basic models for saving open pull requests
Marcin Kuzminski <marcin@python-works.com>
parents:
2430
diff
changeset
|
1949 pull_request_id = Column("pull_request_id", Integer(), ForeignKey('pull_requests.pull_request_id'), nullable=False) |
f29469677319
Added basic models for saving open pull requests
Marcin Kuzminski <marcin@python-works.com>
parents:
2430
diff
changeset
|
1950 user_id = Column("user_id", Integer(), ForeignKey('users.user_id'), nullable=True) |
f29469677319
Added basic models for saving open pull requests
Marcin Kuzminski <marcin@python-works.com>
parents:
2430
diff
changeset
|
1951 |
f29469677319
Added basic models for saving open pull requests
Marcin Kuzminski <marcin@python-works.com>
parents:
2430
diff
changeset
|
1952 user = relationship('User') |
f29469677319
Added basic models for saving open pull requests
Marcin Kuzminski <marcin@python-works.com>
parents:
2430
diff
changeset
|
1953 pull_request = relationship('PullRequest') |
1886 | 1954 |
1703
f23828b00b21
notification fixes and improvements
Marcin Kuzminski <marcin@python-works.com>
parents:
1702
diff
changeset
|
1955 |
1702
8cb7f5c4d494
#302 - basic notification system, models+tests
Marcin Kuzminski <marcin@python-works.com>
parents:
1693
diff
changeset
|
1956 class Notification(Base, BaseModel): |
8cb7f5c4d494
#302 - basic notification system, models+tests
Marcin Kuzminski <marcin@python-works.com>
parents:
1693
diff
changeset
|
1957 __tablename__ = 'notifications' |
2149 | 1958 __table_args__ = ( |
2463
b426ecc30319
Added some DB indexes to optimize queries
Marcin Kuzminski <marcin@python-works.com>
parents:
2462
diff
changeset
|
1959 Index('notification_type_idx', 'type'), |
2356
2da7b5984ae5
typo fix + code garden
Marcin Kuzminski <marcin@python-works.com>
parents:
2352
diff
changeset
|
1960 {'extend_existing': True, 'mysql_engine': 'InnoDB', |
2149 | 1961 'mysql_charset': 'utf8'}, |
1962 ) | |
1703
f23828b00b21
notification fixes and improvements
Marcin Kuzminski <marcin@python-works.com>
parents:
1702
diff
changeset
|
1963 |
1712
cac5109ac3b6
Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents:
1703
diff
changeset
|
1964 TYPE_CHANGESET_COMMENT = u'cs_comment' |
cac5109ac3b6
Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents:
1703
diff
changeset
|
1965 TYPE_MESSAGE = u'message' |
cac5109ac3b6
Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents:
1703
diff
changeset
|
1966 TYPE_MENTION = u'mention' |
1731
31e6eb2fb4b2
implements #222 registration feedback
Marcin Kuzminski <marcin@python-works.com>
parents:
1729
diff
changeset
|
1967 TYPE_REGISTRATION = u'registration' |
2244
77e376fdc4c6
pull requests draft UI
Marcin Kuzminski <marcin@python-works.com>
parents:
2218
diff
changeset
|
1968 TYPE_PULL_REQUEST = u'pull_request' |
2443
fd0a822481ec
- added commenting to pull requests
Marcin Kuzminski <marcin@python-works.com>
parents:
2440
diff
changeset
|
1969 TYPE_PULL_REQUEST_COMMENT = u'pull_request_comment' |
1703
f23828b00b21
notification fixes and improvements
Marcin Kuzminski <marcin@python-works.com>
parents:
1702
diff
changeset
|
1970 |
1702
8cb7f5c4d494
#302 - basic notification system, models+tests
Marcin Kuzminski <marcin@python-works.com>
parents:
1693
diff
changeset
|
1971 notification_id = Column('notification_id', Integer(), nullable=False, primary_key=True) |
8cb7f5c4d494
#302 - basic notification system, models+tests
Marcin Kuzminski <marcin@python-works.com>
parents:
1693
diff
changeset
|
1972 subject = Column('subject', Unicode(512), nullable=True) |
2588
32dd6896abcf
added status column to pull request + some small refactoring of models
Marcin Kuzminski <marcin@python-works.com>
parents:
2585
diff
changeset
|
1973 body = Column('body', UnicodeText(50000), nullable=True) |
1703
f23828b00b21
notification fixes and improvements
Marcin Kuzminski <marcin@python-works.com>
parents:
1702
diff
changeset
|
1974 created_by = Column("created_by", Integer(), ForeignKey('users.user_id'), nullable=True) |
1702
8cb7f5c4d494
#302 - basic notification system, models+tests
Marcin Kuzminski <marcin@python-works.com>
parents:
1693
diff
changeset
|
1975 created_on = Column('created_on', DateTime(timezone=False), nullable=False, default=datetime.datetime.now) |
1703
f23828b00b21
notification fixes and improvements
Marcin Kuzminski <marcin@python-works.com>
parents:
1702
diff
changeset
|
1976 type_ = Column('type', Unicode(256)) |
1702
8cb7f5c4d494
#302 - basic notification system, models+tests
Marcin Kuzminski <marcin@python-works.com>
parents:
1693
diff
changeset
|
1977 |
1712
cac5109ac3b6
Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents:
1703
diff
changeset
|
1978 created_by_user = relationship('User') |
1717
7ff304d3028f
Notification fixes
Marcin Kuzminski <marcin@python-works.com>
parents:
1716
diff
changeset
|
1979 notifications_to_users = relationship('UserNotification', lazy='joined', |
7ff304d3028f
Notification fixes
Marcin Kuzminski <marcin@python-works.com>
parents:
1716
diff
changeset
|
1980 cascade="all, delete, delete-orphan") |
1702
8cb7f5c4d494
#302 - basic notification system, models+tests
Marcin Kuzminski <marcin@python-works.com>
parents:
1693
diff
changeset
|
1981 |
8cb7f5c4d494
#302 - basic notification system, models+tests
Marcin Kuzminski <marcin@python-works.com>
parents:
1693
diff
changeset
|
1982 @property |
8cb7f5c4d494
#302 - basic notification system, models+tests
Marcin Kuzminski <marcin@python-works.com>
parents:
1693
diff
changeset
|
1983 def recipients(self): |
8cb7f5c4d494
#302 - basic notification system, models+tests
Marcin Kuzminski <marcin@python-works.com>
parents:
1693
diff
changeset
|
1984 return [x.user for x in UserNotification.query()\ |
2248
72542dc597be
fixed issue with empty APIKEYS on registration #438
Marcin Kuzminski <marcin@python-works.com>
parents:
2161
diff
changeset
|
1985 .filter(UserNotification.notification == self)\ |
2585
a52cee88d612
fixed sorting in recipients query of notifications
Marcin Kuzminski <marcin@python-works.com>
parents:
2562
diff
changeset
|
1986 .order_by(UserNotification.user_id.asc()).all()] |
1702
8cb7f5c4d494
#302 - basic notification system, models+tests
Marcin Kuzminski <marcin@python-works.com>
parents:
1693
diff
changeset
|
1987 |
8cb7f5c4d494
#302 - basic notification system, models+tests
Marcin Kuzminski <marcin@python-works.com>
parents:
1693
diff
changeset
|
1988 @classmethod |
1703
f23828b00b21
notification fixes and improvements
Marcin Kuzminski <marcin@python-works.com>
parents:
1702
diff
changeset
|
1989 def create(cls, created_by, subject, body, recipients, type_=None): |
f23828b00b21
notification fixes and improvements
Marcin Kuzminski <marcin@python-works.com>
parents:
1702
diff
changeset
|
1990 if type_ is None: |
f23828b00b21
notification fixes and improvements
Marcin Kuzminski <marcin@python-works.com>
parents:
1702
diff
changeset
|
1991 type_ = Notification.TYPE_MESSAGE |
f23828b00b21
notification fixes and improvements
Marcin Kuzminski <marcin@python-works.com>
parents:
1702
diff
changeset
|
1992 |
1702
8cb7f5c4d494
#302 - basic notification system, models+tests
Marcin Kuzminski <marcin@python-works.com>
parents:
1693
diff
changeset
|
1993 notification = cls() |
1712
cac5109ac3b6
Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents:
1703
diff
changeset
|
1994 notification.created_by_user = created_by |
1702
8cb7f5c4d494
#302 - basic notification system, models+tests
Marcin Kuzminski <marcin@python-works.com>
parents:
1693
diff
changeset
|
1995 notification.subject = subject |
8cb7f5c4d494
#302 - basic notification system, models+tests
Marcin Kuzminski <marcin@python-works.com>
parents:
1693
diff
changeset
|
1996 notification.body = body |
1703
f23828b00b21
notification fixes and improvements
Marcin Kuzminski <marcin@python-works.com>
parents:
1702
diff
changeset
|
1997 notification.type_ = type_ |
1717
7ff304d3028f
Notification fixes
Marcin Kuzminski <marcin@python-works.com>
parents:
1716
diff
changeset
|
1998 notification.created_on = datetime.datetime.now() |
1713
54687aa00724
Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents:
1712
diff
changeset
|
1999 |
1702
8cb7f5c4d494
#302 - basic notification system, models+tests
Marcin Kuzminski <marcin@python-works.com>
parents:
1693
diff
changeset
|
2000 for u in recipients: |
1713
54687aa00724
Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents:
1712
diff
changeset
|
2001 assoc = UserNotification() |
54687aa00724
Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents:
1712
diff
changeset
|
2002 assoc.notification = notification |
54687aa00724
Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents:
1712
diff
changeset
|
2003 u.notifications.append(assoc) |
2520
a1e156503afe
Fixed calls to Session in db model
Marcin Kuzminski <marcin@python-works.com>
parents:
2510
diff
changeset
|
2004 Session().add(notification) |
1702
8cb7f5c4d494
#302 - basic notification system, models+tests
Marcin Kuzminski <marcin@python-works.com>
parents:
1693
diff
changeset
|
2005 return notification |
8cb7f5c4d494
#302 - basic notification system, models+tests
Marcin Kuzminski <marcin@python-works.com>
parents:
1693
diff
changeset
|
2006 |
1712
cac5109ac3b6
Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents:
1703
diff
changeset
|
2007 @property |
cac5109ac3b6
Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents:
1703
diff
changeset
|
2008 def description(self): |
cac5109ac3b6
Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents:
1703
diff
changeset
|
2009 from rhodecode.model.notification import NotificationModel |
cac5109ac3b6
Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents:
1703
diff
changeset
|
2010 return NotificationModel().make_description(self) |
cac5109ac3b6
Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents:
1703
diff
changeset
|
2011 |
1800 | 2012 |
1702
8cb7f5c4d494
#302 - basic notification system, models+tests
Marcin Kuzminski <marcin@python-works.com>
parents:
1693
diff
changeset
|
2013 class UserNotification(Base, BaseModel): |
8cb7f5c4d494
#302 - basic notification system, models+tests
Marcin Kuzminski <marcin@python-works.com>
parents:
1693
diff
changeset
|
2014 __tablename__ = 'user_to_notification' |
1958
7e4b3d3a9c5c
renamed repo groups table
Marcin Kuzminski <marcin@python-works.com>
parents:
1950
diff
changeset
|
2015 __table_args__ = ( |
7e4b3d3a9c5c
renamed repo groups table
Marcin Kuzminski <marcin@python-works.com>
parents:
1950
diff
changeset
|
2016 UniqueConstraint('user_id', 'notification_id'), |
2356
2da7b5984ae5
typo fix + code garden
Marcin Kuzminski <marcin@python-works.com>
parents:
2352
diff
changeset
|
2017 {'extend_existing': True, 'mysql_engine': 'InnoDB', |
2149 | 2018 'mysql_charset': 'utf8'} |
1958
7e4b3d3a9c5c
renamed repo groups table
Marcin Kuzminski <marcin@python-works.com>
parents:
1950
diff
changeset
|
2019 ) |
7e4b3d3a9c5c
renamed repo groups table
Marcin Kuzminski <marcin@python-works.com>
parents:
1950
diff
changeset
|
2020 user_id = Column('user_id', Integer(), ForeignKey('users.user_id'), primary_key=True) |
1713
54687aa00724
Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents:
1712
diff
changeset
|
2021 notification_id = Column("notification_id", Integer(), ForeignKey('notifications.notification_id'), primary_key=True) |
1703
f23828b00b21
notification fixes and improvements
Marcin Kuzminski <marcin@python-works.com>
parents:
1702
diff
changeset
|
2022 read = Column('read', Boolean, default=False) |
1702
8cb7f5c4d494
#302 - basic notification system, models+tests
Marcin Kuzminski <marcin@python-works.com>
parents:
1693
diff
changeset
|
2023 sent_on = Column('sent_on', DateTime(timezone=False), nullable=True, unique=None) |
8cb7f5c4d494
#302 - basic notification system, models+tests
Marcin Kuzminski <marcin@python-works.com>
parents:
1693
diff
changeset
|
2024 |
1713
54687aa00724
Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents:
1712
diff
changeset
|
2025 user = relationship('User', lazy="joined") |
1717
7ff304d3028f
Notification fixes
Marcin Kuzminski <marcin@python-works.com>
parents:
1716
diff
changeset
|
2026 notification = relationship('Notification', lazy="joined", |
1960
3daa7093fbbb
fix typo in db models
Marcin Kuzminski <marcin@python-works.com>
parents:
1958
diff
changeset
|
2027 order_by=lambda: Notification.created_on.desc(),) |
1702
8cb7f5c4d494
#302 - basic notification system, models+tests
Marcin Kuzminski <marcin@python-works.com>
parents:
1693
diff
changeset
|
2028 |
1712
cac5109ac3b6
Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents:
1703
diff
changeset
|
2029 def mark_as_read(self): |
cac5109ac3b6
Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents:
1703
diff
changeset
|
2030 self.read = True |
2520
a1e156503afe
Fixed calls to Session in db model
Marcin Kuzminski <marcin@python-works.com>
parents:
2510
diff
changeset
|
2031 Session().add(self) |
1702
8cb7f5c4d494
#302 - basic notification system, models+tests
Marcin Kuzminski <marcin@python-works.com>
parents:
1693
diff
changeset
|
2032 |
1800 | 2033 |
1593 | 2034 class DbMigrateVersion(Base, BaseModel): |
834
8924ed0e4f36
added current db version into rhodecode,
Marcin Kuzminski <marcin@python-works.com>
parents:
832
diff
changeset
|
2035 __tablename__ = 'db_migrate_version' |
2149 | 2036 __table_args__ = ( |
2356
2da7b5984ae5
typo fix + code garden
Marcin Kuzminski <marcin@python-works.com>
parents:
2352
diff
changeset
|
2037 {'extend_existing': True, 'mysql_engine': 'InnoDB', |
2149 | 2038 'mysql_charset': 'utf8'}, |
2039 ) | |
1594 | 2040 repository_id = Column('repository_id', String(250), primary_key=True) |
1593 | 2041 repository_path = Column('repository_path', Text) |
2042 version = Column('version', Integer) |