From dd28e3dc09fa937b91f803aeaeebde021e0726f1 Mon Sep 17 00:00:00 2001 From: Roberto Rosario Date: Fri, 24 Jun 2016 03:26:24 -0400 Subject: [PATCH] Allow superusers to login from any organization. --- mayan/apps/authentication/auth/model_auth_backend.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/mayan/apps/authentication/auth/model_auth_backend.py b/mayan/apps/authentication/auth/model_auth_backend.py index 575c65c6ea..96beabcd7e 100644 --- a/mayan/apps/authentication/auth/model_auth_backend.py +++ b/mayan/apps/authentication/auth/model_auth_backend.py @@ -15,6 +15,12 @@ class UsernameModelBackend(ModelBackend): if user.check_password(password): return user except UserModel.DoesNotExist: - # Run the default password hasher once to reduce the timing - # difference between an existing and a non-existing user (#20760). - UserModel().set_password(password) + # Check for superadmins, they can login from any organization. + try: + user = UserModel.objects.filter(is_superuser=True).get(username=username) + if user.check_password(password): + return user + except UserModel.DoesNotExist: + # Run the default password hasher once to reduce the timing + # difference between an existing and a non-existing user (#20760). + UserModel().set_password(password)