schemas/workflow.py
changeset 3890 d7a270f50f54
parent 3629 559cad62c786
parent 3877 7ca53fc72a0a
child 3998 94cc7cad3d2d
equal deleted inserted replaced
3810:5b75fd66c80e 3890:d7a270f50f54
    13 from cubicweb.schema import RQLConstraint, RQLUniqueConstraint
    13 from cubicweb.schema import RQLConstraint, RQLUniqueConstraint
    14 from cubicweb.schemas import (META_ETYPE_PERMS, META_RTYPE_PERMS,
    14 from cubicweb.schemas import (META_ETYPE_PERMS, META_RTYPE_PERMS,
    15                               HOOKS_RTYPE_PERMS)
    15                               HOOKS_RTYPE_PERMS)
    16 
    16 
    17 class Workflow(EntityType):
    17 class Workflow(EntityType):
    18     permissions = META_ETYPE_PERMS
    18     __permissions__ = META_ETYPE_PERMS
    19 
    19 
    20     name = String(required=True, indexed=True, internationalizable=True,
    20     name = String(required=True, indexed=True, internationalizable=True,
    21                   maxsize=256)
    21                   maxsize=256)
    22     description = RichString(fulltextindexed=True, default_format='text/rest',
    22     description = RichString(fulltextindexed=True, default_format='text/rest',
    23                              description=_('semantic description of this workflow'))
    23                              description=_('semantic description of this workflow'))
    31                                    description=_('initial state for this workflow'))
    31                                    description=_('initial state for this workflow'))
    32 
    32 
    33 
    33 
    34 class default_workflow(RelationType):
    34 class default_workflow(RelationType):
    35     """default workflow for an entity type"""
    35     """default workflow for an entity type"""
    36     permissions = META_RTYPE_PERMS
    36     __permissions__ = META_RTYPE_PERMS
    37 
    37 
    38     subject = 'CWEType'
    38     subject = 'CWEType'
    39     object = 'Workflow'
    39     object = 'Workflow'
    40     cardinality = '?*'
    40     cardinality = '?*'
    41     constraints = [RQLConstraint('S final FALSE, O workflow_of S')]
    41     constraints = [RQLConstraint('S final FALSE, O workflow_of S')]
    43 
    43 
    44 class State(EntityType):
    44 class State(EntityType):
    45     """used to associate simple states to an entity type and/or to define
    45     """used to associate simple states to an entity type and/or to define
    46     workflows
    46     workflows
    47     """
    47     """
    48     permissions = META_ETYPE_PERMS
    48     __permissions__ = META_ETYPE_PERMS
    49 
    49 
    50     name = String(required=True, indexed=True, internationalizable=True,
    50     name = String(required=True, indexed=True, internationalizable=True,
    51                   maxsize=256)
    51                   maxsize=256)
    52     description = RichString(fulltextindexed=True, default_format='text/rest',
    52     description = RichString(fulltextindexed=True, default_format='text/rest',
    53                              description=_('semantic description of this state'))
    53                              description=_('semantic description of this state'))
    62                                constraints=[RQLUniqueConstraint('S name N, Y state_of O, Y name N')])
    62                                constraints=[RQLUniqueConstraint('S name N, Y state_of O, Y name N')])
    63 
    63 
    64 
    64 
    65 class BaseTransition(EntityType):
    65 class BaseTransition(EntityType):
    66     """abstract base class for transitions"""
    66     """abstract base class for transitions"""
    67     permissions = META_ETYPE_PERMS
    67     __permissions__ = META_ETYPE_PERMS
    68 
    68 
    69     name = String(required=True, indexed=True, internationalizable=True,
    69     name = String(required=True, indexed=True, internationalizable=True,
    70                   maxsize=256)
    70                   maxsize=256)
    71     type = String(vocabulary=(_('normal'), _('auto')), default='normal')
    71     type = String(vocabulary=(_('normal'), _('auto')), default='normal')
    72     description = RichString(fulltextindexed=True,
    72     description = RichString(fulltextindexed=True,
   124 
   124 
   125 
   125 
   126 class TrInfo(EntityType):
   126 class TrInfo(EntityType):
   127     """workflow history item"""
   127     """workflow history item"""
   128     # 'add' security actually done by hooks
   128     # 'add' security actually done by hooks
   129     permissions = {
   129     __permissions__ = {
   130         'read':   ('managers', 'users', 'guests',), # XXX U has_read_permission O ?
   130         'read':   ('managers', 'users', 'guests',), # XXX U has_read_permission O ?
   131         'add':    ('managers', 'users', 'guests',),
   131         'add':    ('managers', 'users', 'guests',),
   132         'delete': (), # XXX should we allow managers to delete TrInfo?
   132         'delete': (), # XXX should we allow managers to delete TrInfo?
   133         'update': ('managers', 'owners',),
   133         'update': ('managers', 'owners',),
   134     }
   134     }
   140     by_transition = SubjectRelation('BaseTransition', cardinality='?*')
   140     by_transition = SubjectRelation('BaseTransition', cardinality='?*')
   141     comment = RichString(fulltextindexed=True)
   141     comment = RichString(fulltextindexed=True)
   142     # get actor and date time using owned_by and creation_date
   142     # get actor and date time using owned_by and creation_date
   143 
   143 
   144 class from_state(RelationType):
   144 class from_state(RelationType):
   145     permissions = HOOKS_RTYPE_PERMS.copy()
   145     __permissions__ = HOOKS_RTYPE_PERMS.copy()
   146     inlined = True
   146     inlined = True
   147 
   147 
   148 class to_state(RelationType):
   148 class to_state(RelationType):
   149     permissions = {
   149     __permissions__ = {
   150         'read':   ('managers', 'users', 'guests',),
   150         'read':   ('managers', 'users', 'guests',),
   151         'add':    ('managers',),
   151         'add':    ('managers',),
   152         'delete': (),
   152         'delete': (),
   153     }
   153     }
   154     inlined = True
   154     inlined = True
   155 
   155 
   156 class by_transition(RelationType):
   156 class by_transition(RelationType):
   157     # 'add' security actually done by hooks
   157     # 'add' security actually done by hooks
   158     permissions = {
   158     __permissions__ = {
   159         'read':   ('managers', 'users', 'guests',),
   159         'read':   ('managers', 'users', 'guests',),
   160         'add':    ('managers', 'users', 'guests',),
   160         'add':    ('managers', 'users', 'guests',),
   161         'delete': (),
   161         'delete': (),
   162     }
   162     }
   163     inlined = True
   163     inlined = True
   164 
   164 
   165 class workflow_of(RelationType):
   165 class workflow_of(RelationType):
   166     """link a workflow to one or more entity type"""
   166     """link a workflow to one or more entity type"""
   167     permissions = META_RTYPE_PERMS
   167     __permissions__ = META_RTYPE_PERMS
   168 
   168 
   169 class state_of(RelationType):
   169 class state_of(RelationType):
   170     """link a state to one or more workflow"""
   170     """link a state to one or more workflow"""
       
   171     __permissions__ = META_RTYPE_PERMS
       
   172     inlined = True
       
   173 
       
   174 class transition_of(RelationType):
       
   175     """link a transition to one or more workflow"""
   171     permissions = META_RTYPE_PERMS
   176     permissions = META_RTYPE_PERMS
   172     inlined = True
   177     inlined = True
   173 
   178 
   174 class transition_of(RelationType):
       
   175     """link a transition to one or more workflow"""
       
   176     permissions = META_RTYPE_PERMS
       
   177     inlined = True
       
   178 
       
   179 class subworkflow(RelationType):
   179 class subworkflow(RelationType):
   180     """link a transition to one or more workflow"""
   180     """link a transition to one or more workflow"""
   181     permissions = META_RTYPE_PERMS
   181     __permissions__ = META_RTYPE_PERMS
   182     inlined = True
   182     inlined = True
   183 
   183 
   184 class exit_point(RelationType):
   184 class exit_point(RelationType):
   185     """link a transition to one or more workflow"""
   185     """link a transition to one or more workflow"""
   186     permissions = META_RTYPE_PERMS
   186     __permissions__ = META_RTYPE_PERMS
   187 
   187 
   188 class subworkflow_state(RelationType):
   188 class subworkflow_state(RelationType):
   189     """link a transition to one or more workflow"""
   189     """link a transition to one or more workflow"""
   190     permissions = META_RTYPE_PERMS
   190     __permissions__ = META_RTYPE_PERMS
   191     inlined = True
   191     inlined = True
   192 
   192 
   193 class initial_state(RelationType):
   193 class initial_state(RelationType):
   194     """indicate which state should be used by default when an entity using
   194     """indicate which state should be used by default when an entity using
   195     states is created
   195     states is created
   196     """
   196     """
   197     permissions = META_RTYPE_PERMS
   197     __permissions__ = META_RTYPE_PERMS
   198     inlined = True
   198     inlined = True
   199 
   199 
   200 class destination_state(RelationType):
   200 class destination_state(RelationType):
   201     """destination state of a transition"""
   201     """destination state of a transition"""
   202     permissions = META_RTYPE_PERMS
   202     __permissions__ = META_RTYPE_PERMS
   203     inlined = True
   203     inlined = True
   204 
   204 
   205 class allowed_transition(RelationType):
   205 class allowed_transition(RelationType):
   206     """allowed transition from this state"""
   206     """allowed transition from this state"""
   207     permissions = META_RTYPE_PERMS
   207     __permissions__ = META_RTYPE_PERMS
   208 
   208 
   209 
   209 
   210 # "abstract" relations, set by WorkflowableEntityType ##########################
   210 # "abstract" relations, set by WorkflowableEntityType ##########################
   211 
   211 
   212 class custom_workflow(RelationType):
   212 class custom_workflow(RelationType):
   213     """allow to set a specific workflow for an entity"""
   213     """allow to set a specific workflow for an entity"""
   214     permissions = META_RTYPE_PERMS
   214     __permissions__ = META_RTYPE_PERMS
   215 
   215 
   216     cardinality = '?*'
   216     cardinality = '?*'
   217     constraints = [RQLConstraint('S is ET, O workflow_of ET')]
   217     constraints = [RQLConstraint('S is ET, O workflow_of ET')]
   218     object = 'Workflow'
   218     object = 'Workflow'
   219 
   219 
   220 
   220 
   221 class wf_info_for(RelationType):
   221 class wf_info_for(RelationType):
   222     """link a transition information to its object"""
   222     """link a transition information to its object"""
   223     # 'add' security actually done by hooks
   223     # 'add' security actually done by hooks
   224     permissions = {
   224     __permissions__ = {
   225         'read':   ('managers', 'users', 'guests',),
   225         'read':   ('managers', 'users', 'guests',),
   226         'add':    ('managers', 'users', 'guests',),
   226         'add':    ('managers', 'users', 'guests',),
   227         'delete': (),
   227         'delete': (),
   228     }
   228     }
   229     inlined = True
   229     inlined = True
   234     subject = 'TrInfo'
   234     subject = 'TrInfo'
   235 
   235 
   236 
   236 
   237 class in_state(RelationType):
   237 class in_state(RelationType):
   238     """indicate the current state of an entity"""
   238     """indicate the current state of an entity"""
   239     permissions = HOOKS_RTYPE_PERMS
   239     __permissions__ = HOOKS_RTYPE_PERMS
   240 
   240 
   241     # not inlined intentionnaly since when using ldap sources, user'state
   241     # not inlined intentionnaly since when using ldap sources, user'state
   242     # has to be stored outside the CWUser table
   242     # has to be stored outside the CWUser table
   243     inlined = False
   243     inlined = False
   244 
   244