Metadata-Version: 2.5
Name: trytond_etude_token
Version: 8.0.0.1
Summary: Etude Form Server — Participants, Invitation Tokens and Reminders
Author: Clemens Hupka
Maintainer-email: Clemens Hupka <clemens.hupka@backend.at>
License-Expression: GPL-3.0-or-later
License-File: COPYRIGHT
License-File: LICENSE
Keywords: form,invitation,participant,reminder,survey,token,tryton
Classifier: Development Status :: 2 - Pre-Alpha
Classifier: Environment :: Plugins
Classifier: Framework :: Tryton
Classifier: Topic :: Office/Business
Requires-Python: >=3.10
Requires-Dist: trytond-etude-collect<8.1,>=8.0
Requires-Dist: trytond-etude<8.1,>=8.0
Requires-Dist: trytond-party<8.1,>=8.0
Requires-Dist: trytond<8.1,>=8.0
Provides-Extra: test
Description-Content-Type: text/x-rst

Etude Token Module
==================

The ``etude_token`` module invites named participants to a form: the
``etude.participant`` a form is sent to, the ``etude.token`` which is the
right to answer it and the ``etude.invitation`` which carries the token in a
mail.
It is a companion of ``etude_collect`` - it depends on it for the response a
token starts - and it is what turns a form open to whoever finds it into a
form answered by the people a deployment named.

A participant belongs to one form
---------------------------------

A participant is the named person an invitation is addressed to: a name, an
address, the free attributes a template personalises the mail with, and the
language the mail is written in.  The same person invited to two forms is two
participants, because it is the form that decides what a mail says, how long
a token stays valid and how often a participant is reminded.

The pair of a form and an address is unique, so a participant is never
registered twice for the same form by mistake, while the same address invited
to another form is a participant of its own.  An address is stored the way a
deployment sends it - normalized when it is written - so that the pair stays
comparable, and an address which is no address at all is refused where it is
written rather than when the mail bounces.

A participant may be linked to a party of the deployment - a customer, a
student, an employee - and where it is, the invitation is addressed to the
name of the party, to the address of its e-mail contact mechanism and in its
language, so that what a deployment keeps up to date is what an invitation
reads.  A participant the deployment holds no party for reads what it holds
itself, which is why its address is required either way.

A code a participant can type
-----------------------------

A token is the right to answer a form, handed to one participant: it names the
participant it invites and the form it opens, and the code a participant
follows - from the link of an invitation, from a printed letter or from a card
- is what it is found by.

The code is generated from a cryptographically secure source, out of an
alphabet of the upper case letters and the digits which are told apart by eye,
in a length which is not searched by guessing, and it is unique.  It is stored
as it is written, because it is printed in a mail a participant reads and types
back: unlike the token of an API, which a deployment only stores the digest of,
this one is read again.  A typed code is therefore read through one search
rather than through a form of the entry, and a code typed in lower case or
copied with the blank of the mail around it opens the same form.

What a token is worth is bounded on three sides: the state it is in, the moment
it expires and the number of responses it still takes.  A token which was used
up, which expired or which a deployment deactivated starts no new response, and
each of the three is told apart with its own message, so that a participant
which follows an old link reads why it opens nothing.  ``max_uses`` is the
number of responses a token takes and it is positive by a constraint of the
database; a token which took its last response is written into the used state
rather than read against its count, so that a job which invites or reminds
finds it by a search.

The invitations of a form, and the reminders after them
-------------------------------------------------------

An invitation is created with the token it invites through, because a token is
issued to be handed to its participant: what a deployment prepared to send is
read in one window, and the jobs which send it have one row per token to write
to.  A token is invited through once - a second invitation for one token is a
mistake a deployment reads rather than a second mail a participant gets.

Sending an invitation is a batch rather than something read while a designer
works, so it is a job of the ``ir.cron`` of the deployment and not a button of
the form: a deployment registers the participants of a form and lets the
deployment send them.  What was sent is written on the invitation -
``sent_at``, ``reminded_at`` and the number of reminders - which is what makes
the job idempotent: a second run sends nothing to a participant which was
already invited or reminded as often as its form permits, and a run which fails
halfway sends nothing at all, because a mail leaves when the transaction of the
job commits.

A participant who answered is not reminded, because a reminder is a call back
to a form which was left unanswered: what counts as an answer is a response the
form took, and a draft is deliberately none of them, because a participant
which saved a partial response and left it is exactly what a reminder is for.
A participant a deployment deactivated is written to neither, and neither is
the participant of a token which expired or which is used up.

The policy of a form is held by the form
----------------------------------------

How often a participant is reminded is a field of the form rather than a
setting of the deployment, because two forms of a deployment are invited and
reminded at their own pace: a form closed after a week is reminded once, a form
open for a term is reminded every fortnight for as long as it runs.

``reminder_delay`` is the number of days between two mails to a participant -
the delay after which a reminder follows an invitation, and the delay between
two reminders - and ``reminder_limit`` is the number of reminders a participant
is sent before it is left alone.  Seven days and one reminder are what a form
which configured nothing gets, and a negative number of either is a policy a
deployment did not mean and is refused where the form is written.  The two
columns are read with a fallback where they hold nothing, because they belong
to a form which was designed before this module was installed.

The mail is written from a template of the deployment
-----------------------------------------------------

An invitation and a reminder are written from an ``ir.email.template`` of the
deployment rather than from a text this module stores, so that a deployment
words them with the templates it words every other mail with and so that they
are translated with them.  The template of the invitation wins over the one of
its form, which is what lets a deployment word one invitation apart without
wording the whole form apart, and a form which words no reminder writes the
invitation of the participant again.

A template is addressed to ``etude.participant``, which this module adds to the
models a template may be addressed to, and a participant is read as a whole: a
template which names the participant itself is addressed to the address its
invitation is sent to and is written in its language, which is what makes a
template of a participant reusable by every form of a deployment.  An
invitation whose address resolves to nothing is refused rather than sent as an
empty mail.

The jobs of the module
----------------------

Three records of ``ir.cron`` run once a day, and how often each of them runs
afterwards is the decision of a deployment:

- ``etude.invitation|send_invitations`` writes to the participants which were
  not written to yet,
- ``etude.invitation|send_reminders`` reminds the participants the forms of the
  deployment ask to remind, and
- ``etude.token|expire_tokens`` writes the state of the tokens which passed
  their expiry, so that what a deployment can not use any more is read at a
  glance.

The expiry is a job of its own because a token which passed its moment is worth
nothing whether it was invited through or not, and a token which is already
used up is left used: what a token took is not undone by the delay which
followed it.

The windows and the access rights
---------------------------------

The module adds the participants, the invitation tokens and the invitations
under the menu of the etude group: a designer prepares the participants of a
form and the tokens they answer with, and reads what went out and what came
back.  The rights are read from the groups of the etude group - the
administration and the designer write, a user reads - and a deployment which
installs none of them gets nothing, because the default of the models is to
allow nobody.

See ``doc/index.rst`` for the module documentation and ``ETUDE.md`` in
``modules-cch/`` for the architecture of the whole group.
