From 0a8ee9cbad80550d1deba4d8c1a4928ce08906dc Mon Sep 17 00:00:00 2001 From: Oskar Hahn Date: Sun, 12 Aug 2012 10:12:26 +0200 Subject: [PATCH] changed request.user to be the openslidesuser --- openslides/openslides_settings.py | 2 +- openslides/participant/middleware.py | 22 ++++++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) create mode 100644 openslides/participant/middleware.py diff --git a/openslides/openslides_settings.py b/openslides/openslides_settings.py index b3f14315f..b14ff673e 100755 --- a/openslides/openslides_settings.py +++ b/openslides/openslides_settings.py @@ -101,7 +101,7 @@ MIDDLEWARE_CLASSES = ( 'django.middleware.common.CommonMiddleware', 'django.contrib.sessions.middleware.SessionMiddleware', 'django.middleware.csrf.CsrfViewMiddleware', - 'django.contrib.auth.middleware.AuthenticationMiddleware', + 'openslides.participant.middleware.AuthenticationMiddleware', 'django.contrib.messages.middleware.MessageMiddleware', 'django.middleware.locale.LocaleMiddleware', ) diff --git a/openslides/participant/middleware.py b/openslides/participant/middleware.py new file mode 100644 index 000000000..0e86e8ad2 --- /dev/null +++ b/openslides/participant/middleware.py @@ -0,0 +1,22 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- +""" + openslides.utils.middleware + ~~~~~~~~~~~~~~~~~~~~~~ + + Additional definitions for OpenSlides forms. + + :copyright: 2011, 2012 by OpenSlides team, see AUTHORS. + :license: GNU GPL, see LICENSE for more details. +""" + +from django.contrib.auth.middleware import AuthenticationMiddleware as _AuthenticationMiddleware +from django.contrib.auth.models import AnonymousUser + + +class AuthenticationMiddleware(_AuthenticationMiddleware): + def process_request(self, request): + super(AuthenticationMiddleware, self).process_request(request) + + if not isinstance(request.user, AnonymousUser): + request.user = request.user.openslidesuser