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