Commit 7a95a4c4 authored by Sylvain Thénault's avatar Sylvain Thénault
Browse files

[hook] Fix dispatching for file_category to format_id / mime_type on import of...

[hook] Fix dispatching for file_category to format_id / mime_type on import of an archive unit component

by changing related hook's category to metadata, since others are deactivated
during sub-tree cloning.
parent 1662ae046c78
......@@ -520,6 +520,11 @@ class SyncFileCategoryOp(hook.DataOperationMixIn, hook.LateOperation):
def precommit_event(self):
for bdo_eid in self.get_data():
bdo = self.cnx.entity_from_eid(bdo_eid)
if not bdo.container:
# we may have to clear the container cache if the parent has
# been added in the same transaction
bdo.cw_clear_relation_cache('container', 'subject')
container = bdo.cw_adapt_to('IContained').container
if container.cw_etype != 'SEDAArchiveTransfer':
# don't afford doing this in components which are not bound to
......@@ -551,6 +556,7 @@ class SyncFileCategoryHook(hook.Hook):
__regid__ = 'seda.ux.filecategory'
__select__ = hook.Hook.__select__ & hook.match_rtype('file_category')
events = ('after_add_relation', 'after_delete_relation')
category = 'metadata'
def __call__(self):
SyncFileCategoryOp.get_instance(self._cw).add_data(self.eidfrom)
......
......@@ -20,6 +20,7 @@ from itertools import chain, repeat
from cubicweb.devtools.testlib import CubicWebTC
from cubicweb_compound.entities import copy_entity
from cubicweb_seda import testutils, dataimport
......@@ -305,6 +306,26 @@ class DispatchFileCategoryTC(CubicWebTC):
[concepts['application/msword']],
[concepts['fmt/37'], concepts['fmt/38']])
# test no dispatch occurs on component archive unit...
unit_comp, unit_comp_alt, unit_comp_alt_seq = testutils.create_archive_unit(
None, cnx=cnx)
bdo_comp = testutils.create_data_object(unit_comp_alt_seq)
cnx.commit()
bdo_comp.cw_set(file_category=categories['document'])
cnx.commit()
self.assertFormatEqual(bdo_comp, u'0..1',
[],
[])
# until it's imported into some parent
copy_entity(unit_comp, seda_archive_unit=unit_alt_seq, clone_of=unit_comp)
cnx.commit()
transfer.cw_clear_relation_cache('seda_binary_data_object', 'object')
imported_bdo, = [x for x in transfer.binary_data_objects if x.eid != bdo.eid]
self.assertFormatEqual(imported_bdo, u'1',
[concepts['application/msword'], concepts['application/pdf']],
[concepts['fmt/37'], concepts['fmt/38'], concepts['fmt/14']])
def assertFormatEqual(self, bdo, cardinality, mime_types, format_ids):
bdo.cw_clear_all_caches()
bdo.reverse_seda_mime_type_from[0].cw_clear_all_caches()
......
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