mirror of
https://gitlab2.federez.net/re2o/re2o
synced 2024-12-22 23:13:46 +00:00
Merge branch 'user_adh_pas_encore' into 'dev'
User adh pas encore See merge request federez/re2o!279
This commit is contained in:
commit
5af66b400b
5 changed files with 47 additions and 9 deletions
|
@ -29,6 +29,7 @@ the response (JSON or other), the CSRF exempting, ...
|
|||
import datetime
|
||||
|
||||
from django.conf import settings
|
||||
from django.db.models import Q
|
||||
from rest_framework.authtoken.views import ObtainAuthToken
|
||||
from rest_framework.authtoken.models import Token
|
||||
from rest_framework.response import Response
|
||||
|
@ -421,7 +422,7 @@ class UserViewSet(viewsets.ReadOnlyModelViewSet):
|
|||
class HomeCreationViewSet(viewsets.ReadOnlyModelViewSet):
|
||||
"""Exposes infos of `users.models.Users` objects to create homes.
|
||||
"""
|
||||
queryset = users.User.objects.all()
|
||||
queryset = users.User.objects.exclude(Q(state=User.STATE_DISABLED) | Q(state=User.STATE_NOT_YET_ACTIVE))
|
||||
serializer_class = serializers.HomeCreationSerializer
|
||||
|
||||
class ClubViewSet(viewsets.ReadOnlyModelViewSet):
|
||||
|
|
|
@ -243,7 +243,8 @@ def facture_post_save(**kwargs):
|
|||
"""
|
||||
facture = kwargs['instance']
|
||||
user = facture.user
|
||||
user.ldap_sync(base=False, access_refresh=True, mac_refresh=False)
|
||||
user.set_active()
|
||||
user.ldap_sync(base=True, access_refresh=True, mac_refresh=False)
|
||||
|
||||
|
||||
@receiver(post_delete, sender=Facture)
|
||||
|
@ -472,7 +473,8 @@ def vente_post_save(**kwargs):
|
|||
purchase.create_cotis()
|
||||
purchase.cotisation.save()
|
||||
user = purchase.facture.user
|
||||
user.ldap_sync(base=False, access_refresh=True, mac_refresh=False)
|
||||
user.set_active()
|
||||
user.ldap_sync(base=True, access_refresh=True, mac_refresh=False)
|
||||
|
||||
|
||||
# TODO : change vente to purchase
|
||||
|
|
20
users/migrations/0077_auto_20180824_1750.py
Normal file
20
users/migrations/0077_auto_20180824_1750.py
Normal file
|
@ -0,0 +1,20 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
# Generated by Django 1.10.7 on 2018-08-24 15:50
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('users', '0076_auto_20180818_1321'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterField(
|
||||
model_name='user',
|
||||
name='state',
|
||||
field=models.IntegerField(choices=[(0, 'STATE_ACTIVE'), (1, 'STATE_DISABLED'), (2, 'STATE_ARCHIVE'), (3, 'STATE_NOT_YET_ACTIVE')], default=3),
|
||||
),
|
||||
]
|
|
@ -186,10 +186,12 @@ class User(RevMixin, FieldPermissionModelMixin, AbstractBaseUser,
|
|||
STATE_ACTIVE = 0
|
||||
STATE_DISABLED = 1
|
||||
STATE_ARCHIVE = 2
|
||||
STATE_NOT_YET_ACTIVE = 3
|
||||
STATES = (
|
||||
(0, 'STATE_ACTIVE'),
|
||||
(1, 'STATE_DISABLED'),
|
||||
(2, 'STATE_ARCHIVE'),
|
||||
(3, 'STATE_NOT_YET_ACTIVE'),
|
||||
)
|
||||
|
||||
surname = models.CharField(max_length=255)
|
||||
|
@ -231,7 +233,7 @@ class User(RevMixin, FieldPermissionModelMixin, AbstractBaseUser,
|
|||
blank=True
|
||||
)
|
||||
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)
|
||||
telephone = models.CharField(max_length=15, blank=True, null=True)
|
||||
uid_number = models.PositiveIntegerField(
|
||||
|
@ -329,7 +331,14 @@ class User(RevMixin, FieldPermissionModelMixin, AbstractBaseUser,
|
|||
@property
|
||||
def is_active(self):
|
||||
""" 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
|
||||
def is_staff(self):
|
||||
|
@ -561,6 +570,9 @@ class User(RevMixin, FieldPermissionModelMixin, AbstractBaseUser,
|
|||
try:
|
||||
user_ldap = LdapUser.objects.get(uidNumber=self.uid_number)
|
||||
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)
|
||||
base = True
|
||||
access_refresh = True
|
||||
|
|
|
@ -52,7 +52,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
|||
{% elif not users.has_access %}
|
||||
<div class="panel panel-danger">
|
||||
<div class="panel-heading dashboard">{% trans "No connection" %}</div>
|
||||
<div class="panel-body dashboard">
|
||||
<div class="panel-body dashboard">
|
||||
{% can_create Facture %}
|
||||
<a class="btn btn-danger btn-sm" role="button" href="{% url 'cotisations:new-facture' users.id %}">
|
||||
<i class="fas fa-sign-in-alt"></i> {% trans "Pay for a connection" %}
|
||||
|
@ -213,9 +213,12 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
|||
{% if users.state == 0 %}
|
||||
<td><i class="text-success">{% trans "Active" %}</i></td>
|
||||
{% elif users.state == 1 %}
|
||||
<td><i class="text-danger">{% trans "Disabled" %}</i></td>
|
||||
{% else %}
|
||||
<td><i class="text-warning">{% trans "Archived" %}</i></td>
|
||||
<td><i class="text-warning">{% trans "Disabled" %}</i></td>
|
||||
{% elif users.state == 2 %}
|
||||
<td><i class="text-danger">{% trans "Archived" %}</i></td>
|
||||
{% elif users.state == 3 %}
|
||||
<td><i class="text-danger">{% trans "Not yet Member" %}</i></td>
|
||||
|
||||
{% endif %}
|
||||
</tr>
|
||||
<tr>
|
||||
|
|
Loading…
Reference in a new issue