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

Allow instructors to also be CAs #2084

Merged
merged 1 commit into from
Feb 12, 2024
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
39 changes: 18 additions & 21 deletions app/assets/javascripts/course_user_data_edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,30 +16,27 @@ function formvalidation(form){
}
}

// User can be at most one of the following: instructor, course assistant, or dropped (student)
const $instructor_checkbox = $('#course_user_datum_instructor');
const $course_assistant_checkbox = $('#course_user_datum_course_assistant');
const $dropped_checkbox = $('#course_user_datum_dropped');
const mutually_exclusive_fields = [
$instructor_checkbox, $course_assistant_checkbox, $dropped_checkbox
];
const $fields = [$instructor_checkbox, $course_assistant_checkbox, $dropped_checkbox];

function mutual_exclusion() {
const fields = mutually_exclusive_fields; // For brevity
// Enable all fields
fields.forEach((field) => field.prop('disabled', false));
function disable_fields(cur_field, excluded_fields) {
const checked = cur_field.is(':checked');
if (checked) {
excluded_fields.forEach((field) => {
field.prop('disabled', true);
field.prop('checked', false);
});
}
}
damianhxy marked this conversation as resolved.
Show resolved Hide resolved

// If any field is checked, disable the rest
fields.forEach((field, idx) => {
if (field.is(':checked')) {
fields.forEach((field2, idx2) => {
if (idx !== idx2) {
field2.prop('disabled', true);
field2.prop('checked', false);
}
});
}
});
// User can't be dropped if they are an instructor or course assistant
function instructor_or_ca_not_dropped() {
$fields.forEach((field) => field.prop('disabled', false));
disable_fields($instructor_checkbox, [$dropped_checkbox]);
disable_fields($course_assistant_checkbox, [$dropped_checkbox]);
disable_fields($dropped_checkbox, [$instructor_checkbox, $course_assistant_checkbox]);
damianhxy marked this conversation as resolved.
Show resolved Hide resolved
}

$(document).ready(function(){
Expand All @@ -48,6 +45,6 @@ $(document).ready(function(){
e.preventDefault();
});

mutual_exclusion();
mutually_exclusive_fields.forEach((field) => field.on("click", mutual_exclusion));
instructor_or_ca_not_dropped();
$fields.forEach((field) => field.on("click", instructor_or_ca_not_dropped));
damianhxy marked this conversation as resolved.
Show resolved Hide resolved
});
12 changes: 5 additions & 7 deletions app/models/course_user_datum.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def initialize(user_message, dev_message)
accepts_nested_attributes_for :tweak, allow_destroy: true
accepts_nested_attributes_for :user, allow_destroy: false
validate :valid_nickname?
validate :instructor_or_ca_or_dropped
validate :instructor_or_ca_not_dropped
after_create :create_AUDs_modulo_callbacks

def self.conditions_by_like(value, *columns)
Expand Down Expand Up @@ -75,13 +75,11 @@ def valid_nickname?
errors.add("nickname", "can only contain ASCII characters")
end

# User can be at most one of the following: instructor, course assistant, or dropped (student)
def instructor_or_ca_or_dropped
status_count = [instructor?, course_assistant?, dropped?].count(true)
# User can't be dropped if they are an instructor or course assistant
def instructor_or_ca_not_dropped
return unless dropped? && (instructor? || course_assistant?)

return if status_count <= 1

errors.add(:base, "User can be at most one of instructor, course assistant, or dropped")
errors.add(:base, "User can't be dropped if they are an instructor or course assistant")
damianhxy marked this conversation as resolved.
Show resolved Hide resolved
end

##
Expand Down
Loading