CSC/ECE 517 Spring 2023 E2342: Reimplement Participants Model and Controller

From Expertiza_Wiki
Jump to navigation Jump to search

Background

In expertiza, there are two different models: Course and Assignment. Although an Assignment is a part of a Course, students can participate in a Course or an Assignment independently.

The ParticipantsController provides functionalities for listing the participants of a course or an assignment, adding a participant to a course or an assignment, updating the authorizations of a participant (can_submit, can_review, can_take_quiz), updating the handle of a participant for an assignment, inheriting course participants to its assignment, bequeathing assignment participants to its course and deleting a participant from a course or an assignment.

Project Purpose

The aim of our project is to integrate the reimplemented version of participants_controller with the Participant Model while maintaining the existing functionality of the feature. We plan on restricting all the business logic to the model, which will also handle all of the interactions with the database. The controller, on the other hand, will be responsible only for accepting appropriate input and returning the results in a JSON format. The test suite will be updated accordingly to accommodate the above-mentioned development plan.

Project Design

High-level Design Diagram

The architecture diagram shown below serves the purpose of our high-level design diagram. As seen in the figure, the user interacts with the web client i.e. browser which sends an HTTP request to the web server available in the back-end. The web server is responsible for handling the rails routes corresponding to the RESTful endpoints of the APIs that we have developed. The endpoints then route to the corresponding method in the participants controller where the intended functionality is carried out. For certain APIs, such as inherit, this involves interacting with the participants model and the database to update the state of the system. For other simpler features, such as index, the controller method handles all the processing. The method responds with a JSON structure which is sent back as an HTTP response to the front-end and then returned back to the client.
The diagram lays out the general workflow of a user interacting with the system and helps the viewer understand the responsibilities of the model, controller, and view in our system. Models are responsible for dealing with the business logic of the features and interact with the database for all data operations. Controllers are responsible for taking appropriate input and returning JSON-formatted output without changing any data or the state of the system. Lastly, views are responsible for rendering the output in a user-friendly interface for the client.

Use Case Diagram

The following Use Case Diagram demonstrates the primary functionality relevant to participants for different types of users in the system. We've highlighted three primary users of our system who might use the participants features - instructors/TAs, participants (who are expected to be students), and admins.

Implementation

This project has been split up in two phases, with phase 1 being the re-implementation of the participants model and controller. The second phase of the project focuses on the integration of the newly implemented versions of participants model and controller.
During the first phase, the controller employed an API-first approach while maintaining all the existing functionality in an efficient, robust and simple manner. Specifically for the participants controller, we added seven different API endpoints to extend the current functionalities while modifying the code to support these APIs. For the participants model, we removed all unnecessary functionality and retained only the core business logic for participants. The details for the model changes and new endpoints have been discussed later in this section.
For the second phase, we plan on maintaining the ideology of restricting business logic to the model and API logic to the controller. We will fill in the missing gaps and modify the code after re-implementation to enable integration of the new code. The proposed changes for this phase have been discussed later in this section.

Assumptions

  1. The CourseParticipant and AssignmentParticipant models implement the copy method which copies participants from the course to assignment and vice-versa. This functionality is used in the inherit and bequeath methods.

Phase 1a: Reimplementation of Participants Model

The participants model file participant.rb was re-implemented to include only the necessary business logic and remove unnecessary functionality.
Note: More details on this can be found here.

Task Status Testing
Replaced force_delete method with leave_team method Implemented Completed
mail_assigned_reviewers method was removed Implemented N/A
able_to_review method was eliminated Implemented N/A
email method was removed Implemented N/A

Phase 1b: Reimplementation of Participants Controller

The endpoints implemented as part of this phase have been summarized here. The code for these can be found in the participants_controller.rb file.
Note: Detailed API documentation and other details for these can be found here.

 #  Method Endpoint Description
1 index GET /participants/index/:model/:id returns a list of participants of an assignment or a course
2 create POST /participants/:model/:id creates a participant in an assignment or a course
3 update_handle PATCH /participants/change_handle/:id updates the participant's handle for an assignment
4 update_authorizations PATCH /participants/update_authorizations/:id updates the participant's permissions for an assignment or a course depending on the role
5 delete DELETE /participants/:id deletes a participant from an assignment or a course
6 inherit GET /participants/inherit/:id copies existing participants from a course down to its assignment
7 bequeath GET /participants/bequeath/:id copies existing participants from an assignment up to its course

Current Work

Task Notes
Modify the team method in Participants model The team method uses TeamsParticipant instead of TeamsUser based on E2304
Replace sort_by_name method with sort_participants method in Participants model sort_participants can either sort by id of the participants or name of the corresponding user depending on the parameter passed
Modify destroy in participants_controller The destroy method uses the delete method from the Participants model to check if the participant is on a team or assigned as a reviewer or reviewee before destroying
Fill testing gaps Tests were updated after the integration of Participant model with participants_controller
Add comments Clear and concise comments to explain what each section of the code is doing, why it is doing it, and how it fits into the overall task

Test Plan

So far we've written individual tests for the model and controller files of the participants functionality. With the goal of this project being the integration of the two, we will look to add some tests which facilitate the combined working of the two files. This might include modifying existing test scenarios as well as writing new ones. We expect the number of tests to go up as well as the overall code coverage to improve after this project. The existing test suites for the model and controller can be found below.

Model test suite

The testing framework used here is RSpec. The participants.rb contains many methods and associations with other models. Hence, to test the methods in participants, the other dependent methods have to be stubbed. To deal with the models, dummy models/dummy app can be created which will act as the associated classes. We have created all the required dummy classes by scaffolding them.

To create test fixtures and to build the required models, Factory Bot has been used. Two separate files, factories.rb and factory_bot.rb was created to build the factories. Four participants and other required fields were created as fixtures after which the tests were written.

To run the tests:
1. git clone https://github.com/amarthyasa/reimplementation-back-end/tree/testing_files
2. cd reimplementation-back-end/
3. bundle install
4. bundle exec rspec spec/models/participants_spec.rb

Tests

Test No. Description
1 Tests if the team method returns the team of the participant
2 Tests if the name method returns the name of the participant
3 Tests if the fullname method returns the full name of the participant
4 Tests if the handle method returns the handle of the participant
5 Tests if the sort_participants method returns a sorted list of participants in alphabetical order
6 Tests if the sort_participants method returns a sorted list of participants in id order
7 Tests if the topic_name method returns the participant topic name when nil
8 Tests if the topic_name method returns the participant topic name when not nil.
9 Tests if the authorization method returns participant when no arguments are passed.
10 Tests if the authorization method returns reader when no arguments are passed.
11 Tests if the authorization method returns submitter when no arguments are passed.
12 Tests if the authorization method returns reviewer when no arguments are passed.
13 Tests if it returns participant data in the correct format.
14 Test if it exports the details of the participant correctly.

Previous Participant Model Test Implementation: here

Controller test suite

The testing framework used here is RSpec. The participants_controller.rb has dependencies on models and methods which are yet to be implemented. In the meantime, to test the API, we have used stubs and mocks. We have created some new models and added some associations in them which were required for stubbing.

To run the tests:
1. git clone https://github.com/devashish-vachhani/reimplementation-back-end
2. cd reimplementation-back-end/
3. bundle install
4. bundle exec rspec spec/requests/api/v1/participants_spec.rb

Tests

Test ID Test Description
1 Test to check index with Assignment model and id - Lists Participants
2 Test to check index with Assignment model and id - Invalid Parameters
3 Test to create a new participant - With non existing User
4 Test to create a new participant - When participant already exists
5 Test to create a new participant - Successful creation of participant
6 Test to update handle request for a participant - When handle name already exists
7 Test to update handle request for a participant - Successful update of participant handle
8 Test to update handle request for a participant - Failed update of participant handle
9 Test to update authorizations request for a participant - Successful update of authorizations of a participant
10 Test to update authorizations request for a participant - Failed update of authorizations of a participant
11 Test to inherit participants from a Course to an Assignment - Failure in inherit because Assignment has no Course
12 Test to inherit participants from a Course to an Assignment - Failure for when there are no participants to inherit
13 Test to inherit participants from a Course to an Assignment - Checks if participants in Assignment is already in Course
14 Test to inherit participants from a Course to an Assignment - Successful inherit from Course to Assignment
15 Test to bequeath participants from an Assignment to a Course - Failure in bequeath because Course has no Assignment
16 Test to bequeath participants from an Assignment to a Course - Failure for when there are no participants to inherit
17 Test to bequeath participants from an Assignment to a Course - Checks if participants in Course is already in Assignment
18 Test to bequeath participants from an Assignment to a Course - Successful inherit from Course to Assignment
19 Test to destroy participant - Failed to remove participant
20 Test to destroy participant - Successful deletion of a participant


Previous Participants Controller Test Implementation: here

Contributors

  1. Saksham Pandey (spandey5@ncsu.edu)
  2. Devashish Vachhani (dvachha@ncsu.edu)
  3. Karthik K Jayakumar (kkunnum@ncsu.edu)

Mentor: Rucha Kolekar (rbkoleka@ncsu.edu)

Thanks to participants model re-implementation team

Relevant Links