Skip to content

Commit fde584f

Browse files
authored
multi tenant (#296)
* Add multi tenant system * Fix tests * Bump version 2.0.0 * Clean code * Fix celery * Add ignore * Fix beat scheduler * Split media by folder and update the serve view for dev * Update nginx to return correct media folder for tenant * Fix flake * Fix periodic task always using utc * Rename field * Revert tests * Clean code * Fix tests * Update workflows * Fix tests * Update tenant based tests * Add model limitation content and apply to project * Add dashboard indicator layer limitation * Add other dashboard relations limitation * Fix flake * Update requirements * De-couple tenants * Move tenants to geosight folder * Refactor * Fix media to use default django tenants approach * Hide tenant admin from non public tenant * Fix tests * Move utils folder to georepo * Add create tenant API * Fix tests * Add content limitation API * Refactor tenants model * Refactor models * Add limitation API update and tests * Add PLUGINS as env * Update cloud native gis as plugin * Update code * Fix entrypoints
1 parent cd34e97 commit fde584f

File tree

152 files changed

+3616
-620
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

152 files changed

+3616
-620
lines changed

.github/workflows/tests.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ name: Tests
1515

1616
on:
1717
push:
18-
branches: [ main ]
18+
branches: [ main, version-2.0.0 ]
1919
pull_request:
2020
branches: [ main, version-2.0.0 ]
2121

deployment/.template.env

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ SECRET_KEY=SECRET_KEY
33

44
COMPOSE_PROJECT_NAME=geosight
55
NGINX_TAG=0.0.1
6-
DJANGO_TAG=0.4.0
6+
DJANGO_TAG=2.0.0
77

88
# Environments
99
DJANGO_SETTINGS_MODULE=core.settings.prod
@@ -41,4 +41,20 @@ EMAIL_HOST_USER=
4141
EMAIL_HOST_PASSWORD=
4242
EMAIL_USE_TLS=
4343
EMAIL_USE_SSL=
44-
DEFAULT_FROM_EMAIL=
44+
DEFAULT_FROM_EMAIL=
45+
46+
# --------------------------------
47+
# ---------- APP DOMAIN ----------
48+
# This is needed for tenants
49+
APP_DOMAIN=localhost
50+
51+
# -------------------------------
52+
# ---------- PLUGINS ------------
53+
# Add or remove the app that you want the app
54+
# Put it in comma separator
55+
56+
# Plugins app on GeoSight
57+
# - tenants
58+
# - cloud_native_gis
59+
PLUGINS=tenants,cloud_native_gis
60+
# -----------------------------

deployment/docker-compose.test.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ services:
5757
5858
- SENTRY_DSN=
5959
- SENTRY_ENVIRONMENT=staging
60+
- PLUGINS=tenants
6061
entrypoint: [ ]
6162
ports:
6263
# for django test server

deployment/docker-compose.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,9 @@ x-common-django:
6060
- EMAIL_USE_TLS=${EMAIL_USE_TLS:-False}
6161
- EMAIL_USE_SSL=${EMAIL_USE_SSL:-False}
6262
- DEFAULT_FROM_EMAIL=${DEFAULT_FROM_EMAIL:[email protected]}
63+
64+
# PLUGINS
65+
- PLUGINS=${PLUGINS:-''}
6366
volumes:
6467
- static-data:/home/web/static
6568
- media-data:/home/web/media

deployment/docker/requirements.txt

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,4 +48,12 @@ msal==1.21.0
4848
selenium==4.13.0
4949
webdriver-manager==4.0.1
5050

51-
git+https://github.com/kartoza/CloudNativeGIS.git@updates
51+
git+https://github.com/kartoza/CloudNativeGIS.git@updates
52+
53+
# FEATURE: Multi tenant
54+
# Comment below for excluding the multi tenants feature
55+
# -----------------------------------------------------
56+
django-tenants==3.6.1
57+
tenant-schemas-celery==3.0.0
58+
django-tenants-celery-beat==0.2.1
59+
# -----------------------------------------------------

deployment/nginx/sites-enabled/default.conf

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,14 @@ server {
4040

4141
# max upload size, adjust to taste
4242
client_max_body_size 15M;
43+
4344
# Django media
4445
location /media {
4546
# your Django project's media files - amend as required
4647
alias /home/web/media;
4748
expires 21d; # cache for 71 days
4849
}
50+
4951
location /static {
5052
# your Django project's static files - amend as required
5153
alias /home/web/static;

django_project/core/celery.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,12 @@
33

44
import os
55

6-
from celery import Celery
6+
from django.conf import settings
7+
8+
if settings.TENANTS_ENABLED:
9+
from tenant_schemas_celery.app import CeleryApp as Celery
10+
else:
11+
from celery import Celery
712

813
"""
914
GeoSight is UNICEF's geospatial web-based business intelligence platform.
@@ -16,6 +21,7 @@
1621
(at your option) any later version.
1722
1823
"""
24+
1925
__author__ = '[email protected]'
2026
__date__ = '13/06/2023'
2127
__copyright__ = ('Copyright 2023, Unicef')

django_project/core/context_processors/global_context.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,12 @@ def global_context(request):
5252
api_key_email=request.user.email
5353

5454
).details
55+
5556
return {
5657
'DEBUG': settings.DEBUG,
5758
'preferences': pref_data,
5859
'preferences_js': json.dumps(pref_data),
5960
'use_azure_auth': settings.USE_AZURE,
60-
'version': project_version(request)
61+
'version': project_version(request),
62+
'plugins': settings.PLUGINS
6163
}
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
# coding=utf-8
2+
"""
3+
GeoSight is UNICEF's geospatial web-based business intelligence platform.
4+
5+
6+
7+
.. note:: This program is free software; you can redistribute it and/or modify
8+
it under the terms of the GNU Affero General Public License as published by
9+
the Free Software Foundation; either version 3 of the License, or
10+
(at your option) any later version.
11+
12+
"""
13+
__author__ = '[email protected]'
14+
__date__ = '20/08/2024'
15+
__copyright__ = ('Copyright 2023, Unicef')
16+
17+
from .cloud_native_gis import *
18+
from .contrib import *
19+
from .django import *
20+
from .project import *
21+
from .tenants import *
22+
23+
# --------------------------------------
24+
# FEATURE: SSL
25+
# --------------------------------------
26+
try:
27+
import sslserver # noqa:F401
28+
29+
CONTRIB_APPS = CONTRIB_APPS + [
30+
'sslserver',
31+
]
32+
except ImportError:
33+
pass
34+
35+
SHARED_APPS = (
36+
TENANTS_APPS + DJANGO_APPS + CONTRIB_APPS + PROJECT_APPS +
37+
CLOUD_NATIVE_GIS_APPS
38+
)
39+
TENANT_APPS = (
40+
DJANGO_APPS_TENANT + CONTRIB_APPS_TENANT + TENANTS_CONTRIB_APPS +
41+
PROJECT_APPS + CLOUD_NATIVE_GIS_APPS
42+
)
43+
44+
# Save it to installed apps
45+
INSTALLED_APPS = SHARED_APPS + [
46+
app for app in TENANT_APPS if app not in SHARED_APPS
47+
]
48+
49+
# Check plugins
50+
PLUGINS = []
51+
if CLOUD_NATIVE_GIS_ENABLED:
52+
PLUGINS.append(CLOUD_NATIVE_GIS_PLUGIN_NAME)
53+
if TENANTS_ENABLED:
54+
PLUGINS.append(TENANTS_PLUGIN_NAME)
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# coding=utf-8
2+
"""
3+
GeoSight is UNICEF's geospatial web-based business intelligence platform.
4+
5+
6+
7+
.. note:: This program is free software; you can redistribute it and/or modify
8+
it under the terms of the GNU Affero General Public License as published by
9+
the Free Software Foundation; either version 3 of the License, or
10+
(at your option) any later version.
11+
12+
THIS IS PLUGIN.
13+
"""
14+
15+
__author__ = '[email protected]'
16+
__date__ = '20/08/2024'
17+
__copyright__ = ('Copyright 2023, Unicef')
18+
19+
import os
20+
21+
CLOUD_NATIVE_GIS_PLUGIN_NAME = 'cloud_native_gis'
22+
CLOUD_NATIVE_GIS_APPS = []
23+
CLOUD_NATIVE_GIS_ENABLED = False
24+
25+
# --------------------------------------
26+
# FEATURE: CLOUD NATIVE GIS
27+
# --------------------------------------
28+
try:
29+
import cloud_native_gis # noqa:F401
30+
CLOUD_NATIVE_GIS_ENABLED = CLOUD_NATIVE_GIS_PLUGIN_NAME in os.environ.get(
31+
'PLUGINS', ''
32+
)
33+
except ImportError:
34+
pass
35+
36+
if CLOUD_NATIVE_GIS_ENABLED:
37+
CLOUD_NATIVE_GIS_APPS = [
38+
'cloud_native_gis',
39+
'geosight.cloud_native_gis'
40+
]

0 commit comments

Comments
 (0)