Proca.Org (proca v3.4.1)
Represents an organisation in Proca. Org can have many Proca.Staffers, Proca.Services, Proca.Campaigns and Proca.ActionPage's.
Org can have one or more PublicKey's. Only one of them is active at a particular time. Others are expired.
Org fields define how services are used (as which backends):
event_backend- where to send events (SeeProca.Stage.Event)email_backend- where to send emailsdetail_backend- where to fetch supporter detail fromstorage_backend- where to store files (attached to actions)push_backend- where to push action data
Link to this section Summary
Functions
The code you provided defines a function called cast_backend in the Elixir programming language. This function takes five arguments: chset, backend_type, allow_list, params, and org.
The code you provided defines a function called changeset in the Elixir programming language.
The code you provided defines a function called delete in the Elixir programming language. This function takes one argument, org, which represents an organization.
The code you provided defines a function called get_by_name in the Elixir programming language. This function takes two arguments: name and preload, with preload being an optional argument that defaults to an empty list.
Link to this section Functions
active_public_key(org)
active_public_keys(public_keys)
Specs
active_public_keys([Proca.PublicKey]) :: [Proca.PublicKey]
active_public_keys(Proca.Org) :: Proca.PublicKey | nil
all(kw)
all(query, list)
cast_backend(chset, backend_type, allow_list, params, org)
The code you provided defines a function called cast_backend in the Elixir programming language. This function takes five arguments: chset, backend_type, allow_list, params, and org.
Here's a breakdown of what the code does:
- The function checks if the
paramsmap has a key that matches thebackend_type.
- If the
backend_typekey is present in theparamsmap, the code proceeds to execute thecaseexpression. - If the
backend_typekey is not present, the function simply returns the unchangedchsetargument.
Inside the
caseexpression, the function calls thecast_backend_servicefunction with thebackend_typekey and the corresponding value from theparamsmap. Thecast_backend_servicefunction is likely a custom function defined elsewhere and its purpose is not shown in the provided code snippet. It presumably performs some processing specific to the backend service.Based on the result of the
cast_backend_servicefunction, the code executes one of three possible branches:
- If the result is
nil, meaning no such service was found, an error is added to the changeset (chset) using theadd_errorfunction. - If the result is a map with keys
:idand:name, the code checks if thenameis a member of theallow_list. If it is, the changeset is updated by putting a change to thechsetwith the backend ID based on thebackend_type. Otherwise, an error is added to the changeset. - If the result is
:disable, the changeset is updated by putting a change to thechsetwith the backend ID based on thebackend_typeset tonil.
- After executing one of the branches, the resulting changeset is returned.
changeset(org, attrs)
The code you provided defines a function called changeset in the Elixir programming language.
This function takes two arguments, org and attrs. It performs a series of operations to build a changeset for the org struct, which can be used for inserting or updating data in a database.
Here's a breakdown of what the code does:
The code uses the Elixir pipe operator (
|>) to pass theorgstruct through a series of transformations.The
castfunction is used to update fields of theorgstruct based on the provided attributes. It takes theorgstruct, a list of field names to update, and the attrs map. Any fields that are not included in the list are ignored.The
cast_backendfunction is used multiple times to update backend settings based on the provided attributes. It takes a field name, a list of allowed values for that field, theattrsmap, and theorgstruct. It updates the backend field if the corresponding field inattrsmatches one of the allowed values.The
validate_requiredfunction is called with a list of required field names (:nameand:title) to ensure they are present in theorgstruct.The
validate_formatfunction is used to validate that the:namefield matches the regular expression pattern~r/^[[:alnum:]_-]+$/, which allows only alphanumeric characters, underscores, and hyphens.The
unique_constraintfunction is used to add a unique constraint validation on the:namefield.The
Proca.Contact.Input.validate_emailfunction is used to validate the format of the:email_fromfield.The
Proca.Service.EmailTemplate.validate_existsfunction is used to validate that the:supporter_confirm_templatefield references an existing email template.
Finally, the resulting changeset is returned by the function. This changeset represents the updates that can be applied to the org struct in the database.
defaults(arg1)
delete(org)
The code you provided defines a function called delete in the Elixir programming language. This function takes one argument, org, which represents an organization.
Here's a breakdown of what the code does:
The code uses the Elixir pipe operator (
|>) to pass theorgargument through a series of transformations.The
changefunction is called with theorgargument. This function is likely a custom function defined elsewhere and its purpose is not shown in the provided code snippet. It could perform any necessary changes or transformations on theorgstruct.After the
changefunction is applied to theorg, the resulting value is piped into theforeign_key_constraintfunction.The
foreign_key_constraintfunction adds a foreign key constraint to theorgstruct. It is used to define a relationship between theorgand the:action_pagestable, where theorghas a foreign key reference in the:action_pagestable. This constraint ensures referential integrity, meaning that theorgcannot be deleted if there are any associated records in the:action_pagestable.
- The
:action_pagesis the table name where the foreign key constraint is applied. - The
nameoption is used to specify the name of the foreign key constraint. In this case, it is set to:action_pages_org_id_fkey. - The
messageoption is used to provide a custom error message that will be shown if the foreign key constraint is violated. In this case, it is set to "has action pages".
The purpose of this code snippet is to build a changeset that verifies whether an organization (org) can be deleted based on the presence of associated records in the :action_pages table. If there are action pages associated with the organization, a foreign key constraint is added to prevent deletion and an error message is provided.
get_by_id(id, preload \\ [])
get_by_name(name, preload \\ [])
The code you provided defines a function called get_by_name in the Elixir programming language. This function takes two arguments: name and preload, with preload being an optional argument that defaults to an empty list.
Here's a breakdown of what the code does:
The function calls the
onefunction with thenameargument and an options map that includes thepreloadargument.The
onefunction is likely a part of a database querying library or framework, and its purpose is not shown in the provided code snippet. It is used here to retrieve a single record from the database based on thenamevalue. Thenamecould represent a unique identifier or a specific condition to filter the records.The
preloadoption allows for eager-loading associations or related data in the returned record. Thepreloadvalue, which is optional and defaults to an empty list, can be provided to specify which associations should be preloaded. Preloading associations is useful to avoid making additional database queries when accessing related data.The result of the
onefunction, which represents a single record from the database based on the specifiedname, is returned by theget_by_namefunction.
In summary, the purpose of this code snippet is to provide a convenient wrapper function get_by_name that retrieves a single record from the database based on the provided name value. The optional preload argument allows for eager-loading specific associations.