Browse Source

Fix study invitations

master
Joshua Rubingh 6 months ago
parent
commit
5349504cc4
  1. 2
      VRE/VRE/settings.py
  2. 5
      VRE/apps/study/models.py
  3. 2
      VRE/apps/study/views.py

2
VRE/VRE/settings.py

@ -268,7 +268,7 @@ if DEBUG: @@ -268,7 +268,7 @@ if DEBUG:
# Study settings
# Duration of the JWT invite link in seconds. Default is 3 days
STUDY_INVITATION_LINK_EXPIRE_DURATION = config('STUDY_INVITATION_LINK_EXPIRE_DURATION', default=3 * 24 * 60 * 60, cast=int)
STUDY_INVITATION_LINK_DOMAIN = config('STUDY_INVITATION_LINK_DOMAIN', default='http://localhost:8000')
STUDY_INVITATION_LINK_DOMAIN = config('STUDY_INVITATION_LINK_DOMAIN', default='http://localhost:3000/researchStudies/{study_id}/contributors/join?key={jwt_token}')
# Dropoff settings.
# Enter the full path to the Webbased file uploading without the Study ID part. The Study ID will be added to this url based on the visitor.

5
VRE/apps/study/models.py

@ -172,7 +172,7 @@ class StudyRole(MetaDataModel): @@ -172,7 +172,7 @@ class StudyRole(MetaDataModel):
}
jwt_token = jwt.encode(payload=jwt_data, key=settings.SECRET_KEY, algorithm="HS256")
url = f'{settings.STUDY_INVITATION_LINK_DOMAIN}' + reverse('api:v1:study-invite-join', kwargs={'study_id': self.study.pk, 'jwt_token': jwt_token})
url = settings.STUDY_INVITATION_LINK_DOMAIN.format(study_id=self.study.pk, jwt_token=jwt_token)
template_variables = {
'researcher': self.researcher.display_name,
@ -218,7 +218,8 @@ class StudyRole(MetaDataModel): @@ -218,7 +218,8 @@ class StudyRole(MetaDataModel):
jwt_data = None
try:
jwt_data = jwt.decode(jwt_token, settings.SECRET_KEY, algorithms=["HS256"])
except jwt.DecodeError:
raise ValidationError(_('Invitation token is not a valid JSON token'))
except jwt.ExpiredSignatureError:
raise ValidationError(_('Invitation token is expired. Please ask for a new invitation'))

2
VRE/apps/study/views.py

@ -324,7 +324,7 @@ def validate_study_invite(request, *args, **kwargs): @@ -324,7 +324,7 @@ def validate_study_invite(request, *args, **kwargs):
JSON message: Message if ok
"""
# Check if we are a contributor of the project and does project exists. And make sure the user is not yet activated
study = get_object_or_404(Study, pk=kwargs['pk'], contributors__in=[request.user.researcher], studyrole__active=False)
study = get_object_or_404(Study, pk=kwargs['study_id'], contributors__in=[request.user.researcher], studyrole__active=False)
# Check if we are invited for this study
invitation = get_object_or_404(StudyRole, study=study, researcher=request.user.researcher, active=False)

Loading…
Cancel
Save