Commit e61af2f5 authored by Samuel GAIST's avatar Samuel GAIST
Browse files

Merge branch '558_fix_accounts_api_url_prefix_usage' into 'django3_migration'

Cleanup url prefix use in accounts api

See merge request !389
parents af2e7192 1e0213d7
Pipeline #43139 passed with stage
in 15 minutes and 36 seconds
......@@ -26,7 +26,6 @@
###############################################################################
import datetime
from urllib.parse import urlparse
from django.conf import settings
from django.contrib.auth.models import User
......@@ -42,7 +41,6 @@ from ..ui.registration.models import RegistrationProfile
from ..utils import mail
from .models import Profile
from .models import SupervisionTrack
from .models import TemporaryUrl
from .permissions import IsAuthorAndNotSupervisor
from .permissions import IsAuthorAndPossiblySupervisor
from .permissions import IsSuperUser
......@@ -52,6 +50,7 @@ from .serializers import SupervisionTrackUpdateSerializer
from .serializers import UserSerializer
from .views import accept_supervisee
from .views import emergency_rejection
from .views import inform_supervisor_new_supervisee_request
from .views import perform_revalidation
from .views import supervisee_rejection
......@@ -203,20 +202,15 @@ class SupervisorRemoveSuperviseeView(BaseUpdateSupervisionTrackView):
}
return BadRequestResponse(result)
parsed_url = urlparse(settings.URL_PREFIX)
server_address = "%s://%s" % (parsed_url.scheme, parsed_url.hostname)
if not supervisee.profile.is_supervisor:
context = {
"supervisor": supervisiontrack.supervisor,
"supervisee": supervisee,
"prefix": server_address,
}
else:
context = {
"supervisor": request.user,
"supervisee": supervisee,
"prefix": server_address,
}
if supervisee.profile.status == Profile.WAITINGVALIDATION:
......@@ -314,7 +308,6 @@ class SupervisorRemoveSuperviseeView(BaseUpdateSupervisionTrackView):
context = {
"supervisor": supervisee,
"supervisee": track_supervisee,
"prefix": server_address,
}
mail.send_email(
......@@ -344,7 +337,6 @@ class SupervisorRemoveSuperviseeView(BaseUpdateSupervisionTrackView):
context = {
"supervisor": track_supervisor,
"supervisee": track_supervisee,
"prefix": server_address,
}
# New user account waiting validation, so delete this account and inform by email the user
......@@ -421,9 +413,6 @@ class SuperviseeAddSupervisorView(BaseCreateSupervisionTrackViewSupervisee):
}
return BadRequestResponse(result)
parsed_url = urlparse(settings.URL_PREFIX)
server_address = "%s://%s" % (parsed_url.scheme, parsed_url.hostname)
supervisee = request.user
if supervisee.profile.supervision_key is not None:
# There's a key check if there's a valid track
......@@ -451,7 +440,6 @@ class SuperviseeAddSupervisorView(BaseCreateSupervisionTrackViewSupervisee):
context = {
"supervisor": supervisiontrack.supervisor,
"supervisee": supervisiontrack.supervisee,
"prefix": server_address,
}
mail.send_email(
......@@ -518,21 +506,8 @@ class SuperviseeAddSupervisorView(BaseCreateSupervisionTrackViewSupervisee):
supervisee.save()
# Inform by email the supervisor that he has a new supervisee request
temp_url = TemporaryUrl.objects.create_temporary_url(
TemporaryUrl.VALIDATION, supervisiontrack
)
context = {
"supervisor": supervisor,
"supervisee": supervisee,
"prefix": server_address,
"temp_url": temp_url.url_hash,
}
mail.send_email(
"registration/mail.supervisor_validation.subject.txt",
"registration/mail.supervisor_validation_supervisee_add_request.message.txt",
context,
[supervisor.email],
inform_supervisor_new_supervisee_request(
request, supervisiontrack, supervisor, supervisee
)
return Response(status=status.HTTP_204_NO_CONTENT)
......@@ -673,9 +648,6 @@ class RemoveSupervisorModeView(BaseUpdateSupervisorModeView):
| Q(supervisee__profile__status=Profile.WAITINGVALIDATION)
)
parsed_url = urlparse(settings.URL_PREFIX)
server_address = "%s://%s" % (parsed_url.scheme, parsed_url.hostname)
if supervisiontracks.count() > 0:
for track in supervisiontracks:
track.expiration_date = now
......@@ -700,7 +672,6 @@ class RemoveSupervisorModeView(BaseUpdateSupervisorModeView):
context = {
"supervisor": user,
"supervisee": track_supervisee,
"prefix": server_address,
}
mail.send_email(
......@@ -730,7 +701,6 @@ class RemoveSupervisorModeView(BaseUpdateSupervisorModeView):
context = {
"supervisor": track_supervisor,
"supervisee": track_supervisee,
"prefix": server_address,
}
# New user account waiting validation, so delete this account and inform by email the user
......@@ -895,14 +865,9 @@ class UpdateSupervisorCandidateView(BaseUpdateSupervisorCandidateView):
supervisee.is_active = True
supervisee.save()
parsed_url = urlparse(settings.URL_PREFIX)
server_address = "%s://%s" % (parsed_url.scheme, parsed_url.hostname)
# Inform by email the new supervisor
context = {
"supervisor": request.user,
"supervisee": supervisee,
"prefix": server_address,
}
mail.send_email(
......
......@@ -412,3 +412,32 @@ def load_temporary_url_rejection(request, hash_url):
return generate_load_response(
request, temp_url, "accounts/url_rejection_failed.html", {}
)
def inform_supervisor_new_supervisee_request(
request, supervisiontrack, supervisor, supervisee
):
# Inform by email the supervisor that he has a new supervisee request
temp_url = TemporaryUrl.objects.create_temporary_url(
TemporaryUrl.VALIDATION, supervisiontrack
)
supervisor_validation_url = request.build_absolute_uri(
reverse("accounts:temp_url_validation", kwargs={"hash_url": temp_url.url_hash},)
)
contact_url = request.build_absolute_uri(reverse("contact"))
context = {
"supervisor": supervisor,
"supervisee": supervisee,
"supervisor_validation_url": supervisor_validation_url,
"contact_url": contact_url,
}
mail.send_email(
"registration/mail.supervisor_validation.subject.txt",
"registration/mail.supervisor_validation_supervisee_add_request.message.txt",
context,
[supervisor.email],
)
return context
......@@ -205,7 +205,6 @@ def register(
"form_supervisor": form_supervisor,
"supervisor_form_active": supervisor_form_active,
"documentation_link": settings.DOCUMENTATION_LINK,
"url_prefix": settings.URL_PREFIX,
}
if extra_context is not None:
......
......@@ -48,7 +48,7 @@ from rest_framework.authtoken.models import Token
from .. import __version__
from ..accounts.models import Profile
from ..accounts.models import SupervisionTrack
from ..accounts.models import TemporaryUrl
from ..accounts.views import inform_supervisor_new_supervisee_request
from ..common.models import Shareable
from ..utils import mail
from .registration.forms import BlockedUserRevalidationForm
......@@ -150,31 +150,8 @@ def blocked_user_reactivation(request):
supervisee.save()
# Inform by email the supervisor that he has a new supervisee request
temp_url = TemporaryUrl.objects.create_temporary_url(
TemporaryUrl.VALIDATION, supervisiontrack
)
supervisor_validation_url = request.build_absolute_uri(
reverse(
"accounts:temp_url_validation",
kwargs={"hash_url": temp_url.url_hash},
)
)
contact_url = request.build_absolute_uri(
reverse("contact")
)
context = {
"supervisor": supervisor,
"supervisee": supervisee,
"supervisor_validation_url": supervisor_validation_url,
"contact_url": contact_url,
}
mail.send_email(
"registration/mail.supervisor_validation.subject.txt",
"registration/mail.supervisor_validation_supervisee_add_request.message.txt",
context,
[supervisor.email],
context = inform_supervisor_new_supervisee_request(
request, supervisiontrack, supervisor, supervisee
)
# inform the supervisee of his request
......
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