[PATCH 1 of 1 seda] [views] Hide rule inheritance controls for simplified profiles

Sylvain Thenault sylvain.thenault at logilab.fr
Tue Mar 7 17:02:40 CET 2017


# HG changeset patch
# User Sylvain Thénault <sylvain.thenault at logilab.fr>
# Date 1488902540 -3600
#      Tue Mar 07 17:02:20 2017 +0100
# Node ID d3f725f5de534a6f7bb6f92ce8b8f028b05cf2d1
# Parent  d4c0e6edccf6541c102e8f3166b7b1bf88d70316
[views] Hide rule inheritance controls for simplified profiles

Closes #16684622

diff --git a/cubicweb_seda/views/simplified.py b/cubicweb_seda/views/simplified.py
--- a/cubicweb_seda/views/simplified.py
+++ b/cubicweb_seda/views/simplified.py
@@ -18,10 +18,11 @@
 from logilab.common.registry import objectify_predicate
 
 from cubicweb.predicates import is_instance
 from cubicweb.web.views import uicfg, autoform, formrenderers
 
+from ..xsd2yams import RULE_TYPES
 from ..entities import simplified_profile
 from . import CONTENT_ETYPE, copy_rtag
 # ensure those are registered first
 from . import mgmt_rules, archivetransfer, dataobject, archiveunit  # noqa
 
@@ -145,68 +146,17 @@ class StartDateInlineEntityCreationFormV
                   & simplified_start_date())
     removejs = None
     form_renderer_id = 'notitle'
 
 
-# simplified profil will have a single appraisal/access rule, hence 'ignore inherited rules' is
-# enough, no need for explicit rule deactivation. This implies:
-# 1. hide explicit rule deactivation
-# 2. force appearance (hence choice) of the ignore all rules entity
-# 3. adapt alternative's title, so it doesn't appear like an alternative
-
-# 1. hide explicit rule deactivation
-simplified_afs.tag_object_of(('*', 'seda_ref_non_rule_id_from', '*'),
-                             'main', 'hidden')
-
-
-class AltInheritanceAutomaticEntityForm(autoform.AutomaticEntityForm):
-    __select__ = (is_instance('SEDAAltAccessRulePreventInheritance',
-                              'SEDAAltAppraisalRulePreventInheritance')
-                  & simplified_profile())
-
-    # 3. adapt alternative's title, so it doesn't appear like an alternative
-    def __init__(self, *args, **kwargs):
-        super(AltInheritanceAutomaticEntityForm, self).__init__(*args, **kwargs)
-        self.form_renderer_id = 'not-an-alt'
-
-    # 2. force appearance (hence choice) of the ignore all rules entity
-    def should_display_inline_creation_form(self, rschema, existing, card):
-        if not existing and rschema == 'seda_prevent_inheritance':
-            return True
-        return super(AltInheritanceAutomaticEntityForm, self).should_display_inline_creation_form(
-            rschema, existing, card)
-
-
-# 2. force appearance (hence choice) of the ignore all rules entity
-
- at objectify_predicate
-def simplified_prevent_inheritance(cls, req, rtype=None, pform=None, **kwargs):
-    if isinstance(pform, AltInheritanceAutomaticEntityForm) and rtype == 'seda_prevent_inheritance':
-        return 1
-    return 0
-
-
-class PreventInheritanceInlineEntityEditionFormView(autoform.InlineEntityEditionFormView):
-    __select__ = (autoform.InlineEntityEditionFormView.__select__
-                  & simplified_prevent_inheritance())
-    removejs = None
-
-
-class PreventInheritanceInlineEntityCreationFormView(autoform.InlineEntityCreationFormView):
-    __select__ = (autoform.InlineEntityCreationFormView.__select__
-                  & simplified_prevent_inheritance())
-    removejs = None
-
-
-class NotAnAltEntityInlinedFormRenderer(formrenderers.EntityInlinedFormRenderer):
-    """Custom form renderer that remove 'Alternative :' from an alternative's inlined form's title.
-    """
-    __regid__ = 'not-an-alt'
-
-    def render_title(self, w, form, values):
-        values['title'] = values['title'].split(':', 1)[1]
-        super(NotAnAltEntityInlinedFormRenderer, self).render_title(w, form, values)
+# simplified profil will have a single appraisal/access rule, hence we can remove all the
+# inheritance control mecanism: override will simply mean redefining a rule at some point in the
+# tree.
+for rule_type in RULE_TYPES:
+    etype = 'SEDA{0}Rule'.format(rule_type.capitalize())
+    rtype = 'seda_alt_{0}_rule_prevent_inheritance'.format(rule_type)
+    simplified_afs.tag_subject_of((etype, rtype, '*'), 'main', 'hidden')
 
 
 # SEDAArchiveTransfer customization
 for rtype, role in archivetransfer.at_ordered_fields:
     if not rtype.endswith('agency'):
diff --git a/test/test_views.py b/test/test_views.py
--- a/test/test_views.py
+++ b/test/test_views.py
@@ -384,12 +384,10 @@ class SimplifiedFormsTC(CubicWebTC):
             for rule_type in ('access', 'appraisal'):
                 form = self.create_and_link_form(req, 'SEDA{0}Rule'.format(rule_type.capitalize()))
                 self.assertInlinedFields(form, [
                     ('seda_seq_{0}_rule_rule'.format(rule_type),
                      'RuleRuleInlineEntityCreationFormView'),
-                    ('seda_alt_{0}_rule_prevent_inheritance'.format(rule_type),
-                     'InlineAddNewLinkView'),
                 ])
                 self.assertNoRemove(form, 'seda_seq_{0}_rule_rule'.format(rule_type), 'subject')
 
     def test_rule_rule_form(self):
         with self.admin_access.web_request() as req:
@@ -403,21 +401,10 @@ class SimplifiedFormsTC(CubicWebTC):
                     ('seda_start_date', 'StartDateInlineEntityCreationFormView'),
                 ])
                 self.assertNoRemove(form, 'seda_start_date', 'object')
                 self.assertNoTitle(form, 'seda_start_date', 'object')
 
-    def test_prevent_inheritance_form(self):
-        with self.admin_access.web_request() as req:
-            for rule_type in ('access', 'appraisal'):
-                form = self.create_and_link_form(req, 'SEDAAlt{0}RulePreventInheritance'.format(
-                    rule_type.capitalize()))
-                self.assertInlinedFields(form, [
-                    ('seda_prevent_inheritance', 'PreventInheritanceInlineEntityCreationFormView'),
-                ])
-                self.assertNoRemove(form, 'seda_prevent_inheritance', 'object')
-                self.assertEqual(form.form_renderer_id, 'not-an-alt')
-
     def test_create_data_object_full(self):
         with self.admin_access.web_request() as req:
             req.entity_from_eid(self.transfer_eid).cw_set(simplified_profile=False)
             req.cnx.commit()
             form = self.create_inlined_form(req, 'SEDADataObjectReference', formtype='inlined')


More information about the saem-devel mailing list