store files per-tenant

Signed-off-by: Marc 'risson' Schmitt <marc.schmitt@risson.space>
This commit is contained in:
Marc 'risson' Schmitt 2023-12-04 10:11:59 +01:00
parent f0b8fefd56
commit bfc36bc993
No known key found for this signature in database
GPG Key ID: 9C3FA22FABF1AA8D
2 changed files with 20 additions and 0 deletions

View File

@ -19,6 +19,8 @@ from authentik.stages.password import BACKEND_APP_PASSWORD, BACKEND_INBUILT, BAC
BASE_DIR = Path(__file__).absolute().parent.parent.parent
STATICFILES_DIRS = [BASE_DIR / Path("web")]
MEDIA_ROOT = BASE_DIR / Path("media")
DEFAULT_FILE_STORAGE = "django_tenants.files.storage.TenantFileSystemStorage"
MULTITENANT_RELATIVE_MEDIA_ROOT = "tenants"
DEBUG = CONFIG.get_bool("debug")
SECRET_KEY = CONFIG.get("secret_key")

View File

@ -0,0 +1,18 @@
# flake8: noqa
from pathlib import Path
from lifecycle.migrate import BaseMigration
MEDIA_ROOT = Path(__file__).parent.parent.parent / "media"
TENANT_MEDIA_ROOT = MEDIA_ROOT / "tenants"
class Migration(BaseMigration):
def needs_migration(self) -> bool:
return not TENANT_MEDIA_ROOT.exists()
def run(self):
TENANT_MEDIA_ROOT.mkdir()
for d in ("application-icons", "source-icons", "flow-backgrounds"):
if (MEDIA_ROOT / d).exists():
(MEDIA_ROOT / d).rename(TENANT_MEDIA_ROOT / d)