canvas_link_migrator 1.0.0 → 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b03a701351cd4f8484cd257bdbbb3e4437ada4d39988d97230e48093e6a8c2a9
4
- data.tar.gz: 2fadff9dc0f3a7c0d07ef2d7e79bd20f2e8c9ee14ccf71e4951c89417aa35659
3
+ metadata.gz: 7d147093c7e6b397c3eb184aba4af1595f782e14735a50e9d4986be628af75f3
4
+ data.tar.gz: cb48c35f35dd333b02ff7dcba5e3bd79d1a1a7b736b7bb14c56de11b6c91565e
5
5
  SHA512:
6
- metadata.gz: 12d6e3e37c9d8115ce1e47712b0f6192a9d4d6617ec038d8d1b94eb3ec27996f4062d60c75b0b1f26b25675be1738a3dbe121fdc5707c182ca78751f7b47010d
7
- data.tar.gz: e9fb1a26ea2aa9b9a24e799f407a05792b26c5743cd919e221e32309d20c49e603a51ec967bf28de51aba60954842793196024d74cae26f232ded871bb55725e
6
+ metadata.gz: 4074cbb1bfa20b00f4843327d62ee0e1cf739f7450b46698ee1a6a240054f27acd34046605e2ae4f54bbdf02b529272ba165769352e10abff1f5950c08af6ad8
7
+ data.tar.gz: e1deecf7b1d6586c432234092e338c9d3059f26b744072eab1cb6e644c25dbcec9ffacfb53239b6c9ffc0610c210bf80399f097f2d7efa2265686caf314a8fee
@@ -182,11 +182,13 @@ module CanvasLinkMigrator
182
182
 
183
183
  # returns a hash with resolution status and data to hold onto if unresolved
184
184
  def parse_url(url, node, attr)
185
- url = Addressable::URI.parse(url)
186
- query_values = url.query_values || {}
187
- media_attachment = query_values.delete("media_attachment") == "true"
188
- url.query_values = query_values.present? ? query_values : nil
189
- url = url.to_s
185
+ parsed_url = Addressable::URI.parse(url)
186
+ query_values = parsed_url.query_values
187
+ media_attachment = query_values.try(:delete, "media_attachment") == "true"
188
+ if media_attachment
189
+ parsed_url.query_values = query_values.present? ? query_values : nil
190
+ url = Addressable::URI.unencode(parsed_url)
191
+ end
190
192
 
191
193
  if url =~ /wiki_page_migration_id=(.*)/
192
194
  unresolved(:wiki_page, migration_id: $1)
@@ -122,15 +122,14 @@ module CanvasLinkMigrator
122
122
  # context prepended to the URL. This prevents
123
123
  # redirects to non cross-origin friendly urls
124
124
  # during a file fetch
125
- link[:new_value] = if rest.include?("icon_maker_icon=1")
126
- "/files/#{file_id}#{rest}"
127
- elsif link[:in_media_iframe] && link[:media_attachment]
128
- "/media_attachments_iframe/#{file_id}#{rest}"
129
- elsif link[:in_media_iframe]
130
- "/media_objects_iframe?mediahref=#{link[:new_value]}"
131
- else
132
- "#{context_path}/files/#{file_id}#{rest}"
133
- end
125
+ if rest.include?("icon_maker_icon=1")
126
+ link[:new_value] = "/files/#{file_id}#{rest}"
127
+ elsif link[:in_media_iframe] && link[:media_attachment]
128
+ link[:new_value] = "/media_attachments_iframe/#{file_id}#{rest}"
129
+ else
130
+ link[:new_value] = "#{context_path}/files/#{file_id}#{rest}"
131
+ link[:new_value] = "/media_objects_iframe?mediahref=#{link[:new_value]}" if link[:in_media_iframe]
132
+ end
134
133
  end
135
134
  else
136
135
  raise "unrecognized link_type (#{link[:link_type]}) in unresolved link"
@@ -240,6 +240,12 @@ describe CanvasLinkMigrator::ImportedHtmlConverter do
240
240
  expect(@converter.convert_exported_html(test_string)).to eq([converted_string, nil])
241
241
  end
242
242
 
243
+ it "converts mediahref iframes" do
244
+ test_string = %(<iframe data-media-type="video" src="/media_objects_iframe?mediahref=$CANVAS_COURSE_REFERENCE$/file_ref/I/download" data-media-id="m-yodawg"></iframe>)
245
+ converted_string = %(<iframe data-media-type="video" src="/media_objects_iframe?mediahref=/courses/2/files/9/download" data-media-id="m-yodawg"></iframe>)
246
+ expect(@converter.convert_exported_html(test_string)).to eq([converted_string, nil])
247
+ end
248
+
243
249
  it "leaves source tags without data-media-id alone" do
244
250
  test_string = %(<video style="width: 400px; height: 225px; display: inline-block;" title="this is a non-canvas video" allowfullscreen="allowfullscreen" allow="fullscreen"><source src="http://www.example.com/video.mov"></video>)
245
251
  expect(@converter.convert_exported_html(test_string)).to eq([test_string, nil])
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: canvas_link_migrator
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mysti Lilla
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2023-11-02 00:00:00.000000000 Z
13
+ date: 2023-11-04 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: activesupport