fix: don't crash dashboard as mentor
This commit is contained in:
parent
6479683ad8
commit
368ef7d16e
|
|
@ -40,6 +40,7 @@ from vbv_lernwelt.course_session.models import (
|
||||||
)
|
)
|
||||||
from vbv_lernwelt.course_session_group.models import CourseSessionGroup
|
from vbv_lernwelt.course_session_group.models import CourseSessionGroup
|
||||||
from vbv_lernwelt.duedate.models import DueDate
|
from vbv_lernwelt.duedate.models import DueDate
|
||||||
|
from vbv_lernwelt.learning_mentor.models import LearningMentor
|
||||||
from vbv_lernwelt.learnpath.models import (
|
from vbv_lernwelt.learnpath.models import (
|
||||||
Circle,
|
Circle,
|
||||||
LearningContentAssignment,
|
LearningContentAssignment,
|
||||||
|
|
@ -94,6 +95,14 @@ def create_course_session(
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def add_learning_mentor(
|
||||||
|
course: Course, mentor: User, mentee: CourseSessionUser
|
||||||
|
) -> LearningMentor:
|
||||||
|
learning_mentor = LearningMentor.objects.create(course=course, mentor=mentor)
|
||||||
|
learning_mentor.participants.add(mentee)
|
||||||
|
return learning_mentor
|
||||||
|
|
||||||
|
|
||||||
def add_course_session_user(
|
def add_course_session_user(
|
||||||
course_session: CourseSession, user: User, role: CourseSessionUser.Role
|
course_session: CourseSession, user: User, role: CourseSessionUser.Role
|
||||||
) -> CourseSessionUser:
|
) -> CourseSessionUser:
|
||||||
|
|
|
||||||
|
|
@ -23,6 +23,7 @@ from vbv_lernwelt.iam.permissions import (
|
||||||
can_view_course_session_group_statistics,
|
can_view_course_session_group_statistics,
|
||||||
can_view_course_session_progress,
|
can_view_course_session_progress,
|
||||||
)
|
)
|
||||||
|
from vbv_lernwelt.learning_mentor.models import LearningMentor
|
||||||
|
|
||||||
|
|
||||||
class DashboardQuery(graphene.ObjectType):
|
class DashboardQuery(graphene.ObjectType):
|
||||||
|
|
@ -86,7 +87,13 @@ class DashboardQuery(graphene.ObjectType):
|
||||||
user=user, exclude_course_ids=statistics_dashboard_course_ids
|
user=user, exclude_course_ids=statistics_dashboard_course_ids
|
||||||
)
|
)
|
||||||
|
|
||||||
return statistic_dashboards + course_session_dashboards
|
learning_mentor_dashboards = get_learning_mentor_dashboards(user=user)
|
||||||
|
|
||||||
|
return (
|
||||||
|
statistic_dashboards
|
||||||
|
+ course_session_dashboards
|
||||||
|
+ learning_mentor_dashboards
|
||||||
|
)
|
||||||
|
|
||||||
def resolve_course_progress(root, info, course_id: str): # noqa
|
def resolve_course_progress(root, info, course_id: str): # noqa
|
||||||
"""
|
"""
|
||||||
|
|
@ -174,6 +181,24 @@ def get_user_statistics_dashboards(user: User) -> Tuple[List[Dict[str, str]], Se
|
||||||
return dashboards, course_index
|
return dashboards, course_index
|
||||||
|
|
||||||
|
|
||||||
|
def get_learning_mentor_dashboards(user: User) -> List[Dict[str, str]]:
|
||||||
|
learning_mentor = LearningMentor.objects.filter(mentor=user)
|
||||||
|
dashboards = []
|
||||||
|
|
||||||
|
for mentor in learning_mentor:
|
||||||
|
course = mentor.course
|
||||||
|
dashboards.append(
|
||||||
|
{
|
||||||
|
"id": str(course.id),
|
||||||
|
"name": course.title,
|
||||||
|
"slug": course.slug,
|
||||||
|
"dashboard_type": DashboardType.SIMPLE_DASHBOARD,
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
return dashboards
|
||||||
|
|
||||||
|
|
||||||
def get_user_course_session_dashboards(
|
def get_user_course_session_dashboards(
|
||||||
user: User, exclude_course_ids: Set[int]
|
user: User, exclude_course_ids: Set[int]
|
||||||
) -> List[Dict[str, str]]:
|
) -> List[Dict[str, str]]:
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,7 @@ from vbv_lernwelt.assignment.models import AssignmentType
|
||||||
from vbv_lernwelt.course.creators.test_utils import (
|
from vbv_lernwelt.course.creators.test_utils import (
|
||||||
add_course_session_group_supervisor,
|
add_course_session_group_supervisor,
|
||||||
add_course_session_user,
|
add_course_session_user,
|
||||||
|
add_learning_mentor,
|
||||||
create_assignment,
|
create_assignment,
|
||||||
create_assignment_completion,
|
create_assignment_completion,
|
||||||
create_circle,
|
create_circle,
|
||||||
|
|
@ -213,6 +214,44 @@ class DashboardTestCase(GraphQLTestCase):
|
||||||
self.assertEqual(course_3_config["slug"], course_3.slug)
|
self.assertEqual(course_3_config["slug"], course_3.slug)
|
||||||
self.assertEqual(course_3_config["dashboard_type"], "SIMPLE_DASHBOARD")
|
self.assertEqual(course_3_config["dashboard_type"], "SIMPLE_DASHBOARD")
|
||||||
|
|
||||||
|
def test_dashboard_config_mentor(self):
|
||||||
|
# GIVEN
|
||||||
|
course_1, _ = create_course("Test Course 1")
|
||||||
|
cs_1 = create_course_session(course=course_1, title="Test Course 1 Session")
|
||||||
|
|
||||||
|
mentor = create_user("learning mentor")
|
||||||
|
csu = add_course_session_user(
|
||||||
|
course_session=cs_1,
|
||||||
|
user=create_user("csu"),
|
||||||
|
role=CourseSessionUser.Role.MEMBER,
|
||||||
|
)
|
||||||
|
|
||||||
|
add_learning_mentor(course=course_1, mentor=mentor, mentee=csu)
|
||||||
|
|
||||||
|
self.client.force_login(mentor)
|
||||||
|
|
||||||
|
# WHEN
|
||||||
|
query = """query {
|
||||||
|
dashboard_config {
|
||||||
|
id
|
||||||
|
name
|
||||||
|
slug
|
||||||
|
dashboard_type
|
||||||
|
}
|
||||||
|
}
|
||||||
|
"""
|
||||||
|
|
||||||
|
response = self.query(query)
|
||||||
|
|
||||||
|
# THEN
|
||||||
|
self.assertResponseNoErrors(response)
|
||||||
|
|
||||||
|
self.assertEqual(len(response.json()["data"]["dashboard_config"]), 1)
|
||||||
|
self.assertEqual(
|
||||||
|
response.json()["data"]["dashboard_config"][0]["dashboard_type"],
|
||||||
|
"SIMPLE_DASHBOARD",
|
||||||
|
)
|
||||||
|
|
||||||
def test_course_statistics_deny_not_allowed_user(self):
|
def test_course_statistics_deny_not_allowed_user(self):
|
||||||
# GIVEN
|
# GIVEN
|
||||||
disallowed_user = create_user("1337_hacker_schorsch")
|
disallowed_user = create_user("1337_hacker_schorsch")
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue