-
Notifications
You must be signed in to change notification settings - Fork 479
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
Changes from 26 commits
91c44f5
cf3a484
5a112b6
ecd60be
44428ab
46234df
94f28cd
a726bf7
e7afd0f
848265a
47a8e13
4ea3146
fe205bd
3dd4581
17627d6
9d7018c
f63dd8e
b6f6b3f
e45285c
9e95f85
0145989
df7ae28
46fbb9c
80ee695
b6319a7
2412c1d
626dd32
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -15,11 +15,45 @@ module Curriculum::CourseTypes | |||||
validates :participant_audience, acceptance: {accept: SharedCourseConstants::PARTICIPANT_AUDIENCE.to_h.values, message: 'must be facilitator, teacher, or student'} | ||||||
|
||||||
validate :cannot_have_same_audiences | ||||||
validate :must_have_same_course_type_as_family | ||||||
end | ||||||
|
||||||
# All courses in the same family name must have the save instruction_type, instructor_audience, and participant audience | ||||||
def must_have_same_course_type_as_family | ||||||
all_family_courses = get_family_courses | ||||||
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 | ||||||
errors.add(:participant_audience, 'must be the same for all courses in a family.') if all_family_courses.map(&:participant_audience).uniq.length > 1 || all_family_courses.last&.participant_audience != participant_audience | ||||||
errors.add(:instruction_type, 'must be the same for all courses in a family.') if all_family_courses.map(&:instruction_type).uniq.length > 1 || all_family_courses.last&.instruction_type != instruction_type | ||||||
end | ||||||
|
||||||
# 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 | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||||||
end | ||||||
|
||||||
# If course we are check is a unit_group or a unit that is in a unit_group check the family_name on the UnitGroup. | ||||||
# If the course is a unit that is not in a unit_group check the unit for the family_name | ||||||
def get_family_courses | ||||||
family_name = get_course_family_name | ||||||
return nil if family_name.nil_or_empty? | ||||||
|
||||||
all_family_courses = nil | ||||||
|
||||||
if is_a?(UnitGroup) || (is_a?(Script) && unit_group) | ||||||
all_family_courses = UnitGroup.all.select {|c| c.family_name == family_name} | ||||||
dmcavoy marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
elsif is_a?(Script) | ||||||
all_family_courses = Script.get_family_from_cache(family_name) | ||||||
Comment on lines
+45
to
+48
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||||||
end | ||||||
dmcavoy marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
|
||||||
all_family_courses | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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! |
||||||
end | ||||||
|
||||||
# Instructor and Participant Audience can not be equal unless they are nil | ||||||
def cannot_have_same_audiences | ||||||
errors.add(:instructor_audience, 'You cannot have the same instructor and participant audiences.') if !instructor_audience.nil? && instructor_audience == participant_audience | ||||||
errors.add(:instructor_audience, 'should be different from participant audiences.') if !instructor_audience.nil? && instructor_audience == participant_audience | ||||||
end | ||||||
|
||||||
# Checks if a user can be the instructor for the course. universal instructors and levelbuilders | ||||||
|
There was a problem hiding this comment.
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:
or