15 |
15 |
16 from logilab.common.decorators import cached, clear_cache, monkeypatch |
16 from logilab.common.decorators import cached, clear_cache, monkeypatch |
17 from logilab.common.deprecation import obsolete |
17 from logilab.common.deprecation import obsolete |
18 from logilab.common.compat import any |
18 from logilab.common.compat import any |
19 |
19 |
20 from yams import BadSchemaDefinition, buildobjs as ybo, constraints |
20 from yams import BadSchemaDefinition, buildobjs as ybo |
21 from yams.schema import Schema, ERSchema, EntitySchema, RelationSchema |
21 from yams.schema import Schema, ERSchema, EntitySchema, RelationSchema |
22 from yams.constraints import BaseConstraint, StaticVocabularyConstraint |
22 from yams.constraints import (BaseConstraint, StaticVocabularyConstraint, |
23 from yams.reader import CONSTRAINTS, PyFileReader, SchemaLoader, \ |
23 FormatConstraint) |
24 obsolete as yobsolete, cleanup_sys_modules |
24 from yams.reader import (CONSTRAINTS, PyFileReader, SchemaLoader, |
|
25 obsolete as yobsolete, cleanup_sys_modules) |
25 |
26 |
26 from rql import parse, nodes, RQLSyntaxError, TypeResolverException |
27 from rql import parse, nodes, RQLSyntaxError, TypeResolverException |
27 |
28 |
28 from cubicweb import ETYPE_NAME_MAP, ValidationError, Unauthorized |
29 from cubicweb import ETYPE_NAME_MAP, ValidationError, Unauthorized |
29 from cubicweb import set_log_methods |
30 from cubicweb import set_log_methods |
894 # _() is just there to add messages to the catalog, don't care about actual |
895 # _() is just there to add messages to the catalog, don't care about actual |
895 # translation |
896 # translation |
896 PERM_USE_TEMPLATE_FORMAT = _('use_template_format') |
897 PERM_USE_TEMPLATE_FORMAT = _('use_template_format') |
897 NEED_PERM_FORMATS = [_('text/cubicweb-page-template')] |
898 NEED_PERM_FORMATS = [_('text/cubicweb-page-template')] |
898 |
899 |
899 @monkeypatch(constraints.FormatConstraint) |
900 @monkeypatch(FormatConstraint) |
900 def vocabulary(self, entity=None, req=None): |
901 def vocabulary(self, entity=None, req=None): |
901 if req is None and entity is not None: |
902 if req is None and entity is not None: |
902 req = entity.req |
903 req = entity.req |
903 if req is not None and req.user.has_permission(PERM_USE_TEMPLATE_FORMAT): |
904 if req is not None and req.user.has_permission(PERM_USE_TEMPLATE_FORMAT): |
904 return self.regular_formats + tuple(NEED_PERM_FORMATS) |
905 return self.regular_formats + tuple(NEED_PERM_FORMATS) |