Add a rule preventing usage of RefNonRuleId in simplified profiles
authorSylvain Thénault <sylvain.thenault@logilab.fr>
Fri, 14 Oct 2016 11:17:02 +0200
changeset 1837 acdeecc5ef3c
parent 1836 86da8574b021
child 1838 ee6b7e0d1c52
Add a rule preventing usage of RefNonRuleId in simplified profiles
entities/diag.py
i18n/en.po
i18n/fr.po
test/test_diag.py
--- a/entities/diag.py	Thu Oct 13 18:03:16 2016 +0200
+++ b/entities/diag.py	Fri Oct 14 11:17:02 2016 +0200
@@ -77,6 +77,14 @@
         set([
             ('SEDAStartDate', 'user_cardinality'),
         ])),
+    'rule_ref_non_rule_id': Rule(
+        set(['SEDA 1.0', 'SEDA 0.2', 'simplified']),
+        _("Rule has an explicit rule deactivation - only ignore all rules is supported in "
+          "simplified profiles."),
+        'seda_management_tab',
+        set([
+            'seda_ref_non_rule_id_from',
+        ])),
 }
 
 
@@ -144,6 +152,14 @@
                     yield 'rule_need_start_date', _parent(rule)
                 elif rule_seq.start_date.user_cardinality != '1':
                     yield 'rule_start_unsupported_card', _parent(rule)
+        # Access/appraisal rule shouldn't use ref non rule id
+        for rule_type in ('access', 'appraisal'):
+            for rule in self._cw.execute(
+                    'DISTINCT Any X WHERE X seda_alt_{0}_rule_prevent_inheritance ALT,'
+                    'REF seda_ref_non_rule_id_from ALT, '
+                    'X container C, C eid %(c)s'.format(rule_type),
+                    {'c': profile.eid}).entities():
+                yield 'rule_ref_non_rule_id', _parent(rule)
 
 
 def _parent(entity):
--- a/i18n/en.po	Thu Oct 13 18:03:16 2016 +0200
+++ b/i18n/en.po	Fri Oct 14 11:17:02 2016 +0200
@@ -560,6 +560,11 @@
 msgid "Relationship target of"
 msgstr ""
 
+msgid ""
+"Rule has an explicit rule deactivation - only ignore all rules is supported "
+"in simplified profiles."
+msgstr ""
+
 msgid "SEDA 0.2 RNG export"
 msgstr ""
 
--- a/i18n/fr.po	Thu Oct 13 18:03:16 2016 +0200
+++ b/i18n/fr.po	Fri Oct 14 11:17:02 2016 +0200
@@ -566,6 +566,14 @@
 msgid "Relationship target of"
 msgstr "Cible des relations"
 
+msgid ""
+"Rule has an explicit rule deactivation - only ignore all rules is supported "
+"in simplified profiles."
+msgstr ""
+"Une règle désactive l'héritage d'une autre règle explicitement - seule la "
+"désactivation de toutes les règles parentes est supportée dans les profils "
+"simplifiés."
+
 msgid "SEDA 0.2 RNG export"
 msgstr "export SEDA 0.2 RNG"
 
--- a/test/test_diag.py	Thu Oct 13 18:03:16 2016 +0200
+++ b/test/test_diag.py	Fri Oct 14 11:17:02 2016 +0200
@@ -24,7 +24,9 @@
 
     def test_base(self):
         with self.admin_access.repo_cnx() as cnx:
-            transfer = cnx.create_entity('SEDAArchiveTransfer', title=u'diagnosis testing')
+            create = cnx.create_entity
+
+            transfer = create('SEDAArchiveTransfer', title=u'diagnosis testing')
             doctor = transfer.cw_adapt_to('ISEDACompatAnalyzer')
             cnx.commit()
             self.assertDiagnostic(doctor, ['SEDA 2.0', 'SEDA 1.0', 'SEDA 0.2', 'simplified'])
@@ -35,23 +37,23 @@
             self.assertDiagnostic(doctor, ['SEDA 2.0', 'SEDA 0.2', 'simplified'],
                                   'seda1_need_access_rule')
 
-            access_rule = cnx.create_entity('SEDAAccessRule', seda_access_rule=unit_alt_seq)
+            access_rule = create('SEDAAccessRule', seda_access_rule=unit_alt_seq)
             unit_alt_seq.cw_clear_all_caches()
             cnx.commit()
             self.assertDiagnostic(doctor, ['SEDA 2.0'], 'rule_without_rule')
 
-            access_rule_seq = cnx.create_entity('SEDASeqAccessRuleRule',
-                                                user_cardinality=u'1..n',
-                                                reverse_seda_seq_access_rule_rule=access_rule)
+            access_rule_seq = create('SEDASeqAccessRuleRule',
+                                     user_cardinality=u'1..n',
+                                     reverse_seda_seq_access_rule_rule=access_rule)
             access_rule.cw_clear_all_caches()
             cnx.commit()
             self.assertDiagnostic(doctor, ['SEDA 2.0'],
                                   'rule_unsupported_card', 'rule_need_start_date')
 
             access_rule_seq.cw_set(user_cardinality=u'1')
-            start_date = cnx.create_entity('SEDAStartDate',
-                                           user_cardinality=u'0..1',
-                                           seda_start_date=access_rule_seq)
+            start_date = create('SEDAStartDate',
+                                user_cardinality=u'0..1',
+                                seda_start_date=access_rule_seq)
             access_rule_seq.cw_clear_all_caches()
             cnx.commit()
             self.assertDiagnostic(doctor, ['SEDA 2.0'],
@@ -59,14 +61,23 @@
 
             start_date.cw_set(user_cardinality=u'1')
             start_date.cw_clear_all_caches()
-            access_rule_seq = cnx.create_entity('SEDASeqAccessRuleRule',
-                                                user_cardinality=u'1..n',
-                                                reverse_seda_seq_access_rule_rule=access_rule)
+            access_rule_seq2 = create('SEDASeqAccessRuleRule',
+                                      user_cardinality=u'1..n',
+                                      reverse_seda_seq_access_rule_rule=access_rule)
             access_rule.cw_clear_all_caches()
             cnx.commit()
             self.assertDiagnostic(doctor, ['SEDA 2.0'],
                                   'rule_with_too_much_rules')
 
+            access_rule_seq2.cw_delete()
+            inherit_ctl = create('SEDAAltAccessRulePreventInheritance',
+                                 reverse_seda_alt_access_rule_prevent_inheritance=access_rule)
+            create('SEDARefNonRuleId', seda_ref_non_rule_id_from=inherit_ctl)
+            access_rule.cw_clear_all_caches()
+            cnx.commit()
+            self.assertDiagnostic(doctor, ['SEDA 2.0'],
+                                  'rule_ref_non_rule_id')
+
     def assertDiagnostic(self, doctor, expected_formats, *expected_rule_ids):
         doctor.entity.cw_clear_all_caches()
         rule_ids = set(rule_id for rule_id, entity in doctor.failing_rules())