mirror of
https://gitlab2.federez.net/re2o/re2o
synced 2024-11-23 11:53:12 +00:00
Add new full_archive state for user
This commit is contained in:
parent
e83e5d4f79
commit
706903f8c9
4 changed files with 67 additions and 16 deletions
|
@ -257,6 +257,14 @@ def stats_general(request):
|
||||||
.count()),
|
.count()),
|
||||||
Club.objects.filter(state=Club.STATE_ARCHIVE).count()
|
Club.objects.filter(state=Club.STATE_ARCHIVE).count()
|
||||||
],
|
],
|
||||||
|
'full_archive_users': [
|
||||||
|
_("Full Archived users"),
|
||||||
|
User.objects.filter(state=User.STATE_FULL_ARCHIVE).count(),
|
||||||
|
(Adherent.objects
|
||||||
|
.filter(state=Adherent.STATE_FULL_ARCHIVE)
|
||||||
|
.count()),
|
||||||
|
Club.objects.filter(state=Club.STATE_FULL_ARCHIVE).count()
|
||||||
|
],
|
||||||
'not_active_users': [
|
'not_active_users': [
|
||||||
_("Not yet active users"),
|
_("Not yet active users"),
|
||||||
User.objects.filter(state=User.STATE_NOT_YET_ACTIVE).count(),
|
User.objects.filter(state=User.STATE_NOT_YET_ACTIVE).count(),
|
||||||
|
|
20
users/migrations/0081_auto_20190317_0302.py
Normal file
20
users/migrations/0081_auto_20190317_0302.py
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
# Generated by Django 1.10.7 on 2019-03-17 02:02
|
||||||
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('users', '0080_auto_20190108_1726'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name='user',
|
||||||
|
name='state',
|
||||||
|
field=models.IntegerField(choices=[(0, 'Active'), (1, 'Disabled'), (2, 'Archived'), (3, 'Not yet active'), (4, 'Full Archived')], default=3),
|
||||||
|
),
|
||||||
|
]
|
|
@ -188,11 +188,13 @@ class User(RevMixin, FieldPermissionModelMixin, AbstractBaseUser,
|
||||||
STATE_DISABLED = 1
|
STATE_DISABLED = 1
|
||||||
STATE_ARCHIVE = 2
|
STATE_ARCHIVE = 2
|
||||||
STATE_NOT_YET_ACTIVE = 3
|
STATE_NOT_YET_ACTIVE = 3
|
||||||
|
STATE_FULL_ARCHIVE = 4
|
||||||
STATES = (
|
STATES = (
|
||||||
(0, _("Active")),
|
(0, _("Active")),
|
||||||
(1, _("Disabled")),
|
(1, _("Disabled")),
|
||||||
(2, _("Archived")),
|
(2, _("Archived")),
|
||||||
(3, _("Not yet active")),
|
(3, _("Not yet active")),
|
||||||
|
(4, _("Full Archived")),
|
||||||
)
|
)
|
||||||
|
|
||||||
surname = models.CharField(max_length=255)
|
surname = models.CharField(max_length=255)
|
||||||
|
@ -335,11 +337,17 @@ class User(RevMixin, FieldPermissionModelMixin, AbstractBaseUser,
|
||||||
return self.state == self.STATE_ACTIVE or self.state == self.STATE_NOT_YET_ACTIVE
|
return self.state == self.STATE_ACTIVE or self.state == self.STATE_NOT_YET_ACTIVE
|
||||||
|
|
||||||
def set_active(self):
|
def set_active(self):
|
||||||
"""Enable this user if he subscribed successfully one time before"""
|
"""Enable this user if he subscribed successfully one time before
|
||||||
|
Reenable it if it was archived
|
||||||
|
Do nothing if disabed"""
|
||||||
if self.state == self.STATE_NOT_YET_ACTIVE:
|
if self.state == self.STATE_NOT_YET_ACTIVE:
|
||||||
if self.facture_set.filter(valid=True).filter(Q(vente__type_cotisation='All') | Q(vente__type_cotisation='Adhesion')).exists() or OptionalUser.get_cached_value('all_users_active'):
|
if self.facture_set.filter(valid=True).filter(Q(vente__type_cotisation='All') | Q(vente__type_cotisation='Adhesion')).exists() or OptionalUser.get_cached_value('all_users_active'):
|
||||||
self.state = self.STATE_ACTIVE
|
self.state = self.STATE_ACTIVE
|
||||||
self.save()
|
self.save()
|
||||||
|
if self.state == self.STATE_ARCHIVE or self.state == self.STATE_FULL_ARCHIVE:
|
||||||
|
self.state = self.STATE_ACTIVE
|
||||||
|
self.unarchive()
|
||||||
|
self.save()
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def is_staff(self):
|
def is_staff(self):
|
||||||
|
@ -519,9 +527,14 @@ class User(RevMixin, FieldPermissionModelMixin, AbstractBaseUser,
|
||||||
)['total'] or 0
|
)['total'] or 0
|
||||||
return somme_credit - somme_debit
|
return somme_credit - somme_debit
|
||||||
|
|
||||||
def user_interfaces(self, active=True):
|
def user_interfaces(self, active=True, all_interfaces=False):
|
||||||
""" Renvoie toutes les interfaces dont les machines appartiennent à
|
""" Renvoie toutes les interfaces dont les machines appartiennent à
|
||||||
self. Par defaut ne prend que les interfaces actives"""
|
self. Par defaut ne prend que les interfaces actives"""
|
||||||
|
if all_interfaces:
|
||||||
|
return Interface.objects.filter(
|
||||||
|
machine__in=Machine.objects.filter(user=self)
|
||||||
|
).select_related('domain__extension')
|
||||||
|
else:
|
||||||
return Interface.objects.filter(
|
return Interface.objects.filter(
|
||||||
machine__in=Machine.objects.filter(user=self, active=active)
|
machine__in=Machine.objects.filter(user=self, active=active)
|
||||||
).select_related('domain__extension')
|
).select_related('domain__extension')
|
||||||
|
@ -547,18 +560,28 @@ class User(RevMixin, FieldPermissionModelMixin, AbstractBaseUser,
|
||||||
|
|
||||||
def disable_email(self):
|
def disable_email(self):
|
||||||
"""Disable email account and redirection"""
|
"""Disable email account and redirection"""
|
||||||
self.email = ""
|
|
||||||
self.local_email_enabled = False
|
self.local_email_enabled = False
|
||||||
self.local_email_redirect = False
|
self.local_email_redirect = False
|
||||||
|
|
||||||
|
def delete_data(self):
|
||||||
|
"""This user will be completely archived, so only keep mandatory data"""
|
||||||
|
self.disabled_email()
|
||||||
|
self.user_interfaces(all_interfaces=True).delete()
|
||||||
|
self.ldap_del()
|
||||||
|
|
||||||
def archive(self):
|
def archive(self):
|
||||||
""" Filling the user; no more active"""
|
""" Filling the user; no more active"""
|
||||||
self.unassign_ips()
|
self.unassign_ips()
|
||||||
self.disable_email()
|
|
||||||
|
def full_archive(self):
|
||||||
|
"""Full Archive = Archive + Service access complete deletion"""
|
||||||
|
self.archive()
|
||||||
|
self.delete_data()
|
||||||
|
|
||||||
def unarchive(self):
|
def unarchive(self):
|
||||||
"""Unfilling the user"""
|
"""Unfilling the user"""
|
||||||
self.assign_ips()
|
self.assign_ips()
|
||||||
|
self.ldap_sync()
|
||||||
|
|
||||||
def state_sync(self):
|
def state_sync(self):
|
||||||
"""Archive, or unarchive, if the user was not active/or archived before"""
|
"""Archive, or unarchive, if the user was not active/or archived before"""
|
||||||
|
@ -566,6 +589,8 @@ class User(RevMixin, FieldPermissionModelMixin, AbstractBaseUser,
|
||||||
self.unarchive()
|
self.unarchive()
|
||||||
elif self.__original_state != self.STATE_ARCHIVE and self.state == self.STATE_ARCHIVE:
|
elif self.__original_state != self.STATE_ARCHIVE and self.state == self.STATE_ARCHIVE:
|
||||||
self.archive()
|
self.archive()
|
||||||
|
elif self.__original_state != self.STATE_FULL_ARCHIVE and self.state == self.STATE_FULL_ARCHIVE:
|
||||||
|
self.full_archive()
|
||||||
|
|
||||||
def ldap_sync(self, base=True, access_refresh=True, mac_refresh=True,
|
def ldap_sync(self, base=True, access_refresh=True, mac_refresh=True,
|
||||||
group_refresh=False):
|
group_refresh=False):
|
||||||
|
@ -578,15 +603,11 @@ class User(RevMixin, FieldPermissionModelMixin, AbstractBaseUser,
|
||||||
mac_refresh : synchronise les machines de l'user
|
mac_refresh : synchronise les machines de l'user
|
||||||
group_refresh : synchronise les group de l'user
|
group_refresh : synchronise les group de l'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 self.state != self.STATE_ARCHIVE and\
|
if sys.version_info[0] >= 3 and (self.state == self.STATE_ACTIVE or self.state == self.STATE_ARCHIVE or self.state == self.STATE_DISABLED):
|
||||||
self.state != self.STATE_DISABLED:
|
|
||||||
self.refresh_from_db()
|
self.refresh_from_db()
|
||||||
try:
|
try:
|
||||||
user_ldap = LdapUser.objects.get(uidNumber=self.uid_number)
|
user_ldap = LdapUser.objects.get(uidNumber=self.uid_number)
|
||||||
except LdapUser.DoesNotExist:
|
except LdapUser.DoesNotExist:
|
||||||
# Freshly created users are NOT synced in ldap base
|
|
||||||
if self.state == self.STATE_NOT_YET_ACTIVE:
|
|
||||||
return
|
|
||||||
user_ldap = LdapUser(uidNumber=self.uid_number)
|
user_ldap = LdapUser(uidNumber=self.uid_number)
|
||||||
base = True
|
base = True
|
||||||
access_refresh = True
|
access_refresh = True
|
||||||
|
@ -1025,7 +1046,7 @@ class User(RevMixin, FieldPermissionModelMixin, AbstractBaseUser,
|
||||||
.filter(local_part=self.pseudo.lower()).exclude(user_id=self.id)
|
.filter(local_part=self.pseudo.lower()).exclude(user_id=self.id)
|
||||||
):
|
):
|
||||||
raise ValidationError(_("This username is already used."))
|
raise ValidationError(_("This username is already used."))
|
||||||
if not self.local_email_enabled and not self.email and not (self.state == self.STATE_ARCHIVE):
|
if not self.local_email_enabled and not self.email and not (self.state == self.STATE_FULL_ARCHIVE):
|
||||||
raise ValidationError(_("There is neither a local email address nor an external"
|
raise ValidationError(_("There is neither a local email address nor an external"
|
||||||
" email address for this user.")
|
" email address for this user.")
|
||||||
)
|
)
|
||||||
|
|
|
@ -253,6 +253,8 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
||||||
<dd><i class="text-danger">{% trans "Archived" %}</i></dd>
|
<dd><i class="text-danger">{% trans "Archived" %}</i></dd>
|
||||||
{% elif users.state == 3 %}
|
{% elif users.state == 3 %}
|
||||||
<dd><i class="text-danger">{% trans "Not yet member" %}</i></dd>
|
<dd><i class="text-danger">{% trans "Not yet member" %}</i></dd>
|
||||||
|
{% elif users.state == 4 %}
|
||||||
|
<dd><i class="text-danger">{% trans "Full Archived" %}</i></dd>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue