Z.Accounts (Portico/Z v0.1.0)
ZSchemas.Account
s 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
Import a ZSchemas.Account
record to the database from a Library.Google.User
Create an account for an existing ZSchemas.Flat.Contact
, if none exists.
Create/update a ZSchemas.Account
, using the related ZSchemas.Flat.Contact
record.
Generate EXPLO's default staff email address for a given first name + last name.
Delete a ZSchemas.Account
Create an email address for a new ZSchemas.Account
.
Find ZSchemas.Account
by attribute
List all ZSchemas.Account
records.
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
Convert a ZSchemas.Account
to a Library.Google.UserCsv
struct
Link to this section Functions
create_account_from_google_user(user, attrs \\ %{})
Import a ZSchemas.Account
record to the database from a Library.Google.User
create_from_contact(portico_contact_id, attrs \\ %{})
Create an account for an existing ZSchemas.Flat.Contact
, if none exists.
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.
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"
delete_account(account)
Delete a ZSchemas.Account
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.
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.
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 ofaccount_id
s to limit the search results.not_in
- [strings] - A list ofaccount_id
s 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).
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"})
[]
to_csv(accounts)
Convert a list of accounts into a CSV string
update_account(account, attrs \\ %{})
Update a ZSchemas.Account
update_password_reset(accounts, reset_password \\ false)
Set the reset_password
field for a list of accounts
update_sync_timestamp(accounts)
Set the sync timestamp for a list of accounts
user_csv_struct(account)
Convert a ZSchemas.Account
to a Library.Google.UserCsv
struct
See this helpful Google article for more information.