Fix selector of manage view and action
authorSylvain Thénault <sylvain.thenault@logilab.fr>
Fri, 24 Feb 2017 16:26:00 +0100
changeset 176 e1f4c31c2414
parent 169 efcc1ab69722
child 177 3efd0259a9ac
Fix selector of manage view and action Without strict=True, predicate is always true because owned_by as some local role.
cubicweb_sherpa/views/management.py
test/test_management.py
--- a/cubicweb_sherpa/views/management.py	Wed Feb 22 18:06:29 2017 +0100
+++ b/cubicweb_sherpa/views/management.py	Fri Feb 24 16:26:00 2017 +0100
@@ -28,7 +28,7 @@
     """Security view overriden to hide permissions definitions and using a
     RelationFacetWidget to edit owner"""
     __select__ = (management.SecurityManagementView.__select__ &
-                  relation_possible('owned_by', action='add'))
+                  relation_possible('owned_by', action='add', strict=True))
 
     def entity_call(self, entity):
         w = self.w
@@ -56,7 +56,7 @@
 
 actions.ManagePermissionsAction.__select__ = (
     action.Action.__select__ & one_line_rset() & non_final_entity()
-    & relation_possible('owned_by', action='add'))
+    & relation_possible('owned_by', action='add', strict=True))
 
 
 def registration_callback(vreg):
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/test_management.py	Fri Feb 24 16:26:00 2017 +0100
@@ -0,0 +1,42 @@
+# copyright 2017 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
+# contact http://www.logilab.fr -- mailto:contact@logilab.fr
+#
+# This program is free software: you can redistribute it and/or modify it under
+# the terms of the GNU Lesser General Public License as published by the Free
+# Software Foundation, either version 2.1 of the License, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+# FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
+# details.
+#
+# You should have received a copy of the GNU Lesser General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+from cubicweb.devtools.testlib import CubicWebTC
+from cubicweb.web.views import actions
+
+
+class ActionTC(CubicWebTC):
+
+    def test_management(self):
+        with self.admin_access.cnx() as cnx:
+            at = cnx.create_entity('SEDAArchiveTransfer', title=u'hop')
+            self.create_user(cnx, 'user')
+            cnx.commit()
+
+        with self.admin_access.web_request() as req:
+            rset = req.entity_from_eid(at.eid).as_rset()
+            actionsdict = self.pactionsdict(req, rset)
+            self.assertIn(actions.ManagePermissionsAction, actionsdict['moreactions'])
+
+        with self.new_access('user').web_request() as req:
+            rset = req.entity_from_eid(at.eid).as_rset()
+            actionsdict = self.pactionsdict(req, rset)
+            self.assertNotIn(actions.ManagePermissionsAction, actionsdict['moreactions'])
+
+
+if __name__ == '__main__':
+    import unittest
+    unittest.main()