Mercurial > kallithea
annotate rhodecode/lib/base.py @ 3264:565806c66c4d beta
Add new attr to pull request
author | Marcin Kuzminski <marcin@python-works.com> |
---|---|
date | Wed, 30 Jan 2013 00:33:28 +0100 |
parents | 2fb94c52e20e |
children | cd50d1b5f35b 72a91632b731 |
rev | line source |
---|---|
0 | 1 """The base Controller API |
2 | |
3 Provides the BaseController class for subclassing. | |
4 """ | |
1373
66f03a87141c
Fixes issue #201
Marcin Kuzminski <marcin@python-works.com>
parents:
1366
diff
changeset
|
5 import logging |
1601
6f06daeed294
Added Request time tracking
Marcin Kuzminski <marcin@python-works.com>
parents:
1530
diff
changeset
|
6 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
|
7 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
|
8 |
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
|
9 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
|
10 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
|
11 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
|
12 |
1373
66f03a87141c
Fixes issue #201
Marcin Kuzminski <marcin@python-works.com>
parents:
1366
diff
changeset
|
13 from pylons import config, tmpl_context as c, request, session, url |
0 | 14 from pylons.controllers import WSGIController |
1373
66f03a87141c
Fixes issue #201
Marcin Kuzminski <marcin@python-works.com>
parents:
1366
diff
changeset
|
15 from pylons.controllers.util import redirect |
0 | 16 from pylons.templating import render_mako as render |
1304
5a96551ee9c0
gui-improvments
Marcin Kuzminski <marcin@python-works.com>
parents:
1282
diff
changeset
|
17 |
1718
f78bee8eec78
reduce cookie size for better support of client side sessions
Marcin Kuzminski <marcin@python-works.com>
parents:
1702
diff
changeset
|
18 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
|
19 |
2726
aa17c7a1b8a5
Implemented basic locking functionality.
Marcin Kuzminski <marcin@python-works.com>
parents:
2708
diff
changeset
|
20 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
|
21 safe_str, safe_int |
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
|
22 from rhodecode.lib.auth import AuthUser, get_container_username, authfunc,\ |
3146
c5169e445fb8
Full IP restrictions enabled
Marcin Kuzminski <marcin@python-works.com>
parents:
3125
diff
changeset
|
23 HasPermissionAnyMiddleware, CookieStoreWrapper |
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
|
24 from rhodecode.lib.utils import get_repo_slug, invalidate_cache |
547
1e757ac98988
renamed project to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
537
diff
changeset
|
25 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
|
26 |
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
|
27 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
|
28 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
|
29 from rhodecode.model.scm import ScmModel |
2726
aa17c7a1b8a5
Implemented basic locking functionality.
Marcin Kuzminski <marcin@python-works.com>
parents:
2708
diff
changeset
|
30 from rhodecode.model.meta import Session |
665
070f32743632
Moved out reposcan into hg Model.
Marcin Kuzminski <marcin@python-works.com>
parents:
659
diff
changeset
|
31 |
1373
66f03a87141c
Fixes issue #201
Marcin Kuzminski <marcin@python-works.com>
parents:
1366
diff
changeset
|
32 log = logging.getLogger(__name__) |
1307 | 33 |
1813
a8c66e870bd0
implements #285: Implemented non changeable urls for clone url, and web views
Marcin Kuzminski <marcin@python-works.com>
parents:
1763
diff
changeset
|
34 |
2374
be2163ef127e
Add ip reference into BaseController
Marcin Kuzminski <marcin@python-works.com>
parents:
2184
diff
changeset
|
35 def _get_ip_addr(environ): |
be2163ef127e
Add ip reference into BaseController
Marcin Kuzminski <marcin@python-works.com>
parents:
2184
diff
changeset
|
36 proxy_key = 'HTTP_X_REAL_IP' |
be2163ef127e
Add ip reference into BaseController
Marcin Kuzminski <marcin@python-works.com>
parents:
2184
diff
changeset
|
37 proxy_key2 = 'HTTP_X_FORWARDED_FOR' |
be2163ef127e
Add ip reference into BaseController
Marcin Kuzminski <marcin@python-works.com>
parents:
2184
diff
changeset
|
38 def_key = 'REMOTE_ADDR' |
be2163ef127e
Add ip reference into BaseController
Marcin Kuzminski <marcin@python-works.com>
parents:
2184
diff
changeset
|
39 |
3153
8046d1979674
fix multiple ips addresses in X_FORWARDER_FOR header
Marcin Kuzminski <marcin@python-works.com>
parents:
3147
diff
changeset
|
40 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
|
41 if ip: |
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
|
42 return ip |
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
|
43 |
3153
8046d1979674
fix multiple ips addresses in X_FORWARDER_FOR header
Marcin Kuzminski <marcin@python-works.com>
parents:
3147
diff
changeset
|
44 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
|
45 if ip: |
3153
8046d1979674
fix multiple ips addresses in X_FORWARDER_FOR header
Marcin Kuzminski <marcin@python-works.com>
parents:
3147
diff
changeset
|
46 # HTTP_X_FORWARDED_FOR can have mutliple ips inside |
3168
2fb94c52e20e
whitespace cleanup
Marcin Kuzminski <marcin@python-works.com>
parents:
3153
diff
changeset
|
47 # the left-most being the original client, and each successive proxy |
2fb94c52e20e
whitespace cleanup
Marcin Kuzminski <marcin@python-works.com>
parents:
3153
diff
changeset
|
48 # that passed the request adding the IP address where it received the |
3153
8046d1979674
fix multiple ips addresses in X_FORWARDER_FOR header
Marcin Kuzminski <marcin@python-works.com>
parents:
3147
diff
changeset
|
49 # request from. |
8046d1979674
fix multiple ips addresses in X_FORWARDER_FOR header
Marcin Kuzminski <marcin@python-works.com>
parents:
3147
diff
changeset
|
50 if ',' in ip: |
8046d1979674
fix multiple ips addresses in X_FORWARDER_FOR header
Marcin Kuzminski <marcin@python-works.com>
parents:
3147
diff
changeset
|
51 ip = ip.split(',')[0].strip() |
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
|
52 return ip |
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
|
53 |
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
|
54 ip = environ.get(def_key, '0.0.0.0') |
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
|
55 return ip |
2374
be2163ef127e
Add ip reference into BaseController
Marcin Kuzminski <marcin@python-works.com>
parents:
2184
diff
changeset
|
56 |
be2163ef127e
Add ip reference into BaseController
Marcin Kuzminski <marcin@python-works.com>
parents:
2184
diff
changeset
|
57 |
2490
7a5eeafb1a9a
better path extraction method.
Marcin Kuzminski <marcin@python-works.com>
parents:
2486
diff
changeset
|
58 def _get_access_path(environ): |
7a5eeafb1a9a
better path extraction method.
Marcin Kuzminski <marcin@python-works.com>
parents:
2486
diff
changeset
|
59 path = environ.get('PATH_INFO') |
7a5eeafb1a9a
better path extraction method.
Marcin Kuzminski <marcin@python-works.com>
parents:
2486
diff
changeset
|
60 org_req = environ.get('pylons.original_request') |
7a5eeafb1a9a
better path extraction method.
Marcin Kuzminski <marcin@python-works.com>
parents:
2486
diff
changeset
|
61 if org_req: |
7a5eeafb1a9a
better path extraction method.
Marcin Kuzminski <marcin@python-works.com>
parents:
2486
diff
changeset
|
62 path = org_req.environ.get('PATH_INFO') |
7a5eeafb1a9a
better path extraction method.
Marcin Kuzminski <marcin@python-works.com>
parents:
2486
diff
changeset
|
63 return path |
7a5eeafb1a9a
better path extraction method.
Marcin Kuzminski <marcin@python-works.com>
parents:
2486
diff
changeset
|
64 |
7a5eeafb1a9a
better path extraction method.
Marcin Kuzminski <marcin@python-works.com>
parents:
2486
diff
changeset
|
65 |
2132
9f5582151d53
Alternative HTTP response codes when client failed to Authenticate correctly
Marcin Kuzminski <marcin@python-works.com>
parents:
2109
diff
changeset
|
66 class BasicAuth(AuthBasicAuthenticator): |
9f5582151d53
Alternative HTTP response codes when client failed to Authenticate correctly
Marcin Kuzminski <marcin@python-works.com>
parents:
2109
diff
changeset
|
67 |
9f5582151d53
Alternative HTTP response codes when client failed to Authenticate correctly
Marcin Kuzminski <marcin@python-works.com>
parents:
2109
diff
changeset
|
68 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
|
69 self.realm = realm |
9f5582151d53
Alternative HTTP response codes when client failed to Authenticate correctly
Marcin Kuzminski <marcin@python-works.com>
parents:
2109
diff
changeset
|
70 self.authfunc = authfunc |
9f5582151d53
Alternative HTTP response codes when client failed to Authenticate correctly
Marcin Kuzminski <marcin@python-works.com>
parents:
2109
diff
changeset
|
71 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
|
72 |
9f5582151d53
Alternative HTTP response codes when client failed to Authenticate correctly
Marcin Kuzminski <marcin@python-works.com>
parents:
2109
diff
changeset
|
73 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
|
74 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
|
75 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
|
76 # 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
|
77 # RhodeCode config |
9f5582151d53
Alternative HTTP response codes when client failed to Authenticate correctly
Marcin Kuzminski <marcin@python-works.com>
parents:
2109
diff
changeset
|
78 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
|
79 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
|
80 |
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
|
81 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
|
82 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
|
83 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
|
84 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
|
85 (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
|
86 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
|
87 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
|
88 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
|
89 _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
|
90 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
|
91 username, password = _parts |
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
|
92 if self.authfunc(environ, username, password): |
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
|
93 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
|
94 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
|
95 |
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
|
96 __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
|
97 |
2132
9f5582151d53
Alternative HTTP response codes when client failed to Authenticate correctly
Marcin Kuzminski <marcin@python-works.com>
parents:
2109
diff
changeset
|
98 |
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
|
99 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
|
100 |
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
|
101 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
|
102 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
|
103 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
|
104 # 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
|
105 self.basepath = self.config['base_path'] |
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
|
106 #authenticate this mercurial request using authfunc |
2132
9f5582151d53
Alternative HTTP response codes when client failed to Authenticate correctly
Marcin Kuzminski <marcin@python-works.com>
parents:
2109
diff
changeset
|
107 self.authenticate = BasicAuth('', authfunc, |
9f5582151d53
Alternative HTTP response codes when client failed to Authenticate correctly
Marcin Kuzminski <marcin@python-works.com>
parents:
2109
diff
changeset
|
108 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
|
109 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
|
110 |
1978
164199e476e9
code garden, pep8
Marcin Kuzminski <marcin@python-works.com>
parents:
1818
diff
changeset
|
111 def _handle_request(self, environ, start_response): |
164199e476e9
code garden, pep8
Marcin Kuzminski <marcin@python-works.com>
parents:
1818
diff
changeset
|
112 raise NotImplementedError() |
164199e476e9
code garden, pep8
Marcin Kuzminski <marcin@python-works.com>
parents:
1818
diff
changeset
|
113 |
1813
a8c66e870bd0
implements #285: Implemented non changeable urls for clone url, and web views
Marcin Kuzminski <marcin@python-works.com>
parents:
1763
diff
changeset
|
114 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
|
115 """ |
a8c66e870bd0
implements #285: Implemented non changeable urls for clone url, and web views
Marcin Kuzminski <marcin@python-works.com>
parents:
1763
diff
changeset
|
116 Get's a special pattern _<ID> from clone url and tries to replace it |
a8c66e870bd0
implements #285: Implemented non changeable urls for clone url, and web views
Marcin Kuzminski <marcin@python-works.com>
parents:
1763
diff
changeset
|
117 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
|
118 |
a8c66e870bd0
implements #285: Implemented non changeable urls for clone url, and web views
Marcin Kuzminski <marcin@python-works.com>
parents:
1763
diff
changeset
|
119 :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
|
120 """ |
a8c66e870bd0
implements #285: Implemented non changeable urls for clone url, and web views
Marcin Kuzminski <marcin@python-works.com>
parents:
1763
diff
changeset
|
121 try: |
a8c66e870bd0
implements #285: Implemented non changeable urls for clone url, and web views
Marcin Kuzminski <marcin@python-works.com>
parents:
1763
diff
changeset
|
122 data = repo_name.split('/') |
a8c66e870bd0
implements #285: Implemented non changeable urls for clone url, and web views
Marcin Kuzminski <marcin@python-works.com>
parents:
1763
diff
changeset
|
123 if len(data) >= 2: |
a8c66e870bd0
implements #285: Implemented non changeable urls for clone url, and web views
Marcin Kuzminski <marcin@python-works.com>
parents:
1763
diff
changeset
|
124 by_id = data[1].split('_') |
a8c66e870bd0
implements #285: Implemented non changeable urls for clone url, and web views
Marcin Kuzminski <marcin@python-works.com>
parents:
1763
diff
changeset
|
125 if len(by_id) == 2 and by_id[1].isdigit(): |
a8c66e870bd0
implements #285: Implemented non changeable urls for clone url, and web views
Marcin Kuzminski <marcin@python-works.com>
parents:
1763
diff
changeset
|
126 _repo_name = Repository.get(by_id[1]).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
|
127 data[1] = _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
|
128 except: |
a8c66e870bd0
implements #285: Implemented non changeable urls for clone url, and web views
Marcin Kuzminski <marcin@python-works.com>
parents:
1763
diff
changeset
|
129 log.debug('Failed to extract repo_name from id %s' % ( |
a8c66e870bd0
implements #285: Implemented non changeable urls for clone url, and web views
Marcin Kuzminski <marcin@python-works.com>
parents:
1763
diff
changeset
|
130 traceback.format_exc() |
a8c66e870bd0
implements #285: Implemented non changeable urls for clone url, and web views
Marcin Kuzminski <marcin@python-works.com>
parents:
1763
diff
changeset
|
131 ) |
a8c66e870bd0
implements #285: Implemented non changeable urls for clone url, and web views
Marcin Kuzminski <marcin@python-works.com>
parents:
1763
diff
changeset
|
132 ) |
a8c66e870bd0
implements #285: Implemented non changeable urls for clone url, and web views
Marcin Kuzminski <marcin@python-works.com>
parents:
1763
diff
changeset
|
133 |
a8c66e870bd0
implements #285: Implemented non changeable urls for clone url, and web views
Marcin Kuzminski <marcin@python-works.com>
parents:
1763
diff
changeset
|
134 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
|
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 _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
|
137 """ |
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 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
|
139 |
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
|
140 :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
|
141 """ |
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
|
142 invalidate_cache('get_repo_cached_%s' % 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
|
143 |
3125
9b92cf5a0cca
Added UserIpMap interface for allowed IP addresses and IP restriction access
Marcin Kuzminski <marcin@python-works.com>
parents:
3087
diff
changeset
|
144 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
|
145 """ |
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
|
146 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
|
147 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
|
148 |
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
|
149 :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
|
150 :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
|
151 :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
|
152 """ |
3125
9b92cf5a0cca
Added UserIpMap interface for allowed IP addresses and IP restriction access
Marcin Kuzminski <marcin@python-works.com>
parents:
3087
diff
changeset
|
153 #check IP |
3146
c5169e445fb8
Full IP restrictions enabled
Marcin Kuzminski <marcin@python-works.com>
parents:
3125
diff
changeset
|
154 authuser = AuthUser(user_id=user.user_id, ip_addr=ip_addr) |
c5169e445fb8
Full IP restrictions enabled
Marcin Kuzminski <marcin@python-works.com>
parents:
3125
diff
changeset
|
155 if not authuser.ip_allowed: |
3125
9b92cf5a0cca
Added UserIpMap interface for allowed IP addresses and IP restriction access
Marcin Kuzminski <marcin@python-works.com>
parents:
3087
diff
changeset
|
156 return False |
9b92cf5a0cca
Added UserIpMap interface for allowed IP addresses and IP restriction access
Marcin Kuzminski <marcin@python-works.com>
parents:
3087
diff
changeset
|
157 else: |
9b92cf5a0cca
Added UserIpMap interface for allowed IP addresses and IP restriction access
Marcin Kuzminski <marcin@python-works.com>
parents:
3087
diff
changeset
|
158 log.info('Access for IP:%s allowed' % (ip_addr)) |
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
|
159 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
|
160 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
|
161 '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
|
162 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
|
163 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
|
164 |
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
|
165 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
|
166 #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
|
167 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
|
168 '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
|
169 '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
|
170 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
|
171 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
|
172 |
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 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
|
174 |
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
|
175 def _get_ip_addr(self, environ): |
2374
be2163ef127e
Add ip reference into BaseController
Marcin Kuzminski <marcin@python-works.com>
parents:
2184
diff
changeset
|
176 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
|
177 |
2668
f0851f37d6be
Implementes #509 require SSL flag now works for both git and mercurial.
Marcin Kuzminski <marcin@python-works.com>
parents:
2490
diff
changeset
|
178 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
|
179 """ |
f0851f37d6be
Implementes #509 require SSL flag now works for both git and mercurial.
Marcin Kuzminski <marcin@python-works.com>
parents:
2490
diff
changeset
|
180 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
|
181 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
|
182 """ |
f0851f37d6be
Implementes #509 require SSL flag now works for both git and mercurial.
Marcin Kuzminski <marcin@python-works.com>
parents:
2490
diff
changeset
|
183 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
|
184 #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
|
185 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
|
186 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
|
187 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
|
188 % 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
|
189 return False |
2674
a221706dab50
merged + fixed pull request #62: Implemented metatags and visualisation options.
Marcin Kuzminski <marcin@python-works.com>
parents:
2668
diff
changeset
|
190 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
|
191 |
2726
aa17c7a1b8a5
Implemented basic locking functionality.
Marcin Kuzminski <marcin@python-works.com>
parents:
2708
diff
changeset
|
192 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
|
193 """ |
aa17c7a1b8a5
Implemented basic locking functionality.
Marcin Kuzminski <marcin@python-works.com>
parents:
2708
diff
changeset
|
194 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
|
195 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
|
196 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
|
197 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
|
198 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
|
199 |
aa17c7a1b8a5
Implemented basic locking functionality.
Marcin Kuzminski <marcin@python-works.com>
parents:
2708
diff
changeset
|
200 """ |
2752
6d904a0cd48d
added new suite of tests for VCS operations
Marcin Kuzminski <marcin@python-works.com>
parents:
2726
diff
changeset
|
201 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
|
202 make_lock = None |
aa17c7a1b8a5
Implemented basic locking functionality.
Marcin Kuzminski <marcin@python-works.com>
parents:
2708
diff
changeset
|
203 repo = Repository.get_by_repo_name(repo) |
aa17c7a1b8a5
Implemented basic locking functionality.
Marcin Kuzminski <marcin@python-works.com>
parents:
2708
diff
changeset
|
204 user = User.get(user_id) |
aa17c7a1b8a5
Implemented basic locking functionality.
Marcin Kuzminski <marcin@python-works.com>
parents:
2708
diff
changeset
|
205 |
aa17c7a1b8a5
Implemented basic locking functionality.
Marcin Kuzminski <marcin@python-works.com>
parents:
2708
diff
changeset
|
206 # 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
|
207 # server see all operation on changeset; bookmarks, phases and |
aa17c7a1b8a5
Implemented basic locking functionality.
Marcin Kuzminski <marcin@python-works.com>
parents:
2708
diff
changeset
|
208 # 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
|
209 # locking on those |
aa17c7a1b8a5
Implemented basic locking functionality.
Marcin Kuzminski <marcin@python-works.com>
parents:
2708
diff
changeset
|
210 obsolete_call = environ['QUERY_STRING'] in ['cmd=listkeys',] |
aa17c7a1b8a5
Implemented basic locking functionality.
Marcin Kuzminski <marcin@python-works.com>
parents:
2708
diff
changeset
|
211 locked_by = repo.locked |
aa17c7a1b8a5
Implemented basic locking functionality.
Marcin Kuzminski <marcin@python-works.com>
parents:
2708
diff
changeset
|
212 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
|
213 if action == 'push': |
aa17c7a1b8a5
Implemented basic locking functionality.
Marcin Kuzminski <marcin@python-works.com>
parents:
2708
diff
changeset
|
214 #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
|
215 user_id, _date = repo.locked |
aa17c7a1b8a5
Implemented basic locking functionality.
Marcin Kuzminski <marcin@python-works.com>
parents:
2708
diff
changeset
|
216 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
|
217 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
|
218 # unlock if we have push from user who locked |
aa17c7a1b8a5
Implemented basic locking functionality.
Marcin Kuzminski <marcin@python-works.com>
parents:
2708
diff
changeset
|
219 make_lock = False |
aa17c7a1b8a5
Implemented basic locking functionality.
Marcin Kuzminski <marcin@python-works.com>
parents:
2708
diff
changeset
|
220 else: |
aa17c7a1b8a5
Implemented basic locking functionality.
Marcin Kuzminski <marcin@python-works.com>
parents:
2708
diff
changeset
|
221 # 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
|
222 locked = True |
aa17c7a1b8a5
Implemented basic locking functionality.
Marcin Kuzminski <marcin@python-works.com>
parents:
2708
diff
changeset
|
223 if action == 'pull': |
aa17c7a1b8a5
Implemented basic locking functionality.
Marcin Kuzminski <marcin@python-works.com>
parents:
2708
diff
changeset
|
224 if repo.locked[0] and repo.locked[1]: |
aa17c7a1b8a5
Implemented basic locking functionality.
Marcin Kuzminski <marcin@python-works.com>
parents:
2708
diff
changeset
|
225 locked = True |
aa17c7a1b8a5
Implemented basic locking functionality.
Marcin Kuzminski <marcin@python-works.com>
parents:
2708
diff
changeset
|
226 else: |
aa17c7a1b8a5
Implemented basic locking functionality.
Marcin Kuzminski <marcin@python-works.com>
parents:
2708
diff
changeset
|
227 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
|
228 make_lock = True |
aa17c7a1b8a5
Implemented basic locking functionality.
Marcin Kuzminski <marcin@python-works.com>
parents:
2708
diff
changeset
|
229 |
aa17c7a1b8a5
Implemented basic locking functionality.
Marcin Kuzminski <marcin@python-works.com>
parents:
2708
diff
changeset
|
230 else: |
aa17c7a1b8a5
Implemented basic locking functionality.
Marcin Kuzminski <marcin@python-works.com>
parents:
2708
diff
changeset
|
231 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
|
232 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
|
233 % (make_lock, locked, locked_by)) |
2726
aa17c7a1b8a5
Implemented basic locking functionality.
Marcin Kuzminski <marcin@python-works.com>
parents:
2708
diff
changeset
|
234 return make_lock, locked, locked_by |
aa17c7a1b8a5
Implemented basic locking functionality.
Marcin Kuzminski <marcin@python-works.com>
parents:
2708
diff
changeset
|
235 |
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
|
236 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
|
237 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
|
238 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
|
239 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
|
240 finally: |
1763
d09c52be40e0
logger name update
Marcin Kuzminski <marcin@python-works.com>
parents:
1761
diff
changeset
|
241 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
|
242 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
|
243 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
|
244 |
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
|
245 |
0 | 246 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
|
247 |
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
|
248 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
|
249 """ |
9b92cf5a0cca
Added UserIpMap interface for allowed IP addresses and IP restriction access
Marcin Kuzminski <marcin@python-works.com>
parents:
3087
diff
changeset
|
250 __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
|
251 """ |
548
b75b77ef649d
renamed hg_app to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
547
diff
changeset
|
252 c.rhodecode_version = __version__ |
2016
6020e3884a58
implements #212 moved default encoding variable into rhodecode-config. It's now possible to change
Marcin Kuzminski <marcin@python-works.com>
parents:
1978
diff
changeset
|
253 c.rhodecode_instanceid = config.get('instance_id') |
890
042d38683d42
implemented #89 google analytics code
Marcin Kuzminski <marcin@python-works.com>
parents:
812
diff
changeset
|
254 c.rhodecode_name = config.get('rhodecode_title') |
1629
2196aa27954b
implements #293 gravatar link should be disabled when use_gravatar = false
Marcin Kuzminski <marcin@python-works.com>
parents:
1628
diff
changeset
|
255 c.use_gravatar = str2bool(config.get('use_gravatar')) |
891
cca7286401b3
fixes for #89 ga code
Marcin Kuzminski <marcin@python-works.com>
parents:
890
diff
changeset
|
256 c.ga_code = config.get('rhodecode_ga_code') |
2674
a221706dab50
merged + fixed pull request #62: Implemented metatags and visualisation options.
Marcin Kuzminski <marcin@python-works.com>
parents:
2668
diff
changeset
|
257 # Visual options |
a221706dab50
merged + fixed pull request #62: Implemented metatags and visualisation options.
Marcin Kuzminski <marcin@python-works.com>
parents:
2668
diff
changeset
|
258 c.visual = AttributeDict({}) |
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
|
259 rc_config = RhodeCodeSetting.get_app_settings() |
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
|
260 |
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
|
261 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
|
262 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
|
263 c.visual.stylify_metatags = str2bool(rc_config.get('rhodecode_stylify_metatags')) |
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
|
264 c.visual.lightweight_dashboard = str2bool(rc_config.get('rhodecode_lightweight_dashboard')) |
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
|
265 c.visual.lightweight_dashboard_items = safe_int(config.get('dashboard_items', 100)) |
2674
a221706dab50
merged + fixed pull request #62: Implemented metatags and visualisation options.
Marcin Kuzminski <marcin@python-works.com>
parents:
2668
diff
changeset
|
266 |
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
|
267 c.repo_name = get_repo_slug(request) |
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
|
268 c.backends = BACKENDS.keys() |
1702
8cb7f5c4d494
#302 - basic notification system, models+tests
Marcin Kuzminski <marcin@python-works.com>
parents:
1630
diff
changeset
|
269 c.unread_notifications = NotificationModel()\ |
8cb7f5c4d494
#302 - basic notification system, models+tests
Marcin Kuzminski <marcin@python-works.com>
parents:
1630
diff
changeset
|
270 .get_unread_cnt_for_user(c.rhodecode_user.user_id) |
890
042d38683d42
implemented #89 google analytics code
Marcin Kuzminski <marcin@python-works.com>
parents:
812
diff
changeset
|
271 self.cut_off_limit = int(config.get('cut_off_limit')) |
1036
405b80e4ccd5
Major refactoring, removed when possible calls to app globals.
Marcin Kuzminski <marcin@python-works.com>
parents:
891
diff
changeset
|
272 |
1749
8ecc6b8229a5
commit less models
Marcin Kuzminski <marcin@python-works.com>
parents:
1728
diff
changeset
|
273 self.sa = meta.Session |
1045
3fc9183e05dd
another major codes rewrite:
Marcin Kuzminski <marcin@python-works.com>
parents:
1038
diff
changeset
|
274 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
|
275 |
0 | 276 def __call__(self, environ, start_response): |
277 """Invoke the Controller""" | |
278 # WSGIController.__call__ dispatches to the Controller method | |
279 # the request is routed to. This routing information is | |
280 # available in environ['pylons.routes_dict'] | |
1601
6f06daeed294
Added Request time tracking
Marcin Kuzminski <marcin@python-works.com>
parents:
1530
diff
changeset
|
281 start = time.time() |
0 | 282 try: |
2374
be2163ef127e
Add ip reference into BaseController
Marcin Kuzminski <marcin@python-works.com>
parents:
2184
diff
changeset
|
283 self.ip_addr = _get_ip_addr(environ) |
1628
de71a4bde097
Some code cleanups and fixes
Marcin Kuzminski <marcin@python-works.com>
parents:
1622
diff
changeset
|
284 # 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
|
285 api_key = request.GET.get('api_key') |
2030
61f9aeb2129e
Added session wrapper, for rc 1.2.X compatibility. Adds backwards compatability
Marcin Kuzminski <marcin@python-works.com>
parents:
2027
diff
changeset
|
286 cookie_store = CookieStoreWrapper(session.get('rhodecode_user')) |
1718
f78bee8eec78
reduce cookie size for better support of client side sessions
Marcin Kuzminski <marcin@python-works.com>
parents:
1702
diff
changeset
|
287 user_id = cookie_store.get('user_id', None) |
1630
25d8e4836bc2
Improved container-based auth support for middleware
Liad Shani <liadff@gmail.com>
parents:
1629
diff
changeset
|
288 username = get_container_username(environ, config) |
3125
9b92cf5a0cca
Added UserIpMap interface for allowed IP addresses and IP restriction access
Marcin Kuzminski <marcin@python-works.com>
parents:
3087
diff
changeset
|
289 auth_user = AuthUser(user_id, api_key, username, self.ip_addr) |
1728
07e56179633e
- fixes celery sqlalchemy session issues for async forking
Marcin Kuzminski <marcin@python-works.com>
parents:
1718
diff
changeset
|
290 request.user = auth_user |
1628
de71a4bde097
Some code cleanups and fixes
Marcin Kuzminski <marcin@python-works.com>
parents:
1622
diff
changeset
|
291 self.rhodecode_user = c.rhodecode_user = auth_user |
1618
9353189b7675
Added automatic logout of deactivated/deleted users
Liad Shani <liadff@gmail.com>
parents:
1617
diff
changeset
|
292 if not self.rhodecode_user.is_authenticated and \ |
9353189b7675
Added automatic logout of deactivated/deleted users
Liad Shani <liadff@gmail.com>
parents:
1617
diff
changeset
|
293 self.rhodecode_user.user_id is not None: |
2030
61f9aeb2129e
Added session wrapper, for rc 1.2.X compatibility. Adds backwards compatability
Marcin Kuzminski <marcin@python-works.com>
parents:
2027
diff
changeset
|
294 self.rhodecode_user.set_authenticated( |
61f9aeb2129e
Added session wrapper, for rc 1.2.X compatibility. Adds backwards compatability
Marcin Kuzminski <marcin@python-works.com>
parents:
2027
diff
changeset
|
295 cookie_store.get('is_authenticated') |
61f9aeb2129e
Added session wrapper, for rc 1.2.X compatibility. Adds backwards compatability
Marcin Kuzminski <marcin@python-works.com>
parents:
2027
diff
changeset
|
296 ) |
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
|
297 log.info('IP: %s User: %s accessed %s' % ( |
2490
7a5eeafb1a9a
better path extraction method.
Marcin Kuzminski <marcin@python-works.com>
parents:
2486
diff
changeset
|
298 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
|
299 ) |
0 | 300 return WSGIController.__call__(self, environ, start_response) |
301 finally: | |
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
|
302 log.info('IP: %s Request to %s time: %.3fs' % ( |
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
|
303 _get_ip_addr(environ), |
2490
7a5eeafb1a9a
better path extraction method.
Marcin Kuzminski <marcin@python-works.com>
parents:
2486
diff
changeset
|
304 safe_unicode(_get_access_path(environ)), time.time() - start) |
2027
88d5e42a66c3
fixed logging issue on non-ascii repos
Marcin Kuzminski <marcin@python-works.com>
parents:
2025
diff
changeset
|
305 ) |
51 | 306 meta.Session.remove() |
1045
3fc9183e05dd
another major codes rewrite:
Marcin Kuzminski <marcin@python-works.com>
parents:
1038
diff
changeset
|
307 |
3fc9183e05dd
another major codes rewrite:
Marcin Kuzminski <marcin@python-works.com>
parents:
1038
diff
changeset
|
308 |
3fc9183e05dd
another major codes rewrite:
Marcin Kuzminski <marcin@python-works.com>
parents:
1038
diff
changeset
|
309 class BaseRepoController(BaseController): |
3fc9183e05dd
another major codes rewrite:
Marcin Kuzminski <marcin@python-works.com>
parents:
1038
diff
changeset
|
310 """ |
1628
de71a4bde097
Some code cleanups and fixes
Marcin Kuzminski <marcin@python-works.com>
parents:
1622
diff
changeset
|
311 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
|
312 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
|
313 |
1628
de71a4bde097
Some code cleanups and fixes
Marcin Kuzminski <marcin@python-works.com>
parents:
1622
diff
changeset
|
314 c.rhodecode_repo: instance of scm repository |
de71a4bde097
Some code cleanups and fixes
Marcin Kuzminski <marcin@python-works.com>
parents:
1622
diff
changeset
|
315 c.rhodecode_db_repo: instance of db |
de71a4bde097
Some code cleanups and fixes
Marcin Kuzminski <marcin@python-works.com>
parents:
1622
diff
changeset
|
316 c.repository_followers: number of followers |
de71a4bde097
Some code cleanups and fixes
Marcin Kuzminski <marcin@python-works.com>
parents:
1622
diff
changeset
|
317 c.repository_forks: number of forks |
1045
3fc9183e05dd
another major codes rewrite:
Marcin Kuzminski <marcin@python-works.com>
parents:
1038
diff
changeset
|
318 """ |
3fc9183e05dd
another major codes rewrite:
Marcin Kuzminski <marcin@python-works.com>
parents:
1038
diff
changeset
|
319 |
3fc9183e05dd
another major codes rewrite:
Marcin Kuzminski <marcin@python-works.com>
parents:
1038
diff
changeset
|
320 def __before__(self): |
3fc9183e05dd
another major codes rewrite:
Marcin Kuzminski <marcin@python-works.com>
parents:
1038
diff
changeset
|
321 super(BaseRepoController, self).__before__() |
3fc9183e05dd
another major codes rewrite:
Marcin Kuzminski <marcin@python-works.com>
parents:
1038
diff
changeset
|
322 if c.repo_name: |
3fc9183e05dd
another major codes rewrite:
Marcin Kuzminski <marcin@python-works.com>
parents:
1038
diff
changeset
|
323 |
2440
1bc579bcd67a
- pull request generates overview based on it's params
Marcin Kuzminski <marcin@python-works.com>
parents:
2374
diff
changeset
|
324 dbr = c.rhodecode_db_repo = Repository.get_by_repo_name(c.repo_name) |
1373
66f03a87141c
Fixes issue #201
Marcin Kuzminski <marcin@python-works.com>
parents:
1366
diff
changeset
|
325 c.rhodecode_repo = c.rhodecode_db_repo.scm_instance |
2937
d439d408b415
Update last_change from VCS data on request.
Marcin Kuzminski <marcin@python-works.com>
parents:
2936
diff
changeset
|
326 # update last change according to VCS data |
3147
8182ebed2922
Added full last changeset info to lightweight dashboard
Marcin Kuzminski <marcin@python-works.com>
parents:
3146
diff
changeset
|
327 dbr.update_changeset_cache(dbr.get_changeset()) |
1373
66f03a87141c
Fixes issue #201
Marcin Kuzminski <marcin@python-works.com>
parents:
1366
diff
changeset
|
328 if c.rhodecode_repo is None: |
66f03a87141c
Fixes issue #201
Marcin Kuzminski <marcin@python-works.com>
parents:
1366
diff
changeset
|
329 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
|
330 '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
|
331 |
1373
66f03a87141c
Fixes issue #201
Marcin Kuzminski <marcin@python-works.com>
parents:
1366
diff
changeset
|
332 redirect(url('home')) |
1304
5a96551ee9c0
gui-improvments
Marcin Kuzminski <marcin@python-works.com>
parents:
1282
diff
changeset
|
333 |
2440
1bc579bcd67a
- pull request generates overview based on it's params
Marcin Kuzminski <marcin@python-works.com>
parents:
2374
diff
changeset
|
334 # 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
|
335 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
|
336 c.repository_forks = self.scm_model.get_forks(dbr) |
2478
8eab81115660
white space cleanup
Marcin Kuzminski <marcin@python-works.com>
parents:
2440
diff
changeset
|
337 c.repository_pull_requests = self.scm_model.get_pull_requests(dbr) |