cubicweb/server/test/data-migractions/schema.py
changeset 12841 fceae84a22dd
parent 11362 ebe75d73acdd
equal deleted inserted replaced
12840:d29955a6dbba 12841:fceae84a22dd
    11 # CubicWeb is distributed in the hope that it will be useful, but WITHOUT
    11 # CubicWeb is distributed in the hope that it will be useful, but WITHOUT
    12 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
    12 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
    13 # FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more
    13 # FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more
    14 # details.
    14 # details.
    15 #
    15 #
    16 # You should have received a copy of the GNU Lesser General Public License along
    16 # You should have received a copy of the GNU Lesser General Public License
    17 # with CubicWeb.  If not, see <http://www.gnu.org/licenses/>.
    17 # along with CubicWeb.  If not, see <http://www.gnu.org/licenses/>.
    18 
    18 
    19 from yams.buildobjs import (EntityType, RelationType, RelationDefinition, ComputedRelation,
    19 from yams.buildobjs import (EntityType, RelationType, RelationDefinition, ComputedRelation,
    20                             SubjectRelation, RichString, String, Int, Float,
    20                             SubjectRelation, RichString, String, Int, Float,
    21                             Boolean, Datetime, TZDatetime, Bytes)
    21                             Boolean, Datetime, TZDatetime, Bytes)
    22 from yams.constraints import SizeConstraint
    22 from yams.constraints import SizeConstraint
    28 
    28 
    29 
    29 
    30 class Affaire(WorkflowableEntityType):
    30 class Affaire(WorkflowableEntityType):
    31     __permissions__ = {
    31     __permissions__ = {
    32         'read':   ('managers',
    32         'read':   ('managers',
    33                    ERQLExpression('X owned_by U'), ERQLExpression('X concerne S?, S owned_by U')),
    33                    ERQLExpression('X owned_by U'),
       
    34                    ERQLExpression('X concerne S?, S owned_by U')),
    34         'add':    ('managers', ERQLExpression('X concerne S, S owned_by U')),
    35         'add':    ('managers', ERQLExpression('X concerne S, S owned_by U')),
    35         'update': ('managers', 'owners', ERQLExpression('X in_state S, S name in ("pitetre", "en cours")')),
    36         'update': ('managers', 'owners',
    36         'delete': ('managers', 'owners', ERQLExpression('X concerne S, S owned_by U')),
    37                    ERQLExpression('X in_state S, '
       
    38                                   'S name in ("pitetre", "en cours")')),
       
    39         'delete': ('managers', 'owners',
       
    40                    ERQLExpression('X concerne S, S owned_by U')),
    37         }
    41         }
    38 
    42 
    39     ref = String(fulltextindexed=True, indexed=True,
    43     ref = String(fulltextindexed=True, indexed=True,
    40                  constraints=[SizeConstraint(16)])
    44                  constraints=[SizeConstraint(16)])
    41     sujet = String(fulltextindexed=True,
    45     sujet = String(fulltextindexed=True,
    59     __permissions__ = {
    63     __permissions__ = {
    60         'read': ('managers', 'users', 'guests'),
    64         'read': ('managers', 'users', 'guests'),
    61         'update': ('managers', 'owners', ERQLExpression('U login L, X nom L')),
    65         'update': ('managers', 'owners', ERQLExpression('U login L, X nom L')),
    62         'delete': ('managers', 'owners', ERQLExpression('U login L, X nom L')),
    66         'delete': ('managers', 'owners', ERQLExpression('U login L, X nom L')),
    63         'add': ('managers', 'users',)
    67         'add': ('managers', 'users',)
    64         }
    68     }
    65 
    69 
    66     nom  = String(maxsize=64, fulltextindexed=True)
    70     nom  = String(maxsize=64, fulltextindexed=True)
    67     web  = String(maxsize=128)
    71     web  = String(maxsize=128)
    68     type  = String(maxsize=128) # attribute in common with Note
    72     type  = String(maxsize=128) # attribute in common with Note
    69     tel  = Int()
    73     tel  = Int()
    77 
    81 
    78 
    82 
    79 class Division(Societe):
    83 class Division(Societe):
    80     __specializes_schema__ = True
    84     __specializes_schema__ = True
    81 
    85 
       
    86 
    82 class SubDivision(Division):
    87 class SubDivision(Division):
    83     __specializes_schema__ = True
    88     __specializes_schema__ = True
       
    89 
    84 
    90 
    85 class travaille_subdivision(RelationDefinition):
    91 class travaille_subdivision(RelationDefinition):
    86     subject = 'Personne'
    92     subject = 'Personne'
    87     object = 'SubDivision'
    93     object = 'SubDivision'
       
    94 
    88 
    95 
    89 from cubicweb.schemas.base import CWUser
    96 from cubicweb.schemas.base import CWUser
    90 next(CWUser.get_relations('login')).fulltextindexed = True
    97 next(CWUser.get_relations('login')).fulltextindexed = True
    91 
    98 
    92 class Note(WorkflowableEntityType):
    99 class Note(WorkflowableEntityType):
   104                           'add': (ERQLExpression('NOT X para NULL'),),
   111                           'add': (ERQLExpression('NOT X para NULL'),),
   105                           'update': ('managers', 'owners')
   112                           'update': ('managers', 'owners')
   106                       })
   113                       })
   107     migrated_from = SubjectRelation('Note')
   114     migrated_from = SubjectRelation('Note')
   108     attachment = SubjectRelation('File')
   115     attachment = SubjectRelation('File')
   109     inline1 = SubjectRelation('Affaire', inlined=True, cardinality='?*',
   116     inline1 = SubjectRelation(
   110                               constraints=[RQLUniqueConstraint('S type T, S inline1 A1, A1 todo_by C, '
   117         'Affaire', inlined=True, cardinality='?*',
   111                                                               'Y type T, Y inline1 A2, A2 todo_by C',
   118         constraints=[
   112                                                                'S,Y')])
   119             RQLUniqueConstraint('S type T, S inline1 A1, A1 todo_by C, '
       
   120                                 'Y type T, Y inline1 A2, A2 todo_by C',
       
   121                                 'S,Y')])
   113     todo_by = SubjectRelation('CWUser')
   122     todo_by = SubjectRelation('CWUser')
   114 
   123 
   115 
   124 
   116 class Frozable(EntityType):
   125 class Frozable(EntityType):
   117     __permissions__ = {
   126     __permissions__ = {
   166 
   175 
   167 
   176 
   168 class connait(RelationType):
   177 class connait(RelationType):
   169     symmetric = True
   178     symmetric = True
   170 
   179 
       
   180 
   171 class concerne(RelationType):
   181 class concerne(RelationType):
   172     __permissions__ = {
   182     __permissions__ = {
   173         'read':   ('managers', 'users', 'guests'),
   183         'read':   ('managers', 'users', 'guests'),
   174         'add':    ('managers', RRQLExpression('U has_update_permission S')),
   184         'add':    ('managers', RRQLExpression('U has_update_permission S')),
   175         'delete': ('managers', RRQLExpression('O owned_by U')),
   185         'delete': ('managers', RRQLExpression('O owned_by U')),
   176         }
   186         }
       
   187 
   177 
   188 
   178 class travaille(RelationDefinition):
   189 class travaille(RelationDefinition):
   179     __permissions__ = {
   190     __permissions__ = {
   180         'read':   ('managers', 'users', 'guests'),
   191         'read':   ('managers', 'users', 'guests'),
   181         'add':    ('managers', RRQLExpression('U has_update_permission S')),
   192         'add':    ('managers', RRQLExpression('U has_update_permission S')),
   184     subject = 'Personne'
   195     subject = 'Personne'
   185     object = 'Societe'
   196     object = 'Societe'
   186     constraints = [RQLVocabularyConstraint('S owned_by U'),
   197     constraints = [RQLVocabularyConstraint('S owned_by U'),
   187                    RQLVocabularyConstraint('S created_by U')]
   198                    RQLVocabularyConstraint('S created_by U')]
   188 
   199 
       
   200 
   189 class comments(RelationDefinition):
   201 class comments(RelationDefinition):
   190     subject = 'Comment'
   202     subject = 'Comment'
   191     object = 'Personne'
   203     object = 'Personne'
       
   204 
   192 
   205 
   193 class fiche(RelationDefinition):
   206 class fiche(RelationDefinition):
   194     inlined = True
   207     inlined = True
   195     subject = 'Personne'
   208     subject = 'Personne'
   196     object = 'Card'
   209     object = 'Card'
   197     cardinality = '??'
   210     cardinality = '??'
   198 
   211 
       
   212 
   199 class multisource_inlined_rel(RelationDefinition):
   213 class multisource_inlined_rel(RelationDefinition):
   200     inlined = True
   214     inlined = True
   201     cardinality = '?*'
   215     cardinality = '?*'
   202     subject = ('Card', 'Note')
   216     subject = ('Card', 'Note')
   203     object = ('Affaire', 'Note')
   217     object = ('Affaire', 'Note')
   205 
   219 
   206 class see_also_1(RelationDefinition):
   220 class see_also_1(RelationDefinition):
   207     name = 'see_also'
   221     name = 'see_also'
   208     subject = object = 'Folder'
   222     subject = object = 'Folder'
   209 
   223 
       
   224 
   210 class see_also_2(RelationDefinition):
   225 class see_also_2(RelationDefinition):
   211     name = 'see_also'
   226     name = 'see_also'
   212     subject = ('Bookmark', 'Note')
   227     subject = ('Bookmark', 'Note')
   213     object = ('Bookmark', 'Note')
   228     object = ('Bookmark', 'Note')
       
   229 
   214 
   230 
   215 class evaluee(RelationDefinition):
   231 class evaluee(RelationDefinition):
   216     subject = ('Personne', 'CWUser', 'Societe')
   232     subject = ('Personne', 'CWUser', 'Societe')
   217     object = ('Note')
   233     object = ('Note')
   218     constraints = [
   234     constraints = [
   219         RQLVocabularyConstraint('S created_by U'),
   235         RQLVocabularyConstraint('S created_by U'),
   220         RQLVocabularyConstraint('S owned_by U'),
   236         RQLVocabularyConstraint('S owned_by U'),
   221     ]
   237     ]
   222 
   238 
       
   239 
   223 class ecrit_par(RelationType):
   240 class ecrit_par(RelationType):
   224     inlined = True
   241     inlined = True
       
   242 
   225 
   243 
   226 class ecrit_par_1(RelationDefinition):
   244 class ecrit_par_1(RelationDefinition):
   227     name = 'ecrit_par'
   245     name = 'ecrit_par'
   228     subject = 'Note'
   246     subject = 'Note'
   229     object = 'Personne'
   247     object = 'Personne'
   230     cardinality = '?*'
   248     cardinality = '?*'
   231 
   249 
       
   250 
   232 class ecrit_par_2(RelationDefinition):
   251 class ecrit_par_2(RelationDefinition):
   233     name = 'ecrit_par'
   252     name = 'ecrit_par'
   234     subject = 'Note'
   253     subject = 'Note'
   235     object = 'CWUser'
   254     object = 'CWUser'
   236     cardinality='?*'
   255     cardinality='?*'
   237 
   256 
   238 
   257 
   239 class copain(RelationDefinition):
   258 class copain(RelationDefinition):
   240     subject = object = 'CWUser'
   259     subject = object = 'CWUser'
   241 
   260 
       
   261 
   242 class tags(RelationDefinition):
   262 class tags(RelationDefinition):
   243     subject = 'Tag'
   263     subject = 'Tag'
   244     object = ('CWUser', 'CWGroup', 'State', 'Note', 'Card', 'Affaire')
   264     object = ('CWUser', 'CWGroup', 'State', 'Note', 'Card', 'Affaire')
       
   265 
   245 
   266 
   246 class Folder(EntityType):
   267 class Folder(EntityType):
   247     """folders are used to classify entities. They may be defined as a tree.
   268     """folders are used to classify entities. They may be defined as a tree.
   248     """
   269     """
   249     name = String(required=True, indexed=True, internationalizable=True,
   270     name = String(required=True, indexed=True, internationalizable=True,
   250                   maxsize=64)
   271                   maxsize=64)
   251     description = RichString(fulltextindexed=True)
   272     description = RichString(fulltextindexed=True)
   252     filed_under = SubjectRelation('Folder', description=_('parent folder'))
   273     filed_under = SubjectRelation('Folder', description=_('parent folder'))
   253 
   274 
       
   275 
   254 class filed_under(RelationDefinition):
   276 class filed_under(RelationDefinition):
   255     subject = ('Note', 'Affaire')
   277     subject = ('Note', 'Affaire')
   256     object = 'Folder'
   278     object = 'Folder'
   257 
   279 
       
   280 
   258 class require_permission(RelationDefinition):
   281 class require_permission(RelationDefinition):
   259     subject = ('Card', 'Note', 'Personne')
   282     subject = ('Card', 'Note', 'Personne')
   260     object = 'CWPermission'
   283     object = 'CWPermission'
   261 
   284 
       
   285 
   262 class require_state(RelationDefinition):
   286 class require_state(RelationDefinition):
   263     subject = 'CWPermission'
   287     subject = 'CWPermission'
   264     object = 'State'
   288     object = 'State'
       
   289 
   265 
   290 
   266 class personne_composite(RelationDefinition):
   291 class personne_composite(RelationDefinition):
   267     subject='Personne'
   292     subject='Personne'
   268     object='Personne'
   293     object='Personne'
   269     composite='subject'
   294     composite='subject'
       
   295 
   270 
   296 
   271 class personne_inlined(RelationDefinition):
   297 class personne_inlined(RelationDefinition):
   272     subject='Personne'
   298     subject='Personne'
   273     object='Personne'
   299     object='Personne'
   274     cardinality='?*'
   300     cardinality='?*'
   278 class login_user(RelationDefinition):
   304 class login_user(RelationDefinition):
   279     subject = 'Personne'
   305     subject = 'Personne'
   280     object = 'CWUser'
   306     object = 'CWUser'
   281     cardinality = '??'
   307     cardinality = '??'
   282 
   308 
       
   309 
   283 class ambiguous_inlined(RelationDefinition):
   310 class ambiguous_inlined(RelationDefinition):
   284     subject = ('Affaire', 'Note')
   311     subject = ('Affaire', 'Note')
   285     object = 'CWUser'
   312     object = 'CWUser'
   286     inlined = True
   313     inlined = True
   287     cardinality = '?*'
   314     cardinality = '?*'