Only consider the first encountered rdef with inserting RQL permissions draft
authorDenis Laxalde <denis.laxalde@logilab.fr>
Thu, 12 Apr 2018 17:17:34 +0200
changeset 2954 89d7f634ea40
parent 2953 97b06a36d104
Only consider the first encountered rdef with inserting RQL permissions iter_all_rdefs() might return the same rdef multiple times (with different role) so when consuming these values in schema's post_build_callback() to generate and insert RQL permissions we might not always get the same expressions depending on how items are returned (which is random and the underlying data structure is a dict). This occurs in practice when walking from SEDAArchiveTransfer container etype for a couple of relations (see those which permissions are updated in migration script). Now to get predictable results, we keep track of "seen" rdef in post_build_callback() when and sort values produced by iter_all_rdefs().
cubicweb_seda/migration/0.13.3_Any.py
cubicweb_seda/schema/__init__.py
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/cubicweb_seda/migration/0.13.3_Any.py	Thu Apr 12 17:17:34 2018 +0200
@@ -0,0 +1,2 @@
+for rtype in ('seda_archive_unit_ref_id_to', 'seda_target', 'seda_data_object_reference_id'):
+    sync_schema_props_perms(rtype)
--- a/cubicweb_seda/schema/__init__.py	Tue Feb 20 16:28:20 2018 +0100
+++ b/cubicweb_seda/schema/__init__.py	Thu Apr 12 17:17:34 2018 +0200
@@ -202,7 +202,11 @@
                                     'G name IN ("managers", "users")')))
     # set permissions on all relation defs related to the compound graph according to permission on
     # the container entity
-    for rdef, role in iter_all_rdefs(schema, 'SEDAArchiveTransfer'):
+    seen = set()
+    for rdef, role in sorted(iter_all_rdefs(schema, 'SEDAArchiveTransfer')):
+        if rdef in seen:
+            continue
+        seen.add(rdef)
         if role == 'subject':
             target_etype, var = rdef.subject, 'S'
         else: