View Source ZoonkWeb.Plugs.School (Zoonk v0.3.0-alpha)
This is a multi-tenant app where we assign schools depending on the host
value.
examples
Examples
app.zoonk.org
->zoonk
schooldavinci.zoonk.org
->davinci
schoolinteractive.harvard.edu
->harvard
school
This means we need to fetch the app school's data when starting this application.
Link to this section Summary
Functions
Fetches the school's data from the database.
Only allows a route if coming from the marketplace.
Handles mounting the school data to a LiveView.
When running the app for the first time, there won't be any schools assigned to the host
.
In those cases, we need to redirect the user to the setup page instead.
Requires authentication for private schools.
Some schools set their visibility to false
through school.public?
.
In those cases none of the school pages should be publicly visible.
Requires manager
permissions to access a certain route.
Requires manager
or teacher
permissions to access a certain route.
Requires a subscription for private schools.
Link to this section Functions
@spec fetch_school(Plug.Conn.t(), Keyword.t()) :: Plug.Conn.t()
Fetches the school's data from the database.
@spec marketplace_only(Plug.Conn.t(), Keyword.t()) :: Plug.Conn.t()
Only allows a route if coming from the marketplace.
@spec on_mount( atom(), Phoenix.LiveView.unsigned_params(), map(), Phoenix.LiveView.Socket.t() ) :: {:cont, Phoenix.LiveView.Socket.t()}
Handles mounting the school data to a LiveView.
on_mount-options
on_mount
options
:mount_school
- Mounts the school from theschool_username
param and thehost
.
@spec redirect_to_setup_school(Plug.Conn.t(), Keyword.t()) :: Plug.Conn.t()
When running the app for the first time, there won't be any schools assigned to the host
.
In those cases, we need to redirect the user to the setup page instead.
@spec require_auth_for_private_schools(Plug.Conn.t(), Keyword.t()) :: Plug.Conn.t()
Requires authentication for private schools.
Some schools set their visibility to false
through school.public?
.
In those cases none of the school pages should be publicly visible.
@spec require_manager(Plug.Conn.t(), Keyword.t()) :: Plug.Conn.t()
Requires manager
permissions to access a certain route.
@spec require_manager_or_teacher(Plug.Conn.t(), Keyword.t()) :: Plug.Conn.t()
Requires manager
or teacher
permissions to access a certain route.
@spec require_subscription_for_private_schools(Plug.Conn.t(), Keyword.t()) :: Plug.Conn.t()
Requires a subscription for private schools.