@ -249,6 +249,16 @@ class Contributors(ModelViewSet):
@@ -249,6 +249,16 @@ class Contributors(ModelViewSet):
return Response ( serializer . data )
def delete ( self , request , * args , * * kwargs ) :
""" Delete an existing researche from a study. This can only be done by either an admin or owner of the study
Raises :
PermissionDenied : Only admin or owner can delete a researcher from a study
ValidationError : You cannot remove the owner of a study
ValidationError : You should have at least 1 admin researcher
Returns :
HTTP 204 : Action OK , no content
"""
# Check if combination of study and contributor does exists and the logged in user is part of the study
contributor = get_object_or_404 ( StudyRole , pk = kwargs [ ' contributor_id ' ] , study = kwargs [ ' study_id ' ] , study__contributors__in = [ self . request . user . researcher ] )
@ -275,6 +285,14 @@ class Contributors(ModelViewSet):
@@ -275,6 +285,14 @@ class Contributors(ModelViewSet):
@swagger_auto_schema ( methods = [ ' post ' ] , request_body = InviteSerializer ( many = False ) )
@api_view ( [ ' POST ' ] )
def process_study_invite ( request , * args , * * kwargs ) :
""" Sent an invitation to a new or existing researcher. The researcher is looked up based on email address.
Raises :
PermissionDenied : Only an admin or owner can invite a new researcher
Returns :
JSON message : Message if ok
"""
# TODO: How is allowed to make an invitation? Owner or any Admin? For now, an owner and any admin can send invitations
# Check if we are a contributor of the project and does project exists
@ -292,9 +310,17 @@ def process_study_invite(request, *args, **kwargs):
@@ -292,9 +310,17 @@ def process_study_invite(request, *args, **kwargs):
return Response ( { ' message ' : _ ( ' Invitation to %(researcher_name)s for study %(study_name)s is sent. ' ) % { ' researcher_name ' : contributor . researcher . display_name , ' study_name ' : study . name } } )
@swagger_auto_schema ( method = ' get ' , auto_schema = None )
@swagger_auto_schema ( method = ' get ' , request_body = None )
@api_view ( [ ' GET ' ] )
def validate_study_invite ( request , * args , * * kwargs ) :
""" This will validate an invitation for a researcher for a single study. The JWT token is valid for 3 days.
Raises :
ValidationError : When the JWT token has expired or incorrect content
Returns :
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 )