Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
E
edx-platform
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
edx
edx-platform
Commits
41f88344
Commit
41f88344
authored
Jan 15, 2014
by
Don Mitchell
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #2167 from edx/dhm/split_block_id
Encode periods and $ in block_id map
parents
80d54afd
13a04927
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
40 additions
and
7 deletions
+40
-7
common/lib/xmodule/xmodule/modulestore/loc_mapper_store.py
+8
-6
common/lib/xmodule/xmodule/modulestore/split_mongo/caching_descriptor_system.py
+4
-1
common/lib/xmodule/xmodule/modulestore/split_mongo/split.py
+0
-0
common/lib/xmodule/xmodule/modulestore/tests/test_split_modulestore.py
+28
-0
No files found.
common/lib/xmodule/xmodule/modulestore/loc_mapper_store.py
View file @
41f88344
...
...
@@ -156,7 +156,7 @@ class LocMapperStore(object):
entry
=
item
break
block_id
=
entry
[
'block_map'
]
.
get
(
self
.
_encode
_for_mongo
(
location
.
name
))
block_id
=
entry
[
'block_map'
]
.
get
(
self
.
encode_key
_for_mongo
(
location
.
name
))
if
block_id
is
None
:
if
add_entry_if_missing
:
block_id
=
self
.
_add_to_block_map
(
location
,
location_id
,
entry
[
'block_map'
])
...
...
@@ -231,7 +231,7 @@ class LocMapperStore(object):
candidate
[
'_id'
][
'org'
],
candidate
[
'_id'
][
'course'
],
category
,
self
.
_decode
_from_mongo
(
old_name
),
self
.
decode_key
_from_mongo
(
old_name
),
None
)
published_locator
=
BlockUsageLocator
(
candidate
[
'course_id'
],
branch
=
candidate
[
'prod_branch'
],
block_id
=
block_id
...
...
@@ -261,7 +261,7 @@ class LocMapperStore(object):
# if 2 different category locations had same name, then they'll collide. Make the later
# mapped ones unique
block_id
=
self
.
_verify_uniqueness
(
location
.
name
,
block_map
)
encoded_location_name
=
self
.
_encode
_for_mongo
(
location
.
name
)
encoded_location_name
=
self
.
encode_key
_for_mongo
(
location
.
name
)
block_map
.
setdefault
(
encoded_location_name
,
{})[
location
.
category
]
=
block_id
self
.
location_map
.
update
(
location_id
,
{
'$set'
:
{
'block_map'
:
block_map
}})
return
block_id
...
...
@@ -331,7 +331,8 @@ class LocMapperStore(object):
return
self
.
_verify_uniqueness
(
name
,
block_map
)
return
name
def
_encode_for_mongo
(
self
,
fieldname
):
@staticmethod
def
encode_key_for_mongo
(
fieldname
):
"""
Fieldnames in mongo cannot have periods nor dollar signs. So encode them.
:param fieldname: an atomic field name. Note, don't pass structured paths as it will flatten them
...
...
@@ -340,9 +341,10 @@ class LocMapperStore(object):
fieldname
=
fieldname
.
replace
(
char
,
'
%
{:02x}'
.
format
(
ord
(
char
)))
return
fieldname
def
_decode_from_mongo
(
self
,
fieldname
):
@staticmethod
def
decode_key_from_mongo
(
fieldname
):
"""
The inverse of
_encode
_for_mongo
The inverse of
encode_key
_for_mongo
:param fieldname: with period and dollar escaped
"""
return
urllib
.
unquote
(
fieldname
)
...
...
common/lib/xmodule/xmodule/modulestore/split_mongo/caching_descriptor_system.py
View file @
41f88344
...
...
@@ -8,6 +8,7 @@ from xblock.runtime import KvsFieldData, IdReader
from
..exceptions
import
ItemNotFoundError
from
.split_mongo_kvs
import
SplitMongoKVS
from
xblock.fields
import
ScopeIds
from
xmodule.modulestore.loc_mapper_store
import
LocMapperStore
log
=
logging
.
getLogger
(
__name__
)
...
...
@@ -63,7 +64,9 @@ class CachingDescriptorSystem(MakoDescriptorSystem):
# Compute inheritance
modulestore
.
inherit_settings
(
course_entry
[
'structure'
]
.
get
(
'blocks'
,
{}),
course_entry
[
'structure'
]
.
get
(
'blocks'
,
{})
.
get
(
course_entry
[
'structure'
]
.
get
(
'root'
))
course_entry
[
'structure'
]
.
get
(
'blocks'
,
{})
.
get
(
LocMapperStore
.
encode_key_for_mongo
(
course_entry
[
'structure'
]
.
get
(
'root'
))
)
)
self
.
default_class
=
default_class
self
.
local_modules
=
{}
...
...
common/lib/xmodule/xmodule/modulestore/split_mongo/split.py
View file @
41f88344
This diff is collapsed.
Click to expand it.
common/lib/xmodule/xmodule/modulestore/tests/test_split_modulestore.py
View file @
41f88344
...
...
@@ -620,6 +620,34 @@ class TestItemCrud(SplitModuleTest):
another_history
=
modulestore
()
.
get_definition_history_info
(
another_module
.
definition_locator
)
self
.
assertEqual
(
str
(
another_history
[
'previous_version'
]),
'0d00000040000000dddd0031'
)
def
test_encoded_naming
(
self
):
"""
Check that using odd characters in block id don't break ability to add and retrieve block.
"""
parent_locator
=
BlockUsageLocator
(
package_id
=
"contender"
,
block_id
=
"head345679"
,
branch
=
'draft'
)
chapter_locator
=
BlockUsageLocator
(
package_id
=
"contender"
,
block_id
=
"foo.bar_-~:0"
,
branch
=
'draft'
)
modulestore
()
.
create_item
(
parent_locator
,
'chapter'
,
'anotheruser'
,
block_id
=
chapter_locator
.
block_id
,
fields
=
{
'display_name'
:
'chapter 99'
},
)
# check that course version changed and course's previous is the other one
new_module
=
modulestore
()
.
get_item
(
chapter_locator
)
self
.
assertEqual
(
new_module
.
location
.
block_id
,
"foo.bar_-~:0"
)
# hardcode to ensure BUL init didn't change
# now try making that a parent of something
new_payload
=
"<problem>empty</problem>"
problem_locator
=
BlockUsageLocator
(
package_id
=
"contender"
,
block_id
=
"prob.bar_-~:99a"
,
branch
=
'draft'
)
modulestore
()
.
create_item
(
chapter_locator
,
'problem'
,
'anotheruser'
,
block_id
=
problem_locator
.
block_id
,
fields
=
{
'display_name'
:
'chapter 99'
,
'data'
:
new_payload
},
)
# check that course version changed and course's previous is the other one
new_module
=
modulestore
()
.
get_item
(
problem_locator
)
self
.
assertEqual
(
new_module
.
location
.
block_id
,
problem_locator
.
block_id
)
chapter
=
modulestore
()
.
get_item
(
chapter_locator
)
self
.
assertIn
(
problem_locator
.
block_id
,
chapter
.
children
)
def
test_create_continue_version
(
self
):
"""
Test create_item using the continue_version flag
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment