load mobile css/js files in native iOS/andorid apps and not mobile browsers
fixes: CNVS-29413 test plan: * set up an account with new ui, and upload a custom css/js * using something like postman, make an api request to a wiki page * it should include a <link> to that css file and a <script> for that js file. * make the same request from a mobile web browser (you can fake your user agent string in safari or chrome dev tools to fake this) * it should not include that css or js file Change-Id: I07493c8dc474231463cb1f97c0e07f2aad59ed0f Reviewed-on: https://gerrit.instructure.com/79921 Reviewed-by: Simon Williams <simon@instructure.com> Tested-by: Jenkins QA-Review: Benjamin Christian Nelson <bcnelson@instructure.com> Product-Review: Ryan Shaw <ryan@instructure.com>
This commit is contained in:
parent
72e2f5bac0
commit
3a7a18bf81
|
@ -442,13 +442,13 @@ define([
|
||||||
<div className="Theme__editor-upload-overrides">
|
<div className="Theme__editor-upload-overrides">
|
||||||
|
|
||||||
<div className="Theme__editor-upload-overrides_header">
|
<div className="Theme__editor-upload-overrides_header">
|
||||||
{ I18n.t('File(s) will be included when user content is displayed within Canvas iOS or Android apps.') }
|
{ I18n.t('File(s) will be included when user content is displayed within the Canvas iOS or Android apps, and in third-party apps built on our API.') }
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className="Theme__editor-upload-overrides_form">
|
<div className="Theme__editor-upload-overrides_form">
|
||||||
|
|
||||||
<ThemeEditorFileUpload
|
<ThemeEditorFileUpload
|
||||||
label={I18n.t('Mobile CSS file')}
|
label={I18n.t('Mobile app CSS file')}
|
||||||
accept=".css"
|
accept=".css"
|
||||||
name="mobile_css_overrides"
|
name="mobile_css_overrides"
|
||||||
currentValue={this.props.brandConfig.mobile_css_overrides}
|
currentValue={this.props.brandConfig.mobile_css_overrides}
|
||||||
|
@ -457,7 +457,7 @@ define([
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<ThemeEditorFileUpload
|
<ThemeEditorFileUpload
|
||||||
label={I18n.t('Mobile JavaScript file')}
|
label={I18n.t('Mobile app JavaScript file')}
|
||||||
accept=".js"
|
accept=".js"
|
||||||
name="mobile_js_overrides"
|
name="mobile_js_overrides"
|
||||||
currentValue={this.props.brandConfig.mobile_js_overrides}
|
currentValue={this.props.brandConfig.mobile_js_overrides}
|
||||||
|
|
|
@ -508,7 +508,7 @@ module Api
|
||||||
|
|
||||||
url_helper = Html::UrlProxy.new(self, context, host, protocol)
|
url_helper = Html::UrlProxy.new(self, context, host, protocol)
|
||||||
account = Context.get_account(context) || @domain_root_account
|
account = Context.get_account(context) || @domain_root_account
|
||||||
include_mobile = respond_to?(:mobile_device?, true) && mobile_device?
|
include_mobile = !(respond_to?(:in_app?, true) && in_app?)
|
||||||
Html::Content.rewrite_outgoing(html, account, url_helper, include_mobile: include_mobile)
|
Html::Content.rewrite_outgoing(html, account, url_helper, include_mobile: include_mobile)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -659,22 +659,39 @@ describe Api do
|
||||||
expect(res).to eq html
|
expect(res).to eq html
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'prepends mobile css' do
|
context "mobile css/js" do
|
||||||
student_in_course
|
before(:each) do
|
||||||
account = @course.root_account
|
student_in_course
|
||||||
account.enable_feature!(:use_new_styles)
|
account = @course.root_account
|
||||||
bc = BrandConfig.create(mobile_css_overrides: 'somewhere.css')
|
account.enable_feature!(:use_new_styles)
|
||||||
account.brand_config_md5 = bc.md5
|
bc = BrandConfig.create(mobile_css_overrides: 'somewhere.css')
|
||||||
account.save!
|
account.brand_config_md5 = bc.md5
|
||||||
|
account.save!
|
||||||
|
|
||||||
html = "<p>a</p><p>b</p>"
|
@html = "<p>a</p><p>b</p>"
|
||||||
|
|
||||||
k = klass.new
|
@k = klass.new
|
||||||
k.stubs(:mobile_device?).returns(true)
|
end
|
||||||
res = k.api_user_content(html, @course, @student)
|
|
||||||
expect(res).to eq <<-HTML.strip
|
it 'prepends mobile css when not coming from a web browser' do
|
||||||
<link rel="stylesheet" href="somewhere.css"><p>a</p><p>b</p>
|
res = @k.api_user_content(@html, @course, @student)
|
||||||
HTML
|
expect(res).to eq <<-HTML.strip
|
||||||
|
<link rel="stylesheet" href="somewhere.css"><p>a</p><p>b</p>
|
||||||
|
HTML
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'does not prepend mobile css when coming from a web browser' do
|
||||||
|
@k.stubs(:in_app?).returns(true)
|
||||||
|
res = @k.api_user_content(@html, @course, @student)
|
||||||
|
expect(res).to eq "<p>a</p><p>b</p>"
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'does not prepend mobile css when coming from a web browser, even if it is a mobile browser' do
|
||||||
|
@k.stubs(:in_app?).returns(true)
|
||||||
|
@k.stubs(:mobile_device?).returns(true)
|
||||||
|
res = @k.api_user_content(@html, @course, @student)
|
||||||
|
expect(res).to eq "<p>a</p><p>b</p>"
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue