Commit da8ca3f3 authored by Sylvain Thénault's avatar Sylvain Thénault
Browse files

Add a rule preventing usage of RefNonRuleId in simplified profiles

parent 86da8574b021
......@@ -77,6 +77,14 @@ RULES = {
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 @@ class ISEDACompatAnalyzer(EntityAdapter):
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):
......
......@@ -560,6 +560,11 @@ msgstr ""
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 ""
......
......@@ -566,6 +566,14 @@ msgstr "Aucun problème détecté, félicitations !"
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"
......
......@@ -24,7 +24,9 @@ class CompatAnalyzerTC(CubicWebTC):
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 @@ class CompatAnalyzerTC(CubicWebTC):
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 @@ class CompatAnalyzerTC(CubicWebTC):
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())
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment