Final official name is Custom Courses for EdX (CCX), rename all code to remove previous name. Rename the FEATURE constant used to identify this feature Rename the middleware for the CCX change rename the constant used for storing the current poc id on the session. rename the _PocContext threading local rename the override provider in all places where it is referenced `PersonalOnlineCoursesOverrideProvider` -> `CustomCoursesForEdxOverrideProvider` generally rename symbols from overrides.py to replace `poc` with `ccx` where possible without changing model names or attributes rename more symbols from poc to ccx rename util functions from app utils module general symbol renaming poc -> ccx in views.py and related url changes Rename the coach role wherever it is used. reword poc_coach to ccx_coach UI rename replace POC with CCX globally template context variable renamed rename poc_ to ccx_ in urls and all related locations (views, js, scss etc) remove pocs migrations Final massive renaming, including models. Re-built migration. cleaning up a few tailing references Fix reference typo in schedule template JS undo modifications made on the fly in test setup to ensure that our tests are properly isolated from the rest of the system tests. Fixes jazkarta/edx-platform#38 Clean up some leftover strings and comments fixing more strings and comments in python files fix a naming error in the schedule tab that was causing problems in deleting courseware items. Fixes jazkarta/edx-platform#36 updating tests and utility code to match changes in infrastructure from latest rebase
103 lines
2.6 KiB
Python
103 lines
2.6 KiB
Python
"""
|
|
Access control operations for use by instructor APIs.
|
|
|
|
Does not include any access control, be sure to check access before calling.
|
|
|
|
TO DO sync instructor and staff flags
|
|
e.g. should these be possible?
|
|
{instructor: true, staff: false}
|
|
{instructor: true, staff: true}
|
|
"""
|
|
|
|
import logging
|
|
from django_comment_common.models import Role
|
|
|
|
from student.roles import (
|
|
CourseBetaTesterRole,
|
|
CourseInstructorRole,
|
|
CourseCcxCoachRole,
|
|
CourseStaffRole,
|
|
)
|
|
|
|
|
|
log = logging.getLogger(__name__)
|
|
|
|
ROLES = {
|
|
'beta': CourseBetaTesterRole,
|
|
'instructor': CourseInstructorRole,
|
|
'staff': CourseStaffRole,
|
|
'ccx_coach': CourseCcxCoachRole,
|
|
}
|
|
|
|
|
|
def list_with_level(course, level):
|
|
"""
|
|
List users who have 'level' access.
|
|
|
|
`level` is in ['instructor', 'staff', 'beta'] for standard courses.
|
|
There could be other levels specific to the course.
|
|
If there is no Group for that course-level, returns an empty list
|
|
"""
|
|
return ROLES[level](course.id).users_with_role()
|
|
|
|
|
|
def allow_access(course, user, level):
|
|
"""
|
|
Allow user access to course modification.
|
|
|
|
`level` is one of ['instructor', 'staff', 'beta']
|
|
"""
|
|
_change_access(course, user, level, 'allow')
|
|
|
|
|
|
def revoke_access(course, user, level):
|
|
"""
|
|
Revoke access from user to course modification.
|
|
|
|
`level` is one of ['instructor', 'staff', 'beta']
|
|
"""
|
|
_change_access(course, user, level, 'revoke')
|
|
|
|
|
|
def _change_access(course, user, level, action):
|
|
"""
|
|
Change access of user.
|
|
|
|
`level` is one of ['instructor', 'staff', 'beta']
|
|
action is one of ['allow', 'revoke']
|
|
|
|
NOTE: will create a group if it does not yet exist.
|
|
"""
|
|
|
|
try:
|
|
role = ROLES[level](course.id)
|
|
except KeyError:
|
|
raise ValueError("unrecognized level '{}'".format(level))
|
|
|
|
if action == 'allow':
|
|
role.add_users(user)
|
|
elif action == 'revoke':
|
|
role.remove_users(user)
|
|
else:
|
|
raise ValueError("unrecognized action '{}'".format(action))
|
|
|
|
|
|
def update_forum_role(course_id, user, rolename, action):
|
|
"""
|
|
Change forum access of user.
|
|
|
|
`rolename` is one of [FORUM_ROLE_ADMINISTRATOR, FORUM_ROLE_MODERATOR, FORUM_ROLE_COMMUNITY_TA]
|
|
`action` is one of ['allow', 'revoke']
|
|
|
|
if `action` is bad, raises ValueError
|
|
if `rolename` does not exist, raises Role.DoesNotExist
|
|
"""
|
|
role = Role.objects.get(course_id=course_id, name=rolename)
|
|
|
|
if action == 'allow':
|
|
role.users.add(user)
|
|
elif action == 'revoke':
|
|
role.users.remove(user)
|
|
else:
|
|
raise ValueError("unrecognized action '{}'".format(action))
|