Mercurial > kallithea
annotate rhodecode/lib/base.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 | a5888ca796b5 |
children | 7e5f8c12a3fc |
rev | line source |
---|---|
4116
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4089
diff
changeset
|
1 # -*- coding: utf-8 -*- |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4089
diff
changeset
|
2 # This program is free software: you can redistribute it and/or modify |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4089
diff
changeset
|
3 # it under the terms of the GNU General Public License as published by |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4089
diff
changeset
|
4 # the Free Software Foundation, either version 3 of the License, or |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4089
diff
changeset
|
5 # (at your option) any later version. |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4089
diff
changeset
|
6 # |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4089
diff
changeset
|
7 # This program is distributed in the hope that it will be useful, |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4089
diff
changeset
|
8 # but WITHOUT ANY WARRANTY; without even the implied warranty of |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4089
diff
changeset
|
9 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4089
diff
changeset
|
10 # GNU General Public License for more details. |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4089
diff
changeset
|
11 # |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4089
diff
changeset
|
12 # You should have received a copy of the GNU General Public License |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4089
diff
changeset
|
13 # along with this program. If not, see <http://www.gnu.org/licenses/>. |
0 | 14 |
15 """ | |
4116
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4089
diff
changeset
|
16 rhodecode.lib.base |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4089
diff
changeset
|
17 ~~~~~~~~~~~~~~~~~~ |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4089
diff
changeset
|
18 |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4089
diff
changeset
|
19 The base Controller API |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4089
diff
changeset
|
20 Provides the BaseController class for subclassing. And usage in different |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4089
diff
changeset
|
21 controllers |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4089
diff
changeset
|
22 |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4089
diff
changeset
|
23 :created_on: Oct 06, 2010 |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4089
diff
changeset
|
24 :author: marcink |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4089
diff
changeset
|
25 :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:
4089
diff
changeset
|
26 :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:
4089
diff
changeset
|
27 """ |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4089
diff
changeset
|
28 |
1373
66f03a87141c
Fixes issue #201
Marcin Kuzminski <marcin@python-works.com>
parents:
1366
diff
changeset
|
29 import logging |
1601
6f06daeed294
Added Request time tracking
Marcin Kuzminski <marcin@python-works.com>
parents:
1530
diff
changeset
|
30 import time |
1813
a8c66e870bd0
implements #285: Implemented non changeable urls for clone url, and web views
Marcin Kuzminski <marcin@python-works.com>
parents:
1763
diff
changeset
|
31 import traceback |
1761
b265be1c6093
Wrapped calls for git and hg middleware in extra block that clears db Session.
Marcin Kuzminski <marcin@python-works.com>
parents:
1749
diff
changeset
|
32 |
b265be1c6093
Wrapped calls for git and hg middleware in extra block that clears db Session.
Marcin Kuzminski <marcin@python-works.com>
parents:
1749
diff
changeset
|
33 from paste.auth.basic import AuthBasicAuthenticator |
2132
9f5582151d53
Alternative HTTP response codes when client failed to Authenticate correctly
Marcin Kuzminski <marcin@python-works.com>
parents:
2109
diff
changeset
|
34 from paste.httpexceptions import HTTPUnauthorized, HTTPForbidden |
2912
976e2b032650
patched basic auth function to overcome git issues with proxy that doesn't send both username and password. ref #586
Marcin Kuzminski <marcin@python-works.com>
parents:
2752
diff
changeset
|
35 from paste.httpheaders import WWW_AUTHENTICATE, AUTHORIZATION |
1761
b265be1c6093
Wrapped calls for git and hg middleware in extra block that clears db Session.
Marcin Kuzminski <marcin@python-works.com>
parents:
1749
diff
changeset
|
36 |
1373
66f03a87141c
Fixes issue #201
Marcin Kuzminski <marcin@python-works.com>
parents:
1366
diff
changeset
|
37 from pylons import config, tmpl_context as c, request, session, url |
0 | 38 from pylons.controllers import WSGIController |
1373
66f03a87141c
Fixes issue #201
Marcin Kuzminski <marcin@python-works.com>
parents:
1366
diff
changeset
|
39 from pylons.controllers.util import redirect |
4116
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4089
diff
changeset
|
40 from pylons.templating import render_mako as render # don't remove this import |
1304
5a96551ee9c0
gui-improvments
Marcin Kuzminski <marcin@python-works.com>
parents:
1282
diff
changeset
|
41 |
1718
f78bee8eec78
reduce cookie size for better support of client side sessions
Marcin Kuzminski <marcin@python-works.com>
parents:
1702
diff
changeset
|
42 from rhodecode import __version__, BACKENDS |
f78bee8eec78
reduce cookie size for better support of client side sessions
Marcin Kuzminski <marcin@python-works.com>
parents:
1702
diff
changeset
|
43 |
2726
aa17c7a1b8a5
Implemented basic locking functionality.
Marcin Kuzminski <marcin@python-works.com>
parents:
2708
diff
changeset
|
44 from rhodecode.lib.utils2 import str2bool, safe_unicode, AttributeDict,\ |
3087
a797ada9d2ad
added option to ini file to define lightweight dashboard items per page before pagination
Marcin Kuzminski <marcin@python-works.com>
parents:
2958
diff
changeset
|
45 safe_str, safe_int |
4116
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4089
diff
changeset
|
46 from rhodecode.lib import auth_modules |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4089
diff
changeset
|
47 from rhodecode.lib.auth import AuthUser, HasPermissionAnyMiddleware, CookieStoreWrapper |
3693
6843cabe9925
removed duplicated logic of how we invalidate caches for repos
Marcin Kuzminski <marcin@python-works.com>
parents:
3669
diff
changeset
|
48 from rhodecode.lib.utils import get_repo_slug |
4074
3b136af34329
Added pre-create user hook.
Marcin Kuzminski <marcin@python-works.com>
parents:
4045
diff
changeset
|
49 from rhodecode.lib.exceptions import UserCreationError |
547
1e757ac98988
renamed project to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
537
diff
changeset
|
50 from rhodecode.model import meta |
1718
f78bee8eec78
reduce cookie size for better support of client side sessions
Marcin Kuzminski <marcin@python-works.com>
parents:
1702
diff
changeset
|
51 |
2955
9c85d884315b
don't use config for visual settings. It totally doesn't work on multi instance mode
Marcin Kuzminski <marcin@python-works.com>
parents:
2952
diff
changeset
|
52 from rhodecode.model.db import Repository, RhodeCodeUi, User, RhodeCodeSetting |
1702
8cb7f5c4d494
#302 - basic notification system, models+tests
Marcin Kuzminski <marcin@python-works.com>
parents:
1630
diff
changeset
|
53 from rhodecode.model.notification import NotificationModel |
1718
f78bee8eec78
reduce cookie size for better support of client side sessions
Marcin Kuzminski <marcin@python-works.com>
parents:
1702
diff
changeset
|
54 from rhodecode.model.scm import ScmModel |
2726
aa17c7a1b8a5
Implemented basic locking functionality.
Marcin Kuzminski <marcin@python-works.com>
parents:
2708
diff
changeset
|
55 from rhodecode.model.meta import Session |
665
070f32743632
Moved out reposcan into hg Model.
Marcin Kuzminski <marcin@python-works.com>
parents:
659
diff
changeset
|
56 |
1373
66f03a87141c
Fixes issue #201
Marcin Kuzminski <marcin@python-works.com>
parents:
1366
diff
changeset
|
57 log = logging.getLogger(__name__) |
1307 | 58 |
1813
a8c66e870bd0
implements #285: Implemented non changeable urls for clone url, and web views
Marcin Kuzminski <marcin@python-works.com>
parents:
1763
diff
changeset
|
59 |
3669
b66fd6de093c
fixed multiple IP addresses in each of extracted IP.
Marcin Kuzminski <marcin@python-works.com>
parents:
3631
diff
changeset
|
60 def _filter_proxy(ip): |
b66fd6de093c
fixed multiple IP addresses in each of extracted IP.
Marcin Kuzminski <marcin@python-works.com>
parents:
3631
diff
changeset
|
61 """ |
3987
b58ed6d608cc
Use space after , in lists
Mads Kiilerich <madski@unity3d.com>
parents:
3960
diff
changeset
|
62 HEADERS can have multiple ips inside the left-most being the original |
3669
b66fd6de093c
fixed multiple IP addresses in each of extracted IP.
Marcin Kuzminski <marcin@python-works.com>
parents:
3631
diff
changeset
|
63 client, and each successive proxy that passed the request adding the IP |
b66fd6de093c
fixed multiple IP addresses in each of extracted IP.
Marcin Kuzminski <marcin@python-works.com>
parents:
3631
diff
changeset
|
64 address where it received the request from. |
b66fd6de093c
fixed multiple IP addresses in each of extracted IP.
Marcin Kuzminski <marcin@python-works.com>
parents:
3631
diff
changeset
|
65 |
b66fd6de093c
fixed multiple IP addresses in each of extracted IP.
Marcin Kuzminski <marcin@python-works.com>
parents:
3631
diff
changeset
|
66 :param ip: |
b66fd6de093c
fixed multiple IP addresses in each of extracted IP.
Marcin Kuzminski <marcin@python-works.com>
parents:
3631
diff
changeset
|
67 """ |
b66fd6de093c
fixed multiple IP addresses in each of extracted IP.
Marcin Kuzminski <marcin@python-works.com>
parents:
3631
diff
changeset
|
68 if ',' in ip: |
b66fd6de093c
fixed multiple IP addresses in each of extracted IP.
Marcin Kuzminski <marcin@python-works.com>
parents:
3631
diff
changeset
|
69 _ips = ip.split(',') |
b66fd6de093c
fixed multiple IP addresses in each of extracted IP.
Marcin Kuzminski <marcin@python-works.com>
parents:
3631
diff
changeset
|
70 _first_ip = _ips[0].strip() |
b66fd6de093c
fixed multiple IP addresses in each of extracted IP.
Marcin Kuzminski <marcin@python-works.com>
parents:
3631
diff
changeset
|
71 log.debug('Got multiple IPs %s, using %s' % (','.join(_ips), _first_ip)) |
b66fd6de093c
fixed multiple IP addresses in each of extracted IP.
Marcin Kuzminski <marcin@python-works.com>
parents:
3631
diff
changeset
|
72 return _first_ip |
b66fd6de093c
fixed multiple IP addresses in each of extracted IP.
Marcin Kuzminski <marcin@python-works.com>
parents:
3631
diff
changeset
|
73 return ip |
b66fd6de093c
fixed multiple IP addresses in each of extracted IP.
Marcin Kuzminski <marcin@python-works.com>
parents:
3631
diff
changeset
|
74 |
b66fd6de093c
fixed multiple IP addresses in each of extracted IP.
Marcin Kuzminski <marcin@python-works.com>
parents:
3631
diff
changeset
|
75 |
2374
be2163ef127e
Add ip reference into BaseController
Marcin Kuzminski <marcin@python-works.com>
parents:
2184
diff
changeset
|
76 def _get_ip_addr(environ): |
be2163ef127e
Add ip reference into BaseController
Marcin Kuzminski <marcin@python-works.com>
parents:
2184
diff
changeset
|
77 proxy_key = 'HTTP_X_REAL_IP' |
be2163ef127e
Add ip reference into BaseController
Marcin Kuzminski <marcin@python-works.com>
parents:
2184
diff
changeset
|
78 proxy_key2 = 'HTTP_X_FORWARDED_FOR' |
be2163ef127e
Add ip reference into BaseController
Marcin Kuzminski <marcin@python-works.com>
parents:
2184
diff
changeset
|
79 def_key = 'REMOTE_ADDR' |
be2163ef127e
Add ip reference into BaseController
Marcin Kuzminski <marcin@python-works.com>
parents:
2184
diff
changeset
|
80 |
3153
8046d1979674
fix multiple ips addresses in X_FORWARDER_FOR header
Marcin Kuzminski <marcin@python-works.com>
parents:
3147
diff
changeset
|
81 ip = environ.get(proxy_key) |
2486
6f537e3da9c4
add IP into base logging, and change a little IP extraction login, if some header is passed as empty
Marcin Kuzminski <marcin@python-works.com>
parents:
2478
diff
changeset
|
82 if ip: |
3669
b66fd6de093c
fixed multiple IP addresses in each of extracted IP.
Marcin Kuzminski <marcin@python-works.com>
parents:
3631
diff
changeset
|
83 return _filter_proxy(ip) |
2486
6f537e3da9c4
add IP into base logging, and change a little IP extraction login, if some header is passed as empty
Marcin Kuzminski <marcin@python-works.com>
parents:
2478
diff
changeset
|
84 |
3153
8046d1979674
fix multiple ips addresses in X_FORWARDER_FOR header
Marcin Kuzminski <marcin@python-works.com>
parents:
3147
diff
changeset
|
85 ip = environ.get(proxy_key2) |
2486
6f537e3da9c4
add IP into base logging, and change a little IP extraction login, if some header is passed as empty
Marcin Kuzminski <marcin@python-works.com>
parents:
2478
diff
changeset
|
86 if ip: |
3669
b66fd6de093c
fixed multiple IP addresses in each of extracted IP.
Marcin Kuzminski <marcin@python-works.com>
parents:
3631
diff
changeset
|
87 return _filter_proxy(ip) |
2486
6f537e3da9c4
add IP into base logging, and change a little IP extraction login, if some header is passed as empty
Marcin Kuzminski <marcin@python-works.com>
parents:
2478
diff
changeset
|
88 |
6f537e3da9c4
add IP into base logging, and change a little IP extraction login, if some header is passed as empty
Marcin Kuzminski <marcin@python-works.com>
parents:
2478
diff
changeset
|
89 ip = environ.get(def_key, '0.0.0.0') |
3669
b66fd6de093c
fixed multiple IP addresses in each of extracted IP.
Marcin Kuzminski <marcin@python-works.com>
parents:
3631
diff
changeset
|
90 return _filter_proxy(ip) |
2374
be2163ef127e
Add ip reference into BaseController
Marcin Kuzminski <marcin@python-works.com>
parents:
2184
diff
changeset
|
91 |
be2163ef127e
Add ip reference into BaseController
Marcin Kuzminski <marcin@python-works.com>
parents:
2184
diff
changeset
|
92 |
2490
7a5eeafb1a9a
better path extraction method.
Marcin Kuzminski <marcin@python-works.com>
parents:
2486
diff
changeset
|
93 def _get_access_path(environ): |
7a5eeafb1a9a
better path extraction method.
Marcin Kuzminski <marcin@python-works.com>
parents:
2486
diff
changeset
|
94 path = environ.get('PATH_INFO') |
7a5eeafb1a9a
better path extraction method.
Marcin Kuzminski <marcin@python-works.com>
parents:
2486
diff
changeset
|
95 org_req = environ.get('pylons.original_request') |
7a5eeafb1a9a
better path extraction method.
Marcin Kuzminski <marcin@python-works.com>
parents:
2486
diff
changeset
|
96 if org_req: |
7a5eeafb1a9a
better path extraction method.
Marcin Kuzminski <marcin@python-works.com>
parents:
2486
diff
changeset
|
97 path = org_req.environ.get('PATH_INFO') |
7a5eeafb1a9a
better path extraction method.
Marcin Kuzminski <marcin@python-works.com>
parents:
2486
diff
changeset
|
98 return path |
7a5eeafb1a9a
better path extraction method.
Marcin Kuzminski <marcin@python-works.com>
parents:
2486
diff
changeset
|
99 |
7a5eeafb1a9a
better path extraction method.
Marcin Kuzminski <marcin@python-works.com>
parents:
2486
diff
changeset
|
100 |
2132
9f5582151d53
Alternative HTTP response codes when client failed to Authenticate correctly
Marcin Kuzminski <marcin@python-works.com>
parents:
2109
diff
changeset
|
101 class BasicAuth(AuthBasicAuthenticator): |
9f5582151d53
Alternative HTTP response codes when client failed to Authenticate correctly
Marcin Kuzminski <marcin@python-works.com>
parents:
2109
diff
changeset
|
102 |
9f5582151d53
Alternative HTTP response codes when client failed to Authenticate correctly
Marcin Kuzminski <marcin@python-works.com>
parents:
2109
diff
changeset
|
103 def __init__(self, realm, authfunc, auth_http_code=None): |
9f5582151d53
Alternative HTTP response codes when client failed to Authenticate correctly
Marcin Kuzminski <marcin@python-works.com>
parents:
2109
diff
changeset
|
104 self.realm = realm |
9f5582151d53
Alternative HTTP response codes when client failed to Authenticate correctly
Marcin Kuzminski <marcin@python-works.com>
parents:
2109
diff
changeset
|
105 self.authfunc = authfunc |
9f5582151d53
Alternative HTTP response codes when client failed to Authenticate correctly
Marcin Kuzminski <marcin@python-works.com>
parents:
2109
diff
changeset
|
106 self._rc_auth_http_code = auth_http_code |
9f5582151d53
Alternative HTTP response codes when client failed to Authenticate correctly
Marcin Kuzminski <marcin@python-works.com>
parents:
2109
diff
changeset
|
107 |
9f5582151d53
Alternative HTTP response codes when client failed to Authenticate correctly
Marcin Kuzminski <marcin@python-works.com>
parents:
2109
diff
changeset
|
108 def build_authentication(self): |
9f5582151d53
Alternative HTTP response codes when client failed to Authenticate correctly
Marcin Kuzminski <marcin@python-works.com>
parents:
2109
diff
changeset
|
109 head = WWW_AUTHENTICATE.tuples('Basic realm="%s"' % self.realm) |
9f5582151d53
Alternative HTTP response codes when client failed to Authenticate correctly
Marcin Kuzminski <marcin@python-works.com>
parents:
2109
diff
changeset
|
110 if self._rc_auth_http_code and self._rc_auth_http_code == '403': |
9f5582151d53
Alternative HTTP response codes when client failed to Authenticate correctly
Marcin Kuzminski <marcin@python-works.com>
parents:
2109
diff
changeset
|
111 # return 403 if alternative http return code is specified in |
9f5582151d53
Alternative HTTP response codes when client failed to Authenticate correctly
Marcin Kuzminski <marcin@python-works.com>
parents:
2109
diff
changeset
|
112 # RhodeCode config |
9f5582151d53
Alternative HTTP response codes when client failed to Authenticate correctly
Marcin Kuzminski <marcin@python-works.com>
parents:
2109
diff
changeset
|
113 return HTTPForbidden(headers=head) |
9f5582151d53
Alternative HTTP response codes when client failed to Authenticate correctly
Marcin Kuzminski <marcin@python-works.com>
parents:
2109
diff
changeset
|
114 return HTTPUnauthorized(headers=head) |
9f5582151d53
Alternative HTTP response codes when client failed to Authenticate correctly
Marcin Kuzminski <marcin@python-works.com>
parents:
2109
diff
changeset
|
115 |
2912
976e2b032650
patched basic auth function to overcome git issues with proxy that doesn't send both username and password. ref #586
Marcin Kuzminski <marcin@python-works.com>
parents:
2752
diff
changeset
|
116 def authenticate(self, environ): |
976e2b032650
patched basic auth function to overcome git issues with proxy that doesn't send both username and password. ref #586
Marcin Kuzminski <marcin@python-works.com>
parents:
2752
diff
changeset
|
117 authorization = AUTHORIZATION(environ) |
976e2b032650
patched basic auth function to overcome git issues with proxy that doesn't send both username and password. ref #586
Marcin Kuzminski <marcin@python-works.com>
parents:
2752
diff
changeset
|
118 if not authorization: |
976e2b032650
patched basic auth function to overcome git issues with proxy that doesn't send both username and password. ref #586
Marcin Kuzminski <marcin@python-works.com>
parents:
2752
diff
changeset
|
119 return self.build_authentication() |
976e2b032650
patched basic auth function to overcome git issues with proxy that doesn't send both username and password. ref #586
Marcin Kuzminski <marcin@python-works.com>
parents:
2752
diff
changeset
|
120 (authmeth, auth) = authorization.split(' ', 1) |
976e2b032650
patched basic auth function to overcome git issues with proxy that doesn't send both username and password. ref #586
Marcin Kuzminski <marcin@python-works.com>
parents:
2752
diff
changeset
|
121 if 'basic' != authmeth.lower(): |
976e2b032650
patched basic auth function to overcome git issues with proxy that doesn't send both username and password. ref #586
Marcin Kuzminski <marcin@python-works.com>
parents:
2752
diff
changeset
|
122 return self.build_authentication() |
976e2b032650
patched basic auth function to overcome git issues with proxy that doesn't send both username and password. ref #586
Marcin Kuzminski <marcin@python-works.com>
parents:
2752
diff
changeset
|
123 auth = auth.strip().decode('base64') |
976e2b032650
patched basic auth function to overcome git issues with proxy that doesn't send both username and password. ref #586
Marcin Kuzminski <marcin@python-works.com>
parents:
2752
diff
changeset
|
124 _parts = auth.split(':', 1) |
976e2b032650
patched basic auth function to overcome git issues with proxy that doesn't send both username and password. ref #586
Marcin Kuzminski <marcin@python-works.com>
parents:
2752
diff
changeset
|
125 if len(_parts) == 2: |
976e2b032650
patched basic auth function to overcome git issues with proxy that doesn't send both username and password. ref #586
Marcin Kuzminski <marcin@python-works.com>
parents:
2752
diff
changeset
|
126 username, password = _parts |
4116
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4089
diff
changeset
|
127 if self.authfunc(username, password, environ): |
2912
976e2b032650
patched basic auth function to overcome git issues with proxy that doesn't send both username and password. ref #586
Marcin Kuzminski <marcin@python-works.com>
parents:
2752
diff
changeset
|
128 return username |
976e2b032650
patched basic auth function to overcome git issues with proxy that doesn't send both username and password. ref #586
Marcin Kuzminski <marcin@python-works.com>
parents:
2752
diff
changeset
|
129 return self.build_authentication() |
976e2b032650
patched basic auth function to overcome git issues with proxy that doesn't send both username and password. ref #586
Marcin Kuzminski <marcin@python-works.com>
parents:
2752
diff
changeset
|
130 |
976e2b032650
patched basic auth function to overcome git issues with proxy that doesn't send both username and password. ref #586
Marcin Kuzminski <marcin@python-works.com>
parents:
2752
diff
changeset
|
131 __call__ = authenticate |
976e2b032650
patched basic auth function to overcome git issues with proxy that doesn't send both username and password. ref #586
Marcin Kuzminski <marcin@python-works.com>
parents:
2752
diff
changeset
|
132 |
2132
9f5582151d53
Alternative HTTP response codes when client failed to Authenticate correctly
Marcin Kuzminski <marcin@python-works.com>
parents:
2109
diff
changeset
|
133 |
1761
b265be1c6093
Wrapped calls for git and hg middleware in extra block that clears db Session.
Marcin Kuzminski <marcin@python-works.com>
parents:
1749
diff
changeset
|
134 class BaseVCSController(object): |
1813
a8c66e870bd0
implements #285: Implemented non changeable urls for clone url, and web views
Marcin Kuzminski <marcin@python-works.com>
parents:
1763
diff
changeset
|
135 |
1761
b265be1c6093
Wrapped calls for git and hg middleware in extra block that clears db Session.
Marcin Kuzminski <marcin@python-works.com>
parents:
1749
diff
changeset
|
136 def __init__(self, application, config): |
b265be1c6093
Wrapped calls for git and hg middleware in extra block that clears db Session.
Marcin Kuzminski <marcin@python-works.com>
parents:
1749
diff
changeset
|
137 self.application = application |
b265be1c6093
Wrapped calls for git and hg middleware in extra block that clears db Session.
Marcin Kuzminski <marcin@python-works.com>
parents:
1749
diff
changeset
|
138 self.config = config |
b265be1c6093
Wrapped calls for git and hg middleware in extra block that clears db Session.
Marcin Kuzminski <marcin@python-works.com>
parents:
1749
diff
changeset
|
139 # base path of repo locations |
b265be1c6093
Wrapped calls for git and hg middleware in extra block that clears db Session.
Marcin Kuzminski <marcin@python-works.com>
parents:
1749
diff
changeset
|
140 self.basepath = self.config['base_path'] |
4116
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4089
diff
changeset
|
141 #authenticate this VCS request using authfunc |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4089
diff
changeset
|
142 self.authenticate = BasicAuth('', auth_modules.authenticate, |
2132
9f5582151d53
Alternative HTTP response codes when client failed to Authenticate correctly
Marcin Kuzminski <marcin@python-works.com>
parents:
2109
diff
changeset
|
143 config.get('auth_ret_code')) |
3125
9b92cf5a0cca
Added UserIpMap interface for allowed IP addresses and IP restriction access
Marcin Kuzminski <marcin@python-works.com>
parents:
3087
diff
changeset
|
144 self.ip_addr = '0.0.0.0' |
1813
a8c66e870bd0
implements #285: Implemented non changeable urls for clone url, and web views
Marcin Kuzminski <marcin@python-works.com>
parents:
1763
diff
changeset
|
145 |
1978
164199e476e9
code garden, pep8
Marcin Kuzminski <marcin@python-works.com>
parents:
1818
diff
changeset
|
146 def _handle_request(self, environ, start_response): |
164199e476e9
code garden, pep8
Marcin Kuzminski <marcin@python-works.com>
parents:
1818
diff
changeset
|
147 raise NotImplementedError() |
164199e476e9
code garden, pep8
Marcin Kuzminski <marcin@python-works.com>
parents:
1818
diff
changeset
|
148 |
1813
a8c66e870bd0
implements #285: Implemented non changeable urls for clone url, and web views
Marcin Kuzminski <marcin@python-works.com>
parents:
1763
diff
changeset
|
149 def _get_by_id(self, repo_name): |
a8c66e870bd0
implements #285: Implemented non changeable urls for clone url, and web views
Marcin Kuzminski <marcin@python-works.com>
parents:
1763
diff
changeset
|
150 """ |
4089
a5888ca796b5
Fixed spelling of get's to gets
Marcin Kuzminski <marcin@python-works.com>
parents:
4074
diff
changeset
|
151 Gets a special pattern _<ID> from clone url and tries to replace it |
1813
a8c66e870bd0
implements #285: Implemented non changeable urls for clone url, and web views
Marcin Kuzminski <marcin@python-works.com>
parents:
1763
diff
changeset
|
152 with a repository_name for support of _<ID> non changable urls |
a8c66e870bd0
implements #285: Implemented non changeable urls for clone url, and web views
Marcin Kuzminski <marcin@python-works.com>
parents:
1763
diff
changeset
|
153 |
a8c66e870bd0
implements #285: Implemented non changeable urls for clone url, and web views
Marcin Kuzminski <marcin@python-works.com>
parents:
1763
diff
changeset
|
154 :param repo_name: |
a8c66e870bd0
implements #285: Implemented non changeable urls for clone url, and web views
Marcin Kuzminski <marcin@python-works.com>
parents:
1763
diff
changeset
|
155 """ |
4116
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4089
diff
changeset
|
156 |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4089
diff
changeset
|
157 data = repo_name.split('/') |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4089
diff
changeset
|
158 if len(data) >= 2: |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4089
diff
changeset
|
159 from rhodecode.lib.utils import get_repo_by_id |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4089
diff
changeset
|
160 by_id_match = get_repo_by_id(repo_name) |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4089
diff
changeset
|
161 if by_id_match: |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4089
diff
changeset
|
162 data[1] = by_id_match |
1813
a8c66e870bd0
implements #285: Implemented non changeable urls for clone url, and web views
Marcin Kuzminski <marcin@python-works.com>
parents:
1763
diff
changeset
|
163 |
a8c66e870bd0
implements #285: Implemented non changeable urls for clone url, and web views
Marcin Kuzminski <marcin@python-works.com>
parents:
1763
diff
changeset
|
164 return '/'.join(data) |
a8c66e870bd0
implements #285: Implemented non changeable urls for clone url, and web views
Marcin Kuzminski <marcin@python-works.com>
parents:
1763
diff
changeset
|
165 |
1761
b265be1c6093
Wrapped calls for git and hg middleware in extra block that clears db Session.
Marcin Kuzminski <marcin@python-works.com>
parents:
1749
diff
changeset
|
166 def _invalidate_cache(self, repo_name): |
b265be1c6093
Wrapped calls for git and hg middleware in extra block that clears db Session.
Marcin Kuzminski <marcin@python-works.com>
parents:
1749
diff
changeset
|
167 """ |
b265be1c6093
Wrapped calls for git and hg middleware in extra block that clears db Session.
Marcin Kuzminski <marcin@python-works.com>
parents:
1749
diff
changeset
|
168 Set's cache for this repository for invalidation on next access |
1813
a8c66e870bd0
implements #285: Implemented non changeable urls for clone url, and web views
Marcin Kuzminski <marcin@python-works.com>
parents:
1763
diff
changeset
|
169 |
1761
b265be1c6093
Wrapped calls for git and hg middleware in extra block that clears db Session.
Marcin Kuzminski <marcin@python-works.com>
parents:
1749
diff
changeset
|
170 :param repo_name: full repo name, also a cache key |
b265be1c6093
Wrapped calls for git and hg middleware in extra block that clears db Session.
Marcin Kuzminski <marcin@python-works.com>
parents:
1749
diff
changeset
|
171 """ |
3693
6843cabe9925
removed duplicated logic of how we invalidate caches for repos
Marcin Kuzminski <marcin@python-works.com>
parents:
3669
diff
changeset
|
172 ScmModel().mark_for_invalidation(repo_name) |
1813
a8c66e870bd0
implements #285: Implemented non changeable urls for clone url, and web views
Marcin Kuzminski <marcin@python-works.com>
parents:
1763
diff
changeset
|
173 |
3125
9b92cf5a0cca
Added UserIpMap interface for allowed IP addresses and IP restriction access
Marcin Kuzminski <marcin@python-works.com>
parents:
3087
diff
changeset
|
174 def _check_permission(self, action, user, repo_name, ip_addr=None): |
1761
b265be1c6093
Wrapped calls for git and hg middleware in extra block that clears db Session.
Marcin Kuzminski <marcin@python-works.com>
parents:
1749
diff
changeset
|
175 """ |
b265be1c6093
Wrapped calls for git and hg middleware in extra block that clears db Session.
Marcin Kuzminski <marcin@python-works.com>
parents:
1749
diff
changeset
|
176 Checks permissions using action (push/pull) user and repository |
b265be1c6093
Wrapped calls for git and hg middleware in extra block that clears db Session.
Marcin Kuzminski <marcin@python-works.com>
parents:
1749
diff
changeset
|
177 name |
b265be1c6093
Wrapped calls for git and hg middleware in extra block that clears db Session.
Marcin Kuzminski <marcin@python-works.com>
parents:
1749
diff
changeset
|
178 |
b265be1c6093
Wrapped calls for git and hg middleware in extra block that clears db Session.
Marcin Kuzminski <marcin@python-works.com>
parents:
1749
diff
changeset
|
179 :param action: push or pull action |
b265be1c6093
Wrapped calls for git and hg middleware in extra block that clears db Session.
Marcin Kuzminski <marcin@python-works.com>
parents:
1749
diff
changeset
|
180 :param user: user instance |
b265be1c6093
Wrapped calls for git and hg middleware in extra block that clears db Session.
Marcin Kuzminski <marcin@python-works.com>
parents:
1749
diff
changeset
|
181 :param repo_name: repository name |
b265be1c6093
Wrapped calls for git and hg middleware in extra block that clears db Session.
Marcin Kuzminski <marcin@python-works.com>
parents:
1749
diff
changeset
|
182 """ |
4116
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4089
diff
changeset
|
183 # check IP |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4089
diff
changeset
|
184 inherit = user.inherit_default_permissions |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4089
diff
changeset
|
185 ip_allowed = AuthUser.check_ip_allowed(user.user_id, ip_addr, |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4089
diff
changeset
|
186 inherit_from_default=inherit) |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4089
diff
changeset
|
187 if ip_allowed: |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4089
diff
changeset
|
188 log.info('Access for IP:%s allowed' % (ip_addr,)) |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4089
diff
changeset
|
189 else: |
3125
9b92cf5a0cca
Added UserIpMap interface for allowed IP addresses and IP restriction access
Marcin Kuzminski <marcin@python-works.com>
parents:
3087
diff
changeset
|
190 return False |
4116
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4089
diff
changeset
|
191 |
1761
b265be1c6093
Wrapped calls for git and hg middleware in extra block that clears db Session.
Marcin Kuzminski <marcin@python-works.com>
parents:
1749
diff
changeset
|
192 if action == 'push': |
b265be1c6093
Wrapped calls for git and hg middleware in extra block that clears db Session.
Marcin Kuzminski <marcin@python-works.com>
parents:
1749
diff
changeset
|
193 if not HasPermissionAnyMiddleware('repository.write', |
b265be1c6093
Wrapped calls for git and hg middleware in extra block that clears db Session.
Marcin Kuzminski <marcin@python-works.com>
parents:
1749
diff
changeset
|
194 'repository.admin')(user, |
b265be1c6093
Wrapped calls for git and hg middleware in extra block that clears db Session.
Marcin Kuzminski <marcin@python-works.com>
parents:
1749
diff
changeset
|
195 repo_name): |
b265be1c6093
Wrapped calls for git and hg middleware in extra block that clears db Session.
Marcin Kuzminski <marcin@python-works.com>
parents:
1749
diff
changeset
|
196 return False |
b265be1c6093
Wrapped calls for git and hg middleware in extra block that clears db Session.
Marcin Kuzminski <marcin@python-works.com>
parents:
1749
diff
changeset
|
197 |
b265be1c6093
Wrapped calls for git and hg middleware in extra block that clears db Session.
Marcin Kuzminski <marcin@python-works.com>
parents:
1749
diff
changeset
|
198 else: |
b265be1c6093
Wrapped calls for git and hg middleware in extra block that clears db Session.
Marcin Kuzminski <marcin@python-works.com>
parents:
1749
diff
changeset
|
199 #any other action need at least read permission |
b265be1c6093
Wrapped calls for git and hg middleware in extra block that clears db Session.
Marcin Kuzminski <marcin@python-works.com>
parents:
1749
diff
changeset
|
200 if not HasPermissionAnyMiddleware('repository.read', |
b265be1c6093
Wrapped calls for git and hg middleware in extra block that clears db Session.
Marcin Kuzminski <marcin@python-works.com>
parents:
1749
diff
changeset
|
201 'repository.write', |
b265be1c6093
Wrapped calls for git and hg middleware in extra block that clears db Session.
Marcin Kuzminski <marcin@python-works.com>
parents:
1749
diff
changeset
|
202 'repository.admin')(user, |
b265be1c6093
Wrapped calls for git and hg middleware in extra block that clears db Session.
Marcin Kuzminski <marcin@python-works.com>
parents:
1749
diff
changeset
|
203 repo_name): |
b265be1c6093
Wrapped calls for git and hg middleware in extra block that clears db Session.
Marcin Kuzminski <marcin@python-works.com>
parents:
1749
diff
changeset
|
204 return False |
b265be1c6093
Wrapped calls for git and hg middleware in extra block that clears db Session.
Marcin Kuzminski <marcin@python-works.com>
parents:
1749
diff
changeset
|
205 |
1813
a8c66e870bd0
implements #285: Implemented non changeable urls for clone url, and web views
Marcin Kuzminski <marcin@python-works.com>
parents:
1763
diff
changeset
|
206 return True |
a8c66e870bd0
implements #285: Implemented non changeable urls for clone url, and web views
Marcin Kuzminski <marcin@python-works.com>
parents:
1763
diff
changeset
|
207 |
2184
79e4d6b9c1f0
Added HTTP_X_FORWARDED_FOR as another method of extracting IP for pull/push logs.
Marcin Kuzminski <marcin@python-works.com>
parents:
2132
diff
changeset
|
208 def _get_ip_addr(self, environ): |
2374
be2163ef127e
Add ip reference into BaseController
Marcin Kuzminski <marcin@python-works.com>
parents:
2184
diff
changeset
|
209 return _get_ip_addr(environ) |
2184
79e4d6b9c1f0
Added HTTP_X_FORWARDED_FOR as another method of extracting IP for pull/push logs.
Marcin Kuzminski <marcin@python-works.com>
parents:
2132
diff
changeset
|
210 |
2668
f0851f37d6be
Implementes #509 require SSL flag now works for both git and mercurial.
Marcin Kuzminski <marcin@python-works.com>
parents:
2490
diff
changeset
|
211 def _check_ssl(self, environ, start_response): |
f0851f37d6be
Implementes #509 require SSL flag now works for both git and mercurial.
Marcin Kuzminski <marcin@python-works.com>
parents:
2490
diff
changeset
|
212 """ |
f0851f37d6be
Implementes #509 require SSL flag now works for both git and mercurial.
Marcin Kuzminski <marcin@python-works.com>
parents:
2490
diff
changeset
|
213 Checks the SSL check flag and returns False if SSL is not present |
f0851f37d6be
Implementes #509 require SSL flag now works for both git and mercurial.
Marcin Kuzminski <marcin@python-works.com>
parents:
2490
diff
changeset
|
214 and required True otherwise |
f0851f37d6be
Implementes #509 require SSL flag now works for both git and mercurial.
Marcin Kuzminski <marcin@python-works.com>
parents:
2490
diff
changeset
|
215 """ |
f0851f37d6be
Implementes #509 require SSL flag now works for both git and mercurial.
Marcin Kuzminski <marcin@python-works.com>
parents:
2490
diff
changeset
|
216 org_proto = environ['wsgi._org_proto'] |
f0851f37d6be
Implementes #509 require SSL flag now works for both git and mercurial.
Marcin Kuzminski <marcin@python-works.com>
parents:
2490
diff
changeset
|
217 #check if we have SSL required ! if not it's a bad request ! |
2708
9bce679a3f49
Added form for controlling mercurial extensions
Marcin Kuzminski <marcin@python-works.com>
parents:
2674
diff
changeset
|
218 require_ssl = str2bool(RhodeCodeUi.get_by_key('push_ssl').ui_value) |
2668
f0851f37d6be
Implementes #509 require SSL flag now works for both git and mercurial.
Marcin Kuzminski <marcin@python-works.com>
parents:
2490
diff
changeset
|
219 if require_ssl and org_proto == 'http': |
f0851f37d6be
Implementes #509 require SSL flag now works for both git and mercurial.
Marcin Kuzminski <marcin@python-works.com>
parents:
2490
diff
changeset
|
220 log.debug('proto is %s and SSL is required BAD REQUEST !' |
f0851f37d6be
Implementes #509 require SSL flag now works for both git and mercurial.
Marcin Kuzminski <marcin@python-works.com>
parents:
2490
diff
changeset
|
221 % org_proto) |
f0851f37d6be
Implementes #509 require SSL flag now works for both git and mercurial.
Marcin Kuzminski <marcin@python-works.com>
parents:
2490
diff
changeset
|
222 return False |
2674
a221706dab50
merged + fixed pull request #62: Implemented metatags and visualisation options.
Marcin Kuzminski <marcin@python-works.com>
parents:
2668
diff
changeset
|
223 return True |
2668
f0851f37d6be
Implementes #509 require SSL flag now works for both git and mercurial.
Marcin Kuzminski <marcin@python-works.com>
parents:
2490
diff
changeset
|
224 |
2726
aa17c7a1b8a5
Implemented basic locking functionality.
Marcin Kuzminski <marcin@python-works.com>
parents:
2708
diff
changeset
|
225 def _check_locking_state(self, environ, action, repo, user_id): |
aa17c7a1b8a5
Implemented basic locking functionality.
Marcin Kuzminski <marcin@python-works.com>
parents:
2708
diff
changeset
|
226 """ |
aa17c7a1b8a5
Implemented basic locking functionality.
Marcin Kuzminski <marcin@python-works.com>
parents:
2708
diff
changeset
|
227 Checks locking on this repository, if locking is enabled and lock is |
aa17c7a1b8a5
Implemented basic locking functionality.
Marcin Kuzminski <marcin@python-works.com>
parents:
2708
diff
changeset
|
228 present returns a tuple of make_lock, locked, locked_by. |
aa17c7a1b8a5
Implemented basic locking functionality.
Marcin Kuzminski <marcin@python-works.com>
parents:
2708
diff
changeset
|
229 make_lock can have 3 states None (do nothing) True, make lock |
aa17c7a1b8a5
Implemented basic locking functionality.
Marcin Kuzminski <marcin@python-works.com>
parents:
2708
diff
changeset
|
230 False release lock, This value is later propagated to hooks, which |
aa17c7a1b8a5
Implemented basic locking functionality.
Marcin Kuzminski <marcin@python-works.com>
parents:
2708
diff
changeset
|
231 do the locking. Think about this as signals passed to hooks what to do. |
aa17c7a1b8a5
Implemented basic locking functionality.
Marcin Kuzminski <marcin@python-works.com>
parents:
2708
diff
changeset
|
232 |
aa17c7a1b8a5
Implemented basic locking functionality.
Marcin Kuzminski <marcin@python-works.com>
parents:
2708
diff
changeset
|
233 """ |
2752
6d904a0cd48d
added new suite of tests for VCS operations
Marcin Kuzminski <marcin@python-works.com>
parents:
2726
diff
changeset
|
234 locked = False # defines that locked error should be thrown to user |
2726
aa17c7a1b8a5
Implemented basic locking functionality.
Marcin Kuzminski <marcin@python-works.com>
parents:
2708
diff
changeset
|
235 make_lock = None |
aa17c7a1b8a5
Implemented basic locking functionality.
Marcin Kuzminski <marcin@python-works.com>
parents:
2708
diff
changeset
|
236 repo = Repository.get_by_repo_name(repo) |
aa17c7a1b8a5
Implemented basic locking functionality.
Marcin Kuzminski <marcin@python-works.com>
parents:
2708
diff
changeset
|
237 user = User.get(user_id) |
aa17c7a1b8a5
Implemented basic locking functionality.
Marcin Kuzminski <marcin@python-works.com>
parents:
2708
diff
changeset
|
238 |
aa17c7a1b8a5
Implemented basic locking functionality.
Marcin Kuzminski <marcin@python-works.com>
parents:
2708
diff
changeset
|
239 # this is kind of hacky, but due to how mercurial handles client-server |
aa17c7a1b8a5
Implemented basic locking functionality.
Marcin Kuzminski <marcin@python-works.com>
parents:
2708
diff
changeset
|
240 # server see all operation on changeset; bookmarks, phases and |
aa17c7a1b8a5
Implemented basic locking functionality.
Marcin Kuzminski <marcin@python-works.com>
parents:
2708
diff
changeset
|
241 # obsolescence marker in different transaction, we don't want to check |
aa17c7a1b8a5
Implemented basic locking functionality.
Marcin Kuzminski <marcin@python-works.com>
parents:
2708
diff
changeset
|
242 # locking on those |
aa17c7a1b8a5
Implemented basic locking functionality.
Marcin Kuzminski <marcin@python-works.com>
parents:
2708
diff
changeset
|
243 obsolete_call = environ['QUERY_STRING'] in ['cmd=listkeys',] |
aa17c7a1b8a5
Implemented basic locking functionality.
Marcin Kuzminski <marcin@python-works.com>
parents:
2708
diff
changeset
|
244 locked_by = repo.locked |
aa17c7a1b8a5
Implemented basic locking functionality.
Marcin Kuzminski <marcin@python-works.com>
parents:
2708
diff
changeset
|
245 if repo and repo.enable_locking and not obsolete_call: |
aa17c7a1b8a5
Implemented basic locking functionality.
Marcin Kuzminski <marcin@python-works.com>
parents:
2708
diff
changeset
|
246 if action == 'push': |
aa17c7a1b8a5
Implemented basic locking functionality.
Marcin Kuzminski <marcin@python-works.com>
parents:
2708
diff
changeset
|
247 #check if it's already locked !, if it is compare users |
aa17c7a1b8a5
Implemented basic locking functionality.
Marcin Kuzminski <marcin@python-works.com>
parents:
2708
diff
changeset
|
248 user_id, _date = repo.locked |
aa17c7a1b8a5
Implemented basic locking functionality.
Marcin Kuzminski <marcin@python-works.com>
parents:
2708
diff
changeset
|
249 if user.user_id == user_id: |
2752
6d904a0cd48d
added new suite of tests for VCS operations
Marcin Kuzminski <marcin@python-works.com>
parents:
2726
diff
changeset
|
250 log.debug('Got push from user %s, now unlocking' % (user)) |
2726
aa17c7a1b8a5
Implemented basic locking functionality.
Marcin Kuzminski <marcin@python-works.com>
parents:
2708
diff
changeset
|
251 # unlock if we have push from user who locked |
aa17c7a1b8a5
Implemented basic locking functionality.
Marcin Kuzminski <marcin@python-works.com>
parents:
2708
diff
changeset
|
252 make_lock = False |
aa17c7a1b8a5
Implemented basic locking functionality.
Marcin Kuzminski <marcin@python-works.com>
parents:
2708
diff
changeset
|
253 else: |
aa17c7a1b8a5
Implemented basic locking functionality.
Marcin Kuzminski <marcin@python-works.com>
parents:
2708
diff
changeset
|
254 # we're not the same user who locked, ban with 423 ! |
aa17c7a1b8a5
Implemented basic locking functionality.
Marcin Kuzminski <marcin@python-works.com>
parents:
2708
diff
changeset
|
255 locked = True |
aa17c7a1b8a5
Implemented basic locking functionality.
Marcin Kuzminski <marcin@python-works.com>
parents:
2708
diff
changeset
|
256 if action == 'pull': |
aa17c7a1b8a5
Implemented basic locking functionality.
Marcin Kuzminski <marcin@python-works.com>
parents:
2708
diff
changeset
|
257 if repo.locked[0] and repo.locked[1]: |
aa17c7a1b8a5
Implemented basic locking functionality.
Marcin Kuzminski <marcin@python-works.com>
parents:
2708
diff
changeset
|
258 locked = True |
aa17c7a1b8a5
Implemented basic locking functionality.
Marcin Kuzminski <marcin@python-works.com>
parents:
2708
diff
changeset
|
259 else: |
aa17c7a1b8a5
Implemented basic locking functionality.
Marcin Kuzminski <marcin@python-works.com>
parents:
2708
diff
changeset
|
260 log.debug('Setting lock on repo %s by %s' % (repo, user)) |
aa17c7a1b8a5
Implemented basic locking functionality.
Marcin Kuzminski <marcin@python-works.com>
parents:
2708
diff
changeset
|
261 make_lock = True |
aa17c7a1b8a5
Implemented basic locking functionality.
Marcin Kuzminski <marcin@python-works.com>
parents:
2708
diff
changeset
|
262 |
aa17c7a1b8a5
Implemented basic locking functionality.
Marcin Kuzminski <marcin@python-works.com>
parents:
2708
diff
changeset
|
263 else: |
aa17c7a1b8a5
Implemented basic locking functionality.
Marcin Kuzminski <marcin@python-works.com>
parents:
2708
diff
changeset
|
264 log.debug('Repository %s do not have locking enabled' % (repo)) |
2752
6d904a0cd48d
added new suite of tests for VCS operations
Marcin Kuzminski <marcin@python-works.com>
parents:
2726
diff
changeset
|
265 log.debug('FINAL locking values make_lock:%s,locked:%s,locked_by:%s' |
6d904a0cd48d
added new suite of tests for VCS operations
Marcin Kuzminski <marcin@python-works.com>
parents:
2726
diff
changeset
|
266 % (make_lock, locked, locked_by)) |
2726
aa17c7a1b8a5
Implemented basic locking functionality.
Marcin Kuzminski <marcin@python-works.com>
parents:
2708
diff
changeset
|
267 return make_lock, locked, locked_by |
aa17c7a1b8a5
Implemented basic locking functionality.
Marcin Kuzminski <marcin@python-works.com>
parents:
2708
diff
changeset
|
268 |
1761
b265be1c6093
Wrapped calls for git and hg middleware in extra block that clears db Session.
Marcin Kuzminski <marcin@python-works.com>
parents:
1749
diff
changeset
|
269 def __call__(self, environ, start_response): |
b265be1c6093
Wrapped calls for git and hg middleware in extra block that clears db Session.
Marcin Kuzminski <marcin@python-works.com>
parents:
1749
diff
changeset
|
270 start = time.time() |
b265be1c6093
Wrapped calls for git and hg middleware in extra block that clears db Session.
Marcin Kuzminski <marcin@python-works.com>
parents:
1749
diff
changeset
|
271 try: |
b265be1c6093
Wrapped calls for git and hg middleware in extra block that clears db Session.
Marcin Kuzminski <marcin@python-works.com>
parents:
1749
diff
changeset
|
272 return self._handle_request(environ, start_response) |
b265be1c6093
Wrapped calls for git and hg middleware in extra block that clears db Session.
Marcin Kuzminski <marcin@python-works.com>
parents:
1749
diff
changeset
|
273 finally: |
1763
d09c52be40e0
logger name update
Marcin Kuzminski <marcin@python-works.com>
parents:
1761
diff
changeset
|
274 log = logging.getLogger('rhodecode.' + self.__class__.__name__) |
1761
b265be1c6093
Wrapped calls for git and hg middleware in extra block that clears db Session.
Marcin Kuzminski <marcin@python-works.com>
parents:
1749
diff
changeset
|
275 log.debug('Request time: %.3fs' % (time.time() - start)) |
b265be1c6093
Wrapped calls for git and hg middleware in extra block that clears db Session.
Marcin Kuzminski <marcin@python-works.com>
parents:
1749
diff
changeset
|
276 meta.Session.remove() |
b265be1c6093
Wrapped calls for git and hg middleware in extra block that clears db Session.
Marcin Kuzminski <marcin@python-works.com>
parents:
1749
diff
changeset
|
277 |
b265be1c6093
Wrapped calls for git and hg middleware in extra block that clears db Session.
Marcin Kuzminski <marcin@python-works.com>
parents:
1749
diff
changeset
|
278 |
0 | 279 class BaseController(WSGIController): |
659
758f64f3fbda
extended repo creation by repo type. fixed fork creation to maintain repo type.
Marcin Kuzminski <marcin@python-works.com>
parents:
629
diff
changeset
|
280 |
185
3380ca40cdba
added version generation to pylons_app and showed it into template. Propagated baseController with some data for acces into each controller. Fixed simplehg middleware to get proper name of application
Marcin Kuzminski <marcin@python-works.com>
parents:
169
diff
changeset
|
281 def __before__(self): |
3125
9b92cf5a0cca
Added UserIpMap interface for allowed IP addresses and IP restriction access
Marcin Kuzminski <marcin@python-works.com>
parents:
3087
diff
changeset
|
282 """ |
9b92cf5a0cca
Added UserIpMap interface for allowed IP addresses and IP restriction access
Marcin Kuzminski <marcin@python-works.com>
parents:
3087
diff
changeset
|
283 __before__ is called before controller methods and after __call__ |
9b92cf5a0cca
Added UserIpMap interface for allowed IP addresses and IP restriction access
Marcin Kuzminski <marcin@python-works.com>
parents:
3087
diff
changeset
|
284 """ |
548
b75b77ef649d
renamed hg_app to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
547
diff
changeset
|
285 c.rhodecode_version = __version__ |
4116
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4089
diff
changeset
|
286 rc_config = RhodeCodeSetting.get_app_settings() |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4089
diff
changeset
|
287 |
2674
a221706dab50
merged + fixed pull request #62: Implemented metatags and visualisation options.
Marcin Kuzminski <marcin@python-works.com>
parents:
2668
diff
changeset
|
288 # Visual options |
a221706dab50
merged + fixed pull request #62: Implemented metatags and visualisation options.
Marcin Kuzminski <marcin@python-works.com>
parents:
2668
diff
changeset
|
289 c.visual = AttributeDict({}) |
4116
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4089
diff
changeset
|
290 |
3904
fe053a42c4ce
added dashboard items config in visual settings
Marcin Kuzminski <marcin@python-works.com>
parents:
3752
diff
changeset
|
291 ## DB stored |
2955
9c85d884315b
don't use config for visual settings. It totally doesn't work on multi instance mode
Marcin Kuzminski <marcin@python-works.com>
parents:
2952
diff
changeset
|
292 c.visual.show_public_icon = str2bool(rc_config.get('rhodecode_show_public_icon')) |
9c85d884315b
don't use config for visual settings. It totally doesn't work on multi instance mode
Marcin Kuzminski <marcin@python-works.com>
parents:
2952
diff
changeset
|
293 c.visual.show_private_icon = str2bool(rc_config.get('rhodecode_show_private_icon')) |
9c85d884315b
don't use config for visual settings. It totally doesn't work on multi instance mode
Marcin Kuzminski <marcin@python-works.com>
parents:
2952
diff
changeset
|
294 c.visual.stylify_metatags = str2bool(rc_config.get('rhodecode_stylify_metatags')) |
3904
fe053a42c4ce
added dashboard items config in visual settings
Marcin Kuzminski <marcin@python-works.com>
parents:
3752
diff
changeset
|
295 c.visual.dashboard_items = safe_int(rc_config.get('rhodecode_dashboard_items', 100)) |
4116
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4089
diff
changeset
|
296 c.visual.admin_grid_items = safe_int(rc_config.get('rhodecode_admin_grid_items', 100)) |
3308
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3168
diff
changeset
|
297 c.visual.repository_fields = str2bool(rc_config.get('rhodecode_repository_fields')) |
3910
36f7562a5919
Implements #842 RhodeCode version disclosure.
Marcin Kuzminski <marcin@python-works.com>
parents:
3904
diff
changeset
|
298 c.visual.show_version = str2bool(rc_config.get('rhodecode_show_version')) |
4116
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4089
diff
changeset
|
299 c.visual.use_gravatar = str2bool(rc_config.get('rhodecode_use_gravatar')) |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4089
diff
changeset
|
300 c.visual.gravatar_url = rc_config.get('rhodecode_gravatar_url') |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4089
diff
changeset
|
301 |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4089
diff
changeset
|
302 c.ga_code = rc_config.get('rhodecode_ga_code') |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4089
diff
changeset
|
303 c.rhodecode_name = rc_config.get('rhodecode_title') |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4089
diff
changeset
|
304 c.clone_uri_tmpl = rc_config.get('rhodecode_clone_uri_tmpl') |
3910
36f7562a5919
Implements #842 RhodeCode version disclosure.
Marcin Kuzminski <marcin@python-works.com>
parents:
3904
diff
changeset
|
305 |
3904
fe053a42c4ce
added dashboard items config in visual settings
Marcin Kuzminski <marcin@python-works.com>
parents:
3752
diff
changeset
|
306 ## INI stored |
3920
985db7f7b9b2
Added flag to controll option for changing the repos path location
Marcin Kuzminski <marcin@python-works.com>
parents:
3910
diff
changeset
|
307 c.visual.allow_repo_location_change = str2bool(config.get('allow_repo_location_change', True)) |
4045
9b4ba12ef8c3
Add ini option to controll custom advanced hooks settings
Marcin Kuzminski <marcin@python-works.com>
parents:
4006
diff
changeset
|
308 c.visual.allow_custom_hooks_settings = str2bool(config.get('allow_custom_hooks_settings', True)) |
3904
fe053a42c4ce
added dashboard items config in visual settings
Marcin Kuzminski <marcin@python-works.com>
parents:
3752
diff
changeset
|
309 |
4116
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4089
diff
changeset
|
310 c.rhodecode_instanceid = config.get('instance_id') |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4089
diff
changeset
|
311 c.rhodecode_bugtracker = config.get('bugtracker', url('rc_issue_tracker')) |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4089
diff
changeset
|
312 # END CONFIG VARS |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4089
diff
changeset
|
313 |
3580
7b9d4f6bb04e
show only open pull requests in the counter, and use repo context bar in pull requests view
Marcin Kuzminski <marcin@python-works.com>
parents:
3552
diff
changeset
|
314 c.repo_name = get_repo_slug(request) # can be empty |
659
758f64f3fbda
extended repo creation by repo type. fixed fork creation to maintain repo type.
Marcin Kuzminski <marcin@python-works.com>
parents:
629
diff
changeset
|
315 c.backends = BACKENDS.keys() |
1702
8cb7f5c4d494
#302 - basic notification system, models+tests
Marcin Kuzminski <marcin@python-works.com>
parents:
1630
diff
changeset
|
316 c.unread_notifications = NotificationModel()\ |
8cb7f5c4d494
#302 - basic notification system, models+tests
Marcin Kuzminski <marcin@python-works.com>
parents:
1630
diff
changeset
|
317 .get_unread_cnt_for_user(c.rhodecode_user.user_id) |
4116
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4089
diff
changeset
|
318 |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4089
diff
changeset
|
319 self.cut_off_limit = safe_int(config.get('cut_off_limit')) |
1749
8ecc6b8229a5
commit less models
Marcin Kuzminski <marcin@python-works.com>
parents:
1728
diff
changeset
|
320 self.sa = meta.Session |
1045
3fc9183e05dd
another major codes rewrite:
Marcin Kuzminski <marcin@python-works.com>
parents:
1038
diff
changeset
|
321 self.scm_model = ScmModel(self.sa) |
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:
1351
diff
changeset
|
322 |
0 | 323 def __call__(self, environ, start_response): |
324 """Invoke the Controller""" | |
325 # WSGIController.__call__ dispatches to the Controller method | |
326 # the request is routed to. This routing information is | |
327 # available in environ['pylons.routes_dict'] | |
328 try: | |
2374
be2163ef127e
Add ip reference into BaseController
Marcin Kuzminski <marcin@python-works.com>
parents:
2184
diff
changeset
|
329 self.ip_addr = _get_ip_addr(environ) |
1628
de71a4bde097
Some code cleanups and fixes
Marcin Kuzminski <marcin@python-works.com>
parents:
1622
diff
changeset
|
330 # make sure that we update permissions each time we call controller |
1117
6eb5bb24a948
Major rewrite of auth objects. Moved parts of filling user data into user model.
Marcin Kuzminski <marcin@python-works.com>
parents:
1045
diff
changeset
|
331 api_key = request.GET.get('api_key') |
4074
3b136af34329
Added pre-create user hook.
Marcin Kuzminski <marcin@python-works.com>
parents:
4045
diff
changeset
|
332 |
4116
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4089
diff
changeset
|
333 if api_key: |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4089
diff
changeset
|
334 # when using API_KEY we are sure user exists. |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4089
diff
changeset
|
335 auth_user = AuthUser(api_key=api_key, ip_addr=self.ip_addr) |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4089
diff
changeset
|
336 authenticated = False |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4089
diff
changeset
|
337 else: |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4089
diff
changeset
|
338 cookie_store = CookieStoreWrapper(session.get('rhodecode_user')) |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4089
diff
changeset
|
339 try: |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4089
diff
changeset
|
340 auth_user = AuthUser(user_id=cookie_store.get('user_id', None), |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4089
diff
changeset
|
341 ip_addr=self.ip_addr) |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4089
diff
changeset
|
342 except UserCreationError, e: |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4089
diff
changeset
|
343 from rhodecode.lib import helpers as h |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4089
diff
changeset
|
344 h.flash(e, 'error') |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4089
diff
changeset
|
345 # container auth or other auth functions that create users on |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4089
diff
changeset
|
346 # the fly can throw this exception signaling that there's issue |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4089
diff
changeset
|
347 # with user creation, explanation should be provided in |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4089
diff
changeset
|
348 # Exception itself |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4089
diff
changeset
|
349 auth_user = AuthUser(ip_addr=self.ip_addr) |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4089
diff
changeset
|
350 |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4089
diff
changeset
|
351 authenticated = cookie_store.get('is_authenticated') |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4089
diff
changeset
|
352 |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4089
diff
changeset
|
353 if not auth_user.is_authenticated and auth_user.user_id is not None: |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4089
diff
changeset
|
354 # user is not authenticated and not empty |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4089
diff
changeset
|
355 auth_user.set_authenticated(authenticated) |
1728
07e56179633e
- fixes celery sqlalchemy session issues for async forking
Marcin Kuzminski <marcin@python-works.com>
parents:
1718
diff
changeset
|
356 request.user = auth_user |
4116
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4089
diff
changeset
|
357 #set globals for auth user |
1628
de71a4bde097
Some code cleanups and fixes
Marcin Kuzminski <marcin@python-works.com>
parents:
1622
diff
changeset
|
358 self.rhodecode_user = c.rhodecode_user = auth_user |
2486
6f537e3da9c4
add IP into base logging, and change a little IP extraction login, if some header is passed as empty
Marcin Kuzminski <marcin@python-works.com>
parents:
2478
diff
changeset
|
359 log.info('IP: %s User: %s accessed %s' % ( |
2490
7a5eeafb1a9a
better path extraction method.
Marcin Kuzminski <marcin@python-works.com>
parents:
2486
diff
changeset
|
360 self.ip_addr, auth_user, safe_unicode(_get_access_path(environ))) |
2027
88d5e42a66c3
fixed logging issue on non-ascii repos
Marcin Kuzminski <marcin@python-works.com>
parents:
2025
diff
changeset
|
361 ) |
0 | 362 return WSGIController.__call__(self, environ, start_response) |
363 finally: | |
51 | 364 meta.Session.remove() |
1045
3fc9183e05dd
another major codes rewrite:
Marcin Kuzminski <marcin@python-works.com>
parents:
1038
diff
changeset
|
365 |
3fc9183e05dd
another major codes rewrite:
Marcin Kuzminski <marcin@python-works.com>
parents:
1038
diff
changeset
|
366 |
3fc9183e05dd
another major codes rewrite:
Marcin Kuzminski <marcin@python-works.com>
parents:
1038
diff
changeset
|
367 class BaseRepoController(BaseController): |
3fc9183e05dd
another major codes rewrite:
Marcin Kuzminski <marcin@python-works.com>
parents:
1038
diff
changeset
|
368 """ |
1628
de71a4bde097
Some code cleanups and fixes
Marcin Kuzminski <marcin@python-works.com>
parents:
1622
diff
changeset
|
369 Base class for controllers responsible for loading all needed data for |
de71a4bde097
Some code cleanups and fixes
Marcin Kuzminski <marcin@python-works.com>
parents:
1622
diff
changeset
|
370 repository loaded items are |
1203
6832ef664673
source code cleanup: remove trailing white space, normalize file endings
Marcin Kuzminski <marcin@python-works.com>
parents:
1117
diff
changeset
|
371 |
1628
de71a4bde097
Some code cleanups and fixes
Marcin Kuzminski <marcin@python-works.com>
parents:
1622
diff
changeset
|
372 c.rhodecode_repo: instance of scm repository |
de71a4bde097
Some code cleanups and fixes
Marcin Kuzminski <marcin@python-works.com>
parents:
1622
diff
changeset
|
373 c.rhodecode_db_repo: instance of db |
de71a4bde097
Some code cleanups and fixes
Marcin Kuzminski <marcin@python-works.com>
parents:
1622
diff
changeset
|
374 c.repository_followers: number of followers |
de71a4bde097
Some code cleanups and fixes
Marcin Kuzminski <marcin@python-works.com>
parents:
1622
diff
changeset
|
375 c.repository_forks: number of forks |
3527
87c97fcea029
Adding the context bar too all pages related to a Repository.
Leonardo <leo@unity3d.com>
parents:
3308
diff
changeset
|
376 c.repository_following: weather the current user is following the current repo |
1045
3fc9183e05dd
another major codes rewrite:
Marcin Kuzminski <marcin@python-works.com>
parents:
1038
diff
changeset
|
377 """ |
3fc9183e05dd
another major codes rewrite:
Marcin Kuzminski <marcin@python-works.com>
parents:
1038
diff
changeset
|
378 |
3fc9183e05dd
another major codes rewrite:
Marcin Kuzminski <marcin@python-works.com>
parents:
1038
diff
changeset
|
379 def __before__(self): |
3fc9183e05dd
another major codes rewrite:
Marcin Kuzminski <marcin@python-works.com>
parents:
1038
diff
changeset
|
380 super(BaseRepoController, self).__before__() |
4116
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4089
diff
changeset
|
381 if c.repo_name: # extracted from routes |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4089
diff
changeset
|
382 _dbr = Repository.get_by_repo_name(c.repo_name) |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4089
diff
changeset
|
383 if not _dbr: |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4089
diff
changeset
|
384 return |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4089
diff
changeset
|
385 |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4089
diff
changeset
|
386 log.debug('Found repository in database %s with state `%s`' |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4089
diff
changeset
|
387 % (safe_unicode(_dbr), safe_unicode(_dbr.repo_state))) |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4089
diff
changeset
|
388 route = getattr(request.environ.get('routes.route'), 'name', '') |
1045
3fc9183e05dd
another major codes rewrite:
Marcin Kuzminski <marcin@python-works.com>
parents:
1038
diff
changeset
|
389 |
4116
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4089
diff
changeset
|
390 # allow to delete repos that are somehow damages in filesystem |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4089
diff
changeset
|
391 if route in ['delete_repo']: |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4089
diff
changeset
|
392 return |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4089
diff
changeset
|
393 |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4089
diff
changeset
|
394 if _dbr.repo_state in [Repository.STATE_PENDING]: |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4089
diff
changeset
|
395 if route in ['repo_creating_home']: |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4089
diff
changeset
|
396 return |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4089
diff
changeset
|
397 check_url = url('repo_creating_home', repo_name=c.repo_name) |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4089
diff
changeset
|
398 return redirect(check_url) |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4089
diff
changeset
|
399 |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4089
diff
changeset
|
400 dbr = c.rhodecode_db_repo = _dbr |
1373
66f03a87141c
Fixes issue #201
Marcin Kuzminski <marcin@python-works.com>
parents:
1366
diff
changeset
|
401 c.rhodecode_repo = c.rhodecode_db_repo.scm_instance |
66f03a87141c
Fixes issue #201
Marcin Kuzminski <marcin@python-works.com>
parents:
1366
diff
changeset
|
402 if c.rhodecode_repo is None: |
66f03a87141c
Fixes issue #201
Marcin Kuzminski <marcin@python-works.com>
parents:
1366
diff
changeset
|
403 log.error('%s this repository is present in database but it ' |
66f03a87141c
Fixes issue #201
Marcin Kuzminski <marcin@python-works.com>
parents:
1366
diff
changeset
|
404 'cannot be created as an scm instance', c.repo_name) |
1282
faaadfc3c359
fixed condition evaluated for gitrepo that returned null, simplified scm functions
Marcin Kuzminski <marcin@python-works.com>
parents:
1203
diff
changeset
|
405 |
1373
66f03a87141c
Fixes issue #201
Marcin Kuzminski <marcin@python-works.com>
parents:
1366
diff
changeset
|
406 redirect(url('home')) |
1304
5a96551ee9c0
gui-improvments
Marcin Kuzminski <marcin@python-works.com>
parents:
1282
diff
changeset
|
407 |
4116
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4089
diff
changeset
|
408 # update last change according to VCS data |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4089
diff
changeset
|
409 dbr.update_changeset_cache(dbr.get_changeset()) |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4089
diff
changeset
|
410 |
2440
1bc579bcd67a
- pull request generates overview based on it's params
Marcin Kuzminski <marcin@python-works.com>
parents:
2374
diff
changeset
|
411 # some globals counter for menu |
1bc579bcd67a
- pull request generates overview based on it's params
Marcin Kuzminski <marcin@python-works.com>
parents:
2374
diff
changeset
|
412 c.repository_followers = self.scm_model.get_followers(dbr) |
1bc579bcd67a
- pull request generates overview based on it's params
Marcin Kuzminski <marcin@python-works.com>
parents:
2374
diff
changeset
|
413 c.repository_forks = self.scm_model.get_forks(dbr) |
2478
8eab81115660
white space cleanup
Marcin Kuzminski <marcin@python-works.com>
parents:
2440
diff
changeset
|
414 c.repository_pull_requests = self.scm_model.get_pull_requests(dbr) |
4116
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4089
diff
changeset
|
415 c.repository_following = self.scm_model.is_following_repo( |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4089
diff
changeset
|
416 c.repo_name, self.rhodecode_user.user_id) |