1
2
3
4
5
6
7
8
9
10
11
12
13
14 from sets import Set
15 import os, md5
16 from Globals import InitializeClass, DevelopmentMode
17 from AccessControl import getSecurityManager
18 from OFS.SimpleItem import SimpleItem
19 from OFS.PropertyManager import PropertyManager
20 from Acquisition import aq_base
21 from Products.ZenRelations.RelSchema import *
22 from Products.ZenModel.ZenModelRM import ZenModelRM
23
24 from Products.ZenModel.ZenossSecurity import *
25
26 from Portlet import Portlet
27
28 getuid = lambda:md5.md5(os.urandom(10)).hexdigest()[:8]
29
31
41
43 """
44 A registry for portlet source and metadata. Provides access functions and
45 handles portlet permissions.
46 """
47
48 portal_type = meta_type = 'PortletManager'
49
50 _relations = (
51 ("portlets", ToManyCont(ToOne, "Products.ZenWidgets.Portlet",
52 "portletManager")),
53 )
54
65
70
72 """
73 Looks up in the registry and returns all portlet objects to which the
74 current user has access.
75 """
76 user = getSecurityManager().getUser()
77 dmd = self.dmd.primaryAq()
78 return filter(
79 lambda x:user.has_permission(x.permission, dmd) and x.check(),
80 self.portlets())
81
82 - def find(self, id='', sourcepath=''):
83 """
84 Look for a registered portlet with an id or source path.
85 """
86 for portlet in self.portlets():
87 if portlet.id==id or portlet.sourcepath==sourcepath: return portlet
88 return None
89
91 """
92 Return the source of the portlets permitted to this user as a
93 javascript file.
94 """
95 srcs = [x.get_source(DevelopmentMode) for x in self.get_portlets()]
96 srcs.append('YAHOO.register("portletsource", YAHOO.zenoss.portlet, {})')
97 if REQUEST:
98 REQUEST.response.headers['Content-Type'] = 'text/javascript'
99 return '\n'.join(srcs)
100
102 """
103 blargh
104 """
105 for portlet in REQUEST.form:
106 if not portlet.endswith('_permission'): continue
107 portname = portlet.split('_')[0]
108 p = self.find(id=portname)
109 p.permission = REQUEST.form[portlet]
110 if REQUEST:
111 from Products.ZenUtils.Time import SaveMessage
112 REQUEST['message'] = SaveMessage()
113 REQUEST['RESPONSE'].redirect('/zport/dmd/editPortletPerms')
114
115
116 InitializeClass(PortletManager)
117