Commit 82696fe5 authored by 's avatar

Added knob to import/export to retain ownership info, changed handling

of ownership for move and rename (ownership not changed).
parent 80bf9f52
...@@ -83,7 +83,7 @@ ...@@ -83,7 +83,7 @@
# #
############################################################################## ##############################################################################
__doc__="""Copy interface""" __doc__="""Copy interface"""
__version__='$Revision: 1.54 $'[11:-2] __version__='$Revision: 1.55 $'[11:-2]
import sys, string, Globals, Moniker, tempfile, ExtensionClass import sys, string, Globals, Moniker, tempfile, ExtensionClass
from marshal import loads, dumps from marshal import loads, dumps
...@@ -236,12 +236,22 @@ class CopyContainer(ExtensionClass.Base): ...@@ -236,12 +236,22 @@ class CopyContainer(ExtensionClass.Base):
action ='manage_main') 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'
# try to make ownership explicit so that it gets carried
# along to the new location if needed.
ob.manage_changeOwnershipType(explicit=1)
ob.aq_parent._delObject(id) ob.aq_parent._delObject(id)
if hasattr(ob, 'aq_base'): if hasattr(ob, 'aq_base'):
ob=ob.aq_base ob=ob.aq_base
id=self._get_id(id) id=self._get_id(id)
ob._setId(id) ob._setId(id)
self._setObject(id, ob)
self._setObject(id, ob, set_owner=0)
# try to make ownership implicit if possible
ob=self._getOb(id)
ob.manage_changeOwnershipType(explicit=0)
if REQUEST is not None: if REQUEST is not None:
REQUEST['RESPONSE'].setCookie('cp_', 'deleted', REQUEST['RESPONSE'].setCookie('cp_', 'deleted',
...@@ -285,9 +295,11 @@ class CopyContainer(ExtensionClass.Base): ...@@ -285,9 +295,11 @@ class CopyContainer(ExtensionClass.Base):
if hasattr(ob, 'aq_base'): if hasattr(ob, 'aq_base'):
ob=ob.aq_base ob=ob.aq_base
ob._setId(new_id) ob._setId(new_id)
self._setObject(new_id, ob)
#ob=ob.__of__(self) # Note - because a rename always keeps the same context, we
#ob._postCopy(self, op=1) # can just leave the ownership info unchanged.
self._setObject(new_id, ob, set_owner=0)
if REQUEST is not None: if REQUEST is not None:
return self.manage_main(self, REQUEST, update_menu=1) return self.manage_main(self, REQUEST, update_menu=1)
return None return None
......
...@@ -84,9 +84,9 @@ ...@@ -84,9 +84,9 @@
############################################################################## ##############################################################################
__doc__="""Object Manager __doc__="""Object Manager
$Id: ObjectManager.py,v 1.97 2000/05/30 20:27:17 brian Exp $""" $Id: ObjectManager.py,v 1.98 2000/06/01 19:58:05 brian Exp $"""
__version__='$Revision: 1.97 $'[11:-2] __version__='$Revision: 1.98 $'[11:-2]
import App.Management, Acquisition, Globals, CopySupport, Products import App.Management, Acquisition, Globals, CopySupport, Products
import os, App.FactoryDispatcher, ts_regex, Products import os, App.FactoryDispatcher, ts_regex, Products
...@@ -234,7 +234,7 @@ class ObjectManager( ...@@ -234,7 +234,7 @@ class ObjectManager(
return default return default
return getattr(self, id) return getattr(self, id)
def _setObject(self,id,object,roles=None,user=None): def _setObject(self,id,object,roles=None,user=None, set_owner=1):
v=self._checkId(id) v=self._checkId(id)
if v is not None: id=v if v is not None: id=v
try: t=object.meta_type try: t=object.meta_type
...@@ -244,17 +244,20 @@ class ObjectManager( ...@@ -244,17 +244,20 @@ class ObjectManager(
object._p_jar = self._p_jar object._p_jar = self._p_jar
self._setOb(id,object) self._setOb(id,object)
object=self._getOb(id) object=self._getOb(id)
object.manage_fixupOwnershipAfterAdd()
if set_owner:
object.manage_fixupOwnershipAfterAdd()
# Try to give user the local role "Owner", but only if
# no local roles have been set on the object yet.
if hasattr(object, '__ac_local_roles__'):
if object.__ac_local_roles__ is None:
user=getSecurityManager().getUser()
name=user.getUserName()
if name != 'Anonymous User':
object.manage_setLocalRoles(name, ['Owner'])
object.manage_afterAdd(object, self) object.manage_afterAdd(object, self)
# Try to give user the local role "Owner", but only if
# no local roles have been set on the object yet.
if hasattr(object, '__ac_local_roles__'):
if object.__ac_local_roles__ is None:
user=getSecurityManager().getUser()
name=user.getUserName()
if name != 'Anonymous User':
object.manage_setLocalRoles(name, ['Owner'])
return id return id
def manage_afterAdd(self, item, container): def manage_afterAdd(self, item, container):
...@@ -437,27 +440,6 @@ class ObjectManager( ...@@ -437,27 +440,6 @@ class ObjectManager(
return r return r
# The Following methods are short-term measures to get Paul off my back;)
def manage_exportHack(self, id=None):
"""Exports a folder and its contents to /var/export.bbe
This file can later be imported by using manage_importHack"""
if id is None: o=self
else: o=self._getOb(id)
f=Globals.data_dir+'/export.bbe'
o._p_jar.exportFile(o._p_oid,f)
return f
def manage_importHack(self, REQUEST=None):
"Imports a previously exported object from /var/export.bbe"
f=Globals.data_dir+'/export.bbe'
o=self._p_jar.importFile(f)
id=o.id
if hasattr(id,'im_func'): id=id()
self._setObject(id,o)
return 'OK, I imported %s' % id
# These methods replace manage_importHack and manage_exportHack
def manage_exportObject(self, id='', download=None, toxml=None, def manage_exportObject(self, id='', download=None, toxml=None,
RESPONSE=None): RESPONSE=None):
"""Exports an object to a file and returns that file.""" """Exports an object to a file and returns that file."""
...@@ -491,7 +473,7 @@ class ObjectManager( ...@@ -491,7 +473,7 @@ class ObjectManager(
manage_importExportForm=HTMLFile('importExport',globals()) manage_importExportForm=HTMLFile('importExport',globals())
def manage_importObject(self, file, REQUEST=None): def manage_importObject(self, file, REQUEST=None, set_owner=1):
"""Import an object from a file""" """Import an object from a file"""
dirname, file=os.path.split(file) dirname, file=os.path.split(file)
if dirname: if dirname:
...@@ -509,7 +491,13 @@ class ObjectManager( ...@@ -509,7 +491,13 @@ class ObjectManager(
if REQUEST: self._verifyObjectPaste(ob, validate_src=0) if REQUEST: self._verifyObjectPaste(ob, validate_src=0)
id=ob.id id=ob.id
if hasattr(id, 'im_func'): id=id() if hasattr(id, 'im_func'): id=id()
self._setObject(id, ob) self._setObject(id, ob, set_owner=set_owner)
# try to make ownership implicit if possible in the context
# that the object was imported into.
ob=self._getOb(id)
ob.manage_changeOwnershipType(explicit=0)
if REQUEST is not None: if REQUEST is not None:
return MessageDialog( return MessageDialog(
title='Object imported', title='Object imported',
......
...@@ -45,13 +45,20 @@ on the server. ...@@ -45,13 +45,20 @@ on the server.
</TABLE> </TABLE>
</FORM> </FORM>
<P> <p>
You may import Zope objects which have been previously You may import Zope objects which have been previously
exported to a file, by placing the file in the &quot;import&quot; exported to a file, by placing the file in the &quot;import&quot;
directory of your Zope installation on the server. You should create directory of your Zope installation on the server. You should create
the &quot;import&quot; directory in the root of your Zope installation the &quot;import&quot; directory in the root of your Zope installation
if it does not yet exist. if it does not yet exist.
</P> </p>
<p>
Note that by default, you will become the owner of the objects
that you are importing. If you wish the imported objects to retain
their existing ownership information, select "retain existing
ownership information".
</p>
<FORM ACTION="manage_importObject" METHOD="POST"> <FORM ACTION="manage_importObject" METHOD="POST">
<TABLE CELLSPACING="2"> <TABLE CELLSPACING="2">
...@@ -62,6 +69,18 @@ if it does not yet exist. ...@@ -62,6 +69,18 @@ if it does not yet exist.
<INPUT TYPE="text" NAME="file" SIZE="25" VALUE=""> <INPUT TYPE="text" NAME="file" SIZE="25" VALUE="">
</TD> </TD>
</TR> </TR>
<TR>
<TH ALIGN="LEFT" VALIGN="TOP">
Ownership
</TH>
<TD ALIGN="LEFT" VALIGN="TOP">
<input type="radio" name="set_owner:int" value="1" checked>
Take ownership of imported objects
<br>
<input type="radio" name="set_owner:int" value="0">
Retain existing ownership information
</TD>
</TR>
<TR> <TR>
<TD></TD> <TD></TD>
<TD><INPUT TYPE="SUBMIT" VALUE="Import"> <TD><INPUT TYPE="SUBMIT" VALUE="Import">
......
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