# HG changeset patch # User Sylvain Thénault # Date 1427267396 -3600 # Node ID 0f8c3ac88f1e34884e27cd31cf600c2abb40faac # Parent d14db30b90d65a6bdc9298a80e766d17c8f1c378 [dataimport] don't insert created_by / owned_by relations when user is the internal manager (eid = -1). Closes #5162943 diff -r d14db30b90d6 -r 0f8c3ac88f1e dataimport.py --- a/dataimport.py Wed Mar 25 07:57:38 2015 +0100 +++ b/dataimport.py Wed Mar 25 08:09:56 2015 +0100 @@ -855,6 +855,9 @@ schema = cnx.vreg.schema rschema = schema.rschema for rtype in self.META_RELATIONS: + # skip owned_by / created_by if user is the internal manager + if cnx.user.eid == -1 and rtype in ('owned_by', 'created_by'): + continue if rschema(rtype).final: self.etype_attrs.append(rtype) else: diff -r d14db30b90d6 -r 0f8c3ac88f1e test/unittest_dataimport.py --- a/test/unittest_dataimport.py Wed Mar 25 07:57:38 2015 +0100 +++ b/test/unittest_dataimport.py Wed Mar 25 08:09:56 2015 +0100 @@ -134,5 +134,17 @@ [u'1', u'2', u'3', u'4', u'']]) +class MetaGeneratorTC(CubicWebTC): + def test_dont_generate_relation_to_internal_manager(self): + from cubicweb.server.edition import EditedEntity + with self.admin_access.repo_cnx() as cnx: + metagen = dataimport.MetaGenerator(cnx) + self.assertIn('created_by', metagen.etype_rels) + self.assertIn('owned_by', metagen.etype_rels) + with self.repo.internal_cnx() as cnx: + metagen = dataimport.MetaGenerator(cnx) + self.assertNotIn('created_by', metagen.etype_rels) + self.assertNotIn('owned_by', metagen.etype_rels) + if __name__ == '__main__': unittest_main()