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

Don't show rule inheritance control for rules at the transfer level

It doesn't make sense since there may be no parent rule. This is probably a bug
in the SEDA 2 specification.

Closes #15045330
parent cc3540bc2628
......@@ -22,6 +22,7 @@ from six import text_type
from cubicweb.devtools.testlib import CubicWebTC
from cubicweb.web import INTERNAL_FIELD_VALUE
from cubes.seda.xsd2yams import RULE_TYPES
from cubes.seda.views import export
from cubes.seda.views.export import SEDAExportView, SEDANonSupportedExportView
......@@ -237,13 +238,18 @@ class SimplifiedFormsTC(CubicWebTC):
with self.admin_access.repo_cnx() as cnx:
transfer = cnx.create_entity('SEDAArchiveTransfer', title=u'diagnosis testing',
simplified_profile=True)
archive_unit = create_archive_unit(transfer)[0]
cnx.commit()
self.transfer_eid = transfer.eid
self.archive_unit_eid = archive_unit.eid
def rule_form(self, req, etype):
def rule_form(self, req, etype, linkto=None):
# add minimal information in for to detect container even if edited entity isn't
# actually created
req.form['__linkto'] = 'x:{0}:y'.format(self.transfer_eid)
if linkto is None:
linkto = self.archive_unit_eid
req.form['__linkto'] = 'x:{0}:y'.format(linkto)
rule = req.vreg['etypes'].etype_class(etype)(req)
return self.vreg['forms'].select('edition', req, entity=rule)
......@@ -266,6 +272,39 @@ class SimplifiedFormsTC(CubicWebTC):
field = form.field_by_name(field_name, role=role)
self.assertEqual(field.view.form_renderer_id, 'notitle')
def test_top_level_rule_form(self):
with self.admin_access.web_request() as req:
req.entity_from_eid(self.transfer_eid).cw_set(simplified_profile=False)
req.cnx.commit()
for rule_type in RULE_TYPES:
if rule_type == 'classification':
continue
with self.subTest(rule_type=rule_type):
form = self.rule_form(req, 'SEDA{0}Rule'.format(rule_type.capitalize()),
linkto=self.transfer_eid)
self.assertInlinedFields(form, [
('seda_seq_{0}_rule_rule'.format(rule_type),
'InlineAddNewLinkView'),
])
form = self.rule_form(req, 'SEDAClassificationRule'.format(rule_type.capitalize()),
linkto=self.transfer_eid)
self.assertInlinedFields(form, [
('seda_seq_classification_rule_rule', 'InlineAddNewLinkView'),
('seda_classification_reassessing_date', 'InlineAddNewLinkView'),
('seda_need_reassessing_authorization', 'InlineAddNewLinkView'),
])
def test_top_level_rule_form_simplified(self):
with self.admin_access.web_request() as req:
for rule_type in ('appraisal', 'access'):
with self.subTest(rule_type=rule_type):
form = self.rule_form(req, 'SEDA{0}Rule'.format(rule_type.capitalize()),
linkto=self.transfer_eid)
self.assertInlinedFields(form, [
('seda_seq_{0}_rule_rule'.format(rule_type),
'RuleRuleInlineEntityCreationFormView'),
])
def test_rule_form(self):
with self.admin_access.web_request() as req:
for rule_type in ('access', 'appraisal'):
......
......@@ -16,13 +16,15 @@
"""cubicweb-seda views for ArchiveTransfer"""
from logilab.common.decorators import monkeypatch
from logilab.common.registry import objectify_predicate
from cubicweb import _, tags
from cubicweb.predicates import is_instance
from cubicweb.web import formwidgets as fw
from cubicweb.web.views import tabs, uicfg, reledit
from cubes.seda.entities import full_seda2_profile, simplified_profile
from cubes.seda.xsd2yams import RULE_TYPES
from cubes.seda.entities import full_seda2_profile, simplified_profile, parent_and_container
from cubes.seda.views import rtags_from_xsd_element, rtags_from_rtype_role_targets
from cubes.seda.views import viewlib, copy_rtag
from cubes.seda.views import uicfg as sedauicfg # noqa - ensure those rules are defined first
......@@ -78,6 +80,27 @@ affk.set_fields_order('SEDAArchiveTransfer',
pvdc.set_fields_order('SEDAArchiveTransfer', ['title', 'user_annotation'] + at_ordered_fields)
# don't show inheritance control on top level rules
@objectify_predicate
def top_level_rule(cls, req, rset=None, entity=None, **kwargs):
"""Predicate returning 1 score if rule is linked to the transfer, not to an archive unit."""
if entity is None:
entity = rset.one()
parent = parent_and_container(entity)[0]
if parent.cw_etype == 'SEDAArchiveTransfer':
return 1
return 0
top_level_rule_afs = copy_rtag(
afs, __name__,
is_instance(*['SEDA{0}Rule'.format(rule_type.capitalize())
for rule_type in RULE_TYPES]) & top_level_rule())
for rule_type in RULE_TYPES:
etype = 'SEDA{0}Rule'.format(rule_type.capitalize())
rtype = 'seda_alt_{0}_rule_prevent_inheritance'.format(rule_type)
top_level_rule_afs.tag_subject_of((etype, rtype, '*'), 'main', 'hidden')
class ArchiveTransferTabbedPrimaryView(tabs.TabbedPrimaryView):
__select__ = tabs.TabbedPrimaryView.__select__ & is_instance('SEDAArchiveTransfer')
tabs = [
......
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