[views] Hide rule inheritance controls for simplified profiles
authorSylvain Thénault <sylvain.thenault@logilab.fr>
Tue, 07 Mar 2017 17:02:20 +0100
changeset 2462 2ba5bead36d2
parent 2461 c60d5381ddfc
child 2465 3b5249ffe7a1
[views] Hide rule inheritance controls for simplified profiles Closes #16684622
cubicweb_seda/views/simplified.py
test/test_views.py
--- a/cubicweb_seda/views/simplified.py	Wed Mar 08 07:04:23 2017 +0100
+++ b/cubicweb_seda/views/simplified.py	Tue Mar 07 17:02:20 2017 +0100
@@ -18,8 +18,9 @@
 from logilab.common.registry import objectify_predicate
 
 from cubicweb.predicates import is_instance
-from cubicweb.web.views import uicfg, autoform, formrenderers
+from cubicweb.web.views import uicfg, autoform
 
+from ..xsd2yams import RULE_TYPES
 from ..entities import simplified_profile
 from . import CONTENT_ETYPE, copy_rtag
 # ensure those are registered first
@@ -147,64 +148,13 @@
     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
-
-@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
--- a/test/test_views.py	Wed Mar 08 07:04:23 2017 +0100
+++ b/test/test_views.py	Tue Mar 07 17:02:20 2017 +0100
@@ -386,8 +386,6 @@
                 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')
 
@@ -405,17 +403,6 @@
                 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)