canvas_link_migrator 1.0.1 → 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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6c077949f9cef706c71bff4537a9df6a3e53cb5306dadab87fb0281c79754a16
|
4
|
+
data.tar.gz: d1f6d129570271a82b293f6422b00cb1b6533233713adaf1479fd5d7efda47cb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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,7 +181,7 @@ 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
|
@@ -186,7 +190,7 @@ module CanvasLinkMigrator
|
|
186
190
|
query_values = parsed_url.query_values
|
187
191
|
media_attachment = query_values.try(:delete, "media_attachment") == "true"
|
188
192
|
if media_attachment
|
189
|
-
parsed_url.query_values = query_values.
|
193
|
+
parsed_url.query_values = query_values.presence || nil
|
190
194
|
url = Addressable::URI.unencode(parsed_url)
|
191
195
|
end
|
192
196
|
|
@@ -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.
|
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-
|
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
|