Proca.Confirm (proca v3.4.1)

Confirm represents a confirmable action deferred in time. It is called confirm, because it is a confirmable - something that must be confirmed by a party. Usually party A creates a confirm, and party B accepts or rejects it. Upon acceptance, the operation can run. Optionaly upon rejection a different action can be triggered.

The confirm uses subject - operation - object terminology.

Eg. Marcin eats a-dosa would contain "eats" as operation, subject_id would be an FK to Marcin and object_id would be a FK to a dosa. To eat a dosa, Marcin creats a Confirm{operation: :eats, subject_id: marcin.id, object_id: dosa.id}. Then someone who is responsible for the dosas can accept the confirm, after which Marcin will instantly devour the dosa.

The order of subject and object can also be altered.

Eg. A dosa served to Marcin, in which case subject will be a dosa, and object is Marcin. In this case the dosa maker will create a Confirm{operaition: :serving, subject_id: dosa.id, object_id: marcin.id} and Marcin must accept this offer, after which he will instantly devour the dosa.

There are also other possibilities. The Confirm can omit the objectid, but just have a special code to accept it. In our example the dosa maker will make a Confirm{operation: :serving, subject_id: dosa.id, code: "98429214"}, and whoever is the lucky person to use that _open code can become the object of the confirm and devour the dosa. The code can be used by both authenticated and non-authenticated users (works like one-time-password).

Similarly, the confirm can be given an email, in which case the code will be sent to a person with particular email, as the intended devourer of the dosa. This way of creating a confirm is useful when we do not have the user.id for someone, but want them to confirm an operation (eg.: inviting new users to do somehing by email).

The confirm can have many charges which means they can be used more then once - for example when we have more then one dosa to give away.

Confirm contains:

  • operation - name of operation, an enum defined in Proca.EctoEnum
  • subject_id - the action taker
  • object_id - some object
  • code - code to trigger the accept or reject
  • charge - how many times can be used? defaults to 1

Partner joins a campaign

        subject v   object v
join_campaign(partner_org, campaign)
  • confirm created by partner_org
  • accepted by someone from campaign lead or campaign coordinator
  • charges: 1

Inviting a partner over email

invite_partner(campaign, email)

invite_partner(campaign, code)
  • confirm created by campaign lead or coordinator
  • confirm sent by email to particular org so they can accept the invitation instantly
  • or confirm code can be put on some forum or group, with 20 charges - the first 20 users of the code can accept the invitation.
  • after 20 uses, a new code needs to be generated.

Link to this section Summary

Functions

Try to insert the confirm with special handling of situation, when randomly generated code is duplicated. In case of duplication, we will keep adding one random digit to the code, until we succeed

Send a confirm operation specific email notification to list of emails or to confirm email. Uses dynamic dispatch to get template name and personalisation fields from each Confirm operation module. Will send the email from instance org backend.

Link to this section Functions

Link to this function

by_email_code(email, code)

Link to this function

by_object_code(object_id, code)

Link to this function

by_open_code(code)

Link to this function

changeset(attrs)

Link to this function

confirm(confirm, auth \\ nil)

Try to insert the confirm with special handling of situation, when randomly generated code is duplicated. In case of duplication, we will keep adding one random digit to the code, until we succeed

Link to this function

insert_and_notify!(ch)

Link to this function

notify_by_email(cnf)

Send a confirm operation specific email notification to list of emails or to confirm email. Uses dynamic dispatch to get template name and personalisation fields from each Confirm operation module. Will send the email from instance org backend.

Link to this function

notify_by_email(cnf, emails)

Link to this function

notify_fields(cnf)

Link to this function

reject(confirm, auth \\ nil)