From fb5c215f4736a466b80ef0c07f35e8954bcc82bb Mon Sep 17 00:00:00 2001 From: Gabriel Detraz Date: Sat, 18 Apr 2020 00:12:22 +0200 Subject: [PATCH] Allow admin to modify email state --- users/forms.py | 4 ++-- users/locale/fr/LC_MESSAGES/django.po | 4 ++-- users/models.py | 10 ++++++++++ users/views.py | 6 ++++-- 4 files changed, 18 insertions(+), 6 deletions(-) diff --git a/users/forms.py b/users/forms.py index 687c9e11..158965d6 100644 --- a/users/forms.py +++ b/users/forms.py @@ -650,11 +650,11 @@ class EditServiceUserForm(ServiceUserForm): class StateForm(FormRevMixin, ModelForm): - """ Changement de l'état d'un user""" + """Change state of an user, and if its main email is verified or not""" class Meta: model = User - fields = ["state"] + fields = ["state" ,"email_state"] def __init__(self, *args, **kwargs): prefix = kwargs.pop("prefix", self.Meta.model.__name__) diff --git a/users/locale/fr/LC_MESSAGES/django.po b/users/locale/fr/LC_MESSAGES/django.po index e19e19c6..77e5a4f9 100644 --- a/users/locale/fr/LC_MESSAGES/django.po +++ b/users/locale/fr/LC_MESSAGES/django.po @@ -1360,8 +1360,8 @@ msgid "Sent a new confirmation email." msgstr "Un nouveau mail de confirmation a été envoyé." #: users/views.py:225 -msgid "The state was edited." -msgstr "L'état a été modifié." +msgid "The states were edited." +msgstr "Les états ont été modifié." #: users/views.py:242 msgid "The groups were edited." diff --git a/users/models.py b/users/models.py index 613aa9ef..56f411b1 100755 --- a/users/models.py +++ b/users/models.py @@ -828,6 +828,16 @@ class User( self.confirm_email_address_mail(request) return True + def trigger_email_changed_state(self, request): + """Trigger an email, and changed values after email_state been manually updated""" + if self.email_state == self.EMAIL_STATE_VERIFIED: + return False + + self.email_change_date = timezone.now() + + self.confirm_email_address_mail(request) + return True + def confirm_email_before_date(self): if self.email_state == self.EMAIL_STATE_VERIFIED: return None diff --git a/users/views.py b/users/views.py index 77e40701..3d5b0205 100644 --- a/users/views.py +++ b/users/views.py @@ -243,8 +243,10 @@ def state(request, user, userid): state_form = StateForm(request.POST or None, instance=user) if state_form.is_valid(): if state_form.changed_data: - state_form.save() - messages.success(request, _("The state was edited.")) + user_instance = state_form.save() + messages.success(request, _("The states were edited.")) + if user_instance.trigger_email_changed_state(request): + messages.success(request, _("An email to confirm the address was sent.")) return redirect(reverse("users:profil", kwargs={"userid": str(userid)})) return form( {"userform": state_form, "action_name": _("Edit")},