Package Products :: Package ZenUtils :: Module events |
[hide private]
[frames] | no frames]

# Source Code for Module Products.ZenUtils.events

     1  ##############################################################################
     2  #
     3  # Copyright (C) Zenoss, Inc. 2012, all rights reserved.
     4  #
     5  # This content is made available according to terms specified in
     6  # License.zenoss under the directory where your Zenoss product is installed.
     7  #
     8  ##############################################################################
     9
    10
    11  from Products.PluggableAuthService.interfaces.events import IUserLoggedInEvent
    12  from Products.PluggableAuthService.interfaces.events import IUserLoggedOutEvent
    13  from Products.PluggableAuthService.events import PASEvent
    14  from zope.interface import implements, Interface, Attribute
    15  from zope.event import notify
    16  from ZODB.transact import transact
    17
    18 -class UserLoggedInEvent(PASEvent):
    19      """
    20      Login notification event.
    21
    22      Subscribe to this to run code when a user logs in.
    23      The username can be obtained in the handler via: evt.object.id
    24
    25      WARNING: Currently it doesn't notify when switching directly from
    26               a non-admin user to the admin user without logging out,
    27               because we're unable to determine whether the login succeeded.
    28      """
    29      implements(IUserLoggedInEvent)
    30
    31
    32 -class UserLoggedOutEvent(PASEvent):
    33      """
    34      Manual logout notification event.
    35
    36      This does not fire for session timeouts.
    37      """
    38      implements(IUserLoggedOutEvent)
    39
    40 -class IZopeApplicationOpenedEvent(Interface):
    41      """
    42      Returns the Zope application.
    43      """
    44      app = Attribute("The Zope Application")
    45
    46 -class ZopeApplicationOpenedEvent(object):
    47      implements(IZopeApplicationOpenedEvent)
    48
    49 -    def __init__(self, app):
    50          self.app = app
    51
    52 -def notifyZopeApplicationOpenedSubscribers(event):
    53      """
    54      Re-fires the IDatabaseOpenedWithRoot notification to subscribers with an
    55      open handle to the application defined in the database.
    56      """
    57      db = event.database
    58      conn = db.open()
    59      try:
    60          app = conn.root()['Application']
    61          transact(notify)(ZopeApplicationOpenedEvent(app))
    62      finally:
    63          conn.close()
    64