CSC/ECE 517 Fall 2024 - E2484. Reimplement participants controller.rb
About Expertiza
Expertiza is an open source project based on Ruby on Rails framework. Expertiza allows the instructor to create new assignments and customize new or existing assignments. It also allows the instructor to create a list of topics the students can sign up for. Students can form teams in Expertiza to work on various projects and assignments. Students can also peer review other students' submissions. Expertiza supports submission across various document types, including the URLs and wiki pages.
Introduction
This project aims to reimplement the participants_controller.rb
and participants_helper.rb
in the new Expertiza system. The participants_controller.rb
manages participants within assignments, and this reimplementation focuses on streamlining its methods, eliminating redundancy, and enhancing code readability and maintainability.
Requirements
participants_controller.rb
Methods: Fully implement each controller method with the same functionality as the current controller. participants_helper.rb
: Integrate relevant helper methods to streamline functionality and remove redundancy. Existing Issues
Reimplement participants_controller.rb
while addressing the following:
Design / Proposed Solution
Controller Diagram
participants_controller.rb
Methods / API Calls
# | Method | Endpoint | Description |
---|---|---|---|
1 | index | GET /participants
|
Return a list of participants |
2 | show | GET /participants/:id
|
Return a specified participant |
3 | inherit | GET /participants/inherit
|
Copy all participants from a course to an assignment |
4 | bequeath | GET /participants/bequeath
|
Copy all participants from an assignment to a course |
5 | create | POST /participants
|
Create a participant |
6 | update_authorization | PATCH /participants/:id/authorization
|
Update the permissions of a participant |
7 | update_handle | PATCH /participants/:id/handle
|
Update the handle of a participant |
8 | destroy | DELETE /participants/:id
|
Delete a specified participant |
9 | participant_params | ||
Permitted parameters for creating or updating a Participant object |
It is worth mentioning that the following methods were removed from participants_controller.rb
:
action_allowed?
- No impact on functionality controller_locale
- No impact on functionality delete
- Handled in the Assignment model, specifically assignment.rb
view_copyright_grants
- Incorrectly implemented in the old implementation get_user_info
- All needed User data can be accessed by leveraging the Participant model's belongs_to relationship to the User model get_signup_topics_for_assignment
- Handled in the SignUpTopicsController, specifically sign_up_topics_controller.rb
participants_helper.rb
Methods
The methods in participants_helper.rb
are outdated and do not impact any functionality in participants_controller.rb
. Most of these methods pertain to user creation/management and managing permissions—tasks that no longer require separate methods due to improved associations and centralized authorization management.
The Participant model is associated with the User model through a belongs_to relationship. This association allows user data to be accessed directly, eliminating the need for many of the methods in the old implementation that manually handled such data retrieval.
In addition, authorization_helper.rb
centralizes and manages all aspects of permissions and access control. This significantly simplifies the implementation, rendering much of the legacy logic redundant.
As a result, the methods in participants_helper.rb
will not be carried forward to the new implementation.
Pattern(s)
Facade: "A simplified interface that performs many other actions behind the scenes."
The participants_controller.rb uses the Facade Design Pattern to streamline interactions with the Expertiza backend, abstracting away complex logic and data handling tasks into a simplified API layer. A lot of calls to various services, objects, and features are abstracted, providing a unified, cohesive interface. By centralizing these calls, the controller can reduce dependencies on specific backend structures, making it easier for the front end to perform actions with minimal knowledge of what is going on in the backend, enhancing the maintainability and scalability of our codebase. Some such examples would be to call all the participants of a specific assignment, or pulling information about the course from a participant. Things that would otherwise complicate the front end due to the need to hunt through the backend for information that they need can be abstracted away into the facade interface. The current implementation already employs the facade pattern by its nature, but we will improve it by specifically targeting features of the facade design pattern.
SOLID Principle(s)
Open and Closed Principle: "Software entities should be open for extension, but closed for modification."
Currently, the code directly checks the type of curr_object to determine whether it’s an Assignment or Course, which can make it challenging to extend or modify. To address this, we will implement polymorphism by moving participant-related logic into the respective classes (Assignment, Course, etc.). Each class will define its own behavior for handling participants by overriding a common interface or inheriting from a shared base class. For example, A ParticipantHelper file will define methods like add_user_to_course/assignment, store item, participant_permissions, and numerous other non-idiomatic methods that go against the model view controller design pattern. Method operations that implement business logic, such as the methods listed before, should generally not be the responsibility of the controller.
Single Responsibility Principle: "A class should only have one responsibility and should never have more than one reason to change."
The current implementation of the participant controller mostly aligns with the Single Responsibility Principle, but some methods have more than one responsibility, such as combining backend logic with UI feedback. Many methods within the ParticipantsController class have this type of combined logic, for example, list, add, and inherit methods. These methods blend participant management logic with flash message handling. To make our code comply with the Single Responsibility Principle, we can move these flash messages into a helper method. These modifications reduce the controller’s responsibilities, improving our code’s readability and reusability. Lastly, the frontend developers will have predictable API behavior and consistent responses when our code adheres to the Single Responsibility Principle.
Implementation
Implement participants_controller.rb
Methods
Refer to the API Call section for all design-related inquiries
Old Method Name | Action | New Method Name |
---|---|---|
action_allowed? | Removed | - |
controller_locale | Removed | - |
list | Renamed | index |
add | Renamed | create |
update_authorizations | Renamed | update_authorization |
destroy | No Change | destroy |
inherit | No Change | inherit |
bequeath_all | Renamed | bequeath |
change_handle | Renamed | update_handle |
delete | Removed | - |
view_copyright_grants | Removed | - |
participant_params | No Change | participant_params |
get_user_info | Removed | - |
get_signup_topics_for_assignment | Removed | - |
- | Added | show |
To be expanded upon during implementation
Import from participants_helper.rb
Refer to the Helper Methods section for all design-related inquiries
To be expanded upon during implementation
API Creation
Refer to the API Call section for all design-related inquiries
To be expanded upon during implementation
Testing with rswag
Refer to the Testing Plan section
To be expanded upon during implementation
Swagger UI Video Documentation
To be added at a later time
Testing Plan
rswag
We will use rswag to test and document our project’s API endpoints. Rswag integrates RSpec testing with Swagger, allowing us to define test cases in RSpec to validate functionality while automatically generating interactive Swagger documentation. This documentation, accessible through Swagger UI, provides developers and stakeholders with a user-friendly way to explore and interact with our API endpoints.
Tests
Test ID | Test Description |
---|---|
1 | Test 'index' with valid model (Assignment) and ID - Should list participants |
2 | Test 'index' with invalid model (Assignment) and ID - Should return an error message |
3 | Test 'show' with valid participant ID - Should return the specified participant details |
4 | Test 'show' with invalid participant ID - Should return participant not found |
5 | Test 'inherit' with valid assignment ID but no course participants - Should display a message indicating no participants were found to inherit |
6 | Test 'inherit' with invalid assignment ID - Should return assignment not found message |
7 | Test 'inherit' with valid assignment ID and course with participants - Should copy participants from course to assignment |
8 | Test 'bequeath' with valid assignment ID with no assignment participants - Should display a message indicating no participants were found |
9 | Test 'bequeath' with invalid assignment ID - Should return assignment not found message |
10 | Test 'bequeath' with valid assignment ID and course with participants - Should copy participants from assignment to course |
11 | Test 'create' with valid user detail - Should successfully create a new participant |
12 | Test 'create' with duplicate user information - Should return an error message indicating that the participant already exists |
13 | Test 'update_authorization' with valid participant ID and permissions - Should update participant’s permissions successfully |
14 | Test `update_authorization` with invalid participant ID - Should return not found message |
15 | Test 'update_handle' with valid participant ID and unique handle - Should successfully update |
16 | Test 'update_handle' with duplicate handle - Should return an error message indicating handle is in use |
17 | Test 'destroy' with valid participant ID - Should delete the specified participant |
18 | Test 'destroy' with invalid participant ID - Should return participant not found message |
Team
Mentor
- Jay Patel <jhpatel9@ncsu.edu>
Students
- Pierce Whelan <pwwhelan@ncsu.edu>
- Calvin Jiang <crjiang@ncsu.edu>
- Hechun Zhang <hzhang56@ncsu.edu>
Relevant Links
Pull Request [1]
GitHub Repository [2]
GitHub Project Board [3]
participants_controller.rb
in Old Expertiza [4]
participants_helper.rb
in Old Expertiza [5]