author | Sylvain Thénault <sylvain.thenault@logilab.fr> |
Tue, 23 Jun 2009 13:36:38 +0200 | |
changeset 2144 | 51c84d585456 |
parent 2140 | 1cba3393ba01 |
child 2297 | 4cf57dd80650 |
permissions | -rw-r--r-- |
0 | 1 |
"""core CubicWeb schema, but not necessary at bootstrap time |
2 |
||
3 |
:organization: Logilab |
|
1977
606923dff11b
big bunch of copyright / docstring update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1742
diff
changeset
|
4 |
:copyright: 2001-2009 LOGILAB S.A. (Paris, FRANCE), license is LGPL v2. |
0 | 5 |
:contact: http://www.logilab.fr/ -- mailto:contact@logilab.fr |
1977
606923dff11b
big bunch of copyright / docstring update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1742
diff
changeset
|
6 |
:license: GNU Lesser General Public License, v2.1 - http://www.gnu.org/licenses |
0 | 7 |
""" |
8 |
__docformat__ = "restructuredtext en" |
|
2140
1cba3393ba01
update schema definition to avoid deprecation warning with new yams api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
9 |
_ = unicode |
0 | 10 |
|
2140
1cba3393ba01
update schema definition to avoid deprecation warning with new yams api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
11 |
from yams.buildobjs import (EntityType, RelationType, SubjectRelation, |
1cba3393ba01
update schema definition to avoid deprecation warning with new yams api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
12 |
String, Boolean, Datetime) |
1cba3393ba01
update schema definition to avoid deprecation warning with new yams api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
13 |
from cubicweb.schema import RQLConstraint |
1cba3393ba01
update schema definition to avoid deprecation warning with new yams api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
14 |
from cubicweb.schemas import META_ETYPE_PERMS, META_RTYPE_PERMS |
0 | 15 |
|
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1303
diff
changeset
|
16 |
class CWUser(WorkflowableEntityType): |
0 | 17 |
"""define a CubicWeb user""" |
18 |
permissions = { |
|
19 |
'read': ('managers', 'users', ERQLExpression('X identity U')), |
|
20 |
'add': ('managers',), |
|
21 |
'delete': ('managers',), |
|
22 |
'update': ('managers', ERQLExpression('X identity U, NOT U in_group G, G name "guests"'),), |
|
23 |
} |
|
24 |
||
25 |
login = String(required=True, unique=True, maxsize=64, |
|
26 |
description=_('unique identifier used to connect to the application')) |
|
27 |
upassword = Password(required=True) # password is a reserved word for mysql |
|
28 |
firstname = String(maxsize=64) |
|
29 |
surname = String(maxsize=64) |
|
30 |
last_login_time = Datetime(description=_('last connection date')) |
|
31 |
# allowing an email to be the primary email of multiple entities is necessary for |
|
1451 | 32 |
# test at least :-/ |
0 | 33 |
primary_email = SubjectRelation('EmailAddress', cardinality='??', |
34 |
description=_('email address to use for notification')) |
|
35 |
use_email = SubjectRelation('EmailAddress', cardinality='*?', composite='subject') |
|
36 |
||
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1303
diff
changeset
|
37 |
in_group = SubjectRelation('CWGroup', cardinality='+*', |
0 | 38 |
constraints=[RQLConstraint('NOT O name "owners"')], |
39 |
description=_('groups grant permissions to the user')) |
|
40 |
||
41 |
||
2140
1cba3393ba01
update schema definition to avoid deprecation warning with new yams api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
42 |
class EmailAddress(EntityType): |
0 | 43 |
"""an electronic mail address associated to a short alias""" |
44 |
permissions = { |
|
45 |
'read': ('managers', 'users', 'guests',), # XXX if P use_email X, U has_read_permission P |
|
46 |
'add': ('managers', 'users',), |
|
47 |
'delete': ('managers', 'owners', ERQLExpression('P use_email X, U has_update_permission P')), |
|
48 |
'update': ('managers', 'owners', ERQLExpression('P use_email X, U has_update_permission P')), |
|
49 |
} |
|
1451 | 50 |
|
0 | 51 |
alias = String(fulltextindexed=True, maxsize=56) |
1451 | 52 |
address = String(required=True, fulltextindexed=True, |
0 | 53 |
indexed=True, unique=True, maxsize=128) |
54 |
canonical = Boolean(default=False, |
|
55 |
description=_('when multiple addresses are equivalent \ |
|
56 |
(such as python-projects@logilab.org and python-projects@lists.logilab.org), set this \ |
|
57 |
to true on one of them which is the preferred form.')) |
|
58 |
identical_to = SubjectRelation('EmailAddress') |
|
59 |
||
60 |
class use_email(RelationType): |
|
1742
25a765e756c4
fix self on initfunc
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
1477
diff
changeset
|
61 |
""" """ |
0 | 62 |
permissions = { |
63 |
'read': ('managers', 'users', 'guests',), |
|
64 |
'add': ('managers', RRQLExpression('U has_update_permission S'),), |
|
65 |
'delete': ('managers', RRQLExpression('U has_update_permission S'),), |
|
66 |
} |
|
67 |
fulltext_container = 'subject' |
|
68 |
||
69 |
class primary_email(RelationType): |
|
70 |
"""the prefered email""" |
|
71 |
permissions = use_email.permissions |
|
1451 | 72 |
|
0 | 73 |
class identical_to(RelationType): |
74 |
"""identical_to""" |
|
75 |
symetric = True |
|
76 |
permissions = { |
|
77 |
'read': ('managers', 'users', 'guests',), |
|
78 |
# XXX should have update permissions on both subject and object, |
|
79 |
# though by doing this we will probably have no way to add |
|
80 |
# this relation in the web ui. The easiest way to acheive this |
|
81 |
# is probably to be able to have "U has_update_permission O" as |
|
82 |
# RQLConstraint of the relation definition, though this is not yet |
|
83 |
# possible |
|
84 |
'add': ('managers', RRQLExpression('U has_update_permission S'),), |
|
85 |
'delete': ('managers', RRQLExpression('U has_update_permission S'),), |
|
86 |
} |
|
87 |
||
2140
1cba3393ba01
update schema definition to avoid deprecation warning with new yams api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
88 |
class in_group(RelationType): |
0 | 89 |
"""core relation indicating a user's groups""" |
2140
1cba3393ba01
update schema definition to avoid deprecation warning with new yams api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
90 |
permissions = META_RTYPE_PERMS |
1451 | 91 |
|
2140
1cba3393ba01
update schema definition to avoid deprecation warning with new yams api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
92 |
class owned_by(RelationType): |
0 | 93 |
"""core relation indicating owners of an entity. This relation |
94 |
implicitly put the owner into the owners group for the entity |
|
95 |
""" |
|
96 |
permissions = { |
|
97 |
'read': ('managers', 'users', 'guests'), |
|
1451 | 98 |
'add': ('managers', RRQLExpression('S owned_by U'),), |
0 | 99 |
'delete': ('managers', RRQLExpression('S owned_by U'),), |
100 |
} |
|
101 |
# 0..n cardinality for entities created by internal session (no attached user) |
|
102 |
# and to support later deletion of a user which has created some entities |
|
103 |
cardinality = '**' |
|
104 |
subject = '**' |
|
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1303
diff
changeset
|
105 |
object = 'CWUser' |
1451 | 106 |
|
2140
1cba3393ba01
update schema definition to avoid deprecation warning with new yams api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
107 |
class created_by(RelationType): |
0 | 108 |
"""core relation indicating the original creator of an entity""" |
109 |
permissions = { |
|
110 |
'read': ('managers', 'users', 'guests'), |
|
111 |
'add': ('managers',), |
|
112 |
'delete': ('managers',), |
|
113 |
} |
|
114 |
# 0..1 cardinality for entities created by internal session (no attached user) |
|
115 |
# and to support later deletion of a user which has created some entities |
|
1451 | 116 |
cardinality = '?*' |
0 | 117 |
subject = '**' |
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1303
diff
changeset
|
118 |
object = 'CWUser' |
0 | 119 |
|
1451 | 120 |
|
2140
1cba3393ba01
update schema definition to avoid deprecation warning with new yams api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
121 |
class creation_date(RelationType): |
0 | 122 |
"""creation time of an entity""" |
123 |
cardinality = '11' |
|
124 |
subject = '**' |
|
125 |
object = 'Datetime' |
|
126 |
||
2140
1cba3393ba01
update schema definition to avoid deprecation warning with new yams api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
127 |
class modification_date(RelationType): |
0 | 128 |
"""latest modification time of an entity""" |
129 |
cardinality = '11' |
|
130 |
subject = '**' |
|
131 |
object = 'Datetime' |
|
132 |
||
133 |
||
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1303
diff
changeset
|
134 |
class CWProperty(EntityType): |
0 | 135 |
"""used for cubicweb configuration. Once a property has been created you |
136 |
can't change the key. |
|
137 |
""" |
|
138 |
permissions = { |
|
139 |
'read': ('managers', 'users', 'guests'), |
|
140 |
'add': ('managers', 'users',), |
|
141 |
'update': ('managers', 'owners',), |
|
142 |
'delete': ('managers', 'owners',), |
|
143 |
} |
|
144 |
# key is a reserved word for mysql |
|
145 |
pkey = String(required=True, internationalizable=True, maxsize=256, |
|
146 |
description=_('defines what\'s the property is applied for. ' |
|
147 |
'You must select this first to be able to set ' |
|
148 |
'value')) |
|
149 |
value = String(internationalizable=True, maxsize=256) |
|
1451 | 150 |
|
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1303
diff
changeset
|
151 |
for_user = SubjectRelation('CWUser', cardinality='?*', composite='object', |
0 | 152 |
description=_('user for which this property is ' |
153 |
'applying. If this relation is not ' |
|
154 |
'set, the property is considered as' |
|
155 |
' a global property')) |
|
156 |
||
157 |
||
2140
1cba3393ba01
update schema definition to avoid deprecation warning with new yams api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
158 |
class for_user(RelationType): |
0 | 159 |
"""link a property to the user which want this property customization. Unless |
160 |
you're a site manager, this relation will be handled automatically. |
|
161 |
""" |
|
162 |
permissions = { |
|
163 |
'read': ('managers', 'users', 'guests'), |
|
164 |
'add': ('managers',), |
|
165 |
'delete': ('managers',), |
|
166 |
} |
|
167 |
inlined = True |
|
168 |
||
169 |
||
2140
1cba3393ba01
update schema definition to avoid deprecation warning with new yams api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
170 |
class CWPermission(EntityType): |
0 | 171 |
"""entity type that may be used to construct some advanced security configuration |
172 |
""" |
|
2140
1cba3393ba01
update schema definition to avoid deprecation warning with new yams api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
173 |
permissions = META_ETYPE_PERMS |
1cba3393ba01
update schema definition to avoid deprecation warning with new yams api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
174 |
|
0 | 175 |
name = String(required=True, indexed=True, internationalizable=True, maxsize=100, |
176 |
description=_('name or identifier of the permission')) |
|
177 |
label = String(required=True, internationalizable=True, maxsize=100, |
|
178 |
description=_('distinct label to distinguate between other permission entity of the same name')) |
|
1451 | 179 |
require_group = SubjectRelation('CWGroup', |
0 | 180 |
description=_('groups to which the permission is granted')) |
181 |
||
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1303
diff
changeset
|
182 |
# explicitly add X require_permission CWPermission for each entity that should have |
0 | 183 |
# configurable security |
184 |
class require_permission(RelationType): |
|
185 |
"""link a permission to the entity. This permission should be used in the |
|
186 |
security definition of the entity's type to be useful. |
|
187 |
""" |
|
188 |
permissions = { |
|
189 |
'read': ('managers', 'users', 'guests'), |
|
190 |
'add': ('managers',), |
|
191 |
'delete': ('managers',), |
|
192 |
} |
|
1451 | 193 |
|
2140
1cba3393ba01
update schema definition to avoid deprecation warning with new yams api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
194 |
class require_group(RelationType): |
0 | 195 |
"""used to grant a permission to a group""" |
196 |
permissions = { |
|
197 |
'read': ('managers', 'users', 'guests'), |
|
198 |
'add': ('managers',), |
|
199 |
'delete': ('managers',), |
|
200 |
} |
|
201 |
||
1451 | 202 |
|
0 | 203 |
class see_also(RelationType): |
204 |
"""generic relation to link one entity to another""" |
|
205 |
symetric = True |
|
206 |
||
1477 | 207 |
|
2140
1cba3393ba01
update schema definition to avoid deprecation warning with new yams api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
208 |
class CWCache(EntityType): |
59
9660bd221553
ECache should be a meta entity
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6
diff
changeset
|
209 |
"""a simple cache entity characterized by a name and |
9660bd221553
ECache should be a meta entity
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6
diff
changeset
|
210 |
a validity date. |
9660bd221553
ECache should be a meta entity
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6
diff
changeset
|
211 |
|
9660bd221553
ECache should be a meta entity
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6
diff
changeset
|
212 |
The target application is responsible for updating timestamp |
9660bd221553
ECache should be a meta entity
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6
diff
changeset
|
213 |
when necessary to invalidate the cache (typically in hooks). |
9660bd221553
ECache should be a meta entity
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6
diff
changeset
|
214 |
|
9660bd221553
ECache should be a meta entity
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6
diff
changeset
|
215 |
Also, checkout the AppRsetObject.get_cache() method. |
9660bd221553
ECache should be a meta entity
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6
diff
changeset
|
216 |
""" |
6
29ab115b9fcb
change permissions for Ecache
Stephanie Marcu <stephanie.marcu@logilab.fr>
parents:
0
diff
changeset
|
217 |
permissions = { |
29ab115b9fcb
change permissions for Ecache
Stephanie Marcu <stephanie.marcu@logilab.fr>
parents:
0
diff
changeset
|
218 |
'read': ('managers', 'users', 'guests'), |
29ab115b9fcb
change permissions for Ecache
Stephanie Marcu <stephanie.marcu@logilab.fr>
parents:
0
diff
changeset
|
219 |
'add': ('managers',), |
2140
1cba3393ba01
update schema definition to avoid deprecation warning with new yams api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
220 |
'update': ('managers', 'users',), # XXX |
6
29ab115b9fcb
change permissions for Ecache
Stephanie Marcu <stephanie.marcu@logilab.fr>
parents:
0
diff
changeset
|
221 |
'delete': ('managers',), |
29ab115b9fcb
change permissions for Ecache
Stephanie Marcu <stephanie.marcu@logilab.fr>
parents:
0
diff
changeset
|
222 |
} |
29ab115b9fcb
change permissions for Ecache
Stephanie Marcu <stephanie.marcu@logilab.fr>
parents:
0
diff
changeset
|
223 |
|
1445
d3c9b075ceb7
set a size constraint on ECache's title
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1281
diff
changeset
|
224 |
name = String(required=True, unique=True, indexed=True, maxsize=128, |
0 | 225 |
description=_('name of the cache')) |
226 |
timestamp = Datetime(default='NOW') |