canvas_link_migrator 1.0.3 → 1.0.5
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 +3 -2
- data/lib/canvas_link_migrator/resource_map_service.rb +1 -1
- data/lib/canvas_link_migrator/version.rb +1 -1
- data/spec/canvas_link_migrator/imported_html_converter_spec.rb +19 -1
- data/spec/canvas_link_migrator/link_parser_spec.rb +6 -0
- data/spec/canvas_link_migrator/link_resolver_spec.rb +12 -0
- data/spec/fixtures/canvas_resource_map_pages.json +134 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 69ea954296733466368b26038c4408f864cb840c758591a3129a5cb0c2970a96
|
4
|
+
data.tar.gz: 4bb90f2745274adfe514bd22ff321a2ec62dafd379b6ad3cb90aff739c2a8fee
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 26f74e87e3e4a5240d7e0de8782d429d0e194ac311d9453ae636b7cbe114bfdb5fda2948b3c6fd135f462cd5a59369406e3eb908e595b4ab0a1669eb45f536e0
|
7
|
+
data.tar.gz: 31a6317ec5d8fdd8ba524713a5f71ad948740ce6ae27e5f35b3691a78222efeb04a25cf8c127b4c76791e01588831e9df96dc3deea60a2485d31b4d342d7aed8
|
@@ -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)
|
@@ -116,13 +116,14 @@ module CanvasLinkMigrator
|
|
116
116
|
when :file_ref
|
117
117
|
file_id = @migration_id_converter.convert_attachment_migration_id(link[:migration_id])
|
118
118
|
if file_id
|
119
|
-
rest = link[:rest].presence
|
119
|
+
rest = link[:rest].presence
|
120
|
+
rest ||= "/preview" unless link[:target_blank]
|
120
121
|
|
121
122
|
# Icon Maker files should not have the course
|
122
123
|
# context prepended to the URL. This prevents
|
123
124
|
# redirects to non cross-origin friendly urls
|
124
125
|
# during a file fetch
|
125
|
-
if rest
|
126
|
+
if rest&.include?("icon_maker_icon=1")
|
126
127
|
link[:new_value] = "/files/#{file_id}#{rest}"
|
127
128
|
elsif link[:in_media_iframe] && link[:media_attachment]
|
128
129
|
link[:new_value] = "/media_attachments_iframe/#{file_id}#{rest}"
|
@@ -69,7 +69,7 @@ module CanvasLinkMigrator
|
|
69
69
|
|
70
70
|
# Looks up a wiki page slug for a migration id
|
71
71
|
def convert_wiki_page_migration_id_to_slug(migration_id)
|
72
|
-
resources.dig("wiki_pages", migration_id, "destination", "url")
|
72
|
+
resources.dig("wiki_pages", migration_id, "destination", "url") || resources.dig("pages", migration_id, "destination", "url")
|
73
73
|
end
|
74
74
|
|
75
75
|
# looks up a discussion topic
|
@@ -25,7 +25,7 @@ describe CanvasLinkMigrator::ImportedHtmlConverter do
|
|
25
25
|
# tests link_parser and link_resolver
|
26
26
|
|
27
27
|
describe ".convert" do
|
28
|
-
before do
|
28
|
+
before(:each) do
|
29
29
|
@path = "/courses/2/"
|
30
30
|
@converter = CanvasLinkMigrator::ImportedHtmlConverter.new(resource_map: JSON.parse(File.read("spec/fixtures/canvas_resource_map.json")))
|
31
31
|
end
|
@@ -44,6 +44,24 @@ describe CanvasLinkMigrator::ImportedHtmlConverter do
|
|
44
44
|
expect(bad_links).to be_nil
|
45
45
|
end
|
46
46
|
|
47
|
+
context "when pages in resource map but no wiki_pages" do
|
48
|
+
before(:each) do
|
49
|
+
@converter = CanvasLinkMigrator::ImportedHtmlConverter.new(resource_map: JSON.parse(File.read("spec/fixtures/canvas_resource_map_pages.json")))
|
50
|
+
end
|
51
|
+
|
52
|
+
it "converts a wiki reference with migration id" do
|
53
|
+
test_string = %(<a href="%24WIKI_REFERENCE%24/pages/A?query=blah">Test Wiki Page</a>)
|
54
|
+
html, bad_links = @converter.convert_exported_html(test_string)
|
55
|
+
expect(html).to eq %(<a href="#{@path}pages/slug-a?query=blah">Test Wiki Page</a>)
|
56
|
+
expect(bad_links).to be_nil
|
57
|
+
end
|
58
|
+
|
59
|
+
it "converts a wiki reference by migration id" do
|
60
|
+
test_string = %(<a href="wiki_page_migration_id=A">Test Wiki Page</a>)
|
61
|
+
expect(@converter.convert_exported_html(test_string)).to eq([%(<a href="#{@path}pages/slug-a">Test Wiki Page</a>), nil])
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
47
65
|
context "when course attachments exist" do
|
48
66
|
subject { @converter.convert_exported_html(test_string) }
|
49
67
|
|
@@ -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", "")
|
@@ -33,6 +33,12 @@ describe CanvasLinkMigrator::LinkResolver do
|
|
33
33
|
expect(link[:new_value]).to eq("/courses/2/pages/slug-a?foo=bar")
|
34
34
|
end
|
35
35
|
|
36
|
+
it "converts wiki_pages links with pages in resource map" do
|
37
|
+
link = { link_type: :wiki_page, migration_id: "A", query: "?foo=bar" }
|
38
|
+
resolver(JSON.parse(File.read("spec/fixtures/canvas_resource_map_pages.json"))).resolve_link!(link)
|
39
|
+
expect(link[:new_value]).to eq("/courses/2/pages/slug-a?foo=bar")
|
40
|
+
end
|
41
|
+
|
36
42
|
it "converts module_item links" do
|
37
43
|
link = { link_type: :module_item, migration_id: "C", query: "?foo=bar" }
|
38
44
|
resolver.resolve_link!(link)
|
@@ -45,6 +51,12 @@ describe CanvasLinkMigrator::LinkResolver do
|
|
45
51
|
expect(link[:new_value]).to eq("/courses/2/files/6/preview")
|
46
52
|
end
|
47
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
|
+
|
48
60
|
it "converts attachment urls" do
|
49
61
|
link = { link_type: :object, type: "attachments", migration_id: "E", query: "?foo=bar" }
|
50
62
|
resolver.resolve_link!(link)
|
@@ -0,0 +1,134 @@
|
|
1
|
+
{
|
2
|
+
"attachment_path_id_lookup": {
|
3
|
+
"subfolder/test.png": "G",
|
4
|
+
"subfolder/with a space/test.png": "F",
|
5
|
+
"subfolder/with a space/yodawg.mov": "I",
|
6
|
+
"subfolder/withCapital/test.png": "migration_id!",
|
7
|
+
"lolcat.mp3": "H",
|
8
|
+
"test.png": "E"
|
9
|
+
},
|
10
|
+
"contains_migration_ids": true,
|
11
|
+
"destination_course": "2",
|
12
|
+
"destination_hosts": [
|
13
|
+
"apple.edu",
|
14
|
+
"kiwi.edu"
|
15
|
+
],
|
16
|
+
"destination_root_folder": "course files/",
|
17
|
+
"resource_mapping": {
|
18
|
+
"announcements": {
|
19
|
+
"H": {
|
20
|
+
"source": {
|
21
|
+
"id": "9"
|
22
|
+
},
|
23
|
+
"destination": {
|
24
|
+
"id": "10"
|
25
|
+
}
|
26
|
+
}
|
27
|
+
},
|
28
|
+
"assignments": {
|
29
|
+
"I": {
|
30
|
+
"source": {
|
31
|
+
"id": "11"
|
32
|
+
},
|
33
|
+
"destination": {
|
34
|
+
"id": "12"
|
35
|
+
}
|
36
|
+
}
|
37
|
+
},
|
38
|
+
"discussion_topics": {
|
39
|
+
"G": {
|
40
|
+
"destination": {
|
41
|
+
"id": "7"
|
42
|
+
},
|
43
|
+
"source": {
|
44
|
+
"id": "6"
|
45
|
+
}
|
46
|
+
}
|
47
|
+
},
|
48
|
+
"files": {
|
49
|
+
"E": {
|
50
|
+
"destination": {
|
51
|
+
"id": "5",
|
52
|
+
"media_entry_id": "m-stuff"
|
53
|
+
},
|
54
|
+
"source": {
|
55
|
+
"id": "3",
|
56
|
+
"media_entry_id": "m-stuff"
|
57
|
+
}
|
58
|
+
},
|
59
|
+
"F": {
|
60
|
+
"destination": {
|
61
|
+
"id": "6",
|
62
|
+
"media_entry_id": "m-stuff"
|
63
|
+
},
|
64
|
+
"source": {
|
65
|
+
"id": "4",
|
66
|
+
"media_entry_id": "m-stuff"
|
67
|
+
}
|
68
|
+
},
|
69
|
+
"G": {
|
70
|
+
"destination": {
|
71
|
+
"id": "7"
|
72
|
+
},
|
73
|
+
"source": {
|
74
|
+
"id": "2"
|
75
|
+
}
|
76
|
+
},
|
77
|
+
"H": {
|
78
|
+
"destination": {
|
79
|
+
"id": "8",
|
80
|
+
"media_entry_id": "m-lolcat"
|
81
|
+
},
|
82
|
+
"source": {
|
83
|
+
"id": "3",
|
84
|
+
"media_entry_id": "m-lolcat"
|
85
|
+
}
|
86
|
+
},
|
87
|
+
"I": {
|
88
|
+
"destination": {
|
89
|
+
"id": "9",
|
90
|
+
"media_entry_id": "m-yodawg"
|
91
|
+
},
|
92
|
+
"source": {
|
93
|
+
"id": "4",
|
94
|
+
"media_entry_id": "m-yodawg"
|
95
|
+
}
|
96
|
+
}
|
97
|
+
},
|
98
|
+
"module_items": {
|
99
|
+
"C": {
|
100
|
+
"destination": {
|
101
|
+
"id": "3"
|
102
|
+
},
|
103
|
+
"source": {
|
104
|
+
"id": "2"
|
105
|
+
}
|
106
|
+
}
|
107
|
+
},
|
108
|
+
"modules": {
|
109
|
+
"J": {
|
110
|
+
"destination": {
|
111
|
+
"id": "36"
|
112
|
+
},
|
113
|
+
"source": {
|
114
|
+
"id": "22"
|
115
|
+
}
|
116
|
+
}
|
117
|
+
},
|
118
|
+
"pages": {
|
119
|
+
"A": {
|
120
|
+
"destination": {
|
121
|
+
"id": "2",
|
122
|
+
"url": "slug-a"
|
123
|
+
},
|
124
|
+
"source": {
|
125
|
+
"id": "1",
|
126
|
+
"url": "slug-a"
|
127
|
+
}
|
128
|
+
}
|
129
|
+
}
|
130
|
+
},
|
131
|
+
"source_course": "1",
|
132
|
+
"source_host": "pineapple.edu"
|
133
|
+
}
|
134
|
+
|
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.5
|
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-
|
14
|
+
date: 2024-02-09 00:00:00.000000000 Z
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
17
17
|
name: activesupport
|
@@ -147,6 +147,7 @@ files:
|
|
147
147
|
- spec/canvas_link_migrator/link_resolver_spec.rb
|
148
148
|
- spec/canvas_link_migrator_spec.rb
|
149
149
|
- spec/fixtures/canvas_resource_map.json
|
150
|
+
- spec/fixtures/canvas_resource_map_pages.json
|
150
151
|
- spec/spec_helper.rb
|
151
152
|
- test.sh
|
152
153
|
homepage:
|