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.

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

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.

Updates a provider.

Link to this section Functions

Link to this function

active_organizations(orgs, suspended \\ false)

View Source
@spec active_organizations(list(), boolean()) :: map()

List of organizations that are active within the system

Link to this function

attachments_enabled?(organization_id)

View Source
@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

Link to this function

change_organization(organization, attrs \\ %{})

View Source
@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{}}
Link to this function

change_provider(provider, attrs \\ %{})

View Source
@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{}}

Link to this function

contact_organization_query(org_id_list)

View Source
@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

Link to this function

count_organizations(args \\ %{})

View Source
@spec count_organizations(map()) :: integer()

Return the count of organizations, using the same filter as list_organizations

Link to this function

count_providers(args \\ %{})

View Source
@spec count_providers(map()) :: integer()

Return the count of providers, using the same filter as list_providers

Link to this function

create_credential(attrs)

View Source
@spec create_credential(map()) ::
  {:ok, Glific.Partners.Credential.t()} | {:error, any()}

Creates an organization's credential

Link to this function

create_organization(attrs \\ %{})

View Source
@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{}}
Link to this function

create_organization_data(attrs \\ %{})

View Source
@spec create_organization_data(map()) ::
  {:ok, Glific.Partners.OrganizationData.t()} | {:error, Ecto.Changeset.t()}

Create a Client Data struct

Link to this function

create_provider(attrs \\ %{})

View Source
@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{}}
Link to this function

delete_organization(organization)

View Source
@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{}}
Link to this function

delete_organization_data(organization_data)

View Source
@spec delete_organization_data(Glific.Partners.OrganizationData.t()) ::
  {:ok, Glific.Partners.OrganizationData.t()} | {:error, Ecto.Changeset.t()}

Delete Client Data struct

Link to this function

delete_provider(provider)

View Source
@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{}}
Link to this function

disable_credential(organization_id, shortcode, error_message)

View Source
@spec disable_credential(non_neg_integer(), String.t(), String.t()) ::
  :ok | {:error, list()}

Disable a specific credential for the organization

Link to this function

fill_cache(organization)

View Source

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

Link to this function

get_bsp_balance(organization_id)

View Source
@spec get_bsp_balance(non_neg_integer()) :: {:ok, any()} | {:error, String.t()}

Returns bsp balance for an organization

Link to this function

get_contact_profile_enabled(organization)

View Source
@spec get_contact_profile_enabled(map()) :: boolean()

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

Link to this function

get_flow_uuid_display(organization)

View Source
@spec get_flow_uuid_display(map()) :: boolean()

Determine if we need to show uuid on the nodes.

Link to this function

get_global_field_map(organization_id)

View Source
@spec get_global_field_map(integer()) :: map()

Convert global field to map for variable substitution

Link to this function

get_goth_token(organization_id, provider_shortcode)

View Source
@spec get_goth_token(non_neg_integer(), String.t()) :: nil | Goth.Token.t()

Common function to get the goth config

Link to this function

get_org_services_by_id(organization_id)

View Source
@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)

Link to this function

get_organization_services()

View Source
@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)
Link to this function

get_quality_rating(organization_id)

View Source
@spec get_quality_rating(non_neg_integer()) :: {:ok, any()} | {:error, String.t()}

Returns quality rating information for an organization provider

Link to this function

get_roles_and_permission(organization)

View Source
@spec get_roles_and_permission(Glific.Partners.Organization.t()) :: boolean()

check fun_with_flag toggle for an organization and returns boolean value

Link to this function

list_organization_data(args \\ %{})

View Source
@spec list_organization_data(map()) :: [Glific.Partners.Provider.t(), ...]

Get a List for org data

Link to this function

list_organizations(args \\ %{})

View Source
@spec list_organizations(map()) :: [Glific.Partners.Organization.t()]

Returns the list of organizations.

examples

Examples

iex> Glific.Partners.list_organizations()
[%Glific.Partners.Organization{}, ...]
Link to this function

list_providers(args \\ %{})

View Source
@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

Link to this function

maybe_insert_organization_data(key, data, org_id)

View Source
@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.

Link to this function

org_id_list(list, recent)

View Source
@spec org_id_list(list(), boolean()) :: list()

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.

Link to this function

organization_contact_id(organization_id)

View Source
@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

Link to this function

organization_language_id(organization_id)

View Source
@spec organization_language_id(non_neg_integer()) :: integer()

Get the default language id

Link to this function

organization_timezone(organization_id)

View Source
@spec organization_timezone(non_neg_integer()) :: String.t()

Get the timezone

Link to this function

perform_all(handler, handler_args, list, opts \\ [])

View Source
@spec perform_all((... -> nil), map() | nil, list() | [] | nil, Keyword.t()) :: any()

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

Link to this function

recent_organizations(map, bool)

View Source
@spec recent_organizations(map(), boolean()) :: map()

Get the organizations which had a message transaction in the last minutes as defined by @active_minutes

Link to this function

remove_organization_cache(organization_id, shortcode)

View Source
@spec remove_organization_cache(non_neg_integer(), String.t()) :: any()

Removing organization and service cache

Link to this function

set_bsp_app_id(org, shortcode)

View Source
@spec set_bsp_app_id(Glific.Partners.Organization.t(), String.t()) :: any()

Set BSP APP id whenever we update the bsp credentials.

Link to this function

suspend_organization(organization, hours \\ 0)

View Source
@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)

Link to this function

unsuspend_organizations()

View Source
@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

Link to this function

update_credential(credential, attrs)

View Source
@spec update_credential(Glific.Partners.Credential.t(), map()) ::
  {:ok, Glific.Partners.Credential.t()} | {:error, any()}

Updates an organization's credential

Link to this function

update_organization(organization, attrs)

View Source
@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{}}
Link to this function

update_organization_data(organization_data, attrs)

View Source
@spec update_organization_data(Glific.Partners.OrganizationData.t(), map()) ::
  {:ok, Glific.Partners.OrganizationData.t()} | {:error, Ecto.Changeset.t()}

Update a Client Data struct

Link to this function

update_provider(provider, attrs)

View Source
@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{}}