entities/wfobjs.py
changeset 10096 decd60fa8cc5
parent 10095 200bd6a601dc
child 10374 699e49d76334
equal deleted inserted replaced
10095:200bd6a601dc 10096:decd60fa8cc5
    30 
    30 
    31 from cubicweb.entities import AnyEntity, fetch_config
    31 from cubicweb.entities import AnyEntity, fetch_config
    32 from cubicweb.view import EntityAdapter
    32 from cubicweb.view import EntityAdapter
    33 from cubicweb.predicates import relation_possible
    33 from cubicweb.predicates import relation_possible
    34 
    34 
       
    35 
       
    36 try:
       
    37     from cubicweb import server
       
    38 except ImportError:
       
    39     # We need to lookup DEBUG from there,
       
    40     # however a pure dbapi client may not have it.
       
    41     class server(object): pass
       
    42     server.DEBUG = False
       
    43 
       
    44 
    35 class WorkflowException(Exception): pass
    45 class WorkflowException(Exception): pass
    36 
    46 
    37 class Workflow(AnyEntity):
    47 class Workflow(AnyEntity):
    38     __regid__ = 'Workflow'
    48     __regid__ = 'Workflow'
    39 
    49 
   199     def may_be_fired(self, eid):
   209     def may_be_fired(self, eid):
   200         """return true if the logged user may fire this transition
   210         """return true if the logged user may fire this transition
   201 
   211 
   202         `eid` is the eid of the object on which we may fire the transition
   212         `eid` is the eid of the object on which we may fire the transition
   203         """
   213         """
       
   214         DBG = False
       
   215         if server.DEBUG & server.DBG_SEC:
       
   216             if 'transition' in server._SECURITY_CAPS:
       
   217                 DBG = True
   204         user = self._cw.user
   218         user = self._cw.user
   205         # check user is at least in one of the required groups if any
   219         # check user is at least in one of the required groups if any
   206         groups = frozenset(g.name for g in self.require_group)
   220         groups = frozenset(g.name for g in self.require_group)
   207         if groups:
   221         if groups:
   208             matches = user.matching_groups(groups)
   222             matches = user.matching_groups(groups)
   209             if matches:
   223             if matches:
       
   224                 if DBG:
       
   225                     print 'may_be_fired: %r may fire: user matches %s' % (self.name, groups)
   210                 return matches
   226                 return matches
   211             if 'owners' in groups and user.owns(eid):
   227             if 'owners' in groups and user.owns(eid):
       
   228                 if DBG:
       
   229                     print 'may_be_fired: %r may fire: user is owner' % self.name
   212                 return True
   230                 return True
   213         # check one of the rql expression conditions matches if any
   231         # check one of the rql expression conditions matches if any
   214         if self.condition:
   232         if self.condition:
       
   233             if DBG:
       
   234                 print ('my_be_fired: %r: %s' %
       
   235                        (self.name, [(rqlexpr.expression,
       
   236                                     rqlexpr.check_expression(self._cw, eid))
       
   237                                    for rqlexpr in self.condition]))
   215             for rqlexpr in self.condition:
   238             for rqlexpr in self.condition:
   216                 if rqlexpr.check_expression(self._cw, eid):
   239                 if rqlexpr.check_expression(self._cw, eid):
   217                     return True
   240                     return True
   218         if self.condition or groups:
   241         if self.condition or groups:
   219             return False
   242             return False