wagtail-tenants


Namewagtail-tenants JSON
Version 0.2.0 PyPI version JSON
download
home_pagehttps://wagtail-tenants.readthedocs.io/en/latest/
SummaryAdds multitenancy based on django_tenants to wagtail cms
upload_time2023-09-05 10:35:33
maintainer
docs_urlNone
authorBoris Brue
requires_python>=3.9.0,<4.0.0
licenseMIT
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # wagtail-tenants

[![Documentation Status](https://readthedocs.org/projects/wagtail-tenants/badge/?version=latest)](https://wagtail-tenants.readthedocs.io/en/latest/?badge=latest)
[![Testing the wagtail tenants with postgres](https://github.com/borisbrue/wagtail-tenants/actions/workflows/integrationtest.yml/badge.svg)](https://github.com/borisbrue/wagtail-tenants/actions/workflows/integrationtest.yml)

wagtail_tenants is a Django/Wagtail app to provide multitenancy to your wagtail project.
You are able to run a main Wagtail Site and from within you are able to host as many Wagtailsites as you want. 
django_tenants is used to slice the database layer in a postgres database based on a given schema.

Detailed documentation will be in the "docs" directory. 

## Quick start

### Installation

```bash
pip install wagtail-tenants
```

### Configuration

1. Add "wagtail_tenants" to your INSTALLED_APPS setting like this:

    ```python
    SHARED_APPS = (
        'wagtail_tenants.customers',
        'wagtail_tenants',
        'wagtail.contrib.forms',
        ...
        "wagtail_tenants.users",
        "wagtail.users",
        ...
    )

    TENANT_APPS = (
        'wagtail_tenants',
        "django.contrib.contenttypes",
        ...
        # rest of the wagtail apps
        ...
        "wagtail_tenants.users",
        "wagtail.users",
        ...
    )

    INSTALLED_APPS = list(SHARED_APPS) + [
        app for app in TENANT_APPS if app not in SHARED_APPS
    ]
    ```

2. Include the the tenants middleware at the beginning of your middlewares:

    ```python
    MIDDLEWARE = [
    "wagtail_tenants.middleware.main.WagtailTenantMainMiddleware",
    ...
    ]
    ```

3. Define the Tenant model Constants (and also set the default auto field if not already done):

    ```python
    AUTH_USER_MODEL = 'wagtail_tenants.User' 
    TENANT_MODEL = "customers.Client" 
    TENANT_DOMAIN_MODEL = "customers.Domain"
    DEFAULT_AUTO_FIELD='django.db.models.AutoField'
    ```

4. Set the Database backend to the **django_tenants** backend:

    ```python
    DATABASES = {
        "default": {
            "ENGINE": "django_tenants.postgresql_backend",
            "NAME": "db_name",
            "USER": "db_user",
            "PASSWORD": "",
            "HOST": "127.0.0.1",
            "PORT": "5432",
        }
    }
    ```

5. Set the Database Router to work with the tenants:

    ```python
    DATABASE_ROUTERS = ("wagtail_tenants.routers.WagtailTenantSyncRouter",)
    ```

6. Set the authentication backend to fit to our Tenant model.

    ```python
    AUTHENTICATION_BACKENDS = [
        'wagtail_tenants.backends.TenantBackend',
    ]
    ```

7. Run the migrations with `./manage.py migrate_schemas --shared`
8. Create a public schema with `./manage.py create_tenant` and use `public` as the schema name and `localhost`
9. Create a superuser for the public tenant `./manage.py create_tenant_superuser`
10. Start the Server and have fun
11. You are able to create tenants within the admin of your public wagtailsite. If you want to log into a tenant you need at least one superuser for the tenant. You can use `./manage.py create_tenant_superuser` for that.


### Update 0.1.10

The new version of wagtail_tenants is now able to archive the follwing features:

#### wagtail 4.2. support

As the developemt of wagtail still goes on, so we do. Wagtail incuded a reference index for models it was necessary to handle this feature, as we don 't need this feature on our tenant models.

#### Create tenantaware apps

Only users of a given tenant are able to interact within the wagtail admin with that kind of app.
This works in two ways:

1. Add a tenantaware property to the apps AppConfig class in `yourtenantapp.apps.py` 
in the `admin.py` create a ModelAdmin or ModelAdminGroup for your app and use the `menu_item_name` property to fit to your apps name from your AppConfig. If this fits the app will be hidden for all tenants withou a TenantFeaure of the same name. This feature is good for providing different tiers of your app (eg. free | premium )

2. You can specify the tenant directly within the AppConfig so that only users of the tenant have access to this app. This is necessary if you want to create complete and complex functionality only for one tenant. To archive this you have to add the `WagtailTenantPermissionMiddleware`to your middlewares in your settings like so: 

```python
MIDDLEWARE = [
    "wagtail_tenants.middleware.main.WagtailTenantMainMiddleware",
    "wagtail_tenants.middleware.main.WagtailTenantPermissionMiddleware",
    "..."
]
```

#### Exclude permissions from normal users in the group create and group edit view

We are able to hide apps from the group create and group edit views in the wagtail admin. With this approach it is possible to create a tenant admin group with all permissions and distribute it to a tenant user. The tenant admin is able to create and edit groups, but you can decide which apps should be excluded from the view. By default this should include all customers apps. But feel free to extend the list.

```python
TENANT_EXCLUDE_MODEL_PERMISSIONS = [
    "customers.Client",
    "customers.ClientFeature",
    "customers.Domain",
    "customers.ClientBackup",
]
```
            

Raw data

            {
    "_id": null,
    "home_page": "https://wagtail-tenants.readthedocs.io/en/latest/",
    "name": "wagtail-tenants",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.9.0,<4.0.0",
    "maintainer_email": "",
    "keywords": "",
    "author": "Boris Brue",
    "author_email": "boris@zuckersalzundpfeffer.de",
    "download_url": "https://files.pythonhosted.org/packages/d7/a8/717f82a651cd4e43504861e386c36255f925480cd7796e039063b81bd4c8/wagtail_tenants-0.2.0.tar.gz",
    "platform": null,
    "description": "# wagtail-tenants\n\n[![Documentation Status](https://readthedocs.org/projects/wagtail-tenants/badge/?version=latest)](https://wagtail-tenants.readthedocs.io/en/latest/?badge=latest)\n[![Testing the wagtail tenants with postgres](https://github.com/borisbrue/wagtail-tenants/actions/workflows/integrationtest.yml/badge.svg)](https://github.com/borisbrue/wagtail-tenants/actions/workflows/integrationtest.yml)\n\nwagtail_tenants is a Django/Wagtail app to provide multitenancy to your wagtail project.\nYou are able to run a main Wagtail Site and from within you are able to host as many Wagtailsites as you want. \ndjango_tenants is used to slice the database layer in a postgres database based on a given schema.\n\nDetailed documentation will be in the \"docs\" directory. \n\n## Quick start\n\n### Installation\n\n```bash\npip install wagtail-tenants\n```\n\n### Configuration\n\n1. Add \"wagtail_tenants\" to your INSTALLED_APPS setting like this:\n\n    ```python\n    SHARED_APPS = (\n        'wagtail_tenants.customers',\n        'wagtail_tenants',\n        'wagtail.contrib.forms',\n        ...\n        \"wagtail_tenants.users\",\n        \"wagtail.users\",\n        ...\n    )\n\n    TENANT_APPS = (\n        'wagtail_tenants',\n        \"django.contrib.contenttypes\",\n        ...\n        # rest of the wagtail apps\n        ...\n        \"wagtail_tenants.users\",\n        \"wagtail.users\",\n        ...\n    )\n\n    INSTALLED_APPS = list(SHARED_APPS) + [\n        app for app in TENANT_APPS if app not in SHARED_APPS\n    ]\n    ```\n\n2. Include the the tenants middleware at the beginning of your middlewares:\n\n    ```python\n    MIDDLEWARE = [\n    \"wagtail_tenants.middleware.main.WagtailTenantMainMiddleware\",\n    ...\n    ]\n    ```\n\n3. Define the Tenant model Constants (and also set the default auto field if not already done):\n\n    ```python\n    AUTH_USER_MODEL = 'wagtail_tenants.User' \n    TENANT_MODEL = \"customers.Client\" \n    TENANT_DOMAIN_MODEL = \"customers.Domain\"\n    DEFAULT_AUTO_FIELD='django.db.models.AutoField'\n    ```\n\n4. Set the Database backend to the **django_tenants** backend:\n\n    ```python\n    DATABASES = {\n        \"default\": {\n            \"ENGINE\": \"django_tenants.postgresql_backend\",\n            \"NAME\": \"db_name\",\n            \"USER\": \"db_user\",\n            \"PASSWORD\": \"\",\n            \"HOST\": \"127.0.0.1\",\n            \"PORT\": \"5432\",\n        }\n    }\n    ```\n\n5. Set the Database Router to work with the tenants:\n\n    ```python\n    DATABASE_ROUTERS = (\"wagtail_tenants.routers.WagtailTenantSyncRouter\",)\n    ```\n\n6. Set the authentication backend to fit to our Tenant model.\n\n    ```python\n    AUTHENTICATION_BACKENDS = [\n        'wagtail_tenants.backends.TenantBackend',\n    ]\n    ```\n\n7. Run the migrations with `./manage.py migrate_schemas --shared`\n8. Create a public schema with `./manage.py create_tenant` and use `public` as the schema name and `localhost`\n9. Create a superuser for the public tenant `./manage.py create_tenant_superuser`\n10. Start the Server and have fun\n11. You are able to create tenants within the admin of your public wagtailsite. If you want to log into a tenant you need at least one superuser for the tenant. You can use `./manage.py create_tenant_superuser` for that.\n\n\n### Update 0.1.10\n\nThe new version of wagtail_tenants is now able to archive the follwing features:\n\n#### wagtail 4.2. support\n\nAs the developemt of wagtail still goes on, so we do. Wagtail incuded a reference index for models it was necessary to handle this feature, as we don 't need this feature on our tenant models.\n\n#### Create tenantaware apps\n\nOnly users of a given tenant are able to interact within the wagtail admin with that kind of app.\nThis works in two ways:\n\n1. Add a tenantaware property to the apps AppConfig class in `yourtenantapp.apps.py` \nin the `admin.py` create a ModelAdmin or ModelAdminGroup for your app and use the `menu_item_name` property to fit to your apps name from your AppConfig. If this fits the app will be hidden for all tenants withou a TenantFeaure of the same name. This feature is good for providing different tiers of your app (eg. free | premium )\n\n2. You can specify the tenant directly within the AppConfig so that only users of the tenant have access to this app. This is necessary if you want to create complete and complex functionality only for one tenant. To archive this you have to add the `WagtailTenantPermissionMiddleware`to your middlewares in your settings like so: \n\n```python\nMIDDLEWARE = [\n    \"wagtail_tenants.middleware.main.WagtailTenantMainMiddleware\",\n    \"wagtail_tenants.middleware.main.WagtailTenantPermissionMiddleware\",\n    \"...\"\n]\n```\n\n#### Exclude permissions from normal users in the group create and group edit view\n\nWe are able to hide apps from the group create and group edit views in the wagtail admin. With this approach it is possible to create a tenant admin group with all permissions and distribute it to a tenant user. The tenant admin is able to create and edit groups, but you can decide which apps should be excluded from the view. By default this should include all customers apps. But feel free to extend the list.\n\n```python\nTENANT_EXCLUDE_MODEL_PERMISSIONS = [\n    \"customers.Client\",\n    \"customers.ClientFeature\",\n    \"customers.Domain\",\n    \"customers.ClientBackup\",\n]\n```",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Adds multitenancy based on django_tenants to wagtail cms",
    "version": "0.2.0",
    "project_urls": {
        "Homepage": "https://wagtail-tenants.readthedocs.io/en/latest/",
        "Repository": "https://github.com/borisbrue/wagtail-tenants"
    },
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "f6fcecf2b3ecfe8b6b4d5abd809e863d0bf95130d26545d8f3ce828b3fd6202b",
                "md5": "d2be2e5b3f539a3b22f2263d946b33a4",
                "sha256": "70d5983db1aacf0fd59511245d6c017f4b44638d99e70081ab27ccc58ac58ccf"
            },
            "downloads": -1,
            "filename": "wagtail_tenants-0.2.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "d2be2e5b3f539a3b22f2263d946b33a4",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.9.0,<4.0.0",
            "size": 37165,
            "upload_time": "2023-09-05T10:35:32",
            "upload_time_iso_8601": "2023-09-05T10:35:32.052585Z",
            "url": "https://files.pythonhosted.org/packages/f6/fc/ecf2b3ecfe8b6b4d5abd809e863d0bf95130d26545d8f3ce828b3fd6202b/wagtail_tenants-0.2.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "d7a8717f82a651cd4e43504861e386c36255f925480cd7796e039063b81bd4c8",
                "md5": "434af94c7e7b5843a8789e66eac80c8c",
                "sha256": "0db4085eab19f5cb878906e12fd9de48bff27108139fba61ffaea49cde506153"
            },
            "downloads": -1,
            "filename": "wagtail_tenants-0.2.0.tar.gz",
            "has_sig": false,
            "md5_digest": "434af94c7e7b5843a8789e66eac80c8c",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.9.0,<4.0.0",
            "size": 23581,
            "upload_time": "2023-09-05T10:35:33",
            "upload_time_iso_8601": "2023-09-05T10:35:33.721203Z",
            "url": "https://files.pythonhosted.org/packages/d7/a8/717f82a651cd4e43504861e386c36255f925480cd7796e039063b81bd4c8/wagtail_tenants-0.2.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-09-05 10:35:33",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "borisbrue",
    "github_project": "wagtail-tenants",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "tox": true,
    "lcname": "wagtail-tenants"
}
        
Elapsed time: 0.11349s