##// END OF EJS Templates
events: cleanup code, pep8, better logging.
marcink -
r2920:c35ca856 default
parent child Browse files
Show More
@@ -32,6 +32,7 b' def trigger_user_permission_flush(event)'
32 automatic flush of permission caches, so the users affected receive new permissions
32 automatic flush of permission caches, so the users affected receive new permissions
33 Right Away
33 Right Away
34 """
34 """
35
35 affected_user_ids = set(event.user_ids)
36 affected_user_ids = set(event.user_ids)
36 for user_id in affected_user_ids:
37 for user_id in affected_user_ids:
37 cache_namespace_uid = 'cache_user_auth.{}'.format(user_id)
38 cache_namespace_uid = 'cache_user_auth.{}'.format(user_id)
@@ -34,7 +34,7 b' def trigger(event, registry=None):'
34 # passing the registry as an argument to get rid of it.
34 # passing the registry as an argument to get rid of it.
35 registry = registry or get_current_registry()
35 registry = registry or get_current_registry()
36 registry.notify(event)
36 registry.notify(event)
37 log.debug('event %s triggered using registry %s', event, registry)
37 log.debug('event %s triggered using registry %s', event.__class__, registry)
38
38
39 # Until we can work around the problem that VCS operations do not have a
39 # Until we can work around the problem that VCS operations do not have a
40 # pyramid context to work with, we send the events to integrations directly
40 # pyramid context to work with, we send the events to integrations directly
@@ -33,7 +33,7 b' from rhodecode import events'
33 from rhodecode.integrations.types.base import EEIntegration
33 from rhodecode.integrations.types.base import EEIntegration
34 from rhodecode.lib.caching_query import FromCache
34 from rhodecode.lib.caching_query import FromCache
35 from rhodecode.model import BaseModel
35 from rhodecode.model import BaseModel
36 from rhodecode.model.db import Integration, Repository, RepoGroup
36 from rhodecode.model.db import Integration, Repository, RepoGroup, true, false
37 from rhodecode.integrations import integration_type_registry
37 from rhodecode.integrations import integration_type_registry
38
38
39 log = logging.getLogger(__name__)
39 log = logging.getLogger(__name__)
@@ -119,20 +119,20 b' class IntegrationModel(BaseModel):'
119
119
120 if isinstance(scope, Repository):
120 if isinstance(scope, Repository):
121 query = self.sa.query(Integration).filter(
121 query = self.sa.query(Integration).filter(
122 Integration.repo==scope)
122 Integration.repo == scope)
123 elif isinstance(scope, RepoGroup):
123 elif isinstance(scope, RepoGroup):
124 query = self.sa.query(Integration).filter(
124 query = self.sa.query(Integration).filter(
125 Integration.repo_group==scope)
125 Integration.repo_group == scope)
126 elif scope == 'global':
126 elif scope == 'global':
127 # global integrations
127 # global integrations
128 query = self.sa.query(Integration).filter(
128 query = self.sa.query(Integration).filter(
129 and_(Integration.repo_id==None, Integration.repo_group_id==None)
129 and_(Integration.repo_id == None, Integration.repo_group_id == None)
130 )
130 )
131 elif scope == 'root-repos':
131 elif scope == 'root-repos':
132 query = self.sa.query(Integration).filter(
132 query = self.sa.query(Integration).filter(
133 and_(Integration.repo_id==None,
133 and_(Integration.repo_id == None,
134 Integration.repo_group_id==None,
134 Integration.repo_group_id == None,
135 Integration.child_repos_only==True)
135 Integration.child_repos_only == true())
136 )
136 )
137 elif scope == 'all':
137 elif scope == 'all':
138 query = self.sa.query(Integration)
138 query = self.sa.query(Integration)
@@ -158,20 +158,20 b' class IntegrationModel(BaseModel):'
158 query = self.sa.query(
158 query = self.sa.query(
159 Integration
159 Integration
160 ).filter(
160 ).filter(
161 Integration.enabled==True
161 Integration.enabled == true()
162 )
162 )
163
163
164 global_integrations_filter = and_(
164 global_integrations_filter = and_(
165 Integration.repo_id==None,
165 Integration.repo_id == None,
166 Integration.repo_group_id==None,
166 Integration.repo_group_id == None,
167 Integration.child_repos_only==False,
167 Integration.child_repos_only == False,
168 )
168 )
169
169
170 if isinstance(event, events.RepoEvent):
170 if isinstance(event, events.RepoEvent):
171 root_repos_integrations_filter = and_(
171 root_repos_integrations_filter = and_(
172 Integration.repo_id==None,
172 Integration.repo_id == None,
173 Integration.repo_group_id==None,
173 Integration.repo_group_id == None,
174 Integration.child_repos_only==True,
174 Integration.child_repos_only == true(),
175 )
175 )
176
176
177 clauses = [
177 clauses = [
@@ -179,16 +179,16 b' class IntegrationModel(BaseModel):'
179 ]
179 ]
180
180
181 # repo integrations
181 # repo integrations
182 if event.repo.repo_id: # pre create events dont have a repo_id yet
182 if event.repo.repo_id: # pre create events dont have a repo_id yet
183 clauses.append(
183 clauses.append(
184 Integration.repo_id==event.repo.repo_id
184 Integration.repo_id == event.repo.repo_id
185 )
185 )
186
186
187 if event.repo.group:
187 if event.repo.group:
188 clauses.append(
188 clauses.append(
189 and_(
189 and_(
190 Integration.repo_group_id==event.repo.group.group_id,
190 Integration.repo_group_id == event.repo.group.group_id,
191 Integration.child_repos_only==True
191 Integration.child_repos_only == true()
192 )
192 )
193 )
193 )
194 # repo group cascade to kids
194 # repo group cascade to kids
@@ -196,14 +196,13 b' class IntegrationModel(BaseModel):'
196 and_(
196 and_(
197 Integration.repo_group_id.in_(
197 Integration.repo_group_id.in_(
198 [group.group_id for group in
198 [group.group_id for group in
199 event.repo.groups_with_parents]
199 event.repo.groups_with_parents]
200 ),
200 ),
201 Integration.child_repos_only==False
201 Integration.child_repos_only == false()
202 )
202 )
203 )
203 )
204
204
205
205 if not event.repo.group: # root repo
206 if not event.repo.group: # root repo
207 clauses.append(root_repos_integrations_filter)
206 clauses.append(root_repos_integrations_filter)
208
207
209 query = query.filter(or_(*clauses))
208 query = query.filter(or_(*clauses))
@@ -212,11 +211,11 b' class IntegrationModel(BaseModel):'
212 cache_key = "get_enabled_repo_integrations_%i" % event.repo.repo_id
211 cache_key = "get_enabled_repo_integrations_%i" % event.repo.repo_id
213 query = query.options(
212 query = query.options(
214 FromCache("sql_cache_short", cache_key))
213 FromCache("sql_cache_short", cache_key))
215 else: # only global integrations
214 else: # only global integrations
216 query = query.filter(global_integrations_filter)
215 query = query.filter(global_integrations_filter)
217 if cache:
216 if cache:
218 query = query.options(
217 query = query.options(
219 FromCache("sql_cache_short", "get_enabled_global_integrations"))
218 FromCache("sql_cache_short", "get_enabled_global_integrations"))
220
219
221 result = query.all()
220 result = query.all()
222 return result No newline at end of file
221 return result
General Comments 0
You need to be logged in to leave comments. Login now