Files
edx-platform/lms/djangoapps/course_wiki/tab.py
Kshitij Sobti 3e05e0f49b feat: add support for enabling/disabling the wiki app (#28889)
Currently the wiki app can't be enabled or configured. This change allows enabling/disabling the wiki app which effectively hides/shows the wiki tab.
2021-10-07 11:04:03 +05:00

45 lines
1.2 KiB
Python

"""
These callables are used by django-wiki to check various permissions
a user has on an article.
"""
from django.conf import settings
from django.utils.translation import ugettext_noop
from lms.djangoapps.courseware.tabs import EnrolledTab
class WikiTab(EnrolledTab):
"""
Defines the Wiki view type that is shown as a course tab.
"""
type = "wiki"
title = ugettext_noop('Wiki')
view_name = "course_wiki"
is_hideable = True
is_default = False
def __init__(self, tab_dict):
# Default to hidden
super().__init__({"is_hidden": True, **tab_dict})
def to_json(self):
json_val = super().to_json()
# Persist that the tab is *not* hidden
if not self.is_hidden:
json_val.update({"is_hidden": False})
return json_val
@classmethod
def is_enabled(cls, course, user=None):
"""
Returns true if the wiki is enabled and the specified user is enrolled or has staff access.
"""
if not settings.WIKI_ENABLED:
return False
if course.allow_public_wiki_access:
return True
return super().is_enabled(course, user=user)