def can_load(): """ NOTE: This does not check that the student is enrolled in the course that contains this module. We may or may not want to allow non-enrolled 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. """ # If the user (or the role the user is currently masquerading as) does not have # access to this content, then deny access. The problem with calling _has_staff_access_to_descriptor # before this method is that _has_staff_access_to_descriptor short-circuits and returns True # for staff users in preview mode. if not _has_group_access(descriptor, user, course_key): return ACCESS_DENIED # If the user has staff access, they can load the module and checks below are not needed. if _has_staff_access_to_descriptor(user, descriptor, course_key): return ACCESS_GRANTED return ( _visible_to_nonstaff_users(descriptor) and ( _has_detached_class_tag(descriptor) or check_start_date(user, descriptor.days_early_for_beta, descriptor.start, course_key) ) )
def _can_access_descriptor_with_start_date(user, descriptor, course_key): # pylint: disable=invalid-name """ Checks if a user has access to a descriptor based on its start date. If there is no start date specified, grant access. Else, check if we're past the start date. Note: We do NOT check whether the user is staff or if the descriptor is detached... it is assumed both of these are checked by the caller. Arguments: user (User): the user whose descriptor access we are checking. descriptor (AType): the descriptor for which we are checking access, where AType is CourseDescriptor, CourseOverview, or any other class that represents a descriptor and has the attributes .location, .id, .start, and .days_early_for_beta. Returns: AccessResponse: The result of this access check. Possible results are ACCESS_GRANTED or a StartDateError. """ return check_start_date(user, descriptor.days_early_for_beta, descriptor.start, course_key)
def _can_access_descriptor_with_start_date(user, descriptor, course_key): # pylint: disable=invalid-name """ Checks if a user has access to a descriptor based on its start date. If there is no start date specified, grant access. Else, check if we're past the start date. Note: We do NOT check whether the user is staff or if the descriptor is detached... it is assumed both of these are checked by the caller. Arguments: user (User): the user whose descriptor access we are checking. descriptor (AType): the descriptor for which we are checking access, where AType is CourseDescriptor, CourseOverview, or any other class that represents a descriptor and has the attributes .location, .id, .start, and .days_early_for_beta. Returns: AccessResponse: The result of this access check. Possible results are ACCESS_GRANTED or a StartDateError. """ return check_start_date(user, descriptor.days_early_for_beta, descriptor.start, course_key)