Exemplo n.º 1
0
    def test_get_courses(self):
        course = CourseFactory()
        student = UserFactory()
        instructor = UserFactory()

        course.group.user_set.add(student)
        course.group.user_set.add(instructor)
        course.faculty_group.user_set.add(instructor)

        # as student
        lst = get_courses_for_user(student)
        self.assertEquals(len(lst), 1)
        self.assertTrue(course in lst)

        lst = get_courses_for_instructor(student)
        self.assertEquals(len(lst), 0)

        # as instructor
        lst = get_courses_for_user(instructor)
        self.assertEquals(len(lst), 1)
        self.assertTrue(course in lst)

        lst = get_courses_for_instructor(instructor)
        self.assertEquals(len(lst), 1)
        self.assertTrue(course in lst)
Exemplo n.º 2
0
 def get_queryset(self):
     """
     A user can GET / Activityies if the user is in the
     course group for the related Course object
     """
     user = self.request.user
     courses = get_courses_for_user(user)
     return Activity.objects.filter(project__course__in=courses)
Exemplo n.º 3
0
    def post(self, request, *args, **kwargs) -> HttpResponse:
        is_grid = not request.session.get('course_grid_layout', False)
        request.session['course_grid_layout'] = is_grid

        ctx = {
            'user': request.user,
            'courses': get_courses_for_user(
                self.request.user).order_by('title'),
            'page_type': 'dashboard',
            'breadcrumb': self.get_breadcrumb(),
            'course_grid_layout': is_grid
        }
        return render(request, self.template_name, ctx)
Exemplo n.º 4
0
 def get_queryset(self):
     """
     Users in a course MAY be able to view a project if:
     A) They are faculty in the course
     OR
     B) They are in the course and the project has an activity
     """
     user = self.request.user
     instructor_courses = get_courses_for_instructor(user)
     user_courses = get_courses_for_user(user)
     return Project.objects.filter((Q(course__in=instructor_courses))
                                   | (Q(course__in=user_courses)
                                      & Q(activity__isnull=False)))
Exemplo n.º 5
0
 def get_queryset(self):
     """
     Authenticated users can access a layer if any:
     (Project Layers)
     - If the Layer is associated with a Project, and the user is faculty in
       Layer => Project => Course
     - If the Layer is associated with a Project, the user is a student in
       Layer => Project => Course, and the Project has an Activity
     (Response Layers)
     - If the Layer is associated with a Response, and the user is an owner
       of the Response
     - If the Layer is associated with a Response, the Response state is not
       "Draft", and the user is faculty in Layer => Response => Activity =>
       Project => Course
     - If the Layer is associated with a Response, the Response state is not
       "Draft", the user is owner of a Response related to Layer => Response
       => Activity, the state of the user's Response is not "Draft", and the
       user is a student in Layer => Response => Activity => Project =>
       Course
     """
     user = self.request.user
     instructor_courses = get_courses_for_instructor(user)
     user_courses = get_courses_for_user(user)
     user_owned_response = Response.objects.filter(
         activity=OuterRef('response__activity__pk'),
         owners__in=[user],
         status__in=[Response.SUBMITTED, Response.REVIEWED])
     return Layer.objects.annotate(
         user_has_related_response=Exists(user_owned_response)
     ).filter(
         (Q(project__course__in=instructor_courses))
         | (Q(project__course__in=user_courses)
            & Q(project__activity__isnull=False))
         | (Q(response__owners__in=[user]))
         | (Q(response__status__in=[Response.SUBMITTED, Response.REVIEWED])
            & Q(response__activity__project__course__in=instructor_courses))
         | (Q(response__status__in=[Response.SUBMITTED, Response.REVIEWED])
            & Q(user_has_related_response=True)
            & Q(response__activity__project__course__in=user_courses)))