[dataimport] don't insert created_by / owned_by relations when user is the internal manager (eid = -1).
Closes #5162943
--- 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:
--- 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()