def courseware_mfe_is_advertised( course_key: CourseKey, is_global_staff=False, is_course_staff=False, ) -> bool: """ Should we invite the user to view a course run's content in the Learning MFE? This check is slightly different than `courseware_mfe_is_visible`, in that we always *permit* global staff to view MFE content (assuming it's deployed), but we do not shove the New Experience in their face if the preview isn't enabled. """ #Avoid circular imports. from lms.djangoapps.courseware.access_utils import in_preview_mode # DENY: Old Mongo courses don't work in the MFE. if course_key.deprecated: return False # DENY: Course preview doesn't work in the MFE if in_preview_mode(): return False # ALLOW: Both global and course staff can see the MFE link if the course team # preview is enabled. is_staff = is_global_staff or is_course_staff if is_staff and COURSEWARE_MICROFRONTEND_COURSE_TEAM_PREVIEW.is_enabled( course_key): return True # OTHERWISE: The MFE is only advertised if it's the active (ie canonical) experience. return courseware_mfe_is_active(course_key)
def courseware_mfe_is_visible( course_key: CourseKey, is_global_staff=False, is_course_staff=False, ) -> bool: """ Can we see a course run's content in the Learning MFE? """ #Avoid circular imports. from lms.djangoapps.courseware.access_utils import in_preview_mode # DENY: Old Mongo courses don't work in the MFE. if course_key.deprecated: return False # DENY: Course preview doesn't work in the MFE if in_preview_mode(): return False # ALLOW: Where techincally possible, global staff may always see the MFE. if is_global_staff: return True # ALLOW: If course team preview is enabled, then course staff may see their # course in the MFE. if is_course_staff and COURSEWARE_MICROFRONTEND_COURSE_TEAM_PREVIEW.is_enabled( course_key): return True # OTHERWISE: The MFE is only visible if it's the active (ie canonical) experience. return courseware_mfe_is_active(course_key)
def courseware_mfe_is_active() -> bool: """ Should we serve the Learning MFE as the canonical courseware experience? """ from lms.djangoapps.courseware.access_utils import in_preview_mode # avoid a circular import # We only use legacy views for the Studio "preview mode" feature these days, while everyone else gets the MFE return not in_preview_mode()
def mfe_proctored_exams_is_active(course_key: CourseKey) -> bool: """ Can we see a course special exams in the Learning MFE? """ #Avoid circular imports. from lms.djangoapps.courseware.access_utils import in_preview_mode # DENY: Old Mongo courses don't work in the MFE. if course_key.deprecated: return False # DENY: Course preview doesn't work in the MFE if in_preview_mode(): return False # OTHERWISE: Defer to value of waffle flag for this course run and user. return COURSEWARE_MICROFRONTEND_PROCTORED_EXAMS.is_enabled(course_key)
def courseware_mfe_is_active(course_key: CourseKey) -> bool: """ Should we serve the Learning MFE as the canonical courseware experience? """ #Avoid circular imports. from lms.djangoapps.courseware.access_utils import in_preview_mode # NO: Old Mongo courses are always served in the Legacy frontend, # regardless of configuration. if course_key.deprecated: return False # NO: MFE courseware can be disabled for users/courses/globally via this # Waffle flag. if COURSEWARE_USE_LEGACY_FRONTEND.is_enabled(course_key): return False # NO: Course preview doesn't work in the MFE if in_preview_mode(): return False # OTHERWISE: MFE courseware experience is active by default. return True
def courseware_legacy_is_visible( course_key: CourseKey, is_global_staff=False, ) -> bool: """ Can we see a course run's content in the Legacy frontend? Note: This function will always return True for Old Mongo courses, since `courseware_mfe_is_active` will always return False for them. """ #Avoid circular imports. from lms.djangoapps.courseware.access_utils import in_preview_mode # ALLOW: Global staff may always see the Legacy experience. if is_global_staff: return True # ALLOW: All course previews will be shown in Legacy experience if in_preview_mode(): return True # OTHERWISE: Legacy is only visible if it's the active (ie canonical) experience. # Note that Old Mongo courses are never the active experience, # so we effectively always ALLOW them to be viewed in Legacy. return not courseware_mfe_is_active(course_key)
def has_access(user, action, obj, course_key=None): """ Check whether a user has the access to do action on obj. Handles any magic switching based on various settings. Things this module understands: - start dates for modules - visible_to_staff_only for modules - DISABLE_START_DATES - different access for instructor, staff, course staff, and students. - mobile_available flag for course modules user: a Django user object. May be anonymous. If none is passed, anonymous is assumed obj: The object to check access for. A module, descriptor, location, or certain special strings (e.g. 'global') action: A string specifying the action that the client is trying to perform. actions depend on the obj type, but include e.g. 'enroll' for courses. See the type-specific functions below for the known actions for that type. course_key: A course_key specifying which course run this access is for. Required when accessing anything other than a CourseBlock, 'global', or a location with category 'course' Returns an AccessResponse object. It is up to the caller to actually deny access in a way that makes sense in context. """ # Just in case user is passed in as None, make them anonymous if not user: user = AnonymousUser() # Preview mode is only accessible by staff. if in_preview_mode() and course_key: if not has_staff_access_to_preview_mode(user, course_key): return ACCESS_DENIED # delegate the work to type-specific functions. # (start with more specific types, then get more general) if isinstance(obj, CourseBlock): return _has_access_course(user, action, obj) if isinstance(obj, CourseOverview): return _has_access_course(user, action, obj) if isinstance(obj, ErrorBlock): return _has_access_error_desc(user, action, obj, course_key) if isinstance(obj, XModule): return _has_access_xmodule(user, action, obj, course_key) # NOTE: any descriptor access checkers need to go above this if isinstance(obj, XBlock): return _has_access_descriptor(user, action, obj, course_key) if isinstance(obj, CourseKey): return _has_access_course_key(user, action, obj) if isinstance(obj, UsageKey): return _has_access_location(user, action, obj, course_key) if isinstance(obj, str): return _has_access_string(user, action, obj) # Passing an unknown object here is a coding error, so rather than # returning a default, complain. raise TypeError("Unknown object type in has_access(): '{}'".format( type(obj)))