Zoonk.Orgs (Zoonk v0.1.0-dev)

View Source

The Orgs context.

Zoonk is a multi-tenant application. Therefore, we need to keep track of organizations and their members.

This context is responsible for managing organizations, their settings, and members.

Summary

Functions

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

Returns an Ecto.Changeset{} for tracking org settings changes.

Creates an organization.

Gets an organization by host value.

Gets an org member.

Gets org settings.

Functions

change_org(org, attrs \\ %{})

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

Examples

iex> change_org(org, %{field: new_value})
%Ecto.Changeset{data: %Org{}}

change_org_settings(org_settings, attrs \\ %{})

Returns an Ecto.Changeset{} for tracking org settings changes.

Examples

iex> change_org_settings(org_settings, %{field: new_value})
%Ecto.Changeset{data: %OrgSettings{}}

create_org(kind, attrs \\ %{})

Creates an organization.

Examples

iex> create_org(%{name: "My Org", subdomain: "my-org"})
{:ok, %Org{}}

iex> create_org(%{name: "My Org"})
{:error, %Ecto.Changeset{}}

get_org_by_host(host)

Gets an organization by host value.

Examples

iex> get_org_by_host("custom-domain.com")
%Org{custom_domain: "custom-domain.com"}

iex> get_org_by_host("subdomain.zoonk.com")
%Org{subdomain: "subdomain"}

iex> get_org_by_host("unknown.zoonk.com")
nil

get_org_member(org, user)

Gets an org member.

Examples

iex> get_org_member(%Org{}, %User{})
%OrgMember{user_id: user.id, org_id: org.id}

iex> get_org_member(%Org{}, nil)
nil

get_org_settings(scope)

Gets org settings.

Given a Zoonk.Scope, allows org admins to retrieve settings for their organization.

Examples

iex> get_org_settings(%Scope{org_member: %{role: :admin}})
%OrgSettings{}

iex> get_org_settings(%Scope{org_member: %{role: :member}})
nil

iex> get_org_settings(%Scope{org_id: nil})
nil