def can_load(): """ Can this user load this course? NOTE: this is not checking whether user is actually enrolled in the course. """ # N.B. I'd love a better way to handle this pattern, without breaking the # shortcircuiting logic. Maybe AccessResponse needs to grow a # fluent interface? # # return ( # _visible_to_nonstaff_users(courselike).and( # check_course_open_for_learner, user, courselike # ).and( # _can_view_courseware_with_prerequisites, user, courselike # ) # ).or( # _has_staff_access_to_descriptor, user, courselike, courselike.id # ) visible_to_nonstaff = _visible_to_nonstaff_users(courselike) if not visible_to_nonstaff: staff_access = _has_staff_access_to_descriptor( user, courselike, courselike.id) if staff_access: return staff_access else: return visible_to_nonstaff open_for_learner = check_course_open_for_learner(user, courselike) if not open_for_learner: staff_access = _has_staff_access_to_descriptor( user, courselike, courselike.id) if staff_access: return staff_access else: return open_for_learner view_with_prereqs = _can_view_courseware_with_prerequisites( user, courselike) if not view_with_prereqs: staff_access = _has_staff_access_to_descriptor( user, courselike, courselike.id) if staff_access: return staff_access else: return view_with_prereqs if CONTENT_TYPE_GATING_FLAG.is_enabled(): has_not_expired = check_course_expired(user, courselike) if not has_not_expired: staff_access = _has_staff_access_to_descriptor( user, courselike, courselike.id) if staff_access: return staff_access else: return has_not_expired return ACCESS_GRANTED
def can_load(): """ Can this user load this course? NOTE: this is not checking whether user is actually enrolled in the course. """ response = (_visible_to_nonstaff_users(courselike) and check_course_open_for_learner(user, courselike)) return (ACCESS_GRANTED if (response or _has_staff_access_to_descriptor( user, courselike, courselike.id)) else response)
def can_load(): """ Can this user load this course? NOTE: this is not checking whether user is actually enrolled in the course. """ # N.B. I'd love a better way to handle this pattern, without breaking the # shortcircuiting logic. Maybe AccessResponse needs to grow a # fluent interface? # # return ( # _visible_to_nonstaff_users(courselike).and( # check_course_open_for_learner, user, courselike # ).and( # _can_view_courseware_with_prerequisites, user, courselike # ) # ).or( # _has_staff_access_to_descriptor, user, courselike, courselike.id # ) visible_to_nonstaff = _visible_to_nonstaff_users(courselike) if not visible_to_nonstaff: staff_access = _has_staff_access_to_descriptor(user, courselike, courselike.id) if staff_access: return staff_access else: return visible_to_nonstaff open_for_learner = check_course_open_for_learner(user, courselike) if not open_for_learner: staff_access = _has_staff_access_to_descriptor(user, courselike, courselike.id) if staff_access: return staff_access else: return open_for_learner view_with_prereqs = _can_view_courseware_with_prerequisites(user, courselike) if not view_with_prereqs: staff_access = _has_staff_access_to_descriptor(user, courselike, courselike.id) if staff_access: return staff_access else: return view_with_prereqs has_not_expired = check_course_expired(user, courselike) if not has_not_expired: staff_access = _has_staff_access_to_descriptor(user, courselike, courselike.id) if staff_access: return staff_access else: return has_not_expired return ACCESS_GRANTED
def can_load(): """ Can this user load this course? NOTE: this is not checking whether user is actually enrolled in the course. """ response = ( _visible_to_nonstaff_users(courselike) and check_course_open_for_learner(user, courselike) and _can_view_courseware_with_prerequisites(user, courselike) ) return ( ACCESS_GRANTED if (response or _has_staff_access_to_descriptor(user, courselike, courselike.id)) else response )