I’m making a View with customized traversal. I want to traverse to next object dynamically base on current logged in user. But all method I know (portal_membership.getAuthenticatedUser, portal_state.member etc..) always return anonymous on View object’s __init__ and publicTraversal. The only case they return right is in object’s __call__.
What should I do to make getAuthenticatedUser work on my case (either on view’s __init__ or publicTraversal call)?
You can’t. Due to Zope’s security model, the user is determined after traversal, because this information depends on the context of the published object.
You can only rely on
getAuthenticatedUserwhen the object is being published; after traversal, authentication and authorization take place, and then publication, which in views means invoking the__call__method.Because
publicTraversalis called as part of the traversal stage, you cannot know the authenticated user in that method either. You’ll have to re-think your view to not rely on the authenticated user being known during that stage.