Commit e6384b92 by Martyn James Committed by Jonathan Piacenti

Added new assistant role

parent 79405d9a
......@@ -273,6 +273,14 @@ class CourseBetaTesterRole(CourseRole):
super(CourseBetaTesterRole, self).__init__(self.ROLE, *args, **kwargs)
class CourseAssistantRole(CourseRole):
"""A course assistant"""
ROLE = 'assistant'
def __init__(self, *args, **kwargs):
super(CourseAssistantRole, self).__init__(self.ROLE, *args, **kwargs)
@register_access_role
class LibraryUserRole(CourseRole):
"""
......
......@@ -7,7 +7,7 @@ from django.test import TestCase
from django.contrib.auth.models import User, AnonymousUser
from django.core.exceptions import PermissionDenied
from student.roles import CourseInstructorRole, CourseStaffRole, CourseCreatorRole
from student.roles import CourseInstructorRole, CourseStaffRole, CourseCreatorRole, CourseAssistantRole
from student.tests.factories import AdminFactory
from student.auth import has_access, add_users, remove_users
from opaque_keys.edx.locations import SlashSeparatedCourseKey
......@@ -143,6 +143,7 @@ class CourseGroupTest(TestCase):
self.global_admin = AdminFactory()
self.creator = User.objects.create_user('testcreator', 'testcreator+courses@edx.org', 'foo')
self.staff = User.objects.create_user('teststaff', 'teststaff+courses@edx.org', 'foo')
self.assistant = User.objects.create_user('testassistant', 'testta+courses@edx.org', 'foo')
self.course_key = SlashSeparatedCourseKey('mitX', '101', 'test')
def test_add_user_to_course_group(self):
......@@ -160,6 +161,11 @@ class CourseGroupTest(TestCase):
add_users(self.creator, CourseStaffRole(self.course_key), self.staff)
self.assertTrue(has_access(self.staff, CourseStaffRole(self.course_key)))
# Add another user to the TA role
self.assertFalse(has_access(self.assistant, CourseAssistantRole(self.course_key)))
add_users(self.creator, CourseAssistantRole(self.course_key), self.assistant)
self.assertTrue(has_access(self.assistant, CourseAssistantRole(self.course_key)))
def test_add_user_to_course_group_permission_denied(self):
"""
Verifies PermissionDenied if caller of add_user_to_course_group is not instructor role.
......@@ -168,6 +174,8 @@ class CourseGroupTest(TestCase):
add_users(self.global_admin, CourseStaffRole(self.course_key), self.creator)
with self.assertRaises(PermissionDenied):
add_users(self.staff, CourseStaffRole(self.course_key), self.staff)
with self.assertRaises(PermissionDenied):
add_users(self.assistant, CourseAssistantRole(self.course_key), self.assistant)
def test_remove_user_from_course_group(self):
"""
......@@ -182,6 +190,12 @@ class CourseGroupTest(TestCase):
remove_users(self.creator, CourseStaffRole(self.course_key), self.staff)
self.assertFalse(has_access(self.staff, CourseStaffRole(self.course_key)))
add_users(self.creator, CourseAssistantRole(self.course_key), self.assistant)
self.assertTrue(has_access(self.assistant, CourseAssistantRole(self.course_key)))
remove_users(self.creator, CourseAssistantRole(self.course_key), self.assistant)
self.assertFalse(has_access(self.assistant, CourseAssistantRole(self.course_key)))
remove_users(self.creator, CourseInstructorRole(self.course_key), self.creator)
self.assertFalse(has_access(self.creator, CourseInstructorRole(self.course_key)))
......@@ -194,3 +208,5 @@ class CourseGroupTest(TestCase):
add_users(self.global_admin, CourseStaffRole(self.course_key), self.creator, self.staff, another_staff)
with self.assertRaises(PermissionDenied):
remove_users(self.staff, CourseStaffRole(self.course_key), another_staff)
with self.assertRaises(PermissionDenied):
remove_users(self.assistant, CourseAssistantRole(self.course_key), another_staff)
......@@ -25,7 +25,7 @@ from django_comment_common.models import FORUM_ROLE_MODERATOR
from gradebook.models import StudentGradebook
from instructor.access import revoke_access, update_forum_role
from student.models import CourseEnrollment, CourseEnrollmentAllowed
from student.roles import CourseRole, CourseAccessRole, CourseInstructorRole, CourseStaffRole, CourseObserverRole, UserBasedRole
from student.roles import CourseRole, CourseAccessRole, CourseInstructorRole, CourseStaffRole, CourseObserverRole, CourseAssistantRole, UserBasedRole
from xmodule.modulestore.django import modulestore
......@@ -289,8 +289,8 @@ def _manage_role(course_descriptor, user, role, action):
"""
Helper method for managing course/forum roles
"""
supported_roles = ('instructor', 'staff', 'observer')
forum_moderator_roles = ('instructor', 'staff')
supported_roles = ('instructor', 'staff', 'observer', 'assistant')
forum_moderator_roles = ('instructor', 'staff', 'assistant')
if role not in supported_roles:
raise ValueError
if action is 'allow':
......@@ -309,7 +309,8 @@ def _manage_role(course_descriptor, user, role, action):
# Before we can safely remove the corresponding forum moderator role
user_instructor_courses = UserBasedRole(user, CourseInstructorRole.ROLE).courses_with_role()
user_staff_courses = UserBasedRole(user, CourseStaffRole.ROLE).courses_with_role()
queryset = user_instructor_courses | user_staff_courses
user_assistant_courses = UserBasedRole(user, CourseAssistantRole.ROLE).courses_with_role()
queryset = user_instructor_courses | user_staff_courses | user_assistant_courses
queryset = queryset.filter(course_id=course_descriptor.id)
if len(queryset) == 0:
update_forum_role(course_descriptor.id, user, FORUM_ROLE_MODERATOR, 'revoke')
......@@ -1768,6 +1769,10 @@ class CoursesRolesList(SecureAPIView):
for observer in observers:
response_data.append({'id': observer.id, 'role': 'observer'})
assistants = CourseAssistantRole(course_key).users_with_role()
for assistant in assistants:
response_data.append({'id': assistant.id, 'role': 'assistant'})
user_id = self.request.QUERY_PARAMS.get('user_id', None)
if user_id:
response_data = list([item for item in response_data if int(item['id']) == int(user_id)])
......
......@@ -26,7 +26,7 @@ from lms.lib.comment_client.utils import CommentClientRequestError
from opaque_keys.edx.locations import SlashSeparatedCourseKey
from student.models import CourseEnrollment, PasswordHistory, UserProfile
from openedx.core.djangoapps.user_api.models import UserPreference
from student.roles import CourseAccessRole, CourseInstructorRole, CourseObserverRole, CourseStaffRole, UserBasedRole
from student.roles import CourseAccessRole, CourseInstructorRole, CourseObserverRole, CourseStaffRole, CourseAssistantRole, UserBasedRole
from util.bad_request_rate_limiter import BadRequestRateLimiter
from util.password_policy_validators import (
validate_password_length, validate_password_complexity,
......@@ -132,8 +132,8 @@ def _manage_role(course_descriptor, user, role, action):
"""
Helper method for managing course/forum roles
"""
supported_roles = ('instructor', 'staff', 'observer')
forum_moderator_roles = ('instructor', 'staff')
supported_roles = ('instructor', 'staff', 'observer', 'assistant')
forum_moderator_roles = ('instructor', 'staff', 'assistant')
if role not in supported_roles:
raise ValueError
if action is 'allow':
......@@ -161,7 +161,8 @@ def _manage_role(course_descriptor, user, role, action):
# Before we can safely remove the corresponding forum moderator role
user_instructor_courses = UserBasedRole(user, CourseInstructorRole.ROLE).courses_with_role()
user_staff_courses = UserBasedRole(user, CourseStaffRole.ROLE).courses_with_role()
queryset = user_instructor_courses | user_staff_courses
user_assistant_courses = UserBasedRole(user, CourseAssistantRole.ROLE).courses_with_role()
queryset = user_instructor_courses | user_staff_courses | user_assistant_courses
queryset = queryset.filter(course_id=course_descriptor.id)
if len(queryset) == 0:
try:
......@@ -1221,7 +1222,8 @@ class UsersRolesList(SecureListAPIView):
instructor_courses = UserBasedRole(user, CourseInstructorRole.ROLE).courses_with_role()
staff_courses = UserBasedRole(user, CourseStaffRole.ROLE).courses_with_role()
observer_courses = UserBasedRole(user, CourseObserverRole.ROLE).courses_with_role()
queryset = instructor_courses | staff_courses | observer_courses
assistant_courses = UserBasedRole(user, CourseAssistantRole.ROLE).courses_with_role()
queryset = instructor_courses | staff_courses | observer_courses | assistant_courses
course_id = self.request.QUERY_PARAMS.get('course_id', None)
if course_id:
......
......@@ -18,6 +18,7 @@ from student.roles import (
CourseCcxCoachRole,
CourseStaffRole,
CourseObserverRole,
CourseAssistantRole,
)
log = logging.getLogger(__name__)
......@@ -28,6 +29,7 @@ ROLES = {
'observer': CourseObserverRole,
'staff': CourseStaffRole,
'ccx_coach': CourseCcxCoachRole,
'assistant': CourseAssistantRole,
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment