l.s.w.interaction : module documentation

Part of lp.services.webapp

Methods dealing with interactions.

Almost everything in Launchpad relies on a security policy, in particular retrieving utilities and accessing attributes.

Zope obtains the security policy by looking at the 'interaction', which is a thread-local variable. If there is no interaction, one is likely to encounter an error like:

AttributeError("'thread._local' object has no attribute 'interaction'")

In Launchpad, we frequently refer to the state of having no interaction as being "logged out".

Because one needs an interaction to do practically anything, and because Launchpad allows anonymous access, it is possible to create an interaction (informally, "log in") for a mythical anonymous user.

The object representing the logged-in user is called the "principal", and the relationship between the principal and the interaction is called the "participation".

In Launchpad and in standard usage, the participation is the request and the principal is the requesting user. Although Zope has support for more than one of these, we only ever allow one.

There are test helpers in lp.testing._login.

See also lib/canonical/launchpad/doc/webapp-authorization.txt.

Function get_current_principal Get the principal from the current interaction.
Function setupInteraction Sets up a new interaction with the given principal.
Function setupInteractionByEmail Setup an interaction using an email.
Function setupInteractionForPerson Setup a participation for a person.
Class Participation A very simple participation.
Class InteractionExtras Extra data attached to all interactions. See IInteractionExtras.
Function get_interaction_extras Return the active provider of IInteractionExtras.
def get_current_principal():
Get the principal from the current interaction.
ReturnsThe current principal if there is an interaction, None otherwise.
def setupInteraction(principal, login=None, participation=None):
Sets up a new interaction with the given principal.

The login gets added to the launch bag.

You can optionally pass in a participation to be used. If no participation is given, a Participation is used.

def setupInteractionByEmail(email, participation=None):
Setup an interaction using an email.

If the ANONYMOUS constant is supplied as the email, an interaction for the anonymous user will be used.

You can optionally pass in a participation to be used. If no participation is given, an empty participation is used.

If the participation provides IPublicationRequest, it must implement setPrincipal(), otherwise it must allow setting its principal attribute.

def setupInteractionForPerson(person, participation=None):
Setup a participation for a person.
def get_interaction_extras():
Return the active provider of IInteractionExtras.

This is looked up from the interaction. If there is no interaction then return None.

API Documentation for Launchpad, generated by pydoctor at 2022-06-16 00:00:12.