View Source Glific.Groups (Glific v5.1.6)

The Groups context.

Link to this section Summary

Functions

Add permissioning specific to groups, in this case we want to restrict the visibility of groups that the user can see

Returns an %Ecto.Changeset{} for tracking group changes.

Get the contacts ids for a specific group that have not opted out

Return the count of group contacts

Return the count of groups, using the same filter as list_groups

Creates a contact group.

Creates a group.

Creates a user group.

Deletes a group.

Gets a single group.

Fetches all group ids in an organization

Get group by group name. Create the group if it does not exist

Given a group id, get stats on the contacts within this group based on bsp_status and also the total count

Returns the list of groups.

Returns the list of groups.

This function will load id by label

Updates a group.

Updates user groups entries

Return the count of group users

Link to this section Functions

Link to this function

add_permission(query, user)

View Source
@spec add_permission(Ecto.Query.t(), Glific.Users.User.t()) :: Ecto.Query.t()

Add permissioning specific to groups, in this case we want to restrict the visibility of groups that the user can see

Link to this function

change_group(group, attrs \\ %{})

View Source
@spec change_group(Glific.Groups.Group.t(), map()) :: Ecto.Changeset.t()

Returns an %Ecto.Changeset{} for tracking group changes.

examples

Examples

iex> change_group(group)
%Ecto.Changeset{data: %Group{}}
@spec contact_ids(non_neg_integer()) :: [non_neg_integer()]

Get the contacts ids for a specific group that have not opted out

@spec contacts_count(map()) :: integer()

Return the count of group contacts

@spec count_groups(map()) :: integer()

Return the count of groups, using the same filter as list_groups

Link to this function

create_contact_group(attrs \\ %{})

View Source
@spec create_contact_group(map()) ::
  {:ok, Glific.Groups.ContactGroup.t()} | {:error, Ecto.Changeset.t()}

Creates a contact group.

examples

Examples

iex> create_contact_group(%{field: value})
{:ok, %Contact{}}

iex> create_contact_group(%{field: bad_value})
{:error, %Ecto.Changeset{}}
Link to this function

create_group(attrs \\ %{})

View Source
@spec create_group(map()) ::
  {:ok, Glific.Groups.Group.t()} | {:error, Ecto.Changeset.t()}

Creates a group.

examples

Examples

iex> create_group(%{field: value})
{:ok, %Group{}}

iex> create_group(%{field: bad_value})
{:error, %Ecto.Changeset{}}
Link to this function

create_user_group(attrs \\ %{})

View Source
@spec create_user_group(map()) ::
  {:ok, Glific.Groups.UserGroup.t()} | {:error, Ecto.Changeset.t()}

Creates a user group.

examples

Examples

iex> create_user_group(%{field: value})
{:ok, %User{}}

iex> create_user_group(%{field: bad_value})
{:error, %Ecto.Changeset{}}
Link to this function

delete_contact_groups_by_ids(contact_id, group_ids)

View Source
@spec delete_contact_groups_by_ids(integer(), list()) :: {integer(), nil | [term()]}

Delete contact groups

@spec delete_group(Glific.Groups.Group.t()) ::
  {:ok, Glific.Groups.Group.t()} | {:error, Ecto.Changeset.t()}

Deletes a group.

examples

Examples

iex> delete_group(group)
{:ok, %Group{}}

iex> delete_group(group)
{:error, %Ecto.Changeset{}}
Link to this function

delete_group_contacts_by_ids(group_id, contact_ids)

View Source
@spec delete_group_contacts_by_ids(integer(), list()) :: {integer(), nil | [term()]}

Delete group contacts

Link to this function

delete_group_users_by_ids(group_id, user_ids)

View Source
@spec delete_group_users_by_ids(integer(), []) :: {integer(), nil | [term()]}

Delete group users

Link to this function

delete_user_groups_by_ids(user_id, group_ids)

View Source
@spec delete_user_groups_by_ids(integer(), []) :: {integer(), nil | [term()]}

Delete user groups

@spec get_group!(integer()) :: Glific.Groups.Group.t()

Gets a single group.

Raises Ecto.NoResultsError if the Group does not exist.

examples

Examples

iex> get_group!(123)
%Group{}

iex> get_group!(456)
** (Ecto.NoResultsError)
@spec get_group_ids() :: list()

Fetches all group ids in an organization

Link to this function

get_or_create_group_by_label(label, organization_id)

View Source
@spec get_or_create_group_by_label(String.t(), non_neg_integer()) ::
  {:ok, Glific.Groups.Group.t()} | nil

Get group by group name. Create the group if it does not exist

Link to this function

info_group_contacts(group_id)

View Source
@spec info_group_contacts(non_neg_integer()) :: map()

Given a group id, get stats on the contacts within this group based on bsp_status and also the total count

Link to this function

list_groups(args, skip_permission \\ false)

View Source
@spec list_groups(map(), boolean()) :: [Glific.Groups.Group.t()]

Returns the list of groups.

examples

Examples

iex> list_groups()
[%Group{}, ...]
Link to this function

list_organizations_groups(args)

View Source
@spec list_organizations_groups(map()) :: [Glific.Groups.Group.t()]

Returns the list of groups.

examples

Examples

iex> list_organizations_groups()
[%Group{}, ...]
Link to this function

load_group_by_label(group_label)

View Source
@spec load_group_by_label(any()) :: list()

This function will load id by label

Link to this function

update_group(group, attrs)

View Source
@spec update_group(Glific.Groups.Group.t(), map()) ::
  {:ok, Glific.Groups.Group.t()} | {:error, Ecto.Changeset.t()}

Updates a group.

examples

Examples

iex> update_group(group, %{field: new_value})
{:ok, %Group{}}

iex> update_group(group, %{field: bad_value})
{:error, %Ecto.Changeset{}}
@spec update_user_groups(map()) :: :ok

Updates user groups entries

@spec users_count(map()) :: integer()

Return the count of group users