[PATCH 3 of 6 seda] [schema] Fix definition of the container relation

Philippe Pepiot philippe.pepiot at logilab.fr
Mon Mar 27 10:31:08 CEST 2017


On 03/24/2017 10:48 AM, Sylvain Thenault wrote:
> # HG changeset patch
> # User Sylvain Thénault <sylvain.thenault at logilab.fr>
> # Date 1490200634 -3600
> #      Wed Mar 22 17:37:14 2017 +0100
> # Node ID a5a36f8af01cf746882d2ff66b032f89ebe55c65
> # Parent  97ae1cc7a9e7e129f73fe0a3cb6ec7044b9706fe
> [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.
>
> diff --git a/cubicweb_seda/migration/0.9.1_Any.py b/cubicweb_seda/migration/0.9.1_Any.py
> new file mode 100644
> --- /dev/null
> +++ b/cubicweb_seda/migration/0.9.1_Any.py
> @@ -0,0 +1,9 @@
> +for e in rql('Any X groupby X WHERE X container C HAVING COUNT(C) > 1').entities():
> +    container = min(c.eid for c in e.container)
> +    e.cw_set(container=None)
> +    e.cw_set(container=container)
> +    commit()

Commit message say 'pick the container with the greatest eid' but you 
actually pick the lowest.

> +
> +sync_schema_props_perms('container')
> +
> +
> diff --git a/cubicweb_seda/schema/__init__.py b/cubicweb_seda/schema/__init__.py
> --- a/cubicweb_seda/schema/__init__.py
> +++ b/cubicweb_seda/schema/__init__.py
> @@ -84,12 +84,10 @@ class seda_keyword_reference_to_scheme(R
>      cardinality = '?*'
>      inlined = True
>
>
>  class container(RelationType):
> -    __permissions__ = {'add': (), 'delete': (), 'read': ()}
> -    cardinality = '1*'
>      inlined = False
>
>
>  class _clone_of(RelationDefinition):
>      __permissions__ = {'read': ('managers', 'users', 'guests'),
> @@ -169,11 +167,16 @@ def post_build_callback(schema):
>
>      container_etypes = ('SEDAArchiveTransfer', 'SEDAArchiveUnit')
>      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)
> +            container_rdef = RelationDefinition(
> +                etype, 'container', container_etype,
> +                cardinality='?*' if etype == 'SEDAArchiveUnit' else '1*',

Can you explain the difference of cardinality between 
SEDAArchiveTransfer and SEDAArchiveUnit in the commit message ? I don't 
understand if the cardinality is changed by this patch or not for each 
container etypes.

> +                __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
>          # container entity
>          for action in ('update', 'delete'):
> diff --git a/test/test_schema.py b/test/test_schema.py
> --- a/test/test_schema.py
> +++ b/test/test_schema.py
> @@ -250,10 +250,21 @@ class SchemaTC(CubicWebTC):
>                  cnx.commit()
>
>              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):
>
>      @contextmanager
>      def assertUnauthorized(self, cnx):
>



More information about the saem-devel mailing list