def test_is_publisher_admin(self):
        """
        Verify the function returns a boolean indicating if the user is a member of the administrative group.
        """
        self.assertFalse(self.user.groups.filter(name=ADMIN_GROUP_NAME).exists())
        self.assertFalse(is_publisher_admin(self.user))

        admin_group = Group.objects.get(name=ADMIN_GROUP_NAME)
        self.user.groups.add(admin_group)
        self.assertTrue(is_publisher_admin(self.user))
Exemple #2
0
    def test_is_publisher_admin(self):
        """ Verify the function returns a boolean indicating if the user
        is a member of the administrative group.
        """
        self.assertFalse(self.user.groups.filter(name=ADMIN_GROUP_NAME).exists())
        self.assertFalse(is_publisher_admin(self.user))

        admin_group = Group.objects.get(name=ADMIN_GROUP_NAME)
        self.user.groups.add(admin_group)
        self.assertTrue(is_publisher_admin(self.user))
Exemple #3
0
    def get_queryset(self):
        user = self.request.user
        if is_publisher_admin(user):
            courses = Course.objects.all()
        elif is_internal_user(user):
            courses = Course.objects.filter(course_user_roles__user=user).distinct()
        else:
            courses = get_objects_for_user(user, Course.VIEW_PERMISSION, Course)

        return courses
Exemple #4
0
    def get_queryset(self):
        user = self.request.user
        if is_publisher_admin(user):
            course_runs = CourseRun.objects.select_related('course').all()
        elif is_internal_user(user):
            internal_user_courses = Course.objects.filter(course_user_roles__user=user)
            course_runs = CourseRun.objects.filter(course__in=internal_user_courses).select_related('course').all()
        else:
            # in future we will change permission from course to OrganizationExtension model
            courses = get_objects_for_user(user, Course.VIEW_PERMISSION, Course)
            course_runs = CourseRun.objects.filter(course__in=courses).select_related('course').all()

        return course_runs
Exemple #5
0
    def get_courses(user, queryset=None):
        if queryset is None:
            queryset = Course.objects.all()

        if is_publisher_admin(user):
            return queryset
        elif is_internal_user(user):
            return queryset.filter(course_user_roles__user=user).distinct()
        else:
            organizations = get_objects_for_user(
                user,
                OrganizationExtension.VIEW_COURSE,
                OrganizationExtension,
                use_groups=True,
                with_superuser=False).values_list('organization')
            return queryset.filter(organizations__in=organizations)
Exemple #6
0
    def get_queryset(self):
        user = self.request.user
        if is_publisher_admin(user):
            courses = Course.objects.all()
        elif is_internal_user(user):
            courses = Course.objects.filter(
                course_user_roles__user=user).distinct()
        else:
            organizations = get_objects_for_user(
                user,
                OrganizationExtension.VIEW_COURSE,
                OrganizationExtension,
                use_groups=True,
                with_superuser=False).values_list('organization')
            courses = Course.objects.filter(organizations__in=organizations)

        return courses
    def get_queryset(self):
        if self.q:
            user = self.request.user
            if is_publisher_admin(user):
                qs = Course.objects.filter(title__icontains=self.q)
            elif is_internal_user(user):
                qs = Course.objects.filter(title__icontains=self.q, course_user_roles__user=user).distinct()
            else:
                organizations = get_objects_for_user(
                    user,
                    OrganizationExtension.VIEW_COURSE,
                    OrganizationExtension,
                    use_groups=True,
                    with_superuser=False
                ).values_list('organization')
                qs = Course.objects.filter(title__icontains=self.q, organizations__in=organizations)

            return qs

        return []
Exemple #8
0
    def get_context_data(self, **kwargs):
        context = super(Dashboard, self).get_context_data(**kwargs)
        course_runs = context.get('object_list')

        published_course_runs = course_runs.filter(
            state__name=State.PUBLISHED,
            state__modified__gt=datetime.today() - timedelta(days=self.default_published_days)
        ).select_related('state').order_by('-state__modified')

        unpublished_course_runs = course_runs.exclude(state__name=State.PUBLISHED)

        # Studio requests needs to check depending upon the user role with course
        # Also user should be part of partner coordinator group.
        if is_publisher_admin(self.request.user):
            studio_request_courses = unpublished_course_runs.filter(lms_course_id__isnull=True)
        elif is_partner_coordinator_user(self.request.user):
            studio_request_courses = unpublished_course_runs.filter(lms_course_id__isnull=True).filter(
                course__course_user_roles__role=PublisherUserRole.PartnerCoordinator
            )
        else:
            studio_request_courses = []

        context['studio_request_courses'] = [CourseRunWrapper(course_run) for course_run in studio_request_courses]
        context['unpublished_course_runs'] = [CourseRunWrapper(course_run) for course_run in unpublished_course_runs]
        context['published_course_runs'] = [CourseRunWrapper(course_run) for course_run in published_course_runs]
        context['default_published_days'] = self.default_published_days

        in_progress_course_runs = course_runs.filter(
            state__name=State.NEEDS_FINAL_APPROVAL
        ).select_related('state').order_by('-state__modified')

        preview_course_runs = in_progress_course_runs.filter(
            preview_url__isnull=False
        ).order_by('-state__modified')

        context['in_progress_course_runs'] = [CourseRunWrapper(course_run) for course_run in in_progress_course_runs]
        context['preview_course_runs'] = [CourseRunWrapper(course_run) for course_run in preview_course_runs]

        return context
Exemple #9
0
def check_roles_access(user):
    """ Return True if user is part of a role that gives implicit access. """
    return is_publisher_admin(user) or is_internal_user(user)
Exemple #10
0
    def get_context_data(self, **kwargs):
        context = super(Dashboard, self).get_context_data(**kwargs)
        course_runs = context.get('object_list')
        published_course_runs = course_runs.filter(
            course_run_state__name=CourseRunStateChoices.Published,
            course_run_state__modified__gt=datetime.today() -
            timedelta(days=self.default_published_days)).select_related(
                'course_run_state').order_by('-course_run_state__modified')

        unpublished_course_runs = course_runs.exclude(
            course_run_state__name=CourseRunStateChoices.Published)

        # Studio requests needs to check depending upon the user role with course
        # Also user should be part of project coordinator group.
        if is_publisher_admin(self.request.user):
            studio_request_courses = unpublished_course_runs.filter(
                lms_course_id__isnull=True)
        elif is_project_coordinator_user(self.request.user):
            studio_request_courses = unpublished_course_runs.filter(
                lms_course_id__isnull=True).filter(
                    course__course_user_roles__role=PublisherUserRole.
                    ProjectCoordinator)
        else:
            studio_request_courses = []

        context['studio_request_courses'] = [
            CourseRunWrapper(course_run)
            for course_run in studio_request_courses
        ]
        context['unpublished_course_runs'] = [
            CourseRunWrapper(course_run)
            for course_run in unpublished_course_runs
        ]
        context['published_course_runs'] = [
            CourseRunWrapper(course_run)
            for course_run in published_course_runs
        ]
        context['default_published_days'] = self.default_published_days

        in_progress_course_runs = course_runs.filter(
            course_run_state__name__in=[
                CourseRunStateChoices.Review, CourseRunStateChoices.Draft
            ]).select_related('course_run_state').order_by(
                '-course_run_state__modified')

        preview_course_runs = unpublished_course_runs.filter(
            course_run_state__name=CourseRunStateChoices.Approved,
            preview_url__isnull=False).order_by('-course_run_state__modified')

        context['in_progress_course_runs'] = [
            CourseRunWrapper(course_run)
            for course_run in in_progress_course_runs
        ]
        context['preview_course_runs'] = [
            CourseRunWrapper(course_run) for course_run in preview_course_runs
        ]

        # If user is course team member only show in-progress tab.
        # shows all tabs to internal-users and publisher admins
        context['can_view_all_tabs'] = mixins.check_roles_access(
            self.request.user)

        return context