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 as published by
      8  # 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  import types
     20  from AccessControl import ClassSecurityInfo
     21  from Products.ZenModel.AdministrativeRole import AdministrativeRole
     22  from Globals import InitializeClass
     23  from ZenossSecurity import *
     24  from Products.ZenWidgets import messaging
     25
     26 -class AdministrativeRoleable:
     27
     28      security = ClassSecurityInfo()
     29
     30      security.declareProtected(ZEN_ADMINISTRATORS_VIEW,
     31          'getAdministrativeRoles')
     32 -    def getAdministrativeRoles(self):
     33          "Get the Admin Roles on this device"
     34          return self.adminRoles.objectValuesAll()
     35
     36      security.declareProtected(ZEN_ADMINISTRATORS_EDIT,
     37          'manage_addAdministrativeRole')
     38 -    def manage_addAdministrativeRole(self, newId=None, REQUEST=None):
     39          "Add a Admin Role to this device"
     40          us = self.ZenUsers.getUserSettings(newId)
     41          AdministrativeRole(us, self)
     42          self.setAdminLocalRoles()
     43          if REQUEST:
     44              if us:
     45                  messaging.IMessageSender(self).sendToBrowser(
     46                      'Admin Role Added',
     47                      'The %s administrative role has been added.' % newId
     48                  )
     49              return self.callZenScreen(REQUEST)
     50
     51      security.declareProtected(ZEN_ADMINISTRATORS_EDIT,
     52          'manage_editAdministrativeRoles')
     53 -    def manage_editAdministrativeRoles(self, ids=(), role=(),
     54                                          level=(), REQUEST=None):
     55          """Edit list of admin roles.
     56          """
     57          if type(ids) in types.StringTypes:
     58              ids = [ids]
     59              role = [role]
     60              level = [level]
     61          for i, id in enumerate(ids):
     62              ar = self.adminRoles._getOb(id)
     63              ar.update(role[i], level[i])
     64          self.setAdminLocalRoles()
     65          if REQUEST:
     66              messaging.IMessageSender(self).sendToBrowser(
     67                  'Admin Roles Updated',
     68                  ('The following administrative roles have been updated: '
     69                   '%s' % ", ".join(ids))
     70              )
     71              return self.callZenScreen(REQUEST)
     72
     73
     74      security.declareProtected(ZEN_ADMINISTRATORS_EDIT,
     75          'manage_deleteAdministrativeRole')
     76 -    def manage_deleteAdministrativeRole(self, delids=(), REQUEST=None):
     77          "Delete a admin role to this device"
     78          if type(delids) in types.StringTypes:
     79              delids = [delids]
     80          for userid in delids:
     81              ar = self.adminRoles._getOb(userid, None)
     82              if ar is not None: ar.delete()
     83              self.manage_delLocalRoles((userid,))
     84          self.setAdminLocalRoles()
     85          if REQUEST:
     86              if delids:
     87                  messaging.IMessageSender(self).sendToBrowser(
     88                      'Admin Roles Deleted',
     89                      ('The following administrative roles have been deleted: '
     90                       '%s' % ", ".join(delids))
     91                  )
     92              return self.callZenScreen(REQUEST)
     93
     94 -    def manage_listAdministrativeRoles(self):
     95          """List the user and their roles on an object"""
     96          return [ (ar.id, (ar.role,)) for ar in self.adminRoles() ]
     97
     98
     99 -    def setAdminLocalRoles(self):
    100          """Hook for setting permissions"""
    101          pass
    102
    103
    104  InitializeClass(AdministrativeRoleable)
    105