diff --git a/futurex_openedx_extensions/helpers/apps.py b/futurex_openedx_extensions/helpers/apps.py index f19e6fc5..1d3fbf2f 100644 --- a/futurex_openedx_extensions/helpers/apps.py +++ b/futurex_openedx_extensions/helpers/apps.py @@ -1,6 +1,7 @@ """helpers Django application initialization""" from __future__ import annotations +from bridgekeeper import perms from django.apps import AppConfig @@ -29,8 +30,19 @@ class HelpersConfig(AppConfig): def ready(self) -> None: """Connect handlers to send notifications about discussions.""" + from lms.djangoapps.course_home_api.permissions import ( # pylint: disable=import-outside-toplevel + CAN_MASQUARADE_LEARNER_PROGRESS, + ) + from lms.djangoapps.courseware.rules import ( # pylint: disable=import-outside-toplevel + HasAccessRule, + HasRolesRule, + ) + from futurex_openedx_extensions.helpers import \ custom_roles # pylint: disable=unused-import, import-outside-toplevel from futurex_openedx_extensions.helpers import \ monkey_patches # pylint: disable=unused-import, import-outside-toplevel from futurex_openedx_extensions.helpers import signals # pylint: disable=unused-import, import-outside-toplevel + if CAN_MASQUARADE_LEARNER_PROGRESS in perms: + del perms[CAN_MASQUARADE_LEARNER_PROGRESS] + perms[CAN_MASQUARADE_LEARNER_PROGRESS] = HasAccessRule('staff') | HasRolesRule('data_researcher') diff --git a/test_utils/edx_platform_mocks_shared/bridgekeeper.py b/test_utils/edx_platform_mocks_shared/bridgekeeper.py new file mode 100644 index 00000000..6dc598a6 --- /dev/null +++ b/test_utils/edx_platform_mocks_shared/bridgekeeper.py @@ -0,0 +1,4 @@ +"""Mock bridgekeeper permission map""" + + +perms = {} diff --git a/test_utils/edx_platform_mocks_shared/lms/djangoapps/course_home_api/permissions.py b/test_utils/edx_platform_mocks_shared/lms/djangoapps/course_home_api/permissions.py new file mode 100644 index 00000000..cb89c93d --- /dev/null +++ b/test_utils/edx_platform_mocks_shared/lms/djangoapps/course_home_api/permissions.py @@ -0,0 +1,3 @@ +"""Mocked course api permissions""" + +CAN_MASQUARADE_LEARNER_PROGRESS = 'fake_name' diff --git a/test_utils/edx_platform_mocks_shared/lms/djangoapps/courseware/rules.py b/test_utils/edx_platform_mocks_shared/lms/djangoapps/courseware/rules.py new file mode 100644 index 00000000..67d16cb1 --- /dev/null +++ b/test_utils/edx_platform_mocks_shared/lms/djangoapps/courseware/rules.py @@ -0,0 +1,30 @@ +"""Mocked bridgekeepr lms rules""" + + +class Rule: + """Mocked Base class for rules.""" + def check(self, user, instance=None): + """Check if a user satisfies this rule.""" + raise NotImplementedError() + + def __or__(self, other): + return True + + +class HasRolesRule(Rule): # pylint: disable=too-few-public-methods + """Mocked HasRolesRule""" + def __init__(self, *roles): + self.roles = roles + + def check(self, user=None, instance=None): + return True + + +class HasAccessRule(Rule): # pylint: disable=too-few-public-methods + """Mocked HasAccessRule""" + + def __init__(self, *roles): + self.roles = roles + + def check(self, user=None, instance=None): + return True