canvas_link_migrator 1.0.2 → 1.0.4

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: 6c077949f9cef706c71bff4537a9df6a3e53cb5306dadab87fb0281c79754a16
4
- data.tar.gz: d1f6d129570271a82b293f6422b00cb1b6533233713adaf1479fd5d7efda47cb
3
+ metadata.gz: c3b1e71c22b8899f6fe7b5986ee5569fbb9525c0d4cb9e6eb25c9f6ef1804435
4
+ data.tar.gz: ba9a4fc3a6ce17be40afab0814818fa7b62603e2aee6d6e5e784110c3fb975c0
5
5
  SHA512:
6
- metadata.gz: b07d22a498fbb5188874aa67a6702be9ee349ed2be2efb5c4f42050d45b7914afb0edeae7d2f2127dae44531631f371cb1d8df62923133f8a88b96bcbe8f997f
7
- data.tar.gz: f1c6fa682fc28072571d3841d4418e14bc1240b453618ec19be98df2d09ab8a217c3638310bc0383e1a63f32ade812008f69a3198ad436167dd12f5ffc672673
6
+ metadata.gz: 191de3ba56873baa45d3f922f7276edcdc0f84eda77fc6627cb9d55e4058b00ec792785b08ad4ef666dd4c0efe95b9cdde289320293466dc598d9a703c3532a8
7
+ data.tar.gz: 4462eb3f2b424ac381ba35a0f9369c2a671d47efdcb7ac9698ebfeeedccaed397e0736f4d321ba366d9620f7734a9aa69621aba128c47a5a317c6559476ae86d
@@ -129,7 +129,12 @@ module CanvasLinkMigrator
129
129
  url.gsub!("%24#{ref}%24", "$#{ref}$")
130
130
  end
131
131
 
132
- result = parse_url(url, node, attr)
132
+ begin
133
+ result = parse_url(url, node, attr)
134
+ rescue Addressable::URI::InvalidURIError
135
+ return
136
+ end
137
+
133
138
  if result[:resolved]
134
139
  # resolved, just replace and carry on
135
140
  new_url = result[:new_url] || url
@@ -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
 
@@ -42,5 +42,10 @@ describe CanvasLinkMigrator::LinkParser do
42
42
  expect(doc.at_css('a')['href']).to include("LINK.PLACEHOLDER")
43
43
  expect(doc.at_css('a').inner_html).not_to include("LINK.PLACEHOLDER")
44
44
  end
45
+
46
+ it "doesn't convert inner html of anchor tags if unnecessary" do
47
+ doc = Nokogiri::HTML5.fragment("<a href=\"https://what:10.1111/HFP.0b013e31828df26\">broken link</a>")
48
+ expect{ parser.convert_link(doc.at_css('a'), "href", "wiki_page", "migrationid", "") }.not_to raise_error
49
+ end
45
50
  end
46
51
  end
@@ -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)
@@ -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.2
4
+ version: 1.0.4
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: 2023-11-21 00:00:00.000000000 Z
14
+ date: 2024-02-01 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: