Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Parametrize import script by model and add vocab import logic #38486

Merged
merged 6 commits into from
Jan 13, 2021

Conversation

bethanyaconnor
Copy link
Contributor

@bethanyaconnor bethanyaconnor commented Jan 8, 2021

First part of PLAT-359 (the second part is the actual import). In order to import vocab, we still need the logic in import_unit_details that pairs lessons but we don't want to update most objects now that they're been imported. 2db91b1 adds a command line flag to specify which models to update, with an empty list meaning no updates. This will allow us to run the script with the -m Vocabulary flag in order to only update vocabulary.

Relies on code-dot-org/curriculumbuilder#335 on the curriculumbuilder side to export vocab for levelbuilder to consume.

Links

Testing story

Reviewer Checklist:

  • Tests provide adequate coverage
  • Privacy and Security impacts have been assessed
  • Code is well-commented
  • New features are translatable or updates will not break translations
  • Relevant documentation has been added or updated
  • User impact is well-understood and desirable
  • Pull Request is labeled appropriately
  • Follow-up work items (including potential tech debt) are tracked and linked

@bethanyaconnor bethanyaconnor marked this pull request as ready for review January 11, 2021 23:15
Copy link
Member

@davidsbailey davidsbailey left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice refactor, Bethany! It makes the new functionality a nice, clean addition. Just a few minor comments inline.

Example: runner.rb -l -u csp2-2021,csp3-2021,csp4-2021
Example: runner.rb -u coursea-2021 -m LessonGroup,Lesson,Activity,Resource,Objective,Vocabulary
Example: runner.rb -l -u csd1-2021 -m Activity,Resource,Objective
Example: runner.rb -l -u csp2-2021,csp3-2021,csp4-2021 -m Lesson
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just noticed that these all say runner.rb. could use #{$0} to get the right command name?

raise unless [:development, :adhoc, :levelbuilder].include? rack_env
raise unless lesson.script.hidden

raise "Must specify models to import" if models_to_import.blank?
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this seems like an odd place for this check -- for example, if I do not specify any models, I hit this error. but if I specify -m LessonGroup, this check will pass, even though no lesson-related models are being imported. how about moving it up to the main import_unit_details.rb script?

lesson.assessment_opportunities = cb_lesson_data['assessment'] unless cb_lesson_data['assessment'].blank?
lesson.objectives = cb_lesson_data['objectives'].map do |o|
Objective.new(key: SecureRandom.uuid, description: o["name"])
if models_to_import.include?('Lesson')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: this is just my opinion, but I think it would be a little easier to read if you did the if models_to_import.include?('Lesson') as the outer conditional, and if cb_lesson_data.empty? as the inner one.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That makes a lot of sense! I'll rearrange

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh actually, this doesn't work. Lockable lessons cause other blocks to crash because the entry in the hash doesn't exist. We shouldn't be trying to import anything other than lesson information for lockable lessons so I'm going to switch this back (mostly)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ohh, I see. I don't know if I have just become totally allergic to nested ifs, but if you are on board with it another option would be to do an early return from this method if cb_lesson_data.empty?. otherwise how you have it is fine. "as simple as possible, but not simpler". :-)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Haha I went back and forth between an early return and the way it is now. They both feel kind of bad to me so I'm not particularly attached to either

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

as the PR author, you have the burden of deciding :-)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm going to leave as-is then. It's very slightly clearer this way to me

Base automatically changed from seed-serialize-vocab to staging January 12, 2021 17:21
@bethanyaconnor bethanyaconnor merged commit 1e61ef9 into staging Jan 13, 2021
@bethanyaconnor bethanyaconnor deleted the import-vocab branch January 13, 2021 16:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants