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 from cgi import escape
27
28
29 from OFS.ObjectManager import checkValidId
30 from OFS.CopySupport import CopyContainer, eNotSupported
31
32 from webdav.Lockable import ResourceLockedError
33
34 from Acquisition import aq_base
35 from AccessControl import getSecurityManager
36
37 from OFS import Moniker
38 from OFS.CopySupport import CopyError, _cb_decode, eInvalid, eNotFound, eNoData
39
40 from App.Dialogs import MessageDialog
41
42 from Products.ZenRelations.Exceptions import *
43
45
47 """This method gets called from the new manage_renameObject which
48 seems to be a bug in the Zope code. We add it until the problem is
49 fixed.
50 """
51 checkValidId(self, new_id)
52
53
66
67
68
81
82
83
85 """
86 check to see if this object is allowed to be pasted into this path
87 """
88 pathres = getattr(object, 'relationshipManagerPathRestriction', None)
89 if (pathres and '/'.join(self.getPhysicalPath()).find(pathres) == -1):
90 raise CopyError, MessageDialog(title='Not Supported',
91 message='The object <EM>%s</EM> can not be pasted into' \
92 ' the path <EM>%s</EM>' %
93 (object.id, '/'.join(self.getPhysicalPath())),
94 action='manage_main')
95
96
97
98
99
101 """
102 Return our relationship name from the UI.
103 If there is more than one id defined raise because only one
104 target relationship can be defined. If no ids are defined
105 check to see that we are a ToManyRelationship and return self.id.
106 """
107 if not ids:
108 if self.meta_type == "ToManyRelationship":
109 return self.getId()
110 else:
111 raise ZenRelationsError("No relation name defined")
112 if isinstance(ids, basestring): return ids
113 if len(ids) > 1:
114 raise ZenRelationsError("You can only link to one relationship!")
115 return ids[0]
116
117
119 """
120 When linking check that the user has "Copy or Move" permission
121 on the relation. Can't use _verifyObjectPaste because there
122 is an empty all_meta_types on ToManyRelations which causes it
123 to falsely fail.
124 """
125 if not getSecurityManager().checkPermission('Copy or Move', self):
126 message = ('You do not possess the "Copy or Move" permission in '
127 'the context of the container into which you are '
128 'pasting, thus you are not able to perform '
129 'this operation.')
130 raise CopyError, MessageDialog(title = 'Insufficient Privileges',
131 message = message, action = 'manage_main')
132
133
134
135
137 """get the source objects to link"""
138 cp=None
139 if cb_copy_data is not None:
140 cp=cb_copy_data
141 else:
142 if REQUEST and REQUEST.has_key('__cp'):
143 cp=REQUEST['__cp']
144 if cp is None:
145 raise CopyError, eNoData
146
147 try: cp=_cb_decode(cp)
148 except: raise CopyError, eInvalid
149
150 oblist=[]
151 app = self.getPhysicalRoot()
152
153 for mdata in cp[1]:
154 m = Moniker.loadMoniker(mdata)
155 try: ob = m.bind(app)
156 except: raise CopyError, eNotFound
157 self._verifyObjectLink()
158 oblist.append(ob)
159 return oblist
160