Commit 0947e7fd authored by Hanno Schlichting's avatar Hanno Schlichting

Remove MessageDialog return values from CopySupport.

parent 05c6a413
...@@ -32,7 +32,7 @@ Restructuring ...@@ -32,7 +32,7 @@ Restructuring
- Remove property management ZMI screens. - Remove property management ZMI screens.
- Remove ZMI copy/cut/paste and re-ordering features. - Remove ZMI copy/cut/paste/rename and re-ordering features.
- Drop `OFS.History` functionality. - Drop `OFS.History` functionality.
......
...@@ -13,11 +13,9 @@ ...@@ -13,11 +13,9 @@
"""Copy interface """Copy interface
""" """
from cgi import escape
from marshal import dumps from marshal import dumps
from marshal import loads from marshal import loads
import re import re
import sys
import tempfile import tempfile
from urllib import quote from urllib import quote
from urllib import unquote from urllib import unquote
...@@ -35,9 +33,6 @@ from AccessControl.Permissions import delete_objects ...@@ -35,9 +33,6 @@ from AccessControl.Permissions import delete_objects
from Acquisition import aq_base from Acquisition import aq_base
from Acquisition import aq_inner from Acquisition import aq_inner
from Acquisition import aq_parent from Acquisition import aq_parent
from App.Dialogs import MessageDialog
from App.special_dtml import HTML
from App.special_dtml import DTMLFile
from ExtensionClass import Base from ExtensionClass import Base
from zExceptions import Unauthorized, BadRequest, ResourceLockedError from zExceptions import Unauthorized, BadRequest, ResourceLockedError
from ZODB.POSException import ConflictError from ZODB.POSException import ConflictError
...@@ -97,7 +92,7 @@ class CopyContainer(Base): ...@@ -97,7 +92,7 @@ class CopyContainer(Base):
def manage_cutObjects(self, ids=None, REQUEST=None): def manage_cutObjects(self, ids=None, REQUEST=None):
"""Put a reference to the objects named in ids in the clip board""" """Put a reference to the objects named in ids in the clip board"""
if ids is None and REQUEST is not None: if ids is None and REQUEST is not None:
return eNoItemsSpecified raise BadRequest('No items specified')
elif ids is None: elif ids is None:
raise ValueError('ids must be specified') raise ValueError('ids must be specified')
...@@ -111,20 +106,18 @@ class CopyContainer(Base): ...@@ -111,20 +106,18 @@ class CopyContainer(Base):
raise ResourceLockedError('Object "%s" is locked' % ob.getId()) raise ResourceLockedError('Object "%s" is locked' % ob.getId())
if not ob.cb_isMoveable(): if not ob.cb_isMoveable():
raise CopyError(eNotSupported % escape(id)) raise CopyError('Not Supported')
m = Moniker(ob) m = Moniker(ob)
oblist.append(m.dump()) oblist.append(m.dump())
cp = (1, oblist) cp = (1, oblist)
cp = _cb_encode(cp) cp = _cb_encode(cp)
if REQUEST is not None:
return self.manage_main(self, REQUEST)
return cp return cp
security.declareProtected(view_management_screens, 'manage_copyObjects') security.declareProtected(view_management_screens, 'manage_copyObjects')
def manage_copyObjects(self, ids=None, REQUEST=None, RESPONSE=None): def manage_copyObjects(self, ids=None, REQUEST=None, RESPONSE=None):
"""Put a reference to the objects named in ids in the clip board""" """Put a reference to the objects named in ids in the clip board"""
if ids is None and REQUEST is not None: if ids is None and REQUEST is not None:
return eNoItemsSpecified raise BadRequest('No items specified')
elif ids is None: elif ids is None:
raise ValueError('ids must be specified') raise ValueError('ids must be specified')
...@@ -134,13 +127,11 @@ class CopyContainer(Base): ...@@ -134,13 +127,11 @@ class CopyContainer(Base):
for id in ids: for id in ids:
ob = self._getOb(id) ob = self._getOb(id)
if not ob.cb_isCopyable(): if not ob.cb_isCopyable():
raise CopyError(eNotSupported % escape(id)) raise CopyError('Not Supported')
m = Moniker(ob) m = Moniker(ob)
oblist.append(m.dump()) oblist.append(m.dump())
cp = (0, oblist) cp = (0, oblist)
cp = _cb_encode(cp) cp = _cb_encode(cp)
if REQUEST is not None:
return self.manage_main(self, REQUEST)
return cp return cp
def _get_id(self, id): def _get_id(self, id):
...@@ -173,12 +164,12 @@ class CopyContainer(Base): ...@@ -173,12 +164,12 @@ class CopyContainer(Base):
""" """
cp = cb_copy_data cp = cb_copy_data
if cp is None: if cp is None:
raise CopyError(eNoData) raise CopyError('No clipboard data found.')
try: try:
op, mdatas = _cb_decode(cp) op, mdatas = _cb_decode(cp)
except Exception: except Exception:
raise CopyError(eInvalid) raise CopyError('Clipboard Error')
oblist = [] oblist = []
app = self.getPhysicalRoot() app = self.getPhysicalRoot()
...@@ -189,7 +180,7 @@ class CopyContainer(Base): ...@@ -189,7 +180,7 @@ class CopyContainer(Base):
except ConflictError: except ConflictError:
raise raise
except Exception: except Exception:
raise CopyError(eNotFound) raise CopyError('Item Not Found')
self._verifyObjectPaste(ob, validate_src=op + 1) self._verifyObjectPaste(ob, validate_src=op + 1)
oblist.append(ob) oblist.append(ob)
...@@ -199,17 +190,14 @@ class CopyContainer(Base): ...@@ -199,17 +190,14 @@ class CopyContainer(Base):
for ob in oblist: for ob in oblist:
orig_id = ob.getId() orig_id = ob.getId()
if not ob.cb_isCopyable(): if not ob.cb_isCopyable():
raise CopyError(eNotSupported % escape(orig_id)) raise CopyError('Not Supported')
try: try:
ob._notifyOfCopyTo(self, op=0) ob._notifyOfCopyTo(self, op=0)
except ConflictError: except ConflictError:
raise raise
except Exception: except Exception:
raise CopyError(MessageDialog( raise CopyError('Copy Error')
title="Copy Error",
message=sys.exc_info()[1],
action='manage_main'))
id = self._get_id(orig_id) id = self._get_id(orig_id)
result.append({'id': orig_id, 'new_id': id}) result.append({'id': orig_id, 'new_id': id})
...@@ -229,25 +217,19 @@ class CopyContainer(Base): ...@@ -229,25 +217,19 @@ class CopyContainer(Base):
notify(ObjectClonedEvent(ob)) notify(ObjectClonedEvent(ob))
if REQUEST is not None:
return self.manage_main(self, REQUEST)
elif op == 1: elif op == 1:
# Move operation # Move operation
for ob in oblist: for ob in oblist:
orig_id = ob.getId() orig_id = ob.getId()
if not ob.cb_isMoveable(): if not ob.cb_isMoveable():
raise CopyError(eNotSupported % escape(orig_id)) raise CopyError('Not Supported')
try: try:
ob._notifyOfCopyTo(self, op=1) ob._notifyOfCopyTo(self, op=1)
except ConflictError: except ConflictError:
raise raise
except Exception: except Exception:
raise CopyError(MessageDialog( raise CopyError('Move Error')
title="Move Error",
message=sys.exc_info()[1],
action='manage_main'))
if not sanity_check(self, ob): if not sanity_check(self, ob):
raise CopyError("This object cannot be pasted into itself") raise CopyError("This object cannot be pasted into itself")
...@@ -295,14 +277,8 @@ class CopyContainer(Base): ...@@ -295,14 +277,8 @@ class CopyContainer(Base):
# try to make ownership implicit if possible # try to make ownership implicit if possible
ob.manage_changeOwnershipType(explicit=0) ob.manage_changeOwnershipType(explicit=0)
if REQUEST is not None:
return self.manage_main(self, REQUEST)
return result return result
security.declareProtected(view_management_screens, 'manage_renameForm')
manage_renameForm = DTMLFile('dtml/renameForm', globals())
security.declareProtected(view_management_screens, 'manage_renameObjects') security.declareProtected(view_management_screens, 'manage_renameObjects')
def manage_renameObjects(self, ids=[], new_ids=[], REQUEST=None): def manage_renameObjects(self, ids=[], new_ids=[], REQUEST=None):
"""Rename several sub-objects""" """Rename several sub-objects"""
...@@ -311,9 +287,6 @@ class CopyContainer(Base): ...@@ -311,9 +287,6 @@ class CopyContainer(Base):
for i in range(len(ids)): for i in range(len(ids)):
if ids[i] != new_ids[i]: if ids[i] != new_ids[i]:
self.manage_renameObject(ids[i], new_ids[i], REQUEST) self.manage_renameObject(ids[i], new_ids[i], REQUEST)
if REQUEST is not None:
return self.manage_main(self, REQUEST)
return None
security.declareProtected(view_management_screens, 'manage_renameObject') security.declareProtected(view_management_screens, 'manage_renameObject')
def manage_renameObject(self, id, new_id, REQUEST=None): def manage_renameObject(self, id, new_id, REQUEST=None):
...@@ -322,17 +295,14 @@ class CopyContainer(Base): ...@@ -322,17 +295,14 @@ class CopyContainer(Base):
try: try:
self._checkId(new_id) self._checkId(new_id)
except Exception: except Exception:
raise CopyError(MessageDialog( raise CopyError('Invalid Id')
title='Invalid Id',
message=sys.exc_info()[1],
action='manage_main'))
ob = self._getOb(id) ob = self._getOb(id)
if ob.wl_isLocked(): if ob.wl_isLocked():
raise ResourceLockedError('Object "%s" is locked' % ob.getId()) raise ResourceLockedError('Object "%s" is locked' % ob.getId())
if not ob.cb_isMoveable(): if not ob.cb_isMoveable():
raise CopyError(eNotSupported % escape(id)) raise CopyError('Not Supported')
self._verifyObjectPaste(ob) self._verifyObjectPaste(ob)
try: try:
...@@ -340,10 +310,7 @@ class CopyContainer(Base): ...@@ -340,10 +310,7 @@ class CopyContainer(Base):
except ConflictError: except ConflictError:
raise raise
except Exception: except Exception:
raise CopyError(MessageDialog( raise CopyError('Rename Error')
title="Rename Error",
message=sys.exc_info()[1],
action='manage_main'))
notify(ObjectWillBeMovedEvent(ob, self, id, self, new_id)) notify(ObjectWillBeMovedEvent(ob, self, id, self, new_id))
...@@ -373,28 +340,16 @@ class CopyContainer(Base): ...@@ -373,28 +340,16 @@ class CopyContainer(Base):
ob._postCopy(self, op=1) ob._postCopy(self, op=1)
if REQUEST is not None:
return self.manage_main(self, REQUEST)
return None
# Why did we give this a manage_ prefix if its really
# supposed to be public since it does its own auth ?
#
# Because it's still a "management" function.
security.declarePublic('manage_clone') security.declarePublic('manage_clone')
def manage_clone(self, ob, id, REQUEST=None): def manage_clone(self, ob, id, REQUEST=None):
"""Clone an object, creating a new object with the given id. """Clone an object, creating a new object with the given id.
""" """
if not ob.cb_isCopyable(): if not ob.cb_isCopyable():
raise CopyError(eNotSupported % escape(ob.getId())) raise CopyError('Not Supported')
try: try:
self._checkId(id) self._checkId(id)
except Exception: except Exception:
raise CopyError(MessageDialog( raise CopyError('Invalid Id')
title='Invalid Id',
message=sys.exc_info()[1],
action='manage_main'))
self._verifyObjectPaste(ob) self._verifyObjectPaste(ob)
...@@ -403,10 +358,7 @@ class CopyContainer(Base): ...@@ -403,10 +358,7 @@ class CopyContainer(Base):
except ConflictError: except ConflictError:
raise raise
except Exception: except Exception:
raise CopyError(MessageDialog( raise CopyError('Clone Error')
title="Clone Error",
message=sys.exc_info()[1],
action='manage_main'))
orig_ob = ob orig_ob = ob
ob = ob._getCopy(self) ob = ob._getCopy(self)
...@@ -440,17 +392,10 @@ class CopyContainer(Base): ...@@ -440,17 +392,10 @@ class CopyContainer(Base):
# heirarchy). # heirarchy).
if not hasattr(object, 'meta_type'): if not hasattr(object, 'meta_type'):
raise CopyError(MessageDialog( raise CopyError('Not Supported')
title='Not Supported',
message=('The object <em>%s</em> does not support this '
'operation' % escape(absattr(object.id))),
action='manage_main'))
if not hasattr(self, 'all_meta_types'): if not hasattr(self, 'all_meta_types'):
raise CopyError(MessageDialog( raise CopyError('Cannot paste into this object.')
title='Not Supported',
message='Cannot paste into this object.',
action='manage_main'))
mt_permission = None mt_permission = None
meta_types = absattr(self.all_meta_types) meta_types = absattr(self.all_meta_types)
...@@ -479,19 +424,9 @@ class CopyContainer(Base): ...@@ -479,19 +424,9 @@ class CopyContainer(Base):
if not sm.checkPermission(delete_objects, parent): if not sm.checkPermission(delete_objects, parent):
raise Unauthorized('Delete not allowed.') raise Unauthorized('Delete not allowed.')
else: else:
raise CopyError(MessageDialog( raise CopyError('Insufficient privileges')
title='Insufficient Privileges',
message=('You do not possess the %s permission in the '
'context of the container into which you are '
'pasting, thus you are not able to perform '
'this operation.' % mt_permission),
action='manage_main'))
else: else:
raise CopyError(MessageDialog( raise CopyError('Not Supported')
title='Not Supported',
message=('The object <em>%s</em> does not support this '
'operation.' % escape(absattr(object.id))),
action='manage_main'))
InitializeClass(CopyContainer) InitializeClass(CopyContainer)
...@@ -614,77 +549,3 @@ def _cb_decode(s, maxsize=8192): ...@@ -614,77 +549,3 @@ def _cb_decode(s, maxsize=8192):
if dec.unconsumed_tail: if dec.unconsumed_tail:
raise ValueError raise ValueError
return loads(data) return loads(data)
fMessageDialog = HTML("""
<HTML>
<HEAD>
<TITLE>&dtml-title;</TITLE>
</HEAD>
<BODY BGCOLOR="#FFFFFF">
<FORM ACTION="&dtml-action;" METHOD="GET" <dtml-if
target>TARGET="&dtml-target;"</dtml-if>>
<TABLE BORDER="0" WIDTH="100%%" CELLPADDING="10">
<TR>
<TD VALIGN="TOP">
<BR>
<CENTER><B><FONT SIZE="+6" COLOR="#77003B">!</FONT></B></CENTER>
</TD>
<TD VALIGN="TOP">
<BR><BR>
<CENTER>
<dtml-var message>
</CENTER>
</TD>
</TR>
<TR>
<TD VALIGN="TOP">
</TD>
<TD VALIGN="TOP">
<CENTER>
<INPUT TYPE="SUBMIT" VALUE=" Ok ">
</CENTER>
</TD>
</TR>
</TABLE>
</FORM>
</BODY></HTML>""", target='', action='manage_main', title='Changed')
eNoData = MessageDialog(
title='No Data',
message='No clipboard data found.',
action='manage_main')
eInvalid = MessageDialog(
title='Clipboard Error',
message='The data in the clipboard could not be read, possibly due '
'to cookie data being truncated by your web browser. Try copying '
'fewer objects.',
action='manage_main')
eNotFound = MessageDialog(
title='Item Not Found',
message='One or more items referred to in the clipboard data was '
'not found. The item may have been moved or deleted after you '
'copied it.',
action='manage_main')
eNotSupported = fMessageDialog(
title='Not Supported',
message=(
'The action against the <em>%s</em> object could not be carried '
'out. '
'One of the following constraints caused the problem: <br><br>'
'The object does not support this operation.'
'<br><br>-- OR --<br><br>'
'The currently logged-in user does not have the <b>Copy or '
'Move</b> permission respective to the object.'
),
action='manage_main')
eNoItemsSpecified = MessageDialog(
title='No items specified',
message='You must select one or more items to perform '
'this operation.',
action='manage_main')
<dtml-var manage_page_header>
<dtml-var "manage_form_title(this(), _,
form_title='Rename Items',
)">
<dtml-if expr="REQUEST.has_key('ids')">
<form action="<dtml-var "REQUEST.URL1" html_quote>" method="post">
<table border="0">
<dtml-in expr="manage_CopyContainerAllItems(REQUEST)">
<tr>
<td align="left" valign="bottom" width="16"></td>
<td align="left" valign="bottom">
<div class="form-text">
&dtml-id;
</div>
</td>
<td align="left" valign="bottom">
<dtml-if cb_isMoveable>
<span class="form-text">to:</span>
<input type="hidden" name="ids:list" value="&dtml-id;" />
<input type="text" name="new_ids:list" size="<dtml-var "_.max(40,_.len(getId())+4)">" value="&dtml-id;" />
<dtml-else>
<span class="form-text">
may not be renamed.
</span>
</dtml-if>
</td>
</tr>
</dtml-in>
<tr>
<td></td>
<td colspan="2">
<div class="form-element">
<input class="form-element" type="hidden" name=":default_method"
value="manage_renameObjects" />
<input class="form-element" type="submit" name="manage_renameObjects:method"
value=" Ok " />
<input class="form-element" type="submit" name="manage_main:method"
value="Cancel" />
</div>
</td>
</tr>
</table>
</form>
<dtml-else>
<form action="manage_main" method="get">
<p align="center">
<br /><br />
<span class="form-text">
You must select an item to rename.
</span>
<br /><br />
<input class="form-element" type="submit" name="submit" value=" Ok " />
</p>
</form>
</dtml-if>
<dtml-var manage_page_footer>
...@@ -597,8 +597,6 @@ class ICopyContainer(Interface): ...@@ -597,8 +597,6 @@ class ICopyContainer(Interface):
argument. argument.
""" """
manage_renameForm = Attribute("""Rename management view""")
def manage_renameObjects(ids=[], new_ids=[], REQUEST=None): def manage_renameObjects(ids=[], new_ids=[], REQUEST=None):
"""Rename several sub-objects""" """Rename several sub-objects"""
......
...@@ -334,21 +334,15 @@ class TestCopySupportSecurity(CopySupportTestBase): ...@@ -334,21 +334,15 @@ class TestCopySupportSecurity(CopySupportTestBase):
try: try:
callable(*args, **kw) callable(*args, **kw)
except CopyError as e: except CopyError as e:
if ce_regex is not None: if ce_regex is not None:
pattern = re.compile(ce_regex, re.DOTALL) pattern = re.compile(ce_regex, re.DOTALL)
if pattern.search(e.args[0]) is None: if pattern.search(e.args[0]) is None:
self.fail("Paste failed; didn't match pattern:\n%s" % e) self.fail("Paste failed; didn't match pattern:\n%s" % e)
else: else:
self.fail("Paste failed; no pattern:\n%s" % e) self.fail("Paste failed; no pattern:\n%s" % e)
except Unauthorized: except Unauthorized:
pass pass
else: else:
self.fail("Paste allowed unexpectedly.") self.fail("Paste allowed unexpectedly.")
...@@ -464,7 +458,7 @@ class TestCopySupportSecurity(CopySupportTestBase): ...@@ -464,7 +458,7 @@ class TestCopySupportSecurity(CopySupportTestBase):
cookie = folder1.manage_cutObjects(ids=('file', )) cookie = folder1.manage_cutObjects(ids=('file', ))
self._assertCopyErrorUnauth( self._assertCopyErrorUnauth(
folder2.manage_pasteObjects, cookie, folder2.manage_pasteObjects, cookie,
ce_regex='Insufficient Privileges.*%s' % ADD_IMAGES_AND_FILES) ce_regex='Insufficient privileges')
def test_move_cant_delete_source(self): def test_move_cant_delete_source(self):
from AccessControl.Permissions import delete_objects from AccessControl.Permissions import delete_objects
...@@ -481,4 +475,4 @@ class TestCopySupportSecurity(CopySupportTestBase): ...@@ -481,4 +475,4 @@ class TestCopySupportSecurity(CopySupportTestBase):
cookie = folder1.manage_cutObjects(ids=('file', )) cookie = folder1.manage_cutObjects(ids=('file', ))
self._assertCopyErrorUnauth( self._assertCopyErrorUnauth(
folder2.manage_pasteObjects, cookie, folder2.manage_pasteObjects, cookie,
ce_regex='Insufficient Privileges.*%s' % delete_objects) ce_regex='Insufficient privileges')
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment