Commit 6afb9c00 authored by Hamza Dely's avatar Hamza Dely
Browse files

Merge branch '18-api-de-l-app-comptes' into 'master'

Resolve "API de l'app Comptes"

Closes #18

See merge request dely/note-kfet!4
parents 6fcefe22 07ff3cc2
......@@ -68,6 +68,16 @@ class AliasSerializer(serializers.ModelSerializer):
raise serializers.ValidationError("Cet alias est déjà pris")
return normalized_alias
### Sérialiseurs pour le modèle Historique
class HistoriqueSerializer(serializers.ModelSerializer):
"""
Sérialiseur pour le modèle Historique
"""
class Meta:
model = Historique
fields = ['date', 'precedent', 'suivant']
### Sérialiseurs pour le modèle Adhérent
class AdherentSerializer(mixins.DynamicFieldsMixin, serializers.ModelSerializer):
......
{% extends "base.html" %}
{% from "forms.html" import display_simple %}
{% block app %}Gestion des comptes{% endblock %}
{% block fonction %}Historique de l'alias « {{ object.alias }} »{% endblock %}
{% block contenu %}
<div class="row">
<table class="table">
<thead class="thead-light">
<tr>
<th scope="col">Date</th>
<th scope="col">Action</th>
</tr>
</thead>
<tbody>
{% for h in historique %}
<tr>
<td>{{ h.date|date("r") }}</td>
{% if h.suivant is none %}
<td>Abandon de l'alias par #{{ h.precedent.id }}</td>
{% elif loop.last and (h.precedent is none) %}
<td>Création de l'alias par #{{ h.suivant.id }}</td>
{% elif h.precedent is none %}
<td>Adoption de l'alias par #{{ h.suivant.id }}</td>
{% else %}
<td>Transfert de l'alias de #{{ h.precedent.id }} vers #{{ h.suivant.id }}</td>
{% endif %}
</tr>
{% endfor %}
</tbody>
</table>
</div>
{% endblock %}
......@@ -13,7 +13,7 @@ from comptes.views import (
NoteLoginView, NoteLogoutView, NotePasswordResetDoneView, NotePasswordResetCompleteView,
AdherentInscriptionView, AdherentDetailView, AdherentRechercheView,
AdherentUpdateView, AdherentDroitChangeView, AdherentPasswordChangeView,
AdherentAvatarView, AdherentDeleteView,
AdherentAvatarView, AdherentDeleteView, AliasesHistoriqueView,
)
......@@ -35,4 +35,6 @@ urlpatterns = [
url(r'^(?P<pk>\d+)/pw_change/$', AdherentPasswordChangeView.as_view(), name="pw_change"),
url(r'^(?P<pk>\d+)/supprimer/$', AdherentDeleteView.as_view(), name="suppression"),
url(r'^rechercher/$', AdherentRechercheView.as_view(), name="recherche"),
# Vues pour la gestion des aliases
url(r'^aliases/(?P<pk>\d+)/$', AliasesHistoriqueView.as_view(), name="aliases_historique"),
]
......@@ -38,7 +38,7 @@ from note_kfet.droits import Acl, D
from note_kfet.views.mixins import NoteMixin
from comptes.models import (
Section, Alias, Droit, Accreditation, Adhesion, Adherent,
Section, Alias, Droit, Accreditation, Adhesion, Adherent, Historique
)
from comptes.forms import (
AdherentInscriptionForm, AdherentPasswordChangeForm, AdherentDroitForm,
......@@ -46,7 +46,7 @@ from comptes.forms import (
)
from comptes.filters import AdherentRechercheFilter
from comptes.serializers import (
AdherentSerializer, AliasSerializer, AccreditationSerializer,
AdherentSerializer, AliasSerializer, HistoriqueSerializer, AccreditationSerializer,
)
#%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
......@@ -357,6 +357,24 @@ class AdherentDeleteView(NoteMixin, LoginRequiredMixin, PermissionRequiredMixin,
def get_success_url(self, *args, **kwargs):
return reverse_lazy('comptes:detail', kwargs={'pk' : self.object.id})
class AliasesHistoriqueView(NoteMixin, LoginRequiredMixin, PermissionRequiredMixin, DetailView):
"""
Vue permettant de consulter l'historique d'attribution d'un pseudo
"""
app_label = "comptes"
permission_required = D("comptes.adherent_detail", Acl.BASIQUE)
template_name = "alias_historique.html"
model = Alias
def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
context.update({
'historique' : Historique.objects.filter(alias=self.get_object()).order_by('-date'),
})
return context
#%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
# Vues de l'API
#%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
......@@ -784,6 +802,23 @@ class AliasViewSet(viewsets.GenericViewSet):
except Alias.DoesNotExist:
return Response({'id' : None}, status=status.HTTP_200_OK)
def retrieve(self, request, pk=None):
"""
Consulte les informations liées à un alias donné
"""
if not request.user.has_perm("comptes.adherent_detail", Acl.BASIQUE):
return Response({}, status=status.HTTP_403_FORBIDDEN)
serialized_alias = self.get_serializer(self.get_object())
qs = Historique.objects.filter(alias=self.get_object()).order_by('-date')
serialized_history = HistoriqueSerializer(qs, many=True)
return Response(
{
"alias" : serialized_alias.data,
"history" : serialized_history.data,
}
)
def create(self, request):
"""
Crée un nouvel alias.
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment