[gen] Added some utility methods.

This commit is contained in:
Gaetan Delannay 2014-06-01 11:44:07 +02:00
parent 2eee217b05
commit 6494bf22c7
3 changed files with 35 additions and 1 deletions

View file

@ -937,7 +937,7 @@ class Ref(Field):
return gutils.No('no_write_perm') return gutils.No('no_write_perm')
# May the user create instances of the referred class? # May the user create instances of the referred class?
if not obj.getTool().userMayCreate(self.klass): if not obj.getTool().userMayCreate(self.klass):
return gutils.No('no_add_perm') return gutils.No('no_create_perm')
return True return True
def checkAdd(self, obj): def checkAdd(self, obj):

View file

@ -162,6 +162,32 @@ class State:
roles.append(self.getRole(newRoleName)) roles.append(self.getRole(newRoleName))
break break
def isIsolated(self, wf):
'''Returns True if, from this state, we cannot reach another state. The
workflow class is given in p_wf. Modifying a workflow for getting a
state with auto-transitions only is a common technique for disabling
a state in a workflow. Note that if this state is in a single-state
worklflow, this method will always return True (I mean: in this case,
having an isolated state does not mean the state has been
deactivated).'''
for tr in wf.__dict__.itervalues():
if not isinstance(tr, Transition): continue
if not tr.hasState(self, True): continue
# Transition "tr" has this state as start state. If the end state is
# different from the start state, it means that the state is not
# isolated.
if tr.isSingle():
if tr.states[1] != self: return
else:
for start, end in tr.states:
# Bypass (start, end) pairs that have nothing to do with
# self.
if start != self: continue
if end != self: return
# If we are here, either there was no transition starting from self,
# either all transitions were auto-transitions: self is then isolated.
return True
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
class Transition: class Transition:
'''Represents a workflow transition.''' '''Represents a workflow transition.'''

View file

@ -1095,4 +1095,12 @@ class AbstractWrapper(object):
def allows(self, permission, raiseError=False): def allows(self, permission, raiseError=False):
'''Check doc @Mixin.allows.''' '''Check doc @Mixin.allows.'''
return self.o.allows(permission, raiseError=raiseError) return self.o.allows(permission, raiseError=raiseError)
def resetLocalRoles(self):
'''Removes all local roles defined on this object, excepted local role
Owner, granted to the item creator.'''
from persistent.mapping import PersistentMapping
localRoles = PersistentMapping({ self.o.creator: ['Owner'] })
self.o.__ac_local_roles__ = localRoles
return localRoles
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------