Skip to main content

Zope 2 publisher validation hook

Project description

Introduction

This package provides a hook into Zope’s ZPublisher that is run after the publisher has completed traversal and authentication, but before it tries to publish an object. This is practical for tasks such as tracking user activity.

Hooks use zope.event’s event mechanism using the plone.validatehook.interfaces.IPostValidationEvent. This is based on the standard ObjectEvent form zope.component.

The IPostValidationEvent event has two attributes: user which is the currently authenticated user object and request, which is the current request object.

Keep in mind that even unauthenticated requests have a user object. If you only want to deal with ‘normal’ users make sure you ignore any instances of AccessControl.User.SpecialUser.

Example

As an example we will write a bit of code which logs the id of the current user and the path to the current code. This is the code for the event handler:

from zope.interface import Interface
from zope.component import adapter
from plone.validatehook.interfaces import IPostValidationEvent
import logging

logger = logging.getLogger("LogRequest")

@adapter(Interface, IPostValidationEvent)
def LogRequest(object, event):
    if getattr(object, "getPhysicalPath", None) is None:
        path="Unknown path"
    else:
        path="/".join(object.getPhysicalPath()

    logger.info("Request from user '%s' for object %s" %
            event.user.getId(), path)

To use this code you need to register it in zcml:

<subscriber handler=".events.LogRequest" />

Changelog

1.0 - October 15, 2008

  • Move to svn.zope.org and relicense under ZPL. [wichert]

1.0rc1 - July 15, 2008

  • Initial release [wichert]

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

plone.validatehook-1.0.zip (10.2 kB view details)

Uploaded Source

File details

Details for the file plone.validatehook-1.0.zip.

File metadata

File hashes

Hashes for plone.validatehook-1.0.zip
Algorithm Hash digest
SHA256 1f790be5a942c67cb8b66b3e5c3224c02835098f4cd612c1c67425eae7ee935f
MD5 dee17ae09fece540350b3961526abda6
BLAKE2b-256 eac2276c917b8458b1f149b84b63171addfe26dbee934bf3c738b2dee964c992

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page