feat: mentor mgmt
This commit is contained in:
parent
b75737468c
commit
27ab8caf24
|
|
@ -82,7 +82,7 @@ class LearningMentorInvitationTest(APITestCase):
|
||||||
self.participant,
|
self.participant,
|
||||||
role=CourseSessionUser.Role.MEMBER,
|
role=CourseSessionUser.Role.MEMBER,
|
||||||
)
|
)
|
||||||
email = "test@exmaple.com"
|
email = "test@example.com"
|
||||||
|
|
||||||
MentorInvitation.objects.create(participant=participant_cs_user, email=email)
|
MentorInvitation.objects.create(participant=participant_cs_user, email=email)
|
||||||
|
|
||||||
|
|
@ -108,7 +108,7 @@ class LearningMentorInvitationTest(APITestCase):
|
||||||
self.participant,
|
self.participant,
|
||||||
role=CourseSessionUser.Role.MEMBER,
|
role=CourseSessionUser.Role.MEMBER,
|
||||||
)
|
)
|
||||||
email = "test@exmaple.com"
|
email = "test@example.com"
|
||||||
|
|
||||||
invitation = MentorInvitation.objects.create(
|
invitation = MentorInvitation.objects.create(
|
||||||
participant=participant_cs_user, email=email
|
participant=participant_cs_user, email=email
|
||||||
|
|
|
||||||
|
|
@ -158,3 +158,71 @@ class LearningMentorAPITest(APITestCase):
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
assignment["completions"][2]["last_name"], self.participant_2.user.last_name
|
assignment["completions"][2]["last_name"], self.participant_2.user.last_name
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def test_list_user_mentors(self) -> None:
|
||||||
|
# GIVEN
|
||||||
|
participant = create_user("participant")
|
||||||
|
self.client.force_login(participant)
|
||||||
|
|
||||||
|
participant_cs_user = add_course_session_user(
|
||||||
|
self.course_session,
|
||||||
|
participant,
|
||||||
|
role=CourseSessionUser.Role.MEMBER,
|
||||||
|
)
|
||||||
|
|
||||||
|
learning_mentor = LearningMentor.objects.create(
|
||||||
|
mentor=self.mentor,
|
||||||
|
course=self.course_session.course,
|
||||||
|
)
|
||||||
|
|
||||||
|
learning_mentor.participants.add(participant_cs_user)
|
||||||
|
|
||||||
|
list_url = reverse(
|
||||||
|
"list_user_mentors", kwargs={"course_session_id": self.course_session.id}
|
||||||
|
)
|
||||||
|
|
||||||
|
# WHEN
|
||||||
|
response = self.client.get(list_url)
|
||||||
|
|
||||||
|
# THEN
|
||||||
|
self.assertEqual(response.status_code, status.HTTP_200_OK)
|
||||||
|
|
||||||
|
mentor_user = response.data[0]
|
||||||
|
|
||||||
|
self.assertEqual(mentor_user["email"], self.mentor.email)
|
||||||
|
self.assertEqual(mentor_user["id"], str(self.mentor.id))
|
||||||
|
|
||||||
|
def test_remove_user_mentor(self) -> None:
|
||||||
|
# GIVEN
|
||||||
|
participant = create_user("participant")
|
||||||
|
self.client.force_login(participant)
|
||||||
|
|
||||||
|
participant_cs_user = add_course_session_user(
|
||||||
|
self.course_session,
|
||||||
|
participant,
|
||||||
|
role=CourseSessionUser.Role.MEMBER,
|
||||||
|
)
|
||||||
|
|
||||||
|
learning_mentor = LearningMentor.objects.create(
|
||||||
|
mentor=self.mentor,
|
||||||
|
course=self.course_session.course,
|
||||||
|
)
|
||||||
|
|
||||||
|
learning_mentor.participants.add(participant_cs_user)
|
||||||
|
|
||||||
|
remove_self_url = reverse(
|
||||||
|
"remove_self_from_mentor",
|
||||||
|
kwargs={
|
||||||
|
"course_session_id": self.course_session.id,
|
||||||
|
"mentor_id": learning_mentor.id,
|
||||||
|
},
|
||||||
|
)
|
||||||
|
|
||||||
|
# WHEN
|
||||||
|
response = self.client.delete(remove_self_url)
|
||||||
|
|
||||||
|
# THEN
|
||||||
|
self.assertEqual(response.status_code, status.HTTP_204_NO_CONTENT)
|
||||||
|
self.assertFalse(
|
||||||
|
LearningMentor.objects.filter(participants=participant_cs_user).exists()
|
||||||
|
)
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,12 @@ from . import views
|
||||||
|
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
path("summary", views.mentor_summary, name="mentor_summary"),
|
path("summary", views.mentor_summary, name="mentor_summary"),
|
||||||
|
path("mentors", views.list_user_mentors, name="list_user_mentors"),
|
||||||
|
path(
|
||||||
|
"mentors/<int:mentor_id>/leave",
|
||||||
|
views.remove_self_from_mentor,
|
||||||
|
name="remove_self_from_mentor",
|
||||||
|
),
|
||||||
path("invitations", views.list_invitations, name="list_invitations"),
|
path("invitations", views.list_invitations, name="list_invitations"),
|
||||||
path("invitations/create", views.create_invitation, name="create_invitation"),
|
path("invitations/create", views.create_invitation, name="create_invitation"),
|
||||||
path(
|
path(
|
||||||
|
|
|
||||||
|
|
@ -117,6 +117,39 @@ def create_invitation(request, course_session_id: int):
|
||||||
return Response(serializer.data)
|
return Response(serializer.data)
|
||||||
|
|
||||||
|
|
||||||
|
@api_view(["GET"])
|
||||||
|
@permission_classes([IsAuthenticated, CourseSessionMember])
|
||||||
|
def list_user_mentors(request, course_session_id: int):
|
||||||
|
course_session = get_object_or_404(CourseSession, id=course_session_id)
|
||||||
|
|
||||||
|
course_session_user = get_object_or_404(
|
||||||
|
CourseSessionUser, user=request.user, course_session=course_session
|
||||||
|
)
|
||||||
|
|
||||||
|
mentors = LearningMentor.objects.filter(
|
||||||
|
course=course_session.course, participants=course_session_user
|
||||||
|
)
|
||||||
|
|
||||||
|
mentor_users = [mentor.mentor for mentor in mentors]
|
||||||
|
|
||||||
|
return Response(UserSerializer(mentor_users, many=True).data)
|
||||||
|
|
||||||
|
|
||||||
|
@api_view(["DELETE"])
|
||||||
|
@permission_classes([IsAuthenticated, CourseSessionMember])
|
||||||
|
def remove_self_from_mentor(request, course_session_id: int, mentor_id: int):
|
||||||
|
course_session = get_object_or_404(CourseSession, id=course_session_id)
|
||||||
|
course_session_user = get_object_or_404(
|
||||||
|
CourseSessionUser, user=request.user, course_session=course_session
|
||||||
|
)
|
||||||
|
|
||||||
|
mentor = get_object_or_404(LearningMentor, id=mentor_id)
|
||||||
|
|
||||||
|
mentor.participants.remove(course_session_user)
|
||||||
|
|
||||||
|
return Response(status=status.HTTP_204_NO_CONTENT)
|
||||||
|
|
||||||
|
|
||||||
@api_view(["POST"])
|
@api_view(["POST"])
|
||||||
@permission_classes([IsAuthenticated])
|
@permission_classes([IsAuthenticated])
|
||||||
def accept_invitation(request, course_session_id: int):
|
def accept_invitation(request, course_session_id: int):
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue