diff --git a/fields/ref.py b/fields/ref.py index 161ea98..4855ed1 100644 --- a/fields/ref.py +++ b/fields/ref.py @@ -937,7 +937,7 @@ class Ref(Field): return gutils.No('no_write_perm') # May the user create instances of the referred class? if not obj.getTool().userMayCreate(self.klass): - return gutils.No('no_add_perm') + return gutils.No('no_create_perm') return True def checkAdd(self, obj): diff --git a/fields/workflow.py b/fields/workflow.py index 8c1caf1..f0c830c 100644 --- a/fields/workflow.py +++ b/fields/workflow.py @@ -162,6 +162,32 @@ class State: roles.append(self.getRole(newRoleName)) 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: '''Represents a workflow transition.''' diff --git a/gen/wrappers/__init__.py b/gen/wrappers/__init__.py index 2fdedd6..dff9f5c 100644 --- a/gen/wrappers/__init__.py +++ b/gen/wrappers/__init__.py @@ -1095,4 +1095,12 @@ class AbstractWrapper(object): def allows(self, permission, raiseError=False): '''Check doc @Mixin.allows.''' 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 # ------------------------------------------------------------------------------