Zoonk.Orgs (Zoonk v0.1.0-dev)
View SourceThe 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
Returns an %Ecto.Changeset{}
for tracking org changes.
Examples
iex> change_org(org, %{field: new_value})
%Ecto.Changeset{data: %Org{}}
Returns an Ecto.Changeset{}
for tracking org settings changes.
Examples
iex> change_org_settings(org_settings, %{field: new_value})
%Ecto.Changeset{data: %OrgSettings{}}
Creates an organization.
Examples
iex> create_org(%{name: "My Org", subdomain: "my-org"})
{:ok, %Org{}}
iex> create_org(%{name: "My Org"})
{:error, %Ecto.Changeset{}}
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
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
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