def event_create(values): new_event = api_base.entity_create(models.TimeLineEvent, values) if new_event: if new_event.story_id is not None: stories_api.story_update_updated_at(new_event.story_id) # TODO(SotK): Update board and worklist updated_at when they get events if CONF.enable_notifications: # Build the payload. Use of None is included to ensure that we don't # accidentally blow up the API call, but we don't anticipate it # happening. event_dict = tojson(TimeLineEvent, TimeLineEvent.from_db_model(new_event)) publish(author_id=request.current_user_id or None, method="POST", url=request.headers.get('Referer') or None, path=request.path or None, query_string=request.query_string or None, status=response.status_code or None, resource="timeline_event", resource_id=new_event.id or None, resource_after=event_dict or None) return new_event
def after(self, state): # Ignore get methods, we only care about changes. if state.request.method not in ['POST', 'PUT', 'DELETE']: return # Ignore requests that failed if state.response.status_code >= 400: return request = state.request response = state.response # Attempt to determine the type of the payload. This checks for # nested paths. (resource, resource_id, subresource, subresource_id) \ = self.parse(request.path) # FIXME: Ignore worklists and boards for now, since they cause a # 500 error when moving cards that seems to be pika breaking. if resource in ['board', 'worklist']: return # On a POST method, the server has assigned an ID to the resource, # so we should be getting it from the resource rather than the URL. if state.request.method == 'POST': response_body = json.loads(response.body) if response_body: if not subresource: resource_id = response_body.get('id') elif subresource == 'comment': subresource_id = response_body.get('comment').get('id') else: resource_id = None # Get a copy of the resource post-modification. Will return None in # the case of a DELETE. new_resource = self.get_original_resource(resource, resource_id) # Extract the old resource when possible. if hasattr(state, 'old_entity_values'): old_resource = state.old_entity_values else: old_resource = None # Build the payload. Use of None is included to ensure that we don't # accidentally blow up the API call, but we don't anticipate it # happening. publish(author_id=request.current_user_id, method=request.method, url=request.headers.get('Referer'), path=request.path, query_string=request.query_string, status=response.status_code, resource=resource, resource_id=resource_id, sub_resource=subresource, sub_resource_id=subresource_id, resource_before=old_resource, resource_after=new_resource)
def after(self, state): # Ignore get methods, we only care about changes. if state.request.method not in ['POST', 'PUT', 'DELETE']: return request = state.request response = state.response # Attempt to determine the type of the payload. This checks for # nested paths. (resource, resource_id, subresource, subresource_id) \ = self.parse(request.path) # FIXME: Ignore worklists and boards for now, since they cause a # 500 error when moving cards that seems to be pika breaking. if resource in ['board', 'worklist']: return # On a POST method, the server has assigned an ID to the resource, # so we should be getting it from the resource rather than the URL. if state.request.method == 'POST': response_body = json.loads(response.body) if response_body: if not subresource: resource_id = response_body.get('id') elif subresource == 'comment': subresource_id = response_body.get('comment').get('id') else: resource_id = None # Get a copy of the resource post-modification. Will return None in # the case of a DELETE. new_resource = self.get_original_resource(resource, resource_id) # Extract the old resource when possible. if hasattr(state, 'old_entity_values'): old_resource = state.old_entity_values else: old_resource = None # Build the payload. Use of None is included to ensure that we don't # accidentally blow up the API call, but we don't anticipate it # happening. publish(author_id=request.current_user_id, method=request.method, url=request.headers.get('Referer'), path=request.path, query_string=request.query_string, status=response.status_code, resource=resource, resource_id=resource_id, sub_resource=subresource, sub_resource_id=subresource_id, resource_before=old_resource, resource_after=new_resource)
def after(self, state): # Ignore get methods, we only care about changes. if state.request.method not in ["POST", "PUT", "DELETE"]: return request = state.request response = state.response # Attempt to determine the type of the payload. This checks for # nested paths. (resource, resource_id, subresource, subresource_id) = self.parse(request.path) # On a POST method, the server has assigned an ID to the resource, # so we should be getting it from the resource rather than the URL. if state.request.method == "POST": response_body = json.loads(response.body) if response_body: resource_id = response_body.get("id") else: resource_id = None # Get a copy of the resource post-modification. Will return None in # the case of a DELETE. new_resource = self.get_original_resource(resource, resource_id) # Extract the old resource when possible. if hasattr(state, "old_entity_values"): old_resource = state.old_entity_values else: old_resource = None # Build the payload. Use of None is included to ensure that we don't # accidentally blow up the API call, but we don't anticipate it # happening. publish( author_id=request.current_user_id, method=request.method, path=request.path, status=response.status_code, resource=resource, resource_id=resource_id, sub_resource=subresource, sub_resource_id=subresource_id, resource_before=old_resource, resource_after=new_resource, )
def event_create(values): new_event = api_base.entity_create(models.TimeLineEvent, values) if CONF.enable_notifications: # Build the payload. Use of None is included to ensure that we don't # accidentally blow up the API call, but we don't anticipate it # happening. event_dict = tojson(TimeLineEvent, TimeLineEvent.from_db_model(new_event)) publish(author_id=request.current_user_id or None, method="POST", path=request.path or None, status=response.status_code or None, resource="timeline_event", resource_id=new_event.id or None, resource_after=event_dict or None) return new_event