-
-
Notifications
You must be signed in to change notification settings - Fork 570
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
use tenant uuid instead of install_id when tenants are enabled
Signed-off-by: Jens Langhammer <jens@goauthentik.io>
- Loading branch information
Showing
7 changed files
with
27 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,26 @@ | ||
"""Tenant utils""" | ||
|
||
from django.db import connection | ||
from django_tenants.utils import get_public_schema_name | ||
|
||
from authentik.lib.config import CONFIG | ||
from authentik.root.install_id import get_install_id | ||
from authentik.tenants.models import Tenant | ||
|
||
|
||
def get_current_tenant() -> Tenant: | ||
"""Get tenant for current request""" | ||
return Tenant.objects.get(schema_name=connection.schema_name) | ||
|
||
|
||
def get_unique_identifier() -> str: | ||
"""Get a globally unique identifier that does not change""" | ||
install_id = get_install_id() | ||
if CONFIG.get_bool("tenants.enabled"): | ||
tenant = get_current_tenant() | ||
# Only use tenant's uuid if this request is not from the "public" | ||
# (i.e. default) tenant | ||
if tenant.schema_name == get_public_schema_name(): | ||
return install_id | ||
return str(get_current_tenant().tenant_uuid) | ||
return install_id |