Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add user tenancy data to request #474

Open
2 tasks
jon-nfc opened this issue Jan 16, 2025 · 0 comments
Open
2 tasks

Add user tenancy data to request #474

jon-nfc opened this issue Jan 16, 2025 · 0 comments

Comments

@jon-nfc
Copy link
Member

jon-nfc commented Jan 16, 2025

User tenancy data is used by Centurion for user authorization. Currently the authorization system fetches this multiple times from the database.

Details

Django currently adds the user details to the request via middleware, django.contrib.auth.middleware.AuthenticationMiddleware, This class will have to be overridden to add the tenancy details.

Django 5.1 Class

class AuthenticationMiddleware(MiddlewareMixin):
    def process_request(self, request):
        if not hasattr(request, "session"):
            raise ImproperlyConfigured(
                "The Django authentication middleware requires session "
                "middleware to be installed. Edit your MIDDLEWARE setting to "
                "insert "
                "'django.contrib.sessions.middleware.SessionMiddleware' before "
                "'django.contrib.auth.middleware.AuthenticationMiddleware'."
            )
        request.user = SimpleLazyObject(lambda: get_user(request))
        request.auser = partial(auser, request)

modification of the above class, specifically AuthenticationMiddleware.process_request().request.user, to ensure the following is included:

  • Groups
  • Teams
  • Organizations

The above models will also require pre-fetching of the following:

  • content_types
  • permissions

Links

Tasks

  • add tenancy details to request
  • Test page speed must be < 1s per request
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Backlog
Development

No branches or pull requests

1 participant