--- a/schema.py Thu Jul 07 16:47:34 2011 +0200
+++ b/schema.py Mon Jul 11 09:18:18 2011 +0200
@@ -1011,6 +1011,9 @@
else:
expression = 'S eid %(s)s, O eid %(o)s, ' + self.expression
args = {'s': eidfrom, 'o': eidto}
+ if 'U' in self.rqlst.defined_vars:
+ expression = 'U eid %(u)s, ' + expression
+ args['u'] = session.user.eid
rql = 'Any %s WHERE %s' % (','.join(sorted(self.mainvars)), expression)
if self.distinct_query:
rql = 'DISTINCT ' + rql
--- a/test/unittest_schema.py Thu Jul 07 16:47:34 2011 +0200
+++ b/test/unittest_schema.py Mon Jul 11 09:18:18 2011 +0200
@@ -26,7 +26,7 @@
from rql import RQLSyntaxError
-from yams import BadSchemaDefinition
+from yams import ValidationError, BadSchemaDefinition
from yams.constraints import SizeConstraint, StaticVocabularyConstraint
from yams.buildobjs import RelationDefinition, EntityType, RelationType
from yams.reader import PyFileReader
@@ -37,6 +37,7 @@
RQLExpression, ERQLExpression, RRQLExpression,
normalize_expression, order_eschemas, guess_rrqlexpr_mainvars)
from cubicweb.devtools import TestServerConfiguration as TestConfiguration
+from cubicweb.devtools.testlib import CubicWebTC
DATADIR = join(dirname(__file__), 'data')
@@ -319,5 +320,14 @@
self.assertEqual(mainvars, set(['S', 'O']))
+class RQLConstraintTC(CubicWebTC):
+ def test_user_constraint(self):
+ cstr = RQLConstraint('U identity O')
+ anoneid = self.execute('Any X WHERE X login "anon"')[0][0]
+ self.assertRaises(ValidationError, cstr.repo_check, self.session, 1, 'rel', anoneid)
+ self.assertEqual(cstr.repo_check(self.session, 1, self.session.user.eid),
+ None) # no validation error, constraint checked
+
+
if __name__ == '__main__':
unittest_main()