[PATCH 1 of 2 saem_ref] Allow deletion of "seda_archive_unit" relation (CONSEJIRA-591)

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


# HG changeset patch
# User Denis Laxalde <denis.laxalde at logilab.fr>
# Date 1539954007 -7200
#      Fri Oct 19 15:00:07 2018 +0200
# Node ID dee432b4cb20b621566caf632b3248cda09d92a8
# Parent  802343c3d460266cfa8bbe61d39f472af02afe79
# Available At http://hg.logilab.org/review/cubes/saem_ref
#              hg pull http://hg.logilab.org/review/cubes/saem_ref -r dee432b4cb20
# EXP-Topic consejira-591
Allow deletion of "seda_archive_unit" relation (CONSEJIRA-591)

Per CONSEJIRA-591, we now want to allow deletion of a SEDAArchiveUnit
entity even when related to a SEDAArchiveTransfer in public workflow
state (whereas we used to want to disallow this). The first step for
this is to allow deletion of the "seda_archive_unit" relation. As
permission of this relation is defined in cubicweb-seda, we override it
in post-build callback.

In the new test, we first check that deletion of the relation works.
Then we check that deletion of the unlinked entity (SEDAArchiveUnit) is
also possible. This should be true as it is no longer related to an
archive transfer but due to an integrity bug in cubicweb-seda which
makes the "container" relation out-of-sync, this does not work. So we
require a new cubicweb-seda version with a fix for this issue and the
check passes.

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
@@ -6,3 +6,5 @@ sql("DELETE FROM container_relation WHER
     " (SELECT c.eid_from FROM container_relation AS c"
     "   JOIN entities AS e ON e.eid=c.eid_from WHERE e.type='Activity');")
 commit()
+
+sync_schema_props_perms('seda_archive_unit')
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
@@ -539,6 +539,12 @@ def post_build_callback(schema):
             if rtype == 'label_of':
                 rdef.set_action_permissions('delete', ('managers', 'users'))
 
+    # allow deletion of an archive unit, even if within a public profile
+    seda_archive_unit = schema['seda_archive_unit'].rdef(
+        'SEDAArchiveUnit', 'SEDAArchiveTransfer')
+    for action in ('add', 'delete'):
+        seda_archive_unit.set_action_permissions(action, ('managers', 'users'))
+
     # reset permissions, unexpectedly changed by seda's post_build_callback
     def sync_perms(erdef, permissions):
         for action, permissions in permissions.items():
diff --git a/dev-requirements.txt b/dev-requirements.txt
--- a/dev-requirements.txt
+++ b/dev-requirements.txt
@@ -2,3 +2,4 @@ mock
 psycopg2
 pytest
 webtest
+http://hg.logilab.org/review/cubes/seda/archive/2823afce6ee5.tar.bz2#egg=cubicweb-seda
diff --git a/test/unittest_schema.py b/test/unittest_schema.py
--- a/test/unittest_schema.py
+++ b/test/unittest_schema.py
@@ -43,7 +43,7 @@ def create_published_records_panel(cnx):
         cnx.commit()
 
 
-class SchemaConstraintsTC(CubicWebTC):
+class SchemaTC(CubicWebTC):
 
     configcls = PostgresApptestConfiguration
     assertValidationError = testutils.assertValidationError
@@ -231,6 +231,23 @@ class SchemaConstraintsTC(CubicWebTC):
             testutils.agent(cnx, u'bob', authority=other_authority)
             cnx.commit()
 
+    def test_can_delete_archiveunit_unlinked_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
+            # First deletion the relation,
+            transfer.cw_set(reverse_seda_archive_unit=None)
+            cnx.commit()
+            # Then delete (old) target.
+            unit.cw_delete()
+            cnx.commit()
+
 
 class AuthorityRecordTC(CubicWebTC):
 



More information about the saem-devel mailing list