8
0
Fork 0
mirror of https://gitlab2.federez.net/re2o/re2o synced 2024-11-22 03:13:12 +00:00

Replace STATE_EMAIL_NOT_YET_CONFIRMED with an email_state

This commit is contained in:
Jean-Romain Garnier 2020-04-17 17:35:24 +02:00 committed by Jean-Romain Garnier
parent 60186071db
commit 43eadaa712
14 changed files with 73 additions and 53 deletions

View file

@ -513,7 +513,6 @@ class HomeCreationViewSet(viewsets.ReadOnlyModelViewSet):
queryset = users.User.objects.exclude( queryset = users.User.objects.exclude(
Q(state=users.User.STATE_DISABLED) Q(state=users.User.STATE_DISABLED)
| Q(state=users.User.STATE_NOT_YET_ACTIVE) | Q(state=users.User.STATE_NOT_YET_ACTIVE)
| Q(state=users.STATE_EMAIL_NOT_YET_CONFIRMED)
| Q(state=users.User.STATE_FULL_ARCHIVE) | Q(state=users.User.STATE_FULL_ARCHIVE)
) )
serializer_class = serializers.BasicUserSerializer serializer_class = serializers.BasicUserSerializer

View file

@ -469,7 +469,7 @@ def decide_vlan_switch(nas_machine, nas_type, port_number, mac_address):
RadiusOption.get_attributes("non_member_attributes", attributes_kwargs), RadiusOption.get_attributes("non_member_attributes", attributes_kwargs),
) )
for user in room_user: for user in room_user:
if user.is_ban() or user.state not in [User.STATE_ACTIVE, User.STATE_EMAIL_NOT_YET_CONFIRMED]: if user.is_ban() or user.state != User.STATE_ACTIVE:
return ( return (
sw_name, sw_name,
room, room,
@ -480,6 +480,21 @@ def decide_vlan_switch(nas_machine, nas_type, port_number, mac_address):
RadiusOption.get_cached_value("banned") != RadiusOption.REJECT, RadiusOption.get_cached_value("banned") != RadiusOption.REJECT,
RadiusOption.get_attributes("banned_attributes", attributes_kwargs), RadiusOption.get_attributes("banned_attributes", attributes_kwargs),
) )
elif user.email_state == User.EMAIL_STATE_UNVERIFIED:
return (
sw_name,
room,
u"Utilisateur suspendu (mail non confirme)",
getattr(
RadiusOption.get_cached_value("non_member_vlan"),
"vlan_id",
None,
),
RadiusOption.get_cached_value("non_member") != RadiusOption.REJECT,
RadiusOption.get_attributes(
"non_member_attributes", attributes_kwargs
),
)
elif not (user.is_connected() or user.is_whitelisted()): elif not (user.is_connected() or user.is_whitelisted()):
return ( return (
sw_name, sw_name,

View file

@ -260,16 +260,6 @@ def stats_general(request):
), ),
Club.objects.filter(state=Club.STATE_NOT_YET_ACTIVE).count(), Club.objects.filter(state=Club.STATE_NOT_YET_ACTIVE).count(),
], ],
"email_not_confirmed_users": [
_("Waiting for email confirmation users"),
User.objects.filter(state=User.STATE_EMAIL_NOT_YET_CONFIRMED).count(),
(
Adherent.objects.filter(
state=Adherent.STATE_EMAIL_NOT_YET_CONFIRMED
).count()
),
Club.objects.filter(state=Club.STATE_EMAIL_NOT_YET_CONFIRMED).count(),
],
"adherent_users": [ "adherent_users": [
_("Contributing members"), _("Contributing members"),
_all_adherent.count(), _all_adherent.count(),

View file

@ -116,7 +116,8 @@ def all_has_access(search_time=None, including_asso=True):
if search_time is None: if search_time is None:
search_time = timezone.now() search_time = timezone.now()
filter_user = ( filter_user = (
(Q(state=User.STATE_ACTIVE) | Q(state=User.STATE_EMAIL_NOT_YET_CONFIRMED)) Q(state=User.STATE_ACTIVE)
& ~Q(email_state=User.EMAIL_STATE_UNVERIFIED)
& ~Q( & ~Q(
ban__in=Ban.objects.filter( ban__in=Ban.objects.filter(
Q(date_start__lt=search_time) & Q(date_end__gt=search_time) Q(date_start__lt=search_time) & Q(date_end__gt=search_time)

View file

@ -388,8 +388,8 @@ class AdherentForm(FormRevMixin, FieldPermissionFormMixin, ModelForm):
if not self.is_anon and self.initial["email"] and user.email != self.initial["email"]: if not self.is_anon and self.initial["email"] and user.email != self.initial["email"]:
# Send a confirmation email # Send a confirmation email
if user.state in [User.STATE_ACTIVE, User.STATE_DISABLED, User.STATE_NOT_YET_ACTIVE, User.STATE_EMAIL_NOT_YET_CONFIRMED]: if user.state in [User.STATE_ACTIVE, User.STATE_DISABLED, User.STATE_NOT_YET_ACTIVE]:
user.state = User.STATE_EMAIL_NOT_YET_CONFIRMED user.email_state = User.EMAIL_STATE_PENDING
self.should_send_confirmation_email = True self.should_send_confirmation_email = True
# Always keep the oldest change date # Always keep the oldest change date
@ -682,7 +682,6 @@ class StateForm(FormRevMixin, ModelForm):
user.state = self.cleaned_data.get("state") user.state = self.cleaned_data.get("state")
user.state_sync() user.state_sync()
user.email_change_date_sync()
user.save() user.save()

View file

@ -1008,8 +1008,8 @@ msgstr "Vous n'avez pas reçu le mail ?"
#: users/templates/users/profil.html:53 #: users/templates/users/profil.html:53
#, python-format #, python-format
msgid "Your account has been suspended." msgid "Your account has been suspended, please confirm your email address."
msgstr "Votre compte a été suspendu." msgstr "Votre compte a été suspendu, veuillez confirmer votre adresse mail."
#: users/templates/users/profil.html:46 #: users/templates/users/profil.html:46
msgid "Your account has been banned." msgid "Your account has been banned."

View file

@ -77,7 +77,6 @@ class Command(BaseCommand):
.exclude(id__in=all_has_access(search_time=date)) .exclude(id__in=all_has_access(search_time=date))
.exclude(state=User.STATE_NOT_YET_ACTIVE) .exclude(state=User.STATE_NOT_YET_ACTIVE)
.exclude(state=User.STATE_FULL_ARCHIVE) .exclude(state=User.STATE_FULL_ARCHIVE)
.exclude(state=User.STATE_EMAIL_NOT_YET_CONFIRMED)
) )
if show: if show:

View file

@ -31,13 +31,13 @@ class Command(BaseCommand):
"""First deleting invalid invoices, and then deleting the users""" """First deleting invalid invoices, and then deleting the users"""
days = OptionalUser.get_cached_value("disable_emailnotyetconfirmed") days = OptionalUser.get_cached_value("disable_emailnotyetconfirmed")
users_to_disable = ( users_to_disable = (
User.objects.filter(state=User.STATE_EMAIL_NOT_YET_CONFIRMED) User.objects.filter(email_state=User.EMAIL_STATE_PENDING)
.filter(email_change_date__lte=timezone.now() - timedelta(days=days)) .filter(email_change_date__lte=timezone.now() - timedelta(days=days))
.distinct() .distinct()
) )
print("Disabling " + str(users_to_disable.count()) + " users.") print("Disabling " + str(users_to_disable.count()) + " users.")
for user in users_to_disable: for user in users_to_disable:
user.state = User.STATE_DISABLED user.email_state = User.EMAIL_STATE_UNVERIFIED
user.notif_disable() user.notif_disable()
user.save() user.save()

View file

@ -11,10 +11,16 @@ class Migration(migrations.Migration):
('users', '0084_auto_20191120_0159'), ('users', '0084_auto_20191120_0159'),
] ]
def flag_verified(apps, schema_editor):
db_alias = schema_editor.connection.alias
users = apps.get_model("users", "User")
users.objects.using(db_alias).all().update(email_state=0)
operations = [ operations = [
migrations.AlterField( migrations.AddField(
model_name='user', model_name='user',
name='state', name='email_state',
field=models.IntegerField(choices=[(0, 'Active'), (1, 'Disabled'), (2, 'Archived'), (3, 'Not yet active'), (4, 'Fully archived'), (5, 'Waiting for email confirmation')], default=3), field=models.IntegerField(choices=[(0, 'Verified'), (1, 'Unverified'), (2, 'Waiting for email confirmation')], default=2),
), ),
migrations.RunPython(flag_verified),
] ]

View file

@ -0,0 +1,20 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.11.28 on 2020-04-16 22:31
from __future__ import unicode_literals
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('users', '0084_auto_20191120_0159'),
]
operations = [
migrations.AddField(
model_name='user',
name='email_state',
field=models.IntegerField(choices=[(0, 'Verified'), (1, 'Unverified'), (2, 'Waiting for email confirmation')], default=2),
),
]

View file

@ -8,7 +8,7 @@ from django.db import migrations, models
class Migration(migrations.Migration): class Migration(migrations.Migration):
dependencies = [ dependencies = [
('users', '0085_auto_20200417_0031'), ('users', '0085_user_email_state'),
] ]
operations = [ operations = [

View file

@ -179,14 +179,21 @@ class User(
STATE_ARCHIVE = 2 STATE_ARCHIVE = 2
STATE_NOT_YET_ACTIVE = 3 STATE_NOT_YET_ACTIVE = 3
STATE_FULL_ARCHIVE = 4 STATE_FULL_ARCHIVE = 4
STATE_EMAIL_NOT_YET_CONFIRMED = 5
STATES = ( STATES = (
(0, _("Active")), (0, _("Active")),
(1, _("Disabled")), (1, _("Disabled")),
(2, _("Archived")), (2, _("Archived")),
(3, _("Not yet active")), (3, _("Not yet active")),
(4, _("Fully archived")), (4, _("Fully archived")),
(5, _("Waiting for email confirmation")), )
EMAIL_STATE_VERIFIED = 0
EMAIL_STATE_UNVERIFIED = 1
EMAIL_STATE_PENDING = 2
EMAIL_STATES = (
(0, _("Verified")),
(1, _("Unverified")),
(2, _("Waiting for email confirmation")),
) )
surname = models.CharField(max_length=255) surname = models.CharField(max_length=255)
@ -222,6 +229,7 @@ class User(
) )
pwd_ntlm = models.CharField(max_length=255) pwd_ntlm = models.CharField(max_length=255)
state = models.IntegerField(choices=STATES, default=STATE_NOT_YET_ACTIVE) state = models.IntegerField(choices=STATES, default=STATE_NOT_YET_ACTIVE)
email_state = models.IntegerField(choices=EMAIL_STATES, default=EMAIL_STATE_PENDING)
registered = models.DateTimeField(auto_now_add=True) registered = models.DateTimeField(auto_now_add=True)
telephone = models.CharField(max_length=15, blank=True, null=True) telephone = models.CharField(max_length=15, blank=True, null=True)
uid_number = models.PositiveIntegerField(default=get_fresh_user_uid, unique=True) uid_number = models.PositiveIntegerField(default=get_fresh_user_uid, unique=True)
@ -332,7 +340,6 @@ class User(
return ( return (
self.state == self.STATE_ACTIVE self.state == self.STATE_ACTIVE
or self.state == self.STATE_NOT_YET_ACTIVE or self.state == self.STATE_NOT_YET_ACTIVE
or self.state == self.STATE_EMAIL_NOT_YET_CONFIRMED
or ( or (
allow_archived allow_archived
and self.state in (self.STATE_ARCHIVE, self.STATE_FULL_ARCHIVE) and self.state in (self.STATE_ARCHIVE, self.STATE_FULL_ARCHIVE)
@ -395,7 +402,7 @@ class User(
@cached_property @cached_property
def get_shadow_expire(self): def get_shadow_expire(self):
"""Return the shadow_expire value for the user""" """Return the shadow_expire value for the user"""
if self.state == self.STATE_DISABLED: if self.state == self.STATE_DISABLED or self.email_state == self.EMAIL_STATE_UNVERIFIED:
return str(0) return str(0)
else: else:
return None return None
@ -487,7 +494,8 @@ class User(
def has_access(self): def has_access(self):
""" Renvoie si un utilisateur a accès à internet """ """ Renvoie si un utilisateur a accès à internet """
return ( return (
self.state in [User.STATE_ACTIVE, User.STATE_EMAIL_NOT_YET_CONFIRMED] self.state == User.STATE_ACTIVE
and self.email_state != User.EMAIL_STATE_UNVERIFIED
and not self.is_ban() and not self.is_ban()
and (self.is_connected() or self.is_whitelisted()) and (self.is_connected() or self.is_whitelisted())
) or self == AssoOption.get_cached_value("utilisateur_asso") ) or self == AssoOption.get_cached_value("utilisateur_asso")
@ -658,21 +666,6 @@ class User(
): ):
self.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( def ldap_sync(
self, base=True, access_refresh=True, mac_refresh=True, group_refresh=False self, base=True, access_refresh=True, mac_refresh=True, group_refresh=False
): ):
@ -687,7 +680,6 @@ class User(
Si l'instance n'existe pas, on crée le ldapuser correspondant""" Si l'instance n'existe pas, on crée le ldapuser correspondant"""
if sys.version_info[0] >= 3 and ( if sys.version_info[0] >= 3 and (
self.state == self.STATE_ACTIVE self.state == self.STATE_ACTIVE
or self.state == self.STATE_EMAIL_NOT_YET_CONFIRMED
or self.state == self.STATE_ARCHIVE or self.state == self.STATE_ARCHIVE
or self.state == self.STATE_DISABLED or self.state == self.STATE_DISABLED
): ):
@ -807,7 +799,7 @@ class User(
return return
def confirm_email_before_date(self): def confirm_email_before_date(self):
if self.email_change_date is None or self.state != self.STATE_EMAIL_NOT_YET_CONFIRMED: if self.email_change_date is None or self.email_state == self.EMAIL_STATE_VERIFIED:
return None return None
days = OptionalUser.get_cached_value("disable_emailnotyetconfirmed") days = OptionalUser.get_cached_value("disable_emailnotyetconfirmed")

View file

@ -42,7 +42,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
</div> </div>
{% if users.state == users.STATE_EMAIL_NOT_YET_CONFIRMED %} {% if users.email_state == users.EMAIL_STATE_PENDING %}
<div class="alert alert-warning"> <div class="alert alert-warning">
{% blocktrans with confirm_before_date=users.confirm_email_before_date|date:"DATE_FORMAT" %}Please confirm your email address before {{ confirm_before_date }}, or your account will be suspended.{% endblocktrans %} {% blocktrans with confirm_before_date=users.confirm_email_before_date|date:"DATE_FORMAT" %}Please confirm your email address before {{ confirm_before_date }}, or your account will be suspended.{% endblocktrans %}
<br/> <br/>
@ -50,9 +50,9 @@ with this program; if not, write to the Free Software Foundation, Inc.,
{% blocktrans %}Didn't receive the email?{% endblocktrans %} {% blocktrans %}Didn't receive the email?{% endblocktrans %}
</a> </a>
</div> </div>
{% elif users.state == users.STATE_DISABLED %} {% elif users.email_state == users.EMAIL_STATE_UNVERIFIED %}
<div class="alert alert-danger"> <div class="alert alert-danger">
{% blocktrans %}Your account has been suspended.{% endblocktrans %} {% blocktrans %}Your account has been suspended, please confirm your email address.{% endblocktrans %}
</div> </div>
{% endif %} {% endif %}

View file

@ -745,7 +745,6 @@ def mass_archive(request):
.exclude(id__in=all_has_access(search_time=date)) .exclude(id__in=all_has_access(search_time=date))
.exclude(state=User.STATE_NOT_YET_ACTIVE) .exclude(state=User.STATE_NOT_YET_ACTIVE)
.exclude(state=User.STATE_FULL_ARCHIVE) .exclude(state=User.STATE_FULL_ARCHIVE)
.exclude(state=User.STATE_EMAIL_NOT_YET_CONFIRMED)
) )
if not full_archive: if not full_archive:
to_archive_list = to_archive_list.exclude(state=User.STATE_ARCHIVE) to_archive_list = to_archive_list.exclude(state=User.STATE_ARCHIVE)
@ -981,7 +980,7 @@ def reset_password(request):
user = User.objects.get( user = User.objects.get(
pseudo=userform.cleaned_data["pseudo"], pseudo=userform.cleaned_data["pseudo"],
email=userform.cleaned_data["email"], email=userform.cleaned_data["email"],
state__in=[User.STATE_ACTIVE, User.STATE_NOT_YET_ACTIVE, User.STATE_EMAIL_NOT_YET_CONFIRMED], state__in=[User.STATE_ACTIVE, User.STATE_NOT_YET_ACTIVE],
) )
except User.DoesNotExist: except User.DoesNotExist:
messages.error(request, _("The user doesn't exist.")) messages.error(request, _("The user doesn't exist."))
@ -1060,7 +1059,7 @@ def resend_confirmation_email(request, logged_user, userid):
try: try:
user = User.objects.get( user = User.objects.get(
id=userid, id=userid,
state__in=[User.STATE_EMAIL_NOT_YET_CONFIRMED], email_state__in=[User.EMAIL_STATE_PENDING, User.EMAIL_STATE_UNVERIFIED],
) )
except User.DoesNotExist: except User.DoesNotExist:
messages.error(request, _("The user doesn't exist.")) messages.error(request, _("The user doesn't exist."))