From 523bd709238f48ccaba24baf8b4a33b5c0ed29bc Mon Sep 17 00:00:00 2001 From: Sergio Vargas Villar Date: Sun, 29 Oct 2023 19:40:49 -0400 Subject: [PATCH] Removed trailing whitespaces and fixed som lint problems --- app/models/instructor.rb | 22 +++++++++++----------- app/models/ta.rb | 40 ++++++++++++++++++++-------------------- 2 files changed, 31 insertions(+), 31 deletions(-) diff --git a/app/models/instructor.rb b/app/models/instructor.rb index c090a84219f..8eddfa2c90d 100644 --- a/app/models/instructor.rb +++ b/app/models/instructor.rb @@ -32,16 +32,16 @@ def get(object_type, id, user_id) def my_tas # Get all courses where the user is an instructor. courses = Course.where(instructor_id: id) - + # Initialize an array to store the TA IDs. ta_ids = courses.flat_map do |course| # For each course, get the TA mappings (i.e., associations between TAs and the course). ta_mappings = TaMapping.where(course_id: course.id) - + # Use 'map' to transform each TA mapping into its TA ID. ta_mappings.map(&:ta_id) end - + # Return the list of TA IDs. ta_ids end @@ -49,39 +49,39 @@ def my_tas # This method retrieves a list of users who are participants in the courses and assignments where the given user is an instructor. def self.get_user_list(user) user_list = [] - + # Retrieve participants from courses where the user is an instructor user_list.concat(get_participants_from_instructed_entities(Course, user)) - + # Retrieve participants from assignments where the user is an instructor user_list.concat(get_participants_from_instructed_entities(Assignment.includes(:participants), user)) - + # Return the list of users user_list end - + # This method retrieves the participants from the entities (either Course or Assignment) where the given user is an instructor. def self.get_participants_from_instructed_entities(entity, user) # Get all entities where the user is an instructor entities = entity.where(instructor_id: user.id) - + # For each entity, get its participants and filter them based on the user's privileges entities.flat_map do |entity| # Check if the entity has a get_participants method (as in Course) or directly has a participants association (as in Assignment) participants = entity.respond_to?(:get_participants) ? entity.get_participants : entity.participants - + # Filter the participants based on the user's privileges filter_participants(participants, user) end end - + # This method filters a list of participants based on whether the given user has all privileges of each participant's role. def self.filter_participants(participants, user) # Select only those participants whose role's privileges are all included in the user's role's privileges filtered_participants = participants.select do |participant| user.role.has_all_privileges_of?(participant.user.role) end - + # Map each participant to its associated user and return this list of users filtered_participants.map(&:user) end diff --git a/app/models/ta.rb b/app/models/ta.rb index 8a5fa762748..2cda3515d43 100644 --- a/app/models/ta.rb +++ b/app/models/ta.rb @@ -14,7 +14,7 @@ class Ta < User def courses_assisted_with TaMapping.where(ta_id: id).map { |c| Course.find(c.course_id) } end - + # Checks if the TA is an instructor or co-TA for a given questionnaire. def is_instructor_or_co_ta?(questionnaire) return false if questionnaire.nil? @@ -26,7 +26,7 @@ def is_instructor_or_co_ta?(questionnaire) questionnaire_ta = Ta.find(instructor_id) courses_assisted_with.any? { |course| course.tas.include?(questionnaire_ta) } end - + # Lists all objects of a certain type that are either owned by the user or are public. def list_all(object_type, user_id) object_type.where(['instructor_id = ? OR private = 0', user_id]) @@ -46,14 +46,14 @@ def list_mine(object_type, user_id) #### this find method compares the directories of an assignment and a course to find out if the #### the assignment is in a subdirectory of a course that the user is a TA for. Assignment.find_by_sql(['SELECT assignments.id, assignments.name, assignments.directory_path ' \ - 'FROM assignments ' \ - 'INNER JOIN ta_mappings ON assignments.course_id = ta_mappings.course_id ' \ - 'WHERE ta_mappings.ta_id = ?', user_id]) - else - # Find objects where the user is the instructor - object_type.where(instructor_id: user_id) + 'FROM assignments ' \ + 'INNER JOIN ta_mappings ON assignments.course_id = ta_mappings.course_id ' \ + 'WHERE ta_mappings.ta_id = ?', user_id]) + else + # Find objects where the user is the instructor + object_type.where(instructor_id: user_id) + end end -end # Gets an object of a certain type that is either owned by the user or is public. def get(object_type, id, user_id) @@ -74,17 +74,17 @@ def self.get_my_instructors(user_id) instructor_ids = ta_mappings.map { |ta_mapping| Course.find(ta_mapping.course_id).instructor_id } instructor_ids end - + # Returns all instructor IDs for courses that this TA helps teach. def self.get_mapped_instructor_ids(user_id) TaMapping.where(ta_id: user_id).map { |map| map.course.instructor.id } end - + # Returns all course IDs for courses that this TA helps teach. def self.get_mapped_courses(user_id) TaMapping.where(ta_id: user_id).map { |map| map.course.id } end - + # Returns the instructor ID for the first course that this TA helps teach. def get_instructor Ta.get_my_instructor(id) @@ -104,31 +104,31 @@ def assign_courses_to_assignment def teaching_assistant? true end - + # Returns a list of users who have the same or lower privilege level as the given user # and are participants in the courses that the user is a TA for. def self.get_user_list(user) # Get the roles associated with the user user_roles = user.role - + # Get a list of course IDs associated with the user courses = Ta.get_mapped_courses(user.id) - + # Initialize an array to store participants participants = [] - + # Iterate through each course to collect participants courses.each do |course_id| course = Course.find(course_id) participants.concat(course.get_participants) end - + # Select participants whose role has all privileges of the user's role selected_participants = participants.select do |participant| user_roles.has_all_privileges_of?(participant.user.role) end - + # Extract the user objects from the selected participants selected_participants.map(&:user) - end -end \ No newline at end of file + end +end