canvas_link_migrator 1.0.6 → 1.0.7
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 +32 -25
- data/lib/canvas_link_migrator/link_resolver.rb +13 -32
- data/lib/canvas_link_migrator/resource_map_service.rb +12 -0
- data/lib/canvas_link_migrator/version.rb +1 -1
- data/spec/canvas_link_migrator/imported_html_converter_spec.rb +71 -24
- data/spec/canvas_link_migrator/link_parser_spec.rb +2 -5
- data/spec/fixtures/canvas_resource_map.json +4 -3
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e74a62a030858ee5785138c032c6a03e38f75d05acac287dbded691fa642c593
|
4
|
+
data.tar.gz: d380a8f3b556d0da9d18e198483e48590e767b481415dd417d808da70d12f5fe
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a8b6f64385cfa820b655f009a327bb207320ffb673ea4228b69f13584550b9da18cb5d79abdf0f3c7c861249ad2a49c20c5fcec0d9372d6299dd832dfe2e18f9
|
7
|
+
data.tar.gz: 442098e04f4bd979f6c64eb6a83060cd8635f8c1cc7dc28e4688b0516cd9dc4215877352e9c3dde7c55798aa88059987ca1578bfb612e844222099940608ecde
|
@@ -82,7 +82,7 @@ module CanvasLinkMigrator
|
|
82
82
|
|
83
83
|
def convert(html, item_type, mig_id, field, remove_outer_nodes_if_one_child: nil)
|
84
84
|
mig_id = mig_id.to_s
|
85
|
-
doc = Nokogiri::HTML5(html || "")
|
85
|
+
doc = Nokogiri::HTML5.fragment(html || "")
|
86
86
|
|
87
87
|
# Replace source tags with iframes
|
88
88
|
doc.search("source[data-media-id]").each do |source|
|
@@ -94,24 +94,36 @@ module CanvasLinkMigrator
|
|
94
94
|
source.remove
|
95
95
|
end
|
96
96
|
|
97
|
+
# Replace old style media anchor tags with iframes
|
98
|
+
doc.search("a[id*='media_comment_']").each do |media_node|
|
99
|
+
media_node.name = "iframe"
|
100
|
+
# smallest accepted size for iframe since we don't have the size available for these
|
101
|
+
media_node["style"] = "width: 320px; height: 240px; display: inline-block;"
|
102
|
+
media_node["title"] = media_node.text
|
103
|
+
media_node.child&.remove
|
104
|
+
media_node["data-media-type"] = media_node["class"].match(/(audio|video)_comment/)[1]
|
105
|
+
media_node["src"] = media_node["href"]
|
106
|
+
media_node.delete("href")
|
107
|
+
media_node["allowfullscreen"] = "allowfullscreen"
|
108
|
+
media_node["allow"] = "fullscreen"
|
109
|
+
media_node["data-media-id"] = media_node["id"].sub("media_comment_", "")
|
110
|
+
end
|
111
|
+
|
97
112
|
doc.search("*").each do |node|
|
98
113
|
LINK_ATTRS.each do |attr|
|
99
114
|
convert_link(node, attr, item_type, mig_id, field)
|
100
115
|
end
|
101
116
|
end
|
102
117
|
|
103
|
-
node = doc.at_css("body")
|
104
|
-
return "" unless node
|
105
|
-
|
106
118
|
if remove_outer_nodes_if_one_child
|
107
|
-
while
|
108
|
-
break unless CONTAINER_TYPES.member?(
|
119
|
+
while doc.children.size == 1 && doc.child.child
|
120
|
+
break unless CONTAINER_TYPES.member?(doc.child.name) && doc.child.attributes.blank?
|
109
121
|
|
110
|
-
|
122
|
+
doc = doc.child
|
111
123
|
end
|
112
124
|
end
|
113
125
|
|
114
|
-
|
126
|
+
doc.inner_html
|
115
127
|
rescue Nokogiri::SyntaxError
|
116
128
|
""
|
117
129
|
end
|
@@ -189,16 +201,12 @@ module CanvasLinkMigrator
|
|
189
201
|
{ resolved: true, new_url: new_url}
|
190
202
|
end
|
191
203
|
|
204
|
+
def media_params(type)
|
205
|
+
"?type=#{type}&embedded=true"
|
206
|
+
end
|
207
|
+
|
192
208
|
# returns a hash with resolution status and data to hold onto if unresolved
|
193
209
|
def parse_url(url, node, attr)
|
194
|
-
parsed_url = Addressable::URI.parse(url)
|
195
|
-
query_values = parsed_url.query_values
|
196
|
-
media_attachment = query_values.try(:delete, "media_attachment") == "true"
|
197
|
-
if media_attachment
|
198
|
-
parsed_url.query_values = query_values.presence || nil
|
199
|
-
url = Addressable::URI.unencode(parsed_url)
|
200
|
-
end
|
201
|
-
|
202
210
|
if url =~ /wiki_page_migration_id=(.*)/
|
203
211
|
unresolved(:wiki_page, migration_id: $1)
|
204
212
|
elsif url =~ /discussion_topic_migration_id=(.*)/
|
@@ -206,11 +214,12 @@ module CanvasLinkMigrator
|
|
206
214
|
elsif url =~ %r{\$CANVAS_COURSE_REFERENCE\$/modules/items/([^?]*)(\?.*)?}
|
207
215
|
unresolved(:module_item, migration_id: $1, query: $2)
|
208
216
|
elsif url =~ %r{\$CANVAS_COURSE_REFERENCE\$/file_ref/([^/?#]+)(.*)}
|
217
|
+
in_media_iframe = (attr == "src" && ["iframe", "source"].include?(node.name) && node["data-media-id"])
|
218
|
+
rest = in_media_iframe ? media_params(node["data-media-type"]) : $2
|
209
219
|
unresolved(:file_ref,
|
210
220
|
migration_id: $1,
|
211
|
-
rest:
|
212
|
-
in_media_iframe:
|
213
|
-
media_attachment: media_attachment,
|
221
|
+
rest: rest,
|
222
|
+
in_media_iframe: in_media_iframe,
|
214
223
|
target_blank: node['target'] == "_blank" && node.name == "a" && attr == "href"
|
215
224
|
)
|
216
225
|
elsif url =~ %r{(?:\$CANVAS_OBJECT_REFERENCE\$|\$WIKI_REFERENCE\$)/([^/]*)/([^?]*)(\?.*)?}
|
@@ -223,19 +232,17 @@ module CanvasLinkMigrator
|
|
223
232
|
end
|
224
233
|
elsif url =~ %r{\$CANVAS_COURSE_REFERENCE\$/(.*)}
|
225
234
|
resolved("#{@migration_query_service.context_path}/#{$1}")
|
226
|
-
|
227
235
|
elsif url =~ %r{\$IMS(?:-|_)CC(?:-|_)FILEBASE\$/(.*)}
|
228
236
|
rel_path = URI::DEFAULT_PARSER.unescape($1)
|
229
237
|
if (attr == "href" && node["class"]&.include?("instructure_inline_media_comment")) ||
|
230
238
|
(attr == "src" && ["iframe", "source"].include?(node.name) && node["data-media-id"])
|
231
|
-
unresolved(:media_object, rel_path: rel_path
|
239
|
+
unresolved(:media_object, rel_path: rel_path)
|
232
240
|
else
|
233
241
|
unresolved(:file, rel_path: rel_path)
|
234
242
|
end
|
235
|
-
elsif (attr == "
|
236
|
-
|
237
|
-
|
238
|
-
resolved
|
243
|
+
elsif (attr == "src" && ["iframe", "source"].include?(node.name) && node["data-media-id"])
|
244
|
+
# media_objects_iframe course copy reference without an attachment id, change to media_attachments_iframe
|
245
|
+
unresolved(:media_object, rel_path: node["src"])
|
239
246
|
elsif @migration_query_service.supports_embedded_images && attr == "src" && (info_match = url.match(%r{\Adata:(?<mime_type>[-\w]+/[-\w+.]+)?;base64,(?<image>.*)}m))
|
240
247
|
result = @migration_query_service.link_embedded_image(info_match)
|
241
248
|
if result[:resolved]
|
@@ -92,11 +92,11 @@ module CanvasLinkMigrator
|
|
92
92
|
# see LinkParser for details
|
93
93
|
rel_path = link[:rel_path]
|
94
94
|
node = Nokogiri::HTML5.fragment(link[:old_value]).children.first
|
95
|
-
new_url =
|
95
|
+
new_url = resolve_media_data(node, rel_path)
|
96
96
|
new_url ||= resolve_relative_file_url(rel_path)
|
97
97
|
|
98
98
|
unless new_url
|
99
|
-
new_url
|
99
|
+
new_url = rel_path.include?("#{context_path}/file_contents") ? rel_path : missing_relative_file_url(rel_path)
|
100
100
|
link[:missing_url] = new_url
|
101
101
|
end
|
102
102
|
if ["iframe", "source"].include?(node.name)
|
@@ -127,12 +127,13 @@ module CanvasLinkMigrator
|
|
127
127
|
# during a file fetch
|
128
128
|
if rest&.include?("icon_maker_icon=1")
|
129
129
|
link[:new_value] = "/files/#{file_id}#{rest}"
|
130
|
-
elsif link[:in_media_iframe]
|
130
|
+
elsif link[:in_media_iframe]
|
131
131
|
link[:new_value] = "/media_attachments_iframe/#{file_id}#{rest}"
|
132
132
|
else
|
133
133
|
link[:new_value] = "#{context_path}/files/#{file_id}#{rest}"
|
134
|
-
link[:new_value] = "/media_objects_iframe?mediahref=#{link[:new_value]}" if link[:in_media_iframe]
|
135
134
|
end
|
135
|
+
else
|
136
|
+
link[:missing_url] = link[:old_value].partition("$CANVAS_COURSE_REFERENCE$").last
|
136
137
|
end
|
137
138
|
else
|
138
139
|
raise "unrecognized link_type (#{link[:link_type]}) in unresolved link"
|
@@ -216,40 +217,20 @@ module CanvasLinkMigrator
|
|
216
217
|
new_url
|
217
218
|
end
|
218
219
|
|
219
|
-
def media_iframe_url(media_id, media_type = nil)
|
220
|
-
url = "/media_objects_iframe/#{media_id}"
|
221
|
-
url += "?type=#{media_type}" if media_type.present?
|
222
|
-
url
|
223
|
-
end
|
224
|
-
|
225
220
|
def media_attachment_iframe_url(file_id, media_type = nil)
|
226
|
-
url = "/media_attachments_iframe/#{file_id}"
|
227
|
-
url += "
|
221
|
+
url = "/media_attachments_iframe/#{file_id}?embedded=true"
|
222
|
+
url += "&type=#{media_type}" if media_type.present?
|
228
223
|
url
|
229
224
|
end
|
230
225
|
|
231
|
-
def
|
232
|
-
if (file = find_file_in_context(rel_path[/^[^?]+/])) # strip query string for this search
|
226
|
+
def resolve_media_data(node, rel_path)
|
227
|
+
if rel_path && (file = find_file_in_context(rel_path[/^[^?]+/])) # strip query string for this search
|
233
228
|
media_id = file.try(:media_object)&.media_id || file["media_entry_id"]
|
234
|
-
|
235
|
-
|
236
|
-
node["data-media-id"] = media_id
|
237
|
-
if media_attachment
|
238
|
-
return media_attachment_iframe_url(file["id"], node["data-media-type"])
|
239
|
-
else
|
240
|
-
return media_iframe_url(media_id, node["data-media-type"])
|
241
|
-
end
|
242
|
-
else
|
243
|
-
node["id"] = "media_comment_#{media_id}"
|
244
|
-
return "/media_objects/#{media_id}"
|
245
|
-
end
|
246
|
-
end
|
247
|
-
end
|
248
|
-
|
249
|
-
if node["id"] && node["id"] =~ /\Amedia_comment_(.+)\z/
|
250
|
-
"/media_objects/#{$1}"
|
229
|
+
node["data-media-id"] = media_id # safe to delete?
|
230
|
+
media_attachment_iframe_url(file["id"], node["data-media-type"])
|
251
231
|
elsif node["data-media-id"].present?
|
252
|
-
|
232
|
+
file = @migration_id_converter.lookup_attachment_by_media_id(node["data-media-id"])
|
233
|
+
file ? media_attachment_iframe_url(file["id"], node["data-media-type"]) : nil
|
253
234
|
else
|
254
235
|
node.delete("class")
|
255
236
|
node.delete("id")
|
@@ -106,5 +106,17 @@ module CanvasLinkMigrator
|
|
106
106
|
def lookup_attachment_by_migration_id(migration_id)
|
107
107
|
resources.dig("files", migration_id, "destination")
|
108
108
|
end
|
109
|
+
|
110
|
+
def media_map
|
111
|
+
@media_map ||= resources["files"].each_with_object({}) do |(_mig_id, file), map|
|
112
|
+
media_id = file.dig("destination", "media_entry_id")
|
113
|
+
next unless media_id
|
114
|
+
map[media_id] = file
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
118
|
+
def lookup_attachment_by_media_id(media_id)
|
119
|
+
media_map.dig(media_id, "destination")
|
120
|
+
end
|
109
121
|
end
|
110
122
|
end
|
@@ -210,67 +210,114 @@ describe CanvasLinkMigrator::ImportedHtmlConverter do
|
|
210
210
|
expect(bad_links[0]).to include({ link_type: :file, missing_url: "/courses/2/file_contents/course%20files/relative/path/to/file%20with%20space.html" })
|
211
211
|
end
|
212
212
|
|
213
|
-
it "
|
213
|
+
it "changes old media URL types into media_attachments_iframe" do
|
214
214
|
test_string = <<~HTML.strip
|
215
215
|
<p>
|
216
216
|
with media object url: <a id="media_comment_m-stuff" class="instructure_inline_media_comment video_comment" href="/media_objects/m-stuff">this is a media comment</a>
|
217
217
|
with file content url: <a id="media_comment_0_bq09qam2" class="instructure_inline_media_comment video_comment" href="/courses/2/file_contents/course%20files/media_objects/0_bq09qam2">this is a media comment</a>
|
218
|
+
with mediahref url: <iframe data-media-type="video" src="/media_objects_iframe?mediahref=$CANVAS_COURSE_REFERENCE$/file_ref/I/download" data-media-id="m-yodawg"></iframe>
|
218
219
|
</p>
|
219
220
|
HTML
|
220
221
|
|
221
|
-
|
222
|
+
expected_string = <<~HTML.strip
|
223
|
+
<p>
|
224
|
+
with media object url: <iframe id="media_comment_m-stuff" class="instructure_inline_media_comment video_comment" style="width: 320px; height: 240px; display: inline-block;" title="this is a media comment" data-media-type="video" src="/media_attachments_iframe/5?embedded=true&type=video" allowfullscreen="allowfullscreen" allow="fullscreen" data-media-id="m-stuff"></iframe>
|
225
|
+
with file content url: <iframe id="media_comment_0_bq09qam2" class="instructure_inline_media_comment video_comment" style="width: 320px; height: 240px; display: inline-block;" title="this is a media comment" data-media-type="video" src="/media_attachments_iframe/6?embedded=true&type=video" allowfullscreen="allowfullscreen" allow="fullscreen" data-media-id="0_bq09qam2"></iframe>
|
226
|
+
with mediahref url: <iframe data-media-type="video" src="/media_attachments_iframe/9?type=video&embedded=true" data-media-id="m-yodawg"></iframe>
|
227
|
+
</p>
|
228
|
+
HTML
|
229
|
+
|
230
|
+
expect(@converter.convert_exported_html(test_string)).to eq([expected_string, nil])
|
222
231
|
end
|
223
232
|
|
224
|
-
it "handles
|
225
|
-
test_string =
|
233
|
+
it "handles old media types where we can't find the file" do
|
234
|
+
test_string = <<~HTML.strip
|
235
|
+
<p>
|
236
|
+
with media object url: <a id="media_comment_m-stuff1" class="instructure_inline_media_comment video_comment" href="/media_objects/m-stuff1">this is a media comment</a>
|
237
|
+
with file content url: <a id="media_comment_0_bq09qam3" class="instructure_inline_media_comment video_comment" href="/courses/2/file_contents/course%20files/media_objects/0_bq09qam3">this is a media comment</a>
|
238
|
+
with mediahref url: <iframe data-media-type="video" src="/media_objects_iframe?mediahref=$CANVAS_COURSE_REFERENCE$/file_ref/yarg/download" data-media-id="m-yodawg"></iframe>
|
239
|
+
</p>
|
240
|
+
HTML
|
241
|
+
|
242
|
+
expected_string = <<~HTML.strip
|
243
|
+
<p>
|
244
|
+
with media object url: <iframe id="media_comment_m-stuff1" class="instructure_inline_media_comment video_comment" style="width: 320px; height: 240px; display: inline-block;" title="this is a media comment" data-media-type="video" src="/courses/2/file_contents/course%20files/media_objects/m-stuff1" allowfullscreen="allowfullscreen" allow="fullscreen" data-media-id="m-stuff1"></iframe>
|
245
|
+
with file content url: <iframe id="media_comment_0_bq09qam3" class="instructure_inline_media_comment video_comment" style="width: 320px; height: 240px; display: inline-block;" title="this is a media comment" data-media-type="video" src="/courses/2/file_contents/course%20files/media_objects/0_bq09qam3" allowfullscreen="allowfullscreen" allow="fullscreen" data-media-id="0_bq09qam3"></iframe>
|
246
|
+
with mediahref url: <iframe data-media-type="video" src="/media_objects_iframe?mediahref=$CANVAS_COURSE_REFERENCE$/file_ref/yarg/download" data-media-id="m-yodawg"></iframe>
|
247
|
+
</p>
|
248
|
+
HTML
|
226
249
|
|
227
|
-
|
250
|
+
expected_errors = [
|
251
|
+
{
|
252
|
+
link_type: :media_object,
|
253
|
+
missing_url: "/courses/2/file_contents/course%20files/media_objects/m-stuff1"
|
254
|
+
},
|
255
|
+
{
|
256
|
+
link_type: :media_object,
|
257
|
+
missing_url: "/courses/2/file_contents/course%20files/media_objects/0_bq09qam3"
|
258
|
+
},
|
259
|
+
{
|
260
|
+
link_type: :file_ref, missing_url: "/file_ref/yarg/download"
|
261
|
+
}
|
262
|
+
]
|
263
|
+
expect(@converter.convert_exported_html(test_string)).to eq([expected_string, expected_errors])
|
228
264
|
end
|
229
265
|
|
230
|
-
it "
|
231
|
-
test_string =
|
232
|
-
|
266
|
+
it "handles and repair half broken media links" do
|
267
|
+
test_string = <<~HTML.strip
|
268
|
+
<p>
|
269
|
+
with wrong file in href: <a href="/courses/2/file_contents/%24IMS_CC_FILEBASE%24/#" class="instructure_inline_media_comment video_comment" id="media_comment_m-stuff">this is a media comment</a><br><br>
|
270
|
+
with no href: <a class="instructure_inline_media_comment video_comment" id="media_comment_m-stuff" href="#"></a><br><br>
|
271
|
+
</p>
|
272
|
+
HTML
|
273
|
+
expected_string = <<~HTML.strip
|
274
|
+
<p>
|
275
|
+
with wrong file in href: <iframe class="instructure_inline_media_comment video_comment" id="media_comment_m-stuff" style="width: 320px; height: 240px; display: inline-block;" title="this is a media comment" data-media-type="video" src="/media_attachments_iframe/5?embedded=true&type=video" allowfullscreen="allowfullscreen" allow="fullscreen" data-media-id="m-stuff"></iframe><br><br>
|
276
|
+
with no href: <iframe class="instructure_inline_media_comment video_comment" id="media_comment_m-stuff" style="width: 320px; height: 240px; display: inline-block;" title="" data-media-type="video" src="/media_attachments_iframe/5?embedded=true&type=video" allowfullscreen="allowfullscreen" allow="fullscreen" data-media-id="m-stuff"></iframe><br><br>
|
277
|
+
</p>
|
278
|
+
HTML
|
279
|
+
expect(@converter.convert_exported_html(test_string)).to eq([expected_string, nil])
|
280
|
+
end
|
281
|
+
|
282
|
+
it "converts old RCE media object iframes" do
|
283
|
+
test_string = %(<iframe style="width: 400px; height: 225px; display: inline-block;" title="this is a media comment" data-media-type="video" src="/media_objects_iframe/m-lolcat?type=video" allowfullscreen="allowfullscreen" allow="fullscreen" data-media-id="m-lolcat"></iframe>)
|
284
|
+
replacement_string = %(<iframe style="width: 400px; height: 225px; display: inline-block;" title="this is a media comment" data-media-type="video" src="/media_attachments_iframe/8?embedded=true&type=video" allowfullscreen="allowfullscreen" allow="fullscreen" data-media-id="m-lolcat"></iframe>)
|
285
|
+
expect(@converter.convert_exported_html(test_string)).to eq([replacement_string, nil])
|
233
286
|
end
|
234
287
|
|
235
288
|
it "handles and repair half broken new RCE media iframes" do
|
236
|
-
test_string = %(<iframe style="width: 400px; height: 225px; display: inline-block;" title="this is a media comment" data-media-type="video" src="%24IMS_CC_FILEBASE%24/#" allowfullscreen="allowfullscreen" allow="fullscreen" data-media-id="m-
|
237
|
-
repaired_string = %(<iframe style="width: 400px; height: 225px; display: inline-block;" title="this is a media comment" data-media-type="video" src="/
|
289
|
+
test_string = %(<iframe style="width: 400px; height: 225px; display: inline-block;" title="this is a media comment" data-media-type="video" src="%24IMS_CC_FILEBASE%24/#" allowfullscreen="allowfullscreen" allow="fullscreen" data-media-id="m-lolcat"></iframe>)
|
290
|
+
repaired_string = %(<iframe style="width: 400px; height: 225px; display: inline-block;" title="this is a media comment" data-media-type="video" src="/media_attachments_iframe/8?embedded=true&type=video" allowfullscreen="allowfullscreen" allow="fullscreen" data-media-id="m-lolcat"></iframe>)
|
238
291
|
expect(@converter.convert_exported_html(test_string)).to eq([repaired_string, nil])
|
239
292
|
end
|
240
293
|
|
241
294
|
it "converts source tags to RCE media iframes" do
|
242
|
-
test_string = %(<video style="width: 400px; height: 225px; display: inline-block;" title="this is a media comment" data-media-type="video" allowfullscreen="allowfullscreen" allow="fullscreen" data-media-id="m-
|
243
|
-
converted_string = %(<iframe style="width: 400px; height: 225px; display: inline-block;" title="this is a media comment" data-media-type="video" allowfullscreen="allowfullscreen" allow="fullscreen" data-media-id="m-
|
295
|
+
test_string = %(<video style="width: 400px; height: 225px; display: inline-block;" title="this is a media comment" data-media-type="video" allowfullscreen="allowfullscreen" allow="fullscreen" data-media-id="m-lolcat"><source src="/media_objects_iframe/m-lolcat?type=video" data-media-id="m-lolcat" data-media-type="video"></video>)
|
296
|
+
converted_string = %(<iframe style="width: 400px; height: 225px; display: inline-block;" title="this is a media comment" data-media-type="video" allowfullscreen="allowfullscreen" allow="fullscreen" data-media-id="m-lolcat" src="/media_attachments_iframe/8?embedded=true&type=video"></iframe>)
|
244
297
|
expect(@converter.convert_exported_html(test_string)).to eq([converted_string, nil])
|
245
298
|
|
246
|
-
test_string = %(<audio style="width: 400px; height: 225px; display: inline-block;" title="this is a media comment" data-media-type="audio" data-media-id="m-
|
247
|
-
converted_string = %(<iframe style="width: 400px; height: 225px; display: inline-block;" title="this is a media comment" data-media-type="audio" data-media-id="m-
|
299
|
+
test_string = %(<audio style="width: 400px; height: 225px; display: inline-block;" title="this is a media comment" data-media-type="audio" data-media-id="m-yodawg"><source src="/media_objects_iframe/m-yodawg?type=audio" data-media-id="m-yodawg" data-media-type="audio"></audio>)
|
300
|
+
converted_string = %(<iframe style="width: 400px; height: 225px; display: inline-block;" title="this is a media comment" data-media-type="audio" data-media-id="m-yodawg" src="/media_attachments_iframe/9?embedded=true&type=audio"></iframe>)
|
248
301
|
expect(@converter.convert_exported_html(test_string)).to eq([converted_string, nil])
|
249
302
|
end
|
250
303
|
|
251
304
|
it "converts source tags to RCE media attachment iframes" do
|
252
305
|
test_string = %(<video style="width: 400px; height: 225px; display: inline-block;" title="this is a media comment" data-media-type="video" allowfullscreen="allowfullscreen" allow="fullscreen" data-media-id="m-stuff"><source src="$IMS-CC-FILEBASE$/subfolder/with a space/yodawg.mov?canvas_=1&canvas_qs_type=video&canvas_qs_amp=&canvas_qs_embedded=true&media_attachment=true" data-media-id="m-stuff" data-media-type="video"></video>)
|
253
|
-
converted_string = %(<iframe style="width: 400px; height: 225px; display: inline-block;" title="this is a media comment" data-media-type="video" allowfullscreen="allowfullscreen" allow="fullscreen" data-media-id="m-yodawg" src="/media_attachments_iframe/9?type=video"></iframe>)
|
306
|
+
converted_string = %(<iframe style="width: 400px; height: 225px; display: inline-block;" title="this is a media comment" data-media-type="video" allowfullscreen="allowfullscreen" allow="fullscreen" data-media-id="m-yodawg" src="/media_attachments_iframe/9?embedded=true&type=video"></iframe>)
|
254
307
|
expect(@converter.convert_exported_html(test_string)).to eq([converted_string, nil])
|
255
308
|
|
256
309
|
test_string = %(<audio style="width: 400px; height: 225px; display: inline-block;" title="this is a media comment" data-media-type="audio" data-media-id="m-stuff"><source src="$IMS-CC-FILEBASE$/lolcat.mp3?canvas_=1&canvas_qs_type=audio&canvas_qs_amp=&canvas_qs_embedded=true&media_attachment=true" data-media-id="m-stuff" data-media-type="audio"></video>)
|
257
|
-
converted_string = %(<iframe style="width: 400px; height: 225px; display: inline-block;" title="this is a media comment" data-media-type="audio" data-media-id="m-lolcat" src="/media_attachments_iframe/8?type=audio"></iframe>)
|
310
|
+
converted_string = %(<iframe style="width: 400px; height: 225px; display: inline-block;" title="this is a media comment" data-media-type="audio" data-media-id="m-lolcat" src="/media_attachments_iframe/8?embedded=true&type=audio"></iframe>)
|
258
311
|
expect(@converter.convert_exported_html(test_string)).to eq([converted_string, nil])
|
259
312
|
end
|
260
313
|
|
261
314
|
it "converts course copy style media attachmet iframe links" do
|
262
315
|
test_string = %(<video style="width: 400px; height: 225px; display: inline-block;" title="this is a media comment" data-media-type="video" allowfullscreen="allowfullscreen" allow="fullscreen" data-media-id="m-yodawg"><source src="$CANVAS_COURSE_REFERENCE$/file_ref/I?media_attachment=true&type=video" data-media-id="m-yodawg" data-media-type="video"></video>)
|
263
|
-
converted_string = %(<iframe style="width: 400px; height: 225px; display: inline-block;" title="this is a media comment" data-media-type="video" allowfullscreen="allowfullscreen" allow="fullscreen" data-media-id="m-yodawg" src="/media_attachments_iframe/9?type=video"></iframe>)
|
316
|
+
converted_string = %(<iframe style="width: 400px; height: 225px; display: inline-block;" title="this is a media comment" data-media-type="video" allowfullscreen="allowfullscreen" allow="fullscreen" data-media-id="m-yodawg" src="/media_attachments_iframe/9?type=video&embedded=true"></iframe>)
|
264
317
|
expect(@converter.convert_exported_html(test_string)).to eq([converted_string, nil])
|
265
318
|
|
266
319
|
test_string = %(<audio style="width: 400px; height: 225px; display: inline-block;" title="this is a media comment" data-media-type="audio" data-media-id="m-lolcat"><source src="$CANVAS_COURSE_REFERENCE$/file_ref/H?media_attachment=true&type=audio" data-media-id="m-lolcat" data-media-type="audio"></audio>)
|
267
|
-
converted_string = %(<iframe style="width: 400px; height: 225px; display: inline-block;" title="this is a media comment" data-media-type="audio" data-media-id="m-lolcat" src="/media_attachments_iframe/8?type=audio"></iframe>)
|
268
|
-
expect(@converter.convert_exported_html(test_string)).to eq([converted_string, nil])
|
269
|
-
end
|
270
|
-
|
271
|
-
it "converts mediahref iframes" do
|
272
|
-
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>)
|
273
|
-
converted_string = %(<iframe data-media-type="video" src="/media_objects_iframe?mediahref=/courses/2/files/9/download" data-media-id="m-yodawg"></iframe>)
|
320
|
+
converted_string = %(<iframe style="width: 400px; height: 225px; display: inline-block;" title="this is a media comment" data-media-type="audio" data-media-id="m-lolcat" src="/media_attachments_iframe/8?type=audio&embedded=true"></iframe>)
|
274
321
|
expect(@converter.convert_exported_html(test_string)).to eq([converted_string, nil])
|
275
322
|
end
|
276
323
|
|
@@ -21,11 +21,8 @@
|
|
21
21
|
require "spec_helper"
|
22
22
|
|
23
23
|
describe CanvasLinkMigrator::LinkParser do
|
24
|
-
def parser
|
25
|
-
|
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)
|
24
|
+
def parser(assets = JSON.parse(File.read("spec/fixtures/canvas_resource_map.json")))
|
25
|
+
CanvasLinkMigrator::LinkParser.new(CanvasLinkMigrator::ResourceMapService.new(assets))
|
29
26
|
end
|
30
27
|
|
31
28
|
describe "convert_link" do
|
@@ -5,7 +5,8 @@
|
|
5
5
|
"subfolder/with a space/yodawg.mov": "I",
|
6
6
|
"subfolder/withCapital/test.png": "migration_id!",
|
7
7
|
"lolcat.mp3": "H",
|
8
|
-
"test.png": "E"
|
8
|
+
"test.png": "E",
|
9
|
+
"media_objects/0_bq09qam2": "F"
|
9
10
|
},
|
10
11
|
"contains_migration_ids": true,
|
11
12
|
"destination_course": "2",
|
@@ -59,11 +60,11 @@
|
|
59
60
|
"F": {
|
60
61
|
"destination": {
|
61
62
|
"id": "6",
|
62
|
-
"media_entry_id": "
|
63
|
+
"media_entry_id": "0_bq09qam2"
|
63
64
|
},
|
64
65
|
"source": {
|
65
66
|
"id": "4",
|
66
|
-
"media_entry_id": "
|
67
|
+
"media_entry_id": "0_bq09qam2"
|
67
68
|
}
|
68
69
|
},
|
69
70
|
"G": {
|
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.7
|
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-03-29 00:00:00.000000000 Z
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
17
17
|
name: activesupport
|