schemas/workflow.py
branchreldefsecurity
changeset 3877 7ca53fc72a0a
parent 3628 440931181322
child 3890 d7a270f50f54
equal deleted inserted replaced
3876:1169d3154be6 3877:7ca53fc72a0a
    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
   171     __permissions__ = META_RTYPE_PERMS
   172 
   172 
   173 class transition_of(RelationType):
   173 class transition_of(RelationType):
   174     """link a transition to one or more workflow"""
   174     """link a transition to one or more workflow"""
   175     permissions = META_RTYPE_PERMS
   175     __permissions__ = META_RTYPE_PERMS
   176 
   176 
   177 class subworkflow(RelationType):
   177 class subworkflow(RelationType):
   178     """link a transition to one or more workflow"""
   178     """link a transition to one or more workflow"""
   179     permissions = META_RTYPE_PERMS
   179     __permissions__ = META_RTYPE_PERMS
   180     inlined = True
   180     inlined = True
   181 
   181 
   182 class exit_point(RelationType):
   182 class exit_point(RelationType):
   183     """link a transition to one or more workflow"""
   183     """link a transition to one or more workflow"""
   184     permissions = META_RTYPE_PERMS
   184     __permissions__ = META_RTYPE_PERMS
   185 
   185 
   186 class subworkflow_state(RelationType):
   186 class subworkflow_state(RelationType):
   187     """link a transition to one or more workflow"""
   187     """link a transition to one or more workflow"""
   188     permissions = META_RTYPE_PERMS
   188     __permissions__ = META_RTYPE_PERMS
   189     inlined = True
   189     inlined = True
   190 
   190 
   191 class initial_state(RelationType):
   191 class initial_state(RelationType):
   192     """indicate which state should be used by default when an entity using
   192     """indicate which state should be used by default when an entity using
   193     states is created
   193     states is created
   194     """
   194     """
   195     permissions = META_RTYPE_PERMS
   195     __permissions__ = META_RTYPE_PERMS
   196     inlined = True
   196     inlined = True
   197 
   197 
   198 class destination_state(RelationType):
   198 class destination_state(RelationType):
   199     """destination state of a transition"""
   199     """destination state of a transition"""
   200     permissions = META_RTYPE_PERMS
   200     __permissions__ = META_RTYPE_PERMS
   201     inlined = True
   201     inlined = True
   202 
   202 
   203 class allowed_transition(RelationType):
   203 class allowed_transition(RelationType):
   204     """allowed transition from this state"""
   204     """allowed transition from this state"""
   205     permissions = META_RTYPE_PERMS
   205     __permissions__ = META_RTYPE_PERMS
   206 
   206 
   207 
   207 
   208 # "abstract" relations, set by WorkflowableEntityType ##########################
   208 # "abstract" relations, set by WorkflowableEntityType ##########################
   209 
   209 
   210 class custom_workflow(RelationType):
   210 class custom_workflow(RelationType):
   211     """allow to set a specific workflow for an entity"""
   211     """allow to set a specific workflow for an entity"""
   212     permissions = META_RTYPE_PERMS
   212     __permissions__ = META_RTYPE_PERMS
   213 
   213 
   214     cardinality = '?*'
   214     cardinality = '?*'
   215     constraints = [RQLConstraint('S is ET, O workflow_of ET')]
   215     constraints = [RQLConstraint('S is ET, O workflow_of ET')]
   216     object = 'Workflow'
   216     object = 'Workflow'
   217 
   217 
   218 
   218 
   219 class wf_info_for(RelationType):
   219 class wf_info_for(RelationType):
   220     """link a transition information to its object"""
   220     """link a transition information to its object"""
   221     # 'add' security actually done by hooks
   221     # 'add' security actually done by hooks
   222     permissions = {
   222     __permissions__ = {
   223         'read':   ('managers', 'users', 'guests',),
   223         'read':   ('managers', 'users', 'guests',),
   224         'add':    ('managers', 'users', 'guests',),
   224         'add':    ('managers', 'users', 'guests',),
   225         'delete': (),
   225         'delete': (),
   226     }
   226     }
   227     inlined = True
   227     inlined = True
   232     subject = 'TrInfo'
   232     subject = 'TrInfo'
   233 
   233 
   234 
   234 
   235 class in_state(RelationType):
   235 class in_state(RelationType):
   236     """indicate the current state of an entity"""
   236     """indicate the current state of an entity"""
   237     permissions = HOOKS_RTYPE_PERMS
   237     __permissions__ = HOOKS_RTYPE_PERMS
   238 
   238 
   239     # not inlined intentionnaly since when using ldap sources, user'state
   239     # not inlined intentionnaly since when using ldap sources, user'state
   240     # has to be stored outside the CWUser table
   240     # has to be stored outside the CWUser table
   241     inlined = False
   241     inlined = False
   242 
   242