author | Sylvain Thénault <sylvain.thenault@logilab.fr> |
Tue, 15 Nov 2011 22:22:18 +0100 | |
changeset 8083 | 3db2f3317d15 |
parent 8027 | 9ac82788f67b |
child 8125 | 7070250bf50d |
child 8160 | e53c003e3d37 |
permissions | -rw-r--r-- |
6949
267ce7cf77f1
[test, ui] mark CWSourceSchemaConfig as an internal type
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6944
diff
changeset
|
1 |
# copyright 2003-2011 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 |
|
2147
476a75ede2cc
merge and add missing import in schema.py
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2142
diff
changeset
|
24 |
from os.path import join |
0 | 25 |
from logging import getLogger |
1133 | 26 |
from warnings import warn |
0 | 27 |
|
624
258e5692ae06
provide a new RichString attribute type
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
479
diff
changeset
|
28 |
from logilab.common.decorators import cached, clear_cache, monkeypatch |
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
|
29 |
from logilab.common.logging_ext import set_log_methods |
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
|
30 |
from logilab.common.deprecation import deprecated, class_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
|
31 |
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
|
32 |
from logilab.common.graph import get_cycles |
0 | 33 |
from logilab.common.compat import any |
34 |
||
2531
531ea4e7013e
[cleanup] nicer imports
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
2526
diff
changeset
|
35 |
from yams import BadSchemaDefinition, buildobjs as ybo |
3877
7ca53fc72a0a
reldefsecurity branch :
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3827
diff
changeset
|
36 |
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
|
37 |
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
|
38 |
from yams.constraints import BaseConstraint, FormatConstraint |
2531
531ea4e7013e
[cleanup] nicer imports
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
2526
diff
changeset
|
39 |
from yams.reader import (CONSTRAINTS, PyFileReader, SchemaLoader, |
531ea4e7013e
[cleanup] nicer imports
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
2526
diff
changeset
|
40 |
obsolete as yobsolete, cleanup_sys_modules) |
0 | 41 |
|
42 |
from rql import parse, nodes, RQLSyntaxError, TypeResolverException |
|
43 |
||
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
|
44 |
import cubicweb |
0 | 45 |
from cubicweb import ETYPE_NAME_MAP, ValidationError, Unauthorized |
46 |
||
2596
d02eed70937f
[R repo, schema] use VIRTUAL_RTYPES const
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2531
diff
changeset
|
47 |
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
|
48 |
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
|
49 |
|
4913
083b4d454192
server/web api for accessing to deleted_entites
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
4843
diff
changeset
|
50 |
# 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
|
51 |
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
|
52 |
'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
|
53 |
'eid', 'creation_date', 'cw_source', 'modification_date', 'has_text', 'cwuri', |
2184 | 54 |
)) |
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
|
55 |
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
|
56 |
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
|
57 |
'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
|
58 |
'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
|
59 |
'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
|
60 |
'subworkflow', 'subworkflow_state', 'subworkflow_exit', |
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
|
61 |
)) |
7797
a71618a75b53
backport stable
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7782
diff
changeset
|
62 |
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
|
63 |
# 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
|
64 |
'for_user', |
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
|
65 |
)) | 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
|
66 |
NO_I18NCONTEXT = META_RTYPES | WORKFLOW_RTYPES |
0 | 67 |
|
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
|
68 |
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
|
69 |
|
4913
083b4d454192
server/web api for accessing to deleted_entites
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
4843
diff
changeset
|
70 |
# 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
|
71 |
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
|
72 |
'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
|
73 |
'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
|
74 |
'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
|
75 |
'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
|
76 |
'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
|
77 |
'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
|
78 |
'constraint_of', 'relations', |
6262
84901d735156
add permission relations to schema types
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6233
diff
changeset
|
79 |
'read_permission', 'add_permission', |
84901d735156
add permission relations to schema types
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6233
diff
changeset
|
80 |
'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
|
81 |
)) |
0 | 82 |
|
4434
101344a6ff9b
Improve the schema command with filtering option.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
4252
diff
changeset
|
83 |
WORKFLOW_TYPES = set(('Transition', 'State', 'TrInfo', 'Workflow', |
4759 | 84 |
'WorkflowTransition', 'BaseTransition', |
85 |
'SubWorkflowExitPoint')) |
|
86 |
||
7797
a71618a75b53
backport stable
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7782
diff
changeset
|
87 |
INTERNAL_TYPES = set(('CWProperty', 'CWCache', 'ExternalUri', |
6949
267ce7cf77f1
[test, ui] mark CWSourceSchemaConfig as an internal type
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6944
diff
changeset
|
88 |
'CWSource', 'CWSourceHostConfig', 'CWSourceSchemaConfig')) |
4434
101344a6ff9b
Improve the schema command with filtering option.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
4252
diff
changeset
|
89 |
|
101344a6ff9b
Improve the schema command with filtering option.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
4252
diff
changeset
|
90 |
|
2142
098aa2075903
include_schema_files is useless
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
91 |
_LOGGER = getLogger('cubicweb.schemaloader') |
0 | 92 |
|
93 |
# schema entities created from serialized schema have an eid rproperty |
|
94 |
ybo.ETYPE_PROPERTIES += ('eid',) |
|
95 |
ybo.RTYPE_PROPERTIES += ('eid',) |
|
96 |
ybo.RDEF_PROPERTIES += ('eid',) |
|
97 |
||
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
|
98 |
|
4754
6bf17f810975
[schema] new constants for permissions definitions
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4717
diff
changeset
|
99 |
PUB_SYSTEM_ENTITY_PERMS = { |
6bf17f810975
[schema] new constants for permissions definitions
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4717
diff
changeset
|
100 |
'read': ('managers', 'users', 'guests',), |
6bf17f810975
[schema] new constants for permissions definitions
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4717
diff
changeset
|
101 |
'add': ('managers',), |
6bf17f810975
[schema] new constants for permissions definitions
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4717
diff
changeset
|
102 |
'delete': ('managers',), |
6bf17f810975
[schema] new constants for permissions definitions
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4717
diff
changeset
|
103 |
'update': ('managers',), |
6bf17f810975
[schema] new constants for permissions definitions
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4717
diff
changeset
|
104 |
} |
6bf17f810975
[schema] new constants for permissions definitions
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4717
diff
changeset
|
105 |
PUB_SYSTEM_REL_PERMS = { |
6bf17f810975
[schema] new constants for permissions definitions
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4717
diff
changeset
|
106 |
'read': ('managers', 'users', 'guests',), |
6bf17f810975
[schema] new constants for permissions definitions
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4717
diff
changeset
|
107 |
'add': ('managers',), |
6bf17f810975
[schema] new constants for permissions definitions
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4717
diff
changeset
|
108 |
'delete': ('managers',), |
6bf17f810975
[schema] new constants for permissions definitions
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4717
diff
changeset
|
109 |
} |
6bf17f810975
[schema] new constants for permissions definitions
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4717
diff
changeset
|
110 |
PUB_SYSTEM_ATTR_PERMS = { |
6bf17f810975
[schema] new constants for permissions definitions
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4717
diff
changeset
|
111 |
'read': ('managers', 'users', 'guests',), |
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
|
112 |
'update': ('managers',), |
4754
6bf17f810975
[schema] new constants for permissions definitions
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4717
diff
changeset
|
113 |
} |
6bf17f810975
[schema] new constants for permissions definitions
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4717
diff
changeset
|
114 |
RO_REL_PERMS = { |
6bf17f810975
[schema] new constants for permissions definitions
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4717
diff
changeset
|
115 |
'read': ('managers', 'users', 'guests',), |
6bf17f810975
[schema] new constants for permissions definitions
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4717
diff
changeset
|
116 |
'add': (), |
6bf17f810975
[schema] new constants for permissions definitions
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4717
diff
changeset
|
117 |
'delete': (), |
6bf17f810975
[schema] new constants for permissions definitions
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4717
diff
changeset
|
118 |
} |
6bf17f810975
[schema] new constants for permissions definitions
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4717
diff
changeset
|
119 |
RO_ATTR_PERMS = { |
6bf17f810975
[schema] new constants for permissions definitions
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4717
diff
changeset
|
120 |
'read': ('managers', 'users', 'guests',), |
6bf17f810975
[schema] new constants for permissions definitions
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4717
diff
changeset
|
121 |
'update': (), |
6bf17f810975
[schema] new constants for permissions definitions
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4717
diff
changeset
|
122 |
} |
6bf17f810975
[schema] new constants for permissions definitions
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4717
diff
changeset
|
123 |
|
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
|
124 |
# 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
|
125 |
# 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
|
126 |
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
|
127 |
"""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
|
128 |
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
|
129 |
""" |
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
|
130 |
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
|
131 |
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
|
132 |
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
|
133 |
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
|
134 |
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
|
135 |
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
|
136 |
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
|
137 |
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
|
138 |
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
|
139 |
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
|
140 |
% 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
|
141 |
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
|
142 |
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
|
143 |
# 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
|
144 |
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
|
145 |
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
|
146 |
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
|
147 |
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
|
148 |
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
|
149 |
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
|
150 |
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
|
151 |
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
|
152 |
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
|
153 |
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
|
154 |
|
0 | 155 |
def bw_normalize_etype(etype): |
156 |
if etype in ETYPE_NAME_MAP: |
|
157 |
msg = '%s has been renamed to %s, please update your code' % ( |
|
1451 | 158 |
etype, ETYPE_NAME_MAP[etype]) |
0 | 159 |
warn(msg, DeprecationWarning, stacklevel=4) |
160 |
etype = ETYPE_NAME_MAP[etype] |
|
161 |
return etype |
|
162 |
||
3275
5247789df541
[gettext] provide GNU contexts to avoid translations ambiguities
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3240
diff
changeset
|
163 |
def display_name(req, key, form='', context=None): |
0 | 164 |
"""return a internationalized string for the key (schema entity or relation |
165 |
name) in a given form |
|
166 |
""" |
|
167 |
assert form in ('', 'plural', 'subject', 'object') |
|
168 |
if form == 'subject': |
|
169 |
form = '' |
|
170 |
if form: |
|
171 |
key = key + '_' + form |
|
172 |
# ensure unicode |
|
3284
036cf5a25714
ensure pgettext return unicode as well
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3275
diff
changeset
|
173 |
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
|
174 |
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
|
175 |
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
|
176 |
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
|
177 |
|
3978
2c95e3033f64
finish yesterday work on rql constraints:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3968
diff
changeset
|
178 |
|
2c95e3033f64
finish yesterday work on rql constraints:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3968
diff
changeset
|
179 |
# Schema objects definition ################################################### |
2c95e3033f64
finish yesterday work on rql constraints:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3968
diff
changeset
|
180 |
|
3471
8c57c71b859c
can now give context to rschema.display_name(...)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3401
diff
changeset
|
181 |
def ERSchema_display_name(self, req, form='', context=None): |
0 | 182 |
"""return a internationalized string for the entity/relation type name in |
183 |
a given form |
|
184 |
""" |
|
3471
8c57c71b859c
can now give context to rschema.display_name(...)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3401
diff
changeset
|
185 |
return display_name(req, self.type, form, context) |
0 | 186 |
ERSchema.display_name = ERSchema_display_name |
187 |
||
188 |
@cached |
|
3877
7ca53fc72a0a
reldefsecurity branch :
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3827
diff
changeset
|
189 |
def get_groups(self, action): |
0 | 190 |
"""return the groups authorized to perform <action> on entities of |
191 |
this type |
|
192 |
||
193 |
:type action: str |
|
194 |
:param action: the name of a permission |
|
195 |
||
196 |
:rtype: tuple |
|
197 |
:return: names of the groups with the given permission |
|
198 |
""" |
|
199 |
assert action in self.ACTIONS, action |
|
200 |
#assert action in self._groups, '%s %s' % (self, action) |
|
201 |
try: |
|
3877
7ca53fc72a0a
reldefsecurity branch :
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3827
diff
changeset
|
202 |
return frozenset(g for g in self.permissions[action] if isinstance(g, basestring)) |
0 | 203 |
except KeyError: |
204 |
return () |
|
3877
7ca53fc72a0a
reldefsecurity branch :
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3827
diff
changeset
|
205 |
PermissionMixIn.get_groups = get_groups |
0 | 206 |
|
207 |
@cached |
|
3877
7ca53fc72a0a
reldefsecurity branch :
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3827
diff
changeset
|
208 |
def get_rqlexprs(self, action): |
0 | 209 |
"""return the rql expressions representing queries to check the user is allowed |
210 |
to perform <action> on entities of this type |
|
211 |
||
212 |
:type action: str |
|
213 |
:param action: the name of a permission |
|
214 |
||
215 |
:rtype: tuple |
|
216 |
:return: the rql expressions with the given permission |
|
217 |
""" |
|
218 |
assert action in self.ACTIONS, action |
|
219 |
#assert action in self._rqlexprs, '%s %s' % (self, action) |
|
220 |
try: |
|
3877
7ca53fc72a0a
reldefsecurity branch :
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3827
diff
changeset
|
221 |
return tuple(g for g in self.permissions[action] if not isinstance(g, basestring)) |
0 | 222 |
except KeyError: |
223 |
return () |
|
3877
7ca53fc72a0a
reldefsecurity branch :
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3827
diff
changeset
|
224 |
PermissionMixIn.get_rqlexprs = get_rqlexprs |
0 | 225 |
|
3877
7ca53fc72a0a
reldefsecurity branch :
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3827
diff
changeset
|
226 |
orig_set_action_permissions = PermissionMixIn.set_action_permissions |
7ca53fc72a0a
reldefsecurity branch :
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3827
diff
changeset
|
227 |
def set_action_permissions(self, action, permissions): |
0 | 228 |
"""set the groups and rql expressions allowing to perform <action> on |
229 |
entities of this type |
|
230 |
||
231 |
:type action: str |
|
232 |
:param action: the name of a permission |
|
233 |
||
234 |
:type permissions: tuple |
|
235 |
:param permissions: the groups and rql expressions allowing the given action |
|
236 |
""" |
|
3877
7ca53fc72a0a
reldefsecurity branch :
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3827
diff
changeset
|
237 |
orig_set_action_permissions(self, action, tuple(permissions)) |
7ca53fc72a0a
reldefsecurity branch :
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3827
diff
changeset
|
238 |
clear_cache(self, 'get_rqlexprs') |
7ca53fc72a0a
reldefsecurity branch :
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3827
diff
changeset
|
239 |
clear_cache(self, 'get_groups') |
7ca53fc72a0a
reldefsecurity branch :
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3827
diff
changeset
|
240 |
PermissionMixIn.set_action_permissions = set_action_permissions |
0 | 241 |
|
3877
7ca53fc72a0a
reldefsecurity branch :
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3827
diff
changeset
|
242 |
def has_local_role(self, action): |
0 | 243 |
"""return true if the action *may* be granted localy (eg either rql |
244 |
expressions or the owners group are used in security definition) |
|
245 |
||
246 |
XXX this method is only there since we don't know well how to deal with |
|
247 |
'add' action checking. Also find a better name would be nice. |
|
248 |
""" |
|
249 |
assert action in self.ACTIONS, action |
|
250 |
if self.get_rqlexprs(action): |
|
251 |
return True |
|
252 |
if action in ('update', 'delete'): |
|
3877
7ca53fc72a0a
reldefsecurity branch :
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3827
diff
changeset
|
253 |
return 'owners' in self.get_groups(action) |
0 | 254 |
return False |
3877
7ca53fc72a0a
reldefsecurity branch :
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3827
diff
changeset
|
255 |
PermissionMixIn.has_local_role = has_local_role |
7ca53fc72a0a
reldefsecurity branch :
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3827
diff
changeset
|
256 |
|
7ca53fc72a0a
reldefsecurity branch :
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3827
diff
changeset
|
257 |
def may_have_permission(self, action, req): |
7ca53fc72a0a
reldefsecurity branch :
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3827
diff
changeset
|
258 |
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
|
259 |
self.has_perm(req, 'read')): |
7ca53fc72a0a
reldefsecurity branch :
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3827
diff
changeset
|
260 |
return False |
7ca53fc72a0a
reldefsecurity branch :
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3827
diff
changeset
|
261 |
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
|
262 |
PermissionMixIn.may_have_permission = may_have_permission |
7ca53fc72a0a
reldefsecurity branch :
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3827
diff
changeset
|
263 |
|
7ca53fc72a0a
reldefsecurity branch :
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3827
diff
changeset
|
264 |
def has_perm(self, session, action, **kwargs): |
7ca53fc72a0a
reldefsecurity branch :
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3827
diff
changeset
|
265 |
"""return true if the action is granted globaly or localy""" |
7ca53fc72a0a
reldefsecurity branch :
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3827
diff
changeset
|
266 |
try: |
7ca53fc72a0a
reldefsecurity branch :
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3827
diff
changeset
|
267 |
self.check_perm(session, action, **kwargs) |
7ca53fc72a0a
reldefsecurity branch :
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3827
diff
changeset
|
268 |
return True |
7ca53fc72a0a
reldefsecurity branch :
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3827
diff
changeset
|
269 |
except Unauthorized: |
7ca53fc72a0a
reldefsecurity branch :
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3827
diff
changeset
|
270 |
return False |
7ca53fc72a0a
reldefsecurity branch :
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3827
diff
changeset
|
271 |
PermissionMixIn.has_perm = has_perm |
7ca53fc72a0a
reldefsecurity branch :
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3827
diff
changeset
|
272 |
|
7ca53fc72a0a
reldefsecurity branch :
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3827
diff
changeset
|
273 |
def check_perm(self, session, action, **kwargs): |
7ca53fc72a0a
reldefsecurity branch :
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3827
diff
changeset
|
274 |
# NB: session may be a server session or a request object check user is |
7ca53fc72a0a
reldefsecurity branch :
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3827
diff
changeset
|
275 |
# in an allowed group, if so that's enough internal sessions should |
7ca53fc72a0a
reldefsecurity branch :
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3827
diff
changeset
|
276 |
# always stop there |
7ca53fc72a0a
reldefsecurity branch :
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3827
diff
changeset
|
277 |
groups = self.get_groups(action) |
7ca53fc72a0a
reldefsecurity branch :
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3827
diff
changeset
|
278 |
if session.user.matching_groups(groups): |
7ca53fc72a0a
reldefsecurity branch :
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3827
diff
changeset
|
279 |
return |
7ca53fc72a0a
reldefsecurity branch :
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3827
diff
changeset
|
280 |
# 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
|
281 |
# object, if so that's enough |
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
|
282 |
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
|
283 |
kwargs.get('creating') |
4608 | 284 |
or ('eid' in kwargs and session.user.owns(kwargs['eid']))): |
3877
7ca53fc72a0a
reldefsecurity branch :
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3827
diff
changeset
|
285 |
return |
7ca53fc72a0a
reldefsecurity branch :
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3827
diff
changeset
|
286 |
# else if there is some rql expressions, check them |
7ca53fc72a0a
reldefsecurity branch :
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3827
diff
changeset
|
287 |
if any(rqlexpr.check(session, **kwargs) |
7ca53fc72a0a
reldefsecurity branch :
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3827
diff
changeset
|
288 |
for rqlexpr in self.get_rqlexprs(action)): |
7ca53fc72a0a
reldefsecurity branch :
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3827
diff
changeset
|
289 |
return |
7ca53fc72a0a
reldefsecurity branch :
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3827
diff
changeset
|
290 |
raise Unauthorized(action, str(self)) |
7ca53fc72a0a
reldefsecurity branch :
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3827
diff
changeset
|
291 |
PermissionMixIn.check_perm = check_perm |
7ca53fc72a0a
reldefsecurity branch :
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3827
diff
changeset
|
292 |
|
7ca53fc72a0a
reldefsecurity branch :
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3827
diff
changeset
|
293 |
|
7ca53fc72a0a
reldefsecurity branch :
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3827
diff
changeset
|
294 |
RelationDefinitionSchema._RPROPERTIES['eid'] = None |
7ca53fc72a0a
reldefsecurity branch :
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3827
diff
changeset
|
295 |
|
7ca53fc72a0a
reldefsecurity branch :
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3827
diff
changeset
|
296 |
def rql_expression(self, expression, mainvars=None, eid=None): |
7ca53fc72a0a
reldefsecurity branch :
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3827
diff
changeset
|
297 |
"""rql expression factory""" |
7ca53fc72a0a
reldefsecurity branch :
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3827
diff
changeset
|
298 |
if self.rtype.final: |
7ca53fc72a0a
reldefsecurity branch :
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3827
diff
changeset
|
299 |
return ERQLExpression(expression, mainvars, eid) |
7ca53fc72a0a
reldefsecurity branch :
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3827
diff
changeset
|
300 |
return RRQLExpression(expression, mainvars, eid) |
7ca53fc72a0a
reldefsecurity branch :
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3827
diff
changeset
|
301 |
RelationDefinitionSchema.rql_expression = rql_expression |
7ca53fc72a0a
reldefsecurity branch :
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3827
diff
changeset
|
302 |
|
7ca53fc72a0a
reldefsecurity branch :
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3827
diff
changeset
|
303 |
orig_check_permission_definitions = RelationDefinitionSchema.check_permission_definitions |
7ca53fc72a0a
reldefsecurity branch :
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3827
diff
changeset
|
304 |
def check_permission_definitions(self): |
7ca53fc72a0a
reldefsecurity branch :
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3827
diff
changeset
|
305 |
orig_check_permission_definitions(self) |
7ca53fc72a0a
reldefsecurity branch :
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3827
diff
changeset
|
306 |
schema = self.subject.schema |
7ca53fc72a0a
reldefsecurity branch :
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3827
diff
changeset
|
307 |
for action, groups in self.permissions.iteritems(): |
7ca53fc72a0a
reldefsecurity branch :
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3827
diff
changeset
|
308 |
for group_or_rqlexpr in groups: |
7ca53fc72a0a
reldefsecurity branch :
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3827
diff
changeset
|
309 |
if action == 'read' and \ |
7ca53fc72a0a
reldefsecurity branch :
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3827
diff
changeset
|
310 |
isinstance(group_or_rqlexpr, RQLExpression): |
7ca53fc72a0a
reldefsecurity branch :
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3827
diff
changeset
|
311 |
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
|
312 |
raise BadSchemaDefinition(msg % self) |
4574
2380444d982c
[schema] refactor/cleanup check_permissions
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4570
diff
changeset
|
313 |
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
|
314 |
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
|
315 |
raise BadSchemaDefinition(msg % self) |
2380444d982c
[schema] refactor/cleanup check_permissions
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4570
diff
changeset
|
316 |
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
|
317 |
msg = "can't use ERQLExpression on %s, use a RRQLExpression" |
7ca53fc72a0a
reldefsecurity branch :
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3827
diff
changeset
|
318 |
raise BadSchemaDefinition(msg % self) |
7ca53fc72a0a
reldefsecurity branch :
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3827
diff
changeset
|
319 |
RelationDefinitionSchema.check_permission_definitions = check_permission_definitions |
0 | 320 |
|
321 |
||
322 |
class CubicWebEntitySchema(EntitySchema): |
|
323 |
"""a entity has a type, a set of subject and or object relations |
|
324 |
the entity schema defines the possible relations for a given type and some |
|
325 |
constraints on those relations |
|
326 |
""" |
|
327 |
def __init__(self, schema=None, edef=None, eid=None, **kwargs): |
|
328 |
super(CubicWebEntitySchema, self).__init__(schema, edef, **kwargs) |
|
329 |
if eid is None and edef is not None: |
|
330 |
eid = getattr(edef, 'eid', None) |
|
331 |
self.eid = eid |
|
4574
2380444d982c
[schema] refactor/cleanup check_permissions
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4570
diff
changeset
|
332 |
|
2380444d982c
[schema] refactor/cleanup check_permissions
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4570
diff
changeset
|
333 |
def check_permission_definitions(self): |
2380444d982c
[schema] refactor/cleanup check_permissions
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4570
diff
changeset
|
334 |
super(CubicWebEntitySchema, self).check_permission_definitions() |
2380444d982c
[schema] refactor/cleanup check_permissions
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4570
diff
changeset
|
335 |
for groups in self.permissions.itervalues(): |
2380444d982c
[schema] refactor/cleanup check_permissions
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4570
diff
changeset
|
336 |
for group_or_rqlexpr in groups: |
2380444d982c
[schema] refactor/cleanup check_permissions
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4570
diff
changeset
|
337 |
if isinstance(group_or_rqlexpr, RRQLExpression): |
2380444d982c
[schema] refactor/cleanup check_permissions
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4570
diff
changeset
|
338 |
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
|
339 |
raise BadSchemaDefinition(msg % self.type) |
1451 | 340 |
|
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
|
341 |
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
|
342 |
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
|
343 |
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
|
344 |
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
|
345 |
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
|
346 |
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
|
347 |
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
|
348 |
|
0 | 349 |
def attribute_definitions(self): |
350 |
"""return an iterator on attribute definitions |
|
1451 | 351 |
|
0 | 352 |
attribute relations are a subset of subject relations where the |
353 |
object's type is a final entity |
|
1451 | 354 |
|
0 | 355 |
an attribute definition is a 2-uple : |
356 |
* name of the relation |
|
357 |
* schema of the destination entity type |
|
358 |
""" |
|
359 |
iter = super(CubicWebEntitySchema, self).attribute_definitions() |
|
360 |
for rschema, attrschema in iter: |
|
361 |
if rschema.type == 'has_text': |
|
362 |
continue |
|
363 |
yield rschema, attrschema |
|
1451 | 364 |
|
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
|
365 |
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
|
366 |
"""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
|
367 |
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
|
368 |
""" |
464edb198faa
drop @ wildcard in relation subject/object, override main_attribute for proper behaviour
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2126
diff
changeset
|
369 |
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
|
370 |
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
|
371 |
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
|
372 |
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
|
373 |
|
0 | 374 |
def add_subject_relation(self, rschema): |
375 |
"""register the relation schema as possible subject relation""" |
|
376 |
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
|
377 |
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
|
378 |
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
|
379 |
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
|
380 |
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
|
381 |
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
|
382 |
|
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
|
383 |
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
|
384 |
"""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
|
385 |
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
|
386 |
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
|
387 |
self._update_has_text() |
0 | 388 |
|
389 |
def del_subject_relation(self, rtype): |
|
390 |
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
|
391 |
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
|
392 |
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
|
393 |
|
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
|
394 |
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
|
395 |
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
|
396 |
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
|
397 |
self._update_has_text(deletion=True) |
1451 | 398 |
|
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
|
399 |
def _update_has_text(self, deletion=False): |
0 | 400 |
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
|
401 |
need_has_text = None |
0 | 402 |
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
|
403 |
if rschema.final: |
0 | 404 |
if rschema == 'has_text': |
405 |
has_has_text = True |
|
3877
7ca53fc72a0a
reldefsecurity branch :
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3827
diff
changeset
|
406 |
elif self.rdef(rschema).get('fulltextindexed'): |
0 | 407 |
may_need_has_text = True |
408 |
elif rschema.fulltext_container: |
|
409 |
if rschema.fulltext_container == 'subject': |
|
410 |
may_need_has_text = True |
|
411 |
else: |
|
412 |
need_has_text = False |
|
413 |
for rschema in self.object_relations(): |
|
414 |
if rschema.fulltext_container: |
|
415 |
if rschema.fulltext_container == 'object': |
|
416 |
may_need_has_text = True |
|
417 |
else: |
|
418 |
need_has_text = False |
|
419 |
if need_has_text is None: |
|
420 |
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
|
421 |
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
|
422 |
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
|
423 |
__permissions__=RO_ATTR_PERMS) |
0 | 424 |
self.schema.add_relation_def(rdef) |
425 |
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
|
426 |
# 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
|
427 |
# 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
|
428 |
self.schema['has_text'].del_relation_def(self, self.schema['String']) |
1451 | 429 |
|
5896 | 430 |
def schema_entity(self): # XXX @property for consistency with meta |
0 | 431 |
"""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
|
432 |
return self.type in SCHEMA_TYPES |
0 | 433 |
|
434 |
def rql_expression(self, expression, mainvars=None, eid=None): |
|
435 |
"""rql expression factory""" |
|
436 |
return ERQLExpression(expression, mainvars, eid) |
|
1451 | 437 |
|
2252 | 438 |
|
0 | 439 |
class CubicWebRelationSchema(RelationSchema): |
1451 | 440 |
|
0 | 441 |
def __init__(self, schema=None, rdef=None, eid=None, **kwargs): |
442 |
if rdef is not None: |
|
443 |
# if this relation is inlined |
|
444 |
self.inlined = rdef.inlined |
|
445 |
super(CubicWebRelationSchema, self).__init__(schema, rdef, **kwargs) |
|
446 |
if eid is None and rdef is not None: |
|
447 |
eid = getattr(rdef, 'eid', None) |
|
448 |
self.eid = eid |
|
1451 | 449 |
|
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
|
450 |
@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
|
451 |
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
|
452 |
return self.type in META_RTYPES |
1451 | 453 |
|
5896 | 454 |
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
|
455 |
"""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
|
456 |
return self.type in SCHEMA_TYPES |
1451 | 457 |
|
3877
7ca53fc72a0a
reldefsecurity branch :
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3827
diff
changeset
|
458 |
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
|
459 |
if eschema is not None: |
4019 | 460 |
for tschema in self.targets(eschema, role): |
461 |
rdef = self.role_rdef(eschema, tschema, role) |
|
3877
7ca53fc72a0a
reldefsecurity branch :
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3827
diff
changeset
|
462 |
if rdef.may_have_permission(action, req): |
7ca53fc72a0a
reldefsecurity branch :
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3827
diff
changeset
|
463 |
return True |
7ca53fc72a0a
reldefsecurity branch :
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3827
diff
changeset
|
464 |
else: |
7ca53fc72a0a
reldefsecurity branch :
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3827
diff
changeset
|
465 |
for rdef in self.rdefs.itervalues(): |
7ca53fc72a0a
reldefsecurity branch :
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3827
diff
changeset
|
466 |
if rdef.may_have_permission(action, req): |
7ca53fc72a0a
reldefsecurity branch :
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3827
diff
changeset
|
467 |
return True |
7ca53fc72a0a
reldefsecurity branch :
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3827
diff
changeset
|
468 |
return False |
0 | 469 |
|
3877
7ca53fc72a0a
reldefsecurity branch :
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3827
diff
changeset
|
470 |
def has_perm(self, session, action, **kwargs): |
7ca53fc72a0a
reldefsecurity branch :
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3827
diff
changeset
|
471 |
"""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
|
472 |
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
|
473 |
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
|
474 |
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
|
475 |
if 'eid' in kwargs: |
4a7fe84f7803
[schema] fix RelationSchema.has_perm to properly works with attribute relations
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4574
diff
changeset
|
476 |
subjtype = session.describe(kwargs['eid'])[0] |
4a7fe84f7803
[schema] fix RelationSchema.has_perm to properly works with attribute relations
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4574
diff
changeset
|
477 |
else: |
4a7fe84f7803
[schema] fix RelationSchema.has_perm to properly works with attribute relations
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4574
diff
changeset
|
478 |
subjtype = objtype = None |
3877
7ca53fc72a0a
reldefsecurity branch :
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3827
diff
changeset
|
479 |
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
|
480 |
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
|
481 |
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
|
482 |
if 'fromeid' in kwargs: |
4a7fe84f7803
[schema] fix RelationSchema.has_perm to properly works with attribute relations
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4574
diff
changeset
|
483 |
subjtype = session.describe(kwargs['fromeid'])[0] |
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
|
484 |
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
|
485 |
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
|
486 |
else: |
4a7fe84f7803
[schema] fix RelationSchema.has_perm to properly works with attribute relations
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4574
diff
changeset
|
487 |
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
|
488 |
if 'toeid' in kwargs: |
4a7fe84f7803
[schema] fix RelationSchema.has_perm to properly works with attribute relations
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4574
diff
changeset
|
489 |
objtype = session.describe(kwargs['toeid'])[0] |
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
|
490 |
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
|
491 |
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
|
492 |
else: |
4a7fe84f7803
[schema] fix RelationSchema.has_perm to properly works with attribute relations
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4574
diff
changeset
|
493 |
objtype = None |
3877
7ca53fc72a0a
reldefsecurity branch :
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3827
diff
changeset
|
494 |
if objtype and subjtype: |
7ca53fc72a0a
reldefsecurity branch :
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3827
diff
changeset
|
495 |
return self.rdef(subjtype, objtype).has_perm(session, action, **kwargs) |
7ca53fc72a0a
reldefsecurity branch :
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3827
diff
changeset
|
496 |
elif subjtype: |
4004
c52619c738a5
api renaming update
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
4003
diff
changeset
|
497 |
for tschema in self.targets(subjtype, 'subject'): |
c52619c738a5
api renaming update
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
4003
diff
changeset
|
498 |
rdef = self.rdef(subjtype, tschema) |
4045
f4a52abb6f4f
cw 3.6 api update
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
4037
diff
changeset
|
499 |
if not rdef.has_perm(session, action, **kwargs): |
3877
7ca53fc72a0a
reldefsecurity branch :
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3827
diff
changeset
|
500 |
return False |
7ca53fc72a0a
reldefsecurity branch :
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3827
diff
changeset
|
501 |
elif objtype: |
4004
c52619c738a5
api renaming update
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
4003
diff
changeset
|
502 |
for tschema in self.targets(objtype, 'object'): |
c52619c738a5
api renaming update
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
4003
diff
changeset
|
503 |
rdef = self.rdef(tschema, objtype) |
c52619c738a5
api renaming update
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
4003
diff
changeset
|
504 |
if not rdef.has_perm(session, action, **kwargs): |
3877
7ca53fc72a0a
reldefsecurity branch :
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3827
diff
changeset
|
505 |
return False |
7ca53fc72a0a
reldefsecurity branch :
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3827
diff
changeset
|
506 |
else: |
7ca53fc72a0a
reldefsecurity branch :
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3827
diff
changeset
|
507 |
for rdef in self.rdefs.itervalues(): |
4004
c52619c738a5
api renaming update
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
4003
diff
changeset
|
508 |
if not rdef.has_perm(session, action, **kwargs): |
3877
7ca53fc72a0a
reldefsecurity branch :
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3827
diff
changeset
|
509 |
return False |
4233
94ffaecd8e8c
ouch, has_perm was always returning False...
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4181
diff
changeset
|
510 |
return True |
0 | 511 |
|
3877
7ca53fc72a0a
reldefsecurity branch :
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3827
diff
changeset
|
512 |
@deprecated('use .rdef(subjtype, objtype).role_cardinality(role)') |
7ca53fc72a0a
reldefsecurity branch :
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3827
diff
changeset
|
513 |
def cardinality(self, subjtype, objtype, target): |
7ca53fc72a0a
reldefsecurity branch :
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3827
diff
changeset
|
514 |
return self.rdef(subjtype, objtype).role_cardinality(target) |
0 | 515 |
|
1451 | 516 |
|
0 | 517 |
class CubicWebSchema(Schema): |
518 |
"""set of entities and relations schema defining the possible data sets |
|
519 |
used in an application |
|
520 |
||
521 |
:type name: str |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2460
diff
changeset
|
522 |
:ivar name: name of the schema, usually the instance identifier |
1451 | 523 |
|
0 | 524 |
:type base: str |
525 |
:ivar base: path of the directory where the schema is defined |
|
526 |
""" |
|
1451 | 527 |
reading_from_database = False |
0 | 528 |
entity_class = CubicWebEntitySchema |
529 |
relation_class = CubicWebRelationSchema |
|
2958
44e5446b649b
no inference for the identity relation
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2926
diff
changeset
|
530 |
no_specialization_inference = ('identity',) |
0 | 531 |
|
532 |
def __init__(self, *args, **kwargs): |
|
533 |
self._eid_index = {} |
|
534 |
super(CubicWebSchema, self).__init__(*args, **kwargs) |
|
535 |
ybo.register_base_types(self) |
|
2300
c8151d004e06
meta has been drop
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2293
diff
changeset
|
536 |
rschema = self.add_relation_type(ybo.RelationType('eid')) |
0 | 537 |
rschema.final = True |
2300
c8151d004e06
meta has been drop
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2293
diff
changeset
|
538 |
rschema = self.add_relation_type(ybo.RelationType('has_text')) |
0 | 539 |
rschema.final = True |
2300
c8151d004e06
meta has been drop
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2293
diff
changeset
|
540 |
rschema = self.add_relation_type(ybo.RelationType('identity')) |
0 | 541 |
rschema.final = False |
1451 | 542 |
|
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
|
543 |
etype_name_re = r'[A-Z][A-Za-z0-9]*[a-z]+[A-Za-z0-9]*$' |
0 | 544 |
def add_entity_type(self, edef): |
545 |
edef.name = edef.name.encode() |
|
546 |
edef.name = bw_normalize_etype(edef.name) |
|
7383
1719eab69551
[schema] fix imprecise error message
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
7152
diff
changeset
|
547 |
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
|
548 |
raise BadSchemaDefinition( |
9d4e11d6e783
[schema] ease understanding of schema naming error
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6827
diff
changeset
|
549 |
'%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
|
550 |
'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
|
551 |
'lower cased letter' % edef.name) |
0 | 552 |
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
|
553 |
if not eschema.final: |
0 | 554 |
# automatically add the eid relation to non final entity types |
555 |
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
|
556 |
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
|
557 |
__permissions__=RO_ATTR_PERMS) |
0 | 558 |
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
|
559 |
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
|
560 |
__permissions__=RO_REL_PERMS) |
0 | 561 |
self.add_relation_def(rdef) |
562 |
self._eid_index[eschema.eid] = eschema |
|
563 |
return eschema |
|
1451 | 564 |
|
0 | 565 |
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
|
566 |
if not rdef.name.islower(): |
9d4e11d6e783
[schema] ease understanding of schema naming error
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6827
diff
changeset
|
567 |
raise BadSchemaDefinition( |
9d4e11d6e783
[schema] ease understanding of schema naming error
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6827
diff
changeset
|
568 |
'%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
|
569 |
'lower cased' % rdef.name) |
9d4e11d6e783
[schema] ease understanding of schema naming error
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6827
diff
changeset
|
570 |
rdef.name = rdef.name.encode() |
0 | 571 |
rschema = super(CubicWebSchema, self).add_relation_type(rdef) |
572 |
self._eid_index[rschema.eid] = rschema |
|
573 |
return rschema |
|
1451 | 574 |
|
0 | 575 |
def add_relation_def(self, rdef): |
576 |
"""build a part of a relation schema |
|
577 |
(i.e. add a relation between two specific entity's types) |
|
578 |
||
579 |
:type subject: str |
|
580 |
:param subject: entity's type that is subject of the relation |
|
581 |
||
582 |
:type rtype: str |
|
583 |
:param rtype: the relation's type (i.e. the name of the relation) |
|
584 |
||
585 |
:type obj: str |
|
586 |
:param obj: entity's type that is object of the relation |
|
587 |
||
588 |
:rtype: RelationSchema |
|
589 |
:param: the newly created or just completed relation schema |
|
590 |
""" |
|
591 |
rdef.name = rdef.name.lower() |
|
592 |
rdef.subject = bw_normalize_etype(rdef.subject) |
|
593 |
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
|
594 |
rdefs = super(CubicWebSchema, self).add_relation_def(rdef) |
3877
7ca53fc72a0a
reldefsecurity branch :
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3827
diff
changeset
|
595 |
if rdefs: |
1034
0356bbfb2f26
fix to pass arguments to base class
sylvain.thenault@logilab.fr
parents:
1016
diff
changeset
|
596 |
try: |
3877
7ca53fc72a0a
reldefsecurity branch :
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3827
diff
changeset
|
597 |
self._eid_index[rdef.eid] = rdefs |
1034
0356bbfb2f26
fix to pass arguments to base class
sylvain.thenault@logilab.fr
parents:
1016
diff
changeset
|
598 |
except AttributeError: |
0356bbfb2f26
fix to pass arguments to base class
sylvain.thenault@logilab.fr
parents:
1016
diff
changeset
|
599 |
pass # not a serialized schema |
4003
b9436fe77c9e
fix bad merge
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
3998
diff
changeset
|
600 |
return rdefs |
1451 | 601 |
|
0 | 602 |
def del_relation_type(self, rtype): |
603 |
rschema = self.rschema(rtype) |
|
604 |
self._eid_index.pop(rschema.eid, None) |
|
605 |
super(CubicWebSchema, self).del_relation_type(rtype) |
|
1451 | 606 |
|
0 | 607 |
def del_relation_def(self, subjtype, rtype, objtype): |
608 |
for k, v in self._eid_index.items(): |
|
3877
7ca53fc72a0a
reldefsecurity branch :
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3827
diff
changeset
|
609 |
if not isinstance(v, RelationDefinitionSchema): |
7ca53fc72a0a
reldefsecurity branch :
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3827
diff
changeset
|
610 |
continue |
7ca53fc72a0a
reldefsecurity branch :
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3827
diff
changeset
|
611 |
if v.subject == subjtype and v.rtype == rtype and v.object == objtype: |
0 | 612 |
del self._eid_index[k] |
2718
3a56b87bb5d6
[schema] break when found
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2716
diff
changeset
|
613 |
break |
0 | 614 |
super(CubicWebSchema, self).del_relation_def(subjtype, rtype, objtype) |
1451 | 615 |
|
0 | 616 |
def del_entity_type(self, etype): |
617 |
eschema = self.eschema(etype) |
|
618 |
self._eid_index.pop(eschema.eid, None) |
|
619 |
# deal with has_text first, else its automatic deletion (see above) |
|
620 |
# may trigger an error in ancestor's del_entity_type method |
|
621 |
if 'has_text' in eschema.subject_relations(): |
|
622 |
self.del_relation_def(etype, 'has_text', 'String') |
|
623 |
super(CubicWebSchema, self).del_entity_type(etype) |
|
1451 | 624 |
|
0 | 625 |
def schema_by_eid(self, eid): |
626 |
return self._eid_index[eid] |
|
627 |
||
7152
39c1ffc7d93f
[schema, refactoring] use RQLExpression as base class for RQL constraint classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7103
diff
changeset
|
628 |
# Bases for manipulating RQL in schema ######################################### |
3961
d1cbf77db999
fix RQLUniqueConstraint behaviour by using a DISTINCT query and allowing
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3827
diff
changeset
|
629 |
|
7152
39c1ffc7d93f
[schema, refactoring] use RQLExpression as base class for RQL constraint classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7103
diff
changeset
|
630 |
def guess_rrqlexpr_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
|
631 |
defined = set(split_expression(expression)) |
39c1ffc7d93f
[schema, refactoring] use RQLExpression as base class for RQL constraint classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7103
diff
changeset
|
632 |
mainvars = set() |
39c1ffc7d93f
[schema, refactoring] use RQLExpression as base class for RQL constraint classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7103
diff
changeset
|
633 |
if 'S' in defined: |
39c1ffc7d93f
[schema, refactoring] use RQLExpression as base class for RQL constraint classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7103
diff
changeset
|
634 |
mainvars.add('S') |
39c1ffc7d93f
[schema, refactoring] use RQLExpression as base class for RQL constraint classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7103
diff
changeset
|
635 |
if 'O' in defined: |
39c1ffc7d93f
[schema, refactoring] use RQLExpression as base class for RQL constraint classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7103
diff
changeset
|
636 |
mainvars.add('O') |
39c1ffc7d93f
[schema, refactoring] use RQLExpression as base class for RQL constraint classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7103
diff
changeset
|
637 |
if 'U' in defined: |
39c1ffc7d93f
[schema, refactoring] use RQLExpression as base class for RQL constraint classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7103
diff
changeset
|
638 |
mainvars.add('U') |
39c1ffc7d93f
[schema, refactoring] use RQLExpression as base class for RQL constraint classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7103
diff
changeset
|
639 |
if not mainvars: |
39c1ffc7d93f
[schema, refactoring] use RQLExpression as base class for RQL constraint classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7103
diff
changeset
|
640 |
raise Exception('unable to guess selection variables') |
39c1ffc7d93f
[schema, refactoring] use RQLExpression as base class for RQL constraint classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7103
diff
changeset
|
641 |
return mainvars |
3964
21387ffb0731
refactor so that we can specify an extra argument to constraints which
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3963
diff
changeset
|
642 |
|
7152
39c1ffc7d93f
[schema, refactoring] use RQLExpression as base class for RQL constraint classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7103
diff
changeset
|
643 |
def split_expression(rqlstring): |
39c1ffc7d93f
[schema, refactoring] use RQLExpression as base class for RQL constraint classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7103
diff
changeset
|
644 |
for expr in rqlstring.split(','): |
7603
1302aa6ba4da
[schema / rql] fix mainvars of RRQLExpression with parens
Florent Cayré <florent.cayre@gmail.com>
parents:
7467
diff
changeset
|
645 |
for noparen1 in expr.split('('): |
1302aa6ba4da
[schema / rql] fix mainvars of RRQLExpression with parens
Florent Cayré <florent.cayre@gmail.com>
parents:
7467
diff
changeset
|
646 |
for noparen2 in noparen1.split(')'): |
1302aa6ba4da
[schema / rql] fix mainvars of RRQLExpression with parens
Florent Cayré <florent.cayre@gmail.com>
parents:
7467
diff
changeset
|
647 |
for word in noparen2.split(): |
1302aa6ba4da
[schema / rql] fix mainvars of RRQLExpression with parens
Florent Cayré <florent.cayre@gmail.com>
parents:
7467
diff
changeset
|
648 |
yield word |
0 | 649 |
|
7152
39c1ffc7d93f
[schema, refactoring] use RQLExpression as base class for RQL constraint classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7103
diff
changeset
|
650 |
def normalize_expression(rqlstring): |
39c1ffc7d93f
[schema, refactoring] use RQLExpression as base class for RQL constraint classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7103
diff
changeset
|
651 |
"""normalize an rql expression to ease schema synchronization (avoid |
39c1ffc7d93f
[schema, refactoring] use RQLExpression as base class for RQL constraint classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7103
diff
changeset
|
652 |
suppressing and reinserting an expression if only a space has been |
39c1ffc7d93f
[schema, refactoring] use RQLExpression as base class for RQL constraint classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7103
diff
changeset
|
653 |
added/removed for instance) |
3978
2c95e3033f64
finish yesterday work on rql constraints:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3968
diff
changeset
|
654 |
""" |
7152
39c1ffc7d93f
[schema, refactoring] use RQLExpression as base class for RQL constraint classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7103
diff
changeset
|
655 |
return u', '.join(' '.join(expr.split()) for expr in rqlstring.split(',')) |
0 | 656 |
|
657 |
||
658 |
class RQLExpression(object): |
|
7152
39c1ffc7d93f
[schema, refactoring] use RQLExpression as base class for RQL constraint classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7103
diff
changeset
|
659 |
"""Base class for RQL expression used in schema (constraints and |
39c1ffc7d93f
[schema, refactoring] use RQLExpression as base class for RQL constraint classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7103
diff
changeset
|
660 |
permissions) |
39c1ffc7d93f
[schema, refactoring] use RQLExpression as base class for RQL constraint classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7103
diff
changeset
|
661 |
""" |
39c1ffc7d93f
[schema, refactoring] use RQLExpression as base class for RQL constraint classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7103
diff
changeset
|
662 |
# these are overridden by set_log_methods below |
39c1ffc7d93f
[schema, refactoring] use RQLExpression as base class for RQL constraint classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7103
diff
changeset
|
663 |
# only defining here to prevent pylint from complaining |
39c1ffc7d93f
[schema, refactoring] use RQLExpression as base class for RQL constraint classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7103
diff
changeset
|
664 |
info = warning = error = critical = exception = debug = lambda msg,*a,**kw: None |
7879
9aae456abab5
[pylint] fix pylint detected errors and tweak it so that pylint -E will be much less verbose next time (+ update some copyrights on the way)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7782
diff
changeset
|
665 |
# to be defined in concrete classes |
9aae456abab5
[pylint] fix pylint detected errors and tweak it so that pylint -E will be much less verbose next time (+ update some copyrights on the way)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7782
diff
changeset
|
666 |
full_rql = None |
7103 | 667 |
|
0 | 668 |
def __init__(self, expression, mainvars, eid): |
669 |
self.eid = eid # eid of the entity representing this rql expression |
|
7152
39c1ffc7d93f
[schema, refactoring] use RQLExpression as base class for RQL constraint classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7103
diff
changeset
|
670 |
assert mainvars, 'bad mainvars %s' % mainvars |
39c1ffc7d93f
[schema, refactoring] use RQLExpression as base class for RQL constraint classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7103
diff
changeset
|
671 |
if isinstance(mainvars, basestring): |
39c1ffc7d93f
[schema, refactoring] use RQLExpression as base class for RQL constraint classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7103
diff
changeset
|
672 |
mainvars = set(splitstrip(mainvars)) |
39c1ffc7d93f
[schema, refactoring] use RQLExpression as base class for RQL constraint classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7103
diff
changeset
|
673 |
elif not isinstance(mainvars, set): |
39c1ffc7d93f
[schema, refactoring] use RQLExpression as base class for RQL constraint classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7103
diff
changeset
|
674 |
mainvars = set(mainvars) |
0 | 675 |
self.mainvars = mainvars |
676 |
self.expression = normalize_expression(expression) |
|
677 |
try: |
|
678 |
self.rqlst = parse(self.full_rql, print_errors=False).children[0] |
|
679 |
except RQLSyntaxError: |
|
680 |
raise RQLSyntaxError(expression) |
|
7152
39c1ffc7d93f
[schema, refactoring] use RQLExpression as base class for RQL constraint classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7103
diff
changeset
|
681 |
for mainvar in mainvars: |
0 | 682 |
if len(self.rqlst.defined_vars[mainvar].references()) <= 2: |
2142
098aa2075903
include_schema_files is useless
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
683 |
_LOGGER.warn('You did not use the %s variable in your RQL ' |
098aa2075903
include_schema_files is useless
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
684 |
'expression %s', mainvar, self) |
3825 | 685 |
# syntax tree used by read security (inserted in queries when necessary) |
3240
8604a15995d1
refactor so that rql rewriter may be used outside the server. Enhance it to be usable for RRQLExpression as well
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2967
diff
changeset
|
686 |
self.snippet_rqlst = parse(self.minimal_rql, print_errors=False).children[0] |
1451 | 687 |
|
0 | 688 |
def __str__(self): |
689 |
return self.full_rql |
|
690 |
def __repr__(self): |
|
691 |
return '%s(%s)' % (self.__class__.__name__, self.full_rql) |
|
1451 | 692 |
|
3877
7ca53fc72a0a
reldefsecurity branch :
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3827
diff
changeset
|
693 |
def __cmp__(self, other): |
7ca53fc72a0a
reldefsecurity branch :
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3827
diff
changeset
|
694 |
if hasattr(other, 'expression'): |
7ca53fc72a0a
reldefsecurity branch :
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3827
diff
changeset
|
695 |
return cmp(other.expression, self.expression) |
4066
0555f170c4d1
__cmp__ should *NOT* return False when different
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4045
diff
changeset
|
696 |
return -1 |
3877
7ca53fc72a0a
reldefsecurity branch :
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3827
diff
changeset
|
697 |
|
0 | 698 |
def __deepcopy__(self, memo): |
699 |
return self.__class__(self.expression, self.mainvars) |
|
700 |
def __getstate__(self): |
|
701 |
return (self.expression, self.mainvars) |
|
702 |
def __setstate__(self, state): |
|
703 |
self.__init__(*state) |
|
1451 | 704 |
|
7152
39c1ffc7d93f
[schema, refactoring] use RQLExpression as base class for RQL constraint classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7103
diff
changeset
|
705 |
# permission rql expression specific stuff ################################# |
39c1ffc7d93f
[schema, refactoring] use RQLExpression as base class for RQL constraint classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7103
diff
changeset
|
706 |
|
0 | 707 |
@cached |
708 |
def transform_has_permission(self): |
|
709 |
found = None |
|
710 |
rqlst = self.rqlst |
|
711 |
for var in rqlst.defined_vars.itervalues(): |
|
712 |
for varref in var.references(): |
|
713 |
rel = varref.relation() |
|
714 |
if rel is None: |
|
715 |
continue |
|
716 |
try: |
|
717 |
prefix, action, suffix = rel.r_type.split('_') |
|
718 |
except ValueError: |
|
719 |
continue |
|
720 |
if prefix != 'has' or suffix != 'permission' or \ |
|
721 |
not action in ('add', 'delete', 'update', 'read'): |
|
722 |
continue |
|
723 |
if found is None: |
|
724 |
found = [] |
|
725 |
rqlst.save_state() |
|
726 |
assert rel.children[0].name == 'U' |
|
727 |
objvar = rel.children[1].children[0].variable |
|
728 |
rqlst.remove_node(rel) |
|
729 |
selected = [v.name for v in rqlst.get_selected_variables()] |
|
730 |
if objvar.name not in selected: |
|
731 |
colindex = len(selected) |
|
732 |
rqlst.add_selected(objvar) |
|
733 |
else: |
|
734 |
colindex = selected.index(objvar.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
|
735 |
found.append((action, colindex)) |
0 | 736 |
# remove U eid %(u)s if U is not used in any other relation |
737 |
uvrefs = rqlst.defined_vars['U'].references() |
|
738 |
if len(uvrefs) == 1: |
|
739 |
rqlst.remove_node(uvrefs[0].relation()) |
|
740 |
if found is not None: |
|
741 |
rql = rqlst.as_string() |
|
742 |
if len(rqlst.selection) == 1 and isinstance(rqlst.where, nodes.Relation): |
|
743 |
# only "Any X WHERE X eid %(x)s" remaining, no need to execute the rql |
|
744 |
keyarg = rqlst.selection[0].name.lower() |
|
745 |
else: |
|
746 |
keyarg = None |
|
747 |
rqlst.recover() |
|
748 |
return rql, found, keyarg |
|
749 |
return rqlst.as_string(), None, None |
|
1451 | 750 |
|
0 | 751 |
def _check(self, session, **kwargs): |
752 |
"""return True if the rql expression is matching the given relation |
|
753 |
between fromeid and toeid |
|
754 |
||
755 |
session may actually be a request as well |
|
756 |
""" |
|
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
|
757 |
creating = kwargs.get('creating') |
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
|
758 |
if not creating and self.eid is not None: |
0 | 759 |
key = (self.eid, tuple(sorted(kwargs.iteritems()))) |
760 |
try: |
|
761 |
return session.local_perm_cache[key] |
|
762 |
except KeyError: |
|
763 |
pass |
|
764 |
rql, has_perm_defs, keyarg = self.transform_has_permission() |
|
5703
24ca7615379b
[security] consider any rql expression refering to X while X is being created as satisfied
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5531
diff
changeset
|
765 |
# when creating an entity, expression related to X satisfied |
24ca7615379b
[security] consider any rql expression refering to X while X is being created as satisfied
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5531
diff
changeset
|
766 |
if creating and 'X' in self.rqlst.defined_vars: |
24ca7615379b
[security] consider any rql expression refering to X while X is being created as satisfied
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5531
diff
changeset
|
767 |
return True |
0 | 768 |
if keyarg is None: |
4619
f4254586e867
[security] allow to call .check on rql expression with a user eid specified
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4608
diff
changeset
|
769 |
kwargs.setdefault('u', session.user.eid) |
0 | 770 |
try: |
5174
78438ad513ca
#759035: Automate addition of eid cachekey in RQL analysis
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5122
diff
changeset
|
771 |
rset = session.execute(rql, kwargs, build_descr=True) |
0 | 772 |
except NotImplementedError: |
773 |
self.critical('cant check rql expression, unsupported rql %s', rql) |
|
774 |
if self.eid is not None: |
|
775 |
session.local_perm_cache[key] = False |
|
776 |
return False |
|
777 |
except TypeResolverException, ex: |
|
778 |
# some expression may not be resolvable with current kwargs |
|
779 |
# (type conflict) |
|
780 |
self.warning('%s: %s', rql, str(ex)) |
|
781 |
if self.eid is not None: |
|
782 |
session.local_perm_cache[key] = False |
|
783 |
return False |
|
5531
0ce62ac0d1d7
catch unauthorized when executing rql to check an rql expression. Fix #968824
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5426
diff
changeset
|
784 |
except Unauthorized, ex: |
0ce62ac0d1d7
catch unauthorized when executing rql to check an rql expression. Fix #968824
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5426
diff
changeset
|
785 |
self.debug('unauthorized %s: %s', rql, str(ex)) |
0ce62ac0d1d7
catch unauthorized when executing rql to check an rql expression. Fix #968824
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5426
diff
changeset
|
786 |
if self.eid is not None: |
0ce62ac0d1d7
catch unauthorized when executing rql to check an rql expression. Fix #968824
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5426
diff
changeset
|
787 |
session.local_perm_cache[key] = False |
0ce62ac0d1d7
catch unauthorized when executing rql to check an rql expression. Fix #968824
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5426
diff
changeset
|
788 |
return False |
0 | 789 |
else: |
790 |
rset = session.eid_rset(kwargs[keyarg]) |
|
791 |
# if no special has_*_permission relation in the rql expression, just |
|
792 |
# check the result set contains something |
|
793 |
if has_perm_defs is None: |
|
794 |
if rset: |
|
795 |
if self.eid is not None: |
|
796 |
session.local_perm_cache[key] = True |
|
797 |
return True |
|
798 |
elif rset: |
|
799 |
# check every special has_*_permission relation is satisfied |
|
800 |
get_eschema = session.vreg.schema.eschema |
|
801 |
try: |
|
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
|
802 |
for eaction, col in has_perm_defs: |
0 | 803 |
for i in xrange(len(rset)): |
804 |
eschema = get_eschema(rset.description[i][col]) |
|
3877
7ca53fc72a0a
reldefsecurity branch :
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3827
diff
changeset
|
805 |
eschema.check_perm(session, eaction, eid=rset[i][col]) |
0 | 806 |
if self.eid is not None: |
807 |
session.local_perm_cache[key] = True |
|
808 |
return True |
|
809 |
except Unauthorized: |
|
810 |
pass |
|
811 |
if self.eid is not None: |
|
812 |
session.local_perm_cache[key] = False |
|
813 |
return False |
|
1451 | 814 |
|
0 | 815 |
@property |
816 |
def minimal_rql(self): |
|
7152
39c1ffc7d93f
[schema, refactoring] use RQLExpression as base class for RQL constraint classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7103
diff
changeset
|
817 |
return 'Any %s WHERE %s' % (','.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
|
818 |
self.expression) |
0 | 819 |
|
7152
39c1ffc7d93f
[schema, refactoring] use RQLExpression as base class for RQL constraint classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7103
diff
changeset
|
820 |
# rql expressions for use in permission definition ############################# |
0 | 821 |
|
822 |
class ERQLExpression(RQLExpression): |
|
823 |
def __init__(self, expression, mainvars=None, eid=None): |
|
824 |
RQLExpression.__init__(self, expression, mainvars or 'X', eid) |
|
825 |
||
826 |
@property |
|
827 |
def full_rql(self): |
|
828 |
rql = self.minimal_rql |
|
829 |
rqlst = getattr(self, 'rqlst', None) # may be not set yet |
|
830 |
if rqlst is not None: |
|
831 |
defined = rqlst.defined_vars |
|
832 |
else: |
|
833 |
defined = set(split_expression(self.expression)) |
|
834 |
if 'X' in defined: |
|
835 |
rql += ', X eid %(x)s' |
|
836 |
if 'U' in defined: |
|
837 |
rql += ', U eid %(u)s' |
|
838 |
return rql |
|
1451 | 839 |
|
4619
f4254586e867
[security] allow to call .check on rql expression with a user eid specified
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4608
diff
changeset
|
840 |
def check(self, session, eid=None, creating=False, **kwargs): |
0 | 841 |
if 'X' in self.rqlst.defined_vars: |
842 |
if eid is None: |
|
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
|
843 |
if creating: |
4619
f4254586e867
[security] allow to call .check on rql expression with a user eid specified
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4608
diff
changeset
|
844 |
return self._check(session, creating=True, **kwargs) |
0 | 845 |
return False |
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
|
846 |
assert creating == False |
4619
f4254586e867
[security] allow to call .check on rql expression with a user eid specified
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4608
diff
changeset
|
847 |
return self._check(session, x=eid, **kwargs) |
f4254586e867
[security] allow to call .check on rql expression with a user eid specified
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4608
diff
changeset
|
848 |
return self._check(session, **kwargs) |
1451 | 849 |
|
3961
d1cbf77db999
fix RQLUniqueConstraint behaviour by using a DISTINCT query and allowing
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3827
diff
changeset
|
850 |
|
7973
64639bc94e25
[entity] restrict creation form field vocabulary using __linkto information (closes #1799997)
Florent Cayré <florent.cayre@gmail.com>
parents:
7951
diff
changeset
|
851 |
def vargraph(rqlst): |
64639bc94e25
[entity] restrict creation form field vocabulary using __linkto information (closes #1799997)
Florent Cayré <florent.cayre@gmail.com>
parents:
7951
diff
changeset
|
852 |
""" builds an adjacency graph of variables from the rql syntax tree, e.g: |
64639bc94e25
[entity] restrict creation form field vocabulary using __linkto information (closes #1799997)
Florent Cayré <florent.cayre@gmail.com>
parents:
7951
diff
changeset
|
853 |
Any O,S WHERE T subworkflow_exit S, T subworkflow WF, O state_of WF |
64639bc94e25
[entity] restrict creation form field vocabulary using __linkto information (closes #1799997)
Florent Cayré <florent.cayre@gmail.com>
parents:
7951
diff
changeset
|
854 |
=> {'WF': ['O', 'T'], 'S': ['T'], 'T': ['WF', 'S'], 'O': ['WF']} |
64639bc94e25
[entity] restrict creation form field vocabulary using __linkto information (closes #1799997)
Florent Cayré <florent.cayre@gmail.com>
parents:
7951
diff
changeset
|
855 |
""" |
64639bc94e25
[entity] restrict creation form field vocabulary using __linkto information (closes #1799997)
Florent Cayré <florent.cayre@gmail.com>
parents:
7951
diff
changeset
|
856 |
vargraph = {} |
64639bc94e25
[entity] restrict creation form field vocabulary using __linkto information (closes #1799997)
Florent Cayré <florent.cayre@gmail.com>
parents:
7951
diff
changeset
|
857 |
for relation in rqlst.get_nodes(nodes.Relation): |
64639bc94e25
[entity] restrict creation form field vocabulary using __linkto information (closes #1799997)
Florent Cayré <florent.cayre@gmail.com>
parents:
7951
diff
changeset
|
858 |
try: |
64639bc94e25
[entity] restrict creation form field vocabulary using __linkto information (closes #1799997)
Florent Cayré <florent.cayre@gmail.com>
parents:
7951
diff
changeset
|
859 |
rhsvarname = relation.children[1].children[0].variable.name |
64639bc94e25
[entity] restrict creation form field vocabulary using __linkto information (closes #1799997)
Florent Cayré <florent.cayre@gmail.com>
parents:
7951
diff
changeset
|
860 |
lhsvarname = relation.children[0].name |
64639bc94e25
[entity] restrict creation form field vocabulary using __linkto information (closes #1799997)
Florent Cayré <florent.cayre@gmail.com>
parents:
7951
diff
changeset
|
861 |
except AttributeError: |
64639bc94e25
[entity] restrict creation form field vocabulary using __linkto information (closes #1799997)
Florent Cayré <florent.cayre@gmail.com>
parents:
7951
diff
changeset
|
862 |
pass |
64639bc94e25
[entity] restrict creation form field vocabulary using __linkto information (closes #1799997)
Florent Cayré <florent.cayre@gmail.com>
parents:
7951
diff
changeset
|
863 |
else: |
64639bc94e25
[entity] restrict creation form field vocabulary using __linkto information (closes #1799997)
Florent Cayré <florent.cayre@gmail.com>
parents:
7951
diff
changeset
|
864 |
vargraph.setdefault(lhsvarname, []).append(rhsvarname) |
64639bc94e25
[entity] restrict creation form field vocabulary using __linkto information (closes #1799997)
Florent Cayré <florent.cayre@gmail.com>
parents:
7951
diff
changeset
|
865 |
vargraph.setdefault(rhsvarname, []).append(lhsvarname) |
64639bc94e25
[entity] restrict creation form field vocabulary using __linkto information (closes #1799997)
Florent Cayré <florent.cayre@gmail.com>
parents:
7951
diff
changeset
|
866 |
#vargraph[(lhsvarname, rhsvarname)] = relation.r_type |
64639bc94e25
[entity] restrict creation form field vocabulary using __linkto information (closes #1799997)
Florent Cayré <florent.cayre@gmail.com>
parents:
7951
diff
changeset
|
867 |
return vargraph |
64639bc94e25
[entity] restrict creation form field vocabulary using __linkto information (closes #1799997)
Florent Cayré <florent.cayre@gmail.com>
parents:
7951
diff
changeset
|
868 |
|
64639bc94e25
[entity] restrict creation form field vocabulary using __linkto information (closes #1799997)
Florent Cayré <florent.cayre@gmail.com>
parents:
7951
diff
changeset
|
869 |
|
64639bc94e25
[entity] restrict creation form field vocabulary using __linkto information (closes #1799997)
Florent Cayré <florent.cayre@gmail.com>
parents:
7951
diff
changeset
|
870 |
class GeneratedConstraint(object): |
64639bc94e25
[entity] restrict creation form field vocabulary using __linkto information (closes #1799997)
Florent Cayré <florent.cayre@gmail.com>
parents:
7951
diff
changeset
|
871 |
def __init__(self, rqlst, mainvars): |
64639bc94e25
[entity] restrict creation form field vocabulary using __linkto information (closes #1799997)
Florent Cayré <florent.cayre@gmail.com>
parents:
7951
diff
changeset
|
872 |
self.snippet_rqlst = rqlst |
64639bc94e25
[entity] restrict creation form field vocabulary using __linkto information (closes #1799997)
Florent Cayré <florent.cayre@gmail.com>
parents:
7951
diff
changeset
|
873 |
self.mainvars = mainvars |
64639bc94e25
[entity] restrict creation form field vocabulary using __linkto information (closes #1799997)
Florent Cayré <florent.cayre@gmail.com>
parents:
7951
diff
changeset
|
874 |
self.vargraph = vargraph(rqlst) |
64639bc94e25
[entity] restrict creation form field vocabulary using __linkto information (closes #1799997)
Florent Cayré <florent.cayre@gmail.com>
parents:
7951
diff
changeset
|
875 |
|
64639bc94e25
[entity] restrict creation form field vocabulary using __linkto information (closes #1799997)
Florent Cayré <florent.cayre@gmail.com>
parents:
7951
diff
changeset
|
876 |
|
0 | 877 |
class RRQLExpression(RQLExpression): |
878 |
def __init__(self, expression, mainvars=None, eid=None): |
|
879 |
if mainvars is None: |
|
3961
d1cbf77db999
fix RQLUniqueConstraint behaviour by using a DISTINCT query and allowing
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3827
diff
changeset
|
880 |
mainvars = guess_rrqlexpr_mainvars(expression) |
0 | 881 |
RQLExpression.__init__(self, expression, mainvars, eid) |
3827 | 882 |
# graph of links between variable, used by rql rewriter |
7973
64639bc94e25
[entity] restrict creation form field vocabulary using __linkto information (closes #1799997)
Florent Cayré <florent.cayre@gmail.com>
parents:
7951
diff
changeset
|
883 |
self.vargraph = vargraph(self.rqlst) |
0 | 884 |
|
885 |
@property |
|
886 |
def full_rql(self): |
|
887 |
rql = self.minimal_rql |
|
888 |
rqlst = getattr(self, 'rqlst', None) # may be not set yet |
|
889 |
if rqlst is not None: |
|
890 |
defined = rqlst.defined_vars |
|
891 |
else: |
|
892 |
defined = set(split_expression(self.expression)) |
|
893 |
if 'S' in defined: |
|
894 |
rql += ', S eid %(s)s' |
|
895 |
if 'O' in defined: |
|
896 |
rql += ', O eid %(o)s' |
|
897 |
if 'U' in defined: |
|
898 |
rql += ', U eid %(u)s' |
|
899 |
return rql |
|
1451 | 900 |
|
0 | 901 |
def check(self, session, fromeid=None, toeid=None): |
902 |
kwargs = {} |
|
903 |
if 'S' in self.rqlst.defined_vars: |
|
904 |
if fromeid is None: |
|
905 |
return False |
|
906 |
kwargs['s'] = fromeid |
|
907 |
if 'O' in self.rqlst.defined_vars: |
|
908 |
if toeid is None: |
|
909 |
return False |
|
910 |
kwargs['o'] = toeid |
|
911 |
return self._check(session, **kwargs) |
|
1451 | 912 |
|
7152
39c1ffc7d93f
[schema, refactoring] use RQLExpression as base class for RQL constraint classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7103
diff
changeset
|
913 |
|
4570
ede247bbbf62
follow yams api change: attributes permissions are now defined for
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4466
diff
changeset
|
914 |
# in yams, default 'update' perm for attributes granted to managers and owners. |
ede247bbbf62
follow yams api change: attributes permissions are now defined for
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4466
diff
changeset
|
915 |
# Within cw, we want to default to users who may edit the entity holding the |
ede247bbbf62
follow yams api change: attributes permissions are now defined for
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4466
diff
changeset
|
916 |
# attribute. |
4586
440e340c61fe
DEFAULT_ATTRPERMS is now public
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4575
diff
changeset
|
917 |
ybo.DEFAULT_ATTRPERMS['update'] = ( |
4570
ede247bbbf62
follow yams api change: attributes permissions are now defined for
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4466
diff
changeset
|
918 |
'managers', ERQLExpression('U has_update_permission X')) |
0 | 919 |
|
7152
39c1ffc7d93f
[schema, refactoring] use RQLExpression as base class for RQL constraint classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7103
diff
changeset
|
920 |
# 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
|
921 |
|
39c1ffc7d93f
[schema, refactoring] use RQLExpression as base class for RQL constraint classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7103
diff
changeset
|
922 |
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
|
923 |
"""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
|
924 |
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
|
925 |
|
39c1ffc7d93f
[schema, refactoring] use RQLExpression as base class for RQL constraint classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7103
diff
changeset
|
926 |
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
|
927 |
# start with a comma 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
|
928 |
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
|
929 |
|
39c1ffc7d93f
[schema, refactoring] use RQLExpression as base class for RQL constraint classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7103
diff
changeset
|
930 |
@classmethod |
39c1ffc7d93f
[schema, refactoring] use RQLExpression as base class for RQL constraint classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7103
diff
changeset
|
931 |
def deserialize(cls, value): |
8027
9ac82788f67b
[schema, old instance] restore some pre 3.5.10 bw compat as some old instances may still have this, and add migration so we can remove it at some point
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7990
diff
changeset
|
932 |
# XXX < 3.5.10 bw compat |
9ac82788f67b
[schema, old instance] restore some pre 3.5.10 bw compat as some old instances may still have this, and add migration so we can remove it at some point
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7990
diff
changeset
|
933 |
if not value.startswith(';'): |
9ac82788f67b
[schema, old instance] restore some pre 3.5.10 bw compat as some old instances may still have this, and add migration so we can remove it at some point
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7990
diff
changeset
|
934 |
return cls(value) |
7152
39c1ffc7d93f
[schema, refactoring] use RQLExpression as base class for RQL constraint classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7103
diff
changeset
|
935 |
_, 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
|
936 |
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
|
937 |
|
39c1ffc7d93f
[schema, refactoring] use RQLExpression as base class for RQL constraint classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7103
diff
changeset
|
938 |
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
|
939 |
"""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
|
940 |
# 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
|
941 |
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
|
942 |
|
39c1ffc7d93f
[schema, refactoring] use RQLExpression as base class for RQL constraint classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7103
diff
changeset
|
943 |
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
|
944 |
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
|
945 |
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
|
946 |
else: |
39c1ffc7d93f
[schema, refactoring] use RQLExpression as base class for RQL constraint classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7103
diff
changeset
|
947 |
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
|
948 |
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
|
949 |
','.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
|
950 |
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
|
951 |
|
39c1ffc7d93f
[schema, refactoring] use RQLExpression as base class for RQL constraint classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7103
diff
changeset
|
952 |
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
|
953 |
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
|
954 |
|
39c1ffc7d93f
[schema, refactoring] use RQLExpression as base class for RQL constraint classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7103
diff
changeset
|
955 |
|
39c1ffc7d93f
[schema, refactoring] use RQLExpression as base class for RQL constraint classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7103
diff
changeset
|
956 |
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
|
957 |
"""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
|
958 |
|
39c1ffc7d93f
[schema, refactoring] use RQLExpression as base class for RQL constraint classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7103
diff
changeset
|
959 |
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
|
960 |
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
|
961 |
|
39c1ffc7d93f
[schema, refactoring] use RQLExpression as base class for RQL constraint classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7103
diff
changeset
|
962 |
`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
|
963 |
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
|
964 |
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
|
965 |
|
39c1ffc7d93f
[schema, refactoring] use RQLExpression as base class for RQL constraint classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7103
diff
changeset
|
966 |
`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
|
967 |
(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
|
968 |
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
|
969 |
""" |
39c1ffc7d93f
[schema, refactoring] use RQLExpression as base class for RQL constraint classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7103
diff
changeset
|
970 |
|
39c1ffc7d93f
[schema, refactoring] use RQLExpression as base class for RQL constraint classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7103
diff
changeset
|
971 |
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
|
972 |
"""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
|
973 |
""" |
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
|
974 |
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
|
975 |
|
39c1ffc7d93f
[schema, refactoring] use RQLExpression as base class for RQL constraint classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7103
diff
changeset
|
976 |
|
39c1ffc7d93f
[schema, refactoring] use RQLExpression as base class for RQL constraint classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7103
diff
changeset
|
977 |
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
|
978 |
|
39c1ffc7d93f
[schema, refactoring] use RQLExpression as base class for RQL constraint classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7103
diff
changeset
|
979 |
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
|
980 |
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
|
981 |
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
|
982 |
|
39c1ffc7d93f
[schema, refactoring] use RQLExpression as base class for RQL constraint classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7103
diff
changeset
|
983 |
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
|
984 |
# 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
|
985 |
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
|
986 |
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
|
987 |
|
39c1ffc7d93f
[schema, refactoring] use RQLExpression as base class for RQL constraint classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7103
diff
changeset
|
988 |
def deserialize(cls, value): |
8027
9ac82788f67b
[schema, old instance] restore some pre 3.5.10 bw compat as some old instances may still have this, and add migration so we can remove it at some point
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7990
diff
changeset
|
989 |
# XXX < 3.5.10 bw compat |
9ac82788f67b
[schema, old instance] restore some pre 3.5.10 bw compat as some old instances may still have this, and add migration so we can remove it at some point
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7990
diff
changeset
|
990 |
if not value.startswith(';'): |
9ac82788f67b
[schema, old instance] restore some pre 3.5.10 bw compat as some old instances may still have this, and add migration so we can remove it at some point
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7990
diff
changeset
|
991 |
return cls(value) |
7152
39c1ffc7d93f
[schema, refactoring] use RQLExpression as base class for RQL constraint classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7103
diff
changeset
|
992 |
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
|
993 |
_, 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
|
994 |
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
|
995 |
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
|
996 |
|
39c1ffc7d93f
[schema, refactoring] use RQLExpression as base class for RQL constraint classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7103
diff
changeset
|
997 |
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
|
998 |
"""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
|
999 |
""" |
39c1ffc7d93f
[schema, refactoring] use RQLExpression as base class for RQL constraint classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7103
diff
changeset
|
1000 |
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
|
1001 |
# 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
|
1002 |
# 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
|
1003 |
# 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
|
1004 |
# |
39c1ffc7d93f
[schema, refactoring] use RQLExpression as base class for RQL constraint classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7103
diff
changeset
|
1005 |
# 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
|
1006 |
# 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
|
1007 |
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
|
1008 |
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
|
1009 |
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
|
1010 |
else: |
39c1ffc7d93f
[schema, refactoring] use RQLExpression as base class for RQL constraint classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7103
diff
changeset
|
1011 |
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
|
1012 |
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
|
1013 |
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
|
1014 |
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
|
1015 |
else: |
39c1ffc7d93f
[schema, refactoring] use RQLExpression as base class for RQL constraint classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7103
diff
changeset
|
1016 |
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
|
1017 |
'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
|
1018 |
'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
|
1019 |
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
|
1020 |
|
39c1ffc7d93f
[schema, refactoring] use RQLExpression as base class for RQL constraint classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7103
diff
changeset
|
1021 |
def exec_query(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
|
1022 |
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
|
1023 |
# 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
|
1024 |
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
|
1025 |
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
|
1026 |
else: |
39c1ffc7d93f
[schema, refactoring] use RQLExpression as base class for RQL constraint classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7103
diff
changeset
|
1027 |
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
|
1028 |
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
|
1029 |
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
|
1030 |
expression = 'U eid %(u)s, ' + expression |
85ebdbbcb321
[schema] closes #1816439: RQLConstraint does not take variable U into account
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7603
diff
changeset
|
1031 |
args['u'] = session.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
|
1032 |
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
|
1033 |
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
|
1034 |
rql = 'DISTINCT ' + rql |
39c1ffc7d93f
[schema, refactoring] use RQLExpression as base class for RQL constraint classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7103
diff
changeset
|
1035 |
return session.execute(rql, args, build_descr=False) |
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 |
|
39c1ffc7d93f
[schema, refactoring] use RQLExpression as base class for RQL constraint classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7103
diff
changeset
|
1038 |
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
|
1039 |
"""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
|
1040 |
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
|
1041 |
""" |
39c1ffc7d93f
[schema, refactoring] use RQLExpression as base class for RQL constraint classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7103
diff
changeset
|
1042 |
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
|
1043 |
|
39c1ffc7d93f
[schema, refactoring] use RQLExpression as base class for RQL constraint classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7103
diff
changeset
|
1044 |
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
|
1045 |
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
|
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 |
|
39c1ffc7d93f
[schema, refactoring] use RQLExpression as base class for RQL constraint classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7103
diff
changeset
|
1048 |
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
|
1049 |
"""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
|
1050 |
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
|
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 |
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
|
1053 |
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
|
1054 |
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
|
1055 |
""" |
39c1ffc7d93f
[schema, refactoring] use RQLExpression as base class for RQL constraint classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7103
diff
changeset
|
1056 |
# 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
|
1057 |
distinct_query = True |
39c1ffc7d93f
[schema, refactoring] use RQLExpression as base class for RQL constraint classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7103
diff
changeset
|
1058 |
|
39c1ffc7d93f
[schema, refactoring] use RQLExpression as base class for RQL constraint classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7103
diff
changeset
|
1059 |
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
|
1060 |
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
|
1061 |
|
39c1ffc7d93f
[schema, refactoring] use RQLExpression as base class for RQL constraint classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7103
diff
changeset
|
1062 |
|
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
|
1063 |
# 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
|
1064 |
|
2460
ce1a7ffc6c90
fix a couple NameErrors
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
2459
diff
changeset
|
1065 |
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
|
1066 |
|
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
|
1067 |
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
|
1068 |
"""extends default EntityType's metaclass to add workflow relations |
5378
0f54a0e128ac
[schema] cleanup
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5372
diff
changeset
|
1069 |
(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
|
1070 |
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
|
1071 |
""" |
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
|
1072 |
def __new__(mcs, name, bases, classdict): |
2920
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2782
diff
changeset
|
1073 |
abstract = classdict.pop('__abstract__', False) |
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2782
diff
changeset
|
1074 |
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
|
1075 |
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
|
1076 |
if not abstract: |
2920
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2782
diff
changeset
|
1077 |
make_workflowable(cls) |
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2782
diff
changeset
|
1078 |
return cls |
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2782
diff
changeset
|
1079 |
|
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
|
1080 |
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
|
1081 |
"""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
|
1082 |
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
|
1083 |
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
|
1084 |
""" |
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
|
1085 |
__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
|
1086 |
__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
|
1087 |
|
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
|
1088 |
|
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
|
1089 |
def make_workflowable(cls, in_state_descr=None): |
5378
0f54a0e128ac
[schema] cleanup
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5372
diff
changeset
|
1090 |
"""Adds workflow relations as :class:`WorkflowableEntityType`, but usable on |
0f54a0e128ac
[schema] cleanup
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5372
diff
changeset
|
1091 |
existing classes which are not using that base class. |
0f54a0e128ac
[schema] cleanup
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5372
diff
changeset
|
1092 |
""" |
2920
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2782
diff
changeset
|
1093 |
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
|
1094 |
# 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
|
1095 |
# 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
|
1096 |
etype = getattr(cls, 'name', cls.__name__) |
2920
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2782
diff
changeset
|
1097 |
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
|
1098 |
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
|
1099 |
yams_add_relation(cls.__relations__, rdef) |
2920
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2782
diff
changeset
|
1100 |
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
|
1101 |
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
|
1102 |
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
|
1103 |
yams_add_relation(cls.__relations__, rdef) |
2920
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2782
diff
changeset
|
1104 |
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
|
1105 |
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
|
1106 |
yams_add_relation(cls.__relations__, rdef) |
1451 | 1107 |
|
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
|
1108 |
|
0 | 1109 |
# schema loading ############################################################## |
1110 |
||
1111 |
CONSTRAINTS['RQLConstraint'] = RQLConstraint |
|
1112 |
CONSTRAINTS['RQLUniqueConstraint'] = RQLUniqueConstraint |
|
1113 |
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
|
1114 |
CONSTRAINTS.pop('MultipleStaticVocabularyConstraint', None) # don't want this in cw yams schema |
0 | 1115 |
PyFileReader.context.update(CONSTRAINTS) |
1116 |
||
1117 |
||
1118 |
class BootstrapSchemaLoader(SchemaLoader): |
|
1119 |
"""cubicweb specific schema loader, loading only schema necessary to read |
|
1120 |
the persistent schema |
|
1121 |
""" |
|
1122 |
schemacls = CubicWebSchema |
|
1123 |
||
1034
0356bbfb2f26
fix to pass arguments to base class
sylvain.thenault@logilab.fr
parents:
1016
diff
changeset
|
1124 |
def load(self, config, path=(), **kwargs): |
0 | 1125 |
"""return a Schema instance from the schema definition read |
1126 |
from <directory> |
|
1127 |
""" |
|
1128 |
return super(BootstrapSchemaLoader, self).load( |
|
1034
0356bbfb2f26
fix to pass arguments to base class
sylvain.thenault@logilab.fr
parents:
1016
diff
changeset
|
1129 |
path, config.appid, register_base_types=False, **kwargs) |
1451 | 1130 |
|
0 | 1131 |
def _load_definition_files(self, cubes=None): |
1132 |
# bootstraping, ignore cubes |
|
2735
39c942241b48
no need for lib_directory
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2730
diff
changeset
|
1133 |
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
|
1134 |
self.info('loading %s', filepath) |
098aa2075903
include_schema_files is useless
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
1135 |
self.handle_file(filepath) |
1451 | 1136 |
|
0 | 1137 |
def unhandled_file(self, filepath): |
1138 |
"""called when a file without handler associated has been found""" |
|
1139 |
self.warning('ignoring file %r', filepath) |
|
1140 |
||
7083
b8e35cde46e9
help pylint by explicitely defining some attributes
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
6861
diff
changeset
|
1141 |
# 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
|
1142 |
# 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
|
1143 |
info = warning = error = critical = exception = debug = lambda msg,*a,**kw: None |
0 | 1144 |
|
1145 |
class CubicWebSchemaLoader(BootstrapSchemaLoader): |
|
1146 |
"""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
|
1147 |
instance's schema |
0 | 1148 |
""" |
1149 |
||
1034
0356bbfb2f26
fix to pass arguments to base class
sylvain.thenault@logilab.fr
parents:
1016
diff
changeset
|
1150 |
def load(self, config, **kwargs): |
0 | 1151 |
"""return a Schema instance from the schema definition read |
1152 |
from <directory> |
|
1153 |
""" |
|
1154 |
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
|
1155 |
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
|
1156 |
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
|
1157 |
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
|
1158 |
self.extrapath[cubesdir] = 'cubes' |
372
a8a975a88368
check apphome is not None
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
0
diff
changeset
|
1159 |
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
|
1160 |
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
|
1161 |
else: |
2598
a66fe74bd9fc
[R schema] dont give an iterator, it's a trap
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2596
diff
changeset
|
1162 |
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
|
1163 |
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
|
1164 |
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
|
1165 |
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
|
1166 |
# 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
|
1167 |
cleanup_sys_modules([join(cubicweb.CW_SOFTWARE_ROOT, 'schemas')]) |
0 | 1168 |
|
1169 |
def _load_definition_files(self, cubes): |
|
2741
148d0cea1fb5
[schema] oops
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2736
diff
changeset
|
1170 |
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
|
1171 |
join(cubicweb.CW_SOFTWARE_ROOT, 'schemas', 'base.py'), |
148d0cea1fb5
[schema] oops
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2736
diff
changeset
|
1172 |
join(cubicweb.CW_SOFTWARE_ROOT, 'schemas', 'workflow.py'), |
148d0cea1fb5
[schema] oops
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2736
diff
changeset
|
1173 |
join(cubicweb.CW_SOFTWARE_ROOT, 'schemas', 'Bookmark.py')): |
0 | 1174 |
self.info('loading %s', filepath) |
1175 |
self.handle_file(filepath) |
|
1176 |
for cube in cubes: |
|
1177 |
for filepath in self.get_schema_files(cube): |
|
1178 |
self.info('loading %s', filepath) |
|
1179 |
self.handle_file(filepath) |
|
1180 |
||
7083
b8e35cde46e9
help pylint by explicitely defining some attributes
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
6861
diff
changeset
|
1181 |
# 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
|
1182 |
# 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
|
1183 |
info = warning = error = critical = exception = debug = lambda msg,*a,**kw: None |
0 | 1184 |
|
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
|
1185 |
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
|
1186 |
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
|
1187 |
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
|
1188 |
|
0 | 1189 |
# _() is just there to add messages to the catalog, don't care about actual |
1190 |
# translation |
|
7797
a71618a75b53
backport stable
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7782
diff
changeset
|
1191 |
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
|
1192 |
NEED_PERM_FORMATS = [_('text/cubicweb-page-template')] |
0 | 1193 |
|
2531
531ea4e7013e
[cleanup] nicer imports
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
2526
diff
changeset
|
1194 |
@monkeypatch(FormatConstraint) |
3347
428f95118556
fix vocab param to avoid deprecation warning
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3287
diff
changeset
|
1195 |
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
|
1196 |
cw = None |
3347
428f95118556
fix vocab param to avoid deprecation warning
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3287
diff
changeset
|
1197 |
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
|
1198 |
cw = entity._cw |
3347
428f95118556
fix vocab param to avoid deprecation warning
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3287
diff
changeset
|
1199 |
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
|
1200 |
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
|
1201 |
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
|
1202 |
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
|
1203 |
# 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
|
1204 |
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
|
1205 |
not cw.is_hook_category_activated('integrity') or \ |
7797
a71618a75b53
backport stable
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7782
diff
changeset
|
1206 |
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
|
1207 |
else: |
7797
a71618a75b53
backport stable
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7782
diff
changeset
|
1208 |
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
|
1209 |
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
|
1210 |
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
|
1211 |
return self.regular_formats |
0 | 1212 |
|
1213 |
# XXX monkey patch PyFileReader.import_erschema until bw_normalize_etype is |
|
1214 |
# necessary |
|
1215 |
orig_import_erschema = PyFileReader.import_erschema |
|
1216 |
def bw_import_erschema(self, ertype, schemamod=None, instantiate=True): |
|
1217 |
return orig_import_erschema(self, bw_normalize_etype(ertype), schemamod, instantiate) |
|
1218 |
PyFileReader.import_erschema = bw_import_erschema |
|
1451 | 1219 |
|
0 | 1220 |
# XXX itou for some Statement methods |
1221 |
from rql import stmts |
|
1222 |
orig_get_etype = stmts.ScopeNode.get_etype |
|
1223 |
def bw_get_etype(self, name): |
|
1224 |
return orig_get_etype(self, bw_normalize_etype(name)) |
|
1225 |
stmts.ScopeNode.get_etype = bw_get_etype |
|
1226 |
||
1227 |
orig_add_main_variable_delete = stmts.Delete.add_main_variable |
|
1228 |
def bw_add_main_variable_delete(self, etype, vref): |
|
1229 |
return orig_add_main_variable_delete(self, bw_normalize_etype(etype), vref) |
|
1230 |
stmts.Delete.add_main_variable = bw_add_main_variable_delete |
|
1231 |
||
1232 |
orig_add_main_variable_insert = stmts.Insert.add_main_variable |
|
1233 |
def bw_add_main_variable_insert(self, etype, vref): |
|
1234 |
return orig_add_main_variable_insert(self, bw_normalize_etype(etype), vref) |
|
1235 |
stmts.Insert.add_main_variable = bw_add_main_variable_insert |
|
1236 |
||
1237 |
orig_set_statement_type = stmts.Select.set_statement_type |
|
1238 |
def bw_set_statement_type(self, etype): |
|
1239 |
return orig_set_statement_type(self, bw_normalize_etype(etype)) |
|
1240 |
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
|
1241 |
|
c5048502409f
restore backward compat, still imported a lot
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2735
diff
changeset
|
1242 |
# XXX deprecated |
3978
2c95e3033f64
finish yesterday work on rql constraints:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3968
diff
changeset
|
1243 |
|
2736
c5048502409f
restore backward compat, still imported a lot
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2735
diff
changeset
|
1244 |
from yams.buildobjs import 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
|
1245 |
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
|
1246 |
|
535705688f4f
proper deprecation warning when import class that should be imported from yams
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4702
diff
changeset
|
1247 |
RichString = class_moved(RichString) |
535705688f4f
proper deprecation warning when import class that should be imported from yams
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4702
diff
changeset
|
1248 |
|
535705688f4f
proper deprecation warning when import class that should be imported from yams
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4702
diff
changeset
|
1249 |
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
|
1250 |
FormatConstraint = class_moved(FormatConstraint) |
3978
2c95e3033f64
finish yesterday work on rql constraints:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3968
diff
changeset
|
1251 |
|
2c95e3033f64
finish yesterday work on rql constraints:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3968
diff
changeset
|
1252 |
PyFileReader.context['ERQLExpression'] = yobsolete(ERQLExpression) |
2c95e3033f64
finish yesterday work on rql constraints:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3968
diff
changeset
|
1253 |
PyFileReader.context['RRQLExpression'] = yobsolete(RRQLExpression) |
2c95e3033f64
finish yesterday work on rql constraints:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3968
diff
changeset
|
1254 |
PyFileReader.context['WorkflowableEntityType'] = WorkflowableEntityType |