annotate rhodecode/model/db.py @ 2666:c51fb1da6df2 beta

cascade fixes for comments/pull-requests/reviewers when deleting a repo. Just CLEAN ALL !
author Marcin Kuzminski <marcin@python-works.com>
date Thu, 26 Jul 2012 22:14:40 +0200
parents 81a17ef4afc0
children f0851f37d6be
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
759
a7f50911a945 Models code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 734
diff changeset
1 # -*- coding: utf-8 -*-
a7f50911a945 Models code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 734
diff changeset
2 """
832
634596f81cfd new improved models with helper functions for easier data fetching
Marcin Kuzminski <marcin@python-works.com>
parents: 810
diff changeset
3 rhodecode.model.db
634596f81cfd new improved models with helper functions for easier data fetching
Marcin Kuzminski <marcin@python-works.com>
parents: 810
diff changeset
4 ~~~~~~~~~~~~~~~~~~
1203
6832ef664673 source code cleanup: remove trailing white space, normalize file endings
Marcin Kuzminski <marcin@python-works.com>
parents: 1199
diff changeset
5
834
8924ed0e4f36 added current db version into rhodecode,
Marcin Kuzminski <marcin@python-works.com>
parents: 832
diff changeset
6 Database Models for RhodeCode
1203
6832ef664673 source code cleanup: remove trailing white space, normalize file endings
Marcin Kuzminski <marcin@python-works.com>
parents: 1199
diff changeset
7
759
a7f50911a945 Models code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 734
diff changeset
8 :created_on: Apr 08, 2010
a7f50911a945 Models code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 734
diff changeset
9 :author: marcink
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
1884
0614862a20ec Added number of comments in changelog for each changeset
Marcin Kuzminski <marcin@python-works.com>
parents: 1824
diff changeset
31 from collections import defaultdict
759
a7f50911a945 Models code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 734
diff changeset
32
658
4ecb2ffcc110 fixed imports
Marcin Kuzminski <marcin@python-works.com>
parents: 657
diff changeset
33 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
34 from sqlalchemy.ext.hybrid import hybrid_property
1594
9dae92a65e40 fixes #288
Marcin Kuzminski <marcin@python-works.com>
parents: 1593
diff changeset
35 from sqlalchemy.orm import relationship, joinedload, class_mapper, validates
2357
ea079c9b62b5 merge with beta
Marcin Kuzminski <marcin@python-works.com>
parents: 2346 2356
diff changeset
36 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
37 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
38 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
39
2218
6e5d686084f1 fixed translation function for models
Marcin Kuzminski <marcin@python-works.com>
parents: 2217
diff changeset
40 from pylons.i18n.translation import lazy_ugettext as _
2215
2c2bdaeca912 code-review initial
Marcin Kuzminski <marcin@python-works.com>
parents: 2161
diff changeset
41
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
42 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
43 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
44 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
45 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
46
2109
8ecfed1d8f8b utils/conf
Marcin Kuzminski <marcin@python-works.com>
parents: 2079
diff changeset
47 from rhodecode.lib.utils2 import str2bool, safe_str, get_changeset_safe, \
8ecfed1d8f8b utils/conf
Marcin Kuzminski <marcin@python-works.com>
parents: 2079
diff changeset
48 safe_unicode
1514
87ec80c280bb fixed issues with python2.5
Marcin Kuzminski <marcin@python-works.com>
parents: 1508
diff changeset
49 from rhodecode.lib.compat import json
1669
f522f4d3bf93 moved caching query to libs
Marcin Kuzminski <marcin@python-works.com>
parents: 1665
diff changeset
50 from rhodecode.lib.caching_query import FromCache
1500
256e729a94cd Extended API
Marcin Kuzminski <marcin@python-works.com>
parents: 1466
diff changeset
51
2356
2da7b5984ae5 typo fix + code garden
Marcin Kuzminski <marcin@python-works.com>
parents: 2352
diff changeset
52 from rhodecode.model.meta import Base, Session
1500
256e729a94cd Extended API
Marcin Kuzminski <marcin@python-works.com>
parents: 1466
diff changeset
53
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
54 URL_SEP = '/'
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
55 log = logging.getLogger(__name__)
49
3ada2f409c1c Added sqlalchemy support
Marcin Kuzminski <marcin@python-blog.com>
parents:
diff changeset
56
1081
70bf0be59653 fixed Session problems in model class functions
Marcin Kuzminski <marcin@python-works.com>
parents: 1065
diff changeset
57 #==============================================================================
1388
2029c17cc6c6 Added basic JsonSerialization into models.
Marcin Kuzminski <marcin@python-works.com>
parents: 1385
diff changeset
58 # BASE CLASSES
1081
70bf0be59653 fixed Session problems in model class functions
Marcin Kuzminski <marcin@python-works.com>
parents: 1065
diff changeset
59 #==============================================================================
70bf0be59653 fixed Session problems in model class functions
Marcin Kuzminski <marcin@python-works.com>
parents: 1065
diff changeset
60
2062
bf8ed0adbc66 fixes #371 fixed issues with beaker/sqlalchemy and non-ascii cache keys
Marcin Kuzminski <marcin@python-works.com>
parents: 2058
diff changeset
61 _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
62
1800
6c86c987cf93 pep8ify
Marcin Kuzminski <marcin@python-works.com>
parents: 1758
diff changeset
63
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
64 class BaseModel(object):
1758
a87aa385f21c fixed repo_create permission by adding missing commit statements
Marcin Kuzminski <marcin@python-works.com>
parents: 1757
diff changeset
65 """
a87aa385f21c fixed repo_create permission by adding missing commit statements
Marcin Kuzminski <marcin@python-works.com>
parents: 1757
diff changeset
66 Base Model for all classess
1388
2029c17cc6c6 Added basic JsonSerialization into models.
Marcin Kuzminski <marcin@python-works.com>
parents: 1385
diff changeset
67 """
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 @classmethod
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
70 def _get_keys(cls):
1388
2029c17cc6c6 Added basic JsonSerialization into models.
Marcin Kuzminski <marcin@python-works.com>
parents: 1385
diff changeset
71 """return column names for this model """
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
72 return class_mapper(cls).c.keys()
1388
2029c17cc6c6 Added basic JsonSerialization into models.
Marcin Kuzminski <marcin@python-works.com>
parents: 1385
diff changeset
73
1948
4582e6b9e2f6 get_dict function garden
Marcin Kuzminski <marcin@python-works.com>
parents: 1886
diff changeset
74 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
75 """
a87aa385f21c fixed repo_create permission by adding missing commit statements
Marcin Kuzminski <marcin@python-works.com>
parents: 1757
diff changeset
76 return dict with keys and values corresponding
1948
4582e6b9e2f6 get_dict function garden
Marcin Kuzminski <marcin@python-works.com>
parents: 1886
diff changeset
77 to this model data """
1388
2029c17cc6c6 Added basic JsonSerialization into models.
Marcin Kuzminski <marcin@python-works.com>
parents: 1385
diff changeset
78
2029c17cc6c6 Added basic JsonSerialization into models.
Marcin Kuzminski <marcin@python-works.com>
parents: 1385
diff changeset
79 d = {}
2029c17cc6c6 Added basic JsonSerialization into models.
Marcin Kuzminski <marcin@python-works.com>
parents: 1385
diff changeset
80 for k in self._get_keys():
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
81 d[k] = getattr(self, k)
1800
6c86c987cf93 pep8ify
Marcin Kuzminski <marcin@python-works.com>
parents: 1758
diff changeset
82
1758
a87aa385f21c fixed repo_create permission by adding missing commit statements
Marcin Kuzminski <marcin@python-works.com>
parents: 1757
diff changeset
83 # 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
84 _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
85 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
86 # 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
87 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
88 _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
89 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
90 d[k] = val
1388
2029c17cc6c6 Added basic JsonSerialization into models.
Marcin Kuzminski <marcin@python-works.com>
parents: 1385
diff changeset
91 return d
2029c17cc6c6 Added basic JsonSerialization into models.
Marcin Kuzminski <marcin@python-works.com>
parents: 1385
diff changeset
92
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
93 def get_appstruct(self):
1388
2029c17cc6c6 Added basic JsonSerialization into models.
Marcin Kuzminski <marcin@python-works.com>
parents: 1385
diff changeset
94 """return list with keys and values tupples corresponding
2029c17cc6c6 Added basic JsonSerialization into models.
Marcin Kuzminski <marcin@python-works.com>
parents: 1385
diff changeset
95 to this model data """
2029c17cc6c6 Added basic JsonSerialization into models.
Marcin Kuzminski <marcin@python-works.com>
parents: 1385
diff changeset
96
2029c17cc6c6 Added basic JsonSerialization into models.
Marcin Kuzminski <marcin@python-works.com>
parents: 1385
diff changeset
97 l = []
2029c17cc6c6 Added basic JsonSerialization into models.
Marcin Kuzminski <marcin@python-works.com>
parents: 1385
diff changeset
98 for k in self._get_keys():
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
99 l.append((k, getattr(self, k),))
1388
2029c17cc6c6 Added basic JsonSerialization into models.
Marcin Kuzminski <marcin@python-works.com>
parents: 1385
diff changeset
100 return l
2029c17cc6c6 Added basic JsonSerialization into models.
Marcin Kuzminski <marcin@python-works.com>
parents: 1385
diff changeset
101
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
102 def populate_obj(self, populate_dict):
1388
2029c17cc6c6 Added basic JsonSerialization into models.
Marcin Kuzminski <marcin@python-works.com>
parents: 1385
diff changeset
103 """populate model with data from given populate_dict"""
2029c17cc6c6 Added basic JsonSerialization into models.
Marcin Kuzminski <marcin@python-works.com>
parents: 1385
diff changeset
104
2029c17cc6c6 Added basic JsonSerialization into models.
Marcin Kuzminski <marcin@python-works.com>
parents: 1385
diff changeset
105 for k in self._get_keys():
2029c17cc6c6 Added basic JsonSerialization into models.
Marcin Kuzminski <marcin@python-works.com>
parents: 1385
diff changeset
106 if k in populate_dict:
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
107 setattr(self, k, populate_dict[k])
1388
2029c17cc6c6 Added basic JsonSerialization into models.
Marcin Kuzminski <marcin@python-works.com>
parents: 1385
diff changeset
108
2029c17cc6c6 Added basic JsonSerialization into models.
Marcin Kuzminski <marcin@python-works.com>
parents: 1385
diff changeset
109 @classmethod
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
110 def query(cls):
2520
a1e156503afe Fixed calls to Session in db model
Marcin Kuzminski <marcin@python-works.com>
parents: 2510
diff changeset
111 return Session().query(cls)
1388
2029c17cc6c6 Added basic JsonSerialization into models.
Marcin Kuzminski <marcin@python-works.com>
parents: 1385
diff changeset
112
2029c17cc6c6 Added basic JsonSerialization into models.
Marcin Kuzminski <marcin@python-works.com>
parents: 1385
diff changeset
113 @classmethod
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
114 def get(cls, id_):
1594
9dae92a65e40 fixes #288
Marcin Kuzminski <marcin@python-works.com>
parents: 1593
diff changeset
115 if id_:
9dae92a65e40 fixes #288
Marcin Kuzminski <marcin@python-works.com>
parents: 1593
diff changeset
116 return cls.query().get(id_)
1466
ad5a543a9b2f Code cleanup
Marcin Kuzminski <marcin@python-works.com>
parents: 1460
diff changeset
117
1460
b50348816a80 Added more advanced hook management into rhodecode admin settings
Marcin Kuzminski <marcin@python-works.com>
parents: 1436
diff changeset
118 @classmethod
2496
fddd8e3fc157 use get_or_404 where possible
Marcin Kuzminski <marcin@python-works.com>
parents: 2481
diff changeset
119 def get_or_404(cls, id_):
fddd8e3fc157 use get_or_404 where possible
Marcin Kuzminski <marcin@python-works.com>
parents: 2481
diff changeset
120 if id_:
fddd8e3fc157 use get_or_404 where possible
Marcin Kuzminski <marcin@python-works.com>
parents: 2481
diff changeset
121 res = cls.query().get(id_)
fddd8e3fc157 use get_or_404 where possible
Marcin Kuzminski <marcin@python-works.com>
parents: 2481
diff changeset
122 if not res:
fddd8e3fc157 use get_or_404 where possible
Marcin Kuzminski <marcin@python-works.com>
parents: 2481
diff changeset
123 raise HTTPNotFound
fddd8e3fc157 use get_or_404 where possible
Marcin Kuzminski <marcin@python-works.com>
parents: 2481
diff changeset
124 return res
fddd8e3fc157 use get_or_404 where possible
Marcin Kuzminski <marcin@python-works.com>
parents: 2481
diff changeset
125
fddd8e3fc157 use get_or_404 where possible
Marcin Kuzminski <marcin@python-works.com>
parents: 2481
diff changeset
126 @classmethod
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
127 def getAll(cls):
1584
3338a0994472 Improve API with user/group/repo CRUD methods
Nicolas VINOT <aeris@imirhil.fr>
parents: 1508
diff changeset
128 return cls.query().all()
1466
ad5a543a9b2f Code cleanup
Marcin Kuzminski <marcin@python-works.com>
parents: 1460
diff changeset
129
1460
b50348816a80 Added more advanced hook management into rhodecode admin settings
Marcin Kuzminski <marcin@python-works.com>
parents: 1436
diff changeset
130 @classmethod
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
131 def delete(cls, id_):
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
132 obj = cls.query().get(id_)
2520
a1e156503afe Fixed calls to Session in db model
Marcin Kuzminski <marcin@python-works.com>
parents: 2510
diff changeset
133 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
134
2156
a27e4d44237e Use __unicode__ instead of __repr__ in models.
Marcin Kuzminski <marcin@python-works.com>
parents: 2152
diff changeset
135 def __repr__(self):
a27e4d44237e Use __unicode__ instead of __repr__ in models.
Marcin Kuzminski <marcin@python-works.com>
parents: 2152
diff changeset
136 if hasattr(self, '__unicode__'):
a27e4d44237e Use __unicode__ instead of __repr__ in models.
Marcin Kuzminski <marcin@python-works.com>
parents: 2152
diff changeset
137 # python repr needs to return str
a27e4d44237e Use __unicode__ instead of __repr__ in models.
Marcin Kuzminski <marcin@python-works.com>
parents: 2152
diff changeset
138 return safe_str(self.__unicode__())
a27e4d44237e Use __unicode__ instead of __repr__ in models.
Marcin Kuzminski <marcin@python-works.com>
parents: 2152
diff changeset
139 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
140
2356
2da7b5984ae5 typo fix + code garden
Marcin Kuzminski <marcin@python-works.com>
parents: 2352
diff changeset
141
1633
2c0d35e336b5 refactoring of models names for repoGroup permissions
Marcin Kuzminski <marcin@python-works.com>
parents: 1607
diff changeset
142 class RhodeCodeSetting(Base, BaseModel):
548
b75b77ef649d renamed hg_app to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents: 547
diff changeset
143 __tablename__ = 'rhodecode_settings'
1958
7e4b3d3a9c5c renamed repo groups table
Marcin Kuzminski <marcin@python-works.com>
parents: 1950
diff changeset
144 __table_args__ = (
7e4b3d3a9c5c renamed repo groups table
Marcin Kuzminski <marcin@python-works.com>
parents: 1950
diff changeset
145 UniqueConstraint('app_settings_name'),
2356
2da7b5984ae5 typo fix + code garden
Marcin Kuzminski <marcin@python-works.com>
parents: 2352
diff changeset
146 {'extend_existing': True, 'mysql_engine': 'InnoDB',
2149
50aa7cb78cfe Mysql fixes
Marcin Kuzminski <marcin@python-works.com>
parents: 2147
diff changeset
147 'mysql_charset': 'utf8'}
1958
7e4b3d3a9c5c renamed repo groups table
Marcin Kuzminski <marcin@python-works.com>
parents: 1950
diff changeset
148 )
1594
9dae92a65e40 fixes #288
Marcin Kuzminski <marcin@python-works.com>
parents: 1593
diff changeset
149 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
150 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
151 _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
152
1594
9dae92a65e40 fixes #288
Marcin Kuzminski <marcin@python-works.com>
parents: 1593
diff changeset
153 def __init__(self, k='', v=''):
704
26237de9b613 Added settings model, and Exceptions lib.
Marcin Kuzminski <marcin@python-works.com>
parents: 692
diff changeset
154 self.app_settings_name = k
26237de9b613 Added settings model, and Exceptions lib.
Marcin Kuzminski <marcin@python-works.com>
parents: 692
diff changeset
155 self.app_settings_value = v
26237de9b613 Added settings model, and Exceptions lib.
Marcin Kuzminski <marcin@python-works.com>
parents: 692
diff changeset
156
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
157 @validates('_app_settings_value')
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
158 def validate_settings_value(self, key, val):
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
159 assert type(val) == unicode
1561
4d841e565237 added validation of params on settings table
Marcin Kuzminski <marcin@python-works.com>
parents: 1556
diff changeset
160 return val
4d841e565237 added validation of params on settings table
Marcin Kuzminski <marcin@python-works.com>
parents: 1556
diff changeset
161
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
162 @hybrid_property
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
163 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
164 v = self._app_settings_value
2013
8530c3cd9d04 fixed issue with hybrid property for ldap_active
Marcin Kuzminski <marcin@python-works.com>
parents: 2007
diff changeset
165 if self.app_settings_name == 'ldap_active':
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
166 v = str2bool(v)
1591
0b63a0d2cede Merge with upstream
Nicolas VINOT <aeris@imirhil.fr>
parents: 1576 1590
diff changeset
167 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
168
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 @app_settings_value.setter
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
170 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
171 """
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
172 Setter that will always make sure we use unicode in app_settings_value
1591
0b63a0d2cede Merge with upstream
Nicolas VINOT <aeris@imirhil.fr>
parents: 1576 1590
diff changeset
173
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
174 :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
175 """
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
176 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
177
2156
a27e4d44237e Use __unicode__ instead of __repr__ in models.
Marcin Kuzminski <marcin@python-works.com>
parents: 2152
diff changeset
178 def __unicode__(self):
a27e4d44237e Use __unicode__ instead of __repr__ in models.
Marcin Kuzminski <marcin@python-works.com>
parents: 2152
diff changeset
179 return u"<%s('%s:%s')>" % (
1958
7e4b3d3a9c5c renamed repo groups table
Marcin Kuzminski <marcin@python-works.com>
parents: 1950
diff changeset
180 self.__class__.__name__,
7e4b3d3a9c5c renamed repo groups table
Marcin Kuzminski <marcin@python-works.com>
parents: 1950
diff changeset
181 self.app_settings_name, self.app_settings_value
7e4b3d3a9c5c renamed repo groups table
Marcin Kuzminski <marcin@python-works.com>
parents: 1950
diff changeset
182 )
704
26237de9b613 Added settings model, and Exceptions lib.
Marcin Kuzminski <marcin@python-works.com>
parents: 692
diff changeset
183
1266
a1bcfe58a1ab Fixed #161 form saves the create repository permission.
Marcin Kuzminski <marcin@python-works.com>
parents: 1206
diff changeset
184 @classmethod
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
185 def get_by_name(cls, ldap_key):
1584
3338a0994472 Improve API with user/group/repo CRUD methods
Nicolas VINOT <aeris@imirhil.fr>
parents: 1508
diff changeset
186 return cls.query()\
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
187 .filter(cls.app_settings_name == ldap_key).scalar()
1292
c0335c1dee36 added some fixes to LDAP form re-submition, new simples ldap-settings getter.
Marcin Kuzminski <marcin@python-works.com>
parents: 1279
diff changeset
188
c0335c1dee36 added some fixes to LDAP form re-submition, new simples ldap-settings getter.
Marcin Kuzminski <marcin@python-works.com>
parents: 1279
diff changeset
189 @classmethod
1594
9dae92a65e40 fixes #288
Marcin Kuzminski <marcin@python-works.com>
parents: 1593
diff changeset
190 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
191
1584
3338a0994472 Improve API with user/group/repo CRUD methods
Nicolas VINOT <aeris@imirhil.fr>
parents: 1508
diff changeset
192 ret = cls.query()
1266
a1bcfe58a1ab Fixed #161 form saves the create repository permission.
Marcin Kuzminski <marcin@python-works.com>
parents: 1206
diff changeset
193
a1bcfe58a1ab Fixed #161 form saves the create repository permission.
Marcin Kuzminski <marcin@python-works.com>
parents: 1206
diff changeset
194 if cache:
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
195 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
196
a1bcfe58a1ab Fixed #161 form saves the create repository permission.
Marcin Kuzminski <marcin@python-works.com>
parents: 1206
diff changeset
197 if not ret:
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
198 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
199 settings = {}
a1bcfe58a1ab Fixed #161 form saves the create repository permission.
Marcin Kuzminski <marcin@python-works.com>
parents: 1206
diff changeset
200 for each in ret:
a1bcfe58a1ab Fixed #161 form saves the create repository permission.
Marcin Kuzminski <marcin@python-works.com>
parents: 1206
diff changeset
201 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
202 each.app_settings_value
a1bcfe58a1ab Fixed #161 form saves the create repository permission.
Marcin Kuzminski <marcin@python-works.com>
parents: 1206
diff changeset
203
a1bcfe58a1ab Fixed #161 form saves the create repository permission.
Marcin Kuzminski <marcin@python-works.com>
parents: 1206
diff changeset
204 return settings
a1bcfe58a1ab Fixed #161 form saves the create repository permission.
Marcin Kuzminski <marcin@python-works.com>
parents: 1206
diff changeset
205
a1bcfe58a1ab Fixed #161 form saves the create repository permission.
Marcin Kuzminski <marcin@python-works.com>
parents: 1206
diff changeset
206 @classmethod
1594
9dae92a65e40 fixes #288
Marcin Kuzminski <marcin@python-works.com>
parents: 1593
diff changeset
207 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
208 ret = cls.query()\
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
209 .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
210 fd = {}
a1bcfe58a1ab Fixed #161 form saves the create repository permission.
Marcin Kuzminski <marcin@python-works.com>
parents: 1206
diff changeset
211 for row in ret:
2356
2da7b5984ae5 typo fix + code garden
Marcin Kuzminski <marcin@python-works.com>
parents: 2352
diff changeset
212 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
213
1266
a1bcfe58a1ab Fixed #161 form saves the create repository permission.
Marcin Kuzminski <marcin@python-works.com>
parents: 1206
diff changeset
214 return fd
a1bcfe58a1ab Fixed #161 form saves the create repository permission.
Marcin Kuzminski <marcin@python-works.com>
parents: 1206
diff changeset
215
a1bcfe58a1ab Fixed #161 form saves the create repository permission.
Marcin Kuzminski <marcin@python-works.com>
parents: 1206
diff changeset
216
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
217 class RhodeCodeUi(Base, BaseModel):
548
b75b77ef649d renamed hg_app to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents: 547
diff changeset
218 __tablename__ = 'rhodecode_ui'
1958
7e4b3d3a9c5c renamed repo groups table
Marcin Kuzminski <marcin@python-works.com>
parents: 1950
diff changeset
219 __table_args__ = (
1963
9bbde54232dc white space cleanup
Marcin Kuzminski <marcin@python-works.com>
parents: 1960
diff changeset
220 UniqueConstraint('ui_key'),
2356
2da7b5984ae5 typo fix + code garden
Marcin Kuzminski <marcin@python-works.com>
parents: 2352
diff changeset
221 {'extend_existing': True, 'mysql_engine': 'InnoDB',
2149
50aa7cb78cfe Mysql fixes
Marcin Kuzminski <marcin@python-works.com>
parents: 2147
diff changeset
222 'mysql_charset': 'utf8'}
1958
7e4b3d3a9c5c renamed repo groups table
Marcin Kuzminski <marcin@python-works.com>
parents: 1950
diff changeset
223 )
1460
b50348816a80 Added more advanced hook management into rhodecode admin settings
Marcin Kuzminski <marcin@python-works.com>
parents: 1436
diff changeset
224
b50348816a80 Added more advanced hook management into rhodecode admin settings
Marcin Kuzminski <marcin@python-works.com>
parents: 1436
diff changeset
225 HOOK_UPDATE = 'changegroup.update'
b50348816a80 Added more advanced hook management into rhodecode admin settings
Marcin Kuzminski <marcin@python-works.com>
parents: 1436
diff changeset
226 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
227 HOOK_PUSH = 'changegroup.push_logger'
1460
b50348816a80 Added more advanced hook management into rhodecode admin settings
Marcin Kuzminski <marcin@python-works.com>
parents: 1436
diff changeset
228 HOOK_PULL = 'preoutgoing.pull_logger'
b50348816a80 Added more advanced hook management into rhodecode admin settings
Marcin Kuzminski <marcin@python-works.com>
parents: 1436
diff changeset
229
1594
9dae92a65e40 fixes #288
Marcin Kuzminski <marcin@python-works.com>
parents: 1593
diff changeset
230 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
231 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
232 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
233 ui_value = Column("ui_value", String(255, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None)
1594
9dae92a65e40 fixes #288
Marcin Kuzminski <marcin@python-works.com>
parents: 1593
diff changeset
234 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
235
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
236 @classmethod
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
237 def get_by_key(cls, key):
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
238 return cls.query().filter(cls.ui_key == key)
1345
3bce31f026b8 #47 implemented Adding of new repo_groups+forms+validators. Fixed sorting of repo groups by main names in multiple locations. Removed some unneeded calls to self.sa for exchange to .query() methods.
Marcin Kuzminski <marcin@python-works.com>
parents: 1343
diff changeset
239
1460
b50348816a80 Added more advanced hook management into rhodecode admin settings
Marcin Kuzminski <marcin@python-works.com>
parents: 1436
diff changeset
240 @classmethod
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
241 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
242 q = cls.query()
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
243 q = q.filter(cls.ui_key.in_([cls.HOOK_UPDATE,
1460
b50348816a80 Added more advanced hook management into rhodecode admin settings
Marcin Kuzminski <marcin@python-works.com>
parents: 1436
diff changeset
244 cls.HOOK_REPO_SIZE,
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
245 cls.HOOK_PUSH, cls.HOOK_PULL]))
1460
b50348816a80 Added more advanced hook management into rhodecode admin settings
Marcin Kuzminski <marcin@python-works.com>
parents: 1436
diff changeset
246 return q.all()
b50348816a80 Added more advanced hook management into rhodecode admin settings
Marcin Kuzminski <marcin@python-works.com>
parents: 1436
diff changeset
247
b50348816a80 Added more advanced hook management into rhodecode admin settings
Marcin Kuzminski <marcin@python-works.com>
parents: 1436
diff changeset
248 @classmethod
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
249 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
250 q = cls.query()
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
251 q = q.filter(~cls.ui_key.in_([cls.HOOK_UPDATE,
1460
b50348816a80 Added more advanced hook management into rhodecode admin settings
Marcin Kuzminski <marcin@python-works.com>
parents: 1436
diff changeset
252 cls.HOOK_REPO_SIZE,
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
253 cls.HOOK_PUSH, cls.HOOK_PULL]))
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
254 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
255 return q.all()
b50348816a80 Added more advanced hook management into rhodecode admin settings
Marcin Kuzminski <marcin@python-works.com>
parents: 1436
diff changeset
256
b50348816a80 Added more advanced hook management into rhodecode admin settings
Marcin Kuzminski <marcin@python-works.com>
parents: 1436
diff changeset
257 @classmethod
2401
e2af60e480ce Removed hardcoded hooks names from settings.
Marcin Kuzminski <marcin@python-works.com>
parents: 2400
diff changeset
258 def get_repos_location(cls):
e2af60e480ce Removed hardcoded hooks names from settings.
Marcin Kuzminski <marcin@python-works.com>
parents: 2400
diff changeset
259 return cls.get_by_key('/').one().ui_value
e2af60e480ce Removed hardcoded hooks names from settings.
Marcin Kuzminski <marcin@python-works.com>
parents: 2400
diff changeset
260
e2af60e480ce Removed hardcoded hooks names from settings.
Marcin Kuzminski <marcin@python-works.com>
parents: 2400
diff changeset
261 @classmethod
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
262 def create_or_update_hook(cls, key, val):
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
263 new_ui = cls.get_by_key(key).scalar() or cls()
1460
b50348816a80 Added more advanced hook management into rhodecode admin settings
Marcin Kuzminski <marcin@python-works.com>
parents: 1436
diff changeset
264 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
265 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
266 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
267 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
268
2520
a1e156503afe Fixed calls to Session in db model
Marcin Kuzminski <marcin@python-works.com>
parents: 2510
diff changeset
269 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
270
b50348816a80 Added more advanced hook management into rhodecode admin settings
Marcin Kuzminski <marcin@python-works.com>
parents: 1436
diff changeset
271
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
272 class User(Base, BaseModel):
49
3ada2f409c1c Added sqlalchemy support
Marcin Kuzminski <marcin@python-blog.com>
parents:
diff changeset
273 __tablename__ = 'users'
1958
7e4b3d3a9c5c renamed repo groups table
Marcin Kuzminski <marcin@python-works.com>
parents: 1950
diff changeset
274 __table_args__ = (
1963
9bbde54232dc white space cleanup
Marcin Kuzminski <marcin@python-works.com>
parents: 1960
diff changeset
275 UniqueConstraint('username'), UniqueConstraint('email'),
2356
2da7b5984ae5 typo fix + code garden
Marcin Kuzminski <marcin@python-works.com>
parents: 2352
diff changeset
276 {'extend_existing': True, 'mysql_engine': 'InnoDB',
2149
50aa7cb78cfe Mysql fixes
Marcin Kuzminski <marcin@python-works.com>
parents: 2147
diff changeset
277 'mysql_charset': 'utf8'}
1958
7e4b3d3a9c5c renamed repo groups table
Marcin Kuzminski <marcin@python-works.com>
parents: 1950
diff changeset
278 )
1594
9dae92a65e40 fixes #288
Marcin Kuzminski <marcin@python-works.com>
parents: 1593
diff changeset
279 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
280 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
281 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
282 active = Column("active", Boolean(), nullable=True, unique=None, default=True)
1594
9dae92a65e40 fixes #288
Marcin Kuzminski <marcin@python-works.com>
parents: 1593
diff changeset
283 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
284 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
285 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
286 _email = Column("email", String(255, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None)
1594
9dae92a65e40 fixes #288
Marcin Kuzminski <marcin@python-works.com>
parents: 1593
diff changeset
287 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
288 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
289 api_key = Column("api_key", 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
290
1594
9dae92a65e40 fixes #288
Marcin Kuzminski <marcin@python-works.com>
parents: 1593
diff changeset
291 user_log = relationship('UserLog', cascade='all')
9dae92a65e40 fixes #288
Marcin Kuzminski <marcin@python-works.com>
parents: 1593
diff changeset
292 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
293
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
294 repositories = relationship('Repository')
1594
9dae92a65e40 fixes #288
Marcin Kuzminski <marcin@python-works.com>
parents: 1593
diff changeset
295 user_followers = relationship('UserFollowing', primaryjoin='UserFollowing.follows_user_id==User.user_id', cascade='all')
1633
2c0d35e336b5 refactoring of models names for repoGroup permissions
Marcin Kuzminski <marcin@python-works.com>
parents: 1607
diff changeset
296 repo_to_perm = relationship('UserRepoToPerm', primaryjoin='UserRepoToPerm.user_id==User.user_id', cascade='all')
2149
50aa7cb78cfe Mysql fixes
Marcin Kuzminski <marcin@python-works.com>
parents: 2147
diff changeset
297 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
298
1594
9dae92a65e40 fixes #288
Marcin Kuzminski <marcin@python-works.com>
parents: 1593
diff changeset
299 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
300
2157
6a2c0cfb018d Cascade delete comments and notifications when removing user.
Marcin Kuzminski <marcin@python-works.com>
parents: 2156
diff changeset
301 notifications = relationship('UserNotification', cascade='all')
6a2c0cfb018d Cascade delete comments and notifications when removing user.
Marcin Kuzminski <marcin@python-works.com>
parents: 2156
diff changeset
302 # notifications assigned to this user
6a2c0cfb018d Cascade delete comments and notifications when removing user.
Marcin Kuzminski <marcin@python-works.com>
parents: 2156
diff changeset
303 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
304 # comments created by this user
6a2c0cfb018d Cascade delete comments and notifications when removing user.
Marcin Kuzminski <marcin@python-works.com>
parents: 2156
diff changeset
305 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
306 #extra emails for this user
78f96d7bb23b cascade delete extra emails on user delete
Marcin Kuzminski <marcin@python-works.com>
parents: 2544
diff changeset
307 user_emails = relationship('UserEmailMap', cascade='all')
1702
8cb7f5c4d494 #302 - basic notification system, models+tests
Marcin Kuzminski <marcin@python-works.com>
parents: 1693
diff changeset
308
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
309 @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
310 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
311 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
312
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
313 @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
314 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
315 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
316
759
a7f50911a945 Models code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 734
diff changeset
317 @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
318 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
319 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
320 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
321
7e3e9d0c5575 Add list of all emails that user may have into get_user call
Marcin Kuzminski <marcin@python-works.com>
parents: 2496
diff changeset
322 @property
1731
31e6eb2fb4b2 implements #222 registration feedback
Marcin Kuzminski <marcin@python-works.com>
parents: 1729
diff changeset
323 def full_name(self):
31e6eb2fb4b2 implements #222 registration feedback
Marcin Kuzminski <marcin@python-works.com>
parents: 1729
diff changeset
324 return '%s %s' % (self.name, self.lastname)
31e6eb2fb4b2 implements #222 registration feedback
Marcin Kuzminski <marcin@python-works.com>
parents: 1729
diff changeset
325
31e6eb2fb4b2 implements #222 registration feedback
Marcin Kuzminski <marcin@python-works.com>
parents: 1729
diff changeset
326 @property
1950
4ae17f819ee8 #344 optional firstname lastname on user creation
Marcin Kuzminski <marcin@python-works.com>
parents: 1948
diff changeset
327 def full_name_or_username(self):
4ae17f819ee8 #344 optional firstname lastname on user creation
Marcin Kuzminski <marcin@python-works.com>
parents: 1948
diff changeset
328 return ('%s %s' % (self.name, self.lastname)
4ae17f819ee8 #344 optional firstname lastname on user creation
Marcin Kuzminski <marcin@python-works.com>
parents: 1948
diff changeset
329 if (self.name and self.lastname) else self.username)
4ae17f819ee8 #344 optional firstname lastname on user creation
Marcin Kuzminski <marcin@python-works.com>
parents: 1948
diff changeset
330
4ae17f819ee8 #344 optional firstname lastname on user creation
Marcin Kuzminski <marcin@python-works.com>
parents: 1948
diff changeset
331 @property
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
332 def full_contact(self):
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
333 return '%s %s <%s>' % (self.name, self.lastname, self.email)
631
05528ad948c4 Hacking for git support,and new faster repo scan
Marcin Kuzminski <marcin@python-works.com>
parents: 549
diff changeset
334
895
62c04c5cc971 Added some more details into user edit permissions view
Marcin Kuzminski <marcin@python-works.com>
parents: 880
diff changeset
335 @property
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
336 def short_contact(self):
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
337 return '%s %s' % (self.name, self.lastname)
1088
fee472613dfa made simple global rss and atom feed
Marcin Kuzminski <marcin@python-works.com>
parents: 1081
diff changeset
338
fee472613dfa made simple global rss and atom feed
Marcin Kuzminski <marcin@python-works.com>
parents: 1081
diff changeset
339 @property
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
340 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
341 return self.admin
62c04c5cc971 Added some more details into user edit permissions view
Marcin Kuzminski <marcin@python-works.com>
parents: 880
diff changeset
342
2156
a27e4d44237e Use __unicode__ instead of __repr__ in models.
Marcin Kuzminski <marcin@python-works.com>
parents: 2152
diff changeset
343 def __unicode__(self):
a27e4d44237e Use __unicode__ instead of __repr__ in models.
Marcin Kuzminski <marcin@python-works.com>
parents: 2152
diff changeset
344 return u"<%s('id:%s:%s')>" % (self.__class__.__name__,
1712
cac5109ac3b6 Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents: 1703
diff changeset
345 self.user_id, self.username)
cac5109ac3b6 Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents: 1703
diff changeset
346
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
347 @classmethod
1665
36f77a46f291 Added cache options to some db getters
Marcin Kuzminski <marcin@python-works.com>
parents: 1634
diff changeset
348 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
349 if case_insensitive:
1665
36f77a46f291 Added cache options to some db getters
Marcin Kuzminski <marcin@python-works.com>
parents: 1634
diff changeset
350 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
351 else:
1665
36f77a46f291 Added cache options to some db getters
Marcin Kuzminski <marcin@python-works.com>
parents: 1634
diff changeset
352 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
353
36f77a46f291 Added cache options to some db getters
Marcin Kuzminski <marcin@python-works.com>
parents: 1634
diff changeset
354 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
355 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
356 "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
357 "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
358 )
bf8ed0adbc66 fixes #371 fixed issues with beaker/sqlalchemy and non-ascii cache keys
Marcin Kuzminski <marcin@python-works.com>
parents: 2058
diff changeset
359 )
1665
36f77a46f291 Added cache options to some db getters
Marcin Kuzminski <marcin@python-works.com>
parents: 1634
diff changeset
360 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
361
1417
5875955def39 fixes #223 improve password reset form
Marcin Kuzminski <marcin@python-works.com>
parents: 1401
diff changeset
362 @classmethod
1665
36f77a46f291 Added cache options to some db getters
Marcin Kuzminski <marcin@python-works.com>
parents: 1634
diff changeset
363 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
364 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
365
36f77a46f291 Added cache options to some db getters
Marcin Kuzminski <marcin@python-works.com>
parents: 1634
diff changeset
366 if cache:
36f77a46f291 Added cache options to some db getters
Marcin Kuzminski <marcin@python-works.com>
parents: 1634
diff changeset
367 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
368 "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
369 return q.scalar()
1417
5875955def39 fixes #223 improve password reset form
Marcin Kuzminski <marcin@python-works.com>
parents: 1401
diff changeset
370
1716
7d1fc253549e notification to commit author + gardening
Marcin Kuzminski <marcin@python-works.com>
parents: 1713
diff changeset
371 @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
372 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
373 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
374 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
375 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
376 q = cls.query().filter(cls.email == email)
1716
7d1fc253549e notification to commit author + gardening
Marcin Kuzminski <marcin@python-works.com>
parents: 1713
diff changeset
377
7d1fc253549e notification to commit author + gardening
Marcin Kuzminski <marcin@python-works.com>
parents: 1713
diff changeset
378 if cache:
7d1fc253549e notification to commit author + gardening
Marcin Kuzminski <marcin@python-works.com>
parents: 1713
diff changeset
379 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
380 "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
381
20e307d5250f Added email-map for alternative email addresses for users
Marcin Kuzminski <marcin@python-works.com>
parents: 2296
diff changeset
382 ret = q.scalar()
20e307d5250f Added email-map for alternative email addresses for users
Marcin Kuzminski <marcin@python-works.com>
parents: 2296
diff changeset
383 if ret is None:
20e307d5250f Added email-map for alternative email addresses for users
Marcin Kuzminski <marcin@python-works.com>
parents: 2296
diff changeset
384 q = UserEmailMap.query()
20e307d5250f Added email-map for alternative email addresses for users
Marcin Kuzminski <marcin@python-works.com>
parents: 2296
diff changeset
385 # 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
386 if case_insensitive:
20e307d5250f Added email-map for alternative email addresses for users
Marcin Kuzminski <marcin@python-works.com>
parents: 2296
diff changeset
387 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
388 else:
20e307d5250f Added email-map for alternative email addresses for users
Marcin Kuzminski <marcin@python-works.com>
parents: 2296
diff changeset
389 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
390 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
391 if cache:
20e307d5250f Added email-map for alternative email addresses for users
Marcin Kuzminski <marcin@python-works.com>
parents: 2296
diff changeset
392 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
393 "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
394 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
395
20e307d5250f Added email-map for alternative email addresses for users
Marcin Kuzminski <marcin@python-works.com>
parents: 2296
diff changeset
396 return ret
1716
7d1fc253549e notification to commit author + gardening
Marcin Kuzminski <marcin@python-works.com>
parents: 1713
diff changeset
397
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
398 def update_lastlogin(self):
442
d66a7fa7689b moved loged in user propagation out of forms,
Marcin Kuzminski <marcin@python-works.com>
parents: 417
diff changeset
399 """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
400 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
401 Session().add(self)
1976
Marcin Kuzminski <marcin@python-works.com>
parents: 1963
diff changeset
402 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
403
2508
43cb5b6047fd Added functions for getting API data to repo and user models
Marcin Kuzminski <marcin@python-works.com>
parents: 2506
diff changeset
404 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
405 """
43cb5b6047fd Added functions for getting API data to repo and user models
Marcin Kuzminski <marcin@python-works.com>
parents: 2506
diff changeset
406 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
407 """
43cb5b6047fd Added functions for getting API data to repo and user models
Marcin Kuzminski <marcin@python-works.com>
parents: 2506
diff changeset
408 user = self
43cb5b6047fd Added functions for getting API data to repo and user models
Marcin Kuzminski <marcin@python-works.com>
parents: 2506
diff changeset
409 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
410 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
411 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
412 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
413 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
414 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
415 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
416 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
417 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
418 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
419 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
420 last_login=user.last_login,
43cb5b6047fd Added functions for getting API data to repo and user models
Marcin Kuzminski <marcin@python-works.com>
parents: 2506
diff changeset
421 )
43cb5b6047fd Added functions for getting API data to repo and user models
Marcin Kuzminski <marcin@python-works.com>
parents: 2506
diff changeset
422 return data
43cb5b6047fd Added functions for getting API data to repo and user models
Marcin Kuzminski <marcin@python-works.com>
parents: 2506
diff changeset
423
1758
a87aa385f21c fixed repo_create permission by adding missing commit statements
Marcin Kuzminski <marcin@python-works.com>
parents: 1757
diff changeset
424 def __json__(self):
2544
6ce3387bf0ce Renamed name to firstname in forms
Marcin Kuzminski <marcin@python-works.com>
parents: 2542
diff changeset
425 data = dict(
1950
4ae17f819ee8 #344 optional firstname lastname on user creation
Marcin Kuzminski <marcin@python-works.com>
parents: 1948
diff changeset
426 full_name=self.full_name,
4ae17f819ee8 #344 optional firstname lastname on user creation
Marcin Kuzminski <marcin@python-works.com>
parents: 1948
diff changeset
427 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
428 short_contact=self.short_contact,
4ae17f819ee8 #344 optional firstname lastname on user creation
Marcin Kuzminski <marcin@python-works.com>
parents: 1948
diff changeset
429 full_contact=self.full_contact
4ae17f819ee8 #344 optional firstname lastname on user creation
Marcin Kuzminski <marcin@python-works.com>
parents: 1948
diff changeset
430 )
2544
6ce3387bf0ce Renamed name to firstname in forms
Marcin Kuzminski <marcin@python-works.com>
parents: 2542
diff changeset
431 data.update(self.get_api_data())
6ce3387bf0ce Renamed name to firstname in forms
Marcin Kuzminski <marcin@python-works.com>
parents: 2542
diff changeset
432 return data
1758
a87aa385f21c fixed repo_create permission by adding missing commit statements
Marcin Kuzminski <marcin@python-works.com>
parents: 1757
diff changeset
433
a87aa385f21c fixed repo_create permission by adding missing commit statements
Marcin Kuzminski <marcin@python-works.com>
parents: 1757
diff changeset
434
2329
20e307d5250f Added email-map for alternative email addresses for users
Marcin Kuzminski <marcin@python-works.com>
parents: 2296
diff changeset
435 class UserEmailMap(Base, BaseModel):
20e307d5250f Added email-map for alternative email addresses for users
Marcin Kuzminski <marcin@python-works.com>
parents: 2296
diff changeset
436 __tablename__ = 'user_email_map'
20e307d5250f Added email-map for alternative email addresses for users
Marcin Kuzminski <marcin@python-works.com>
parents: 2296
diff changeset
437 __table_args__ = (
2463
b426ecc30319 Added some DB indexes to optimize queries
Marcin Kuzminski <marcin@python-works.com>
parents: 2462
diff changeset
438 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
439 UniqueConstraint('email'),
2463
b426ecc30319 Added some DB indexes to optimize queries
Marcin Kuzminski <marcin@python-works.com>
parents: 2462
diff changeset
440 {'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
441 'mysql_charset': 'utf8'}
20e307d5250f Added email-map for alternative email addresses for users
Marcin Kuzminski <marcin@python-works.com>
parents: 2296
diff changeset
442 )
20e307d5250f Added email-map for alternative email addresses for users
Marcin Kuzminski <marcin@python-works.com>
parents: 2296
diff changeset
443 __mapper_args__ = {}
20e307d5250f Added email-map for alternative email addresses for users
Marcin Kuzminski <marcin@python-works.com>
parents: 2296
diff changeset
444
20e307d5250f Added email-map for alternative email addresses for users
Marcin Kuzminski <marcin@python-works.com>
parents: 2296
diff changeset
445 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
446 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
447 _email = Column("email", String(255, convert_unicode=False, assert_unicode=None), nullable=True, unique=False, default=None)
2329
20e307d5250f Added email-map for alternative email addresses for users
Marcin Kuzminski <marcin@python-works.com>
parents: 2296
diff changeset
448
2463
b426ecc30319 Added some DB indexes to optimize queries
Marcin Kuzminski <marcin@python-works.com>
parents: 2462
diff changeset
449 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
450
20e307d5250f Added email-map for alternative email addresses for users
Marcin Kuzminski <marcin@python-works.com>
parents: 2296
diff changeset
451 @validates('_email')
20e307d5250f Added email-map for alternative email addresses for users
Marcin Kuzminski <marcin@python-works.com>
parents: 2296
diff changeset
452 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
453 # 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
454 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
455 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
456 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
457 return email
20e307d5250f Added email-map for alternative email addresses for users
Marcin Kuzminski <marcin@python-works.com>
parents: 2296
diff changeset
458
20e307d5250f Added email-map for alternative email addresses for users
Marcin Kuzminski <marcin@python-works.com>
parents: 2296
diff changeset
459 @hybrid_property
20e307d5250f Added email-map for alternative email addresses for users
Marcin Kuzminski <marcin@python-works.com>
parents: 2296
diff changeset
460 def email(self):
20e307d5250f Added email-map for alternative email addresses for users
Marcin Kuzminski <marcin@python-works.com>
parents: 2296
diff changeset
461 return self._email
20e307d5250f Added email-map for alternative email addresses for users
Marcin Kuzminski <marcin@python-works.com>
parents: 2296
diff changeset
462
20e307d5250f Added email-map for alternative email addresses for users
Marcin Kuzminski <marcin@python-works.com>
parents: 2296
diff changeset
463 @email.setter
20e307d5250f Added email-map for alternative email addresses for users
Marcin Kuzminski <marcin@python-works.com>
parents: 2296
diff changeset
464 def email(self, val):
20e307d5250f Added email-map for alternative email addresses for users
Marcin Kuzminski <marcin@python-works.com>
parents: 2296
diff changeset
465 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
466
20e307d5250f Added email-map for alternative email addresses for users
Marcin Kuzminski <marcin@python-works.com>
parents: 2296
diff changeset
467
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
468 class UserLog(Base, BaseModel):
49
3ada2f409c1c Added sqlalchemy support
Marcin Kuzminski <marcin@python-blog.com>
parents:
diff changeset
469 __tablename__ = 'user_logs'
2149
50aa7cb78cfe Mysql fixes
Marcin Kuzminski <marcin@python-works.com>
parents: 2147
diff changeset
470 __table_args__ = (
2356
2da7b5984ae5 typo fix + code garden
Marcin Kuzminski <marcin@python-works.com>
parents: 2352
diff changeset
471 {'extend_existing': True, 'mysql_engine': 'InnoDB',
2149
50aa7cb78cfe Mysql fixes
Marcin Kuzminski <marcin@python-works.com>
parents: 2147
diff changeset
472 'mysql_charset': 'utf8'},
50aa7cb78cfe Mysql fixes
Marcin Kuzminski <marcin@python-works.com>
parents: 2147
diff changeset
473 )
1594
9dae92a65e40 fixes #288
Marcin Kuzminski <marcin@python-works.com>
parents: 1593
diff changeset
474 user_log_id = Column("user_log_id", Integer(), nullable=False, unique=True, default=None, primary_key=True)
9dae92a65e40 fixes #288
Marcin Kuzminski <marcin@python-works.com>
parents: 1593
diff changeset
475 user_id = Column("user_id", Integer(), ForeignKey('users.user_id'), nullable=False, 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
476 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
477 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
478 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
479 action = Column("action", UnicodeText(1200000, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None)
1594
9dae92a65e40 fixes #288
Marcin Kuzminski <marcin@python-works.com>
parents: 1593
diff changeset
480 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
481
994
7f9d23f6a526 Added grouping by days in journal
Marcin Kuzminski <marcin@python-works.com>
parents: 991
diff changeset
482 @property
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
483 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
484 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
485
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
486 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
487 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
488
956
83d35d716a02 started working on issue #56
Marcin Kuzminski <marcin@python-works.com>
parents: 907
diff changeset
489
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
490 class UsersGroup(Base, BaseModel):
956
83d35d716a02 started working on issue #56
Marcin Kuzminski <marcin@python-works.com>
parents: 907
diff changeset
491 __tablename__ = 'users_groups'
2149
50aa7cb78cfe Mysql fixes
Marcin Kuzminski <marcin@python-works.com>
parents: 2147
diff changeset
492 __table_args__ = (
2356
2da7b5984ae5 typo fix + code garden
Marcin Kuzminski <marcin@python-works.com>
parents: 2352
diff changeset
493 {'extend_existing': True, 'mysql_engine': 'InnoDB',
2149
50aa7cb78cfe Mysql fixes
Marcin Kuzminski <marcin@python-works.com>
parents: 2147
diff changeset
494 'mysql_charset': 'utf8'},
50aa7cb78cfe Mysql fixes
Marcin Kuzminski <marcin@python-works.com>
parents: 2147
diff changeset
495 )
956
83d35d716a02 started working on issue #56
Marcin Kuzminski <marcin@python-works.com>
parents: 907
diff changeset
496
1594
9dae92a65e40 fixes #288
Marcin Kuzminski <marcin@python-works.com>
parents: 1593
diff changeset
497 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
498 users_group_name = Column("users_group_name", String(255, convert_unicode=False, assert_unicode=None), nullable=False, unique=True, default=None)
1594
9dae92a65e40 fixes #288
Marcin Kuzminski <marcin@python-works.com>
parents: 1593
diff changeset
499 users_group_active = Column("users_group_active", Boolean(), nullable=True, unique=None, default=None)
956
83d35d716a02 started working on issue #56
Marcin Kuzminski <marcin@python-works.com>
parents: 907
diff changeset
500
1594
9dae92a65e40 fixes #288
Marcin Kuzminski <marcin@python-works.com>
parents: 1593
diff changeset
501 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
502 users_group_to_perm = relationship('UsersGroupToPerm', cascade='all')
2149
50aa7cb78cfe Mysql fixes
Marcin Kuzminski <marcin@python-works.com>
parents: 2147
diff changeset
503 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
504
2156
a27e4d44237e Use __unicode__ instead of __repr__ in models.
Marcin Kuzminski <marcin@python-works.com>
parents: 2152
diff changeset
505 def __unicode__(self):
a27e4d44237e Use __unicode__ instead of __repr__ in models.
Marcin Kuzminski <marcin@python-works.com>
parents: 2152
diff changeset
506 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
507
aa7e45ad0cea Fixed permissions for users groups, group can have create repo permission now.
Marcin Kuzminski <marcin@python-works.com>
parents: 1266
diff changeset
508 @classmethod
1728
07e56179633e - fixes celery sqlalchemy session issues for async forking
Marcin Kuzminski <marcin@python-works.com>
parents: 1727
diff changeset
509 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
510 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
511 if case_insensitive:
1728
07e56179633e - fixes celery sqlalchemy session issues for async forking
Marcin Kuzminski <marcin@python-works.com>
parents: 1727
diff changeset
512 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
513 else:
1728
07e56179633e - fixes celery sqlalchemy session issues for async forking
Marcin Kuzminski <marcin@python-works.com>
parents: 1727
diff changeset
514 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
515 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
516 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
517 "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
518 "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
519 )
bf8ed0adbc66 fixes #371 fixed issues with beaker/sqlalchemy and non-ascii cache keys
Marcin Kuzminski <marcin@python-works.com>
parents: 2058
diff changeset
520 )
1728
07e56179633e - fixes celery sqlalchemy session issues for async forking
Marcin Kuzminski <marcin@python-works.com>
parents: 1727
diff changeset
521 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
522
1436
88d13c1c6a55 removed users_group controller in replace for model methods,
Marcin Kuzminski <marcin@python-works.com>
parents: 1435
diff changeset
523 @classmethod
1594
9dae92a65e40 fixes #288
Marcin Kuzminski <marcin@python-works.com>
parents: 1593
diff changeset
524 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
525 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
526 if cache:
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
527 users_group = users_group.options(FromCache("sql_cache_short",
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
528 "get_users_group_%s" % users_group_id))
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
529 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
530
2523
788ae4f7d8df added get_api_data into UsersGroup
Marcin Kuzminski <marcin@python-works.com>
parents: 2520
diff changeset
531 def get_api_data(self):
788ae4f7d8df added get_api_data into UsersGroup
Marcin Kuzminski <marcin@python-works.com>
parents: 2520
diff changeset
532 users_group = self
788ae4f7d8df added get_api_data into UsersGroup
Marcin Kuzminski <marcin@python-works.com>
parents: 2520
diff changeset
533
788ae4f7d8df added get_api_data into UsersGroup
Marcin Kuzminski <marcin@python-works.com>
parents: 2520
diff changeset
534 data = dict(
2531
d80a68e2ebcc return proper id from users_group
Marcin Kuzminski <marcin@python-works.com>
parents: 2523
diff changeset
535 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
536 group_name=users_group.users_group_name,
788ae4f7d8df added get_api_data into UsersGroup
Marcin Kuzminski <marcin@python-works.com>
parents: 2520
diff changeset
537 active=users_group.users_group_active,
788ae4f7d8df added get_api_data into UsersGroup
Marcin Kuzminski <marcin@python-works.com>
parents: 2520
diff changeset
538 )
788ae4f7d8df added get_api_data into UsersGroup
Marcin Kuzminski <marcin@python-works.com>
parents: 2520
diff changeset
539
788ae4f7d8df added get_api_data into UsersGroup
Marcin Kuzminski <marcin@python-works.com>
parents: 2520
diff changeset
540 return data
788ae4f7d8df added get_api_data into UsersGroup
Marcin Kuzminski <marcin@python-works.com>
parents: 2520
diff changeset
541
1800
6c86c987cf93 pep8ify
Marcin Kuzminski <marcin@python-works.com>
parents: 1758
diff changeset
542
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
543 class UsersGroupMember(Base, BaseModel):
956
83d35d716a02 started working on issue #56
Marcin Kuzminski <marcin@python-works.com>
parents: 907
diff changeset
544 __tablename__ = 'users_groups_members'
2149
50aa7cb78cfe Mysql fixes
Marcin Kuzminski <marcin@python-works.com>
parents: 2147
diff changeset
545 __table_args__ = (
2356
2da7b5984ae5 typo fix + code garden
Marcin Kuzminski <marcin@python-works.com>
parents: 2352
diff changeset
546 {'extend_existing': True, 'mysql_engine': 'InnoDB',
2149
50aa7cb78cfe Mysql fixes
Marcin Kuzminski <marcin@python-works.com>
parents: 2147
diff changeset
547 'mysql_charset': 'utf8'},
50aa7cb78cfe Mysql fixes
Marcin Kuzminski <marcin@python-works.com>
parents: 2147
diff changeset
548 )
956
83d35d716a02 started working on issue #56
Marcin Kuzminski <marcin@python-works.com>
parents: 907
diff changeset
549
1594
9dae92a65e40 fixes #288
Marcin Kuzminski <marcin@python-works.com>
parents: 1593
diff changeset
550 users_group_member_id = Column("users_group_member_id", Integer(), nullable=False, unique=True, default=None, primary_key=True)
9dae92a65e40 fixes #288
Marcin Kuzminski <marcin@python-works.com>
parents: 1593
diff changeset
551 users_group_id = Column("users_group_id", Integer(), ForeignKey('users_groups.users_group_id'), nullable=False, unique=None, default=None)
9dae92a65e40 fixes #288
Marcin Kuzminski <marcin@python-works.com>
parents: 1593
diff changeset
552 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
553
1594
9dae92a65e40 fixes #288
Marcin Kuzminski <marcin@python-works.com>
parents: 1593
diff changeset
554 user = relationship('User', lazy='joined')
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
555 users_group = relationship('UsersGroup')
972
2c8fd84935a4 #56 implemented users groups editing,
Marcin Kuzminski <marcin@python-works.com>
parents: 962
diff changeset
556
1594
9dae92a65e40 fixes #288
Marcin Kuzminski <marcin@python-works.com>
parents: 1593
diff changeset
557 def __init__(self, gr_id='', u_id=''):
972
2c8fd84935a4 #56 implemented users groups editing,
Marcin Kuzminski <marcin@python-works.com>
parents: 962
diff changeset
558 self.users_group_id = gr_id
2c8fd84935a4 #56 implemented users groups editing,
Marcin Kuzminski <marcin@python-works.com>
parents: 962
diff changeset
559 self.user_id = u_id
956
83d35d716a02 started working on issue #56
Marcin Kuzminski <marcin@python-works.com>
parents: 907
diff changeset
560
2013
8530c3cd9d04 fixed issue with hybrid property for ldap_active
Marcin Kuzminski <marcin@python-works.com>
parents: 2007
diff changeset
561
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
562 class Repository(Base, BaseModel):
234
a0116e944da1 changed naming convention for db modules.
Marcin Kuzminski <marcin@python-works.com>
parents: 232
diff changeset
563 __tablename__ = 'repositories'
1958
7e4b3d3a9c5c renamed repo groups table
Marcin Kuzminski <marcin@python-works.com>
parents: 1950
diff changeset
564 __table_args__ = (
1963
9bbde54232dc white space cleanup
Marcin Kuzminski <marcin@python-works.com>
parents: 1960
diff changeset
565 UniqueConstraint('repo_name'),
2356
2da7b5984ae5 typo fix + code garden
Marcin Kuzminski <marcin@python-works.com>
parents: 2352
diff changeset
566 {'extend_existing': True, 'mysql_engine': 'InnoDB',
2149
50aa7cb78cfe Mysql fixes
Marcin Kuzminski <marcin@python-works.com>
parents: 2147
diff changeset
567 'mysql_charset': 'utf8'},
1958
7e4b3d3a9c5c renamed repo groups table
Marcin Kuzminski <marcin@python-works.com>
parents: 1950
diff changeset
568 )
1081
70bf0be59653 fixed Session problems in model class functions
Marcin Kuzminski <marcin@python-works.com>
parents: 1065
diff changeset
569
1594
9dae92a65e40 fixes #288
Marcin Kuzminski <marcin@python-works.com>
parents: 1593
diff changeset
570 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
571 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
572 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
573 repo_type = Column("repo_type", String(255, convert_unicode=False, assert_unicode=None), nullable=False, unique=False, default=None)
1594
9dae92a65e40 fixes #288
Marcin Kuzminski <marcin@python-works.com>
parents: 1593
diff changeset
574 user_id = Column("user_id", Integer(), ForeignKey('users.user_id'), nullable=False, unique=False, default=None)
9dae92a65e40 fixes #288
Marcin Kuzminski <marcin@python-works.com>
parents: 1593
diff changeset
575 private = Column("private", Boolean(), nullable=True, unique=None, default=None)
9dae92a65e40 fixes #288
Marcin Kuzminski <marcin@python-works.com>
parents: 1593
diff changeset
576 enable_statistics = Column("statistics", Boolean(), nullable=True, unique=None, default=True)
9dae92a65e40 fixes #288
Marcin Kuzminski <marcin@python-works.com>
parents: 1593
diff changeset
577 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
578 description = Column("description", String(10000, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None)
1594
9dae92a65e40 fixes #288
Marcin Kuzminski <marcin@python-works.com>
parents: 1593
diff changeset
579 created_on = Column('created_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
580 landing_rev = Column("landing_revision", String(255, convert_unicode=False, assert_unicode=None), nullable=False, unique=False, default=None)
1301
7e75af301842 Added simple forks page, resolves issue #179
Marcin Kuzminski <marcin@python-works.com>
parents: 1292
diff changeset
581
1594
9dae92a65e40 fixes #288
Marcin Kuzminski <marcin@python-works.com>
parents: 1593
diff changeset
582 fork_id = Column("fork_id", Integer(), ForeignKey('repositories.repo_id'), nullable=True, unique=False, default=None)
9dae92a65e40 fixes #288
Marcin Kuzminski <marcin@python-works.com>
parents: 1593
diff changeset
583 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
584
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
585 user = relationship('User')
1594
9dae92a65e40 fixes #288
Marcin Kuzminski <marcin@python-works.com>
parents: 1593
diff changeset
586 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
587 group = relationship('RepoGroup')
2c0d35e336b5 refactoring of models names for repoGroup permissions
Marcin Kuzminski <marcin@python-works.com>
parents: 1607
diff changeset
588 repo_to_perm = relationship('UserRepoToPerm', cascade='all', order_by='UserRepoToPerm.repo_to_perm_id')
1594
9dae92a65e40 fixes #288
Marcin Kuzminski <marcin@python-works.com>
parents: 1593
diff changeset
589 users_group_to_perm = relationship('UsersGroupRepoToPerm', cascade='all')
9dae92a65e40 fixes #288
Marcin Kuzminski <marcin@python-works.com>
parents: 1593
diff changeset
590 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
591
2666
c51fb1da6df2 cascade fixes for comments/pull-requests/reviewers
Marcin Kuzminski <marcin@python-works.com>
parents: 2665
diff changeset
592 followers = relationship('UserFollowing',
c51fb1da6df2 cascade fixes for comments/pull-requests/reviewers
Marcin Kuzminski <marcin@python-works.com>
parents: 2665
diff changeset
593 primaryjoin='UserFollowing.follows_repo_id==Repository.repo_id',
c51fb1da6df2 cascade fixes for comments/pull-requests/reviewers
Marcin Kuzminski <marcin@python-works.com>
parents: 2665
diff changeset
594 cascade='all')
734
49eb69d78988 implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents: 713
diff changeset
595
1747
8804715404c9 implements #193 journal stores information about deleting of repos
Marcin Kuzminski <marcin@python-works.com>
parents: 1744
diff changeset
596 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
597 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
598
2666
c51fb1da6df2 cascade fixes for comments/pull-requests/reviewers
Marcin Kuzminski <marcin@python-works.com>
parents: 2665
diff changeset
599 pull_requests_org = relationship('PullRequest',
c51fb1da6df2 cascade fixes for comments/pull-requests/reviewers
Marcin Kuzminski <marcin@python-works.com>
parents: 2665
diff changeset
600 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
601 cascade="all, delete, delete-orphan")
c51fb1da6df2 cascade fixes for comments/pull-requests/reviewers
Marcin Kuzminski <marcin@python-works.com>
parents: 2665
diff changeset
602
c51fb1da6df2 cascade fixes for comments/pull-requests/reviewers
Marcin Kuzminski <marcin@python-works.com>
parents: 2665
diff changeset
603 pull_requests_other = relationship('PullRequest',
c51fb1da6df2 cascade fixes for comments/pull-requests/reviewers
Marcin Kuzminski <marcin@python-works.com>
parents: 2665
diff changeset
604 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
605 cascade="all, delete, delete-orphan")
c51fb1da6df2 cascade fixes for comments/pull-requests/reviewers
Marcin Kuzminski <marcin@python-works.com>
parents: 2665
diff changeset
606
2156
a27e4d44237e Use __unicode__ instead of __repr__ in models.
Marcin Kuzminski <marcin@python-works.com>
parents: 2152
diff changeset
607 def __unicode__(self):
2459
9492ab68331f Initial version of landing revisions ref #483
Marcin Kuzminski <marcin@python-works.com>
parents: 2407
diff changeset
608 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
609 self.repo_name)
878
859bc9e7a15d Extended repo2db mapper with group creation via directory structures
Marcin Kuzminski <marcin@python-works.com>
parents: 836
diff changeset
610
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
611 @classmethod
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
612 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
613 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
614
1554
e7c6341ad3cb fixes #245 Rescan of the repositories on Windows
Marcin Kuzminski <marcin@python-works.com>
parents: 1547
diff changeset
615 @classmethod
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
616 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
617 q = Session().query(cls).filter(cls.repo_name == repo_name)
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
618 q = q.options(joinedload(Repository.fork))\
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
619 .options(joinedload(Repository.user))\
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
620 .options(joinedload(Repository.group))
1749
8ecc6b8229a5 commit less models
Marcin Kuzminski <marcin@python-works.com>
parents: 1747
diff changeset
621 return q.scalar()
1301
7e75af301842 Added simple forks page, resolves issue #179
Marcin Kuzminski <marcin@python-works.com>
parents: 1292
diff changeset
622
7e75af301842 Added simple forks page, resolves issue #179
Marcin Kuzminski <marcin@python-works.com>
parents: 1292
diff changeset
623 @classmethod
2400
e87c6aa9c5e7 Add method for fetching repos by full path
Marcin Kuzminski <marcin@python-works.com>
parents: 2356
diff changeset
624 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
625 repo_name = repo_full_path.split(cls.base_path(), 1)[-1]
e87c6aa9c5e7 Add method for fetching repos by full path
Marcin Kuzminski <marcin@python-works.com>
parents: 2356
diff changeset
626 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
627
e87c6aa9c5e7 Add method for fetching repos by full path
Marcin Kuzminski <marcin@python-works.com>
parents: 2356
diff changeset
628 @classmethod
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
629 def get_repo_forks(cls, repo_id):
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
630 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
631
1508
4aba7be311e8 API added checks for a valid repository on pull command
Marcin Kuzminski <marcin@python-works.com>
parents: 1500
diff changeset
632 @classmethod
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
633 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
634 """
4aba7be311e8 API added checks for a valid repository on pull command
Marcin Kuzminski <marcin@python-works.com>
parents: 1500
diff changeset
635 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
636
1508
4aba7be311e8 API added checks for a valid repository on pull command
Marcin Kuzminski <marcin@python-works.com>
parents: 1500
diff changeset
637 :param cls:
4aba7be311e8 API added checks for a valid repository on pull command
Marcin Kuzminski <marcin@python-works.com>
parents: 1500
diff changeset
638 """
2520
a1e156503afe Fixed calls to Session in db model
Marcin Kuzminski <marcin@python-works.com>
parents: 2510
diff changeset
639 q = Session().query(RhodeCodeUi)\
1728
07e56179633e - fixes celery sqlalchemy session issues for async forking
Marcin Kuzminski <marcin@python-works.com>
parents: 1727
diff changeset
640 .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
641 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
642 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
643
1113
c1eda8ec4a46 added clone_uri,api_key into models. Fixed models for mysql compatibilty
Marcin Kuzminski <marcin@python-works.com>
parents: 1088
diff changeset
644 @property
2395
b262e349a7a5 created pull-request overview
Marcin Kuzminski <marcin@python-works.com>
parents: 2392
diff changeset
645 def forks(self):
b262e349a7a5 created pull-request overview
Marcin Kuzminski <marcin@python-works.com>
parents: 2392
diff changeset
646 """
b262e349a7a5 created pull-request overview
Marcin Kuzminski <marcin@python-works.com>
parents: 2392
diff changeset
647 Return forks of this repo
b262e349a7a5 created pull-request overview
Marcin Kuzminski <marcin@python-works.com>
parents: 2392
diff changeset
648 """
b262e349a7a5 created pull-request overview
Marcin Kuzminski <marcin@python-works.com>
parents: 2392
diff changeset
649 return Repository.get_repo_forks(self.repo_id)
b262e349a7a5 created pull-request overview
Marcin Kuzminski <marcin@python-works.com>
parents: 2392
diff changeset
650
b262e349a7a5 created pull-request overview
Marcin Kuzminski <marcin@python-works.com>
parents: 2392
diff changeset
651 @property
b262e349a7a5 created pull-request overview
Marcin Kuzminski <marcin@python-works.com>
parents: 2392
diff changeset
652 def parent(self):
b262e349a7a5 created pull-request overview
Marcin Kuzminski <marcin@python-works.com>
parents: 2392
diff changeset
653 """
b262e349a7a5 created pull-request overview
Marcin Kuzminski <marcin@python-works.com>
parents: 2392
diff changeset
654 Returns fork parent
b262e349a7a5 created pull-request overview
Marcin Kuzminski <marcin@python-works.com>
parents: 2392
diff changeset
655 """
b262e349a7a5 created pull-request overview
Marcin Kuzminski <marcin@python-works.com>
parents: 2392
diff changeset
656 return self.fork
b262e349a7a5 created pull-request overview
Marcin Kuzminski <marcin@python-works.com>
parents: 2392
diff changeset
657
b262e349a7a5 created pull-request overview
Marcin Kuzminski <marcin@python-works.com>
parents: 2392
diff changeset
658 @property
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
659 def just_name(self):
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
660 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
661
37a9421f32a0 Added handy methods to Repository model for fetching groups with parents
Marcin Kuzminski <marcin@python-works.com>
parents: 1113
diff changeset
662 @property
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
663 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
664 groups = []
37a9421f32a0 Added handy methods to Repository model for fetching groups with parents
Marcin Kuzminski <marcin@python-works.com>
parents: 1113
diff changeset
665 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
666 return groups
37a9421f32a0 Added handy methods to Repository model for fetching groups with parents
Marcin Kuzminski <marcin@python-works.com>
parents: 1113
diff changeset
667
37a9421f32a0 Added handy methods to Repository model for fetching groups with parents
Marcin Kuzminski <marcin@python-works.com>
parents: 1113
diff changeset
668 cur_gr = self.group
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
669 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
670 while 1:
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
671 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
672 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
673 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
674 break
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
675 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
676
37a9421f32a0 Added handy methods to Repository model for fetching groups with parents
Marcin Kuzminski <marcin@python-works.com>
parents: 1113
diff changeset
677 return groups
37a9421f32a0 Added handy methods to Repository model for fetching groups with parents
Marcin Kuzminski <marcin@python-works.com>
parents: 1113
diff changeset
678
37a9421f32a0 Added handy methods to Repository model for fetching groups with parents
Marcin Kuzminski <marcin@python-works.com>
parents: 1113
diff changeset
679 @property
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
680 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
681 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
682
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
683 @LazyProperty
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
684 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
685 """
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
686 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
687 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
688 """
2520
a1e156503afe Fixed calls to Session in db model
Marcin Kuzminski <marcin@python-works.com>
parents: 2510
diff changeset
689 q = Session().query(RhodeCodeUi).filter(RhodeCodeUi.ui_key ==
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
690 Repository.url_sep())
1727
8e9f51091229 fixed caching query on repos path
Marcin Kuzminski <marcin@python-works.com>
parents: 1723
diff changeset
691 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
692 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
693
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
694 @property
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
695 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
696 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
697 # 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
698 # 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
699 # into a valid system path
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
700 p += self.repo_name.split(Repository.url_sep())
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
701 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
702
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
703 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
704 """
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
705 returns new full repository name based on assigned group and new new
1591
0b63a0d2cede Merge with upstream
Nicolas VINOT <aeris@imirhil.fr>
parents: 1576 1590
diff changeset
706
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
707 :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
708 """
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
709 path_prefix = self.group.full_path_splitted if self.group else []
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
710 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
711
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
712 @property
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
713 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
714 """
9c0f5d558789 fixes #200, rewrote the whole caching mechanism to get rid of such problems. Now cached instances are attached
Marcin Kuzminski <marcin@python-works.com>
parents: 1360
diff changeset
715 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
716 """
9c0f5d558789 fixes #200, rewrote the whole caching mechanism to get rid of such problems. Now cached instances are attached
Marcin Kuzminski <marcin@python-works.com>
parents: 1360
diff changeset
717 from mercurial import ui
9c0f5d558789 fixes #200, rewrote the whole caching mechanism to get rid of such problems. Now cached instances are attached
Marcin Kuzminski <marcin@python-works.com>
parents: 1360
diff changeset
718 from mercurial import config
9c0f5d558789 fixes #200, rewrote the whole caching mechanism to get rid of such problems. Now cached instances are attached
Marcin Kuzminski <marcin@python-works.com>
parents: 1360
diff changeset
719 baseui = ui.ui()
9c0f5d558789 fixes #200, rewrote the whole caching mechanism to get rid of such problems. Now cached instances are attached
Marcin Kuzminski <marcin@python-works.com>
parents: 1360
diff changeset
720
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
721 #clean the baseui object
9c0f5d558789 fixes #200, rewrote the whole caching mechanism to get rid of such problems. Now cached instances are attached
Marcin Kuzminski <marcin@python-works.com>
parents: 1360
diff changeset
722 baseui._ocfg = config.config()
9c0f5d558789 fixes #200, rewrote the whole caching mechanism to get rid of such problems. Now cached instances are attached
Marcin Kuzminski <marcin@python-works.com>
parents: 1360
diff changeset
723 baseui._ucfg = config.config()
9c0f5d558789 fixes #200, rewrote the whole caching mechanism to get rid of such problems. Now cached instances are attached
Marcin Kuzminski <marcin@python-works.com>
parents: 1360
diff changeset
724 baseui._tcfg = config.config()
9c0f5d558789 fixes #200, rewrote the whole caching mechanism to get rid of such problems. Now cached instances are attached
Marcin Kuzminski <marcin@python-works.com>
parents: 1360
diff changeset
725
1584
3338a0994472 Improve API with user/group/repo CRUD methods
Nicolas VINOT <aeris@imirhil.fr>
parents: 1508
diff changeset
726 ret = RhodeCodeUi.query()\
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
727 .options(FromCache("sql_cache_short", "repository_repo_ui")).all()
1366
9c0f5d558789 fixes #200, rewrote the whole caching mechanism to get rid of such problems. Now cached instances are attached
Marcin Kuzminski <marcin@python-works.com>
parents: 1360
diff changeset
728
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
729 hg_ui = ret
9c0f5d558789 fixes #200, rewrote the whole caching mechanism to get rid of such problems. Now cached instances are attached
Marcin Kuzminski <marcin@python-works.com>
parents: 1360
diff changeset
730 for ui_ in hg_ui:
9c0f5d558789 fixes #200, rewrote the whole caching mechanism to get rid of such problems. Now cached instances are attached
Marcin Kuzminski <marcin@python-works.com>
parents: 1360
diff changeset
731 if ui_.ui_active:
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
732 log.debug('settings ui from db[%s]%s:%s', ui_.ui_section,
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
733 ui_.ui_key, ui_.ui_value)
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
734 baseui.setconfig(ui_.ui_section, ui_.ui_key, ui_.ui_value)
1366
9c0f5d558789 fixes #200, rewrote the whole caching mechanism to get rid of such problems. Now cached instances are attached
Marcin Kuzminski <marcin@python-works.com>
parents: 1360
diff changeset
735
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
736 return baseui
9c0f5d558789 fixes #200, rewrote the whole caching mechanism to get rid of such problems. Now cached instances are attached
Marcin Kuzminski <marcin@python-works.com>
parents: 1360
diff changeset
737
1508
4aba7be311e8 API added checks for a valid repository on pull command
Marcin Kuzminski <marcin@python-works.com>
parents: 1500
diff changeset
738 @classmethod
2520
a1e156503afe Fixed calls to Session in db model
Marcin Kuzminski <marcin@python-works.com>
parents: 2510
diff changeset
739 def inject_ui(cls, repo, extras={}):
a1e156503afe Fixed calls to Session in db model
Marcin Kuzminski <marcin@python-works.com>
parents: 2510
diff changeset
740 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
741 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
742 required = (MercurialRepository, GitRepository)
a1e156503afe Fixed calls to Session in db model
Marcin Kuzminski <marcin@python-works.com>
parents: 2510
diff changeset
743 if not isinstance(repo, required):
a1e156503afe Fixed calls to Session in db model
Marcin Kuzminski <marcin@python-works.com>
parents: 2510
diff changeset
744 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
745
a1e156503afe Fixed calls to Session in db model
Marcin Kuzminski <marcin@python-works.com>
parents: 2510
diff changeset
746 # 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
747 for k, v in extras.items():
a1e156503afe Fixed calls to Session in db model
Marcin Kuzminski <marcin@python-works.com>
parents: 2510
diff changeset
748 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
749
a1e156503afe Fixed calls to Session in db model
Marcin Kuzminski <marcin@python-works.com>
parents: 2510
diff changeset
750 @classmethod
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
751 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
752 """
4aba7be311e8 API added checks for a valid repository on pull command
Marcin Kuzminski <marcin@python-works.com>
parents: 1500
diff changeset
753 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
754
1819
9451a569aee5 sphinx doc cleanup
Marcin Kuzminski <marcin@python-works.com>
parents: 1818
diff changeset
755 :param cls:
9451a569aee5 sphinx doc cleanup
Marcin Kuzminski <marcin@python-works.com>
parents: 1818
diff changeset
756 :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
757 """
4aba7be311e8 API added checks for a valid repository on pull command
Marcin Kuzminski <marcin@python-works.com>
parents: 1500
diff changeset
758 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
759
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
760 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
761
2508
43cb5b6047fd Added functions for getting API data to repo and user models
Marcin Kuzminski <marcin@python-works.com>
parents: 2506
diff changeset
762 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
763 """
43cb5b6047fd Added functions for getting API data to repo and user models
Marcin Kuzminski <marcin@python-works.com>
parents: 2506
diff changeset
764 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
765
43cb5b6047fd Added functions for getting API data to repo and user models
Marcin Kuzminski <marcin@python-works.com>
parents: 2506
diff changeset
766 """
43cb5b6047fd Added functions for getting API data to repo and user models
Marcin Kuzminski <marcin@python-works.com>
parents: 2506
diff changeset
767 repo = self
43cb5b6047fd Added functions for getting API data to repo and user models
Marcin Kuzminski <marcin@python-works.com>
parents: 2506
diff changeset
768 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
769 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
770 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
771 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
772 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
773 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
774 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
775 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
776 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
777 owner=repo.user.username,
43cb5b6047fd Added functions for getting API data to repo and user models
Marcin Kuzminski <marcin@python-works.com>
parents: 2506
diff changeset
778 fork_of=repo.fork.repo_name if repo.fork else None
43cb5b6047fd Added functions for getting API data to repo and user models
Marcin Kuzminski <marcin@python-works.com>
parents: 2506
diff changeset
779 )
43cb5b6047fd Added functions for getting API data to repo and user models
Marcin Kuzminski <marcin@python-works.com>
parents: 2506
diff changeset
780
43cb5b6047fd Added functions for getting API data to repo and user models
Marcin Kuzminski <marcin@python-works.com>
parents: 2506
diff changeset
781 return data
43cb5b6047fd Added functions for getting API data to repo and user models
Marcin Kuzminski <marcin@python-works.com>
parents: 2506
diff changeset
782
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
783 #==========================================================================
1466
ad5a543a9b2f Code cleanup
Marcin Kuzminski <marcin@python-works.com>
parents: 1460
diff changeset
784 # SCM PROPERTIES
ad5a543a9b2f Code cleanup
Marcin Kuzminski <marcin@python-works.com>
parents: 1460
diff changeset
785 #==========================================================================
ad5a543a9b2f Code cleanup
Marcin Kuzminski <marcin@python-works.com>
parents: 1460
diff changeset
786
2251
986430cde505 fixed issue with getting README files from git repositories
Marcin Kuzminski <marcin@python-works.com>
parents: 2248
diff changeset
787 def get_changeset(self, rev=None):
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
788 return get_changeset_safe(self.scm_instance, rev)
1466
ad5a543a9b2f Code cleanup
Marcin Kuzminski <marcin@python-works.com>
parents: 1460
diff changeset
789
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
790 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
791 """
370ed7829168 Readme renderer now uses landing_rev parameter to render the readme based on
Marcin Kuzminski <marcin@python-works.com>
parents: 2588
diff changeset
792 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
793 """
370ed7829168 Readme renderer now uses landing_rev parameter to render the readme based on
Marcin Kuzminski <marcin@python-works.com>
parents: 2588
diff changeset
794 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
795 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
796
1466
ad5a543a9b2f Code cleanup
Marcin Kuzminski <marcin@python-works.com>
parents: 1460
diff changeset
797 @property
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
798 def tip(self):
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
799 return self.get_changeset('tip')
1466
ad5a543a9b2f Code cleanup
Marcin Kuzminski <marcin@python-works.com>
parents: 1460
diff changeset
800
ad5a543a9b2f Code cleanup
Marcin Kuzminski <marcin@python-works.com>
parents: 1460
diff changeset
801 @property
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
802 def author(self):
1466
ad5a543a9b2f Code cleanup
Marcin Kuzminski <marcin@python-works.com>
parents: 1460
diff changeset
803 return self.tip.author
ad5a543a9b2f Code cleanup
Marcin Kuzminski <marcin@python-works.com>
parents: 1460
diff changeset
804
ad5a543a9b2f Code cleanup
Marcin Kuzminski <marcin@python-works.com>
parents: 1460
diff changeset
805 @property
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
806 def last_change(self):
1466
ad5a543a9b2f Code cleanup
Marcin Kuzminski <marcin@python-works.com>
parents: 1460
diff changeset
807 return self.scm_instance.last_change
ad5a543a9b2f Code cleanup
Marcin Kuzminski <marcin@python-works.com>
parents: 1460
diff changeset
808
2520
a1e156503afe Fixed calls to Session in db model
Marcin Kuzminski <marcin@python-works.com>
parents: 2510
diff changeset
809 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
810 """
0614862a20ec Added number of comments in changelog for each changeset
Marcin Kuzminski <marcin@python-works.com>
parents: 1824
diff changeset
811 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
812
0614862a20ec Added number of comments in changelog for each changeset
Marcin Kuzminski <marcin@python-works.com>
parents: 1824
diff changeset
813 :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
814 """
0614862a20ec Added number of comments in changelog for each changeset
Marcin Kuzminski <marcin@python-works.com>
parents: 1824
diff changeset
815 cmts = ChangesetComment.query()\
0614862a20ec Added number of comments in changelog for each changeset
Marcin Kuzminski <marcin@python-works.com>
parents: 1824
diff changeset
816 .filter(ChangesetComment.repo == self)
0614862a20ec Added number of comments in changelog for each changeset
Marcin Kuzminski <marcin@python-works.com>
parents: 1824
diff changeset
817 if revisions:
0614862a20ec Added number of comments in changelog for each changeset
Marcin Kuzminski <marcin@python-works.com>
parents: 1824
diff changeset
818 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
819 grouped = defaultdict(list)
0614862a20ec Added number of comments in changelog for each changeset
Marcin Kuzminski <marcin@python-works.com>
parents: 1824
diff changeset
820 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
821 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
822 return grouped
0614862a20ec Added number of comments in changelog for each changeset
Marcin Kuzminski <marcin@python-works.com>
parents: 1824
diff changeset
823
2215
2c2bdaeca912 code-review initial
Marcin Kuzminski <marcin@python-works.com>
parents: 2161
diff changeset
824 def statuses(self, revisions=None):
2c2bdaeca912 code-review initial
Marcin Kuzminski <marcin@python-works.com>
parents: 2161
diff changeset
825 """
2c2bdaeca912 code-review initial
Marcin Kuzminski <marcin@python-works.com>
parents: 2161
diff changeset
826 Returns statuses for this repository
2217
76947224bf27 Implemented initial code-review status of changesets
Marcin Kuzminski <marcin@python-works.com>
parents: 2215
diff changeset
827
2215
2c2bdaeca912 code-review initial
Marcin Kuzminski <marcin@python-works.com>
parents: 2161
diff changeset
828 :param revisions: list of revisions to get statuses for
2c2bdaeca912 code-review initial
Marcin Kuzminski <marcin@python-works.com>
parents: 2161
diff changeset
829 :type revisions: list
2c2bdaeca912 code-review initial
Marcin Kuzminski <marcin@python-works.com>
parents: 2161
diff changeset
830 """
2c2bdaeca912 code-review initial
Marcin Kuzminski <marcin@python-works.com>
parents: 2161
diff changeset
831
2c2bdaeca912 code-review initial
Marcin Kuzminski <marcin@python-works.com>
parents: 2161
diff changeset
832 statuses = ChangesetStatus.query()\
2287
8447d35b674e Added simple versioning for changeset status
Marcin Kuzminski <marcin@python-works.com>
parents: 2286
diff changeset
833 .filter(ChangesetStatus.repo == self)\
8447d35b674e Added simple versioning for changeset status
Marcin Kuzminski <marcin@python-works.com>
parents: 2286
diff changeset
834 .filter(ChangesetStatus.version == 0)
2215
2c2bdaeca912 code-review initial
Marcin Kuzminski <marcin@python-works.com>
parents: 2161
diff changeset
835 if revisions:
2c2bdaeca912 code-review initial
Marcin Kuzminski <marcin@python-works.com>
parents: 2161
diff changeset
836 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
837 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
838
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
839 #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
840 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
841 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
842 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
843 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
844 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
845 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
846 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
847
2215
2c2bdaeca912 code-review initial
Marcin Kuzminski <marcin@python-works.com>
parents: 2161
diff changeset
848 for stat in statuses.all():
2443
fd0a822481ec - added commenting to pull requests
Marcin Kuzminski <marcin@python-works.com>
parents: 2440
diff changeset
849 pr_id = pr_repo = None
fd0a822481ec - added commenting to pull requests
Marcin Kuzminski <marcin@python-works.com>
parents: 2440
diff changeset
850 if stat.pull_request:
fd0a822481ec - added commenting to pull requests
Marcin Kuzminski <marcin@python-works.com>
parents: 2440
diff changeset
851 pr_id = stat.pull_request.pull_request_id
fd0a822481ec - added commenting to pull requests
Marcin Kuzminski <marcin@python-works.com>
parents: 2440
diff changeset
852 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
853 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
854 pr_id, pr_repo]
2215
2c2bdaeca912 code-review initial
Marcin Kuzminski <marcin@python-works.com>
parents: 2161
diff changeset
855 return grouped
2c2bdaeca912 code-review initial
Marcin Kuzminski <marcin@python-works.com>
parents: 2161
diff changeset
856
1466
ad5a543a9b2f Code cleanup
Marcin Kuzminski <marcin@python-works.com>
parents: 1460
diff changeset
857 #==========================================================================
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
858 # 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
859 #==========================================================================
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
860
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
861 @property
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
862 def invalidate(self):
1607
e886f91fcb71 Cached readme generation
Marcin Kuzminski <marcin@python-works.com>
parents: 1594
diff changeset
863 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
864
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
865 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
866 """
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
867 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
868 """
1607
e886f91fcb71 Cached readme generation
Marcin Kuzminski <marcin@python-works.com>
parents: 1594
diff changeset
869 CacheInvalidation.set_invalidate(self.repo_name)
1366
9c0f5d558789 fixes #200, rewrote the whole caching mechanism to get rid of such problems. Now cached instances are attached
Marcin Kuzminski <marcin@python-works.com>
parents: 1360
diff changeset
870
1466
ad5a543a9b2f Code cleanup
Marcin Kuzminski <marcin@python-works.com>
parents: 1460
diff changeset
871 @LazyProperty
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
872 def scm_instance(self):
1400
0d7b56b97953 Simplified last_login call on user, and changed login to use User model directly
Marcin Kuzminski <marcin@python-works.com>
parents: 1388
diff changeset
873 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
874
2352
90e06f53af8c Implemented cache-map on main page to save executing select
Marcin Kuzminski <marcin@python-works.com>
parents: 2339
diff changeset
875 def scm_instance_cached(self, cache_map=None):
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
876 @cache_region('long_term')
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
877 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
878 return self.__get_instance()
1607
e886f91fcb71 Cached readme generation
Marcin Kuzminski <marcin@python-works.com>
parents: 1594
diff changeset
879 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
880 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
881
90e06f53af8c Implemented cache-map on main page to save executing select
Marcin Kuzminski <marcin@python-works.com>
parents: 2339
diff changeset
882 if cache_map:
90e06f53af8c Implemented cache-map on main page to save executing select
Marcin Kuzminski <marcin@python-works.com>
parents: 2339
diff changeset
883 # 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
884 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
885 if invalidate_repo:
2356
2da7b5984ae5 typo fix + code garden
Marcin Kuzminski <marcin@python-works.com>
parents: 2352
diff changeset
886 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
887 else invalidate_repo)
90e06f53af8c Implemented cache-map on main page to save executing select
Marcin Kuzminski <marcin@python-works.com>
parents: 2339
diff changeset
888 else:
90e06f53af8c Implemented cache-map on main page to save executing select
Marcin Kuzminski <marcin@python-works.com>
parents: 2339
diff changeset
889 # get from invalidate
90e06f53af8c Implemented cache-map on main page to save executing select
Marcin Kuzminski <marcin@python-works.com>
parents: 2339
diff changeset
890 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
891
90e06f53af8c Implemented cache-map on main page to save executing select
Marcin Kuzminski <marcin@python-works.com>
parents: 2339
diff changeset
892 if invalidate_repo is not None:
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
893 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
894 # 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
895 CacheInvalidation.set_valid(invalidate_repo.cache_key)
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
896 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
897
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
898 def __get_instance(self):
1368
04b43168742d adde short cache for repo_path
Marcin Kuzminski <marcin@python-works.com>
parents: 1366
diff changeset
899 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
900 try:
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
901 alias = get_scm(repo_full_path)[0]
1976
Marcin Kuzminski <marcin@python-works.com>
parents: 1963
diff changeset
902 log.debug('Creating instance of %s repository' % alias)
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
903 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
904 except VCSError:
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
905 log.error(traceback.format_exc())
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
906 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
907 'filesystem run rescan repositories with '
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
908 '"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
909 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
910
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
911 if alias == 'hg':
2000
72c525a7e7ad added migrations from 1.2.X to 1.3
Marcin Kuzminski <marcin@python-works.com>
parents: 1990
diff changeset
912
1594
9dae92a65e40 fixes #288
Marcin Kuzminski <marcin@python-works.com>
parents: 1593
diff changeset
913 repo = backend(safe_str(repo_full_path), create=False,
9dae92a65e40 fixes #288
Marcin Kuzminski <marcin@python-works.com>
parents: 1593
diff changeset
914 baseui=self._ui)
1607
e886f91fcb71 Cached readme generation
Marcin Kuzminski <marcin@python-works.com>
parents: 1594
diff changeset
915 # 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
916 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
917 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
918 else:
1594
9dae92a65e40 fixes #288
Marcin Kuzminski <marcin@python-works.com>
parents: 1593
diff changeset
919 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
920
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
921 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
922
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
923
1633
2c0d35e336b5 refactoring of models names for repoGroup permissions
Marcin Kuzminski <marcin@python-works.com>
parents: 1607
diff changeset
924 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
925 __tablename__ = 'groups'
1958
7e4b3d3a9c5c renamed repo groups table
Marcin Kuzminski <marcin@python-works.com>
parents: 1950
diff changeset
926 __table_args__ = (
7e4b3d3a9c5c renamed repo groups table
Marcin Kuzminski <marcin@python-works.com>
parents: 1950
diff changeset
927 UniqueConstraint('group_name', 'group_parent_id'),
1963
9bbde54232dc white space cleanup
Marcin Kuzminski <marcin@python-works.com>
parents: 1960
diff changeset
928 CheckConstraint('group_id != group_parent_id'),
2356
2da7b5984ae5 typo fix + code garden
Marcin Kuzminski <marcin@python-works.com>
parents: 2352
diff changeset
929 {'extend_existing': True, 'mysql_engine': 'InnoDB',
2149
50aa7cb78cfe Mysql fixes
Marcin Kuzminski <marcin@python-works.com>
parents: 2147
diff changeset
930 'mysql_charset': 'utf8'},
1958
7e4b3d3a9c5c renamed repo groups table
Marcin Kuzminski <marcin@python-works.com>
parents: 1950
diff changeset
931 )
7e4b3d3a9c5c renamed repo groups table
Marcin Kuzminski <marcin@python-works.com>
parents: 1950
diff changeset
932 __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
933
1594
9dae92a65e40 fixes #288
Marcin Kuzminski <marcin@python-works.com>
parents: 1593
diff changeset
934 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
935 group_name = Column("group_name", String(255, convert_unicode=False, assert_unicode=None), nullable=False, unique=True, default=None)
1594
9dae92a65e40 fixes #288
Marcin Kuzminski <marcin@python-works.com>
parents: 1593
diff changeset
936 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
937 group_description = Column("group_description", String(10000, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None)
878
859bc9e7a15d Extended repo2db mapper with group creation via directory structures
Marcin Kuzminski <marcin@python-works.com>
parents: 836
diff changeset
938
1982
87f0800abc7b #227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents: 1976
diff changeset
939 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
940 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
941
1633
2c0d35e336b5 refactoring of models names for repoGroup permissions
Marcin Kuzminski <marcin@python-works.com>
parents: 1607
diff changeset
942 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
943
1594
9dae92a65e40 fixes #288
Marcin Kuzminski <marcin@python-works.com>
parents: 1593
diff changeset
944 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
945 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
946 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
947
2156
a27e4d44237e Use __unicode__ instead of __repr__ in models.
Marcin Kuzminski <marcin@python-works.com>
parents: 2152
diff changeset
948 def __unicode__(self):
a27e4d44237e Use __unicode__ instead of __repr__ in models.
Marcin Kuzminski <marcin@python-works.com>
parents: 2152
diff changeset
949 return u"<%s('%s:%s')>" % (self.__class__.__name__, self.group_id,
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
950 self.group_name)
631
05528ad948c4 Hacking for git support,and new faster repo scan
Marcin Kuzminski <marcin@python-works.com>
parents: 549
diff changeset
951
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
952 @classmethod
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
953 def groups_choices(cls):
1547
fbc762ae3496 unified generation of repo groups choices
Marcin Kuzminski <marcin@python-works.com>
parents: 1546
diff changeset
954 from webhelpers.html import literal as _literal
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
955 repo_groups = [('', '')]
1547
fbc762ae3496 unified generation of repo groups choices
Marcin Kuzminski <marcin@python-works.com>
parents: 1546
diff changeset
956 sep = ' &raquo; '
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
957 _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
958
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
959 repo_groups.extend([(x.group_id, _name(x.full_path_splitted))
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
960 for x in cls.query().all()])
1591
0b63a0d2cede Merge with upstream
Nicolas VINOT <aeris@imirhil.fr>
parents: 1576 1590
diff changeset
961
1594
9dae92a65e40 fixes #288
Marcin Kuzminski <marcin@python-works.com>
parents: 1593
diff changeset
962 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
963 return repo_groups
1591
0b63a0d2cede Merge with upstream
Nicolas VINOT <aeris@imirhil.fr>
parents: 1576 1590
diff changeset
964
1547
fbc762ae3496 unified generation of repo groups choices
Marcin Kuzminski <marcin@python-works.com>
parents: 1546
diff changeset
965 @classmethod
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
966 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
967 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
968
1538
27be8f94c207 implements #226 repo groups available by path
Marcin Kuzminski <marcin@python-works.com>
parents: 1530
diff changeset
969 @classmethod
1594
9dae92a65e40 fixes #288
Marcin Kuzminski <marcin@python-works.com>
parents: 1593
diff changeset
970 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
971 if case_insensitive:
3338a0994472 Improve API with user/group/repo CRUD methods
Nicolas VINOT <aeris@imirhil.fr>
parents: 1508
diff changeset
972 gr = cls.query()\
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
973 .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
974 else:
3338a0994472 Improve API with user/group/repo CRUD methods
Nicolas VINOT <aeris@imirhil.fr>
parents: 1508
diff changeset
975 gr = cls.query()\
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
976 .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
977 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
978 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
979 "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
980 "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
981 )
bf8ed0adbc66 fixes #371 fixed issues with beaker/sqlalchemy and non-ascii cache keys
Marcin Kuzminski <marcin@python-works.com>
parents: 2058
diff changeset
982 )
1584
3338a0994472 Improve API with user/group/repo CRUD methods
Nicolas VINOT <aeris@imirhil.fr>
parents: 1508
diff changeset
983 return gr.scalar()
1538
27be8f94c207 implements #226 repo groups available by path
Marcin Kuzminski <marcin@python-works.com>
parents: 1530
diff changeset
984
1159
187a924ed653 Changes for repo groups
Marcin Kuzminski <marcin@python-works.com>
parents: 1155
diff changeset
985 @property
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
986 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
987 parents_recursion_limit = 5
1159
187a924ed653 Changes for repo groups
Marcin Kuzminski <marcin@python-works.com>
parents: 1155
diff changeset
988 groups = []
187a924ed653 Changes for repo groups
Marcin Kuzminski <marcin@python-works.com>
parents: 1155
diff changeset
989 if self.parent_group is None:
187a924ed653 Changes for repo groups
Marcin Kuzminski <marcin@python-works.com>
parents: 1155
diff changeset
990 return groups
187a924ed653 Changes for repo groups
Marcin Kuzminski <marcin@python-works.com>
parents: 1155
diff changeset
991 cur_gr = self.parent_group
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
992 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
993 cnt = 0
1159
187a924ed653 Changes for repo groups
Marcin Kuzminski <marcin@python-works.com>
parents: 1155
diff changeset
994 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
995 cnt += 1
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
996 gr = getattr(cur_gr, 'parent_group', None)
1159
187a924ed653 Changes for repo groups
Marcin Kuzminski <marcin@python-works.com>
parents: 1155
diff changeset
997 cur_gr = cur_gr.parent_group
187a924ed653 Changes for repo groups
Marcin Kuzminski <marcin@python-works.com>
parents: 1155
diff changeset
998 if gr is None:
187a924ed653 Changes for repo groups
Marcin Kuzminski <marcin@python-works.com>
parents: 1155
diff changeset
999 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
1000 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
1001 # this will prevent accidental infinit loops
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
1002 log.error('group nested more than %s' %
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
1003 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
1004 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
1005
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
1006 groups.insert(0, gr)
1159
187a924ed653 Changes for repo groups
Marcin Kuzminski <marcin@python-works.com>
parents: 1155
diff changeset
1007 return groups
187a924ed653 Changes for repo groups
Marcin Kuzminski <marcin@python-works.com>
parents: 1155
diff changeset
1008
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
1009 @property
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
1010 def children(self):
1633
2c0d35e336b5 refactoring of models names for repoGroup permissions
Marcin Kuzminski <marcin@python-works.com>
parents: 1607
diff changeset
1011 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
1012
a7a772ea7b95 fixed saving settings on repositories inside groups, also fixes #187
Marcin Kuzminski <marcin@python-works.com>
parents: 1301
diff changeset
1013 @property
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
1014 def name(self):
1633
2c0d35e336b5 refactoring of models names for repoGroup permissions
Marcin Kuzminski <marcin@python-works.com>
parents: 1607
diff changeset
1015 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
1016
27be8f94c207 implements #226 repo groups available by path
Marcin Kuzminski <marcin@python-works.com>
parents: 1530
diff changeset
1017 @property
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
1018 def full_path(self):
1594
9dae92a65e40 fixes #288
Marcin Kuzminski <marcin@python-works.com>
parents: 1593
diff changeset
1019 return self.group_name
1538
27be8f94c207 implements #226 repo groups available by path
Marcin Kuzminski <marcin@python-works.com>
parents: 1530
diff changeset
1020
27be8f94c207 implements #226 repo groups available by path
Marcin Kuzminski <marcin@python-works.com>
parents: 1530
diff changeset
1021 @property
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
1022 def full_path_splitted(self):
1633
2c0d35e336b5 refactoring of models names for repoGroup permissions
Marcin Kuzminski <marcin@python-works.com>
parents: 1607
diff changeset
1023 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
1024
1193
523382549c45 Added repo group page showing what reposiories are inside a group
Marcin Kuzminski <marcin@python-works.com>
parents: 1159
diff changeset
1025 @property
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
1026 def repositories(self):
2079
477fe54b8af8 fixed sorting of repos in group
Marcin Kuzminski <marcin@python-works.com>
parents: 2063
diff changeset
1027 return Repository.query()\
477fe54b8af8 fixed sorting of repos in group
Marcin Kuzminski <marcin@python-works.com>
parents: 2063
diff changeset
1028 .filter(Repository.group == self)\
477fe54b8af8 fixed sorting of repos in group
Marcin Kuzminski <marcin@python-works.com>
parents: 2063
diff changeset
1029 .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
1030
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
1031 @property
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
1032 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
1033 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
1034
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
1035 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
1036 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
1037 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
1038 cnt += child.repositories.count()
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
1039 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
1040 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
1041
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
1042 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
1043
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
1044 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
1045 """
27be8f94c207 implements #226 repo groups available by path
Marcin Kuzminski <marcin@python-works.com>
parents: 1530
diff changeset
1046 returns new full group name based on parent and new name
1591
0b63a0d2cede Merge with upstream
Nicolas VINOT <aeris@imirhil.fr>
parents: 1576 1590
diff changeset
1047
1538
27be8f94c207 implements #226 repo groups available by path
Marcin Kuzminski <marcin@python-works.com>
parents: 1530
diff changeset
1048 :param group_name:
27be8f94c207 implements #226 repo groups available by path
Marcin Kuzminski <marcin@python-works.com>
parents: 1530
diff changeset
1049 """
1607
e886f91fcb71 Cached readme generation
Marcin Kuzminski <marcin@python-works.com>
parents: 1594
diff changeset
1050 path_prefix = (self.parent_group.full_path_splitted if
1594
9dae92a65e40 fixes #288
Marcin Kuzminski <marcin@python-works.com>
parents: 1593
diff changeset
1051 self.parent_group else [])
1633
2c0d35e336b5 refactoring of models names for repoGroup permissions
Marcin Kuzminski <marcin@python-works.com>
parents: 1607
diff changeset
1052 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
1053
27be8f94c207 implements #226 repo groups available by path
Marcin Kuzminski <marcin@python-works.com>
parents: 1530
diff changeset
1054
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
1055 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
1056 __tablename__ = 'permissions'
2149
50aa7cb78cfe Mysql fixes
Marcin Kuzminski <marcin@python-works.com>
parents: 2147
diff changeset
1057 __table_args__ = (
2463
b426ecc30319 Added some DB indexes to optimize queries
Marcin Kuzminski <marcin@python-works.com>
parents: 2462
diff changeset
1058 Index('p_perm_name_idx', 'permission_name'),
2356
2da7b5984ae5 typo fix + code garden
Marcin Kuzminski <marcin@python-works.com>
parents: 2352
diff changeset
1059 {'extend_existing': True, 'mysql_engine': 'InnoDB',
2149
50aa7cb78cfe Mysql fixes
Marcin Kuzminski <marcin@python-works.com>
parents: 2147
diff changeset
1060 'mysql_charset': 'utf8'},
50aa7cb78cfe Mysql fixes
Marcin Kuzminski <marcin@python-works.com>
parents: 2147
diff changeset
1061 )
2532
19de74e33fb0 Better descriptions of given permission overview in edit user view
Marcin Kuzminski <marcin@python-works.com>
parents: 2531
diff changeset
1062 PERMS = [
19de74e33fb0 Better descriptions of given permission overview in edit user view
Marcin Kuzminski <marcin@python-works.com>
parents: 2531
diff changeset
1063 ('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
1064 ('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
1065 ('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
1066 ('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
1067
19de74e33fb0 Better descriptions of given permission overview in edit user view
Marcin Kuzminski <marcin@python-works.com>
parents: 2531
diff changeset
1068 ('group.none', _('Repositories Group no access')),
19de74e33fb0 Better descriptions of given permission overview in edit user view
Marcin Kuzminski <marcin@python-works.com>
parents: 2531
diff changeset
1069 ('group.read', _('Repositories Group read access')),
19de74e33fb0 Better descriptions of given permission overview in edit user view
Marcin Kuzminski <marcin@python-works.com>
parents: 2531
diff changeset
1070 ('group.write', _('Repositories Group write access')),
19de74e33fb0 Better descriptions of given permission overview in edit user view
Marcin Kuzminski <marcin@python-works.com>
parents: 2531
diff changeset
1071 ('group.admin', _('Repositories Group admin access')),
19de74e33fb0 Better descriptions of given permission overview in edit user view
Marcin Kuzminski <marcin@python-works.com>
parents: 2531
diff changeset
1072
19de74e33fb0 Better descriptions of given permission overview in edit user view
Marcin Kuzminski <marcin@python-works.com>
parents: 2531
diff changeset
1073 ('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
1074 ('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
1075 ('hg.create.repository', _('Repository creation enabled')),
19de74e33fb0 Better descriptions of given permission overview in edit user view
Marcin Kuzminski <marcin@python-works.com>
parents: 2531
diff changeset
1076 ('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
1077 ('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
1078 'with manual activation')),
19de74e33fb0 Better descriptions of given permission overview in edit user view
Marcin Kuzminski <marcin@python-works.com>
parents: 2531
diff changeset
1079
19de74e33fb0 Better descriptions of given permission overview in edit user view
Marcin Kuzminski <marcin@python-works.com>
parents: 2531
diff changeset
1080 ('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
1081 'with auto activation')),
19de74e33fb0 Better descriptions of given permission overview in edit user view
Marcin Kuzminski <marcin@python-works.com>
parents: 2531
diff changeset
1082 ]
19de74e33fb0 Better descriptions of given permission overview in edit user view
Marcin Kuzminski <marcin@python-works.com>
parents: 2531
diff changeset
1083
1594
9dae92a65e40 fixes #288
Marcin Kuzminski <marcin@python-works.com>
parents: 1593
diff changeset
1084 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
1085 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
1086 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
1087
2156
a27e4d44237e Use __unicode__ instead of __repr__ in models.
Marcin Kuzminski <marcin@python-works.com>
parents: 2152
diff changeset
1088 def __unicode__(self):
a27e4d44237e Use __unicode__ instead of __repr__ in models.
Marcin Kuzminski <marcin@python-works.com>
parents: 2152
diff changeset
1089 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
1090 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
1091 )
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
1092
1266
a1bcfe58a1ab Fixed #161 form saves the create repository permission.
Marcin Kuzminski <marcin@python-works.com>
parents: 1206
diff changeset
1093 @classmethod
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
1094 def get_by_key(cls, key):
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
1095 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
1096
1728
07e56179633e - fixes celery sqlalchemy session issues for async forking
Marcin Kuzminski <marcin@python-works.com>
parents: 1727
diff changeset
1097 @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
1098 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
1099 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
1100 .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
1101 .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
1102 .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
1103
87f0800abc7b #227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents: 1976
diff changeset
1104 return q.all()
87f0800abc7b #227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents: 1976
diff changeset
1105
87f0800abc7b #227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents: 1976
diff changeset
1106 @classmethod
87f0800abc7b #227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents: 1976
diff changeset
1107 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
1108 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
1109 .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
1110 .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
1111 .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
1112
07e56179633e - fixes celery sqlalchemy session issues for async forking
Marcin Kuzminski <marcin@python-works.com>
parents: 1727
diff changeset
1113 return q.all()
07e56179633e - fixes celery sqlalchemy session issues for async forking
Marcin Kuzminski <marcin@python-works.com>
parents: 1727
diff changeset
1114
07e56179633e - fixes celery sqlalchemy session issues for async forking
Marcin Kuzminski <marcin@python-works.com>
parents: 1727
diff changeset
1115
1633
2c0d35e336b5 refactoring of models names for repoGroup permissions
Marcin Kuzminski <marcin@python-works.com>
parents: 1607
diff changeset
1116 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
1117 __tablename__ = 'repo_to_perm'
1958
7e4b3d3a9c5c renamed repo groups table
Marcin Kuzminski <marcin@python-works.com>
parents: 1950
diff changeset
1118 __table_args__ = (
2000
72c525a7e7ad added migrations from 1.2.X to 1.3
Marcin Kuzminski <marcin@python-works.com>
parents: 1990
diff changeset
1119 UniqueConstraint('user_id', 'repository_id', 'permission_id'),
2356
2da7b5984ae5 typo fix + code garden
Marcin Kuzminski <marcin@python-works.com>
parents: 2352
diff changeset
1120 {'extend_existing': True, 'mysql_engine': 'InnoDB',
2149
50aa7cb78cfe Mysql fixes
Marcin Kuzminski <marcin@python-works.com>
parents: 2147
diff changeset
1121 'mysql_charset': 'utf8'}
1958
7e4b3d3a9c5c renamed repo groups table
Marcin Kuzminski <marcin@python-works.com>
parents: 1950
diff changeset
1122 )
1594
9dae92a65e40 fixes #288
Marcin Kuzminski <marcin@python-works.com>
parents: 1593
diff changeset
1123 repo_to_perm_id = Column("repo_to_perm_id", Integer(), nullable=False, unique=True, default=None, primary_key=True)
9dae92a65e40 fixes #288
Marcin Kuzminski <marcin@python-works.com>
parents: 1593
diff changeset
1124 user_id = Column("user_id", Integer(), ForeignKey('users.user_id'), nullable=False, unique=None, default=None)
9dae92a65e40 fixes #288
Marcin Kuzminski <marcin@python-works.com>
parents: 1593
diff changeset
1125 permission_id = Column("permission_id", Integer(), ForeignKey('permissions.permission_id'), nullable=False, unique=None, default=None)
9dae92a65e40 fixes #288
Marcin Kuzminski <marcin@python-works.com>
parents: 1593
diff changeset
1126 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
1127
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
1128 user = relationship('User')
2000
72c525a7e7ad added migrations from 1.2.X to 1.3
Marcin Kuzminski <marcin@python-works.com>
parents: 1990
diff changeset
1129 repository = relationship('Repository')
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
1130 permission = relationship('Permission')
399
f5c1eec9f376 rename repo2perm into repo_to_perm
Marcin Kuzminski <marcin@python-works.com>
parents: 392
diff changeset
1131
1729
da8ee2ef7f6d implements #236 forking copy permission option
Marcin Kuzminski <marcin@python-works.com>
parents: 1728
diff changeset
1132 @classmethod
da8ee2ef7f6d implements #236 forking copy permission option
Marcin Kuzminski <marcin@python-works.com>
parents: 1728
diff changeset
1133 def create(cls, user, repository, permission):
da8ee2ef7f6d implements #236 forking copy permission option
Marcin Kuzminski <marcin@python-works.com>
parents: 1728
diff changeset
1134 n = cls()
da8ee2ef7f6d implements #236 forking copy permission option
Marcin Kuzminski <marcin@python-works.com>
parents: 1728
diff changeset
1135 n.user = user
da8ee2ef7f6d implements #236 forking copy permission option
Marcin Kuzminski <marcin@python-works.com>
parents: 1728
diff changeset
1136 n.repository = repository
da8ee2ef7f6d implements #236 forking copy permission option
Marcin Kuzminski <marcin@python-works.com>
parents: 1728
diff changeset
1137 n.permission = permission
2520
a1e156503afe Fixed calls to Session in db model
Marcin Kuzminski <marcin@python-works.com>
parents: 2510
diff changeset
1138 Session().add(n)
1729
da8ee2ef7f6d implements #236 forking copy permission option
Marcin Kuzminski <marcin@python-works.com>
parents: 1728
diff changeset
1139 return n
da8ee2ef7f6d implements #236 forking copy permission option
Marcin Kuzminski <marcin@python-works.com>
parents: 1728
diff changeset
1140
2156
a27e4d44237e Use __unicode__ instead of __repr__ in models.
Marcin Kuzminski <marcin@python-works.com>
parents: 2152
diff changeset
1141 def __unicode__(self):
a27e4d44237e Use __unicode__ instead of __repr__ in models.
Marcin Kuzminski <marcin@python-works.com>
parents: 2152
diff changeset
1142 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
1143
1800
6c86c987cf93 pep8ify
Marcin Kuzminski <marcin@python-works.com>
parents: 1758
diff changeset
1144
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
1145 class UserToPerm(Base, BaseModel):
399
f5c1eec9f376 rename repo2perm into repo_to_perm
Marcin Kuzminski <marcin@python-works.com>
parents: 392
diff changeset
1146 __tablename__ = 'user_to_perm'
1988
5eae67552695 db unique constraints fixes
Marcin Kuzminski <marcin@python-works.com>
parents: 1982
diff changeset
1147 __table_args__ = (
5eae67552695 db unique constraints fixes
Marcin Kuzminski <marcin@python-works.com>
parents: 1982
diff changeset
1148 UniqueConstraint('user_id', 'permission_id'),
2356
2da7b5984ae5 typo fix + code garden
Marcin Kuzminski <marcin@python-works.com>
parents: 2352
diff changeset
1149 {'extend_existing': True, 'mysql_engine': 'InnoDB',
2149
50aa7cb78cfe Mysql fixes
Marcin Kuzminski <marcin@python-works.com>
parents: 2147
diff changeset
1150 'mysql_charset': 'utf8'}
1988
5eae67552695 db unique constraints fixes
Marcin Kuzminski <marcin@python-works.com>
parents: 1982
diff changeset
1151 )
1594
9dae92a65e40 fixes #288
Marcin Kuzminski <marcin@python-works.com>
parents: 1593
diff changeset
1152 user_to_perm_id = Column("user_to_perm_id", Integer(), nullable=False, unique=True, default=None, primary_key=True)
9dae92a65e40 fixes #288
Marcin Kuzminski <marcin@python-works.com>
parents: 1593
diff changeset
1153 user_id = Column("user_id", Integer(), ForeignKey('users.user_id'), nullable=False, unique=None, default=None)
9dae92a65e40 fixes #288
Marcin Kuzminski <marcin@python-works.com>
parents: 1593
diff changeset
1154 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
1155
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
1156 user = relationship('User')
1728
07e56179633e - fixes celery sqlalchemy session issues for async forking
Marcin Kuzminski <marcin@python-works.com>
parents: 1727
diff changeset
1157 permission = relationship('Permission', lazy='joined')
399
f5c1eec9f376 rename repo2perm into repo_to_perm
Marcin Kuzminski <marcin@python-works.com>
parents: 392
diff changeset
1158
1014
6fdc3ff65fce #56 added assignments of users groups into repository
Marcin Kuzminski <marcin@python-works.com>
parents: 1000
diff changeset
1159
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
1160 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
1161 __tablename__ = 'users_group_repo_to_perm'
1958
7e4b3d3a9c5c renamed repo groups table
Marcin Kuzminski <marcin@python-works.com>
parents: 1950
diff changeset
1162 __table_args__ = (
2000
72c525a7e7ad added migrations from 1.2.X to 1.3
Marcin Kuzminski <marcin@python-works.com>
parents: 1990
diff changeset
1163 UniqueConstraint('repository_id', 'users_group_id', 'permission_id'),
2356
2da7b5984ae5 typo fix + code garden
Marcin Kuzminski <marcin@python-works.com>
parents: 2352
diff changeset
1164 {'extend_existing': True, 'mysql_engine': 'InnoDB',
2149
50aa7cb78cfe Mysql fixes
Marcin Kuzminski <marcin@python-works.com>
parents: 2147
diff changeset
1165 'mysql_charset': 'utf8'}
1958
7e4b3d3a9c5c renamed repo groups table
Marcin Kuzminski <marcin@python-works.com>
parents: 1950
diff changeset
1166 )
1594
9dae92a65e40 fixes #288
Marcin Kuzminski <marcin@python-works.com>
parents: 1593
diff changeset
1167 users_group_to_perm_id = Column("users_group_to_perm_id", Integer(), nullable=False, unique=True, default=None, primary_key=True)
9dae92a65e40 fixes #288
Marcin Kuzminski <marcin@python-works.com>
parents: 1593
diff changeset
1168 users_group_id = Column("users_group_id", Integer(), ForeignKey('users_groups.users_group_id'), nullable=False, unique=None, default=None)
9dae92a65e40 fixes #288
Marcin Kuzminski <marcin@python-works.com>
parents: 1593
diff changeset
1169 permission_id = Column("permission_id", Integer(), ForeignKey('permissions.permission_id'), nullable=False, unique=None, default=None)
9dae92a65e40 fixes #288
Marcin Kuzminski <marcin@python-works.com>
parents: 1593
diff changeset
1170 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
1171
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
1172 users_group = relationship('UsersGroup')
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
1173 permission = relationship('Permission')
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
1174 repository = relationship('Repository')
958
7d1483f3170b added user group to perm table
Marcin Kuzminski <marcin@python-works.com>
parents: 956
diff changeset
1175
1729
da8ee2ef7f6d implements #236 forking copy permission option
Marcin Kuzminski <marcin@python-works.com>
parents: 1728
diff changeset
1176 @classmethod
da8ee2ef7f6d implements #236 forking copy permission option
Marcin Kuzminski <marcin@python-works.com>
parents: 1728
diff changeset
1177 def create(cls, users_group, repository, permission):
da8ee2ef7f6d implements #236 forking copy permission option
Marcin Kuzminski <marcin@python-works.com>
parents: 1728
diff changeset
1178 n = cls()
da8ee2ef7f6d implements #236 forking copy permission option
Marcin Kuzminski <marcin@python-works.com>
parents: 1728
diff changeset
1179 n.users_group = users_group
da8ee2ef7f6d implements #236 forking copy permission option
Marcin Kuzminski <marcin@python-works.com>
parents: 1728
diff changeset
1180 n.repository = repository
da8ee2ef7f6d implements #236 forking copy permission option
Marcin Kuzminski <marcin@python-works.com>
parents: 1728
diff changeset
1181 n.permission = permission
2520
a1e156503afe Fixed calls to Session in db model
Marcin Kuzminski <marcin@python-works.com>
parents: 2510
diff changeset
1182 Session().add(n)
1729
da8ee2ef7f6d implements #236 forking copy permission option
Marcin Kuzminski <marcin@python-works.com>
parents: 1728
diff changeset
1183 return n
da8ee2ef7f6d implements #236 forking copy permission option
Marcin Kuzminski <marcin@python-works.com>
parents: 1728
diff changeset
1184
2156
a27e4d44237e Use __unicode__ instead of __repr__ in models.
Marcin Kuzminski <marcin@python-works.com>
parents: 2152
diff changeset
1185 def __unicode__(self):
a27e4d44237e Use __unicode__ instead of __repr__ in models.
Marcin Kuzminski <marcin@python-works.com>
parents: 2152
diff changeset
1186 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
1187
1800
6c86c987cf93 pep8ify
Marcin Kuzminski <marcin@python-works.com>
parents: 1758
diff changeset
1188
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
1189 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
1190 __tablename__ = 'users_group_to_perm'
1988
5eae67552695 db unique constraints fixes
Marcin Kuzminski <marcin@python-works.com>
parents: 1982
diff changeset
1191 __table_args__ = (
5eae67552695 db unique constraints fixes
Marcin Kuzminski <marcin@python-works.com>
parents: 1982
diff changeset
1192 UniqueConstraint('users_group_id', 'permission_id',),
2356
2da7b5984ae5 typo fix + code garden
Marcin Kuzminski <marcin@python-works.com>
parents: 2352
diff changeset
1193 {'extend_existing': True, 'mysql_engine': 'InnoDB',
2149
50aa7cb78cfe Mysql fixes
Marcin Kuzminski <marcin@python-works.com>
parents: 2147
diff changeset
1194 'mysql_charset': 'utf8'}
1988
5eae67552695 db unique constraints fixes
Marcin Kuzminski <marcin@python-works.com>
parents: 1982
diff changeset
1195 )
1594
9dae92a65e40 fixes #288
Marcin Kuzminski <marcin@python-works.com>
parents: 1593
diff changeset
1196 users_group_to_perm_id = Column("users_group_to_perm_id", Integer(), nullable=False, unique=True, default=None, primary_key=True)
9dae92a65e40 fixes #288
Marcin Kuzminski <marcin@python-works.com>
parents: 1593
diff changeset
1197 users_group_id = Column("users_group_id", Integer(), ForeignKey('users_groups.users_group_id'), nullable=False, unique=None, default=None)
9dae92a65e40 fixes #288
Marcin Kuzminski <marcin@python-works.com>
parents: 1593
diff changeset
1198 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
1199
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
1200 users_group = relationship('UsersGroup')
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
1201 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
1202
aa7e45ad0cea Fixed permissions for users groups, group can have create repo permission now.
Marcin Kuzminski <marcin@python-works.com>
parents: 1266
diff changeset
1203
1633
2c0d35e336b5 refactoring of models names for repoGroup permissions
Marcin Kuzminski <marcin@python-works.com>
parents: 1607
diff changeset
1204 class UserRepoGroupToPerm(Base, BaseModel):
1958
7e4b3d3a9c5c renamed repo groups table
Marcin Kuzminski <marcin@python-works.com>
parents: 1950
diff changeset
1205 __tablename__ = 'user_repo_group_to_perm'
7e4b3d3a9c5c renamed repo groups table
Marcin Kuzminski <marcin@python-works.com>
parents: 1950
diff changeset
1206 __table_args__ = (
2000
72c525a7e7ad added migrations from 1.2.X to 1.3
Marcin Kuzminski <marcin@python-works.com>
parents: 1990
diff changeset
1207 UniqueConstraint('user_id', 'group_id', 'permission_id'),
2356
2da7b5984ae5 typo fix + code garden
Marcin Kuzminski <marcin@python-works.com>
parents: 2352
diff changeset
1208 {'extend_existing': True, 'mysql_engine': 'InnoDB',
2149
50aa7cb78cfe Mysql fixes
Marcin Kuzminski <marcin@python-works.com>
parents: 2147
diff changeset
1209 'mysql_charset': 'utf8'}
1958
7e4b3d3a9c5c renamed repo groups table
Marcin Kuzminski <marcin@python-works.com>
parents: 1950
diff changeset
1210 )
879
b19341623d48 added group to perm mapping table
Marcin Kuzminski <marcin@python-works.com>
parents: 878
diff changeset
1211
1594
9dae92a65e40 fixes #288
Marcin Kuzminski <marcin@python-works.com>
parents: 1593
diff changeset
1212 group_to_perm_id = Column("group_to_perm_id", Integer(), nullable=False, unique=True, default=None, primary_key=True)
9dae92a65e40 fixes #288
Marcin Kuzminski <marcin@python-works.com>
parents: 1593
diff changeset
1213 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
1214 group_id = Column("group_id", Integer(), ForeignKey('groups.group_id'), nullable=False, unique=None, default=None)
1594
9dae92a65e40 fixes #288
Marcin Kuzminski <marcin@python-works.com>
parents: 1593
diff changeset
1215 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
1216
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
1217 user = relationship('User')
2000
72c525a7e7ad added migrations from 1.2.X to 1.3
Marcin Kuzminski <marcin@python-works.com>
parents: 1990
diff changeset
1218 group = relationship('RepoGroup')
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
1219 permission = relationship('Permission')
1633
2c0d35e336b5 refactoring of models names for repoGroup permissions
Marcin Kuzminski <marcin@python-works.com>
parents: 1607
diff changeset
1220
1800
6c86c987cf93 pep8ify
Marcin Kuzminski <marcin@python-works.com>
parents: 1758
diff changeset
1221
1633
2c0d35e336b5 refactoring of models names for repoGroup permissions
Marcin Kuzminski <marcin@python-works.com>
parents: 1607
diff changeset
1222 class UsersGroupRepoGroupToPerm(Base, BaseModel):
2c0d35e336b5 refactoring of models names for repoGroup permissions
Marcin Kuzminski <marcin@python-works.com>
parents: 1607
diff changeset
1223 __tablename__ = 'users_group_repo_group_to_perm'
1958
7e4b3d3a9c5c renamed repo groups table
Marcin Kuzminski <marcin@python-works.com>
parents: 1950
diff changeset
1224 __table_args__ = (
1988
5eae67552695 db unique constraints fixes
Marcin Kuzminski <marcin@python-works.com>
parents: 1982
diff changeset
1225 UniqueConstraint('users_group_id', 'group_id'),
2356
2da7b5984ae5 typo fix + code garden
Marcin Kuzminski <marcin@python-works.com>
parents: 2352
diff changeset
1226 {'extend_existing': True, 'mysql_engine': 'InnoDB',
2149
50aa7cb78cfe Mysql fixes
Marcin Kuzminski <marcin@python-works.com>
parents: 2147
diff changeset
1227 'mysql_charset': 'utf8'}
1958
7e4b3d3a9c5c renamed repo groups table
Marcin Kuzminski <marcin@python-works.com>
parents: 1950
diff changeset
1228 )
1633
2c0d35e336b5 refactoring of models names for repoGroup permissions
Marcin Kuzminski <marcin@python-works.com>
parents: 1607
diff changeset
1229
2c0d35e336b5 refactoring of models names for repoGroup permissions
Marcin Kuzminski <marcin@python-works.com>
parents: 1607
diff changeset
1230 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
1231 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
1232 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
1233 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
1234
2c0d35e336b5 refactoring of models names for repoGroup permissions
Marcin Kuzminski <marcin@python-works.com>
parents: 1607
diff changeset
1235 users_group = relationship('UsersGroup')
2c0d35e336b5 refactoring of models names for repoGroup permissions
Marcin Kuzminski <marcin@python-works.com>
parents: 1607
diff changeset
1236 permission = relationship('Permission')
2c0d35e336b5 refactoring of models names for repoGroup permissions
Marcin Kuzminski <marcin@python-works.com>
parents: 1607
diff changeset
1237 group = relationship('RepoGroup')
879
b19341623d48 added group to perm mapping table
Marcin Kuzminski <marcin@python-works.com>
parents: 878
diff changeset
1238
1800
6c86c987cf93 pep8ify
Marcin Kuzminski <marcin@python-works.com>
parents: 1758
diff changeset
1239
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
1240 class Statistics(Base, BaseModel):
493
2256c78afe53 implemented basic autoupdating statistics fetched from database
Marcin Kuzminski <marcin@python-works.com>
parents: 473
diff changeset
1241 __tablename__ = 'statistics'
2149
50aa7cb78cfe Mysql fixes
Marcin Kuzminski <marcin@python-works.com>
parents: 2147
diff changeset
1242 __table_args__ = (
2150
a8c9c0094ddf White space cleanup
Marcin Kuzminski <marcin@python-works.com>
parents: 2149
diff changeset
1243 UniqueConstraint('repository_id'),
2356
2da7b5984ae5 typo fix + code garden
Marcin Kuzminski <marcin@python-works.com>
parents: 2352
diff changeset
1244 {'extend_existing': True, 'mysql_engine': 'InnoDB',
2149
50aa7cb78cfe Mysql fixes
Marcin Kuzminski <marcin@python-works.com>
parents: 2147
diff changeset
1245 'mysql_charset': 'utf8'}
50aa7cb78cfe Mysql fixes
Marcin Kuzminski <marcin@python-works.com>
parents: 2147
diff changeset
1246 )
1594
9dae92a65e40 fixes #288
Marcin Kuzminski <marcin@python-works.com>
parents: 1593
diff changeset
1247 stat_id = Column("stat_id", Integer(), nullable=False, unique=True, default=None, primary_key=True)
9dae92a65e40 fixes #288
Marcin Kuzminski <marcin@python-works.com>
parents: 1593
diff changeset
1248 repository_id = Column("repository_id", Integer(), ForeignKey('repositories.repo_id'), nullable=False, unique=True, default=None)
9dae92a65e40 fixes #288
Marcin Kuzminski <marcin@python-works.com>
parents: 1593
diff changeset
1249 stat_on_revision = Column("stat_on_revision", Integer(), nullable=False)
9dae92a65e40 fixes #288
Marcin Kuzminski <marcin@python-works.com>
parents: 1593
diff changeset
1250 commit_activity = Column("commit_activity", LargeBinary(1000000), nullable=False)#JSON data
9dae92a65e40 fixes #288
Marcin Kuzminski <marcin@python-works.com>
parents: 1593
diff changeset
1251 commit_activity_combined = Column("commit_activity_combined", LargeBinary(), nullable=False)#JSON data
9dae92a65e40 fixes #288
Marcin Kuzminski <marcin@python-works.com>
parents: 1593
diff changeset
1252 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
1253
1594
9dae92a65e40 fixes #288
Marcin Kuzminski <marcin@python-works.com>
parents: 1593
diff changeset
1254 repository = relationship('Repository', single_parent=True)
399
f5c1eec9f376 rename repo2perm into repo_to_perm
Marcin Kuzminski <marcin@python-works.com>
parents: 392
diff changeset
1255
1800
6c86c987cf93 pep8ify
Marcin Kuzminski <marcin@python-works.com>
parents: 1758
diff changeset
1256
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
1257 class UserFollowing(Base, BaseModel):
734
49eb69d78988 implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents: 713
diff changeset
1258 __tablename__ = 'user_followings'
1958
7e4b3d3a9c5c renamed repo groups table
Marcin Kuzminski <marcin@python-works.com>
parents: 1950
diff changeset
1259 __table_args__ = (
7e4b3d3a9c5c renamed repo groups table
Marcin Kuzminski <marcin@python-works.com>
parents: 1950
diff changeset
1260 UniqueConstraint('user_id', 'follows_repository_id'),
7e4b3d3a9c5c renamed repo groups table
Marcin Kuzminski <marcin@python-works.com>
parents: 1950
diff changeset
1261 UniqueConstraint('user_id', 'follows_user_id'),
2356
2da7b5984ae5 typo fix + code garden
Marcin Kuzminski <marcin@python-works.com>
parents: 2352
diff changeset
1262 {'extend_existing': True, 'mysql_engine': 'InnoDB',
2149
50aa7cb78cfe Mysql fixes
Marcin Kuzminski <marcin@python-works.com>
parents: 2147
diff changeset
1263 'mysql_charset': 'utf8'}
1958
7e4b3d3a9c5c renamed repo groups table
Marcin Kuzminski <marcin@python-works.com>
parents: 1950
diff changeset
1264 )
734
49eb69d78988 implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents: 713
diff changeset
1265
1594
9dae92a65e40 fixes #288
Marcin Kuzminski <marcin@python-works.com>
parents: 1593
diff changeset
1266 user_following_id = Column("user_following_id", Integer(), nullable=False, unique=True, default=None, primary_key=True)
9dae92a65e40 fixes #288
Marcin Kuzminski <marcin@python-works.com>
parents: 1593
diff changeset
1267 user_id = Column("user_id", Integer(), ForeignKey('users.user_id'), nullable=False, unique=None, default=None)
9dae92a65e40 fixes #288
Marcin Kuzminski <marcin@python-works.com>
parents: 1593
diff changeset
1268 follows_repo_id = Column("follows_repository_id", Integer(), ForeignKey('repositories.repo_id'), nullable=True, unique=None, default=None)
9dae92a65e40 fixes #288
Marcin Kuzminski <marcin@python-works.com>
parents: 1593
diff changeset
1269 follows_user_id = Column("follows_user_id", Integer(), ForeignKey('users.user_id'), nullable=True, unique=None, default=None)
9dae92a65e40 fixes #288
Marcin Kuzminski <marcin@python-works.com>
parents: 1593
diff changeset
1270 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
1271
1594
9dae92a65e40 fixes #288
Marcin Kuzminski <marcin@python-works.com>
parents: 1593
diff changeset
1272 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
1273
1594
9dae92a65e40 fixes #288
Marcin Kuzminski <marcin@python-works.com>
parents: 1593
diff changeset
1274 follows_user = relationship('User', primaryjoin='User.user_id==UserFollowing.follows_user_id')
9dae92a65e40 fixes #288
Marcin Kuzminski <marcin@python-works.com>
parents: 1593
diff changeset
1275 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
1276
1279
cb216757a62d #179 Added followers page
Marcin Kuzminski <marcin@python-works.com>
parents: 1271
diff changeset
1277 @classmethod
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
1278 def get_repo_followers(cls, repo_id):
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
1279 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
1280
1800
6c86c987cf93 pep8ify
Marcin Kuzminski <marcin@python-works.com>
parents: 1758
diff changeset
1281
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
1282 class CacheInvalidation(Base, BaseModel):
670
e7c670cc03cb Adde table for cache invalidation
Marcin Kuzminski <marcin@python-works.com>
parents: 667
diff changeset
1283 __tablename__ = 'cache_invalidation'
2149
50aa7cb78cfe Mysql fixes
Marcin Kuzminski <marcin@python-works.com>
parents: 2147
diff changeset
1284 __table_args__ = (
50aa7cb78cfe Mysql fixes
Marcin Kuzminski <marcin@python-works.com>
parents: 2147
diff changeset
1285 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
1286 Index('key_idx', 'cache_key'),
2356
2da7b5984ae5 typo fix + code garden
Marcin Kuzminski <marcin@python-works.com>
parents: 2352
diff changeset
1287 {'extend_existing': True, 'mysql_engine': 'InnoDB',
2149
50aa7cb78cfe Mysql fixes
Marcin Kuzminski <marcin@python-works.com>
parents: 2147
diff changeset
1288 'mysql_charset': 'utf8'},
50aa7cb78cfe Mysql fixes
Marcin Kuzminski <marcin@python-works.com>
parents: 2147
diff changeset
1289 )
1594
9dae92a65e40 fixes #288
Marcin Kuzminski <marcin@python-works.com>
parents: 1593
diff changeset
1290 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
1291 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
1292 cache_args = Column("cache_args", String(255, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None)
1594
9dae92a65e40 fixes #288
Marcin Kuzminski <marcin@python-works.com>
parents: 1593
diff changeset
1293 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
1294
1594
9dae92a65e40 fixes #288
Marcin Kuzminski <marcin@python-works.com>
parents: 1593
diff changeset
1295 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
1296 self.cache_key = cache_key
cb0d9ce6ac5c #50 on point cache invalidation changes.
Marcin Kuzminski <marcin@python-works.com>
parents: 670
diff changeset
1297 self.cache_args = cache_args
cb0d9ce6ac5c #50 on point cache invalidation changes.
Marcin Kuzminski <marcin@python-works.com>
parents: 670
diff changeset
1298 self.cache_active = False
cb0d9ce6ac5c #50 on point cache invalidation changes.
Marcin Kuzminski <marcin@python-works.com>
parents: 670
diff changeset
1299
2156
a27e4d44237e Use __unicode__ instead of __repr__ in models.
Marcin Kuzminski <marcin@python-works.com>
parents: 2152
diff changeset
1300 def __unicode__(self):
a27e4d44237e Use __unicode__ instead of __repr__ in models.
Marcin Kuzminski <marcin@python-works.com>
parents: 2152
diff changeset
1301 return u"<%s('%s:%s')>" % (self.__class__.__name__,
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
1302 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
1303
2147
d25bd432bc3e - #347 when running multiple RhodeCode instances, properly invalidates cache
Marcin Kuzminski <marcin@python-works.com>
parents: 2109
diff changeset
1304 @classmethod
d25bd432bc3e - #347 when running multiple RhodeCode instances, properly invalidates cache
Marcin Kuzminski <marcin@python-works.com>
parents: 2109
diff changeset
1305 def clear_cache(cls):
d25bd432bc3e - #347 when running multiple RhodeCode instances, properly invalidates cache
Marcin Kuzminski <marcin@python-works.com>
parents: 2109
diff changeset
1306 cls.query().delete()
834
8924ed0e4f36 added current db version into rhodecode,
Marcin Kuzminski <marcin@python-works.com>
parents: 832
diff changeset
1307
1607
e886f91fcb71 Cached readme generation
Marcin Kuzminski <marcin@python-works.com>
parents: 1594
diff changeset
1308 @classmethod
2013
8530c3cd9d04 fixed issue with hybrid property for ldap_active
Marcin Kuzminski <marcin@python-works.com>
parents: 2007
diff changeset
1309 def _get_key(cls, key):
8530c3cd9d04 fixed issue with hybrid property for ldap_active
Marcin Kuzminski <marcin@python-works.com>
parents: 2007
diff changeset
1310 """
2147
d25bd432bc3e - #347 when running multiple RhodeCode instances, properly invalidates cache
Marcin Kuzminski <marcin@python-works.com>
parents: 2109
diff changeset
1311 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
1312
8530c3cd9d04 fixed issue with hybrid property for ldap_active
Marcin Kuzminski <marcin@python-works.com>
parents: 2007
diff changeset
1313 :param key:
8530c3cd9d04 fixed issue with hybrid property for ldap_active
Marcin Kuzminski <marcin@python-works.com>
parents: 2007
diff changeset
1314 """
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
1315 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
1316 prefix = ''
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
1317 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
1318 if iid:
2058
fb51a6fc10ae updated CONTRIBUTORS
Marcin Kuzminski <marcin@python-works.com>
parents: 2016
diff changeset
1319 prefix = iid
2147
d25bd432bc3e - #347 when running multiple RhodeCode instances, properly invalidates cache
Marcin Kuzminski <marcin@python-works.com>
parents: 2109
diff changeset
1320 return "%s%s" % (prefix, key), prefix, key.rstrip('_README')
2013
8530c3cd9d04 fixed issue with hybrid property for ldap_active
Marcin Kuzminski <marcin@python-works.com>
parents: 2007
diff changeset
1321
8530c3cd9d04 fixed issue with hybrid property for ldap_active
Marcin Kuzminski <marcin@python-works.com>
parents: 2007
diff changeset
1322 @classmethod
8530c3cd9d04 fixed issue with hybrid property for ldap_active
Marcin Kuzminski <marcin@python-works.com>
parents: 2007
diff changeset
1323 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
1324 return cls.query().filter(cls.cache_key == key).scalar()
2149
50aa7cb78cfe Mysql fixes
Marcin Kuzminski <marcin@python-works.com>
parents: 2147
diff changeset
1325
2147
d25bd432bc3e - #347 when running multiple RhodeCode instances, properly invalidates cache
Marcin Kuzminski <marcin@python-works.com>
parents: 2109
diff changeset
1326 @classmethod
d25bd432bc3e - #347 when running multiple RhodeCode instances, properly invalidates cache
Marcin Kuzminski <marcin@python-works.com>
parents: 2109
diff changeset
1327 def _get_or_create_key(cls, key, prefix, org_key):
2520
a1e156503afe Fixed calls to Session in db model
Marcin Kuzminski <marcin@python-works.com>
parents: 2510
diff changeset
1328 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
1329 if not inv_obj:
d25bd432bc3e - #347 when running multiple RhodeCode instances, properly invalidates cache
Marcin Kuzminski <marcin@python-works.com>
parents: 2109
diff changeset
1330 try:
d25bd432bc3e - #347 when running multiple RhodeCode instances, properly invalidates cache
Marcin Kuzminski <marcin@python-works.com>
parents: 2109
diff changeset
1331 inv_obj = CacheInvalidation(key, org_key)
2520
a1e156503afe Fixed calls to Session in db model
Marcin Kuzminski <marcin@python-works.com>
parents: 2510
diff changeset
1332 Session().add(inv_obj)
a1e156503afe Fixed calls to Session in db model
Marcin Kuzminski <marcin@python-works.com>
parents: 2510
diff changeset
1333 Session().commit()
2147
d25bd432bc3e - #347 when running multiple RhodeCode instances, properly invalidates cache
Marcin Kuzminski <marcin@python-works.com>
parents: 2109
diff changeset
1334 except Exception:
d25bd432bc3e - #347 when running multiple RhodeCode instances, properly invalidates cache
Marcin Kuzminski <marcin@python-works.com>
parents: 2109
diff changeset
1335 log.error(traceback.format_exc())
2520
a1e156503afe Fixed calls to Session in db model
Marcin Kuzminski <marcin@python-works.com>
parents: 2510
diff changeset
1336 Session().rollback()
2147
d25bd432bc3e - #347 when running multiple RhodeCode instances, properly invalidates cache
Marcin Kuzminski <marcin@python-works.com>
parents: 2109
diff changeset
1337 return inv_obj
2149
50aa7cb78cfe Mysql fixes
Marcin Kuzminski <marcin@python-works.com>
parents: 2147
diff changeset
1338
2013
8530c3cd9d04 fixed issue with hybrid property for ldap_active
Marcin Kuzminski <marcin@python-works.com>
parents: 2007
diff changeset
1339 @classmethod
1607
e886f91fcb71 Cached readme generation
Marcin Kuzminski <marcin@python-works.com>
parents: 1594
diff changeset
1340 def invalidate(cls, key):
e886f91fcb71 Cached readme generation
Marcin Kuzminski <marcin@python-works.com>
parents: 1594
diff changeset
1341 """
e886f91fcb71 Cached readme generation
Marcin Kuzminski <marcin@python-works.com>
parents: 1594
diff changeset
1342 Returns Invalidation object if this given key should be invalidated
e886f91fcb71 Cached readme generation
Marcin Kuzminski <marcin@python-works.com>
parents: 1594
diff changeset
1343 None otherwise. `cache_active = False` means that this cache
e886f91fcb71 Cached readme generation
Marcin Kuzminski <marcin@python-works.com>
parents: 1594
diff changeset
1344 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
1345
1607
e886f91fcb71 Cached readme generation
Marcin Kuzminski <marcin@python-works.com>
parents: 1594
diff changeset
1346 :param key:
e886f91fcb71 Cached readme generation
Marcin Kuzminski <marcin@python-works.com>
parents: 1594
diff changeset
1347 """
2149
50aa7cb78cfe Mysql fixes
Marcin Kuzminski <marcin@python-works.com>
parents: 2147
diff changeset
1348
2147
d25bd432bc3e - #347 when running multiple RhodeCode instances, properly invalidates cache
Marcin Kuzminski <marcin@python-works.com>
parents: 2109
diff changeset
1349 key, _prefix, _org_key = cls._get_key(key)
d25bd432bc3e - #347 when running multiple RhodeCode instances, properly invalidates cache
Marcin Kuzminski <marcin@python-works.com>
parents: 2109
diff changeset
1350 inv = cls._get_or_create_key(key, _prefix, _org_key)
d25bd432bc3e - #347 when running multiple RhodeCode instances, properly invalidates cache
Marcin Kuzminski <marcin@python-works.com>
parents: 2109
diff changeset
1351
d25bd432bc3e - #347 when running multiple RhodeCode instances, properly invalidates cache
Marcin Kuzminski <marcin@python-works.com>
parents: 2109
diff changeset
1352 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
1353 return inv
1607
e886f91fcb71 Cached readme generation
Marcin Kuzminski <marcin@python-works.com>
parents: 1594
diff changeset
1354
e886f91fcb71 Cached readme generation
Marcin Kuzminski <marcin@python-works.com>
parents: 1594
diff changeset
1355 @classmethod
e886f91fcb71 Cached readme generation
Marcin Kuzminski <marcin@python-works.com>
parents: 1594
diff changeset
1356 def set_invalidate(cls, key):
e886f91fcb71 Cached readme generation
Marcin Kuzminski <marcin@python-works.com>
parents: 1594
diff changeset
1357 """
e886f91fcb71 Cached readme generation
Marcin Kuzminski <marcin@python-works.com>
parents: 1594
diff changeset
1358 Mark this Cache key for invalidation
1818
cf51bbfb120e auto white-space removal
Marcin Kuzminski <marcin@python-works.com>
parents: 1800
diff changeset
1359
1607
e886f91fcb71 Cached readme generation
Marcin Kuzminski <marcin@python-works.com>
parents: 1594
diff changeset
1360 :param key:
e886f91fcb71 Cached readme generation
Marcin Kuzminski <marcin@python-works.com>
parents: 1594
diff changeset
1361 """
e886f91fcb71 Cached readme generation
Marcin Kuzminski <marcin@python-works.com>
parents: 1594
diff changeset
1362
2147
d25bd432bc3e - #347 when running multiple RhodeCode instances, properly invalidates cache
Marcin Kuzminski <marcin@python-works.com>
parents: 2109
diff changeset
1363 key, _prefix, _org_key = cls._get_key(key)
2520
a1e156503afe Fixed calls to Session in db model
Marcin Kuzminski <marcin@python-works.com>
parents: 2510
diff changeset
1364 inv_objs = Session().query(cls).filter(cls.cache_args == _org_key).all()
2147
d25bd432bc3e - #347 when running multiple RhodeCode instances, properly invalidates cache
Marcin Kuzminski <marcin@python-works.com>
parents: 2109
diff changeset
1365 log.debug('marking %s key[s] %s for invalidation' % (len(inv_objs),
d25bd432bc3e - #347 when running multiple RhodeCode instances, properly invalidates cache
Marcin Kuzminski <marcin@python-works.com>
parents: 2109
diff changeset
1366 _org_key))
d25bd432bc3e - #347 when running multiple RhodeCode instances, properly invalidates cache
Marcin Kuzminski <marcin@python-works.com>
parents: 2109
diff changeset
1367 try:
d25bd432bc3e - #347 when running multiple RhodeCode instances, properly invalidates cache
Marcin Kuzminski <marcin@python-works.com>
parents: 2109
diff changeset
1368 for inv_obj in inv_objs:
d25bd432bc3e - #347 when running multiple RhodeCode instances, properly invalidates cache
Marcin Kuzminski <marcin@python-works.com>
parents: 2109
diff changeset
1369 if inv_obj:
d25bd432bc3e - #347 when running multiple RhodeCode instances, properly invalidates cache
Marcin Kuzminski <marcin@python-works.com>
parents: 2109
diff changeset
1370 inv_obj.cache_active = False
1607
e886f91fcb71 Cached readme generation
Marcin Kuzminski <marcin@python-works.com>
parents: 1594
diff changeset
1371
2520
a1e156503afe Fixed calls to Session in db model
Marcin Kuzminski <marcin@python-works.com>
parents: 2510
diff changeset
1372 Session().add(inv_obj)
a1e156503afe Fixed calls to Session in db model
Marcin Kuzminski <marcin@python-works.com>
parents: 2510
diff changeset
1373 Session().commit()
1607
e886f91fcb71 Cached readme generation
Marcin Kuzminski <marcin@python-works.com>
parents: 1594
diff changeset
1374 except Exception:
e886f91fcb71 Cached readme generation
Marcin Kuzminski <marcin@python-works.com>
parents: 1594
diff changeset
1375 log.error(traceback.format_exc())
2520
a1e156503afe Fixed calls to Session in db model
Marcin Kuzminski <marcin@python-works.com>
parents: 2510
diff changeset
1376 Session().rollback()
1607
e886f91fcb71 Cached readme generation
Marcin Kuzminski <marcin@python-works.com>
parents: 1594
diff changeset
1377
e886f91fcb71 Cached readme generation
Marcin Kuzminski <marcin@python-works.com>
parents: 1594
diff changeset
1378 @classmethod
e886f91fcb71 Cached readme generation
Marcin Kuzminski <marcin@python-works.com>
parents: 1594
diff changeset
1379 def set_valid(cls, key):
e886f91fcb71 Cached readme generation
Marcin Kuzminski <marcin@python-works.com>
parents: 1594
diff changeset
1380 """
e886f91fcb71 Cached readme generation
Marcin Kuzminski <marcin@python-works.com>
parents: 1594
diff changeset
1381 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
1382
1607
e886f91fcb71 Cached readme generation
Marcin Kuzminski <marcin@python-works.com>
parents: 1594
diff changeset
1383 :param key:
e886f91fcb71 Cached readme generation
Marcin Kuzminski <marcin@python-works.com>
parents: 1594
diff changeset
1384 """
2013
8530c3cd9d04 fixed issue with hybrid property for ldap_active
Marcin Kuzminski <marcin@python-works.com>
parents: 2007
diff changeset
1385 inv_obj = cls.get_by_key(key)
1607
e886f91fcb71 Cached readme generation
Marcin Kuzminski <marcin@python-works.com>
parents: 1594
diff changeset
1386 inv_obj.cache_active = True
2520
a1e156503afe Fixed calls to Session in db model
Marcin Kuzminski <marcin@python-works.com>
parents: 2510
diff changeset
1387 Session().add(inv_obj)
a1e156503afe Fixed calls to Session in db model
Marcin Kuzminski <marcin@python-works.com>
parents: 2510
diff changeset
1388 Session().commit()
1607
e886f91fcb71 Cached readme generation
Marcin Kuzminski <marcin@python-works.com>
parents: 1594
diff changeset
1389
2352
90e06f53af8c Implemented cache-map on main page to save executing select
Marcin Kuzminski <marcin@python-works.com>
parents: 2339
diff changeset
1390 @classmethod
90e06f53af8c Implemented cache-map on main page to save executing select
Marcin Kuzminski <marcin@python-works.com>
parents: 2339
diff changeset
1391 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
1392
90e06f53af8c Implemented cache-map on main page to save executing select
Marcin Kuzminski <marcin@python-works.com>
parents: 2339
diff changeset
1393 class cachemapdict(dict):
90e06f53af8c Implemented cache-map on main page to save executing select
Marcin Kuzminski <marcin@python-works.com>
parents: 2339
diff changeset
1394
90e06f53af8c Implemented cache-map on main page to save executing select
Marcin Kuzminski <marcin@python-works.com>
parents: 2339
diff changeset
1395 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
1396 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
1397 if fixkey:
90e06f53af8c Implemented cache-map on main page to save executing select
Marcin Kuzminski <marcin@python-works.com>
parents: 2339
diff changeset
1398 del kwargs['fixkey']
2356
2da7b5984ae5 typo fix + code garden
Marcin Kuzminski <marcin@python-works.com>
parents: 2352
diff changeset
1399 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
1400 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
1401
90e06f53af8c Implemented cache-map on main page to save executing select
Marcin Kuzminski <marcin@python-works.com>
parents: 2339
diff changeset
1402 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
1403 key = name
90e06f53af8c Implemented cache-map on main page to save executing select
Marcin Kuzminski <marcin@python-works.com>
parents: 2339
diff changeset
1404 if self.fixkey:
90e06f53af8c Implemented cache-map on main page to save executing select
Marcin Kuzminski <marcin@python-works.com>
parents: 2339
diff changeset
1405 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
1406 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
1407 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
1408 else:
90e06f53af8c Implemented cache-map on main page to save executing select
Marcin Kuzminski <marcin@python-works.com>
parents: 2339
diff changeset
1409 return self[key]
90e06f53af8c Implemented cache-map on main page to save executing select
Marcin Kuzminski <marcin@python-works.com>
parents: 2339
diff changeset
1410
90e06f53af8c Implemented cache-map on main page to save executing select
Marcin Kuzminski <marcin@python-works.com>
parents: 2339
diff changeset
1411 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
1412 if self.fixkey:
90e06f53af8c Implemented cache-map on main page to save executing select
Marcin Kuzminski <marcin@python-works.com>
parents: 2339
diff changeset
1413 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
1414 try:
90e06f53af8c Implemented cache-map on main page to save executing select
Marcin Kuzminski <marcin@python-works.com>
parents: 2339
diff changeset
1415 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
1416 except KeyError:
90e06f53af8c Implemented cache-map on main page to save executing select
Marcin Kuzminski <marcin@python-works.com>
parents: 2339
diff changeset
1417 return
90e06f53af8c Implemented cache-map on main page to save executing select
Marcin Kuzminski <marcin@python-works.com>
parents: 2339
diff changeset
1418
90e06f53af8c Implemented cache-map on main page to save executing select
Marcin Kuzminski <marcin@python-works.com>
parents: 2339
diff changeset
1419 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
1420 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
1421 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
1422 return cache_map
90e06f53af8c Implemented cache-map on main page to save executing select
Marcin Kuzminski <marcin@python-works.com>
parents: 2339
diff changeset
1423
1665
36f77a46f291 Added cache options to some db getters
Marcin Kuzminski <marcin@python-works.com>
parents: 1634
diff changeset
1424
1670
d2de0c2f02cd #77 code review
Marcin Kuzminski <marcin@python-works.com>
parents: 1669
diff changeset
1425 class ChangesetComment(Base, BaseModel):
d2de0c2f02cd #77 code review
Marcin Kuzminski <marcin@python-works.com>
parents: 1669
diff changeset
1426 __tablename__ = 'changeset_comments'
2149
50aa7cb78cfe Mysql fixes
Marcin Kuzminski <marcin@python-works.com>
parents: 2147
diff changeset
1427 __table_args__ = (
2463
b426ecc30319 Added some DB indexes to optimize queries
Marcin Kuzminski <marcin@python-works.com>
parents: 2462
diff changeset
1428 Index('cc_revision_idx', 'revision'),
2356
2da7b5984ae5 typo fix + code garden
Marcin Kuzminski <marcin@python-works.com>
parents: 2352
diff changeset
1429 {'extend_existing': True, 'mysql_engine': 'InnoDB',
2149
50aa7cb78cfe Mysql fixes
Marcin Kuzminski <marcin@python-works.com>
parents: 2147
diff changeset
1430 'mysql_charset': 'utf8'},
50aa7cb78cfe Mysql fixes
Marcin Kuzminski <marcin@python-works.com>
parents: 2147
diff changeset
1431 )
1670
d2de0c2f02cd #77 code review
Marcin Kuzminski <marcin@python-works.com>
parents: 1669
diff changeset
1432 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
1433 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
1434 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
1435 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
1436 line_no = Column('line_no', Unicode(10), nullable=True)
7276b170ce8b #71 code-review
Marcin Kuzminski <marcin@python-works.com>
parents: 1675
diff changeset
1437 f_path = Column('f_path', Unicode(1000), nullable=True)
1670
d2de0c2f02cd #77 code review
Marcin Kuzminski <marcin@python-works.com>
parents: 1669
diff changeset
1438 user_id = Column('user_id', Integer(), ForeignKey('users.user_id'), nullable=False)
1677
7276b170ce8b #71 code-review
Marcin Kuzminski <marcin@python-works.com>
parents: 1675
diff changeset
1439 text = Column('text', Unicode(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
1440 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
1441 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
1442
1703
f23828b00b21 notification fixes and improvements
Marcin Kuzminski <marcin@python-works.com>
parents: 1702
diff changeset
1443 author = relationship('User', lazy='joined')
1670
d2de0c2f02cd #77 code review
Marcin Kuzminski <marcin@python-works.com>
parents: 1669
diff changeset
1444 repo = relationship('Repository')
2286
9265958e33bb Show changes of status inside comments
Marcin Kuzminski <marcin@python-works.com>
parents: 2280
diff changeset
1445 status_change = relationship('ChangesetStatus', uselist=False)
2440
1bc579bcd67a - pull request generates overview based on it's params
Marcin Kuzminski <marcin@python-works.com>
parents: 2434
diff changeset
1446 pull_request = relationship('PullRequest', lazy='joined')
1670
d2de0c2f02cd #77 code review
Marcin Kuzminski <marcin@python-works.com>
parents: 1669
diff changeset
1447
1703
f23828b00b21 notification fixes and improvements
Marcin Kuzminski <marcin@python-works.com>
parents: 1702
diff changeset
1448 @classmethod
2443
fd0a822481ec - added commenting to pull requests
Marcin Kuzminski <marcin@python-works.com>
parents: 2440
diff changeset
1449 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
1450 """
2443
fd0a822481ec - added commenting to pull requests
Marcin Kuzminski <marcin@python-works.com>
parents: 2440
diff changeset
1451 Returns user associated with this ChangesetComment. ie those
1703
f23828b00b21 notification fixes and improvements
Marcin Kuzminski <marcin@python-works.com>
parents: 1702
diff changeset
1452 who actually commented
1818
cf51bbfb120e auto white-space removal
Marcin Kuzminski <marcin@python-works.com>
parents: 1800
diff changeset
1453
1703
f23828b00b21 notification fixes and improvements
Marcin Kuzminski <marcin@python-works.com>
parents: 1702
diff changeset
1454 :param cls:
f23828b00b21 notification fixes and improvements
Marcin Kuzminski <marcin@python-works.com>
parents: 1702
diff changeset
1455 :param revision:
f23828b00b21 notification fixes and improvements
Marcin Kuzminski <marcin@python-works.com>
parents: 1702
diff changeset
1456 """
2520
a1e156503afe Fixed calls to Session in db model
Marcin Kuzminski <marcin@python-works.com>
parents: 2510
diff changeset
1457 q = Session().query(User)\
2443
fd0a822481ec - added commenting to pull requests
Marcin Kuzminski <marcin@python-works.com>
parents: 2440
diff changeset
1458 .join(ChangesetComment.author)
fd0a822481ec - added commenting to pull requests
Marcin Kuzminski <marcin@python-works.com>
parents: 2440
diff changeset
1459 if revision:
fd0a822481ec - added commenting to pull requests
Marcin Kuzminski <marcin@python-works.com>
parents: 2440
diff changeset
1460 q = q.filter(cls.revision == revision)
fd0a822481ec - added commenting to pull requests
Marcin Kuzminski <marcin@python-works.com>
parents: 2440
diff changeset
1461 elif pull_request_id:
fd0a822481ec - added commenting to pull requests
Marcin Kuzminski <marcin@python-works.com>
parents: 2440
diff changeset
1462 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
1463 return q.all()
1886
50e32940e464 code garden
Marcin Kuzminski <marcin@python-works.com>
parents: 1884
diff changeset
1464
1703
f23828b00b21 notification fixes and improvements
Marcin Kuzminski <marcin@python-works.com>
parents: 1702
diff changeset
1465
2215
2c2bdaeca912 code-review initial
Marcin Kuzminski <marcin@python-works.com>
parents: 2161
diff changeset
1466 class ChangesetStatus(Base, BaseModel):
2c2bdaeca912 code-review initial
Marcin Kuzminski <marcin@python-works.com>
parents: 2161
diff changeset
1467 __tablename__ = 'changeset_statuses'
2c2bdaeca912 code-review initial
Marcin Kuzminski <marcin@python-works.com>
parents: 2161
diff changeset
1468 __table_args__ = (
2463
b426ecc30319 Added some DB indexes to optimize queries
Marcin Kuzminski <marcin@python-works.com>
parents: 2462
diff changeset
1469 Index('cs_revision_idx', 'revision'),
b426ecc30319 Added some DB indexes to optimize queries
Marcin Kuzminski <marcin@python-works.com>
parents: 2462
diff changeset
1470 Index('cs_version_idx', 'version'),
2287
8447d35b674e Added simple versioning for changeset status
Marcin Kuzminski <marcin@python-works.com>
parents: 2286
diff changeset
1471 UniqueConstraint('repo_id', 'revision', 'version'),
2215
2c2bdaeca912 code-review initial
Marcin Kuzminski <marcin@python-works.com>
parents: 2161
diff changeset
1472 {'extend_existing': True, 'mysql_engine': 'InnoDB',
2c2bdaeca912 code-review initial
Marcin Kuzminski <marcin@python-works.com>
parents: 2161
diff changeset
1473 'mysql_charset': 'utf8'}
2c2bdaeca912 code-review initial
Marcin Kuzminski <marcin@python-works.com>
parents: 2161
diff changeset
1474 )
2481
4d3032431d4f Adde pull request voting recalculation
Marcin Kuzminski <marcin@python-works.com>
parents: 2480
diff changeset
1475 STATUS_NOT_REVIEWED = DEFAULT = 'not_reviewed'
4d3032431d4f Adde pull request voting recalculation
Marcin Kuzminski <marcin@python-works.com>
parents: 2480
diff changeset
1476 STATUS_APPROVED = 'approved'
4d3032431d4f Adde pull request voting recalculation
Marcin Kuzminski <marcin@python-works.com>
parents: 2480
diff changeset
1477 STATUS_REJECTED = 'rejected'
4d3032431d4f Adde pull request voting recalculation
Marcin Kuzminski <marcin@python-works.com>
parents: 2480
diff changeset
1478 STATUS_UNDER_REVIEW = 'under_review'
2215
2c2bdaeca912 code-review initial
Marcin Kuzminski <marcin@python-works.com>
parents: 2161
diff changeset
1479
2c2bdaeca912 code-review initial
Marcin Kuzminski <marcin@python-works.com>
parents: 2161
diff changeset
1480 STATUSES = [
2481
4d3032431d4f Adde pull request voting recalculation
Marcin Kuzminski <marcin@python-works.com>
parents: 2480
diff changeset
1481 (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
1482 (STATUS_APPROVED, _("Approved")),
4d3032431d4f Adde pull request voting recalculation
Marcin Kuzminski <marcin@python-works.com>
parents: 2480
diff changeset
1483 (STATUS_REJECTED, _("Rejected")),
4d3032431d4f Adde pull request voting recalculation
Marcin Kuzminski <marcin@python-works.com>
parents: 2480
diff changeset
1484 (STATUS_UNDER_REVIEW, _("Under Review")),
2215
2c2bdaeca912 code-review initial
Marcin Kuzminski <marcin@python-works.com>
parents: 2161
diff changeset
1485 ]
2c2bdaeca912 code-review initial
Marcin Kuzminski <marcin@python-works.com>
parents: 2161
diff changeset
1486
2c2bdaeca912 code-review initial
Marcin Kuzminski <marcin@python-works.com>
parents: 2161
diff changeset
1487 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
1488 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
1489 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
1490 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
1491 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
1492 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
1493 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
1494 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
1495 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
1496
2215
2c2bdaeca912 code-review initial
Marcin Kuzminski <marcin@python-works.com>
parents: 2161
diff changeset
1497 author = relationship('User', lazy='joined')
2c2bdaeca912 code-review initial
Marcin Kuzminski <marcin@python-works.com>
parents: 2161
diff changeset
1498 repo = relationship('Repository')
2286
9265958e33bb Show changes of status inside comments
Marcin Kuzminski <marcin@python-works.com>
parents: 2280
diff changeset
1499 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
1500 pull_request = relationship('PullRequest', lazy='joined')
2215
2c2bdaeca912 code-review initial
Marcin Kuzminski <marcin@python-works.com>
parents: 2161
diff changeset
1501
2481
4d3032431d4f Adde pull request voting recalculation
Marcin Kuzminski <marcin@python-works.com>
parents: 2480
diff changeset
1502 def __unicode__(self):
4d3032431d4f Adde pull request voting recalculation
Marcin Kuzminski <marcin@python-works.com>
parents: 2480
diff changeset
1503 return u"<%s('%s:%s')>" % (
4d3032431d4f Adde pull request voting recalculation
Marcin Kuzminski <marcin@python-works.com>
parents: 2480
diff changeset
1504 self.__class__.__name__,
4d3032431d4f Adde pull request voting recalculation
Marcin Kuzminski <marcin@python-works.com>
parents: 2480
diff changeset
1505 self.status, self.author
4d3032431d4f Adde pull request voting recalculation
Marcin Kuzminski <marcin@python-works.com>
parents: 2480
diff changeset
1506 )
4d3032431d4f Adde pull request voting recalculation
Marcin Kuzminski <marcin@python-works.com>
parents: 2480
diff changeset
1507
2296
e5c0f201ca0b Add changeset status change into emails
Marcin Kuzminski <marcin@python-works.com>
parents: 2287
diff changeset
1508 @classmethod
e5c0f201ca0b Add changeset status change into emails
Marcin Kuzminski <marcin@python-works.com>
parents: 2287
diff changeset
1509 def get_status_lbl(cls, value):
e5c0f201ca0b Add changeset status change into emails
Marcin Kuzminski <marcin@python-works.com>
parents: 2287
diff changeset
1510 return dict(cls.STATUSES).get(value)
e5c0f201ca0b Add changeset status change into emails
Marcin Kuzminski <marcin@python-works.com>
parents: 2287
diff changeset
1511
2217
76947224bf27 Implemented initial code-review status of changesets
Marcin Kuzminski <marcin@python-works.com>
parents: 2215
diff changeset
1512 @property
76947224bf27 Implemented initial code-review status of changesets
Marcin Kuzminski <marcin@python-works.com>
parents: 2215
diff changeset
1513 def status_lbl(self):
2296
e5c0f201ca0b Add changeset status change into emails
Marcin Kuzminski <marcin@python-works.com>
parents: 2287
diff changeset
1514 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
1515
2215
2c2bdaeca912 code-review initial
Marcin Kuzminski <marcin@python-works.com>
parents: 2161
diff changeset
1516
2434
f29469677319 Added basic models for saving open pull requests
Marcin Kuzminski <marcin@python-works.com>
parents: 2430
diff changeset
1517 class PullRequest(Base, BaseModel):
f29469677319 Added basic models for saving open pull requests
Marcin Kuzminski <marcin@python-works.com>
parents: 2430
diff changeset
1518 __tablename__ = 'pull_requests'
f29469677319 Added basic models for saving open pull requests
Marcin Kuzminski <marcin@python-works.com>
parents: 2430
diff changeset
1519 __table_args__ = (
f29469677319 Added basic models for saving open pull requests
Marcin Kuzminski <marcin@python-works.com>
parents: 2430
diff changeset
1520 {'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
1521 'mysql_charset': 'utf8'},
f29469677319 Added basic models for saving open pull requests
Marcin Kuzminski <marcin@python-works.com>
parents: 2430
diff changeset
1522 )
f29469677319 Added basic models for saving open pull requests
Marcin Kuzminski <marcin@python-works.com>
parents: 2430
diff changeset
1523
2588
32dd6896abcf added status column to pull request + some small refactoring of models
Marcin Kuzminski <marcin@python-works.com>
parents: 2585
diff changeset
1524 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
1525 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
1526 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
1527
2434
f29469677319 Added basic models for saving open pull requests
Marcin Kuzminski <marcin@python-works.com>
parents: 2430
diff changeset
1528 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
1529 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
1530 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
1531 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
1532 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
1533 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
1534 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
1535 _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
1536 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
1537 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
1538 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
1539 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
1540
f29469677319 Added basic models for saving open pull requests
Marcin Kuzminski <marcin@python-works.com>
parents: 2430
diff changeset
1541 @hybrid_property
f29469677319 Added basic models for saving open pull requests
Marcin Kuzminski <marcin@python-works.com>
parents: 2430
diff changeset
1542 def revisions(self):
f29469677319 Added basic models for saving open pull requests
Marcin Kuzminski <marcin@python-works.com>
parents: 2430
diff changeset
1543 return self._revisions.split(':')
f29469677319 Added basic models for saving open pull requests
Marcin Kuzminski <marcin@python-works.com>
parents: 2430
diff changeset
1544
f29469677319 Added basic models for saving open pull requests
Marcin Kuzminski <marcin@python-works.com>
parents: 2430
diff changeset
1545 @revisions.setter
f29469677319 Added basic models for saving open pull requests
Marcin Kuzminski <marcin@python-works.com>
parents: 2430
diff changeset
1546 def revisions(self, val):
f29469677319 Added basic models for saving open pull requests
Marcin Kuzminski <marcin@python-works.com>
parents: 2430
diff changeset
1547 self._revisions = ':'.join(val)
f29469677319 Added basic models for saving open pull requests
Marcin Kuzminski <marcin@python-works.com>
parents: 2430
diff changeset
1548
2440
1bc579bcd67a - pull request generates overview based on it's params
Marcin Kuzminski <marcin@python-works.com>
parents: 2434
diff changeset
1549 author = relationship('User', lazy='joined')
2666
c51fb1da6df2 cascade fixes for comments/pull-requests/reviewers
Marcin Kuzminski <marcin@python-works.com>
parents: 2665
diff changeset
1550 reviewers = relationship('PullRequestReviewers',
c51fb1da6df2 cascade fixes for comments/pull-requests/reviewers
Marcin Kuzminski <marcin@python-works.com>
parents: 2665
diff changeset
1551 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
1552 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
1553 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
1554 statuses = relationship('ChangesetStatus')
c51fb1da6df2 cascade fixes for comments/pull-requests/reviewers
Marcin Kuzminski <marcin@python-works.com>
parents: 2665
diff changeset
1555 comments = relationship('ChangesetComment',
c51fb1da6df2 cascade fixes for comments/pull-requests/reviewers
Marcin Kuzminski <marcin@python-works.com>
parents: 2665
diff changeset
1556 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
1557
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
1558 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
1559 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
1560
2434
f29469677319 Added basic models for saving open pull requests
Marcin Kuzminski <marcin@python-works.com>
parents: 2430
diff changeset
1561 def __json__(self):
f29469677319 Added basic models for saving open pull requests
Marcin Kuzminski <marcin@python-works.com>
parents: 2430
diff changeset
1562 return dict(
f29469677319 Added basic models for saving open pull requests
Marcin Kuzminski <marcin@python-works.com>
parents: 2430
diff changeset
1563 revisions=self.revisions
f29469677319 Added basic models for saving open pull requests
Marcin Kuzminski <marcin@python-works.com>
parents: 2430
diff changeset
1564 )
f29469677319 Added basic models for saving open pull requests
Marcin Kuzminski <marcin@python-works.com>
parents: 2430
diff changeset
1565
f29469677319 Added basic models for saving open pull requests
Marcin Kuzminski <marcin@python-works.com>
parents: 2430
diff changeset
1566
f29469677319 Added basic models for saving open pull requests
Marcin Kuzminski <marcin@python-works.com>
parents: 2430
diff changeset
1567 class PullRequestReviewers(Base, BaseModel):
f29469677319 Added basic models for saving open pull requests
Marcin Kuzminski <marcin@python-works.com>
parents: 2430
diff changeset
1568 __tablename__ = 'pull_request_reviewers'
f29469677319 Added basic models for saving open pull requests
Marcin Kuzminski <marcin@python-works.com>
parents: 2430
diff changeset
1569 __table_args__ = (
f29469677319 Added basic models for saving open pull requests
Marcin Kuzminski <marcin@python-works.com>
parents: 2430
diff changeset
1570 {'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
1571 'mysql_charset': 'utf8'},
f29469677319 Added basic models for saving open pull requests
Marcin Kuzminski <marcin@python-works.com>
parents: 2430
diff changeset
1572 )
f29469677319 Added basic models for saving open pull requests
Marcin Kuzminski <marcin@python-works.com>
parents: 2430
diff changeset
1573
f29469677319 Added basic models for saving open pull requests
Marcin Kuzminski <marcin@python-works.com>
parents: 2430
diff changeset
1574 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
1575 self.user = user
f29469677319 Added basic models for saving open pull requests
Marcin Kuzminski <marcin@python-works.com>
parents: 2430
diff changeset
1576 self.pull_request = pull_request
f29469677319 Added basic models for saving open pull requests
Marcin Kuzminski <marcin@python-works.com>
parents: 2430
diff changeset
1577
f29469677319 Added basic models for saving open pull requests
Marcin Kuzminski <marcin@python-works.com>
parents: 2430
diff changeset
1578 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
1579 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
1580 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
1581
f29469677319 Added basic models for saving open pull requests
Marcin Kuzminski <marcin@python-works.com>
parents: 2430
diff changeset
1582 user = relationship('User')
f29469677319 Added basic models for saving open pull requests
Marcin Kuzminski <marcin@python-works.com>
parents: 2430
diff changeset
1583 pull_request = relationship('PullRequest')
1886
50e32940e464 code garden
Marcin Kuzminski <marcin@python-works.com>
parents: 1884
diff changeset
1584
1703
f23828b00b21 notification fixes and improvements
Marcin Kuzminski <marcin@python-works.com>
parents: 1702
diff changeset
1585
1702
8cb7f5c4d494 #302 - basic notification system, models+tests
Marcin Kuzminski <marcin@python-works.com>
parents: 1693
diff changeset
1586 class Notification(Base, BaseModel):
8cb7f5c4d494 #302 - basic notification system, models+tests
Marcin Kuzminski <marcin@python-works.com>
parents: 1693
diff changeset
1587 __tablename__ = 'notifications'
2149
50aa7cb78cfe Mysql fixes
Marcin Kuzminski <marcin@python-works.com>
parents: 2147
diff changeset
1588 __table_args__ = (
2463
b426ecc30319 Added some DB indexes to optimize queries
Marcin Kuzminski <marcin@python-works.com>
parents: 2462
diff changeset
1589 Index('notification_type_idx', 'type'),
2356
2da7b5984ae5 typo fix + code garden
Marcin Kuzminski <marcin@python-works.com>
parents: 2352
diff changeset
1590 {'extend_existing': True, 'mysql_engine': 'InnoDB',
2149
50aa7cb78cfe Mysql fixes
Marcin Kuzminski <marcin@python-works.com>
parents: 2147
diff changeset
1591 'mysql_charset': 'utf8'},
50aa7cb78cfe Mysql fixes
Marcin Kuzminski <marcin@python-works.com>
parents: 2147
diff changeset
1592 )
1703
f23828b00b21 notification fixes and improvements
Marcin Kuzminski <marcin@python-works.com>
parents: 1702
diff changeset
1593
1712
cac5109ac3b6 Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents: 1703
diff changeset
1594 TYPE_CHANGESET_COMMENT = u'cs_comment'
cac5109ac3b6 Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents: 1703
diff changeset
1595 TYPE_MESSAGE = u'message'
cac5109ac3b6 Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents: 1703
diff changeset
1596 TYPE_MENTION = u'mention'
1731
31e6eb2fb4b2 implements #222 registration feedback
Marcin Kuzminski <marcin@python-works.com>
parents: 1729
diff changeset
1597 TYPE_REGISTRATION = u'registration'
2244
77e376fdc4c6 pull requests draft UI
Marcin Kuzminski <marcin@python-works.com>
parents: 2218
diff changeset
1598 TYPE_PULL_REQUEST = u'pull_request'
2443
fd0a822481ec - added commenting to pull requests
Marcin Kuzminski <marcin@python-works.com>
parents: 2440
diff changeset
1599 TYPE_PULL_REQUEST_COMMENT = u'pull_request_comment'
1703
f23828b00b21 notification fixes and improvements
Marcin Kuzminski <marcin@python-works.com>
parents: 1702
diff changeset
1600
1702
8cb7f5c4d494 #302 - basic notification system, models+tests
Marcin Kuzminski <marcin@python-works.com>
parents: 1693
diff changeset
1601 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
1602 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
1603 body = Column('body', UnicodeText(50000), nullable=True)
1703
f23828b00b21 notification fixes and improvements
Marcin Kuzminski <marcin@python-works.com>
parents: 1702
diff changeset
1604 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
1605 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
1606 type_ = Column('type', Unicode(256))
1702
8cb7f5c4d494 #302 - basic notification system, models+tests
Marcin Kuzminski <marcin@python-works.com>
parents: 1693
diff changeset
1607
1712
cac5109ac3b6 Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents: 1703
diff changeset
1608 created_by_user = relationship('User')
1717
7ff304d3028f Notification fixes
Marcin Kuzminski <marcin@python-works.com>
parents: 1716
diff changeset
1609 notifications_to_users = relationship('UserNotification', lazy='joined',
7ff304d3028f Notification fixes
Marcin Kuzminski <marcin@python-works.com>
parents: 1716
diff changeset
1610 cascade="all, delete, delete-orphan")
1702
8cb7f5c4d494 #302 - basic notification system, models+tests
Marcin Kuzminski <marcin@python-works.com>
parents: 1693
diff changeset
1611
8cb7f5c4d494 #302 - basic notification system, models+tests
Marcin Kuzminski <marcin@python-works.com>
parents: 1693
diff changeset
1612 @property
8cb7f5c4d494 #302 - basic notification system, models+tests
Marcin Kuzminski <marcin@python-works.com>
parents: 1693
diff changeset
1613 def recipients(self):
8cb7f5c4d494 #302 - basic notification system, models+tests
Marcin Kuzminski <marcin@python-works.com>
parents: 1693
diff changeset
1614 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
1615 .filter(UserNotification.notification == self)\
2585
a52cee88d612 fixed sorting in recipients query of notifications
Marcin Kuzminski <marcin@python-works.com>
parents: 2562
diff changeset
1616 .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
1617
8cb7f5c4d494 #302 - basic notification system, models+tests
Marcin Kuzminski <marcin@python-works.com>
parents: 1693
diff changeset
1618 @classmethod
1703
f23828b00b21 notification fixes and improvements
Marcin Kuzminski <marcin@python-works.com>
parents: 1702
diff changeset
1619 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
1620 if type_ is None:
f23828b00b21 notification fixes and improvements
Marcin Kuzminski <marcin@python-works.com>
parents: 1702
diff changeset
1621 type_ = Notification.TYPE_MESSAGE
f23828b00b21 notification fixes and improvements
Marcin Kuzminski <marcin@python-works.com>
parents: 1702
diff changeset
1622
1702
8cb7f5c4d494 #302 - basic notification system, models+tests
Marcin Kuzminski <marcin@python-works.com>
parents: 1693
diff changeset
1623 notification = cls()
1712
cac5109ac3b6 Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents: 1703
diff changeset
1624 notification.created_by_user = created_by
1702
8cb7f5c4d494 #302 - basic notification system, models+tests
Marcin Kuzminski <marcin@python-works.com>
parents: 1693
diff changeset
1625 notification.subject = subject
8cb7f5c4d494 #302 - basic notification system, models+tests
Marcin Kuzminski <marcin@python-works.com>
parents: 1693
diff changeset
1626 notification.body = body
1703
f23828b00b21 notification fixes and improvements
Marcin Kuzminski <marcin@python-works.com>
parents: 1702
diff changeset
1627 notification.type_ = type_
1717
7ff304d3028f Notification fixes
Marcin Kuzminski <marcin@python-works.com>
parents: 1716
diff changeset
1628 notification.created_on = datetime.datetime.now()
1713
54687aa00724 Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents: 1712
diff changeset
1629
1702
8cb7f5c4d494 #302 - basic notification system, models+tests
Marcin Kuzminski <marcin@python-works.com>
parents: 1693
diff changeset
1630 for u in recipients:
1713
54687aa00724 Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents: 1712
diff changeset
1631 assoc = UserNotification()
54687aa00724 Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents: 1712
diff changeset
1632 assoc.notification = notification
54687aa00724 Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents: 1712
diff changeset
1633 u.notifications.append(assoc)
2520
a1e156503afe Fixed calls to Session in db model
Marcin Kuzminski <marcin@python-works.com>
parents: 2510
diff changeset
1634 Session().add(notification)
1702
8cb7f5c4d494 #302 - basic notification system, models+tests
Marcin Kuzminski <marcin@python-works.com>
parents: 1693
diff changeset
1635 return notification
8cb7f5c4d494 #302 - basic notification system, models+tests
Marcin Kuzminski <marcin@python-works.com>
parents: 1693
diff changeset
1636
1712
cac5109ac3b6 Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents: 1703
diff changeset
1637 @property
cac5109ac3b6 Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents: 1703
diff changeset
1638 def description(self):
cac5109ac3b6 Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents: 1703
diff changeset
1639 from rhodecode.model.notification import NotificationModel
cac5109ac3b6 Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents: 1703
diff changeset
1640 return NotificationModel().make_description(self)
cac5109ac3b6 Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents: 1703
diff changeset
1641
1800
6c86c987cf93 pep8ify
Marcin Kuzminski <marcin@python-works.com>
parents: 1758
diff changeset
1642
1702
8cb7f5c4d494 #302 - basic notification system, models+tests
Marcin Kuzminski <marcin@python-works.com>
parents: 1693
diff changeset
1643 class UserNotification(Base, BaseModel):
8cb7f5c4d494 #302 - basic notification system, models+tests
Marcin Kuzminski <marcin@python-works.com>
parents: 1693
diff changeset
1644 __tablename__ = 'user_to_notification'
1958
7e4b3d3a9c5c renamed repo groups table
Marcin Kuzminski <marcin@python-works.com>
parents: 1950
diff changeset
1645 __table_args__ = (
7e4b3d3a9c5c renamed repo groups table
Marcin Kuzminski <marcin@python-works.com>
parents: 1950
diff changeset
1646 UniqueConstraint('user_id', 'notification_id'),
2356
2da7b5984ae5 typo fix + code garden
Marcin Kuzminski <marcin@python-works.com>
parents: 2352
diff changeset
1647 {'extend_existing': True, 'mysql_engine': 'InnoDB',
2149
50aa7cb78cfe Mysql fixes
Marcin Kuzminski <marcin@python-works.com>
parents: 2147
diff changeset
1648 'mysql_charset': 'utf8'}
1958
7e4b3d3a9c5c renamed repo groups table
Marcin Kuzminski <marcin@python-works.com>
parents: 1950
diff changeset
1649 )
7e4b3d3a9c5c renamed repo groups table
Marcin Kuzminski <marcin@python-works.com>
parents: 1950
diff changeset
1650 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
1651 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
1652 read = Column('read', Boolean, default=False)
1702
8cb7f5c4d494 #302 - basic notification system, models+tests
Marcin Kuzminski <marcin@python-works.com>
parents: 1693
diff changeset
1653 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
1654
1713
54687aa00724 Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents: 1712
diff changeset
1655 user = relationship('User', lazy="joined")
1717
7ff304d3028f Notification fixes
Marcin Kuzminski <marcin@python-works.com>
parents: 1716
diff changeset
1656 notification = relationship('Notification', lazy="joined",
1960
3daa7093fbbb fix typo in db models
Marcin Kuzminski <marcin@python-works.com>
parents: 1958
diff changeset
1657 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
1658
1712
cac5109ac3b6 Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents: 1703
diff changeset
1659 def mark_as_read(self):
cac5109ac3b6 Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents: 1703
diff changeset
1660 self.read = True
2520
a1e156503afe Fixed calls to Session in db model
Marcin Kuzminski <marcin@python-works.com>
parents: 2510
diff changeset
1661 Session().add(self)
1702
8cb7f5c4d494 #302 - basic notification system, models+tests
Marcin Kuzminski <marcin@python-works.com>
parents: 1693
diff changeset
1662
1800
6c86c987cf93 pep8ify
Marcin Kuzminski <marcin@python-works.com>
parents: 1758
diff changeset
1663
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
1664 class DbMigrateVersion(Base, BaseModel):
834
8924ed0e4f36 added current db version into rhodecode,
Marcin Kuzminski <marcin@python-works.com>
parents: 832
diff changeset
1665 __tablename__ = 'db_migrate_version'
2149
50aa7cb78cfe Mysql fixes
Marcin Kuzminski <marcin@python-works.com>
parents: 2147
diff changeset
1666 __table_args__ = (
2356
2da7b5984ae5 typo fix + code garden
Marcin Kuzminski <marcin@python-works.com>
parents: 2352
diff changeset
1667 {'extend_existing': True, 'mysql_engine': 'InnoDB',
2149
50aa7cb78cfe Mysql fixes
Marcin Kuzminski <marcin@python-works.com>
parents: 2147
diff changeset
1668 'mysql_charset': 'utf8'},
50aa7cb78cfe Mysql fixes
Marcin Kuzminski <marcin@python-works.com>
parents: 2147
diff changeset
1669 )
1594
9dae92a65e40 fixes #288
Marcin Kuzminski <marcin@python-works.com>
parents: 1593
diff changeset
1670 repository_id = Column('repository_id', String(250), primary_key=True)
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
1671 repository_path = Column('repository_path', Text)
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
1672 version = Column('version', Integer)