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

[schema] Fix definition of the container relation

Cardinality and permissions defined on the relation type wasn't considered as
expected because the relation is added dynamically in post_build_callback. We
have to set them explicitly there.

This added to a bug in the cloning code led to entities with several containers.
To fix this, migration script pick the container with the greatest eid since it
should be the one which is not unexpectedly copied. Anyway, even if that's wrong
that's no big deal because there are only demo instances for now which don't
really care of data loss.

This patch also set properly cardinality on container relation for
SEDAArchiveUnit, which is expected to be optional while mandatory for others.
This has not been detected before since it wasn't actually mandatory by default
before this patch.
parent 02f4b849a80f
for e in rql('Any X groupby X WHERE X container C HAVING COUNT(C) > 1').entities():
container = max(c.eid for c in e.container)
e.cw_set(container=None)
e.cw_set(container=container)
commit()
sync_schema_props_perms('container')
......@@ -86,8 +86,6 @@ class seda_keyword_reference_to_scheme(RelationDefinition):
class container(RelationType):
__permissions__ = {'add': (), 'delete': (), 'read': ()}
cardinality = '1*'
inlined = False
......@@ -171,7 +169,14 @@ def post_build_callback(schema):
for etype, parent_rdefs in seda_profile_container_def(schema):
# add relation to the container from every entity type within the compound graph
for container_etype in container_etypes:
container_rdef = RelationDefinition(etype, 'container', container_etype)
# special case for SEDAArchiveUnit's cardinality as it may be both
# contained and container
container_rdef = RelationDefinition(
etype, 'container', container_etype,
cardinality='?*' if etype == 'SEDAArchiveUnit' else '1*',
__permissions__={'add': (),
'delete': (),
'read': ('managers', 'users', 'guests')})
schema.add_relation_def(container_rdef)
eschema = schema[etype]
# set permissions on entity types from the compound graph according to permission on the
......
......@@ -255,6 +255,17 @@ class SchemaTC(CubicWebTC):
scheme.cw_set(code_keyword_type=ckt_concept)
cnx.commit()
def test_container_relation(self):
container_rtype = self.schema['container']
for rdef in container_rtype.rdefs.values():
if rdef.subject == 'SEDAArchiveUnit':
self.assertEqual(rdef.cardinality, '?*')
else:
self.assertEqual(rdef.cardinality, '1*')
self.assertEqual(rdef.permissions, {'add': (),
'delete': (),
'read': ('managers', 'users', 'guests')})
class SecurityTC(CubicWebTC):
......
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