Skip to content

Commit

Permalink
Removed trailing whitespaces and fixed som lint problems
Browse files Browse the repository at this point in the history
  • Loading branch information
sergioncsu committed Oct 29, 2023
1 parent e001106 commit 523bd70
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 31 deletions.
22 changes: 11 additions & 11 deletions app/models/instructor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,56 +32,56 @@ 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

# 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
Expand Down
40 changes: 20 additions & 20 deletions app/models/ta.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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?
Expand All @@ -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])
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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
end
end

0 comments on commit 523bd70

Please sign in to comment.