Skip to content
Snippets Groups Projects
Commit efa7b3b8 authored by Jeff LaJoie's avatar Jeff LaJoie
Browse files

AA-164: Performance fixes for course home

parent 1703a88d
Branches
Tags
No related merge requests found
......@@ -2,6 +2,8 @@
Start Date Transformer implementation.
"""
from datetime import datetime
from pytz import UTC
from lms.djangoapps.courseware.access_utils import check_start_date
from openedx.core.djangoapps.content.block_structure.transformer import (
......@@ -74,10 +76,13 @@ class StartDateTransformer(FilteringTransformerMixin, BlockStructureTransformer)
if usage_info.has_staff_access or usage_info.allow_start_dates_in_future:
return [block_structure.create_universal_filter()]
now = datetime.now(UTC)
removal_condition = lambda block_key: not check_start_date(
usage_info.user,
block_structure.get_xblock_field(block_key, 'days_early_for_beta'),
self._get_merged_start_date(block_structure, block_key),
usage_info.course_key,
now=now,
)
return [block_structure.create_removal_filter(removal_condition)]
......@@ -81,6 +81,11 @@ class UserPartitionTransformer(FilteringTransformerMixin, BlockStructureTransfor
def transform_block_filters(self, usage_info, block_structure):
user = usage_info.user
result_list = SplitTestTransformer().transform_block_filters(usage_info, block_structure)
staff_access = has_access(user, 'staff', usage_info.course_key)
# If you have staff access, you are allowed access to the entire result list
if staff_access:
return result_list
user_partitions = block_structure.get_transformer_data(self, 'user_partitions')
if not user_partitions:
......@@ -97,7 +102,7 @@ class UserPartitionTransformer(FilteringTransformerMixin, BlockStructureTransfor
)
access_denying_partition = get_partition_from_id(user_partitions, access_denying_partition_id)
if not has_access(user, 'staff', block_key) and access_denying_partition:
if access_denying_partition:
user_group = user_groups.get(access_denying_partition.id)
allowed_groups = transformer_block_field.get_allowed_groups()[access_denying_partition.id]
access_denied_message = access_denying_partition.access_denied_message(
......@@ -112,7 +117,6 @@ class UserPartitionTransformer(FilteringTransformerMixin, BlockStructureTransfor
group_access_filter = block_structure.create_removal_filter(
lambda block_key: (
not has_access(user, 'staff', block_key) and
block_structure.get_transformer_block_field(
block_key, self, 'merged_group_access'
).get_access_denying_partition(user_groups) is not None and
......@@ -120,6 +124,7 @@ class UserPartitionTransformer(FilteringTransformerMixin, BlockStructureTransfor
)
)
result_list.append(group_access_filter)
return result_list
......
......@@ -65,7 +65,7 @@ def adjust_start_date(user, days_early_for_beta, start, course_key):
return start
def check_start_date(user, days_early_for_beta, start, course_key, display_error_to_user=True):
def check_start_date(user, days_early_for_beta, start, course_key, display_error_to_user=True, now=None):
"""
Verifies whether the given user is allowed access given the
start date and the Beta offset for the given course.
......@@ -82,10 +82,11 @@ def check_start_date(user, days_early_for_beta, start, course_key, display_error
if start_dates_disabled and not masquerading_as_student:
return ACCESS_GRANTED
else:
now = datetime.now(UTC)
if start is None or in_preview_mode() or get_course_masquerade(user, course_key):
return ACCESS_GRANTED
if now is None:
now = datetime.now(UTC)
effective_start = adjust_start_date(user, days_early_for_beta, start, course_key)
if now > effective_start:
return ACCESS_GRANTED
......
......@@ -22,6 +22,8 @@ from opaque_keys.edx.keys import UsageKey
from path import Path as path
from six import text_type
from openedx.core.lib.cache_utils import request_cached
import branding
from course_modes.models import CourseMode
from lms.djangoapps.courseware.access import has_access
......@@ -511,6 +513,7 @@ def get_course_assignment_date_blocks(course, user, request, num_return=None,
return date_blocks
@request_cached()
def get_course_assignments(course_key, user, request, include_access=False):
"""
Returns a list of assignment (at the subsection/sequential level) due dates for the given course.
......
......@@ -9,7 +9,7 @@ from pytz import timezone, utc
from django.urls import reverse
from django.utils.translation import ugettext as _
from lms.djangoapps.courseware.courses import get_course_info_section, get_course_date_blocks
from lms.djangoapps.courseware.courses import get_course_info_section
from openedx.core.djangoapps.self_paced.models import SelfPacedConfiguration
from openedx.core.djangolib.markup import HTML, Text
%>
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment