2222from enterprise .api .v1 .serializers import EnterpriseCustomerSerializer
2323from milestones .tests .utils import MilestonesTestCaseMixin
2424from opaque_keys .edx .locator import CourseLocator
25- from openedx_authz .constants .roles import COURSE_EDITOR
2625
2726import lms .djangoapps .courseware .access as access
2827import lms .djangoapps .courseware .access_response as access_response
2928from common .djangoapps .student .models import CourseEnrollment
30- from common .djangoapps .student .roles import CourseCcxCoachRole , CourseLimitedStaffRole , CourseStaffRole
29+ from common .djangoapps .student .roles import CourseCcxCoachRole , CourseStaffRole
3130from common .djangoapps .student .tests .factories import (
3231 AdminFactory ,
3332 AnonymousUserFactory ,
4443from lms .djangoapps .courseware .masquerade import CourseMasquerade
4544from lms .djangoapps .courseware .tests .helpers import LoginEnrollmentTestCase , masquerade_as_group_member
4645from lms .djangoapps .courseware .toggles import course_is_invitation_only
47- from openedx .core import toggles as core_toggles
4846from openedx .core .djangoapps .authz .tests .mixins import CourseAuthoringAuthzTestMixin
4947from openedx .core .djangoapps .content .course_overviews .models import CourseOverview
5048from openedx .core .djangoapps .content .course_overviews .tests .factories import CourseOverviewFactory
@@ -1026,7 +1024,11 @@ def test_course_catalog_access_num_queries_enterprise(self, user_attr_name, cour
10261024
10271025class AuthzSeeAboutPageAccessTestCase (CourseAuthoringAuthzTestMixin , SharedModuleStoreTestCase ):
10281026 """
1029- see_about_page access when AuthZ course authoring is enabled for the course.
1027+ AuthZ-specific see_about_page edge cases not covered elsewhere.
1028+
1029+ Catalog visibility grants, staff bypass, AuthZ role grants, and learner
1030+ denials are tested in test__catalog_visibility*, TestGetCourseDetailAuthz,
1031+ and AuthzAboutPageTestCase.
10301032 """
10311033
10321034 @classmethod
@@ -1049,16 +1051,6 @@ def _see_about_page_response(self, user, course):
10491051 course_overview = CourseOverview .get_from_id (course .id )
10501052 return access .has_access (user , "see_about_page" , course_overview , course_key = course .id )
10511053
1052- def test_learner_granted_via_catalog_visibility_both (self ):
1053- """Learners without AuthZ roles can view the about page when catalog allows it."""
1054- response = self ._see_about_page_response (self .unauthorized_user , self .course_public )
1055- assert response
1056-
1057- def test_learner_granted_via_catalog_visibility_about_only (self ):
1058- """Learners without AuthZ roles can view about-only courses."""
1059- response = self ._see_about_page_response (self .unauthorized_user , self .course_about_only )
1060- assert response
1061-
10621054 def test_enrolled_learner_denied_when_catalog_hidden (self ):
10631055 """Enrollment alone does not grant about-page access when catalog is hidden."""
10641056 CourseEnrollmentFactory (user = self .unauthorized_user , course_id = self .course_hidden .id )
@@ -1076,55 +1068,23 @@ def test_beta_tester_granted_via_catalog_about(self):
10761068
10771069 assert response
10781070
1079- def test_course_staff_bypass_when_catalog_hidden (self ):
1080- """Course staff can preview the about page when catalog visibility is none."""
1081- course_staff = StaffFactory .create (course_key = self .course_hidden .id )
1082-
1083- response = self ._see_about_page_response (course_staff , self .course_hidden )
1084-
1085- assert response
1086-
1087- def test_limited_staff_bypass_when_catalog_hidden (self ):
1088- """Limited staff inherit staff bypass for about-page access."""
1089- limited_staff = UserFactory .create ()
1090- CourseLimitedStaffRole (self .course_hidden .id ).add_users (limited_staff )
1091-
1092- response = self ._see_about_page_response (limited_staff , self .course_hidden )
1093-
1094- assert response
1095-
1096- def test_authz_role_grants_access_when_catalog_hidden (self ):
1097- """Users with COURSES_VIEW_COURSE can access hidden about pages."""
1098- self .add_user_to_role_in_course (self .unauthorized_user , COURSE_EDITOR .external_key , self .course_hidden .id )
1099-
1100- response = self ._see_about_page_response (self .unauthorized_user , self .course_hidden )
1101-
1102- assert response
1103-
11041071 def test_anonymous_user_uses_legacy_path (self ):
1105- """Anonymous users are routed to the legacy path and follow catalog visibility."""
1106- anonymous_user = AnonymousUserFactory .create ()
1107-
1108- response = self ._see_about_page_response (anonymous_user , self .course_public )
1109-
1110- assert response
1111-
1112- def test_denied_returns_catalog_visibility_error (self ):
1113- """AuthZ path returns CatalogVisibilityError when all checks fail."""
1114- response = self ._see_about_page_response (self .unauthorized_user , self .course_hidden )
1115-
1116- assert not response
1117- assert isinstance (response , access_response .CatalogVisibilityError )
1118- assert response .error_code == "not_visible_in_catalog"
1072+ """
1073+ Anonymous users skip the AuthZ path even when course authoring AuthZ is enabled.
11191074
1120- def test_legacy_path_when_authz_disabled ( self ):
1121- """When AuthZ is off, catalog visibility rules still apply."""
1122- with patch . object ( core_toggles . AUTHZ_COURSE_AUTHORING_FLAG , "is_enabled" , return_value = False ):
1123- response = self . _see_about_page_response ( self . unauthorized_user , self . course_public )
1075+ user_has_course_permission is only reached on the AuthZ path, so it must not
1076+ be called for anonymous users on a catalog-hidden course.
1077+ """
1078+ anonymous_user = AnonymousUserFactory . create ( )
11241079
1125- assert response
1080+ with patch (
1081+ "lms.djangoapps.courseware.access.user_has_course_permission" ,
1082+ ) as mock_authz_permission :
1083+ hidden_response = self ._see_about_page_response (anonymous_user , self .course_hidden )
11261084
1127- hidden_response = self ._see_about_page_response (self .unauthorized_user , self .course_hidden )
1085+ mock_authz_permission .assert_not_called ()
1086+ assert not hidden_response
1087+ assert isinstance (hidden_response , access_response .CatalogVisibilityError )
11281088
1129- assert not hidden_response
1130- assert isinstance ( hidden_response , access_response . CatalogVisibilityError )
1089+ public_response = self . _see_about_page_response ( anonymous_user , self . course_public )
1090+ assert public_response
0 commit comments