CSC/ECE 517/Spring 2023/E2332 Reimplement Courses (Refactor course.rb)

From Expertiza_Wiki
Jump to navigation Jump to search


Team Contact

Team Members

  • Kartik Rawool, (unityID:khrawool, GitHub:kartikrawool)
  • Ameya Vaichalkar, (unityID:agvaicha, GitHub:ameyagv)
  • Vikram Pande, (unityID:vspande, GitHub:vikrampande7)

Mentor

  • Kartiki Bhandakkar, kbhanda3

Overview of Expertiza

Expertiza is an open-source software written using Ruby on Rails, which functions as a learning management software system. It has many different functions and abilities, including the ability to create assignments, quizzes, assignment groups, and topics, and also a complete mechanism for providing peer reviews and feedback for other groups and other teammates. Part of its functionality is a system containing information about the course and a list of operations that can be performed on the course model. The Course model and CoursesController, which are the classes primarily addressed in this project, are both critical components in providing this functionality.

Description of Project

The Course model stores information about the instructor and institution it belongs to, and it is associated with other models such as User, Assignment, etc. The course model is responsible for completing a variety of tasks, including returning the submission directory for the course, viewing students enrolled in the course, and adding a student to the course, etc.

The CoursesController is responsible for managing courses. It performs CRUD operations on the Course model. It is responsible for creating, editing, deleting courses, and adding/removing teaching assistants to the course. The controller also returns a list of Teaching assistants associated with the course.

Problem Statement

The problem statement requires us to re-implement the Course model and CoursesController in a Rails application, with the goal of managing courses by allowing admins to create, edit, update, and delete courses, as well as create copies of existing courses. The re-implementation should follow RESTful conventions, including appropriate HTTP response codes and status codes for each endpoint. We are required to write RSpec tests for the Course model and the CoursesController, covering all endpoints and including appropriate HTTP response codes for every method. Tests for the controller will be made compatible with RSwag to generate API documentation and test REST APIs from the Swagger UI.

Previous Work

Index Previous Proposed changes Rationale
1 user_on_team method in course.rb model

 def user_on_team?(user)
   teams = get_teams
   users = []
   teams.each do |team|
     users << team.users
   end
   users.flatten.include? user
 end

user_on_team method in team.rb The functionality to check whether a user is a member of any team is associated with team model, follows Single Responsibility Principle
2 copy method present in controller

# Create a copy of a course with a new submission directory
 def copy
   orig_course = Course.find(params[:id])
   new_course = orig_course.dup
   new_course.instructor_id = session[:user].id
   new_course.name = 'Copy of ' + orig_course.name
   new_course.directory_path = new_course.directory_path + '_copy'
   begin
     new_course.save!
     parent_id = CourseNode.get_parent_id
     if parent_id
       CourseNode.create(node_object_id: new_course.id, parent_id: parent_id)
     else
       CourseNode.create(node_object_id: new_course.id)
     end
     undo_link("The course \"#{orig_course.name}\" has been successfully copied.
       Warning: The submission directory path for this copy is the original course's directory path appended with the word \"_copy\".
       If you do not want this to happen, change the submission directory in the new copy of the course.")
     redirect_to controller: 'courses', action: 'edit', id: new_course.id
   rescue StandardError
     flash[:error] = 'The course was not able to be copied: ' + $ERROR_INFO
     redirect_to controller: 'tree_display', action: 'list'
   end
 end

copy method should be added in the model as well The controller should not have the logic of copying the course attributes, instead, the controller should call the copy method defined in the model to create a copy of a course.
3 action_allowed method in controller

def action_allowed?
   current_user_has_instructor_privileges?
end

action_allowed method should be in a model which deals with authorization The course model class does not have the responsibility to check whether the user has instructor privileges.

Implementation

Based on the current functionality of the Course model and controller we have defined the following RESTful endpoints with their Request type which would be implemented in the controller. The Strategy Pattern will be followed in the context of a controller, this pattern can be used to encapsulate the actions that the controller can perform and make them easily extensible and usable.

Controller

Index Method Request Type Description
1 action_allowed HELPER FUNCTION Determines whether the current user has permission to perform certain actions based on their role
2 auto_complete_for_user_name GET Provides an autocomplete feature for the form input when adding a TA
3 new GET Displays the form for creating a new course
4 edit GET Method to get the course to edit
5 update PUT Method to update an existing course based on the form input and save the changes to database
6 copy GET Creates a new copy of an existing course with a new submission directory and saves it to the database
7 create POST Creates a new course based on the form input and saves it to database
8 delete DELETE Method to delete an existing course
9 view_teaching_assistant GET Displays all the teaching assistants for a course
10 add_ta POST Method to add teaching assistant to a course
11 remove_ta POST Method to remove teaching assistant from a course
12 set_course_fields POST Called in Update and Create methods to set the fields of course


Model

Index Method Description
1 get_teams Returns any predefined teams associated with a particular course object
2 get_participants Returns multiple records of course participants from database given parent_id and user_id
3 get_participant Returns a single record course participant from Course Participant given parent_id
4 add _participant Add a new Course Participant to the course given user_name
5 copy_participants Copies all the participants from a given assignment to the current course
6 user_on_team Checks whether a given user is a member of any team associated with the course
7 path Returns the course's submission directory

UML Diagram

Testing Plan

The Course model and controller will be tested using Rspec. FactoryBot will be utilized to create test fixtures and to build the required models. As the methods in the controller are defined as RESTful endpoints. The test take into consideration that the methods return the correct status codes for the output. Based on the current functionality of Course model and controller we have defined the following test which would implemented to test the reimplemented code of course model and controller.

Tests

Course Controller

Test No. Description
1 Tests if the action_allowed disallows all actions when current user is student.
2 Tests if the action_allowed allows all course actions when current user is instructor.
3 Tests if create method returns a 201 Created status code if the resource is successfully created.
4 Tests if create method returns a 422 Unprocessable Entity status code if the resource cannot be created due to validation errors.
5 Tests if the delete method returns a 204 No Content status code if the resource is successfully deleted.
6 Tests if the delete method returns a 404 Not Found status code if the resource cannot be found.
7 Tests if the new method sets the private instance variable.
8 Tests if the update method returns a 200 OK status code if the resource is successfully updated.
9 Tests if the update method returns a 422 Unprocessable Entity status code if the resource cannot be updated due to validation errors.
10 Tests if the topic_name method returns the participant topic name when not nil.
11 Tests if the auto_complete_for_user_name method returns a list of users.
12 Tests if the copy method redirects to new course when new course id fetched successfully.
13 Tests if the view_teaching_assistants method returns list of TAs for the course.
14 Tests if the add_ta method returns a 200 OK status code if a TA added successfully to the course.
13 Tests if the add_ta method returns a 422 Unprocessable Entity status code if a TA cannot be added to the course.
14 Tests if the remove_ta method returns a 204 No Content status code if the ta is successfully removed from the course.
15 Tests if the remove_ta method returns a 404 Not Found status code if the ta cannot be found.
16 Tests if the set_course_fields method sets the course fields.

Course Model

Test No. Description
1 Tests if the model validates presence of name
2 Tests if the model validates presence of directory_path
3 Tests if path method raises an error when there is no associated instructor.
4 Tests if path method returns a directory when there is an associated instructor.

Relevant Links

Contributors to this project

  • Kartik Rawool, (unityID:khrawool, GitHub:kartikrawool)
  • Ameya Vaichalkar, (unityID:agvaicha, GitHub:ameyagv)
  • Vikram Pande, (unityID:vspande, GitHub:vikrampande7)