View Source GlificWeb.Tenants (Glific v5.1.6)

This is the main module of multi-tenancy in Glific. It has been borrowed from Triplex. (https://github.com/ateliware/triplex). However we are going to us postgres row level security instead, and hence copying the code from there. The original copyright and license (MIT) belong to the contributors to Triplex.

The main objective of it is to make a little bit easier to manage organizations through postgres db schemas or equivalents, executing queries and commands inside and outside the organization without much boilerplate code.

Link to this section Summary

Functions

Given a string from the connection info (subdomain), check and retrieve the organization id.

Given a conn object, get the remote ip of the user as a string

Returns if the given organization is reserved or not.

Returns the list of reserved organizations.

Link to this section Functions

Link to this function

organization_handler(name \\ nil)

View Source
@spec organization_handler(String.t() | nil) :: integer()

Given a string from the connection info (subdomain), check and retrieve the organization id.

For the short term, we'll default to organization id Glific, if we cannot resolve the sub-domain, we'll remove this in v0.4

@spec remote_ip(Plug.Conn.t()) :: String.t()

Given a conn object, get the remote ip of the user as a string

Link to this function

reserved_organization?(prefix)

View Source
@spec reserved_organization?(String.t()) :: boolean()

Returns if the given organization is reserved or not.

The function to_prefix/1 will be applied to the organization.

Link to this function

reserved_organizations()

View Source
@spec reserved_organizations() :: list()

Returns the list of reserved organizations.

By default, there are some limitations for the name of a organization depending on the database, like "public" or anything that start with "pg_".

Notice that you can use regexes, and they will be applied to the organization names.