Commit 935d5dee by Don Mitchell Committed by Nimisha Asthagiri

LMS-11331, LMS-11345 Make auth check branch agnostic; fix deserialize keys

parent 3a772752
...@@ -20,7 +20,8 @@ def has_course_access(user, course_key, role=CourseStaffRole): ...@@ -20,7 +20,8 @@ def has_course_access(user, course_key, role=CourseStaffRole):
return True return True
if OrgStaffRole(org=course_key.org).has_user(user): if OrgStaffRole(org=course_key.org).has_user(user):
return True return True
return auth.has_access(user, role(course_key)) # temporary to ensure we give universal access given a course until we impl branch specific perms
return auth.has_access(user, role(course_key.for_branch(None)))
def get_user_role(user, course_id): def get_user_role(user, course_id):
......
...@@ -2101,7 +2101,8 @@ class SplitMongoModuleStore(SplitBulkWriteMixin, ModuleStoreWriteBase): ...@@ -2101,7 +2101,8 @@ class SplitMongoModuleStore(SplitBulkWriteMixin, ModuleStoreWriteBase):
def _serialize_fields(self, category, fields): def _serialize_fields(self, category, fields):
""" """
Convert any references to their serialized form. Convert any references to their serialized form. Handle some references already being unicoded
because the client passed them that way and nothing above this layer did the necessary deserialization.
Remove any fields which split or its kvs computes or adds but does not want persisted. Remove any fields which split or its kvs computes or adds but does not want persisted.
...@@ -2111,17 +2112,26 @@ class SplitMongoModuleStore(SplitBulkWriteMixin, ModuleStoreWriteBase): ...@@ -2111,17 +2112,26 @@ class SplitMongoModuleStore(SplitBulkWriteMixin, ModuleStoreWriteBase):
xblock_class = XBlock.load_class(category, self.default_class) xblock_class = XBlock.load_class(category, self.default_class)
xblock_class = self.mixologist.mix(xblock_class) xblock_class = self.mixologist.mix(xblock_class)
def reference_block_id(reference):
"""
Handle client possibly setting field to strings rather than keys to get the block_id
"""
# perhaps replace by fixing the views or Field Reference*.from_json to return a Key
if isinstance(reference, basestring):
reference = BlockUsageLocator.from_string(reference)
return BlockKey.from_usage_key(reference)
for field_name, value in fields.iteritems(): for field_name, value in fields.iteritems():
if value is not None: if value is not None:
if isinstance(xblock_class.fields[field_name], Reference): if isinstance(xblock_class.fields[field_name], Reference):
fields[field_name] = BlockKey.from_usage_key(value) fields[field_name] = reference_block_id(value)
elif isinstance(xblock_class.fields[field_name], ReferenceList): elif isinstance(xblock_class.fields[field_name], ReferenceList):
fields[field_name] = [ fields[field_name] = [
BlockKey.from_usage_key(ele) for ele in value reference_block_id(ele) for ele in value
] ]
elif isinstance(xblock_class.fields[field_name], ReferenceValueDict): elif isinstance(xblock_class.fields[field_name], ReferenceValueDict):
for key, subvalue in value.iteritems(): for key, subvalue in value.iteritems():
value[key] = BlockKey.from_usage_key(subvalue) value[key] = reference_block_id(subvalue)
# should this recurse down dicts and lists just in case they contain datetime? # should this recurse down dicts and lists just in case they contain datetime?
elif not isinstance(value, datetime.datetime): # don't convert datetimes! elif not isinstance(value, datetime.datetime): # don't convert datetimes!
fields[field_name] = xblock_class.fields[field_name].to_json(value) fields[field_name] = xblock_class.fields[field_name].to_json(value)
......
...@@ -12,7 +12,6 @@ from collections import namedtuple ...@@ -12,7 +12,6 @@ from collections import namedtuple
from path import path from path import path
from lazy import lazy from lazy import lazy
from opaque_keys.edx.keys import CourseKey from opaque_keys.edx.keys import CourseKey
from opaque_keys.edx.locator import CourseLocator
from . import STUDIO_BASE_URL from . import STUDIO_BASE_URL
...@@ -272,7 +271,11 @@ class CourseFixture(StudioApiFixture): ...@@ -272,7 +271,11 @@ class CourseFixture(StudioApiFixture):
Return the locator string for the course. Return the locator string for the course.
""" """
course_key = CourseKey.from_string(self._course_key) course_key = CourseKey.from_string(self._course_key)
return unicode(course_key.make_usage_key('course', self._course_dict['run'])) if getattr(course_key, 'deprecated', False):
block_id = self._course_dict['run']
else:
block_id = 'course'
return unicode(course_key.make_usage_key('course', block_id))
@property @property
def _assets_url(self): def _assets_url(self):
......
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