--- a/schema.py Thu Dec 08 14:29:48 2011 +0100
+++ b/schema.py Fri Dec 09 12:08:44 2011 +0100
@@ -59,12 +59,11 @@
'from_state', 'to_state', 'condition',
'subworkflow', 'subworkflow_state', 'subworkflow_exit',
))
-SYSTEM_RTYPES = set(('in_group', 'require_group', 'require_permission',
+SYSTEM_RTYPES = set(('in_group', 'require_group',
# cwproperty
'for_user',
)) | WORKFLOW_RTYPES
NO_I18NCONTEXT = META_RTYPES | WORKFLOW_RTYPES
-NO_I18NCONTEXT.add('require_permission')
SKIP_COMPOSITE_RELS = [('cw_source', 'subject')]
@@ -85,7 +84,7 @@
'WorkflowTransition', 'BaseTransition',
'SubWorkflowExitPoint'))
-INTERNAL_TYPES = set(('CWProperty', 'CWPermission', 'CWCache', 'ExternalUri',
+INTERNAL_TYPES = set(('CWProperty', 'CWCache', 'ExternalUri',
'CWSource', 'CWSourceHostConfig', 'CWSourceSchemaConfig'))
@@ -171,13 +170,10 @@
if form:
key = key + '_' + form
# ensure unicode
- # .lower() in case no translation are available XXX done whatever a translation is there or not!
if context is not None:
- return unicode(req.pgettext(context, key)).lower()
+ return unicode(req.pgettext(context, key))
else:
- return unicode(req._(key)).lower()
-
-__builtins__['display_name'] = deprecated('[3.4] display_name should be imported from cubicweb.schema')(display_name)
+ return unicode(req._(key))
# Schema objects definition ###################################################
@@ -852,23 +848,39 @@
return self._check(session, **kwargs)
+def vargraph(rqlst):
+ """ builds an adjacency graph of variables from the rql syntax tree, e.g:
+ Any O,S WHERE T subworkflow_exit S, T subworkflow WF, O state_of WF
+ => {'WF': ['O', 'T'], 'S': ['T'], 'T': ['WF', 'S'], 'O': ['WF']}
+ """
+ vargraph = {}
+ for relation in rqlst.get_nodes(nodes.Relation):
+ try:
+ rhsvarname = relation.children[1].children[0].variable.name
+ lhsvarname = relation.children[0].name
+ except AttributeError:
+ pass
+ else:
+ vargraph.setdefault(lhsvarname, []).append(rhsvarname)
+ vargraph.setdefault(rhsvarname, []).append(lhsvarname)
+ #vargraph[(lhsvarname, rhsvarname)] = relation.r_type
+ return vargraph
+
+
+class GeneratedConstraint(object):
+ def __init__(self, rqlst, mainvars):
+ self.snippet_rqlst = rqlst
+ self.mainvars = mainvars
+ self.vargraph = vargraph(rqlst)
+
+
class RRQLExpression(RQLExpression):
def __init__(self, expression, mainvars=None, eid=None):
if mainvars is None:
mainvars = guess_rrqlexpr_mainvars(expression)
RQLExpression.__init__(self, expression, mainvars, eid)
# graph of links between variable, used by rql rewriter
- self.vargraph = {}
- for relation in self.rqlst.get_nodes(nodes.Relation):
- try:
- rhsvarname = relation.children[1].children[0].variable.name
- lhsvarname = relation.children[0].name
- except AttributeError:
- pass
- else:
- self.vargraph.setdefault(lhsvarname, []).append(rhsvarname)
- self.vargraph.setdefault(rhsvarname, []).append(lhsvarname)
- #self.vargraph[(lhsvarname, rhsvarname)] = relation.r_type
+ self.vargraph = vargraph(self.rqlst)
@property
def full_rql(self):
@@ -959,7 +971,7 @@
def repo_check(self, session, eidfrom, rtype, eidto):
"""raise ValidationError if the relation doesn't satisfy the constraint
"""
- pass # this is a vocabulary constraint, not enforce
+ pass # this is a vocabulary constraint, not enforced
class RepoEnforcedRQLConstraintMixIn(object):
@@ -1176,7 +1188,7 @@
# _() is just there to add messages to the catalog, don't care about actual
# translation
-PERM_USE_TEMPLATE_FORMAT = _('use_template_format')
+MAY_USE_TEMPLATE_FORMAT = set(('managers',))
NEED_PERM_FORMATS = [_('text/cubicweb-page-template')]
@monkeypatch(FormatConstraint)
@@ -1191,9 +1203,9 @@
# cw is a server session
hasperm = not cw.write_security or \
not cw.is_hook_category_activated('integrity') or \
- cw.user.has_permission(PERM_USE_TEMPLATE_FORMAT)
+ cw.user.matching_groups(MAY_USE_TEMPLATE_FORMAT)
else:
- hasperm = cw.user.has_permission(PERM_USE_TEMPLATE_FORMAT)
+ hasperm = cw.user.matching_groups(MAY_USE_TEMPLATE_FORMAT)
if hasperm:
return self.regular_formats + tuple(NEED_PERM_FORMATS)
return self.regular_formats