Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for logging workflow transitions
- Loading branch information
Showing
13 changed files
with
160 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
<?xml version="1.0"?> | ||
<metadata> | ||
<version>3</version> | ||
<version>4</version> | ||
</metadata> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
src/collective/fingerpointing/subscribers/workflow_logger.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# -*- coding: utf-8 -*- | ||
"""Event subscriber handler for IActionSucceededEvent.""" | ||
from collective.fingerpointing.config import AUDIT_MESSAGE | ||
from collective.fingerpointing.interfaces import IFingerPointingSettings | ||
from collective.fingerpointing.logger import log_info | ||
from collective.fingerpointing.utils import get_request_information | ||
from plone import api | ||
from plone.api.exc import InvalidParameterError | ||
|
||
|
||
def workflow_logger(event): | ||
"""Log workflow transitions.""" | ||
try: | ||
record = IFingerPointingSettings.__identifier__ + '.audit_workflow' | ||
audit_workflow = api.portal.get_registry_record(record) | ||
except InvalidParameterError: | ||
return # package is not installed | ||
|
||
if audit_workflow: | ||
user, ip = get_request_information() | ||
action = 'workflow transition' | ||
extras = u'object={0} transition={1}'.format(event.object, event.action) | ||
log_info(AUDIT_MESSAGE.format(user, ip, action, extras)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
src/collective/fingerpointing/tests/test_workflow_subscriber.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
# -*- coding: utf-8 -*- | ||
"""Tests for workflow subscriber.""" | ||
from collective.fingerpointing.config import PROJECTNAME | ||
from collective.fingerpointing.interfaces import IFingerPointingSettings | ||
from collective.fingerpointing.testing import INTEGRATION_TESTING | ||
from logging import INFO | ||
from plone import api | ||
from plone.app.testing import setRoles | ||
from plone.app.testing import TEST_USER_ID | ||
from testfixtures import LogCapture | ||
|
||
import unittest | ||
|
||
|
||
class WorkflowSubscribersTestCase(unittest.TestCase): | ||
|
||
"""Tests content type life cycle subscribers.""" | ||
|
||
layer = INTEGRATION_TESTING | ||
|
||
def setUp(self): | ||
self.portal = self.layer['portal'] | ||
setRoles(self.portal, TEST_USER_ID, ['Manager']) | ||
|
||
# disable lifecycle audit | ||
record = IFingerPointingSettings.__identifier__ + '.audit_lifecycle' | ||
api.portal.set_registry_record(record, False) | ||
|
||
def test_workflow_transitions(self): | ||
expected = ( | ||
('collective.fingerpointing', 'INFO', u'user=test ip=127.0.0.1 action=workflow transition object=<NewsItem at foo> transition=submit'), | ||
('collective.fingerpointing', 'INFO', u'user=test ip=127.0.0.1 action=workflow transition object=<NewsItem at foo> transition=publish'), | ||
('collective.fingerpointing', 'INFO', u'user=test ip=127.0.0.1 action=workflow transition object=<NewsItem at foo> transition=retract'), | ||
) | ||
|
||
with LogCapture('collective.fingerpointing', level=INFO) as log: | ||
obj = api.content.create(self.portal, 'News Item', 'foo') | ||
api.content.transition(obj=obj, transition='submit') | ||
api.content.transition(obj=obj, transition='publish') | ||
api.content.transition(obj=obj, transition='retract') | ||
log.check(*expected) | ||
|
||
def test_susbcriber_ignored_when_package_not_installed(self): | ||
# events should not raise errors if package is not installed | ||
qi = self.portal['portal_quickinstaller'] | ||
qi.uninstallProducts(products=[PROJECTNAME]) | ||
|
||
obj = api.content.create(self.portal, 'News Item', 'foo') | ||
api.content.transition(obj=obj, transition='submit') | ||
api.content.transition(obj=obj, transition='publish') | ||
api.content.transition(obj=obj, transition='retract') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
<configure xmlns="http://namespaces.zope.org/zope"> | ||
<include package=".v2" /> | ||
<include package=".v3" /> | ||
<include package=".v4" /> | ||
</configure> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
# -*- coding: utf-8 -*- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<configure | ||
xmlns="http://namespaces.zope.org/zope" | ||
xmlns:genericsetup="http://namespaces.zope.org/genericsetup"> | ||
|
||
<genericsetup:upgradeSteps | ||
source="3" | ||
destination="4" | ||
profile="collective.fingerpointing:default"> | ||
|
||
<genericsetup:upgradeDepends | ||
title="Add new field audit_workflow to configlet" | ||
description="Reload registration of configlet registry to add new field." | ||
import_steps="plone.app.registry" | ||
run_deps="false" | ||
/> | ||
|
||
</genericsetup:upgradeSteps> | ||
|
||
</configure> |