-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Discussion service to enable permission and access provider #37912
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from 6 commits
3c5abde
45239cd
459406c
be10fd9
5a7e796
fb78b42
a461a75
f6d10e5
6718701
4c57989
d381093
e82a3b2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,49 @@ | ||||||
| """ | ||||||
| Discussion Configuration Service for XBlock runtime. | ||||||
|
|
||||||
| This service provides discussion-related configuration and feature flags | ||||||
| that are specific to the edx-platform implementation | ||||||
| for the extracted discussion block in xblocks-contrib repository. | ||||||
| """ | ||||||
|
|
||||||
| from edx_django_utils.cache import DEFAULT_REQUEST_CACHE | ||||||
| from opaque_keys.edx.keys import CourseKey | ||||||
|
|
||||||
| from django.conf import settings | ||||||
| from openedx.core.djangoapps.django_comment_common.models import ( | ||||||
| all_permissions_for_user_in_course | ||||||
| ) | ||||||
| from openedx.core.djangoapps.discussions.models import DiscussionsConfiguration, Provider | ||||||
|
|
||||||
|
|
||||||
| class DiscussionConfigService: | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The method bodies look good. Could you add type annotations to all the args and return values? Check out the new VideoConfigService for an example. |
||||||
| """ | ||||||
| Service for providing video-related configuration and feature flags. | ||||||
| """ | ||||||
|
|
||||||
| def has_permission(self, user, permission, course_id=None): # lint-amnesty, pylint: disable=missing-function-docstring | ||||||
|
||||||
| assert isinstance(course_id, (type(None), CourseKey)) | ||||||
| request_cache_dict = DEFAULT_REQUEST_CACHE.data | ||||||
| cache_key = "django_comment_client.permissions.has_permission.all_permissions.{}.{}".format( | ||||||
| user.id, course_id | ||||||
| ) | ||||||
| if cache_key in request_cache_dict: | ||||||
| all_permissions = request_cache_dict[cache_key] | ||||||
| else: | ||||||
| all_permissions = all_permissions_for_user_in_course(user, course_id) | ||||||
| request_cache_dict[cache_key] = all_permissions | ||||||
|
|
||||||
| return permission in all_permissions | ||||||
|
|
||||||
| def is_discussion_visible(self, course_key): | ||||||
| """ | ||||||
| Discussion Xblock does not support new OPEN_EDX provider | ||||||
| """ | ||||||
| provider = DiscussionsConfiguration.get(course_key) | ||||||
| return provider.provider_type == Provider.LEGACY | ||||||
|
|
||||||
| def is_discussion_enabled(self): | ||||||
| """ | ||||||
| Return True if discussions are enabled; else False | ||||||
| """ | ||||||
| return settings.FEATURES.get('ENABLE_DISCUSSION_SERVICE') | ||||||
|
||||||
| return settings.FEATURES.get('ENABLE_DISCUSSION_SERVICE') | |
| return settings.ENABLE_DISCUSSION_SERVICE |
FEATURES items can now be accessed directly on the settings object. This is preferrable because you will get an exception or linter warning if the setting is misspelled or later removed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will this service be needed to edit courses/discussions in studio? If so, we'll need to add it to load_services_for_studio too. If not, then this is fine.