Skip to content

Commit

Permalink
feat: accessible tenants info api v2
Browse files Browse the repository at this point in the history
  • Loading branch information
tehreem-sadat committed Feb 5, 2025
1 parent ec2006d commit 3a99729
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 0 deletions.
1 change: 1 addition & 0 deletions futurex_openedx_extensions/dashboard/docs_src.py
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,7 @@ def get_optional_parameter(path: str) -> Any:
},
},
},
remove=[404]
),
},

Expand Down
1 change: 1 addition & 0 deletions futurex_openedx_extensions/dashboard/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

urlpatterns = [
re_path(r'^api/fx/accessible/v1/info/$', views.AccessibleTenantsInfoView.as_view(), name='accessible-info'),
re_path(r'^api/fx/accessible/v2/info/$', views.AccessibleTenantsInfoViewV2.as_view(), name='accessible-info-v2'),
re_path(r'^api/fx/courses/v1/courses/$', views.CoursesView.as_view(), name='courses'),
re_path(r'^api/fx/learners/v1/learners/$', views.LearnersView.as_view(), name='learners'),
re_path(
Expand Down
8 changes: 8 additions & 0 deletions futurex_openedx_extensions/dashboard/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -445,6 +445,14 @@ def get(self, request: Any, *args: Any, **kwargs: Any) -> JsonResponse: # pylin
return JsonResponse(get_tenants_info(tenant_ids))


class AccessibleTenantsInfoViewV2(FXViewRoleInfoMixin, AccessibleTenantsInfoView):
"""View to get the list of accessible tenants version 2"""
permission_classes = [FXHasTenantCourseAccess]
fx_view_name = 'accessible_info'
fx_default_read_only_roles = ['staff', 'instructor', 'data_researcher', 'org_course_creator_group']
fx_view_description = '/api/fx/accessible/v2/info/: Get accessible tenants'


@docs('LearnersDetailsForCourseView.get')
class LearnersDetailsForCourseView(ExportCSVMixin, FXViewRoleInfoMixin, ListAPIView):
"""View to get the list of learners for a course"""
Expand Down
45 changes: 45 additions & 0 deletions tests/test_dashboard/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -789,6 +789,51 @@ def test_not_existing_username_or_email(self):
self.assertDictEqual(json.loads(response.content), {})


@pytest.mark.usefixtures('base_data')
class TestAccessibleTenantsInfoViewV2(BaseTestViewMixin):
"""Tests for AccessibleTenantsInfoViewv2"""
VIEW_NAME = 'fx_dashboard:accessible-info-v2'

def test_permission_classes(self):
"""Verify that the view has the correct permission classes"""
view_func, _, _ = resolve(self.url)
view_class = view_func.view_class
self.assertEqual(view_class.permission_classes, [FXHasTenantCourseAccess])

@patch('futurex_openedx_extensions.dashboard.views.get_user_by_username_or_email')
def test_success(self, mock_get_user):
"""Verify that the view returns the correct response"""
mock_get_user.return_value = get_user_model().objects.get(username='user4')
self.login_user(self.staff_user)
response = self.client.get(self.url, data={'username_or_email': 'dummy, the user loader function is mocked'})
self.assertEqual(response.status_code, http_status.HTTP_200_OK)
self.assertDictEqual(json.loads(response.content), {
'1': {
'lms_root_url': 'https://s1.sample.com',
'studio_root_url': 'https://studio.example.com',
'platform_name': '', 'logo_image_url': ''
},
'2': {
'lms_root_url': 'https://s2.sample.com',
'studio_root_url': 'https://studio.example.com',
'platform_name': '', 'logo_image_url': ''
},
'7': {
'lms_root_url': 'https://s7.sample.com',
'studio_root_url': 'https://studio.example.com',
'platform_name': '', 'logo_image_url': ''
},
})

self.login_user(5)
response = self.client.get(self.url, data={'username_or_email': 'dummy'})
self.assertEqual(
response.status_code,
http_status.HTTP_403_FORBIDDEN,
f'Expected 403 for non staf users, but got {response.status_code}'
)


@pytest.mark.usefixtures('base_data')
class TestLearnersDetailsForCourseView(BaseTestViewMixin):
"""Tests for LearnersDetailsForCourseView"""
Expand Down

0 comments on commit 3a99729

Please sign in to comment.