[schema] Fix permissions of the clone_of relation
authorSylvain Thénault <sylvain.thenault@logilab.fr>
Wed, 08 Mar 2017 06:30:23 +0100
changeset 2481 64ffda562109
parent 2480 904f78b40d55
child 2482 de2afb160604
[schema] Fix permissions of the clone_of relation so user can clone entities.
cubicweb_seda/migration/0.9.0_Any.py
cubicweb_seda/schema/__init__.py
test/test_schema.py
--- a/cubicweb_seda/migration/0.9.0_Any.py	Fri Mar 10 10:50:21 2017 +0100
+++ b/cubicweb_seda/migration/0.9.0_Any.py	Wed Mar 08 06:30:23 2017 +0100
@@ -7,3 +7,5 @@
         target_etype = rdef.object
     if target_etype == 'SEDAArchiveUnit':
         sync_schema_props_perms((rdef.subject, rdef.rtype, rdef.object))
+
+sync_schema_props_perms('clone_of')
--- a/cubicweb_seda/schema/__init__.py	Fri Mar 10 10:50:21 2017 +0100
+++ b/cubicweb_seda/schema/__init__.py	Wed Mar 08 06:30:23 2017 +0100
@@ -90,20 +90,23 @@
     inlined = False
 
 
-class clone_of_archive_transfer(RelationDefinition):
+class _clone_of(RelationDefinition):
+    __permissions__ = {'read': ('managers', 'users', 'guests'),
+                       'add': ('managers', 'users',),
+                       'delete': ()}
     name = 'clone_of'
-    subject = 'SEDAArchiveTransfer'
-    object = 'SEDAArchiveTransfer'
     cardinality = '?*'
     inlined = True
 
 
-class clone_of_archive_unit(RelationDefinition):
-    name = 'clone_of'
+class clone_of_archive_transfer(_clone_of):
+    subject = 'SEDAArchiveTransfer'
+    object = 'SEDAArchiveTransfer'
+
+
+class clone_of_archive_unit(_clone_of):
     subject = 'SEDAArchiveUnit'
     object = 'SEDAArchiveUnit'
-    cardinality = '?*'
-    inlined = True
 
 
 class title(RelationDefinition):
@@ -172,6 +175,8 @@
     # set permissions on all relation defs related to the compound graph according to permission on
     # the container entity
     for rdef, role in iter_all_rdefs(schema, 'SEDAArchiveTransfer'):
+        if rdef.rtype == 'clone_of':
+            continue
         if role == 'subject':
             target_etype, var = rdef.subject, 'S'
         else:
--- a/test/test_schema.py	Fri Mar 10 10:50:21 2017 +0100
+++ b/test/test_schema.py	Wed Mar 08 06:30:23 2017 +0100
@@ -326,13 +326,28 @@
             unit.cw_delete()
             cnx.commit()
 
-    def test_users_can_created_unit(self):
+    def test_users_can_create_unit(self):
         with self.admin_access.cnx() as cnx:
             self.create_user(cnx, 'bob')
         with self.new_access('bob').cnx() as cnx:
             unit, unit_alt, unit_alt_seq = testutils.create_archive_unit(None, cnx=cnx)
             cnx.commit()
 
+    def test_users_can_clone(self):
+        """Functional test for SEDA component clone."""
+        with self.admin_access.repo_cnx() as cnx:
+            self.create_user(cnx, login='alice')
+            unit, unit_alt, unit_alt_seq = testutils.create_archive_unit(None, cnx=cnx)
+            cnx.commit()
+
+        with self.new_access('alice').repo_cnx() as cnx:
+            unit = cnx.entity_from_eid(unit.eid)
+            cloned = cnx.create_entity(unit.cw_etype, user_annotation=u'x', clone_of=unit)
+            cnx.commit()
+            cloned.cw_clear_all_caches()
+
+            self.assertTrue(cloned.first_level_choice.content_sequence)
+
 
 if __name__ == '__main__':
     import unittest