Commit f1f083c2 authored by Rémi Cardona's avatar Rémi Cardona
Browse files

[entities] cw_rest_attr_info() should only consider required attributes (closes #3766717)

This prevents CW from choosing unique but non-required attributes. None/NULL is
a poor choice for RESTful URIs.
parent e48e5a597ccc
......@@ -425,8 +425,10 @@ class Entity(AppObject):
needcheck = not cls.e_schema.has_unique_values(mainattr)
for rschema in cls.e_schema.subject_relations():
if and rschema != 'eid' \
and cls.e_schema.has_unique_values(rschema):
if (
and rschema != 'eid'
and cls.e_schema.has_unique_values(rschema)
and cls.e_schema.rdef(rschema.type).cardinality[0] == '1'):
mainattr = str(rschema)
needcheck = False
......@@ -89,3 +89,8 @@ class evaluee(RelationDefinition):
class StateFull(WorkflowableEntityType):
name = String()
class Reference(EntityType):
nom = String(unique=True)
ean = String(unique=True, required=True)
......@@ -754,6 +754,11 @@ du :eid:`1:*ReST*`'''
# unique attr with None value (nom in this case)
friend = req.create_entity('Ami', prenom=u'bob')
self.assertEqual(friend.rest_path(), unicode(friend.eid))
# 'ref' below is created without the unique but not required
# attribute, make sur that the unique _and_ required 'ean' is used
# as the rest attribute
ref = req.create_entity('Reference', ean=u'42-1337-42')
self.assertEqual(ref.rest_path(), 'reference/42-1337-42')
def test_can_use_rest_path(self):
......@@ -168,7 +168,7 @@ class SchemaReaderClassTest(TestCase):
'CWUniqueTogetherConstraint', 'CWUser',
'ExternalUri', 'File', 'Float', 'Int', 'Interval', 'Note',
'Password', 'Personne', 'Produit',
'RQLExpression', 'Reference',
'Service', 'Societe', 'State', 'StateFull', 'String', 'SubNote', 'SubWorkflowExitPoint',
'Tag', 'TZDatetime', 'TZTime', 'Time', 'Transition', 'TrInfo',
......@@ -417,6 +417,7 @@ class CompositeSchemaTC(CubicWebTC):
('cw_source', 'Personne', 'CWSource', 'object'),
('cw_source', 'Produit', 'CWSource', 'object'),
('cw_source', 'RQLExpression', 'CWSource', 'object'),
('cw_source', 'Reference', 'CWSource', 'object'),
('cw_source', 'Service', 'CWSource', 'object'),
('cw_source', 'Societe', 'CWSource', 'object'),
('cw_source', 'State', 'CWSource', 'object'),
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