Show More
@@ -15,13 +15,14 b'' | |||||
15 | # This program is dual-licensed. If you wish to learn more about the |
|
15 | # This program is dual-licensed. If you wish to learn more about the | |
16 | # RhodeCode Enterprise Edition, including its added features, Support services, |
|
16 | # RhodeCode Enterprise Edition, including its added features, Support services, | |
17 | # and proprietary license terms, please see https://rhodecode.com/licenses/ |
|
17 | # and proprietary license terms, please see https://rhodecode.com/licenses/ | |
|
18 | ||||
18 | import logging |
|
19 | import logging | |
19 | import datetime |
|
20 | import datetime | |
20 | import typing |
|
|||
21 |
|
21 | |||
22 | from zope.cachedescriptors.property import Lazy as LazyProperty |
|
22 | from zope.cachedescriptors.property import Lazy as LazyProperty | |
23 | from pyramid.threadlocal import get_current_request |
|
|||
24 |
|
23 | |||
|
24 | from rhodecode.lib.pyramid_utils import get_current_request | |||
|
25 | from rhodecode.lib.auth import AuthUser | |||
25 | from rhodecode.lib.utils2 import AttributeDict |
|
26 | from rhodecode.lib.utils2 import AttributeDict | |
26 |
|
27 | |||
27 |
|
28 | |||
@@ -41,8 +42,9 b' class RhodecodeEvent(object):' | |||||
41 | name = "RhodeCodeEvent" |
|
42 | name = "RhodeCodeEvent" | |
42 | no_url_set = '<no server_url available>' |
|
43 | no_url_set = '<no server_url available>' | |
43 |
|
44 | |||
44 | def __init__(self, request=None): |
|
45 | def __init__(self, request=None, actor=None): | |
45 | self._request = request |
|
46 | self._request = request | |
|
47 | self._actor = actor | |||
46 | self.utc_timestamp = datetime.datetime.utcnow() |
|
48 | self.utc_timestamp = datetime.datetime.utcnow() | |
47 |
|
49 | |||
48 | def __repr__(self): |
|
50 | def __repr__(self): | |
@@ -72,16 +74,22 b' class RhodecodeEvent(object):' | |||||
72 |
|
74 | |||
73 | @property |
|
75 | @property | |
74 | def actor(self): |
|
76 | def actor(self): | |
|
77 | # if an explicit actor is specified, use this | |||
|
78 | if self._actor: | |||
|
79 | return self._actor | |||
|
80 | ||||
75 | auth_user = self.auth_user |
|
81 | auth_user = self.auth_user | |
76 | if auth_user: |
|
82 | log.debug('Got integration actor: %s', auth_user) | |
|
83 | if isinstance(auth_user, AuthUser): | |||
77 | instance = auth_user.get_instance() |
|
84 | instance = auth_user.get_instance() | |
|
85 | # we can't find this DB user... | |||
78 | if not instance: |
|
86 | if not instance: | |
79 | return AttributeDict(dict( |
|
87 | return AttributeDict(dict( | |
80 | username=auth_user.username, |
|
88 | username=auth_user.username, | |
81 | user_id=auth_user.user_id, |
|
89 | user_id=auth_user.user_id, | |
82 | )) |
|
90 | )) | |
83 | return instance |
|
91 | elif auth_user: | |
84 |
|
92 | return auth_user | ||
85 | return SYSTEM_USER |
|
93 | return SYSTEM_USER | |
86 |
|
94 | |||
87 | @property |
|
95 | @property | |
@@ -129,3 +137,4 b' class FtsBuild(RhodecodeEvent):' | |||||
129 | """ |
|
137 | """ | |
130 | name = 'fts-build' |
|
138 | name = 'fts-build' | |
131 | display_name = 'Start FTS Build' |
|
139 | display_name = 'Start FTS Build' | |
|
140 |
@@ -156,11 +156,11 b' class RepoEvent(RhodeCodeIntegrationEven' | |||||
156 | Base class for events acting on a repository. |
|
156 | Base class for events acting on a repository. | |
157 | """ |
|
157 | """ | |
158 |
|
158 | |||
159 | def __init__(self, repo): |
|
159 | def __init__(self, repo, actor=None): | |
160 | """ |
|
160 | """ | |
161 | :param repo: a :class:`Repository` instance |
|
161 | :param repo: a :class:`Repository` instance | |
162 | """ |
|
162 | """ | |
163 | super().__init__() |
|
163 | super().__init__(actor=actor) | |
164 | self.repo = repo |
|
164 | self.repo = repo | |
165 |
|
165 | |||
166 | def as_dict(self): |
|
166 | def as_dict(self): |
@@ -1688,7 +1688,7 b' def get_csrf_token(session, force_new=Fa' | |||||
1688 |
|
1688 | |||
1689 |
|
1689 | |||
1690 | def get_request(perm_class_instance): |
|
1690 | def get_request(perm_class_instance): | |
1691 |
from |
|
1691 | from rhodecode.lib.pyramid_utils import get_current_request | |
1692 | pyramid_request = get_current_request() |
|
1692 | pyramid_request = get_current_request() | |
1693 | return pyramid_request |
|
1693 | return pyramid_request | |
1694 |
|
1694 |
@@ -193,6 +193,7 b' def create_repo(form_data, cur_user):' | |||||
193 | enable_downloads=enable_downloads, |
|
193 | enable_downloads=enable_downloads, | |
194 | state=state |
|
194 | state=state | |
195 | ) |
|
195 | ) | |
|
196 | ||||
196 | Session().commit() |
|
197 | Session().commit() | |
197 |
|
198 | |||
198 | # now create this repo on Filesystem |
|
199 | # now create this repo on Filesystem |
@@ -17,7 +17,6 b'' | |||||
17 | # and proprietary license terms, please see https://rhodecode.com/licenses/ |
|
17 | # and proprietary license terms, please see https://rhodecode.com/licenses/ | |
18 |
|
18 | |||
19 | import webob |
|
19 | import webob | |
20 | from pyramid.threadlocal import get_current_request |
|
|||
21 |
|
20 | |||
22 | from rhodecode import events |
|
21 | from rhodecode import events | |
23 | from rhodecode.lib import hooks_base |
|
22 | from rhodecode.lib import hooks_base | |
@@ -33,6 +32,7 b' def _supports_repo_type(repo_type):' | |||||
33 | def _get_vcs_operation_context(username, repo_name, repo_type, action): |
|
32 | def _get_vcs_operation_context(username, repo_name, repo_type, action): | |
34 | # NOTE(dan): import loop |
|
33 | # NOTE(dan): import loop | |
35 | from rhodecode.lib.base import vcs_operation_context |
|
34 | from rhodecode.lib.base import vcs_operation_context | |
|
35 | from rhodecode.lib.pyramid_utils import get_current_request | |||
36 |
|
36 | |||
37 | check_locking = action in ('pull', 'push') |
|
37 | check_locking = action in ('pull', 'push') | |
38 |
|
38 |
@@ -23,6 +23,7 b' import configparser' | |||||
23 |
|
23 | |||
24 | from rhodecode.lib.config_utils import get_config |
|
24 | from rhodecode.lib.config_utils import get_config | |
25 | from pyramid.paster import bootstrap as pyramid_bootstrap, setup_logging # pragma: no cover |
|
25 | from pyramid.paster import bootstrap as pyramid_bootstrap, setup_logging # pragma: no cover | |
|
26 | from pyramid.threadlocal import get_current_request as pyramid_current_request | |||
26 |
|
27 | |||
27 |
|
28 | |||
28 | def bootstrap(config_uri, options=None, env=None): |
|
29 | def bootstrap(config_uri, options=None, env=None): | |
@@ -46,3 +47,11 b' def bootstrap(config_uri, options=None, ' | |||||
46 | 'ip_addr': '127.0.0.1'}) |
|
47 | 'ip_addr': '127.0.0.1'}) | |
47 | return pyramid_bootstrap(config_uri, request=request, options=options) |
|
48 | return pyramid_bootstrap(config_uri, request=request, options=options) | |
48 |
|
49 | |||
|
50 | ||||
|
51 | def get_current_request(): | |||
|
52 | pyramid_req = pyramid_current_request() | |||
|
53 | if not pyramid_req: | |||
|
54 | # maybe we're in celery context and need to get the PYRAMID_REQUEST | |||
|
55 | from rhodecode.lib.celerylib.loader import celery_app | |||
|
56 | pyramid_req = celery_app.conf['PYRAMID_REQUEST'] | |||
|
57 | return pyramid_req |
@@ -608,7 +608,7 b' class RepoModel(BaseModel):' | |||||
608 | # we need to flush here, in order to check if database won't |
|
608 | # we need to flush here, in order to check if database won't | |
609 | # throw any exceptions, create filesystem dirs at the very end |
|
609 | # throw any exceptions, create filesystem dirs at the very end | |
610 | self.sa.flush() |
|
610 | self.sa.flush() | |
611 | events.trigger(events.RepoCreateEvent(new_repo)) |
|
611 | events.trigger(events.RepoCreateEvent(new_repo, actor=owner)) | |
612 | return new_repo |
|
612 | return new_repo | |
613 |
|
613 | |||
614 | except Exception: |
|
614 | except Exception: |
General Comments 0
You need to be logged in to leave comments.
Login now