##// END OF EJS Templates
fix(events): fixed celery based events where it was missing request object
super-admin -
r5340:d43cbc34 default
parent child Browse files
Show More
@@ -15,13 +15,14 b''
15 15 # This program is dual-licensed. If you wish to learn more about the
16 16 # RhodeCode Enterprise Edition, including its added features, Support services,
17 17 # and proprietary license terms, please see https://rhodecode.com/licenses/
18
18 19 import logging
19 20 import datetime
20 import typing
21 21
22 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 26 from rhodecode.lib.utils2 import AttributeDict
26 27
27 28
@@ -41,8 +42,9 b' class RhodecodeEvent(object):'
41 42 name = "RhodeCodeEvent"
42 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 46 self._request = request
47 self._actor = actor
46 48 self.utc_timestamp = datetime.datetime.utcnow()
47 49
48 50 def __repr__(self):
@@ -72,16 +74,22 b' class RhodecodeEvent(object):'
72 74
73 75 @property
74 76 def actor(self):
77 # if an explicit actor is specified, use this
78 if self._actor:
79 return self._actor
80
75 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 84 instance = auth_user.get_instance()
85 # we can't find this DB user...
78 86 if not instance:
79 87 return AttributeDict(dict(
80 88 username=auth_user.username,
81 89 user_id=auth_user.user_id,
82 90 ))
83 return instance
84
91 elif auth_user:
92 return auth_user
85 93 return SYSTEM_USER
86 94
87 95 @property
@@ -129,3 +137,4 b' class FtsBuild(RhodecodeEvent):'
129 137 """
130 138 name = 'fts-build'
131 139 display_name = 'Start FTS Build'
140
@@ -156,11 +156,11 b' class RepoEvent(RhodeCodeIntegrationEven'
156 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 161 :param repo: a :class:`Repository` instance
162 162 """
163 super().__init__()
163 super().__init__(actor=actor)
164 164 self.repo = repo
165 165
166 166 def as_dict(self):
@@ -1688,7 +1688,7 b' def get_csrf_token(session, force_new=Fa'
1688 1688
1689 1689
1690 1690 def get_request(perm_class_instance):
1691 from pyramid.threadlocal import get_current_request
1691 from rhodecode.lib.pyramid_utils import get_current_request
1692 1692 pyramid_request = get_current_request()
1693 1693 return pyramid_request
1694 1694
@@ -193,6 +193,7 b' def create_repo(form_data, cur_user):'
193 193 enable_downloads=enable_downloads,
194 194 state=state
195 195 )
196
196 197 Session().commit()
197 198
198 199 # now create this repo on Filesystem
@@ -17,7 +17,6 b''
17 17 # and proprietary license terms, please see https://rhodecode.com/licenses/
18 18
19 19 import webob
20 from pyramid.threadlocal import get_current_request
21 20
22 21 from rhodecode import events
23 22 from rhodecode.lib import hooks_base
@@ -33,6 +32,7 b' def _supports_repo_type(repo_type):'
33 32 def _get_vcs_operation_context(username, repo_name, repo_type, action):
34 33 # NOTE(dan): import loop
35 34 from rhodecode.lib.base import vcs_operation_context
35 from rhodecode.lib.pyramid_utils import get_current_request
36 36
37 37 check_locking = action in ('pull', 'push')
38 38
@@ -23,6 +23,7 b' import configparser'
23 23
24 24 from rhodecode.lib.config_utils import get_config
25 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 29 def bootstrap(config_uri, options=None, env=None):
@@ -46,3 +47,11 b' def bootstrap(config_uri, options=None, '
46 47 'ip_addr': '127.0.0.1'})
47 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 608 # we need to flush here, in order to check if database won't
609 609 # throw any exceptions, create filesystem dirs at the very end
610 610 self.sa.flush()
611 events.trigger(events.RepoCreateEvent(new_repo))
611 events.trigger(events.RepoCreateEvent(new_repo, actor=owner))
612 612 return new_repo
613 613
614 614 except Exception:
General Comments 0
You need to be logged in to leave comments. Login now