From 80124695ad967021abbddc1f05846a5428f116d4 Mon Sep 17 00:00:00 2001 From: Jean-Romain Garnier Date: Fri, 17 Apr 2020 13:01:10 +0200 Subject: [PATCH] Move user email_change_date update on manual state change to seperate method --- users/forms.py | 1 + users/models.py | 13 +++++++++++-- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/users/forms.py b/users/forms.py index f3ea52de..be248214 100644 --- a/users/forms.py +++ b/users/forms.py @@ -675,6 +675,7 @@ class StateForm(FormRevMixin, ModelForm): if self.cleaned_data["state"]: user.state = self.cleaned_data.get("state") user.state_sync() + user.email_change_date_sync() user.save() diff --git a/users/models.py b/users/models.py index 0f04aeaf..12f88c56 100755 --- a/users/models.py +++ b/users/models.py @@ -638,12 +638,11 @@ class User( self.ldap_sync() def state_sync(self): - """Handle archiving/unarchiving, and manually confirming a user's email address""" + """Archive, or unarchive, if the user was not active/or archived before""" if ( self.__original_state != self.STATE_ACTIVE and self.state == self.STATE_ACTIVE ): - self.email_change_date = None self.unarchive() elif ( self.__original_state != self.STATE_ARCHIVE @@ -655,11 +654,21 @@ class User( and self.state == self.STATE_FULL_ARCHIVE ): self.full_archive() + + def email_change_date_sync(self): + """Update user's email_change_date based on state update""" + if ( + self.__original_state != self.STATE_ACTIVE + and self.state == self.STATE_ACTIVE + ): + self.email_change_date = None + self.save() elif ( self.__original_state != self.STATE_EMAIL_NOT_YET_CONFIRMED and self.state == self.STATE_EMAIL_NOT_YET_CONFIRMED ): self.email_change_date = timezone.now() + self.save() def ldap_sync( self, base=True, access_refresh=True, mac_refresh=True, group_refresh=False