From 25fe59188d512bdeec46a5c983a122c5bd1caece Mon Sep 17 00:00:00 2001 From: AhtishamShahid Date: Mon, 24 Jul 2023 14:19:48 +0500 Subject: [PATCH 1/5] fix: use student role for zoom in case of global staff. --- .../core/djangoapps/course_live/plugins.py | 2 +- openedx/core/djangoapps/course_live/tab.py | 32 ++++++++++++++----- 2 files changed, 25 insertions(+), 9 deletions(-) diff --git a/openedx/core/djangoapps/course_live/plugins.py b/openedx/core/djangoapps/course_live/plugins.py index 4ef546a22887..fbb85a1d1b9f 100644 --- a/openedx/core/djangoapps/course_live/plugins.py +++ b/openedx/core/djangoapps/course_live/plugins.py @@ -44,7 +44,7 @@ def is_enabled(cls, course_key: CourseKey) -> bool: return CourseLiveConfiguration.is_enabled(course_key) @classmethod - def set_enabled(cls, course_key: CourseKey, enabled: bool, user: 'User') -> bool: + def set_enabled(cls, course_key: CourseKey, enabled: bool, user: User) -> bool: """ Set live enabled status in CourseLiveConfiguration model. """ diff --git a/openedx/core/djangoapps/course_live/tab.py b/openedx/core/djangoapps/course_live/tab.py index 34bcc8ba1655..31eb5658441e 100644 --- a/openedx/core/djangoapps/course_live/tab.py +++ b/openedx/core/djangoapps/course_live/tab.py @@ -1,20 +1,21 @@ """ Configurations to render Course Live Tab """ +from django.contrib.auth.base_user import AbstractBaseUser from django.utils.translation import gettext_lazy from lti_consumer.models import LtiConfiguration +from opaque_keys.edx.keys import CourseKey - -from common.djangoapps.student.roles import CourseStaffRole, CourseInstructorRole -from xmodule.course_block import CourseBlock -from xmodule.tabs import TabFragmentViewMixin +from common.djangoapps.student.roles import CourseInstructorRole, CourseStaffRole, GlobalStaff from lms.djangoapps.courseware.tabs import EnrolledTab from openedx.core.djangoapps.course_live.config.waffle import ENABLE_COURSE_LIVE from openedx.core.djangoapps.course_live.models import CourseLiveConfiguration -from openedx.core.djangoapps.course_live.providers import ProviderManager, HasGlobalCredentials +from openedx.core.djangoapps.course_live.providers import HasGlobalCredentials, ProviderManager from openedx.core.lib.cache_utils import request_cached from openedx.features.course_experience.url_helpers import get_learning_mfe_home_url from openedx.features.lti_course_tab.tab import LtiCourseLaunchMixin +from xmodule.course_block import CourseBlock +from xmodule.tabs import TabFragmentViewMixin class CourseLiveTab(LtiCourseLaunchMixin, TabFragmentViewMixin, EnrolledTab): @@ -79,9 +80,24 @@ def _get_pii_lti_parameters(self, course, request): course_live_configurations = CourseLiveConfiguration.get(course.id) if course_live_configurations: provider_type = course_live_configurations.provider_type - - if provider_type == 'zoom' and (CourseStaffRole(course.id).has_user(request.user) or - CourseInstructorRole(course.id).has_user(request.user)): + if ( + provider_type == 'zoom' and + ( + CourseStaffRole(course.id).has_user(request.user) or + CourseInstructorRole(course.id).has_user(request.user) + ) + ): pii_config['person_contact_email_primary'] = request.user.email return pii_config + + def _get_lti_roles(self, user: AbstractBaseUser, course_key: CourseKey) -> str: + """ + Get LTI roles for the user and course. + If the user is a global staff member, return the student role. + """ + course_live_configurations = CourseLiveConfiguration.get(course_key) + provider_type = course_live_configurations.provider_type + if provider_type == "zoom" and GlobalStaff().has_user(user): + return self.ROLE_MAP.get('student') + return super()._get_lti_roles(user, course_key) From 2c079f19727da3c0d30ca8b59a4b0b8d042ceca1 Mon Sep 17 00:00:00 2001 From: AhtishamShahid Date: Mon, 24 Jul 2023 14:36:32 +0500 Subject: [PATCH 2/5] fix: use student role for zoom in case of global staff. --- openedx/core/djangoapps/course_live/tab.py | 35 ++++++++++++---------- 1 file changed, 19 insertions(+), 16 deletions(-) diff --git a/openedx/core/djangoapps/course_live/tab.py b/openedx/core/djangoapps/course_live/tab.py index 31eb5658441e..39f171f2d533 100644 --- a/openedx/core/djangoapps/course_live/tab.py +++ b/openedx/core/djangoapps/course_live/tab.py @@ -18,6 +18,23 @@ from xmodule.tabs import TabFragmentViewMixin +def provider_is_zoom(course: CourseBlock) -> bool: + """ + Check if the provider exists and is Zoom. + """ + course_live_configurations = CourseLiveConfiguration.get(course.id) + if not course_live_configurations: + return False + return course_live_configurations.provider_type == "zoom" + + +def user_is_staff_or_instructor(user: AbstractBaseUser, course: CourseBlock) -> bool: + """ + Check if the user is a staff or instructor for the course. + """ + return CourseStaffRole(course.id).has_user(user) or CourseInstructorRole(course.id).has_user(user) + + class CourseLiveTab(LtiCourseLaunchMixin, TabFragmentViewMixin, EnrolledTab): """ Course tab that loads the associated LTI-based live provider in a tab. @@ -75,20 +92,8 @@ def is_enabled(cls, course, user=None): def _get_pii_lti_parameters(self, course, request): pii_config = super()._get_pii_lti_parameters(course, request) - provider_type = '' - - course_live_configurations = CourseLiveConfiguration.get(course.id) - if course_live_configurations: - provider_type = course_live_configurations.provider_type - if ( - provider_type == 'zoom' and - ( - CourseStaffRole(course.id).has_user(request.user) or - CourseInstructorRole(course.id).has_user(request.user) - ) - ): + if provider_is_zoom(course) and user_is_staff_or_instructor(request.user, course): pii_config['person_contact_email_primary'] = request.user.email - return pii_config def _get_lti_roles(self, user: AbstractBaseUser, course_key: CourseKey) -> str: @@ -96,8 +101,6 @@ def _get_lti_roles(self, user: AbstractBaseUser, course_key: CourseKey) -> str: Get LTI roles for the user and course. If the user is a global staff member, return the student role. """ - course_live_configurations = CourseLiveConfiguration.get(course_key) - provider_type = course_live_configurations.provider_type - if provider_type == "zoom" and GlobalStaff().has_user(user): + if provider_is_zoom and GlobalStaff().has_user(user): return self.ROLE_MAP.get('student') return super()._get_lti_roles(user, course_key) From 88af3248b2a648191eb7b9cd2fdcd9ca4c7af442 Mon Sep 17 00:00:00 2001 From: AhtishamShahid Date: Mon, 24 Jul 2023 14:40:03 +0500 Subject: [PATCH 3/5] fix: added request cache to avoid duplicate db calls. --- openedx/core/djangoapps/course_live/tab.py | 1 + 1 file changed, 1 insertion(+) diff --git a/openedx/core/djangoapps/course_live/tab.py b/openedx/core/djangoapps/course_live/tab.py index 39f171f2d533..cc52ceeb12a3 100644 --- a/openedx/core/djangoapps/course_live/tab.py +++ b/openedx/core/djangoapps/course_live/tab.py @@ -18,6 +18,7 @@ from xmodule.tabs import TabFragmentViewMixin +@request_cached() def provider_is_zoom(course: CourseBlock) -> bool: """ Check if the provider exists and is Zoom. From efbd79bd9c13749a88c0cfed4d290c0d7227a1ee Mon Sep 17 00:00:00 2001 From: AhtishamShahid Date: Tue, 25 Jul 2023 14:46:04 +0500 Subject: [PATCH 4/5] fix: updated method declaration --- openedx/core/djangoapps/course_live/tab.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/openedx/core/djangoapps/course_live/tab.py b/openedx/core/djangoapps/course_live/tab.py index cc52ceeb12a3..296677cbaf0b 100644 --- a/openedx/core/djangoapps/course_live/tab.py +++ b/openedx/core/djangoapps/course_live/tab.py @@ -19,11 +19,14 @@ @request_cached() -def provider_is_zoom(course: CourseBlock) -> bool: +def provider_is_zoom(course: CourseBlock, course_key=None) -> bool: """ Check if the provider exists and is Zoom. """ - course_live_configurations = CourseLiveConfiguration.get(course.id) + if not course_key: + course_key = course.id + course_live_configurations = CourseLiveConfiguration.get(course_key) + if not course_live_configurations: return False return course_live_configurations.provider_type == "zoom" @@ -102,6 +105,6 @@ def _get_lti_roles(self, user: AbstractBaseUser, course_key: CourseKey) -> str: Get LTI roles for the user and course. If the user is a global staff member, return the student role. """ - if provider_is_zoom and GlobalStaff().has_user(user): + if provider_is_zoom(course_key=course_key) and GlobalStaff().has_user(user): return self.ROLE_MAP.get('student') return super()._get_lti_roles(user, course_key) From e16e30d5daee636e52bc5ac253389a292cb92abb Mon Sep 17 00:00:00 2001 From: AhtishamShahid Date: Tue, 25 Jul 2023 15:05:58 +0500 Subject: [PATCH 5/5] fix: updated method declaration --- openedx/core/djangoapps/course_live/tab.py | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/openedx/core/djangoapps/course_live/tab.py b/openedx/core/djangoapps/course_live/tab.py index 296677cbaf0b..3fe7a64587c8 100644 --- a/openedx/core/djangoapps/course_live/tab.py +++ b/openedx/core/djangoapps/course_live/tab.py @@ -19,12 +19,10 @@ @request_cached() -def provider_is_zoom(course: CourseBlock, course_key=None) -> bool: +def provider_is_zoom(course_key: CourseKey) -> bool: """ Check if the provider exists and is Zoom. """ - if not course_key: - course_key = course.id course_live_configurations = CourseLiveConfiguration.get(course_key) if not course_live_configurations: @@ -96,7 +94,7 @@ def is_enabled(cls, course, user=None): def _get_pii_lti_parameters(self, course, request): pii_config = super()._get_pii_lti_parameters(course, request) - if provider_is_zoom(course) and user_is_staff_or_instructor(request.user, course): + if provider_is_zoom(course.id) and user_is_staff_or_instructor(request.user, course): pii_config['person_contact_email_primary'] = request.user.email return pii_config @@ -105,6 +103,6 @@ def _get_lti_roles(self, user: AbstractBaseUser, course_key: CourseKey) -> str: Get LTI roles for the user and course. If the user is a global staff member, return the student role. """ - if provider_is_zoom(course_key=course_key) and GlobalStaff().has_user(user): + if provider_is_zoom(course_key) and GlobalStaff().has_user(user): return self.ROLE_MAP.get('student') return super()._get_lti_roles(user, course_key)