1
#------------------------------------------------------------------------------
2
# Copyright (c) 2008, Riverbank Computing Limited
5
# This software is provided without warranty under the terms of the BSD
6
# license included in enthought/LICENSE.txt and may be redistributed only
7
# under the conditions described in the aforementioned license. The license
8
# is also available online at http://www.enthought.com/licenses/BSD.txt
9
# Thanks for using Enthought open source!
11
# Author: Riverbank Computing Limited
12
# Description: <Enthought permissions package component>
13
#------------------------------------------------------------------------------
16
# Enthought library imports.
17
from pyface.action.api import Action
18
from traits.api import Bool, Unicode
21
from apptools.permissions.package_globals import get_permissions_manager
24
class LogoutAction(Action):
25
"""An action that unauthenticates the current user."""
27
#### 'Action' interface ###################################################
31
name = Unicode("Log&out")
33
###########################################################################
35
###########################################################################
37
def __init__(self, **traits):
38
"""Initialise the object."""
40
super(LogoutAction, self).__init__(**traits)
42
get_permissions_manager().user_manager.on_trait_event(self._refresh_enabled, 'user_authenticated')
44
###########################################################################
46
###########################################################################
48
def perform(self, event):
49
"""Perform the action."""
51
get_permissions_manager().user_manager.unauthenticate_user()
53
###########################################################################
55
###########################################################################
57
def _refresh_enabled(self, user):
58
"""Invoked whenever the current user's authorisation state changes."""
60
self.enabled = user is not None