1
2
3
4
5
6
7
8
9
10
11 """MultiCopySupport
12
13 MultiCopySupport over rides manage_pasteObjects in CopySupport to handle
14 cut/past for a MultiItem. Semantics of cut/paste are to remove time from
15 current container and put it in new container but other container mappings
16 remain.
17
18 $Id: RelCopySupport.py,v 1.15 2004/04/13 22:02:18 edahl Exp $"""
19
20 __version__ = '$Revision: 1.15 $'
21
22 import sys
23 from cgi import escape
24
25
26 from OFS.ObjectManager import checkValidId
27 from OFS.CopySupport import CopyContainer, eNotSupported
28
29 from webdav.Lockable import ResourceLockedError
30
31 from Acquisition import aq_base
32 from AccessControl import getSecurityManager
33
34 from OFS import Moniker
35 from OFS.CopySupport import CopyError, _cb_decode, eInvalid, eNotFound, eNoData
36
37 from App.Dialogs import MessageDialog
38
39 from Products.ZenRelations.Exceptions import *
40
42
44 """This method gets called from the new manage_renameObject which
45 seems to be a bug in the Zope code. We add it until the problem is
46 fixed.
47 """
48 checkValidId(self, new_id)
49
50
63
64
65
78
79
80
82 """
83 check to see if this object is allowed to be pasted into this path
84 """
85 pathres = getattr(object, 'relationshipManagerPathRestriction', None)
86 if (pathres and '/'.join(self.getPhysicalPath()).find(pathres) == -1):
87 raise CopyError, MessageDialog(title='Not Supported',
88 message='The object <EM>%s</EM> can not be pasted into' \
89 ' the path <EM>%s</EM>' %
90 (object.id, '/'.join(self.getPhysicalPath())),
91 action='manage_main')
92
93
94
95
96
98 """
99 Return our relationship name from the UI.
100 If there is more than one id defined raise because only one
101 target relationship can be defined. If no ids are defined
102 check to see that we are a ToManyRelationship and return self.id.
103 """
104 if not ids:
105 if self.meta_type == "ToManyRelationship":
106 return self.getId()
107 else:
108 raise ZenRelationsError("No relation name defined")
109 if isinstance(ids, basestring): return ids
110 if len(ids) > 1:
111 raise ZenRelationsError("You can only link to one relationship!")
112 return ids[0]
113
114
116 """
117 When linking check that the user has "Copy or Move" permission
118 on the relation. Can't use _verifyObjectPaste because there
119 is an empty all_meta_types on ToManyRelations which causes it
120 to falsely fail.
121 """
122 if not getSecurityManager().checkPermission('Copy or Move', self):
123 message = ('You do not possess the "Copy or Move" permission in '
124 'the context of the container into which you are '
125 'pasting, thus you are not able to perform '
126 'this operation.')
127 raise CopyError, MessageDialog(title = 'Insufficient Privileges',
128 message = message, action = 'manage_main')
129
130
131
132
134 """get the source objects to link"""
135 cp=None
136 if cb_copy_data is not None:
137 cp=cb_copy_data
138 else:
139 if REQUEST and REQUEST.has_key('__cp'):
140 cp=REQUEST['__cp']
141 if cp is None:
142 raise CopyError, eNoData
143
144 try: cp=_cb_decode(cp)
145 except: raise CopyError, eInvalid
146
147 oblist=[]
148 app = self.getPhysicalRoot()
149
150 for mdata in cp[1]:
151 m = Moniker.loadMoniker(mdata)
152 try: ob = m.bind(app)
153 except: raise CopyError, eNotFound
154 self._verifyObjectLink()
155 oblist.append(ob)
156 return oblist
157