author | Julien Cristau <julien.cristau@logilab.fr> |
Tue, 22 Apr 2014 15:18:04 +0200 | |
changeset 9689 | 9e4a3c8719a7 |
parent 9660 | a78efec4cf04 |
child 9711 | 59616edc20d7 |
permissions | -rw-r--r-- |
9547
43aace16a953
[schema] add composite handling helpers on EntitySchema (related to #3463112)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9469
diff
changeset
|
1 |
# copyright 2003-2014 LOGILAB S.A. (Paris, FRANCE), all rights reserved. |
5421
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5122
diff
changeset
|
2 |
# contact http://www.logilab.fr/ -- mailto:contact@logilab.fr |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5122
diff
changeset
|
3 |
# |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5122
diff
changeset
|
4 |
# This file is part of CubicWeb. |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5122
diff
changeset
|
5 |
# |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5122
diff
changeset
|
6 |
# CubicWeb is free software: you can redistribute it and/or modify it under the |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5122
diff
changeset
|
7 |
# terms of the GNU Lesser General Public License as published by the Free |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5122
diff
changeset
|
8 |
# Software Foundation, either version 2.1 of the License, or (at your option) |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5122
diff
changeset
|
9 |
# any later version. |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5122
diff
changeset
|
10 |
# |
5424
8ecbcbff9777
replace logilab-common by CubicWeb in disclaimer
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5421
diff
changeset
|
11 |
# CubicWeb is distributed in the hope that it will be useful, but WITHOUT |
5421
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5122
diff
changeset
|
12 |
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5122
diff
changeset
|
13 |
# FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5122
diff
changeset
|
14 |
# details. |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5122
diff
changeset
|
15 |
# |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5122
diff
changeset
|
16 |
# You should have received a copy of the GNU Lesser General Public License along |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5122
diff
changeset
|
17 |
# with CubicWeb. If not, see <http://www.gnu.org/licenses/>. |
6017
5f6a60ea8544
[relations in ui] provide context information when computing label for a relation
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5896
diff
changeset
|
18 |
"""classes to define schemas for CubicWeb""" |
0 | 19 |
|
20 |
__docformat__ = "restructuredtext en" |
|
2142
098aa2075903
include_schema_files is useless
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
21 |
_ = unicode |
0 | 22 |
|
23 |
import re |
|
9366
bcbc92223b35
set proper PACKAGE information for yams 0.39
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9283
diff
changeset
|
24 |
from os.path import join, basename |
0 | 25 |
from logging import getLogger |
1133 | 26 |
from warnings import warn |
0 | 27 |
|
9366
bcbc92223b35
set proper PACKAGE information for yams 0.39
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9283
diff
changeset
|
28 |
from logilab.common import tempattr |
9280
bae0caa8477a
[schema] edit syntax tree instead of playing with strings for RQLExpressions
Julien Cristau <julien.cristau@logilab.fr>
parents:
9262
diff
changeset
|
29 |
from logilab.common.decorators import cached, clear_cache, monkeypatch, cachedproperty |
2730
bb6fcb8c5d71
to make cw schemas importable, they have to be installed w/ cw code, not in /usr/share/cubicweb/schemas
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2718
diff
changeset
|
30 |
from logilab.common.logging_ext import set_log_methods |
8256
852c73392b00
[schema] make cubicweb 3.14 compatible with yams 0.35
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8160
diff
changeset
|
31 |
from logilab.common.deprecation import deprecated, class_moved, moved |
7152
39c1ffc7d93f
[schema, refactoring] use RQLExpression as base class for RQL constraint classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7103
diff
changeset
|
32 |
from logilab.common.textutils import splitstrip |
2926
4484387ed012
when adding/removing cubes, we should add/remove entity types in correct order if one inherits from another
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2782
diff
changeset
|
33 |
from logilab.common.graph import get_cycles |
0 | 34 |
from logilab.common.compat import any |
35 |
||
2531
531ea4e7013e
[cleanup] nicer imports
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
2526
diff
changeset
|
36 |
from yams import BadSchemaDefinition, buildobjs as ybo |
3877
7ca53fc72a0a
reldefsecurity branch :
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3827
diff
changeset
|
37 |
from yams.schema import Schema, ERSchema, EntitySchema, RelationSchema, \ |
5030
5238d9a8dfee
[form] put qualified name on validation error, should fix #784299
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4913
diff
changeset
|
38 |
RelationDefinitionSchema, PermissionMixIn, role_name |
4717
535705688f4f
proper deprecation warning when import class that should be imported from yams
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4702
diff
changeset
|
39 |
from yams.constraints import BaseConstraint, FormatConstraint |
2531
531ea4e7013e
[cleanup] nicer imports
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
2526
diff
changeset
|
40 |
from yams.reader import (CONSTRAINTS, PyFileReader, SchemaLoader, |
531ea4e7013e
[cleanup] nicer imports
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
2526
diff
changeset
|
41 |
obsolete as yobsolete, cleanup_sys_modules) |
0 | 42 |
|
43 |
from rql import parse, nodes, RQLSyntaxError, TypeResolverException |
|
44 |
||
2730
bb6fcb8c5d71
to make cw schemas importable, they have to be installed w/ cw code, not in /usr/share/cubicweb/schemas
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2718
diff
changeset
|
45 |
import cubicweb |
0 | 46 |
from cubicweb import ETYPE_NAME_MAP, ValidationError, Unauthorized |
47 |
||
9148
1b549c1acd4f
[schema,server] add a security debugging aid (closes #2920304)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8945
diff
changeset
|
48 |
try: |
1b549c1acd4f
[schema,server] add a security debugging aid (closes #2920304)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8945
diff
changeset
|
49 |
from cubicweb import server |
1b549c1acd4f
[schema,server] add a security debugging aid (closes #2920304)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8945
diff
changeset
|
50 |
except ImportError: |
1b549c1acd4f
[schema,server] add a security debugging aid (closes #2920304)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8945
diff
changeset
|
51 |
# We need to lookup DEBUG from there, |
1b549c1acd4f
[schema,server] add a security debugging aid (closes #2920304)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8945
diff
changeset
|
52 |
# however a pure dbapi client may not have it. |
1b549c1acd4f
[schema,server] add a security debugging aid (closes #2920304)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8945
diff
changeset
|
53 |
class server(object): pass |
1b549c1acd4f
[schema,server] add a security debugging aid (closes #2920304)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8945
diff
changeset
|
54 |
server.DEBUG = False |
1b549c1acd4f
[schema,server] add a security debugging aid (closes #2920304)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8945
diff
changeset
|
55 |
|
1b549c1acd4f
[schema,server] add a security debugging aid (closes #2920304)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8945
diff
changeset
|
56 |
|
2596
d02eed70937f
[R repo, schema] use VIRTUAL_RTYPES const
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2531
diff
changeset
|
57 |
PURE_VIRTUAL_RTYPES = set(('identity', 'has_text',)) |
d02eed70937f
[R repo, schema] use VIRTUAL_RTYPES const
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2531
diff
changeset
|
58 |
VIRTUAL_RTYPES = set(('eid', 'identity', 'has_text',)) |
d02eed70937f
[R repo, schema] use VIRTUAL_RTYPES const
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2531
diff
changeset
|
59 |
|
4913
083b4d454192
server/web api for accessing to deleted_entites
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
4843
diff
changeset
|
60 |
# set of meta-relations available for every entity types |
2622
3c7edaa6c6d2
oops, should have been in a earlier commit (META_RELATION_TYPES renaming)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2616
diff
changeset
|
61 |
META_RTYPES = set(( |
2126
a25859917ccc
stop using meta attribute from yams schema. Use instead sets defining meta relations and another defining schema types. Refactor various schema view based on this
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
62 |
'owned_by', 'created_by', 'is', 'is_instance_of', 'identity', |
6427
c8a5ac2d1eaa
[schema / sources] store data sources as cubicweb entities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6377
diff
changeset
|
63 |
'eid', 'creation_date', 'cw_source', 'modification_date', 'has_text', 'cwuri', |
2184 | 64 |
)) |
6375
df4fd2a1b0e7
[schema] introduce new WORKFLOW_RTYPES set and use it to build SYSTEM_RTYPES/DONT_CHECK_RTYPES_ON_ADD/DONT_CHECK_RTYPES_ON_DEL sets
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6262
diff
changeset
|
65 |
WORKFLOW_RTYPES = set(('custom_workflow', 'in_state', 'wf_info_for')) |
6377
3bb415310d4f
[schema] introduce some new sets categorizing entity/relation types and benefits from them where possible
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6375
diff
changeset
|
66 |
WORKFLOW_DEF_RTYPES = set(('workflow_of', 'state_of', 'transition_of', |
3bb415310d4f
[schema] introduce some new sets categorizing entity/relation types and benefits from them where possible
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6375
diff
changeset
|
67 |
'initial_state', 'default_workflow', |
3bb415310d4f
[schema] introduce some new sets categorizing entity/relation types and benefits from them where possible
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6375
diff
changeset
|
68 |
'allowed_transition', 'destination_state', |
3bb415310d4f
[schema] introduce some new sets categorizing entity/relation types and benefits from them where possible
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6375
diff
changeset
|
69 |
'from_state', 'to_state', 'condition', |
3bb415310d4f
[schema] introduce some new sets categorizing entity/relation types and benefits from them where possible
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6375
diff
changeset
|
70 |
'subworkflow', 'subworkflow_state', 'subworkflow_exit', |
9660
a78efec4cf04
Add missing relation types items in schema global variables
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
9635
diff
changeset
|
71 |
'by_transition', |
6377
3bb415310d4f
[schema] introduce some new sets categorizing entity/relation types and benefits from them where possible
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6375
diff
changeset
|
72 |
)) |
7797
a71618a75b53
backport stable
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7782
diff
changeset
|
73 |
SYSTEM_RTYPES = set(('in_group', 'require_group', |
6377
3bb415310d4f
[schema] introduce some new sets categorizing entity/relation types and benefits from them where possible
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6375
diff
changeset
|
74 |
# cwproperty |
3bb415310d4f
[schema] introduce some new sets categorizing entity/relation types and benefits from them where possible
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6375
diff
changeset
|
75 |
'for_user', |
9660
a78efec4cf04
Add missing relation types items in schema global variables
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
9635
diff
changeset
|
76 |
'cw_schema', 'cw_import_of', 'cw_for_source', |
a78efec4cf04
Add missing relation types items in schema global variables
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
9635
diff
changeset
|
77 |
'cw_host_config_of', |
6377
3bb415310d4f
[schema] introduce some new sets categorizing entity/relation types and benefits from them where possible
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6375
diff
changeset
|
78 |
)) | WORKFLOW_RTYPES |
6481
103774c8c215
[schema categorization] new NO_I18NCONTEXT set usable to somewhat control c-c i18n
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6427
diff
changeset
|
79 |
NO_I18NCONTEXT = META_RTYPES | WORKFLOW_RTYPES |
0 | 80 |
|
6951
cb6314b09e0f
[schema, ui] fix is_subobject to skip cw_source relation (else everything is considered as a subobject, since this relation is now composite)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6949
diff
changeset
|
81 |
SKIP_COMPOSITE_RELS = [('cw_source', 'subject')] |
cb6314b09e0f
[schema, ui] fix is_subobject to skip cw_source relation (else everything is considered as a subobject, since this relation is now composite)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6949
diff
changeset
|
82 |
|
4913
083b4d454192
server/web api for accessing to deleted_entites
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
4843
diff
changeset
|
83 |
# set of entity and relation types used to build the schema |
2126
a25859917ccc
stop using meta attribute from yams schema. Use instead sets defining meta relations and another defining schema types. Refactor various schema view based on this
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
84 |
SCHEMA_TYPES = set(( |
a25859917ccc
stop using meta attribute from yams schema. Use instead sets defining meta relations and another defining schema types. Refactor various schema view based on this
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
85 |
'CWEType', 'CWRType', 'CWAttribute', 'CWRelation', |
6229
c4a70a5dd144
[schema] mark CWUniqueTogetherConstraint and its relations as schema entity/relations
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6191
diff
changeset
|
86 |
'CWConstraint', 'CWConstraintType', 'CWUniqueTogetherConstraint', |
c4a70a5dd144
[schema] mark CWUniqueTogetherConstraint and its relations as schema entity/relations
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6191
diff
changeset
|
87 |
'RQLExpression', |
6377
3bb415310d4f
[schema] introduce some new sets categorizing entity/relation types and benefits from them where possible
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6375
diff
changeset
|
88 |
'specializes', |
2126
a25859917ccc
stop using meta attribute from yams schema. Use instead sets defining meta relations and another defining schema types. Refactor various schema view based on this
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
89 |
'relation_type', 'from_entity', 'to_entity', |
a25859917ccc
stop using meta attribute from yams schema. Use instead sets defining meta relations and another defining schema types. Refactor various schema view based on this
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
90 |
'constrained_by', 'cstrtype', |
6229
c4a70a5dd144
[schema] mark CWUniqueTogetherConstraint and its relations as schema entity/relations
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6191
diff
changeset
|
91 |
'constraint_of', 'relations', |
6262
84901d735156
add permission relations to schema types
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6233
diff
changeset
|
92 |
'read_permission', 'add_permission', |
84901d735156
add permission relations to schema types
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6233
diff
changeset
|
93 |
'delete_permission', 'update_permission', |
2126
a25859917ccc
stop using meta attribute from yams schema. Use instead sets defining meta relations and another defining schema types. Refactor various schema view based on this
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
94 |
)) |
0 | 95 |
|
4434
101344a6ff9b
Improve the schema command with filtering option.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
4252
diff
changeset
|
96 |
WORKFLOW_TYPES = set(('Transition', 'State', 'TrInfo', 'Workflow', |
4759 | 97 |
'WorkflowTransition', 'BaseTransition', |
98 |
'SubWorkflowExitPoint')) |
|
99 |
||
9173
f3286e817f28
[schema] mark CWDataImport as an internal type. Closes #3025536
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9168
diff
changeset
|
100 |
INTERNAL_TYPES = set(('CWProperty', 'CWCache', 'ExternalUri', 'CWDataImport', |
6949
267ce7cf77f1
[test, ui] mark CWSourceSchemaConfig as an internal type
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6944
diff
changeset
|
101 |
'CWSource', 'CWSourceHostConfig', 'CWSourceSchemaConfig')) |
4434
101344a6ff9b
Improve the schema command with filtering option.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
4252
diff
changeset
|
102 |
|
101344a6ff9b
Improve the schema command with filtering option.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
4252
diff
changeset
|
103 |
|
2142
098aa2075903
include_schema_files is useless
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
104 |
_LOGGER = getLogger('cubicweb.schemaloader') |
0 | 105 |
|
8945
ba9e3fbfa5a5
[schemaserial] serialize additional yams parameter for customs type
Vincent Michel <vincent.michel@logilab.fr>
parents:
8892
diff
changeset
|
106 |
# entity and relation schema created from serialized schema have an eid |
0 | 107 |
ybo.ETYPE_PROPERTIES += ('eid',) |
108 |
ybo.RTYPE_PROPERTIES += ('eid',) |
|
2926
4484387ed012
when adding/removing cubes, we should add/remove entity types in correct order if one inherits from another
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2782
diff
changeset
|
109 |
|
9393
8266c8c375bb
[schema] move definition of RQLExpression classes before default permission dicts
Julien Cristau <julien.cristau@logilab.fr>
parents:
9366
diff
changeset
|
110 |
# Bases for manipulating RQL in schema ######################################### |
8266c8c375bb
[schema] move definition of RQLExpression classes before default permission dicts
Julien Cristau <julien.cristau@logilab.fr>
parents:
9366
diff
changeset
|
111 |
|
8266c8c375bb
[schema] move definition of RQLExpression classes before default permission dicts
Julien Cristau <julien.cristau@logilab.fr>
parents:
9366
diff
changeset
|
112 |
def guess_rrqlexpr_mainvars(expression): |
8266c8c375bb
[schema] move definition of RQLExpression classes before default permission dicts
Julien Cristau <julien.cristau@logilab.fr>
parents:
9366
diff
changeset
|
113 |
defined = set(split_expression(expression)) |
8266c8c375bb
[schema] move definition of RQLExpression classes before default permission dicts
Julien Cristau <julien.cristau@logilab.fr>
parents:
9366
diff
changeset
|
114 |
mainvars = set() |
8266c8c375bb
[schema] move definition of RQLExpression classes before default permission dicts
Julien Cristau <julien.cristau@logilab.fr>
parents:
9366
diff
changeset
|
115 |
if 'S' in defined: |
8266c8c375bb
[schema] move definition of RQLExpression classes before default permission dicts
Julien Cristau <julien.cristau@logilab.fr>
parents:
9366
diff
changeset
|
116 |
mainvars.add('S') |
8266c8c375bb
[schema] move definition of RQLExpression classes before default permission dicts
Julien Cristau <julien.cristau@logilab.fr>
parents:
9366
diff
changeset
|
117 |
if 'O' in defined: |
8266c8c375bb
[schema] move definition of RQLExpression classes before default permission dicts
Julien Cristau <julien.cristau@logilab.fr>
parents:
9366
diff
changeset
|
118 |
mainvars.add('O') |
8266c8c375bb
[schema] move definition of RQLExpression classes before default permission dicts
Julien Cristau <julien.cristau@logilab.fr>
parents:
9366
diff
changeset
|
119 |
if 'U' in defined: |
8266c8c375bb
[schema] move definition of RQLExpression classes before default permission dicts
Julien Cristau <julien.cristau@logilab.fr>
parents:
9366
diff
changeset
|
120 |
mainvars.add('U') |
8266c8c375bb
[schema] move definition of RQLExpression classes before default permission dicts
Julien Cristau <julien.cristau@logilab.fr>
parents:
9366
diff
changeset
|
121 |
if not mainvars: |
8266c8c375bb
[schema] move definition of RQLExpression classes before default permission dicts
Julien Cristau <julien.cristau@logilab.fr>
parents:
9366
diff
changeset
|
122 |
raise Exception('unable to guess selection variables') |
8266c8c375bb
[schema] move definition of RQLExpression classes before default permission dicts
Julien Cristau <julien.cristau@logilab.fr>
parents:
9366
diff
changeset
|
123 |
return mainvars |
8266c8c375bb
[schema] move definition of RQLExpression classes before default permission dicts
Julien Cristau <julien.cristau@logilab.fr>
parents:
9366
diff
changeset
|
124 |
|
8266c8c375bb
[schema] move definition of RQLExpression classes before default permission dicts
Julien Cristau <julien.cristau@logilab.fr>
parents:
9366
diff
changeset
|
125 |
def split_expression(rqlstring): |
8266c8c375bb
[schema] move definition of RQLExpression classes before default permission dicts
Julien Cristau <julien.cristau@logilab.fr>
parents:
9366
diff
changeset
|
126 |
for expr in rqlstring.split(','): |
8266c8c375bb
[schema] move definition of RQLExpression classes before default permission dicts
Julien Cristau <julien.cristau@logilab.fr>
parents:
9366
diff
changeset
|
127 |
for noparen1 in expr.split('('): |
8266c8c375bb
[schema] move definition of RQLExpression classes before default permission dicts
Julien Cristau <julien.cristau@logilab.fr>
parents:
9366
diff
changeset
|
128 |
for noparen2 in noparen1.split(')'): |
8266c8c375bb
[schema] move definition of RQLExpression classes before default permission dicts
Julien Cristau <julien.cristau@logilab.fr>
parents:
9366
diff
changeset
|
129 |
for word in noparen2.split(): |
8266c8c375bb
[schema] move definition of RQLExpression classes before default permission dicts
Julien Cristau <julien.cristau@logilab.fr>
parents:
9366
diff
changeset
|
130 |
yield word |
8266c8c375bb
[schema] move definition of RQLExpression classes before default permission dicts
Julien Cristau <julien.cristau@logilab.fr>
parents:
9366
diff
changeset
|
131 |
|
8266c8c375bb
[schema] move definition of RQLExpression classes before default permission dicts
Julien Cristau <julien.cristau@logilab.fr>
parents:
9366
diff
changeset
|
132 |
def normalize_expression(rqlstring): |
8266c8c375bb
[schema] move definition of RQLExpression classes before default permission dicts
Julien Cristau <julien.cristau@logilab.fr>
parents:
9366
diff
changeset
|
133 |
"""normalize an rql expression to ease schema synchronization (avoid |
8266c8c375bb
[schema] move definition of RQLExpression classes before default permission dicts
Julien Cristau <julien.cristau@logilab.fr>
parents:
9366
diff
changeset
|
134 |
suppressing and reinserting an expression if only a space has been |
8266c8c375bb
[schema] move definition of RQLExpression classes before default permission dicts
Julien Cristau <julien.cristau@logilab.fr>
parents:
9366
diff
changeset
|
135 |
added/removed for instance) |
8266c8c375bb
[schema] move definition of RQLExpression classes before default permission dicts
Julien Cristau <julien.cristau@logilab.fr>
parents:
9366
diff
changeset
|
136 |
""" |
8266c8c375bb
[schema] move definition of RQLExpression classes before default permission dicts
Julien Cristau <julien.cristau@logilab.fr>
parents:
9366
diff
changeset
|
137 |
return u', '.join(' '.join(expr.split()) for expr in rqlstring.split(',')) |
8266c8c375bb
[schema] move definition of RQLExpression classes before default permission dicts
Julien Cristau <julien.cristau@logilab.fr>
parents:
9366
diff
changeset
|
138 |
|
8266c8c375bb
[schema] move definition of RQLExpression classes before default permission dicts
Julien Cristau <julien.cristau@logilab.fr>
parents:
9366
diff
changeset
|
139 |
|
8266c8c375bb
[schema] move definition of RQLExpression classes before default permission dicts
Julien Cristau <julien.cristau@logilab.fr>
parents:
9366
diff
changeset
|
140 |
class RQLExpression(object): |
8266c8c375bb
[schema] move definition of RQLExpression classes before default permission dicts
Julien Cristau <julien.cristau@logilab.fr>
parents:
9366
diff
changeset
|
141 |
"""Base class for RQL expression used in schema (constraints and |
8266c8c375bb
[schema] move definition of RQLExpression classes before default permission dicts
Julien Cristau <julien.cristau@logilab.fr>
parents:
9366
diff
changeset
|
142 |
permissions) |
8266c8c375bb
[schema] move definition of RQLExpression classes before default permission dicts
Julien Cristau <julien.cristau@logilab.fr>
parents:
9366
diff
changeset
|
143 |
""" |
8266c8c375bb
[schema] move definition of RQLExpression classes before default permission dicts
Julien Cristau <julien.cristau@logilab.fr>
parents:
9366
diff
changeset
|
144 |
# these are overridden by set_log_methods below |
8266c8c375bb
[schema] move definition of RQLExpression classes before default permission dicts
Julien Cristau <julien.cristau@logilab.fr>
parents:
9366
diff
changeset
|
145 |
# only defining here to prevent pylint from complaining |
8266c8c375bb
[schema] move definition of RQLExpression classes before default permission dicts
Julien Cristau <julien.cristau@logilab.fr>
parents:
9366
diff
changeset
|
146 |
info = warning = error = critical = exception = debug = lambda msg,*a,**kw: None |
8266c8c375bb
[schema] move definition of RQLExpression classes before default permission dicts
Julien Cristau <julien.cristau@logilab.fr>
parents:
9366
diff
changeset
|
147 |
# to be defined in concrete classes |
8266c8c375bb
[schema] move definition of RQLExpression classes before default permission dicts
Julien Cristau <julien.cristau@logilab.fr>
parents:
9366
diff
changeset
|
148 |
rqlst = None |
8266c8c375bb
[schema] move definition of RQLExpression classes before default permission dicts
Julien Cristau <julien.cristau@logilab.fr>
parents:
9366
diff
changeset
|
149 |
predefined_variables = None |
8266c8c375bb
[schema] move definition of RQLExpression classes before default permission dicts
Julien Cristau <julien.cristau@logilab.fr>
parents:
9366
diff
changeset
|
150 |
|
8266c8c375bb
[schema] move definition of RQLExpression classes before default permission dicts
Julien Cristau <julien.cristau@logilab.fr>
parents:
9366
diff
changeset
|
151 |
def __init__(self, expression, mainvars, eid): |
8266c8c375bb
[schema] move definition of RQLExpression classes before default permission dicts
Julien Cristau <julien.cristau@logilab.fr>
parents:
9366
diff
changeset
|
152 |
""" |
8266c8c375bb
[schema] move definition of RQLExpression classes before default permission dicts
Julien Cristau <julien.cristau@logilab.fr>
parents:
9366
diff
changeset
|
153 |
:type mainvars: sequence of RQL variables' names. Can be provided as a |
8266c8c375bb
[schema] move definition of RQLExpression classes before default permission dicts
Julien Cristau <julien.cristau@logilab.fr>
parents:
9366
diff
changeset
|
154 |
comma separated string. |
8266c8c375bb
[schema] move definition of RQLExpression classes before default permission dicts
Julien Cristau <julien.cristau@logilab.fr>
parents:
9366
diff
changeset
|
155 |
:param mainvars: names of the variables being selected. |
8266c8c375bb
[schema] move definition of RQLExpression classes before default permission dicts
Julien Cristau <julien.cristau@logilab.fr>
parents:
9366
diff
changeset
|
156 |
|
8266c8c375bb
[schema] move definition of RQLExpression classes before default permission dicts
Julien Cristau <julien.cristau@logilab.fr>
parents:
9366
diff
changeset
|
157 |
""" |
8266c8c375bb
[schema] move definition of RQLExpression classes before default permission dicts
Julien Cristau <julien.cristau@logilab.fr>
parents:
9366
diff
changeset
|
158 |
self.eid = eid # eid of the entity representing this rql expression |
8266c8c375bb
[schema] move definition of RQLExpression classes before default permission dicts
Julien Cristau <julien.cristau@logilab.fr>
parents:
9366
diff
changeset
|
159 |
assert mainvars, 'bad mainvars %s' % mainvars |
8266c8c375bb
[schema] move definition of RQLExpression classes before default permission dicts
Julien Cristau <julien.cristau@logilab.fr>
parents:
9366
diff
changeset
|
160 |
if isinstance(mainvars, basestring): |
8266c8c375bb
[schema] move definition of RQLExpression classes before default permission dicts
Julien Cristau <julien.cristau@logilab.fr>
parents:
9366
diff
changeset
|
161 |
mainvars = set(splitstrip(mainvars)) |
8266c8c375bb
[schema] move definition of RQLExpression classes before default permission dicts
Julien Cristau <julien.cristau@logilab.fr>
parents:
9366
diff
changeset
|
162 |
elif not isinstance(mainvars, set): |
8266c8c375bb
[schema] move definition of RQLExpression classes before default permission dicts
Julien Cristau <julien.cristau@logilab.fr>
parents:
9366
diff
changeset
|
163 |
mainvars = set(mainvars) |
8266c8c375bb
[schema] move definition of RQLExpression classes before default permission dicts
Julien Cristau <julien.cristau@logilab.fr>
parents:
9366
diff
changeset
|
164 |
self.mainvars = mainvars |
8266c8c375bb
[schema] move definition of RQLExpression classes before default permission dicts
Julien Cristau <julien.cristau@logilab.fr>
parents:
9366
diff
changeset
|
165 |
self.expression = normalize_expression(expression) |
8266c8c375bb
[schema] move definition of RQLExpression classes before default permission dicts
Julien Cristau <julien.cristau@logilab.fr>
parents:
9366
diff
changeset
|
166 |
try: |
8266c8c375bb
[schema] move definition of RQLExpression classes before default permission dicts
Julien Cristau <julien.cristau@logilab.fr>
parents:
9366
diff
changeset
|
167 |
self.full_rql = self.rqlst.as_string() |
8266c8c375bb
[schema] move definition of RQLExpression classes before default permission dicts
Julien Cristau <julien.cristau@logilab.fr>
parents:
9366
diff
changeset
|
168 |
except RQLSyntaxError: |
8266c8c375bb
[schema] move definition of RQLExpression classes before default permission dicts
Julien Cristau <julien.cristau@logilab.fr>
parents:
9366
diff
changeset
|
169 |
raise RQLSyntaxError(expression) |
8266c8c375bb
[schema] move definition of RQLExpression classes before default permission dicts
Julien Cristau <julien.cristau@logilab.fr>
parents:
9366
diff
changeset
|
170 |
for mainvar in mainvars: |
8266c8c375bb
[schema] move definition of RQLExpression classes before default permission dicts
Julien Cristau <julien.cristau@logilab.fr>
parents:
9366
diff
changeset
|
171 |
# if variable is predefined, an extra reference is inserted |
8266c8c375bb
[schema] move definition of RQLExpression classes before default permission dicts
Julien Cristau <julien.cristau@logilab.fr>
parents:
9366
diff
changeset
|
172 |
# automatically (`VAR eid %(v)s`) |
8266c8c375bb
[schema] move definition of RQLExpression classes before default permission dicts
Julien Cristau <julien.cristau@logilab.fr>
parents:
9366
diff
changeset
|
173 |
if mainvar in self.predefined_variables: |
8266c8c375bb
[schema] move definition of RQLExpression classes before default permission dicts
Julien Cristau <julien.cristau@logilab.fr>
parents:
9366
diff
changeset
|
174 |
min_refs = 3 |
8266c8c375bb
[schema] move definition of RQLExpression classes before default permission dicts
Julien Cristau <julien.cristau@logilab.fr>
parents:
9366
diff
changeset
|
175 |
else: |
8266c8c375bb
[schema] move definition of RQLExpression classes before default permission dicts
Julien Cristau <julien.cristau@logilab.fr>
parents:
9366
diff
changeset
|
176 |
min_refs = 2 |
8266c8c375bb
[schema] move definition of RQLExpression classes before default permission dicts
Julien Cristau <julien.cristau@logilab.fr>
parents:
9366
diff
changeset
|
177 |
if len(self.rqlst.defined_vars[mainvar].references()) < min_refs: |
8266c8c375bb
[schema] move definition of RQLExpression classes before default permission dicts
Julien Cristau <julien.cristau@logilab.fr>
parents:
9366
diff
changeset
|
178 |
_LOGGER.warn('You did not use the %s variable in your RQL ' |
8266c8c375bb
[schema] move definition of RQLExpression classes before default permission dicts
Julien Cristau <julien.cristau@logilab.fr>
parents:
9366
diff
changeset
|
179 |
'expression %s', mainvar, self) |
8266c8c375bb
[schema] move definition of RQLExpression classes before default permission dicts
Julien Cristau <julien.cristau@logilab.fr>
parents:
9366
diff
changeset
|
180 |
# syntax tree used by read security (inserted in queries when necessary) |
8266c8c375bb
[schema] move definition of RQLExpression classes before default permission dicts
Julien Cristau <julien.cristau@logilab.fr>
parents:
9366
diff
changeset
|
181 |
self.snippet_rqlst = parse(self.minimal_rql, print_errors=False).children[0] |
8266c8c375bb
[schema] move definition of RQLExpression classes before default permission dicts
Julien Cristau <julien.cristau@logilab.fr>
parents:
9366
diff
changeset
|
182 |
# graph of links between variables, used by rql rewriter |
8266c8c375bb
[schema] move definition of RQLExpression classes before default permission dicts
Julien Cristau <julien.cristau@logilab.fr>
parents:
9366
diff
changeset
|
183 |
self.vargraph = vargraph(self.rqlst) |
8266c8c375bb
[schema] move definition of RQLExpression classes before default permission dicts
Julien Cristau <julien.cristau@logilab.fr>
parents:
9366
diff
changeset
|
184 |
# useful for some instrumentation, e.g. localperms permcheck command |
8266c8c375bb
[schema] move definition of RQLExpression classes before default permission dicts
Julien Cristau <julien.cristau@logilab.fr>
parents:
9366
diff
changeset
|
185 |
self.package = ybo.PACKAGE |
8266c8c375bb
[schema] move definition of RQLExpression classes before default permission dicts
Julien Cristau <julien.cristau@logilab.fr>
parents:
9366
diff
changeset
|
186 |
|
8266c8c375bb
[schema] move definition of RQLExpression classes before default permission dicts
Julien Cristau <julien.cristau@logilab.fr>
parents:
9366
diff
changeset
|
187 |
def __str__(self): |
8266c8c375bb
[schema] move definition of RQLExpression classes before default permission dicts
Julien Cristau <julien.cristau@logilab.fr>
parents:
9366
diff
changeset
|
188 |
return self.full_rql |
8266c8c375bb
[schema] move definition of RQLExpression classes before default permission dicts
Julien Cristau <julien.cristau@logilab.fr>
parents:
9366
diff
changeset
|
189 |
def __repr__(self): |
8266c8c375bb
[schema] move definition of RQLExpression classes before default permission dicts
Julien Cristau <julien.cristau@logilab.fr>
parents:
9366
diff
changeset
|
190 |
return '%s(%s)' % (self.__class__.__name__, self.full_rql) |
8266c8c375bb
[schema] move definition of RQLExpression classes before default permission dicts
Julien Cristau <julien.cristau@logilab.fr>
parents:
9366
diff
changeset
|
191 |
|
8266c8c375bb
[schema] move definition of RQLExpression classes before default permission dicts
Julien Cristau <julien.cristau@logilab.fr>
parents:
9366
diff
changeset
|
192 |
def __lt__(self, other): |
8266c8c375bb
[schema] move definition of RQLExpression classes before default permission dicts
Julien Cristau <julien.cristau@logilab.fr>
parents:
9366
diff
changeset
|
193 |
if hasattr(other, 'expression'): |
8266c8c375bb
[schema] move definition of RQLExpression classes before default permission dicts
Julien Cristau <julien.cristau@logilab.fr>
parents:
9366
diff
changeset
|
194 |
return self.expression < other.expression |
8266c8c375bb
[schema] move definition of RQLExpression classes before default permission dicts
Julien Cristau <julien.cristau@logilab.fr>
parents:
9366
diff
changeset
|
195 |
return True |
8266c8c375bb
[schema] move definition of RQLExpression classes before default permission dicts
Julien Cristau <julien.cristau@logilab.fr>
parents:
9366
diff
changeset
|
196 |
|
8266c8c375bb
[schema] move definition of RQLExpression classes before default permission dicts
Julien Cristau <julien.cristau@logilab.fr>
parents:
9366
diff
changeset
|
197 |
def __eq__(self, other): |
8266c8c375bb
[schema] move definition of RQLExpression classes before default permission dicts
Julien Cristau <julien.cristau@logilab.fr>
parents:
9366
diff
changeset
|
198 |
if hasattr(other, 'expression'): |
8266c8c375bb
[schema] move definition of RQLExpression classes before default permission dicts
Julien Cristau <julien.cristau@logilab.fr>
parents:
9366
diff
changeset
|
199 |
return self.expression == other.expression |
8266c8c375bb
[schema] move definition of RQLExpression classes before default permission dicts
Julien Cristau <julien.cristau@logilab.fr>
parents:
9366
diff
changeset
|
200 |
return False |
8266c8c375bb
[schema] move definition of RQLExpression classes before default permission dicts
Julien Cristau <julien.cristau@logilab.fr>
parents:
9366
diff
changeset
|
201 |
|
8266c8c375bb
[schema] move definition of RQLExpression classes before default permission dicts
Julien Cristau <julien.cristau@logilab.fr>
parents:
9366
diff
changeset
|
202 |
def __hash__(self): |
8266c8c375bb
[schema] move definition of RQLExpression classes before default permission dicts
Julien Cristau <julien.cristau@logilab.fr>
parents:
9366
diff
changeset
|
203 |
return hash(self.expression) |
8266c8c375bb
[schema] move definition of RQLExpression classes before default permission dicts
Julien Cristau <julien.cristau@logilab.fr>
parents:
9366
diff
changeset
|
204 |
|
8266c8c375bb
[schema] move definition of RQLExpression classes before default permission dicts
Julien Cristau <julien.cristau@logilab.fr>
parents:
9366
diff
changeset
|
205 |
def __deepcopy__(self, memo): |
8266c8c375bb
[schema] move definition of RQLExpression classes before default permission dicts
Julien Cristau <julien.cristau@logilab.fr>
parents:
9366
diff
changeset
|
206 |
return self.__class__(self.expression, self.mainvars) |
8266c8c375bb
[schema] move definition of RQLExpression classes before default permission dicts
Julien Cristau <julien.cristau@logilab.fr>
parents:
9366
diff
changeset
|
207 |
def __getstate__(self): |
8266c8c375bb
[schema] move definition of RQLExpression classes before default permission dicts
Julien Cristau <julien.cristau@logilab.fr>
parents:
9366
diff
changeset
|
208 |
return (self.expression, self.mainvars) |
8266c8c375bb
[schema] move definition of RQLExpression classes before default permission dicts
Julien Cristau <julien.cristau@logilab.fr>
parents:
9366
diff
changeset
|
209 |
def __setstate__(self, state): |
8266c8c375bb
[schema] move definition of RQLExpression classes before default permission dicts
Julien Cristau <julien.cristau@logilab.fr>
parents:
9366
diff
changeset
|
210 |
self.__init__(*state) |
8266c8c375bb
[schema] move definition of RQLExpression classes before default permission dicts
Julien Cristau <julien.cristau@logilab.fr>
parents:
9366
diff
changeset
|
211 |
|
8266c8c375bb
[schema] move definition of RQLExpression classes before default permission dicts
Julien Cristau <julien.cristau@logilab.fr>
parents:
9366
diff
changeset
|
212 |
@cachedproperty |
8266c8c375bb
[schema] move definition of RQLExpression classes before default permission dicts
Julien Cristau <julien.cristau@logilab.fr>
parents:
9366
diff
changeset
|
213 |
def rqlst(self): |
8266c8c375bb
[schema] move definition of RQLExpression classes before default permission dicts
Julien Cristau <julien.cristau@logilab.fr>
parents:
9366
diff
changeset
|
214 |
select = parse(self.minimal_rql, print_errors=False).children[0] |
8266c8c375bb
[schema] move definition of RQLExpression classes before default permission dicts
Julien Cristau <julien.cristau@logilab.fr>
parents:
9366
diff
changeset
|
215 |
defined = set(split_expression(self.expression)) |
8266c8c375bb
[schema] move definition of RQLExpression classes before default permission dicts
Julien Cristau <julien.cristau@logilab.fr>
parents:
9366
diff
changeset
|
216 |
for varname in self.predefined_variables: |
8266c8c375bb
[schema] move definition of RQLExpression classes before default permission dicts
Julien Cristau <julien.cristau@logilab.fr>
parents:
9366
diff
changeset
|
217 |
if varname in defined: |
8266c8c375bb
[schema] move definition of RQLExpression classes before default permission dicts
Julien Cristau <julien.cristau@logilab.fr>
parents:
9366
diff
changeset
|
218 |
select.add_eid_restriction(select.get_variable(varname), varname.lower(), 'Substitute') |
8266c8c375bb
[schema] move definition of RQLExpression classes before default permission dicts
Julien Cristau <julien.cristau@logilab.fr>
parents:
9366
diff
changeset
|
219 |
return select |
8266c8c375bb
[schema] move definition of RQLExpression classes before default permission dicts
Julien Cristau <julien.cristau@logilab.fr>
parents:
9366
diff
changeset
|
220 |
|
8266c8c375bb
[schema] move definition of RQLExpression classes before default permission dicts
Julien Cristau <julien.cristau@logilab.fr>
parents:
9366
diff
changeset
|
221 |
# permission rql expression specific stuff ################################# |
8266c8c375bb
[schema] move definition of RQLExpression classes before default permission dicts
Julien Cristau <julien.cristau@logilab.fr>
parents:
9366
diff
changeset
|
222 |
|
8266c8c375bb
[schema] move definition of RQLExpression classes before default permission dicts
Julien Cristau <julien.cristau@logilab.fr>
parents:
9366
diff
changeset
|
223 |
@cached |
8266c8c375bb
[schema] move definition of RQLExpression classes before default permission dicts
Julien Cristau <julien.cristau@logilab.fr>
parents:
9366
diff
changeset
|
224 |
def transform_has_permission(self): |
8266c8c375bb
[schema] move definition of RQLExpression classes before default permission dicts
Julien Cristau <julien.cristau@logilab.fr>
parents:
9366
diff
changeset
|
225 |
found = None |
8266c8c375bb
[schema] move definition of RQLExpression classes before default permission dicts
Julien Cristau <julien.cristau@logilab.fr>
parents:
9366
diff
changeset
|
226 |
rqlst = self.rqlst |
8266c8c375bb
[schema] move definition of RQLExpression classes before default permission dicts
Julien Cristau <julien.cristau@logilab.fr>
parents:
9366
diff
changeset
|
227 |
for var in rqlst.defined_vars.itervalues(): |
8266c8c375bb
[schema] move definition of RQLExpression classes before default permission dicts
Julien Cristau <julien.cristau@logilab.fr>
parents:
9366
diff
changeset
|
228 |
for varref in var.references(): |
8266c8c375bb
[schema] move definition of RQLExpression classes before default permission dicts
Julien Cristau <julien.cristau@logilab.fr>
parents:
9366
diff
changeset
|
229 |
rel = varref.relation() |
8266c8c375bb
[schema] move definition of RQLExpression classes before default permission dicts
Julien Cristau <julien.cristau@logilab.fr>
parents:
9366
diff
changeset
|
230 |
if rel is None: |
8266c8c375bb
[schema] move definition of RQLExpression classes before default permission dicts
Julien Cristau <julien.cristau@logilab.fr>
parents:
9366
diff
changeset
|
231 |
continue |
8266c8c375bb
[schema] move definition of RQLExpression classes before default permission dicts
Julien Cristau <julien.cristau@logilab.fr>
parents:
9366
diff
changeset
|
232 |
try: |
8266c8c375bb
[schema] move definition of RQLExpression classes before default permission dicts
Julien Cristau <julien.cristau@logilab.fr>
parents:
9366
diff
changeset
|
233 |
prefix, action, suffix = rel.r_type.split('_') |
8266c8c375bb
[schema] move definition of RQLExpression classes before default permission dicts
Julien Cristau <julien.cristau@logilab.fr>
parents:
9366
diff
changeset
|
234 |
except ValueError: |
8266c8c375bb
[schema] move definition of RQLExpression classes before default permission dicts
Julien Cristau <julien.cristau@logilab.fr>
parents:
9366
diff
changeset
|
235 |
continue |
8266c8c375bb
[schema] move definition of RQLExpression classes before default permission dicts
Julien Cristau <julien.cristau@logilab.fr>
parents:
9366
diff
changeset
|
236 |
if prefix != 'has' or suffix != 'permission' or \ |
8266c8c375bb
[schema] move definition of RQLExpression classes before default permission dicts
Julien Cristau <julien.cristau@logilab.fr>
parents:
9366
diff
changeset
|
237 |
not action in ('add', 'delete', 'update', 'read'): |
8266c8c375bb
[schema] move definition of RQLExpression classes before default permission dicts
Julien Cristau <julien.cristau@logilab.fr>
parents:
9366
diff
changeset
|
238 |
continue |
8266c8c375bb
[schema] move definition of RQLExpression classes before default permission dicts
Julien Cristau <julien.cristau@logilab.fr>
parents:
9366
diff
changeset
|
239 |
if found is None: |
8266c8c375bb
[schema] move definition of RQLExpression classes before default permission dicts
Julien Cristau <julien.cristau@logilab.fr>
parents:
9366
diff
changeset
|
240 |
found = [] |
8266c8c375bb
[schema] move definition of RQLExpression classes before default permission dicts
Julien Cristau <julien.cristau@logilab.fr>
parents:
9366
diff
changeset
|
241 |
rqlst.save_state() |
8266c8c375bb
[schema] move definition of RQLExpression classes before default permission dicts
Julien Cristau <julien.cristau@logilab.fr>
parents:
9366
diff
changeset
|
242 |
assert rel.children[0].name == 'U' |
8266c8c375bb
[schema] move definition of RQLExpression classes before default permission dicts
Julien Cristau <julien.cristau@logilab.fr>
parents:
9366
diff
changeset
|
243 |
objvar = rel.children[1].children[0].variable |
8266c8c375bb
[schema] move definition of RQLExpression classes before default permission dicts
Julien Cristau <julien.cristau@logilab.fr>
parents:
9366
diff
changeset
|
244 |
rqlst.remove_node(rel) |
8266c8c375bb
[schema] move definition of RQLExpression classes before default permission dicts
Julien Cristau <julien.cristau@logilab.fr>
parents:
9366
diff
changeset
|
245 |
selected = [v.name for v in rqlst.get_selected_variables()] |
8266c8c375bb
[schema] move definition of RQLExpression classes before default permission dicts
Julien Cristau <julien.cristau@logilab.fr>
parents:
9366
diff
changeset
|
246 |
if objvar.name not in selected: |
8266c8c375bb
[schema] move definition of RQLExpression classes before default permission dicts
Julien Cristau <julien.cristau@logilab.fr>
parents:
9366
diff
changeset
|
247 |
colindex = len(selected) |
8266c8c375bb
[schema] move definition of RQLExpression classes before default permission dicts
Julien Cristau <julien.cristau@logilab.fr>
parents:
9366
diff
changeset
|
248 |
rqlst.add_selected(objvar) |
8266c8c375bb
[schema] move definition of RQLExpression classes before default permission dicts
Julien Cristau <julien.cristau@logilab.fr>
parents:
9366
diff
changeset
|
249 |
else: |
8266c8c375bb
[schema] move definition of RQLExpression classes before default permission dicts
Julien Cristau <julien.cristau@logilab.fr>
parents:
9366
diff
changeset
|
250 |
colindex = selected.index(objvar.name) |
8266c8c375bb
[schema] move definition of RQLExpression classes before default permission dicts
Julien Cristau <julien.cristau@logilab.fr>
parents:
9366
diff
changeset
|
251 |
found.append((action, colindex)) |
8266c8c375bb
[schema] move definition of RQLExpression classes before default permission dicts
Julien Cristau <julien.cristau@logilab.fr>
parents:
9366
diff
changeset
|
252 |
# remove U eid %(u)s if U is not used in any other relation |
8266c8c375bb
[schema] move definition of RQLExpression classes before default permission dicts
Julien Cristau <julien.cristau@logilab.fr>
parents:
9366
diff
changeset
|
253 |
uvrefs = rqlst.defined_vars['U'].references() |
8266c8c375bb
[schema] move definition of RQLExpression classes before default permission dicts
Julien Cristau <julien.cristau@logilab.fr>
parents:
9366
diff
changeset
|
254 |
if len(uvrefs) == 1: |
8266c8c375bb
[schema] move definition of RQLExpression classes before default permission dicts
Julien Cristau <julien.cristau@logilab.fr>
parents:
9366
diff
changeset
|
255 |
rqlst.remove_node(uvrefs[0].relation()) |
8266c8c375bb
[schema] move definition of RQLExpression classes before default permission dicts
Julien Cristau <julien.cristau@logilab.fr>
parents:
9366
diff
changeset
|
256 |
if found is not None: |
8266c8c375bb
[schema] move definition of RQLExpression classes before default permission dicts
Julien Cristau <julien.cristau@logilab.fr>
parents:
9366
diff
changeset
|
257 |
rql = rqlst.as_string() |
8266c8c375bb
[schema] move definition of RQLExpression classes before default permission dicts
Julien Cristau <julien.cristau@logilab.fr>
parents:
9366
diff
changeset
|
258 |
if len(rqlst.selection) == 1 and isinstance(rqlst.where, nodes.Relation): |
8266c8c375bb
[schema] move definition of RQLExpression classes before default permission dicts
Julien Cristau <julien.cristau@logilab.fr>
parents:
9366
diff
changeset
|
259 |
# only "Any X WHERE X eid %(x)s" remaining, no need to execute the rql |
8266c8c375bb
[schema] move definition of RQLExpression classes before default permission dicts
Julien Cristau <julien.cristau@logilab.fr>
parents:
9366
diff
changeset
|
260 |
keyarg = rqlst.selection[0].name.lower() |
8266c8c375bb
[schema] move definition of RQLExpression classes before default permission dicts
Julien Cristau <julien.cristau@logilab.fr>
parents:
9366
diff
changeset
|
261 |
else: |
8266c8c375bb
[schema] move definition of RQLExpression classes before default permission dicts
Julien Cristau <julien.cristau@logilab.fr>
parents:
9366
diff
changeset
|
262 |
keyarg = None |
8266c8c375bb
[schema] move definition of RQLExpression classes before default permission dicts
Julien Cristau <julien.cristau@logilab.fr>
parents:
9366
diff
changeset
|
263 |
rqlst.recover() |
8266c8c375bb
[schema] move definition of RQLExpression classes before default permission dicts
Julien Cristau <julien.cristau@logilab.fr>
parents:
9366
diff
changeset
|
264 |
return rql, found, keyarg |
8266c8c375bb
[schema] move definition of RQLExpression classes before default permission dicts
Julien Cristau <julien.cristau@logilab.fr>
parents:
9366
diff
changeset
|
265 |
return rqlst.as_string(), None, None |
8266c8c375bb
[schema] move definition of RQLExpression classes before default permission dicts
Julien Cristau <julien.cristau@logilab.fr>
parents:
9366
diff
changeset
|
266 |
|
8266c8c375bb
[schema] move definition of RQLExpression classes before default permission dicts
Julien Cristau <julien.cristau@logilab.fr>
parents:
9366
diff
changeset
|
267 |
def _check(self, _cw, **kwargs): |
8266c8c375bb
[schema] move definition of RQLExpression classes before default permission dicts
Julien Cristau <julien.cristau@logilab.fr>
parents:
9366
diff
changeset
|
268 |
"""return True if the rql expression is matching the given relation |
8266c8c375bb
[schema] move definition of RQLExpression classes before default permission dicts
Julien Cristau <julien.cristau@logilab.fr>
parents:
9366
diff
changeset
|
269 |
between fromeid and toeid |
8266c8c375bb
[schema] move definition of RQLExpression classes before default permission dicts
Julien Cristau <julien.cristau@logilab.fr>
parents:
9366
diff
changeset
|
270 |
|
8266c8c375bb
[schema] move definition of RQLExpression classes before default permission dicts
Julien Cristau <julien.cristau@logilab.fr>
parents:
9366
diff
changeset
|
271 |
_cw may be a request or a server side transaction |
8266c8c375bb
[schema] move definition of RQLExpression classes before default permission dicts
Julien Cristau <julien.cristau@logilab.fr>
parents:
9366
diff
changeset
|
272 |
""" |
8266c8c375bb
[schema] move definition of RQLExpression classes before default permission dicts
Julien Cristau <julien.cristau@logilab.fr>
parents:
9366
diff
changeset
|
273 |
creating = kwargs.get('creating') |
8266c8c375bb
[schema] move definition of RQLExpression classes before default permission dicts
Julien Cristau <julien.cristau@logilab.fr>
parents:
9366
diff
changeset
|
274 |
if not creating and self.eid is not None: |
8266c8c375bb
[schema] move definition of RQLExpression classes before default permission dicts
Julien Cristau <julien.cristau@logilab.fr>
parents:
9366
diff
changeset
|
275 |
key = (self.eid, tuple(sorted(kwargs.iteritems()))) |
8266c8c375bb
[schema] move definition of RQLExpression classes before default permission dicts
Julien Cristau <julien.cristau@logilab.fr>
parents:
9366
diff
changeset
|
276 |
try: |
8266c8c375bb
[schema] move definition of RQLExpression classes before default permission dicts
Julien Cristau <julien.cristau@logilab.fr>
parents:
9366
diff
changeset
|
277 |
return _cw.local_perm_cache[key] |
8266c8c375bb
[schema] move definition of RQLExpression classes before default permission dicts
Julien Cristau <julien.cristau@logilab.fr>
parents:
9366
diff
changeset
|
278 |
except KeyError: |
8266c8c375bb
[schema] move definition of RQLExpression classes before default permission dicts
Julien Cristau <julien.cristau@logilab.fr>
parents:
9366
diff
changeset
|
279 |
pass |
8266c8c375bb
[schema] move definition of RQLExpression classes before default permission dicts
Julien Cristau <julien.cristau@logilab.fr>
parents:
9366
diff
changeset
|
280 |
rql, has_perm_defs, keyarg = self.transform_has_permission() |
8266c8c375bb
[schema] move definition of RQLExpression classes before default permission dicts
Julien Cristau <julien.cristau@logilab.fr>
parents:
9366
diff
changeset
|
281 |
# when creating an entity, expression related to X satisfied |
8266c8c375bb
[schema] move definition of RQLExpression classes before default permission dicts
Julien Cristau <julien.cristau@logilab.fr>
parents:
9366
diff
changeset
|
282 |
if creating and 'X' in self.rqlst.defined_vars: |
8266c8c375bb
[schema] move definition of RQLExpression classes before default permission dicts
Julien Cristau <julien.cristau@logilab.fr>
parents:
9366
diff
changeset
|
283 |
return True |
8266c8c375bb
[schema] move definition of RQLExpression classes before default permission dicts
Julien Cristau <julien.cristau@logilab.fr>
parents:
9366
diff
changeset
|
284 |
if keyarg is None: |
8266c8c375bb
[schema] move definition of RQLExpression classes before default permission dicts
Julien Cristau <julien.cristau@logilab.fr>
parents:
9366
diff
changeset
|
285 |
kwargs.setdefault('u', _cw.user.eid) |
8266c8c375bb
[schema] move definition of RQLExpression classes before default permission dicts
Julien Cristau <julien.cristau@logilab.fr>
parents:
9366
diff
changeset
|
286 |
try: |
8266c8c375bb
[schema] move definition of RQLExpression classes before default permission dicts
Julien Cristau <julien.cristau@logilab.fr>
parents:
9366
diff
changeset
|
287 |
rset = _cw.execute(rql, kwargs, build_descr=True) |
8266c8c375bb
[schema] move definition of RQLExpression classes before default permission dicts
Julien Cristau <julien.cristau@logilab.fr>
parents:
9366
diff
changeset
|
288 |
except NotImplementedError: |
8266c8c375bb
[schema] move definition of RQLExpression classes before default permission dicts
Julien Cristau <julien.cristau@logilab.fr>
parents:
9366
diff
changeset
|
289 |
self.critical('cant check rql expression, unsupported rql %s', rql) |
8266c8c375bb
[schema] move definition of RQLExpression classes before default permission dicts
Julien Cristau <julien.cristau@logilab.fr>
parents:
9366
diff
changeset
|
290 |
if self.eid is not None: |
8266c8c375bb
[schema] move definition of RQLExpression classes before default permission dicts
Julien Cristau <julien.cristau@logilab.fr>
parents:
9366
diff
changeset
|
291 |
_cw.local_perm_cache[key] = False |
8266c8c375bb
[schema] move definition of RQLExpression classes before default permission dicts
Julien Cristau <julien.cristau@logilab.fr>
parents:
9366
diff
changeset
|
292 |
return False |
8266c8c375bb
[schema] move definition of RQLExpression classes before default permission dicts
Julien Cristau <julien.cristau@logilab.fr>
parents:
9366
diff
changeset
|
293 |
except TypeResolverException as ex: |
8266c8c375bb
[schema] move definition of RQLExpression classes before default permission dicts
Julien Cristau <julien.cristau@logilab.fr>
parents:
9366
diff
changeset
|
294 |
# some expression may not be resolvable with current kwargs |
8266c8c375bb
[schema] move definition of RQLExpression classes before default permission dicts
Julien Cristau <julien.cristau@logilab.fr>
parents:
9366
diff
changeset
|
295 |
# (type conflict) |
8266c8c375bb
[schema] move definition of RQLExpression classes before default permission dicts
Julien Cristau <julien.cristau@logilab.fr>
parents:
9366
diff
changeset
|
296 |
self.warning('%s: %s', rql, str(ex)) |
8266c8c375bb
[schema] move definition of RQLExpression classes before default permission dicts
Julien Cristau <julien.cristau@logilab.fr>
parents:
9366
diff
changeset
|
297 |
if self.eid is not None: |
8266c8c375bb
[schema] move definition of RQLExpression classes before default permission dicts
Julien Cristau <julien.cristau@logilab.fr>
parents:
9366
diff
changeset
|
298 |
_cw.local_perm_cache[key] = False |
8266c8c375bb
[schema] move definition of RQLExpression classes before default permission dicts
Julien Cristau <julien.cristau@logilab.fr>
parents:
9366
diff
changeset
|
299 |
return False |
8266c8c375bb
[schema] move definition of RQLExpression classes before default permission dicts
Julien Cristau <julien.cristau@logilab.fr>
parents:
9366
diff
changeset
|
300 |
except Unauthorized as ex: |
8266c8c375bb
[schema] move definition of RQLExpression classes before default permission dicts
Julien Cristau <julien.cristau@logilab.fr>
parents:
9366
diff
changeset
|
301 |
self.debug('unauthorized %s: %s', rql, str(ex)) |
8266c8c375bb
[schema] move definition of RQLExpression classes before default permission dicts
Julien Cristau <julien.cristau@logilab.fr>
parents:
9366
diff
changeset
|
302 |
if self.eid is not None: |
8266c8c375bb
[schema] move definition of RQLExpression classes before default permission dicts
Julien Cristau <julien.cristau@logilab.fr>
parents:
9366
diff
changeset
|
303 |
_cw.local_perm_cache[key] = False |
8266c8c375bb
[schema] move definition of RQLExpression classes before default permission dicts
Julien Cristau <julien.cristau@logilab.fr>
parents:
9366
diff
changeset
|
304 |
return False |
8266c8c375bb
[schema] move definition of RQLExpression classes before default permission dicts
Julien Cristau <julien.cristau@logilab.fr>
parents:
9366
diff
changeset
|
305 |
else: |
8266c8c375bb
[schema] move definition of RQLExpression classes before default permission dicts
Julien Cristau <julien.cristau@logilab.fr>
parents:
9366
diff
changeset
|
306 |
rset = _cw.eid_rset(kwargs[keyarg]) |
8266c8c375bb
[schema] move definition of RQLExpression classes before default permission dicts
Julien Cristau <julien.cristau@logilab.fr>
parents:
9366
diff
changeset
|
307 |
# if no special has_*_permission relation in the rql expression, just |
8266c8c375bb
[schema] move definition of RQLExpression classes before default permission dicts
Julien Cristau <julien.cristau@logilab.fr>
parents:
9366
diff
changeset
|
308 |
# check the result set contains something |
8266c8c375bb
[schema] move definition of RQLExpression classes before default permission dicts
Julien Cristau <julien.cristau@logilab.fr>
parents:
9366
diff
changeset
|
309 |
if has_perm_defs is None: |
8266c8c375bb
[schema] move definition of RQLExpression classes before default permission dicts
Julien Cristau <julien.cristau@logilab.fr>
parents:
9366
diff
changeset
|
310 |
if rset: |
8266c8c375bb
[schema] move definition of RQLExpression classes before default permission dicts
Julien Cristau <julien.cristau@logilab.fr>
parents:
9366
diff
changeset
|
311 |
if self.eid is not None: |
8266c8c375bb
[schema] move definition of RQLExpression classes before default permission dicts
Julien Cristau <julien.cristau@logilab.fr>
parents:
9366
diff
changeset
|
312 |
_cw.local_perm_cache[key] = True |
8266c8c375bb
[schema] move definition of RQLExpression classes before default permission dicts
Julien Cristau <julien.cristau@logilab.fr>
parents:
9366
diff
changeset
|
313 |
return True |
8266c8c375bb
[schema] move definition of RQLExpression classes before default permission dicts
Julien Cristau <julien.cristau@logilab.fr>
parents:
9366
diff
changeset
|
314 |
elif rset: |
8266c8c375bb
[schema] move definition of RQLExpression classes before default permission dicts
Julien Cristau <julien.cristau@logilab.fr>
parents:
9366
diff
changeset
|
315 |
# check every special has_*_permission relation is satisfied |
8266c8c375bb
[schema] move definition of RQLExpression classes before default permission dicts
Julien Cristau <julien.cristau@logilab.fr>
parents:
9366
diff
changeset
|
316 |
get_eschema = _cw.vreg.schema.eschema |
8266c8c375bb
[schema] move definition of RQLExpression classes before default permission dicts
Julien Cristau <julien.cristau@logilab.fr>
parents:
9366
diff
changeset
|
317 |
try: |
8266c8c375bb
[schema] move definition of RQLExpression classes before default permission dicts
Julien Cristau <julien.cristau@logilab.fr>
parents:
9366
diff
changeset
|
318 |
for eaction, col in has_perm_defs: |
8266c8c375bb
[schema] move definition of RQLExpression classes before default permission dicts
Julien Cristau <julien.cristau@logilab.fr>
parents:
9366
diff
changeset
|
319 |
for i in xrange(len(rset)): |
8266c8c375bb
[schema] move definition of RQLExpression classes before default permission dicts
Julien Cristau <julien.cristau@logilab.fr>
parents:
9366
diff
changeset
|
320 |
eschema = get_eschema(rset.description[i][col]) |
8266c8c375bb
[schema] move definition of RQLExpression classes before default permission dicts
Julien Cristau <julien.cristau@logilab.fr>
parents:
9366
diff
changeset
|
321 |
eschema.check_perm(_cw, eaction, eid=rset[i][col]) |
8266c8c375bb
[schema] move definition of RQLExpression classes before default permission dicts
Julien Cristau <julien.cristau@logilab.fr>
parents:
9366
diff
changeset
|
322 |
if self.eid is not None: |
8266c8c375bb
[schema] move definition of RQLExpression classes before default permission dicts
Julien Cristau <julien.cristau@logilab.fr>
parents:
9366
diff
changeset
|
323 |
_cw.local_perm_cache[key] = True |
8266c8c375bb
[schema] move definition of RQLExpression classes before default permission dicts
Julien Cristau <julien.cristau@logilab.fr>
parents:
9366
diff
changeset
|
324 |
return True |
8266c8c375bb
[schema] move definition of RQLExpression classes before default permission dicts
Julien Cristau <julien.cristau@logilab.fr>
parents:
9366
diff
changeset
|
325 |
except Unauthorized: |
8266c8c375bb
[schema] move definition of RQLExpression classes before default permission dicts
Julien Cristau <julien.cristau@logilab.fr>
parents:
9366
diff
changeset
|
326 |
pass |
8266c8c375bb
[schema] move definition of RQLExpression classes before default permission dicts
Julien Cristau <julien.cristau@logilab.fr>
parents:
9366
diff
changeset
|
327 |
if self.eid is not None: |
8266c8c375bb
[schema] move definition of RQLExpression classes before default permission dicts
Julien Cristau <julien.cristau@logilab.fr>
parents:
9366
diff
changeset
|
328 |
_cw.local_perm_cache[key] = False |
8266c8c375bb
[schema] move definition of RQLExpression classes before default permission dicts
Julien Cristau <julien.cristau@logilab.fr>
parents:
9366
diff
changeset
|
329 |
return False |
8266c8c375bb
[schema] move definition of RQLExpression classes before default permission dicts
Julien Cristau <julien.cristau@logilab.fr>
parents:
9366
diff
changeset
|
330 |
|
8266c8c375bb
[schema] move definition of RQLExpression classes before default permission dicts
Julien Cristau <julien.cristau@logilab.fr>
parents:
9366
diff
changeset
|
331 |
@property |
8266c8c375bb
[schema] move definition of RQLExpression classes before default permission dicts
Julien Cristau <julien.cristau@logilab.fr>
parents:
9366
diff
changeset
|
332 |
def minimal_rql(self): |
8266c8c375bb
[schema] move definition of RQLExpression classes before default permission dicts
Julien Cristau <julien.cristau@logilab.fr>
parents:
9366
diff
changeset
|
333 |
return 'Any %s WHERE %s' % (','.join(sorted(self.mainvars)), |
8266c8c375bb
[schema] move definition of RQLExpression classes before default permission dicts
Julien Cristau <julien.cristau@logilab.fr>
parents:
9366
diff
changeset
|
334 |
self.expression) |
8266c8c375bb
[schema] move definition of RQLExpression classes before default permission dicts
Julien Cristau <julien.cristau@logilab.fr>
parents:
9366
diff
changeset
|
335 |
|
9395
96dba2efd16d
[hooks/security] provide attribute "add" permission
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9393
diff
changeset
|
336 |
|
96dba2efd16d
[hooks/security] provide attribute "add" permission
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9393
diff
changeset
|
337 |
|
9393
8266c8c375bb
[schema] move definition of RQLExpression classes before default permission dicts
Julien Cristau <julien.cristau@logilab.fr>
parents:
9366
diff
changeset
|
338 |
# rql expressions for use in permission definition ############################# |
8266c8c375bb
[schema] move definition of RQLExpression classes before default permission dicts
Julien Cristau <julien.cristau@logilab.fr>
parents:
9366
diff
changeset
|
339 |
|
8266c8c375bb
[schema] move definition of RQLExpression classes before default permission dicts
Julien Cristau <julien.cristau@logilab.fr>
parents:
9366
diff
changeset
|
340 |
class ERQLExpression(RQLExpression): |
8266c8c375bb
[schema] move definition of RQLExpression classes before default permission dicts
Julien Cristau <julien.cristau@logilab.fr>
parents:
9366
diff
changeset
|
341 |
predefined_variables = 'XU' |
8266c8c375bb
[schema] move definition of RQLExpression classes before default permission dicts
Julien Cristau <julien.cristau@logilab.fr>
parents:
9366
diff
changeset
|
342 |
|
8266c8c375bb
[schema] move definition of RQLExpression classes before default permission dicts
Julien Cristau <julien.cristau@logilab.fr>
parents:
9366
diff
changeset
|
343 |
def __init__(self, expression, mainvars=None, eid=None): |
8266c8c375bb
[schema] move definition of RQLExpression classes before default permission dicts
Julien Cristau <julien.cristau@logilab.fr>
parents:
9366
diff
changeset
|
344 |
RQLExpression.__init__(self, expression, mainvars or 'X', eid) |
8266c8c375bb
[schema] move definition of RQLExpression classes before default permission dicts
Julien Cristau <julien.cristau@logilab.fr>
parents:
9366
diff
changeset
|
345 |
|
8266c8c375bb
[schema] move definition of RQLExpression classes before default permission dicts
Julien Cristau <julien.cristau@logilab.fr>
parents:
9366
diff
changeset
|
346 |
def check(self, _cw, eid=None, creating=False, **kwargs): |
8266c8c375bb
[schema] move definition of RQLExpression classes before default permission dicts
Julien Cristau <julien.cristau@logilab.fr>
parents:
9366
diff
changeset
|
347 |
if 'X' in self.rqlst.defined_vars: |
8266c8c375bb
[schema] move definition of RQLExpression classes before default permission dicts
Julien Cristau <julien.cristau@logilab.fr>
parents:
9366
diff
changeset
|
348 |
if eid is None: |
8266c8c375bb
[schema] move definition of RQLExpression classes before default permission dicts
Julien Cristau <julien.cristau@logilab.fr>
parents:
9366
diff
changeset
|
349 |
if creating: |
8266c8c375bb
[schema] move definition of RQLExpression classes before default permission dicts
Julien Cristau <julien.cristau@logilab.fr>
parents:
9366
diff
changeset
|
350 |
return self._check(_cw, creating=True, **kwargs) |
8266c8c375bb
[schema] move definition of RQLExpression classes before default permission dicts
Julien Cristau <julien.cristau@logilab.fr>
parents:
9366
diff
changeset
|
351 |
return False |
8266c8c375bb
[schema] move definition of RQLExpression classes before default permission dicts
Julien Cristau <julien.cristau@logilab.fr>
parents:
9366
diff
changeset
|
352 |
assert creating == False |
8266c8c375bb
[schema] move definition of RQLExpression classes before default permission dicts
Julien Cristau <julien.cristau@logilab.fr>
parents:
9366
diff
changeset
|
353 |
return self._check(_cw, x=eid, **kwargs) |
8266c8c375bb
[schema] move definition of RQLExpression classes before default permission dicts
Julien Cristau <julien.cristau@logilab.fr>
parents:
9366
diff
changeset
|
354 |
return self._check(_cw, **kwargs) |
8266c8c375bb
[schema] move definition of RQLExpression classes before default permission dicts
Julien Cristau <julien.cristau@logilab.fr>
parents:
9366
diff
changeset
|
355 |
|
9600
bde625698f44
[merge] bring the 3.17.14 fixes to 3.18
Aurelien Campeas <aurelien.campeas@logilab.fr>
diff
changeset
|
356 |
def constraint_by_eid(self, eid): |
bde625698f44
[merge] bring the 3.17.14 fixes to 3.18
Aurelien Campeas <aurelien.campeas@logilab.fr>
diff
changeset
|
357 |
for cstr in self.constraints: |
bde625698f44
[merge] bring the 3.17.14 fixes to 3.18
Aurelien Campeas <aurelien.campeas@logilab.fr>
diff
changeset
|
358 |
if cstr.eid == eid: |
bde625698f44
[merge] bring the 3.17.14 fixes to 3.18
Aurelien Campeas <aurelien.campeas@logilab.fr>
diff
changeset
|
359 |
return cstr |
bde625698f44
[merge] bring the 3.17.14 fixes to 3.18
Aurelien Campeas <aurelien.campeas@logilab.fr>
diff
changeset
|
360 |
raise ValueError('No constraint with eid %d' % eid) |
bde625698f44
[merge] bring the 3.17.14 fixes to 3.18
Aurelien Campeas <aurelien.campeas@logilab.fr>
diff
changeset
|
361 |
RelationDefinitionSchema.constraint_by_eid = constraint_by_eid |
bde625698f44
[merge] bring the 3.17.14 fixes to 3.18
Aurelien Campeas <aurelien.campeas@logilab.fr>
diff
changeset
|
362 |
|
9393
8266c8c375bb
[schema] move definition of RQLExpression classes before default permission dicts
Julien Cristau <julien.cristau@logilab.fr>
parents:
9366
diff
changeset
|
363 |
|
8266c8c375bb
[schema] move definition of RQLExpression classes before default permission dicts
Julien Cristau <julien.cristau@logilab.fr>
parents:
9366
diff
changeset
|
364 |
def vargraph(rqlst): |
8266c8c375bb
[schema] move definition of RQLExpression classes before default permission dicts
Julien Cristau <julien.cristau@logilab.fr>
parents:
9366
diff
changeset
|
365 |
""" builds an adjacency graph of variables from the rql syntax tree, e.g: |
8266c8c375bb
[schema] move definition of RQLExpression classes before default permission dicts
Julien Cristau <julien.cristau@logilab.fr>
parents:
9366
diff
changeset
|
366 |
Any O,S WHERE T subworkflow_exit S, T subworkflow WF, O state_of WF |
8266c8c375bb
[schema] move definition of RQLExpression classes before default permission dicts
Julien Cristau <julien.cristau@logilab.fr>
parents:
9366
diff
changeset
|
367 |
=> {'WF': ['O', 'T'], 'S': ['T'], 'T': ['WF', 'S'], 'O': ['WF']} |
8266c8c375bb
[schema] move definition of RQLExpression classes before default permission dicts
Julien Cristau <julien.cristau@logilab.fr>
parents:
9366
diff
changeset
|
368 |
""" |
8266c8c375bb
[schema] move definition of RQLExpression classes before default permission dicts
Julien Cristau <julien.cristau@logilab.fr>
parents:
9366
diff
changeset
|
369 |
vargraph = {} |
8266c8c375bb
[schema] move definition of RQLExpression classes before default permission dicts
Julien Cristau <julien.cristau@logilab.fr>
parents:
9366
diff
changeset
|
370 |
for relation in rqlst.get_nodes(nodes.Relation): |
8266c8c375bb
[schema] move definition of RQLExpression classes before default permission dicts
Julien Cristau <julien.cristau@logilab.fr>
parents:
9366
diff
changeset
|
371 |
try: |
8266c8c375bb
[schema] move definition of RQLExpression classes before default permission dicts
Julien Cristau <julien.cristau@logilab.fr>
parents:
9366
diff
changeset
|
372 |
rhsvarname = relation.children[1].children[0].variable.name |
8266c8c375bb
[schema] move definition of RQLExpression classes before default permission dicts
Julien Cristau <julien.cristau@logilab.fr>
parents:
9366
diff
changeset
|
373 |
lhsvarname = relation.children[0].name |
8266c8c375bb
[schema] move definition of RQLExpression classes before default permission dicts
Julien Cristau <julien.cristau@logilab.fr>
parents:
9366
diff
changeset
|
374 |
except AttributeError: |
8266c8c375bb
[schema] move definition of RQLExpression classes before default permission dicts
Julien Cristau <julien.cristau@logilab.fr>
parents:
9366
diff
changeset
|
375 |
pass |
8266c8c375bb
[schema] move definition of RQLExpression classes before default permission dicts
Julien Cristau <julien.cristau@logilab.fr>
parents:
9366
diff
changeset
|
376 |
else: |
8266c8c375bb
[schema] move definition of RQLExpression classes before default permission dicts
Julien Cristau <julien.cristau@logilab.fr>
parents:
9366
diff
changeset
|
377 |
vargraph.setdefault(lhsvarname, []).append(rhsvarname) |
8266c8c375bb
[schema] move definition of RQLExpression classes before default permission dicts
Julien Cristau <julien.cristau@logilab.fr>
parents:
9366
diff
changeset
|
378 |
vargraph.setdefault(rhsvarname, []).append(lhsvarname) |
8266c8c375bb
[schema] move definition of RQLExpression classes before default permission dicts
Julien Cristau <julien.cristau@logilab.fr>
parents:
9366
diff
changeset
|
379 |
#vargraph[(lhsvarname, rhsvarname)] = relation.r_type |
8266c8c375bb
[schema] move definition of RQLExpression classes before default permission dicts
Julien Cristau <julien.cristau@logilab.fr>
parents:
9366
diff
changeset
|
380 |
return vargraph |
8266c8c375bb
[schema] move definition of RQLExpression classes before default permission dicts
Julien Cristau <julien.cristau@logilab.fr>
parents:
9366
diff
changeset
|
381 |
|
8266c8c375bb
[schema] move definition of RQLExpression classes before default permission dicts
Julien Cristau <julien.cristau@logilab.fr>
parents:
9366
diff
changeset
|
382 |
|
8266c8c375bb
[schema] move definition of RQLExpression classes before default permission dicts
Julien Cristau <julien.cristau@logilab.fr>
parents:
9366
diff
changeset
|
383 |
class GeneratedConstraint(object): |
8266c8c375bb
[schema] move definition of RQLExpression classes before default permission dicts
Julien Cristau <julien.cristau@logilab.fr>
parents:
9366
diff
changeset
|
384 |
def __init__(self, rqlst, mainvars): |
8266c8c375bb
[schema] move definition of RQLExpression classes before default permission dicts
Julien Cristau <julien.cristau@logilab.fr>
parents:
9366
diff
changeset
|
385 |
self.snippet_rqlst = rqlst |
8266c8c375bb
[schema] move definition of RQLExpression classes before default permission dicts
Julien Cristau <julien.cristau@logilab.fr>
parents:
9366
diff
changeset
|
386 |
self.mainvars = mainvars |
8266c8c375bb
[schema] move definition of RQLExpression classes before default permission dicts
Julien Cristau <julien.cristau@logilab.fr>
parents:
9366
diff
changeset
|
387 |
self.vargraph = vargraph(rqlst) |
8266c8c375bb
[schema] move definition of RQLExpression classes before default permission dicts
Julien Cristau <julien.cristau@logilab.fr>
parents:
9366
diff
changeset
|
388 |
|
8266c8c375bb
[schema] move definition of RQLExpression classes before default permission dicts
Julien Cristau <julien.cristau@logilab.fr>
parents:
9366
diff
changeset
|
389 |
|
8266c8c375bb
[schema] move definition of RQLExpression classes before default permission dicts
Julien Cristau <julien.cristau@logilab.fr>
parents:
9366
diff
changeset
|
390 |
class RRQLExpression(RQLExpression): |
8266c8c375bb
[schema] move definition of RQLExpression classes before default permission dicts
Julien Cristau <julien.cristau@logilab.fr>
parents:
9366
diff
changeset
|
391 |
predefined_variables = 'SOU' |
8266c8c375bb
[schema] move definition of RQLExpression classes before default permission dicts
Julien Cristau <julien.cristau@logilab.fr>
parents:
9366
diff
changeset
|
392 |
|
8266c8c375bb
[schema] move definition of RQLExpression classes before default permission dicts
Julien Cristau <julien.cristau@logilab.fr>
parents:
9366
diff
changeset
|
393 |
def __init__(self, expression, mainvars=None, eid=None): |
8266c8c375bb
[schema] move definition of RQLExpression classes before default permission dicts
Julien Cristau <julien.cristau@logilab.fr>
parents:
9366
diff
changeset
|
394 |
if mainvars is None: |
8266c8c375bb
[schema] move definition of RQLExpression classes before default permission dicts
Julien Cristau <julien.cristau@logilab.fr>
parents:
9366
diff
changeset
|
395 |
mainvars = guess_rrqlexpr_mainvars(expression) |
8266c8c375bb
[schema] move definition of RQLExpression classes before default permission dicts
Julien Cristau <julien.cristau@logilab.fr>
parents:
9366
diff
changeset
|
396 |
RQLExpression.__init__(self, expression, mainvars, eid) |
8266c8c375bb
[schema] move definition of RQLExpression classes before default permission dicts
Julien Cristau <julien.cristau@logilab.fr>
parents:
9366
diff
changeset
|
397 |
|
8266c8c375bb
[schema] move definition of RQLExpression classes before default permission dicts
Julien Cristau <julien.cristau@logilab.fr>
parents:
9366
diff
changeset
|
398 |
def check(self, _cw, fromeid=None, toeid=None): |
8266c8c375bb
[schema] move definition of RQLExpression classes before default permission dicts
Julien Cristau <julien.cristau@logilab.fr>
parents:
9366
diff
changeset
|
399 |
kwargs = {} |
8266c8c375bb
[schema] move definition of RQLExpression classes before default permission dicts
Julien Cristau <julien.cristau@logilab.fr>
parents:
9366
diff
changeset
|
400 |
if 'S' in self.rqlst.defined_vars: |
8266c8c375bb
[schema] move definition of RQLExpression classes before default permission dicts
Julien Cristau <julien.cristau@logilab.fr>
parents:
9366
diff
changeset
|
401 |
if fromeid is None: |
8266c8c375bb
[schema] move definition of RQLExpression classes before default permission dicts
Julien Cristau <julien.cristau@logilab.fr>
parents:
9366
diff
changeset
|
402 |
return False |
8266c8c375bb
[schema] move definition of RQLExpression classes before default permission dicts
Julien Cristau <julien.cristau@logilab.fr>
parents:
9366
diff
changeset
|
403 |
kwargs['s'] = fromeid |
8266c8c375bb
[schema] move definition of RQLExpression classes before default permission dicts
Julien Cristau <julien.cristau@logilab.fr>
parents:
9366
diff
changeset
|
404 |
if 'O' in self.rqlst.defined_vars: |
8266c8c375bb
[schema] move definition of RQLExpression classes before default permission dicts
Julien Cristau <julien.cristau@logilab.fr>
parents:
9366
diff
changeset
|
405 |
if toeid is None: |
8266c8c375bb
[schema] move definition of RQLExpression classes before default permission dicts
Julien Cristau <julien.cristau@logilab.fr>
parents:
9366
diff
changeset
|
406 |
return False |
8266c8c375bb
[schema] move definition of RQLExpression classes before default permission dicts
Julien Cristau <julien.cristau@logilab.fr>
parents:
9366
diff
changeset
|
407 |
kwargs['o'] = toeid |
8266c8c375bb
[schema] move definition of RQLExpression classes before default permission dicts
Julien Cristau <julien.cristau@logilab.fr>
parents:
9366
diff
changeset
|
408 |
return self._check(_cw, **kwargs) |
8266c8c375bb
[schema] move definition of RQLExpression classes before default permission dicts
Julien Cristau <julien.cristau@logilab.fr>
parents:
9366
diff
changeset
|
409 |
|
9395
96dba2efd16d
[hooks/security] provide attribute "add" permission
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9393
diff
changeset
|
410 |
|
96dba2efd16d
[hooks/security] provide attribute "add" permission
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9393
diff
changeset
|
411 |
# In yams, default 'update' perm for attributes granted to managers and owners. |
96dba2efd16d
[hooks/security] provide attribute "add" permission
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9393
diff
changeset
|
412 |
# Within cw, we want to default to users who may edit the entity holding the |
96dba2efd16d
[hooks/security] provide attribute "add" permission
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9393
diff
changeset
|
413 |
# attribute. |
96dba2efd16d
[hooks/security] provide attribute "add" permission
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9393
diff
changeset
|
414 |
# These default permissions won't be checked by the security hooks: |
96dba2efd16d
[hooks/security] provide attribute "add" permission
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9393
diff
changeset
|
415 |
# since they delegate checking to the entity, we can skip actual checks. |
96dba2efd16d
[hooks/security] provide attribute "add" permission
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9393
diff
changeset
|
416 |
ybo.DEFAULT_ATTRPERMS['update'] = ('managers', ERQLExpression('U has_update_permission X')) |
96dba2efd16d
[hooks/security] provide attribute "add" permission
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9393
diff
changeset
|
417 |
ybo.DEFAULT_ATTRPERMS['add'] = ('managers', ERQLExpression('U has_add_permission X')) |
96dba2efd16d
[hooks/security] provide attribute "add" permission
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9393
diff
changeset
|
418 |
|
96dba2efd16d
[hooks/security] provide attribute "add" permission
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9393
diff
changeset
|
419 |
|
4754
6bf17f810975
[schema] new constants for permissions definitions
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4717
diff
changeset
|
420 |
PUB_SYSTEM_ENTITY_PERMS = { |
6bf17f810975
[schema] new constants for permissions definitions
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4717
diff
changeset
|
421 |
'read': ('managers', 'users', 'guests',), |
6bf17f810975
[schema] new constants for permissions definitions
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4717
diff
changeset
|
422 |
'add': ('managers',), |
6bf17f810975
[schema] new constants for permissions definitions
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4717
diff
changeset
|
423 |
'delete': ('managers',), |
6bf17f810975
[schema] new constants for permissions definitions
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4717
diff
changeset
|
424 |
'update': ('managers',), |
6bf17f810975
[schema] new constants for permissions definitions
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4717
diff
changeset
|
425 |
} |
6bf17f810975
[schema] new constants for permissions definitions
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4717
diff
changeset
|
426 |
PUB_SYSTEM_REL_PERMS = { |
6bf17f810975
[schema] new constants for permissions definitions
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4717
diff
changeset
|
427 |
'read': ('managers', 'users', 'guests',), |
6bf17f810975
[schema] new constants for permissions definitions
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4717
diff
changeset
|
428 |
'add': ('managers',), |
6bf17f810975
[schema] new constants for permissions definitions
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4717
diff
changeset
|
429 |
'delete': ('managers',), |
6bf17f810975
[schema] new constants for permissions definitions
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4717
diff
changeset
|
430 |
} |
6bf17f810975
[schema] new constants for permissions definitions
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4717
diff
changeset
|
431 |
PUB_SYSTEM_ATTR_PERMS = { |
6bf17f810975
[schema] new constants for permissions definitions
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4717
diff
changeset
|
432 |
'read': ('managers', 'users', 'guests',), |
9395
96dba2efd16d
[hooks/security] provide attribute "add" permission
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9393
diff
changeset
|
433 |
'add': ('managers',), |
6944
0cf10429ad39
[sources] rewrite the way pyrorql mapping are stored in the database so it can be reused for other sources (eg datafeed+cwxml)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6861
diff
changeset
|
434 |
'update': ('managers',), |
4754
6bf17f810975
[schema] new constants for permissions definitions
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4717
diff
changeset
|
435 |
} |
6bf17f810975
[schema] new constants for permissions definitions
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4717
diff
changeset
|
436 |
RO_REL_PERMS = { |
6bf17f810975
[schema] new constants for permissions definitions
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4717
diff
changeset
|
437 |
'read': ('managers', 'users', 'guests',), |
6bf17f810975
[schema] new constants for permissions definitions
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4717
diff
changeset
|
438 |
'add': (), |
6bf17f810975
[schema] new constants for permissions definitions
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4717
diff
changeset
|
439 |
'delete': (), |
6bf17f810975
[schema] new constants for permissions definitions
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4717
diff
changeset
|
440 |
} |
6bf17f810975
[schema] new constants for permissions definitions
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4717
diff
changeset
|
441 |
RO_ATTR_PERMS = { |
6bf17f810975
[schema] new constants for permissions definitions
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4717
diff
changeset
|
442 |
'read': ('managers', 'users', 'guests',), |
9395
96dba2efd16d
[hooks/security] provide attribute "add" permission
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9393
diff
changeset
|
443 |
'add': ybo.DEFAULT_ATTRPERMS['add'], |
4754
6bf17f810975
[schema] new constants for permissions definitions
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4717
diff
changeset
|
444 |
'update': (), |
6bf17f810975
[schema] new constants for permissions definitions
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4717
diff
changeset
|
445 |
} |
6bf17f810975
[schema] new constants for permissions definitions
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4717
diff
changeset
|
446 |
|
2926
4484387ed012
when adding/removing cubes, we should add/remove entity types in correct order if one inherits from another
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2782
diff
changeset
|
447 |
# XXX same algorithm as in reorder_cubes and probably other place, |
4484387ed012
when adding/removing cubes, we should add/remove entity types in correct order if one inherits from another
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2782
diff
changeset
|
448 |
# may probably extract a generic function |
4484387ed012
when adding/removing cubes, we should add/remove entity types in correct order if one inherits from another
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2782
diff
changeset
|
449 |
def order_eschemas(eschemas): |
4484387ed012
when adding/removing cubes, we should add/remove entity types in correct order if one inherits from another
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2782
diff
changeset
|
450 |
"""return entity schemas ordered such that entity types which specializes an |
4484387ed012
when adding/removing cubes, we should add/remove entity types in correct order if one inherits from another
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2782
diff
changeset
|
451 |
other one appears after that one |
4484387ed012
when adding/removing cubes, we should add/remove entity types in correct order if one inherits from another
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2782
diff
changeset
|
452 |
""" |
4484387ed012
when adding/removing cubes, we should add/remove entity types in correct order if one inherits from another
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2782
diff
changeset
|
453 |
graph = {} |
4484387ed012
when adding/removing cubes, we should add/remove entity types in correct order if one inherits from another
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2782
diff
changeset
|
454 |
for eschema in eschemas: |
4484387ed012
when adding/removing cubes, we should add/remove entity types in correct order if one inherits from another
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2782
diff
changeset
|
455 |
if eschema.specializes(): |
4484387ed012
when adding/removing cubes, we should add/remove entity types in correct order if one inherits from another
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2782
diff
changeset
|
456 |
graph[eschema] = set((eschema.specializes(),)) |
4484387ed012
when adding/removing cubes, we should add/remove entity types in correct order if one inherits from another
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2782
diff
changeset
|
457 |
else: |
4484387ed012
when adding/removing cubes, we should add/remove entity types in correct order if one inherits from another
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2782
diff
changeset
|
458 |
graph[eschema] = set() |
4484387ed012
when adding/removing cubes, we should add/remove entity types in correct order if one inherits from another
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2782
diff
changeset
|
459 |
cycles = get_cycles(graph) |
4484387ed012
when adding/removing cubes, we should add/remove entity types in correct order if one inherits from another
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2782
diff
changeset
|
460 |
if cycles: |
4484387ed012
when adding/removing cubes, we should add/remove entity types in correct order if one inherits from another
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2782
diff
changeset
|
461 |
cycles = '\n'.join(' -> '.join(cycle) for cycle in cycles) |
4484387ed012
when adding/removing cubes, we should add/remove entity types in correct order if one inherits from another
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2782
diff
changeset
|
462 |
raise Exception('cycles in entity schema specialization: %s' |
4484387ed012
when adding/removing cubes, we should add/remove entity types in correct order if one inherits from another
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2782
diff
changeset
|
463 |
% cycles) |
4484387ed012
when adding/removing cubes, we should add/remove entity types in correct order if one inherits from another
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2782
diff
changeset
|
464 |
eschemas = [] |
4484387ed012
when adding/removing cubes, we should add/remove entity types in correct order if one inherits from another
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2782
diff
changeset
|
465 |
while graph: |
4484387ed012
when adding/removing cubes, we should add/remove entity types in correct order if one inherits from another
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2782
diff
changeset
|
466 |
# sorted to get predictable results |
4484387ed012
when adding/removing cubes, we should add/remove entity types in correct order if one inherits from another
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2782
diff
changeset
|
467 |
for eschema, deps in sorted(graph.items()): |
4484387ed012
when adding/removing cubes, we should add/remove entity types in correct order if one inherits from another
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2782
diff
changeset
|
468 |
if not deps: |
4484387ed012
when adding/removing cubes, we should add/remove entity types in correct order if one inherits from another
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2782
diff
changeset
|
469 |
eschemas.append(eschema) |
4484387ed012
when adding/removing cubes, we should add/remove entity types in correct order if one inherits from another
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2782
diff
changeset
|
470 |
del graph[eschema] |
4484387ed012
when adding/removing cubes, we should add/remove entity types in correct order if one inherits from another
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2782
diff
changeset
|
471 |
for deps in graph.itervalues(): |
4484387ed012
when adding/removing cubes, we should add/remove entity types in correct order if one inherits from another
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2782
diff
changeset
|
472 |
try: |
4484387ed012
when adding/removing cubes, we should add/remove entity types in correct order if one inherits from another
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2782
diff
changeset
|
473 |
deps.remove(eschema) |
4484387ed012
when adding/removing cubes, we should add/remove entity types in correct order if one inherits from another
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2782
diff
changeset
|
474 |
except KeyError: |
4484387ed012
when adding/removing cubes, we should add/remove entity types in correct order if one inherits from another
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2782
diff
changeset
|
475 |
continue |
4484387ed012
when adding/removing cubes, we should add/remove entity types in correct order if one inherits from another
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2782
diff
changeset
|
476 |
return eschemas |
4484387ed012
when adding/removing cubes, we should add/remove entity types in correct order if one inherits from another
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2782
diff
changeset
|
477 |
|
0 | 478 |
def bw_normalize_etype(etype): |
479 |
if etype in ETYPE_NAME_MAP: |
|
480 |
msg = '%s has been renamed to %s, please update your code' % ( |
|
1451 | 481 |
etype, ETYPE_NAME_MAP[etype]) |
0 | 482 |
warn(msg, DeprecationWarning, stacklevel=4) |
483 |
etype = ETYPE_NAME_MAP[etype] |
|
484 |
return etype |
|
485 |
||
3275
5247789df541
[gettext] provide GNU contexts to avoid translations ambiguities
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3240
diff
changeset
|
486 |
def display_name(req, key, form='', context=None): |
0 | 487 |
"""return a internationalized string for the key (schema entity or relation |
488 |
name) in a given form |
|
489 |
""" |
|
490 |
assert form in ('', 'plural', 'subject', 'object') |
|
491 |
if form == 'subject': |
|
492 |
form = '' |
|
493 |
if form: |
|
494 |
key = key + '_' + form |
|
495 |
# ensure unicode |
|
3284
036cf5a25714
ensure pgettext return unicode as well
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3275
diff
changeset
|
496 |
if context is not None: |
7951
b7c825b00f64
[schema display] display_name shouldn't call .lower(). Note the only proper way is to have different msgid for upper/lower cases. Closes #1105433
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7894
diff
changeset
|
497 |
return unicode(req.pgettext(context, key)) |
3275
5247789df541
[gettext] provide GNU contexts to avoid translations ambiguities
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3240
diff
changeset
|
498 |
else: |
7951
b7c825b00f64
[schema display] display_name shouldn't call .lower(). Note the only proper way is to have different msgid for upper/lower cases. Closes #1105433
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7894
diff
changeset
|
499 |
return unicode(req._(key)) |
3275
5247789df541
[gettext] provide GNU contexts to avoid translations ambiguities
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3240
diff
changeset
|
500 |
|
3978
2c95e3033f64
finish yesterday work on rql constraints:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3968
diff
changeset
|
501 |
|
2c95e3033f64
finish yesterday work on rql constraints:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3968
diff
changeset
|
502 |
# Schema objects definition ################################################### |
2c95e3033f64
finish yesterday work on rql constraints:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3968
diff
changeset
|
503 |
|
3471
8c57c71b859c
can now give context to rschema.display_name(...)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3401
diff
changeset
|
504 |
def ERSchema_display_name(self, req, form='', context=None): |
0 | 505 |
"""return a internationalized string for the entity/relation type name in |
506 |
a given form |
|
507 |
""" |
|
3471
8c57c71b859c
can now give context to rschema.display_name(...)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3401
diff
changeset
|
508 |
return display_name(req, self.type, form, context) |
0 | 509 |
ERSchema.display_name = ERSchema_display_name |
510 |
||
511 |
@cached |
|
3877
7ca53fc72a0a
reldefsecurity branch :
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3827
diff
changeset
|
512 |
def get_groups(self, action): |
0 | 513 |
"""return the groups authorized to perform <action> on entities of |
514 |
this type |
|
515 |
||
516 |
:type action: str |
|
517 |
:param action: the name of a permission |
|
518 |
||
519 |
:rtype: tuple |
|
520 |
:return: names of the groups with the given permission |
|
521 |
""" |
|
522 |
assert action in self.ACTIONS, action |
|
523 |
#assert action in self._groups, '%s %s' % (self, action) |
|
524 |
try: |
|
3877
7ca53fc72a0a
reldefsecurity branch :
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3827
diff
changeset
|
525 |
return frozenset(g for g in self.permissions[action] if isinstance(g, basestring)) |
0 | 526 |
except KeyError: |
527 |
return () |
|
3877
7ca53fc72a0a
reldefsecurity branch :
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3827
diff
changeset
|
528 |
PermissionMixIn.get_groups = get_groups |
0 | 529 |
|
530 |
@cached |
|
3877
7ca53fc72a0a
reldefsecurity branch :
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3827
diff
changeset
|
531 |
def get_rqlexprs(self, action): |
0 | 532 |
"""return the rql expressions representing queries to check the user is allowed |
533 |
to perform <action> on entities of this type |
|
534 |
||
535 |
:type action: str |
|
536 |
:param action: the name of a permission |
|
537 |
||
538 |
:rtype: tuple |
|
539 |
:return: the rql expressions with the given permission |
|
540 |
""" |
|
541 |
assert action in self.ACTIONS, action |
|
542 |
#assert action in self._rqlexprs, '%s %s' % (self, action) |
|
543 |
try: |
|
3877
7ca53fc72a0a
reldefsecurity branch :
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3827
diff
changeset
|
544 |
return tuple(g for g in self.permissions[action] if not isinstance(g, basestring)) |
0 | 545 |
except KeyError: |
546 |
return () |
|
3877
7ca53fc72a0a
reldefsecurity branch :
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3827
diff
changeset
|
547 |
PermissionMixIn.get_rqlexprs = get_rqlexprs |
0 | 548 |
|
3877
7ca53fc72a0a
reldefsecurity branch :
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3827
diff
changeset
|
549 |
orig_set_action_permissions = PermissionMixIn.set_action_permissions |
7ca53fc72a0a
reldefsecurity branch :
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3827
diff
changeset
|
550 |
def set_action_permissions(self, action, permissions): |
0 | 551 |
"""set the groups and rql expressions allowing to perform <action> on |
552 |
entities of this type |
|
553 |
||
554 |
:type action: str |
|
555 |
:param action: the name of a permission |
|
556 |
||
557 |
:type permissions: tuple |
|
558 |
:param permissions: the groups and rql expressions allowing the given action |
|
559 |
""" |
|
3877
7ca53fc72a0a
reldefsecurity branch :
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3827
diff
changeset
|
560 |
orig_set_action_permissions(self, action, tuple(permissions)) |
7ca53fc72a0a
reldefsecurity branch :
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3827
diff
changeset
|
561 |
clear_cache(self, 'get_rqlexprs') |
7ca53fc72a0a
reldefsecurity branch :
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3827
diff
changeset
|
562 |
clear_cache(self, 'get_groups') |
7ca53fc72a0a
reldefsecurity branch :
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3827
diff
changeset
|
563 |
PermissionMixIn.set_action_permissions = set_action_permissions |
0 | 564 |
|
3877
7ca53fc72a0a
reldefsecurity branch :
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3827
diff
changeset
|
565 |
def has_local_role(self, action): |
0 | 566 |
"""return true if the action *may* be granted localy (eg either rql |
567 |
expressions or the owners group are used in security definition) |
|
568 |
||
569 |
XXX this method is only there since we don't know well how to deal with |
|
570 |
'add' action checking. Also find a better name would be nice. |
|
571 |
""" |
|
572 |
assert action in self.ACTIONS, action |
|
573 |
if self.get_rqlexprs(action): |
|
574 |
return True |
|
575 |
if action in ('update', 'delete'): |
|
3877
7ca53fc72a0a
reldefsecurity branch :
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3827
diff
changeset
|
576 |
return 'owners' in self.get_groups(action) |
0 | 577 |
return False |
3877
7ca53fc72a0a
reldefsecurity branch :
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3827
diff
changeset
|
578 |
PermissionMixIn.has_local_role = has_local_role |
7ca53fc72a0a
reldefsecurity branch :
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3827
diff
changeset
|
579 |
|
7ca53fc72a0a
reldefsecurity branch :
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3827
diff
changeset
|
580 |
def may_have_permission(self, action, req): |
7ca53fc72a0a
reldefsecurity branch :
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3827
diff
changeset
|
581 |
if action != 'read' and not (self.has_local_role('read') or |
7ca53fc72a0a
reldefsecurity branch :
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3827
diff
changeset
|
582 |
self.has_perm(req, 'read')): |
7ca53fc72a0a
reldefsecurity branch :
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3827
diff
changeset
|
583 |
return False |
7ca53fc72a0a
reldefsecurity branch :
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3827
diff
changeset
|
584 |
return self.has_local_role(action) or self.has_perm(req, action) |
7ca53fc72a0a
reldefsecurity branch :
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3827
diff
changeset
|
585 |
PermissionMixIn.may_have_permission = may_have_permission |
7ca53fc72a0a
reldefsecurity branch :
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3827
diff
changeset
|
586 |
|
8540
fee98af8bb33
[schema] rename schema permissions function: session may also be a request, use _cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8258
diff
changeset
|
587 |
def has_perm(self, _cw, action, **kwargs): |
3877
7ca53fc72a0a
reldefsecurity branch :
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3827
diff
changeset
|
588 |
"""return true if the action is granted globaly or localy""" |
7ca53fc72a0a
reldefsecurity branch :
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3827
diff
changeset
|
589 |
try: |
8540
fee98af8bb33
[schema] rename schema permissions function: session may also be a request, use _cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8258
diff
changeset
|
590 |
self.check_perm(_cw, action, **kwargs) |
3877
7ca53fc72a0a
reldefsecurity branch :
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3827
diff
changeset
|
591 |
return True |
7ca53fc72a0a
reldefsecurity branch :
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3827
diff
changeset
|
592 |
except Unauthorized: |
7ca53fc72a0a
reldefsecurity branch :
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3827
diff
changeset
|
593 |
return False |
7ca53fc72a0a
reldefsecurity branch :
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3827
diff
changeset
|
594 |
PermissionMixIn.has_perm = has_perm |
7ca53fc72a0a
reldefsecurity branch :
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3827
diff
changeset
|
595 |
|
9148
1b549c1acd4f
[schema,server] add a security debugging aid (closes #2920304)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8945
diff
changeset
|
596 |
|
8540
fee98af8bb33
[schema] rename schema permissions function: session may also be a request, use _cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8258
diff
changeset
|
597 |
def check_perm(self, _cw, action, **kwargs): |
fee98af8bb33
[schema] rename schema permissions function: session may also be a request, use _cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8258
diff
changeset
|
598 |
# NB: _cw may be a server transaction or a request object. |
fee98af8bb33
[schema] rename schema permissions function: session may also be a request, use _cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8258
diff
changeset
|
599 |
# |
fee98af8bb33
[schema] rename schema permissions function: session may also be a request, use _cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8258
diff
changeset
|
600 |
# check user is in an allowed group, if so that's enough internal |
fee98af8bb33
[schema] rename schema permissions function: session may also be a request, use _cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8258
diff
changeset
|
601 |
# transactions should always stop there |
9148
1b549c1acd4f
[schema,server] add a security debugging aid (closes #2920304)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8945
diff
changeset
|
602 |
DBG = False |
1b549c1acd4f
[schema,server] add a security debugging aid (closes #2920304)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8945
diff
changeset
|
603 |
if server.DEBUG & server.DBG_SEC: |
1b549c1acd4f
[schema,server] add a security debugging aid (closes #2920304)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8945
diff
changeset
|
604 |
if action in server._SECURITY_CAPS: |
1b549c1acd4f
[schema,server] add a security debugging aid (closes #2920304)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8945
diff
changeset
|
605 |
_self_str = str(self) |
1b549c1acd4f
[schema,server] add a security debugging aid (closes #2920304)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8945
diff
changeset
|
606 |
if server._SECURITY_ITEMS: |
1b549c1acd4f
[schema,server] add a security debugging aid (closes #2920304)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8945
diff
changeset
|
607 |
if any(item in _self_str for item in server._SECURITY_ITEMS): |
1b549c1acd4f
[schema,server] add a security debugging aid (closes #2920304)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8945
diff
changeset
|
608 |
DBG = True |
1b549c1acd4f
[schema,server] add a security debugging aid (closes #2920304)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8945
diff
changeset
|
609 |
else: |
1b549c1acd4f
[schema,server] add a security debugging aid (closes #2920304)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8945
diff
changeset
|
610 |
DBG = True |
3877
7ca53fc72a0a
reldefsecurity branch :
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3827
diff
changeset
|
611 |
groups = self.get_groups(action) |
8540
fee98af8bb33
[schema] rename schema permissions function: session may also be a request, use _cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8258
diff
changeset
|
612 |
if _cw.user.matching_groups(groups): |
9148
1b549c1acd4f
[schema,server] add a security debugging aid (closes #2920304)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8945
diff
changeset
|
613 |
if DBG: |
1b549c1acd4f
[schema,server] add a security debugging aid (closes #2920304)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8945
diff
changeset
|
614 |
print 'check_perm: %r %r: user matches %s' % (action, _self_str, groups) |
3877
7ca53fc72a0a
reldefsecurity branch :
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3827
diff
changeset
|
615 |
return |
7ca53fc72a0a
reldefsecurity branch :
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3827
diff
changeset
|
616 |
# if 'owners' in allowed groups, check if the user actually owns this |
7ca53fc72a0a
reldefsecurity branch :
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3827
diff
changeset
|
617 |
# object, if so that's enough |
8540
fee98af8bb33
[schema] rename schema permissions function: session may also be a request, use _cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8258
diff
changeset
|
618 |
# |
fee98af8bb33
[schema] rename schema permissions function: session may also be a request, use _cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8258
diff
changeset
|
619 |
# NB: give _cw to user.owns since user is not be bound to a transaction on |
fee98af8bb33
[schema] rename schema permissions function: session may also be a request, use _cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8258
diff
changeset
|
620 |
# the repository side |
4607
55eab66c6592
[schema security] fix so that when cheking attributes perms for an entity being created, 'owners' and has_*_permission in erqlexpr are considered satisfied
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4586
diff
changeset
|
621 |
if 'owners' in groups and ( |
55eab66c6592
[schema security] fix so that when cheking attributes perms for an entity being created, 'owners' and has_*_permission in erqlexpr are considered satisfied
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4586
diff
changeset
|
622 |
kwargs.get('creating') |
8540
fee98af8bb33
[schema] rename schema permissions function: session may also be a request, use _cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8258
diff
changeset
|
623 |
or ('eid' in kwargs and _cw.user.owns(kwargs['eid']))): |
9148
1b549c1acd4f
[schema,server] add a security debugging aid (closes #2920304)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8945
diff
changeset
|
624 |
if DBG: |
1b549c1acd4f
[schema,server] add a security debugging aid (closes #2920304)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8945
diff
changeset
|
625 |
print ('check_perm: %r %r: user is owner or creation time' % |
1b549c1acd4f
[schema,server] add a security debugging aid (closes #2920304)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8945
diff
changeset
|
626 |
(action, _self_str)) |
3877
7ca53fc72a0a
reldefsecurity branch :
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3827
diff
changeset
|
627 |
return |
7ca53fc72a0a
reldefsecurity branch :
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3827
diff
changeset
|
628 |
# else if there is some rql expressions, check them |
9148
1b549c1acd4f
[schema,server] add a security debugging aid (closes #2920304)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8945
diff
changeset
|
629 |
if DBG: |
1b549c1acd4f
[schema,server] add a security debugging aid (closes #2920304)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8945
diff
changeset
|
630 |
print ('check_perm: %r %r %s' % |
1b549c1acd4f
[schema,server] add a security debugging aid (closes #2920304)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8945
diff
changeset
|
631 |
(action, _self_str, [(rqlexpr, kwargs, rqlexpr.check(_cw, **kwargs)) |
1b549c1acd4f
[schema,server] add a security debugging aid (closes #2920304)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8945
diff
changeset
|
632 |
for rqlexpr in self.get_rqlexprs(action)])) |
8540
fee98af8bb33
[schema] rename schema permissions function: session may also be a request, use _cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8258
diff
changeset
|
633 |
if any(rqlexpr.check(_cw, **kwargs) |
3877
7ca53fc72a0a
reldefsecurity branch :
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3827
diff
changeset
|
634 |
for rqlexpr in self.get_rqlexprs(action)): |
7ca53fc72a0a
reldefsecurity branch :
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3827
diff
changeset
|
635 |
return |
7ca53fc72a0a
reldefsecurity branch :
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3827
diff
changeset
|
636 |
raise Unauthorized(action, str(self)) |
7ca53fc72a0a
reldefsecurity branch :
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3827
diff
changeset
|
637 |
PermissionMixIn.check_perm = check_perm |
7ca53fc72a0a
reldefsecurity branch :
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3827
diff
changeset
|
638 |
|
7ca53fc72a0a
reldefsecurity branch :
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3827
diff
changeset
|
639 |
|
7ca53fc72a0a
reldefsecurity branch :
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3827
diff
changeset
|
640 |
RelationDefinitionSchema._RPROPERTIES['eid'] = None |
8945
ba9e3fbfa5a5
[schemaserial] serialize additional yams parameter for customs type
Vincent Michel <vincent.michel@logilab.fr>
parents:
8892
diff
changeset
|
641 |
# remember rproperties defined at this point. Others will have to be serialized in |
ba9e3fbfa5a5
[schemaserial] serialize additional yams parameter for customs type
Vincent Michel <vincent.michel@logilab.fr>
parents:
8892
diff
changeset
|
642 |
# CWAttribute.extra_props |
ba9e3fbfa5a5
[schemaserial] serialize additional yams parameter for customs type
Vincent Michel <vincent.michel@logilab.fr>
parents:
8892
diff
changeset
|
643 |
KNOWN_RPROPERTIES = RelationDefinitionSchema.ALL_PROPERTIES() |
3877
7ca53fc72a0a
reldefsecurity branch :
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3827
diff
changeset
|
644 |
|
7ca53fc72a0a
reldefsecurity branch :
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3827
diff
changeset
|
645 |
def rql_expression(self, expression, mainvars=None, eid=None): |
7ca53fc72a0a
reldefsecurity branch :
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3827
diff
changeset
|
646 |
"""rql expression factory""" |
7ca53fc72a0a
reldefsecurity branch :
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3827
diff
changeset
|
647 |
if self.rtype.final: |
7ca53fc72a0a
reldefsecurity branch :
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3827
diff
changeset
|
648 |
return ERQLExpression(expression, mainvars, eid) |
7ca53fc72a0a
reldefsecurity branch :
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3827
diff
changeset
|
649 |
return RRQLExpression(expression, mainvars, eid) |
7ca53fc72a0a
reldefsecurity branch :
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3827
diff
changeset
|
650 |
RelationDefinitionSchema.rql_expression = rql_expression |
7ca53fc72a0a
reldefsecurity branch :
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3827
diff
changeset
|
651 |
|
7ca53fc72a0a
reldefsecurity branch :
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3827
diff
changeset
|
652 |
orig_check_permission_definitions = RelationDefinitionSchema.check_permission_definitions |
7ca53fc72a0a
reldefsecurity branch :
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3827
diff
changeset
|
653 |
def check_permission_definitions(self): |
7ca53fc72a0a
reldefsecurity branch :
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3827
diff
changeset
|
654 |
orig_check_permission_definitions(self) |
7ca53fc72a0a
reldefsecurity branch :
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3827
diff
changeset
|
655 |
schema = self.subject.schema |
7ca53fc72a0a
reldefsecurity branch :
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3827
diff
changeset
|
656 |
for action, groups in self.permissions.iteritems(): |
7ca53fc72a0a
reldefsecurity branch :
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3827
diff
changeset
|
657 |
for group_or_rqlexpr in groups: |
7ca53fc72a0a
reldefsecurity branch :
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3827
diff
changeset
|
658 |
if action == 'read' and \ |
7ca53fc72a0a
reldefsecurity branch :
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3827
diff
changeset
|
659 |
isinstance(group_or_rqlexpr, RQLExpression): |
7ca53fc72a0a
reldefsecurity branch :
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3827
diff
changeset
|
660 |
msg = "can't use rql expression for read permission of %s" |
7ca53fc72a0a
reldefsecurity branch :
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3827
diff
changeset
|
661 |
raise BadSchemaDefinition(msg % self) |
4574
2380444d982c
[schema] refactor/cleanup check_permissions
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4570
diff
changeset
|
662 |
if self.final and isinstance(group_or_rqlexpr, RRQLExpression): |
2380444d982c
[schema] refactor/cleanup check_permissions
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4570
diff
changeset
|
663 |
msg = "can't use RRQLExpression on %s, use an ERQLExpression" |
2380444d982c
[schema] refactor/cleanup check_permissions
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4570
diff
changeset
|
664 |
raise BadSchemaDefinition(msg % self) |
2380444d982c
[schema] refactor/cleanup check_permissions
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4570
diff
changeset
|
665 |
if not self.final and isinstance(group_or_rqlexpr, ERQLExpression): |
3877
7ca53fc72a0a
reldefsecurity branch :
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3827
diff
changeset
|
666 |
msg = "can't use ERQLExpression on %s, use a RRQLExpression" |
7ca53fc72a0a
reldefsecurity branch :
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3827
diff
changeset
|
667 |
raise BadSchemaDefinition(msg % self) |
7ca53fc72a0a
reldefsecurity branch :
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3827
diff
changeset
|
668 |
RelationDefinitionSchema.check_permission_definitions = check_permission_definitions |
0 | 669 |
|
670 |
||
671 |
class CubicWebEntitySchema(EntitySchema): |
|
672 |
"""a entity has a type, a set of subject and or object relations |
|
673 |
the entity schema defines the possible relations for a given type and some |
|
674 |
constraints on those relations |
|
675 |
""" |
|
676 |
def __init__(self, schema=None, edef=None, eid=None, **kwargs): |
|
677 |
super(CubicWebEntitySchema, self).__init__(schema, edef, **kwargs) |
|
678 |
if eid is None and edef is not None: |
|
679 |
eid = getattr(edef, 'eid', None) |
|
680 |
self.eid = eid |
|
4574
2380444d982c
[schema] refactor/cleanup check_permissions
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4570
diff
changeset
|
681 |
|
9547
43aace16a953
[schema] add composite handling helpers on EntitySchema (related to #3463112)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9469
diff
changeset
|
682 |
def targets(self, role): |
43aace16a953
[schema] add composite handling helpers on EntitySchema (related to #3463112)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9469
diff
changeset
|
683 |
assert role in ('subject', 'object') |
43aace16a953
[schema] add composite handling helpers on EntitySchema (related to #3463112)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9469
diff
changeset
|
684 |
if role == 'subject': |
43aace16a953
[schema] add composite handling helpers on EntitySchema (related to #3463112)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9469
diff
changeset
|
685 |
return self.subjrels.values() |
43aace16a953
[schema] add composite handling helpers on EntitySchema (related to #3463112)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9469
diff
changeset
|
686 |
return self.objrels.values() |
43aace16a953
[schema] add composite handling helpers on EntitySchema (related to #3463112)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9469
diff
changeset
|
687 |
|
43aace16a953
[schema] add composite handling helpers on EntitySchema (related to #3463112)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9469
diff
changeset
|
688 |
@cachedproperty |
43aace16a953
[schema] add composite handling helpers on EntitySchema (related to #3463112)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9469
diff
changeset
|
689 |
def composite_rdef_roles(self): |
43aace16a953
[schema] add composite handling helpers on EntitySchema (related to #3463112)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9469
diff
changeset
|
690 |
"""Return all relation definitions that define the current entity |
43aace16a953
[schema] add composite handling helpers on EntitySchema (related to #3463112)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9469
diff
changeset
|
691 |
type as a composite. |
43aace16a953
[schema] add composite handling helpers on EntitySchema (related to #3463112)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9469
diff
changeset
|
692 |
""" |
43aace16a953
[schema] add composite handling helpers on EntitySchema (related to #3463112)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9469
diff
changeset
|
693 |
rdef_roles = [] |
43aace16a953
[schema] add composite handling helpers on EntitySchema (related to #3463112)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9469
diff
changeset
|
694 |
for role in ('subject', 'object'): |
43aace16a953
[schema] add composite handling helpers on EntitySchema (related to #3463112)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9469
diff
changeset
|
695 |
for rschema in self.targets(role): |
43aace16a953
[schema] add composite handling helpers on EntitySchema (related to #3463112)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9469
diff
changeset
|
696 |
if rschema.final: |
43aace16a953
[schema] add composite handling helpers on EntitySchema (related to #3463112)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9469
diff
changeset
|
697 |
continue |
43aace16a953
[schema] add composite handling helpers on EntitySchema (related to #3463112)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9469
diff
changeset
|
698 |
for rdef in rschema.rdefs.values(): |
43aace16a953
[schema] add composite handling helpers on EntitySchema (related to #3463112)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9469
diff
changeset
|
699 |
crole = rdef.composite |
43aace16a953
[schema] add composite handling helpers on EntitySchema (related to #3463112)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9469
diff
changeset
|
700 |
if crole == role: |
43aace16a953
[schema] add composite handling helpers on EntitySchema (related to #3463112)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9469
diff
changeset
|
701 |
rdef_roles.append((rdef, role)) |
43aace16a953
[schema] add composite handling helpers on EntitySchema (related to #3463112)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9469
diff
changeset
|
702 |
return rdef_roles |
43aace16a953
[schema] add composite handling helpers on EntitySchema (related to #3463112)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9469
diff
changeset
|
703 |
|
43aace16a953
[schema] add composite handling helpers on EntitySchema (related to #3463112)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9469
diff
changeset
|
704 |
@cachedproperty |
43aace16a953
[schema] add composite handling helpers on EntitySchema (related to #3463112)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9469
diff
changeset
|
705 |
def is_composite(self): |
43aace16a953
[schema] add composite handling helpers on EntitySchema (related to #3463112)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9469
diff
changeset
|
706 |
return bool(len(self.composite_rdef_roles)) |
43aace16a953
[schema] add composite handling helpers on EntitySchema (related to #3463112)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9469
diff
changeset
|
707 |
|
4574
2380444d982c
[schema] refactor/cleanup check_permissions
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4570
diff
changeset
|
708 |
def check_permission_definitions(self): |
2380444d982c
[schema] refactor/cleanup check_permissions
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4570
diff
changeset
|
709 |
super(CubicWebEntitySchema, self).check_permission_definitions() |
2380444d982c
[schema] refactor/cleanup check_permissions
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4570
diff
changeset
|
710 |
for groups in self.permissions.itervalues(): |
2380444d982c
[schema] refactor/cleanup check_permissions
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4570
diff
changeset
|
711 |
for group_or_rqlexpr in groups: |
2380444d982c
[schema] refactor/cleanup check_permissions
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4570
diff
changeset
|
712 |
if isinstance(group_or_rqlexpr, RRQLExpression): |
2380444d982c
[schema] refactor/cleanup check_permissions
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4570
diff
changeset
|
713 |
msg = "can't use RRQLExpression on %s, use an ERQLExpression" |
2380444d982c
[schema] refactor/cleanup check_permissions
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4570
diff
changeset
|
714 |
raise BadSchemaDefinition(msg % self.type) |
1451 | 715 |
|
6951
cb6314b09e0f
[schema, ui] fix is_subobject to skip cw_source relation (else everything is considered as a subobject, since this relation is now composite)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6949
diff
changeset
|
716 |
def is_subobject(self, strict=False, skiprels=None): |
cb6314b09e0f
[schema, ui] fix is_subobject to skip cw_source relation (else everything is considered as a subobject, since this relation is now composite)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6949
diff
changeset
|
717 |
if skiprels is None: |
cb6314b09e0f
[schema, ui] fix is_subobject to skip cw_source relation (else everything is considered as a subobject, since this relation is now composite)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6949
diff
changeset
|
718 |
skiprels = SKIP_COMPOSITE_RELS |
cb6314b09e0f
[schema, ui] fix is_subobject to skip cw_source relation (else everything is considered as a subobject, since this relation is now composite)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6949
diff
changeset
|
719 |
else: |
cb6314b09e0f
[schema, ui] fix is_subobject to skip cw_source relation (else everything is considered as a subobject, since this relation is now composite)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6949
diff
changeset
|
720 |
skiprels += SKIP_COMPOSITE_RELS |
cb6314b09e0f
[schema, ui] fix is_subobject to skip cw_source relation (else everything is considered as a subobject, since this relation is now composite)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6949
diff
changeset
|
721 |
return super(CubicWebEntitySchema, self).is_subobject(strict, |
cb6314b09e0f
[schema, ui] fix is_subobject to skip cw_source relation (else everything is considered as a subobject, since this relation is now composite)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6949
diff
changeset
|
722 |
skiprels=skiprels) |
cb6314b09e0f
[schema, ui] fix is_subobject to skip cw_source relation (else everything is considered as a subobject, since this relation is now composite)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6949
diff
changeset
|
723 |
|
0 | 724 |
def attribute_definitions(self): |
725 |
"""return an iterator on attribute definitions |
|
1451 | 726 |
|
0 | 727 |
attribute relations are a subset of subject relations where the |
728 |
object's type is a final entity |
|
1451 | 729 |
|
0 | 730 |
an attribute definition is a 2-uple : |
731 |
* name of the relation |
|
732 |
* schema of the destination entity type |
|
733 |
""" |
|
734 |
iter = super(CubicWebEntitySchema, self).attribute_definitions() |
|
735 |
for rschema, attrschema in iter: |
|
736 |
if rschema.type == 'has_text': |
|
737 |
continue |
|
738 |
yield rschema, attrschema |
|
1451 | 739 |
|
2128
464edb198faa
drop @ wildcard in relation subject/object, override main_attribute for proper behaviour
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2126
diff
changeset
|
740 |
def main_attribute(self): |
464edb198faa
drop @ wildcard in relation subject/object, override main_attribute for proper behaviour
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2126
diff
changeset
|
741 |
"""convenience method that returns the *main* (i.e. the first non meta) |
464edb198faa
drop @ wildcard in relation subject/object, override main_attribute for proper behaviour
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2126
diff
changeset
|
742 |
attribute defined in the entity schema |
464edb198faa
drop @ wildcard in relation subject/object, override main_attribute for proper behaviour
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2126
diff
changeset
|
743 |
""" |
464edb198faa
drop @ wildcard in relation subject/object, override main_attribute for proper behaviour
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2126
diff
changeset
|
744 |
for rschema, _ in self.attribute_definitions(): |
2622
3c7edaa6c6d2
oops, should have been in a earlier commit (META_RELATION_TYPES renaming)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2616
diff
changeset
|
745 |
if not (rschema in META_RTYPES |
2128
464edb198faa
drop @ wildcard in relation subject/object, override main_attribute for proper behaviour
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2126
diff
changeset
|
746 |
or self.is_metadata(rschema)): |
464edb198faa
drop @ wildcard in relation subject/object, override main_attribute for proper behaviour
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2126
diff
changeset
|
747 |
return rschema |
464edb198faa
drop @ wildcard in relation subject/object, override main_attribute for proper behaviour
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2126
diff
changeset
|
748 |
|
0 | 749 |
def add_subject_relation(self, rschema): |
750 |
"""register the relation schema as possible subject relation""" |
|
751 |
super(CubicWebEntitySchema, self).add_subject_relation(rschema) |
|
7467
5a6b3e51807d
[schema] fix computing of has_text relation: when a fulltext_container relation is added, we need to recompute has_text for the target entity type as well. Also, avoid computation when not needed
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7152
diff
changeset
|
752 |
if rschema.final: |
5a6b3e51807d
[schema] fix computing of has_text relation: when a fulltext_container relation is added, we need to recompute has_text for the target entity type as well. Also, avoid computation when not needed
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7152
diff
changeset
|
753 |
if self.rdef(rschema).get('fulltextindexed'): |
5a6b3e51807d
[schema] fix computing of has_text relation: when a fulltext_container relation is added, we need to recompute has_text for the target entity type as well. Also, avoid computation when not needed
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7152
diff
changeset
|
754 |
self._update_has_text() |
5a6b3e51807d
[schema] fix computing of has_text relation: when a fulltext_container relation is added, we need to recompute has_text for the target entity type as well. Also, avoid computation when not needed
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7152
diff
changeset
|
755 |
elif rschema.fulltext_container: |
5a6b3e51807d
[schema] fix computing of has_text relation: when a fulltext_container relation is added, we need to recompute has_text for the target entity type as well. Also, avoid computation when not needed
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7152
diff
changeset
|
756 |
self._update_has_text() |
5a6b3e51807d
[schema] fix computing of has_text relation: when a fulltext_container relation is added, we need to recompute has_text for the target entity type as well. Also, avoid computation when not needed
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7152
diff
changeset
|
757 |
|
5a6b3e51807d
[schema] fix computing of has_text relation: when a fulltext_container relation is added, we need to recompute has_text for the target entity type as well. Also, avoid computation when not needed
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7152
diff
changeset
|
758 |
def add_object_relation(self, rschema): |
5a6b3e51807d
[schema] fix computing of has_text relation: when a fulltext_container relation is added, we need to recompute has_text for the target entity type as well. Also, avoid computation when not needed
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7152
diff
changeset
|
759 |
"""register the relation schema as possible object relation""" |
5a6b3e51807d
[schema] fix computing of has_text relation: when a fulltext_container relation is added, we need to recompute has_text for the target entity type as well. Also, avoid computation when not needed
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7152
diff
changeset
|
760 |
super(CubicWebEntitySchema, self).add_object_relation(rschema) |
5a6b3e51807d
[schema] fix computing of has_text relation: when a fulltext_container relation is added, we need to recompute has_text for the target entity type as well. Also, avoid computation when not needed
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7152
diff
changeset
|
761 |
if rschema.fulltext_container: |
5a6b3e51807d
[schema] fix computing of has_text relation: when a fulltext_container relation is added, we need to recompute has_text for the target entity type as well. Also, avoid computation when not needed
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7152
diff
changeset
|
762 |
self._update_has_text() |
0 | 763 |
|
764 |
def del_subject_relation(self, rtype): |
|
765 |
super(CubicWebEntitySchema, self).del_subject_relation(rtype) |
|
7467
5a6b3e51807d
[schema] fix computing of has_text relation: when a fulltext_container relation is added, we need to recompute has_text for the target entity type as well. Also, avoid computation when not needed
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7152
diff
changeset
|
766 |
if 'has_text' in self.subjrels: |
5a6b3e51807d
[schema] fix computing of has_text relation: when a fulltext_container relation is added, we need to recompute has_text for the target entity type as well. Also, avoid computation when not needed
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7152
diff
changeset
|
767 |
self._update_has_text(deletion=True) |
5a6b3e51807d
[schema] fix computing of has_text relation: when a fulltext_container relation is added, we need to recompute has_text for the target entity type as well. Also, avoid computation when not needed
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7152
diff
changeset
|
768 |
|
5a6b3e51807d
[schema] fix computing of has_text relation: when a fulltext_container relation is added, we need to recompute has_text for the target entity type as well. Also, avoid computation when not needed
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7152
diff
changeset
|
769 |
def del_object_relation(self, rtype): |
5a6b3e51807d
[schema] fix computing of has_text relation: when a fulltext_container relation is added, we need to recompute has_text for the target entity type as well. Also, avoid computation when not needed
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7152
diff
changeset
|
770 |
super(CubicWebEntitySchema, self).del_object_relation(rtype) |
5a6b3e51807d
[schema] fix computing of has_text relation: when a fulltext_container relation is added, we need to recompute has_text for the target entity type as well. Also, avoid computation when not needed
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7152
diff
changeset
|
771 |
if 'has_text' in self.subjrels: |
5a6b3e51807d
[schema] fix computing of has_text relation: when a fulltext_container relation is added, we need to recompute has_text for the target entity type as well. Also, avoid computation when not needed
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7152
diff
changeset
|
772 |
self._update_has_text(deletion=True) |
1451 | 773 |
|
2632
920bfaff60a4
B [schema update] may remove has_text unexpectedly, give another argument to fix it
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2622
diff
changeset
|
774 |
def _update_has_text(self, deletion=False): |
0 | 775 |
may_need_has_text, has_has_text = False, False |
2632
920bfaff60a4
B [schema update] may remove has_text unexpectedly, give another argument to fix it
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2622
diff
changeset
|
776 |
need_has_text = None |
0 | 777 |
for rschema in self.subject_relations(): |
3689
deb13e88e037
follow yams 0.25 api changes to improve performance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3554
diff
changeset
|
778 |
if rschema.final: |
0 | 779 |
if rschema == 'has_text': |
780 |
has_has_text = True |
|
3877
7ca53fc72a0a
reldefsecurity branch :
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3827
diff
changeset
|
781 |
elif self.rdef(rschema).get('fulltextindexed'): |
0 | 782 |
may_need_has_text = True |
783 |
elif rschema.fulltext_container: |
|
784 |
if rschema.fulltext_container == 'subject': |
|
785 |
may_need_has_text = True |
|
786 |
else: |
|
787 |
need_has_text = False |
|
788 |
for rschema in self.object_relations(): |
|
789 |
if rschema.fulltext_container: |
|
790 |
if rschema.fulltext_container == 'object': |
|
791 |
may_need_has_text = True |
|
792 |
else: |
|
793 |
need_has_text = False |
|
794 |
if need_has_text is None: |
|
795 |
need_has_text = may_need_has_text |
|
2632
920bfaff60a4
B [schema update] may remove has_text unexpectedly, give another argument to fix it
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2622
diff
changeset
|
796 |
if need_has_text and not has_has_text and not deletion: |
4755
13a5d3a7410e
[schema] tweaks meta-relations and schema/workflow entities attributes permissions
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4754
diff
changeset
|
797 |
rdef = ybo.RelationDefinition(self.type, 'has_text', 'String', |
13a5d3a7410e
[schema] tweaks meta-relations and schema/workflow entities attributes permissions
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4754
diff
changeset
|
798 |
__permissions__=RO_ATTR_PERMS) |
0 | 799 |
self.schema.add_relation_def(rdef) |
800 |
elif not need_has_text and has_has_text: |
|
5122
c06078d59e87
[schema] ensure we don't remove has_text relation type unfortunatly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5030
diff
changeset
|
801 |
# use rschema.del_relation_def and not schema.del_relation_def to |
c06078d59e87
[schema] ensure we don't remove has_text relation type unfortunatly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5030
diff
changeset
|
802 |
# avoid deleting the relation type accidentally... |
c06078d59e87
[schema] ensure we don't remove has_text relation type unfortunatly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5030
diff
changeset
|
803 |
self.schema['has_text'].del_relation_def(self, self.schema['String']) |
1451 | 804 |
|
5896 | 805 |
def schema_entity(self): # XXX @property for consistency with meta |
0 | 806 |
"""return True if this entity type is used to build the schema""" |
2126
a25859917ccc
stop using meta attribute from yams schema. Use instead sets defining meta relations and another defining schema types. Refactor various schema view based on this
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
807 |
return self.type in SCHEMA_TYPES |
0 | 808 |
|
809 |
def rql_expression(self, expression, mainvars=None, eid=None): |
|
810 |
"""rql expression factory""" |
|
811 |
return ERQLExpression(expression, mainvars, eid) |
|
1451 | 812 |
|
2252 | 813 |
|
0 | 814 |
class CubicWebRelationSchema(RelationSchema): |
1451 | 815 |
|
0 | 816 |
def __init__(self, schema=None, rdef=None, eid=None, **kwargs): |
817 |
if rdef is not None: |
|
818 |
# if this relation is inlined |
|
819 |
self.inlined = rdef.inlined |
|
820 |
super(CubicWebRelationSchema, self).__init__(schema, rdef, **kwargs) |
|
821 |
if eid is None and rdef is not None: |
|
822 |
eid = getattr(rdef, 'eid', None) |
|
823 |
self.eid = eid |
|
1451 | 824 |
|
2126
a25859917ccc
stop using meta attribute from yams schema. Use instead sets defining meta relations and another defining schema types. Refactor various schema view based on this
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
825 |
@property |
a25859917ccc
stop using meta attribute from yams schema. Use instead sets defining meta relations and another defining schema types. Refactor various schema view based on this
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
826 |
def meta(self): |
2622
3c7edaa6c6d2
oops, should have been in a earlier commit (META_RELATION_TYPES renaming)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2616
diff
changeset
|
827 |
return self.type in META_RTYPES |
1451 | 828 |
|
5896 | 829 |
def schema_relation(self): # XXX @property for consistency with meta |
2126
a25859917ccc
stop using meta attribute from yams schema. Use instead sets defining meta relations and another defining schema types. Refactor various schema view based on this
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
830 |
"""return True if this relation type is used to build the schema""" |
a25859917ccc
stop using meta attribute from yams schema. Use instead sets defining meta relations and another defining schema types. Refactor various schema view based on this
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
831 |
return self.type in SCHEMA_TYPES |
1451 | 832 |
|
3877
7ca53fc72a0a
reldefsecurity branch :
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3827
diff
changeset
|
833 |
def may_have_permission(self, action, req, eschema=None, role=None): |
7ca53fc72a0a
reldefsecurity branch :
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3827
diff
changeset
|
834 |
if eschema is not None: |
4019 | 835 |
for tschema in self.targets(eschema, role): |
836 |
rdef = self.role_rdef(eschema, tschema, role) |
|
3877
7ca53fc72a0a
reldefsecurity branch :
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3827
diff
changeset
|
837 |
if rdef.may_have_permission(action, req): |
7ca53fc72a0a
reldefsecurity branch :
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3827
diff
changeset
|
838 |
return True |
7ca53fc72a0a
reldefsecurity branch :
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3827
diff
changeset
|
839 |
else: |
7ca53fc72a0a
reldefsecurity branch :
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3827
diff
changeset
|
840 |
for rdef in self.rdefs.itervalues(): |
7ca53fc72a0a
reldefsecurity branch :
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3827
diff
changeset
|
841 |
if rdef.may_have_permission(action, req): |
7ca53fc72a0a
reldefsecurity branch :
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3827
diff
changeset
|
842 |
return True |
7ca53fc72a0a
reldefsecurity branch :
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3827
diff
changeset
|
843 |
return False |
0 | 844 |
|
8540
fee98af8bb33
[schema] rename schema permissions function: session may also be a request, use _cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8258
diff
changeset
|
845 |
def has_perm(self, _cw, action, **kwargs): |
3877
7ca53fc72a0a
reldefsecurity branch :
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3827
diff
changeset
|
846 |
"""return true if the action is granted globaly or localy""" |
4575
4a7fe84f7803
[schema] fix RelationSchema.has_perm to properly works with attribute relations
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4574
diff
changeset
|
847 |
if self.final: |
4a7fe84f7803
[schema] fix RelationSchema.has_perm to properly works with attribute relations
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4574
diff
changeset
|
848 |
assert not ('fromeid' in kwargs or 'toeid' in kwargs), kwargs |
4a7fe84f7803
[schema] fix RelationSchema.has_perm to properly works with attribute relations
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4574
diff
changeset
|
849 |
assert action in ('read', 'update') |
4a7fe84f7803
[schema] fix RelationSchema.has_perm to properly works with attribute relations
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4574
diff
changeset
|
850 |
if 'eid' in kwargs: |
9469
032825bbacab
[multi-sources-removal] Drop entities.source column
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9395
diff
changeset
|
851 |
subjtype = _cw.entity_metas(kwargs['eid'])['type'] |
4575
4a7fe84f7803
[schema] fix RelationSchema.has_perm to properly works with attribute relations
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4574
diff
changeset
|
852 |
else: |
4a7fe84f7803
[schema] fix RelationSchema.has_perm to properly works with attribute relations
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4574
diff
changeset
|
853 |
subjtype = objtype = None |
3877
7ca53fc72a0a
reldefsecurity branch :
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3827
diff
changeset
|
854 |
else: |
4575
4a7fe84f7803
[schema] fix RelationSchema.has_perm to properly works with attribute relations
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4574
diff
changeset
|
855 |
assert not 'eid' in kwargs, kwargs |
4a7fe84f7803
[schema] fix RelationSchema.has_perm to properly works with attribute relations
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4574
diff
changeset
|
856 |
assert action in ('read', 'add', 'delete') |
4a7fe84f7803
[schema] fix RelationSchema.has_perm to properly works with attribute relations
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4574
diff
changeset
|
857 |
if 'fromeid' in kwargs: |
9469
032825bbacab
[multi-sources-removal] Drop entities.source column
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9395
diff
changeset
|
858 |
subjtype = _cw.entity_metas(kwargs['fromeid'])['type'] |
5746
f4fc424747db
[security] SchemaRelation.has_perm grows to new arguments allowing to specify subject/object entity type when actual eid are not known, but their types are
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5703
diff
changeset
|
859 |
elif 'frometype' in kwargs: |
f4fc424747db
[security] SchemaRelation.has_perm grows to new arguments allowing to specify subject/object entity type when actual eid are not known, but their types are
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5703
diff
changeset
|
860 |
subjtype = kwargs.pop('frometype') |
4575
4a7fe84f7803
[schema] fix RelationSchema.has_perm to properly works with attribute relations
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4574
diff
changeset
|
861 |
else: |
4a7fe84f7803
[schema] fix RelationSchema.has_perm to properly works with attribute relations
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4574
diff
changeset
|
862 |
subjtype = None |
4a7fe84f7803
[schema] fix RelationSchema.has_perm to properly works with attribute relations
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4574
diff
changeset
|
863 |
if 'toeid' in kwargs: |
9469
032825bbacab
[multi-sources-removal] Drop entities.source column
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9395
diff
changeset
|
864 |
objtype = _cw.entity_metas(kwargs['toeid'])['type'] |
5746
f4fc424747db
[security] SchemaRelation.has_perm grows to new arguments allowing to specify subject/object entity type when actual eid are not known, but their types are
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5703
diff
changeset
|
865 |
elif 'toetype' in kwargs: |
f4fc424747db
[security] SchemaRelation.has_perm grows to new arguments allowing to specify subject/object entity type when actual eid are not known, but their types are
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5703
diff
changeset
|
866 |
objtype = kwargs.pop('toetype') |
4575
4a7fe84f7803
[schema] fix RelationSchema.has_perm to properly works with attribute relations
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4574
diff
changeset
|
867 |
else: |
4a7fe84f7803
[schema] fix RelationSchema.has_perm to properly works with attribute relations
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4574
diff
changeset
|
868 |
objtype = None |
3877
7ca53fc72a0a
reldefsecurity branch :
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3827
diff
changeset
|
869 |
if objtype and subjtype: |
8540
fee98af8bb33
[schema] rename schema permissions function: session may also be a request, use _cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8258
diff
changeset
|
870 |
return self.rdef(subjtype, objtype).has_perm(_cw, action, **kwargs) |
3877
7ca53fc72a0a
reldefsecurity branch :
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3827
diff
changeset
|
871 |
elif subjtype: |
4004
c52619c738a5
api renaming update
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
4003
diff
changeset
|
872 |
for tschema in self.targets(subjtype, 'subject'): |
c52619c738a5
api renaming update
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
4003
diff
changeset
|
873 |
rdef = self.rdef(subjtype, tschema) |
8540
fee98af8bb33
[schema] rename schema permissions function: session may also be a request, use _cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8258
diff
changeset
|
874 |
if not rdef.has_perm(_cw, action, **kwargs): |
3877
7ca53fc72a0a
reldefsecurity branch :
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3827
diff
changeset
|
875 |
return False |
7ca53fc72a0a
reldefsecurity branch :
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3827
diff
changeset
|
876 |
elif objtype: |
4004
c52619c738a5
api renaming update
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
4003
diff
changeset
|
877 |
for tschema in self.targets(objtype, 'object'): |
c52619c738a5
api renaming update
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
4003
diff
changeset
|
878 |
rdef = self.rdef(tschema, objtype) |
8540
fee98af8bb33
[schema] rename schema permissions function: session may also be a request, use _cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8258
diff
changeset
|
879 |
if not rdef.has_perm(_cw, action, **kwargs): |
3877
7ca53fc72a0a
reldefsecurity branch :
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3827
diff
changeset
|
880 |
return False |
7ca53fc72a0a
reldefsecurity branch :
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3827
diff
changeset
|
881 |
else: |
7ca53fc72a0a
reldefsecurity branch :
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3827
diff
changeset
|
882 |
for rdef in self.rdefs.itervalues(): |
8540
fee98af8bb33
[schema] rename schema permissions function: session may also be a request, use _cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8258
diff
changeset
|
883 |
if not rdef.has_perm(_cw, action, **kwargs): |
3877
7ca53fc72a0a
reldefsecurity branch :
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3827
diff
changeset
|
884 |
return False |
4233
94ffaecd8e8c
ouch, has_perm was always returning False...
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4181
diff
changeset
|
885 |
return True |
0 | 886 |
|
3877
7ca53fc72a0a
reldefsecurity branch :
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3827
diff
changeset
|
887 |
@deprecated('use .rdef(subjtype, objtype).role_cardinality(role)') |
7ca53fc72a0a
reldefsecurity branch :
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3827
diff
changeset
|
888 |
def cardinality(self, subjtype, objtype, target): |
7ca53fc72a0a
reldefsecurity branch :
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3827
diff
changeset
|
889 |
return self.rdef(subjtype, objtype).role_cardinality(target) |
0 | 890 |
|
1451 | 891 |
|
0 | 892 |
class CubicWebSchema(Schema): |
893 |
"""set of entities and relations schema defining the possible data sets |
|
894 |
used in an application |
|
895 |
||
896 |
:type name: str |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2460
diff
changeset
|
897 |
:ivar name: name of the schema, usually the instance identifier |
1451 | 898 |
|
0 | 899 |
:type base: str |
900 |
:ivar base: path of the directory where the schema is defined |
|
901 |
""" |
|
1451 | 902 |
reading_from_database = False |
0 | 903 |
entity_class = CubicWebEntitySchema |
904 |
relation_class = CubicWebRelationSchema |
|
2958
44e5446b649b
no inference for the identity relation
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2926
diff
changeset
|
905 |
no_specialization_inference = ('identity',) |
0 | 906 |
|
907 |
def __init__(self, *args, **kwargs): |
|
908 |
self._eid_index = {} |
|
909 |
super(CubicWebSchema, self).__init__(*args, **kwargs) |
|
910 |
ybo.register_base_types(self) |
|
2300
c8151d004e06
meta has been drop
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2293
diff
changeset
|
911 |
rschema = self.add_relation_type(ybo.RelationType('eid')) |
0 | 912 |
rschema.final = True |
2300
c8151d004e06
meta has been drop
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2293
diff
changeset
|
913 |
rschema = self.add_relation_type(ybo.RelationType('has_text')) |
0 | 914 |
rschema.final = True |
2300
c8151d004e06
meta has been drop
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2293
diff
changeset
|
915 |
rschema = self.add_relation_type(ybo.RelationType('identity')) |
0 | 916 |
rschema.final = False |
1451 | 917 |
|
7440
539de926ec9d
[test] fix failure introduced by 1719eab69551: the regexp should be fixed, not the error message
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7383
diff
changeset
|
918 |
etype_name_re = r'[A-Z][A-Za-z0-9]*[a-z]+[A-Za-z0-9]*$' |
0 | 919 |
def add_entity_type(self, edef): |
920 |
edef.name = edef.name.encode() |
|
921 |
edef.name = bw_normalize_etype(edef.name) |
|
7383
1719eab69551
[schema] fix imprecise error message
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
7152
diff
changeset
|
922 |
if not re.match(self.etype_name_re, edef.name): |
6861
9d4e11d6e783
[schema] ease understanding of schema naming error
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6827
diff
changeset
|
923 |
raise BadSchemaDefinition( |
9d4e11d6e783
[schema] ease understanding of schema naming error
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6827
diff
changeset
|
924 |
'%r is not a valid name for an entity type. It should start ' |
9d4e11d6e783
[schema] ease understanding of schema naming error
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6827
diff
changeset
|
925 |
'with an upper cased letter and be followed by at least a ' |
9d4e11d6e783
[schema] ease understanding of schema naming error
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6827
diff
changeset
|
926 |
'lower cased letter' % edef.name) |
0 | 927 |
eschema = super(CubicWebSchema, self).add_entity_type(edef) |
3689
deb13e88e037
follow yams 0.25 api changes to improve performance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3554
diff
changeset
|
928 |
if not eschema.final: |
0 | 929 |
# automatically add the eid relation to non final entity types |
930 |
rdef = ybo.RelationDefinition(eschema.type, 'eid', 'Int', |
|
4755
13a5d3a7410e
[schema] tweaks meta-relations and schema/workflow entities attributes permissions
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4754
diff
changeset
|
931 |
cardinality='11', uid=True, |
13a5d3a7410e
[schema] tweaks meta-relations and schema/workflow entities attributes permissions
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4754
diff
changeset
|
932 |
__permissions__=RO_ATTR_PERMS) |
0 | 933 |
self.add_relation_def(rdef) |
4755
13a5d3a7410e
[schema] tweaks meta-relations and schema/workflow entities attributes permissions
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4754
diff
changeset
|
934 |
rdef = ybo.RelationDefinition(eschema.type, 'identity', eschema.type, |
13a5d3a7410e
[schema] tweaks meta-relations and schema/workflow entities attributes permissions
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4754
diff
changeset
|
935 |
__permissions__=RO_REL_PERMS) |
0 | 936 |
self.add_relation_def(rdef) |
937 |
self._eid_index[eschema.eid] = eschema |
|
938 |
return eschema |
|
1451 | 939 |
|
0 | 940 |
def add_relation_type(self, rdef): |
6861
9d4e11d6e783
[schema] ease understanding of schema naming error
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6827
diff
changeset
|
941 |
if not rdef.name.islower(): |
9d4e11d6e783
[schema] ease understanding of schema naming error
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6827
diff
changeset
|
942 |
raise BadSchemaDefinition( |
9d4e11d6e783
[schema] ease understanding of schema naming error
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6827
diff
changeset
|
943 |
'%r is not a valid name for a relation type. It should be ' |
9d4e11d6e783
[schema] ease understanding of schema naming error
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6827
diff
changeset
|
944 |
'lower cased' % rdef.name) |
9d4e11d6e783
[schema] ease understanding of schema naming error
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6827
diff
changeset
|
945 |
rdef.name = rdef.name.encode() |
0 | 946 |
rschema = super(CubicWebSchema, self).add_relation_type(rdef) |
947 |
self._eid_index[rschema.eid] = rschema |
|
948 |
return rschema |
|
1451 | 949 |
|
0 | 950 |
def add_relation_def(self, rdef): |
951 |
"""build a part of a relation schema |
|
952 |
(i.e. add a relation between two specific entity's types) |
|
953 |
||
954 |
:type subject: str |
|
955 |
:param subject: entity's type that is subject of the relation |
|
956 |
||
957 |
:type rtype: str |
|
958 |
:param rtype: the relation's type (i.e. the name of the relation) |
|
959 |
||
960 |
:type obj: str |
|
961 |
:param obj: entity's type that is object of the relation |
|
962 |
||
963 |
:rtype: RelationSchema |
|
964 |
:param: the newly created or just completed relation schema |
|
965 |
""" |
|
966 |
rdef.name = rdef.name.lower() |
|
967 |
rdef.subject = bw_normalize_etype(rdef.subject) |
|
968 |
rdef.object = bw_normalize_etype(rdef.object) |
|
6191
ece6996e6ac8
[schema deserial] fix loading of schema when mapping an entity type to an existing one
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6109
diff
changeset
|
969 |
rdefs = super(CubicWebSchema, self).add_relation_def(rdef) |
3877
7ca53fc72a0a
reldefsecurity branch :
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3827
diff
changeset
|
970 |
if rdefs: |
1034
0356bbfb2f26
fix to pass arguments to base class
sylvain.thenault@logilab.fr
parents:
1016
diff
changeset
|
971 |
try: |
3877
7ca53fc72a0a
reldefsecurity branch :
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3827
diff
changeset
|
972 |
self._eid_index[rdef.eid] = rdefs |
1034
0356bbfb2f26
fix to pass arguments to base class
sylvain.thenault@logilab.fr
parents:
1016
diff
changeset
|
973 |
except AttributeError: |
0356bbfb2f26
fix to pass arguments to base class
sylvain.thenault@logilab.fr
parents:
1016
diff
changeset
|
974 |
pass # not a serialized schema |
4003
b9436fe77c9e
fix bad merge
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
3998
diff
changeset
|
975 |
return rdefs |
1451 | 976 |
|
0 | 977 |
def del_relation_type(self, rtype): |
978 |
rschema = self.rschema(rtype) |
|
979 |
self._eid_index.pop(rschema.eid, None) |
|
980 |
super(CubicWebSchema, self).del_relation_type(rtype) |
|
1451 | 981 |
|
0 | 982 |
def del_relation_def(self, subjtype, rtype, objtype): |
983 |
for k, v in self._eid_index.items(): |
|
3877
7ca53fc72a0a
reldefsecurity branch :
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3827
diff
changeset
|
984 |
if not isinstance(v, RelationDefinitionSchema): |
7ca53fc72a0a
reldefsecurity branch :
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3827
diff
changeset
|
985 |
continue |
7ca53fc72a0a
reldefsecurity branch :
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3827
diff
changeset
|
986 |
if v.subject == subjtype and v.rtype == rtype and v.object == objtype: |
0 | 987 |
del self._eid_index[k] |
2718
3a56b87bb5d6
[schema] break when found
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2716
diff
changeset
|
988 |
break |
0 | 989 |
super(CubicWebSchema, self).del_relation_def(subjtype, rtype, objtype) |
1451 | 990 |
|
0 | 991 |
def del_entity_type(self, etype): |
992 |
eschema = self.eschema(etype) |
|
993 |
self._eid_index.pop(eschema.eid, None) |
|
994 |
# deal with has_text first, else its automatic deletion (see above) |
|
995 |
# may trigger an error in ancestor's del_entity_type method |
|
996 |
if 'has_text' in eschema.subject_relations(): |
|
997 |
self.del_relation_def(etype, 'has_text', 'String') |
|
998 |
super(CubicWebSchema, self).del_entity_type(etype) |
|
1451 | 999 |
|
0 | 1000 |
def schema_by_eid(self, eid): |
1001 |
return self._eid_index[eid] |
|
1002 |
||
1003 |
||
7152
39c1ffc7d93f
[schema, refactoring] use RQLExpression as base class for RQL constraint classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7103
diff
changeset
|
1004 |
# additional cw specific constraints ########################################### |
39c1ffc7d93f
[schema, refactoring] use RQLExpression as base class for RQL constraint classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7103
diff
changeset
|
1005 |
|
39c1ffc7d93f
[schema, refactoring] use RQLExpression as base class for RQL constraint classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7103
diff
changeset
|
1006 |
class BaseRQLConstraint(RRQLExpression, BaseConstraint): |
39c1ffc7d93f
[schema, refactoring] use RQLExpression as base class for RQL constraint classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7103
diff
changeset
|
1007 |
"""base class for rql constraints""" |
39c1ffc7d93f
[schema, refactoring] use RQLExpression as base class for RQL constraint classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7103
diff
changeset
|
1008 |
distinct_query = None |
39c1ffc7d93f
[schema, refactoring] use RQLExpression as base class for RQL constraint classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7103
diff
changeset
|
1009 |
|
39c1ffc7d93f
[schema, refactoring] use RQLExpression as base class for RQL constraint classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7103
diff
changeset
|
1010 |
def serialize(self): |
9253
77e31ede9b04
[schema] drop very old bw compat (pre 3.5.10)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9246
diff
changeset
|
1011 |
# start with a semicolon for bw compat, see below |
7152
39c1ffc7d93f
[schema, refactoring] use RQLExpression as base class for RQL constraint classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7103
diff
changeset
|
1012 |
return ';' + ','.join(sorted(self.mainvars)) + ';' + self.expression |
39c1ffc7d93f
[schema, refactoring] use RQLExpression as base class for RQL constraint classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7103
diff
changeset
|
1013 |
|
39c1ffc7d93f
[schema, refactoring] use RQLExpression as base class for RQL constraint classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7103
diff
changeset
|
1014 |
@classmethod |
39c1ffc7d93f
[schema, refactoring] use RQLExpression as base class for RQL constraint classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7103
diff
changeset
|
1015 |
def deserialize(cls, value): |
39c1ffc7d93f
[schema, refactoring] use RQLExpression as base class for RQL constraint classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7103
diff
changeset
|
1016 |
_, mainvars, expression = value.split(';', 2) |
39c1ffc7d93f
[schema, refactoring] use RQLExpression as base class for RQL constraint classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7103
diff
changeset
|
1017 |
return cls(expression, mainvars) |
39c1ffc7d93f
[schema, refactoring] use RQLExpression as base class for RQL constraint classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7103
diff
changeset
|
1018 |
|
39c1ffc7d93f
[schema, refactoring] use RQLExpression as base class for RQL constraint classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7103
diff
changeset
|
1019 |
def check(self, entity, rtype, value): |
39c1ffc7d93f
[schema, refactoring] use RQLExpression as base class for RQL constraint classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7103
diff
changeset
|
1020 |
"""return true if the value satisfy the constraint, else false""" |
39c1ffc7d93f
[schema, refactoring] use RQLExpression as base class for RQL constraint classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7103
diff
changeset
|
1021 |
# implemented as a hook in the repository |
39c1ffc7d93f
[schema, refactoring] use RQLExpression as base class for RQL constraint classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7103
diff
changeset
|
1022 |
return 1 |
39c1ffc7d93f
[schema, refactoring] use RQLExpression as base class for RQL constraint classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7103
diff
changeset
|
1023 |
|
39c1ffc7d93f
[schema, refactoring] use RQLExpression as base class for RQL constraint classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7103
diff
changeset
|
1024 |
def __str__(self): |
39c1ffc7d93f
[schema, refactoring] use RQLExpression as base class for RQL constraint classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7103
diff
changeset
|
1025 |
if self.distinct_query: |
39c1ffc7d93f
[schema, refactoring] use RQLExpression as base class for RQL constraint classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7103
diff
changeset
|
1026 |
selop = 'Any' |
39c1ffc7d93f
[schema, refactoring] use RQLExpression as base class for RQL constraint classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7103
diff
changeset
|
1027 |
else: |
39c1ffc7d93f
[schema, refactoring] use RQLExpression as base class for RQL constraint classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7103
diff
changeset
|
1028 |
selop = 'DISTINCT Any' |
39c1ffc7d93f
[schema, refactoring] use RQLExpression as base class for RQL constraint classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7103
diff
changeset
|
1029 |
return '%s(%s %s WHERE %s)' % (self.__class__.__name__, selop, |
39c1ffc7d93f
[schema, refactoring] use RQLExpression as base class for RQL constraint classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7103
diff
changeset
|
1030 |
','.join(sorted(self.mainvars)), |
39c1ffc7d93f
[schema, refactoring] use RQLExpression as base class for RQL constraint classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7103
diff
changeset
|
1031 |
self.expression) |
39c1ffc7d93f
[schema, refactoring] use RQLExpression as base class for RQL constraint classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7103
diff
changeset
|
1032 |
|
39c1ffc7d93f
[schema, refactoring] use RQLExpression as base class for RQL constraint classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7103
diff
changeset
|
1033 |
def __repr__(self): |
39c1ffc7d93f
[schema, refactoring] use RQLExpression as base class for RQL constraint classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7103
diff
changeset
|
1034 |
return '<%s @%#x>' % (self.__str__(), id(self)) |
39c1ffc7d93f
[schema, refactoring] use RQLExpression as base class for RQL constraint classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7103
diff
changeset
|
1035 |
|
39c1ffc7d93f
[schema, refactoring] use RQLExpression as base class for RQL constraint classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7103
diff
changeset
|
1036 |
|
39c1ffc7d93f
[schema, refactoring] use RQLExpression as base class for RQL constraint classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7103
diff
changeset
|
1037 |
class RQLVocabularyConstraint(BaseRQLConstraint): |
39c1ffc7d93f
[schema, refactoring] use RQLExpression as base class for RQL constraint classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7103
diff
changeset
|
1038 |
"""the rql vocabulary constraint: |
39c1ffc7d93f
[schema, refactoring] use RQLExpression as base class for RQL constraint classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7103
diff
changeset
|
1039 |
|
39c1ffc7d93f
[schema, refactoring] use RQLExpression as base class for RQL constraint classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7103
diff
changeset
|
1040 |
limit the proposed values to a set of entities returned by a rql query, |
39c1ffc7d93f
[schema, refactoring] use RQLExpression as base class for RQL constraint classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7103
diff
changeset
|
1041 |
but this is not enforced at the repository level |
39c1ffc7d93f
[schema, refactoring] use RQLExpression as base class for RQL constraint classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7103
diff
changeset
|
1042 |
|
39c1ffc7d93f
[schema, refactoring] use RQLExpression as base class for RQL constraint classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7103
diff
changeset
|
1043 |
`expression` is additional rql restriction that will be added to |
39c1ffc7d93f
[schema, refactoring] use RQLExpression as base class for RQL constraint classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7103
diff
changeset
|
1044 |
a predefined query, where the S and O variables respectivly represent |
39c1ffc7d93f
[schema, refactoring] use RQLExpression as base class for RQL constraint classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7103
diff
changeset
|
1045 |
the subject and the object of the relation |
39c1ffc7d93f
[schema, refactoring] use RQLExpression as base class for RQL constraint classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7103
diff
changeset
|
1046 |
|
39c1ffc7d93f
[schema, refactoring] use RQLExpression as base class for RQL constraint classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7103
diff
changeset
|
1047 |
`mainvars` is a set of variables that should be used as selection variable |
39c1ffc7d93f
[schema, refactoring] use RQLExpression as base class for RQL constraint classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7103
diff
changeset
|
1048 |
(eg `'Any %s WHERE ...' % mainvars`). If not specified, an attempt will be |
39c1ffc7d93f
[schema, refactoring] use RQLExpression as base class for RQL constraint classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7103
diff
changeset
|
1049 |
done to guess it according to variable used in the expression. |
39c1ffc7d93f
[schema, refactoring] use RQLExpression as base class for RQL constraint classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7103
diff
changeset
|
1050 |
""" |
39c1ffc7d93f
[schema, refactoring] use RQLExpression as base class for RQL constraint classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7103
diff
changeset
|
1051 |
|
39c1ffc7d93f
[schema, refactoring] use RQLExpression as base class for RQL constraint classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7103
diff
changeset
|
1052 |
def repo_check(self, session, eidfrom, rtype, eidto): |
39c1ffc7d93f
[schema, refactoring] use RQLExpression as base class for RQL constraint classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7103
diff
changeset
|
1053 |
"""raise ValidationError if the relation doesn't satisfy the constraint |
39c1ffc7d93f
[schema, refactoring] use RQLExpression as base class for RQL constraint classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7103
diff
changeset
|
1054 |
""" |
7990
a673d1d9a738
[diet]Â drop pre 3.6 API compatibility (but attempt to keep data cmopatibility). Closes #2017916
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7973
diff
changeset
|
1055 |
pass # this is a vocabulary constraint, not enforced |
7152
39c1ffc7d93f
[schema, refactoring] use RQLExpression as base class for RQL constraint classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7103
diff
changeset
|
1056 |
|
39c1ffc7d93f
[schema, refactoring] use RQLExpression as base class for RQL constraint classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7103
diff
changeset
|
1057 |
|
39c1ffc7d93f
[schema, refactoring] use RQLExpression as base class for RQL constraint classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7103
diff
changeset
|
1058 |
class RepoEnforcedRQLConstraintMixIn(object): |
39c1ffc7d93f
[schema, refactoring] use RQLExpression as base class for RQL constraint classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7103
diff
changeset
|
1059 |
|
39c1ffc7d93f
[schema, refactoring] use RQLExpression as base class for RQL constraint classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7103
diff
changeset
|
1060 |
def __init__(self, expression, mainvars=None, msg=None): |
39c1ffc7d93f
[schema, refactoring] use RQLExpression as base class for RQL constraint classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7103
diff
changeset
|
1061 |
super(RepoEnforcedRQLConstraintMixIn, self).__init__(expression, mainvars) |
39c1ffc7d93f
[schema, refactoring] use RQLExpression as base class for RQL constraint classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7103
diff
changeset
|
1062 |
self.msg = msg |
39c1ffc7d93f
[schema, refactoring] use RQLExpression as base class for RQL constraint classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7103
diff
changeset
|
1063 |
|
39c1ffc7d93f
[schema, refactoring] use RQLExpression as base class for RQL constraint classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7103
diff
changeset
|
1064 |
def serialize(self): |
39c1ffc7d93f
[schema, refactoring] use RQLExpression as base class for RQL constraint classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7103
diff
changeset
|
1065 |
# start with a semicolon for bw compat, see below |
39c1ffc7d93f
[schema, refactoring] use RQLExpression as base class for RQL constraint classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7103
diff
changeset
|
1066 |
return ';%s;%s\n%s' % (','.join(sorted(self.mainvars)), self.expression, |
39c1ffc7d93f
[schema, refactoring] use RQLExpression as base class for RQL constraint classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7103
diff
changeset
|
1067 |
self.msg or '') |
39c1ffc7d93f
[schema, refactoring] use RQLExpression as base class for RQL constraint classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7103
diff
changeset
|
1068 |
|
39c1ffc7d93f
[schema, refactoring] use RQLExpression as base class for RQL constraint classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7103
diff
changeset
|
1069 |
def deserialize(cls, value): |
39c1ffc7d93f
[schema, refactoring] use RQLExpression as base class for RQL constraint classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7103
diff
changeset
|
1070 |
value, msg = value.split('\n', 1) |
39c1ffc7d93f
[schema, refactoring] use RQLExpression as base class for RQL constraint classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7103
diff
changeset
|
1071 |
_, mainvars, expression = value.split(';', 2) |
39c1ffc7d93f
[schema, refactoring] use RQLExpression as base class for RQL constraint classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7103
diff
changeset
|
1072 |
return cls(expression, mainvars, msg) |
39c1ffc7d93f
[schema, refactoring] use RQLExpression as base class for RQL constraint classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7103
diff
changeset
|
1073 |
deserialize = classmethod(deserialize) |
39c1ffc7d93f
[schema, refactoring] use RQLExpression as base class for RQL constraint classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7103
diff
changeset
|
1074 |
|
39c1ffc7d93f
[schema, refactoring] use RQLExpression as base class for RQL constraint classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7103
diff
changeset
|
1075 |
def repo_check(self, session, eidfrom, rtype, eidto=None): |
39c1ffc7d93f
[schema, refactoring] use RQLExpression as base class for RQL constraint classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7103
diff
changeset
|
1076 |
"""raise ValidationError if the relation doesn't satisfy the constraint |
39c1ffc7d93f
[schema, refactoring] use RQLExpression as base class for RQL constraint classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7103
diff
changeset
|
1077 |
""" |
39c1ffc7d93f
[schema, refactoring] use RQLExpression as base class for RQL constraint classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7103
diff
changeset
|
1078 |
if not self.match_condition(session, eidfrom, eidto): |
39c1ffc7d93f
[schema, refactoring] use RQLExpression as base class for RQL constraint classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7103
diff
changeset
|
1079 |
# XXX at this point if both or neither of S and O are in mainvar we |
39c1ffc7d93f
[schema, refactoring] use RQLExpression as base class for RQL constraint classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7103
diff
changeset
|
1080 |
# dunno if the validation error `occurred` on eidfrom or eidto (from |
39c1ffc7d93f
[schema, refactoring] use RQLExpression as base class for RQL constraint classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7103
diff
changeset
|
1081 |
# user interface point of view) |
39c1ffc7d93f
[schema, refactoring] use RQLExpression as base class for RQL constraint classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7103
diff
changeset
|
1082 |
# |
39c1ffc7d93f
[schema, refactoring] use RQLExpression as base class for RQL constraint classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7103
diff
changeset
|
1083 |
# possible enhancement: check entity being created, it's probably |
39c1ffc7d93f
[schema, refactoring] use RQLExpression as base class for RQL constraint classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7103
diff
changeset
|
1084 |
# the main eid unless this is a composite relation |
39c1ffc7d93f
[schema, refactoring] use RQLExpression as base class for RQL constraint classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7103
diff
changeset
|
1085 |
if eidto is None or 'S' in self.mainvars or not 'O' in self.mainvars: |
39c1ffc7d93f
[schema, refactoring] use RQLExpression as base class for RQL constraint classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7103
diff
changeset
|
1086 |
maineid = eidfrom |
39c1ffc7d93f
[schema, refactoring] use RQLExpression as base class for RQL constraint classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7103
diff
changeset
|
1087 |
qname = role_name(rtype, 'subject') |
39c1ffc7d93f
[schema, refactoring] use RQLExpression as base class for RQL constraint classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7103
diff
changeset
|
1088 |
else: |
39c1ffc7d93f
[schema, refactoring] use RQLExpression as base class for RQL constraint classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7103
diff
changeset
|
1089 |
maineid = eidto |
39c1ffc7d93f
[schema, refactoring] use RQLExpression as base class for RQL constraint classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7103
diff
changeset
|
1090 |
qname = role_name(rtype, 'object') |
39c1ffc7d93f
[schema, refactoring] use RQLExpression as base class for RQL constraint classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7103
diff
changeset
|
1091 |
if self.msg: |
39c1ffc7d93f
[schema, refactoring] use RQLExpression as base class for RQL constraint classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7103
diff
changeset
|
1092 |
msg = session._(self.msg) |
39c1ffc7d93f
[schema, refactoring] use RQLExpression as base class for RQL constraint classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7103
diff
changeset
|
1093 |
else: |
39c1ffc7d93f
[schema, refactoring] use RQLExpression as base class for RQL constraint classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7103
diff
changeset
|
1094 |
msg = '%(constraint)s %(expression)s failed' % { |
39c1ffc7d93f
[schema, refactoring] use RQLExpression as base class for RQL constraint classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7103
diff
changeset
|
1095 |
'constraint': session._(self.type()), |
39c1ffc7d93f
[schema, refactoring] use RQLExpression as base class for RQL constraint classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7103
diff
changeset
|
1096 |
'expression': self.expression} |
39c1ffc7d93f
[schema, refactoring] use RQLExpression as base class for RQL constraint classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7103
diff
changeset
|
1097 |
raise ValidationError(maineid, {qname: msg}) |
39c1ffc7d93f
[schema, refactoring] use RQLExpression as base class for RQL constraint classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7103
diff
changeset
|
1098 |
|
8540
fee98af8bb33
[schema] rename schema permissions function: session may also be a request, use _cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8258
diff
changeset
|
1099 |
def exec_query(self, _cw, eidfrom, eidto): |
7152
39c1ffc7d93f
[schema, refactoring] use RQLExpression as base class for RQL constraint classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7103
diff
changeset
|
1100 |
if eidto is None: |
39c1ffc7d93f
[schema, refactoring] use RQLExpression as base class for RQL constraint classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7103
diff
changeset
|
1101 |
# checking constraint for an attribute relation |
39c1ffc7d93f
[schema, refactoring] use RQLExpression as base class for RQL constraint classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7103
diff
changeset
|
1102 |
expression = 'S eid %(s)s, ' + self.expression |
39c1ffc7d93f
[schema, refactoring] use RQLExpression as base class for RQL constraint classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7103
diff
changeset
|
1103 |
args = {'s': eidfrom} |
39c1ffc7d93f
[schema, refactoring] use RQLExpression as base class for RQL constraint classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7103
diff
changeset
|
1104 |
else: |
39c1ffc7d93f
[schema, refactoring] use RQLExpression as base class for RQL constraint classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7103
diff
changeset
|
1105 |
expression = 'S eid %(s)s, O eid %(o)s, ' + self.expression |
39c1ffc7d93f
[schema, refactoring] use RQLExpression as base class for RQL constraint classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7103
diff
changeset
|
1106 |
args = {'s': eidfrom, 'o': eidto} |
7640
85ebdbbcb321
[schema] closes #1816439: RQLConstraint does not take variable U into account
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7603
diff
changeset
|
1107 |
if 'U' in self.rqlst.defined_vars: |
85ebdbbcb321
[schema] closes #1816439: RQLConstraint does not take variable U into account
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7603
diff
changeset
|
1108 |
expression = 'U eid %(u)s, ' + expression |
8540
fee98af8bb33
[schema] rename schema permissions function: session may also be a request, use _cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8258
diff
changeset
|
1109 |
args['u'] = _cw.user.eid |
7152
39c1ffc7d93f
[schema, refactoring] use RQLExpression as base class for RQL constraint classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7103
diff
changeset
|
1110 |
rql = 'Any %s WHERE %s' % (','.join(sorted(self.mainvars)), expression) |
39c1ffc7d93f
[schema, refactoring] use RQLExpression as base class for RQL constraint classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7103
diff
changeset
|
1111 |
if self.distinct_query: |
39c1ffc7d93f
[schema, refactoring] use RQLExpression as base class for RQL constraint classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7103
diff
changeset
|
1112 |
rql = 'DISTINCT ' + rql |
8540
fee98af8bb33
[schema] rename schema permissions function: session may also be a request, use _cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8258
diff
changeset
|
1113 |
return _cw.execute(rql, args, build_descr=False) |
7152
39c1ffc7d93f
[schema, refactoring] use RQLExpression as base class for RQL constraint classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7103
diff
changeset
|
1114 |
|
39c1ffc7d93f
[schema, refactoring] use RQLExpression as base class for RQL constraint classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7103
diff
changeset
|
1115 |
|
39c1ffc7d93f
[schema, refactoring] use RQLExpression as base class for RQL constraint classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7103
diff
changeset
|
1116 |
class RQLConstraint(RepoEnforcedRQLConstraintMixIn, RQLVocabularyConstraint): |
39c1ffc7d93f
[schema, refactoring] use RQLExpression as base class for RQL constraint classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7103
diff
changeset
|
1117 |
"""the rql constraint is similar to the RQLVocabularyConstraint but |
39c1ffc7d93f
[schema, refactoring] use RQLExpression as base class for RQL constraint classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7103
diff
changeset
|
1118 |
are also enforced at the repository level |
39c1ffc7d93f
[schema, refactoring] use RQLExpression as base class for RQL constraint classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7103
diff
changeset
|
1119 |
""" |
39c1ffc7d93f
[schema, refactoring] use RQLExpression as base class for RQL constraint classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7103
diff
changeset
|
1120 |
distinct_query = False |
39c1ffc7d93f
[schema, refactoring] use RQLExpression as base class for RQL constraint classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7103
diff
changeset
|
1121 |
|
39c1ffc7d93f
[schema, refactoring] use RQLExpression as base class for RQL constraint classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7103
diff
changeset
|
1122 |
def match_condition(self, session, eidfrom, eidto): |
39c1ffc7d93f
[schema, refactoring] use RQLExpression as base class for RQL constraint classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7103
diff
changeset
|
1123 |
return self.exec_query(session, eidfrom, eidto) |
39c1ffc7d93f
[schema, refactoring] use RQLExpression as base class for RQL constraint classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7103
diff
changeset
|
1124 |
|
39c1ffc7d93f
[schema, refactoring] use RQLExpression as base class for RQL constraint classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7103
diff
changeset
|
1125 |
|
39c1ffc7d93f
[schema, refactoring] use RQLExpression as base class for RQL constraint classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7103
diff
changeset
|
1126 |
class RQLUniqueConstraint(RepoEnforcedRQLConstraintMixIn, BaseRQLConstraint): |
39c1ffc7d93f
[schema, refactoring] use RQLExpression as base class for RQL constraint classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7103
diff
changeset
|
1127 |
"""the unique rql constraint check that the result of the query isn't |
39c1ffc7d93f
[schema, refactoring] use RQLExpression as base class for RQL constraint classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7103
diff
changeset
|
1128 |
greater than one. |
39c1ffc7d93f
[schema, refactoring] use RQLExpression as base class for RQL constraint classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7103
diff
changeset
|
1129 |
|
39c1ffc7d93f
[schema, refactoring] use RQLExpression as base class for RQL constraint classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7103
diff
changeset
|
1130 |
You *must* specify `mainvars` when instantiating the constraint since there |
39c1ffc7d93f
[schema, refactoring] use RQLExpression as base class for RQL constraint classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7103
diff
changeset
|
1131 |
is no way to guess it correctly (e.g. if using S,O or U the constraint will |
39c1ffc7d93f
[schema, refactoring] use RQLExpression as base class for RQL constraint classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7103
diff
changeset
|
1132 |
always be satisfied because we've to use a DISTINCT query). |
39c1ffc7d93f
[schema, refactoring] use RQLExpression as base class for RQL constraint classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7103
diff
changeset
|
1133 |
""" |
39c1ffc7d93f
[schema, refactoring] use RQLExpression as base class for RQL constraint classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7103
diff
changeset
|
1134 |
# XXX turns mainvars into a required argument in __init__ |
39c1ffc7d93f
[schema, refactoring] use RQLExpression as base class for RQL constraint classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7103
diff
changeset
|
1135 |
distinct_query = True |
9227
762a331db741
[schema]Â fix spurious warning when rqlexpr/constraint mainvars specify a non predefined variable. Closes #3098165
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9173
diff
changeset
|
1136 |
|
7152
39c1ffc7d93f
[schema, refactoring] use RQLExpression as base class for RQL constraint classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7103
diff
changeset
|
1137 |
def match_condition(self, session, eidfrom, eidto): |
39c1ffc7d93f
[schema, refactoring] use RQLExpression as base class for RQL constraint classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7103
diff
changeset
|
1138 |
return len(self.exec_query(session, eidfrom, eidto)) <= 1 |
39c1ffc7d93f
[schema, refactoring] use RQLExpression as base class for RQL constraint classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7103
diff
changeset
|
1139 |
|
39c1ffc7d93f
[schema, refactoring] use RQLExpression as base class for RQL constraint classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7103
diff
changeset
|
1140 |
|
629
59b6542f5729
provide a new WorkflowableEntityType base class (will be refactored later, maybe with schema interfaces)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
628
diff
changeset
|
1141 |
# workflow extensions ######################################################### |
2926
4484387ed012
when adding/removing cubes, we should add/remove entity types in correct order if one inherits from another
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2782
diff
changeset
|
1142 |
|
2460
ce1a7ffc6c90
fix a couple NameErrors
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
2459
diff
changeset
|
1143 |
from yams.buildobjs import _add_relation as yams_add_relation |
629
59b6542f5729
provide a new WorkflowableEntityType base class (will be refactored later, maybe with schema interfaces)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
628
diff
changeset
|
1144 |
|
59b6542f5729
provide a new WorkflowableEntityType base class (will be refactored later, maybe with schema interfaces)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
628
diff
changeset
|
1145 |
class workflowable_definition(ybo.metadefinition): |
59b6542f5729
provide a new WorkflowableEntityType base class (will be refactored later, maybe with schema interfaces)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
628
diff
changeset
|
1146 |
"""extends default EntityType's metaclass to add workflow relations |
5378
0f54a0e128ac
[schema] cleanup
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5372
diff
changeset
|
1147 |
(i.e. in_state, wf_info_for and custom_workflow). This is the default |
0f54a0e128ac
[schema] cleanup
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5372
diff
changeset
|
1148 |
metaclass for WorkflowableEntityType. |
629
59b6542f5729
provide a new WorkflowableEntityType base class (will be refactored later, maybe with schema interfaces)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
628
diff
changeset
|
1149 |
""" |
59b6542f5729
provide a new WorkflowableEntityType base class (will be refactored later, maybe with schema interfaces)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
628
diff
changeset
|
1150 |
def __new__(mcs, name, bases, classdict): |
2920
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2782
diff
changeset
|
1151 |
abstract = classdict.pop('__abstract__', False) |
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2782
diff
changeset
|
1152 |
cls = super(workflowable_definition, mcs).__new__(mcs, name, bases, |
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2782
diff
changeset
|
1153 |
classdict) |
629
59b6542f5729
provide a new WorkflowableEntityType base class (will be refactored later, maybe with schema interfaces)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
628
diff
changeset
|
1154 |
if not abstract: |
2920
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2782
diff
changeset
|
1155 |
make_workflowable(cls) |
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2782
diff
changeset
|
1156 |
return cls |
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2782
diff
changeset
|
1157 |
|
5379
c082dea0731b
[schema] update for yams 0.29: BoundConstraint renamed to BoundaryConstraint; new constraint messages; ObjectRelation deprecated
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5378
diff
changeset
|
1158 |
class WorkflowableEntityType(ybo.EntityType): |
c082dea0731b
[schema] update for yams 0.29: BoundConstraint renamed to BoundaryConstraint; new constraint messages; ObjectRelation deprecated
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5378
diff
changeset
|
1159 |
"""Use this base class instead of :class:`EntityType` to have workflow |
c082dea0731b
[schema] update for yams 0.29: BoundConstraint renamed to BoundaryConstraint; new constraint messages; ObjectRelation deprecated
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5378
diff
changeset
|
1160 |
relations (i.e. `in_state`, `wf_info_for` and `custom_workflow`) on your |
c082dea0731b
[schema] update for yams 0.29: BoundConstraint renamed to BoundaryConstraint; new constraint messages; ObjectRelation deprecated
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5378
diff
changeset
|
1161 |
entity type. |
c082dea0731b
[schema] update for yams 0.29: BoundConstraint renamed to BoundaryConstraint; new constraint messages; ObjectRelation deprecated
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5378
diff
changeset
|
1162 |
""" |
c082dea0731b
[schema] update for yams 0.29: BoundConstraint renamed to BoundaryConstraint; new constraint messages; ObjectRelation deprecated
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5378
diff
changeset
|
1163 |
__metaclass__ = workflowable_definition |
c082dea0731b
[schema] update for yams 0.29: BoundConstraint renamed to BoundaryConstraint; new constraint messages; ObjectRelation deprecated
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5378
diff
changeset
|
1164 |
__abstract__ = True |
c082dea0731b
[schema] update for yams 0.29: BoundConstraint renamed to BoundaryConstraint; new constraint messages; ObjectRelation deprecated
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5378
diff
changeset
|
1165 |
|
c082dea0731b
[schema] update for yams 0.29: BoundConstraint renamed to BoundaryConstraint; new constraint messages; ObjectRelation deprecated
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5378
diff
changeset
|
1166 |
|
2957
2daabf4c646e
[schema] make_workflowable now take an option description for the in_state relation
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2931
diff
changeset
|
1167 |
def make_workflowable(cls, in_state_descr=None): |
5378
0f54a0e128ac
[schema] cleanup
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5372
diff
changeset
|
1168 |
"""Adds workflow relations as :class:`WorkflowableEntityType`, but usable on |
0f54a0e128ac
[schema] cleanup
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5372
diff
changeset
|
1169 |
existing classes which are not using that base class. |
0f54a0e128ac
[schema] cleanup
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5372
diff
changeset
|
1170 |
""" |
2920
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2782
diff
changeset
|
1171 |
existing_rels = set(rdef.name for rdef in cls.__relations__) |
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2782
diff
changeset
|
1172 |
# let relation types defined in cw.schemas.workflow carrying |
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2782
diff
changeset
|
1173 |
# cardinality, constraints and other relation definition properties |
5379
c082dea0731b
[schema] update for yams 0.29: BoundConstraint renamed to BoundaryConstraint; new constraint messages; ObjectRelation deprecated
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5378
diff
changeset
|
1174 |
etype = getattr(cls, 'name', cls.__name__) |
2920
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2782
diff
changeset
|
1175 |
if 'custom_workflow' not in existing_rels: |
5379
c082dea0731b
[schema] update for yams 0.29: BoundConstraint renamed to BoundaryConstraint; new constraint messages; ObjectRelation deprecated
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5378
diff
changeset
|
1176 |
rdef = ybo.RelationDefinition(etype, 'custom_workflow', 'Workflow') |
c082dea0731b
[schema] update for yams 0.29: BoundConstraint renamed to BoundaryConstraint; new constraint messages; ObjectRelation deprecated
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5378
diff
changeset
|
1177 |
yams_add_relation(cls.__relations__, rdef) |
2920
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2782
diff
changeset
|
1178 |
if 'in_state' not in existing_rels: |
5379
c082dea0731b
[schema] update for yams 0.29: BoundConstraint renamed to BoundaryConstraint; new constraint messages; ObjectRelation deprecated
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5378
diff
changeset
|
1179 |
rdef = ybo.RelationDefinition(etype, 'in_state', 'State', |
c082dea0731b
[schema] update for yams 0.29: BoundConstraint renamed to BoundaryConstraint; new constraint messages; ObjectRelation deprecated
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5378
diff
changeset
|
1180 |
description=in_state_descr) |
c082dea0731b
[schema] update for yams 0.29: BoundConstraint renamed to BoundaryConstraint; new constraint messages; ObjectRelation deprecated
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5378
diff
changeset
|
1181 |
yams_add_relation(cls.__relations__, rdef) |
2920
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2782
diff
changeset
|
1182 |
if 'wf_info_for' not in existing_rels: |
5379
c082dea0731b
[schema] update for yams 0.29: BoundConstraint renamed to BoundaryConstraint; new constraint messages; ObjectRelation deprecated
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5378
diff
changeset
|
1183 |
rdef = ybo.RelationDefinition('TrInfo', 'wf_info_for', etype) |
c082dea0731b
[schema] update for yams 0.29: BoundConstraint renamed to BoundaryConstraint; new constraint messages; ObjectRelation deprecated
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5378
diff
changeset
|
1184 |
yams_add_relation(cls.__relations__, rdef) |
1451 | 1185 |
|
629
59b6542f5729
provide a new WorkflowableEntityType base class (will be refactored later, maybe with schema interfaces)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
628
diff
changeset
|
1186 |
|
0 | 1187 |
# schema loading ############################################################## |
1188 |
||
1189 |
CONSTRAINTS['RQLConstraint'] = RQLConstraint |
|
1190 |
CONSTRAINTS['RQLUniqueConstraint'] = RQLUniqueConstraint |
|
1191 |
CONSTRAINTS['RQLVocabularyConstraint'] = RQLVocabularyConstraint |
|
3980
b17cf4a2e09e
this constraint is actually unusable in yams schema for cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3979
diff
changeset
|
1192 |
CONSTRAINTS.pop('MultipleStaticVocabularyConstraint', None) # don't want this in cw yams schema |
0 | 1193 |
PyFileReader.context.update(CONSTRAINTS) |
1194 |
||
1195 |
||
1196 |
class BootstrapSchemaLoader(SchemaLoader): |
|
1197 |
"""cubicweb specific schema loader, loading only schema necessary to read |
|
1198 |
the persistent schema |
|
1199 |
""" |
|
1200 |
schemacls = CubicWebSchema |
|
1201 |
||
1034
0356bbfb2f26
fix to pass arguments to base class
sylvain.thenault@logilab.fr
parents:
1016
diff
changeset
|
1202 |
def load(self, config, path=(), **kwargs): |
0 | 1203 |
"""return a Schema instance from the schema definition read |
1204 |
from <directory> |
|
1205 |
""" |
|
1206 |
return super(BootstrapSchemaLoader, self).load( |
|
1034
0356bbfb2f26
fix to pass arguments to base class
sylvain.thenault@logilab.fr
parents:
1016
diff
changeset
|
1207 |
path, config.appid, register_base_types=False, **kwargs) |
1451 | 1208 |
|
0 | 1209 |
def _load_definition_files(self, cubes=None): |
1210 |
# bootstraping, ignore cubes |
|
2735
39c942241b48
no need for lib_directory
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2730
diff
changeset
|
1211 |
filepath = join(cubicweb.CW_SOFTWARE_ROOT, 'schemas', 'bootstrap.py') |
2142
098aa2075903
include_schema_files is useless
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
1212 |
self.info('loading %s', filepath) |
9366
bcbc92223b35
set proper PACKAGE information for yams 0.39
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9283
diff
changeset
|
1213 |
with tempattr(ybo, 'PACKAGE', 'cubicweb'): # though we don't care here |
bcbc92223b35
set proper PACKAGE information for yams 0.39
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9283
diff
changeset
|
1214 |
self.handle_file(filepath) |
1451 | 1215 |
|
0 | 1216 |
def unhandled_file(self, filepath): |
1217 |
"""called when a file without handler associated has been found""" |
|
1218 |
self.warning('ignoring file %r', filepath) |
|
1219 |
||
7083
b8e35cde46e9
help pylint by explicitely defining some attributes
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
6861
diff
changeset
|
1220 |
# these are overridden by set_log_methods below |
b8e35cde46e9
help pylint by explicitely defining some attributes
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
6861
diff
changeset
|
1221 |
# only defining here to prevent pylint from complaining |
b8e35cde46e9
help pylint by explicitely defining some attributes
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
6861
diff
changeset
|
1222 |
info = warning = error = critical = exception = debug = lambda msg,*a,**kw: None |
0 | 1223 |
|
1224 |
class CubicWebSchemaLoader(BootstrapSchemaLoader): |
|
1225 |
"""cubicweb specific schema loader, automatically adding metadata to the |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2460
diff
changeset
|
1226 |
instance's schema |
0 | 1227 |
""" |
1228 |
||
1034
0356bbfb2f26
fix to pass arguments to base class
sylvain.thenault@logilab.fr
parents:
1016
diff
changeset
|
1229 |
def load(self, config, **kwargs): |
0 | 1230 |
"""return a Schema instance from the schema definition read |
1231 |
from <directory> |
|
1232 |
""" |
|
1233 |
self.info('loading %s schemas', ', '.join(config.cubes())) |
|
2782
998f24dabd0d
compute extrapath, necessary for proper schema module detection when CW_CUBES_PATH is set
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2742
diff
changeset
|
1234 |
self.extrapath = {} |
998f24dabd0d
compute extrapath, necessary for proper schema module detection when CW_CUBES_PATH is set
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2742
diff
changeset
|
1235 |
for cubesdir in config.cubes_search_path(): |
998f24dabd0d
compute extrapath, necessary for proper schema module detection when CW_CUBES_PATH is set
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2742
diff
changeset
|
1236 |
if cubesdir != config.CUBES_DIR: |
998f24dabd0d
compute extrapath, necessary for proper schema module detection when CW_CUBES_PATH is set
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2742
diff
changeset
|
1237 |
self.extrapath[cubesdir] = 'cubes' |
372
a8a975a88368
check apphome is not None
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
0
diff
changeset
|
1238 |
if config.apphome: |
2598
a66fe74bd9fc
[R schema] dont give an iterator, it's a trap
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2596
diff
changeset
|
1239 |
path = tuple(reversed([config.apphome] + config.cubes_path())) |
372
a8a975a88368
check apphome is not None
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
0
diff
changeset
|
1240 |
else: |
2598
a66fe74bd9fc
[R schema] dont give an iterator, it's a trap
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2596
diff
changeset
|
1241 |
path = tuple(reversed(config.cubes_path())) |
2526
40e41eb34a7d
we've to call cleanup_sys_modules manually for proper schema modules cleanup
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2476
diff
changeset
|
1242 |
try: |
40e41eb34a7d
we've to call cleanup_sys_modules manually for proper schema modules cleanup
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2476
diff
changeset
|
1243 |
return super(CubicWebSchemaLoader, self).load(config, path=path, **kwargs) |
40e41eb34a7d
we've to call cleanup_sys_modules manually for proper schema modules cleanup
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2476
diff
changeset
|
1244 |
finally: |
40e41eb34a7d
we've to call cleanup_sys_modules manually for proper schema modules cleanup
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2476
diff
changeset
|
1245 |
# we've to cleanup modules imported from cubicweb.schemas as well |
2735
39c942241b48
no need for lib_directory
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2730
diff
changeset
|
1246 |
cleanup_sys_modules([join(cubicweb.CW_SOFTWARE_ROOT, 'schemas')]) |
0 | 1247 |
|
1248 |
def _load_definition_files(self, cubes): |
|
2741
148d0cea1fb5
[schema] oops
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2736
diff
changeset
|
1249 |
for filepath in (join(cubicweb.CW_SOFTWARE_ROOT, 'schemas', 'bootstrap.py'), |
148d0cea1fb5
[schema] oops
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2736
diff
changeset
|
1250 |
join(cubicweb.CW_SOFTWARE_ROOT, 'schemas', 'base.py'), |
148d0cea1fb5
[schema] oops
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2736
diff
changeset
|
1251 |
join(cubicweb.CW_SOFTWARE_ROOT, 'schemas', 'workflow.py'), |
148d0cea1fb5
[schema] oops
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2736
diff
changeset
|
1252 |
join(cubicweb.CW_SOFTWARE_ROOT, 'schemas', 'Bookmark.py')): |
0 | 1253 |
self.info('loading %s', filepath) |
9366
bcbc92223b35
set proper PACKAGE information for yams 0.39
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9283
diff
changeset
|
1254 |
with tempattr(ybo, 'PACKAGE', 'cubicweb'): |
bcbc92223b35
set proper PACKAGE information for yams 0.39
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9283
diff
changeset
|
1255 |
self.handle_file(filepath) |
0 | 1256 |
for cube in cubes: |
1257 |
for filepath in self.get_schema_files(cube): |
|
9366
bcbc92223b35
set proper PACKAGE information for yams 0.39
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9283
diff
changeset
|
1258 |
with tempattr(ybo, 'PACKAGE', basename(cube)): |
bcbc92223b35
set proper PACKAGE information for yams 0.39
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9283
diff
changeset
|
1259 |
self.handle_file(filepath) |
0 | 1260 |
|
7083
b8e35cde46e9
help pylint by explicitely defining some attributes
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
6861
diff
changeset
|
1261 |
# these are overridden by set_log_methods below |
b8e35cde46e9
help pylint by explicitely defining some attributes
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
6861
diff
changeset
|
1262 |
# only defining here to prevent pylint from complaining |
b8e35cde46e9
help pylint by explicitely defining some attributes
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
6861
diff
changeset
|
1263 |
info = warning = error = critical = exception = debug = lambda msg,*a,**kw: None |
0 | 1264 |
|
2459
d088d0ff48a1
move RichString and co to yams, keeping only a small monkeypatch for cw-page-template here
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2456
diff
changeset
|
1265 |
set_log_methods(CubicWebSchemaLoader, getLogger('cubicweb.schemaloader')) |
d088d0ff48a1
move RichString and co to yams, keeping only a small monkeypatch for cw-page-template here
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2456
diff
changeset
|
1266 |
set_log_methods(BootstrapSchemaLoader, getLogger('cubicweb.bootstrapschemaloader')) |
d088d0ff48a1
move RichString and co to yams, keeping only a small monkeypatch for cw-page-template here
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2456
diff
changeset
|
1267 |
set_log_methods(RQLExpression, getLogger('cubicweb.schema')) |
d088d0ff48a1
move RichString and co to yams, keeping only a small monkeypatch for cw-page-template here
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2456
diff
changeset
|
1268 |
|
0 | 1269 |
# _() is just there to add messages to the catalog, don't care about actual |
1270 |
# translation |
|
7797
a71618a75b53
backport stable
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7782
diff
changeset
|
1271 |
MAY_USE_TEMPLATE_FORMAT = set(('managers',)) |
2459
d088d0ff48a1
move RichString and co to yams, keeping only a small monkeypatch for cw-page-template here
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2456
diff
changeset
|
1272 |
NEED_PERM_FORMATS = [_('text/cubicweb-page-template')] |
0 | 1273 |
|
2531
531ea4e7013e
[cleanup] nicer imports
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
2526
diff
changeset
|
1274 |
@monkeypatch(FormatConstraint) |
3347
428f95118556
fix vocab param to avoid deprecation warning
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3287
diff
changeset
|
1275 |
def vocabulary(self, entity=None, form=None): |
3401
f893f4f199fc
use ._cw instead of req on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3369
diff
changeset
|
1276 |
cw = None |
3347
428f95118556
fix vocab param to avoid deprecation warning
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3287
diff
changeset
|
1277 |
if form is None and entity is not None: |
3401
f893f4f199fc
use ._cw instead of req on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3369
diff
changeset
|
1278 |
cw = entity._cw |
3347
428f95118556
fix vocab param to avoid deprecation warning
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3287
diff
changeset
|
1279 |
elif form is not None: |
3401
f893f4f199fc
use ._cw instead of req on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3369
diff
changeset
|
1280 |
cw = form._cw |
4757
5d937aeaa6fb
do not check for use template permission when session is super session or integrity hooks are deactivated
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4755
diff
changeset
|
1281 |
if cw is not None: |
4835
13b0b96d7982
[repo] enhanced security handling: deprecates unsafe_execute, in favor of explicit read/write security control using the `enabled_security` context manager. Also code executed on the repository side is now unsafe by default.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4834
diff
changeset
|
1282 |
if hasattr(cw, 'write_security'): # test it's a session and not a request |
4757
5d937aeaa6fb
do not check for use template permission when session is super session or integrity hooks are deactivated
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4755
diff
changeset
|
1283 |
# cw is a server session |
4835
13b0b96d7982
[repo] enhanced security handling: deprecates unsafe_execute, in favor of explicit read/write security control using the `enabled_security` context manager. Also code executed on the repository side is now unsafe by default.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4834
diff
changeset
|
1284 |
hasperm = not cw.write_security or \ |
4843
5f7363416765
fix hooks control method name + other litle cleanups
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4835
diff
changeset
|
1285 |
not cw.is_hook_category_activated('integrity') or \ |
7797
a71618a75b53
backport stable
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7782
diff
changeset
|
1286 |
cw.user.matching_groups(MAY_USE_TEMPLATE_FORMAT) |
4757
5d937aeaa6fb
do not check for use template permission when session is super session or integrity hooks are deactivated
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4755
diff
changeset
|
1287 |
else: |
7797
a71618a75b53
backport stable
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7782
diff
changeset
|
1288 |
hasperm = cw.user.matching_groups(MAY_USE_TEMPLATE_FORMAT) |
4757
5d937aeaa6fb
do not check for use template permission when session is super session or integrity hooks are deactivated
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4755
diff
changeset
|
1289 |
if hasperm: |
5d937aeaa6fb
do not check for use template permission when session is super session or integrity hooks are deactivated
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4755
diff
changeset
|
1290 |
return self.regular_formats + tuple(NEED_PERM_FORMATS) |
2459
d088d0ff48a1
move RichString and co to yams, keeping only a small monkeypatch for cw-page-template here
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2456
diff
changeset
|
1291 |
return self.regular_formats |
0 | 1292 |
|
1293 |
# XXX monkey patch PyFileReader.import_erschema until bw_normalize_etype is |
|
1294 |
# necessary |
|
1295 |
orig_import_erschema = PyFileReader.import_erschema |
|
1296 |
def bw_import_erschema(self, ertype, schemamod=None, instantiate=True): |
|
1297 |
return orig_import_erschema(self, bw_normalize_etype(ertype), schemamod, instantiate) |
|
1298 |
PyFileReader.import_erschema = bw_import_erschema |
|
1451 | 1299 |
|
0 | 1300 |
# XXX itou for some Statement methods |
1301 |
from rql import stmts |
|
1302 |
orig_get_etype = stmts.ScopeNode.get_etype |
|
1303 |
def bw_get_etype(self, name): |
|
1304 |
return orig_get_etype(self, bw_normalize_etype(name)) |
|
1305 |
stmts.ScopeNode.get_etype = bw_get_etype |
|
1306 |
||
1307 |
orig_add_main_variable_delete = stmts.Delete.add_main_variable |
|
1308 |
def bw_add_main_variable_delete(self, etype, vref): |
|
1309 |
return orig_add_main_variable_delete(self, bw_normalize_etype(etype), vref) |
|
1310 |
stmts.Delete.add_main_variable = bw_add_main_variable_delete |
|
1311 |
||
1312 |
orig_add_main_variable_insert = stmts.Insert.add_main_variable |
|
1313 |
def bw_add_main_variable_insert(self, etype, vref): |
|
1314 |
return orig_add_main_variable_insert(self, bw_normalize_etype(etype), vref) |
|
1315 |
stmts.Insert.add_main_variable = bw_add_main_variable_insert |
|
1316 |
||
1317 |
orig_set_statement_type = stmts.Select.set_statement_type |
|
1318 |
def bw_set_statement_type(self, etype): |
|
1319 |
return orig_set_statement_type(self, bw_normalize_etype(etype)) |
|
1320 |
stmts.Select.set_statement_type = bw_set_statement_type |
|
2736
c5048502409f
restore backward compat, still imported a lot
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2735
diff
changeset
|
1321 |
|
c5048502409f
restore backward compat, still imported a lot
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2735
diff
changeset
|
1322 |
# XXX deprecated |
3978
2c95e3033f64
finish yesterday work on rql constraints:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3968
diff
changeset
|
1323 |
|
4717
535705688f4f
proper deprecation warning when import class that should be imported from yams
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4702
diff
changeset
|
1324 |
from yams.constraints import StaticVocabularyConstraint |
535705688f4f
proper deprecation warning when import class that should be imported from yams
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4702
diff
changeset
|
1325 |
|
8125
7070250bf50d
[schema] React to yams improvement of metadata attribute handling.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8027
diff
changeset
|
1326 |
RichString = moved('yams.buildobjs', 'RichString') |
4717
535705688f4f
proper deprecation warning when import class that should be imported from yams
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4702
diff
changeset
|
1327 |
|
535705688f4f
proper deprecation warning when import class that should be imported from yams
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4702
diff
changeset
|
1328 |
StaticVocabularyConstraint = class_moved(StaticVocabularyConstraint) |
535705688f4f
proper deprecation warning when import class that should be imported from yams
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4702
diff
changeset
|
1329 |
FormatConstraint = class_moved(FormatConstraint) |
3978
2c95e3033f64
finish yesterday work on rql constraints:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3968
diff
changeset
|
1330 |
|
2c95e3033f64
finish yesterday work on rql constraints:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3968
diff
changeset
|
1331 |
PyFileReader.context['ERQLExpression'] = yobsolete(ERQLExpression) |
2c95e3033f64
finish yesterday work on rql constraints:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3968
diff
changeset
|
1332 |
PyFileReader.context['RRQLExpression'] = yobsolete(RRQLExpression) |
2c95e3033f64
finish yesterday work on rql constraints:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3968
diff
changeset
|
1333 |
PyFileReader.context['WorkflowableEntityType'] = WorkflowableEntityType |