"""workflow definition and history related entities:organization: Logilab:copyright: 2001-2009 LOGILAB S.A. (Paris, FRANCE), license is LGPL v2.:contact: http://www.logilab.fr/ -- mailto:contact@logilab.fr:license: GNU Lesser General Public License, v2.1 - http://www.gnu.org/licenses"""__docformat__="restructuredtext en"fromcubicweb.entitiesimportAnyEntity,fetch_configclassTransition(AnyEntity):"""customized class for Transition entities provides a specific may_be_passed method to check if the relation may be passed by the logged user """id='Transition'fetch_attrs,fetch_order=fetch_config(['name'])defmay_be_passed(self,eid,stateeid):"""return true if the logged user may pass this transition `eid` is the eid of the object on which we may pass the transition `stateeid` is the eid of the current object'state XXX unused """user=self.req.user# check user is at least in one of the required groups if anygroups=frozenset(g.nameforginself.require_group)ifgroups:matches=user.matching_groups(groups)ifmatches:returnmatchesif'owners'ingroupsanduser.owns(eid):returnTrue# check one of the rql expression conditions matches if anyifself.condition:forrqlexprinself.condition:ifrqlexpr.check_expression(self.req,eid):returnTrueifself.conditionorgroups:returnFalsereturnTruedefdestination(self):returnself.destination_state[0]defafter_deletion_path(self):"""return (path, parameters) which should be used as redirect information when this entity is being deleted """ifself.transition_of:returnself.transition_of[0].rest_path(),{'vid':'workflow'}returnsuper(Transition,self).after_deletion_path()classState(AnyEntity):"""customized class for State entities provides a specific transitions method returning transitions that may be passed by the current user for the given entity """id='State'fetch_attrs,fetch_order=fetch_config(['name'])rest_attr='eid'deftransitions(self,entity,desteid=None):rql=('Any T,N,DS where S allowed_transition T, S eid %(x)s, ''T name N, T destination_state DS, ''T transition_of ET, ET name %(et)s')ifdesteidisnotNone:rql+=', DS eid %(ds)s'rset=self.req.execute(rql,{'x':self.eid,'et':str(entity.e_schema),'ds':desteid},'x')fortrinrset.entities():iftr.may_be_passed(entity.eid,self.eid):yieldtrdefafter_deletion_path(self):"""return (path, parameters) which should be used as redirect information when this entity is being deleted """ifself.state_of:returnself.state_of[0].rest_path(),{'vid':'workflow'}returnsuper(State,self).after_deletion_path()classTrInfo(AnyEntity):"""customized class for Transition information entities """id='TrInfo'fetch_attrs,fetch_order=fetch_config(['creation_date','comment'],pclass=None)# don't want modification_date@propertydeffor_entity(self):returnself.wf_info_forandself.wf_info_for[0]@propertydefprevious_state(self):returnself.from_stateandself.from_state[0]@propertydefnew_state(self):returnself.to_state[0]defafter_deletion_path(self):"""return (path, parameters) which should be used as redirect information when this entity is being deleted """ifself.for_entity:returnself.for_entity.rest_path(),{}return'view',{}