~ubuntu-branches/ubuntu/utopic/python-apptools/utopic

« back to all changes in this revision

Viewing changes to apptools/permissions/action/logout_action.py

  • Committer: Bazaar Package Importer
  • Author(s): Varun Hiremath
  • Date: 2011-07-08 23:55:50 UTC
  • mfrom: (2.1.9 sid)
  • Revision ID: james.westby@ubuntu.com-20110708235550-yz5u79ubeo4dhyfx
Tags: 4.0.0-1
* New upstream release
* Update debian/watch file

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#------------------------------------------------------------------------------
 
2
# Copyright (c) 2008, Riverbank Computing Limited
 
3
# All rights reserved.
 
4
#
 
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!
 
10
#
 
11
# Author: Riverbank Computing Limited
 
12
# Description: <Enthought permissions package component>
 
13
#------------------------------------------------------------------------------
 
14
 
 
15
 
 
16
# Enthought library imports.
 
17
from pyface.action.api import Action
 
18
from traits.api import Bool, Unicode
 
19
 
 
20
# Local imports.
 
21
from apptools.permissions.package_globals import get_permissions_manager
 
22
 
 
23
 
 
24
class LogoutAction(Action):
 
25
    """An action that unauthenticates the current user."""
 
26
 
 
27
    #### 'Action' interface ###################################################
 
28
 
 
29
    enabled = Bool(False)
 
30
 
 
31
    name = Unicode("Log&out")
 
32
 
 
33
    ###########################################################################
 
34
    # 'object' interface.
 
35
    ###########################################################################
 
36
 
 
37
    def __init__(self, **traits):
 
38
        """Initialise the object."""
 
39
 
 
40
        super(LogoutAction, self).__init__(**traits)
 
41
 
 
42
        get_permissions_manager().user_manager.on_trait_event(self._refresh_enabled, 'user_authenticated')
 
43
 
 
44
    ###########################################################################
 
45
    # 'Action' interface.
 
46
    ###########################################################################
 
47
 
 
48
    def perform(self, event):
 
49
        """Perform the action."""
 
50
 
 
51
        get_permissions_manager().user_manager.unauthenticate_user()
 
52
 
 
53
    ###########################################################################
 
54
    # Private interface.
 
55
    ###########################################################################
 
56
 
 
57
    def _refresh_enabled(self, user):
 
58
        """Invoked whenever the current user's authorisation state changes."""
 
59
 
 
60
        self.enabled = user is not None