def post(self, request, challenge: Challenge, submission: Submission, submission_comment: SubmissionComment, *args, **kwargs): if challenge.id != submission.challenge_id: return Response( status=400, data={ 'error': f'Submission {submission.id} does not belong to Challenge {challenge.id}' }) if submission_comment.submission_id != submission.id: return Response( status=400, data={ 'error': f'Comment {submission_comment.id} does not belong to Submission {submission.id}' }) # validate that the current User is either the author or has solved it perfectly if submission.author_id != request.user.id and not challenge.is_solved_by_user( request.user): # User has not fully solved this and as such does not have access to the solution return Response( data={'error': 'You have not fully solved the challenge'}, status=401) ser = SubmissionCommentSerializer(data=request.data) if not ser.is_valid(): return Response(data={'error': ser.errors}, status=400) submission_comment.add_reply(author=request.user, content=request.data['content'], to_notify=True) return Response(status=201)
def post(self, request, challenge: Challenge, submission: Submission, *args, **kwargs): ser = SubmissionCommentSerializer(data=request.data) if not ser.is_valid(): return Response(status=400, data={'error': 'Invalid comment content!'}) if submission.challenge_id != challenge.id: return Response( status=400, data={ 'error': f'Submission with ID {submission.id} does not belong to Challenge with ID {challenge.id}' }) # validate that the current User is either the author or has solved it perfectly if submission.author_id != request.user.id and not challenge.is_solved_by_user( request.user): # User has not fully solved this and as such does not have access to the solution return Response( data={'error': 'You have not fully solved the challenge'}, status=401) self.add_comment(submission=submission, author=request.user, content=request.data['content']) return Response(status=201)