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

# Source Code for Module Products.ZenModel.AdministrativeRoleable

      1  ##############################################################################
      2  #
      3  # Copyright (C) Zenoss, Inc. 2007, 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  """
     12  AdministrativeRoleable.py
     13
     14  Created by Marc Irlandez on 2007-04-05.
     15  """
     16
     17  from AccessControl import ClassSecurityInfo
     18  from Products.ZenMessaging.audit import audit
     19  from Products.ZenModel.AdministrativeRole import AdministrativeRole
     20  from Globals import InitializeClass
     21  from zope.event import notify
     22  from Products.ZenUtils.Utils import getDisplayType
     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                  audit(['UI', getDisplayType(self), 'AddAdministrativeRole'], self, newId=newId)
     49                  messaging.IMessageSender(self).sendToBrowser(
     50                      'Admin Role Added',
     51                      'The %s administrative role has been added.' % newId
     52                  )
     53              return self.callZenScreen(REQUEST)
     54
     55      security.declareProtected(ZEN_ADMINISTRATORS_EDIT,
     56          'manage_editAdministrativeRoles')
     57 -    def manage_editAdministrativeRoles(self, ids=(), role=(), REQUEST=None):
     58          """
     59          Edit list of admin roles.
     60          """
     61          if isinstance(ids, basestring):
     62              ids = [ids]
     63              role = [role]
     64
     65          editedRoles = []
     66          for i, id in enumerate(ids):
     67              roleEdit = (id, role[i])
     68              editedRoles.append(roleEdit)
     69              ar = self.adminRoles._getOb(roleEdit[0])
     70              ar.update(roleEdit[1])
     71
     72          self.setAdminLocalRoles()
     73          self.index_object()
     74          notify(IndexingEvent(self))
     75          if REQUEST:
     76              for roleEdit in editedRoles:
     77                  audit(['UI', getDisplayType(self), 'EditAdministrativeRole'], self,
     78                        id=roleEdit[0], role=roleEdit[1])
     79              messaging.IMessageSender(self).sendToBrowser(
     80                  'Admin Roles Updated',
     81                  ('The following administrative roles have been updated: '
     82                   '%s' % ", ".join(ids))
     83              )
     84              return self.callZenScreen(REQUEST)
     85
     86
     87      security.declareProtected(ZEN_ADMINISTRATORS_EDIT,
     88          'manage_deleteAdministrativeRole')
     89 -    def manage_deleteAdministrativeRole(self, delids=(), REQUEST=None):
     90          "Delete a admin role to this device"
     91          if isinstance(delids, basestring):
     92              delids = [delids]
     93          for userid in delids:
     94              ar = self.adminRoles._getOb(userid, None)
     95              if ar is not None: ar.delete()
     96              self.manage_delLocalRoles((userid,))
     97          self.setAdminLocalRoles()
     98          self.index_object()
     99          notify(IndexingEvent(self))
    100          if REQUEST:
    101              if delids:
    102                  for userid in delids:
    103                      audit(['UI', getDisplayType(self), 'DeleteAdministrativeRole'], self, userid=userid)
    104                  messaging.IMessageSender(self).sendToBrowser(
    105                      'Admin Roles Deleted',
    106                      ('The following administrative roles have been deleted: '
    107                       '%s' % ", ".join(delids))
    108                  )
    109              return self.callZenScreen(REQUEST)
    110
    111 -    def manage_listAdministrativeRoles(self):
    112          """List the user and their roles on an object"""
    113          return [ (ar.id, (ar.role,)) for ar in self.adminRoles() ]
    114
    115
    116 -    def setAdminLocalRoles(self):
    117          """Hook for setting permissions"""
    118          pass
    119
    120
    121  InitializeClass(AdministrativeRoleable)
    122