def is_course_public(course_key: CourseKey) -> AccessResponse: """ This checks if a course is publicly accessible or not. """ try: course = get_course(course_key, depth=0) except CourseRunNotFound: return ACCESS_DENIED return check_public_access(course, [COURSE_VISIBILITY_PUBLIC])
def _register_course_home_messages(request, course, user_access, course_start_data): # lint-amnesty, pylint: disable=unused-argument """ Register messages to be shown in the course home content page. """ allow_anonymous = check_public_access(course, [COURSE_VISIBILITY_PUBLIC]) if user_access['is_anonymous'] and not allow_anonymous: sign_in_or_register_text = (_('{sign_in_link} or {register_link} and then enroll in this course.') if not CourseMode.is_masters_only(course.id) else _('{sign_in_link} or {register_link}.')) CourseHomeMessages.register_info_message( request, Text(sign_in_or_register_text).format( sign_in_link=HTML('<a href="/login?next={current_url}">{sign_in_label}</a>').format( sign_in_label=_('Sign in'), current_url=urlquote_plus(request.path), ), register_link=HTML('<a href="/register?next={current_url}">{register_label}</a>').format( register_label=_('register'), current_url=urlquote_plus(request.path), ) ), title=Text(_('You must be enrolled in the course to see course content.')) ) if not user_access['is_anonymous'] and not user_access['is_staff'] and \ not user_access['is_enrolled']: title = Text(_('Welcome to {course_display_name}')).format( course_display_name=course.display_name ) if CourseMode.is_masters_only(course.id): # if a course is a Master's only course, we will not offer user ability to self-enroll CourseHomeMessages.register_info_message( request, Text(_( 'You must be enrolled in the course to see course content. ' 'Please contact your degree administrator or {platform_name} Support if you have questions.' )).format(platform_name=settings.PLATFORM_NAME), title=title ) elif not course.invitation_only: CourseHomeMessages.register_info_message( request, Text(_( '{open_enroll_link}Enroll now{close_enroll_link} to access the full course.' )).format( open_enroll_link=HTML('<button class="enroll-btn btn-link">'), close_enroll_link=HTML('</button>') ), title=title ) else: CourseHomeMessages.register_info_message( request, Text(_('You must be enrolled in the course to see course content.')), )
def is_course_public(course_key: CourseKey) -> AccessResponse: """ This checks if a course is publicly accessible or not. """ course = get_course(course_key, depth=0) return check_public_access(course, [COURSE_VISIBILITY_PUBLIC])