[PATCH 2 of 2 saem_ref] Allow direct deletion of SEDAArchiveUnit entities (CONSEJIRA-591)

Denis Laxalde denis.laxalde at logilab.fr
Fri Oct 19 15:36:37 CEST 2018


# HG changeset patch
# User Denis Laxalde <denis.laxalde at logilab.fr>
# Date 1539954063 -7200
#      Fri Oct 19 15:01:03 2018 +0200
# Node ID 1a24ed0ee94082793afe814e3840be9987f1908b
# Parent  dee432b4cb20b621566caf632b3248cda09d92a8
# Available At http://hg.logilab.org/review/cubes/saem_ref
#              hg pull http://hg.logilab.org/review/cubes/saem_ref -r 1a24ed0ee940
# EXP-Topic consejira-591
Allow direct deletion of SEDAArchiveUnit entities (CONSEJIRA-591)

This is a companion change of the previous one. Here we allow direct
deletion of a SEDAArchiveUnit entity, even without going through
deletion of the "seda_archive_unit" relation first.

diff --git a/cubicweb_saem_ref/migration/0.21.2_Any.py b/cubicweb_saem_ref/migration/0.21.2_Any.py
--- a/cubicweb_saem_ref/migration/0.21.2_Any.py
+++ b/cubicweb_saem_ref/migration/0.21.2_Any.py
@@ -8,3 +8,4 @@ sql("DELETE FROM container_relation WHER
 commit()
 
 sync_schema_props_perms('seda_archive_unit')
+sync_schema_props_perms('SEDAArchiveUnit')
diff --git a/cubicweb_saem_ref/schema.py b/cubicweb_saem_ref/schema.py
--- a/cubicweb_saem_ref/schema.py
+++ b/cubicweb_saem_ref/schema.py
@@ -544,6 +544,8 @@ def post_build_callback(schema):
         'SEDAArchiveUnit', 'SEDAArchiveTransfer')
     for action in ('add', 'delete'):
         seda_archive_unit.set_action_permissions(action, ('managers', 'users'))
+    schema['SEDAArchiveUnit'].set_action_permissions(
+        'delete', ('managers', 'users'))
 
     # reset permissions, unexpectedly changed by seda's post_build_callback
     def sync_perms(erdef, permissions):
diff --git a/test/unittest_schema.py b/test/unittest_schema.py
--- a/test/unittest_schema.py
+++ b/test/unittest_schema.py
@@ -248,6 +248,20 @@ class SchemaTC(CubicWebTC):
             unit.cw_delete()
             cnx.commit()
 
+    def test_can_delete_archiveunit_from_public_profile(self):
+        with self.admin_access.cnx() as cnx:
+            transfer = testutils.setup_profile(cnx, title=u'test')
+            unit, _, _ = testutils.create_archive_unit(transfer, cnx=cnx,
+                                                       user_cardinality=u'1',
+                                                       user_annotation=u'plop')
+            cnx.commit()
+            transfer.cw_adapt_to('IWorkflowable').fire_transition('publish')
+            cnx.commit()
+            assert unit in transfer.reverse_seda_archive_unit
+            # Delete archive unit while still related to the archive transfer.
+            unit.cw_delete()
+            cnx.commit()
+
 
 class AuthorityRecordTC(CubicWebTC):
 



More information about the saem-devel mailing list