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
27258425
Commit
27258425
authored
Oct 26, 2017
by
Eric Fischer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Send contextual data through to studio-frontend
EDUCATOR-1529
parent
dbad9fbc
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
59 additions
and
3 deletions
+59
-3
cms/templates/asset_index.html
+11
-2
common/djangoapps/pipeline_mako/templates/static_content.html
+39
-0
scripts/tests/test_xss_linter.py
+7
-1
scripts/xss_linter.py
+2
-0
No files found.
cms/templates/asset_index.html
View file @
27258425
...
...
@@ -56,8 +56,17 @@
<div
class=
"content"
>
<div
class=
"content-primary"
>
% if waffle_flag_enabled:
<div
id=
"root"
></div>
<
%
static:webpack
entry=
"AssetsPage"
></
%
static:webpack>
<
%
static:studiofrontend
page=
"AssetsPage"
lang=
"fr"
>
{
"id": "${context_course.id | n, js_escaped_string}",
"name": "${context_course.display_name_with_default | n, js_escaped_string}",
"url_name": "${context_course.location.name | n, js_escaped_string}",
"org": "${context_course.location.org | n, js_escaped_string}",
"num": "${context_course.location.course | n, js_escaped_string}",
"display_course_number": "${context_course.display_coursenumber | n, js_escaped_string}",
"revision": "${context_course.location.revision | n, js_escaped_string}"
}
</
%
static:studiofrontend>
% else:
<div
class=
"wrapper-assets"
></div>
% endif
...
...
common/djangoapps/pipeline_mako/templates/static_content.html
View file @
27258425
...
...
@@ -86,6 +86,45 @@ engine = Engine(dirs=settings.DEFAULT_TEMPLATE_ENGINE['DIRS'])
source
,
template_path =
Loader(engine).load_template_source(path)
%
>
${source | n, decode.utf8}
</
%
def>
<
%
def
name=
"studiofrontend(page, lang='en')"
>
<
%
doc
>
Loads a studio-frontend page, with the necessary context. Context is expected
as a dictionary in the body of this tag.
Dev note: we could also add the locale-injection script in this block
-use a better default than the hardcoded 'en'. There should be a setting or something?
-lookup (webpack exported) locale-injection script using lang as key
-include it as the first script in this block
</
%
doc>
<
%
from
django
.
template
import
Template
,
Context
from
webpack_loader
.
exceptions
import
WebpackLoaderBadStatsError
import
json
def
_convert_dict_to_json
(
input_dict
)
:
output_json =
"{"
for
key
in
input_dict:
output_json =
"{}{}:\"
{}\",".
format
(
output_json
,
key
,
input_dict
[
key
])
output_json
+=
"}"
return
output_json
body =
capture(caller.body)
body_dict =
json.loads(body)
body_dict
['
lang
']
=
lang
return
Template
("""
<
script
type=
"text/javascript"
id=
'courseContext'
>
var courseContext = {% autoescape off %}{{ body }}{% endautoescape %};
</script>
<div
id=
"root"
></div>
{% load render_bundle from webpack_loader %}
{% render_bundle page %}
""").render(Context({
'body': _convert_dict_to_json(body_dict),
'page': page
}))
%>
</
%
def>
<
%
def
name=
"webpack(entry)"
>
<
%
doc
>
Loads Javascript onto your page from a Webpack-generated bundle.
...
...
scripts/tests/test_xss_linter.py
View file @
27258425
...
...
@@ -741,16 +741,22 @@ class TestMakoTemplateLinter(TestLinter):
${x | h}
</
%
static:require_module>
${x | h}
<
%
static:studiofrontend page="${x}" lang="en">
${x | h}
</
%
static:studiofrontend>
${x | h}
"""
)
linter
.
_check_mako_file_is_safe
(
mako_template
,
results
)
self
.
assertEqual
(
len
(
results
.
violations
),
5
)
self
.
assertEqual
(
len
(
results
.
violations
),
7
)
self
.
assertEqual
(
results
.
violations
[
0
]
.
rule
,
Rules
.
mako_unwanted_html_filter
)
self
.
assertEqual
(
results
.
violations
[
1
]
.
rule
,
Rules
.
mako_invalid_js_filter
)
self
.
assertEqual
(
results
.
violations
[
2
]
.
rule
,
Rules
.
mako_unwanted_html_filter
)
self
.
assertEqual
(
results
.
violations
[
3
]
.
rule
,
Rules
.
mako_invalid_js_filter
)
self
.
assertEqual
(
results
.
violations
[
4
]
.
rule
,
Rules
.
mako_unwanted_html_filter
)
self
.
assertEqual
(
results
.
violations
[
5
]
.
rule
,
Rules
.
mako_invalid_js_filter
)
self
.
assertEqual
(
results
.
violations
[
6
]
.
rule
,
Rules
.
mako_unwanted_html_filter
)
def
test_check_mako_expressions_javascript_strings
(
self
):
"""
...
...
scripts/xss_linter.py
View file @
27258425
...
...
@@ -2382,6 +2382,8 @@ class MakoTemplateLinter(BaseLinter):
</
%
static:require_module(_async)?> | # require js script tag end (optionally the _async version)
<
%
static:webpack.*?> | # webpack script tag start
</
%
static:webpack> | # webpack script tag end
<
%
static:studiofrontend.*?> | # studiofrontend script tag start
</
%
static:studiofrontend> | # studiofrontend script tag end
<
%
block[ ]*name=['"]requirejs['"]\w*> | # require js tag start
</
%
block> # require js tag end
"""
,
...
...
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