From a263a4640a963d3742d9b93887c6894a805f063f Mon Sep 17 00:00:00 2001 From: Roberto Rosario Date: Sat, 19 Jul 2014 00:19:45 -0400 Subject: [PATCH] Change the way the autoadmin singleton is cleared up after the admin password change --- mayan/apps/common/__init__.py | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/mayan/apps/common/__init__.py b/mayan/apps/common/__init__.py index 81ed1fbe42..e159ed4e14 100644 --- a/mayan/apps/common/__init__.py +++ b/mayan/apps/common/__init__.py @@ -5,7 +5,6 @@ import tempfile from django.contrib.auth import models as auth_models from django.contrib.auth.models import User -from django.db import transaction, DatabaseError from django.db.models.signals import post_save from django.dispatch import receiver from django.utils.translation import ugettext_lazy as _ @@ -66,14 +65,13 @@ def create_superuser_and_anonymous_user(sender, **kwargs): @receiver(post_save, dispatch_uid='auto_admin_account_passwd_change', sender=User) def auto_admin_account_passwd_change(sender, instance, **kwargs): - try: - with transaction.atomic(): - auto_admin_properties, created = AutoAdminSingleton.objects.get_or_create() - if instance == auto_admin_properties.account and instance.password != auto_admin_properties.password_hash: - # Only delete the auto admin properties when the password has been changed - auto_admin_properties.delete(force=True) - except DatabaseError: - pass + auto_admin_properties = AutoAdminSingleton.objects.get() + if instance == auto_admin_properties.account and instance.password != auto_admin_properties.password_hash: + # Only delete the auto admin properties when the password has been changed + auto_admin_properties.account = None + auto_admin_properties.password = None + auto_admin_properties.password_hash = None + auto_admin_properties.save() if (not validate_path(TEMPORARY_DIRECTORY)) or (not TEMPORARY_DIRECTORY):