[PATCH 1 of 4 saem_ref] Let publication_permissions() accept a list of states to configure permissions

Denis Laxalde denis.laxalde at logilab.fr
Fri Apr 13 14:35:07 CEST 2018


# HG changeset patch
# User Denis Laxalde <denis.laxalde at logilab.fr>
# Date 1523539449 -7200
#      Thu Apr 12 15:24:09 2018 +0200
# Node ID 31a3846bab46a63f4832bd37a5a1fbeef3a451e3
# Parent  1643e1be9c15edba6416480e0e353988893bfa99
# Available At http://hg.logilab.org/review/cubes/saem_ref
#              hg pull http://hg.logilab.org/review/cubes/saem_ref -r 31a3846bab46
# EXP-Topic CONSEJIRA-447
Let publication_permissions() accept a list of states to configure permissions

We thus turn RQL expression to use IN, hence changes in permissions
test.

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
@@ -33,19 +33,21 @@ from cubicweb_seda.schema.seda2 import S
 from cubicweb_compound import utils
 
 
-def publication_permissions(cls, groups=('managers', 'users')):
+def publication_permissions(cls, groups=('managers', 'users'),
+                            states=('draft', )):
     """Set __permissions__ of `cls` entity type class preventing modification
-    when not in state "draft".
+    when not in specified states.
     """
     groups = ', '.join('"{}"'.format(group) for group in groups)
+    states = ', '.join('"{}"'.format(state) for state in states)
     cls.__permissions__ = cls.__permissions__.copy()
     cls.__permissions__['update'] = (
         ERQLExpression('U in_group G, G name IN ({}), '
-                       'X in_state ST, ST name "draft"'.format(groups)),
+                       'X in_state ST, ST name IN ({})'.format(groups, states)),
     )
     cls.__permissions__['delete'] = (
         ERQLExpression('U in_group G, G name IN ({}), '
-                       'X in_state ST, ST name "draft"'.format(groups)),
+                       'X in_state ST, ST name IN ({})'.format(groups, states)),
     )
     return cls
 



More information about the saem-devel mailing list