canvas_link_migrator 1.0.4 → 1.0.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/canvas_link_migrator/link_parser.rb +3 -1
- data/lib/canvas_link_migrator/link_resolver.rb +9 -2
- data/lib/canvas_link_migrator/version.rb +1 -1
- data/spec/canvas_link_migrator/imported_html_converter_spec.rb +10 -0
- data/spec/canvas_link_migrator/link_parser_spec.rb +6 -0
- data/spec/canvas_link_migrator/link_resolver_spec.rb +6 -0
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bb741be0946fbad43cb23efadcbeb87d1338485b475cc2c3e699cfef07599263
|
4
|
+
data.tar.gz: f98e804aa56242fe5f08e123166f776b0f8f911b1590f541818ae6b70675395e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3d88c62ed1c8db1c690599ed7f5640a5b516a701c1ee8cd18765a80f1860db104107c8b2135357d5f205a5d176e95fedd3090a9c0dc9c84641bf2f6163d356f2
|
7
|
+
data.tar.gz: 1a9439977136930dfd3b6ea3fdff6d767c772c3ea9107348f4ba51253b1a04710885b141dbb1764cca5c6985213a1131c42bb1bad8676227d9c04a0ef00423fa
|
@@ -210,7 +210,9 @@ module CanvasLinkMigrator
|
|
210
210
|
migration_id: $1,
|
211
211
|
rest: $2,
|
212
212
|
in_media_iframe: attr == "src" && ["iframe", "source"].include?(node.name) && node["data-media-id"],
|
213
|
-
media_attachment: media_attachment
|
213
|
+
media_attachment: media_attachment,
|
214
|
+
target_blank: node['target'] == "_blank" && node.name == "a" && attr == "href"
|
215
|
+
)
|
214
216
|
elsif url =~ %r{(?:\$CANVAS_OBJECT_REFERENCE\$|\$WIKI_REFERENCE\$)/([^/]*)/([^?]*)(\?.*)?}
|
215
217
|
if KNOWN_REFERENCE_TYPES.include?($1)
|
216
218
|
unresolved(:object, type: $1, migration_id: $2, query: $3)
|
@@ -108,6 +108,8 @@ module CanvasLinkMigrator
|
|
108
108
|
when :file
|
109
109
|
rel_path = link[:rel_path]
|
110
110
|
new_url = resolve_relative_file_url(rel_path)
|
111
|
+
# leave user urls alone
|
112
|
+
new_url ||= rel_path if is_relative_user_url(rel_path)
|
111
113
|
unless new_url
|
112
114
|
new_url = missing_relative_file_url(rel_path)
|
113
115
|
link[:missing_url] = new_url
|
@@ -116,13 +118,14 @@ module CanvasLinkMigrator
|
|
116
118
|
when :file_ref
|
117
119
|
file_id = @migration_id_converter.convert_attachment_migration_id(link[:migration_id])
|
118
120
|
if file_id
|
119
|
-
rest = link[:rest].presence
|
121
|
+
rest = link[:rest].presence
|
122
|
+
rest ||= "/preview" unless link[:target_blank]
|
120
123
|
|
121
124
|
# Icon Maker files should not have the course
|
122
125
|
# context prepended to the URL. This prevents
|
123
126
|
# redirects to non cross-origin friendly urls
|
124
127
|
# during a file fetch
|
125
|
-
if rest
|
128
|
+
if rest&.include?("icon_maker_icon=1")
|
126
129
|
link[:new_value] = "/files/#{file_id}#{rest}"
|
127
130
|
elsif link[:in_media_iframe] && link[:media_attachment]
|
128
131
|
link[:new_value] = "/media_attachments_iframe/#{file_id}#{rest}"
|
@@ -254,5 +257,9 @@ module CanvasLinkMigrator
|
|
254
257
|
nil
|
255
258
|
end
|
256
259
|
end
|
260
|
+
|
261
|
+
def is_relative_user_url(rel_path)
|
262
|
+
rel_path.start_with?("/users/")
|
263
|
+
end
|
257
264
|
end
|
258
265
|
end
|
@@ -86,6 +86,16 @@ describe CanvasLinkMigrator::ImportedHtmlConverter do
|
|
86
86
|
expect(@converter.convert_exported_html(test_string)).to eq([%{<p>This is an image: <br><img src="#{@path}files/6/preview" alt=":("></p>}, nil])
|
87
87
|
end
|
88
88
|
|
89
|
+
it "leaves relative user attachments alone" do
|
90
|
+
test_string = %{<p> This is an image: <img src="/users/1/files/1/preview?verifier=someVerifier" alt="some_image"></p>}
|
91
|
+
expect(@converter.convert_exported_html(test_string)).to eq([test_string, nil])
|
92
|
+
end
|
93
|
+
|
94
|
+
it "leaves absolute user attachments alone" do
|
95
|
+
test_string = %{<p> This is an image: <img src="http://mycanvas.com/users/1/files/1/preview?verifier=someVerifier" alt="some_image"></p>}
|
96
|
+
expect(@converter.convert_exported_html(test_string)).to eq([test_string, nil])
|
97
|
+
end
|
98
|
+
|
89
99
|
it "finds an attachment by path" do
|
90
100
|
test_string = %{<p>This is an image: <br /><img src="%24IMS_CC_FILEBASE%24/test.png" alt=":(" /></p>}
|
91
101
|
|
@@ -29,6 +29,12 @@ describe CanvasLinkMigrator::LinkParser do
|
|
29
29
|
end
|
30
30
|
|
31
31
|
describe "convert_link" do
|
32
|
+
it "marks target=_blank anchor tags" do
|
33
|
+
doc = Nokogiri::HTML5.fragment("<a target=\"_blank\"></a>")
|
34
|
+
parsed = parser.parse_url("$CANVAS_COURSE_REFERENCE$/file_ref/whatevs", doc.at_css('a'), "href")
|
35
|
+
expect(parsed[:target_blank]).to be true
|
36
|
+
end
|
37
|
+
|
32
38
|
it "converts inner html of anchor tags when appropriate" do
|
33
39
|
doc = Nokogiri::HTML5.fragment("<a href=\"$WIKI_REFERENCE$/pages/1\">$WIKI_REFERENCE$/pages/1</a>")
|
34
40
|
parser.convert_link(doc.at_css('a'), "href","wiki_page", "migrationid", "")
|
@@ -51,6 +51,12 @@ describe CanvasLinkMigrator::LinkResolver do
|
|
51
51
|
expect(link[:new_value]).to eq("/courses/2/files/6/preview")
|
52
52
|
end
|
53
53
|
|
54
|
+
it "does not suffix /preview to target blank links" do
|
55
|
+
link = { link_type: :file_ref, target_blank: true, migration_id: "F" }
|
56
|
+
resolver.resolve_link!(link)
|
57
|
+
expect(link[:new_value]).to eq("/courses/2/files/6")
|
58
|
+
end
|
59
|
+
|
54
60
|
it "converts attachment urls" do
|
55
61
|
link = { link_type: :object, type: "attachments", migration_id: "E", query: "?foo=bar" }
|
56
62
|
resolver.resolve_link!(link)
|
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.
|
4
|
+
version: 1.0.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mysti Lilla
|
@@ -11,7 +11,7 @@ authors:
|
|
11
11
|
autorequire:
|
12
12
|
bindir: bin
|
13
13
|
cert_chain: []
|
14
|
-
date: 2024-02-
|
14
|
+
date: 2024-02-27 00:00:00.000000000 Z
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
17
17
|
name: activesupport
|
@@ -152,7 +152,8 @@ files:
|
|
152
152
|
- test.sh
|
153
153
|
homepage:
|
154
154
|
licenses: []
|
155
|
-
metadata:
|
155
|
+
metadata:
|
156
|
+
source_code_uri: https://github.com/instructure/canvas_link_migrator
|
156
157
|
post_install_message:
|
157
158
|
rdoc_options: []
|
158
159
|
require_paths:
|