canvas_link_migrator 1.0.7 → 1.0.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/canvas_link_migrator/link_parser.rb +4 -1
- data/lib/canvas_link_migrator/link_resolver.rb +3 -0
- 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 +13 -0
- 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: db94154546720e46dbc316e28fd6b42ee03c51ee13df32d1601924fd78d158d6
|
4
|
+
data.tar.gz: f4a71b858889356c765fcce8360d6266b1b4cd43648cd99eed291287a5229dcb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f2499b2e3764c0bf76ae4f840345104cae6187e970c4bd8f8965254836387221ae84c96041527824fd27edeff602587afb21f629b062c6e83b74e80defd14997
|
7
|
+
data.tar.gz: 49c3e7eb354ea51183ad44706002bb3c92dbc2c98db12371fc420f00eb2616e19fd4b6a8c3e01345d69c7d8b2b81ba71b79341f7ea2802ee8b738b3c56c3a349
|
@@ -96,12 +96,15 @@ module CanvasLinkMigrator
|
|
96
96
|
|
97
97
|
# Replace old style media anchor tags with iframes
|
98
98
|
doc.search("a[id*='media_comment_']").each do |media_node|
|
99
|
+
next unless media_node["class"].match('instructure_inline_media_comment')
|
100
|
+
|
99
101
|
media_node.name = "iframe"
|
100
102
|
# smallest accepted size for iframe since we don't have the size available for these
|
101
103
|
media_node["style"] = "width: 320px; height: 240px; display: inline-block;"
|
102
104
|
media_node["title"] = media_node.text
|
103
105
|
media_node.child&.remove
|
104
|
-
|
106
|
+
media_type = media_node["class"].match(/(audio|video)/)&.[](1)
|
107
|
+
media_node["data-media-type"] = media_type if media_type
|
105
108
|
media_node["src"] = media_node["href"]
|
106
109
|
media_node.delete("href")
|
107
110
|
media_node["allowfullscreen"] = "allowfullscreen"
|
@@ -228,6 +228,9 @@ module CanvasLinkMigrator
|
|
228
228
|
media_id = file.try(:media_object)&.media_id || file["media_entry_id"]
|
229
229
|
node["data-media-id"] = media_id # safe to delete?
|
230
230
|
media_attachment_iframe_url(file["id"], node["data-media-type"])
|
231
|
+
elsif rel_path&.match(/\/media_attachments_iframe\/\d+/)
|
232
|
+
# media attachment from another course or something
|
233
|
+
rel_path
|
231
234
|
elsif node["data-media-id"].present?
|
232
235
|
file = @migration_id_converter.lookup_attachment_by_media_id(node["data-media-id"])
|
233
236
|
file ? media_attachment_iframe_url(file["id"], node["data-media-type"]) : nil
|
@@ -311,6 +311,16 @@ describe CanvasLinkMigrator::ImportedHtmlConverter do
|
|
311
311
|
expect(@converter.convert_exported_html(test_string)).to eq([converted_string, nil])
|
312
312
|
end
|
313
313
|
|
314
|
+
it "converts source tags to RCE media attachment iframes when link is an unknown media attachment reference (link from a public file in another course)" do
|
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="0_l4l5n0wt"><source src="/media_attachments_iframe/18?type=video" data-media-id="0_l4l5n0wt" data-media-type="video"></video>)
|
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="0_l4l5n0wt" src="/media_attachments_iframe/18?type=video"></iframe>)
|
317
|
+
expect(@converter.convert_exported_html(test_string)).to eq([converted_string, nil])
|
318
|
+
|
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="0_l4l5n0wu"><source src="/media_attachments_iframe/19?type=audio" data-media-id="0_l4l5n0wu" data-media-type="audio"></video>)
|
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="0_l4l5n0wu" src="/media_attachments_iframe/19?type=audio"></iframe>)
|
321
|
+
expect(@converter.convert_exported_html(test_string)).to eq([converted_string, nil])
|
322
|
+
end
|
323
|
+
|
314
324
|
it "converts course copy style media attachmet iframe links" do
|
315
325
|
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>)
|
316
326
|
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>)
|
@@ -51,4 +51,17 @@ describe CanvasLinkMigrator::LinkParser do
|
|
51
51
|
expect{ parser.convert_link(doc.at_css('a'), "href", "wiki_page", "migrationid", "") }.not_to raise_error
|
52
52
|
end
|
53
53
|
end
|
54
|
+
|
55
|
+
describe "convert" do
|
56
|
+
it "does not change media anchor tags into iframes if they don't have inline_media_comment in the class" do
|
57
|
+
doc = Nokogiri::HTML5.fragment(%Q(<p><a id="media_comment_m-5HHT5LqZqPf7qhEJ7PbKtehCiunxM4BB" class=" instructure_video_link instructure_file_link" title="00-Personal Intro.m4v" href="https://xu.instructure.com/courses/83206/files/12176377/download?wrap=1" target="" data-api-endpoint="https://xu.instructure.com/api/v1/courses/83206/files/12176377" data-api-returntype="File">Click here to watch personal introduction</a></p>))
|
58
|
+
parser.convert(doc.to_html, "type", "lookup_id", "field")
|
59
|
+
expect(doc.to_html).to match(%Q(<p><a id="media_comment_m-5HHT5LqZqPf7qhEJ7PbKtehCiunxM4BB" class=" instructure_video_link instructure_file_link" title="00-Personal Intro.m4v" href="https://xu.instructure.com/courses/83206/files/12176377/download?wrap=1" target="" data-api-endpoint="https://xu.instructure.com/api/v1/courses/83206/files/12176377" data-api-returntype="File">Click here to watch personal introduction</a></p>))
|
60
|
+
end
|
61
|
+
|
62
|
+
it "does not crash if it can't find a video/audio_comment class name" do
|
63
|
+
doc = Nokogiri::HTML5.fragment(%Q(<a id="media_comment_m-4uoGqVdEqXhpqu2ZMytHSy9XMV73aQ7E" class="instructure_inline_media_comment" data-media_comment_type="video" data-alt=""></a>))
|
64
|
+
expect{ parser.convert(doc.to_html, "type", "lookup_id", "field") }.not_to raise_error
|
65
|
+
end
|
66
|
+
end
|
54
67
|
end
|
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.9
|
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-05-01 00:00:00.000000000 Z
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
17
17
|
name: activesupport
|