8
0
Fork 0
mirror of https://gitlab2.federez.net/re2o/re2o synced 2024-11-30 08:32:26 +00:00

Allow admin to modify email state

This commit is contained in:
Gabriel Detraz 2020-04-18 00:12:22 +02:00
parent cdd9dfae6c
commit fb5c215f47
4 changed files with 18 additions and 6 deletions

View file

@ -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__)

View file

@ -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."

View file

@ -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

View file

@ -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")},