moving milestones check to access.py and upgrading milestones version

This commit is contained in:
Sanford Student
2016-07-29 09:33:00 -04:00
parent 8582da4a97
commit fc943ff539
31 changed files with 68 additions and 124 deletions

View File

@@ -20,6 +20,7 @@ from django.utils.timezone import UTC
from opaque_keys.edx.keys import CourseKey, UsageKey
from util import milestones_helpers as milestones_helpers
from xblock.core import XBlock
from xmodule.course_module import (
@@ -552,19 +553,18 @@ def _has_access_descriptor(user, action, descriptor, course_key=None):
students to see modules. If not, views should check the course, so we
don't have to hit the enrollments table on every module load.
"""
response = (
_visible_to_nonstaff_users(descriptor)
and _has_group_access(descriptor, user, course_key)
and
(
_has_detached_class_tag(descriptor)
or _can_access_descriptor_with_start_date(user, descriptor, course_key)
)
)
if _has_staff_access_to_descriptor(user, descriptor, course_key):
return ACCESS_GRANTED
# if the user has staff access, they can load the module so this code doesn't need to run
return (
ACCESS_GRANTED if (response or _has_staff_access_to_descriptor(user, descriptor, course_key))
else response
_visible_to_nonstaff_users(descriptor) and
_can_access_descriptor_with_milestones(user, descriptor, course_key) and
_has_group_access(descriptor, user, course_key) and
(
_has_detached_class_tag(descriptor) or
_can_access_descriptor_with_start_date(user, descriptor, course_key)
)
)
checkers = {
@@ -801,6 +801,22 @@ def _visible_to_nonstaff_users(descriptor):
return VisibilityError() if descriptor.visible_to_staff_only else ACCESS_GRANTED
def _can_access_descriptor_with_milestones(user, descriptor, course_key):
"""
Returns if the object is blocked by an unfulfilled milestone.
Args:
user: the user trying to access this content
descriptor: the object being accessed
course_key: key for the course for this descriptor
"""
if milestones_helpers.get_course_content_milestones(course_key, unicode(descriptor.location), 'requires', user.id):
debug("Deny: user has not completed all milestones for content")
return ACCESS_DENIED
else:
return ACCESS_GRANTED
def _has_detached_class_tag(descriptor):
"""
Returns if the given descriptor's type is marked as detached.