Commit Graph

42 Commits

Author SHA1 Message Date
Usman Khalid
ca910b6f27 Collect static asset URLs from static_replace.replace_static_urls
Allows users to keep track of which static asset URLs were found in given text,
and what they were replaced from/to.
2018-09-11 11:16:33 +09:30
Jeremy Bowman
d3d6272d8f PLAT-1873 to_deprecated_string() cleanup part 1 2018-01-08 13:51:42 -05:00
John Eskew
02f26f55ce Remove unused imports. Push model imports down into relevant methods.
Mock out the static_replace modules in the proper location.
2017-10-05 11:12:52 -04:00
Toby Lawrence
8ab62b5b99 [PERF-351] Account for settings.STATIC_URL in XBlock resource URLs when
rewriting them.

In PERF-341, we adjusted the static_replace middleware to try and
exclude static XBlock resource URLs from being interpreted as the marker
URLs used to signify course assets in course content.  Since they both
started with /static, this could, and did, cause issues where linking
directly to the assets of an XBlock within, say, one of its templates,
would lead to that link being rewritten and ultimately being incorrect.
The fix attempted to see if the link started with the prefix that all
static XBlock resource URLs start, and if so, it returned them
unmodified.

We incorrectly assumed that our testing captured all cases, and since
we're here, we know that this was wrong.  We weren't accounting for cases
when the URLs being generated had the STATIC_URL configuration value
prefixed -- https://example.com/static/xblock/.... -- and so our direct
check of seeing if such a URL started with "/static/xblock" would always
fail, leading to the erroneous rewriting and nonsensical output.

This fix checks if the link either starts with the prefix OR if it
starts with the STATIC_URL value and contains the prefix overall.  There
is a small overlap between the STATIC_URL and the prefix we check for,
so an inconsistency could arise down the line if we changed our
STATIC_URL to use a difference base directory, but our tests will at
least catch the issue now.
2016-07-12 22:33:11 -04:00
Toby Lawrence
faaa30c02d [PERF-341] Fix up to not rewrite XBlock resource URLs.
For XBlocks that used their static.public resources in the rendered
output -- for example, a link to a bundled image -- those URLs would be
treated as course assets using the '/static/' prefix trick, and thus,
rewritten.  These rewritten URLs don't work because they aren't course
assets.

When course content authors are creating their courses, we provide them
a special shorthand way of writing URLs that reference assets they have
uploaded to the course. If they uploaded a file called my-lil-pony.mp4,
and they wanted to provide a link to it when users view the course, they
would use /static/my-lil-pony.mp4. This special prefix -- /static/ --
signals to the static_replace middleware that it's a course asset and we
should write /static/my-lil-pony.mp4 to a URL that properly references
the asset based on the course ID, and things like the configured asset
CDN, etc.

Thus, the URL /static/my-lil-pony.mp4 gets turned into something like:

/assets/courseware/<md5hash>/asset-v1:edX+Demo+2016T1+type@asset+block/my-lil-pony.mp4

when viewed in the courseware.

Now, we also serve actual static assets from a prefix of /static/. This
is stuff like our JavaScript and CSS, and the JS/CSS/etc of
XBlocks/XModules. These paths look like:

/static/js/lms-main_vendor.46d6a8c02600.js

or

/static/xblock/resources/xmodule.vertical_block/public/js/vertical_student_view.43727a907769.js

Normally, these paths are caught by nginx, before they reach the LMS,
and are served straight from the filesystem. However, if you were to
have one of these paths in your course content, the static_replace
middleware would see the /static/ at the front and immediately think
it's a course asset, and would dutifully rewrite the URL to something
like:

/assets/courseware/<md5hash>/asset-v1:edX+Demo+2016T1+type@asset+block/static_xblock_resources_xmodule.vertical_block_public_js_vertical_student_view.43727a907769.js

which is not a course asset, and so it will always fail to load.

Long story short, I changed the static_replace middleware to
specifically check to see if the path being matched starts with
/static/xblock/, and if so, it keeps the original instead of rewriting
it.
2016-06-23 14:47:02 -04:00
John Eskew
84da6e4c1f Address DaveO's comments. 2016-04-21 11:56:23 -04:00
John Eskew
8a9845c26e Remove ModuleStoreEnum.Type.xml 2016-04-12 11:53:51 -04:00
Toby Lawrence
1183f6cec9 Add the ability to exclude files from URL canonicalization.
To be able to more easily deal with same-origin issues, due to some course assets being loaded in an iframe, we're adding the ability to specify file extensions that should be excluded from URL canonicalization.  The default value is simply 'html', which means we won't rewrite asset links that point to files ending in .html.  Thus, they'll be loaded from the same origin as the parent page, and voila, no SOP issues.
2016-02-01 21:44:35 -05:00
Toby Lawrence
77343df0d9 [PERF-224] Support to serve static assets from a CDN.
A base URL can now be configured which is, potentially, prepended to an
asset URL.  This allows a CDN, or caching server, to front static asset
requests, taking load off of the contentstore and speeding up page load
times.

Asset URL generation respects locked vs unlocked assets, and will not
generate links to locked assets that would traverse a CDN (even though
the authorization component of the contentserver middleware wouldn't
allow those links to work anyways).
2016-01-05 10:24:44 -05:00
Usman Khalid
dbcd1bf430 Use django.contrib.staticfiles instead of django-staticfiles.
TNL-3137
2015-10-06 19:52:38 +05:00
Brian Beggs
c26bb9188a Revert "Upgrade django-pipeline and staticfiles" 2015-09-23 15:52:24 -04:00
Usman Khalid
158bdf4d09 Use django.contrib.staticfiles instead of django-staticfiles.
TNL-3137
2015-09-22 20:39:44 +05:00
Syed Hassan Raza
825aaed67f Split course's assests can access through '/' in asset url 2015-04-08 11:22:25 -04:00
Akiva Leffert
66f41e1d9f Make static URLs absolute in handouts, updates, and about for mobile API
JIRA: MA-147
2014-12-03 16:25:48 -05:00
christopher lee
b89113e114 Revert "Make static URLs absolute in handouts, updates, and about for mobile API"
This reverts commit fb6579abfdb6fc9fb8bc9233554ff5c6e9215659.
2014-12-03 16:24:27 -05:00
Akiva Leffert
1088855d0b Make static URLs absolute in handouts, updates, and about for mobile API
JIRA: MA-147
2014-12-03 16:18:39 -05:00
Don Mitchell
78879ebc18 Asset urls must start w/ slash
LMS-11233
2014-08-21 12:11:27 -04:00
Nimisha Asthagiri
eecff6e0aa ModulestoreEnum class. 2014-06-27 14:37:35 -04:00
Calen Pennington
e2bfcf2a36 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]
2014-05-07 12:54:49 -04:00
Jay Zoldak
bc30addfb9 Unicode changes to support QRF
fixing unit tests

fixing merge error

fixing xqueue submission issue with unicode url (trial 0.1)

fixing fotmats as commented upon

removing yaml file language selection

Unicode changes to support QRF

removed unnecessary pass in modulestore/init.py

fixing merge error

fixing fotmats as commented upon

removing yaml file language selection

fixing pep8 violations

- fixing pylint violations

pylint violation

fixing line spaces and formats

ignore pylint E1101

remove empty line

fixing pylint violations

 pep8 violations

bulk mail unicode/decode

fix migration error

fix pep8 just to push again

more unicode/decode
Final changes to comments and error messages.
2014-01-30 16:20:36 -05:00
David Baumgold
fb13bed947 Updating comments and docs for MITx -> edX transition 2013-12-10 13:21:18 -05:00
David Baumgold
d97921e6e2 Convert Studio JS to use require.js 2013-10-04 13:43:50 -04:00
ichuang
0d938d3940 Merge branch 'master' of github.com:edx/edx-platform into feature/ichuang/import-with-no-static
Conflicts:
	lms/djangoapps/courseware/tests/test_module_render.py
2013-08-20 23:40:09 -04:00
ichuang
95952bd693 add tests of static_asset_path and importing with no static;
fix (again) static_replace to work with static_asset_path
2013-08-20 23:30:26 -04:00
ichuang
220ec522a1 Merge branch 'master' of github.com:edx/edx-platform into feature/ichuang/import-with-no-static
Conflicts:
	common/djangoapps/static_replace/__init__.py
	common/djangoapps/xmodule_modifiers.py
	lms/djangoapps/courseware/courses.py
	lms/djangoapps/courseware/module_render.py
2013-08-19 08:24:35 -04:00
Chris Dodge
033f922ec0 add a try catch around the staticstorage lookup, which can throw an exception 2013-08-17 10:33:59 -04:00
Chris Dodge
cff93d324b WIP 2013-08-15 22:58:02 -04:00
Chris Dodge
82988972ad WIP: added a get_modulestore_type. Added some unit tests. changed over the isinstance() with respect to modulestores to use this get_modulestore_type() 2013-08-15 22:58:02 -04:00
ichuang
a5bb971c9b add static_asset_path metadata to course, and honor its use in link rewriting 2013-08-12 20:26:20 +00:00
Chris Dodge
565564a46e add input/output information in doc strings 2013-07-23 12:15:56 -04:00
Chris Dodge
1c79b9c874 add a /jump_to_id/ shortcut for producing more durable links between courseware in Studio 2013-07-23 12:10:49 -04:00
Chris Dodge
c23c5cc3d9 add comments 2013-03-07 16:12:21 -05:00
Chris Dodge
891bddcdf9 need to support link references to static content that is in the code base (e.g. module's .js/.css) 2013-03-07 14:28:09 -05:00
Victor Shnayder
3ccb33c8b3 Simplify, make it actually work.
- regexp was too complicated, didn't work
2013-02-11 17:50:13 -05:00
Victor Shnayder
2dcdeff4b6 Make replace_static_urls leave alone urls that have '?raw' at the end
- needed for GWT'ed modules that rely on the filename to find dependencies
2013-02-11 17:07:15 -05:00
Calen Pennington
2b637fe511 Fix loads of local static files when running in dev mode 2013-02-07 10:13:53 -05:00
Victor Shnayder
92eb88d464 Merge pull request #1444 from MITx/feature/cale/dev-staticfiles
Make local dev work by trying checking staticfiles_storage for both the ...
2013-02-06 14:02:04 -08:00
Calen Pennington
cfae1cdf62 Pep8 autofixes 2013-02-06 11:13:50 -05:00
Calen Pennington
96eb16cd72 Make local dev work by trying checking staticfiles_storage for both the course_prefixed and non-course_prefixed urls 2013-02-06 10:08:20 -05:00
Calen Pennington
0350d15e29 Make static_replace fall back to data_directory prefix, if it doesn't find the file anywhere else 2013-02-05 11:06:46 -05:00
Calen Pennington
8592db92bf Add more tests of static_replace 2013-02-05 11:06:46 -05:00
Calen Pennington
f1f2bd8fd2 Start adding tests for static replacement 2013-02-05 11:06:46 -05:00