Skip to content

Commit

Permalink
AuditActionExecutor: factored out case distinction into separate method.
Browse files Browse the repository at this point in the history
Refs #18
  • Loading branch information
reinhardt committed Jul 27, 2018
1 parent e07c837 commit bc6aeee
Showing 1 changed file with 52 additions and 34 deletions.
86 changes: 52 additions & 34 deletions collective/auditlog/action.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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' % (
Expand All @@ -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):
Expand All @@ -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
Expand All @@ -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
Expand Down

0 comments on commit bc6aeee

Please sign in to comment.