Source code for nlpmed_portal.users.apps
# SPDX-FileCopyrightText: Copyright (C) 2026 Omid Jafari <omidjafari.com>
# SPDX-License-Identifier: AGPL-3.0-or-later
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import contextlib
from django.apps import AppConfig
from django.utils.translation import gettext_lazy as _
[docs]
class UsersConfig(AppConfig):
name = "nlpmed_portal.users"
verbose_name = _("Users")
[docs]
def ready(self):
with contextlib.suppress(ImportError):
import nlpmed_portal.users.signals # ruff: ignore[unused-import, import-outside-top-level]
with contextlib.suppress(ImportError):
import auditlog.cid as cid_mod # ruff: ignore[import-outside-top-level]
from auditlog.cid import correlation_id # ruff: ignore[import-outside-top-level]
original_set_cid = cid_mod.set_cid
def patched_set_cid(request=None):
original_set_cid(request)
if request is not None and getattr(request.user, "is_hijacked", False):
base = correlation_id.get()
if base:
correlation_id.set(f"HIJACKED:{base}")
else:
correlation_id.set("HIJACKED")
cid_mod.set_cid = patched_set_cid