[schema] set permissions that do not allow edition on computed relation. Closes #4903918
authorSylvain Thénault <sylvain.thenault@logilab.fr>
Wed, 04 Feb 2015 21:55:37 +0100
changeset 10193 a0a11be5a9cb
parent 10192 365e5a0287d6
child 10194 49831fdc84dc
[schema] set permissions that do not allow edition on computed relation. Closes #4903918 Also, drop 'del schema' from test which clutters the code for no benefit.
schema.py
test/unittest_schema.py
--- a/schema.py	Mon Feb 02 23:17:15 2015 +0100
+++ b/schema.py	Wed Feb 04 21:55:37 2015 +0100
@@ -1094,7 +1094,10 @@
                 if self[objtype].final:
                     raise BadSchemaDefinition('computed relations cannot be final')
                 rdef = ybo.RelationDefinition(
-                    subjtype, rschema.type, objtype)
+                    subjtype, rschema.type, objtype,
+                    __permissions__={'add': (),
+                                     'delete': (),
+                                     'read': ('managers', 'users', 'guests')})
                 rdef.infered = True
                 self.add_relation_def(rdef)
 
--- a/test/unittest_schema.py	Mon Feb 02 23:17:15 2015 +0100
+++ b/test/unittest_schema.py	Wed Feb 04 21:55:37 2015 +0100
@@ -298,10 +298,14 @@
             total_salary = Int(formula='Any SUM(SA) GROUPBY X WHERE '
                                        'P works_for X, P salary SA')
         good_schema = build_schema_from_namespace(vars().items())
-
+        rdef = good_schema['Company'].rdef('total_salary')
         # ensure 'X is Company' is added to the rqlst to avoid ambiguities, see #4901163
-        self.assertEqual(str(good_schema['Company'].rdef('total_salary').formula_select),
+        self.assertEqual(str(rdef.formula_select),
                          'Any SUM(SA) GROUPBY X WHERE P works_for X, P salary SA, X is Company')
+        # check relation definition permissions
+        self.assertEqual(rdef.permissions,
+                         {'add': (), 'update': (),
+                          'read': ('managers', 'users', 'guests')})
 
         class Company(EntityType):
             total_salary = String(formula='Any SUM(SA) GROUPBY X WHERE '
@@ -358,11 +362,15 @@
                          schema['produces_and_buys2'].rdefs.keys())
         self.assertEqual([('Company', 'Service'), ('Person', 'Service')],
                          schema['reproduce'].rdefs.keys())
-        # check relations as marked infered
-        self.assertTrue(
-            schema['produces_and_buys'].rdefs[('Person','Service')].infered)
+        # check relation definitions are marked infered
+        rdef = schema['produces_and_buys'].rdefs[('Person','Service')]
+        self.assertTrue(rdef.infered)
+        # and have no add/delete permissions
+        self.assertEqual(rdef.permissions,
+                         {'add': (),
+                          'delete': (),
+                          'read': ('managers', 'users', 'guests')})
 
-        del schema
         class autoname(ComputedRelation):
             rule = 'S produce X, X name O'