Make course ids and usage ids opaque to LMS and Studio [partial commit]
This commit updates common/djangoapps. These keys are now objects with a limited interface, and the particular internal representation is managed by the data storage layer (the modulestore). For the LMS, there should be no outward-facing changes to the system. The keys are, for now, a change to internal representation only. For Studio, the new serialized form of the keys is used in urls, to allow for further migration in the future. Co-Author: Andy Armstrong <andya@edx.org> Co-Author: Christina Roberts <christina@edx.org> Co-Author: David Baumgold <db@edx.org> Co-Author: Diana Huang <dkh@edx.org> Co-Author: Don Mitchell <dmitchell@edx.org> Co-Author: Julia Hansbrough <julia@edx.org> Co-Author: Nimisha Asthagiri <nasthagiri@edx.org> Co-Author: Sarina Canelake <sarina@edx.org> [LMS-2370]
This commit is contained in:
@@ -9,7 +9,8 @@ from django.utils.translation import ugettext_noop
|
||||
from student.models import CourseEnrollment
|
||||
|
||||
from xmodule.modulestore.django import modulestore
|
||||
from xmodule.course_module import CourseDescriptor
|
||||
from xmodule.modulestore.exceptions import ItemNotFoundError
|
||||
from xmodule_django.models import CourseKeyField, NoneToEmptyManager
|
||||
|
||||
FORUM_ROLE_ADMINISTRATOR = ugettext_noop('Administrator')
|
||||
FORUM_ROLE_MODERATOR = ugettext_noop('Moderator')
|
||||
@@ -48,16 +49,20 @@ def assign_default_role(course_id, user):
|
||||
|
||||
|
||||
class Role(models.Model):
|
||||
|
||||
objects = NoneToEmptyManager()
|
||||
|
||||
name = models.CharField(max_length=30, null=False, blank=False)
|
||||
users = models.ManyToManyField(User, related_name="roles")
|
||||
course_id = models.CharField(max_length=255, blank=True, db_index=True)
|
||||
course_id = CourseKeyField(max_length=255, blank=True, db_index=True)
|
||||
|
||||
class Meta:
|
||||
# use existing table that was originally created from django_comment_client app
|
||||
db_table = 'django_comment_client_role'
|
||||
|
||||
def __unicode__(self):
|
||||
return self.name + " for " + (self.course_id if self.course_id else "all courses")
|
||||
# pylint: disable=no-member
|
||||
return self.name + " for " + (self.course_id.to_deprecated_string() if self.course_id else "all courses")
|
||||
|
||||
def inherit_permissions(self, role): # TODO the name of this method is a little bit confusing,
|
||||
# since it's one-off and doesn't handle inheritance later
|
||||
@@ -71,8 +76,9 @@ class Role(models.Model):
|
||||
self.permissions.add(Permission.objects.get_or_create(name=permission)[0])
|
||||
|
||||
def has_permission(self, permission):
|
||||
course_loc = CourseDescriptor.id_to_location(self.course_id)
|
||||
course = modulestore().get_instance(self.course_id, course_loc)
|
||||
course = modulestore().get_course(self.course_id)
|
||||
if course is None:
|
||||
raise ItemNotFoundError(self.course_id)
|
||||
if self.name == FORUM_ROLE_STUDENT and \
|
||||
(permission.startswith('edit') or permission.startswith('update') or permission.startswith('create')) and \
|
||||
(not course.forum_posts_allowed):
|
||||
|
||||
Reference in New Issue
Block a user