1
2
3
4
5
6
7
8
9
10
11
12
13
14 """MultiCopySupport
15
16 MultiCopySupport over rides manage_pasteObjects in CopySupport to handle
17 cut/past for a MultiItem. Semantics of cut/paste are to remove time from
18 current container and put it in new container but other container mappings
19 remain.
20
21 $Id: RelCopySupport.py,v 1.15 2004/04/13 22:02:18 edahl Exp $"""
22
23 __version__ = '$Revision: 1.15 $'
24
25 import sys
26 import types
27
28
29 from OFS.ObjectManager import checkValidId
30 from OFS.CopySupport import CopyContainer
31
32 from Acquisition import aq_base
33 from AccessControl import getSecurityManager
34
35 from OFS import Moniker
36 from OFS.CopySupport import CopyError, _cb_decode, eInvalid, eNotFound, eNoData
37
38 from App.Dialogs import MessageDialog
39
40 from Products.ZenRelations.Exceptions import *
41
43
45 """Rename a particular sub-object"""
46 try: checkValidId(self, new_id)
47 except: raise CopyError, MessageDialog(
48 title='Invalid Id',
49 message=sys.exc_info()[1],
50 action ='manage_main')
51 ob=self._getOb(id)
52 if ob.wl_isLocked():
53 raise ResourceLockedError(
54 'Object "%s" is locked via WebDAV' % ob.getId())
55 if not ob.cb_isMoveable():
56 raise CopyError, eNotSupported % escape(id)
57 self._verifyObjectPaste(ob)
58 try: ob._notifyOfCopyTo(self, op=2)
59 except: raise CopyError, MessageDialog(
60 title='Rename Error',
61 message=sys.exc_info()[1],
62 action ='manage_main')
63 self._delObject(id)
64 ob = aq_base(ob)
65 ob._setId(new_id)
66
67
68
69 self._setObject(new_id, ob, set_owner=0)
70 ob = self._getOb(new_id)
71 ob._postCopy(self, op=1)
72
73 if REQUEST is not None:
74 return self.manage_main(self, REQUEST, update_menu=1)
75 return None
76
77
90
91
92
103
104
105
107 """
108 check to see if this object is allowed to be pasted into this path
109 """
110 pathres = getattr(object, 'relationshipManagerPathRestriction', None)
111 if (pathres and '/'.join(self.getPhysicalPath()).find(pathres) == -1):
112 raise CopyError, MessageDialog(title='Not Supported',
113 message='The object <EM>%s</EM> can not be pasted into' \
114 ' the path <EM>%s</EM>' %
115 (object.id, '/'.join(self.getPhysicalPath())),
116 action='manage_main')
117 CopyContainer._verifyObjectPaste(self,object,validate_src)
118
119
121 """
122 Return our relationship name from the UI.
123 If there is more than one id defined raise because only one
124 target relationship can be defined. If no ids are defined
125 check to see that we are a ToManyRelationship and return self.id.
126 """
127 if not ids:
128 if self.meta_type == "ToManyRelationship":
129 return self.getId()
130 else:
131 raise ZenRelationsError("No relation name defined")
132 if type(ids) == types.StringType: return ids
133 if len(ids) > 1:
134 raise ZenRelationsError("You can only link to one relationship!")
135 return ids[0]
136
137
139 """
140 When linking check that the user has "Copy or Move" permission
141 on the relation. Can't use _verifyObjectPaste because there
142 is an empty all_meta_types on ToManyRelations which causes it
143 to falsely fail.
144 """
145 if not getSecurityManager().checkPermission('Copy or Move', self):
146 message = ('You do not possess the "Copy or Move" permission in '
147 'the context of the container into which you are '
148 'pasting, thus you are not able to perform '
149 'this operation.')
150 raise CopyError, MessageDialog(title = 'Insufficient Privileges',
151 message = message, action = 'manage_main')
152
153
154
155
157 """get the source objects to link"""
158 cp=None
159 if cb_copy_data is not None:
160 cp=cb_copy_data
161 else:
162 if REQUEST and REQUEST.has_key('__cp'):
163 cp=REQUEST['__cp']
164 if cp is None:
165 raise CopyError, eNoData
166
167 try: cp=_cb_decode(cp)
168 except: raise CopyError, eInvalid
169
170 oblist=[]
171 op=cp[0]
172 app = self.getPhysicalRoot()
173
174 for mdata in cp[1]:
175 m = Moniker.loadMoniker(mdata)
176 try: ob = m.bind(app)
177 except: raise CopyError, eNotFound
178 self._verifyObjectLink()
179 oblist.append(ob)
180 return oblist
181