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

Validation that courses in family share course type #44062

Merged
merged 27 commits into from Jan 13, 2022

Conversation

dmcavoy
Copy link
Contributor

@dmcavoy dmcavoy commented Dec 15, 2021

This is a prep step for moving unit redirection to work for all participants instead of just students. In order to be able to redirect correctly we really need to guarantee that all CourseVersions in the same CourseOffering have the same instruction_type, participant_audience, and instructor_audience. This PR adds validation to check that that case is true.

Notes on a couple choices I made:

  • I added the validation to the concern even tho it does a lot of checking of Script and UnitGroup because it seems like co-locating it with the other stuff that is related to course type makes the most sense. If it seems like it violates the way concerns work too much let me know.
  • I'm thinking there is a way to do this with CourseVersion and CourseOffering but this was the first way that came to mind. If you have a suggestion of a better way to do this with CourseVersion and CourseOffering let me know.

Links

Eng Plan
Product Spec

Testing story

  • Updated tests. There were two query count updates, any concerns on those?

@dmcavoy dmcavoy changed the title trying to add validation to make sure family all has same course type Validation that courses in family share course type Dec 16, 2021
@dmcavoy dmcavoy requested a review from a team December 16, 2021 19:15
@dmcavoy
Copy link
Contributor Author

dmcavoy commented Jan 10, 2022

@davidsbailey I just went back to using all instead of all_courses. I didn't want to sink anymore time into the tests here.

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 work, Dani!

I'm thinking there is a way to do this with CourseVersion and CourseOffering but this was the first way that came to mind. If you have a suggestion of a better way to do this with CourseVersion and CourseOffering let me know.

Good thought. Given the move to UnitGroup, this seems like the right strategic direction -- get all the code into one place (the concern), and then it will be easier to move onto UnitGroup later.

moving onto CourseOffering and CourseVersion via the get_course_version helper seems nice-to-have when possible -- I've noted one place where that seems like it can be changed, but I would suggest only doing that when it can be done easily.

return if all_family_courses.nil_or_empty?

return unless all_family_courses.length > 1
errors.add(:instructor_audience, 'must be the same for all courses in a family.') if all_family_courses.map(&:instructor_audience).uniq.length > 1 || all_family_courses.last&.instructor_audience != instructor_audience
Copy link
Member

Choose a reason for hiding this comment

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

if you want to keep these all on one line, how about something a bit shorter, like:

Suggested change
errors.add(:instructor_audience, 'must be the same for all courses in a family.') if all_family_courses.map(&:instructor_audience).uniq.length > 1 || all_family_courses.last&.instructor_audience != instructor_audience
errors.add(:instructor_audience, 'must be the same for all courses in a family.') if all_family_courses.map(&:instructor_audience).uniq != [instructor_audience]

or

Suggested change
errors.add(:instructor_audience, 'must be the same for all courses in a family.') if all_family_courses.map(&:instructor_audience).uniq.length > 1 || all_family_courses.last&.instructor_audience != instructor_audience
errors.add(:instructor_audience, 'must be the same for all courses in a family.') if all_family_courses.map(&:instructor_audience).any? {|audience| audience != instructor_audience}

all_family_courses = Script.get_family_from_cache(family_name)
end

all_family_courses
Copy link
Member

Choose a reason for hiding this comment

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

the additions to this file look much easier to follow now, thanks for updating!

Comment on lines +45 to +48
if is_a?(UnitGroup) || (is_a?(Script) && unit_group)
all_family_courses = UnitGroup.all.select {|c| c.family_name == family_name}
elsif is_a?(Script)
all_family_courses = Script.get_family_from_cache(family_name)
Copy link
Member

Choose a reason for hiding this comment

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

this section looks hard to move onto get_course_version -- I wouldn't worry about this for now, and we can tackle it when we move all Scripts onto UnitGroup.


# Get the family name for the course based on if its set on the UnitGroup or Unit
def get_course_family_name
is_a?(Script) && unit_group ? unit_group.family_name : family_name
Copy link
Member

Choose a reason for hiding this comment

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

per your top-level comment, you could do this more generally as follows:

Suggested change
is_a?(Script) && unit_group ? unit_group.family_name : family_name
get_course_version&.family_name

Copy link
Member

Choose a reason for hiding this comment

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

apologies @dmcavoy but I'm going to backtrack and suggest that you punt on this for now -- this will make more activerecord calls, which could turn up as extra queries... and you've already had to deal with enough of that in this PR. practically speaking this is just as good, assuming that we are moving all Scripts onto UnitGroups some time soon.

@dmcavoy dmcavoy merged commit df80c3a into staging Jan 13, 2022
@dmcavoy dmcavoy deleted the family-name-share-course-type branch January 13, 2022 12:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants