From 90b4794c3b3566bd1208e3c4fab141a06bc29596 Mon Sep 17 00:00:00 2001 From: Henrik Levkowetz <henrik@levkowetz.com> Date: Mon, 22 Dec 2014 17:59:24 +0000 Subject: [PATCH] =?UTF-8?q?Fix=20django=201.7=20incompatibilities:=20The?= =?UTF-8?q?=20role=5Frequired()=20decorator=20isn=E2=80=99t=20signature-pr?= =?UTF-8?q?eserving=20=E2=80=94=20which=20now=20breaks=20reverse().=20=20-?= =?UTF-8?q?=20Legacy-Id:=208832?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ietf/ietfauth/utils.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/ietf/ietfauth/utils.py b/ietf/ietfauth/utils.py index fcdcfbcf6..e957e65bf 100644 --- a/ietf/ietfauth/utils.py +++ b/ietf/ietfauth/utils.py @@ -1,10 +1,13 @@ # various authentication and authorization utilities +from functools import wraps + from django.utils.http import urlquote from django.conf import settings from django.db.models import Q from django.http import HttpResponseRedirect, HttpResponseForbidden from django.contrib.auth import REDIRECT_FIELD_NAME +from django.utils.decorators import available_attrs from ietf.group.models import Role from ietf.person.models import Person @@ -78,6 +81,7 @@ def passes_test_decorator(test_func, message): error. The test function should be on the form fn(user) -> true/false.""" def decorate(view_func): + @wraps(view_func, assigned=available_attrs(view_func)) def inner(request, *args, **kwargs): if not request.user.is_authenticated(): return HttpResponseRedirect('%s?%s=%s' % (settings.LOGIN_URL, REDIRECT_FIELD_NAME, urlquote(request.get_full_path()))) @@ -88,6 +92,7 @@ def passes_test_decorator(test_func, message): return inner return decorate + def role_required(*role_names): """View decorator for checking that the user is logged in and has one of the listed roles."""