|
12 | 12 |
|
13 | 13 | import logging |
14 | 14 |
|
| 15 | +from django.contrib.auth import get_user_model |
| 16 | +from django.utils.translation import gettext_lazy as _ |
| 17 | + |
15 | 18 | from common.djangoapps.student.roles import ( |
16 | 19 | CourseBetaTesterRole, |
17 | 20 | CourseCcxCoachRole, |
|
21 | 24 | CourseStaffRole, |
22 | 25 | ) |
23 | 26 | from lms.djangoapps.instructor.enrollment import enroll_email, get_email_params |
24 | | -from openedx.core.djangoapps.django_comment_common.models import Role |
| 27 | +from openedx.core.djangoapps.django_comment_common.models import ( |
| 28 | + FORUM_ROLE_ADMINISTRATOR, |
| 29 | + FORUM_ROLE_COMMUNITY_TA, |
| 30 | + FORUM_ROLE_GROUP_MODERATOR, |
| 31 | + FORUM_ROLE_MODERATOR, |
| 32 | + Role, |
| 33 | +) |
25 | 34 |
|
26 | 35 | log = logging.getLogger(__name__) |
27 | 36 |
|
|
34 | 43 | 'data_researcher': CourseDataResearcherRole, |
35 | 44 | } |
36 | 45 |
|
| 46 | +#: Forum/discussion roles managed through :func:`update_forum_role`. |
| 47 | +#: Stored separately from :data:`ROLES` because they use a different |
| 48 | +#: model (``Role`` from django_comment_common) and different helpers. |
| 49 | +FORUM_ROLES = ( |
| 50 | + FORUM_ROLE_ADMINISTRATOR, |
| 51 | + FORUM_ROLE_MODERATOR, |
| 52 | + FORUM_ROLE_GROUP_MODERATOR, |
| 53 | + FORUM_ROLE_COMMUNITY_TA, |
| 54 | +) |
| 55 | + |
| 56 | +ROLE_DISPLAY_NAMES = { |
| 57 | + 'instructor': _('Admin'), |
| 58 | + 'staff': _('Staff'), |
| 59 | + 'limited_staff': _('Limited Staff'), |
| 60 | + 'beta': _('Beta Tester'), |
| 61 | + 'ccx_coach': _('CCX Coach'), |
| 62 | + 'data_researcher': _('Data Researcher'), |
| 63 | + FORUM_ROLE_ADMINISTRATOR: _('Discussion Admin'), |
| 64 | + FORUM_ROLE_MODERATOR: _('Discussion Moderator'), |
| 65 | + FORUM_ROLE_GROUP_MODERATOR: _('Group Moderator'), |
| 66 | + FORUM_ROLE_COMMUNITY_TA: _('Community TA'), |
| 67 | +} |
| 68 | + |
| 69 | + |
| 70 | +def is_forum_role(rolename): |
| 71 | + """Return True if ``rolename`` is a forum/discussion role.""" |
| 72 | + return rolename in FORUM_ROLES |
| 73 | + |
| 74 | + |
| 75 | +def list_forum_members(course_id, rolename): |
| 76 | + """ |
| 77 | + Return a User QuerySet of users holding ``rolename`` forum role for the course. |
| 78 | +
|
| 79 | + Returns an empty QuerySet if the role doesn't exist for the course. |
| 80 | + """ |
| 81 | + try: |
| 82 | + role = Role.objects.get(course_id=course_id, name=rolename) |
| 83 | + except Role.DoesNotExist: |
| 84 | + return get_user_model().objects.none() |
| 85 | + return role.users.all() |
| 86 | + |
37 | 87 |
|
38 | 88 | def list_with_level(course_id, level): |
39 | 89 | """ |
|
0 commit comments