Commit ac029442 authored by Flavio TARSETTI's avatar Flavio TARSETTI

[accounts][views] implement rejection endpoint and notify supervisor of...

[accounts][views] implement rejection endpoint and notify supervisor of revalidation through quick link
parent 110568d3
......@@ -148,7 +148,8 @@ def generate_load_response(request, temp_url, template, parameters):
return render(request, answer["template"], answer["parameters"])
def load_temporary_url(request, hash_url):
def load_temporary_url_validation(request, hash_url):
temp_url = get_object_or_404(TemporaryUrl, url_hash=hash_url)
supervisiontrack = temp_url.supervision_track
supervisee = supervisiontrack.supervisee
......@@ -221,6 +222,27 @@ def load_temporary_url(request, hash_url):
supervisiontrack.save()
supervisee.profile.save()
supervisee.save()
# Inform supervisor about supervisee revalidation
# Possible supervisor rejection available
parsed_url = urlparse(settings.URL_PREFIX)
server_address = '%s://%s' % (parsed_url.scheme, parsed_url.hostname)
temp_url_rejection = TemporaryUrl.objects.create_temporary_url(TemporaryUrl.REJECTION, supervisiontrack)
context = {
"supervisor": supervisiontrack.supervisor,
"supervisee": supervisee,
"prefix": server_address,
"temp_url": temp_url_rejection.url_hash,
}
mail.send_email(
"registration/mail.account_revalidation_supervisor.subject.txt",
"registration/mail.supervisor_possible_supervisee_rejection.message.txt",
context,
[supervisiontrack.supervisor.email],
)
else:
#Track already valid
error_message = "You don't need to revalidate at the moment, your supervision is still valid"
......@@ -252,3 +274,51 @@ def load_temporary_url(request, hash_url):
else:
#Track already valid
return generate_load_response(request, temp_url, "accounts/url_validation_failed.html", {})
def load_temporary_url_rejection(request, hash_url):
temp_url = get_object_or_404(TemporaryUrl, url_hash=hash_url)
supervisiontrack = temp_url.supervision_track
supervisee = supervisiontrack.supervisee
parsed_url = urlparse(settings.URL_PREFIX)
server_address = '%s://%s' % (parsed_url.scheme, parsed_url.hostname)
context = {
'supervisor': supervisiontrack.supervisor,
'supervisee': supervisee,
'prefix': server_address,
}
now = datetime.datetime.now()
if temp_url.status == TemporaryUrl.REJECTION:
# Supervisor rejects Supervisee
if supervisee.profile.supervision_key is not None and now < temp_url.expires:
if supervisiontrack.is_valid:
expiration_date_delta = datetime.timedelta(days=settings.ACCOUNT_BLOCKAGE_AFTER_FIRST_REJECTION_DAYS)
supervisiontrack.expiration_date = now
supervisiontrack.is_valid = False
if supervisee.profile.status != Profile.BLOCKED:
supervisee.profile.status = Profile.REJECTED
if supervisee.profile.rejection_date == None:
supervisee.profile.rejection_date = now + expiration_date_delta
else:
supervisee.profile.rejection_date = None
supervisee.profile.supervision_key = None
supervisiontrack.save()
supervisee.profile.save()
supervisee.save()
mail.send_email('registration/mail.supervisor_rejected.subject.txt',
'registration/mail.supervisor_rejected.message.txt',
context,
[supervisee.email])
return generate_load_response(request, temp_url, "accounts/url_rejection.html", {"supervisiontrack": supervisiontrack})
return generate_load_response(request, temp_url, "accounts/url_rejection_failed.html", {})
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