Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ GEM
roar
roar-rails (>= 1)
uber
openstax_content (0.2.0)
openstax_content (1.0.0)
aws-sdk-s3
faraday
nokogiri
Expand Down Expand Up @@ -608,4 +608,4 @@ DEPENDENCIES
webmock

BUNDLED WITH
2.2.19
2.3.7
26 changes: 12 additions & 14 deletions app/controllers/api/v1/books_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,8 @@ class BooksController < OpenStax::Api::V1::ApiController
def index
OSU::AccessPolicy.require_action_allowed! :index, current_api_user, OpenStax::Content::Book

books = abl.approved_books.flat_map do |approved_book|
next [] if approved_book[:books].nil?

approved_book[:books].map do |book|
uuid = book[:uuid]
versions = available_book_versions_by_uuid[uuid]
next if versions.empty?

{ uuid: uuid, versions: versions, title: book[:slug].titleize }
end.compact
books = abl.approved_books(archive: archive).map do |book|
{ uuid: book.uuid, version: book.version, title: book.slug.titleize }
end

render json: books
Expand All @@ -41,16 +33,18 @@ def index
description 'Returns a list of pages in some book version (default: latest version)'
param :archive_version, String, desc: 'Archive code pipeline version (default: latest version)'
param :uuid, String, desc: 'Book uuid'
param :version, String, desc: 'Book version (defaults to latest version)'
param :version, String, desc: 'Book version (defaults to latest version in S3 bucket)'
def show
OSU::AccessPolicy.require_action_allowed! :read, current_api_user, OpenStax::Content::Book

uuid = params[:uuid]
version = params[:version] || available_book_versions_by_uuid[uuid].last

render json: OpenStax::Content::Book.new(
archive_version: archive_version, uuid: uuid, version: version
).tree['contents']
tree = OpenStax::Content::Book.new(
archive: archive, uuid: uuid, version: version
).tree['contents'] rescue []

render json: tree
end


Expand All @@ -74,6 +68,10 @@ def archive_version
@archive_version ||= params[:archive_version] || s3.ls.last
end

def archive
@archive ||= OpenStax::Content::Archive.new(version: archive_version)
end

def available_book_versions_by_uuid
@available_book_versions_by_uuid ||= Hash.new { |hash, key| hash[key] = [] }.tap do |hash|
s3.ls(archive_version).each do |book|
Expand Down
2 changes: 1 addition & 1 deletion app/models/exercise.rb
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ def set_context(archive_version: nil)

s3 = OpenStax::Content::S3.new
archive_version ||= s3.ls.last
archive = OpenStax::Content::Archive.new archive_version
archive = OpenStax::Content::Archive.new version: archive_version
cnxmod_tags.each do |cnxmod_tag|
page_uuid = cnxmod_tag.sub 'context-cnxmod:', ''
page = s3.find_page page_uuid, archive_version: archive_version
Expand Down

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Loading