don't use PluginSetting.cached_plugin_setting outside plugin setting

fixes CNVS-31176

Also refactor a little so we're not querying the DB for the plugin
setting ~3 times per method call.

test plan:
- With the plugin disabled, observe that MathMan is not used for MathML
  or SVG generation.
- When plugin is enabled, observe that specific settings (whether or not
  to use for one or the other target (mml & svg); the base url) are
  respected.

Change-Id: Ie17942644e02088d967ad19a10b0f96f4cd57665
Reviewed-on: https://gerrit.instructure.com/88389
Tested-by: Jenkins
Reviewed-by: Cody Cutrer <cody@instructure.com>
QA-Review: Jeremy Putnam <jeremyp@instructure.com>
Product-Review: John Corrigan <jcorrigan@instructure.com>
This commit is contained in:
John Corrigan 2016-08-22 12:21:49 -05:00
parent 88805f4b1e
commit f09d340142
1 changed files with 22 additions and 18 deletions

View File

@ -1,29 +1,33 @@
module MathMan
def self.base_url
plugin_setting.settings[:base_url].sub(/\/$/, '')
end
def self.enabled?
plugin_setting.present? && plugin_setting.enabled?
end
def self.plugin_setting
PluginSetting.cached_plugin_setting('mathman')
end
def self.url_for(latex:, target:)
"#{base_url}/#{target}?tex=#{latex}"
end
def self.use_for_mml?
enabled? && Canvas::Plugin.value_to_boolean(
plugin_setting.settings[:use_for_mml]
with_plugin_settings do |plugin_settings|
Canvas::Plugin.value_to_boolean(
plugin_settings[:use_for_mml]
)
end
end
def self.use_for_svg?
enabled? && Canvas::Plugin.value_to_boolean(
plugin_setting.settings[:use_for_svg]
with_plugin_settings do |plugin_settings|
Canvas::Plugin.value_to_boolean(
plugin_settings[:use_for_svg]
)
end
end
private
def self.base_url
with_plugin_settings do |plugin_settings|
plugin_settings[:base_url].sub(/\/$/, '')
end
end
def self.with_plugin_settings
plugin_settings = Canvas::Plugin.find(:mathman).settings
yield plugin_settings
end
end