Skip to content

Commit

Permalink
Support multi-tenant in simple mode
Browse files Browse the repository at this point in the history
  • Loading branch information
sbrunner committed Dec 18, 2024
1 parent 9f0c808 commit a95276b
Show file tree
Hide file tree
Showing 10 changed files with 39 additions and 12 deletions.
9 changes: 9 additions & 0 deletions bin/eval-templates
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,13 @@ find /etc/static-ngeo/ \( -name '*.js' -or -name '*.css' -or -name '*.html' \) -
sed --in-place --expression="s#\.__ENTRY_POINT__#${VISIBLE_ENTRY_POINT}#g" "${file}"
done

if [ -d /app/geomapfishapp_geoportal/ ]; then
for name in authentication multi_tenant dev; do
if [ -f "/etc/geomapfish/${name}.py" ]; then
echo "Get: ${name}.py"
cp "/etc/geomapfish/${name}.py" /app/geomapfishapp_geoportal/
fi
done
fi

exec "$@"
4 changes: 2 additions & 2 deletions doc/integrator/create_application.rst
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ We recommend instead that you use dynamic variables as described below.
However, in some use cases extending ``vars.yaml`` may be needed:

* Configuring highly specific environments
* Configuration of a multi-organization project
* Configuration of a multi-tenant project

Use of dynamic variables
........................
Expand Down Expand Up @@ -272,7 +272,7 @@ Do not forget to add your changes to git:

.. note::

If you are using a multi-organization project, you should add all new children to
If you are using a multi-tenant project, you should add all new children to
the parent site check_collector configuration.

After creation and minimal setup the application is ready to be installed.
Expand Down
2 changes: 1 addition & 1 deletion doc/integrator/features.rst
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@ Features that require additional steps (most of the time):
urllogin
pdfreport
routing
multi_organization
multi_tenant
vector_tiles
extend_application
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
.. _integrator_multi_organization:
.. _integrator_multi_tenant:

Multi organization
==================
Multi-tenant
============

The geoportal can host multiple organizations, with configuration differences for each organization.
In a multi-organization geoportal, each organization will have the same program code
Expand All @@ -11,18 +11,21 @@ In this example we will have the came CSS but we can do some variations by using
see ``cssVars`` in ``gmfOptions`` in the ngeo GMF constants definitions
:ngeo_doc:`gmf constants </jsdoc/module-contribs_gmf_src_options.html>`.

The following lines will provide a basic implementation for multi-organization.
The following lines will provide a basic implementation for multi-tenant.

The code should be adapted, currently it handles the hostnames 'org1.camptocamp.com' and
'org2.camptocamp.com', and you probably want to put the hardcoded values in the config.

``__init__.py``
``multi_tenant.py``
---------------

In the file ``geoportal/<package>_geoportal/__init__.py`` add the following lines:
You should have a ``geoportal/<package>_geoportal/multi_tenant.py`` file like this one:

.. code:: python
from pyramid.config import Configurator
def get_instance_prefix(request):
if request.host == "org1.camptocamp.com":
return "org1"
Expand All @@ -49,7 +52,9 @@ In the file ``geoportal/<package>_geoportal/__init__.py`` add the following line
return print_url
# In ``main`` function, after ``config.include("c2cgeoportal_geoportal")``
def includeme(config: Configurator) -> None:
"""Initialize the multi-tenant."""
config.add_request_method(
get_organization_role, name="get_organization_role")
config.add_request_method(
Expand Down
2 changes: 1 addition & 1 deletion doc/integrator/ngeo.rst
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ The sub section is the interface name, and after that we have:
``Request.route_url`` `documentation
<https://docs.pylonsproject.org/projects/pyramid/en/latest/api/request.html#pyramid.request.Request.route_url>`_.

* ``lang_urls_suffix`` suffix used in l10n URL, see: :ref:`integrator_multi_organization`.
* ``lang_urls_suffix`` suffix used in l10n URL, see: :ref:`integrator_multi_tenant`.

The dynamic values names are:

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import {{cookiecutter.package}}_geoportal.authentication
import {{cookiecutter.package}}_geoportal.dev
import {{cookiecutter.package}}_geoportal.multi_organization
import {{cookiecutter.package}}_geoportal.multi_tenant
from c2cgeoportal_geoportal import add_interface_config, locale_negotiator
from c2cgeoportal_geoportal.lib.i18n import LOCALE_PATH
from {{cookiecutter.package}}_geoportal.resources import Root
Expand All @@ -29,6 +30,7 @@ def main(global_config, **settings):
config.include("c2cgeoportal_geoportal")

config.include({{cookiecutter.package}}_geoportal.multi_organization.includeme)
config.include({{cookiecutter.package}}_geoportal.multi_tenant.includeme)

# Scan view decorator for adding routes
config.scan()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@


def includeme(config: Configurator) -> None:
"""Initialize the multi organization."""
"""Initialize the multi-tenant."""

del config # Unused
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
from pyramid.config import Configurator


def includeme(config: Configurator) -> None:
"""Initialize the multi-tenant."""

del config # Unused
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,6 @@
!geoportal/{{cookiecutter.package}}_geoportal/static
!geoportal/{{cookiecutter.package}}_geoportal/locale
geoportal/{{cookiecutter.package}}_geoportal/locale/*.pot
!geoportal/{{cookiecutter.package}}_geoportal/authentication.py
!geoportal/{{cookiecutter.package}}_geoportal/multi_tenant.py
!geoportal/{{cookiecutter.package}}_geoportal/dev.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ ENV PGSCHEMA=$PGSCHEMA

RUN \
cd /tmp/config/geoportal/ \
&& [ "${SIMPLE}" == "TRUE" ] || rm -f {{cookiecutter.package}}_geoportal/*.py \
&& c2c-template --vars ${VARS_FILE} \
--get-config {{cookiecutter.package}}_geoportal/config.yaml \
${CONFIG_VARS} \
Expand Down

0 comments on commit a95276b

Please sign in to comment.