Z.Accounts (Portico/Z v0.1.0)

ZSchemas.Accounts are entities that can log in to Z / Portico.

Accounts are managed by email address, and emails are managed via Google. So there's a fair bit o' Google conversion happening here to bring things in/out.

Sync Timestamp

The field account.synchronized_at is intended to track when the account was initially imported from Google, or last exported to a CSV (intended to be imported into Google). If an account doesn't have a synchronized_at timestamp, it is assumed to be new (ie created somewhere in Portico/Z), and therefore needing to be brought in as a "new" account in a Google CSV export.

Reset Password

The account.reset_password field, if set to true, will tell Google to force a password reset on the next login. To make this work, you set the value of this field as necessary, and then export records to Google CSV.

Once you've exported records to Google CSV, the value of account.reset_password will be automatically set to false again - since you don't want to force a password reset more than once. Accordingly, be careful to only export a found set when you're ready :)

Link to this section Summary

Functions

Create an account for an existing ZSchemas.Flat.Contact, if none exists.

Generate EXPLO's default staff email address for a given first name + last name.

Search all accounts by any account field.

Convert a list of accounts into a CSV string

Set the reset_password field for a list of accounts

Set the sync timestamp for a list of accounts

Link to this section Functions

Link to this function

create_account_from_google_user(user, attrs \\ %{})

Import a ZSchemas.Account record to the database from a Library.Google.User

Link to this function

create_from_contact(portico_contact_id, attrs \\ %{})

Create an account for an existing ZSchemas.Flat.Contact, if none exists.

Link to this function

create_or_update_account(contact, attrs \\ %{})

Create/update a ZSchemas.Account, using the related ZSchemas.Flat.Contact record.

Will attempt to find an existing account based on the portico_contact_id. If one is found, it'll be updated.

Link to this function

default_email_local_part(first_name, last_name)

Generate EXPLO's default staff email address for a given first name + last name.

Examples

iex> Z.Accounts.default_email_local_part "Donald", "Merand"
"donaldmerand"

iex> Z.Accounts.default_email_local_part "Elvis", "PRESLEY"
"elvispresley"

iex> Z.Accounts.default_email_local_part "Adam", "Van der Sluis"
"adamvandersluis"

iex> Z.Accounts.default_email_local_part "Toast🍞", "Emoji"
"toastemoji"
Link to this function

delete_account(account)

Delete a ZSchemas.Account

Link to this function

generate_account_email(first_name, last_name, local_part_suffix \\ "")

Create an email address for a new ZSchemas.Account.

Will use default_email_local_part/2, unless there is already an account with that address, in which case a digit will be appended at the end of the local part.

Link to this function

get_account_by(attrs \\ [])

Find ZSchemas.Account by attribute

attrs should be a keyword list of field names and field values to match. See Z.Repo.get_by for details.

Link to this function

list_accounts(opts \\ [])

List all ZSchemas.Account records.

Defaults to sorting by status, then email address.

Options

You can pass the following options:

  • in - [strings] - A list of account_ids to limit the search results.
  • not_in - [strings] - A list of account_ids to omit from the search results.
  • query - Ecto.Query - a default starting query.
  • needs_sync - boolean - Whether to filter to only folks needing a sync (updated since last sync or password reset).
Link to this function

search_accounts(comparisons, opts \\ [])

Search all accounts by any account field.

Will forward any opts to list_accounts/1.

Examples

iex> Z.Accounts.search_accounts(%{first_name: "Donald"})
[]
Link to this function

to_csv(accounts)

Convert a list of accounts into a CSV string

Link to this function

update_account(account, attrs \\ %{})

Update a ZSchemas.Account

Link to this function

update_password_reset(accounts, reset_password \\ false)

Set the reset_password field for a list of accounts

Link to this function

update_sync_timestamp(accounts)

Set the sync timestamp for a list of accounts

Link to this function

user_csv_struct(account)

Convert a ZSchemas.Account to a Library.Google.UserCsv struct

See this helpful Google article for more information.