View Source GlificWeb.Plug (Glific v5.1.6)
This file and the below files have been "borrowed and modified" from triplex: https://github.com/ateliware/triplex The original copyright and license - MIT belong to the authors and contributors of Triplex
- plug.ex
- ensure_plug.ex
- ensure_plug_config.ex
- subdomain_plug.ex
- subdomain_plug_config.ex
- param_plug.ex
- param_plug_config.ex
This module have some basic functions for our triplex plugs.
The plugs we have for now are:
GlificWeb.ParamPlug
- loads the organization from a body or query paramGlificWeb.SubdomainPlug
- loads the organization from the url subdomainGlificWeb.EnsurePlug
- ensures the current organization is loaded and halts if not
Link to this section Summary
Functions
Ensure the organization is loaded, and if not, halts the conn
.
Puts the given organization
as an assign on the given conn
, but only if the
organization is not reserved.
Global unauthorized error handler
Link to this section Functions
@spec ensure_organization(Plug.Conn.t(), map()) :: Plug.Conn.t()
Ensure the organization is loaded, and if not, halts the conn
.
The config
map/struct must have:
assign
: the name of the assign where we must save the organization.
@spec put_organization(Plug.Conn.t(), any(), map()) :: Plug.Conn.t()
Puts the given organization
as an assign on the given conn
, but only if the
organization is not reserved.
The config
map/struct must have:
organization_handler
: function to handle the organization param. Its return will be used as the organization.assign
: the name of the assign where we must save the organization.
@spec send_error(Plug.Conn.t()) :: Plug.Conn.t()
Global unauthorized error handler