Skip to content

Commit 7e42722

Browse files
authored
Merge pull request #422 from openstax/raise-fixes
Miscellaneous fixes from RAISE imports
2 parents 3b00560 + 45ce0dc commit 7e42722

File tree

3 files changed

+15
-14
lines changed

3 files changed

+15
-14
lines changed

app/routines/exercises/import/assessments.rb

+11-5
Original file line numberDiff line numberDiff line change
@@ -69,15 +69,17 @@ 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 { |header| header == 'uuid' || header == 'page uuid' }
73-
section_index ||= headers.index { |header| header == 'section' }
72+
uuid_index ||= headers.index do |header|
73+
header == 'uuid' || header == 'page uuid' || header == 'section uuid'
74+
end
75+
section_index ||= headers.index { |header| header == 'section' || header == 'section number' }
7476
Rails.logger.warn { 'Could not find "UUID" or "Section" columns' } \
7577
if uuid_index.nil? && section_index.nil?
7678

7779
unless section_index.nil?
7880
book = OpenStax::Content::Abl.new.approved_books.find { |book| book.uuid == book_uuid }
79-
book.all_pages.each { |page| page_uuid_by_book_location[page.book_location] = page.uuid }
8081
raise ArgumentError, "Could not find book with UUID #{book_uuid} in the ABL" if book.nil?
82+
book.all_pages.each { |page| page_uuid_by_book_location[page.book_location] = page.uuid }
8183
end
8284

8385
nickname_index ||= headers.index { |header| header&.include?('nickname') }
@@ -168,7 +170,6 @@ def exec(filename:, book_uuid:)
168170
exercise.questions << question
169171

170172
stem = Stem.new(content: parse(row[question_stem_index], exercise))
171-
stem.stylings << Styling.new(style: ::Style::MULTIPLE_CHOICE)
172173
question.stems << stem
173174

174175
unless detailed_solution_index.nil? || row[detailed_solution_index].blank?
@@ -179,7 +180,12 @@ def exec(filename:, book_uuid:)
179180
question.collaborator_solutions << solution
180181
end
181182

182-
next if correct_answer_index.nil? || row[correct_answer_index].blank?
183+
if correct_answer_index.nil? || row[correct_answer_index].blank?
184+
stem.stylings << Styling.new(style: ::Style::FREE_RESPONSE)
185+
next
186+
end
187+
188+
stem.stylings << Styling.new(style: ::Style::MULTIPLE_CHOICE)
183189

184190
correct_answer = row[correct_answer_index].downcase.strip.each_byte.first - 97
185191
answer_choice_indices.each_with_index do |row_index, answer_index|

config/secrets.yml

-4
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,6 @@ test:
7777
region: us-east-1
7878
exports_bucket_name: not-a-real-bucket
7979
uploads_bucket_name: not-a-real-bucket
80-
access_key_id: NOTAREALKEY
81-
secret_access_key: NOTAREALSECRET
8280

8381
# Do not keep production secrets in the repository,
8482
# instead read values from the environment.
@@ -121,5 +119,3 @@ production:
121119
region: <%= ENV['AWS_S3_REGION'] %>
122120
exports_bucket_name: <%= ENV['AWS_S3_EXPORTS_BUCKET_NAME'] %>
123121
uploads_bucket_name: <%= ENV['AWS_S3_UPLOADS_BUCKET_NAME'] %>
124-
access_key_id: <%= ENV['AWS_S3_ACCESS_KEY_ID'] %>
125-
secret_access_key: <%= ENV['AWS_S3_SECRET_ACCESS_KEY'] %>

lib/openstax_kramdown.rb

+4-5
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,7 @@ def region
1616
end
1717

1818
def s3_client
19-
@s3_client ||= Aws::S3::Client.new(
20-
region: region,
21-
credentials: Aws::Credentials.new(s3_secrets[:access_key_id], s3_secrets[:secret_access_key])
22-
)
19+
@s3_client ||= Aws::S3::Client.new(region: region)
2320
end
2421

2522
def add_text(text, tree = @tree, type = @text_type)
@@ -44,7 +41,7 @@ def handle_html_start_tag(line, &block)
4441
last_el = @tree.children.last
4542
next unless last_el.type == :html_element && last_el.value == 'img' && last_el.attr['src']
4643

47-
uri = URI.parse(last_el.attr['src'])
44+
uri = URI.parse(last_el.attr['src'].strip)
4845
contents = Net::HTTP.get(uri)
4946

5047
bucket_name = s3_secrets[:uploads_bucket_name]
@@ -58,6 +55,8 @@ def handle_html_start_tag(line, &block)
5855

5956
last_el.attr['src'] = "https://s3.#{region}.amazonaws.com/#{bucket_name}/#{key}"
6057

58+
next if @options[:attachable].attachments.any? { |attachment| attachment.asset == last_el.attr['src'] }
59+
6160
@options[:attachable].attachments << Attachment.new(asset: last_el.attr['src'])
6261
end
6362
end

0 commit comments

Comments
 (0)