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 from cgi import escape
28
29
30 from OFS.ObjectManager import checkValidId
31 from OFS.CopySupport import CopyContainer, eNotSupported
32
33 from webdav.Lockable import ResourceLockedError
34
35 from Acquisition import aq_base
36 from AccessControl import getSecurityManager
37
38 from OFS import Moniker
39 from OFS.CopySupport import CopyError, _cb_decode, eInvalid, eNotFound, eNoData
40
41 from App.Dialogs import MessageDialog
42
43 from Products.ZenRelations.Exceptions import *
44
46
48 """Rename a particular sub-object"""
49 try:
50 checkValidId(self, new_id)
51 except:
52 raise CopyError, sys.exc_info()[1]
53
54 ob=self._getOb(id)
55 if ob.wl_isLocked():
56 raise ResourceLockedError(
57 'Object "%s" is locked via WebDAV' % ob.getId())
58 if not ob.cb_isMoveable():
59 raise CopyError, eNotSupported % escape(id)
60 self._verifyObjectPaste(ob)
61
62 try:
63 ob._notifyOfCopyTo(self, op=2)
64 except:
65 raise CopyError, sys.exc_info()[1]
66 self._delObject(id)
67 ob = aq_base(ob)
68 ob._setId(new_id)
69
70
71
72 self._setObject(new_id, ob, set_owner=0)
73 ob = self._getOb(new_id)
74 ob._postCopy(self, op=1)
75
76 if REQUEST is not None:
77 return self.manage_main(self, REQUEST, update_menu=1)
78 return None
79
80
93
94
95
108
109
110
112 """
113 check to see if this object is allowed to be pasted into this path
114 """
115 pathres = getattr(object, 'relationshipManagerPathRestriction', None)
116 if (pathres and '/'.join(self.getPhysicalPath()).find(pathres) == -1):
117 raise CopyError, MessageDialog(title='Not Supported',
118 message='The object <EM>%s</EM> can not be pasted into' \
119 ' the path <EM>%s</EM>' %
120 (object.id, '/'.join(self.getPhysicalPath())),
121 action='manage_main')
122 CopyContainer._verifyObjectPaste(self,object,validate_src)
123
124
126 """
127 Return our relationship name from the UI.
128 If there is more than one id defined raise because only one
129 target relationship can be defined. If no ids are defined
130 check to see that we are a ToManyRelationship and return self.id.
131 """
132 if not ids:
133 if self.meta_type == "ToManyRelationship":
134 return self.getId()
135 else:
136 raise ZenRelationsError("No relation name defined")
137 if type(ids) == types.StringType: return ids
138 if len(ids) > 1:
139 raise ZenRelationsError("You can only link to one relationship!")
140 return ids[0]
141
142
144 """
145 When linking check that the user has "Copy or Move" permission
146 on the relation. Can't use _verifyObjectPaste because there
147 is an empty all_meta_types on ToManyRelations which causes it
148 to falsely fail.
149 """
150 if not getSecurityManager().checkPermission('Copy or Move', self):
151 message = ('You do not possess the "Copy or Move" permission in '
152 'the context of the container into which you are '
153 'pasting, thus you are not able to perform '
154 'this operation.')
155 raise CopyError, MessageDialog(title = 'Insufficient Privileges',
156 message = message, action = 'manage_main')
157
158
159
160
162 """get the source objects to link"""
163 cp=None
164 if cb_copy_data is not None:
165 cp=cb_copy_data
166 else:
167 if REQUEST and REQUEST.has_key('__cp'):
168 cp=REQUEST['__cp']
169 if cp is None:
170 raise CopyError, eNoData
171
172 try: cp=_cb_decode(cp)
173 except: raise CopyError, eInvalid
174
175 oblist=[]
176 app = self.getPhysicalRoot()
177
178 for mdata in cp[1]:
179 m = Moniker.loadMoniker(mdata)
180 try: ob = m.bind(app)
181 except: raise CopyError, eNotFound
182 self._verifyObjectLink()
183 oblist.append(ob)
184 return oblist
185