Package Products :: Package ZenModel :: Module AdministrativeRoleable |
[hide private]
[frames] | no frames]

# Source Code for Module Products.ZenModel.AdministrativeRoleable

      1  ###########################################################################
      2  #
      3  # This program is part of Zenoss Core, an open source monitoring platform.
      4  # Copyright (C) 2007, Zenoss Inc.
      5  #
      6  # This program is free software; you can redistribute it and/or modify it
      7  # under the terms of the GNU General Public License version 2 or (at your
      8  # option) any later version as published by the Free Software Foundation.
      9  #
     10  # For complete information please visit: http://www.zenoss.com/oss/
     11  #
     12  ###########################################################################
     13  """
     14  AdministrativeRoleable.py
     15
     16  Created by Marc Irlandez on 2007-04-05.
     17  """
     18
     19  from AccessControl import ClassSecurityInfo
     20  from Products.ZenModel.AdministrativeRole import AdministrativeRole
     21  from Globals import InitializeClass
     22  from zope.event import notify
     23  from Products.Zuul.catalog.events import IndexingEvent
     24  from ZenossSecurity import *
     25  from Products.ZenWidgets import messaging
     26
     27 -class AdministrativeRoleable:
     28
     29      security = ClassSecurityInfo()
     30
     31      security.declareProtected(ZEN_ADMINISTRATORS_VIEW,
     32          'getAdministrativeRoles')
     33 -    def getAdministrativeRoles(self):
     34          "Get the Admin Roles on this device"
     35          return self.adminRoles.objectValuesAll()
     36
     37      security.declareProtected(ZEN_ADMINISTRATORS_EDIT,
     38          'manage_addAdministrativeRole')
     39 -    def manage_addAdministrativeRole(self, newId=None, REQUEST=None):
     40          "Add a Admin Role to this device"
     41          us = self.ZenUsers.getUserSettings(newId)
     42          AdministrativeRole(us, self)
     43          self.setAdminLocalRoles()
     44          self.index_object()
     45          notify(IndexingEvent(self))
     46          if REQUEST:
     47              if us:
     48                  messaging.IMessageSender(self).sendToBrowser(
     49                      'Admin Role Added',
     50                      'The %s administrative role has been added.' % newId
     51                  )
     52              return self.callZenScreen(REQUEST)
     53
     54      security.declareProtected(ZEN_ADMINISTRATORS_EDIT,
     55          'manage_editAdministrativeRoles')
     56 -    def manage_editAdministrativeRoles(self, ids=(), role=(),
     57                                          level=(), REQUEST=None):
     58          """Edit list of admin roles.
     59          """
     60          if isinstance(ids, basestring):
     61              ids = [ids]
     62              role = [role]
     63              level = [level]
     64          for i, id in enumerate(ids):
     65              ar = self.adminRoles._getOb(id)
     66              ar.update(role[i], level[i])
     67          self.setAdminLocalRoles()
     68          self.index_object()
     69          notify(IndexingEvent(self))
     70          if REQUEST:
     71              messaging.IMessageSender(self).sendToBrowser(
     72                  'Admin Roles Updated',
     73                  ('The following administrative roles have been updated: '
     74                   '%s' % ", ".join(ids))
     75              )
     76              return self.callZenScreen(REQUEST)
     77
     78
     79      security.declareProtected(ZEN_ADMINISTRATORS_EDIT,
     80          'manage_deleteAdministrativeRole')
     81 -    def manage_deleteAdministrativeRole(self, delids=(), REQUEST=None):
     82          "Delete a admin role to this device"
     83          if isinstance(delids, basestring):
     84              delids = [delids]
     85          for userid in delids:
     86              ar = self.adminRoles._getOb(userid, None)
     87              if ar is not None: ar.delete()
     88              self.manage_delLocalRoles((userid,))
     89          self.setAdminLocalRoles()
     90          self.index_object()
     91          notify(IndexingEvent(self))
     92          if REQUEST:
     93              if delids:
     94                  messaging.IMessageSender(self).sendToBrowser(
     95                      'Admin Roles Deleted',
     96                      ('The following administrative roles have been deleted: '
     97                       '%s' % ", ".join(delids))
     98                  )
     99              return self.callZenScreen(REQUEST)
    100
    101 -    def manage_listAdministrativeRoles(self):
    102          """List the user and their roles on an object"""
    103          return [ (ar.id, (ar.role,)) for ar in self.adminRoles() ]
    104
    105
    106 -    def setAdminLocalRoles(self):
    107          """Hook for setting permissions"""
    108          pass
    109
    110
    111  InitializeClass(AdministrativeRoleable)
    112