Skip to content

Commit 69cffe4

Browse files
authored
Merge pull request #423 from openstax/more-content-fixes
Content library and import updates
2 parents 7e42722 + 8f1f377 commit 69cffe4

17 files changed

+4169
-48755
lines changed

Gemfile.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -336,7 +336,7 @@ GEM
336336
roar
337337
roar-rails (>= 1)
338338
uber
339-
openstax_content (1.3.0)
339+
openstax_content (1.5.0)
340340
aws-sdk-s3
341341
faraday
342342
nokogiri

app/controllers/api/v1/books_controller.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ class BooksController < OpenStax::Api::V1::ApiController
1818
def index
1919
OSU::AccessPolicy.require_action_allowed! :index, current_api_user, OpenStax::Content::Book
2020

21-
books = abl.approved_books(archive: archive).group_by(&:uuid).map do |uuid, books|
21+
books = abl.books(archive: archive).group_by(&:uuid).map do |uuid, books|
2222
latest_book = books.sort_by(&:committed_at).last
2323

2424
# We use book.slug.titleize here to avoid fetching all book ToCs,

app/models/publication.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ def before_publication
236236
return if published_at.nil? || publishable.nil?
237237

238238
catch(:abort) do
239-
publishable.before_publication
239+
publishable.before_publication
240240
end
241241

242242
return if publishable.errors.empty?

app/models/publication_group.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
class PublicationGroup < ApplicationRecord
22

3-
PUSLISHABLE_TYPES_WITH_DEFAULT_PUBLIC_SOLUTIONS = Set[ 'VocabTerm' ]
3+
PUBLISHABLE_TYPES_WITH_DEFAULT_PUBLIC_SOLUTIONS = Set[ 'VocabTerm' ]
44

55
has_many :publications, inverse_of: :publication_group, autosave: true
66

@@ -37,7 +37,7 @@ def set_nickname_to_nil_if_blank
3737
end
3838

3939
def set_default_solutions_are_public_if_nil
40-
self.solutions_are_public = PUSLISHABLE_TYPES_WITH_DEFAULT_PUBLIC_SOLUTIONS.include?(
40+
self.solutions_are_public = PUBLISHABLE_TYPES_WITH_DEFAULT_PUBLIC_SOLUTIONS.include?(
4141
publishable_type
4242
) if solutions_are_public.nil?
4343
end

app/routines/exercises/import/assessments.rb

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -69,15 +69,15 @@ def exec(filename:, book_uuid:)
6969
end
7070
raise ArgumentError, 'Could not find "Question Stem" column' if question_stem_index.nil?
7171

72-
uuid_index ||= headers.index do |header|
73-
header == 'uuid' || header == 'page uuid' || header == 'section uuid'
72+
uuid_index ||= headers.index { |header| header&.end_with?('uuid') && !header.include?('book') }
73+
section_index ||= headers.index do |header|
74+
header&.start_with?('section') && !header.include?('uuid') && !header.include?('name')
7475
end
75-
section_index ||= headers.index { |header| header == 'section' || header == 'section number' }
7676
Rails.logger.warn { 'Could not find "UUID" or "Section" columns' } \
7777
if uuid_index.nil? && section_index.nil?
7878

7979
unless section_index.nil?
80-
book = OpenStax::Content::Abl.new.approved_books.find { |book| book.uuid == book_uuid }
80+
book = OpenStax::Content::Abl.new.books.find { |book| book.uuid == book_uuid }
8181
raise ArgumentError, "Could not find book with UUID #{book_uuid} in the ABL" if book.nil?
8282
book.all_pages.each { |page| page_uuid_by_book_location[page.book_location] = page.uuid }
8383
end
@@ -158,7 +158,15 @@ def exec(filename:, book_uuid:)
158158
exercise.publication.authors << Author.new(user: author)
159159
exercise.publication.copyright_holders << CopyrightHolder.new(user: copyright_holder)
160160

161-
exercise.publication.publication_group.nickname = row[nickname_index] unless nickname_index.nil?
161+
unless nickname_index.nil? || row[nickname_index].blank?
162+
existing_pg = PublicationGroup.find_by(nickname: row[nickname_index])
163+
164+
if existing_pg.nil?
165+
exercise.publication.publication_group.nickname = row[nickname_index]
166+
else
167+
exercise.publication.publication_group = existing_pg
168+
end
169+
end
162170

163171
exercise.stimulus = parse(row[background_index], exercise) unless background_index.nil?
164172
else

app/routines/find_book.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ def exec(uuid:, archive_version: nil)
1111
archive_version ||= s3.ls.last
1212
end
1313
archive = OpenStax::Content::Archive.new(version: archive_version)
14-
book = OpenStax::Content::Abl.new.approved_books(archive: archive).find do |book|
14+
book = OpenStax::Content::Abl.new.books(archive: archive).find do |book|
1515
book.uuid == uuid
1616
end
1717

config/secrets.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ development:
2222
url: <%= ENV['OPENSTAX_ACCOUNTS_URL'] || 'http://localhost:2999' %>
2323
stub: <%= ENV['OPENSTAX_ACCOUNTS_STUB'] %>
2424
content:
25-
abl_url: <%= ENV['OPENSTAX_CONTENT_ABL_URL'] || 'https://raw.githubusercontent.com/openstax/content-manager-approved-books/main/approved-book-list.json' %>
25+
abl_url: <%= ENV['OPENSTAX_CONTENT_ABL_URL'] || 'https://corgi.ce.openstax.org/api/abl/' %>
2626
archive_path: <%= ENV['OPENSTAX_CONTENT_ARCHIVE_PATH'] || 'apps/archive' %>
2727
bucket_name: <%= ENV['OPENSTAX_CONTENT_BUCKET_NAME'] %>
2828
domain: <%= ENV['OPENSTAX_CONTENT_DOMAIN'] || 'openstax.org' %>
@@ -51,7 +51,7 @@ test:
5151
url: http://localhost:2999
5252
stub: true
5353
content:
54-
abl_url: https://raw.githubusercontent.com/openstax/content-manager-approved-books/main/approved-book-list.json
54+
abl_url: https://corgi.ce.openstax.org/api/abl/
5555
archive_path: apps/archive
5656
bucket_name: <%= ENV['OPENSTAX_CONTENT_BUCKET_NAME'] || 'not-a-real-bucket' %>
5757
domain: openstax.org

lib/content.rb

Lines changed: 1 addition & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -4,53 +4,6 @@ def self.slugs_by_page_uuid
44
# Otherwise we load it from the cache (Redis in actual servers) until the ABL changes
55
RequestStore.store[:slugs_by_page_uuid] ||= Rails.cache.fetch(
66
"slugs_by_page_uuid/#{OpenStax::Content::Abl.new.digest}"
7-
) do
8-
{}.tap do |hash|
9-
books = OpenStax::Content::Abl.new.approved_books
10-
11-
until books.empty?
12-
previous_version = nil
13-
previous_archive = nil
14-
retry_books = []
15-
16-
books.each do |book|
17-
begin
18-
pages = book.all_pages
19-
rescue StandardError => exception
20-
# Sometimes books in the ABL fail to load
21-
# Retry with an earlier version of archive, if possible
22-
previous_version ||= book.archive.previous_version
23-
24-
if previous_version.nil?
25-
raise exception
26-
else
27-
previous_archive ||= OpenStax::Content::Archive.new version: previous_version
28-
29-
retry_book = OpenStax::Content::Book.new(
30-
archive: previous_archive,
31-
uuid: book.uuid,
32-
version: book.version,
33-
slug: book.slug,
34-
style: book.style,
35-
min_code_version: book.min_code_version,
36-
committed_at: book.committed_at
37-
)
38-
39-
retry_books << retry_book if retry_book.valid? && Rails.env.production?
40-
end
41-
else
42-
pages.each do |page|
43-
hash[page.uuid] ||= []
44-
hash[page.uuid] << { book: book.slug, page: page.slug }
45-
end
46-
end
47-
end
48-
49-
books = retry_books
50-
end
51-
52-
hash.each { |uuid, slugs| slugs.uniq! }
53-
end
54-
end
7+
) { OpenStax::Content::Abl.new.slugs_by_page_uuid }
558
end
569
end

lib/openstax_kramdown.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ def handle_html_start_tag(line, &block)
4141
last_el = @tree.children.last
4242
next unless last_el.type == :html_element && last_el.value == 'img' && last_el.attr['src']
4343

44-
uri = URI.parse(last_el.attr['src'].strip)
44+
uri = URI.parse(ActionController::Base.helpers.strip_tags(last_el.attr['src'].strip))
4545
contents = Net::HTTP.get(uri)
4646

4747
bucket_name = s3_secrets[:uploads_bucket_name]

spec/cassettes/Api_V1_BooksController/_index/returns_a_list_of_books_in_a_given_archive_version.yml

Lines changed: 21 additions & 47 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

spec/cassettes/Api_V1_BooksController/_index/returns_a_list_of_books_in_the_latest_archive_version.yml

Lines changed: 30 additions & 57 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

spec/cassettes/Api_V1_BooksController/_show/returns_a_list_of_pages_in_the_latest_book_version.yml

Lines changed: 507 additions & 65 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

spec/cassettes/Api_V1_BooksController/_show/searches_previous_archive_versions_when_the_latest_book_version_is_not_found.yml

Lines changed: 0 additions & 299 deletions
This file was deleted.

spec/cassettes/Exercises_Import_Assessments/imports_exercises_from_the_spreadsheet_and_adds_Assignable_tags.yml

Lines changed: 975 additions & 44349 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

spec/cassettes/books_breakdown/returns_correct_exercise_counts.yml

Lines changed: 770 additions & 87 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)