Commit 18578372 authored by Flavio TARSETTI's avatar Flavio TARSETTI
Browse files

[accounts] patch api not able to validate already validated user

parent d42a472c
......@@ -126,49 +126,57 @@ class GodfatherAddSuperviseeView(BaseUpdateSupervisionTrackView):
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'))
if supervisee.profile.status != Profile.ACCEPTED:
supervisiontrack = SupervisionTrack.objects.get(godfather=request.user, supervisee=supervisee, supervisee__profile__supervision_key=models.F('supervision_key'))
supervisiontrack.is_valid = True
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
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
supervisee.profile.rejection_date = None
supervisiontrack.start_date = now
supervisiontrack.last_validation_date = now
supervisee.profile.status = Profile.ACCEPTED
supervisee.profile.rejection_date = None
supervisiontrack.save()
supervisee.profile.save()
supervisee.is_active = True
supervisee.save()
supervisiontrack.save()
supervisee.profile.save()
supervisee.is_active = True
supervisee.save()
from django.core.mail import send_mail
from django.core.mail import send_mail
parsed_url = urlparse(settings.URL_PREFIX)
server_address = '%s://%s' % (parsed_url.scheme, parsed_url.hostname)
parsed_url = urlparse(settings.URL_PREFIX)
server_address = '%s://%s' % (parsed_url.scheme, parsed_url.hostname)
c = Context({ 'supervisor': supervisiontrack.godfather,
'supervisee': supervisee,
'prefix': server_address,
})
c = Context({ 'supervisor': supervisiontrack.godfather,
'supervisee': supervisee,
'prefix': server_address,
})
try:
t = loader.get_template('registration/mail.godfather_validated.subject.txt')
subject = t.render(c)
try:
t = loader.get_template('registration/mail.godfather_validated.subject.txt')
subject = t.render(c)
# Note: e-mail subject *must not* contain newlines
subject = settings.EMAIL_SUBJECT_PREFIX + ''.join(subject.splitlines())
# Note: e-mail subject *must not* contain newlines
subject = settings.EMAIL_SUBJECT_PREFIX + ''.join(subject.splitlines())
t = loader.get_template('registration/mail.godfather_validated.message.txt')
message = t.render(c)
t = loader.get_template('registration/mail.godfather_validated.message.txt')
message = t.render(c)
send_mail(subject, message, settings.DEFAULT_FROM_EMAIL, [supervisee.email])
except:
pass
send_mail(subject, message, settings.DEFAULT_FROM_EMAIL, [supervisee.email])
except:
pass
return Response(status=status.HTTP_204_NO_CONTENT)
return Response(status=status.HTTP_204_NO_CONTENT)
else:
#Track already valid
reason = "You can't validate this supervisee as his supervision is still valid"
result = {
'error': reason,
}
return BadRequestResponse(result)
#----------------------------------------------------------
......
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