View Source Zoonk.Organizations (Zoonk v0.1.0-alpha)

Organizations context.

Link to this section Summary

Functions

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

Change a school user's role.

Creates a school.

Deletes a school user.

Gets the parent school of a school.

Gets a single school.

Gets a single school based on the host value.

Gets a single school based on their username.

Get a user from a school given their usernames.

Returns the list of public schools that belong to another school.

List all managers for a school.

List all students for a school.

List all teachers for a school.

List all users for a school.

List all users for a school according to their role.

Returns the list of all schools that belong to another school.

List all schools a user belongs to.

Updates a school.

Link to this section Types

@type school_changeset() ::
  {:ok, Zoonk.Organizations.School.t()}
  | {:error, Ecto.Changeset.t()}
  | {:error, String.t()}
Link to this type

school_user_changeset()

View Source
@type school_user_changeset() ::
  {:ok, Zoonk.Organizations.SchoolUser.t()} | {:error, Ecto.Changeset.t()}

Link to this section Functions

Link to this function

approve_school_user(school_user_id, approved_by_id)

View Source
@spec approve_school_user(integer(), integer()) :: school_user_changeset()

Approves a school user.

examples

Examples

iex> approve_school_user(school_user_id)
{:ok, %SchoolUser{}}

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

change_school(school, attrs \\ %{})

View Source
@spec change_school(Zoonk.Organizations.School.t(), map()) :: Ecto.Changeset.t()

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

examples

Examples

iex> change_school(school)
%Ecto.Changeset{data: %School{}}
Link to this function

change_school_user_role(school_user_id, role)

View Source
@spec change_school_user_role(integer(), atom()) :: school_user_changeset()

Change a school user's role.

examples

Examples

iex> change_school_user_role(school_user_id, :manager)
{:ok, %SchoolUser{}}

iex> change_school_user_role(school_user_id, :invalid)
{:error, %Ecto.Changeset{}}
Link to this function

create_school(attrs \\ %{})

View Source
@spec create_school(map()) :: school_changeset()

Creates a school.

examples

Examples

iex> create_school(%{field: value})
{:ok, %School{}}

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

create_school_user(school, user, attrs \\ %{})

View Source

Adds a user to a school.

examples

Examples

iex> create_school_user(school, user, %{role: :student})
{:ok, %SchoolUser{}}

iex> create_school_user(school, user, %{role: :invalid})
{:error, %Ecto.Changeset{}}
Link to this function

delete_school(school, school_user)

View Source

Deletes a school.

You need to pass a %SchoolUser{} as the second argument to make sure the user has the right permissions because only the school managers can delete a school.

examples

Examples

iex> delete_school(school, school_user)
{:ok, %School{}}

iex> delete_school(school, school_user)
{:error, %Ecto.Changeset{}}

iex> delete_school(school, %{role: :student})
{:error, "You don't have permission to delete this school."}
Link to this function

delete_school_user(school_user_id)

View Source
@spec delete_school_user(integer()) :: school_user_changeset()

Deletes a school user.

examples

Examples

iex> delete_school_user(school_user_id)
{:ok, %SchoolUser{}}

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

get_parent_school(school)

View Source
@spec get_parent_school(Zoonk.Organizations.School.t()) ::
  Zoonk.Organizations.School.t() | nil

Gets the parent school of a school.

examples

Examples

iex> get_parent_school(school)
%School{}
@spec get_school!(non_neg_integer()) :: Zoonk.Organizations.School.t()

Gets a single school.

Raises Ecto.NoResultsError if the School does not exist.

examples

Examples

iex> get_school!(123)
%School{}

iex> get_school!(456)
** (Ecto.NoResultsError)
Link to this function

get_school_by_host(host)

View Source
@spec get_school_by_host(String.t()) :: Zoonk.Organizations.School.t() | nil

Gets a single school based on the host value.

examples

Examples

iex> get_school_by_host("unisc.zoonk.org")
%School{}

iex> get_school_by_host("interactive.rug.nl")
%School{}

iex> get_school_by_host("nonexisting.com")
nil
Link to this function

get_school_by_username!(username)

View Source
@spec get_school_by_username!(String.t()) :: Zoonk.Organizations.School.t()

Gets a single school based on their username.

examples

Examples

iex> get_school_by_username!("unisc")
%School{}

iex> get_school_by_username!("nonexisting")
** (Ecto.NoResultsError)
Link to this function

get_school_user(school_username, user_username)

View Source
@spec get_school_user(String.t(), String.t()) ::
  Zoonk.Organizations.SchoolUser.t() | nil

Get a user from a school given their usernames.

examples

Examples

iex> get_school_user("zoonk", "will")
%SchoolUser{}

iex> get_school_user("zoonk", "invalid")
nil
Link to this function

list_public_schools(parent_school)

View Source
@spec list_public_schools(Zoonk.Organizations.School.t()) :: [
  Zoonk.Organizations.School.t()
]

Returns the list of public schools that belong to another school.

If you want to list schools specific to a user, you should use list_schools_for_user/1 instead.

examples

Examples

iex> list_schools(%School{})
[%School{}, ...]
Link to this function

list_school_managers(school)

View Source
@spec list_school_managers(Zoonk.Organizations.School.t()) :: [
  Zoonk.Accounts.User.t()
]

List all managers for a school.

examples

Examples

iex> list_school_managers(school)
[%User{}, ...]
Link to this function

list_school_students(school)

View Source
@spec list_school_students(Zoonk.Organizations.School.t()) :: [
  Zoonk.Accounts.User.t()
]

List all students for a school.

examples

Examples

iex> list_school_students(school)
[%User{}, ...]
Link to this function

list_school_teachers(school)

View Source
@spec list_school_teachers(Zoonk.Organizations.School.t()) :: [
  Zoonk.Accounts.User.t()
]

List all teachers for a school.

examples

Examples

iex> list_school_teachers(school)
[%User{}, ...]
Link to this function

list_school_users(school)

View Source
@spec list_school_users(Zoonk.Organizations.School.t()) :: [Zoonk.Accounts.User.t()]

List all users for a school.

examples

Examples

iex> list_school_users(school)
[%User{}, ...]
Link to this function

list_school_users_by_role(school, role)

View Source
@spec list_school_users_by_role(Zoonk.Organizations.School.t(), atom()) :: [
  Zoonk.Accounts.User.t()
]

List all users for a school according to their role.

examples

Examples

iex> list_school_users_by_role(school, :manager)
[%User{}, ...]
Link to this function

list_schools(parent_school)

View Source

Returns the list of all schools that belong to another school.

If you want to list schools specific to a user, you should use list_schools_for_user/1 instead.

examples

Examples

iex> list_schools(%School{})
[%School{}, ...]
Link to this function

list_schools_for_user(user)

View Source
@spec list_schools_for_user(Zoonk.Accounts.User.t()) :: [
  Zoonk.Organizations.SchoolUser.t()
]

List all schools a user belongs to.

examples

Examples

iex> list_schools_for_user(%User{})
[%SchoolUser{}, ...]
Link to this function

update_school(school, attrs)

View Source
@spec update_school(Zoonk.Organizations.School.t(), map()) :: school_changeset()

Updates a school.

examples

Examples

iex> update_school(school, %{field: new_value})
{:ok, %School{}}

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

update_school_user(school_user, attrs)

View Source
@spec update_school_user(Zoonk.Organizations.SchoolUser.t(), map()) ::
  school_user_changeset()

Updates a school user.

examples

Examples

iex> update_school_user(school_user, %{role: :teacher})
{:ok, %School{}}

iex> update_school_user(school_user, %{role: :invalid})
{:error, %Ecto.Changeset{}}