1
0
mirror of https://gitlab.crans.org/bde/nk20 synced 2024-12-22 23:42:25 +00:00

List pending users

This commit is contained in:
Yohann D'ANELLO 2020-04-05 06:40:03 +02:00
parent 49807d33d9
commit f10497bac3
11 changed files with 95 additions and 13 deletions

View File

@ -26,7 +26,7 @@ class ProfileForm(forms.ModelForm):
class Meta:
model = Profile
fields = '__all__'
exclude = ('user', 'email_confirmed', )
exclude = ('user', 'email_confirmed', 'registration_valid', )
class ClubForm(forms.ModelForm):

View File

@ -12,7 +12,7 @@ from django.urls import reverse, reverse_lazy
from django.utils.encoding import force_bytes
from django.utils.http import urlsafe_base64_encode
from django.utils.translation import gettext_lazy as _
from member.tokens import account_activation_token
from registration.tokens import account_activation_token
from note.models import MembershipTransaction
@ -53,6 +53,11 @@ class Profile(models.Model):
default=False,
)
registration_valid = models.BooleanField(
verbose_name=_("registration valid"),
default=False,
)
email_confirmed = models.BooleanField(
verbose_name=_("email confirmed"),
default=False,

View File

@ -139,7 +139,7 @@ class UserListView(ProtectQuerysetMixin, LoginRequiredMixin, SingleTableView):
template_name = 'member/user_list.html'
def get_queryset(self, **kwargs):
qs = super().get_queryset()
qs = super().get_queryset().filter(profile__registration_valid=True)
if "search" in self.request.GET:
pattern = self.request.GET["search"]

View File

@ -2,7 +2,7 @@
# SPDX-License-Identifier: GPL-3.0-or-later
def save_user_note(instance, created, raw, **_kwargs):
def save_user_note(instance, raw, **_kwargs):
"""
Hook to create and save a note when an user is updated
"""
@ -10,10 +10,11 @@ def save_user_note(instance, created, raw, **_kwargs):
# When provisionning data, do not try to autocreate
return
if created:
from .models import NoteUser
NoteUser.objects.create(user=instance)
instance.note.save()
if instance.profile.registration_valid and instance.is_active:
# Create note only when the registration is validated
from note.models import NoteUser
NoteUser.objects.get_or_create(user=instance)
instance.note.save()
def save_club_note(instance, created, raw, **_kwargs):

View File

@ -0,0 +1,23 @@
# Copyright (C) 2018-2020 by BDE ENS Paris-Saclay
# SPDX-License-Identifier: GPL-3.0-or-later
import django_tables2 as tables
from django.contrib.auth.models import User
class FutureUserTable(tables.Table):
phone_number = tables.Column(accessor='profile.phone_number')
section = tables.Column(accessor='profile.section')
class Meta:
attrs = {
'class': 'table table-condensed table-striped table-hover'
}
template_name = 'django_tables2/bootstrap4.html'
fields = ('last_name', 'first_name', 'username', 'email', )
model = User
row_attrs = {
'class': 'table-row',
'data-href': lambda record: record.pk
}

View File

@ -8,6 +8,7 @@ from . import views
app_name = 'registration'
urlpatterns = [
path('signup/', views.UserCreateView.as_view(), name="signup"),
path('accounts/activate/sent', views.UserActivationEmailSentView.as_view(), name='account_activation_sent'),
path('accounts/activate/<uidb64>/<token>', views.UserActivateView.as_view(), name='account_activation'),
path('validate_email/sent', views.UserActivationEmailSentView.as_view(), name='account_activation_sent'),
path('validate_email/<uidb64>/<token>', views.UserActivateView.as_view(), name='account_activation'),
path('validate_user/', views.FutureUserListView.as_view(), name="future_user_list"),
]

View File

@ -2,6 +2,7 @@
# SPDX-License-Identifier: GPL-3.0-or-later
from django.conf import settings
from django.contrib.auth.mixins import LoginRequiredMixin
from django.contrib.auth.models import User
from django.core.exceptions import ValidationError
from django.shortcuts import resolve_url
@ -11,10 +12,13 @@ from django.utils.http import urlsafe_base64_decode
from django.utils.translation import gettext_lazy as _
from django.views.decorators.csrf import csrf_protect
from django.views.generic import CreateView, TemplateView
from django_tables2 import SingleTableView
from member.forms import ProfileForm
from member.tokens import account_activation_token
from permission.views import ProtectQuerysetMixin
from .forms import SignUpForm
from .tables import FutureUserTable
from .tokens import account_activation_token
class UserCreateView(CreateView):
@ -23,8 +27,8 @@ class UserCreateView(CreateView):
"""
form_class = SignUpForm
success_url = reverse_lazy('member:login')
template_name = 'member/signup.html'
success_url = reverse_lazy('registration:account_activation_sent')
template_name = 'registration/signup.html'
second_form = ProfileForm
def get_context_data(self, **kwargs):
@ -108,3 +112,22 @@ class UserActivationEmailSentView(TemplateView):
template_name = 'registration/account_activation_email_sent.html'
title = _('Account activation email sent')
class FutureUserListView(ProtectQuerysetMixin, LoginRequiredMixin, SingleTableView):
"""
Affiche la liste des utilisateurs, avec une fonction de recherche statique
"""
model = User
table_class = FutureUserTable
template_name = 'registration/future_user_list.html'
def get_queryset(self, **kwargs):
return super().get_queryset().filter(profile__registration_valid=False)
def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
context["title"] = _("Unregistered users")
return context

View File

@ -94,6 +94,13 @@ SPDX-License-Identifier: GPL-3.0-or-later
<a class="nav-link" href="{% url 'member:club_list' %}"><i class="fa fa-users"></i> {% trans 'Clubs' %}</a>
</li>
{% endif %}
{% if "member.change_profile_registration_valid"|has_perm:user %}
<li class="nav-item active">
<a class="nav-link" href="{% url 'registration:future_user_list' %}">
<i class="fa fa-user-plus"></i> {% trans "Registrations" %}
</a>
</li>
{% endif %}
{% if "activity.activity"|not_empty_model_list %}
<li class="nav-item active">
<a class="nav-link" href="{% url 'activity:activity_list' %}"><i class="fa fa-calendar"></i> {% trans 'Activities' %}</a>

View File

@ -0,0 +1,22 @@
{% extends "base.html" %}
{% load render_table from django_tables2 %}
{% load crispy_forms_tags %}
{% load i18n %}
{% block content %}
<div id="user_table">
{% render_table table %}
</div>
<hr>
<a href="{% url 'registration:signup' %}"><button class="btn btn-primary btn-block">{% trans "New user" %}</button></a>
{% endblock %}
{% block extrajavascript %}
<script type="text/javascript">
$(".table-row").click(function() {
window.document.location = $(this).data("href");
});
</script>
{% endblock %}