def delete(self, course_uuid, assignment_uuid, answer_uuid, answer_comment_uuid): """ Delete an answer comment """ course = Course.get_active_by_uuid_or_404(course_uuid) assignment = Assignment.get_active_by_uuid_or_404(assignment_uuid) answer_comment = AnswerComment.get_active_by_uuid_or_404( answer_comment_uuid) require( DELETE, answer_comment, title="Reply Not Deleted", message= "Sorry, your role in this course does not allow you to delete replies for this answer." ) data = marshal(answer_comment, dataformat.get_answer_comment(False)) answer_comment.active = False db.session.commit() # update course & assignment grade for user if self-evaluation is completed if not answer_comment.draft and answer_comment.comment_type == AnswerCommentType.self_evaluation: assignment.calculate_grade(answer_comment.user) course.calculate_grade(answer_comment.user) on_answer_comment_delete.send(self, event_name=on_answer_comment_delete.name, user=current_user, course_id=course.id, answer_comment=answer_comment, data=data) return {'id': answer_comment.uuid}
def get(self, course_uuid, assignment_uuid, answer_uuid, answer_comment_uuid): """ Get an answer comment """ course = Course.get_active_by_uuid_or_404(course_uuid) assignment = Assignment.get_active_by_uuid_or_404(assignment_uuid) answer = Answer.get_active_by_uuid_or_404(answer_uuid) answer_comment = AnswerComment.get_active_by_uuid_or_404( answer_comment_uuid) require( READ, answer_comment, title="Reply Unavailable", message= "Sorry, your role in this course does not allow you to view this reply." ) on_answer_comment_get.send(self, event_name=on_answer_comment_get.name, user=current_user, course_id=course.id, data={ 'assignment_id': assignment.id, 'answer_id': answer.id, 'answer_comment_id': answer_comment.id }) return marshal(answer_comment, dataformat.get_answer_comment())
def delete(self, course_uuid, assignment_uuid, answer_uuid, answer_comment_uuid): """ Delete an answer comment """ course = Course.get_active_by_uuid_or_404(course_uuid) assignment = Assignment.get_active_by_uuid_or_404(assignment_uuid) answer_comment = AnswerComment.get_active_by_uuid_or_404(answer_comment_uuid) require(DELETE, answer_comment, title="Feedback Not Deleted", message="Sorry, your role in this course does not allow you to delete feedback for this answer.") data = marshal(answer_comment, dataformat.get_answer_comment(False)) answer_comment.active = False db.session.commit() # update course & assignment grade for user if self-evaluation is completed if not answer_comment.draft and answer_comment.comment_type == AnswerCommentType.self_evaluation: assignment.calculate_grade(answer_comment.user) course.calculate_grade(answer_comment.user) on_answer_comment_delete.send( self, event_name=on_answer_comment_delete.name, user=current_user, course_id=course.id, answer_comment=answer_comment, data=data) return {'id': answer_comment.uuid}
def delete(self, course_uuid, assignment_uuid, answer_uuid, answer_comment_uuid): """ Delete an answer comment """ course = Course.get_active_by_uuid_or_404(course_uuid) assignment = Assignment.get_active_by_uuid_or_404(assignment_uuid) answer_comment = AnswerComment.get_active_by_uuid_or_404(answer_comment_uuid) require(DELETE, answer_comment) data = marshal(answer_comment, dataformat.get_answer_comment(False)) answer_comment.active = False db.session.commit() # update course & assignment grade for user if self-evaluation is completed if not answer_comment.draft and answer_comment.comment_type == AnswerCommentType.self_evaluation: assignment.calculate_grade(answer_comment.user) course.calculate_grade(answer_comment.user) on_answer_comment_delete.send( self, event_name=on_answer_comment_delete.name, user=current_user, course_id=course.id, answer_comment=answer_comment, data=data, ) return {"id": answer_comment.uuid}
def post(self, course_uuid, assignment_uuid, answer_uuid): """ Create comment for an answer """ course = Course.get_active_by_uuid_or_404(course_uuid) assignment = Assignment.get_active_by_uuid_or_404(assignment_uuid) answer = Answer.get_active_by_uuid_or_404(answer_uuid) require(CREATE, AnswerComment(course_id=course.id)) answer_comment = AnswerComment(answer_id=answer.id) params = new_answer_comment_parser.parse_args() answer_comment.draft = params.get("draft") answer_comment.content = params.get("content") # require content not empty if not a draft if not answer_comment.content and not answer_comment.draft: return {"error": "The comment content is empty!"}, 400 if params.get("user_id") and current_user.system_role == SystemRole.sys_admin: user = User.get_by_uuid_or_404(params.get("user_id")) answer_comment.user_id = user.id else: answer_comment.user_id = current_user.id comment_types = [ AnswerCommentType.public.value, AnswerCommentType.private.value, AnswerCommentType.evaluation.value, AnswerCommentType.self_evaluation.value, ] comment_type = params.get("comment_type") if comment_type not in comment_types: abort(400) answer_comment.comment_type = AnswerCommentType(comment_type) db.session.add(answer_comment) db.session.commit() # update course & assignment grade for user if self-evaluation is completed if not answer_comment.draft and answer_comment.comment_type == AnswerCommentType.self_evaluation: assignment.calculate_grade(answer_comment.user) course.calculate_grade(answer_comment.user) on_answer_comment_create.send( self, event_name=on_answer_comment_create.name, user=current_user, course_id=course.id, answer_comment=answer_comment, data=marshal(answer_comment, dataformat.get_answer_comment(False)), ) return marshal(answer_comment, dataformat.get_answer_comment())
def get(self, course_uuid, assignment_uuid, answer_uuid, answer_comment_uuid): """ Get an answer comment """ course = Course.get_active_by_uuid_or_404(course_uuid) assignment = Assignment.get_active_by_uuid_or_404(assignment_uuid) answer = Answer.get_active_by_uuid_or_404(answer_uuid) answer_comment = AnswerComment.get_active_by_uuid_or_404(answer_comment_uuid) require(READ, answer_comment) on_answer_comment_get.send( self, event_name=on_answer_comment_get.name, user=current_user, course_id=course.id, data={"assignment_id": assignment.id, "answer_id": answer.id, "answer_comment_id": answer_comment.id}, ) return marshal(answer_comment, dataformat.get_answer_comment())
def get(self, course_uuid, assignment_uuid, answer_uuid, answer_comment_uuid): """ Get an answer comment """ course = Course.get_active_by_uuid_or_404(course_uuid) assignment = Assignment.get_active_by_uuid_or_404(assignment_uuid) answer = Answer.get_active_by_uuid_or_404(answer_uuid) answer_comment = AnswerComment.get_active_by_uuid_or_404(answer_comment_uuid) require(READ, answer_comment, title="Feedback Unavailable", message="Sorry, your role in this course does not allow you to view this feedback.") restrict_user = not allow(MANAGE, assignment) restrict_user = not allow(MANAGE, assignment) on_answer_comment_get.send( self, event_name=on_answer_comment_get.name, user=current_user, course_id=course.id, data={'assignment_id': assignment.id, 'answer_id': answer.id, 'answer_comment_id': answer_comment.id}) return marshal(answer_comment, dataformat.get_answer_comment(restrict_user))
def post(self, course_uuid, assignment_uuid, answer_uuid, answer_comment_uuid): """ Update an answer comment """ course = Course.get_active_by_uuid_or_404(course_uuid) assignment = Assignment.get_active_by_uuid_or_404(assignment_uuid) answer = Answer.get_active_by_uuid_or_404(answer_uuid) answer_comment = AnswerComment.get_active_by_uuid_or_404( answer_comment_uuid) require( EDIT, answer_comment, title="Reply Not Saved", message= "Sorry, your role in this course does not allow you to save replies for this answer." ) was_draft = answer_comment.draft params = existing_answer_comment_parser.parse_args() # make sure the answer comment id in the url and the id matches if params['id'] != answer_comment_uuid: abort( 400, title="Reply Not Saved", message= "The reply's ID does not match the URL, which is required in order to save the reply." ) # modify answer comment according to new values, preserve original values if values not passed answer_comment.content = params.get("content") comment_types = [ AnswerCommentType.public.value, AnswerCommentType.private.value, AnswerCommentType.evaluation.value, AnswerCommentType.self_evaluation.value ] comment_type = params.get("comment_type", AnswerCommentType.private.value) if comment_type not in comment_types: abort( 400, title="Reply Not Saved", message= "This reply type is not recognized. Please contact support for assistance." ) answer_comment.comment_type = AnswerCommentType(comment_type) # only update draft param if currently a draft if answer_comment.draft: answer_comment.draft = params.get('draft', answer_comment.draft) # require content not empty if not a draft if not answer_comment.content and not answer_comment.draft: abort( 400, title="Reply Not Saved", message= "Please provide content in the text editor to reply and try saving again." ) db.session.add(answer_comment) db.session.commit() on_answer_comment_modified.send( self, event_name=on_answer_comment_modified.name, user=current_user, course_id=course.id, answer_comment=answer_comment, was_draft=was_draft, data=get_model_changes(answer_comment)) # update course & assignment grade for user if self-evaluation is completed if not answer_comment.draft and answer_comment.comment_type == AnswerCommentType.self_evaluation: assignment.calculate_grade(answer_comment.user) course.calculate_grade(answer_comment.user) return marshal(answer_comment, dataformat.get_answer_comment())
def post(self, course_uuid, assignment_uuid, answer_uuid): """ Create comment for an answer """ course = Course.get_active_by_uuid_or_404(course_uuid) assignment = Assignment.get_active_by_uuid_or_404(assignment_uuid) answer = Answer.get_active_by_uuid_or_404(answer_uuid) require( CREATE, AnswerComment(course_id=course.id), title="Reply Not Saved", message= "Sorry, your role in this course does not allow you to save replies for this answer." ) answer_comment = AnswerComment(answer_id=answer.id) params = new_answer_comment_parser.parse_args() answer_comment.draft = params.get('draft') answer_comment.content = params.get("content") # require content not empty if not a draft if not answer_comment.content and not answer_comment.draft: abort( 400, title="Reply Not Saved", message= "Please provide content in the text editor to reply and try saving again." ) if params.get('user_id' ) and current_user.system_role == SystemRole.sys_admin: user = User.get_by_uuid_or_404(params.get('user_id')) answer_comment.user_id = user.id else: answer_comment.user_id = current_user.id comment_types = [ AnswerCommentType.public.value, AnswerCommentType.private.value, AnswerCommentType.evaluation.value, AnswerCommentType.self_evaluation.value ] comment_type = params.get("comment_type") if comment_type not in comment_types: abort( 400, title="Reply Not Saved", message= "This reply type is not recognized. Please contact support for assistance." ) answer_comment.comment_type = AnswerCommentType(comment_type) db.session.add(answer_comment) db.session.commit() # update course & assignment grade for user if self-evaluation is completed if not answer_comment.draft and answer_comment.comment_type == AnswerCommentType.self_evaluation: assignment.calculate_grade(answer_comment.user) course.calculate_grade(answer_comment.user) on_answer_comment_create.send( self, event_name=on_answer_comment_create.name, user=current_user, course_id=course.id, answer_comment=answer_comment, data=marshal(answer_comment, dataformat.get_answer_comment(False))) return marshal(answer_comment, dataformat.get_answer_comment())
def post(self, course_uuid, assignment_uuid, answer_uuid, answer_comment_uuid): """ Update an answer comment """ course = Course.get_active_by_uuid_or_404(course_uuid) assignment = Assignment.get_active_by_uuid_or_404(assignment_uuid) answer = Answer.get_active_by_uuid_or_404(answer_uuid) answer_comment = AnswerComment.get_active_by_uuid_or_404(answer_comment_uuid) require(EDIT, answer_comment, title="Feedback Not Saved", message="Sorry, your role in this course does not allow you to save feedback for this answer.") restrict_user = not allow(MANAGE, assignment) restrict_user = not allow(MANAGE, assignment) was_draft = answer_comment.draft params = existing_answer_comment_parser.parse_args() # make sure the answer comment id in the url and the id matches if params['id'] != answer_comment_uuid: abort(400, title="Feedback Not Saved", message="The feedback's ID does not match the URL, which is required in order to save the feedback.") # modify answer comment according to new values, preserve original values if values not passed answer_comment.content = params.get("content") comment_types = [ AnswerCommentType.public.value, AnswerCommentType.private.value, AnswerCommentType.evaluation.value, AnswerCommentType.self_evaluation.value ] eval_comment_types = [ AnswerCommentType.evaluation.value, AnswerCommentType.self_evaluation.value ] comment_type = params.get("comment_type", AnswerCommentType.private.value) if comment_type not in comment_types: abort(400, title="Feedback Not Saved", message="This feedback type is not recognized. Please contact support for assistance.") # do not allow changing a self-eval into a comment or vise-versa if (answer_comment.comment_type.value in eval_comment_types or comment_type in eval_comment_types) and answer_comment.comment_type.value != comment_type: abort(400, title="Feedback Not Saved", message="Feedback type cannot be changed. Please contact support for assistance.") answer_comment.comment_type = AnswerCommentType(comment_type) if answer_comment.comment_type == AnswerCommentType.self_evaluation and not assignment.self_eval_grace and not allow(MANAGE, assignment): abort(403, title="Self-Evaluation Not Saved", message="Sorry, the self-evaluation deadline has passed and therefore cannot be submitted.") # only update draft param if currently a draft if answer_comment.draft: answer_comment.draft = params.get('draft', answer_comment.draft) # require content not empty if not a draft if not answer_comment.content and not answer_comment.draft: abort(400, title="Feedback Not Saved", message="Please provide content in the text editor and try saving again.") answer_comment.update_attempt( params.get('attempt_uuid'), params.get('attempt_started', None), params.get('attempt_ended', None) ) model_changes = get_model_changes(answer_comment) db.session.add(answer_comment) db.session.commit() on_answer_comment_modified.send( self, event_name=on_answer_comment_modified.name, user=current_user, course_id=course.id, answer_comment=answer_comment, evaluation_number=params.get("evaluation_number"), was_draft=was_draft, data=model_changes) # update course & assignment grade for user if self-evaluation is completed if not answer_comment.draft and answer_comment.comment_type == AnswerCommentType.self_evaluation: assignment.calculate_grade(answer_comment.user) course.calculate_grade(answer_comment.user) return marshal(answer_comment, dataformat.get_answer_comment(restrict_user))
def post(self, course_uuid, assignment_uuid, answer_uuid): """ Create comment for an answer """ course = Course.get_active_by_uuid_or_404(course_uuid) assignment = Assignment.get_active_by_uuid_or_404(assignment_uuid) answer = Answer.get_active_by_uuid_or_404(answer_uuid) require(CREATE, AnswerComment(course_id=course.id), title="Feedback Not Saved", message="Sorry, your role in this course does not allow you to save feedback for this answer.") restrict_user = not allow(MANAGE, assignment) restrict_user = not allow(MANAGE, assignment) answer_comment = AnswerComment(answer_id=answer.id) params = new_answer_comment_parser.parse_args() answer_comment.draft = params.get('draft') answer_comment.content = params.get("content") # require content not empty if not a draft if not answer_comment.content and not answer_comment.draft: abort(400, title="Feedback Not Saved", message="Please provide content in the text editor and try saving again.") if params.get('user_id') and current_user.system_role == SystemRole.sys_admin: user = User.get_by_uuid_or_404(params.get('user_id')) answer_comment.user_id = user.id else: answer_comment.user_id = current_user.id comment_types = [ AnswerCommentType.public.value, AnswerCommentType.private.value, AnswerCommentType.evaluation.value, AnswerCommentType.self_evaluation.value ] comment_type = params.get("comment_type") if comment_type not in comment_types: abort(400, title="Feedback Not Saved", message="This feedback type is not recognized. Please contact support for assistance.") answer_comment.comment_type = AnswerCommentType(comment_type) if answer_comment.comment_type == AnswerCommentType.self_evaluation and not assignment.self_eval_grace and not allow(MANAGE, assignment): abort(403, title="Self-Evaluation Not Saved", message="Sorry, the self-evaluation deadline has passed and therefore cannot be submitted.") answer_comment.update_attempt( params.get('attempt_uuid'), params.get('attempt_started', None), params.get('attempt_ended', None) ) db.session.add(answer_comment) db.session.commit() # update course & assignment grade for user if self-evaluation is completed if not answer_comment.draft and answer_comment.comment_type == AnswerCommentType.self_evaluation: assignment.calculate_grade(answer_comment.user) course.calculate_grade(answer_comment.user) on_answer_comment_create.send( self, event_name=on_answer_comment_create.name, user=current_user, course_id=course.id, answer_comment=answer_comment, evaluation_number=params.get("evaluation_number"), data=marshal(answer_comment, dataformat.get_answer_comment(restrict_user))) return marshal(answer_comment, dataformat.get_answer_comment(restrict_user))
def post(self, course_uuid, assignment_uuid, answer_uuid, answer_comment_uuid): """ Create an answer comment """ course = Course.get_active_by_uuid_or_404(course_uuid) assignment = Assignment.get_active_by_uuid_or_404(assignment_uuid) answer = Answer.get_active_by_uuid_or_404(answer_uuid) answer_comment = AnswerComment.get_active_by_uuid_or_404(answer_comment_uuid) require(EDIT, answer_comment) params = existing_answer_comment_parser.parse_args() # make sure the answer comment id in the url and the id matches if params["id"] != answer_comment_uuid: return {"error": "Comment id does not match URL."}, 400 # modify answer comment according to new values, preserve original values if values not passed answer_comment.content = params.get("content") comment_types = [ AnswerCommentType.public.value, AnswerCommentType.private.value, AnswerCommentType.evaluation.value, AnswerCommentType.self_evaluation.value, ] comment_type = params.get("comment_type", AnswerCommentType.private.value) if comment_type not in comment_types: abort(400) answer_comment.comment_type = AnswerCommentType(comment_type) # only update draft param if currently a draft if answer_comment.draft: answer_comment.draft = params.get("draft", answer_comment.draft) # require content not empty if not a draft if not answer_comment.content and not answer_comment.draft: return {"error": "The comment content is empty!"}, 400 db.session.add(answer_comment) if answer_comment.comment_type == AnswerCommentType.evaluation: on_answer_comment_modified.send( self, event_name=on_answer_comment_modified.name, user=current_user, course_id=course.id, answer_comment=answer_comment, data=get_model_changes(answer_comment), ) else: on_answer_comment_modified.send( self, event_name=on_answer_comment_modified.name, user=current_user, course_id=course.id, answer_comment=answer_comment, data=get_model_changes(answer_comment), ) db.session.commit() # update course & assignment grade for user if self-evaluation is completed if not answer_comment.draft and answer_comment.comment_type == AnswerCommentType.self_evaluation: assignment.calculate_grade(answer_comment.user) course.calculate_grade(answer_comment.user) return marshal(answer_comment, dataformat.get_answer_comment())