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

[accounts/ui-registration-templates] Added endpoint to let supervisees change/add a godfather

parent c8ed258f
No related branches found
No related tags found
1 merge request!224Security accounts
Pipeline #
...@@ -135,6 +135,7 @@ class GodfatherAddSuperviseeView(BaseUpdateSupervisionTrackView): ...@@ -135,6 +135,7 @@ class GodfatherAddSuperviseeView(BaseUpdateSupervisionTrackView):
supervisiontrack.start_date = now supervisiontrack.start_date = now
supervisiontrack.last_validation_date = now supervisiontrack.last_validation_date = now
supervisee.profile.status = Profile.ACCEPTED supervisee.profile.status = Profile.ACCEPTED
supervisee.profile.rejection_date = None
supervisiontrack.save() supervisiontrack.save()
supervisee.profile.save() supervisee.profile.save()
...@@ -248,115 +249,146 @@ class GodfatherRemoveSuperviseeView(BaseUpdateSupervisionTrackView): ...@@ -248,115 +249,146 @@ class GodfatherRemoveSuperviseeView(BaseUpdateSupervisionTrackView):
return Response(status=status.HTTP_204_NO_CONTENT) return Response(status=status.HTTP_204_NO_CONTENT)
##---------------------------------------------------------- #----------------------------------------------------------
#
#
#class BaseCreateSupervisionTrackViewSupervisee(generics.CreateAPIView): class BaseCreateSupervisionTrackViewSupervisee(generics.CreateAPIView):
# model = SupervisionTrack model = SupervisionTrack
# serializer_class = SupervisionTrackUpdateSerializer serializer_class = SupervisionTrackUpdateSerializer
#
# def get_permissions(self): def get_permissions(self):
# permission_classes = [permissions.IsAuthenticated, IsAuthorAndNotGodfather] permission_classes = [permissions.IsAuthenticated, IsAuthorAndNotGodfather]
#
# self.permission_classes = permission_classes self.permission_classes = permission_classes
#
# return super(BaseCreateSupervisionTrackViewSupervisee, self).get_permissions() return super(BaseCreateSupervisionTrackViewSupervisee, self).get_permissions()
#
#
##---------------------------------------------------------- #----------------------------------------------------------
#
#
#class SuperviseeAddGodfatherView(BaseCreateSupervisionTrackViewSupervisee): class SuperviseeAddGodfatherView(BaseCreateSupervisionTrackViewSupervisee):
# permission_classes = BaseCreateSupervisionTrackViewSupervisee.permission_classes permission_classes = BaseCreateSupervisionTrackViewSupervisee.permission_classes
#
# def post(self, request, supervisor_name): def post(self, request, supervisor_name):
# godfather = User.objects.get(username=supervisor_name) godfather = User.objects.get(username=supervisor_name)
# supervisee = request.user supervisee = request.user
# print godfather if supervisee.profile.supervision_key is not None:
# print supervisee #There's a key check if there's a valid track
# supervisee.profile.supervision_key = supervisee.profile._generate_current_supervision_key() supervisiontrack = SupervisionTrack.objects.get(supervisee=supervisee, supervisee__profile__supervision_key=models.F('supervision_key'))
# #godfather = User.objects.get(username = self.cleaned_data['godfather']) if supervisiontrack.is_valid:
# supervisiontrack = SupervisionTrack.objects.create( if supervisee.profile.status != Profile.WAITINGVALIDATION and supervisee.profile.status != Profile.NEWUSER and supervisee.profile.status != Profile.BLOCKED:
# supervisee = supervisee, #Stop the current supervision
# godfather = godfather, now = datetime.datetime.now()
# is_valid = False, expiration_date_delta = datetime.timedelta(days=settings.ACCOUNT_BLOCKAGE_AFTER_FIRST_REJECTION_DAYS)
# )
#
# #Assign key to supervision track supervisiontrack.expiration_date = now
# supervisiontrack.supervision_key = supervisee.profile.supervision_key supervisiontrack.is_valid = False
# supervisiontrack.save() supervisiontrack.save()
# supervisee.profile.supervision.add(supervisiontrack)
# supervisee.save() #Inform by email the revoked supervisor
# from django.core.mail import send_mail
# #supervisiontrack = SupervisionTrack.objects.get(godfather=request.user, supervisee=supervisee, supervisee__profile__supervision_key=models.F('supervision_key'))
# parsed_url = urlparse(settings.URL_PREFIX)
# #from django.core.mail import send_mail server_address = '%s://%s' % (parsed_url.scheme, parsed_url.hostname)
#
# #parsed_url = urlparse(settings.URL_PREFIX) c = Context({ 'supervisor': supervisiontrack.godfather,
# #server_address = '%s://%s' % (parsed_url.scheme, parsed_url.hostname) 'supervisee': supervisiontrack.supervisee,
# 'prefix': server_address,
# #c = Context({ 'supervisor': supervisiontrack.godfather, })
# # 'supervisee': supervisee,
# # 'prefix': server_address, try:
# # }) t = loader.get_template('registration/mail.godfather_rejection.subject.txt')
# subject = t.render(c)
# #if supervisee.profile.status == Profile.WAITINGVALIDATION:
# # #New user account waiting validation, so delete this account and inform by email the user # Note: e-mail subject *must not* contain newlines
# # try: subject = settings.EMAIL_SUBJECT_PREFIX + ''.join(subject.splitlines())
# # t = loader.get_template('registration/mail.godfather_rejected.subject.txt')
# # subject = t.render(c) t = loader.get_template('registration/mail.godfather_rejection.message.txt')
# message = t.render(c)
# # # Note: e-mail subject *must not* contain newlines
# # subject = settings.EMAIL_SUBJECT_PREFIX + ''.join(subject.splitlines()) send_mail(subject, message, settings.DEFAULT_FROM_EMAIL, [supervisiontrack.godfather.email])
# except:
# # t = loader.get_template('registration/mail.godfather_rejected_delete_account.message.txt') pass
# # message = t.render(c)
# #Reject this account and inform by email the supervisor and the user
# # send_mail(subject, message, settings.DEFAULT_FROM_EMAIL, [supervisee.email])
# # except: supervisee.profile.status = Profile.REJECTED
# # pass supervisee.profile.supervision_key = None
# if supervisee.profile.rejection_date == None:
# # registration_profile = RegistrationProfile.objects.get(user=supervisee) supervisee.profile.rejection_date = now + expiration_date_delta
# # supervisee.profile.delete()
# # supervisee.delete() supervisee.profile.save()
# # supervisiontrack.delete() supervisee.save()
# # registration_profile.delete() else:
# #else: #Not allowed to do this (unproper profile.status)
# # #Reject this account and inform by email the user reason = "You are not able to perform this action, your profile is %s"%(supervisee.profile.status)
# # now = datetime.datetime.now() result = {
# # expiration_date_delta = datetime.timedelta(days=settings.ACCOUNT_BLOCKAGE_AFTER_FIRST_REJECTION_DAYS) 'error': reason,
# }
# return BadRequestResponse(result)
# # supervisiontrack.expiration_date = now
# # supervisiontrack.is_valid = False else:
# #A pending request already exist
# # supervisee.profile.status = Profile.REJECTED reason = "You are not able to perform this action as you already have a pending request"
# # supervisee.profile.supervision_key = None result = {
# # if supervisee.profile.rejection_date == None: 'error': reason,
# # supervisee.profile.rejection_date = now + expiration_date_delta }
# return BadRequestResponse(result)
# # supervisiontrack.save() else:
# # supervisee.profile.save() #No key is present in supervisee
# # supervisee.save()
# #Make sure all tracks are invalid
# # try: supervisiontracks = SupervisionTrack.objects.filter(supervisee=supervisee, is_valid=True)
# # t = loader.get_template('registration/mail.godfather_rejected.subject.txt') # This should never be the case but if it happens invalidate all tracks
# # subject = t.render(c) if supervisiontracks.count() > 0:
# now = datetime.datetime.now()
# # # Note: e-mail subject *must not* contain newlines for track in supervisiontracks:
# # subject = settings.EMAIL_SUBJECT_PREFIX + ''.join(subject.splitlines()) track.is_valid = False
# track.expiration_date = now
# # t = loader.get_template('registration/mail.godfather_rejected.message.txt') track.save()
# # message = t.render(c)
# #Create and assign key
# # send_mail(subject, message, settings.DEFAULT_FROM_EMAIL, [supervisee.email]) supervisee.profile.supervision_key = supervisee.profile._generate_current_supervision_key()
# # except: supervisiontrack = SupervisionTrack.objects.create(
# # pass supervisee = supervisee,
# godfather = godfather,
# # #if supervisiontrack.start_date is None: is_valid = False,
# # # supervisiontrack.delete() )
#
# return Response(status=status.HTTP_204_NO_CONTENT) #Assign key to supervision track
# supervisiontrack.supervision_key = supervisee.profile.supervision_key
# supervisiontrack.save()
##---------------------------------------------------------- supervisee.profile.supervision.add(supervisiontrack)
supervisee.save()
#Inform by email the supervisor that he has a new supervisee request
from django.core.mail import send_mail
parsed_url = urlparse(settings.URL_PREFIX)
server_address = '%s://%s' % (parsed_url.scheme, parsed_url.hostname)
c = Context({ 'supervisor': godfather,
'supervisee': supervisee,
'prefix': server_address,
})
try:
t = loader.get_template('registration/mail.godfather_validation.subject.txt')
subject = t.render(c)
# Note: e-mail subject *must not* contain newlines
subject = settings.EMAIL_SUBJECT_PREFIX + ''.join(subject.splitlines())
t = loader.get_template('registration/mail.godfather_validation_supervisee_add_request.message.txt')
message = t.render(c)
send_mail(subject, message, settings.DEFAULT_FROM_EMAIL, [godfather.email])
except:
pass
return Response(status=status.HTTP_204_NO_CONTENT)
#----------------------------------------------------------
...@@ -39,3 +39,16 @@ class IsGodfatherAndAuthor(permissions.BasePermission): ...@@ -39,3 +39,16 @@ class IsGodfatherAndAuthor(permissions.BasePermission):
def has_permission(self, request, view): def has_permission(self, request, view):
return request.user.profile.is_godfather return request.user.profile.is_godfather
#----------------------------------------------------------
class IsAuthorAndNotGodfather(permissions.BasePermission):
"""
The logged in user should also be the author
"""
message = 'Not a supervisee account'
def has_permission(self, request, view):
return not request.user.profile.is_godfather
Dear {{ supervisor.first_name }},
One of your supervisee has made a request to end your current supervision and request for a new one towards another supervisor related to his current situation.
First Name: {{ supervisee.first_name }}
Last Name: {{ supervisee.last_name }}
Email: {{ supervisee.email }}
Username: {{ supervisee.username }}
This message is to inform you that you will not be responsible towards this supervisee in the current future.
BEAT Administrators at the Idiap Research Institute
Account validation - Revoked Supervision
Dear {{ supervisor.first_name }},
Thank you in advance for validating the request of one your supervisee at the Idiap Research Institute's Biometric
Evaluation and Testing (BEAT) platform. Before we can activate this
supervision requesti, you must login to your account and under supervision tab validate the following supervisee:
First Name: {{ supervisee.first_name }}
Last Name: {{ supervisee.last_name }}
Email: {{ supervisee.email }}
Username: {{ supervisee.username }}
If you don't do this the supervisee will not be able to use his account in
future and will not be recognized as your supervisee.
If you are having problems to activate your supervisee account, contact a member of our
support staff at {{ prefix }}{% url 'contact' %}.
BEAT Administrators at the Idiap Research Institute
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