|
|
@ -186,10 +186,12 @@ class User(RevMixin, FieldPermissionModelMixin, AbstractBaseUser, |
|
|
STATE_ACTIVE = 0 |
|
|
STATE_ACTIVE = 0 |
|
|
STATE_DISABLED = 1 |
|
|
STATE_DISABLED = 1 |
|
|
STATE_ARCHIVE = 2 |
|
|
STATE_ARCHIVE = 2 |
|
|
|
|
|
STATE_NOT_YET_ACTIVE = 3 |
|
|
STATES = ( |
|
|
STATES = ( |
|
|
(0, 'STATE_ACTIVE'), |
|
|
(0, 'STATE_ACTIVE'), |
|
|
(1, 'STATE_DISABLED'), |
|
|
(1, 'STATE_DISABLED'), |
|
|
(2, 'STATE_ARCHIVE'), |
|
|
(2, 'STATE_ARCHIVE'), |
|
|
|
|
|
(3, 'STATE_NOT_YET_ACTIVE'), |
|
|
) |
|
|
) |
|
|
|
|
|
|
|
|
surname = models.CharField(max_length=255) |
|
|
surname = models.CharField(max_length=255) |
|
|
@ -231,7 +233,7 @@ class User(RevMixin, FieldPermissionModelMixin, AbstractBaseUser, |
|
|
blank=True |
|
|
blank=True |
|
|
) |
|
|
) |
|
|
pwd_ntlm = models.CharField(max_length=255) |
|
|
pwd_ntlm = models.CharField(max_length=255) |
|
|
state = models.IntegerField(choices=STATES, default=STATE_ACTIVE) |
|
|
state = models.IntegerField(choices=STATES, default=STATE_NOT_YET_ACTIVE) |
|
|
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( |
|
|
uid_number = models.PositiveIntegerField( |
|
|
@ -329,7 +331,14 @@ class User(RevMixin, FieldPermissionModelMixin, AbstractBaseUser, |
|
|
@property |
|
|
@property |
|
|
def is_active(self): |
|
|
def is_active(self): |
|
|
""" Renvoie si l'user est à l'état actif""" |
|
|
""" Renvoie si l'user est à l'état actif""" |
|
|
return self.state == self.STATE_ACTIVE |
|
|
return self.state == self.STATE_ACTIVE or self.state == self.STATE_NOT_YET_ACTIVE |
|
|
|
|
|
|
|
|
|
|
|
def set_active(self): |
|
|
|
|
|
"""Enable this user if he subscribed successfully one time before""" |
|
|
|
|
|
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(): |
|
|
|
|
|
self.state = self.STATE_ACTIVE |
|
|
|
|
|
self.save() |
|
|
|
|
|
|
|
|
@property |
|
|
@property |
|
|
def is_staff(self): |
|
|
def is_staff(self): |
|
|
@ -561,6 +570,9 @@ class User(RevMixin, FieldPermissionModelMixin, AbstractBaseUser, |
|
|
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 |
|
|
|