Package ZenModel :: Module ZentinelPortal
[hide private]
[frames] | no frames]

Source Code for Module ZenModel.ZentinelPortal

  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  """ Portal class 
 14   
 15  $Id: ZentinelPortal.py,v 1.17 2004/04/08 15:35:25 edahl Exp $ 
 16  """ 
 17   
 18  import os 
 19  import urllib 
 20   
 21  import Globals 
 22   
 23  from zExceptions import Redirect 
 24  from AccessControl.User import manage_addUserFolder 
 25  from AccessControl import getSecurityManager, ClassSecurityInfo 
 26   
 27  from Products.Sessions.BrowserIdManager import constructBrowserIdManager 
 28  from Products.Sessions.SessionDataManager import constructSessionDataManager 
 29   
 30  from Products.CMFCore.PortalObject import PortalObjectBase 
 31  from Products.CMFCore import PortalFolder 
 32  from Products.CMFCore.utils import getToolByName 
 33   
 34  from Products.ZenUtils import Security 
 35   
 36  from ZenossSecurity import * 
 37   
 38  from Products.AdvancedQuery import MatchGlob, Eq, Or, And, In 
 39   
40 -class ZentinelPortal ( PortalObjectBase ):
41 """ 42 The *only* function this class should have is to help in the setup 43 of a new ZentinelPortal. It should not assist in the functionality at all. 44 """ 45 meta_type = 'ZentinelPortal' 46 47 _properties = ( 48 {'id':'title', 'type':'string'}, 49 {'id':'description', 'type':'text'}, 50 ) 51 title = '' 52 description = '' 53 54 security = ClassSecurityInfo() 55
56 - def __init__( self, id, title='' ):
57 PortalObjectBase.__init__( self, id, title )
58 59 60 security.declareProtected(ZEN_COMMON, 'searchDevices')
61 - def searchDevices(self, queryString='', REQUEST=None):
62 """Returns the concatenation of a device name, ip and mac 63 search on the list of devices. 64 """ 65 zcatalog = self.dmd.Devices.deviceSearch 66 glob = queryString.rstrip('*') + '*' 67 glob = MatchGlob('id', glob) 68 query = Or(glob, Eq('getDeviceIp', queryString)) 69 brains = zcatalog.evalAdvancedQuery(query) 70 if REQUEST and len(brains) == 1: 71 raise Redirect(urllib.quote(brains[0].getPrimaryId)) 72 try: 73 brains += self.dmd.Networks.ipSearch.evalAdvancedQuery(glob) 74 except AttributeError: 75 pass 76 return [ b.getObject() for b in brains ]
77 78 79 security.declareProtected(ZEN_COMMON, 'getOrganizerNames')
80 - def getOrganizerNames(self, dataRoot='Devices', REQUEST=None):
81 """Return the organizer names to which this user has access 82 """ 83 root = self.dmd.getDmdRoot(dataRoot) 84 return root.getOrganizerNames() or '[]'
85 86 security.declareProtected(ZEN_COMMON, 'getRootOrganizerInfo')
87 - def getRootOrganizerInfo(self, dataRoot, REQUEST=None):
88 """ Return json event summaries for root org """ 89 root = self.dmd.getDmdRoot(dataRoot) 90 return root.getSubOrganizersEventSummary() or '[]'
91 92 security.declareProtected(ZEN_COMMON, 'jsonGetDeviceNames')
93 - def jsonGetDeviceNames(self):
94 """Return a list of devices for the dashboard 95 """ 96 return self.dmd.Devices.jsonGetDeviceNames()
97 98
99 - def isManager(self, obj=None):
100 """ 101 Return true if user is authenticated and has Manager role. 102 """ 103 user = self.dmd.ZenUsers.getUser() 104 if user: 105 return user.has_role((MANAGER_ROLE, ZEN_MANAGER_ROLE), obj)
106 107
108 - def has_role(self, role, obj=None):
109 """Check to see of a user has a role. 110 """ 111 if obj is None: obj = self 112 user = getSecurityManager().getUser() 113 if user: return user.has_role(role, obj)
114 115
116 - def has_permission(self, perm, obj=None):
117 """Check to see of a user has a permission. 118 """ 119 if obj is None: obj = self 120 user = getSecurityManager().getUser() 121 if user: return user.has_permission(perm, obj)
122 123 124 Globals.InitializeClass(ZentinelPortal) 125 126
127 -class PortalGenerator:
128 129 klass = ZentinelPortal 130
131 - def setupTools(self, p):
132 """Set up initial tools""" 133 addCMFCoreTool = p.manage_addProduct['CMFCore'].manage_addTool 134 addCMFCoreTool('CMF Skins Tool', None)
135 136
137 - def setupMailHost(self, p):
138 p.manage_addProduct['MailHost'].manage_addMailHost( 139 'MailHost', smtp_host='localhost')
140 141
142 - def setupUserFolder(self, p):
143 #p.manage_addProduct['OFSP'].manage_addUserFolder() 144 Security.createPASFolder(p) 145 Security.setupPASFolder(p)
146 147
148 - def setupCookieAuth(self, p):
149 # XXX PAS is handling this now, right? 150 #p.manage_addProduct['CMFCore'].manage_addCC( 151 # id='cookie_authentication') 152 pass
153 154
155 - def setupRoles(self, p):
156 # Set up the suggested roles. 157 p.__ac_roles__ += (ZEN_USER_ROLE, ZEN_MANAGER_ROLE,)
158 159
160 - def setupPermissions(self, p):
161 # Set up some suggested role to permission mappings. 162 mp = p.manage_permission 163 mp(ZEN_CHANGE_SETTINGS,[ZEN_MANAGER_ROLE, OWNER_ROLE, MANAGER_ROLE,], 1) 164 mp(ZEN_CHANGE_DEVICE, [ZEN_MANAGER_ROLE, OWNER_ROLE, MANAGER_ROLE,], 1) 165 mp(ZEN_MANAGE_DMD, [ZEN_MANAGER_ROLE, OWNER_ROLE, MANAGER_ROLE,], 1) 166 mp(ZEN_DELETE, [ZEN_MANAGER_ROLE, OWNER_ROLE, MANAGER_ROLE,], 1) 167 mp(ZEN_ADD, [ZEN_MANAGER_ROLE, OWNER_ROLE, MANAGER_ROLE,], 1) 168 mp(ZEN_VIEW, [ZEN_USER_ROLE, ZEN_MANAGER_ROLE, 169 MANAGER_ROLE, OWNER_ROLE]) 170 mp(ZEN_COMMON, ["Authenticated", ZEN_USER_ROLE, ZEN_MANAGER_ROLE, 171 MANAGER_ROLE, OWNER_ROLE], 1) 172 mp(ZEN_CHANGE_ALERTING_RULES, 173 [ZEN_MANAGER_ROLE, MANAGER_ROLE, OWNER_ROLE], 1) 174 mp(ZEN_CHANGE_ADMIN_OBJECTS, [ZEN_MANAGER_ROLE, MANAGER_ROLE], 1) 175 mp(ZEN_CHANGE_EVENT_VIEWS, [ZEN_MANAGER_ROLE, MANAGER_ROLE], 1) 176 mp(ZEN_ADMIN_DEVICE, [ZEN_MANAGER_ROLE, MANAGER_ROLE], 1) 177 mp(ZEN_MANAGE_DEVICE, [ZEN_MANAGER_ROLE, MANAGER_ROLE], 1) 178 mp(ZEN_ZPROPERTIES_EDIT, [ZEN_MANAGER_ROLE, MANAGER_ROLE], 1) 179 mp(ZEN_ZPROPERTIES_VIEW, 180 [ZEN_MANAGER_ROLE, MANAGER_ROLE, ZEN_USER_ROLE], 1) 181 mp(ZEN_EDIT_LOCAL_TEMPLATES, [ZEN_MANAGER_ROLE, MANAGER_ROLE], 1) 182 mp(ZEN_DEFINE_COMMANDS_EDIT, [ZEN_MANAGER_ROLE, MANAGER_ROLE], 1) 183 mp(ZEN_DEFINE_COMMANDS_VIEW, 184 [ZEN_MANAGER_ROLE, MANAGER_ROLE, ZEN_USER_ROLE], 1) 185 mp(ZEN_MAINTENANCE_WINDOW_EDIT, [ZEN_MANAGER_ROLE, MANAGER_ROLE], 1) 186 mp(ZEN_MAINTENANCE_WINDOW_VIEW, 187 [ZEN_MANAGER_ROLE, MANAGER_ROLE, ZEN_USER_ROLE], 1) 188 mp(ZEN_ADMINISTRATORS_EDIT, [ZEN_MANAGER_ROLE, MANAGER_ROLE], 1) 189 mp(ZEN_ADMINISTRATORS_VIEW, 190 [ZEN_MANAGER_ROLE, MANAGER_ROLE, ZEN_USER_ROLE], 1)
191
192 - def setupDefaultSkins(self, p):
193 from Products.CMFCore.DirectoryView import addDirectoryViews 194 ps = getToolByName(p, 'portal_skins') 195 addDirectoryViews(ps, 'skins', globals()) 196 ps.manage_addProduct['OFSP'].manage_addFolder(id='custom') 197 ps.addSkinSelection('Basic', "custom, zenmodel", make_default=1) 198 p.setupCurrentSkin()
199 200
201 - def setupSessionManager(self, p):
202 """build a session manager and brower id manager for zport""" 203 constructBrowserIdManager(p, cookiepath="/zport") 204 constructSessionDataManager(p, "session_data_manager", 205 title="Session Data Manager", 206 path='/temp_folder/session_data')
207 208
209 - def setup(self, p, create_userfolder):
210 if create_userfolder: 211 self.setupUserFolder(p) 212 #self.setupCookieAuth(p) 213 self.setupTools(p) 214 self.setupMailHost(p) 215 self.setupRoles(p) 216 self.setupPermissions(p) 217 self.setupDefaultSkins(p) 218 self.setupSessionManager(p)
219 220
221 - def create(self, parent, id, create_userfolder):
222 id = str(id) 223 portal = self.klass(id=id) 224 parent._setObject(id, portal) 225 # Return the fully wrapped object. 226 p = parent.this()._getOb(id) 227 self.setup(p, create_userfolder) 228 return p
229 230
231 - def setupDefaultProperties(self, p, title, description, 232 email_from_address, email_from_name, 233 validate_email, 234 ):
235 p._setProperty('email_from_address', email_from_address, 'string') 236 p._setProperty('email_from_name', email_from_name, 'string') 237 p._setProperty('validate_email', validate_email and 1 or 0, 'boolean') 238 p.title = title 239 p.description = description
240 241 242 manage_addZentinelPortal = Globals.HTMLFile('dtml/addPortal', globals()) 243 manage_addZentinelPortal.__name__ = 'addPortal' 244
245 -def manage_addZentinelPortal(self, id="zport", title='Zentinel Portal', 246 description='', 247 create_userfolder=True, 248 email_from_address='postmaster@localhost', 249 email_from_name='Portal Administrator', 250 validate_email=0, RESPONSE=None):
251 ''' 252 Adds a portal instance. 253 ''' 254 gen = PortalGenerator() 255 from string import strip 256 id = strip(id) 257 p = gen.create(self, id, create_userfolder) 258 gen.setupDefaultProperties(p, title, description, 259 email_from_address, email_from_name, 260 validate_email) 261 if RESPONSE is not None: 262 RESPONSE.redirect(self.absolute_url()+'/manage_main')
263