[entitites] Enhance simplified_profile predicate
authorSylvain Thénault <sylvain.thenault@logilab.fr>
Fri, 21 Apr 2017 16:08:31 +0200
changeset 2627 7d5eca447158
parent 2626 9705a695191b
child 2629 5199411f1e3d
[entitites] Enhance simplified_profile predicate vs creation of component archive unit, in which case it should return a positive score, not zero. This is because in such case, container can't be detected and implementation trapped this and returned 0. In such case, we must check if we're creating an archive unit and return 1 if so. Closes extranet #18337031
cubicweb_seda/entities/__init__.py
test/test_entities.py
--- a/cubicweb_seda/entities/__init__.py	Fri Apr 21 16:04:49 2017 +0200
+++ b/cubicweb_seda/entities/__init__.py	Fri Apr 21 16:08:31 2017 +0200
@@ -102,6 +102,12 @@
     """Predicate returning 1 score if context entity is within a simplified profile."""
     container = _seda_container_from_context(rset, entity, **kwargs)
     if container is None:
+        # Detect creation of a component archive unit, which are supposed to be
+        # simplified. If we can't get a container and we're creating an archive
+        # unit, it must be an archive unit component (else it's parent container
+        # should have been retrieved)
+        if getattr(req, 'form', {}).get('etype') == 'SEDAArchiveUnit':
+            return 1
         return 0
     if container.cw_etype == 'SEDAArchiveUnit':
         # XXX archive unit component, for now suppose it's "simplified"
--- a/test/test_entities.py	Fri Apr 21 16:04:49 2017 +0200
+++ b/test/test_entities.py	Fri Apr 21 16:08:31 2017 +0200
@@ -204,6 +204,13 @@
             self.assertEqual(simplified_profile_pred(None, req, entity=transfer), 1)
             self.assertEqual(full_seda2_profile_pred(None, req, entity=transfer), 0)
 
+            req.form = {'etype': 'SEDAArchiveUnit'}
+            etype_vreg = req.vreg['etypes']
+            unit = etype_vreg.etype_class('SEDAArchiveUnit')(req)
+            self.assertEqual(simplified_profile_pred(None, req, entity=unit), 1)
+            entity = etype_vreg.etype_class('SEDASeqAltArchiveUnitArchiveUnitRefIdManagement')(req)
+            self.assertEqual(simplified_profile_pred(None, req, entity=entity), 1)
+
 
 class ITreeTC(CubicWebTC):