annotate rhodecode/model/db.py @ 4116:ffd45b185016 rhodecode-2.2.5-gpl

Imported some of the GPLv3'd changes from RhodeCode v2.2.5. This imports changes between changesets 21af6c4eab3d and 6177597791c2 in RhodeCode's original repository, including only changes to Python files and HTML. RhodeCode clearly licensed its changes to these files under GPLv3 in their /LICENSE file, which states the following: The Python code and integrated HTML are licensed under the GPLv3 license. (See: https://code.rhodecode.com/rhodecode/files/v2.2.5/LICENSE or http://web.archive.org/web/20140512193334/https://code.rhodecode.com/rhodecode/files/f3b123159901f15426d18e3dc395e8369f70ebe0/LICENSE for an online copy of that LICENSE file) Conservancy reviewed these changes and confirmed that they can be licensed as a whole to the Kallithea project under GPLv3-only. While some of the contents committed herein are clearly licensed GPLv3-or-later, on the whole we must assume the are GPLv3-only, since the statement above from RhodeCode indicates that they intend GPLv3-only as their license, per GPLv3ยง14 and other relevant sections of GPLv3.
author Bradley M. Kuhn <bkuhn@sfconservancy.org>
date Wed, 02 Jul 2014 19:03:13 -0400
parents 3b5f32aeed36
children 48ad84558fb4
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 -*-
1206
a671db5bdd58 fixed license issue #149
Marcin Kuzminski <marcin@python-works.com>
parents: 1203
diff changeset
2 # 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
3 # 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
4 # 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
5 # (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
6 #
759
a7f50911a945 Models code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 734
diff changeset
7 # 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
8 # but WITHOUT ANY WARRANTY; without even the implied warranty of
a7f50911a945 Models code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 734
diff changeset
9 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
a7f50911a945 Models code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 734
diff changeset
10 # 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
11 #
759
a7f50911a945 Models code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 734
diff changeset
12 # 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
13 # along with this program. If not, see <http://www.gnu.org/licenses/>.
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
14 """
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
15 rhodecode.model.db
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
16 ~~~~~~~~~~~~~~~~~~
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
17
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
18 Database Models for RhodeCode
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
19
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
20 :created_on: Apr 08, 2010
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
21 :author: marcink
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
22 :copyright: (c) 2013 RhodeCode GmbH.
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
23 :license: GPLv3, see LICENSE for more details.
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
24 """
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
3850
7a4df261a375 added alias configuration option for gists.
Marcin Kuzminski <marcin@python-works.com>
parents: 3842
diff changeset
27 import time
759
a7f50911a945 Models code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 734
diff changeset
28 import logging
a7f50911a945 Models code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 734
diff changeset
29 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
30 import traceback
2356
2da7b5984ae5 typo fix + code garden
Marcin Kuzminski <marcin@python-works.com>
parents: 2352
diff changeset
31 import hashlib
3850
7a4df261a375 added alias configuration option for gists.
Marcin Kuzminski <marcin@python-works.com>
parents: 3842
diff changeset
32 import collections
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
33 import functools
759
a7f50911a945 Models code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 734
diff changeset
34
658
4ecb2ffcc110 fixed imports
Marcin Kuzminski <marcin@python-works.com>
parents: 657
diff changeset
35 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
36 from sqlalchemy.ext.hybrid import hybrid_property
1594
9dae92a65e40 fixes #288
Marcin Kuzminski <marcin@python-works.com>
parents: 1593
diff changeset
37 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
38 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
39 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
40 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
41
2218
6e5d686084f1 fixed translation function for models
Marcin Kuzminski <marcin@python-works.com>
parents: 2217
diff changeset
42 from pylons.i18n.translation import lazy_ugettext as _
2215
2c2bdaeca912 code-review initial
Marcin Kuzminski <marcin@python-works.com>
parents: 2161
diff changeset
43
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
44 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
45 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
46 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
47 from rhodecode.lib.vcs.utils.lazy import LazyProperty
3420
a6bef3e8a361 Update changeset cache should use non-cache version of repo if given attribute is empty, it's easier to controll how changesets are udpated
Marcin Kuzminski <marcin@python-works.com>
parents: 3417
diff changeset
48 from rhodecode.lib.vcs.backends.base import EmptyChangeset
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
49
2109
8ecfed1d8f8b utils/conf
Marcin Kuzminski <marcin@python-works.com>
parents: 2079
diff changeset
50 from rhodecode.lib.utils2 import str2bool, safe_str, get_changeset_safe, \
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
51 safe_unicode, remove_prefix, time_to_datetime, aslist, Optional, safe_int, \
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
52 get_clone_url
1514
87ec80c280bb fixed issues with python2.5
Marcin Kuzminski <marcin@python-works.com>
parents: 1508
diff changeset
53 from rhodecode.lib.compat import json
1669
f522f4d3bf93 moved caching query to libs
Marcin Kuzminski <marcin@python-works.com>
parents: 1665
diff changeset
54 from rhodecode.lib.caching_query import FromCache
1500
256e729a94cd Extended API
Marcin Kuzminski <marcin@python-works.com>
parents: 1466
diff changeset
55
2356
2da7b5984ae5 typo fix + code garden
Marcin Kuzminski <marcin@python-works.com>
parents: 2352
diff changeset
56 from rhodecode.model.meta import Base, Session
1500
256e729a94cd Extended API
Marcin Kuzminski <marcin@python-works.com>
parents: 1466
diff changeset
57
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
58 URL_SEP = '/'
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
59 log = logging.getLogger(__name__)
49
3ada2f409c1c Added sqlalchemy support
Marcin Kuzminski <marcin@python-blog.com>
parents:
diff changeset
60
1081
70bf0be59653 fixed Session problems in model class functions
Marcin Kuzminski <marcin@python-works.com>
parents: 1065
diff changeset
61 #==============================================================================
1388
2029c17cc6c6 Added basic JsonSerialization into models.
Marcin Kuzminski <marcin@python-works.com>
parents: 1385
diff changeset
62 # BASE CLASSES
1081
70bf0be59653 fixed Session problems in model class functions
Marcin Kuzminski <marcin@python-works.com>
parents: 1065
diff changeset
63 #==============================================================================
70bf0be59653 fixed Session problems in model class functions
Marcin Kuzminski <marcin@python-works.com>
parents: 1065
diff changeset
64
2062
bf8ed0adbc66 fixes #371 fixed issues with beaker/sqlalchemy and non-ascii cache keys
Marcin Kuzminski <marcin@python-works.com>
parents: 2058
diff changeset
65 _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
66
1800
6c86c987cf93 pep8ify
Marcin Kuzminski <marcin@python-works.com>
parents: 1758
diff changeset
67
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
68 class BaseModel(object):
1758
a87aa385f21c fixed repo_create permission by adding missing commit statements
Marcin Kuzminski <marcin@python-works.com>
parents: 1757
diff changeset
69 """
a87aa385f21c fixed repo_create permission by adding missing commit statements
Marcin Kuzminski <marcin@python-works.com>
parents: 1757
diff changeset
70 Base Model for all classess
1388
2029c17cc6c6 Added basic JsonSerialization into models.
Marcin Kuzminski <marcin@python-works.com>
parents: 1385
diff changeset
71 """
2029c17cc6c6 Added basic JsonSerialization into models.
Marcin Kuzminski <marcin@python-works.com>
parents: 1385
diff changeset
72
2029c17cc6c6 Added basic JsonSerialization into models.
Marcin Kuzminski <marcin@python-works.com>
parents: 1385
diff changeset
73 @classmethod
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
74 def _get_keys(cls):
1388
2029c17cc6c6 Added basic JsonSerialization into models.
Marcin Kuzminski <marcin@python-works.com>
parents: 1385
diff changeset
75 """return column names for this model """
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
76 return class_mapper(cls).c.keys()
1388
2029c17cc6c6 Added basic JsonSerialization into models.
Marcin Kuzminski <marcin@python-works.com>
parents: 1385
diff changeset
77
1948
4582e6b9e2f6 get_dict function garden
Marcin Kuzminski <marcin@python-works.com>
parents: 1886
diff changeset
78 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
79 """
a87aa385f21c fixed repo_create permission by adding missing commit statements
Marcin Kuzminski <marcin@python-works.com>
parents: 1757
diff changeset
80 return dict with keys and values corresponding
1948
4582e6b9e2f6 get_dict function garden
Marcin Kuzminski <marcin@python-works.com>
parents: 1886
diff changeset
81 to this model data """
1388
2029c17cc6c6 Added basic JsonSerialization into models.
Marcin Kuzminski <marcin@python-works.com>
parents: 1385
diff changeset
82
2029c17cc6c6 Added basic JsonSerialization into models.
Marcin Kuzminski <marcin@python-works.com>
parents: 1385
diff changeset
83 d = {}
2029c17cc6c6 Added basic JsonSerialization into models.
Marcin Kuzminski <marcin@python-works.com>
parents: 1385
diff changeset
84 for k in self._get_keys():
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
85 d[k] = getattr(self, k)
1800
6c86c987cf93 pep8ify
Marcin Kuzminski <marcin@python-works.com>
parents: 1758
diff changeset
86
1758
a87aa385f21c fixed repo_create permission by adding missing commit statements
Marcin Kuzminski <marcin@python-works.com>
parents: 1757
diff changeset
87 # 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
88 _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
89 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
90 # 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
91 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
92 _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
93 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
94 d[k] = val
1388
2029c17cc6c6 Added basic JsonSerialization into models.
Marcin Kuzminski <marcin@python-works.com>
parents: 1385
diff changeset
95 return d
2029c17cc6c6 Added basic JsonSerialization into models.
Marcin Kuzminski <marcin@python-works.com>
parents: 1385
diff changeset
96
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
97 def get_appstruct(self):
1388
2029c17cc6c6 Added basic JsonSerialization into models.
Marcin Kuzminski <marcin@python-works.com>
parents: 1385
diff changeset
98 """return list with keys and values tupples corresponding
2029c17cc6c6 Added basic JsonSerialization into models.
Marcin Kuzminski <marcin@python-works.com>
parents: 1385
diff changeset
99 to this model data """
2029c17cc6c6 Added basic JsonSerialization into models.
Marcin Kuzminski <marcin@python-works.com>
parents: 1385
diff changeset
100
2029c17cc6c6 Added basic JsonSerialization into models.
Marcin Kuzminski <marcin@python-works.com>
parents: 1385
diff changeset
101 l = []
2029c17cc6c6 Added basic JsonSerialization into models.
Marcin Kuzminski <marcin@python-works.com>
parents: 1385
diff changeset
102 for k in self._get_keys():
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
103 l.append((k, getattr(self, k),))
1388
2029c17cc6c6 Added basic JsonSerialization into models.
Marcin Kuzminski <marcin@python-works.com>
parents: 1385
diff changeset
104 return l
2029c17cc6c6 Added basic JsonSerialization into models.
Marcin Kuzminski <marcin@python-works.com>
parents: 1385
diff changeset
105
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
106 def populate_obj(self, populate_dict):
1388
2029c17cc6c6 Added basic JsonSerialization into models.
Marcin Kuzminski <marcin@python-works.com>
parents: 1385
diff changeset
107 """populate model with data from given populate_dict"""
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 for k in self._get_keys():
2029c17cc6c6 Added basic JsonSerialization into models.
Marcin Kuzminski <marcin@python-works.com>
parents: 1385
diff changeset
110 if k in populate_dict:
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
111 setattr(self, k, populate_dict[k])
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 query(cls):
2520
a1e156503afe Fixed calls to Session in db model
Marcin Kuzminski <marcin@python-works.com>
parents: 2510
diff changeset
115 return Session().query(cls)
1388
2029c17cc6c6 Added basic JsonSerialization into models.
Marcin Kuzminski <marcin@python-works.com>
parents: 1385
diff changeset
116
2029c17cc6c6 Added basic JsonSerialization into models.
Marcin Kuzminski <marcin@python-works.com>
parents: 1385
diff changeset
117 @classmethod
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
118 def get(cls, id_):
1594
9dae92a65e40 fixes #288
Marcin Kuzminski <marcin@python-works.com>
parents: 1593
diff changeset
119 if id_:
9dae92a65e40 fixes #288
Marcin Kuzminski <marcin@python-works.com>
parents: 1593
diff changeset
120 return cls.query().get(id_)
1466
ad5a543a9b2f Code cleanup
Marcin Kuzminski <marcin@python-works.com>
parents: 1460
diff changeset
121
1460
b50348816a80 Added more advanced hook management into rhodecode admin settings
Marcin Kuzminski <marcin@python-works.com>
parents: 1436
diff changeset
122 @classmethod
2496
fddd8e3fc157 use get_or_404 where possible
Marcin Kuzminski <marcin@python-works.com>
parents: 2481
diff changeset
123 def get_or_404(cls, id_):
2942
f53faff4487e get_or_404 method does validation for ID beeing an INT
Marcin Kuzminski <marcin@python-works.com>
parents: 2937
diff changeset
124 try:
f53faff4487e get_or_404 method does validation for ID beeing an INT
Marcin Kuzminski <marcin@python-works.com>
parents: 2937
diff changeset
125 id_ = int(id_)
f53faff4487e get_or_404 method does validation for ID beeing an INT
Marcin Kuzminski <marcin@python-works.com>
parents: 2937
diff changeset
126 except (TypeError, ValueError):
f53faff4487e get_or_404 method does validation for ID beeing an INT
Marcin Kuzminski <marcin@python-works.com>
parents: 2937
diff changeset
127 raise HTTPNotFound
f53faff4487e get_or_404 method does validation for ID beeing an INT
Marcin Kuzminski <marcin@python-works.com>
parents: 2937
diff changeset
128
f53faff4487e get_or_404 method does validation for ID beeing an INT
Marcin Kuzminski <marcin@python-works.com>
parents: 2937
diff changeset
129 res = cls.query().get(id_)
f53faff4487e get_or_404 method does validation for ID beeing an INT
Marcin Kuzminski <marcin@python-works.com>
parents: 2937
diff changeset
130 if not res:
f53faff4487e get_or_404 method does validation for ID beeing an INT
Marcin Kuzminski <marcin@python-works.com>
parents: 2937
diff changeset
131 raise HTTPNotFound
f53faff4487e get_or_404 method does validation for ID beeing an INT
Marcin Kuzminski <marcin@python-works.com>
parents: 2937
diff changeset
132 return res
2496
fddd8e3fc157 use get_or_404 where possible
Marcin Kuzminski <marcin@python-works.com>
parents: 2481
diff changeset
133
fddd8e3fc157 use get_or_404 where possible
Marcin Kuzminski <marcin@python-works.com>
parents: 2481
diff changeset
134 @classmethod
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
135 def getAll(cls):
3714
7e3d89d9d3a2 - Manage Userโ€™s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents: 3687
diff changeset
136 # deprecated and left for backward compatibility
7e3d89d9d3a2 - Manage Userโ€™s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents: 3687
diff changeset
137 return cls.get_all()
7e3d89d9d3a2 - Manage Userโ€™s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents: 3687
diff changeset
138
7e3d89d9d3a2 - Manage Userโ€™s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents: 3687
diff changeset
139 @classmethod
7e3d89d9d3a2 - Manage Userโ€™s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents: 3687
diff changeset
140 def get_all(cls):
1584
3338a0994472 Improve API with user/group/repo CRUD methods
Nicolas VINOT <aeris@imirhil.fr>
parents: 1508
diff changeset
141 return cls.query().all()
1466
ad5a543a9b2f Code cleanup
Marcin Kuzminski <marcin@python-works.com>
parents: 1460
diff changeset
142
1460
b50348816a80 Added more advanced hook management into rhodecode admin settings
Marcin Kuzminski <marcin@python-works.com>
parents: 1436
diff changeset
143 @classmethod
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
144 def delete(cls, id_):
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
145 obj = cls.query().get(id_)
2520
a1e156503afe Fixed calls to Session in db model
Marcin Kuzminski <marcin@python-works.com>
parents: 2510
diff changeset
146 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
147
2156
a27e4d44237e Use __unicode__ instead of __repr__ in models.
Marcin Kuzminski <marcin@python-works.com>
parents: 2152
diff changeset
148 def __repr__(self):
a27e4d44237e Use __unicode__ instead of __repr__ in models.
Marcin Kuzminski <marcin@python-works.com>
parents: 2152
diff changeset
149 if hasattr(self, '__unicode__'):
a27e4d44237e Use __unicode__ instead of __repr__ in models.
Marcin Kuzminski <marcin@python-works.com>
parents: 2152
diff changeset
150 # python repr needs to return str
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
151 try:
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
152 return safe_str(self.__unicode__())
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
153 except UnicodeDecodeError:
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
154 pass
2156
a27e4d44237e Use __unicode__ instead of __repr__ in models.
Marcin Kuzminski <marcin@python-works.com>
parents: 2152
diff changeset
155 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
156
2356
2da7b5984ae5 typo fix + code garden
Marcin Kuzminski <marcin@python-works.com>
parents: 2352
diff changeset
157
1633
2c0d35e336b5 refactoring of models names for repoGroup permissions
Marcin Kuzminski <marcin@python-works.com>
parents: 1607
diff changeset
158 class RhodeCodeSetting(Base, BaseModel):
548
b75b77ef649d renamed hg_app to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents: 547
diff changeset
159 __tablename__ = 'rhodecode_settings'
1958
7e4b3d3a9c5c renamed repo groups table
Marcin Kuzminski <marcin@python-works.com>
parents: 1950
diff changeset
160 __table_args__ = (
7e4b3d3a9c5c renamed repo groups table
Marcin Kuzminski <marcin@python-works.com>
parents: 1950
diff changeset
161 UniqueConstraint('app_settings_name'),
2356
2da7b5984ae5 typo fix + code garden
Marcin Kuzminski <marcin@python-works.com>
parents: 2352
diff changeset
162 {'extend_existing': True, 'mysql_engine': 'InnoDB',
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
163 'mysql_charset': 'utf8', 'sqlite_autoincrement': True}
1958
7e4b3d3a9c5c renamed repo groups table
Marcin Kuzminski <marcin@python-works.com>
parents: 1950
diff changeset
164 )
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
165
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
166 SETTINGS_TYPES = {
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
167 'str': safe_str,
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
168 'int': safe_int,
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
169 'unicode': safe_unicode,
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
170 'bool': str2bool,
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
171 'list': functools.partial(aslist, sep=',')
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
172 }
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
173 DEFAULT_UPDATE_URL = 'https://rhodecode.com/api/v1/info/versions'
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
174
1594
9dae92a65e40 fixes #288
Marcin Kuzminski <marcin@python-works.com>
parents: 1593
diff changeset
175 app_settings_id = Column("app_settings_id", Integer(), nullable=False, unique=True, default=None, primary_key=True)
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
176 app_settings_name = Column("app_settings_name", String(255, convert_unicode=False), nullable=True, unique=None, default=None)
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
177 _app_settings_value = Column("app_settings_value", String(4096, convert_unicode=False), nullable=True, unique=None, default=None)
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
178 _app_settings_type = Column("app_settings_type", String(255, convert_unicode=False), nullable=True, unique=None, default=None)
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
179
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
180 def __init__(self, key='', val='', type='unicode'):
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
181 self.app_settings_name = key
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
182 self.app_settings_value = val
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
183 self.app_settings_type = type
704
26237de9b613 Added settings model, and Exceptions lib.
Marcin Kuzminski <marcin@python-works.com>
parents: 692
diff changeset
184
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
185 @validates('_app_settings_value')
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
186 def validate_settings_value(self, key, val):
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
187 assert type(val) == unicode
1561
4d841e565237 added validation of params on settings table
Marcin Kuzminski <marcin@python-works.com>
parents: 1556
diff changeset
188 return val
4d841e565237 added validation of params on settings table
Marcin Kuzminski <marcin@python-works.com>
parents: 1556
diff changeset
189
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
190 @hybrid_property
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
191 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
192 v = self._app_settings_value
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
193 _type = self.app_settings_type
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
194 converter = self.SETTINGS_TYPES.get(_type) or self.SETTINGS_TYPES['unicode']
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
195 return converter(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
196
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
197 @app_settings_value.setter
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
198 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
199 """
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
200 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
201
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
202 :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
203 """
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
204 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
205
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
206 @hybrid_property
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
207 def app_settings_type(self):
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
208 return self._app_settings_type
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
209
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
210 @app_settings_type.setter
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
211 def app_settings_type(self, val):
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
212 if val not in self.SETTINGS_TYPES:
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
213 raise Exception('type must be one of %s got %s'
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
214 % (self.SETTINGS_TYPES.keys(), val))
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
215 self._app_settings_type = val
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
216
2156
a27e4d44237e Use __unicode__ instead of __repr__ in models.
Marcin Kuzminski <marcin@python-works.com>
parents: 2152
diff changeset
217 def __unicode__(self):
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
218 return u"<%s('%s:%s[%s]')>" % (
1958
7e4b3d3a9c5c renamed repo groups table
Marcin Kuzminski <marcin@python-works.com>
parents: 1950
diff changeset
219 self.__class__.__name__,
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
220 self.app_settings_name, self.app_settings_value, self.app_settings_type
1958
7e4b3d3a9c5c renamed repo groups table
Marcin Kuzminski <marcin@python-works.com>
parents: 1950
diff changeset
221 )
704
26237de9b613 Added settings model, and Exceptions lib.
Marcin Kuzminski <marcin@python-works.com>
parents: 692
diff changeset
222
1266
a1bcfe58a1ab Fixed #161 form saves the create repository permission.
Marcin Kuzminski <marcin@python-works.com>
parents: 1206
diff changeset
223 @classmethod
2674
a221706dab50 merged + fixed pull request #62: Implemented metatags and visualisation options.
Marcin Kuzminski <marcin@python-works.com>
parents: 2668
diff changeset
224 def get_by_name(cls, key):
1584
3338a0994472 Improve API with user/group/repo CRUD methods
Nicolas VINOT <aeris@imirhil.fr>
parents: 1508
diff changeset
225 return cls.query()\
2674
a221706dab50 merged + fixed pull request #62: Implemented metatags and visualisation options.
Marcin Kuzminski <marcin@python-works.com>
parents: 2668
diff changeset
226 .filter(cls.app_settings_name == key).scalar()
a221706dab50 merged + fixed pull request #62: Implemented metatags and visualisation options.
Marcin Kuzminski <marcin@python-works.com>
parents: 2668
diff changeset
227
a221706dab50 merged + fixed pull request #62: Implemented metatags and visualisation options.
Marcin Kuzminski <marcin@python-works.com>
parents: 2668
diff changeset
228 @classmethod
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
229 def get_by_name_or_create(cls, key, val='', type='unicode'):
2674
a221706dab50 merged + fixed pull request #62: Implemented metatags and visualisation options.
Marcin Kuzminski <marcin@python-works.com>
parents: 2668
diff changeset
230 res = cls.get_by_name(key)
a221706dab50 merged + fixed pull request #62: Implemented metatags and visualisation options.
Marcin Kuzminski <marcin@python-works.com>
parents: 2668
diff changeset
231 if not res:
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
232 res = cls(key, val, type)
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
233 return res
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
234
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
235 @classmethod
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
236 def create_or_update(cls, key, val=Optional(''), type=Optional('unicode')):
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
237 """
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
238 Creates or updates RhodeCode setting. If updates is triggered it will only
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
239 update parameters that are explicityl set Optional instance will be skipped
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
240
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
241 :param key:
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
242 :param val:
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
243 :param type:
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
244 :return:
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
245 """
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
246 res = cls.get_by_name(key)
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
247 if not res:
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
248 val = Optional.extract(val)
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
249 type = Optional.extract(type)
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
250 res = cls(key, val, type)
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
251 else:
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
252 res.app_settings_name = key
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
253 if not isinstance(val, Optional):
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
254 # update if set
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
255 res.app_settings_value = val
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
256 if not isinstance(type, Optional):
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
257 # update if set
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
258 res.app_settings_type = type
2674
a221706dab50 merged + fixed pull request #62: Implemented metatags and visualisation options.
Marcin Kuzminski <marcin@python-works.com>
parents: 2668
diff changeset
259 return res
1292
c0335c1dee36 added some fixes to LDAP form re-submition, new simples ldap-settings getter.
Marcin Kuzminski <marcin@python-works.com>
parents: 1279
diff changeset
260
c0335c1dee36 added some fixes to LDAP form re-submition, new simples ldap-settings getter.
Marcin Kuzminski <marcin@python-works.com>
parents: 1279
diff changeset
261 @classmethod
1594
9dae92a65e40 fixes #288
Marcin Kuzminski <marcin@python-works.com>
parents: 1593
diff changeset
262 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
263
1584
3338a0994472 Improve API with user/group/repo CRUD methods
Nicolas VINOT <aeris@imirhil.fr>
parents: 1508
diff changeset
264 ret = cls.query()
1266
a1bcfe58a1ab Fixed #161 form saves the create repository permission.
Marcin Kuzminski <marcin@python-works.com>
parents: 1206
diff changeset
265
a1bcfe58a1ab Fixed #161 form saves the create repository permission.
Marcin Kuzminski <marcin@python-works.com>
parents: 1206
diff changeset
266 if cache:
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
267 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
268
a1bcfe58a1ab Fixed #161 form saves the create repository permission.
Marcin Kuzminski <marcin@python-works.com>
parents: 1206
diff changeset
269 if not ret:
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
270 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
271 settings = {}
a1bcfe58a1ab Fixed #161 form saves the create repository permission.
Marcin Kuzminski <marcin@python-works.com>
parents: 1206
diff changeset
272 for each in ret:
a1bcfe58a1ab Fixed #161 form saves the create repository permission.
Marcin Kuzminski <marcin@python-works.com>
parents: 1206
diff changeset
273 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
274 each.app_settings_value
a1bcfe58a1ab Fixed #161 form saves the create repository permission.
Marcin Kuzminski <marcin@python-works.com>
parents: 1206
diff changeset
275
a1bcfe58a1ab Fixed #161 form saves the create repository permission.
Marcin Kuzminski <marcin@python-works.com>
parents: 1206
diff changeset
276 return settings
a1bcfe58a1ab Fixed #161 form saves the create repository permission.
Marcin Kuzminski <marcin@python-works.com>
parents: 1206
diff changeset
277
a1bcfe58a1ab Fixed #161 form saves the create repository permission.
Marcin Kuzminski <marcin@python-works.com>
parents: 1206
diff changeset
278 @classmethod
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
279 def get_auth_plugins(cls, cache=False):
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
280 auth_plugins = cls.get_by_name("auth_plugins").app_settings_value
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
281 return auth_plugins
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
282
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
283 @classmethod
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
284 def get_auth_settings(cls, cache=False):
1584
3338a0994472 Improve API with user/group/repo CRUD methods
Nicolas VINOT <aeris@imirhil.fr>
parents: 1508
diff changeset
285 ret = cls.query()\
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
286 .filter(cls.app_settings_name.startswith('auth_')).all()
1266
a1bcfe58a1ab Fixed #161 form saves the create repository permission.
Marcin Kuzminski <marcin@python-works.com>
parents: 1206
diff changeset
287 fd = {}
a1bcfe58a1ab Fixed #161 form saves the create repository permission.
Marcin Kuzminski <marcin@python-works.com>
parents: 1206
diff changeset
288 for row in ret:
2356
2da7b5984ae5 typo fix + code garden
Marcin Kuzminski <marcin@python-works.com>
parents: 2352
diff changeset
289 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
290
1266
a1bcfe58a1ab Fixed #161 form saves the create repository permission.
Marcin Kuzminski <marcin@python-works.com>
parents: 1206
diff changeset
291 return fd
a1bcfe58a1ab Fixed #161 form saves the create repository permission.
Marcin Kuzminski <marcin@python-works.com>
parents: 1206
diff changeset
292
3056
6104dfd35b16 Implemented #379 defaults settings page for creation of repositories
Marcin Kuzminski <marcin@python-works.com>
parents: 3052
diff changeset
293 @classmethod
6104dfd35b16 Implemented #379 defaults settings page for creation of repositories
Marcin Kuzminski <marcin@python-works.com>
parents: 3052
diff changeset
294 def get_default_repo_settings(cls, cache=False, strip_prefix=False):
6104dfd35b16 Implemented #379 defaults settings page for creation of repositories
Marcin Kuzminski <marcin@python-works.com>
parents: 3052
diff changeset
295 ret = cls.query()\
6104dfd35b16 Implemented #379 defaults settings page for creation of repositories
Marcin Kuzminski <marcin@python-works.com>
parents: 3052
diff changeset
296 .filter(cls.app_settings_name.startswith('default_')).all()
6104dfd35b16 Implemented #379 defaults settings page for creation of repositories
Marcin Kuzminski <marcin@python-works.com>
parents: 3052
diff changeset
297 fd = {}
6104dfd35b16 Implemented #379 defaults settings page for creation of repositories
Marcin Kuzminski <marcin@python-works.com>
parents: 3052
diff changeset
298 for row in ret:
6104dfd35b16 Implemented #379 defaults settings page for creation of repositories
Marcin Kuzminski <marcin@python-works.com>
parents: 3052
diff changeset
299 key = row.app_settings_name
6104dfd35b16 Implemented #379 defaults settings page for creation of repositories
Marcin Kuzminski <marcin@python-works.com>
parents: 3052
diff changeset
300 if strip_prefix:
6104dfd35b16 Implemented #379 defaults settings page for creation of repositories
Marcin Kuzminski <marcin@python-works.com>
parents: 3052
diff changeset
301 key = remove_prefix(key, prefix='default_')
6104dfd35b16 Implemented #379 defaults settings page for creation of repositories
Marcin Kuzminski <marcin@python-works.com>
parents: 3052
diff changeset
302 fd.update({key: row.app_settings_value})
6104dfd35b16 Implemented #379 defaults settings page for creation of repositories
Marcin Kuzminski <marcin@python-works.com>
parents: 3052
diff changeset
303
6104dfd35b16 Implemented #379 defaults settings page for creation of repositories
Marcin Kuzminski <marcin@python-works.com>
parents: 3052
diff changeset
304 return fd
6104dfd35b16 Implemented #379 defaults settings page for creation of repositories
Marcin Kuzminski <marcin@python-works.com>
parents: 3052
diff changeset
305
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
306 @classmethod
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
307 def get_server_info(cls):
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
308 import pkg_resources
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
309 import platform
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
310 import rhodecode
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
311 from rhodecode.lib.utils import check_git_version
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
312 mods = [(p.project_name, p.version) for p in pkg_resources.working_set]
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
313 info = {
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
314 'modules': sorted(mods, key=lambda k: k[0].lower()),
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
315 'py_version': platform.python_version(),
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
316 'platform': safe_unicode(platform.platform()),
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
317 'rhodecode_version': rhodecode.__version__,
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
318 'git_version': safe_unicode(check_git_version()),
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
319 'git_path': rhodecode.CONFIG.get('git_path')
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
320 }
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
321 return info
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
322
1266
a1bcfe58a1ab Fixed #161 form saves the create repository permission.
Marcin Kuzminski <marcin@python-works.com>
parents: 1206
diff changeset
323
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
324 class RhodeCodeUi(Base, BaseModel):
548
b75b77ef649d renamed hg_app to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents: 547
diff changeset
325 __tablename__ = 'rhodecode_ui'
1958
7e4b3d3a9c5c renamed repo groups table
Marcin Kuzminski <marcin@python-works.com>
parents: 1950
diff changeset
326 __table_args__ = (
1963
9bbde54232dc white space cleanup
Marcin Kuzminski <marcin@python-works.com>
parents: 1960
diff changeset
327 UniqueConstraint('ui_key'),
2356
2da7b5984ae5 typo fix + code garden
Marcin Kuzminski <marcin@python-works.com>
parents: 2352
diff changeset
328 {'extend_existing': True, 'mysql_engine': 'InnoDB',
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
329 'mysql_charset': 'utf8', 'sqlite_autoincrement': True}
1958
7e4b3d3a9c5c renamed repo groups table
Marcin Kuzminski <marcin@python-works.com>
parents: 1950
diff changeset
330 )
1460
b50348816a80 Added more advanced hook management into rhodecode admin settings
Marcin Kuzminski <marcin@python-works.com>
parents: 1436
diff changeset
331
b50348816a80 Added more advanced hook management into rhodecode admin settings
Marcin Kuzminski <marcin@python-works.com>
parents: 1436
diff changeset
332 HOOK_UPDATE = 'changegroup.update'
b50348816a80 Added more advanced hook management into rhodecode admin settings
Marcin Kuzminski <marcin@python-works.com>
parents: 1436
diff changeset
333 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
334 HOOK_PUSH = 'changegroup.push_logger'
2726
aa17c7a1b8a5 Implemented basic locking functionality.
Marcin Kuzminski <marcin@python-works.com>
parents: 2724
diff changeset
335 HOOK_PRE_PUSH = 'prechangegroup.pre_push'
aa17c7a1b8a5 Implemented basic locking functionality.
Marcin Kuzminski <marcin@python-works.com>
parents: 2724
diff changeset
336 HOOK_PULL = 'outgoing.pull_logger'
aa17c7a1b8a5 Implemented basic locking functionality.
Marcin Kuzminski <marcin@python-works.com>
parents: 2724
diff changeset
337 HOOK_PRE_PULL = 'preoutgoing.pre_pull'
1460
b50348816a80 Added more advanced hook management into rhodecode admin settings
Marcin Kuzminski <marcin@python-works.com>
parents: 1436
diff changeset
338
1594
9dae92a65e40 fixes #288
Marcin Kuzminski <marcin@python-works.com>
parents: 1593
diff changeset
339 ui_id = Column("ui_id", Integer(), nullable=False, unique=True, default=None, primary_key=True)
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
340 ui_section = Column("ui_section", String(255, convert_unicode=False), nullable=True, unique=None, default=None)
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
341 ui_key = Column("ui_key", String(255, convert_unicode=False), nullable=True, unique=None, default=None)
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
342 ui_value = Column("ui_value", String(255, convert_unicode=False), nullable=True, unique=None, default=None)
1594
9dae92a65e40 fixes #288
Marcin Kuzminski <marcin@python-works.com>
parents: 1593
diff changeset
343 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
344
3909
e87298ccdfdb Add default for dashbord items and create default
Marcin Kuzminski <marcin@python-works.com>
parents: 3870
diff changeset
345 # def __init__(self, section='', key='', value=''):
e87298ccdfdb Add default for dashbord items and create default
Marcin Kuzminski <marcin@python-works.com>
parents: 3870
diff changeset
346 # self.ui_section = section
e87298ccdfdb Add default for dashbord items and create default
Marcin Kuzminski <marcin@python-works.com>
parents: 3870
diff changeset
347 # self.ui_key = key
e87298ccdfdb Add default for dashbord items and create default
Marcin Kuzminski <marcin@python-works.com>
parents: 3870
diff changeset
348 # self.ui_value = value
e87298ccdfdb Add default for dashbord items and create default
Marcin Kuzminski <marcin@python-works.com>
parents: 3870
diff changeset
349
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
350 @classmethod
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
351 def get_by_key(cls, key):
2708
9bce679a3f49 Added form for controlling mercurial extensions
Marcin Kuzminski <marcin@python-works.com>
parents: 2689
diff changeset
352 return cls.query().filter(cls.ui_key == key).scalar()
1345
3bce31f026b8 #47 implemented Adding of new repo_groups+forms+validators. Fixed sorting of repo groups by main names in multiple locations. Removed some unneeded calls to self.sa for exchange to .query() methods.
Marcin Kuzminski <marcin@python-works.com>
parents: 1343
diff changeset
353
1460
b50348816a80 Added more advanced hook management into rhodecode admin settings
Marcin Kuzminski <marcin@python-works.com>
parents: 1436
diff changeset
354 @classmethod
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
355 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
356 q = cls.query()
2726
aa17c7a1b8a5 Implemented basic locking functionality.
Marcin Kuzminski <marcin@python-works.com>
parents: 2724
diff changeset
357 q = q.filter(cls.ui_key.in_([cls.HOOK_UPDATE, cls.HOOK_REPO_SIZE,
aa17c7a1b8a5 Implemented basic locking functionality.
Marcin Kuzminski <marcin@python-works.com>
parents: 2724
diff changeset
358 cls.HOOK_PUSH, cls.HOOK_PRE_PUSH,
aa17c7a1b8a5 Implemented basic locking functionality.
Marcin Kuzminski <marcin@python-works.com>
parents: 2724
diff changeset
359 cls.HOOK_PULL, cls.HOOK_PRE_PULL]))
1460
b50348816a80 Added more advanced hook management into rhodecode admin settings
Marcin Kuzminski <marcin@python-works.com>
parents: 1436
diff changeset
360 return q.all()
b50348816a80 Added more advanced hook management into rhodecode admin settings
Marcin Kuzminski <marcin@python-works.com>
parents: 1436
diff changeset
361
b50348816a80 Added more advanced hook management into rhodecode admin settings
Marcin Kuzminski <marcin@python-works.com>
parents: 1436
diff changeset
362 @classmethod
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
363 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
364 q = cls.query()
2726
aa17c7a1b8a5 Implemented basic locking functionality.
Marcin Kuzminski <marcin@python-works.com>
parents: 2724
diff changeset
365 q = q.filter(~cls.ui_key.in_([cls.HOOK_UPDATE, cls.HOOK_REPO_SIZE,
aa17c7a1b8a5 Implemented basic locking functionality.
Marcin Kuzminski <marcin@python-works.com>
parents: 2724
diff changeset
366 cls.HOOK_PUSH, cls.HOOK_PRE_PUSH,
aa17c7a1b8a5 Implemented basic locking functionality.
Marcin Kuzminski <marcin@python-works.com>
parents: 2724
diff changeset
367 cls.HOOK_PULL, cls.HOOK_PRE_PULL]))
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
368 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
369 return q.all()
b50348816a80 Added more advanced hook management into rhodecode admin settings
Marcin Kuzminski <marcin@python-works.com>
parents: 1436
diff changeset
370
b50348816a80 Added more advanced hook management into rhodecode admin settings
Marcin Kuzminski <marcin@python-works.com>
parents: 1436
diff changeset
371 @classmethod
2401
e2af60e480ce Removed hardcoded hooks names from settings.
Marcin Kuzminski <marcin@python-works.com>
parents: 2400
diff changeset
372 def get_repos_location(cls):
2708
9bce679a3f49 Added form for controlling mercurial extensions
Marcin Kuzminski <marcin@python-works.com>
parents: 2689
diff changeset
373 return cls.get_by_key('/').ui_value
2401
e2af60e480ce Removed hardcoded hooks names from settings.
Marcin Kuzminski <marcin@python-works.com>
parents: 2400
diff changeset
374
e2af60e480ce Removed hardcoded hooks names from settings.
Marcin Kuzminski <marcin@python-works.com>
parents: 2400
diff changeset
375 @classmethod
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
376 def create_or_update_hook(cls, key, val):
2708
9bce679a3f49 Added form for controlling mercurial extensions
Marcin Kuzminski <marcin@python-works.com>
parents: 2689
diff changeset
377 new_ui = cls.get_by_key(key) or cls()
1460
b50348816a80 Added more advanced hook management into rhodecode admin settings
Marcin Kuzminski <marcin@python-works.com>
parents: 1436
diff changeset
378 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
379 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
380 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
381 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
382
2520
a1e156503afe Fixed calls to Session in db model
Marcin Kuzminski <marcin@python-works.com>
parents: 2510
diff changeset
383 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
384
2821
9c90be87ae05 fixed issue #560 require push ssl checkbox wasn't shown when option was enabled
Marcin Kuzminski <marcin@python-works.com>
parents: 2809
diff changeset
385 def __repr__(self):
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
386 return '<%s[%s]%s=>%s]>' % (self.__class__.__name__, self.ui_section,
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
387 self.ui_key, self.ui_value)
2821
9c90be87ae05 fixed issue #560 require push ssl checkbox wasn't shown when option was enabled
Marcin Kuzminski <marcin@python-works.com>
parents: 2809
diff changeset
388
1460
b50348816a80 Added more advanced hook management into rhodecode admin settings
Marcin Kuzminski <marcin@python-works.com>
parents: 1436
diff changeset
389
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
390 class User(Base, BaseModel):
49
3ada2f409c1c Added sqlalchemy support
Marcin Kuzminski <marcin@python-blog.com>
parents:
diff changeset
391 __tablename__ = 'users'
1958
7e4b3d3a9c5c renamed repo groups table
Marcin Kuzminski <marcin@python-works.com>
parents: 1950
diff changeset
392 __table_args__ = (
1963
9bbde54232dc white space cleanup
Marcin Kuzminski <marcin@python-works.com>
parents: 1960
diff changeset
393 UniqueConstraint('username'), UniqueConstraint('email'),
2726
aa17c7a1b8a5 Implemented basic locking functionality.
Marcin Kuzminski <marcin@python-works.com>
parents: 2724
diff changeset
394 Index('u_username_idx', 'username'),
aa17c7a1b8a5 Implemented basic locking functionality.
Marcin Kuzminski <marcin@python-works.com>
parents: 2724
diff changeset
395 Index('u_email_idx', 'email'),
2356
2da7b5984ae5 typo fix + code garden
Marcin Kuzminski <marcin@python-works.com>
parents: 2352
diff changeset
396 {'extend_existing': True, 'mysql_engine': 'InnoDB',
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
397 'mysql_charset': 'utf8', 'sqlite_autoincrement': True}
1958
7e4b3d3a9c5c renamed repo groups table
Marcin Kuzminski <marcin@python-works.com>
parents: 1950
diff changeset
398 )
2726
aa17c7a1b8a5 Implemented basic locking functionality.
Marcin Kuzminski <marcin@python-works.com>
parents: 2724
diff changeset
399 DEFAULT_USER = 'default'
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
400 DEFAULT_GRAVATAR_URL = 'https://secure.gravatar.com/avatar/{md5email}?d=identicon&s={size}'
3733
af049a957506 fixed default permissions population during upgrades
Marcin Kuzminski <marcin@python-works.com>
parents: 3729
diff changeset
401
1594
9dae92a65e40 fixes #288
Marcin Kuzminski <marcin@python-works.com>
parents: 1593
diff changeset
402 user_id = Column("user_id", Integer(), nullable=False, unique=True, default=None, primary_key=True)
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
403 username = Column("username", String(255, convert_unicode=False), nullable=True, unique=None, default=None)
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
404 password = Column("password", String(255, convert_unicode=False), 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
405 active = Column("active", Boolean(), nullable=True, unique=None, default=True)
1594
9dae92a65e40 fixes #288
Marcin Kuzminski <marcin@python-works.com>
parents: 1593
diff changeset
406 admin = Column("admin", Boolean(), nullable=True, unique=None, default=False)
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
407 name = Column("firstname", String(255, convert_unicode=False), nullable=True, unique=None, default=None)
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
408 lastname = Column("lastname", String(255, convert_unicode=False), nullable=True, unique=None, default=None)
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
409 _email = Column("email", String(255, convert_unicode=False), nullable=True, unique=None, default=None)
1594
9dae92a65e40 fixes #288
Marcin Kuzminski <marcin@python-works.com>
parents: 1593
diff changeset
410 last_login = Column("last_login", DateTime(timezone=False), nullable=True, unique=None, default=None)
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
411 extern_type = Column("extern_type", String(255, convert_unicode=False), nullable=True, unique=None, default=None)
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
412 extern_name = Column("extern_name", String(255, convert_unicode=False), nullable=True, unique=None, default=None)
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
413 api_key = Column("api_key", String(255, convert_unicode=False), nullable=True, unique=None, default=None)
2709
d2d35cf2b351 RhodeCode now has a option to explicitly set forking permissions. ref #508
Marcin Kuzminski <marcin@python-works.com>
parents: 2708
diff changeset
414 inherit_default_permissions = Column("inherit_default_permissions", Boolean(), nullable=False, unique=None, default=True)
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
415 created_on = Column('created_on', DateTime(timezone=False), nullable=False, default=datetime.datetime.now)
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
416 _user_data = Column("user_data", LargeBinary(), nullable=True) # JSON data
631
05528ad948c4 Hacking for git support,and new faster repo scan
Marcin Kuzminski <marcin@python-works.com>
parents: 549
diff changeset
417
3065
09e8623362ef remove not null from user_id column for users log archiving
Marcin Kuzminski <marcin@python-works.com>
parents: 3063
diff changeset
418 user_log = relationship('UserLog')
1594
9dae92a65e40 fixes #288
Marcin Kuzminski <marcin@python-works.com>
parents: 1593
diff changeset
419 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
420
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
421 repositories = relationship('Repository')
1594
9dae92a65e40 fixes #288
Marcin Kuzminski <marcin@python-works.com>
parents: 1593
diff changeset
422 user_followers = relationship('UserFollowing', primaryjoin='UserFollowing.follows_user_id==User.user_id', cascade='all')
3067
9b0636e9b16b fixed issue with cascade deleting of following entries
Marcin Kuzminski <marcin@python-works.com>
parents: 3065
diff changeset
423 followings = relationship('UserFollowing', primaryjoin='UserFollowing.user_id==User.user_id', cascade='all')
9b0636e9b16b fixed issue with cascade deleting of following entries
Marcin Kuzminski <marcin@python-works.com>
parents: 3065
diff changeset
424
1633
2c0d35e336b5 refactoring of models names for repoGroup permissions
Marcin Kuzminski <marcin@python-works.com>
parents: 1607
diff changeset
425 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
426 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
427
3417
fa6ba6727475 further cleanup of UsersGroup
Mads Kiilerich <madski@unity3d.com>
parents: 3416
diff changeset
428 group_member = relationship('UserGroupMember', 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
429
2157
6a2c0cfb018d Cascade delete comments and notifications when removing user.
Marcin Kuzminski <marcin@python-works.com>
parents: 2156
diff changeset
430 notifications = relationship('UserNotification', cascade='all')
6a2c0cfb018d Cascade delete comments and notifications when removing user.
Marcin Kuzminski <marcin@python-works.com>
parents: 2156
diff changeset
431 # notifications assigned to this user
6a2c0cfb018d Cascade delete comments and notifications when removing user.
Marcin Kuzminski <marcin@python-works.com>
parents: 2156
diff changeset
432 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
433 # comments created by this user
6a2c0cfb018d Cascade delete comments and notifications when removing user.
Marcin Kuzminski <marcin@python-works.com>
parents: 2156
diff changeset
434 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
435 #extra emails for this user
78f96d7bb23b cascade delete extra emails on user delete
Marcin Kuzminski <marcin@python-works.com>
parents: 2544
diff changeset
436 user_emails = relationship('UserEmailMap', cascade='all')
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
437 #extra api keys
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
438 user_api_keys = relationship('UserApiKeys', cascade='all')
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
439
1702
8cb7f5c4d494 #302 - basic notification system, models+tests
Marcin Kuzminski <marcin@python-works.com>
parents: 1693
diff changeset
440
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
441 @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
442 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
443 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
444
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
445 @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
446 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
447 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
448
759
a7f50911a945 Models code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 734
diff changeset
449 @property
2731
09d8fec02954 Implemented #532.
Marcin Kuzminski <marcin@python-works.com>
parents: 2726
diff changeset
450 def firstname(self):
09d8fec02954 Implemented #532.
Marcin Kuzminski <marcin@python-works.com>
parents: 2726
diff changeset
451 # alias for future
09d8fec02954 Implemented #532.
Marcin Kuzminski <marcin@python-works.com>
parents: 2726
diff changeset
452 return self.name
09d8fec02954 Implemented #532.
Marcin Kuzminski <marcin@python-works.com>
parents: 2726
diff changeset
453
09d8fec02954 Implemented #532.
Marcin Kuzminski <marcin@python-works.com>
parents: 2726
diff changeset
454 @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
455 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
456 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
457 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
458
7e3e9d0c5575 Add list of all emails that user may have into get_user call
Marcin Kuzminski <marcin@python-works.com>
parents: 2496
diff changeset
459 @property
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
460 def api_keys(self):
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
461 other = UserApiKeys.query().filter(UserApiKeys.user==self).all()
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
462 return [self.api_key] + [x.api_key for x in other]
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
463
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
464 @property
3127
71ce052f8b6b add ipaddresses to repo data on API calls
Marcin Kuzminski <marcin@python-works.com>
parents: 3125
diff changeset
465 def ip_addresses(self):
71ce052f8b6b add ipaddresses to repo data on API calls
Marcin Kuzminski <marcin@python-works.com>
parents: 3125
diff changeset
466 ret = UserIpMap.query().filter(UserIpMap.user == self).all()
71ce052f8b6b add ipaddresses to repo data on API calls
Marcin Kuzminski <marcin@python-works.com>
parents: 3125
diff changeset
467 return [x.ip_addr for x in ret]
71ce052f8b6b add ipaddresses to repo data on API calls
Marcin Kuzminski <marcin@python-works.com>
parents: 3125
diff changeset
468
71ce052f8b6b add ipaddresses to repo data on API calls
Marcin Kuzminski <marcin@python-works.com>
parents: 3125
diff changeset
469 @property
2731
09d8fec02954 Implemented #532.
Marcin Kuzminski <marcin@python-works.com>
parents: 2726
diff changeset
470 def username_and_name(self):
09d8fec02954 Implemented #532.
Marcin Kuzminski <marcin@python-works.com>
parents: 2726
diff changeset
471 return '%s (%s %s)' % (self.username, self.firstname, self.lastname)
09d8fec02954 Implemented #532.
Marcin Kuzminski <marcin@python-works.com>
parents: 2726
diff changeset
472
09d8fec02954 Implemented #532.
Marcin Kuzminski <marcin@python-works.com>
parents: 2726
diff changeset
473 @property
1731
31e6eb2fb4b2 implements #222 registration feedback
Marcin Kuzminski <marcin@python-works.com>
parents: 1729
diff changeset
474 def full_name(self):
2731
09d8fec02954 Implemented #532.
Marcin Kuzminski <marcin@python-works.com>
parents: 2726
diff changeset
475 return '%s %s' % (self.firstname, self.lastname)
1731
31e6eb2fb4b2 implements #222 registration feedback
Marcin Kuzminski <marcin@python-works.com>
parents: 1729
diff changeset
476
31e6eb2fb4b2 implements #222 registration feedback
Marcin Kuzminski <marcin@python-works.com>
parents: 1729
diff changeset
477 @property
1950
4ae17f819ee8 #344 optional firstname lastname on user creation
Marcin Kuzminski <marcin@python-works.com>
parents: 1948
diff changeset
478 def full_name_or_username(self):
2731
09d8fec02954 Implemented #532.
Marcin Kuzminski <marcin@python-works.com>
parents: 2726
diff changeset
479 return ('%s %s' % (self.firstname, self.lastname)
09d8fec02954 Implemented #532.
Marcin Kuzminski <marcin@python-works.com>
parents: 2726
diff changeset
480 if (self.firstname and self.lastname) else self.username)
1950
4ae17f819ee8 #344 optional firstname lastname on user creation
Marcin Kuzminski <marcin@python-works.com>
parents: 1948
diff changeset
481
4ae17f819ee8 #344 optional firstname lastname on user creation
Marcin Kuzminski <marcin@python-works.com>
parents: 1948
diff changeset
482 @property
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
483 def full_contact(self):
2731
09d8fec02954 Implemented #532.
Marcin Kuzminski <marcin@python-works.com>
parents: 2726
diff changeset
484 return '%s %s <%s>' % (self.firstname, self.lastname, self.email)
631
05528ad948c4 Hacking for git support,and new faster repo scan
Marcin Kuzminski <marcin@python-works.com>
parents: 549
diff changeset
485
895
62c04c5cc971 Added some more details into user edit permissions view
Marcin Kuzminski <marcin@python-works.com>
parents: 880
diff changeset
486 @property
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
487 def short_contact(self):
2731
09d8fec02954 Implemented #532.
Marcin Kuzminski <marcin@python-works.com>
parents: 2726
diff changeset
488 return '%s %s' % (self.firstname, self.lastname)
1088
fee472613dfa made simple global rss and atom feed
Marcin Kuzminski <marcin@python-works.com>
parents: 1081
diff changeset
489
fee472613dfa made simple global rss and atom feed
Marcin Kuzminski <marcin@python-works.com>
parents: 1081
diff changeset
490 @property
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
491 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
492 return self.admin
62c04c5cc971 Added some more details into user edit permissions view
Marcin Kuzminski <marcin@python-works.com>
parents: 880
diff changeset
493
3370
fdb0f59b2189 fixes #762, LDAP and container created users are now activated based on
Marcin Kuzminski <marcin@python-works.com>
parents: 3361
diff changeset
494 @property
fdb0f59b2189 fixes #762, LDAP and container created users are now activated based on
Marcin Kuzminski <marcin@python-works.com>
parents: 3361
diff changeset
495 def AuthUser(self):
fdb0f59b2189 fixes #762, LDAP and container created users are now activated based on
Marcin Kuzminski <marcin@python-works.com>
parents: 3361
diff changeset
496 """
fdb0f59b2189 fixes #762, LDAP and container created users are now activated based on
Marcin Kuzminski <marcin@python-works.com>
parents: 3361
diff changeset
497 Returns instance of AuthUser for this user
fdb0f59b2189 fixes #762, LDAP and container created users are now activated based on
Marcin Kuzminski <marcin@python-works.com>
parents: 3361
diff changeset
498 """
fdb0f59b2189 fixes #762, LDAP and container created users are now activated based on
Marcin Kuzminski <marcin@python-works.com>
parents: 3361
diff changeset
499 from rhodecode.lib.auth import AuthUser
fdb0f59b2189 fixes #762, LDAP and container created users are now activated based on
Marcin Kuzminski <marcin@python-works.com>
parents: 3361
diff changeset
500 return AuthUser(user_id=self.user_id, api_key=self.api_key,
fdb0f59b2189 fixes #762, LDAP and container created users are now activated based on
Marcin Kuzminski <marcin@python-works.com>
parents: 3361
diff changeset
501 username=self.username)
fdb0f59b2189 fixes #762, LDAP and container created users are now activated based on
Marcin Kuzminski <marcin@python-works.com>
parents: 3361
diff changeset
502
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
503 @hybrid_property
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
504 def user_data(self):
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
505 if not self._user_data:
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
506 return {}
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
507
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
508 try:
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
509 return json.loads(self._user_data)
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
510 except TypeError:
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
511 return {}
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
512
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
513 @user_data.setter
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
514 def user_data(self, val):
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
515 try:
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
516 self._user_data = json.dumps(val)
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
517 except Exception:
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
518 log.error(traceback.format_exc())
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
519
2156
a27e4d44237e Use __unicode__ instead of __repr__ in models.
Marcin Kuzminski <marcin@python-works.com>
parents: 2152
diff changeset
520 def __unicode__(self):
a27e4d44237e Use __unicode__ instead of __repr__ in models.
Marcin Kuzminski <marcin@python-works.com>
parents: 2152
diff changeset
521 return u"<%s('id:%s:%s')>" % (self.__class__.__name__,
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
522 self.user_id, self.username)
1712
cac5109ac3b6 Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents: 1703
diff changeset
523
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
524 @classmethod
1665
36f77a46f291 Added cache options to some db getters
Marcin Kuzminski <marcin@python-works.com>
parents: 1634
diff changeset
525 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
526 if case_insensitive:
1665
36f77a46f291 Added cache options to some db getters
Marcin Kuzminski <marcin@python-works.com>
parents: 1634
diff changeset
527 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
528 else:
1665
36f77a46f291 Added cache options to some db getters
Marcin Kuzminski <marcin@python-works.com>
parents: 1634
diff changeset
529 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
530
36f77a46f291 Added cache options to some db getters
Marcin Kuzminski <marcin@python-works.com>
parents: 1634
diff changeset
531 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
532 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
533 "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
534 "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
535 )
bf8ed0adbc66 fixes #371 fixed issues with beaker/sqlalchemy and non-ascii cache keys
Marcin Kuzminski <marcin@python-works.com>
parents: 2058
diff changeset
536 )
1665
36f77a46f291 Added cache options to some db getters
Marcin Kuzminski <marcin@python-works.com>
parents: 1634
diff changeset
537 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
538
1417
5875955def39 fixes #223 improve password reset form
Marcin Kuzminski <marcin@python-works.com>
parents: 1401
diff changeset
539 @classmethod
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
540 def get_by_api_key(cls, api_key, cache=False, fallback=True):
1665
36f77a46f291 Added cache options to some db getters
Marcin Kuzminski <marcin@python-works.com>
parents: 1634
diff changeset
541 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
542
36f77a46f291 Added cache options to some db getters
Marcin Kuzminski <marcin@python-works.com>
parents: 1634
diff changeset
543 if cache:
36f77a46f291 Added cache options to some db getters
Marcin Kuzminski <marcin@python-works.com>
parents: 1634
diff changeset
544 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
545 "get_api_key_%s" % api_key))
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
546 res = q.scalar()
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
547
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
548 if fallback and not res:
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
549 #fallback to additional keys
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
550 _res = UserApiKeys.query()\
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
551 .filter(UserApiKeys.api_key == api_key)\
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
552 .filter(or_(UserApiKeys.expires == -1,
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
553 UserApiKeys.expires >= time.time()))\
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
554 .first()
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
555 if _res:
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
556 res = _res.user
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
557 return res
1417
5875955def39 fixes #223 improve password reset form
Marcin Kuzminski <marcin@python-works.com>
parents: 1401
diff changeset
558
1716
7d1fc253549e notification to commit author + gardening
Marcin Kuzminski <marcin@python-works.com>
parents: 1713
diff changeset
559 @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
560 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
561 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
562 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
563 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
564 q = cls.query().filter(cls.email == email)
1716
7d1fc253549e notification to commit author + gardening
Marcin Kuzminski <marcin@python-works.com>
parents: 1713
diff changeset
565
7d1fc253549e notification to commit author + gardening
Marcin Kuzminski <marcin@python-works.com>
parents: 1713
diff changeset
566 if cache:
7d1fc253549e notification to commit author + gardening
Marcin Kuzminski <marcin@python-works.com>
parents: 1713
diff changeset
567 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
568 "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
569
20e307d5250f Added email-map for alternative email addresses for users
Marcin Kuzminski <marcin@python-works.com>
parents: 2296
diff changeset
570 ret = q.scalar()
20e307d5250f Added email-map for alternative email addresses for users
Marcin Kuzminski <marcin@python-works.com>
parents: 2296
diff changeset
571 if ret is None:
20e307d5250f Added email-map for alternative email addresses for users
Marcin Kuzminski <marcin@python-works.com>
parents: 2296
diff changeset
572 q = UserEmailMap.query()
20e307d5250f Added email-map for alternative email addresses for users
Marcin Kuzminski <marcin@python-works.com>
parents: 2296
diff changeset
573 # 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
574 if case_insensitive:
20e307d5250f Added email-map for alternative email addresses for users
Marcin Kuzminski <marcin@python-works.com>
parents: 2296
diff changeset
575 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
576 else:
20e307d5250f Added email-map for alternative email addresses for users
Marcin Kuzminski <marcin@python-works.com>
parents: 2296
diff changeset
577 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
578 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
579 if cache:
20e307d5250f Added email-map for alternative email addresses for users
Marcin Kuzminski <marcin@python-works.com>
parents: 2296
diff changeset
580 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
581 "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
582 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
583
20e307d5250f Added email-map for alternative email addresses for users
Marcin Kuzminski <marcin@python-works.com>
parents: 2296
diff changeset
584 return ret
1716
7d1fc253549e notification to commit author + gardening
Marcin Kuzminski <marcin@python-works.com>
parents: 1713
diff changeset
585
3185
a665d8cdd351 improved extraction of user from changeset when sending notification.
Marcin Kuzminski <marcin@python-works.com>
parents: 3174
diff changeset
586 @classmethod
a665d8cdd351 improved extraction of user from changeset when sending notification.
Marcin Kuzminski <marcin@python-works.com>
parents: 3174
diff changeset
587 def get_from_cs_author(cls, author):
a665d8cdd351 improved extraction of user from changeset when sending notification.
Marcin Kuzminski <marcin@python-works.com>
parents: 3174
diff changeset
588 """
a665d8cdd351 improved extraction of user from changeset when sending notification.
Marcin Kuzminski <marcin@python-works.com>
parents: 3174
diff changeset
589 Tries to get User objects out of commit author string
a665d8cdd351 improved extraction of user from changeset when sending notification.
Marcin Kuzminski <marcin@python-works.com>
parents: 3174
diff changeset
590
a665d8cdd351 improved extraction of user from changeset when sending notification.
Marcin Kuzminski <marcin@python-works.com>
parents: 3174
diff changeset
591 :param author:
a665d8cdd351 improved extraction of user from changeset when sending notification.
Marcin Kuzminski <marcin@python-works.com>
parents: 3174
diff changeset
592 """
a665d8cdd351 improved extraction of user from changeset when sending notification.
Marcin Kuzminski <marcin@python-works.com>
parents: 3174
diff changeset
593 from rhodecode.lib.helpers import email, author_name
a665d8cdd351 improved extraction of user from changeset when sending notification.
Marcin Kuzminski <marcin@python-works.com>
parents: 3174
diff changeset
594 # Valid email in the attribute passed, see if they're in the system
a665d8cdd351 improved extraction of user from changeset when sending notification.
Marcin Kuzminski <marcin@python-works.com>
parents: 3174
diff changeset
595 _email = email(author)
a665d8cdd351 improved extraction of user from changeset when sending notification.
Marcin Kuzminski <marcin@python-works.com>
parents: 3174
diff changeset
596 if _email:
a665d8cdd351 improved extraction of user from changeset when sending notification.
Marcin Kuzminski <marcin@python-works.com>
parents: 3174
diff changeset
597 user = cls.get_by_email(_email, case_insensitive=True)
a665d8cdd351 improved extraction of user from changeset when sending notification.
Marcin Kuzminski <marcin@python-works.com>
parents: 3174
diff changeset
598 if user:
a665d8cdd351 improved extraction of user from changeset when sending notification.
Marcin Kuzminski <marcin@python-works.com>
parents: 3174
diff changeset
599 return user
a665d8cdd351 improved extraction of user from changeset when sending notification.
Marcin Kuzminski <marcin@python-works.com>
parents: 3174
diff changeset
600 # Maybe we can match by username?
a665d8cdd351 improved extraction of user from changeset when sending notification.
Marcin Kuzminski <marcin@python-works.com>
parents: 3174
diff changeset
601 _author = author_name(author)
a665d8cdd351 improved extraction of user from changeset when sending notification.
Marcin Kuzminski <marcin@python-works.com>
parents: 3174
diff changeset
602 user = cls.get_by_username(_author, case_insensitive=True)
a665d8cdd351 improved extraction of user from changeset when sending notification.
Marcin Kuzminski <marcin@python-works.com>
parents: 3174
diff changeset
603 if user:
a665d8cdd351 improved extraction of user from changeset when sending notification.
Marcin Kuzminski <marcin@python-works.com>
parents: 3174
diff changeset
604 return user
a665d8cdd351 improved extraction of user from changeset when sending notification.
Marcin Kuzminski <marcin@python-works.com>
parents: 3174
diff changeset
605
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
606 def update_lastlogin(self):
442
d66a7fa7689b moved loged in user propagation out of forms,
Marcin Kuzminski <marcin@python-works.com>
parents: 417
diff changeset
607 """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
608 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
609 Session().add(self)
1976
Marcin Kuzminski <marcin@python-works.com>
parents: 1963
diff changeset
610 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
611
3714
7e3d89d9d3a2 - Manage Userโ€™s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents: 3687
diff changeset
612 @classmethod
7e3d89d9d3a2 - Manage Userโ€™s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents: 3687
diff changeset
613 def get_first_admin(cls):
7e3d89d9d3a2 - Manage Userโ€™s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents: 3687
diff changeset
614 user = User.query().filter(User.admin == True).first()
7e3d89d9d3a2 - Manage Userโ€™s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents: 3687
diff changeset
615 if user is None:
7e3d89d9d3a2 - Manage Userโ€™s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents: 3687
diff changeset
616 raise Exception('Missing administrative account!')
7e3d89d9d3a2 - Manage Userโ€™s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents: 3687
diff changeset
617 return user
7e3d89d9d3a2 - Manage Userโ€™s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents: 3687
diff changeset
618
3733
af049a957506 fixed default permissions population during upgrades
Marcin Kuzminski <marcin@python-works.com>
parents: 3729
diff changeset
619 @classmethod
af049a957506 fixed default permissions population during upgrades
Marcin Kuzminski <marcin@python-works.com>
parents: 3729
diff changeset
620 def get_default_user(cls, cache=False):
af049a957506 fixed default permissions population during upgrades
Marcin Kuzminski <marcin@python-works.com>
parents: 3729
diff changeset
621 user = User.get_by_username(User.DEFAULT_USER, cache=cache)
af049a957506 fixed default permissions population during upgrades
Marcin Kuzminski <marcin@python-works.com>
parents: 3729
diff changeset
622 if user is None:
af049a957506 fixed default permissions population during upgrades
Marcin Kuzminski <marcin@python-works.com>
parents: 3729
diff changeset
623 raise Exception('Missing default account!')
af049a957506 fixed default permissions population during upgrades
Marcin Kuzminski <marcin@python-works.com>
parents: 3729
diff changeset
624 return user
af049a957506 fixed default permissions population during upgrades
Marcin Kuzminski <marcin@python-works.com>
parents: 3729
diff changeset
625
2508
43cb5b6047fd Added functions for getting API data to repo and user models
Marcin Kuzminski <marcin@python-works.com>
parents: 2506
diff changeset
626 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
627 """
43cb5b6047fd Added functions for getting API data to repo and user models
Marcin Kuzminski <marcin@python-works.com>
parents: 2506
diff changeset
628 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
629 """
43cb5b6047fd Added functions for getting API data to repo and user models
Marcin Kuzminski <marcin@python-works.com>
parents: 2506
diff changeset
630 user = self
43cb5b6047fd Added functions for getting API data to repo and user models
Marcin Kuzminski <marcin@python-works.com>
parents: 2506
diff changeset
631 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
632 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
633 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
634 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
635 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
636 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
637 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
638 api_key=user.api_key,
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
639 api_keys=user.api_keys,
2508
43cb5b6047fd Added functions for getting API data to repo and user models
Marcin Kuzminski <marcin@python-works.com>
parents: 2506
diff changeset
640 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
641 admin=user.admin,
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
642 extern_type=user.extern_type,
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
643 extern_name=user.extern_name,
2508
43cb5b6047fd Added functions for getting API data to repo and user models
Marcin Kuzminski <marcin@python-works.com>
parents: 2506
diff changeset
644 last_login=user.last_login,
3127
71ce052f8b6b add ipaddresses to repo data on API calls
Marcin Kuzminski <marcin@python-works.com>
parents: 3125
diff changeset
645 ip_addresses=user.ip_addresses
2508
43cb5b6047fd Added functions for getting API data to repo and user models
Marcin Kuzminski <marcin@python-works.com>
parents: 2506
diff changeset
646 )
43cb5b6047fd Added functions for getting API data to repo and user models
Marcin Kuzminski <marcin@python-works.com>
parents: 2506
diff changeset
647 return data
43cb5b6047fd Added functions for getting API data to repo and user models
Marcin Kuzminski <marcin@python-works.com>
parents: 2506
diff changeset
648
1758
a87aa385f21c fixed repo_create permission by adding missing commit statements
Marcin Kuzminski <marcin@python-works.com>
parents: 1757
diff changeset
649 def __json__(self):
2544
6ce3387bf0ce Renamed name to firstname in forms
Marcin Kuzminski <marcin@python-works.com>
parents: 2542
diff changeset
650 data = dict(
1950
4ae17f819ee8 #344 optional firstname lastname on user creation
Marcin Kuzminski <marcin@python-works.com>
parents: 1948
diff changeset
651 full_name=self.full_name,
4ae17f819ee8 #344 optional firstname lastname on user creation
Marcin Kuzminski <marcin@python-works.com>
parents: 1948
diff changeset
652 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
653 short_contact=self.short_contact,
4ae17f819ee8 #344 optional firstname lastname on user creation
Marcin Kuzminski <marcin@python-works.com>
parents: 1948
diff changeset
654 full_contact=self.full_contact
4ae17f819ee8 #344 optional firstname lastname on user creation
Marcin Kuzminski <marcin@python-works.com>
parents: 1948
diff changeset
655 )
2544
6ce3387bf0ce Renamed name to firstname in forms
Marcin Kuzminski <marcin@python-works.com>
parents: 2542
diff changeset
656 data.update(self.get_api_data())
6ce3387bf0ce Renamed name to firstname in forms
Marcin Kuzminski <marcin@python-works.com>
parents: 2542
diff changeset
657 return data
1758
a87aa385f21c fixed repo_create permission by adding missing commit statements
Marcin Kuzminski <marcin@python-works.com>
parents: 1757
diff changeset
658
a87aa385f21c fixed repo_create permission by adding missing commit statements
Marcin Kuzminski <marcin@python-works.com>
parents: 1757
diff changeset
659
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
660 class UserApiKeys(Base, BaseModel):
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
661 __tablename__ = 'user_api_keys'
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
662 __table_args__ = (
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
663 Index('uak_api_key_idx', 'api_key'),
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
664 Index('uak_api_key_expires_idx', 'api_key', 'expires'),
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
665 UniqueConstraint('api_key'),
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
666 {'extend_existing': True, 'mysql_engine': 'InnoDB',
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
667 'mysql_charset': 'utf8', 'sqlite_autoincrement': True}
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
668 )
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
669 __mapper_args__ = {}
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
670
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
671 user_api_key_id = Column("user_api_key_id", Integer(), nullable=False, unique=True, default=None, primary_key=True)
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
672 user_id = Column("user_id", Integer(), ForeignKey('users.user_id'), nullable=True, unique=None, default=None)
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
673 api_key = Column("api_key", String(255, convert_unicode=False), nullable=False, unique=True)
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
674 description = Column('description', UnicodeText(1024))
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
675 expires = Column('expires', Float(53), nullable=False)
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
676 created_on = Column('created_on', DateTime(timezone=False), nullable=False, default=datetime.datetime.now)
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
677
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
678 user = relationship('User', lazy='joined')
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
679
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
680 @property
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
681 def expired(self):
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
682 if self.expires == -1:
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
683 return False
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
684 return time.time() > self.expires
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
685
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
686
2329
20e307d5250f Added email-map for alternative email addresses for users
Marcin Kuzminski <marcin@python-works.com>
parents: 2296
diff changeset
687 class UserEmailMap(Base, BaseModel):
20e307d5250f Added email-map for alternative email addresses for users
Marcin Kuzminski <marcin@python-works.com>
parents: 2296
diff changeset
688 __tablename__ = 'user_email_map'
20e307d5250f Added email-map for alternative email addresses for users
Marcin Kuzminski <marcin@python-works.com>
parents: 2296
diff changeset
689 __table_args__ = (
2463
b426ecc30319 Added some DB indexes to optimize queries
Marcin Kuzminski <marcin@python-works.com>
parents: 2462
diff changeset
690 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
691 UniqueConstraint('email'),
2463
b426ecc30319 Added some DB indexes to optimize queries
Marcin Kuzminski <marcin@python-works.com>
parents: 2462
diff changeset
692 {'extend_existing': True, 'mysql_engine': 'InnoDB',
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
693 'mysql_charset': 'utf8', 'sqlite_autoincrement': True}
2329
20e307d5250f Added email-map for alternative email addresses for users
Marcin Kuzminski <marcin@python-works.com>
parents: 2296
diff changeset
694 )
20e307d5250f Added email-map for alternative email addresses for users
Marcin Kuzminski <marcin@python-works.com>
parents: 2296
diff changeset
695 __mapper_args__ = {}
20e307d5250f Added email-map for alternative email addresses for users
Marcin Kuzminski <marcin@python-works.com>
parents: 2296
diff changeset
696
20e307d5250f Added email-map for alternative email addresses for users
Marcin Kuzminski <marcin@python-works.com>
parents: 2296
diff changeset
697 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
698 user_id = Column("user_id", Integer(), ForeignKey('users.user_id'), nullable=True, unique=None, default=None)
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
699 _email = Column("email", String(255, convert_unicode=False), nullable=True, unique=False, default=None)
2463
b426ecc30319 Added some DB indexes to optimize queries
Marcin Kuzminski <marcin@python-works.com>
parents: 2462
diff changeset
700 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
701
20e307d5250f Added email-map for alternative email addresses for users
Marcin Kuzminski <marcin@python-works.com>
parents: 2296
diff changeset
702 @validates('_email')
20e307d5250f Added email-map for alternative email addresses for users
Marcin Kuzminski <marcin@python-works.com>
parents: 2296
diff changeset
703 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
704 # 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
705 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
706 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
707 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
708 return email
20e307d5250f Added email-map for alternative email addresses for users
Marcin Kuzminski <marcin@python-works.com>
parents: 2296
diff changeset
709
20e307d5250f Added email-map for alternative email addresses for users
Marcin Kuzminski <marcin@python-works.com>
parents: 2296
diff changeset
710 @hybrid_property
20e307d5250f Added email-map for alternative email addresses for users
Marcin Kuzminski <marcin@python-works.com>
parents: 2296
diff changeset
711 def email(self):
20e307d5250f Added email-map for alternative email addresses for users
Marcin Kuzminski <marcin@python-works.com>
parents: 2296
diff changeset
712 return self._email
20e307d5250f Added email-map for alternative email addresses for users
Marcin Kuzminski <marcin@python-works.com>
parents: 2296
diff changeset
713
20e307d5250f Added email-map for alternative email addresses for users
Marcin Kuzminski <marcin@python-works.com>
parents: 2296
diff changeset
714 @email.setter
20e307d5250f Added email-map for alternative email addresses for users
Marcin Kuzminski <marcin@python-works.com>
parents: 2296
diff changeset
715 def email(self, val):
20e307d5250f Added email-map for alternative email addresses for users
Marcin Kuzminski <marcin@python-works.com>
parents: 2296
diff changeset
716 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
717
20e307d5250f Added email-map for alternative email addresses for users
Marcin Kuzminski <marcin@python-works.com>
parents: 2296
diff changeset
718
3125
9b92cf5a0cca Added UserIpMap interface for allowed IP addresses and IP restriction access
Marcin Kuzminski <marcin@python-works.com>
parents: 3115
diff changeset
719 class UserIpMap(Base, BaseModel):
9b92cf5a0cca Added UserIpMap interface for allowed IP addresses and IP restriction access
Marcin Kuzminski <marcin@python-works.com>
parents: 3115
diff changeset
720 __tablename__ = 'user_ip_map'
9b92cf5a0cca Added UserIpMap interface for allowed IP addresses and IP restriction access
Marcin Kuzminski <marcin@python-works.com>
parents: 3115
diff changeset
721 __table_args__ = (
9b92cf5a0cca Added UserIpMap interface for allowed IP addresses and IP restriction access
Marcin Kuzminski <marcin@python-works.com>
parents: 3115
diff changeset
722 UniqueConstraint('user_id', 'ip_addr'),
9b92cf5a0cca Added UserIpMap interface for allowed IP addresses and IP restriction access
Marcin Kuzminski <marcin@python-works.com>
parents: 3115
diff changeset
723 {'extend_existing': True, 'mysql_engine': 'InnoDB',
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
724 'mysql_charset': 'utf8', 'sqlite_autoincrement': True}
3125
9b92cf5a0cca Added UserIpMap interface for allowed IP addresses and IP restriction access
Marcin Kuzminski <marcin@python-works.com>
parents: 3115
diff changeset
725 )
9b92cf5a0cca Added UserIpMap interface for allowed IP addresses and IP restriction access
Marcin Kuzminski <marcin@python-works.com>
parents: 3115
diff changeset
726 __mapper_args__ = {}
9b92cf5a0cca Added UserIpMap interface for allowed IP addresses and IP restriction access
Marcin Kuzminski <marcin@python-works.com>
parents: 3115
diff changeset
727
9b92cf5a0cca Added UserIpMap interface for allowed IP addresses and IP restriction access
Marcin Kuzminski <marcin@python-works.com>
parents: 3115
diff changeset
728 ip_id = Column("ip_id", Integer(), nullable=False, unique=True, default=None, primary_key=True)
9b92cf5a0cca Added UserIpMap interface for allowed IP addresses and IP restriction access
Marcin Kuzminski <marcin@python-works.com>
parents: 3115
diff changeset
729 user_id = Column("user_id", Integer(), ForeignKey('users.user_id'), nullable=True, unique=None, default=None)
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
730 ip_addr = Column("ip_addr", String(255, convert_unicode=False), nullable=True, unique=False, default=None)
3146
c5169e445fb8 Full IP restrictions enabled
Marcin Kuzminski <marcin@python-works.com>
parents: 3127
diff changeset
731 active = Column("active", Boolean(), nullable=True, unique=None, default=True)
3125
9b92cf5a0cca Added UserIpMap interface for allowed IP addresses and IP restriction access
Marcin Kuzminski <marcin@python-works.com>
parents: 3115
diff changeset
732 user = relationship('User', lazy='joined')
9b92cf5a0cca Added UserIpMap interface for allowed IP addresses and IP restriction access
Marcin Kuzminski <marcin@python-works.com>
parents: 3115
diff changeset
733
9b92cf5a0cca Added UserIpMap interface for allowed IP addresses and IP restriction access
Marcin Kuzminski <marcin@python-works.com>
parents: 3115
diff changeset
734 @classmethod
9b92cf5a0cca Added UserIpMap interface for allowed IP addresses and IP restriction access
Marcin Kuzminski <marcin@python-works.com>
parents: 3115
diff changeset
735 def _get_ip_range(cls, ip_addr):
9b92cf5a0cca Added UserIpMap interface for allowed IP addresses and IP restriction access
Marcin Kuzminski <marcin@python-works.com>
parents: 3115
diff changeset
736 from rhodecode.lib import ipaddr
3212
6c28533d122c IP restrictions now also enabled for IPv6
Marcin Kuzminski <marcin@python-works.com>
parents: 3185
diff changeset
737 net = ipaddr.IPNetwork(address=ip_addr)
3125
9b92cf5a0cca Added UserIpMap interface for allowed IP addresses and IP restriction access
Marcin Kuzminski <marcin@python-works.com>
parents: 3115
diff changeset
738 return [str(net.network), str(net.broadcast)]
9b92cf5a0cca Added UserIpMap interface for allowed IP addresses and IP restriction access
Marcin Kuzminski <marcin@python-works.com>
parents: 3115
diff changeset
739
9b92cf5a0cca Added UserIpMap interface for allowed IP addresses and IP restriction access
Marcin Kuzminski <marcin@python-works.com>
parents: 3115
diff changeset
740 def __json__(self):
9b92cf5a0cca Added UserIpMap interface for allowed IP addresses and IP restriction access
Marcin Kuzminski <marcin@python-works.com>
parents: 3115
diff changeset
741 return dict(
9b92cf5a0cca Added UserIpMap interface for allowed IP addresses and IP restriction access
Marcin Kuzminski <marcin@python-works.com>
parents: 3115
diff changeset
742 ip_addr=self.ip_addr,
9b92cf5a0cca Added UserIpMap interface for allowed IP addresses and IP restriction access
Marcin Kuzminski <marcin@python-works.com>
parents: 3115
diff changeset
743 ip_range=self._get_ip_range(self.ip_addr)
9b92cf5a0cca Added UserIpMap interface for allowed IP addresses and IP restriction access
Marcin Kuzminski <marcin@python-works.com>
parents: 3115
diff changeset
744 )
9b92cf5a0cca Added UserIpMap interface for allowed IP addresses and IP restriction access
Marcin Kuzminski <marcin@python-works.com>
parents: 3115
diff changeset
745
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
746 def __unicode__(self):
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
747 return u"<%s('user_id:%s=>%s')>" % (self.__class__.__name__,
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
748 self.user_id, self.ip_addr)
3125
9b92cf5a0cca Added UserIpMap interface for allowed IP addresses and IP restriction access
Marcin Kuzminski <marcin@python-works.com>
parents: 3115
diff changeset
749
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
750 class UserLog(Base, BaseModel):
49
3ada2f409c1c Added sqlalchemy support
Marcin Kuzminski <marcin@python-blog.com>
parents:
diff changeset
751 __tablename__ = 'user_logs'
2149
50aa7cb78cfe Mysql fixes
Marcin Kuzminski <marcin@python-works.com>
parents: 2147
diff changeset
752 __table_args__ = (
2356
2da7b5984ae5 typo fix + code garden
Marcin Kuzminski <marcin@python-works.com>
parents: 2352
diff changeset
753 {'extend_existing': True, 'mysql_engine': 'InnoDB',
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
754 'mysql_charset': 'utf8', 'sqlite_autoincrement': True},
2149
50aa7cb78cfe Mysql fixes
Marcin Kuzminski <marcin@python-works.com>
parents: 2147
diff changeset
755 )
1594
9dae92a65e40 fixes #288
Marcin Kuzminski <marcin@python-works.com>
parents: 1593
diff changeset
756 user_log_id = Column("user_log_id", Integer(), nullable=False, unique=True, default=None, primary_key=True)
3065
09e8623362ef remove not null from user_id column for users log archiving
Marcin Kuzminski <marcin@python-works.com>
parents: 3063
diff changeset
757 user_id = Column("user_id", Integer(), ForeignKey('users.user_id'), nullable=True, unique=None, default=None)
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
758 username = Column("username", String(255, convert_unicode=False), nullable=True, unique=None, default=None)
1747
8804715404c9 implements #193 journal stores information about deleting of repos
Marcin Kuzminski <marcin@python-works.com>
parents: 1744
diff changeset
759 repository_id = Column("repository_id", Integer(), ForeignKey('repositories.repo_id'), nullable=True)
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
760 repository_name = Column("repository_name", String(255, convert_unicode=False), nullable=True, unique=None, default=None)
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
761 user_ip = Column("user_ip", String(255, convert_unicode=False), nullable=True, unique=None, default=None)
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
762 action = Column("action", UnicodeText(1200000, convert_unicode=False), nullable=True, unique=None, default=None)
1594
9dae92a65e40 fixes #288
Marcin Kuzminski <marcin@python-works.com>
parents: 1593
diff changeset
763 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
764
3868
e262494ca099 store download archive actions in journal
Marcin Kuzminski <marcin@python-works.com>
parents: 3866
diff changeset
765 def __unicode__(self):
e262494ca099 store download archive actions in journal
Marcin Kuzminski <marcin@python-works.com>
parents: 3866
diff changeset
766 return u"<%s('id:%s:%s')>" % (self.__class__.__name__,
e262494ca099 store download archive actions in journal
Marcin Kuzminski <marcin@python-works.com>
parents: 3866
diff changeset
767 self.repository_name,
e262494ca099 store download archive actions in journal
Marcin Kuzminski <marcin@python-works.com>
parents: 3866
diff changeset
768 self.action)
e262494ca099 store download archive actions in journal
Marcin Kuzminski <marcin@python-works.com>
parents: 3866
diff changeset
769
994
7f9d23f6a526 Added grouping by days in journal
Marcin Kuzminski <marcin@python-works.com>
parents: 991
diff changeset
770 @property
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
771 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
772 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
773
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
774 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
775 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
776
956
83d35d716a02 started working on issue #56
Marcin Kuzminski <marcin@python-works.com>
parents: 907
diff changeset
777
3417
fa6ba6727475 further cleanup of UsersGroup
Mads Kiilerich <madski@unity3d.com>
parents: 3416
diff changeset
778 class UserGroup(Base, BaseModel):
956
83d35d716a02 started working on issue #56
Marcin Kuzminski <marcin@python-works.com>
parents: 907
diff changeset
779 __tablename__ = 'users_groups'
2149
50aa7cb78cfe Mysql fixes
Marcin Kuzminski <marcin@python-works.com>
parents: 2147
diff changeset
780 __table_args__ = (
2356
2da7b5984ae5 typo fix + code garden
Marcin Kuzminski <marcin@python-works.com>
parents: 2352
diff changeset
781 {'extend_existing': True, 'mysql_engine': 'InnoDB',
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
782 'mysql_charset': 'utf8', 'sqlite_autoincrement': True},
2149
50aa7cb78cfe Mysql fixes
Marcin Kuzminski <marcin@python-works.com>
parents: 2147
diff changeset
783 )
956
83d35d716a02 started working on issue #56
Marcin Kuzminski <marcin@python-works.com>
parents: 907
diff changeset
784
1594
9dae92a65e40 fixes #288
Marcin Kuzminski <marcin@python-works.com>
parents: 1593
diff changeset
785 users_group_id = Column("users_group_id", Integer(), nullable=False, unique=True, default=None, primary_key=True)
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
786 users_group_name = Column("users_group_name", String(255, convert_unicode=False), nullable=False, unique=True, default=None)
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
787 user_group_description = Column("user_group_description", String(10000, convert_unicode=False), nullable=True, unique=None, default=None)
1594
9dae92a65e40 fixes #288
Marcin Kuzminski <marcin@python-works.com>
parents: 1593
diff changeset
788 users_group_active = Column("users_group_active", Boolean(), nullable=True, unique=None, default=None)
2709
d2d35cf2b351 RhodeCode now has a option to explicitly set forking permissions. ref #508
Marcin Kuzminski <marcin@python-works.com>
parents: 2708
diff changeset
789 inherit_default_permissions = Column("users_group_inherit_default_permissions", Boolean(), nullable=False, unique=None, default=True)
3714
7e3d89d9d3a2 - Manage Userโ€™s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents: 3687
diff changeset
790 user_id = Column("user_id", Integer(), ForeignKey('users.user_id'), nullable=False, unique=False, default=None)
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
791 created_on = Column('created_on', DateTime(timezone=False), nullable=False, default=datetime.datetime.now)
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
792 _group_data = Column("group_data", LargeBinary(), nullable=True) # JSON data
956
83d35d716a02 started working on issue #56
Marcin Kuzminski <marcin@python-works.com>
parents: 907
diff changeset
793
3417
fa6ba6727475 further cleanup of UsersGroup
Mads Kiilerich <madski@unity3d.com>
parents: 3416
diff changeset
794 members = relationship('UserGroupMember', cascade="all, delete, delete-orphan", lazy="joined")
fa6ba6727475 further cleanup of UsersGroup
Mads Kiilerich <madski@unity3d.com>
parents: 3416
diff changeset
795 users_group_to_perm = relationship('UserGroupToPerm', cascade='all')
fa6ba6727475 further cleanup of UsersGroup
Mads Kiilerich <madski@unity3d.com>
parents: 3416
diff changeset
796 users_group_repo_to_perm = relationship('UserGroupRepoToPerm', cascade='all')
3734
a8f520540ab0 New default permissions definition for user group create
Marcin Kuzminski <marcin@python-works.com>
parents: 3733
diff changeset
797 users_group_repo_group_to_perm = relationship('UserGroupRepoGroupToPerm', cascade='all')
3714
7e3d89d9d3a2 - Manage Userโ€™s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents: 3687
diff changeset
798 user_user_group_to_perm = relationship('UserUserGroupToPerm ', cascade='all')
3788
d9b89874edf9 UserGroup on UserGroup permissions implementation.
Marcin Kuzminski <marcin@python-works.com>
parents: 3786
diff changeset
799 user_group_user_group_to_perm = relationship('UserGroupUserGroupToPerm ', primaryjoin="UserGroupUserGroupToPerm.target_user_group_id==UserGroup.users_group_id", cascade='all')
d9b89874edf9 UserGroup on UserGroup permissions implementation.
Marcin Kuzminski <marcin@python-works.com>
parents: 3786
diff changeset
800
3714
7e3d89d9d3a2 - Manage Userโ€™s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents: 3687
diff changeset
801 user = relationship('User')
956
83d35d716a02 started working on issue #56
Marcin Kuzminski <marcin@python-works.com>
parents: 907
diff changeset
802
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
803 @hybrid_property
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
804 def group_data(self):
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
805 if not self._group_data:
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
806 return {}
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
807
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
808 try:
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
809 return json.loads(self._group_data)
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
810 except TypeError:
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
811 return {}
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
812
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
813 @group_data.setter
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
814 def group_data(self, val):
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
815 try:
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
816 self._group_data = json.dumps(val)
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
817 except Exception:
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
818 log.error(traceback.format_exc())
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
819
2156
a27e4d44237e Use __unicode__ instead of __repr__ in models.
Marcin Kuzminski <marcin@python-works.com>
parents: 2152
diff changeset
820 def __unicode__(self):
3714
7e3d89d9d3a2 - Manage Userโ€™s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents: 3687
diff changeset
821 return u"<%s('id:%s:%s')>" % (self.__class__.__name__,
7e3d89d9d3a2 - Manage Userโ€™s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents: 3687
diff changeset
822 self.users_group_id,
7e3d89d9d3a2 - Manage Userโ€™s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents: 3687
diff changeset
823 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
824
aa7e45ad0cea Fixed permissions for users groups, group can have create repo permission now.
Marcin Kuzminski <marcin@python-works.com>
parents: 1266
diff changeset
825 @classmethod
1728
07e56179633e - fixes celery sqlalchemy session issues for async forking
Marcin Kuzminski <marcin@python-works.com>
parents: 1727
diff changeset
826 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
827 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
828 if case_insensitive:
1728
07e56179633e - fixes celery sqlalchemy session issues for async forking
Marcin Kuzminski <marcin@python-works.com>
parents: 1727
diff changeset
829 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
830 else:
1728
07e56179633e - fixes celery sqlalchemy session issues for async forking
Marcin Kuzminski <marcin@python-works.com>
parents: 1727
diff changeset
831 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
832 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
833 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
834 "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
835 "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
836 )
bf8ed0adbc66 fixes #371 fixed issues with beaker/sqlalchemy and non-ascii cache keys
Marcin Kuzminski <marcin@python-works.com>
parents: 2058
diff changeset
837 )
1728
07e56179633e - fixes celery sqlalchemy session issues for async forking
Marcin Kuzminski <marcin@python-works.com>
parents: 1727
diff changeset
838 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
839
1436
88d13c1c6a55 removed users_group controller in replace for model methods,
Marcin Kuzminski <marcin@python-works.com>
parents: 1435
diff changeset
840 @classmethod
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
841 def get(cls, user_group_id, cache=False):
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
842 user_group = cls.query()
1436
88d13c1c6a55 removed users_group controller in replace for model methods,
Marcin Kuzminski <marcin@python-works.com>
parents: 1435
diff changeset
843 if cache:
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
844 user_group = user_group.options(FromCache("sql_cache_short",
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
845 "get_users_group_%s" % user_group_id))
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
846 return user_group.get(user_group_id)
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
847
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
848 def get_api_data(self, with_members=True):
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
849 user_group = self
2523
788ae4f7d8df added get_api_data into UsersGroup
Marcin Kuzminski <marcin@python-works.com>
parents: 2520
diff changeset
850
788ae4f7d8df added get_api_data into UsersGroup
Marcin Kuzminski <marcin@python-works.com>
parents: 2520
diff changeset
851 data = dict(
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
852 users_group_id=user_group.users_group_id,
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
853 group_name=user_group.users_group_name,
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
854 group_description=user_group.user_group_description,
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
855 active=user_group.users_group_active,
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
856 owner=user_group.user.username,
2523
788ae4f7d8df added get_api_data into UsersGroup
Marcin Kuzminski <marcin@python-works.com>
parents: 2520
diff changeset
857 )
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
858 if with_members:
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
859 members = []
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
860 for user in user_group.members:
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
861 user = user.user
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
862 members.append(user.get_api_data())
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
863 data['members'] = members
2523
788ae4f7d8df added get_api_data into UsersGroup
Marcin Kuzminski <marcin@python-works.com>
parents: 2520
diff changeset
864
788ae4f7d8df added get_api_data into UsersGroup
Marcin Kuzminski <marcin@python-works.com>
parents: 2520
diff changeset
865 return data
788ae4f7d8df added get_api_data into UsersGroup
Marcin Kuzminski <marcin@python-works.com>
parents: 2520
diff changeset
866
1800
6c86c987cf93 pep8ify
Marcin Kuzminski <marcin@python-works.com>
parents: 1758
diff changeset
867
3417
fa6ba6727475 further cleanup of UsersGroup
Mads Kiilerich <madski@unity3d.com>
parents: 3416
diff changeset
868 class UserGroupMember(Base, BaseModel):
956
83d35d716a02 started working on issue #56
Marcin Kuzminski <marcin@python-works.com>
parents: 907
diff changeset
869 __tablename__ = 'users_groups_members'
2149
50aa7cb78cfe Mysql fixes
Marcin Kuzminski <marcin@python-works.com>
parents: 2147
diff changeset
870 __table_args__ = (
2356
2da7b5984ae5 typo fix + code garden
Marcin Kuzminski <marcin@python-works.com>
parents: 2352
diff changeset
871 {'extend_existing': True, 'mysql_engine': 'InnoDB',
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
872 'mysql_charset': 'utf8', 'sqlite_autoincrement': True},
2149
50aa7cb78cfe Mysql fixes
Marcin Kuzminski <marcin@python-works.com>
parents: 2147
diff changeset
873 )
956
83d35d716a02 started working on issue #56
Marcin Kuzminski <marcin@python-works.com>
parents: 907
diff changeset
874
1594
9dae92a65e40 fixes #288
Marcin Kuzminski <marcin@python-works.com>
parents: 1593
diff changeset
875 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
876 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
877 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
878
1594
9dae92a65e40 fixes #288
Marcin Kuzminski <marcin@python-works.com>
parents: 1593
diff changeset
879 user = relationship('User', lazy='joined')
3417
fa6ba6727475 further cleanup of UsersGroup
Mads Kiilerich <madski@unity3d.com>
parents: 3416
diff changeset
880 users_group = relationship('UserGroup')
972
2c8fd84935a4 #56 implemented users groups editing,
Marcin Kuzminski <marcin@python-works.com>
parents: 962
diff changeset
881
1594
9dae92a65e40 fixes #288
Marcin Kuzminski <marcin@python-works.com>
parents: 1593
diff changeset
882 def __init__(self, gr_id='', u_id=''):
972
2c8fd84935a4 #56 implemented users groups editing,
Marcin Kuzminski <marcin@python-works.com>
parents: 962
diff changeset
883 self.users_group_id = gr_id
2c8fd84935a4 #56 implemented users groups editing,
Marcin Kuzminski <marcin@python-works.com>
parents: 962
diff changeset
884 self.user_id = u_id
956
83d35d716a02 started working on issue #56
Marcin Kuzminski <marcin@python-works.com>
parents: 907
diff changeset
885
2013
8530c3cd9d04 fixed issue with hybrid property for ldap_active
Marcin Kuzminski <marcin@python-works.com>
parents: 2007
diff changeset
886
3308
72a91632b731 repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents: 3278
diff changeset
887 class RepositoryField(Base, BaseModel):
72a91632b731 repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents: 3278
diff changeset
888 __tablename__ = 'repositories_fields'
72a91632b731 repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents: 3278
diff changeset
889 __table_args__ = (
72a91632b731 repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents: 3278
diff changeset
890 UniqueConstraint('repository_id', 'field_key'), # no-multi field
72a91632b731 repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents: 3278
diff changeset
891 {'extend_existing': True, 'mysql_engine': 'InnoDB',
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
892 'mysql_charset': 'utf8', 'sqlite_autoincrement': True},
3308
72a91632b731 repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents: 3278
diff changeset
893 )
72a91632b731 repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents: 3278
diff changeset
894 PREFIX = 'ex_' # prefix used in form to not conflict with already existing fields
72a91632b731 repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents: 3278
diff changeset
895
72a91632b731 repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents: 3278
diff changeset
896 repo_field_id = Column("repo_field_id", Integer(), nullable=False, unique=True, default=None, primary_key=True)
72a91632b731 repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents: 3278
diff changeset
897 repository_id = Column("repository_id", Integer(), ForeignKey('repositories.repo_id'), nullable=False, unique=None, default=None)
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
898 field_key = Column("field_key", String(250, convert_unicode=False))
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
899 field_label = Column("field_label", String(1024, convert_unicode=False), nullable=False)
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
900 field_value = Column("field_value", String(10000, convert_unicode=False), nullable=False)
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
901 field_desc = Column("field_desc", String(1024, convert_unicode=False), nullable=False)
3308
72a91632b731 repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents: 3278
diff changeset
902 field_type = Column("field_type", String(256), nullable=False, unique=None)
72a91632b731 repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents: 3278
diff changeset
903 created_on = Column('created_on', DateTime(timezone=False), nullable=False, default=datetime.datetime.now)
72a91632b731 repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents: 3278
diff changeset
904
72a91632b731 repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents: 3278
diff changeset
905 repository = relationship('Repository')
72a91632b731 repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents: 3278
diff changeset
906
72a91632b731 repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents: 3278
diff changeset
907 @property
72a91632b731 repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents: 3278
diff changeset
908 def field_key_prefixed(self):
72a91632b731 repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents: 3278
diff changeset
909 return 'ex_%s' % self.field_key
72a91632b731 repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents: 3278
diff changeset
910
72a91632b731 repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents: 3278
diff changeset
911 @classmethod
72a91632b731 repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents: 3278
diff changeset
912 def un_prefix_key(cls, key):
72a91632b731 repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents: 3278
diff changeset
913 if key.startswith(cls.PREFIX):
72a91632b731 repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents: 3278
diff changeset
914 return key[len(cls.PREFIX):]
72a91632b731 repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents: 3278
diff changeset
915 return key
72a91632b731 repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents: 3278
diff changeset
916
72a91632b731 repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents: 3278
diff changeset
917 @classmethod
72a91632b731 repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents: 3278
diff changeset
918 def get_by_key_name(cls, key, repo):
72a91632b731 repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents: 3278
diff changeset
919 row = cls.query()\
72a91632b731 repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents: 3278
diff changeset
920 .filter(cls.repository == repo)\
72a91632b731 repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents: 3278
diff changeset
921 .filter(cls.field_key == key).scalar()
72a91632b731 repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents: 3278
diff changeset
922 return row
72a91632b731 repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents: 3278
diff changeset
923
72a91632b731 repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents: 3278
diff changeset
924
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
925 class Repository(Base, BaseModel):
234
a0116e944da1 changed naming convention for db modules.
Marcin Kuzminski <marcin@python-works.com>
parents: 232
diff changeset
926 __tablename__ = 'repositories'
1958
7e4b3d3a9c5c renamed repo groups table
Marcin Kuzminski <marcin@python-works.com>
parents: 1950
diff changeset
927 __table_args__ = (
1963
9bbde54232dc white space cleanup
Marcin Kuzminski <marcin@python-works.com>
parents: 1960
diff changeset
928 UniqueConstraint('repo_name'),
2726
aa17c7a1b8a5 Implemented basic locking functionality.
Marcin Kuzminski <marcin@python-works.com>
parents: 2724
diff changeset
929 Index('r_repo_name_idx', 'repo_name'),
2356
2da7b5984ae5 typo fix + code garden
Marcin Kuzminski <marcin@python-works.com>
parents: 2352
diff changeset
930 {'extend_existing': True, 'mysql_engine': 'InnoDB',
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
931 'mysql_charset': 'utf8', 'sqlite_autoincrement': True},
1958
7e4b3d3a9c5c renamed repo groups table
Marcin Kuzminski <marcin@python-works.com>
parents: 1950
diff changeset
932 )
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
933 DEFAULT_CLONE_URI = '{scheme}://{user}@{netloc}/{repo}'
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
934 DEFAULT_CLONE_URI_ID = '{scheme}://{user}@{netloc}/_{repoid}'
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
935
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
936 STATE_CREATED = 'repo_state_created'
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
937 STATE_PENDING = 'repo_state_pending'
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
938 STATE_ERROR = 'repo_state_error'
1081
70bf0be59653 fixed Session problems in model class functions
Marcin Kuzminski <marcin@python-works.com>
parents: 1065
diff changeset
939
1594
9dae92a65e40 fixes #288
Marcin Kuzminski <marcin@python-works.com>
parents: 1593
diff changeset
940 repo_id = Column("repo_id", Integer(), nullable=False, unique=True, default=None, primary_key=True)
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
941 repo_name = Column("repo_name", String(255, convert_unicode=False), nullable=False, unique=True, default=None)
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
942 repo_state = Column("repo_state", String(255), nullable=True)
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
943
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
944 clone_uri = Column("clone_uri", String(255, convert_unicode=False), nullable=True, unique=False, default=None)
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
945 repo_type = Column("repo_type", String(255, convert_unicode=False), nullable=False, unique=False, default=None)
1594
9dae92a65e40 fixes #288
Marcin Kuzminski <marcin@python-works.com>
parents: 1593
diff changeset
946 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
947 private = Column("private", Boolean(), nullable=True, unique=None, default=None)
9dae92a65e40 fixes #288
Marcin Kuzminski <marcin@python-works.com>
parents: 1593
diff changeset
948 enable_statistics = Column("statistics", Boolean(), nullable=True, unique=None, default=True)
9dae92a65e40 fixes #288
Marcin Kuzminski <marcin@python-works.com>
parents: 1593
diff changeset
949 enable_downloads = Column("downloads", Boolean(), nullable=True, unique=None, default=True)
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
950 description = Column("description", String(10000, convert_unicode=False), nullable=True, unique=None, default=None)
1594
9dae92a65e40 fixes #288
Marcin Kuzminski <marcin@python-works.com>
parents: 1593
diff changeset
951 created_on = Column('created_on', DateTime(timezone=False), nullable=True, unique=None, default=datetime.datetime.now)
2797
c9baaacb670a Remove null from revision column as for comments inside pull requests to work properly
Marcin Kuzminski <marcin@python-works.com>
parents: 2791
diff changeset
952 updated_on = Column('updated_on', DateTime(timezone=False), nullable=True, unique=None, default=datetime.datetime.now)
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
953 _landing_revision = Column("landing_revision", String(255, convert_unicode=False), nullable=False, unique=False, default=None)
2726
aa17c7a1b8a5 Implemented basic locking functionality.
Marcin Kuzminski <marcin@python-works.com>
parents: 2724
diff changeset
954 enable_locking = Column("enable_locking", Boolean(), nullable=False, unique=None, default=False)
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
955 _locked = Column("locked", String(255, convert_unicode=False), nullable=True, unique=False, default=None)
3147
8182ebed2922 Added full last changeset info to lightweight dashboard
Marcin Kuzminski <marcin@python-works.com>
parents: 3146
diff changeset
956 _changeset_cache = Column("changeset_cache", LargeBinary(), nullable=True) #JSON data
1301
7e75af301842 Added simple forks page, resolves issue #179
Marcin Kuzminski <marcin@python-works.com>
parents: 1292
diff changeset
957
1594
9dae92a65e40 fixes #288
Marcin Kuzminski <marcin@python-works.com>
parents: 1593
diff changeset
958 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
959 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
960
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
961 user = relationship('User')
1594
9dae92a65e40 fixes #288
Marcin Kuzminski <marcin@python-works.com>
parents: 1593
diff changeset
962 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
963 group = relationship('RepoGroup')
2c0d35e336b5 refactoring of models names for repoGroup permissions
Marcin Kuzminski <marcin@python-works.com>
parents: 1607
diff changeset
964 repo_to_perm = relationship('UserRepoToPerm', cascade='all', order_by='UserRepoToPerm.repo_to_perm_id')
3417
fa6ba6727475 further cleanup of UsersGroup
Mads Kiilerich <madski@unity3d.com>
parents: 3416
diff changeset
965 users_group_to_perm = relationship('UserGroupRepoToPerm', cascade='all')
1594
9dae92a65e40 fixes #288
Marcin Kuzminski <marcin@python-works.com>
parents: 1593
diff changeset
966 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
967
2674
a221706dab50 merged + fixed pull request #62: Implemented metatags and visualisation options.
Marcin Kuzminski <marcin@python-works.com>
parents: 2668
diff changeset
968 followers = relationship('UserFollowing',
a221706dab50 merged + fixed pull request #62: Implemented metatags and visualisation options.
Marcin Kuzminski <marcin@python-works.com>
parents: 2668
diff changeset
969 primaryjoin='UserFollowing.follows_repo_id==Repository.repo_id',
2666
c51fb1da6df2 cascade fixes for comments/pull-requests/reviewers
Marcin Kuzminski <marcin@python-works.com>
parents: 2665
diff changeset
970 cascade='all')
3308
72a91632b731 repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents: 3278
diff changeset
971 extra_fields = relationship('RepositoryField',
72a91632b731 repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents: 3278
diff changeset
972 cascade="all, delete, delete-orphan")
734
49eb69d78988 implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents: 713
diff changeset
973
1747
8804715404c9 implements #193 journal stores information about deleting of repos
Marcin Kuzminski <marcin@python-works.com>
parents: 1744
diff changeset
974 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
975 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
976
2666
c51fb1da6df2 cascade fixes for comments/pull-requests/reviewers
Marcin Kuzminski <marcin@python-works.com>
parents: 2665
diff changeset
977 pull_requests_org = relationship('PullRequest',
c51fb1da6df2 cascade fixes for comments/pull-requests/reviewers
Marcin Kuzminski <marcin@python-works.com>
parents: 2665
diff changeset
978 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
979 cascade="all, delete, delete-orphan")
c51fb1da6df2 cascade fixes for comments/pull-requests/reviewers
Marcin Kuzminski <marcin@python-works.com>
parents: 2665
diff changeset
980
c51fb1da6df2 cascade fixes for comments/pull-requests/reviewers
Marcin Kuzminski <marcin@python-works.com>
parents: 2665
diff changeset
981 pull_requests_other = relationship('PullRequest',
c51fb1da6df2 cascade fixes for comments/pull-requests/reviewers
Marcin Kuzminski <marcin@python-works.com>
parents: 2665
diff changeset
982 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
983 cascade="all, delete, delete-orphan")
c51fb1da6df2 cascade fixes for comments/pull-requests/reviewers
Marcin Kuzminski <marcin@python-works.com>
parents: 2665
diff changeset
984
2156
a27e4d44237e Use __unicode__ instead of __repr__ in models.
Marcin Kuzminski <marcin@python-works.com>
parents: 2152
diff changeset
985 def __unicode__(self):
2459
9492ab68331f Initial version of landing revisions ref #483
Marcin Kuzminski <marcin@python-works.com>
parents: 2407
diff changeset
986 return u"<%s('%s:%s')>" % (self.__class__.__name__, self.repo_id,
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
987 safe_unicode(self.repo_name))
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
988
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
989 @hybrid_property
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
990 def landing_rev(self):
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
991 # always should return [rev_type, rev]
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
992 if self._landing_revision:
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
993 _rev_info = self._landing_revision.split(':')
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
994 if len(_rev_info) < 2:
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
995 _rev_info.insert(0, 'rev')
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
996 return [_rev_info[0], _rev_info[1]]
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
997 return [None, None]
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
998
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
999 @landing_rev.setter
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
1000 def landing_rev(self, val):
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
1001 if ':' not in val:
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
1002 raise ValueError('value must be delimited with `:` and consist '
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
1003 'of <rev_type>:<rev>, got %s instead' % val)
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
1004 self._landing_revision = val
878
859bc9e7a15d Extended repo2db mapper with group creation via directory structures
Marcin Kuzminski <marcin@python-works.com>
parents: 836
diff changeset
1005
2726
aa17c7a1b8a5 Implemented basic locking functionality.
Marcin Kuzminski <marcin@python-works.com>
parents: 2724
diff changeset
1006 @hybrid_property
aa17c7a1b8a5 Implemented basic locking functionality.
Marcin Kuzminski <marcin@python-works.com>
parents: 2724
diff changeset
1007 def locked(self):
aa17c7a1b8a5 Implemented basic locking functionality.
Marcin Kuzminski <marcin@python-works.com>
parents: 2724
diff changeset
1008 # always should return [user_id, timelocked]
aa17c7a1b8a5 Implemented basic locking functionality.
Marcin Kuzminski <marcin@python-works.com>
parents: 2724
diff changeset
1009 if self._locked:
aa17c7a1b8a5 Implemented basic locking functionality.
Marcin Kuzminski <marcin@python-works.com>
parents: 2724
diff changeset
1010 _lock_info = self._locked.split(':')
aa17c7a1b8a5 Implemented basic locking functionality.
Marcin Kuzminski <marcin@python-works.com>
parents: 2724
diff changeset
1011 return int(_lock_info[0]), _lock_info[1]
aa17c7a1b8a5 Implemented basic locking functionality.
Marcin Kuzminski <marcin@python-works.com>
parents: 2724
diff changeset
1012 return [None, None]
aa17c7a1b8a5 Implemented basic locking functionality.
Marcin Kuzminski <marcin@python-works.com>
parents: 2724
diff changeset
1013
aa17c7a1b8a5 Implemented basic locking functionality.
Marcin Kuzminski <marcin@python-works.com>
parents: 2724
diff changeset
1014 @locked.setter
aa17c7a1b8a5 Implemented basic locking functionality.
Marcin Kuzminski <marcin@python-works.com>
parents: 2724
diff changeset
1015 def locked(self, val):
aa17c7a1b8a5 Implemented basic locking functionality.
Marcin Kuzminski <marcin@python-works.com>
parents: 2724
diff changeset
1016 if val and isinstance(val, (list, tuple)):
aa17c7a1b8a5 Implemented basic locking functionality.
Marcin Kuzminski <marcin@python-works.com>
parents: 2724
diff changeset
1017 self._locked = ':'.join(map(str, val))
aa17c7a1b8a5 Implemented basic locking functionality.
Marcin Kuzminski <marcin@python-works.com>
parents: 2724
diff changeset
1018 else:
aa17c7a1b8a5 Implemented basic locking functionality.
Marcin Kuzminski <marcin@python-works.com>
parents: 2724
diff changeset
1019 self._locked = None
aa17c7a1b8a5 Implemented basic locking functionality.
Marcin Kuzminski <marcin@python-works.com>
parents: 2724
diff changeset
1020
3147
8182ebed2922 Added full last changeset info to lightweight dashboard
Marcin Kuzminski <marcin@python-works.com>
parents: 3146
diff changeset
1021 @hybrid_property
8182ebed2922 Added full last changeset info to lightweight dashboard
Marcin Kuzminski <marcin@python-works.com>
parents: 3146
diff changeset
1022 def changeset_cache(self):
8182ebed2922 Added full last changeset info to lightweight dashboard
Marcin Kuzminski <marcin@python-works.com>
parents: 3146
diff changeset
1023 from rhodecode.lib.vcs.backends.base import EmptyChangeset
8182ebed2922 Added full last changeset info to lightweight dashboard
Marcin Kuzminski <marcin@python-works.com>
parents: 3146
diff changeset
1024 dummy = EmptyChangeset().__json__()
8182ebed2922 Added full last changeset info to lightweight dashboard
Marcin Kuzminski <marcin@python-works.com>
parents: 3146
diff changeset
1025 if not self._changeset_cache:
8182ebed2922 Added full last changeset info to lightweight dashboard
Marcin Kuzminski <marcin@python-works.com>
parents: 3146
diff changeset
1026 return dummy
8182ebed2922 Added full last changeset info to lightweight dashboard
Marcin Kuzminski <marcin@python-works.com>
parents: 3146
diff changeset
1027 try:
8182ebed2922 Added full last changeset info to lightweight dashboard
Marcin Kuzminski <marcin@python-works.com>
parents: 3146
diff changeset
1028 return json.loads(self._changeset_cache)
8182ebed2922 Added full last changeset info to lightweight dashboard
Marcin Kuzminski <marcin@python-works.com>
parents: 3146
diff changeset
1029 except TypeError:
8182ebed2922 Added full last changeset info to lightweight dashboard
Marcin Kuzminski <marcin@python-works.com>
parents: 3146
diff changeset
1030 return dummy
8182ebed2922 Added full last changeset info to lightweight dashboard
Marcin Kuzminski <marcin@python-works.com>
parents: 3146
diff changeset
1031
8182ebed2922 Added full last changeset info to lightweight dashboard
Marcin Kuzminski <marcin@python-works.com>
parents: 3146
diff changeset
1032 @changeset_cache.setter
8182ebed2922 Added full last changeset info to lightweight dashboard
Marcin Kuzminski <marcin@python-works.com>
parents: 3146
diff changeset
1033 def changeset_cache(self, val):
8182ebed2922 Added full last changeset info to lightweight dashboard
Marcin Kuzminski <marcin@python-works.com>
parents: 3146
diff changeset
1034 try:
8182ebed2922 Added full last changeset info to lightweight dashboard
Marcin Kuzminski <marcin@python-works.com>
parents: 3146
diff changeset
1035 self._changeset_cache = json.dumps(val)
3631
10b4e34841a4 Don't catch all exceptions
Marcin Kuzminski <marcin@python-works.com>
parents: 3625
diff changeset
1036 except Exception:
3147
8182ebed2922 Added full last changeset info to lightweight dashboard
Marcin Kuzminski <marcin@python-works.com>
parents: 3146
diff changeset
1037 log.error(traceback.format_exc())
8182ebed2922 Added full last changeset info to lightweight dashboard
Marcin Kuzminski <marcin@python-works.com>
parents: 3146
diff changeset
1038
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
1039 @classmethod
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
1040 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
1041 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
1042
1554
e7c6341ad3cb fixes #245 Rescan of the repositories on Windows
Marcin Kuzminski <marcin@python-works.com>
parents: 1547
diff changeset
1043 @classmethod
3152
46234d2d388f fixed issues with getting repos by path on windows
Marcin Kuzminski <marcin@python-works.com>
parents: 3147
diff changeset
1044 def normalize_repo_name(cls, repo_name):
46234d2d388f fixed issues with getting repos by path on windows
Marcin Kuzminski <marcin@python-works.com>
parents: 3147
diff changeset
1045 """
46234d2d388f fixed issues with getting repos by path on windows
Marcin Kuzminski <marcin@python-works.com>
parents: 3147
diff changeset
1046 Normalizes os specific repo_name to the format internally stored inside
46234d2d388f fixed issues with getting repos by path on windows
Marcin Kuzminski <marcin@python-works.com>
parents: 3147
diff changeset
1047 dabatabase using URL_SEP
46234d2d388f fixed issues with getting repos by path on windows
Marcin Kuzminski <marcin@python-works.com>
parents: 3147
diff changeset
1048
46234d2d388f fixed issues with getting repos by path on windows
Marcin Kuzminski <marcin@python-works.com>
parents: 3147
diff changeset
1049 :param cls:
46234d2d388f fixed issues with getting repos by path on windows
Marcin Kuzminski <marcin@python-works.com>
parents: 3147
diff changeset
1050 :param repo_name:
46234d2d388f fixed issues with getting repos by path on windows
Marcin Kuzminski <marcin@python-works.com>
parents: 3147
diff changeset
1051 """
46234d2d388f fixed issues with getting repos by path on windows
Marcin Kuzminski <marcin@python-works.com>
parents: 3147
diff changeset
1052 return cls.url_sep().join(repo_name.split(os.sep))
46234d2d388f fixed issues with getting repos by path on windows
Marcin Kuzminski <marcin@python-works.com>
parents: 3147
diff changeset
1053
46234d2d388f fixed issues with getting repos by path on windows
Marcin Kuzminski <marcin@python-works.com>
parents: 3147
diff changeset
1054 @classmethod
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
1055 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
1056 q = Session().query(cls).filter(cls.repo_name == repo_name)
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
1057 q = q.options(joinedload(Repository.fork))\
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
1058 .options(joinedload(Repository.user))\
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
1059 .options(joinedload(Repository.group))
1749
8ecc6b8229a5 commit less models
Marcin Kuzminski <marcin@python-works.com>
parents: 1747
diff changeset
1060 return q.scalar()
1301
7e75af301842 Added simple forks page, resolves issue #179
Marcin Kuzminski <marcin@python-works.com>
parents: 1292
diff changeset
1061
7e75af301842 Added simple forks page, resolves issue #179
Marcin Kuzminski <marcin@python-works.com>
parents: 1292
diff changeset
1062 @classmethod
2400
e87c6aa9c5e7 Add method for fetching repos by full path
Marcin Kuzminski <marcin@python-works.com>
parents: 2356
diff changeset
1063 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
1064 repo_name = repo_full_path.split(cls.base_path(), 1)[-1]
3152
46234d2d388f fixed issues with getting repos by path on windows
Marcin Kuzminski <marcin@python-works.com>
parents: 3147
diff changeset
1065 repo_name = cls.normalize_repo_name(repo_name)
2400
e87c6aa9c5e7 Add method for fetching repos by full path
Marcin Kuzminski <marcin@python-works.com>
parents: 2356
diff changeset
1066 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
1067
e87c6aa9c5e7 Add method for fetching repos by full path
Marcin Kuzminski <marcin@python-works.com>
parents: 2356
diff changeset
1068 @classmethod
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
1069 def get_repo_forks(cls, repo_id):
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
1070 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
1071
1508
4aba7be311e8 API added checks for a valid repository on pull command
Marcin Kuzminski <marcin@python-works.com>
parents: 1500
diff changeset
1072 @classmethod
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
1073 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
1074 """
4aba7be311e8 API added checks for a valid repository on pull command
Marcin Kuzminski <marcin@python-works.com>
parents: 1500
diff changeset
1075 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
1076
1508
4aba7be311e8 API added checks for a valid repository on pull command
Marcin Kuzminski <marcin@python-works.com>
parents: 1500
diff changeset
1077 :param cls:
4aba7be311e8 API added checks for a valid repository on pull command
Marcin Kuzminski <marcin@python-works.com>
parents: 1500
diff changeset
1078 """
2520
a1e156503afe Fixed calls to Session in db model
Marcin Kuzminski <marcin@python-works.com>
parents: 2510
diff changeset
1079 q = Session().query(RhodeCodeUi)\
1728
07e56179633e - fixes celery sqlalchemy session issues for async forking
Marcin Kuzminski <marcin@python-works.com>
parents: 1727
diff changeset
1080 .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
1081 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
1082 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
1083
1113
c1eda8ec4a46 added clone_uri,api_key into models. Fixed models for mysql compatibilty
Marcin Kuzminski <marcin@python-works.com>
parents: 1088
diff changeset
1084 @property
2395
b262e349a7a5 created pull-request overview
Marcin Kuzminski <marcin@python-works.com>
parents: 2392
diff changeset
1085 def forks(self):
b262e349a7a5 created pull-request overview
Marcin Kuzminski <marcin@python-works.com>
parents: 2392
diff changeset
1086 """
b262e349a7a5 created pull-request overview
Marcin Kuzminski <marcin@python-works.com>
parents: 2392
diff changeset
1087 Return forks of this repo
b262e349a7a5 created pull-request overview
Marcin Kuzminski <marcin@python-works.com>
parents: 2392
diff changeset
1088 """
b262e349a7a5 created pull-request overview
Marcin Kuzminski <marcin@python-works.com>
parents: 2392
diff changeset
1089 return Repository.get_repo_forks(self.repo_id)
b262e349a7a5 created pull-request overview
Marcin Kuzminski <marcin@python-works.com>
parents: 2392
diff changeset
1090
b262e349a7a5 created pull-request overview
Marcin Kuzminski <marcin@python-works.com>
parents: 2392
diff changeset
1091 @property
b262e349a7a5 created pull-request overview
Marcin Kuzminski <marcin@python-works.com>
parents: 2392
diff changeset
1092 def parent(self):
b262e349a7a5 created pull-request overview
Marcin Kuzminski <marcin@python-works.com>
parents: 2392
diff changeset
1093 """
b262e349a7a5 created pull-request overview
Marcin Kuzminski <marcin@python-works.com>
parents: 2392
diff changeset
1094 Returns fork parent
b262e349a7a5 created pull-request overview
Marcin Kuzminski <marcin@python-works.com>
parents: 2392
diff changeset
1095 """
b262e349a7a5 created pull-request overview
Marcin Kuzminski <marcin@python-works.com>
parents: 2392
diff changeset
1096 return self.fork
b262e349a7a5 created pull-request overview
Marcin Kuzminski <marcin@python-works.com>
parents: 2392
diff changeset
1097
b262e349a7a5 created pull-request overview
Marcin Kuzminski <marcin@python-works.com>
parents: 2392
diff changeset
1098 @property
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
1099 def just_name(self):
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
1100 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
1101
37a9421f32a0 Added handy methods to Repository model for fetching groups with parents
Marcin Kuzminski <marcin@python-works.com>
parents: 1113
diff changeset
1102 @property
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
1103 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
1104 groups = []
37a9421f32a0 Added handy methods to Repository model for fetching groups with parents
Marcin Kuzminski <marcin@python-works.com>
parents: 1113
diff changeset
1105 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
1106 return groups
37a9421f32a0 Added handy methods to Repository model for fetching groups with parents
Marcin Kuzminski <marcin@python-works.com>
parents: 1113
diff changeset
1107
37a9421f32a0 Added handy methods to Repository model for fetching groups with parents
Marcin Kuzminski <marcin@python-works.com>
parents: 1113
diff changeset
1108 cur_gr = self.group
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
1109 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
1110 while 1:
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
1111 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
1112 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
1113 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
1114 break
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
1115 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
1116
37a9421f32a0 Added handy methods to Repository model for fetching groups with parents
Marcin Kuzminski <marcin@python-works.com>
parents: 1113
diff changeset
1117 return groups
37a9421f32a0 Added handy methods to Repository model for fetching groups with parents
Marcin Kuzminski <marcin@python-works.com>
parents: 1113
diff changeset
1118
37a9421f32a0 Added handy methods to Repository model for fetching groups with parents
Marcin Kuzminski <marcin@python-works.com>
parents: 1113
diff changeset
1119 @property
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
1120 def groups_and_repo(self):
3599
8087731920d8 breadcrumbs: make repo names link to summary pages
Mads Kiilerich <madski@unity3d.com>
parents: 3577
diff changeset
1121 return self.groups_with_parents, self.just_name, self.repo_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
1122
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
1123 @LazyProperty
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
1124 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
1125 """
9c0f5d558789 fixes #200, rewrote the whole caching mechanism to get rid of such problems. Now cached instances are attached
Marcin Kuzminski <marcin@python-works.com>
parents: 1360
diff changeset
1126 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
1127 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
1128 """
2520
a1e156503afe Fixed calls to Session in db model
Marcin Kuzminski <marcin@python-works.com>
parents: 2510
diff changeset
1129 q = Session().query(RhodeCodeUi).filter(RhodeCodeUi.ui_key ==
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
1130 Repository.url_sep())
1727
8e9f51091229 fixed caching query on repos path
Marcin Kuzminski <marcin@python-works.com>
parents: 1723
diff changeset
1131 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
1132 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
1133
9c0f5d558789 fixes #200, rewrote the whole caching mechanism to get rid of such problems. Now cached instances are attached
Marcin Kuzminski <marcin@python-works.com>
parents: 1360
diff changeset
1134 @property
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
1135 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
1136 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
1137 # 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
1138 # 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
1139 # into a valid system path
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
1140 p += self.repo_name.split(Repository.url_sep())
3636
ddc4c12f00fb fixed issues with importing non-ascii repo names
Marcin Kuzminski <marcin@python-works.com>
parents: 3631
diff changeset
1141 return os.path.join(*map(safe_unicode, 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
1142
2809
070d2eacd48b Show cache keys in admin settings of repository
Marcin Kuzminski <marcin@python-works.com>
parents: 2808
diff changeset
1143 @property
070d2eacd48b Show cache keys in admin settings of repository
Marcin Kuzminski <marcin@python-works.com>
parents: 2808
diff changeset
1144 def cache_keys(self):
070d2eacd48b Show cache keys in admin settings of repository
Marcin Kuzminski <marcin@python-works.com>
parents: 2808
diff changeset
1145 """
070d2eacd48b Show cache keys in admin settings of repository
Marcin Kuzminski <marcin@python-works.com>
parents: 2808
diff changeset
1146 Returns associated cache keys for that repo
070d2eacd48b Show cache keys in admin settings of repository
Marcin Kuzminski <marcin@python-works.com>
parents: 2808
diff changeset
1147 """
070d2eacd48b Show cache keys in admin settings of repository
Marcin Kuzminski <marcin@python-works.com>
parents: 2808
diff changeset
1148 return CacheInvalidation.query()\
070d2eacd48b Show cache keys in admin settings of repository
Marcin Kuzminski <marcin@python-works.com>
parents: 2808
diff changeset
1149 .filter(CacheInvalidation.cache_args == self.repo_name)\
070d2eacd48b Show cache keys in admin settings of repository
Marcin Kuzminski <marcin@python-works.com>
parents: 2808
diff changeset
1150 .order_by(CacheInvalidation.cache_key)\
070d2eacd48b Show cache keys in admin settings of repository
Marcin Kuzminski <marcin@python-works.com>
parents: 2808
diff changeset
1151 .all()
070d2eacd48b Show cache keys in admin settings of repository
Marcin Kuzminski <marcin@python-works.com>
parents: 2808
diff changeset
1152
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
1153 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
1154 """
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
1155 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
1156
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
1157 :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
1158 """
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
1159 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
1160 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
1161
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
1162 @property
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
1163 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
1164 """
9c0f5d558789 fixes #200, rewrote the whole caching mechanism to get rid of such problems. Now cached instances are attached
Marcin Kuzminski <marcin@python-works.com>
parents: 1360
diff changeset
1165 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
1166 """
2982
78227b65a358 remove duplicated code for generating UI objects
Marcin Kuzminski <marcin@python-works.com>
parents: 2942
diff changeset
1167 from rhodecode.lib.utils import make_ui
78227b65a358 remove duplicated code for generating UI objects
Marcin Kuzminski <marcin@python-works.com>
parents: 2942
diff changeset
1168 return make_ui('db', clear_session=False)
1366
9c0f5d558789 fixes #200, rewrote the whole caching mechanism to get rid of such problems. Now cached instances are attached
Marcin Kuzminski <marcin@python-works.com>
parents: 1360
diff changeset
1169
1508
4aba7be311e8 API added checks for a valid repository on pull command
Marcin Kuzminski <marcin@python-works.com>
parents: 1500
diff changeset
1170 @classmethod
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
1171 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
1172 """
4aba7be311e8 API added checks for a valid repository on pull command
Marcin Kuzminski <marcin@python-works.com>
parents: 1500
diff changeset
1173 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
1174
1819
9451a569aee5 sphinx doc cleanup
Marcin Kuzminski <marcin@python-works.com>
parents: 1818
diff changeset
1175 :param cls:
9451a569aee5 sphinx doc cleanup
Marcin Kuzminski <marcin@python-works.com>
parents: 1818
diff changeset
1176 :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
1177 """
4aba7be311e8 API added checks for a valid repository on pull command
Marcin Kuzminski <marcin@python-works.com>
parents: 1500
diff changeset
1178 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
1179
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
1180 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
1181
2508
43cb5b6047fd Added functions for getting API data to repo and user models
Marcin Kuzminski <marcin@python-works.com>
parents: 2506
diff changeset
1182 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
1183 """
43cb5b6047fd Added functions for getting API data to repo and user models
Marcin Kuzminski <marcin@python-works.com>
parents: 2506
diff changeset
1184 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
1185
43cb5b6047fd Added functions for getting API data to repo and user models
Marcin Kuzminski <marcin@python-works.com>
parents: 2506
diff changeset
1186 """
43cb5b6047fd Added functions for getting API data to repo and user models
Marcin Kuzminski <marcin@python-works.com>
parents: 2506
diff changeset
1187 repo = self
43cb5b6047fd Added functions for getting API data to repo and user models
Marcin Kuzminski <marcin@python-works.com>
parents: 2506
diff changeset
1188 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
1189 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
1190 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
1191 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
1192 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
1193 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
1194 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
1195 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
1196 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
1197 owner=repo.user.username,
3115
ebd76deee70d Default parameters are now also used for creating repos using API calls, and initial repo scanner
Marcin Kuzminski <marcin@python-works.com>
parents: 3067
diff changeset
1198 fork_of=repo.fork.repo_name if repo.fork else None,
ebd76deee70d Default parameters are now also used for creating repos using API calls, and initial repo scanner
Marcin Kuzminski <marcin@python-works.com>
parents: 3067
diff changeset
1199 enable_statistics=repo.enable_statistics,
ebd76deee70d Default parameters are now also used for creating repos using API calls, and initial repo scanner
Marcin Kuzminski <marcin@python-works.com>
parents: 3067
diff changeset
1200 enable_locking=repo.enable_locking,
3174
37c0ac5fe42f added last_changeset information in get_repo API function
Marcin Kuzminski <marcin@python-works.com>
parents: 3170
diff changeset
1201 enable_downloads=repo.enable_downloads,
3502
7cde75eac0fe get_locks API function draft
Marcin Kuzminski <marcin@python-works.com>
parents: 3488
diff changeset
1202 last_changeset=repo.changeset_cache,
7cde75eac0fe get_locks API function draft
Marcin Kuzminski <marcin@python-works.com>
parents: 3488
diff changeset
1203 locked_by=User.get(self.locked[0]).get_api_data() \
7cde75eac0fe get_locks API function draft
Marcin Kuzminski <marcin@python-works.com>
parents: 3488
diff changeset
1204 if self.locked[0] else None,
7cde75eac0fe get_locks API function draft
Marcin Kuzminski <marcin@python-works.com>
parents: 3488
diff changeset
1205 locked_date=time_to_datetime(self.locked[1]) \
7cde75eac0fe get_locks API function draft
Marcin Kuzminski <marcin@python-works.com>
parents: 3488
diff changeset
1206 if self.locked[1] else None
2508
43cb5b6047fd Added functions for getting API data to repo and user models
Marcin Kuzminski <marcin@python-works.com>
parents: 2506
diff changeset
1207 )
3308
72a91632b731 repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents: 3278
diff changeset
1208 rc_config = RhodeCodeSetting.get_app_settings()
72a91632b731 repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents: 3278
diff changeset
1209 repository_fields = str2bool(rc_config.get('rhodecode_repository_fields'))
72a91632b731 repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents: 3278
diff changeset
1210 if repository_fields:
72a91632b731 repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents: 3278
diff changeset
1211 for f in self.extra_fields:
72a91632b731 repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents: 3278
diff changeset
1212 data[f.field_key_prefixed] = f.field_value
2508
43cb5b6047fd Added functions for getting API data to repo and user models
Marcin Kuzminski <marcin@python-works.com>
parents: 2506
diff changeset
1213
43cb5b6047fd Added functions for getting API data to repo and user models
Marcin Kuzminski <marcin@python-works.com>
parents: 2506
diff changeset
1214 return data
43cb5b6047fd Added functions for getting API data to repo and user models
Marcin Kuzminski <marcin@python-works.com>
parents: 2506
diff changeset
1215
2726
aa17c7a1b8a5 Implemented basic locking functionality.
Marcin Kuzminski <marcin@python-works.com>
parents: 2724
diff changeset
1216 @classmethod
3808
2feb58495f34 locking API returns objects instead of string messages.
Marcin Kuzminski <marcin@python-works.com>
parents: 3788
diff changeset
1217 def lock(cls, repo, user_id, lock_time=None):
2feb58495f34 locking API returns objects instead of string messages.
Marcin Kuzminski <marcin@python-works.com>
parents: 3788
diff changeset
1218 if not lock_time:
2feb58495f34 locking API returns objects instead of string messages.
Marcin Kuzminski <marcin@python-works.com>
parents: 3788
diff changeset
1219 lock_time = time.time()
2feb58495f34 locking API returns objects instead of string messages.
Marcin Kuzminski <marcin@python-works.com>
parents: 3788
diff changeset
1220 repo.locked = [user_id, lock_time]
2726
aa17c7a1b8a5 Implemented basic locking functionality.
Marcin Kuzminski <marcin@python-works.com>
parents: 2724
diff changeset
1221 Session().add(repo)
aa17c7a1b8a5 Implemented basic locking functionality.
Marcin Kuzminski <marcin@python-works.com>
parents: 2724
diff changeset
1222 Session().commit()
aa17c7a1b8a5 Implemented basic locking functionality.
Marcin Kuzminski <marcin@python-works.com>
parents: 2724
diff changeset
1223
aa17c7a1b8a5 Implemented basic locking functionality.
Marcin Kuzminski <marcin@python-works.com>
parents: 2724
diff changeset
1224 @classmethod
aa17c7a1b8a5 Implemented basic locking functionality.
Marcin Kuzminski <marcin@python-works.com>
parents: 2724
diff changeset
1225 def unlock(cls, repo):
aa17c7a1b8a5 Implemented basic locking functionality.
Marcin Kuzminski <marcin@python-works.com>
parents: 2724
diff changeset
1226 repo.locked = None
aa17c7a1b8a5 Implemented basic locking functionality.
Marcin Kuzminski <marcin@python-works.com>
parents: 2724
diff changeset
1227 Session().add(repo)
aa17c7a1b8a5 Implemented basic locking functionality.
Marcin Kuzminski <marcin@python-works.com>
parents: 2724
diff changeset
1228 Session().commit()
aa17c7a1b8a5 Implemented basic locking functionality.
Marcin Kuzminski <marcin@python-works.com>
parents: 2724
diff changeset
1229
3457
08e8115585bd calling lock function without lock attribute, will return lock state
Marcin Kuzminski <marcin@python-works.com>
parents: 3420
diff changeset
1230 @classmethod
08e8115585bd calling lock function without lock attribute, will return lock state
Marcin Kuzminski <marcin@python-works.com>
parents: 3420
diff changeset
1231 def getlock(cls, repo):
08e8115585bd calling lock function without lock attribute, will return lock state
Marcin Kuzminski <marcin@python-works.com>
parents: 3420
diff changeset
1232 return repo.locked
08e8115585bd calling lock function without lock attribute, will return lock state
Marcin Kuzminski <marcin@python-works.com>
parents: 3420
diff changeset
1233
2936
62e493c7f436 Added lightweight dashboard option. ref #500
Marcin Kuzminski <marcin@python-works.com>
parents: 2835
diff changeset
1234 @property
62e493c7f436 Added lightweight dashboard option. ref #500
Marcin Kuzminski <marcin@python-works.com>
parents: 2835
diff changeset
1235 def last_db_change(self):
62e493c7f436 Added lightweight dashboard option. ref #500
Marcin Kuzminski <marcin@python-works.com>
parents: 2835
diff changeset
1236 return self.updated_on
62e493c7f436 Added lightweight dashboard option. ref #500
Marcin Kuzminski <marcin@python-works.com>
parents: 2835
diff changeset
1237
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
1238 @property
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
1239 def clone_uri_hidden(self):
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
1240 clone_uri = self.clone_uri
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
1241 if clone_uri:
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
1242 import urlobject
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
1243 url_obj = urlobject.URLObject(self.clone_uri)
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
1244 if url_obj.password:
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
1245 clone_uri = url_obj.with_password('*****')
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
1246 return clone_uri
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
1247
3170
2ab2eed4a70a implemented #725 Pull Request View - Show origin repo URL
Marcin Kuzminski <marcin@python-works.com>
parents: 3152
diff changeset
1248 def clone_url(self, **override):
2ab2eed4a70a implemented #725 Pull Request View - Show origin repo URL
Marcin Kuzminski <marcin@python-works.com>
parents: 3152
diff changeset
1249 from pylons import url
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
1250 qualified_home_url = url('home', qualified=True)
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
1251
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
1252 uri_tmpl = None
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
1253 if 'with_id' in override:
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
1254 uri_tmpl = self.DEFAULT_CLONE_URI_ID
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
1255 del override['with_id']
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
1256
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
1257 if 'uri_tmpl' in override:
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
1258 uri_tmpl = override['uri_tmpl']
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
1259 del override['uri_tmpl']
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
1260
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
1261 # we didn't override our tmpl from **overrides
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
1262 if not uri_tmpl:
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
1263 uri_tmpl = self.DEFAULT_CLONE_URI
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
1264 try:
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
1265 from pylons import tmpl_context as c
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
1266 uri_tmpl = c.clone_uri_tmpl
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
1267 except Exception:
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
1268 # in any case if we call this outside of request context,
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
1269 # ie, not having tmpl_context set up
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
1270 pass
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
1271
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
1272 return get_clone_url(uri_tmpl=uri_tmpl,
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
1273 qualifed_home_url=qualified_home_url,
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
1274 repo_name=self.repo_name,
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
1275 repo_id=self.repo_id, **override)
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
1276
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
1277 def set_state(self, state):
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
1278 self.repo_state = state
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
1279 Session().add(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
1280 #==========================================================================
1466
ad5a543a9b2f Code cleanup
Marcin Kuzminski <marcin@python-works.com>
parents: 1460
diff changeset
1281 # SCM PROPERTIES
ad5a543a9b2f Code cleanup
Marcin Kuzminski <marcin@python-works.com>
parents: 1460
diff changeset
1282 #==========================================================================
ad5a543a9b2f Code cleanup
Marcin Kuzminski <marcin@python-works.com>
parents: 1460
diff changeset
1283
2251
986430cde505 fixed issue with getting README files from git repositories
Marcin Kuzminski <marcin@python-works.com>
parents: 2248
diff changeset
1284 def get_changeset(self, rev=None):
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
1285 return get_changeset_safe(self.scm_instance, rev)
1466
ad5a543a9b2f Code cleanup
Marcin Kuzminski <marcin@python-works.com>
parents: 1460
diff changeset
1286
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
1287 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
1288 """
370ed7829168 Readme renderer now uses landing_rev parameter to render the readme based on
Marcin Kuzminski <marcin@python-works.com>
parents: 2588
diff changeset
1289 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
1290 """
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
1291 _rev_type, _rev = self.landing_rev
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
1292 cs = self.get_changeset(_rev)
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
1293 if isinstance(cs, EmptyChangeset):
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
1294 return self.get_changeset()
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
1295 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
1296
3147
8182ebed2922 Added full last changeset info to lightweight dashboard
Marcin Kuzminski <marcin@python-works.com>
parents: 3146
diff changeset
1297 def update_changeset_cache(self, cs_cache=None):
8182ebed2922 Added full last changeset info to lightweight dashboard
Marcin Kuzminski <marcin@python-works.com>
parents: 3146
diff changeset
1298 """
8182ebed2922 Added full last changeset info to lightweight dashboard
Marcin Kuzminski <marcin@python-works.com>
parents: 3146
diff changeset
1299 Update cache of last changeset for repository, keys should be::
8182ebed2922 Added full last changeset info to lightweight dashboard
Marcin Kuzminski <marcin@python-works.com>
parents: 3146
diff changeset
1300
8182ebed2922 Added full last changeset info to lightweight dashboard
Marcin Kuzminski <marcin@python-works.com>
parents: 3146
diff changeset
1301 short_id
8182ebed2922 Added full last changeset info to lightweight dashboard
Marcin Kuzminski <marcin@python-works.com>
parents: 3146
diff changeset
1302 raw_id
8182ebed2922 Added full last changeset info to lightweight dashboard
Marcin Kuzminski <marcin@python-works.com>
parents: 3146
diff changeset
1303 revision
8182ebed2922 Added full last changeset info to lightweight dashboard
Marcin Kuzminski <marcin@python-works.com>
parents: 3146
diff changeset
1304 message
8182ebed2922 Added full last changeset info to lightweight dashboard
Marcin Kuzminski <marcin@python-works.com>
parents: 3146
diff changeset
1305 date
8182ebed2922 Added full last changeset info to lightweight dashboard
Marcin Kuzminski <marcin@python-works.com>
parents: 3146
diff changeset
1306 author
8182ebed2922 Added full last changeset info to lightweight dashboard
Marcin Kuzminski <marcin@python-works.com>
parents: 3146
diff changeset
1307
8182ebed2922 Added full last changeset info to lightweight dashboard
Marcin Kuzminski <marcin@python-works.com>
parents: 3146
diff changeset
1308 :param cs_cache:
8182ebed2922 Added full last changeset info to lightweight dashboard
Marcin Kuzminski <marcin@python-works.com>
parents: 3146
diff changeset
1309 """
8182ebed2922 Added full last changeset info to lightweight dashboard
Marcin Kuzminski <marcin@python-works.com>
parents: 3146
diff changeset
1310 from rhodecode.lib.vcs.backends.base import BaseChangeset
8182ebed2922 Added full last changeset info to lightweight dashboard
Marcin Kuzminski <marcin@python-works.com>
parents: 3146
diff changeset
1311 if cs_cache is None:
3420
a6bef3e8a361 Update changeset cache should use non-cache version of repo if given attribute is empty, it's easier to controll how changesets are udpated
Marcin Kuzminski <marcin@python-works.com>
parents: 3417
diff changeset
1312 cs_cache = EmptyChangeset()
a6bef3e8a361 Update changeset cache should use non-cache version of repo if given attribute is empty, it's easier to controll how changesets are udpated
Marcin Kuzminski <marcin@python-works.com>
parents: 3417
diff changeset
1313 # use no-cache version here
3549
e4a4006faceb no_cache version of scm is now a function
Marcin Kuzminski <marcin@python-works.com>
parents: 3502
diff changeset
1314 scm_repo = self.scm_instance_no_cache()
3420
a6bef3e8a361 Update changeset cache should use non-cache version of repo if given attribute is empty, it's easier to controll how changesets are udpated
Marcin Kuzminski <marcin@python-works.com>
parents: 3417
diff changeset
1315 if scm_repo:
a6bef3e8a361 Update changeset cache should use non-cache version of repo if given attribute is empty, it's easier to controll how changesets are udpated
Marcin Kuzminski <marcin@python-works.com>
parents: 3417
diff changeset
1316 cs_cache = scm_repo.get_changeset()
a6bef3e8a361 Update changeset cache should use non-cache version of repo if given attribute is empty, it's easier to controll how changesets are udpated
Marcin Kuzminski <marcin@python-works.com>
parents: 3417
diff changeset
1317
3147
8182ebed2922 Added full last changeset info to lightweight dashboard
Marcin Kuzminski <marcin@python-works.com>
parents: 3146
diff changeset
1318 if isinstance(cs_cache, BaseChangeset):
8182ebed2922 Added full last changeset info to lightweight dashboard
Marcin Kuzminski <marcin@python-works.com>
parents: 3146
diff changeset
1319 cs_cache = cs_cache.__json__()
8182ebed2922 Added full last changeset info to lightweight dashboard
Marcin Kuzminski <marcin@python-works.com>
parents: 3146
diff changeset
1320
3420
a6bef3e8a361 Update changeset cache should use non-cache version of repo if given attribute is empty, it's easier to controll how changesets are udpated
Marcin Kuzminski <marcin@python-works.com>
parents: 3417
diff changeset
1321 if (cs_cache != self.changeset_cache or not self.changeset_cache):
3226
226013bac971 update repo-info shouldn't allow setting empty values NEVER !
Marcin Kuzminski <marcin@python-works.com>
parents: 3222
diff changeset
1322 _default = datetime.datetime.fromtimestamp(0)
3420
a6bef3e8a361 Update changeset cache should use non-cache version of repo if given attribute is empty, it's easier to controll how changesets are udpated
Marcin Kuzminski <marcin@python-works.com>
parents: 3417
diff changeset
1323 last_change = cs_cache.get('date') or _default
3636
ddc4c12f00fb fixed issues with importing non-ascii repo names
Marcin Kuzminski <marcin@python-works.com>
parents: 3631
diff changeset
1324 log.debug('updated repo %s with new cs cache %s'
ddc4c12f00fb fixed issues with importing non-ascii repo names
Marcin Kuzminski <marcin@python-works.com>
parents: 3631
diff changeset
1325 % (self.repo_name, cs_cache))
2937
d439d408b415 Update last_change from VCS data on request.
Marcin Kuzminski <marcin@python-works.com>
parents: 2936
diff changeset
1326 self.updated_on = last_change
3147
8182ebed2922 Added full last changeset info to lightweight dashboard
Marcin Kuzminski <marcin@python-works.com>
parents: 3146
diff changeset
1327 self.changeset_cache = cs_cache
2937
d439d408b415 Update last_change from VCS data on request.
Marcin Kuzminski <marcin@python-works.com>
parents: 2936
diff changeset
1328 Session().add(self)
d439d408b415 Update last_change from VCS data on request.
Marcin Kuzminski <marcin@python-works.com>
parents: 2936
diff changeset
1329 Session().commit()
3227
99ce5d097a09 fixes for issue #731, update-repoinfo sometimes failed to update data when changesets
Marcin Kuzminski <marcin@python-works.com>
parents: 3226
diff changeset
1330 else:
3636
ddc4c12f00fb fixed issues with importing non-ascii repo names
Marcin Kuzminski <marcin@python-works.com>
parents: 3631
diff changeset
1331 log.debug('Skipping repo:%s already with latest changes'
ddc4c12f00fb fixed issues with importing non-ascii repo names
Marcin Kuzminski <marcin@python-works.com>
parents: 3631
diff changeset
1332 % self.repo_name)
2937
d439d408b415 Update last_change from VCS data on request.
Marcin Kuzminski <marcin@python-works.com>
parents: 2936
diff changeset
1333
1466
ad5a543a9b2f Code cleanup
Marcin Kuzminski <marcin@python-works.com>
parents: 1460
diff changeset
1334 @property
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
1335 def tip(self):
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
1336 return self.get_changeset('tip')
1466
ad5a543a9b2f Code cleanup
Marcin Kuzminski <marcin@python-works.com>
parents: 1460
diff changeset
1337
ad5a543a9b2f Code cleanup
Marcin Kuzminski <marcin@python-works.com>
parents: 1460
diff changeset
1338 @property
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
1339 def author(self):
1466
ad5a543a9b2f Code cleanup
Marcin Kuzminski <marcin@python-works.com>
parents: 1460
diff changeset
1340 return self.tip.author
ad5a543a9b2f Code cleanup
Marcin Kuzminski <marcin@python-works.com>
parents: 1460
diff changeset
1341
ad5a543a9b2f Code cleanup
Marcin Kuzminski <marcin@python-works.com>
parents: 1460
diff changeset
1342 @property
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
1343 def last_change(self):
1466
ad5a543a9b2f Code cleanup
Marcin Kuzminski <marcin@python-works.com>
parents: 1460
diff changeset
1344 return self.scm_instance.last_change
ad5a543a9b2f Code cleanup
Marcin Kuzminski <marcin@python-works.com>
parents: 1460
diff changeset
1345
2520
a1e156503afe Fixed calls to Session in db model
Marcin Kuzminski <marcin@python-works.com>
parents: 2510
diff changeset
1346 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
1347 """
0614862a20ec Added number of comments in changelog for each changeset
Marcin Kuzminski <marcin@python-works.com>
parents: 1824
diff changeset
1348 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
1349
0614862a20ec Added number of comments in changelog for each changeset
Marcin Kuzminski <marcin@python-works.com>
parents: 1824
diff changeset
1350 :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
1351 """
0614862a20ec Added number of comments in changelog for each changeset
Marcin Kuzminski <marcin@python-works.com>
parents: 1824
diff changeset
1352 cmts = ChangesetComment.query()\
0614862a20ec Added number of comments in changelog for each changeset
Marcin Kuzminski <marcin@python-works.com>
parents: 1824
diff changeset
1353 .filter(ChangesetComment.repo == self)
0614862a20ec Added number of comments in changelog for each changeset
Marcin Kuzminski <marcin@python-works.com>
parents: 1824
diff changeset
1354 if revisions:
0614862a20ec Added number of comments in changelog for each changeset
Marcin Kuzminski <marcin@python-works.com>
parents: 1824
diff changeset
1355 cmts = cmts.filter(ChangesetComment.revision.in_(revisions))
3850
7a4df261a375 added alias configuration option for gists.
Marcin Kuzminski <marcin@python-works.com>
parents: 3842
diff changeset
1356 grouped = collections.defaultdict(list)
1884
0614862a20ec Added number of comments in changelog for each changeset
Marcin Kuzminski <marcin@python-works.com>
parents: 1824
diff changeset
1357 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
1358 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
1359 return grouped
0614862a20ec Added number of comments in changelog for each changeset
Marcin Kuzminski <marcin@python-works.com>
parents: 1824
diff changeset
1360
2215
2c2bdaeca912 code-review initial
Marcin Kuzminski <marcin@python-works.com>
parents: 2161
diff changeset
1361 def statuses(self, revisions=None):
2c2bdaeca912 code-review initial
Marcin Kuzminski <marcin@python-works.com>
parents: 2161
diff changeset
1362 """
2c2bdaeca912 code-review initial
Marcin Kuzminski <marcin@python-works.com>
parents: 2161
diff changeset
1363 Returns statuses for this repository
2217
76947224bf27 Implemented initial code-review status of changesets
Marcin Kuzminski <marcin@python-works.com>
parents: 2215
diff changeset
1364
2215
2c2bdaeca912 code-review initial
Marcin Kuzminski <marcin@python-works.com>
parents: 2161
diff changeset
1365 :param revisions: list of revisions to get statuses for
2c2bdaeca912 code-review initial
Marcin Kuzminski <marcin@python-works.com>
parents: 2161
diff changeset
1366 """
2c2bdaeca912 code-review initial
Marcin Kuzminski <marcin@python-works.com>
parents: 2161
diff changeset
1367
2c2bdaeca912 code-review initial
Marcin Kuzminski <marcin@python-works.com>
parents: 2161
diff changeset
1368 statuses = ChangesetStatus.query()\
2287
8447d35b674e Added simple versioning for changeset status
Marcin Kuzminski <marcin@python-works.com>
parents: 2286
diff changeset
1369 .filter(ChangesetStatus.repo == self)\
8447d35b674e Added simple versioning for changeset status
Marcin Kuzminski <marcin@python-works.com>
parents: 2286
diff changeset
1370 .filter(ChangesetStatus.version == 0)
2215
2c2bdaeca912 code-review initial
Marcin Kuzminski <marcin@python-works.com>
parents: 2161
diff changeset
1371 if revisions:
2c2bdaeca912 code-review initial
Marcin Kuzminski <marcin@python-works.com>
parents: 2161
diff changeset
1372 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
1373 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
1374
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
1375 #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
1376 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
1377 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
1378 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
1379 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
1380 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
1381 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
1382 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
1383
2215
2c2bdaeca912 code-review initial
Marcin Kuzminski <marcin@python-works.com>
parents: 2161
diff changeset
1384 for stat in statuses.all():
2443
fd0a822481ec - added commenting to pull requests
Marcin Kuzminski <marcin@python-works.com>
parents: 2440
diff changeset
1385 pr_id = pr_repo = None
fd0a822481ec - added commenting to pull requests
Marcin Kuzminski <marcin@python-works.com>
parents: 2440
diff changeset
1386 if stat.pull_request:
fd0a822481ec - added commenting to pull requests
Marcin Kuzminski <marcin@python-works.com>
parents: 2440
diff changeset
1387 pr_id = stat.pull_request.pull_request_id
fd0a822481ec - added commenting to pull requests
Marcin Kuzminski <marcin@python-works.com>
parents: 2440
diff changeset
1388 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
1389 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
1390 pr_id, pr_repo]
2215
2c2bdaeca912 code-review initial
Marcin Kuzminski <marcin@python-works.com>
parents: 2161
diff changeset
1391 return grouped
2c2bdaeca912 code-review initial
Marcin Kuzminski <marcin@python-works.com>
parents: 2161
diff changeset
1392
3246
b9ba0d4d3abf implemented #83 show repo size on summary page
Marcin Kuzminski <marcin@python-works.com>
parents: 3239
diff changeset
1393 def _repo_size(self):
b9ba0d4d3abf implemented #83 show repo size on summary page
Marcin Kuzminski <marcin@python-works.com>
parents: 3239
diff changeset
1394 from rhodecode.lib import helpers as h
b9ba0d4d3abf implemented #83 show repo size on summary page
Marcin Kuzminski <marcin@python-works.com>
parents: 3239
diff changeset
1395 log.debug('calculating repository size...')
b9ba0d4d3abf implemented #83 show repo size on summary page
Marcin Kuzminski <marcin@python-works.com>
parents: 3239
diff changeset
1396 return h.format_byte_size(self.scm_instance.size)
b9ba0d4d3abf implemented #83 show repo size on summary page
Marcin Kuzminski <marcin@python-works.com>
parents: 3239
diff changeset
1397
1466
ad5a543a9b2f Code cleanup
Marcin Kuzminski <marcin@python-works.com>
parents: 1460
diff changeset
1398 #==========================================================================
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
1399 # 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
1400 #==========================================================================
9c0f5d558789 fixes #200, rewrote the whole caching mechanism to get rid of such problems. Now cached instances are attached
Marcin Kuzminski <marcin@python-works.com>
parents: 1360
diff changeset
1401
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
1402 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
1403 """
3682
cf65b2c1b69d invalidation: some documentation and refactoring, second round
Mads Kiilerich <madski@unity3d.com>
parents: 3680
diff changeset
1404 Mark caches of this repo as invalid.
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
1405 """
3717
6ff98871247a Minor changes
Mads Kiilerich <madski@unity3d.com>
parents: 3714
diff changeset
1406 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
1407
3278
c2bf0fa7b3cb git hook handler shouldn't ever use cache instances
Marcin Kuzminski <marcin@python-works.com>
parents: 3274
diff changeset
1408 def scm_instance_no_cache(self):
c2bf0fa7b3cb git hook handler shouldn't ever use cache instances
Marcin Kuzminski <marcin@python-works.com>
parents: 3274
diff changeset
1409 return self.__get_instance()
c2bf0fa7b3cb git hook handler shouldn't ever use cache instances
Marcin Kuzminski <marcin@python-works.com>
parents: 3274
diff changeset
1410
3680
0db18ba129ea scm_instance shouldn't be cached in anyway inside object
Marcin Kuzminski <marcin@python-works.com>
parents: 3636
diff changeset
1411 @property
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
1412 def scm_instance(self):
3025
f61adead3520 Added option to ini files for controlling full cache of VCS instances.
Marcin Kuzminski <marcin@python-works.com>
parents: 3024
diff changeset
1413 import rhodecode
f61adead3520 Added option to ini files for controlling full cache of VCS instances.
Marcin Kuzminski <marcin@python-works.com>
parents: 3024
diff changeset
1414 full_cache = str2bool(rhodecode.CONFIG.get('vcs_full_cache'))
f61adead3520 Added option to ini files for controlling full cache of VCS instances.
Marcin Kuzminski <marcin@python-works.com>
parents: 3024
diff changeset
1415 if full_cache:
f61adead3520 Added option to ini files for controlling full cache of VCS instances.
Marcin Kuzminski <marcin@python-works.com>
parents: 3024
diff changeset
1416 return self.scm_instance_cached()
1400
0d7b56b97953 Simplified last_login call on user, and changed login to use User model directly
Marcin Kuzminski <marcin@python-works.com>
parents: 1388
diff changeset
1417 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
1418
3772
910ad1ffee99 invalidation: merge .invalidate and .set_valid as .test_and_set_valid
Mads Kiilerich <madski@unity3d.com>
parents: 3759
diff changeset
1419 def scm_instance_cached(self, valid_cache_keys=None):
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
1420 @cache_region('long_term')
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
1421 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
1422 return self.__get_instance()
1607
e886f91fcb71 Cached readme generation
Marcin Kuzminski <marcin@python-works.com>
parents: 1594
diff changeset
1423 rn = self.repo_name
2352
90e06f53af8c Implemented cache-map on main page to save executing select
Marcin Kuzminski <marcin@python-works.com>
parents: 2339
diff changeset
1424
3773
8e2cd46f765b invalidate: encapsulate how key is generated from repo_name and kind
Mads Kiilerich <madski@unity3d.com>
parents: 3772
diff changeset
1425 valid = CacheInvalidation.test_and_set_valid(rn, None, valid_cache_keys=valid_cache_keys)
3772
910ad1ffee99 invalidation: merge .invalidate and .set_valid as .test_and_set_valid
Mads Kiilerich <madski@unity3d.com>
parents: 3759
diff changeset
1426 if not valid:
910ad1ffee99 invalidation: merge .invalidate and .set_valid as .test_and_set_valid
Mads Kiilerich <madski@unity3d.com>
parents: 3759
diff changeset
1427 log.debug('Cache for %s invalidated, getting new object' % (rn))
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
1428 region_invalidate(_c, None, rn)
3686
f18801f827da repr of cache inv object show also now cache_active + some better logging
Marcin Kuzminski <marcin@python-works.com>
parents: 3685
diff changeset
1429 else:
f18801f827da repr of cache inv object show also now cache_active + some better logging
Marcin Kuzminski <marcin@python-works.com>
parents: 3685
diff changeset
1430 log.debug('Getting obj for %s from cache' % (rn))
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
1431 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
1432
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
1433 def __get_instance(self):
1368
04b43168742d adde short cache for repo_path
Marcin Kuzminski <marcin@python-works.com>
parents: 1366
diff changeset
1434 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
1435 try:
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
1436 alias = get_scm(repo_full_path)[0]
3420
a6bef3e8a361 Update changeset cache should use non-cache version of repo if given attribute is empty, it's easier to controll how changesets are udpated
Marcin Kuzminski <marcin@python-works.com>
parents: 3417
diff changeset
1437 log.debug('Creating instance of %s repository from %s'
a6bef3e8a361 Update changeset cache should use non-cache version of repo if given attribute is empty, it's easier to controll how changesets are udpated
Marcin Kuzminski <marcin@python-works.com>
parents: 3417
diff changeset
1438 % (alias, repo_full_path))
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
1439 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
1440 except VCSError:
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
1441 log.error(traceback.format_exc())
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
1442 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
1443 'filesystem run rescan repositories with '
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
1444 '"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
1445 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
1446
9c0f5d558789 fixes #200, rewrote the whole caching mechanism to get rid of such problems. Now cached instances are attached
Marcin Kuzminski <marcin@python-works.com>
parents: 1360
diff changeset
1447 if alias == 'hg':
2000
72c525a7e7ad added migrations from 1.2.X to 1.3
Marcin Kuzminski <marcin@python-works.com>
parents: 1990
diff changeset
1448
1594
9dae92a65e40 fixes #288
Marcin Kuzminski <marcin@python-works.com>
parents: 1593
diff changeset
1449 repo = backend(safe_str(repo_full_path), create=False,
9dae92a65e40 fixes #288
Marcin Kuzminski <marcin@python-works.com>
parents: 1593
diff changeset
1450 baseui=self._ui)
1607
e886f91fcb71 Cached readme generation
Marcin Kuzminski <marcin@python-works.com>
parents: 1594
diff changeset
1451 # 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
1452 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
1453 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
1454 else:
1594
9dae92a65e40 fixes #288
Marcin Kuzminski <marcin@python-works.com>
parents: 1593
diff changeset
1455 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
1456
9c0f5d558789 fixes #200, rewrote the whole caching mechanism to get rid of such problems. Now cached instances are attached
Marcin Kuzminski <marcin@python-works.com>
parents: 1360
diff changeset
1457 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
1458
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
1459 def __json__(self):
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
1460 return dict(landing_rev = self.landing_rev)
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
1461
1633
2c0d35e336b5 refactoring of models names for repoGroup permissions
Marcin Kuzminski <marcin@python-works.com>
parents: 1607
diff changeset
1462 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
1463 __tablename__ = 'groups'
1958
7e4b3d3a9c5c renamed repo groups table
Marcin Kuzminski <marcin@python-works.com>
parents: 1950
diff changeset
1464 __table_args__ = (
7e4b3d3a9c5c renamed repo groups table
Marcin Kuzminski <marcin@python-works.com>
parents: 1950
diff changeset
1465 UniqueConstraint('group_name', 'group_parent_id'),
1963
9bbde54232dc white space cleanup
Marcin Kuzminski <marcin@python-works.com>
parents: 1960
diff changeset
1466 CheckConstraint('group_id != group_parent_id'),
2356
2da7b5984ae5 typo fix + code garden
Marcin Kuzminski <marcin@python-works.com>
parents: 2352
diff changeset
1467 {'extend_existing': True, 'mysql_engine': 'InnoDB',
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
1468 'mysql_charset': 'utf8', 'sqlite_autoincrement': True},
1958
7e4b3d3a9c5c renamed repo groups table
Marcin Kuzminski <marcin@python-works.com>
parents: 1950
diff changeset
1469 )
7e4b3d3a9c5c renamed repo groups table
Marcin Kuzminski <marcin@python-works.com>
parents: 1950
diff changeset
1470 __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
1471
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
1472 SEP = ' &raquo; '
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
1473
1594
9dae92a65e40 fixes #288
Marcin Kuzminski <marcin@python-works.com>
parents: 1593
diff changeset
1474 group_id = Column("group_id", Integer(), nullable=False, unique=True, default=None, primary_key=True)
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
1475 group_name = Column("group_name", String(255, convert_unicode=False), nullable=False, unique=True, default=None)
1594
9dae92a65e40 fixes #288
Marcin Kuzminski <marcin@python-works.com>
parents: 1593
diff changeset
1476 group_parent_id = Column("group_parent_id", Integer(), ForeignKey('groups.group_id'), nullable=True, unique=None, default=None)
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
1477 group_description = Column("group_description", String(10000, convert_unicode=False), nullable=True, unique=None, default=None)
2749
3ed4dae499d0 Recursive set locking on all children of a group.
Marcin Kuzminski <marcin@python-works.com>
parents: 2731
diff changeset
1478 enable_locking = Column("enable_locking", Boolean(), nullable=False, unique=None, default=False)
3714
7e3d89d9d3a2 - Manage Userโ€™s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents: 3687
diff changeset
1479 user_id = Column("user_id", Integer(), ForeignKey('users.user_id'), nullable=False, unique=False, default=None)
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
1480 created_on = Column('created_on', DateTime(timezone=False), nullable=False, default=datetime.datetime.now)
878
859bc9e7a15d Extended repo2db mapper with group creation via directory structures
Marcin Kuzminski <marcin@python-works.com>
parents: 836
diff changeset
1481
1982
87f0800abc7b #227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents: 1976
diff changeset
1482 repo_group_to_perm = relationship('UserRepoGroupToPerm', cascade='all', order_by='UserRepoGroupToPerm.group_to_perm_id')
3417
fa6ba6727475 further cleanup of UsersGroup
Mads Kiilerich <madski@unity3d.com>
parents: 3416
diff changeset
1483 users_group_to_perm = relationship('UserGroupRepoGroupToPerm', cascade='all')
1633
2c0d35e336b5 refactoring of models names for repoGroup permissions
Marcin Kuzminski <marcin@python-works.com>
parents: 1607
diff changeset
1484 parent_group = relationship('RepoGroup', remote_side=group_id)
3714
7e3d89d9d3a2 - Manage Userโ€™s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents: 3687
diff changeset
1485 user = relationship('User')
878
859bc9e7a15d Extended repo2db mapper with group creation via directory structures
Marcin Kuzminski <marcin@python-works.com>
parents: 836
diff changeset
1486
1594
9dae92a65e40 fixes #288
Marcin Kuzminski <marcin@python-works.com>
parents: 1593
diff changeset
1487 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
1488 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
1489 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
1490
2156
a27e4d44237e Use __unicode__ instead of __repr__ in models.
Marcin Kuzminski <marcin@python-works.com>
parents: 2152
diff changeset
1491 def __unicode__(self):
3714
7e3d89d9d3a2 - Manage Userโ€™s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents: 3687
diff changeset
1492 return u"<%s('id:%s:%s')>" % (self.__class__.__name__, self.group_id,
7e3d89d9d3a2 - Manage Userโ€™s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents: 3687
diff changeset
1493 self.group_name)
631
05528ad948c4 Hacking for git support,and new faster repo scan
Marcin Kuzminski <marcin@python-works.com>
parents: 549
diff changeset
1494
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
1495 @classmethod
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
1496 def _generate_choice(cls, repo_group):
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
1497 from webhelpers.html import literal as _literal
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
1498 _name = lambda k: _literal(cls.SEP.join(k))
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
1499 return repo_group.group_id, _name(repo_group.full_path_splitted)
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
1500
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
1501 @classmethod
3239
a9565b8b429b filter out repo groups choices to only ones that you have write+ access to. Before it was read+ access and you got proper
Marcin Kuzminski <marcin@python-works.com>
parents: 3234
diff changeset
1502 def groups_choices(cls, groups=None, show_empty_group=True):
3222
b4daef4cc26d Group management delegation:
Marcin Kuzminski <marcin@python-works.com>
parents: 3212
diff changeset
1503 if not groups:
b4daef4cc26d Group management delegation:
Marcin Kuzminski <marcin@python-works.com>
parents: 3212
diff changeset
1504 groups = cls.query().all()
3239
a9565b8b429b filter out repo groups choices to only ones that you have write+ access to. Before it was read+ access and you got proper
Marcin Kuzminski <marcin@python-works.com>
parents: 3234
diff changeset
1505
3222
b4daef4cc26d Group management delegation:
Marcin Kuzminski <marcin@python-works.com>
parents: 3212
diff changeset
1506 repo_groups = []
b4daef4cc26d Group management delegation:
Marcin Kuzminski <marcin@python-works.com>
parents: 3212
diff changeset
1507 if show_empty_group:
3942
e6a3f4b414d2 fixed translation and unicode issues
Marcin Kuzminski <marcin@python-works.com>
parents: 3909
diff changeset
1508 repo_groups = [('-1', u'-- %s --' % _('top level'))]
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
1509
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
1510 repo_groups.extend([cls._generate_choice(x) for x in groups])
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
1511
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
1512 repo_groups = sorted(repo_groups, key=lambda t: t[1].split(cls.SEP)[0])
1547
fbc762ae3496 unified generation of repo groups choices
Marcin Kuzminski <marcin@python-works.com>
parents: 1546
diff changeset
1513 return repo_groups
1591
0b63a0d2cede Merge with upstream
Nicolas VINOT <aeris@imirhil.fr>
parents: 1576 1590
diff changeset
1514
1547
fbc762ae3496 unified generation of repo groups choices
Marcin Kuzminski <marcin@python-works.com>
parents: 1546
diff changeset
1515 @classmethod
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
1516 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
1517 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
1518
1538
27be8f94c207 implements #226 repo groups available by path
Marcin Kuzminski <marcin@python-works.com>
parents: 1530
diff changeset
1519 @classmethod
1594
9dae92a65e40 fixes #288
Marcin Kuzminski <marcin@python-works.com>
parents: 1593
diff changeset
1520 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
1521 if case_insensitive:
3338a0994472 Improve API with user/group/repo CRUD methods
Nicolas VINOT <aeris@imirhil.fr>
parents: 1508
diff changeset
1522 gr = cls.query()\
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
1523 .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
1524 else:
3338a0994472 Improve API with user/group/repo CRUD methods
Nicolas VINOT <aeris@imirhil.fr>
parents: 1508
diff changeset
1525 gr = cls.query()\
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
1526 .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
1527 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
1528 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
1529 "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
1530 "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
1531 )
bf8ed0adbc66 fixes #371 fixed issues with beaker/sqlalchemy and non-ascii cache keys
Marcin Kuzminski <marcin@python-works.com>
parents: 2058
diff changeset
1532 )
1584
3338a0994472 Improve API with user/group/repo CRUD methods
Nicolas VINOT <aeris@imirhil.fr>
parents: 1508
diff changeset
1533 return gr.scalar()
1538
27be8f94c207 implements #226 repo groups available by path
Marcin Kuzminski <marcin@python-works.com>
parents: 1530
diff changeset
1534
1159
187a924ed653 Changes for repo groups
Marcin Kuzminski <marcin@python-works.com>
parents: 1155
diff changeset
1535 @property
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
1536 def parents(self):
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
1537 parents_recursion_limit = 10
1159
187a924ed653 Changes for repo groups
Marcin Kuzminski <marcin@python-works.com>
parents: 1155
diff changeset
1538 groups = []
187a924ed653 Changes for repo groups
Marcin Kuzminski <marcin@python-works.com>
parents: 1155
diff changeset
1539 if self.parent_group is None:
187a924ed653 Changes for repo groups
Marcin Kuzminski <marcin@python-works.com>
parents: 1155
diff changeset
1540 return groups
187a924ed653 Changes for repo groups
Marcin Kuzminski <marcin@python-works.com>
parents: 1155
diff changeset
1541 cur_gr = self.parent_group
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
1542 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
1543 cnt = 0
1159
187a924ed653 Changes for repo groups
Marcin Kuzminski <marcin@python-works.com>
parents: 1155
diff changeset
1544 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
1545 cnt += 1
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
1546 gr = getattr(cur_gr, 'parent_group', None)
1159
187a924ed653 Changes for repo groups
Marcin Kuzminski <marcin@python-works.com>
parents: 1155
diff changeset
1547 cur_gr = cur_gr.parent_group
187a924ed653 Changes for repo groups
Marcin Kuzminski <marcin@python-works.com>
parents: 1155
diff changeset
1548 if gr is None:
187a924ed653 Changes for repo groups
Marcin Kuzminski <marcin@python-works.com>
parents: 1155
diff changeset
1549 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
1550 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
1551 # this will prevent accidental infinit loops
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
1552 log.error(('more than %s parents found for group %s, stopping '
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
1553 'recursive parent fetching' % (parents_recursion_limit, self)))
1349
526120c77a38 #47 added editing of groups, and moving them between. Added check constraint for groups
Marcin Kuzminski <marcin@python-works.com>
parents: 1346
diff changeset
1554 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
1555
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
1556 groups.insert(0, gr)
1159
187a924ed653 Changes for repo groups
Marcin Kuzminski <marcin@python-works.com>
parents: 1155
diff changeset
1557 return groups
187a924ed653 Changes for repo groups
Marcin Kuzminski <marcin@python-works.com>
parents: 1155
diff changeset
1558
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
1559 @property
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
1560 def children(self):
1633
2c0d35e336b5 refactoring of models names for repoGroup permissions
Marcin Kuzminski <marcin@python-works.com>
parents: 1607
diff changeset
1561 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
1562
a7a772ea7b95 fixed saving settings on repositories inside groups, also fixes #187
Marcin Kuzminski <marcin@python-works.com>
parents: 1301
diff changeset
1563 @property
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
1564 def name(self):
1633
2c0d35e336b5 refactoring of models names for repoGroup permissions
Marcin Kuzminski <marcin@python-works.com>
parents: 1607
diff changeset
1565 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
1566
27be8f94c207 implements #226 repo groups available by path
Marcin Kuzminski <marcin@python-works.com>
parents: 1530
diff changeset
1567 @property
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
1568 def full_path(self):
1594
9dae92a65e40 fixes #288
Marcin Kuzminski <marcin@python-works.com>
parents: 1593
diff changeset
1569 return self.group_name
1538
27be8f94c207 implements #226 repo groups available by path
Marcin Kuzminski <marcin@python-works.com>
parents: 1530
diff changeset
1570
27be8f94c207 implements #226 repo groups available by path
Marcin Kuzminski <marcin@python-works.com>
parents: 1530
diff changeset
1571 @property
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
1572 def full_path_splitted(self):
1633
2c0d35e336b5 refactoring of models names for repoGroup permissions
Marcin Kuzminski <marcin@python-works.com>
parents: 1607
diff changeset
1573 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
1574
1193
523382549c45 Added repo group page showing what reposiories are inside a group
Marcin Kuzminski <marcin@python-works.com>
parents: 1159
diff changeset
1575 @property
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
1576 def repositories(self):
2079
477fe54b8af8 fixed sorting of repos in group
Marcin Kuzminski <marcin@python-works.com>
parents: 2063
diff changeset
1577 return Repository.query()\
477fe54b8af8 fixed sorting of repos in group
Marcin Kuzminski <marcin@python-works.com>
parents: 2063
diff changeset
1578 .filter(Repository.group == self)\
477fe54b8af8 fixed sorting of repos in group
Marcin Kuzminski <marcin@python-works.com>
parents: 2063
diff changeset
1579 .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
1580
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
1581 @property
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
1582 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
1583 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
1584
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
1585 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
1586 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
1587 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
1588 cnt += child.repositories.count()
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
1589 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
1590 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
1591
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
1592 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
1593
3459
94f251fda314 fixed issue with renaming repos group together with changing parents with multiple nested trees
Marcin Kuzminski <marcin@python-works.com>
parents: 3457
diff changeset
1594 def _recursive_objects(self, include_repos=True):
2749
3ed4dae499d0 Recursive set locking on all children of a group.
Marcin Kuzminski <marcin@python-works.com>
parents: 2731
diff changeset
1595 all_ = []
3ed4dae499d0 Recursive set locking on all children of a group.
Marcin Kuzminski <marcin@python-works.com>
parents: 2731
diff changeset
1596
3ed4dae499d0 Recursive set locking on all children of a group.
Marcin Kuzminski <marcin@python-works.com>
parents: 2731
diff changeset
1597 def _get_members(root_gr):
3459
94f251fda314 fixed issue with renaming repos group together with changing parents with multiple nested trees
Marcin Kuzminski <marcin@python-works.com>
parents: 3457
diff changeset
1598 if include_repos:
94f251fda314 fixed issue with renaming repos group together with changing parents with multiple nested trees
Marcin Kuzminski <marcin@python-works.com>
parents: 3457
diff changeset
1599 for r in root_gr.repositories:
94f251fda314 fixed issue with renaming repos group together with changing parents with multiple nested trees
Marcin Kuzminski <marcin@python-works.com>
parents: 3457
diff changeset
1600 all_.append(r)
2749
3ed4dae499d0 Recursive set locking on all children of a group.
Marcin Kuzminski <marcin@python-works.com>
parents: 2731
diff changeset
1601 childs = root_gr.children.all()
3ed4dae499d0 Recursive set locking on all children of a group.
Marcin Kuzminski <marcin@python-works.com>
parents: 2731
diff changeset
1602 if childs:
3ed4dae499d0 Recursive set locking on all children of a group.
Marcin Kuzminski <marcin@python-works.com>
parents: 2731
diff changeset
1603 for gr in childs:
3ed4dae499d0 Recursive set locking on all children of a group.
Marcin Kuzminski <marcin@python-works.com>
parents: 2731
diff changeset
1604 all_.append(gr)
3ed4dae499d0 Recursive set locking on all children of a group.
Marcin Kuzminski <marcin@python-works.com>
parents: 2731
diff changeset
1605 _get_members(gr)
3ed4dae499d0 Recursive set locking on all children of a group.
Marcin Kuzminski <marcin@python-works.com>
parents: 2731
diff changeset
1606
3ed4dae499d0 Recursive set locking on all children of a group.
Marcin Kuzminski <marcin@python-works.com>
parents: 2731
diff changeset
1607 _get_members(self)
3ed4dae499d0 Recursive set locking on all children of a group.
Marcin Kuzminski <marcin@python-works.com>
parents: 2731
diff changeset
1608 return [self] + all_
3ed4dae499d0 Recursive set locking on all children of a group.
Marcin Kuzminski <marcin@python-works.com>
parents: 2731
diff changeset
1609
3459
94f251fda314 fixed issue with renaming repos group together with changing parents with multiple nested trees
Marcin Kuzminski <marcin@python-works.com>
parents: 3457
diff changeset
1610 def recursive_groups_and_repos(self):
94f251fda314 fixed issue with renaming repos group together with changing parents with multiple nested trees
Marcin Kuzminski <marcin@python-works.com>
parents: 3457
diff changeset
1611 """
94f251fda314 fixed issue with renaming repos group together with changing parents with multiple nested trees
Marcin Kuzminski <marcin@python-works.com>
parents: 3457
diff changeset
1612 Recursive return all groups, with repositories in those groups
94f251fda314 fixed issue with renaming repos group together with changing parents with multiple nested trees
Marcin Kuzminski <marcin@python-works.com>
parents: 3457
diff changeset
1613 """
94f251fda314 fixed issue with renaming repos group together with changing parents with multiple nested trees
Marcin Kuzminski <marcin@python-works.com>
parents: 3457
diff changeset
1614 return self._recursive_objects()
94f251fda314 fixed issue with renaming repos group together with changing parents with multiple nested trees
Marcin Kuzminski <marcin@python-works.com>
parents: 3457
diff changeset
1615
94f251fda314 fixed issue with renaming repos group together with changing parents with multiple nested trees
Marcin Kuzminski <marcin@python-works.com>
parents: 3457
diff changeset
1616 def recursive_groups(self):
94f251fda314 fixed issue with renaming repos group together with changing parents with multiple nested trees
Marcin Kuzminski <marcin@python-works.com>
parents: 3457
diff changeset
1617 """
3473
b30a842bc164 codecleaner
Marcin Kuzminski <marcin@python-works.com>
parents: 3459
diff changeset
1618 Returns all children groups for this group including children of children
3459
94f251fda314 fixed issue with renaming repos group together with changing parents with multiple nested trees
Marcin Kuzminski <marcin@python-works.com>
parents: 3457
diff changeset
1619 """
94f251fda314 fixed issue with renaming repos group together with changing parents with multiple nested trees
Marcin Kuzminski <marcin@python-works.com>
parents: 3457
diff changeset
1620 return self._recursive_objects(include_repos=False)
94f251fda314 fixed issue with renaming repos group together with changing parents with multiple nested trees
Marcin Kuzminski <marcin@python-works.com>
parents: 3457
diff changeset
1621
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
1622 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
1623 """
27be8f94c207 implements #226 repo groups available by path
Marcin Kuzminski <marcin@python-works.com>
parents: 1530
diff changeset
1624 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
1625
1538
27be8f94c207 implements #226 repo groups available by path
Marcin Kuzminski <marcin@python-works.com>
parents: 1530
diff changeset
1626 :param group_name:
27be8f94c207 implements #226 repo groups available by path
Marcin Kuzminski <marcin@python-works.com>
parents: 1530
diff changeset
1627 """
1607
e886f91fcb71 Cached readme generation
Marcin Kuzminski <marcin@python-works.com>
parents: 1594
diff changeset
1628 path_prefix = (self.parent_group.full_path_splitted if
1594
9dae92a65e40 fixes #288
Marcin Kuzminski <marcin@python-works.com>
parents: 1593
diff changeset
1629 self.parent_group else [])
1633
2c0d35e336b5 refactoring of models names for repoGroup permissions
Marcin Kuzminski <marcin@python-works.com>
parents: 1607
diff changeset
1630 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
1631
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
1632 def get_api_data(self):
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
1633 """
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
1634 Common function for generating api data
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
1635
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
1636 """
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
1637 group = self
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
1638 data = dict(
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
1639 group_id=group.group_id,
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
1640 group_name=group.group_name,
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
1641 group_description=group.group_description,
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
1642 parent_group=group.parent_group.group_name if group.parent_group else None,
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
1643 repositories=[x.repo_name for x in group.repositories],
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
1644 owner=group.user.username
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
1645 )
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
1646 return data
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
1647
1538
27be8f94c207 implements #226 repo groups available by path
Marcin Kuzminski <marcin@python-works.com>
parents: 1530
diff changeset
1648
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
1649 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
1650 __tablename__ = 'permissions'
2149
50aa7cb78cfe Mysql fixes
Marcin Kuzminski <marcin@python-works.com>
parents: 2147
diff changeset
1651 __table_args__ = (
2463
b426ecc30319 Added some DB indexes to optimize queries
Marcin Kuzminski <marcin@python-works.com>
parents: 2462
diff changeset
1652 Index('p_perm_name_idx', 'permission_name'),
2356
2da7b5984ae5 typo fix + code garden
Marcin Kuzminski <marcin@python-works.com>
parents: 2352
diff changeset
1653 {'extend_existing': True, 'mysql_engine': 'InnoDB',
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
1654 'mysql_charset': 'utf8', 'sqlite_autoincrement': True},
2149
50aa7cb78cfe Mysql fixes
Marcin Kuzminski <marcin@python-works.com>
parents: 2147
diff changeset
1655 )
2532
19de74e33fb0 Better descriptions of given permission overview in edit user view
Marcin Kuzminski <marcin@python-works.com>
parents: 2531
diff changeset
1656 PERMS = [
3733
af049a957506 fixed default permissions population during upgrades
Marcin Kuzminski <marcin@python-works.com>
parents: 3729
diff changeset
1657 ('hg.admin', _('RhodeCode Administrator')),
af049a957506 fixed default permissions population during upgrades
Marcin Kuzminski <marcin@python-works.com>
parents: 3729
diff changeset
1658
2532
19de74e33fb0 Better descriptions of given permission overview in edit user view
Marcin Kuzminski <marcin@python-works.com>
parents: 2531
diff changeset
1659 ('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
1660 ('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
1661 ('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
1662 ('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
1663
3416
5706f6ab60cf follow-up on texts missing from 'users groups'/'repositories group' cleanup
Mads Kiilerich <madski@unity3d.com>
parents: 3370
diff changeset
1664 ('group.none', _('Repository group no access')),
5706f6ab60cf follow-up on texts missing from 'users groups'/'repositories group' cleanup
Mads Kiilerich <madski@unity3d.com>
parents: 3370
diff changeset
1665 ('group.read', _('Repository group read access')),
5706f6ab60cf follow-up on texts missing from 'users groups'/'repositories group' cleanup
Mads Kiilerich <madski@unity3d.com>
parents: 3370
diff changeset
1666 ('group.write', _('Repository group write access')),
5706f6ab60cf follow-up on texts missing from 'users groups'/'repositories group' cleanup
Mads Kiilerich <madski@unity3d.com>
parents: 3370
diff changeset
1667 ('group.admin', _('Repository group admin access')),
2532
19de74e33fb0 Better descriptions of given permission overview in edit user view
Marcin Kuzminski <marcin@python-works.com>
parents: 2531
diff changeset
1668
3714
7e3d89d9d3a2 - Manage Userโ€™s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents: 3687
diff changeset
1669 ('usergroup.none', _('User group no access')),
7e3d89d9d3a2 - Manage Userโ€™s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents: 3687
diff changeset
1670 ('usergroup.read', _('User group read access')),
7e3d89d9d3a2 - Manage Userโ€™s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents: 3687
diff changeset
1671 ('usergroup.write', _('User group write access')),
7e3d89d9d3a2 - Manage Userโ€™s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents: 3687
diff changeset
1672 ('usergroup.admin', _('User group admin access')),
7e3d89d9d3a2 - Manage Userโ€™s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents: 3687
diff changeset
1673
3734
a8f520540ab0 New default permissions definition for user group create
Marcin Kuzminski <marcin@python-works.com>
parents: 3733
diff changeset
1674 ('hg.repogroup.create.false', _('Repository Group creation disabled')),
a8f520540ab0 New default permissions definition for user group create
Marcin Kuzminski <marcin@python-works.com>
parents: 3733
diff changeset
1675 ('hg.repogroup.create.true', _('Repository Group creation enabled')),
a8f520540ab0 New default permissions definition for user group create
Marcin Kuzminski <marcin@python-works.com>
parents: 3733
diff changeset
1676
a8f520540ab0 New default permissions definition for user group create
Marcin Kuzminski <marcin@python-works.com>
parents: 3733
diff changeset
1677 ('hg.usergroup.create.false', _('User Group creation disabled')),
a8f520540ab0 New default permissions definition for user group create
Marcin Kuzminski <marcin@python-works.com>
parents: 3733
diff changeset
1678 ('hg.usergroup.create.true', _('User Group creation enabled')),
a8f520540ab0 New default permissions definition for user group create
Marcin Kuzminski <marcin@python-works.com>
parents: 3733
diff changeset
1679
2532
19de74e33fb0 Better descriptions of given permission overview in edit user view
Marcin Kuzminski <marcin@python-works.com>
parents: 2531
diff changeset
1680 ('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
1681 ('hg.create.repository', _('Repository creation enabled')),
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
1682 ('hg.create.write_on_repogroup.true', _('Repository creation enabled with write permission to a repository group')),
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
1683 ('hg.create.write_on_repogroup.false', _('Repository creation disabled with write permission to a repository group')),
3733
af049a957506 fixed default permissions population during upgrades
Marcin Kuzminski <marcin@python-works.com>
parents: 3729
diff changeset
1684
2709
d2d35cf2b351 RhodeCode now has a option to explicitly set forking permissions. ref #508
Marcin Kuzminski <marcin@python-works.com>
parents: 2708
diff changeset
1685 ('hg.fork.none', _('Repository forking disabled')),
d2d35cf2b351 RhodeCode now has a option to explicitly set forking permissions. ref #508
Marcin Kuzminski <marcin@python-works.com>
parents: 2708
diff changeset
1686 ('hg.fork.repository', _('Repository forking enabled')),
3733
af049a957506 fixed default permissions population during upgrades
Marcin Kuzminski <marcin@python-works.com>
parents: 3729
diff changeset
1687
3786
222e6769e7b5 Added separate default permission for external_auth account
Marcin Kuzminski <marcin@python-works.com>
parents: 3773
diff changeset
1688 ('hg.register.none', _('Registration disabled')),
222e6769e7b5 Added separate default permission for external_auth account
Marcin Kuzminski <marcin@python-works.com>
parents: 3773
diff changeset
1689 ('hg.register.manual_activate', _('User Registration with manual account activation')),
222e6769e7b5 Added separate default permission for external_auth account
Marcin Kuzminski <marcin@python-works.com>
parents: 3773
diff changeset
1690 ('hg.register.auto_activate', _('User Registration with automatic account activation')),
2532
19de74e33fb0 Better descriptions of given permission overview in edit user view
Marcin Kuzminski <marcin@python-works.com>
parents: 2531
diff changeset
1691
3786
222e6769e7b5 Added separate default permission for external_auth account
Marcin Kuzminski <marcin@python-works.com>
parents: 3773
diff changeset
1692 ('hg.extern_activate.manual', _('Manual activation of external account')),
222e6769e7b5 Added separate default permission for external_auth account
Marcin Kuzminski <marcin@python-works.com>
parents: 3773
diff changeset
1693 ('hg.extern_activate.auto', _('Automatic activation of external account')),
222e6769e7b5 Added separate default permission for external_auth account
Marcin Kuzminski <marcin@python-works.com>
parents: 3773
diff changeset
1694
2532
19de74e33fb0 Better descriptions of given permission overview in edit user view
Marcin Kuzminski <marcin@python-works.com>
parents: 2531
diff changeset
1695 ]
19de74e33fb0 Better descriptions of given permission overview in edit user view
Marcin Kuzminski <marcin@python-works.com>
parents: 2531
diff changeset
1696
3733
af049a957506 fixed default permissions population during upgrades
Marcin Kuzminski <marcin@python-works.com>
parents: 3729
diff changeset
1697 #definition of system default permissions for DEFAULT user
af049a957506 fixed default permissions population during upgrades
Marcin Kuzminski <marcin@python-works.com>
parents: 3729
diff changeset
1698 DEFAULT_USER_PERMISSIONS = [
af049a957506 fixed default permissions population during upgrades
Marcin Kuzminski <marcin@python-works.com>
parents: 3729
diff changeset
1699 'repository.read',
af049a957506 fixed default permissions population during upgrades
Marcin Kuzminski <marcin@python-works.com>
parents: 3729
diff changeset
1700 'group.read',
af049a957506 fixed default permissions population during upgrades
Marcin Kuzminski <marcin@python-works.com>
parents: 3729
diff changeset
1701 'usergroup.read',
af049a957506 fixed default permissions population during upgrades
Marcin Kuzminski <marcin@python-works.com>
parents: 3729
diff changeset
1702 'hg.create.repository',
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
1703 'hg.create.write_on_repogroup.true',
3733
af049a957506 fixed default permissions population during upgrades
Marcin Kuzminski <marcin@python-works.com>
parents: 3729
diff changeset
1704 'hg.fork.repository',
af049a957506 fixed default permissions population during upgrades
Marcin Kuzminski <marcin@python-works.com>
parents: 3729
diff changeset
1705 'hg.register.manual_activate',
3786
222e6769e7b5 Added separate default permission for external_auth account
Marcin Kuzminski <marcin@python-works.com>
parents: 3773
diff changeset
1706 'hg.extern_activate.auto',
3733
af049a957506 fixed default permissions population during upgrades
Marcin Kuzminski <marcin@python-works.com>
parents: 3729
diff changeset
1707 ]
af049a957506 fixed default permissions population during upgrades
Marcin Kuzminski <marcin@python-works.com>
parents: 3729
diff changeset
1708
2709
d2d35cf2b351 RhodeCode now has a option to explicitly set forking permissions. ref #508
Marcin Kuzminski <marcin@python-works.com>
parents: 2708
diff changeset
1709 # defines which permissions are more important higher the more important
3734
a8f520540ab0 New default permissions definition for user group create
Marcin Kuzminski <marcin@python-works.com>
parents: 3733
diff changeset
1710 # Weight defines which permissions are more important.
a8f520540ab0 New default permissions definition for user group create
Marcin Kuzminski <marcin@python-works.com>
parents: 3733
diff changeset
1711 # The higher number the more important.
2709
d2d35cf2b351 RhodeCode now has a option to explicitly set forking permissions. ref #508
Marcin Kuzminski <marcin@python-works.com>
parents: 2708
diff changeset
1712 PERM_WEIGHTS = {
d2d35cf2b351 RhodeCode now has a option to explicitly set forking permissions. ref #508
Marcin Kuzminski <marcin@python-works.com>
parents: 2708
diff changeset
1713 'repository.none': 0,
d2d35cf2b351 RhodeCode now has a option to explicitly set forking permissions. ref #508
Marcin Kuzminski <marcin@python-works.com>
parents: 2708
diff changeset
1714 'repository.read': 1,
d2d35cf2b351 RhodeCode now has a option to explicitly set forking permissions. ref #508
Marcin Kuzminski <marcin@python-works.com>
parents: 2708
diff changeset
1715 'repository.write': 3,
d2d35cf2b351 RhodeCode now has a option to explicitly set forking permissions. ref #508
Marcin Kuzminski <marcin@python-works.com>
parents: 2708
diff changeset
1716 'repository.admin': 4,
d2d35cf2b351 RhodeCode now has a option to explicitly set forking permissions. ref #508
Marcin Kuzminski <marcin@python-works.com>
parents: 2708
diff changeset
1717
d2d35cf2b351 RhodeCode now has a option to explicitly set forking permissions. ref #508
Marcin Kuzminski <marcin@python-works.com>
parents: 2708
diff changeset
1718 'group.none': 0,
d2d35cf2b351 RhodeCode now has a option to explicitly set forking permissions. ref #508
Marcin Kuzminski <marcin@python-works.com>
parents: 2708
diff changeset
1719 'group.read': 1,
d2d35cf2b351 RhodeCode now has a option to explicitly set forking permissions. ref #508
Marcin Kuzminski <marcin@python-works.com>
parents: 2708
diff changeset
1720 'group.write': 3,
d2d35cf2b351 RhodeCode now has a option to explicitly set forking permissions. ref #508
Marcin Kuzminski <marcin@python-works.com>
parents: 2708
diff changeset
1721 'group.admin': 4,
d2d35cf2b351 RhodeCode now has a option to explicitly set forking permissions. ref #508
Marcin Kuzminski <marcin@python-works.com>
parents: 2708
diff changeset
1722
3714
7e3d89d9d3a2 - Manage Userโ€™s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents: 3687
diff changeset
1723 'usergroup.none': 0,
7e3d89d9d3a2 - Manage Userโ€™s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents: 3687
diff changeset
1724 'usergroup.read': 1,
7e3d89d9d3a2 - Manage Userโ€™s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents: 3687
diff changeset
1725 'usergroup.write': 3,
7e3d89d9d3a2 - Manage Userโ€™s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents: 3687
diff changeset
1726 'usergroup.admin': 4,
3734
a8f520540ab0 New default permissions definition for user group create
Marcin Kuzminski <marcin@python-works.com>
parents: 3733
diff changeset
1727 'hg.repogroup.create.false': 0,
a8f520540ab0 New default permissions definition for user group create
Marcin Kuzminski <marcin@python-works.com>
parents: 3733
diff changeset
1728 'hg.repogroup.create.true': 1,
a8f520540ab0 New default permissions definition for user group create
Marcin Kuzminski <marcin@python-works.com>
parents: 3733
diff changeset
1729
a8f520540ab0 New default permissions definition for user group create
Marcin Kuzminski <marcin@python-works.com>
parents: 3733
diff changeset
1730 'hg.usergroup.create.false': 0,
a8f520540ab0 New default permissions definition for user group create
Marcin Kuzminski <marcin@python-works.com>
parents: 3733
diff changeset
1731 'hg.usergroup.create.true': 1,
3714
7e3d89d9d3a2 - Manage Userโ€™s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents: 3687
diff changeset
1732
2709
d2d35cf2b351 RhodeCode now has a option to explicitly set forking permissions. ref #508
Marcin Kuzminski <marcin@python-works.com>
parents: 2708
diff changeset
1733 'hg.fork.none': 0,
d2d35cf2b351 RhodeCode now has a option to explicitly set forking permissions. ref #508
Marcin Kuzminski <marcin@python-works.com>
parents: 2708
diff changeset
1734 'hg.fork.repository': 1,
d2d35cf2b351 RhodeCode now has a option to explicitly set forking permissions. ref #508
Marcin Kuzminski <marcin@python-works.com>
parents: 2708
diff changeset
1735 'hg.create.none': 0,
3714
7e3d89d9d3a2 - Manage Userโ€™s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents: 3687
diff changeset
1736 'hg.create.repository': 1
2709
d2d35cf2b351 RhodeCode now has a option to explicitly set forking permissions. ref #508
Marcin Kuzminski <marcin@python-works.com>
parents: 2708
diff changeset
1737 }
d2d35cf2b351 RhodeCode now has a option to explicitly set forking permissions. ref #508
Marcin Kuzminski <marcin@python-works.com>
parents: 2708
diff changeset
1738
1594
9dae92a65e40 fixes #288
Marcin Kuzminski <marcin@python-works.com>
parents: 1593
diff changeset
1739 permission_id = Column("permission_id", Integer(), nullable=False, unique=True, default=None, primary_key=True)
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
1740 permission_name = Column("permission_name", String(255, convert_unicode=False), nullable=True, unique=None, default=None)
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
1741 permission_longname = Column("permission_longname", String(255, convert_unicode=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
1742
2156
a27e4d44237e Use __unicode__ instead of __repr__ in models.
Marcin Kuzminski <marcin@python-works.com>
parents: 2152
diff changeset
1743 def __unicode__(self):
a27e4d44237e Use __unicode__ instead of __repr__ in models.
Marcin Kuzminski <marcin@python-works.com>
parents: 2152
diff changeset
1744 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
1745 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
1746 )
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
1747
1266
a1bcfe58a1ab Fixed #161 form saves the create repository permission.
Marcin Kuzminski <marcin@python-works.com>
parents: 1206
diff changeset
1748 @classmethod
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
1749 def get_by_key(cls, key):
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
1750 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
1751
1728
07e56179633e - fixes celery sqlalchemy session issues for async forking
Marcin Kuzminski <marcin@python-works.com>
parents: 1727
diff changeset
1752 @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
1753 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
1754 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
1755 .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
1756 .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
1757 .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
1758
87f0800abc7b #227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents: 1976
diff changeset
1759 return q.all()
87f0800abc7b #227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents: 1976
diff changeset
1760
87f0800abc7b #227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents: 1976
diff changeset
1761 @classmethod
87f0800abc7b #227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents: 1976
diff changeset
1762 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
1763 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
1764 .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
1765 .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
1766 .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
1767
07e56179633e - fixes celery sqlalchemy session issues for async forking
Marcin Kuzminski <marcin@python-works.com>
parents: 1727
diff changeset
1768 return q.all()
07e56179633e - fixes celery sqlalchemy session issues for async forking
Marcin Kuzminski <marcin@python-works.com>
parents: 1727
diff changeset
1769
3714
7e3d89d9d3a2 - Manage Userโ€™s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents: 3687
diff changeset
1770 @classmethod
7e3d89d9d3a2 - Manage Userโ€™s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents: 3687
diff changeset
1771 def get_default_user_group_perms(cls, default_user_id):
7e3d89d9d3a2 - Manage Userโ€™s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents: 3687
diff changeset
1772 q = Session().query(UserUserGroupToPerm, UserGroup, cls)\
7e3d89d9d3a2 - Manage Userโ€™s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents: 3687
diff changeset
1773 .join((UserGroup, UserUserGroupToPerm.user_group_id == UserGroup.users_group_id))\
7e3d89d9d3a2 - Manage Userโ€™s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents: 3687
diff changeset
1774 .join((cls, UserUserGroupToPerm.permission_id == cls.permission_id))\
7e3d89d9d3a2 - Manage Userโ€™s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents: 3687
diff changeset
1775 .filter(UserUserGroupToPerm.user_id == default_user_id)
7e3d89d9d3a2 - Manage Userโ€™s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents: 3687
diff changeset
1776
7e3d89d9d3a2 - Manage Userโ€™s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents: 3687
diff changeset
1777 return q.all()
7e3d89d9d3a2 - Manage Userโ€™s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents: 3687
diff changeset
1778
1728
07e56179633e - fixes celery sqlalchemy session issues for async forking
Marcin Kuzminski <marcin@python-works.com>
parents: 1727
diff changeset
1779
1633
2c0d35e336b5 refactoring of models names for repoGroup permissions
Marcin Kuzminski <marcin@python-works.com>
parents: 1607
diff changeset
1780 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
1781 __tablename__ = 'repo_to_perm'
1958
7e4b3d3a9c5c renamed repo groups table
Marcin Kuzminski <marcin@python-works.com>
parents: 1950
diff changeset
1782 __table_args__ = (
2000
72c525a7e7ad added migrations from 1.2.X to 1.3
Marcin Kuzminski <marcin@python-works.com>
parents: 1990
diff changeset
1783 UniqueConstraint('user_id', 'repository_id', 'permission_id'),
2356
2da7b5984ae5 typo fix + code garden
Marcin Kuzminski <marcin@python-works.com>
parents: 2352
diff changeset
1784 {'extend_existing': True, 'mysql_engine': 'InnoDB',
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
1785 'mysql_charset': 'utf8', 'sqlite_autoincrement': True}
1958
7e4b3d3a9c5c renamed repo groups table
Marcin Kuzminski <marcin@python-works.com>
parents: 1950
diff changeset
1786 )
1594
9dae92a65e40 fixes #288
Marcin Kuzminski <marcin@python-works.com>
parents: 1593
diff changeset
1787 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
1788 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
1789 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
1790 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
1791
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
1792 user = relationship('User')
2000
72c525a7e7ad added migrations from 1.2.X to 1.3
Marcin Kuzminski <marcin@python-works.com>
parents: 1990
diff changeset
1793 repository = relationship('Repository')
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
1794 permission = relationship('Permission')
399
f5c1eec9f376 rename repo2perm into repo_to_perm
Marcin Kuzminski <marcin@python-works.com>
parents: 392
diff changeset
1795
1729
da8ee2ef7f6d implements #236 forking copy permission option
Marcin Kuzminski <marcin@python-works.com>
parents: 1728
diff changeset
1796 @classmethod
da8ee2ef7f6d implements #236 forking copy permission option
Marcin Kuzminski <marcin@python-works.com>
parents: 1728
diff changeset
1797 def create(cls, user, repository, permission):
da8ee2ef7f6d implements #236 forking copy permission option
Marcin Kuzminski <marcin@python-works.com>
parents: 1728
diff changeset
1798 n = cls()
da8ee2ef7f6d implements #236 forking copy permission option
Marcin Kuzminski <marcin@python-works.com>
parents: 1728
diff changeset
1799 n.user = user
da8ee2ef7f6d implements #236 forking copy permission option
Marcin Kuzminski <marcin@python-works.com>
parents: 1728
diff changeset
1800 n.repository = repository
da8ee2ef7f6d implements #236 forking copy permission option
Marcin Kuzminski <marcin@python-works.com>
parents: 1728
diff changeset
1801 n.permission = permission
2520
a1e156503afe Fixed calls to Session in db model
Marcin Kuzminski <marcin@python-works.com>
parents: 2510
diff changeset
1802 Session().add(n)
1729
da8ee2ef7f6d implements #236 forking copy permission option
Marcin Kuzminski <marcin@python-works.com>
parents: 1728
diff changeset
1803 return n
da8ee2ef7f6d implements #236 forking copy permission option
Marcin Kuzminski <marcin@python-works.com>
parents: 1728
diff changeset
1804
2156
a27e4d44237e Use __unicode__ instead of __repr__ in models.
Marcin Kuzminski <marcin@python-works.com>
parents: 2152
diff changeset
1805 def __unicode__(self):
3714
7e3d89d9d3a2 - Manage Userโ€™s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents: 3687
diff changeset
1806 return u'<%s => %s >' % (self.user, self.repository)
7e3d89d9d3a2 - Manage Userโ€™s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents: 3687
diff changeset
1807
7e3d89d9d3a2 - Manage Userโ€™s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents: 3687
diff changeset
1808
7e3d89d9d3a2 - Manage Userโ€™s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents: 3687
diff changeset
1809 class UserUserGroupToPerm(Base, BaseModel):
7e3d89d9d3a2 - Manage Userโ€™s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents: 3687
diff changeset
1810 __tablename__ = 'user_user_group_to_perm'
7e3d89d9d3a2 - Manage Userโ€™s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents: 3687
diff changeset
1811 __table_args__ = (
7e3d89d9d3a2 - Manage Userโ€™s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents: 3687
diff changeset
1812 UniqueConstraint('user_id', 'user_group_id', 'permission_id'),
7e3d89d9d3a2 - Manage Userโ€™s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents: 3687
diff changeset
1813 {'extend_existing': True, 'mysql_engine': 'InnoDB',
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
1814 'mysql_charset': 'utf8', 'sqlite_autoincrement': True}
3714
7e3d89d9d3a2 - Manage Userโ€™s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents: 3687
diff changeset
1815 )
7e3d89d9d3a2 - Manage Userโ€™s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents: 3687
diff changeset
1816 user_user_group_to_perm_id = Column("user_user_group_to_perm_id", Integer(), nullable=False, unique=True, default=None, primary_key=True)
7e3d89d9d3a2 - Manage Userโ€™s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents: 3687
diff changeset
1817 user_id = Column("user_id", Integer(), ForeignKey('users.user_id'), nullable=False, unique=None, default=None)
7e3d89d9d3a2 - Manage Userโ€™s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents: 3687
diff changeset
1818 permission_id = Column("permission_id", Integer(), ForeignKey('permissions.permission_id'), nullable=False, unique=None, default=None)
7e3d89d9d3a2 - Manage Userโ€™s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents: 3687
diff changeset
1819 user_group_id = Column("user_group_id", Integer(), ForeignKey('users_groups.users_group_id'), nullable=False, unique=None, default=None)
7e3d89d9d3a2 - Manage Userโ€™s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents: 3687
diff changeset
1820
7e3d89d9d3a2 - Manage Userโ€™s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents: 3687
diff changeset
1821 user = relationship('User')
7e3d89d9d3a2 - Manage Userโ€™s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents: 3687
diff changeset
1822 user_group = relationship('UserGroup')
7e3d89d9d3a2 - Manage Userโ€™s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents: 3687
diff changeset
1823 permission = relationship('Permission')
7e3d89d9d3a2 - Manage Userโ€™s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents: 3687
diff changeset
1824
7e3d89d9d3a2 - Manage Userโ€™s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents: 3687
diff changeset
1825 @classmethod
7e3d89d9d3a2 - Manage Userโ€™s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents: 3687
diff changeset
1826 def create(cls, user, user_group, permission):
7e3d89d9d3a2 - Manage Userโ€™s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents: 3687
diff changeset
1827 n = cls()
7e3d89d9d3a2 - Manage Userโ€™s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents: 3687
diff changeset
1828 n.user = user
7e3d89d9d3a2 - Manage Userโ€™s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents: 3687
diff changeset
1829 n.user_group = user_group
7e3d89d9d3a2 - Manage Userโ€™s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents: 3687
diff changeset
1830 n.permission = permission
7e3d89d9d3a2 - Manage Userโ€™s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents: 3687
diff changeset
1831 Session().add(n)
7e3d89d9d3a2 - Manage Userโ€™s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents: 3687
diff changeset
1832 return n
7e3d89d9d3a2 - Manage Userโ€™s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents: 3687
diff changeset
1833
7e3d89d9d3a2 - Manage Userโ€™s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents: 3687
diff changeset
1834 def __unicode__(self):
7e3d89d9d3a2 - Manage Userโ€™s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents: 3687
diff changeset
1835 return u'<%s => %s >' % (self.user, self.user_group)
1729
da8ee2ef7f6d implements #236 forking copy permission option
Marcin Kuzminski <marcin@python-works.com>
parents: 1728
diff changeset
1836
1800
6c86c987cf93 pep8ify
Marcin Kuzminski <marcin@python-works.com>
parents: 1758
diff changeset
1837
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
1838 class UserToPerm(Base, BaseModel):
399
f5c1eec9f376 rename repo2perm into repo_to_perm
Marcin Kuzminski <marcin@python-works.com>
parents: 392
diff changeset
1839 __tablename__ = 'user_to_perm'
1988
5eae67552695 db unique constraints fixes
Marcin Kuzminski <marcin@python-works.com>
parents: 1982
diff changeset
1840 __table_args__ = (
5eae67552695 db unique constraints fixes
Marcin Kuzminski <marcin@python-works.com>
parents: 1982
diff changeset
1841 UniqueConstraint('user_id', 'permission_id'),
2356
2da7b5984ae5 typo fix + code garden
Marcin Kuzminski <marcin@python-works.com>
parents: 2352
diff changeset
1842 {'extend_existing': True, 'mysql_engine': 'InnoDB',
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
1843 'mysql_charset': 'utf8', 'sqlite_autoincrement': True}
1988
5eae67552695 db unique constraints fixes
Marcin Kuzminski <marcin@python-works.com>
parents: 1982
diff changeset
1844 )
1594
9dae92a65e40 fixes #288
Marcin Kuzminski <marcin@python-works.com>
parents: 1593
diff changeset
1845 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
1846 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
1847 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
1848
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
1849 user = relationship('User')
1728
07e56179633e - fixes celery sqlalchemy session issues for async forking
Marcin Kuzminski <marcin@python-works.com>
parents: 1727
diff changeset
1850 permission = relationship('Permission', lazy='joined')
399
f5c1eec9f376 rename repo2perm into repo_to_perm
Marcin Kuzminski <marcin@python-works.com>
parents: 392
diff changeset
1851
3729
49e5d4fa01e9 add repr for UserToPerm
Marcin Kuzminski <marcin@python-works.com>
parents: 3717
diff changeset
1852 def __unicode__(self):
49e5d4fa01e9 add repr for UserToPerm
Marcin Kuzminski <marcin@python-works.com>
parents: 3717
diff changeset
1853 return u'<%s => %s >' % (self.user, self.permission)
49e5d4fa01e9 add repr for UserToPerm
Marcin Kuzminski <marcin@python-works.com>
parents: 3717
diff changeset
1854
1014
6fdc3ff65fce #56 added assignments of users groups into repository
Marcin Kuzminski <marcin@python-works.com>
parents: 1000
diff changeset
1855
3417
fa6ba6727475 further cleanup of UsersGroup
Mads Kiilerich <madski@unity3d.com>
parents: 3416
diff changeset
1856 class UserGroupRepoToPerm(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
1857 __tablename__ = 'users_group_repo_to_perm'
1958
7e4b3d3a9c5c renamed repo groups table
Marcin Kuzminski <marcin@python-works.com>
parents: 1950
diff changeset
1858 __table_args__ = (
2000
72c525a7e7ad added migrations from 1.2.X to 1.3
Marcin Kuzminski <marcin@python-works.com>
parents: 1990
diff changeset
1859 UniqueConstraint('repository_id', 'users_group_id', 'permission_id'),
2356
2da7b5984ae5 typo fix + code garden
Marcin Kuzminski <marcin@python-works.com>
parents: 2352
diff changeset
1860 {'extend_existing': True, 'mysql_engine': 'InnoDB',
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
1861 'mysql_charset': 'utf8', 'sqlite_autoincrement': True}
1958
7e4b3d3a9c5c renamed repo groups table
Marcin Kuzminski <marcin@python-works.com>
parents: 1950
diff changeset
1862 )
1594
9dae92a65e40 fixes #288
Marcin Kuzminski <marcin@python-works.com>
parents: 1593
diff changeset
1863 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
1864 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
1865 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
1866 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
1867
3417
fa6ba6727475 further cleanup of UsersGroup
Mads Kiilerich <madski@unity3d.com>
parents: 3416
diff changeset
1868 users_group = relationship('UserGroup')
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
1869 permission = relationship('Permission')
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
1870 repository = relationship('Repository')
958
7d1483f3170b added user group to perm table
Marcin Kuzminski <marcin@python-works.com>
parents: 956
diff changeset
1871
1729
da8ee2ef7f6d implements #236 forking copy permission option
Marcin Kuzminski <marcin@python-works.com>
parents: 1728
diff changeset
1872 @classmethod
da8ee2ef7f6d implements #236 forking copy permission option
Marcin Kuzminski <marcin@python-works.com>
parents: 1728
diff changeset
1873 def create(cls, users_group, repository, permission):
da8ee2ef7f6d implements #236 forking copy permission option
Marcin Kuzminski <marcin@python-works.com>
parents: 1728
diff changeset
1874 n = cls()
da8ee2ef7f6d implements #236 forking copy permission option
Marcin Kuzminski <marcin@python-works.com>
parents: 1728
diff changeset
1875 n.users_group = users_group
da8ee2ef7f6d implements #236 forking copy permission option
Marcin Kuzminski <marcin@python-works.com>
parents: 1728
diff changeset
1876 n.repository = repository
da8ee2ef7f6d implements #236 forking copy permission option
Marcin Kuzminski <marcin@python-works.com>
parents: 1728
diff changeset
1877 n.permission = permission
2520
a1e156503afe Fixed calls to Session in db model
Marcin Kuzminski <marcin@python-works.com>
parents: 2510
diff changeset
1878 Session().add(n)
1729
da8ee2ef7f6d implements #236 forking copy permission option
Marcin Kuzminski <marcin@python-works.com>
parents: 1728
diff changeset
1879 return n
da8ee2ef7f6d implements #236 forking copy permission option
Marcin Kuzminski <marcin@python-works.com>
parents: 1728
diff changeset
1880
2156
a27e4d44237e Use __unicode__ instead of __repr__ in models.
Marcin Kuzminski <marcin@python-works.com>
parents: 2152
diff changeset
1881 def __unicode__(self):
3788
d9b89874edf9 UserGroup on UserGroup permissions implementation.
Marcin Kuzminski <marcin@python-works.com>
parents: 3786
diff changeset
1882 return u'<UserGroupRepoToPerm:%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
1883
1800
6c86c987cf93 pep8ify
Marcin Kuzminski <marcin@python-works.com>
parents: 1758
diff changeset
1884
3714
7e3d89d9d3a2 - Manage Userโ€™s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents: 3687
diff changeset
1885 class UserGroupUserGroupToPerm(Base, BaseModel):
7e3d89d9d3a2 - Manage Userโ€™s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents: 3687
diff changeset
1886 __tablename__ = 'user_group_user_group_to_perm'
7e3d89d9d3a2 - Manage Userโ€™s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents: 3687
diff changeset
1887 __table_args__ = (
3788
d9b89874edf9 UserGroup on UserGroup permissions implementation.
Marcin Kuzminski <marcin@python-works.com>
parents: 3786
diff changeset
1888 UniqueConstraint('target_user_group_id', 'user_group_id', 'permission_id'),
d9b89874edf9 UserGroup on UserGroup permissions implementation.
Marcin Kuzminski <marcin@python-works.com>
parents: 3786
diff changeset
1889 CheckConstraint('target_user_group_id != user_group_id'),
3714
7e3d89d9d3a2 - Manage Userโ€™s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents: 3687
diff changeset
1890 {'extend_existing': True, 'mysql_engine': 'InnoDB',
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
1891 'mysql_charset': 'utf8', 'sqlite_autoincrement': True}
3714
7e3d89d9d3a2 - Manage Userโ€™s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents: 3687
diff changeset
1892 )
3788
d9b89874edf9 UserGroup on UserGroup permissions implementation.
Marcin Kuzminski <marcin@python-works.com>
parents: 3786
diff changeset
1893 user_group_user_group_to_perm_id = Column("user_group_user_group_to_perm_id", Integer(), nullable=False, unique=True, default=None, primary_key=True)
d9b89874edf9 UserGroup on UserGroup permissions implementation.
Marcin Kuzminski <marcin@python-works.com>
parents: 3786
diff changeset
1894 target_user_group_id = Column("target_user_group_id", Integer(), ForeignKey('users_groups.users_group_id'), nullable=False, unique=None, default=None)
3714
7e3d89d9d3a2 - Manage Userโ€™s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents: 3687
diff changeset
1895 permission_id = Column("permission_id", Integer(), ForeignKey('permissions.permission_id'), nullable=False, unique=None, default=None)
7e3d89d9d3a2 - Manage Userโ€™s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents: 3687
diff changeset
1896 user_group_id = Column("user_group_id", Integer(), ForeignKey('users_groups.users_group_id'), nullable=False, unique=None, default=None)
7e3d89d9d3a2 - Manage Userโ€™s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents: 3687
diff changeset
1897
3788
d9b89874edf9 UserGroup on UserGroup permissions implementation.
Marcin Kuzminski <marcin@python-works.com>
parents: 3786
diff changeset
1898 target_user_group = relationship('UserGroup', primaryjoin='UserGroupUserGroupToPerm.target_user_group_id==UserGroup.users_group_id')
d9b89874edf9 UserGroup on UserGroup permissions implementation.
Marcin Kuzminski <marcin@python-works.com>
parents: 3786
diff changeset
1899 user_group = relationship('UserGroup', primaryjoin='UserGroupUserGroupToPerm.user_group_id==UserGroup.users_group_id')
3714
7e3d89d9d3a2 - Manage Userโ€™s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents: 3687
diff changeset
1900 permission = relationship('Permission')
7e3d89d9d3a2 - Manage Userโ€™s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents: 3687
diff changeset
1901
7e3d89d9d3a2 - Manage Userโ€™s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents: 3687
diff changeset
1902 @classmethod
7e3d89d9d3a2 - Manage Userโ€™s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents: 3687
diff changeset
1903 def create(cls, target_user_group, user_group, permission):
7e3d89d9d3a2 - Manage Userโ€™s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents: 3687
diff changeset
1904 n = cls()
7e3d89d9d3a2 - Manage Userโ€™s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents: 3687
diff changeset
1905 n.target_user_group = target_user_group
7e3d89d9d3a2 - Manage Userโ€™s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents: 3687
diff changeset
1906 n.user_group = user_group
7e3d89d9d3a2 - Manage Userโ€™s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents: 3687
diff changeset
1907 n.permission = permission
7e3d89d9d3a2 - Manage Userโ€™s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents: 3687
diff changeset
1908 Session().add(n)
7e3d89d9d3a2 - Manage Userโ€™s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents: 3687
diff changeset
1909 return n
7e3d89d9d3a2 - Manage Userโ€™s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents: 3687
diff changeset
1910
7e3d89d9d3a2 - Manage Userโ€™s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents: 3687
diff changeset
1911 def __unicode__(self):
3788
d9b89874edf9 UserGroup on UserGroup permissions implementation.
Marcin Kuzminski <marcin@python-works.com>
parents: 3786
diff changeset
1912 return u'<UserGroupUserGroup:%s => %s >' % (self.target_user_group, self.user_group)
3714
7e3d89d9d3a2 - Manage Userโ€™s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents: 3687
diff changeset
1913
7e3d89d9d3a2 - Manage Userโ€™s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents: 3687
diff changeset
1914
3417
fa6ba6727475 further cleanup of UsersGroup
Mads Kiilerich <madski@unity3d.com>
parents: 3416
diff changeset
1915 class UserGroupToPerm(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
1916 __tablename__ = 'users_group_to_perm'
1988
5eae67552695 db unique constraints fixes
Marcin Kuzminski <marcin@python-works.com>
parents: 1982
diff changeset
1917 __table_args__ = (
5eae67552695 db unique constraints fixes
Marcin Kuzminski <marcin@python-works.com>
parents: 1982
diff changeset
1918 UniqueConstraint('users_group_id', 'permission_id',),
2356
2da7b5984ae5 typo fix + code garden
Marcin Kuzminski <marcin@python-works.com>
parents: 2352
diff changeset
1919 {'extend_existing': True, 'mysql_engine': 'InnoDB',
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
1920 'mysql_charset': 'utf8', 'sqlite_autoincrement': True}
1988
5eae67552695 db unique constraints fixes
Marcin Kuzminski <marcin@python-works.com>
parents: 1982
diff changeset
1921 )
1594
9dae92a65e40 fixes #288
Marcin Kuzminski <marcin@python-works.com>
parents: 1593
diff changeset
1922 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
1923 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
1924 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
1925
3417
fa6ba6727475 further cleanup of UsersGroup
Mads Kiilerich <madski@unity3d.com>
parents: 3416
diff changeset
1926 users_group = relationship('UserGroup')
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
1927 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
1928
aa7e45ad0cea Fixed permissions for users groups, group can have create repo permission now.
Marcin Kuzminski <marcin@python-works.com>
parents: 1266
diff changeset
1929
1633
2c0d35e336b5 refactoring of models names for repoGroup permissions
Marcin Kuzminski <marcin@python-works.com>
parents: 1607
diff changeset
1930 class UserRepoGroupToPerm(Base, BaseModel):
1958
7e4b3d3a9c5c renamed repo groups table
Marcin Kuzminski <marcin@python-works.com>
parents: 1950
diff changeset
1931 __tablename__ = 'user_repo_group_to_perm'
7e4b3d3a9c5c renamed repo groups table
Marcin Kuzminski <marcin@python-works.com>
parents: 1950
diff changeset
1932 __table_args__ = (
2000
72c525a7e7ad added migrations from 1.2.X to 1.3
Marcin Kuzminski <marcin@python-works.com>
parents: 1990
diff changeset
1933 UniqueConstraint('user_id', 'group_id', 'permission_id'),
2356
2da7b5984ae5 typo fix + code garden
Marcin Kuzminski <marcin@python-works.com>
parents: 2352
diff changeset
1934 {'extend_existing': True, 'mysql_engine': 'InnoDB',
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
1935 'mysql_charset': 'utf8', 'sqlite_autoincrement': True}
1958
7e4b3d3a9c5c renamed repo groups table
Marcin Kuzminski <marcin@python-works.com>
parents: 1950
diff changeset
1936 )
879
b19341623d48 added group to perm mapping table
Marcin Kuzminski <marcin@python-works.com>
parents: 878
diff changeset
1937
1594
9dae92a65e40 fixes #288
Marcin Kuzminski <marcin@python-works.com>
parents: 1593
diff changeset
1938 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
1939 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
1940 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
1941 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
1942
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
1943 user = relationship('User')
2000
72c525a7e7ad added migrations from 1.2.X to 1.3
Marcin Kuzminski <marcin@python-works.com>
parents: 1990
diff changeset
1944 group = relationship('RepoGroup')
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
1945 permission = relationship('Permission')
1633
2c0d35e336b5 refactoring of models names for repoGroup permissions
Marcin Kuzminski <marcin@python-works.com>
parents: 1607
diff changeset
1946
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
1947 @classmethod
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
1948 def create(cls, user, repository_group, permission):
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
1949 n = cls()
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
1950 n.user = user
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
1951 n.group = repository_group
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
1952 n.permission = permission
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
1953 Session().add(n)
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
1954 return n
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
1955
1800
6c86c987cf93 pep8ify
Marcin Kuzminski <marcin@python-works.com>
parents: 1758
diff changeset
1956
3417
fa6ba6727475 further cleanup of UsersGroup
Mads Kiilerich <madski@unity3d.com>
parents: 3416
diff changeset
1957 class UserGroupRepoGroupToPerm(Base, BaseModel):
1633
2c0d35e336b5 refactoring of models names for repoGroup permissions
Marcin Kuzminski <marcin@python-works.com>
parents: 1607
diff changeset
1958 __tablename__ = 'users_group_repo_group_to_perm'
1958
7e4b3d3a9c5c renamed repo groups table
Marcin Kuzminski <marcin@python-works.com>
parents: 1950
diff changeset
1959 __table_args__ = (
1988
5eae67552695 db unique constraints fixes
Marcin Kuzminski <marcin@python-works.com>
parents: 1982
diff changeset
1960 UniqueConstraint('users_group_id', 'group_id'),
2356
2da7b5984ae5 typo fix + code garden
Marcin Kuzminski <marcin@python-works.com>
parents: 2352
diff changeset
1961 {'extend_existing': True, 'mysql_engine': 'InnoDB',
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
1962 'mysql_charset': 'utf8', 'sqlite_autoincrement': True}
1958
7e4b3d3a9c5c renamed repo groups table
Marcin Kuzminski <marcin@python-works.com>
parents: 1950
diff changeset
1963 )
1633
2c0d35e336b5 refactoring of models names for repoGroup permissions
Marcin Kuzminski <marcin@python-works.com>
parents: 1607
diff changeset
1964
2c0d35e336b5 refactoring of models names for repoGroup permissions
Marcin Kuzminski <marcin@python-works.com>
parents: 1607
diff changeset
1965 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
1966 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
1967 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
1968 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
1969
3417
fa6ba6727475 further cleanup of UsersGroup
Mads Kiilerich <madski@unity3d.com>
parents: 3416
diff changeset
1970 users_group = relationship('UserGroup')
1633
2c0d35e336b5 refactoring of models names for repoGroup permissions
Marcin Kuzminski <marcin@python-works.com>
parents: 1607
diff changeset
1971 permission = relationship('Permission')
2c0d35e336b5 refactoring of models names for repoGroup permissions
Marcin Kuzminski <marcin@python-works.com>
parents: 1607
diff changeset
1972 group = relationship('RepoGroup')
879
b19341623d48 added group to perm mapping table
Marcin Kuzminski <marcin@python-works.com>
parents: 878
diff changeset
1973
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
1974 @classmethod
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
1975 def create(cls, user_group, repository_group, permission):
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
1976 n = cls()
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
1977 n.users_group = user_group
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
1978 n.group = repository_group
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
1979 n.permission = permission
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
1980 Session().add(n)
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
1981 return n
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
1982
1800
6c86c987cf93 pep8ify
Marcin Kuzminski <marcin@python-works.com>
parents: 1758
diff changeset
1983
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
1984 class Statistics(Base, BaseModel):
493
2256c78afe53 implemented basic autoupdating statistics fetched from database
Marcin Kuzminski <marcin@python-works.com>
parents: 473
diff changeset
1985 __tablename__ = 'statistics'
2149
50aa7cb78cfe Mysql fixes
Marcin Kuzminski <marcin@python-works.com>
parents: 2147
diff changeset
1986 __table_args__ = (
2150
a8c9c0094ddf White space cleanup
Marcin Kuzminski <marcin@python-works.com>
parents: 2149
diff changeset
1987 UniqueConstraint('repository_id'),
2356
2da7b5984ae5 typo fix + code garden
Marcin Kuzminski <marcin@python-works.com>
parents: 2352
diff changeset
1988 {'extend_existing': True, 'mysql_engine': 'InnoDB',
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
1989 'mysql_charset': 'utf8', 'sqlite_autoincrement': True}
2149
50aa7cb78cfe Mysql fixes
Marcin Kuzminski <marcin@python-works.com>
parents: 2147
diff changeset
1990 )
1594
9dae92a65e40 fixes #288
Marcin Kuzminski <marcin@python-works.com>
parents: 1593
diff changeset
1991 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
1992 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
1993 stat_on_revision = Column("stat_on_revision", Integer(), nullable=False)
9dae92a65e40 fixes #288
Marcin Kuzminski <marcin@python-works.com>
parents: 1593
diff changeset
1994 commit_activity = Column("commit_activity", LargeBinary(1000000), nullable=False)#JSON data
9dae92a65e40 fixes #288
Marcin Kuzminski <marcin@python-works.com>
parents: 1593
diff changeset
1995 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
1996 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
1997
1594
9dae92a65e40 fixes #288
Marcin Kuzminski <marcin@python-works.com>
parents: 1593
diff changeset
1998 repository = relationship('Repository', single_parent=True)
399
f5c1eec9f376 rename repo2perm into repo_to_perm
Marcin Kuzminski <marcin@python-works.com>
parents: 392
diff changeset
1999
1800
6c86c987cf93 pep8ify
Marcin Kuzminski <marcin@python-works.com>
parents: 1758
diff changeset
2000
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
2001 class UserFollowing(Base, BaseModel):
734
49eb69d78988 implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents: 713
diff changeset
2002 __tablename__ = 'user_followings'
1958
7e4b3d3a9c5c renamed repo groups table
Marcin Kuzminski <marcin@python-works.com>
parents: 1950
diff changeset
2003 __table_args__ = (
7e4b3d3a9c5c renamed repo groups table
Marcin Kuzminski <marcin@python-works.com>
parents: 1950
diff changeset
2004 UniqueConstraint('user_id', 'follows_repository_id'),
7e4b3d3a9c5c renamed repo groups table
Marcin Kuzminski <marcin@python-works.com>
parents: 1950
diff changeset
2005 UniqueConstraint('user_id', 'follows_user_id'),
2356
2da7b5984ae5 typo fix + code garden
Marcin Kuzminski <marcin@python-works.com>
parents: 2352
diff changeset
2006 {'extend_existing': True, 'mysql_engine': 'InnoDB',
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
2007 'mysql_charset': 'utf8', 'sqlite_autoincrement': True}
1958
7e4b3d3a9c5c renamed repo groups table
Marcin Kuzminski <marcin@python-works.com>
parents: 1950
diff changeset
2008 )
734
49eb69d78988 implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents: 713
diff changeset
2009
1594
9dae92a65e40 fixes #288
Marcin Kuzminski <marcin@python-works.com>
parents: 1593
diff changeset
2010 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
2011 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
2012 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
2013 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
2014 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
2015
1594
9dae92a65e40 fixes #288
Marcin Kuzminski <marcin@python-works.com>
parents: 1593
diff changeset
2016 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
2017
1594
9dae92a65e40 fixes #288
Marcin Kuzminski <marcin@python-works.com>
parents: 1593
diff changeset
2018 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
2019 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
2020
1279
cb216757a62d #179 Added followers page
Marcin Kuzminski <marcin@python-works.com>
parents: 1271
diff changeset
2021 @classmethod
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
2022 def get_repo_followers(cls, repo_id):
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
2023 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
2024
1800
6c86c987cf93 pep8ify
Marcin Kuzminski <marcin@python-works.com>
parents: 1758
diff changeset
2025
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
2026 class CacheInvalidation(Base, BaseModel):
670
e7c670cc03cb Adde table for cache invalidation
Marcin Kuzminski <marcin@python-works.com>
parents: 667
diff changeset
2027 __tablename__ = 'cache_invalidation'
2149
50aa7cb78cfe Mysql fixes
Marcin Kuzminski <marcin@python-works.com>
parents: 2147
diff changeset
2028 __table_args__ = (
50aa7cb78cfe Mysql fixes
Marcin Kuzminski <marcin@python-works.com>
parents: 2147
diff changeset
2029 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
2030 Index('key_idx', 'cache_key'),
2356
2da7b5984ae5 typo fix + code garden
Marcin Kuzminski <marcin@python-works.com>
parents: 2352
diff changeset
2031 {'extend_existing': True, 'mysql_engine': 'InnoDB',
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
2032 'mysql_charset': 'utf8', 'sqlite_autoincrement': True},
2149
50aa7cb78cfe Mysql fixes
Marcin Kuzminski <marcin@python-works.com>
parents: 2147
diff changeset
2033 )
3606
c8ecfe42b285 invalidation: some documentation and refactoring
Mads Kiilerich <madski@unity3d.com>
parents: 3599
diff changeset
2034 # cache_id, not used
1594
9dae92a65e40 fixes #288
Marcin Kuzminski <marcin@python-works.com>
parents: 1593
diff changeset
2035 cache_id = Column("cache_id", Integer(), nullable=False, unique=True, default=None, primary_key=True)
3606
c8ecfe42b285 invalidation: some documentation and refactoring
Mads Kiilerich <madski@unity3d.com>
parents: 3599
diff changeset
2036 # cache_key as created by _get_cache_key
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
2037 cache_key = Column("cache_key", String(255, convert_unicode=False), nullable=True, unique=None, default=None)
3682
cf65b2c1b69d invalidation: some documentation and refactoring, second round
Mads Kiilerich <madski@unity3d.com>
parents: 3680
diff changeset
2038 # cache_args is a repo_name
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
2039 cache_args = Column("cache_args", String(255, convert_unicode=False), nullable=True, unique=None, default=None)
3682
cf65b2c1b69d invalidation: some documentation and refactoring, second round
Mads Kiilerich <madski@unity3d.com>
parents: 3680
diff changeset
2040 # instance sets cache_active True when it is caching,
cf65b2c1b69d invalidation: some documentation and refactoring, second round
Mads Kiilerich <madski@unity3d.com>
parents: 3680
diff changeset
2041 # other instances set cache_active to False to indicate that this cache is invalid
1594
9dae92a65e40 fixes #288
Marcin Kuzminski <marcin@python-works.com>
parents: 1593
diff changeset
2042 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
2043
3682
cf65b2c1b69d invalidation: some documentation and refactoring, second round
Mads Kiilerich <madski@unity3d.com>
parents: 3680
diff changeset
2044 def __init__(self, cache_key, repo_name=''):
692
cb0d9ce6ac5c #50 on point cache invalidation changes.
Marcin Kuzminski <marcin@python-works.com>
parents: 670
diff changeset
2045 self.cache_key = cache_key
3682
cf65b2c1b69d invalidation: some documentation and refactoring, second round
Mads Kiilerich <madski@unity3d.com>
parents: 3680
diff changeset
2046 self.cache_args = repo_name
692
cb0d9ce6ac5c #50 on point cache invalidation changes.
Marcin Kuzminski <marcin@python-works.com>
parents: 670
diff changeset
2047 self.cache_active = False
cb0d9ce6ac5c #50 on point cache invalidation changes.
Marcin Kuzminski <marcin@python-works.com>
parents: 670
diff changeset
2048
2156
a27e4d44237e Use __unicode__ instead of __repr__ in models.
Marcin Kuzminski <marcin@python-works.com>
parents: 2152
diff changeset
2049 def __unicode__(self):
3686
f18801f827da repr of cache inv object show also now cache_active + some better logging
Marcin Kuzminski <marcin@python-works.com>
parents: 3685
diff changeset
2050 return u"<%s('%s:%s[%s]')>" % (self.__class__.__name__,
f18801f827da repr of cache inv object show also now cache_active + some better logging
Marcin Kuzminski <marcin@python-works.com>
parents: 3685
diff changeset
2051 self.cache_id, self.cache_key, self.cache_active)
2352
90e06f53af8c Implemented cache-map on main page to save executing select
Marcin Kuzminski <marcin@python-works.com>
parents: 2339
diff changeset
2052
3687
8849c07d8c62 fixed prefix extractions from cache keys + cleanup
Marcin Kuzminski <marcin@python-works.com>
parents: 3686
diff changeset
2053 def _cache_key_partition(self):
8849c07d8c62 fixed prefix extractions from cache keys + cleanup
Marcin Kuzminski <marcin@python-works.com>
parents: 3686
diff changeset
2054 prefix, repo_name, suffix = self.cache_key.partition(self.cache_args)
8849c07d8c62 fixed prefix extractions from cache keys + cleanup
Marcin Kuzminski <marcin@python-works.com>
parents: 3686
diff changeset
2055 return prefix, repo_name, suffix
8849c07d8c62 fixed prefix extractions from cache keys + cleanup
Marcin Kuzminski <marcin@python-works.com>
parents: 3686
diff changeset
2056
3606
c8ecfe42b285 invalidation: some documentation and refactoring
Mads Kiilerich <madski@unity3d.com>
parents: 3599
diff changeset
2057 def get_prefix(self):
c8ecfe42b285 invalidation: some documentation and refactoring
Mads Kiilerich <madski@unity3d.com>
parents: 3599
diff changeset
2058 """
3687
8849c07d8c62 fixed prefix extractions from cache keys + cleanup
Marcin Kuzminski <marcin@python-works.com>
parents: 3686
diff changeset
2059 get prefix that might have been used in _get_cache_key to
8849c07d8c62 fixed prefix extractions from cache keys + cleanup
Marcin Kuzminski <marcin@python-works.com>
parents: 3686
diff changeset
2060 generate self.cache_key. Only used for informational purposes
8849c07d8c62 fixed prefix extractions from cache keys + cleanup
Marcin Kuzminski <marcin@python-works.com>
parents: 3686
diff changeset
2061 in repo_edit.html.
3606
c8ecfe42b285 invalidation: some documentation and refactoring
Mads Kiilerich <madski@unity3d.com>
parents: 3599
diff changeset
2062 """
3687
8849c07d8c62 fixed prefix extractions from cache keys + cleanup
Marcin Kuzminski <marcin@python-works.com>
parents: 3686
diff changeset
2063 # prefix, repo_name, suffix
8849c07d8c62 fixed prefix extractions from cache keys + cleanup
Marcin Kuzminski <marcin@python-works.com>
parents: 3686
diff changeset
2064 return self._cache_key_partition()[0]
8849c07d8c62 fixed prefix extractions from cache keys + cleanup
Marcin Kuzminski <marcin@python-works.com>
parents: 3686
diff changeset
2065
8849c07d8c62 fixed prefix extractions from cache keys + cleanup
Marcin Kuzminski <marcin@python-works.com>
parents: 3686
diff changeset
2066 def get_suffix(self):
8849c07d8c62 fixed prefix extractions from cache keys + cleanup
Marcin Kuzminski <marcin@python-works.com>
parents: 3686
diff changeset
2067 """
8849c07d8c62 fixed prefix extractions from cache keys + cleanup
Marcin Kuzminski <marcin@python-works.com>
parents: 3686
diff changeset
2068 get suffix that might have been used in _get_cache_key to
8849c07d8c62 fixed prefix extractions from cache keys + cleanup
Marcin Kuzminski <marcin@python-works.com>
parents: 3686
diff changeset
2069 generate self.cache_key. Only used for informational purposes
8849c07d8c62 fixed prefix extractions from cache keys + cleanup
Marcin Kuzminski <marcin@python-works.com>
parents: 3686
diff changeset
2070 in repo_edit.html.
8849c07d8c62 fixed prefix extractions from cache keys + cleanup
Marcin Kuzminski <marcin@python-works.com>
parents: 3686
diff changeset
2071 """
8849c07d8c62 fixed prefix extractions from cache keys + cleanup
Marcin Kuzminski <marcin@python-works.com>
parents: 3686
diff changeset
2072 # prefix, repo_name, suffix
8849c07d8c62 fixed prefix extractions from cache keys + cleanup
Marcin Kuzminski <marcin@python-works.com>
parents: 3686
diff changeset
2073 return self._cache_key_partition()[2]
2809
070d2eacd48b Show cache keys in admin settings of repository
Marcin Kuzminski <marcin@python-works.com>
parents: 2808
diff changeset
2074
2147
d25bd432bc3e - #347 when running multiple RhodeCode instances, properly invalidates cache
Marcin Kuzminski <marcin@python-works.com>
parents: 2109
diff changeset
2075 @classmethod
3757
f08881dcc9eb invalidate: clear CacheInvalidation when upgrading
Mads Kiilerich <madski@unity3d.com>
parents: 3734
diff changeset
2076 def clear_cache(cls):
f08881dcc9eb invalidate: clear CacheInvalidation when upgrading
Mads Kiilerich <madski@unity3d.com>
parents: 3734
diff changeset
2077 """
f08881dcc9eb invalidate: clear CacheInvalidation when upgrading
Mads Kiilerich <madski@unity3d.com>
parents: 3734
diff changeset
2078 Delete all cache keys from database.
f08881dcc9eb invalidate: clear CacheInvalidation when upgrading
Mads Kiilerich <madski@unity3d.com>
parents: 3734
diff changeset
2079 Should only be run when all instances are down and all entries thus stale.
f08881dcc9eb invalidate: clear CacheInvalidation when upgrading
Mads Kiilerich <madski@unity3d.com>
parents: 3734
diff changeset
2080 """
f08881dcc9eb invalidate: clear CacheInvalidation when upgrading
Mads Kiilerich <madski@unity3d.com>
parents: 3734
diff changeset
2081 cls.query().delete()
f08881dcc9eb invalidate: clear CacheInvalidation when upgrading
Mads Kiilerich <madski@unity3d.com>
parents: 3734
diff changeset
2082 Session().commit()
f08881dcc9eb invalidate: clear CacheInvalidation when upgrading
Mads Kiilerich <madski@unity3d.com>
parents: 3734
diff changeset
2083
f08881dcc9eb invalidate: clear CacheInvalidation when upgrading
Mads Kiilerich <madski@unity3d.com>
parents: 3734
diff changeset
2084 @classmethod
3606
c8ecfe42b285 invalidation: some documentation and refactoring
Mads Kiilerich <madski@unity3d.com>
parents: 3599
diff changeset
2085 def _get_cache_key(cls, key):
2013
8530c3cd9d04 fixed issue with hybrid property for ldap_active
Marcin Kuzminski <marcin@python-works.com>
parents: 2007
diff changeset
2086 """
3606
c8ecfe42b285 invalidation: some documentation and refactoring
Mads Kiilerich <madski@unity3d.com>
parents: 3599
diff changeset
2087 Wrapper for generating a unique cache key for this instance and "key".
3682
cf65b2c1b69d invalidation: some documentation and refactoring, second round
Mads Kiilerich <madski@unity3d.com>
parents: 3680
diff changeset
2088 key must / will start with a repo_name which will be stored in .cache_args .
2013
8530c3cd9d04 fixed issue with hybrid property for ldap_active
Marcin Kuzminski <marcin@python-works.com>
parents: 2007
diff changeset
2089 """
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
2090 import rhodecode
3606
c8ecfe42b285 invalidation: some documentation and refactoring
Mads Kiilerich <madski@unity3d.com>
parents: 3599
diff changeset
2091 prefix = rhodecode.CONFIG.get('instance_id', '')
c8ecfe42b285 invalidation: some documentation and refactoring
Mads Kiilerich <madski@unity3d.com>
parents: 3599
diff changeset
2092 return "%s%s" % (prefix, key)
2013
8530c3cd9d04 fixed issue with hybrid property for ldap_active
Marcin Kuzminski <marcin@python-works.com>
parents: 2007
diff changeset
2093
8530c3cd9d04 fixed issue with hybrid property for ldap_active
Marcin Kuzminski <marcin@python-works.com>
parents: 2007
diff changeset
2094 @classmethod
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
2095 def set_invalidate(cls, repo_name, delete=False):
1607
e886f91fcb71 Cached readme generation
Marcin Kuzminski <marcin@python-works.com>
parents: 1594
diff changeset
2096 """
3685
02e1e270bf93 invalidation: set_invalidate is (obviously) only used to invalidate the whole repo
Mads Kiilerich <madski@unity3d.com>
parents: 3684
diff changeset
2097 Mark all caches of a repo as invalid in the database.
1607
e886f91fcb71 Cached readme generation
Marcin Kuzminski <marcin@python-works.com>
parents: 1594
diff changeset
2098 """
3685
02e1e270bf93 invalidation: set_invalidate is (obviously) only used to invalidate the whole repo
Mads Kiilerich <madski@unity3d.com>
parents: 3684
diff changeset
2099 inv_objs = Session().query(cls).filter(cls.cache_args == repo_name).all()
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
2100 log.debug('for repo %s got %s invalidation objects'
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
2101 % (safe_str(repo_name), inv_objs))
2147
d25bd432bc3e - #347 when running multiple RhodeCode instances, properly invalidates cache
Marcin Kuzminski <marcin@python-works.com>
parents: 2109
diff changeset
2102 try:
d25bd432bc3e - #347 when running multiple RhodeCode instances, properly invalidates cache
Marcin Kuzminski <marcin@python-works.com>
parents: 2109
diff changeset
2103 for inv_obj in inv_objs:
3685
02e1e270bf93 invalidation: set_invalidate is (obviously) only used to invalidate the whole repo
Mads Kiilerich <madski@unity3d.com>
parents: 3684
diff changeset
2104 log.debug('marking %s key for invalidation based on repo_name=%s'
02e1e270bf93 invalidation: set_invalidate is (obviously) only used to invalidate the whole repo
Mads Kiilerich <madski@unity3d.com>
parents: 3684
diff changeset
2105 % (inv_obj, safe_str(repo_name)))
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
2106 if delete:
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
2107 Session().delete(inv_obj)
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
2108 else:
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
2109 inv_obj.cache_active = False
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
2110 Session().add(inv_obj)
2520
a1e156503afe Fixed calls to Session in db model
Marcin Kuzminski <marcin@python-works.com>
parents: 2510
diff changeset
2111 Session().commit()
1607
e886f91fcb71 Cached readme generation
Marcin Kuzminski <marcin@python-works.com>
parents: 1594
diff changeset
2112 except Exception:
e886f91fcb71 Cached readme generation
Marcin Kuzminski <marcin@python-works.com>
parents: 1594
diff changeset
2113 log.error(traceback.format_exc())
2520
a1e156503afe Fixed calls to Session in db model
Marcin Kuzminski <marcin@python-works.com>
parents: 2510
diff changeset
2114 Session().rollback()
1607
e886f91fcb71 Cached readme generation
Marcin Kuzminski <marcin@python-works.com>
parents: 1594
diff changeset
2115
e886f91fcb71 Cached readme generation
Marcin Kuzminski <marcin@python-works.com>
parents: 1594
diff changeset
2116 @classmethod
3773
8e2cd46f765b invalidate: encapsulate how key is generated from repo_name and kind
Mads Kiilerich <madski@unity3d.com>
parents: 3772
diff changeset
2117 def test_and_set_valid(cls, repo_name, kind, valid_cache_keys=None):
1607
e886f91fcb71 Cached readme generation
Marcin Kuzminski <marcin@python-works.com>
parents: 1594
diff changeset
2118 """
3772
910ad1ffee99 invalidation: merge .invalidate and .set_valid as .test_and_set_valid
Mads Kiilerich <madski@unity3d.com>
parents: 3759
diff changeset
2119 Mark this cache key as active and currently cached.
910ad1ffee99 invalidation: merge .invalidate and .set_valid as .test_and_set_valid
Mads Kiilerich <madski@unity3d.com>
parents: 3759
diff changeset
2120 Return True if the existing cache registration still was valid.
910ad1ffee99 invalidation: merge .invalidate and .set_valid as .test_and_set_valid
Mads Kiilerich <madski@unity3d.com>
parents: 3759
diff changeset
2121 Return False to indicate that it had been invalidated and caches should be refreshed.
1607
e886f91fcb71 Cached readme generation
Marcin Kuzminski <marcin@python-works.com>
parents: 1594
diff changeset
2122 """
3773
8e2cd46f765b invalidate: encapsulate how key is generated from repo_name and kind
Mads Kiilerich <madski@unity3d.com>
parents: 3772
diff changeset
2123
8e2cd46f765b invalidate: encapsulate how key is generated from repo_name and kind
Mads Kiilerich <madski@unity3d.com>
parents: 3772
diff changeset
2124 key = (repo_name + '_' + kind) if kind else repo_name
3772
910ad1ffee99 invalidation: merge .invalidate and .set_valid as .test_and_set_valid
Mads Kiilerich <madski@unity3d.com>
parents: 3759
diff changeset
2125 cache_key = cls._get_cache_key(key)
910ad1ffee99 invalidation: merge .invalidate and .set_valid as .test_and_set_valid
Mads Kiilerich <madski@unity3d.com>
parents: 3759
diff changeset
2126
910ad1ffee99 invalidation: merge .invalidate and .set_valid as .test_and_set_valid
Mads Kiilerich <madski@unity3d.com>
parents: 3759
diff changeset
2127 if valid_cache_keys and cache_key in valid_cache_keys:
910ad1ffee99 invalidation: merge .invalidate and .set_valid as .test_and_set_valid
Mads Kiilerich <madski@unity3d.com>
parents: 3759
diff changeset
2128 return True
910ad1ffee99 invalidation: merge .invalidate and .set_valid as .test_and_set_valid
Mads Kiilerich <madski@unity3d.com>
parents: 3759
diff changeset
2129
910ad1ffee99 invalidation: merge .invalidate and .set_valid as .test_and_set_valid
Mads Kiilerich <madski@unity3d.com>
parents: 3759
diff changeset
2130 try:
910ad1ffee99 invalidation: merge .invalidate and .set_valid as .test_and_set_valid
Mads Kiilerich <madski@unity3d.com>
parents: 3759
diff changeset
2131 inv_obj = cls.query().filter(cls.cache_key == cache_key).scalar()
910ad1ffee99 invalidation: merge .invalidate and .set_valid as .test_and_set_valid
Mads Kiilerich <madski@unity3d.com>
parents: 3759
diff changeset
2132 if not inv_obj:
910ad1ffee99 invalidation: merge .invalidate and .set_valid as .test_and_set_valid
Mads Kiilerich <madski@unity3d.com>
parents: 3759
diff changeset
2133 inv_obj = CacheInvalidation(cache_key, repo_name)
910ad1ffee99 invalidation: merge .invalidate and .set_valid as .test_and_set_valid
Mads Kiilerich <madski@unity3d.com>
parents: 3759
diff changeset
2134 was_valid = inv_obj.cache_active
910ad1ffee99 invalidation: merge .invalidate and .set_valid as .test_and_set_valid
Mads Kiilerich <madski@unity3d.com>
parents: 3759
diff changeset
2135 inv_obj.cache_active = True
910ad1ffee99 invalidation: merge .invalidate and .set_valid as .test_and_set_valid
Mads Kiilerich <madski@unity3d.com>
parents: 3759
diff changeset
2136 Session().add(inv_obj)
910ad1ffee99 invalidation: merge .invalidate and .set_valid as .test_and_set_valid
Mads Kiilerich <madski@unity3d.com>
parents: 3759
diff changeset
2137 Session().commit()
910ad1ffee99 invalidation: merge .invalidate and .set_valid as .test_and_set_valid
Mads Kiilerich <madski@unity3d.com>
parents: 3759
diff changeset
2138 return was_valid
910ad1ffee99 invalidation: merge .invalidate and .set_valid as .test_and_set_valid
Mads Kiilerich <madski@unity3d.com>
parents: 3759
diff changeset
2139 except Exception:
910ad1ffee99 invalidation: merge .invalidate and .set_valid as .test_and_set_valid
Mads Kiilerich <madski@unity3d.com>
parents: 3759
diff changeset
2140 log.error(traceback.format_exc())
910ad1ffee99 invalidation: merge .invalidate and .set_valid as .test_and_set_valid
Mads Kiilerich <madski@unity3d.com>
parents: 3759
diff changeset
2141 Session().rollback()
910ad1ffee99 invalidation: merge .invalidate and .set_valid as .test_and_set_valid
Mads Kiilerich <madski@unity3d.com>
parents: 3759
diff changeset
2142 return False
1607
e886f91fcb71 Cached readme generation
Marcin Kuzminski <marcin@python-works.com>
parents: 1594
diff changeset
2143
2352
90e06f53af8c Implemented cache-map on main page to save executing select
Marcin Kuzminski <marcin@python-works.com>
parents: 2339
diff changeset
2144 @classmethod
3772
910ad1ffee99 invalidation: merge .invalidate and .set_valid as .test_and_set_valid
Mads Kiilerich <madski@unity3d.com>
parents: 3759
diff changeset
2145 def get_valid_cache_keys(cls):
910ad1ffee99 invalidation: merge .invalidate and .set_valid as .test_and_set_valid
Mads Kiilerich <madski@unity3d.com>
parents: 3759
diff changeset
2146 """
910ad1ffee99 invalidation: merge .invalidate and .set_valid as .test_and_set_valid
Mads Kiilerich <madski@unity3d.com>
parents: 3759
diff changeset
2147 Return opaque object with information of which caches still are valid
910ad1ffee99 invalidation: merge .invalidate and .set_valid as .test_and_set_valid
Mads Kiilerich <madski@unity3d.com>
parents: 3759
diff changeset
2148 and can be used without checking for invalidation.
910ad1ffee99 invalidation: merge .invalidate and .set_valid as .test_and_set_valid
Mads Kiilerich <madski@unity3d.com>
parents: 3759
diff changeset
2149 """
910ad1ffee99 invalidation: merge .invalidate and .set_valid as .test_and_set_valid
Mads Kiilerich <madski@unity3d.com>
parents: 3759
diff changeset
2150 return set(inv_obj.cache_key for inv_obj in cls.query().filter(cls.cache_active).all())
2352
90e06f53af8c Implemented cache-map on main page to save executing select
Marcin Kuzminski <marcin@python-works.com>
parents: 2339
diff changeset
2151
1665
36f77a46f291 Added cache options to some db getters
Marcin Kuzminski <marcin@python-works.com>
parents: 1634
diff changeset
2152
1670
d2de0c2f02cd #77 code review
Marcin Kuzminski <marcin@python-works.com>
parents: 1669
diff changeset
2153 class ChangesetComment(Base, BaseModel):
d2de0c2f02cd #77 code review
Marcin Kuzminski <marcin@python-works.com>
parents: 1669
diff changeset
2154 __tablename__ = 'changeset_comments'
2149
50aa7cb78cfe Mysql fixes
Marcin Kuzminski <marcin@python-works.com>
parents: 2147
diff changeset
2155 __table_args__ = (
2463
b426ecc30319 Added some DB indexes to optimize queries
Marcin Kuzminski <marcin@python-works.com>
parents: 2462
diff changeset
2156 Index('cc_revision_idx', 'revision'),
2356
2da7b5984ae5 typo fix + code garden
Marcin Kuzminski <marcin@python-works.com>
parents: 2352
diff changeset
2157 {'extend_existing': True, 'mysql_engine': 'InnoDB',
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
2158 'mysql_charset': 'utf8', 'sqlite_autoincrement': True},
2149
50aa7cb78cfe Mysql fixes
Marcin Kuzminski <marcin@python-works.com>
parents: 2147
diff changeset
2159 )
1670
d2de0c2f02cd #77 code review
Marcin Kuzminski <marcin@python-works.com>
parents: 1669
diff changeset
2160 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
2161 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
2162 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
2163 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
2164 line_no = Column('line_no', Unicode(10), nullable=True)
2724
29db53a79ab2 added highlight lines field in ChangesetComments, will be used
Marcin Kuzminski <marcin@python-works.com>
parents: 2709
diff changeset
2165 hl_lines = Column('hl_lines', Unicode(512), nullable=True)
1677
7276b170ce8b #71 code-review
Marcin Kuzminski <marcin@python-works.com>
parents: 1675
diff changeset
2166 f_path = Column('f_path', Unicode(1000), nullable=True)
1670
d2de0c2f02cd #77 code review
Marcin Kuzminski <marcin@python-works.com>
parents: 1669
diff changeset
2167 user_id = Column('user_id', Integer(), ForeignKey('users.user_id'), nullable=False)
2791
85bb0866d444 UnicodeText make mysql more happy
Marcin Kuzminski <marcin@python-works.com>
parents: 2766
diff changeset
2168 text = Column('text', UnicodeText(25000), nullable=False)
2639
f3e039e4dc49 Added created_on column to changeset comments for proper ordering.
Marcin Kuzminski <marcin@python-works.com>
parents: 2608
diff changeset
2169 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
2170 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
2171
1703
f23828b00b21 notification fixes and improvements
Marcin Kuzminski <marcin@python-works.com>
parents: 1702
diff changeset
2172 author = relationship('User', lazy='joined')
1670
d2de0c2f02cd #77 code review
Marcin Kuzminski <marcin@python-works.com>
parents: 1669
diff changeset
2173 repo = relationship('Repository')
2677
4fbbc65e8cd5 Forbid changing changset status when it is associated with a closed pull request
Marcin Kuzminski <marcin@python-works.com>
parents: 2674
diff changeset
2174 status_change = relationship('ChangesetStatus', cascade="all, delete, delete-orphan")
2440
1bc579bcd67a - pull request generates overview based on it's params
Marcin Kuzminski <marcin@python-works.com>
parents: 2434
diff changeset
2175 pull_request = relationship('PullRequest', lazy='joined')
1670
d2de0c2f02cd #77 code review
Marcin Kuzminski <marcin@python-works.com>
parents: 1669
diff changeset
2176
1703
f23828b00b21 notification fixes and improvements
Marcin Kuzminski <marcin@python-works.com>
parents: 1702
diff changeset
2177 @classmethod
2443
fd0a822481ec - added commenting to pull requests
Marcin Kuzminski <marcin@python-works.com>
parents: 2440
diff changeset
2178 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
2179 """
2443
fd0a822481ec - added commenting to pull requests
Marcin Kuzminski <marcin@python-works.com>
parents: 2440
diff changeset
2180 Returns user associated with this ChangesetComment. ie those
1703
f23828b00b21 notification fixes and improvements
Marcin Kuzminski <marcin@python-works.com>
parents: 1702
diff changeset
2181 who actually commented
1818
cf51bbfb120e auto white-space removal
Marcin Kuzminski <marcin@python-works.com>
parents: 1800
diff changeset
2182
1703
f23828b00b21 notification fixes and improvements
Marcin Kuzminski <marcin@python-works.com>
parents: 1702
diff changeset
2183 :param cls:
f23828b00b21 notification fixes and improvements
Marcin Kuzminski <marcin@python-works.com>
parents: 1702
diff changeset
2184 :param revision:
f23828b00b21 notification fixes and improvements
Marcin Kuzminski <marcin@python-works.com>
parents: 1702
diff changeset
2185 """
2520
a1e156503afe Fixed calls to Session in db model
Marcin Kuzminski <marcin@python-works.com>
parents: 2510
diff changeset
2186 q = Session().query(User)\
2443
fd0a822481ec - added commenting to pull requests
Marcin Kuzminski <marcin@python-works.com>
parents: 2440
diff changeset
2187 .join(ChangesetComment.author)
fd0a822481ec - added commenting to pull requests
Marcin Kuzminski <marcin@python-works.com>
parents: 2440
diff changeset
2188 if revision:
fd0a822481ec - added commenting to pull requests
Marcin Kuzminski <marcin@python-works.com>
parents: 2440
diff changeset
2189 q = q.filter(cls.revision == revision)
fd0a822481ec - added commenting to pull requests
Marcin Kuzminski <marcin@python-works.com>
parents: 2440
diff changeset
2190 elif pull_request_id:
fd0a822481ec - added commenting to pull requests
Marcin Kuzminski <marcin@python-works.com>
parents: 2440
diff changeset
2191 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
2192 return q.all()
1886
50e32940e464 code garden
Marcin Kuzminski <marcin@python-works.com>
parents: 1884
diff changeset
2193
1703
f23828b00b21 notification fixes and improvements
Marcin Kuzminski <marcin@python-works.com>
parents: 1702
diff changeset
2194
2215
2c2bdaeca912 code-review initial
Marcin Kuzminski <marcin@python-works.com>
parents: 2161
diff changeset
2195 class ChangesetStatus(Base, BaseModel):
2c2bdaeca912 code-review initial
Marcin Kuzminski <marcin@python-works.com>
parents: 2161
diff changeset
2196 __tablename__ = 'changeset_statuses'
2c2bdaeca912 code-review initial
Marcin Kuzminski <marcin@python-works.com>
parents: 2161
diff changeset
2197 __table_args__ = (
2463
b426ecc30319 Added some DB indexes to optimize queries
Marcin Kuzminski <marcin@python-works.com>
parents: 2462
diff changeset
2198 Index('cs_revision_idx', 'revision'),
b426ecc30319 Added some DB indexes to optimize queries
Marcin Kuzminski <marcin@python-works.com>
parents: 2462
diff changeset
2199 Index('cs_version_idx', 'version'),
2287
8447d35b674e Added simple versioning for changeset status
Marcin Kuzminski <marcin@python-works.com>
parents: 2286
diff changeset
2200 UniqueConstraint('repo_id', 'revision', 'version'),
2215
2c2bdaeca912 code-review initial
Marcin Kuzminski <marcin@python-works.com>
parents: 2161
diff changeset
2201 {'extend_existing': True, 'mysql_engine': 'InnoDB',
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
2202 'mysql_charset': 'utf8', 'sqlite_autoincrement': True}
2215
2c2bdaeca912 code-review initial
Marcin Kuzminski <marcin@python-works.com>
parents: 2161
diff changeset
2203 )
2481
4d3032431d4f Adde pull request voting recalculation
Marcin Kuzminski <marcin@python-works.com>
parents: 2480
diff changeset
2204 STATUS_NOT_REVIEWED = DEFAULT = 'not_reviewed'
4d3032431d4f Adde pull request voting recalculation
Marcin Kuzminski <marcin@python-works.com>
parents: 2480
diff changeset
2205 STATUS_APPROVED = 'approved'
4d3032431d4f Adde pull request voting recalculation
Marcin Kuzminski <marcin@python-works.com>
parents: 2480
diff changeset
2206 STATUS_REJECTED = 'rejected'
4d3032431d4f Adde pull request voting recalculation
Marcin Kuzminski <marcin@python-works.com>
parents: 2480
diff changeset
2207 STATUS_UNDER_REVIEW = 'under_review'
2215
2c2bdaeca912 code-review initial
Marcin Kuzminski <marcin@python-works.com>
parents: 2161
diff changeset
2208
2c2bdaeca912 code-review initial
Marcin Kuzminski <marcin@python-works.com>
parents: 2161
diff changeset
2209 STATUSES = [
2481
4d3032431d4f Adde pull request voting recalculation
Marcin Kuzminski <marcin@python-works.com>
parents: 2480
diff changeset
2210 (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
2211 (STATUS_APPROVED, _("Approved")),
4d3032431d4f Adde pull request voting recalculation
Marcin Kuzminski <marcin@python-works.com>
parents: 2480
diff changeset
2212 (STATUS_REJECTED, _("Rejected")),
4d3032431d4f Adde pull request voting recalculation
Marcin Kuzminski <marcin@python-works.com>
parents: 2480
diff changeset
2213 (STATUS_UNDER_REVIEW, _("Under Review")),
2215
2c2bdaeca912 code-review initial
Marcin Kuzminski <marcin@python-works.com>
parents: 2161
diff changeset
2214 ]
2c2bdaeca912 code-review initial
Marcin Kuzminski <marcin@python-works.com>
parents: 2161
diff changeset
2215
2c2bdaeca912 code-review initial
Marcin Kuzminski <marcin@python-works.com>
parents: 2161
diff changeset
2216 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
2217 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
2218 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
2219 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
2220 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
2221 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
2222 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
2223 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
2224 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
2225
2215
2c2bdaeca912 code-review initial
Marcin Kuzminski <marcin@python-works.com>
parents: 2161
diff changeset
2226 author = relationship('User', lazy='joined')
2c2bdaeca912 code-review initial
Marcin Kuzminski <marcin@python-works.com>
parents: 2161
diff changeset
2227 repo = relationship('Repository')
2286
9265958e33bb Show changes of status inside comments
Marcin Kuzminski <marcin@python-works.com>
parents: 2280
diff changeset
2228 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
2229 pull_request = relationship('PullRequest', lazy='joined')
2215
2c2bdaeca912 code-review initial
Marcin Kuzminski <marcin@python-works.com>
parents: 2161
diff changeset
2230
2481
4d3032431d4f Adde pull request voting recalculation
Marcin Kuzminski <marcin@python-works.com>
parents: 2480
diff changeset
2231 def __unicode__(self):
4d3032431d4f Adde pull request voting recalculation
Marcin Kuzminski <marcin@python-works.com>
parents: 2480
diff changeset
2232 return u"<%s('%s:%s')>" % (
4d3032431d4f Adde pull request voting recalculation
Marcin Kuzminski <marcin@python-works.com>
parents: 2480
diff changeset
2233 self.__class__.__name__,
4d3032431d4f Adde pull request voting recalculation
Marcin Kuzminski <marcin@python-works.com>
parents: 2480
diff changeset
2234 self.status, self.author
4d3032431d4f Adde pull request voting recalculation
Marcin Kuzminski <marcin@python-works.com>
parents: 2480
diff changeset
2235 )
4d3032431d4f Adde pull request voting recalculation
Marcin Kuzminski <marcin@python-works.com>
parents: 2480
diff changeset
2236
2296
e5c0f201ca0b Add changeset status change into emails
Marcin Kuzminski <marcin@python-works.com>
parents: 2287
diff changeset
2237 @classmethod
e5c0f201ca0b Add changeset status change into emails
Marcin Kuzminski <marcin@python-works.com>
parents: 2287
diff changeset
2238 def get_status_lbl(cls, value):
e5c0f201ca0b Add changeset status change into emails
Marcin Kuzminski <marcin@python-works.com>
parents: 2287
diff changeset
2239 return dict(cls.STATUSES).get(value)
e5c0f201ca0b Add changeset status change into emails
Marcin Kuzminski <marcin@python-works.com>
parents: 2287
diff changeset
2240
2217
76947224bf27 Implemented initial code-review status of changesets
Marcin Kuzminski <marcin@python-works.com>
parents: 2215
diff changeset
2241 @property
76947224bf27 Implemented initial code-review status of changesets
Marcin Kuzminski <marcin@python-works.com>
parents: 2215
diff changeset
2242 def status_lbl(self):
2296
e5c0f201ca0b Add changeset status change into emails
Marcin Kuzminski <marcin@python-works.com>
parents: 2287
diff changeset
2243 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
2244
2215
2c2bdaeca912 code-review initial
Marcin Kuzminski <marcin@python-works.com>
parents: 2161
diff changeset
2245
2434
f29469677319 Added basic models for saving open pull requests
Marcin Kuzminski <marcin@python-works.com>
parents: 2430
diff changeset
2246 class PullRequest(Base, BaseModel):
f29469677319 Added basic models for saving open pull requests
Marcin Kuzminski <marcin@python-works.com>
parents: 2430
diff changeset
2247 __tablename__ = 'pull_requests'
f29469677319 Added basic models for saving open pull requests
Marcin Kuzminski <marcin@python-works.com>
parents: 2430
diff changeset
2248 __table_args__ = (
f29469677319 Added basic models for saving open pull requests
Marcin Kuzminski <marcin@python-works.com>
parents: 2430
diff changeset
2249 {'extend_existing': True, 'mysql_engine': 'InnoDB',
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
2250 'mysql_charset': 'utf8', 'sqlite_autoincrement': True},
2434
f29469677319 Added basic models for saving open pull requests
Marcin Kuzminski <marcin@python-works.com>
parents: 2430
diff changeset
2251 )
f29469677319 Added basic models for saving open pull requests
Marcin Kuzminski <marcin@python-works.com>
parents: 2430
diff changeset
2252
4049
3b5f32aeed36 comments: clarify in ui whether comments are for changeset or PR
Mads Kiilerich <madski@unity3d.com>
parents: 3971
diff changeset
2253 # values for .status
2588
32dd6896abcf added status column to pull request + some small refactoring of models
Marcin Kuzminski <marcin@python-works.com>
parents: 2585
diff changeset
2254 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
2255 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
2256 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
2257
2434
f29469677319 Added basic models for saving open pull requests
Marcin Kuzminski <marcin@python-works.com>
parents: 2430
diff changeset
2258 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
2259 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
2260 description = Column('description', UnicodeText(10240), nullable=True)
4049
3b5f32aeed36 comments: clarify in ui whether comments are for changeset or PR
Mads Kiilerich <madski@unity3d.com>
parents: 3971
diff changeset
2261 status = Column('status', Unicode(256), nullable=False, default=STATUS_NEW) # only for closedness, not approve/reject/etc
2440
1bc579bcd67a - pull request generates overview based on it's params
Marcin Kuzminski <marcin@python-works.com>
parents: 2434
diff changeset
2262 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
2263 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
2264 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
2265 _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
2266 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
2267 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
2268 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
2269 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
2270
f29469677319 Added basic models for saving open pull requests
Marcin Kuzminski <marcin@python-works.com>
parents: 2430
diff changeset
2271 @hybrid_property
f29469677319 Added basic models for saving open pull requests
Marcin Kuzminski <marcin@python-works.com>
parents: 2430
diff changeset
2272 def revisions(self):
f29469677319 Added basic models for saving open pull requests
Marcin Kuzminski <marcin@python-works.com>
parents: 2430
diff changeset
2273 return self._revisions.split(':')
f29469677319 Added basic models for saving open pull requests
Marcin Kuzminski <marcin@python-works.com>
parents: 2430
diff changeset
2274
f29469677319 Added basic models for saving open pull requests
Marcin Kuzminski <marcin@python-works.com>
parents: 2430
diff changeset
2275 @revisions.setter
f29469677319 Added basic models for saving open pull requests
Marcin Kuzminski <marcin@python-works.com>
parents: 2430
diff changeset
2276 def revisions(self, val):
f29469677319 Added basic models for saving open pull requests
Marcin Kuzminski <marcin@python-works.com>
parents: 2430
diff changeset
2277 self._revisions = ':'.join(val)
f29469677319 Added basic models for saving open pull requests
Marcin Kuzminski <marcin@python-works.com>
parents: 2430
diff changeset
2278
3170
2ab2eed4a70a implemented #725 Pull Request View - Show origin repo URL
Marcin Kuzminski <marcin@python-works.com>
parents: 3152
diff changeset
2279 @property
2ab2eed4a70a implemented #725 Pull Request View - Show origin repo URL
Marcin Kuzminski <marcin@python-works.com>
parents: 3152
diff changeset
2280 def org_ref_parts(self):
2ab2eed4a70a implemented #725 Pull Request View - Show origin repo URL
Marcin Kuzminski <marcin@python-works.com>
parents: 3152
diff changeset
2281 return self.org_ref.split(':')
2ab2eed4a70a implemented #725 Pull Request View - Show origin repo URL
Marcin Kuzminski <marcin@python-works.com>
parents: 3152
diff changeset
2282
2ab2eed4a70a implemented #725 Pull Request View - Show origin repo URL
Marcin Kuzminski <marcin@python-works.com>
parents: 3152
diff changeset
2283 @property
2ab2eed4a70a implemented #725 Pull Request View - Show origin repo URL
Marcin Kuzminski <marcin@python-works.com>
parents: 3152
diff changeset
2284 def other_ref_parts(self):
2ab2eed4a70a implemented #725 Pull Request View - Show origin repo URL
Marcin Kuzminski <marcin@python-works.com>
parents: 3152
diff changeset
2285 return self.other_ref.split(':')
2ab2eed4a70a implemented #725 Pull Request View - Show origin repo URL
Marcin Kuzminski <marcin@python-works.com>
parents: 3152
diff changeset
2286
2440
1bc579bcd67a - pull request generates overview based on it's params
Marcin Kuzminski <marcin@python-works.com>
parents: 2434
diff changeset
2287 author = relationship('User', lazy='joined')
2674
a221706dab50 merged + fixed pull request #62: Implemented metatags and visualisation options.
Marcin Kuzminski <marcin@python-works.com>
parents: 2668
diff changeset
2288 reviewers = relationship('PullRequestReviewers',
2666
c51fb1da6df2 cascade fixes for comments/pull-requests/reviewers
Marcin Kuzminski <marcin@python-works.com>
parents: 2665
diff changeset
2289 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
2290 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
2291 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
2292 statuses = relationship('ChangesetStatus')
c51fb1da6df2 cascade fixes for comments/pull-requests/reviewers
Marcin Kuzminski <marcin@python-works.com>
parents: 2665
diff changeset
2293 comments = relationship('ChangesetComment',
c51fb1da6df2 cascade fixes for comments/pull-requests/reviewers
Marcin Kuzminski <marcin@python-works.com>
parents: 2665
diff changeset
2294 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
2295
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
2296 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
2297 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
2298
3264
565806c66c4d Add new attr to pull request
Marcin Kuzminski <marcin@python-works.com>
parents: 3246
diff changeset
2299 @property
565806c66c4d Add new attr to pull request
Marcin Kuzminski <marcin@python-works.com>
parents: 3246
diff changeset
2300 def last_review_status(self):
3274
567207469e95 laste_review status should only return if there are any statuses
Marcin Kuzminski <marcin@python-works.com>
parents: 3267
diff changeset
2301 return self.statuses[-1].status if self.statuses else ''
3264
565806c66c4d Add new attr to pull request
Marcin Kuzminski <marcin@python-works.com>
parents: 3246
diff changeset
2302
2434
f29469677319 Added basic models for saving open pull requests
Marcin Kuzminski <marcin@python-works.com>
parents: 2430
diff changeset
2303 def __json__(self):
f29469677319 Added basic models for saving open pull requests
Marcin Kuzminski <marcin@python-works.com>
parents: 2430
diff changeset
2304 return dict(
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
2305 revisions=self.revisions
2434
f29469677319 Added basic models for saving open pull requests
Marcin Kuzminski <marcin@python-works.com>
parents: 2430
diff changeset
2306 )
f29469677319 Added basic models for saving open pull requests
Marcin Kuzminski <marcin@python-works.com>
parents: 2430
diff changeset
2307
f29469677319 Added basic models for saving open pull requests
Marcin Kuzminski <marcin@python-works.com>
parents: 2430
diff changeset
2308
f29469677319 Added basic models for saving open pull requests
Marcin Kuzminski <marcin@python-works.com>
parents: 2430
diff changeset
2309 class PullRequestReviewers(Base, BaseModel):
f29469677319 Added basic models for saving open pull requests
Marcin Kuzminski <marcin@python-works.com>
parents: 2430
diff changeset
2310 __tablename__ = 'pull_request_reviewers'
f29469677319 Added basic models for saving open pull requests
Marcin Kuzminski <marcin@python-works.com>
parents: 2430
diff changeset
2311 __table_args__ = (
f29469677319 Added basic models for saving open pull requests
Marcin Kuzminski <marcin@python-works.com>
parents: 2430
diff changeset
2312 {'extend_existing': True, 'mysql_engine': 'InnoDB',
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
2313 'mysql_charset': 'utf8', 'sqlite_autoincrement': True},
2434
f29469677319 Added basic models for saving open pull requests
Marcin Kuzminski <marcin@python-works.com>
parents: 2430
diff changeset
2314 )
f29469677319 Added basic models for saving open pull requests
Marcin Kuzminski <marcin@python-works.com>
parents: 2430
diff changeset
2315
f29469677319 Added basic models for saving open pull requests
Marcin Kuzminski <marcin@python-works.com>
parents: 2430
diff changeset
2316 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
2317 self.user = user
f29469677319 Added basic models for saving open pull requests
Marcin Kuzminski <marcin@python-works.com>
parents: 2430
diff changeset
2318 self.pull_request = pull_request
f29469677319 Added basic models for saving open pull requests
Marcin Kuzminski <marcin@python-works.com>
parents: 2430
diff changeset
2319
f29469677319 Added basic models for saving open pull requests
Marcin Kuzminski <marcin@python-works.com>
parents: 2430
diff changeset
2320 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
2321 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
2322 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
2323
f29469677319 Added basic models for saving open pull requests
Marcin Kuzminski <marcin@python-works.com>
parents: 2430
diff changeset
2324 user = relationship('User')
f29469677319 Added basic models for saving open pull requests
Marcin Kuzminski <marcin@python-works.com>
parents: 2430
diff changeset
2325 pull_request = relationship('PullRequest')
1886
50e32940e464 code garden
Marcin Kuzminski <marcin@python-works.com>
parents: 1884
diff changeset
2326
1703
f23828b00b21 notification fixes and improvements
Marcin Kuzminski <marcin@python-works.com>
parents: 1702
diff changeset
2327
1702
8cb7f5c4d494 #302 - basic notification system, models+tests
Marcin Kuzminski <marcin@python-works.com>
parents: 1693
diff changeset
2328 class Notification(Base, BaseModel):
8cb7f5c4d494 #302 - basic notification system, models+tests
Marcin Kuzminski <marcin@python-works.com>
parents: 1693
diff changeset
2329 __tablename__ = 'notifications'
2149
50aa7cb78cfe Mysql fixes
Marcin Kuzminski <marcin@python-works.com>
parents: 2147
diff changeset
2330 __table_args__ = (
2463
b426ecc30319 Added some DB indexes to optimize queries
Marcin Kuzminski <marcin@python-works.com>
parents: 2462
diff changeset
2331 Index('notification_type_idx', 'type'),
2356
2da7b5984ae5 typo fix + code garden
Marcin Kuzminski <marcin@python-works.com>
parents: 2352
diff changeset
2332 {'extend_existing': True, 'mysql_engine': 'InnoDB',
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
2333 'mysql_charset': 'utf8', 'sqlite_autoincrement': True},
2149
50aa7cb78cfe Mysql fixes
Marcin Kuzminski <marcin@python-works.com>
parents: 2147
diff changeset
2334 )
1703
f23828b00b21 notification fixes and improvements
Marcin Kuzminski <marcin@python-works.com>
parents: 1702
diff changeset
2335
1712
cac5109ac3b6 Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents: 1703
diff changeset
2336 TYPE_CHANGESET_COMMENT = u'cs_comment'
cac5109ac3b6 Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents: 1703
diff changeset
2337 TYPE_MESSAGE = u'message'
cac5109ac3b6 Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents: 1703
diff changeset
2338 TYPE_MENTION = u'mention'
1731
31e6eb2fb4b2 implements #222 registration feedback
Marcin Kuzminski <marcin@python-works.com>
parents: 1729
diff changeset
2339 TYPE_REGISTRATION = u'registration'
2244
77e376fdc4c6 pull requests draft UI
Marcin Kuzminski <marcin@python-works.com>
parents: 2218
diff changeset
2340 TYPE_PULL_REQUEST = u'pull_request'
2443
fd0a822481ec - added commenting to pull requests
Marcin Kuzminski <marcin@python-works.com>
parents: 2440
diff changeset
2341 TYPE_PULL_REQUEST_COMMENT = u'pull_request_comment'
1703
f23828b00b21 notification fixes and improvements
Marcin Kuzminski <marcin@python-works.com>
parents: 1702
diff changeset
2342
1702
8cb7f5c4d494 #302 - basic notification system, models+tests
Marcin Kuzminski <marcin@python-works.com>
parents: 1693
diff changeset
2343 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
2344 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
2345 body = Column('body', UnicodeText(50000), nullable=True)
1703
f23828b00b21 notification fixes and improvements
Marcin Kuzminski <marcin@python-works.com>
parents: 1702
diff changeset
2346 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
2347 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
2348 type_ = Column('type', Unicode(256))
1702
8cb7f5c4d494 #302 - basic notification system, models+tests
Marcin Kuzminski <marcin@python-works.com>
parents: 1693
diff changeset
2349
1712
cac5109ac3b6 Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents: 1703
diff changeset
2350 created_by_user = relationship('User')
1717
7ff304d3028f Notification fixes
Marcin Kuzminski <marcin@python-works.com>
parents: 1716
diff changeset
2351 notifications_to_users = relationship('UserNotification', lazy='joined',
7ff304d3028f Notification fixes
Marcin Kuzminski <marcin@python-works.com>
parents: 1716
diff changeset
2352 cascade="all, delete, delete-orphan")
1702
8cb7f5c4d494 #302 - basic notification system, models+tests
Marcin Kuzminski <marcin@python-works.com>
parents: 1693
diff changeset
2353
8cb7f5c4d494 #302 - basic notification system, models+tests
Marcin Kuzminski <marcin@python-works.com>
parents: 1693
diff changeset
2354 @property
8cb7f5c4d494 #302 - basic notification system, models+tests
Marcin Kuzminski <marcin@python-works.com>
parents: 1693
diff changeset
2355 def recipients(self):
8cb7f5c4d494 #302 - basic notification system, models+tests
Marcin Kuzminski <marcin@python-works.com>
parents: 1693
diff changeset
2356 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
2357 .filter(UserNotification.notification == self)\
2585
a52cee88d612 fixed sorting in recipients query of notifications
Marcin Kuzminski <marcin@python-works.com>
parents: 2562
diff changeset
2358 .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
2359
8cb7f5c4d494 #302 - basic notification system, models+tests
Marcin Kuzminski <marcin@python-works.com>
parents: 1693
diff changeset
2360 @classmethod
1703
f23828b00b21 notification fixes and improvements
Marcin Kuzminski <marcin@python-works.com>
parents: 1702
diff changeset
2361 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
2362 if type_ is None:
f23828b00b21 notification fixes and improvements
Marcin Kuzminski <marcin@python-works.com>
parents: 1702
diff changeset
2363 type_ = Notification.TYPE_MESSAGE
f23828b00b21 notification fixes and improvements
Marcin Kuzminski <marcin@python-works.com>
parents: 1702
diff changeset
2364
1702
8cb7f5c4d494 #302 - basic notification system, models+tests
Marcin Kuzminski <marcin@python-works.com>
parents: 1693
diff changeset
2365 notification = cls()
1712
cac5109ac3b6 Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents: 1703
diff changeset
2366 notification.created_by_user = created_by
1702
8cb7f5c4d494 #302 - basic notification system, models+tests
Marcin Kuzminski <marcin@python-works.com>
parents: 1693
diff changeset
2367 notification.subject = subject
8cb7f5c4d494 #302 - basic notification system, models+tests
Marcin Kuzminski <marcin@python-works.com>
parents: 1693
diff changeset
2368 notification.body = body
1703
f23828b00b21 notification fixes and improvements
Marcin Kuzminski <marcin@python-works.com>
parents: 1702
diff changeset
2369 notification.type_ = type_
1717
7ff304d3028f Notification fixes
Marcin Kuzminski <marcin@python-works.com>
parents: 1716
diff changeset
2370 notification.created_on = datetime.datetime.now()
1713
54687aa00724 Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents: 1712
diff changeset
2371
1702
8cb7f5c4d494 #302 - basic notification system, models+tests
Marcin Kuzminski <marcin@python-works.com>
parents: 1693
diff changeset
2372 for u in recipients:
1713
54687aa00724 Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents: 1712
diff changeset
2373 assoc = UserNotification()
54687aa00724 Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents: 1712
diff changeset
2374 assoc.notification = notification
54687aa00724 Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents: 1712
diff changeset
2375 u.notifications.append(assoc)
2520
a1e156503afe Fixed calls to Session in db model
Marcin Kuzminski <marcin@python-works.com>
parents: 2510
diff changeset
2376 Session().add(notification)
1702
8cb7f5c4d494 #302 - basic notification system, models+tests
Marcin Kuzminski <marcin@python-works.com>
parents: 1693
diff changeset
2377 return notification
8cb7f5c4d494 #302 - basic notification system, models+tests
Marcin Kuzminski <marcin@python-works.com>
parents: 1693
diff changeset
2378
1712
cac5109ac3b6 Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents: 1703
diff changeset
2379 @property
cac5109ac3b6 Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents: 1703
diff changeset
2380 def description(self):
cac5109ac3b6 Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents: 1703
diff changeset
2381 from rhodecode.model.notification import NotificationModel
cac5109ac3b6 Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents: 1703
diff changeset
2382 return NotificationModel().make_description(self)
cac5109ac3b6 Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents: 1703
diff changeset
2383
1800
6c86c987cf93 pep8ify
Marcin Kuzminski <marcin@python-works.com>
parents: 1758
diff changeset
2384
1702
8cb7f5c4d494 #302 - basic notification system, models+tests
Marcin Kuzminski <marcin@python-works.com>
parents: 1693
diff changeset
2385 class UserNotification(Base, BaseModel):
8cb7f5c4d494 #302 - basic notification system, models+tests
Marcin Kuzminski <marcin@python-works.com>
parents: 1693
diff changeset
2386 __tablename__ = 'user_to_notification'
1958
7e4b3d3a9c5c renamed repo groups table
Marcin Kuzminski <marcin@python-works.com>
parents: 1950
diff changeset
2387 __table_args__ = (
7e4b3d3a9c5c renamed repo groups table
Marcin Kuzminski <marcin@python-works.com>
parents: 1950
diff changeset
2388 UniqueConstraint('user_id', 'notification_id'),
2356
2da7b5984ae5 typo fix + code garden
Marcin Kuzminski <marcin@python-works.com>
parents: 2352
diff changeset
2389 {'extend_existing': True, 'mysql_engine': 'InnoDB',
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
2390 'mysql_charset': 'utf8', 'sqlite_autoincrement': True}
1958
7e4b3d3a9c5c renamed repo groups table
Marcin Kuzminski <marcin@python-works.com>
parents: 1950
diff changeset
2391 )
7e4b3d3a9c5c renamed repo groups table
Marcin Kuzminski <marcin@python-works.com>
parents: 1950
diff changeset
2392 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
2393 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
2394 read = Column('read', Boolean, default=False)
1702
8cb7f5c4d494 #302 - basic notification system, models+tests
Marcin Kuzminski <marcin@python-works.com>
parents: 1693
diff changeset
2395 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
2396
1713
54687aa00724 Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents: 1712
diff changeset
2397 user = relationship('User', lazy="joined")
1717
7ff304d3028f Notification fixes
Marcin Kuzminski <marcin@python-works.com>
parents: 1716
diff changeset
2398 notification = relationship('Notification', lazy="joined",
1960
3daa7093fbbb fix typo in db models
Marcin Kuzminski <marcin@python-works.com>
parents: 1958
diff changeset
2399 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
2400
1712
cac5109ac3b6 Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents: 1703
diff changeset
2401 def mark_as_read(self):
cac5109ac3b6 Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents: 1703
diff changeset
2402 self.read = True
2520
a1e156503afe Fixed calls to Session in db model
Marcin Kuzminski <marcin@python-works.com>
parents: 2510
diff changeset
2403 Session().add(self)
1702
8cb7f5c4d494 #302 - basic notification system, models+tests
Marcin Kuzminski <marcin@python-works.com>
parents: 1693
diff changeset
2404
1800
6c86c987cf93 pep8ify
Marcin Kuzminski <marcin@python-works.com>
parents: 1758
diff changeset
2405
3840
dc4644865e8b Implemented simple gist functionality ref #530.
Marcin Kuzminski <marcin@python-works.com>
parents: 3808
diff changeset
2406 class Gist(Base, BaseModel):
dc4644865e8b Implemented simple gist functionality ref #530.
Marcin Kuzminski <marcin@python-works.com>
parents: 3808
diff changeset
2407 __tablename__ = 'gists'
dc4644865e8b Implemented simple gist functionality ref #530.
Marcin Kuzminski <marcin@python-works.com>
parents: 3808
diff changeset
2408 __table_args__ = (
dc4644865e8b Implemented simple gist functionality ref #530.
Marcin Kuzminski <marcin@python-works.com>
parents: 3808
diff changeset
2409 Index('g_gist_access_id_idx', 'gist_access_id'),
dc4644865e8b Implemented simple gist functionality ref #530.
Marcin Kuzminski <marcin@python-works.com>
parents: 3808
diff changeset
2410 Index('g_created_on_idx', 'created_on'),
dc4644865e8b Implemented simple gist functionality ref #530.
Marcin Kuzminski <marcin@python-works.com>
parents: 3808
diff changeset
2411 {'extend_existing': True, 'mysql_engine': 'InnoDB',
3957
b87def4b3cbb Add autoincrement for sqlite into Gist table.
Marcin Kuzminski <marcin@python-works.com>
parents: 3942
diff changeset
2412 'mysql_charset': 'utf8', 'sqlite_autoincrement': True}
3840
dc4644865e8b Implemented simple gist functionality ref #530.
Marcin Kuzminski <marcin@python-works.com>
parents: 3808
diff changeset
2413 )
dc4644865e8b Implemented simple gist functionality ref #530.
Marcin Kuzminski <marcin@python-works.com>
parents: 3808
diff changeset
2414 GIST_PUBLIC = u'public'
dc4644865e8b Implemented simple gist functionality ref #530.
Marcin Kuzminski <marcin@python-works.com>
parents: 3808
diff changeset
2415 GIST_PRIVATE = u'private'
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
2416 DEFAULT_FILENAME = u'gistfile1.txt'
3840
dc4644865e8b Implemented simple gist functionality ref #530.
Marcin Kuzminski <marcin@python-works.com>
parents: 3808
diff changeset
2417
dc4644865e8b Implemented simple gist functionality ref #530.
Marcin Kuzminski <marcin@python-works.com>
parents: 3808
diff changeset
2418 gist_id = Column('gist_id', Integer(), primary_key=True)
3870
b08a3f8a4148 decrease column size for gist_access_id.
Marcin Kuzminski <marcin@python-works.com>
parents: 3869
diff changeset
2419 gist_access_id = Column('gist_access_id', Unicode(250))
3840
dc4644865e8b Implemented simple gist functionality ref #530.
Marcin Kuzminski <marcin@python-works.com>
parents: 3808
diff changeset
2420 gist_description = Column('gist_description', UnicodeText(1024))
dc4644865e8b Implemented simple gist functionality ref #530.
Marcin Kuzminski <marcin@python-works.com>
parents: 3808
diff changeset
2421 gist_owner = Column('user_id', Integer(), ForeignKey('users.user_id'), nullable=True)
3971
7f71d22a1794 Fixed issues with how mysql handles float values. Caused gists with
Marcin Kuzminski <marcin@python-works.com>
parents: 3960
diff changeset
2422 gist_expires = Column('gist_expires', Float(53), nullable=False)
3840
dc4644865e8b Implemented simple gist functionality ref #530.
Marcin Kuzminski <marcin@python-works.com>
parents: 3808
diff changeset
2423 gist_type = Column('gist_type', Unicode(128), nullable=False)
dc4644865e8b Implemented simple gist functionality ref #530.
Marcin Kuzminski <marcin@python-works.com>
parents: 3808
diff changeset
2424 created_on = Column('created_on', DateTime(timezone=False), nullable=False, default=datetime.datetime.now)
dc4644865e8b Implemented simple gist functionality ref #530.
Marcin Kuzminski <marcin@python-works.com>
parents: 3808
diff changeset
2425 modified_at = Column('modified_at', DateTime(timezone=False), nullable=False, default=datetime.datetime.now)
dc4644865e8b Implemented simple gist functionality ref #530.
Marcin Kuzminski <marcin@python-works.com>
parents: 3808
diff changeset
2426
dc4644865e8b Implemented simple gist functionality ref #530.
Marcin Kuzminski <marcin@python-works.com>
parents: 3808
diff changeset
2427 owner = relationship('User')
dc4644865e8b Implemented simple gist functionality ref #530.
Marcin Kuzminski <marcin@python-works.com>
parents: 3808
diff changeset
2428
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
2429 def __repr__(self):
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
2430 return '<Gist:[%s]%s>' % (self.gist_type, self.gist_access_id)
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
2431
3840
dc4644865e8b Implemented simple gist functionality ref #530.
Marcin Kuzminski <marcin@python-works.com>
parents: 3808
diff changeset
2432 @classmethod
dc4644865e8b Implemented simple gist functionality ref #530.
Marcin Kuzminski <marcin@python-works.com>
parents: 3808
diff changeset
2433 def get_or_404(cls, id_):
dc4644865e8b Implemented simple gist functionality ref #530.
Marcin Kuzminski <marcin@python-works.com>
parents: 3808
diff changeset
2434 res = cls.query().filter(cls.gist_access_id == id_).scalar()
dc4644865e8b Implemented simple gist functionality ref #530.
Marcin Kuzminski <marcin@python-works.com>
parents: 3808
diff changeset
2435 if not res:
dc4644865e8b Implemented simple gist functionality ref #530.
Marcin Kuzminski <marcin@python-works.com>
parents: 3808
diff changeset
2436 raise HTTPNotFound
dc4644865e8b Implemented simple gist functionality ref #530.
Marcin Kuzminski <marcin@python-works.com>
parents: 3808
diff changeset
2437 return res
dc4644865e8b Implemented simple gist functionality ref #530.
Marcin Kuzminski <marcin@python-works.com>
parents: 3808
diff changeset
2438
dc4644865e8b Implemented simple gist functionality ref #530.
Marcin Kuzminski <marcin@python-works.com>
parents: 3808
diff changeset
2439 @classmethod
dc4644865e8b Implemented simple gist functionality ref #530.
Marcin Kuzminski <marcin@python-works.com>
parents: 3808
diff changeset
2440 def get_by_access_id(cls, gist_access_id):
3842
54bc7a89f090 gists: add some API related code improvements
Marcin Kuzminski <marcin@python-works.com>
parents: 3840
diff changeset
2441 return cls.query().filter(cls.gist_access_id == gist_access_id).scalar()
3840
dc4644865e8b Implemented simple gist functionality ref #530.
Marcin Kuzminski <marcin@python-works.com>
parents: 3808
diff changeset
2442
dc4644865e8b Implemented simple gist functionality ref #530.
Marcin Kuzminski <marcin@python-works.com>
parents: 3808
diff changeset
2443 def gist_url(self):
3850
7a4df261a375 added alias configuration option for gists.
Marcin Kuzminski <marcin@python-works.com>
parents: 3842
diff changeset
2444 import rhodecode
7a4df261a375 added alias configuration option for gists.
Marcin Kuzminski <marcin@python-works.com>
parents: 3842
diff changeset
2445 alias_url = rhodecode.CONFIG.get('gist_alias_url')
7a4df261a375 added alias configuration option for gists.
Marcin Kuzminski <marcin@python-works.com>
parents: 3842
diff changeset
2446 if alias_url:
7a4df261a375 added alias configuration option for gists.
Marcin Kuzminski <marcin@python-works.com>
parents: 3842
diff changeset
2447 return alias_url.replace('{gistid}', self.gist_access_id)
7a4df261a375 added alias configuration option for gists.
Marcin Kuzminski <marcin@python-works.com>
parents: 3842
diff changeset
2448
3840
dc4644865e8b Implemented simple gist functionality ref #530.
Marcin Kuzminski <marcin@python-works.com>
parents: 3808
diff changeset
2449 from pylons import url
3866
1fdec7e3aeb2 refactored url.resource to full definition of routes
Marcin Kuzminski <marcin@python-works.com>
parents: 3850
diff changeset
2450 return url('gist', gist_id=self.gist_access_id, qualified=True)
3840
dc4644865e8b Implemented simple gist functionality ref #530.
Marcin Kuzminski <marcin@python-works.com>
parents: 3808
diff changeset
2451
3842
54bc7a89f090 gists: add some API related code improvements
Marcin Kuzminski <marcin@python-works.com>
parents: 3840
diff changeset
2452 @classmethod
54bc7a89f090 gists: add some API related code improvements
Marcin Kuzminski <marcin@python-works.com>
parents: 3840
diff changeset
2453 def base_path(cls):
54bc7a89f090 gists: add some API related code improvements
Marcin Kuzminski <marcin@python-works.com>
parents: 3840
diff changeset
2454 """
54bc7a89f090 gists: add some API related code improvements
Marcin Kuzminski <marcin@python-works.com>
parents: 3840
diff changeset
2455 Returns base path when all gists are stored
54bc7a89f090 gists: add some API related code improvements
Marcin Kuzminski <marcin@python-works.com>
parents: 3840
diff changeset
2456
54bc7a89f090 gists: add some API related code improvements
Marcin Kuzminski <marcin@python-works.com>
parents: 3840
diff changeset
2457 :param cls:
54bc7a89f090 gists: add some API related code improvements
Marcin Kuzminski <marcin@python-works.com>
parents: 3840
diff changeset
2458 """
54bc7a89f090 gists: add some API related code improvements
Marcin Kuzminski <marcin@python-works.com>
parents: 3840
diff changeset
2459 from rhodecode.model.gist import GIST_STORE_LOC
54bc7a89f090 gists: add some API related code improvements
Marcin Kuzminski <marcin@python-works.com>
parents: 3840
diff changeset
2460 q = Session().query(RhodeCodeUi)\
54bc7a89f090 gists: add some API related code improvements
Marcin Kuzminski <marcin@python-works.com>
parents: 3840
diff changeset
2461 .filter(RhodeCodeUi.ui_key == URL_SEP)
54bc7a89f090 gists: add some API related code improvements
Marcin Kuzminski <marcin@python-works.com>
parents: 3840
diff changeset
2462 q = q.options(FromCache("sql_cache_short", "repository_repo_path"))
54bc7a89f090 gists: add some API related code improvements
Marcin Kuzminski <marcin@python-works.com>
parents: 3840
diff changeset
2463 return os.path.join(q.one().ui_value, GIST_STORE_LOC)
54bc7a89f090 gists: add some API related code improvements
Marcin Kuzminski <marcin@python-works.com>
parents: 3840
diff changeset
2464
54bc7a89f090 gists: add some API related code improvements
Marcin Kuzminski <marcin@python-works.com>
parents: 3840
diff changeset
2465 def get_api_data(self):
54bc7a89f090 gists: add some API related code improvements
Marcin Kuzminski <marcin@python-works.com>
parents: 3840
diff changeset
2466 """
54bc7a89f090 gists: add some API related code improvements
Marcin Kuzminski <marcin@python-works.com>
parents: 3840
diff changeset
2467 Common function for generating gist related data for API
54bc7a89f090 gists: add some API related code improvements
Marcin Kuzminski <marcin@python-works.com>
parents: 3840
diff changeset
2468 """
54bc7a89f090 gists: add some API related code improvements
Marcin Kuzminski <marcin@python-works.com>
parents: 3840
diff changeset
2469 gist = self
54bc7a89f090 gists: add some API related code improvements
Marcin Kuzminski <marcin@python-works.com>
parents: 3840
diff changeset
2470 data = dict(
54bc7a89f090 gists: add some API related code improvements
Marcin Kuzminski <marcin@python-works.com>
parents: 3840
diff changeset
2471 gist_id=gist.gist_id,
54bc7a89f090 gists: add some API related code improvements
Marcin Kuzminski <marcin@python-works.com>
parents: 3840
diff changeset
2472 type=gist.gist_type,
54bc7a89f090 gists: add some API related code improvements
Marcin Kuzminski <marcin@python-works.com>
parents: 3840
diff changeset
2473 access_id=gist.gist_access_id,
54bc7a89f090 gists: add some API related code improvements
Marcin Kuzminski <marcin@python-works.com>
parents: 3840
diff changeset
2474 description=gist.gist_description,
54bc7a89f090 gists: add some API related code improvements
Marcin Kuzminski <marcin@python-works.com>
parents: 3840
diff changeset
2475 url=gist.gist_url(),
54bc7a89f090 gists: add some API related code improvements
Marcin Kuzminski <marcin@python-works.com>
parents: 3840
diff changeset
2476 expires=gist.gist_expires,
54bc7a89f090 gists: add some API related code improvements
Marcin Kuzminski <marcin@python-works.com>
parents: 3840
diff changeset
2477 created_on=gist.created_on,
54bc7a89f090 gists: add some API related code improvements
Marcin Kuzminski <marcin@python-works.com>
parents: 3840
diff changeset
2478 )
54bc7a89f090 gists: add some API related code improvements
Marcin Kuzminski <marcin@python-works.com>
parents: 3840
diff changeset
2479 return data
54bc7a89f090 gists: add some API related code improvements
Marcin Kuzminski <marcin@python-works.com>
parents: 3840
diff changeset
2480
54bc7a89f090 gists: add some API related code improvements
Marcin Kuzminski <marcin@python-works.com>
parents: 3840
diff changeset
2481 def __json__(self):
54bc7a89f090 gists: add some API related code improvements
Marcin Kuzminski <marcin@python-works.com>
parents: 3840
diff changeset
2482 data = dict(
54bc7a89f090 gists: add some API related code improvements
Marcin Kuzminski <marcin@python-works.com>
parents: 3840
diff changeset
2483 )
54bc7a89f090 gists: add some API related code improvements
Marcin Kuzminski <marcin@python-works.com>
parents: 3840
diff changeset
2484 data.update(self.get_api_data())
54bc7a89f090 gists: add some API related code improvements
Marcin Kuzminski <marcin@python-works.com>
parents: 3840
diff changeset
2485 return data
54bc7a89f090 gists: add some API related code improvements
Marcin Kuzminski <marcin@python-works.com>
parents: 3840
diff changeset
2486 ## SCM functions
54bc7a89f090 gists: add some API related code improvements
Marcin Kuzminski <marcin@python-works.com>
parents: 3840
diff changeset
2487
54bc7a89f090 gists: add some API related code improvements
Marcin Kuzminski <marcin@python-works.com>
parents: 3840
diff changeset
2488 @property
54bc7a89f090 gists: add some API related code improvements
Marcin Kuzminski <marcin@python-works.com>
parents: 3840
diff changeset
2489 def scm_instance(self):
54bc7a89f090 gists: add some API related code improvements
Marcin Kuzminski <marcin@python-works.com>
parents: 3840
diff changeset
2490 from rhodecode.lib.vcs import get_repo
54bc7a89f090 gists: add some API related code improvements
Marcin Kuzminski <marcin@python-works.com>
parents: 3840
diff changeset
2491 base_path = self.base_path()
54bc7a89f090 gists: add some API related code improvements
Marcin Kuzminski <marcin@python-works.com>
parents: 3840
diff changeset
2492 return get_repo(os.path.join(*map(safe_str,
54bc7a89f090 gists: add some API related code improvements
Marcin Kuzminski <marcin@python-works.com>
parents: 3840
diff changeset
2493 [base_path, self.gist_access_id])))
54bc7a89f090 gists: add some API related code improvements
Marcin Kuzminski <marcin@python-works.com>
parents: 3840
diff changeset
2494
3840
dc4644865e8b Implemented simple gist functionality ref #530.
Marcin Kuzminski <marcin@python-works.com>
parents: 3808
diff changeset
2495
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
2496 class DbMigrateVersion(Base, BaseModel):
834
8924ed0e4f36 added current db version into rhodecode,
Marcin Kuzminski <marcin@python-works.com>
parents: 832
diff changeset
2497 __tablename__ = 'db_migrate_version'
2149
50aa7cb78cfe Mysql fixes
Marcin Kuzminski <marcin@python-works.com>
parents: 2147
diff changeset
2498 __table_args__ = (
2356
2da7b5984ae5 typo fix + code garden
Marcin Kuzminski <marcin@python-works.com>
parents: 2352
diff changeset
2499 {'extend_existing': True, 'mysql_engine': 'InnoDB',
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4049
diff changeset
2500 'mysql_charset': 'utf8', 'sqlite_autoincrement': True},
2149
50aa7cb78cfe Mysql fixes
Marcin Kuzminski <marcin@python-works.com>
parents: 2147
diff changeset
2501 )
1594
9dae92a65e40 fixes #288
Marcin Kuzminski <marcin@python-works.com>
parents: 1593
diff changeset
2502 repository_id = Column('repository_id', String(250), primary_key=True)
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
2503 repository_path = Column('repository_path', Text)
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1592
diff changeset
2504 version = Column('version', Integer)