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

Enhance parent detection of rule_ref_vocabulary

Consider that:

* container may be find while parent isn't (see previous cset)
* the etype we're interested in may be found on form(.edited_entity)
* if not, there is still some chance to find in req.form['arg] (json encoded)

Refactor _rule_ref_vocabulary accordingly.
parent 4e36b39d78fa
...@@ -47,10 +47,10 @@ class ManagementRulesTC(CubicWebTC): ...@@ -47,10 +47,10 @@ class ManagementRulesTC(CubicWebTC):
cnx.create_entity('SEDAPreventInheritance', seda_prevent_inheritance=rule_alt) cnx.create_entity('SEDAPreventInheritance', seda_prevent_inheritance=rule_alt)
cnx.commit() cnx.commit()
self.assertEqual(_rule_ref_vocabulary(rule_base, transfer), self.assertEqual(_rule_ref_vocabulary(transfer, rule_base.cw_etype),
[('you must specify a scheme for seda_access_rule_code_list_version_' [('you must specify a scheme for seda_access_rule_code_list_version_'
'from_object to select a value', INTERNAL_FIELD_VALUE)]) 'from_object to select a value', INTERNAL_FIELD_VALUE)])
self.assertEqual(_rule_ref_vocabulary(rule_alt, transfer), self.assertEqual(_rule_ref_vocabulary(transfer, rule_alt.cw_etype),
[('you must specify a scheme for seda_access_rule_code_list_version_' [('you must specify a scheme for seda_access_rule_code_list_version_'
'from_object to select a value', INTERNAL_FIELD_VALUE)]) 'from_object to select a value', INTERNAL_FIELD_VALUE)])
...@@ -59,9 +59,9 @@ class ManagementRulesTC(CubicWebTC): ...@@ -59,9 +59,9 @@ class ManagementRulesTC(CubicWebTC):
seda_access_rule_code_list_version_to=access_scheme) seda_access_rule_code_list_version_to=access_scheme)
cnx.commit() cnx.commit()
self.assertEqual(_rule_ref_vocabulary(rule_base, transfer), self.assertEqual(_rule_ref_vocabulary(transfer, rule_base.cw_etype),
[(access_concept.label(), text_type(access_concept.eid))]) [(access_concept.label(), text_type(access_concept.eid))])
self.assertEqual(_rule_ref_vocabulary(rule_alt, transfer), self.assertEqual(_rule_ref_vocabulary(transfer, rule_alt.cw_etype),
[(access_concept.label(), text_type(access_concept.eid))]) [(access_concept.label(), text_type(access_concept.eid))])
......
...@@ -15,6 +15,8 @@ ...@@ -15,6 +15,8 @@
# with this program. If not, see <http://www.gnu.org/licenses/>. # with this program. If not, see <http://www.gnu.org/licenses/>.
"""cubicweb-seda views for management rules""" """cubicweb-seda views for management rules"""
import json
from six import text_type from six import text_type
from logilab.mtconverter import xml_escape from logilab.mtconverter import xml_escape
...@@ -41,12 +43,18 @@ def rule_ref_vocabulary(form, field): ...@@ -41,12 +43,18 @@ def rule_ref_vocabulary(form, field):
# missing parent information # missing parent information
msg = req._('you must validate first to select a possible value') msg = req._('you must validate first to select a possible value')
return [(msg, INTERNAL_FIELD_VALUE)] return [(msg, INTERNAL_FIELD_VALUE)]
return _rule_ref_vocabulary(parent, container) parent_etype = form.edited_entity.cw_etype
if parent_etype == 'SEDARefNonRuleId':
if parent is not None:
parent_etype = parent.cw_etype
else:
parent_etype = json.loads(req.form['arg'][1])
return _rule_ref_vocabulary(container, parent_etype)
def _rule_ref_vocabulary(parent, container): def _rule_ref_vocabulary(container, parent_etype):
req = parent._cw req = container._cw
rule_type = rule_type_from_etype(parent.cw_etype) rule_type = rule_type_from_etype(parent_etype)
rql = ('Any C WHERE C in_scheme CS, AT eid %(at)s, ' rql = ('Any C WHERE C in_scheme CS, AT eid %(at)s, '
'CACLV seda_{0}_rule_code_list_version_from AT, ' 'CACLV seda_{0}_rule_code_list_version_from AT, '
'CACLV seda_{0}_rule_code_list_version_to CS'.format(rule_type)) 'CACLV seda_{0}_rule_code_list_version_to CS'.format(rule_type))
......
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