Files
edx-platform/lms/djangoapps/teams/plugins.py
Kshitij Sobti d2c2fcdefe feat: Course Apps API [BD-38] [TNL-8103] [BB-2716] (#27542)
* feat: Course Apps API

This adds a new concept called course apps. These are exposed via a new
"openedx.course_app" entrypoint, which helps the LMS and studio discover such
apps and list them in a new rest api for the same.

These course apps will drive the pages and resources view in the course authoring
MFE. This system will track which apps are enabled and which are disabled. It
also allows third-party apps to be listed here by using the plugin entrypoint.

* Apply feedback from review
2021-06-23 21:51:12 +05:00

76 lines
2.1 KiB
Python

"""
Definition of the course team feature.
"""
from typing import Dict, Optional
from django.conf import settings
from django.contrib.auth import get_user_model
from django.utils.translation import ugettext_noop as _
from opaque_keys.edx.keys import CourseKey
from lms.djangoapps.courseware.tabs import EnrolledTab
from openedx.core.djangoapps.content.course_overviews.models import CourseOverview
from openedx.core.djangoapps.course_apps.plugins import CourseApp
from . import is_feature_enabled
User = get_user_model()
class TeamsTab(EnrolledTab):
"""
The representation of the course teams view type.
"""
type = "teams"
title = _("Teams")
view_name = "teams_dashboard"
@classmethod
def is_enabled(cls, course, user=None):
"""Returns true if the teams feature is enabled in the course.
Args:
course (CourseBlock): the course using the feature
user (User): the user interacting with the course
"""
if not super().is_enabled(course, user=user):
return False
return is_feature_enabled(course)
class TeamsCourseApp(CourseApp):
"""
Course app for teams.
"""
app_id = "teams"
name = _("Teams")
description = _("Leverage teams to allow learners to connect by topic of interest.")
@classmethod
def is_available(cls, course_key: CourseKey) -> bool:
"""
The teams app is currently available globally based on a feature setting.
"""
return settings.FEATURES.get("ENABLE_TEAMS", False)
@classmethod
def is_enabled(cls, course_key: CourseKey) -> bool:
return CourseOverview.get_from_id(course_key).teams_enabled
@classmethod
def set_enabled(cls, course_key: CourseKey, enabled: bool, user: User) -> bool:
raise ValueError("Teams cannot be enabled/disabled via this API.")
@classmethod
def get_allowed_operations(cls, course_key: CourseKey, user: Optional[User] = None) -> Dict[str, bool]:
"""
Return allowed operations for teams app.
"""
return {
"enable": False,
"configure": True,
}