Commit 0dff010f authored by Denis Laxalde's avatar Denis Laxalde
Browse files

[hooks] Delete binary DO when deleting an archive unit not related to a profile

We extend the logic of "seda.doref.del" hook so that it not only handles
the case of "simplified profile" but also the case of archive unit not
related to a profile. In the later case, we check that the container of
"SEDABinaryDataObject" is really a "SEDAArchiveUnit" (not sure what else
it could be) and trigger the operation deleting the binary data-object
when its parent object reference (SEDADataObjectReference entity) is

Accordingly, we rename hook and operation classes and update their

This resolves CONSEJIRA-643 but making deletion of an archive unit
containing a binary data object but not related to profile. New test
goes into below other tests related to the hook we
parent 049322b9d8ee
......@@ -298,9 +298,9 @@ class SimplifiedProfileSyncDORefCardOp(hook.Operation):
class SimplifiedProfileDelRefROHook(hook.Hook):
class DeleleBDOWhenDeletingDORefHook(hook.Hook):
"""Hook triggering an operation to delete the data object associated to a
reference when the later is deleted from a simplified profile.
reference when the later is deleted from a simplified profile or an archive unit.
__regid__ = 'seda.doref.del'
__select__ = hook.Hook.__select__ & hook.match_rtype('seda_data_object_reference_id')
......@@ -314,13 +314,17 @@ class SimplifiedProfileDelRefROHook(hook.Hook):
container = bdo.seda_binary_data_object[0]
if not container.simplified_profile:
SimplifiedProfileDelRefROOp(self._cw, do_ref=ref, do=bdo)
if not bdo.container or bdo.container[0].cw_etype != 'SEDAArchiveUnit':
DeleleBDOAlongWithDORefOp(self._cw, do_ref=ref, do=bdo)
class SimplifiedProfileDelRefROOp(hook.Operation):
class DeleleBDOAlongWithDORefOp(hook.Operation):
"""Delete data object whose former reference has been deleted in the
transaction. Expected to be run only if the profile is a simplified
profile or if the data object is related to an archive unit not itself
related to profile.
def precommit_event(self):
......@@ -279,6 +279,19 @@ class SchemaTC(CubicWebTC):
len(cnx.execute('Any X WHERE X eid %(x)s', {'x': bdo.eid})),
0 if simplified else 1)
def test_delete_archiveunit_with_data_object(self):
"""Make sure deletion of an archive unit with a binary data object,
but not related to an archive transfer is possible.
with self.admin_access.cnx() as cnx:
unit, unit_alt, unit_alt_seq = testutils.create_archive_unit(None, cnx=cnx)
bdo = testutils.create_data_object(unit_alt_seq)
self.assertFalse(cnx.execute('Any X WHERE X eid %(x)s', {'x': bdo.eid}))
class SecurityTC(CubicWebTC):
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