EquationImagesController#show can support alternate latex service

refs CNVS-29513

- Replace `+` with `%2B` in params[:id]
- Update setting identifier and default value for service url so that
  service interface can be different between existing code cogs
  integration and future integrations.
- Add a predeploy migration to move existing
  `codecogs.equation_image_link` settings to `equation_image.url`, and
  update the values to include a trailing `?`.
- Add a postdeploy migration to remove `codecogs.equation_image_link`
  settings.

test plan:
- Navigate to form to create new assignment.
- Via TinyMCE, open the equation editor and add an equation / formula to
  the assignment description.
- Observe that upon submitting the form to insert the equation, it is
  displayed in the TinyMCE editor text area.
- Observe that upon creating the assignnment and viewing it, the
  equation is visible in the assignment description.

Change-Id: Ie4ffff640e51f9269a68fb3df81aae7d1f5ca33b
Reviewed-on: https://gerrit.instructure.com/80404
Reviewed-by: Cody Cutrer <cody@instructure.com>
Reviewed-by: Simon Williams <simon@instructure.com>
Tested-by: Jenkins
QA-Review: Benjamin Christian Nelson <bcnelson@instructure.com>
Product-Review: John Corrigan <jcorrigan@instructure.com>
This commit is contained in:
John Corrigan 2016-05-23 14:39:22 -05:00
parent 690967a0ad
commit 1c456d640f
4 changed files with 51 additions and 6 deletions

View File

@ -1,12 +1,16 @@
class EquationImagesController < ApplicationController
# Facade to codecogs API so we retain control
# Facade to codecogs API for gif generation or microservice MathMan for svg
def show
# TODO: escape id here, and stop double escaping it in
# public/javascripts/tinymce/jscripts/tiny_mce/plugins/instructure_equation/editor_plugin.js
# this will require a corresponding data migration to fix
base_url = Setting.get('codecogs.equation_image_link', 'http://latex.codecogs.com/gif.latex')
redirect_to base_url + '?' + params[:id]
base_url = Setting.get('equation_image_url', 'http://latex.codecogs.com/gif.latex?')
# At the moment, the latex string is stored in the db double escaped. By
# the time the value gets here as `params[:id]` it has been unescaped once.
# This is nearly how we want it to pass it on to the next service, except
# `+` signs are in tact. Since normally the `+` signifies a space and we
# want the `+` signs for real, we need to encode them.
latex = params[:id].gsub('+', '%2B')
redirect_to base_url + latex
end
end

View File

@ -0,0 +1,21 @@
class UpdateSettingEquationSvgUrlDefault < ActiveRecord::Migration
tag :predeploy
def up
return unless Shard.current.default?
setting = Setting.where(name: 'codecogs.equation_image_link').take
if setting.present?
Setting.set('equation_image_url', "#{setting.value}?")
end
end
def down
return unless Shard.current.default?
setting = Setting.where(name: 'equation_image_url').take
if setting.present?
Setting.set('codecogs.equation_image_link', setting.value.sub(/\?$/, ''))
end
end
end

View File

@ -0,0 +1,15 @@
class RemoveCodecogsEquationImageSettingKey < ActiveRecord::Migration
tag :postdeploy
def up
return unless Shard.current.default?
Setting.remove('codecogs.equation_image_link')
end
def down
return unless Shard.current.default?
Setting.remove('equation_image_url')
end
end

View File

@ -7,4 +7,9 @@ describe EquationImagesController do
expect(response).to redirect_to('http://latex.codecogs.com/gif.latex?foo')
end
it 'encodes `+` signs properly' do
latex = '5%5E5%5C%3A+%5C%3A%5Csqrt%7B9%7D'
get :show, id: latex
expect(response).to redirect_to(/\%2B/)
end
end