1
2
3
4
5
6
7
8
9
10
11
12
13
14 import os, md5
15 from Globals import InitializeClass, DevelopmentMode
16 from AccessControl import getSecurityManager
17 from Products.ZenRelations.RelSchema import *
18 from Products.ZenModel.ZenModelRM import ZenModelRM
19
20 from Products.ZenModel.ZenossSecurity import *
21 from Products.ZenWidgets import messaging
22
23 from Portlet import Portlet
24
25 getuid = lambda:md5.md5(os.urandom(10)).hexdigest()[:8]
26
28
38
40 """
41 A registry for portlet source and metadata. Provides access functions and
42 handles portlet permissions.
43 """
44
45 portal_type = meta_type = 'PortletManager'
46
47 _relations = (
48 ("portlets", ToManyCont(ToOne, "Products.ZenWidgets.Portlet",
49 "portletManager")),
50 )
51
62
67
69 """
70 Looks up in the registry and returns all portlet objects to which the
71 current user has access.
72 """
73 user = getSecurityManager().getUser()
74 dmd = self.dmd.primaryAq()
75 return filter(
76 lambda x:user.has_permission(x.permission, dmd) and x.check(),
77 self.portlets())
78
79 - def find(self, id='', sourcepath=''):
80 """
81 Look for a registered portlet with an id or source path.
82 """
83 for portlet in self.portlets():
84 if portlet.id==id or portlet.sourcepath==sourcepath: return portlet
85 return None
86
88 """
89 Reread the source files for all portlets.
90 """
91 for portlet in self.portlets():
92 portlet._read_source()
93
95 """
96 Return the source of the portlets permitted to this user as a
97 javascript file.
98 """
99 srcs = [x.get_source(DevelopmentMode) for x in self.get_portlets()]
100 srcs.append('YAHOO.register("portletsource", YAHOO.zenoss.portlet, {})')
101 if REQUEST:
102 REQUEST.response.headers['Content-Type'] = 'text/javascript'
103 return '\n'.join(srcs)
104
121
122
123 InitializeClass(PortletManager)
124