View Source Glific.Partners (Glific v5.1.6)
The Partners context. This is the gateway for the application to access/update all the organization and Provider information.
Link to this section Summary
Functions
List of organizations that are active within the system
Check if we can allow attachments for this organization. For now, this is a check to see if GCS is enabled for this organization
Returns an %Ecto.Changeset{}
for tracking organization changes.
Returns an %Ecto.Changeset{}
for tracking provider changes.
Wrapper query used by various statistics collection routines in Glific to return counts on contact with its variations
Return the count of organizations, using the same filter as list_organizations
Return the count of providers, using the same filter as list_providers
Creates an organization's credential
Creates a organization.
Create a Client Data struct
Creates a provider.
Deletes an Organization.
Delete Client Data struct
Deletes a provider.
Disable a specific credential for the organization
Given a minimal organization object, fill it up and store in cache. Making this public so we can call from test harness and avoid SQL Sandbox issues
Returns bsp balance for an organization
Determine if we need to enable contact profile for an organization
Get organization's credential by service shortcode
Determine if we need to show uuid on the nodes.
Convert global field to map for variable substitution
Common function to get the goth config
Get all the services and status for a given organization id.
Gets a single organization.
Returns a map of organizations services as key value pair
Gets a single provider.
Returns quality rating information for an organization provider
check fun_with_flag toggle for an organization and returns boolean value
Get a List for org data
Returns the list of organizations.
Returns the list of providers.
Follow the cachex protocol to load the cache from the DB
Insert or update data if key present for OrganizationData table.
Given an empty list, determine which organizations have been active in the recent past
Cache the entire organization structure.
This contact id is special since it is the sender for all outbound messages and the receiver for all inbound messages
Get the default language id
Get the timezone
Execute a function across all active organizations. This function is typically called by a micron job worker process
Get the organizations which had a message transaction in the last minutes as defined by @active_minutes
Removing organization and service cache
Set BSP APP id whenever we update the bsp credentials.
Suspend an organization till the start of the next day for the organization (we still need to figure out if this is the right WABA interpretation)
Resume all organization that are suspended if we are past the suspended time, we check this on an hourly basis for all organizations that are in a suspended state via a cron job
Updates an organization's credential
Updates an organization.
Update a Client Data struct
Updates a provider.
Link to this section Functions
List of organizations that are active within the system
@spec attachments_enabled?(non_neg_integer()) :: boolean()
Check if we can allow attachments for this organization. For now, this is a check to see if GCS is enabled for this organization
@spec change_organization(Glific.Partners.Organization.t(), map()) :: Ecto.Changeset.t()
Returns an %Ecto.Changeset{}
for tracking organization changes.
examples
Examples
iex> Glific.Partners.change_organization(organization)
%Ecto.Changeset{data: %Glific.Partners.Organization{}}
@spec change_provider(Glific.Partners.Provider.t(), map()) :: Ecto.Changeset.t()
Returns an %Ecto.Changeset{}
for tracking provider changes.
examples
Examples
iex> change_provider(provider) %Ecto.Changeset{data: %Provider{}}
@spec contact_organization_query(list()) :: Ecto.Query.t()
Wrapper query used by various statistics collection routines in Glific to return counts on contact with its variations
Return the count of organizations, using the same filter as list_organizations
Return the count of providers, using the same filter as list_providers
@spec create_credential(map()) :: {:ok, Glific.Partners.Credential.t()} | {:error, any()}
Creates an organization's credential
@spec create_organization(map()) :: {:ok, Glific.Partners.Organization.t()} | {:error, Ecto.Changeset.t()}
Creates a organization.
examples
Examples
iex> Glific.Partners.create_organization(%{name: value})
{:ok, %Glific.Partners.Organization{}}
iex> Glific.Partners.create_organization(%{bad_field: bad_value})
{:error, %Ecto.Changeset{}}
@spec create_organization_data(map()) :: {:ok, Glific.Partners.OrganizationData.t()} | {:error, Ecto.Changeset.t()}
Create a Client Data struct
@spec create_provider(map()) :: {:ok, Glific.Partners.Provider.t()} | {:error, Ecto.Changeset.t()}
Creates a provider.
examples
Examples
iex> create_provider(%{field: value})
{:ok, %Provider{}}
iex> create_provider(%{field: bad_value})
{:error, %Ecto.Changeset{}}
@spec delete_organization(Glific.Partners.Organization.t()) :: {:ok, Glific.Partners.Organization.t()} | {:error, Ecto.Changeset.t()}
Deletes an Organization.
examples
Examples
iex> Glific.Partners.delete_organization(organization)
{:ok, %Glific.Partners.Organization{}}
iex> delete_organization(organization)
{:error, %Ecto.Changeset{}}
@spec delete_organization_data(Glific.Partners.OrganizationData.t()) :: {:ok, Glific.Partners.OrganizationData.t()} | {:error, Ecto.Changeset.t()}
Delete Client Data struct
@spec delete_provider(Glific.Partners.Provider.t()) :: {:ok, Glific.Partners.Provider.t()} | {:error, Ecto.Changeset.t()}
Deletes a provider.
examples
Examples
iex> delete_provider(provider)
{:ok, %Provider{}}
iex> delete_provider(provider)
{:error, %Ecto.Changeset{}}
@spec disable_credential(non_neg_integer(), String.t(), String.t()) :: :ok | {:error, list()}
Disable a specific credential for the organization
@spec fill_cache(Glific.Partners.Organization.t()) :: Glific.Partners.Organization.t()
Given a minimal organization object, fill it up and store in cache. Making this public so we can call from test harness and avoid SQL Sandbox issues
@spec get_bsp_balance(non_neg_integer()) :: {:ok, any()} | {:error, String.t()}
Returns bsp balance for an organization
Determine if we need to enable contact profile for an organization
@spec get_credential(map()) :: {:ok, Glific.Partners.Credential.t()} | {:error, String.t() | [String.t()]}
Get organization's credential by service shortcode
Determine if we need to show uuid on the nodes.
Convert global field to map for variable substitution
@spec get_goth_token(non_neg_integer(), String.t()) :: nil | Goth.Token.t()
Common function to get the goth config
@spec get_org_services_by_id(non_neg_integer()) :: map()
Get all the services and status for a given organization id.
@spec get_organization!(integer()) :: Glific.Partners.Organization.t()
Gets a single organization.
Raises Ecto.NoResultsError
if the organization does not exist.
examples
Examples
iex> Glific.Partners.get_organization!(1) %Glific.Partners.Organization{}
iex> Glific.Partners.get_organization!(-1) ** (Ecto.NoResultsError)
@spec get_organization_services() :: map()
Returns a map of organizations services as key value pair
@spec get_provider!(id :: integer()) :: Glific.Partners.Provider.t()
Gets a single provider.
Raises Ecto.NoResultsError
if the Provider does not exist.
examples
Examples
iex> get_provider!(123)
%Provider{}
iex> get_provider!(456)
** (Ecto.NoResultsError)
@spec get_quality_rating(non_neg_integer()) :: {:ok, any()} | {:error, String.t()}
Returns quality rating information for an organization provider
@spec get_roles_and_permission(Glific.Partners.Organization.t()) :: boolean()
check fun_with_flag toggle for an organization and returns boolean value
@spec list_organization_data(map()) :: [Glific.Partners.Provider.t(), ...]
Get a List for org data
@spec list_organizations(map()) :: [Glific.Partners.Organization.t()]
Returns the list of organizations.
examples
Examples
iex> Glific.Partners.list_organizations()
[%Glific.Partners.Organization{}, ...]
@spec list_providers(map()) :: [Glific.Partners.Provider.t(), ...]
Returns the list of providers.
examples
Examples
iex> list_providers()
[%Provider{}, ...]
@spec load_cache(tuple()) :: {:ignore, Glific.Partners.Organization.t()}
Follow the cachex protocol to load the cache from the DB
@spec maybe_insert_organization_data(String.t(), map(), non_neg_integer()) :: {:ok, Glific.Partners.OrganizationData.t()} | {:error, Ecto.Changeset.t()}
Insert or update data if key present for OrganizationData table.
Given an empty list, determine which organizations have been active in the recent past
@spec organization(non_neg_integer() | String.t()) :: Glific.Partners.Organization.t() | nil | {:error, String.t()}
Cache the entire organization structure.
@spec organization_contact_id(non_neg_integer()) :: integer()
This contact id is special since it is the sender for all outbound messages and the receiver for all inbound messages
@spec organization_language_id(non_neg_integer()) :: integer()
Get the default language id
@spec organization_timezone(non_neg_integer()) :: String.t()
Get the timezone
Execute a function across all active organizations. This function is typically called by a micron job worker process
The handler is expected to take the organization id as its first argument. The second argument is expected to be a map of arguments passed in by the cron job, and can be ignored if not used
The list is a restricted list of organizations, so we don't repeatedly do work. The convention is as follows:
list == nil - the action should not be performed for any organization list == [] (empty list) - the action should be performed for all organizations list == [ values ] - the actions should be performed only for organizations in the values list
Get the organizations which had a message transaction in the last minutes as defined by @active_minutes
@spec remove_organization_cache(non_neg_integer(), String.t()) :: any()
Removing organization and service cache
@spec set_bsp_app_id(Glific.Partners.Organization.t(), String.t()) :: any()
Set BSP APP id whenever we update the bsp credentials.
@spec suspend_organization(Glific.Partners.Organization.t(), non_neg_integer()) :: any()
Suspend an organization till the start of the next day for the organization (we still need to figure out if this is the right WABA interpretation)
@spec unsuspend_organizations() :: any()
Resume all organization that are suspended if we are past the suspended time, we check this on an hourly basis for all organizations that are in a suspended state via a cron job
@spec update_credential(Glific.Partners.Credential.t(), map()) :: {:ok, Glific.Partners.Credential.t()} | {:error, any()}
Updates an organization's credential
@spec update_organization(Glific.Partners.Organization.t(), map()) :: {:ok, Glific.Partners.Organization.t()} | {:error, Ecto.Changeset.t()}
Updates an organization.
examples
Examples
iex> Glific.Partners.update_organization(Organization, %{name: new_name})
{:ok, %Glific.Partners.Organization{}}
iex> Glific.Partners.update_organization(Organization, %{abc: bad_value})
{:error, %Ecto.Changeset{}}
@spec update_organization_data(Glific.Partners.OrganizationData.t(), map()) :: {:ok, Glific.Partners.OrganizationData.t()} | {:error, Ecto.Changeset.t()}
Update a Client Data struct
@spec update_provider(Glific.Partners.Provider.t(), map()) :: {:ok, Glific.Partners.Provider.t()} | {:error, Ecto.Changeset.t()}
Updates a provider.
examples
Examples
iex> update_provider(provider, %{field: new_value})
{:ok, %Provider{}}
iex> update_provider(provider, %{field: bad_value})
{:error, %Ecto.Changeset{}}