Proca.Org (proca v3.4.1)
Represents an organisation in Proca. Org
can have many Proca.Staffer
s, Proca.Service
s, Proca.Campaign
s 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
params
map has a key that matches thebackend_type
.
- If the
backend_type
key is present in theparams
map, the code proceeds to execute thecase
expression. - If the
backend_type
key is not present, the function simply returns the unchangedchset
argument.
Inside the
case
expression, the function calls thecast_backend_service
function with thebackend_type
key and the corresponding value from theparams
map. Thecast_backend_service
function 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_service
function, 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_error
function. - If the result is a map with keys
:id
and:name
, the code checks if thename
is a member of theallow_list
. If it is, the changeset is updated by putting a change to thechset
with 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 thechset
with the backend ID based on thebackend_type
set 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 theorg
struct through a series of transformations.The
cast
function is used to update fields of theorg
struct based on the provided attributes. It takes theorg
struct, a list of field names to update, and the attrs map. Any fields that are not included in the list are ignored.The
cast_backend
function 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, theattrs
map, and theorg
struct. It updates the backend field if the corresponding field inattrs
matches one of the allowed values.The
validate_required
function is called with a list of required field names (:name
and:title
) to ensure they are present in theorg
struct.The
validate_format
function is used to validate that the:name
field matches the regular expression pattern~r/^[[:alnum:]_-]+$/
, which allows only alphanumeric characters, underscores, and hyphens.The
unique_constraint
function is used to add a unique constraint validation on the:name
field.The
Proca.Contact.Input.validate_email
function is used to validate the format of the:email_from
field.The
Proca.Service.EmailTemplate.validate_exists
function is used to validate that the:supporter_confirm_template
field 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 theorg
argument through a series of transformations.The
change
function is called with theorg
argument. 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 theorg
struct.After the
change
function is applied to theorg
, the resulting value is piped into theforeign_key_constraint
function.The
foreign_key_constraint
function adds a foreign key constraint to theorg
struct. It is used to define a relationship between theorg
and the:action_pages
table, where theorg
has a foreign key reference in the:action_pages
table. This constraint ensures referential integrity, meaning that theorg
cannot be deleted if there are any associated records in the:action_pages
table.
- The
:action_pages
is the table name where the foreign key constraint is applied. - The
name
option is used to specify the name of the foreign key constraint. In this case, it is set to:action_pages_org_id_fkey
. - The
message
option 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
one
function with thename
argument and an options map that includes thepreload
argument.The
one
function 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 thename
value. Thename
could represent a unique identifier or a specific condition to filter the records.The
preload
option allows for eager-loading associations or related data in the returned record. Thepreload
value, 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
one
function, which represents a single record from the database based on the specifiedname
, is returned by theget_by_name
function.
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.