ploneintranet.invitations package

Submodules

ploneintranet.invitations.events module

interface ploneintranet.invitations.events.ITokenAccepted

Bases: zope.interface.Interface

token_id = <zope.interface.interface.Attribute object>

The id of the Token that was consumed

class ploneintranet.invitations.events.TokenAccepted(token_id)

Bases: object

Event to be fired whenever a token is consumed

ploneintranet.invitations.interfaces module

interface ploneintranet.invitations.interfaces.IPloneintranetInvitationsLayer

Bases: zope.interface.Interface

Marker interface that defines a Zope 3 browser layer.

interface ploneintranet.invitations.interfaces.IToken

Bases: zope.interface.Interface

Interface for Token class

uses = <zope.interface.interface.Attribute object>

The number of uses for this token before it expires

id = <zope.interface.interface.Attribute object>

The UUID of this token

expiry = <zope.interface.interface.Attribute object>

The datetime this token expires

interface ploneintranet.invitations.interfaces.ITokenUtility

Bases: zope.interface.Interface

Interface for the TokenUtility

generate_new_token()

Get a new unique token

valid(token_id)

Is the token for given id still valid

ploneintranet.invitations.invitations module

class ploneintranet.invitations.invitations.InviteUser(context, request)

Bases: Products.Five.browser.BrowserView

Control panel view for sending invitation emails to potential new users of the Plone site

THIS IS EXAMPLE CODE AND NEEDS ATTENTION.

invite_user(email)

Get new token, build email and send it to the given email address

Parameters:email (str) – Email address to send invitation to, and for new user
Returns:Tuple of token id and token url
ploneintranet.invitations.invitations._ceil_datetime(days=3, now=datetime.datetime(2020, 12, 7, 11, 45, 6, 188362))

Helper method to ceil the datetime to a quarter of a hour and calculate the total_seconds until that moment.

Parameters:
  • days (int) – the amount of days from now.
  • now (datetime) – The current moment. This is a parameter so we can test.
Returns:

(datetime and int)

ploneintranet.invitations.invitations._get_storage(clear=False)
ploneintranet.invitations.invitations._store_invite(token_id, email)
ploneintranet.invitations.invitations.accept_invitation(event)

Event handler for AcceptToken event fired by invitation framework

FIXME #1047: this creates a acl user, not a ploneintranet userprofile

Additionally, this code makes the heroic assumption that email == username == userid which is very brittle, see #1043.

Parameters:event (AcceptToken) – The event object
Returns:

ploneintranet.invitations.testing module

ploneintranet.invitations.token module

class ploneintranet.invitations.token.Token(usage_limit, expiry, redirect_path=None)

Bases: persistent.Persistent

Definition of a token object

Variables:
  • uses_remaining – (int) The number of uses remaining for this token before expiry
  • expiry – (datetime) The datetime this token will expire
  • id – (uuid.uuid4) The unique identifier of this token
  • redirect_path – (str) The optional path to redirect to after the token is accepted
invite_url

The invitation URL of this token

ploneintranet.invitations.token_utility module

class ploneintranet.invitations.token_utility.TokenUtility

Bases: object

Utility to generate and consume tokens

_consume_token(token_id)

Consume the given token and fire the event

Parameters:token_id (str) – The token id
Returns:Whether consumption succeeded or not. It will fail if the token has expired
Return type:bool
_fetch_token(token_id)

Get an existing token from the token storage

Parameters:token_id (str) – A token id
Returns:Token object
_get_storage(clear=False)

Look up storage for tokens

Parameters:clear (bool) – Force clear the storage
Returns:Token storage
_store_token(token)

Store a token in the token storage

Parameters:token (Token) – A token
generate_new_token(usage_limit=1, expire_seconds=None, redirect_path=None)

Get a new unique token

Parameters:
  • usage_limit (int, default 1. None for unlimited use.) – The number of times this token is allowed to be consumed before expiring
  • expire_seconds (int) – The number of seconds before this token expires
  • redirect_path (str) – The optional path to redirect to, relative to the Plone site, after token is accepted
Returns:

A tuple containing the id of the generated token and a url that can be used to accept the token

Return type:

(token_id, token_url)

valid(token_id)

Has the token with the given id expired?

Returns:Whether or not the token has expired
Return type:bool

ploneintranet.invitations.views module

class ploneintranet.invitations.views.AcceptToken(context, request)

Bases: zope.publisher.browser.BrowserView

View that will be called to accept/activate a token

Usage: /@@accept-token/<token_id>

publishTraverse(request, name)
token_id = None

Module contents