canvas_link_migrator 1.0.0 → 1.0.2

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: 6c077949f9cef706c71bff4537a9df6a3e53cb5306dadab87fb0281c79754a16
4
+ data.tar.gz: d1f6d129570271a82b293f6422b00cb1b6533233713adaf1479fd5d7efda47cb
5
5
  SHA512:
6
- metadata.gz: 12d6e3e37c9d8115ce1e47712b0f6192a9d4d6617ec038d8d1b94eb3ec27996f4062d60c75b0b1f26b25675be1738a3dbe121fdc5707c182ca78751f7b47010d
7
- data.tar.gz: e9fb1a26ea2aa9b9a24e799f407a05792b26c5743cd919e221e32309d20c49e603a51ec967bf28de51aba60954842793196024d74cae26f232ded871bb55725e
6
+ metadata.gz: b07d22a498fbb5188874aa67a6702be9ee349ed2be2efb5c4f42050d45b7914afb0edeae7d2f2127dae44531631f371cb1d8df62923133f8a88b96bcbe8f997f
7
+ data.tar.gz: f1c6fa682fc28072571d3841d4418e14bc1240b453618ec19be98df2d09ab8a217c3638310bc0383e1a63f32ade812008f69a3198ad436167dd12f5ffc672673
@@ -166,6 +166,10 @@ module CanvasLinkMigrator
166
166
  else
167
167
  result[:old_value] = node[attr]
168
168
  result[:placeholder] = placeholder(result[:old_value])
169
+ # replace the inner html of an anchor tag if it matches the href
170
+ if node.name == "a" && attr == "href" && node["href"] == node.inner_html.delete("\n").strip
171
+ node.inner_html = result[:placeholder]
172
+ end
169
173
  node[attr] = result[:placeholder]
170
174
  end
171
175
  add_unresolved_link(result, item_type, mig_id, field)
@@ -177,16 +181,18 @@ module CanvasLinkMigrator
177
181
  end
178
182
 
179
183
  def resolved(new_url = nil)
180
- { resolved: true, new_url: new_url }
184
+ { resolved: true, new_url: new_url}
181
185
  end
182
186
 
183
187
  # returns a hash with resolution status and data to hold onto if unresolved
184
188
  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
189
+ parsed_url = Addressable::URI.parse(url)
190
+ query_values = parsed_url.query_values
191
+ media_attachment = query_values.try(:delete, "media_attachment") == "true"
192
+ if media_attachment
193
+ parsed_url.query_values = query_values.presence || nil
194
+ url = Addressable::URI.unencode(parsed_url)
195
+ end
190
196
 
191
197
  if url =~ /wiki_page_migration_id=(.*)/
192
198
  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])
@@ -0,0 +1,46 @@
1
+ # frozen_string_literal: true
2
+
3
+ #
4
+ # Copyright (C) 2023 - present Instructure, Inc.
5
+ #
6
+ # This file is part of Canvas.
7
+ #
8
+ # Canvas is free software: you can redistribute it and/or modify it under
9
+ # the terms of the GNU Affero General Public License as published by the Free
10
+ # Software Foundation, version 3 of the License.
11
+ #
12
+ # Canvas is distributed in the hope that it will be useful, but WITHOUT ANY
13
+ # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
14
+ # A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
15
+ # details.
16
+ #
17
+ # You should have received a copy of the GNU Affero General Public License along
18
+ # with this program. If not, see <http://www.gnu.org/licenses/>.
19
+ #
20
+
21
+ require "spec_helper"
22
+
23
+ describe CanvasLinkMigrator::LinkParser do
24
+ def parser
25
+ migration_query_service_mock = double()
26
+ allow(migration_query_service_mock).to receive(:supports_embedded_images).and_return(true)
27
+ allow(migration_query_service_mock).to receive(:fix_relative_urls?).and_return(true)
28
+ CanvasLinkMigrator::LinkParser.new(migration_query_service_mock)
29
+ end
30
+
31
+ describe "convert_link" do
32
+ it "converts inner html of anchor tags when appropriate" do
33
+ doc = Nokogiri::HTML5.fragment("<a href=\"$WIKI_REFERENCE$/pages/1\">$WIKI_REFERENCE$/pages/1</a>")
34
+ parser.convert_link(doc.at_css('a'), "href","wiki_page", "migrationid", "")
35
+ expect(doc.at_css('a')['href']).to include("LINK.PLACEHOLDER")
36
+ expect(doc.at_css('a').inner_html).to include("LINK.PLACEHOLDER")
37
+ end
38
+
39
+ it "doesn't convert inner html of anchor tags if unnecessary" do
40
+ doc = Nokogiri::HTML5.fragment("<a href=\"$WIKI_REFERENCE$/pages/1\">$WIKI_REFERENCE$/pages/5</a>")
41
+ parser.convert_link(doc.at_css('a'), "href","wiki_page", "migrationid", "")
42
+ expect(doc.at_css('a')['href']).to include("LINK.PLACEHOLDER")
43
+ expect(doc.at_css('a').inner_html).not_to include("LINK.PLACEHOLDER")
44
+ end
45
+ end
46
+ end
metadata CHANGED
@@ -1,16 +1,17 @@
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.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mysti Lilla
8
8
  - James Logan
9
9
  - Sarah Gerard
10
+ - Math Costa
10
11
  autorequire:
11
12
  bindir: bin
12
13
  cert_chain: []
13
- date: 2023-11-02 00:00:00.000000000 Z
14
+ date: 2023-11-21 00:00:00.000000000 Z
14
15
  dependencies:
15
16
  - !ruby/object:Gem::Dependency
16
17
  name: activesupport
@@ -129,6 +130,7 @@ email:
129
130
  - mysti@instructure.com
130
131
  - james.logan@instructure.com
131
132
  - sarah.gerard@instructure.com
133
+ - luis.oliveira@instructure.com
132
134
  executables: []
133
135
  extensions: []
134
136
  extra_rdoc_files: []
@@ -141,6 +143,7 @@ files:
141
143
  - lib/canvas_link_migrator/resource_map_service.rb
142
144
  - lib/canvas_link_migrator/version.rb
143
145
  - spec/canvas_link_migrator/imported_html_converter_spec.rb
146
+ - spec/canvas_link_migrator/link_parser_spec.rb
144
147
  - spec/canvas_link_migrator/link_resolver_spec.rb
145
148
  - spec/canvas_link_migrator_spec.rb
146
149
  - spec/fixtures/canvas_resource_map.json