Skip to content
Snippets Groups Projects
Verified Commit d671948d authored by Andreas Ellewsen's avatar Andreas Ellewsen
Browse files

Move guest info and ou views to better locations

The OU view deserves its own file, and the guest info is actually a
person view and should live with  the other person views.
parent b349e510
No related branches found
No related tags found
1 merge request!170Greg 101 verify identity
from django.http import JsonResponse
from rest_framework.authentication import SessionAuthentication, BasicAuthentication
from rest_framework.permissions import IsAuthenticated
from rest_framework.views import APIView
from greg.models import Sponsor
from greg.permissions import IsSponsor
from gregui.models import GregUserProfile
class OusView(APIView):
"""Fetch Ous related to the authenticated sponsor."""
authentication_classes = [SessionAuthentication, BasicAuthentication]
permission_classes = [IsAuthenticated, IsSponsor]
@staticmethod
# pylint: disable=W0622
def get(request, format=None):
profile = GregUserProfile.objects.get(user=request.user)
sponsor = Sponsor.objects.get(id=profile.sponsor.id)
return JsonResponse(
{
"ous": [
{"id": i.id, "nb": i.name_nb, "en": i.name_en}
for i in sponsor.units.all()
]
}
)
from django.http.response import JsonResponse
from django.utils.timezone import now
from rest_framework import status
from rest_framework.authentication import SessionAuthentication, BasicAuthentication
from rest_framework.permissions import IsAuthenticated
from rest_framework.response import Response
from rest_framework.views import APIView
from greg.models import Identity, Person, InvitationLink
from greg.models import Identity, Person
from greg.permissions import IsSponsor
from gregui.api.serializers.guest import create_identity_or_update
from gregui.models import GregUserProfile
from gregui.validation import validate_email
......@@ -106,3 +106,62 @@ class PersonSearchView(APIView):
]
}
return JsonResponse(response)
class GuestInfoView(APIView):
"""Fetch all the sponsors guests"""
authentication_classes = [SessionAuthentication, BasicAuthentication]
permission_classes = [IsAuthenticated, IsSponsor]
@staticmethod
# pylint: disable=W0622
def get(request, format=None):
user = GregUserProfile.objects.get(user=request.user)
return JsonResponse(
{
"persons": [
{
"pid": person.id,
"first": person.first_name,
"last": person.last_name,
"email": person.private_email and person.private_email.value,
"mobile": person.private_mobile and person.private_mobile.value,
"fnr": person.fnr
and {
"id": person.fnr.id,
"value": "".join((person.fnr.value[:-5], "*****")),
"type": person.fnr.type,
"verified_at": person.fnr.verified_at,
},
"passport": person.passport
and {
"id": person.passport.id,
"value": person.passport.value,
"type": person.passport.type,
"verified_at": person.passport.verified_at,
},
"active": person.is_registered and person.is_verified,
"registered": person.is_registered,
"verified": person.is_verified,
"roles": [
{
"id": role.id,
"name_nb": role.type.name_nb,
"name_en": role.type.name_en,
"ou_nb": role.orgunit.name_nb,
"ou_en": role.orgunit.name_en,
"start_date": role.start_date,
"end_date": role.end_date,
"max_days": role.type.max_days,
}
for role in person.roles.all()
],
}
for person in Person.objects.filter(
roles__sponsor=user.sponsor
).distinct()
]
}
)
......@@ -5,8 +5,9 @@ from django.urls import path
from django.urls.resolvers import URLResolver
from gregui.api import urls as api_urls
from gregui.api.views.ou import OusView
from gregui.api.views.userinfo import UserInfoView
from gregui.views import OusView, GuestInfoView
from gregui.api.views.person import GuestInfoView
from . import views
urlpatterns: List[URLResolver] = [
......
......@@ -6,10 +6,7 @@ from rest_framework.authentication import SessionAuthentication, BasicAuthentica
from rest_framework.permissions import IsAuthenticated
from rest_framework.views import APIView
from greg.models import Person, Sponsor
from greg.permissions import IsSponsor
from gregui import mailutils
from gregui.models import GregUserProfile
def get_csrf(request):
......@@ -61,83 +58,3 @@ class WhoAmIView(APIView):
# pylint: disable=W0622
def get(request, format=None):
return JsonResponse({"username": request.user.username})
class OusView(APIView):
"""Fetch Ous related to the authenticated sponsor."""
authentication_classes = [SessionAuthentication, BasicAuthentication]
permission_classes = [IsAuthenticated, IsSponsor]
@staticmethod
# pylint: disable=W0622
def get(request, format=None):
profile = GregUserProfile.objects.get(user=request.user)
sponsor = Sponsor.objects.get(id=profile.sponsor.id)
return JsonResponse(
{
"ous": [
{"id": i.id, "nb": i.name_nb, "en": i.name_en}
for i in sponsor.units.all()
]
}
)
class GuestInfoView(APIView):
"""Fetch all the sponsors guests"""
authentication_classes = [SessionAuthentication, BasicAuthentication]
permission_classes = [IsAuthenticated, IsSponsor]
@staticmethod
# pylint: disable=W0622
def get(request, format=None):
user = GregUserProfile.objects.get(user=request.user)
return JsonResponse(
{
"persons": [
{
"pid": person.id,
"first": person.first_name,
"last": person.last_name,
"email": person.private_email and person.private_email.value,
"mobile": person.private_mobile and person.private_mobile.value,
"fnr": person.fnr
and {
"id": person.fnr.id,
"value": "".join((person.fnr.value[:-5], "*****")),
"type": person.fnr.type,
"verified_at": person.fnr.verified_at,
},
"passport": person.passport
and {
"id": person.passport.id,
"value": person.passport.value,
"type": person.passport.type,
"verified_at": person.passport.verified_at,
},
"active": person.is_registered and person.is_verified,
"registered": person.is_registered,
"verified": person.is_verified,
"roles": [
{
"id": role.id,
"name_nb": role.type.name_nb,
"name_en": role.type.name_en,
"ou_nb": role.orgunit.name_nb,
"ou_en": role.orgunit.name_en,
"start_date": role.start_date,
"end_date": role.end_date,
"max_days": role.type.max_days,
}
for role in person.roles.all()
],
}
for person in Person.objects.filter(
roles__sponsor=user.sponsor
).distinct()
]
}
)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment