diff --git a/collective/auditlog/action.py b/collective/auditlog/action.py index 10f4e42..69a7b06 100644 --- a/collective/auditlog/action.py +++ b/collective/auditlog/action.py @@ -87,31 +87,10 @@ def get_history_comment(self): return transition.get('comments', '') return '' - def __call__(self): - req = getRequest() - if req.environ.get('disable.auditlog', False): - return True - - event = self.event - obj = event.object - # order of those checks is important since some interfaces - # base off the others - rule = inspect.stack()[1][0].f_locals['self'] - registry = getUtility(IRegistry) - trackWorkingCopies = registry['collective.auditlog.interfaces.IAuditLogSettings.trackworkingcopies'] # noqa - - if not self.canExecute(rule, req): - return True # cut out early, we can't do this event - - data = { - 'info': '' - } - - if IPloneFormGenField.providedBy(obj): - # if ploneformgen field, use parent object for modified data - data['field'] = obj.getId() - obj = aq_parent(obj) - + def process_action(self, event, obj, rule): + result = {} + data = {} + action = None # the order of those interface checks matters since some interfaces # inherit from others if IObjectRemovedEvent.providedBy(event): @@ -130,7 +109,8 @@ def __call__(self): action = 'rename' else: # cut out here, double action for this event - return True + result['stop_execution'] = True + return result else: if 'Moved' in rule.rule.title: data['info'] = 'previous location: %s/%s' % ( @@ -139,7 +119,8 @@ def __call__(self): action = 'moved' else: # step out immediately since this could be a double action - return True + result['stop_execution'] = True + return result elif IObjectModifiedEvent.providedBy(event): action = 'modified' elif IActionSucceededEvent.providedBy(event): @@ -153,21 +134,59 @@ def __call__(self): elif ICheckinEvent.providedBy(event): data['info'] = event.message action = 'checked in' - req.environ['disable.auditlog'] = True + result['disable.auditlog'] = True data['working_copy'] = '/'.join(obj.getPhysicalPath()) - obj = event.baseline + result['object'] = event.baseline elif IBeforeCheckoutEvent.providedBy(event): action = 'checked out' - req.environ['disable.auditlog'] = True + result['disable.auditlog'] = True elif ICancelCheckoutEvent.providedBy(event): action = 'cancel check out' - req.environ['disable.auditlog'] = True + result['disable.auditlog'] = True data['working_copy'] = '/'.join(obj.getPhysicalPath()) - obj = event.baseline + result['object'] = event.baseline else: logger.warn('no action matched') + result['stop_execution'] = True + + data['action'] = action + result['data'] = data + + return result + + def __call__(self): + req = getRequest() + if req.environ.get('disable.auditlog', False): return True + event = self.event + obj = event.object + # order of those checks is important since some interfaces + # base off the others + rule = inspect.stack()[1][0].f_locals['self'] + registry = getUtility(IRegistry) + trackWorkingCopies = registry['collective.auditlog.interfaces.IAuditLogSettings.trackworkingcopies'] # noqa + + if not self.canExecute(rule, req): + return True # cut out early, we can't do this event + + data = { + 'info': '' + } + + if IPloneFormGenField.providedBy(obj): + # if ploneformgen field, use parent object for modified data + data['field'] = obj.getId() + obj = aq_parent(obj) + + result = self.process_action(event, obj, rule) + + if result.get('stop_execution'): + return True + req.environ['disable.auditlog'] = result.get('disable.auditlog', False) + obj = result.get('object', obj) + data.update(result['data']) + if IWorkingCopy.providedBy(obj): # if working copy, iterate, check if Track Working Copies is # enabled @@ -185,11 +204,10 @@ def __call__(self): return True else: # if not enabled, we only care about checked messages - if 'check' not in action: + if 'check' not in data['action']: return True data.update(getObjectInfo(obj)) - data['action'] = action addLogEntry(data) return True