Skip to content

Commit

Permalink
feat: override course api perm to give data researcher progress page …
Browse files Browse the repository at this point in the history
…access
  • Loading branch information
tehreem-sadat committed Jan 7, 2025
1 parent 7f6318c commit 5b07eae
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 0 deletions.
12 changes: 12 additions & 0 deletions futurex_openedx_extensions/helpers/apps.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""helpers Django application initialization"""
from __future__ import annotations

from bridgekeeper import perms
from django.apps import AppConfig


Expand Down Expand Up @@ -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')
4 changes: 4 additions & 0 deletions test_utils/edx_platform_mocks_shared/bridgekeeper.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
"""Mock bridgekeeper permission map"""


perms = {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
"""Mocked course api permissions"""

CAN_MASQUARADE_LEARNER_PROGRESS = 'fake_name'
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 5b07eae

Please sign in to comment.