Skip to content
Snippets Groups Projects
Commit 9ac65966 authored by Flavio TARSETTI's avatar Flavio TARSETTI
Browse files

[accounts] added PUT endpoint for godfather validation

parent 3e761e9a
No related branches found
No related tags found
1 merge request!224Security accounts
Pipeline #
......@@ -40,6 +40,7 @@ from rest_framework.response import Response
from rest_framework import status
from .serializers import FullSupervisionTrackSerializer
from .serializers import SupervisionTrackUpdateSerializer
from ..common.utils import validate_restructuredtext
from ..ui.templatetags.markup import restructuredtext
......@@ -58,6 +59,7 @@ from .permissions import IsGodfatherAndAuthor
from ..common.responses import BadRequestResponse, ForbiddenResponse
import datetime
import re
import simplejson as json
......@@ -95,3 +97,46 @@ class GodfatherListView(generics.ListAPIView):
#----------------------------------------------------------
class BaseUpdateSupervisionTrackView(generics.UpdateAPIView):
model = SupervisionTrack
serializer_class = SupervisionTrackUpdateSerializer
def get_permissions(self):
permission_classes = [permissions.IsAuthenticated, IsGodfatherAndAuthor]
self.permission_classes = permission_classes
return super(BaseUpdateSupervisionTrackView, self).get_permissions()
#----------------------------------------------------------
class GodfatherAddSuperviseeView(BaseUpdateSupervisionTrackView):
permission_classes = BaseUpdateSupervisionTrackView.permission_classes
def put(self, request, supervisee_name):
supervisee = User.objects.get(username=supervisee_name)
profile_supervisee = Profile.objects.get(user=supervisee)
supervisiontrack = SupervisionTrack.objects.get(godfather=request.user, supervisee=supervisee, supervisee__profile__supervision_key=models.F('supervision_key'))
supervisiontrack.is_valid = True
now = datetime.datetime.now()
expiration_date_delta = datetime.timedelta(days=settings.ACCOUNT_EXPIRATION_DAYS)
supervisiontrack.expiration_date = now + expiration_date_delta
supervisiontrack.start_date = now
supervisiontrack.last_validation_date = now
supervisee.profile.status = Profile.ACCEPTED
supervisiontrack.save()
supervisee.profile.save()
return Response(status=status.HTTP_204_NO_CONTENT)
#----------------------------------------------------------
......@@ -34,4 +34,11 @@ urlpatterns = [
api.GodfatherListView.as_view(),
name='list_supervisee'
),
url(
r'^(?P<supervisee_name>[\w\W]+)/validate/$',
api.GodfatherAddSuperviseeView.as_view(),
name='validate_supervisee'
),
]
......@@ -70,7 +70,7 @@ class BasicSupervisionTrackSerializer(serializers.ModelSerializer):
class Meta:
model = SupervisionTrack
fields = ['status', 'is_valid']
fields = ['is_valid']
#def get_supervisee(self, obj):
# return obj.supervisee
......@@ -82,7 +82,7 @@ class BasicSupervisionTrackSerializer(serializers.ModelSerializer):
return obj.is_valid
def get_start_date(self, obj):
return obj.expiration_date
return obj.start_date
def get_expiration_date(self, obj):
return obj.expiration_date
......@@ -104,3 +104,10 @@ class FullSupervisionTrackSerializer(BasicSupervisionTrackSerializer):
#----------------------------------------------------------
class SupervisionTrackUpdateSerializer(BasicSupervisionTrackSerializer):
pass
#----------------------------------------------------------
......@@ -217,6 +217,8 @@ DATASETS_ROOT_PATH = None
ACCOUNT_ACTIVATION_DAYS = 2
ACCOUNT_ACTIVATION_DAYS_FROM_GODFATHER = 7
ACCOUNT_EXPIRATION_DAYS = 365
LOGIN_REDIRECT_URL = '/'
LOGIN_URL = '/login/'
SYSTEM_ACCOUNT = 'system'
......
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