<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://wiki.expertiza.ncsu.edu/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Hzhang56</id>
	<title>Expertiza_Wiki - User contributions [en]</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.expertiza.ncsu.edu/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Hzhang56"/>
	<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=Special:Contributions/Hzhang56"/>
	<updated>2026-08-19T18:10:09Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.41.0</generator>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2024_-_E2484._Reimplement_participants_controller.rb&amp;diff=160178</id>
		<title>CSC/ECE 517 Fall 2024 - E2484. Reimplement participants controller.rb</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2024_-_E2484._Reimplement_participants_controller.rb&amp;diff=160178"/>
		<updated>2024-12-03T18:47:10Z</updated>

		<summary type="html">&lt;p&gt;Hzhang56: /* Swagger UI Video Documentation */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==About Expertiza==&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is an open source project based on [http://rubyonrails.org/ 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.&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
This project aims to reimplement the &amp;lt;code&amp;gt; participants_controller.rb &amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt; participants_helper.rb &amp;lt;/code&amp;gt; in the new Expertiza system. The &amp;lt;code&amp;gt; participants_controller.rb &amp;lt;/code&amp;gt; manages participants within assignments, and this reimplementation focuses on streamlining its methods, eliminating redundancy, and enhancing code readability and maintainability.&lt;br /&gt;
&lt;br /&gt;
==Requirements==&lt;br /&gt;
&amp;lt;li&amp;gt; Implement &amp;lt;code&amp;gt; participants_controller.rb &amp;lt;/code&amp;gt; Methods: Fully implement each controller method with the same functionality as the current controller. &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Import from &amp;lt;code&amp;gt; participants_helper.rb &amp;lt;/code&amp;gt;: Integrate relevant helper methods to streamline functionality and remove redundancy. &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; API Creation: Expose API endpoints for all necessary methods to enable seamless access and integration from the frontend. Ensure that each endpoint follows best practices for RESTful API design, including proper error handling and secure data access. &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Testing with rswag: Create test cases for all methods, focusing on edge cases, and generate rswag documentation. &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Swagger UI Video Documentation: Record a video walkthrough of API endpoints in Swagger UI, showcasing each method’s functionality. &amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Existing Issues==&lt;br /&gt;
Reimplement &amp;lt;code&amp;gt; [https://github.com/expertiza/expertiza/blob/main/app/controllers/participants_controller.rb participants_controller.rb] &amp;lt;/code&amp;gt; while addressing the following:&lt;br /&gt;
&amp;lt;li&amp;gt; Refactor code to comply with the Open-Closed Principle and the Single Responsibility Principle. &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Introduce dependency injection where necessary. &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Reduce excessive conditional statements. &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Include sufficient code tests to verify functionality. &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Enhance comments to better explain each method's functionality, purpose, and rationale for keeping or modifying particular aspects of the code. &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Provide a more detailed explanation of design choices and refactoring steps. &amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Design / Proposed Solution ==&lt;br /&gt;
===Controller Diagram===&lt;br /&gt;
[[File:Participants Controller UML Diagram.png]]&lt;br /&gt;
&lt;br /&gt;
===&amp;lt;code&amp;gt; participants_controller.rb &amp;lt;/code&amp;gt; Methods / API Calls===&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;width: 100%;&lt;br /&gt;
! &amp;amp;nbsp;#&amp;amp;nbsp; !! Method !! Endpoint !! Description &lt;br /&gt;
|-&lt;br /&gt;
|1&lt;br /&gt;
|user_index&lt;br /&gt;
|GET &amp;lt;code&amp;gt; /participants/user/:user_id &amp;lt;/code&amp;gt;&lt;br /&gt;
|Return a list of participants for a given user&lt;br /&gt;
|-&lt;br /&gt;
|2&lt;br /&gt;
|assignment_index&lt;br /&gt;
|GET &amp;lt;code&amp;gt; /participants/assignment/:assignment_id &amp;lt;/code&amp;gt;&lt;br /&gt;
|Return a list of participants for a given assignment&lt;br /&gt;
|-&lt;br /&gt;
|3&lt;br /&gt;
|show&lt;br /&gt;
|GET &amp;lt;code&amp;gt; /participants/:id &amp;lt;/code&amp;gt;&lt;br /&gt;
|Return a specified participant&lt;br /&gt;
|-&lt;br /&gt;
|4&lt;br /&gt;
|add&lt;br /&gt;
|POST &amp;lt;code&amp;gt; /participants/:authorization &amp;lt;/code&amp;gt;&lt;br /&gt;
|Assign the specified authorization to the participant and add them to an assignment&lt;br /&gt;
|-&lt;br /&gt;
|5&lt;br /&gt;
|update_authorization&lt;br /&gt;
|PATCH &amp;lt;code&amp;gt; /participants/:id/:authorization &amp;lt;/code&amp;gt;&lt;br /&gt;
|Update the specified participant to the specified authorization&lt;br /&gt;
|-&lt;br /&gt;
|6&lt;br /&gt;
|destroy&lt;br /&gt;
|DELETE &amp;lt;code&amp;gt; /participants/:id &amp;lt;/code&amp;gt;&lt;br /&gt;
|Delete a participant&lt;br /&gt;
|-&lt;br /&gt;
|7&lt;br /&gt;
|participant_params&lt;br /&gt;
| -&lt;br /&gt;
|Permitted parameters for creating a Participant object&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
The following methods were removed from &amp;lt;code&amp;gt; participants_controller.rb &amp;lt;/code&amp;gt;:&lt;br /&gt;
&amp;lt;li&amp;gt; &amp;lt;code&amp;gt; action_allowed? &amp;lt;/code&amp;gt; - No impact on functionality &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; &amp;lt;code&amp;gt; controller_locale &amp;lt;/code&amp;gt; - No impact on functionality &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; &amp;lt;code&amp;gt; inherit &amp;lt;/code&amp;gt; - Since there is no direct relationship between the Participant and Course classes, this logic is redundant and no longer necessary &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; &amp;lt;code&amp;gt; bequeath_all &amp;lt;/code&amp;gt; - Since there is no direct relationship between the Participant and Course classes, this logic is redundant and no longer necessary &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; &amp;lt;code&amp;gt; change_handle &amp;lt;/code&amp;gt; - The User class has a `handle` field already. It would be redundant to have one in Participant as well.&lt;br /&gt;
&amp;lt;li&amp;gt; &amp;lt;code&amp;gt; delete &amp;lt;/code&amp;gt; - Handled in the &amp;lt;i&amp;gt; remove_participant &amp;lt;/i&amp;gt; method of the AssignmentsController (&amp;lt;code&amp;gt; assignments_controller.rb &amp;lt;/code&amp;gt;) &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; &amp;lt;code&amp;gt; view_copyright_grants &amp;lt;/code&amp;gt; - Incorrectly implemented in the old implementation &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; &amp;lt;code&amp;gt; get_user_info &amp;lt;/code&amp;gt; - All needed user data can be accessed by leveraging the Participant model's &amp;lt;i&amp;gt; belongs_to &amp;lt;/i&amp;gt; relationship to the User model &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; &amp;lt;code&amp;gt; get_signup_topics_for_assignment &amp;lt;/code&amp;gt; - Handled in the &amp;lt;i&amp;gt; index &amp;lt;/i&amp;gt; method of the SignUpTopicsController (&amp;lt;code&amp;gt; sign_up_topics_controller.rb &amp;lt;/code&amp;gt;) &amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===&amp;lt;code&amp;gt; participants_helper.rb &amp;lt;/code&amp;gt; Methods===&lt;br /&gt;
Almost all of the methods in &amp;lt;code&amp;gt;participants_helper.rb&amp;lt;/code&amp;gt; are outdated and do not impact any functionality in &amp;lt;code&amp;gt;participants_controller.rb&amp;lt;/code&amp;gt;. &amp;lt;br/&amp;gt;&lt;br /&gt;
As a result, these methods will not be carried forward to the new implementation:&lt;br /&gt;
&amp;lt;li&amp;gt; &amp;lt;code&amp;gt; upload_users &amp;lt;/code&amp;gt; - Logic for creating a User specifically for the Assignment and Course classes. Since there is no direct relationship between the User and these classes, this logic is redundant and no longer necessary &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; &amp;lt;code&amp;gt; define_attributes &amp;lt;/code&amp;gt; - &amp;lt;i&amp;gt; Same reason as above &amp;lt;/i&amp;gt; &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; &amp;lt;code&amp;gt; define_user &amp;lt;/code&amp;gt; - &amp;lt;i&amp;gt; Same reason as above &amp;lt;/i&amp;gt; &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; &amp;lt;code&amp;gt; create_new_user &amp;lt;/code&amp;gt; - &amp;lt;i&amp;gt; Same reason as above &amp;lt;/i&amp;gt; &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; &amp;lt;code&amp;gt; add_user_to_assignment &amp;lt;/code&amp;gt; - &amp;lt;i&amp;gt; Same reason as above. &amp;lt;/i&amp;gt; Furthermore, since the Participant and Assignment classes are directly related, this functionality has been replaced by the &amp;lt;i&amp;gt; add_participant &amp;lt;/i&amp;gt; method in AssignmentsController (&amp;lt;code&amp;gt;assignments_controller.rb&amp;lt;/code&amp;gt;) &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; &amp;lt;code&amp;gt; add_user_to_course &amp;lt;/code&amp;gt; - &amp;lt;i&amp;gt; Same reason as above &amp;lt;/i&amp;gt; &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; &amp;lt;code&amp;gt; get_config &amp;lt;/code&amp;gt; - &amp;lt;i&amp;gt; Same reason as above &amp;lt;/i&amp;gt; &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; &amp;lt;code&amp;gt; store_item &amp;lt;/code&amp;gt; - &amp;lt;i&amp;gt; Same reason as above &amp;lt;/i&amp;gt; &amp;lt;/li&amp;gt;&lt;br /&gt;
The only method being kept is &amp;lt;code&amp;gt;participant_permissions&amp;lt;/code&amp;gt; as it is responsible for handling the assignment of permissions to a Participant.&lt;br /&gt;
&lt;br /&gt;
===Pattern(s)===&lt;br /&gt;
'''Facade''': &amp;quot;A simplified interface that performs many other actions behind the scenes.&amp;quot; &amp;lt;br/&amp;gt;&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
===SOLID Principle(s)===&lt;br /&gt;
'''Open and Closed Principle''': &amp;quot;Software entities should be open for extension, but closed for modification.&amp;quot;&amp;lt;br/&amp;gt;&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
'''Single Responsibility Principle''': &amp;quot;A class should only have one responsibility and should never have more than one reason to change.&amp;quot;&amp;lt;br/&amp;gt;&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
==Implementation==&lt;br /&gt;
===Implement &amp;lt;code&amp;gt; participants_controller.rb &amp;lt;/code&amp;gt; Methods===&lt;br /&gt;
Refer to the [https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2024_-_E2484._Reimplement_participants_controller.rb#participants_controller.rb_Methods_/_API_Calls &amp;lt;code&amp;gt; participants_controller.rb &amp;lt;/code&amp;gt; Methods / API Calls] section for a brief overview of its use &amp;lt;br/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|+&lt;br /&gt;
! Old Method Name !! Action !! New Method Name&lt;br /&gt;
|-&lt;br /&gt;
| action_allowed? || Removed || -&lt;br /&gt;
|-&lt;br /&gt;
| controller_locale || Removed || -&lt;br /&gt;
|-&lt;br /&gt;
| list || Renamed and Separated || user_index&lt;br /&gt;
|-&lt;br /&gt;
| - || - || assignment_index&lt;br /&gt;
|-&lt;br /&gt;
| add || No Change || add&lt;br /&gt;
|-&lt;br /&gt;
| update_authorizations || Renamed || update_authorization&lt;br /&gt;
|-&lt;br /&gt;
| destroy || No Change || destroy&lt;br /&gt;
|-&lt;br /&gt;
| inherit || Removed || -&lt;br /&gt;
|-&lt;br /&gt;
| bequeath_all || Removed || -&lt;br /&gt;
|-&lt;br /&gt;
| change_handle || Removed || -&lt;br /&gt;
|-&lt;br /&gt;
| delete || Removed || -&lt;br /&gt;
|-&lt;br /&gt;
| view_copyright_grants || Removed || -&lt;br /&gt;
|-&lt;br /&gt;
| participant_params || No Change || participant_params&lt;br /&gt;
|-&lt;br /&gt;
| get_user_info || Removed || -&lt;br /&gt;
|-&lt;br /&gt;
| get_signup_topics_for_assignment || Removed || -&lt;br /&gt;
|-&lt;br /&gt;
| - || Added || show&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;code&amp;gt;user_index&amp;lt;/code&amp;gt; Method====&lt;br /&gt;
Description:&lt;br /&gt;
&lt;br /&gt;
This method retrieves a list of participants associated with a specific user. If a valid user_id is provided in the request, the system searches for the corresponding user and returns the list of participants linked to that user. If no participants are found, or if the user is invalid, an appropriate error response is returned.&lt;br /&gt;
Parameters:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;user_id&amp;lt;/code&amp;gt;: The ID of the user whose participants you want to retrieve. If the user does not exist, the method returns without further action. &amp;lt;br/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Behavior:&lt;br /&gt;
&lt;br /&gt;
*The method validates the presence and existence of the &amp;lt;code&amp;gt;user_id&amp;lt;/code&amp;gt;.&lt;br /&gt;
**If the user_id is invalid, the method then stops execution and does not proceed with participant retrieval. &lt;br /&gt;
**If a valid user is provided, then it will retrieve all participants and filter in the ones of the provided user.&lt;br /&gt;
***The final filtered list of participants is returned as a JSON response.&lt;br /&gt;
***If the final list would be empty, then it will return with error 422&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;code&amp;gt;assignment_index&amp;lt;/code&amp;gt; Method====&lt;br /&gt;
Description:&lt;br /&gt;
&lt;br /&gt;
This method retrieves a list of participants associated with a specific assignment. If a valid assignment_id is provided in the request, the system searches for the corresponding assignment and returns the list of participants linked to that assignment. If no participants are found, or if the assignment is invalid, an appropriate error response is returned.&lt;br /&gt;
Parameters:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;assignment_id&amp;lt;/code&amp;gt;: The ID of the assignment whose participants you want to retrieve. If the assignment does not exist, the method returns without further action. &amp;lt;br/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Behavior:&lt;br /&gt;
&lt;br /&gt;
*The method validates the presence and existence of the &amp;lt;code&amp;gt;assignment_id&amp;lt;/code&amp;gt;.&lt;br /&gt;
**If the assignment_id is invalid, the method then stops execution and does not proceed with participant retrieval. &lt;br /&gt;
**If a valid assignment is provided, then it will retrieve all participants and filter in the ones of the provided assignment.&lt;br /&gt;
***The final filtered list of participants is returned as a JSON response.&lt;br /&gt;
***If the final list would be empty, then it will return with error 422&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;code&amp;gt;add&amp;lt;/code&amp;gt; Method====&lt;br /&gt;
&lt;br /&gt;
Description:&lt;br /&gt;
&lt;br /&gt;
Assigns the specified authorization to a participant and adds them to a given assignment. It performs the necessary validations to ensure that the user, assignment, and authorization are valid before proceeding. If all validations pass, it associates the participant with the assignment and applies the relevant permissions based on the authorization.&lt;br /&gt;
&lt;br /&gt;
Parameters:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;user_id&amp;lt;/code&amp;gt; (required): The ID of the user to be added as a participant.&lt;br /&gt;
&amp;lt;code&amp;gt;assignment_id&amp;lt;/code&amp;gt; (required): The ID of the assignment the user will be added to.&lt;br /&gt;
&amp;lt;code&amp;gt;authorization&amp;lt;/code&amp;gt; (required): The authorization ID to define the user's permissions within the assignment.&lt;br /&gt;
&lt;br /&gt;
Behavior:&lt;br /&gt;
&lt;br /&gt;
*Validates and retrieves the user based on the provided &amp;lt;code&amp;gt;user_id&amp;lt;/code&amp;gt;. If the user is not found, the method terminates.&lt;br /&gt;
*Validates and retrieves the assignment based on the provided &amp;lt;code&amp;gt;assignment_id&amp;lt;/code&amp;gt;. If the assignment is not found, the method terminates.&lt;br /&gt;
*Validates and retrieves the authorization based on the provided &amp;lt;code&amp;gt;assignment_id&amp;lt;/code&amp;gt;. If the authorization is not found, the method terminates.&lt;br /&gt;
*Builds a new Participant instance linked to the validated user and assignment, with the appropriate permissions obtained from authorization.&lt;br /&gt;
*Attempts to save the Participant:&lt;br /&gt;
**If successful: Returns a JSON response containing the created Participant and a 201 Created status.&lt;br /&gt;
**If unsuccessful: Returns a JSON response containing validation errors and a 422 Unprocessable Entity status.&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;code&amp;gt;update_authorization&amp;lt;/code&amp;gt; Method ====&lt;br /&gt;
Description:&lt;br /&gt;
&lt;br /&gt;
Updates the authorization and associated permissions for an existing participant.&lt;br /&gt;
&lt;br /&gt;
Parameters:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;participant_id&amp;lt;/code&amp;gt; (required): The ID of the participant whose authorization is being updated.&lt;br /&gt;
&amp;lt;code&amp;gt;authorization&amp;lt;/code&amp;gt; (required): The new authorization ID to assign to the participant.&lt;br /&gt;
&lt;br /&gt;
Behavior:&lt;br /&gt;
*Validates the provided authorization using validate_authorization after finding the participant. If the authorization is missing, the method halts and returns 422.&lt;br /&gt;
*Upon successful validation of the authorization, the method retrieves the permissions associated with the authorization by calling retrieve_participant_permissions.&lt;br /&gt;
*Updates the participant's authorization field with the new authorization. Relevant permissions (can_submit, can_review, can_take_quiz, and can_mentor) are also updated based on the authorization’s values.&lt;br /&gt;
*Attempts to save the updated participant&lt;br /&gt;
**If the participant is successfully updated and saved to the database, a JSON response with the updated participant details and a 201 Created status is returned.&lt;br /&gt;
**If there are validation errors or the update fails, a JSON response with error details and a 422 Unprocessable Entity status is returned.&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;code&amp;gt;destroy&amp;lt;/code&amp;gt; Method====&lt;br /&gt;
&lt;br /&gt;
Description:&lt;br /&gt;
&lt;br /&gt;
Deletes a specified Participant based on the provided ID.&lt;br /&gt;
&lt;br /&gt;
Parameters:&lt;br /&gt;
&lt;br /&gt;
*&amp;lt;code&amp;gt;id&amp;lt;/code&amp;gt; (required): The ID of the Participant to be deleted.&lt;br /&gt;
&lt;br /&gt;
Behavior:&lt;br /&gt;
&lt;br /&gt;
*Retrieves the Participant using the provided &amp;lt;code&amp;gt;id&amp;lt;/code&amp;gt;.&lt;br /&gt;
*Attempts to delete the Participant:&lt;br /&gt;
**If successful: Returns a JSON response containing a confirmation message and a 200 OK status.&lt;br /&gt;
**If unsuccessful: Returns a JSON response containing validation errors and a 422 Unprocessable Entity status.&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;code&amp;gt;show&amp;lt;/code&amp;gt; Method====&lt;br /&gt;
&lt;br /&gt;
Description:&lt;br /&gt;
&lt;br /&gt;
Retrieves and returns a specific Participant based on the provided ID.&lt;br /&gt;
&lt;br /&gt;
Parameters:&lt;br /&gt;
&lt;br /&gt;
*&amp;lt;code&amp;gt;id&amp;lt;/code&amp;gt; (required): The ID of the Participant to be retrieved.&lt;br /&gt;
&lt;br /&gt;
Behavior:&lt;br /&gt;
&lt;br /&gt;
*Fetches the Participant from the database using the provided &amp;lt;code&amp;gt;id&amp;lt;/code&amp;gt;.&lt;br /&gt;
*Attempts to fetch the Participant:&lt;br /&gt;
**If successful: Returns a JSON response containing a confirmation message and a 200 OK status.&lt;br /&gt;
**If unsuccessful: Returns a JSON response containing validation errors and a 422 Unprocessable Entity status.&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;code&amp;gt;participant_params&amp;lt;/code&amp;gt; Method====&lt;br /&gt;
&lt;br /&gt;
Description:&lt;br /&gt;
&lt;br /&gt;
Defines the permitted parameters for creating or updating a Participant object.&lt;br /&gt;
&lt;br /&gt;
Parameters:&lt;br /&gt;
&lt;br /&gt;
The method expects a Participant object within the request parameters. It permits the following attributes:&lt;br /&gt;
&lt;br /&gt;
*&amp;lt;code&amp;gt;user_id&amp;lt;/code&amp;gt; (required): The ID of the user associated with the Participant.&lt;br /&gt;
*&amp;lt;code&amp;gt;assignment_id&amp;lt;/code&amp;gt; (required): The ID of the assignment linked to the Participant.&lt;br /&gt;
*&amp;lt;code&amp;gt;team_id&amp;lt;/code&amp;gt; (optional): The ID of the team the Participant belongs to.&lt;br /&gt;
*&amp;lt;code&amp;gt;can_submit&amp;lt;/code&amp;gt;: A boolean indicating whether the Participant has submit permissions granted.&lt;br /&gt;
*&amp;lt;code&amp;gt;can_review&amp;lt;/code&amp;gt;: A boolean indicating whether the Participant has review permissions granted.&lt;br /&gt;
*&amp;lt;code&amp;gt;can_take_quiz&amp;lt;/code&amp;gt;: A boolean indicating whether the Participant has take_quiz permissions granted.&lt;br /&gt;
*&amp;lt;code&amp;gt;can_mentor&amp;lt;/code&amp;gt;: A boolean indicating whether the Participant has mentor permissions granted.&lt;br /&gt;
*&amp;lt;code&amp;gt;join_team_request_id&amp;lt;/code&amp;gt; (optional): The ID of any pending team join request related to the Participant.&lt;br /&gt;
*&amp;lt;code&amp;gt;permission_granted&amp;lt;/code&amp;gt; (optional): A boolean indicating whether the Participant has specific permissions granted.&lt;br /&gt;
*&amp;lt;code&amp;gt;topic&amp;lt;/code&amp;gt; (optional): The topic assigned to the Participant (could be a string or other data type depending on the application context).&lt;br /&gt;
*&amp;lt;code&amp;gt;current_stage&amp;lt;/code&amp;gt; (optional): The current progress stage of the Participant.&lt;br /&gt;
*&amp;lt;code&amp;gt;stage_deadline&amp;lt;/code&amp;gt; (optional): The deadline for the current stage.&lt;br /&gt;
&lt;br /&gt;
Behavior:&lt;br /&gt;
&lt;br /&gt;
*Ensures that only allowed parameters are passed when creating a Participant object.&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;code&amp;gt;filter_user_participants&amp;lt;/code&amp;gt; Method ====&lt;br /&gt;
Description:&lt;br /&gt;
&lt;br /&gt;
Retrieves and filters participants based on the provided user.&lt;br /&gt;
&lt;br /&gt;
Parameters:&lt;br /&gt;
&lt;br /&gt;
*&amp;lt;code&amp;gt;user&amp;lt;/code&amp;gt; (required): An instance of the User model. If provided, the method filters participants associated with this user.&lt;br /&gt;
&lt;br /&gt;
Behavior:&lt;br /&gt;
&lt;br /&gt;
*Fetches all participants from the database.&lt;br /&gt;
*The method filters participants where the user_id matches the given user's ID.&lt;br /&gt;
*The final list of participants is then ordered by their id in ascending order.&lt;br /&gt;
====&amp;lt;code&amp;gt;filter_assignment_participants&amp;lt;/code&amp;gt; Method ====&lt;br /&gt;
Description:&lt;br /&gt;
&lt;br /&gt;
Retrieves and filters participants based on the provided assignment.&lt;br /&gt;
&lt;br /&gt;
Parameters:&lt;br /&gt;
&lt;br /&gt;
*&amp;lt;code&amp;gt;assignment&amp;lt;/code&amp;gt; (required): An instance of the assignment model. If provided, the method filters participants associated with this assignment.&lt;br /&gt;
&lt;br /&gt;
Behavior:&lt;br /&gt;
&lt;br /&gt;
*Fetches all participants from the database.&lt;br /&gt;
*The method filters participants where the assignment_id matches the given assignment's ID.&lt;br /&gt;
*The final list of participants is then ordered by their id in ascending order.&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;code&amp;gt;find_user&amp;lt;/code&amp;gt; Method ====&lt;br /&gt;
&lt;br /&gt;
Description:&lt;br /&gt;
Retrieves a User object based on the user_id provided. If the user is not found, it returns an error response and halts further execution.&lt;br /&gt;
&lt;br /&gt;
Parameters:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;user_id&amp;lt;/code&amp;gt; (optional): The ID of the user to be retrieved. Extracted from the permitted parameters.&lt;br /&gt;
&lt;br /&gt;
Behavior:&lt;br /&gt;
&lt;br /&gt;
*Attempts to find the user in the database using the provided user_id.&lt;br /&gt;
**If the user is not found (nil), it renders a JSON response with an error message and 404 Not found status&lt;br /&gt;
**If the user exists, it returns the user object with 200 ok status.&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;code&amp;gt;find_assignment&amp;lt;/code&amp;gt; Method ====&lt;br /&gt;
&lt;br /&gt;
Description:&lt;br /&gt;
&lt;br /&gt;
Retrieves an Assignment object based on the assignment_id provided. If the Assignment is not found, it returns an error response and halts further execution.&lt;br /&gt;
&lt;br /&gt;
Parameters:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;assignment_id&amp;lt;/code&amp;gt; (optional): The ID of the assignment to be retrieved. Extracted from the permitted parameters.&lt;br /&gt;
&lt;br /&gt;
Behavior:&lt;br /&gt;
&lt;br /&gt;
*Attempts to find the assignment in the database using the provided assignment_id.&lt;br /&gt;
**If the assignment is not found (nil), it renders a JSON response with an error message and 404 Not found status&lt;br /&gt;
**If the assignment exists, it returns the assignment object with 200 ok status.&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;code&amp;gt;find_participant&amp;lt;/code&amp;gt; Method ====&lt;br /&gt;
&lt;br /&gt;
Description:&lt;br /&gt;
&lt;br /&gt;
Retrieves an participant object based on the participant_id provided. If the participant is not found, it returns an error response and halts further execution.&lt;br /&gt;
&lt;br /&gt;
Parameters:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;participant_id&amp;lt;/code&amp;gt; (optional): The ID of the participant to be retrieved. Extracted from the permitted parameters.&lt;br /&gt;
&lt;br /&gt;
Behavior:&lt;br /&gt;
&lt;br /&gt;
*Attempts to find the participant in the database using the provided participant_id.&lt;br /&gt;
**If the participant is not found (nil), it renders a JSON response with an error message and 404 Not found status&lt;br /&gt;
**If the participant exists, it returns the participant object with 200 ok status.&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;code&amp;gt;validate_authorization&amp;lt;/code&amp;gt; Method ====&lt;br /&gt;
Description:&lt;br /&gt;
*Validates the authorization parameter provided in the request. Ensures that the authorization value is one of the accepted roles: reader, reviewer, submitter, or mentor.&lt;br /&gt;
&lt;br /&gt;
Parameters:&lt;br /&gt;
*&amp;lt;code&amp;gt;authorization&amp;lt;/code&amp;gt; (required): A string representing the participant’s authorization role. This value must be one of the following: reader, reviewer, submitter, or mentor.&lt;br /&gt;
&lt;br /&gt;
Behavior:&lt;br /&gt;
*If the authorization parameter is present, it is converted to lowercase to ensure case-insensitive comparison.&lt;br /&gt;
*If the authorization parameter is not provided, the method renders a 422 Unprocessable Entity response with an error message indicating that a participant must have an authorization.&lt;br /&gt;
*If the authorization value is provided but does not match one of the valid roles (reader, reviewer, submitter, or mentor), the method renders a 422 Unprocessable Entity response with an error message listing the valid options.&lt;br /&gt;
*If the authorization value is valid, the method returns the authorization string.&lt;br /&gt;
&lt;br /&gt;
===Import from &amp;lt;code&amp;gt; participants_helper.rb &amp;lt;/code&amp;gt;===&lt;br /&gt;
Refer to the [https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2024_-_E2484._Reimplement_participants_controller.rb#participants_helper.rb_Methods &amp;lt;code&amp;gt; participants_helper.rb &amp;lt;/code&amp;gt; Methods] section for all design-related inquiries &amp;lt;br/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|+&lt;br /&gt;
! Old Method Name !! Action !! New Method Name&lt;br /&gt;
|-&lt;br /&gt;
| upload_users || Removed || -&lt;br /&gt;
|-&lt;br /&gt;
| define_attributes || Removed || -&lt;br /&gt;
|-&lt;br /&gt;
| define_user || Removed || -&lt;br /&gt;
|-&lt;br /&gt;
| create_new_user || Removed || -&lt;br /&gt;
|-&lt;br /&gt;
| add_user_to_assignment || Removed || -&lt;br /&gt;
|-&lt;br /&gt;
| add_user_to_course || Removed || -&lt;br /&gt;
|-&lt;br /&gt;
| get_config || Removed || -&lt;br /&gt;
|-&lt;br /&gt;
| store_item || Removed || -&lt;br /&gt;
|-&lt;br /&gt;
| participant_permissions || Renamed || retrieve_participant_permissions&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;code&amp;gt;retrieve_participant_permissions&amp;lt;/code&amp;gt; Method====&lt;br /&gt;
&lt;br /&gt;
Description:&lt;br /&gt;
*Retrieves the permissions associated with a given authorization role. The permissions determine the actions a participant can perform (e.g., submitting, reviewing, taking quizzes, or mentoring). The method merges default permissions with role-specific overrides and returns the final set of permissions for the specified authorization.&lt;br /&gt;
&lt;br /&gt;
Parameters:&lt;br /&gt;
&lt;br /&gt;
*&amp;lt;code&amp;gt;authorization&amp;lt;/code&amp;gt; (required): A string representing the participant's authorization role. This value should be one of the following: reader, reviewer, submitter, or mentor.&lt;br /&gt;
Behavior:&lt;br /&gt;
*The method defines a set of default permissions that are assigned to all participants unless overridden by their specific authorization role. The default permissions allow submitting, reviewing, and taking quizzes, while disallowing mentoring.&lt;br /&gt;
*A permissions_map is used to define role-specific overrides for the default permissions:&lt;br /&gt;
**reader: Cannot submit, but can review and take quizzes.&lt;br /&gt;
**reviewer: Cannot submit or take quizzes, but can review.&lt;br /&gt;
**submitter: Cannot review or take quizzes, but can submit.&lt;br /&gt;
**mentor: Can mentor, and has the same permissions as a reader for other actions.&lt;br /&gt;
*The method merges the default permissions with the overrides for the specified authorization. The final set of permissions is returned.&lt;br /&gt;
&lt;br /&gt;
===API Creation===&lt;br /&gt;
Refer to the [https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2024_-_E2484._Reimplement_participants_controller.rb#participants_controller.rb_Methods_/_API_Calls &amp;lt;code&amp;gt; participants_controller.rb &amp;lt;/code&amp;gt; Methods / API Calls] section for all design-related inquiries &amp;lt;br/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Testing with rswag===&lt;br /&gt;
Refer to the [https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2024_-_E2484._Reimplement_participants_controller.rb#Testing_Plan Testing Plan] section &amp;lt;br/&amp;gt;&lt;br /&gt;
&amp;lt;i&amp;gt; To be expanded upon during implementation &amp;lt;/i&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Swagger UI Video Documentation===&lt;br /&gt;
Swagger UI Testing for the participants_controller.rb [https://www.youtube.com/watch?v=rhP57UexqRs] &amp;lt;br/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Testing Plan==&lt;br /&gt;
'''rswag'''&amp;lt;br/&amp;gt;&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
====Tests====&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;margin-left:40px&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Test ID !! Test Description &lt;br /&gt;
|-&lt;br /&gt;
| 1 || Test 'assignment_index' with valid assignment ID - Should list participants&lt;br /&gt;
|-&lt;br /&gt;
| 2 || Test 'assignment_index' with invalid assignment ID - Should return an 'Assignment not found' error&lt;br /&gt;
|-&lt;br /&gt;
| 3 || Test unauthorized bearer token access to 'assignment_index' endpoint - Should return a 'Not Authorized' message&lt;br /&gt;
|-&lt;br /&gt;
| 4 || Test 'user_index' with valid user ID - Should list participants&lt;br /&gt;
|-&lt;br /&gt;
| 5 || Test 'user_index' with valid user ID but no participants - Should return an empty list&lt;br /&gt;
|-&lt;br /&gt;
| 6 || Test 'user_index' with invalid user ID - Should return a 'User not found' error&lt;br /&gt;
|-&lt;br /&gt;
| 7 || Test unauthorized bearer token access to 'user_index' endpoint - Should return a 'Not Authorized' message&lt;br /&gt;
|-&lt;br /&gt;
| 8 || Test 'show' with valid participant ID - Should return the specified participant details&lt;br /&gt;
|-&lt;br /&gt;
| 9 || Test 'show' with invalid participant ID - Should return participant not found&lt;br /&gt;
|-&lt;br /&gt;
| 10 || Test unauthorized bearer token access to 'show' endpoint - Should return a 'Not Authorized' message&lt;br /&gt;
|-&lt;br /&gt;
| 11 || Test 'add' with valid user, assignment details, and authorization - Should successfully create a new participant&lt;br /&gt;
|-&lt;br /&gt;
| 12 || Test 'add' with duplicate user and assignment details - Should return an error indicating participant already exists&lt;br /&gt;
|-&lt;br /&gt;
| 13 || Test 'add' with invalid user ID - Should return a 'User not found' error&lt;br /&gt;
|-&lt;br /&gt;
| 14 || Test 'add' with invalid assignment ID - Should return an 'Assignment not found' error&lt;br /&gt;
|-&lt;br /&gt;
| 15 || Test 'add' with invalid authorization - Should return an error specifying valid authorizations (Reader, Reviewer, etc.)&lt;br /&gt;
|-&lt;br /&gt;
| 16 || Test unauthorized bearer token access to 'add' endpoint - Should return a 'Not Authorized' message&lt;br /&gt;
|-&lt;br /&gt;
| 17 || Test 'destroy' with valid participant ID - Should delete the specified participant&lt;br /&gt;
|-&lt;br /&gt;
| 18 || Test 'destroy' with invalid participant ID - Should return participant not found message&lt;br /&gt;
|-&lt;br /&gt;
| 19 || Test unauthorized bearer token access to 'destroy' endpoint - Should return a 'Not Authorized' message&lt;br /&gt;
|-&lt;br /&gt;
| 20 || Test 'update_authorization' participant authorization with valid participant ID and authorization - Should update the authorization level successfully&lt;br /&gt;
|-&lt;br /&gt;
| 21 || Test 'update_authorization' participant authorization with invalid participant ID - Should return a 'Participant not found' message&lt;br /&gt;
|-&lt;br /&gt;
| 22 || Test 'update_authorization' participant authorization with invalid participant ID and invalid authorization - Should return a 'Participant not found' message&lt;br /&gt;
|-&lt;br /&gt;
| 23 || Test 'update_authorization' participant authorization with invalid authorization - Should return a validation error for authorization  &lt;br /&gt;
|-&lt;br /&gt;
| 24 || Test unauthorized bearer token access to 'update_authorization' endpoint - Should return a 'Not Authorized' message&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==Next Steps==&lt;br /&gt;
Our goal throughout this implementation was to reduce the bloat and refactor the controller to something significantly cleaner. Originally, we had a design that we believed to be fairly clean, cutting out nearly 80% of the functions and almost half of the database columns. However, we were made aware that the new, significantly cut down implementation would not work within the current system, and we feel that we ended up re adding a lot of the bloat that we had just cut out. Roles are connected to the participant, but these participant roles are different than User roles. Permissions are handled by the participant, which while not bad, we believe it could be improved. The links between assignment and course is hardly fleshed out at all, and participant handles a lot of logic that could be better distributed. We were also made aware of an AssignmentParticipant and a CourseParticipant, which we believe to be unnecessarily specific. &lt;br /&gt;
&lt;br /&gt;
===Proposal===&lt;br /&gt;
We propose that the entire hierarchy and structure of the Course, Assignment, and Participant be re-designed from the ground up alongside each other to delegate tasks in a much more reasonable way. One way to do so would be a system that could look something like the following diagram.&lt;br /&gt;
&lt;br /&gt;
Diagram:&lt;br /&gt;
[[File:NewStructureProposal.png]]&lt;br /&gt;
&lt;br /&gt;
The primary change here would be a slight decoupling of participant from assignment and a unification of the AssignmentParticipant and CourseParticipant classes. We cant really see a logical reason for distinction between the two, and this would significantly reduce the amount of code bloat in the system. Instead, Participants will be the avatar through which a User interacts with the Course hierarchy. User would just be an account that accesses a participant for each class they are in.&lt;br /&gt;
&lt;br /&gt;
There would no longer be a need to create a participant object for every single user in every single assignment in a course, significantly reducing the bloat that creating an assignment for an entire class could cause under the current system.&lt;br /&gt;
&lt;br /&gt;
Roles would be assigned to participants, and then assignments would handle the logic behind permissions. This provides the advantage that different assignments can control how different roles can interact with themselves independently of each other. If they could already do that, then this resolves a DRY violation where permission information is logically acted upon in both Participant and Assignment.&lt;br /&gt;
&lt;br /&gt;
Incidentally, if you were to delegate some of User's roles to participant's roles, such as instructor, then instructors could then also become participants in classes without needing to create another account with student level permissions. If you were to adopt this structure even further out to include universities, Users that are admins of one university can be students of another all under one User account.&lt;br /&gt;
&lt;br /&gt;
However, this is likely to have cascading effects on other critical systems as well. Teams may need to be entirely re organized since there are no longer unique participants per user for each assignment, as well as many other implications that we may not have been able to anticipate.&lt;br /&gt;
&lt;br /&gt;
This is not the solution that has to be used, however, we believe that it would be an improvement on the current system.&lt;br /&gt;
&lt;br /&gt;
==Team==&lt;br /&gt;
'''Mentor''' &lt;br /&gt;
&lt;br /&gt;
*Jay Patel &amp;lt;jhpatel9@ncsu.edu&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Students'''&lt;br /&gt;
&lt;br /&gt;
*Pierce Whelan &amp;lt;pwwhelan@ncsu.edu&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*Calvin Jiang &amp;lt;crjiang@ncsu.edu&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*Hechun Zhang &amp;lt;hzhang56@ncsu.edu&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Relevant Links ==&lt;br /&gt;
Pull Request [https://github.com/expertiza/reimplementation-back-end/pull/135] &amp;lt;br/&amp;gt;&lt;br /&gt;
GitHub Repository [https://github.com/Pierce57/participant_controller_reimplementation.git] &amp;lt;br/&amp;gt;&lt;br /&gt;
GitHub Project Board [https://github.com/users/Pierce57/projects/3] &amp;lt;br/&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt; participants_controller.rb &amp;lt;/code&amp;gt; in Old Expertiza [https://github.com/expertiza/expertiza/blob/main/app/controllers/participants_controller.rb] &amp;lt;br/&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt; participants_helper.rb &amp;lt;/code&amp;gt; in Old Expertiza [https://github.com/expertiza/expertiza/blob/main/app/helpers/participants_helper.rb]&lt;/div&gt;</summary>
		<author><name>Hzhang56</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2024_-_E2484._Reimplement_participants_controller.rb&amp;diff=160176</id>
		<title>CSC/ECE 517 Fall 2024 - E2484. Reimplement participants controller.rb</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2024_-_E2484._Reimplement_participants_controller.rb&amp;diff=160176"/>
		<updated>2024-12-03T18:45:10Z</updated>

		<summary type="html">&lt;p&gt;Hzhang56: /* Swagger UI Video Documentation */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==About Expertiza==&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is an open source project based on [http://rubyonrails.org/ 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.&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
This project aims to reimplement the &amp;lt;code&amp;gt; participants_controller.rb &amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt; participants_helper.rb &amp;lt;/code&amp;gt; in the new Expertiza system. The &amp;lt;code&amp;gt; participants_controller.rb &amp;lt;/code&amp;gt; manages participants within assignments, and this reimplementation focuses on streamlining its methods, eliminating redundancy, and enhancing code readability and maintainability.&lt;br /&gt;
&lt;br /&gt;
==Requirements==&lt;br /&gt;
&amp;lt;li&amp;gt; Implement &amp;lt;code&amp;gt; participants_controller.rb &amp;lt;/code&amp;gt; Methods: Fully implement each controller method with the same functionality as the current controller. &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Import from &amp;lt;code&amp;gt; participants_helper.rb &amp;lt;/code&amp;gt;: Integrate relevant helper methods to streamline functionality and remove redundancy. &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; API Creation: Expose API endpoints for all necessary methods to enable seamless access and integration from the frontend. Ensure that each endpoint follows best practices for RESTful API design, including proper error handling and secure data access. &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Testing with rswag: Create test cases for all methods, focusing on edge cases, and generate rswag documentation. &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Swagger UI Video Documentation: Record a video walkthrough of API endpoints in Swagger UI, showcasing each method’s functionality. &amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Existing Issues==&lt;br /&gt;
Reimplement &amp;lt;code&amp;gt; [https://github.com/expertiza/expertiza/blob/main/app/controllers/participants_controller.rb participants_controller.rb] &amp;lt;/code&amp;gt; while addressing the following:&lt;br /&gt;
&amp;lt;li&amp;gt; Refactor code to comply with the Open-Closed Principle and the Single Responsibility Principle. &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Introduce dependency injection where necessary. &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Reduce excessive conditional statements. &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Include sufficient code tests to verify functionality. &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Enhance comments to better explain each method's functionality, purpose, and rationale for keeping or modifying particular aspects of the code. &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Provide a more detailed explanation of design choices and refactoring steps. &amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Design / Proposed Solution ==&lt;br /&gt;
===Controller Diagram===&lt;br /&gt;
[[File:Participants Controller UML Diagram.png]]&lt;br /&gt;
&lt;br /&gt;
===&amp;lt;code&amp;gt; participants_controller.rb &amp;lt;/code&amp;gt; Methods / API Calls===&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;width: 100%;&lt;br /&gt;
! &amp;amp;nbsp;#&amp;amp;nbsp; !! Method !! Endpoint !! Description &lt;br /&gt;
|-&lt;br /&gt;
|1&lt;br /&gt;
|user_index&lt;br /&gt;
|GET &amp;lt;code&amp;gt; /participants/user/:user_id &amp;lt;/code&amp;gt;&lt;br /&gt;
|Return a list of participants for a given user&lt;br /&gt;
|-&lt;br /&gt;
|2&lt;br /&gt;
|assignment_index&lt;br /&gt;
|GET &amp;lt;code&amp;gt; /participants/assignment/:assignment_id &amp;lt;/code&amp;gt;&lt;br /&gt;
|Return a list of participants for a given assignment&lt;br /&gt;
|-&lt;br /&gt;
|3&lt;br /&gt;
|show&lt;br /&gt;
|GET &amp;lt;code&amp;gt; /participants/:id &amp;lt;/code&amp;gt;&lt;br /&gt;
|Return a specified participant&lt;br /&gt;
|-&lt;br /&gt;
|4&lt;br /&gt;
|add&lt;br /&gt;
|POST &amp;lt;code&amp;gt; /participants/:authorization &amp;lt;/code&amp;gt;&lt;br /&gt;
|Assign the specified authorization to the participant and add them to an assignment&lt;br /&gt;
|-&lt;br /&gt;
|5&lt;br /&gt;
|update_authorization&lt;br /&gt;
|PATCH &amp;lt;code&amp;gt; /participants/:id/:authorization &amp;lt;/code&amp;gt;&lt;br /&gt;
|Update the specified participant to the specified authorization&lt;br /&gt;
|-&lt;br /&gt;
|6&lt;br /&gt;
|destroy&lt;br /&gt;
|DELETE &amp;lt;code&amp;gt; /participants/:id &amp;lt;/code&amp;gt;&lt;br /&gt;
|Delete a participant&lt;br /&gt;
|-&lt;br /&gt;
|7&lt;br /&gt;
|participant_params&lt;br /&gt;
| -&lt;br /&gt;
|Permitted parameters for creating a Participant object&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
The following methods were removed from &amp;lt;code&amp;gt; participants_controller.rb &amp;lt;/code&amp;gt;:&lt;br /&gt;
&amp;lt;li&amp;gt; &amp;lt;code&amp;gt; action_allowed? &amp;lt;/code&amp;gt; - No impact on functionality &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; &amp;lt;code&amp;gt; controller_locale &amp;lt;/code&amp;gt; - No impact on functionality &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; &amp;lt;code&amp;gt; inherit &amp;lt;/code&amp;gt; - Since there is no direct relationship between the Participant and Course classes, this logic is redundant and no longer necessary &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; &amp;lt;code&amp;gt; bequeath_all &amp;lt;/code&amp;gt; - Since there is no direct relationship between the Participant and Course classes, this logic is redundant and no longer necessary &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; &amp;lt;code&amp;gt; change_handle &amp;lt;/code&amp;gt; - The User class has a `handle` field already. It would be redundant to have one in Participant as well.&lt;br /&gt;
&amp;lt;li&amp;gt; &amp;lt;code&amp;gt; delete &amp;lt;/code&amp;gt; - Handled in the &amp;lt;i&amp;gt; remove_participant &amp;lt;/i&amp;gt; method of the AssignmentsController (&amp;lt;code&amp;gt; assignments_controller.rb &amp;lt;/code&amp;gt;) &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; &amp;lt;code&amp;gt; view_copyright_grants &amp;lt;/code&amp;gt; - Incorrectly implemented in the old implementation &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; &amp;lt;code&amp;gt; get_user_info &amp;lt;/code&amp;gt; - All needed user data can be accessed by leveraging the Participant model's &amp;lt;i&amp;gt; belongs_to &amp;lt;/i&amp;gt; relationship to the User model &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; &amp;lt;code&amp;gt; get_signup_topics_for_assignment &amp;lt;/code&amp;gt; - Handled in the &amp;lt;i&amp;gt; index &amp;lt;/i&amp;gt; method of the SignUpTopicsController (&amp;lt;code&amp;gt; sign_up_topics_controller.rb &amp;lt;/code&amp;gt;) &amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===&amp;lt;code&amp;gt; participants_helper.rb &amp;lt;/code&amp;gt; Methods===&lt;br /&gt;
Almost all of the methods in &amp;lt;code&amp;gt;participants_helper.rb&amp;lt;/code&amp;gt; are outdated and do not impact any functionality in &amp;lt;code&amp;gt;participants_controller.rb&amp;lt;/code&amp;gt;. &amp;lt;br/&amp;gt;&lt;br /&gt;
As a result, these methods will not be carried forward to the new implementation:&lt;br /&gt;
&amp;lt;li&amp;gt; &amp;lt;code&amp;gt; upload_users &amp;lt;/code&amp;gt; - Logic for creating a User specifically for the Assignment and Course classes. Since there is no direct relationship between the User and these classes, this logic is redundant and no longer necessary &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; &amp;lt;code&amp;gt; define_attributes &amp;lt;/code&amp;gt; - &amp;lt;i&amp;gt; Same reason as above &amp;lt;/i&amp;gt; &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; &amp;lt;code&amp;gt; define_user &amp;lt;/code&amp;gt; - &amp;lt;i&amp;gt; Same reason as above &amp;lt;/i&amp;gt; &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; &amp;lt;code&amp;gt; create_new_user &amp;lt;/code&amp;gt; - &amp;lt;i&amp;gt; Same reason as above &amp;lt;/i&amp;gt; &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; &amp;lt;code&amp;gt; add_user_to_assignment &amp;lt;/code&amp;gt; - &amp;lt;i&amp;gt; Same reason as above. &amp;lt;/i&amp;gt; Furthermore, since the Participant and Assignment classes are directly related, this functionality has been replaced by the &amp;lt;i&amp;gt; add_participant &amp;lt;/i&amp;gt; method in AssignmentsController (&amp;lt;code&amp;gt;assignments_controller.rb&amp;lt;/code&amp;gt;) &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; &amp;lt;code&amp;gt; add_user_to_course &amp;lt;/code&amp;gt; - &amp;lt;i&amp;gt; Same reason as above &amp;lt;/i&amp;gt; &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; &amp;lt;code&amp;gt; get_config &amp;lt;/code&amp;gt; - &amp;lt;i&amp;gt; Same reason as above &amp;lt;/i&amp;gt; &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; &amp;lt;code&amp;gt; store_item &amp;lt;/code&amp;gt; - &amp;lt;i&amp;gt; Same reason as above &amp;lt;/i&amp;gt; &amp;lt;/li&amp;gt;&lt;br /&gt;
The only method being kept is &amp;lt;code&amp;gt;participant_permissions&amp;lt;/code&amp;gt; as it is responsible for handling the assignment of permissions to a Participant.&lt;br /&gt;
&lt;br /&gt;
===Pattern(s)===&lt;br /&gt;
'''Facade''': &amp;quot;A simplified interface that performs many other actions behind the scenes.&amp;quot; &amp;lt;br/&amp;gt;&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
===SOLID Principle(s)===&lt;br /&gt;
'''Open and Closed Principle''': &amp;quot;Software entities should be open for extension, but closed for modification.&amp;quot;&amp;lt;br/&amp;gt;&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
'''Single Responsibility Principle''': &amp;quot;A class should only have one responsibility and should never have more than one reason to change.&amp;quot;&amp;lt;br/&amp;gt;&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
==Implementation==&lt;br /&gt;
===Implement &amp;lt;code&amp;gt; participants_controller.rb &amp;lt;/code&amp;gt; Methods===&lt;br /&gt;
Refer to the [https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2024_-_E2484._Reimplement_participants_controller.rb#participants_controller.rb_Methods_/_API_Calls &amp;lt;code&amp;gt; participants_controller.rb &amp;lt;/code&amp;gt; Methods / API Calls] section for a brief overview of its use &amp;lt;br/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|+&lt;br /&gt;
! Old Method Name !! Action !! New Method Name&lt;br /&gt;
|-&lt;br /&gt;
| action_allowed? || Removed || -&lt;br /&gt;
|-&lt;br /&gt;
| controller_locale || Removed || -&lt;br /&gt;
|-&lt;br /&gt;
| list || Renamed and Separated || user_index&lt;br /&gt;
|-&lt;br /&gt;
| - || - || assignment_index&lt;br /&gt;
|-&lt;br /&gt;
| add || No Change || add&lt;br /&gt;
|-&lt;br /&gt;
| update_authorizations || Renamed || update_authorization&lt;br /&gt;
|-&lt;br /&gt;
| destroy || No Change || destroy&lt;br /&gt;
|-&lt;br /&gt;
| inherit || Removed || -&lt;br /&gt;
|-&lt;br /&gt;
| bequeath_all || Removed || -&lt;br /&gt;
|-&lt;br /&gt;
| change_handle || Removed || -&lt;br /&gt;
|-&lt;br /&gt;
| delete || Removed || -&lt;br /&gt;
|-&lt;br /&gt;
| view_copyright_grants || Removed || -&lt;br /&gt;
|-&lt;br /&gt;
| participant_params || No Change || participant_params&lt;br /&gt;
|-&lt;br /&gt;
| get_user_info || Removed || -&lt;br /&gt;
|-&lt;br /&gt;
| get_signup_topics_for_assignment || Removed || -&lt;br /&gt;
|-&lt;br /&gt;
| - || Added || show&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;code&amp;gt;user_index&amp;lt;/code&amp;gt; Method====&lt;br /&gt;
Description:&lt;br /&gt;
&lt;br /&gt;
This method retrieves a list of participants associated with a specific user. If a valid user_id is provided in the request, the system searches for the corresponding user and returns the list of participants linked to that user. If no participants are found, or if the user is invalid, an appropriate error response is returned.&lt;br /&gt;
Parameters:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;user_id&amp;lt;/code&amp;gt;: The ID of the user whose participants you want to retrieve. If the user does not exist, the method returns without further action. &amp;lt;br/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Behavior:&lt;br /&gt;
&lt;br /&gt;
*The method validates the presence and existence of the &amp;lt;code&amp;gt;user_id&amp;lt;/code&amp;gt;.&lt;br /&gt;
**If the user_id is invalid, the method then stops execution and does not proceed with participant retrieval. &lt;br /&gt;
**If a valid user is provided, then it will retrieve all participants and filter in the ones of the provided user.&lt;br /&gt;
***The final filtered list of participants is returned as a JSON response.&lt;br /&gt;
***If the final list would be empty, then it will return with error 422&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;code&amp;gt;assignment_index&amp;lt;/code&amp;gt; Method====&lt;br /&gt;
Description:&lt;br /&gt;
&lt;br /&gt;
This method retrieves a list of participants associated with a specific assignment. If a valid assignment_id is provided in the request, the system searches for the corresponding assignment and returns the list of participants linked to that assignment. If no participants are found, or if the assignment is invalid, an appropriate error response is returned.&lt;br /&gt;
Parameters:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;assignment_id&amp;lt;/code&amp;gt;: The ID of the assignment whose participants you want to retrieve. If the assignment does not exist, the method returns without further action. &amp;lt;br/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Behavior:&lt;br /&gt;
&lt;br /&gt;
*The method validates the presence and existence of the &amp;lt;code&amp;gt;assignment_id&amp;lt;/code&amp;gt;.&lt;br /&gt;
**If the assignment_id is invalid, the method then stops execution and does not proceed with participant retrieval. &lt;br /&gt;
**If a valid assignment is provided, then it will retrieve all participants and filter in the ones of the provided assignment.&lt;br /&gt;
***The final filtered list of participants is returned as a JSON response.&lt;br /&gt;
***If the final list would be empty, then it will return with error 422&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;code&amp;gt;add&amp;lt;/code&amp;gt; Method====&lt;br /&gt;
&lt;br /&gt;
Description:&lt;br /&gt;
&lt;br /&gt;
Assigns the specified authorization to a participant and adds them to a given assignment. It performs the necessary validations to ensure that the user, assignment, and authorization are valid before proceeding. If all validations pass, it associates the participant with the assignment and applies the relevant permissions based on the authorization.&lt;br /&gt;
&lt;br /&gt;
Parameters:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;user_id&amp;lt;/code&amp;gt; (required): The ID of the user to be added as a participant.&lt;br /&gt;
&amp;lt;code&amp;gt;assignment_id&amp;lt;/code&amp;gt; (required): The ID of the assignment the user will be added to.&lt;br /&gt;
&amp;lt;code&amp;gt;authorization&amp;lt;/code&amp;gt; (required): The authorization ID to define the user's permissions within the assignment.&lt;br /&gt;
&lt;br /&gt;
Behavior:&lt;br /&gt;
&lt;br /&gt;
*Validates and retrieves the user based on the provided &amp;lt;code&amp;gt;user_id&amp;lt;/code&amp;gt;. If the user is not found, the method terminates.&lt;br /&gt;
*Validates and retrieves the assignment based on the provided &amp;lt;code&amp;gt;assignment_id&amp;lt;/code&amp;gt;. If the assignment is not found, the method terminates.&lt;br /&gt;
*Validates and retrieves the authorization based on the provided &amp;lt;code&amp;gt;assignment_id&amp;lt;/code&amp;gt;. If the authorization is not found, the method terminates.&lt;br /&gt;
*Builds a new Participant instance linked to the validated user and assignment, with the appropriate permissions obtained from authorization.&lt;br /&gt;
*Attempts to save the Participant:&lt;br /&gt;
**If successful: Returns a JSON response containing the created Participant and a 201 Created status.&lt;br /&gt;
**If unsuccessful: Returns a JSON response containing validation errors and a 422 Unprocessable Entity status.&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;code&amp;gt;update_authorization&amp;lt;/code&amp;gt; Method ====&lt;br /&gt;
Description:&lt;br /&gt;
&lt;br /&gt;
Updates the authorization and associated permissions for an existing participant.&lt;br /&gt;
&lt;br /&gt;
Parameters:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;participant_id&amp;lt;/code&amp;gt; (required): The ID of the participant whose authorization is being updated.&lt;br /&gt;
&amp;lt;code&amp;gt;authorization&amp;lt;/code&amp;gt; (required): The new authorization ID to assign to the participant.&lt;br /&gt;
&lt;br /&gt;
Behavior:&lt;br /&gt;
*Validates the provided authorization using validate_authorization after finding the participant. If the authorization is missing, the method halts and returns 422.&lt;br /&gt;
*Upon successful validation of the authorization, the method retrieves the permissions associated with the authorization by calling retrieve_participant_permissions.&lt;br /&gt;
*Updates the participant's authorization field with the new authorization. Relevant permissions (can_submit, can_review, can_take_quiz, and can_mentor) are also updated based on the authorization’s values.&lt;br /&gt;
*Attempts to save the updated participant&lt;br /&gt;
**If the participant is successfully updated and saved to the database, a JSON response with the updated participant details and a 201 Created status is returned.&lt;br /&gt;
**If there are validation errors or the update fails, a JSON response with error details and a 422 Unprocessable Entity status is returned.&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;code&amp;gt;destroy&amp;lt;/code&amp;gt; Method====&lt;br /&gt;
&lt;br /&gt;
Description:&lt;br /&gt;
&lt;br /&gt;
Deletes a specified Participant based on the provided ID.&lt;br /&gt;
&lt;br /&gt;
Parameters:&lt;br /&gt;
&lt;br /&gt;
*&amp;lt;code&amp;gt;id&amp;lt;/code&amp;gt; (required): The ID of the Participant to be deleted.&lt;br /&gt;
&lt;br /&gt;
Behavior:&lt;br /&gt;
&lt;br /&gt;
*Retrieves the Participant using the provided &amp;lt;code&amp;gt;id&amp;lt;/code&amp;gt;.&lt;br /&gt;
*Attempts to delete the Participant:&lt;br /&gt;
**If successful: Returns a JSON response containing a confirmation message and a 200 OK status.&lt;br /&gt;
**If unsuccessful: Returns a JSON response containing validation errors and a 422 Unprocessable Entity status.&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;code&amp;gt;show&amp;lt;/code&amp;gt; Method====&lt;br /&gt;
&lt;br /&gt;
Description:&lt;br /&gt;
&lt;br /&gt;
Retrieves and returns a specific Participant based on the provided ID.&lt;br /&gt;
&lt;br /&gt;
Parameters:&lt;br /&gt;
&lt;br /&gt;
*&amp;lt;code&amp;gt;id&amp;lt;/code&amp;gt; (required): The ID of the Participant to be retrieved.&lt;br /&gt;
&lt;br /&gt;
Behavior:&lt;br /&gt;
&lt;br /&gt;
*Fetches the Participant from the database using the provided &amp;lt;code&amp;gt;id&amp;lt;/code&amp;gt;.&lt;br /&gt;
*Attempts to fetch the Participant:&lt;br /&gt;
**If successful: Returns a JSON response containing a confirmation message and a 200 OK status.&lt;br /&gt;
**If unsuccessful: Returns a JSON response containing validation errors and a 422 Unprocessable Entity status.&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;code&amp;gt;participant_params&amp;lt;/code&amp;gt; Method====&lt;br /&gt;
&lt;br /&gt;
Description:&lt;br /&gt;
&lt;br /&gt;
Defines the permitted parameters for creating or updating a Participant object.&lt;br /&gt;
&lt;br /&gt;
Parameters:&lt;br /&gt;
&lt;br /&gt;
The method expects a Participant object within the request parameters. It permits the following attributes:&lt;br /&gt;
&lt;br /&gt;
*&amp;lt;code&amp;gt;user_id&amp;lt;/code&amp;gt; (required): The ID of the user associated with the Participant.&lt;br /&gt;
*&amp;lt;code&amp;gt;assignment_id&amp;lt;/code&amp;gt; (required): The ID of the assignment linked to the Participant.&lt;br /&gt;
*&amp;lt;code&amp;gt;team_id&amp;lt;/code&amp;gt; (optional): The ID of the team the Participant belongs to.&lt;br /&gt;
*&amp;lt;code&amp;gt;can_submit&amp;lt;/code&amp;gt;: A boolean indicating whether the Participant has submit permissions granted.&lt;br /&gt;
*&amp;lt;code&amp;gt;can_review&amp;lt;/code&amp;gt;: A boolean indicating whether the Participant has review permissions granted.&lt;br /&gt;
*&amp;lt;code&amp;gt;can_take_quiz&amp;lt;/code&amp;gt;: A boolean indicating whether the Participant has take_quiz permissions granted.&lt;br /&gt;
*&amp;lt;code&amp;gt;can_mentor&amp;lt;/code&amp;gt;: A boolean indicating whether the Participant has mentor permissions granted.&lt;br /&gt;
*&amp;lt;code&amp;gt;join_team_request_id&amp;lt;/code&amp;gt; (optional): The ID of any pending team join request related to the Participant.&lt;br /&gt;
*&amp;lt;code&amp;gt;permission_granted&amp;lt;/code&amp;gt; (optional): A boolean indicating whether the Participant has specific permissions granted.&lt;br /&gt;
*&amp;lt;code&amp;gt;topic&amp;lt;/code&amp;gt; (optional): The topic assigned to the Participant (could be a string or other data type depending on the application context).&lt;br /&gt;
*&amp;lt;code&amp;gt;current_stage&amp;lt;/code&amp;gt; (optional): The current progress stage of the Participant.&lt;br /&gt;
*&amp;lt;code&amp;gt;stage_deadline&amp;lt;/code&amp;gt; (optional): The deadline for the current stage.&lt;br /&gt;
&lt;br /&gt;
Behavior:&lt;br /&gt;
&lt;br /&gt;
*Ensures that only allowed parameters are passed when creating a Participant object.&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;code&amp;gt;filter_user_participants&amp;lt;/code&amp;gt; Method ====&lt;br /&gt;
Description:&lt;br /&gt;
&lt;br /&gt;
Retrieves and filters participants based on the provided user.&lt;br /&gt;
&lt;br /&gt;
Parameters:&lt;br /&gt;
&lt;br /&gt;
*&amp;lt;code&amp;gt;user&amp;lt;/code&amp;gt; (required): An instance of the User model. If provided, the method filters participants associated with this user.&lt;br /&gt;
&lt;br /&gt;
Behavior:&lt;br /&gt;
&lt;br /&gt;
*Fetches all participants from the database.&lt;br /&gt;
*The method filters participants where the user_id matches the given user's ID.&lt;br /&gt;
*The final list of participants is then ordered by their id in ascending order.&lt;br /&gt;
====&amp;lt;code&amp;gt;filter_assignment_participants&amp;lt;/code&amp;gt; Method ====&lt;br /&gt;
Description:&lt;br /&gt;
&lt;br /&gt;
Retrieves and filters participants based on the provided assignment.&lt;br /&gt;
&lt;br /&gt;
Parameters:&lt;br /&gt;
&lt;br /&gt;
*&amp;lt;code&amp;gt;assignment&amp;lt;/code&amp;gt; (required): An instance of the assignment model. If provided, the method filters participants associated with this assignment.&lt;br /&gt;
&lt;br /&gt;
Behavior:&lt;br /&gt;
&lt;br /&gt;
*Fetches all participants from the database.&lt;br /&gt;
*The method filters participants where the assignment_id matches the given assignment's ID.&lt;br /&gt;
*The final list of participants is then ordered by their id in ascending order.&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;code&amp;gt;find_user&amp;lt;/code&amp;gt; Method ====&lt;br /&gt;
&lt;br /&gt;
Description:&lt;br /&gt;
Retrieves a User object based on the user_id provided. If the user is not found, it returns an error response and halts further execution.&lt;br /&gt;
&lt;br /&gt;
Parameters:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;user_id&amp;lt;/code&amp;gt; (optional): The ID of the user to be retrieved. Extracted from the permitted parameters.&lt;br /&gt;
&lt;br /&gt;
Behavior:&lt;br /&gt;
&lt;br /&gt;
*Attempts to find the user in the database using the provided user_id.&lt;br /&gt;
**If the user is not found (nil), it renders a JSON response with an error message and 404 Not found status&lt;br /&gt;
**If the user exists, it returns the user object with 200 ok status.&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;code&amp;gt;find_assignment&amp;lt;/code&amp;gt; Method ====&lt;br /&gt;
&lt;br /&gt;
Description:&lt;br /&gt;
&lt;br /&gt;
Retrieves an Assignment object based on the assignment_id provided. If the Assignment is not found, it returns an error response and halts further execution.&lt;br /&gt;
&lt;br /&gt;
Parameters:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;assignment_id&amp;lt;/code&amp;gt; (optional): The ID of the assignment to be retrieved. Extracted from the permitted parameters.&lt;br /&gt;
&lt;br /&gt;
Behavior:&lt;br /&gt;
&lt;br /&gt;
*Attempts to find the assignment in the database using the provided assignment_id.&lt;br /&gt;
**If the assignment is not found (nil), it renders a JSON response with an error message and 404 Not found status&lt;br /&gt;
**If the assignment exists, it returns the assignment object with 200 ok status.&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;code&amp;gt;find_participant&amp;lt;/code&amp;gt; Method ====&lt;br /&gt;
&lt;br /&gt;
Description:&lt;br /&gt;
&lt;br /&gt;
Retrieves an participant object based on the participant_id provided. If the participant is not found, it returns an error response and halts further execution.&lt;br /&gt;
&lt;br /&gt;
Parameters:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;participant_id&amp;lt;/code&amp;gt; (optional): The ID of the participant to be retrieved. Extracted from the permitted parameters.&lt;br /&gt;
&lt;br /&gt;
Behavior:&lt;br /&gt;
&lt;br /&gt;
*Attempts to find the participant in the database using the provided participant_id.&lt;br /&gt;
**If the participant is not found (nil), it renders a JSON response with an error message and 404 Not found status&lt;br /&gt;
**If the participant exists, it returns the participant object with 200 ok status.&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;code&amp;gt;validate_authorization&amp;lt;/code&amp;gt; Method ====&lt;br /&gt;
Description:&lt;br /&gt;
*Validates the authorization parameter provided in the request. Ensures that the authorization value is one of the accepted roles: reader, reviewer, submitter, or mentor.&lt;br /&gt;
&lt;br /&gt;
Parameters:&lt;br /&gt;
*&amp;lt;code&amp;gt;authorization&amp;lt;/code&amp;gt; (required): A string representing the participant’s authorization role. This value must be one of the following: reader, reviewer, submitter, or mentor.&lt;br /&gt;
&lt;br /&gt;
Behavior:&lt;br /&gt;
*If the authorization parameter is present, it is converted to lowercase to ensure case-insensitive comparison.&lt;br /&gt;
*If the authorization parameter is not provided, the method renders a 422 Unprocessable Entity response with an error message indicating that a participant must have an authorization.&lt;br /&gt;
*If the authorization value is provided but does not match one of the valid roles (reader, reviewer, submitter, or mentor), the method renders a 422 Unprocessable Entity response with an error message listing the valid options.&lt;br /&gt;
*If the authorization value is valid, the method returns the authorization string.&lt;br /&gt;
&lt;br /&gt;
===Import from &amp;lt;code&amp;gt; participants_helper.rb &amp;lt;/code&amp;gt;===&lt;br /&gt;
Refer to the [https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2024_-_E2484._Reimplement_participants_controller.rb#participants_helper.rb_Methods &amp;lt;code&amp;gt; participants_helper.rb &amp;lt;/code&amp;gt; Methods] section for all design-related inquiries &amp;lt;br/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|+&lt;br /&gt;
! Old Method Name !! Action !! New Method Name&lt;br /&gt;
|-&lt;br /&gt;
| upload_users || Removed || -&lt;br /&gt;
|-&lt;br /&gt;
| define_attributes || Removed || -&lt;br /&gt;
|-&lt;br /&gt;
| define_user || Removed || -&lt;br /&gt;
|-&lt;br /&gt;
| create_new_user || Removed || -&lt;br /&gt;
|-&lt;br /&gt;
| add_user_to_assignment || Removed || -&lt;br /&gt;
|-&lt;br /&gt;
| add_user_to_course || Removed || -&lt;br /&gt;
|-&lt;br /&gt;
| get_config || Removed || -&lt;br /&gt;
|-&lt;br /&gt;
| store_item || Removed || -&lt;br /&gt;
|-&lt;br /&gt;
| participant_permissions || Renamed || retrieve_participant_permissions&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;code&amp;gt;retrieve_participant_permissions&amp;lt;/code&amp;gt; Method====&lt;br /&gt;
&lt;br /&gt;
Description:&lt;br /&gt;
*Retrieves the permissions associated with a given authorization role. The permissions determine the actions a participant can perform (e.g., submitting, reviewing, taking quizzes, or mentoring). The method merges default permissions with role-specific overrides and returns the final set of permissions for the specified authorization.&lt;br /&gt;
&lt;br /&gt;
Parameters:&lt;br /&gt;
&lt;br /&gt;
*&amp;lt;code&amp;gt;authorization&amp;lt;/code&amp;gt; (required): A string representing the participant's authorization role. This value should be one of the following: reader, reviewer, submitter, or mentor.&lt;br /&gt;
Behavior:&lt;br /&gt;
*The method defines a set of default permissions that are assigned to all participants unless overridden by their specific authorization role. The default permissions allow submitting, reviewing, and taking quizzes, while disallowing mentoring.&lt;br /&gt;
*A permissions_map is used to define role-specific overrides for the default permissions:&lt;br /&gt;
**reader: Cannot submit, but can review and take quizzes.&lt;br /&gt;
**reviewer: Cannot submit or take quizzes, but can review.&lt;br /&gt;
**submitter: Cannot review or take quizzes, but can submit.&lt;br /&gt;
**mentor: Can mentor, and has the same permissions as a reader for other actions.&lt;br /&gt;
*The method merges the default permissions with the overrides for the specified authorization. The final set of permissions is returned.&lt;br /&gt;
&lt;br /&gt;
===API Creation===&lt;br /&gt;
Refer to the [https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2024_-_E2484._Reimplement_participants_controller.rb#participants_controller.rb_Methods_/_API_Calls &amp;lt;code&amp;gt; participants_controller.rb &amp;lt;/code&amp;gt; Methods / API Calls] section for all design-related inquiries &amp;lt;br/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Testing with rswag===&lt;br /&gt;
Refer to the [https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2024_-_E2484._Reimplement_participants_controller.rb#Testing_Plan Testing Plan] section &amp;lt;br/&amp;gt;&lt;br /&gt;
&amp;lt;i&amp;gt; To be expanded upon during implementation &amp;lt;/i&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Swagger UI Video Documentation===&lt;br /&gt;
[https://www.youtube.com/watch?v=rhP57UexqRs] Swagger UI Testing for the participants_controller.rb &amp;lt;br/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Testing Plan==&lt;br /&gt;
'''rswag'''&amp;lt;br/&amp;gt;&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
====Tests====&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;margin-left:40px&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Test ID !! Test Description &lt;br /&gt;
|-&lt;br /&gt;
| 1 || Test 'assignment_index' with valid assignment ID - Should list participants&lt;br /&gt;
|-&lt;br /&gt;
| 2 || Test 'assignment_index' with invalid assignment ID - Should return an 'Assignment not found' error&lt;br /&gt;
|-&lt;br /&gt;
| 3 || Test unauthorized bearer token access to 'assignment_index' endpoint - Should return a 'Not Authorized' message&lt;br /&gt;
|-&lt;br /&gt;
| 4 || Test 'user_index' with valid user ID - Should list participants&lt;br /&gt;
|-&lt;br /&gt;
| 5 || Test 'user_index' with valid user ID but no participants - Should return an empty list&lt;br /&gt;
|-&lt;br /&gt;
| 6 || Test 'user_index' with invalid user ID - Should return a 'User not found' error&lt;br /&gt;
|-&lt;br /&gt;
| 7 || Test unauthorized bearer token access to 'user_index' endpoint - Should return a 'Not Authorized' message&lt;br /&gt;
|-&lt;br /&gt;
| 8 || Test 'show' with valid participant ID - Should return the specified participant details&lt;br /&gt;
|-&lt;br /&gt;
| 9 || Test 'show' with invalid participant ID - Should return participant not found&lt;br /&gt;
|-&lt;br /&gt;
| 10 || Test unauthorized bearer token access to 'show' endpoint - Should return a 'Not Authorized' message&lt;br /&gt;
|-&lt;br /&gt;
| 11 || Test 'add' with valid user, assignment details, and authorization - Should successfully create a new participant&lt;br /&gt;
|-&lt;br /&gt;
| 12 || Test 'add' with duplicate user and assignment details - Should return an error indicating participant already exists&lt;br /&gt;
|-&lt;br /&gt;
| 13 || Test 'add' with invalid user ID - Should return a 'User not found' error&lt;br /&gt;
|-&lt;br /&gt;
| 14 || Test 'add' with invalid assignment ID - Should return an 'Assignment not found' error&lt;br /&gt;
|-&lt;br /&gt;
| 15 || Test 'add' with invalid authorization - Should return an error specifying valid authorizations (Reader, Reviewer, etc.)&lt;br /&gt;
|-&lt;br /&gt;
| 16 || Test unauthorized bearer token access to 'add' endpoint - Should return a 'Not Authorized' message&lt;br /&gt;
|-&lt;br /&gt;
| 17 || Test 'destroy' with valid participant ID - Should delete the specified participant&lt;br /&gt;
|-&lt;br /&gt;
| 18 || Test 'destroy' with invalid participant ID - Should return participant not found message&lt;br /&gt;
|-&lt;br /&gt;
| 19 || Test unauthorized bearer token access to 'destroy' endpoint - Should return a 'Not Authorized' message&lt;br /&gt;
|-&lt;br /&gt;
| 20 || Test 'update_authorization' participant authorization with valid participant ID and authorization - Should update the authorization level successfully&lt;br /&gt;
|-&lt;br /&gt;
| 21 || Test 'update_authorization' participant authorization with invalid participant ID - Should return a 'Participant not found' message&lt;br /&gt;
|-&lt;br /&gt;
| 22 || Test 'update_authorization' participant authorization with invalid participant ID and invalid authorization - Should return a 'Participant not found' message&lt;br /&gt;
|-&lt;br /&gt;
| 23 || Test 'update_authorization' participant authorization with invalid authorization - Should return a validation error for authorization  &lt;br /&gt;
|-&lt;br /&gt;
| 24 || Test unauthorized bearer token access to 'update_authorization' endpoint - Should return a 'Not Authorized' message&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==Next Steps==&lt;br /&gt;
Our goal throughout this implementation was to reduce the bloat and refactor the controller to something significantly cleaner. Originally, we had a design that we believed to be fairly clean, cutting out nearly 80% of the functions and almost half of the database columns. However, we were made aware that the new, significantly cut down implementation would not work within the current system, and we feel that we ended up re adding a lot of the bloat that we had just cut out. Roles are connected to the participant, but these participant roles are different than User roles. Permissions are handled by the participant, which while not bad, we believe it could be improved. The links between assignment and course is hardly fleshed out at all, and participant handles a lot of logic that could be better distributed. We were also made aware of an AssignmentParticipant and a CourseParticipant, which we believe to be unnecessarily specific. &lt;br /&gt;
&lt;br /&gt;
===Proposal===&lt;br /&gt;
We propose that the entire hierarchy and structure of the Course, Assignment, and Participant be re-designed from the ground up alongside each other to delegate tasks in a much more reasonable way. One way to do so would be a system that could look something like the following diagram.&lt;br /&gt;
&lt;br /&gt;
Diagram:&lt;br /&gt;
[[File:NewStructureProposal.png]]&lt;br /&gt;
&lt;br /&gt;
The primary change here would be a slight decoupling of participant from assignment and a unification of the AssignmentParticipant and CourseParticipant classes. We cant really see a logical reason for distinction between the two, and this would significantly reduce the amount of code bloat in the system. Instead, Participants will be the avatar through which a User interacts with the Course hierarchy. User would just be an account that accesses a participant for each class they are in.&lt;br /&gt;
&lt;br /&gt;
There would no longer be a need to create a participant object for every single user in every single assignment in a course, significantly reducing the bloat that creating an assignment for an entire class could cause under the current system.&lt;br /&gt;
&lt;br /&gt;
Roles would be assigned to participants, and then assignments would handle the logic behind permissions. This provides the advantage that different assignments can control how different roles can interact with themselves independently of each other. If they could already do that, then this resolves a DRY violation where permission information is logically acted upon in both Participant and Assignment.&lt;br /&gt;
&lt;br /&gt;
Incidentally, if you were to delegate some of User's roles to participant's roles, such as instructor, then instructors could then also become participants in classes without needing to create another account with student level permissions. If you were to adopt this structure even further out to include universities, Users that are admins of one university can be students of another all under one User account.&lt;br /&gt;
&lt;br /&gt;
However, this is likely to have cascading effects on other critical systems as well. Teams may need to be entirely re organized since there are no longer unique participants per user for each assignment, as well as many other implications that we may not have been able to anticipate.&lt;br /&gt;
&lt;br /&gt;
This is not the solution that has to be used, however, we believe that it would be an improvement on the current system.&lt;br /&gt;
&lt;br /&gt;
==Team==&lt;br /&gt;
'''Mentor''' &lt;br /&gt;
&lt;br /&gt;
*Jay Patel &amp;lt;jhpatel9@ncsu.edu&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Students'''&lt;br /&gt;
&lt;br /&gt;
*Pierce Whelan &amp;lt;pwwhelan@ncsu.edu&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*Calvin Jiang &amp;lt;crjiang@ncsu.edu&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*Hechun Zhang &amp;lt;hzhang56@ncsu.edu&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Relevant Links ==&lt;br /&gt;
Pull Request [https://github.com/expertiza/reimplementation-back-end/pull/135] &amp;lt;br/&amp;gt;&lt;br /&gt;
GitHub Repository [https://github.com/Pierce57/participant_controller_reimplementation.git] &amp;lt;br/&amp;gt;&lt;br /&gt;
GitHub Project Board [https://github.com/users/Pierce57/projects/3] &amp;lt;br/&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt; participants_controller.rb &amp;lt;/code&amp;gt; in Old Expertiza [https://github.com/expertiza/expertiza/blob/main/app/controllers/participants_controller.rb] &amp;lt;br/&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt; participants_helper.rb &amp;lt;/code&amp;gt; in Old Expertiza [https://github.com/expertiza/expertiza/blob/main/app/helpers/participants_helper.rb]&lt;/div&gt;</summary>
		<author><name>Hzhang56</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2024_-_E2484._Reimplement_participants_controller.rb&amp;diff=160169</id>
		<title>CSC/ECE 517 Fall 2024 - E2484. Reimplement participants controller.rb</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2024_-_E2484._Reimplement_participants_controller.rb&amp;diff=160169"/>
		<updated>2024-12-03T18:25:16Z</updated>

		<summary type="html">&lt;p&gt;Hzhang56: /* Tests */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==About Expertiza==&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is an open source project based on [http://rubyonrails.org/ 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.&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
This project aims to reimplement the &amp;lt;code&amp;gt; participants_controller.rb &amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt; participants_helper.rb &amp;lt;/code&amp;gt; in the new Expertiza system. The &amp;lt;code&amp;gt; participants_controller.rb &amp;lt;/code&amp;gt; manages participants within assignments, and this reimplementation focuses on streamlining its methods, eliminating redundancy, and enhancing code readability and maintainability.&lt;br /&gt;
&lt;br /&gt;
==Requirements==&lt;br /&gt;
&amp;lt;li&amp;gt; Implement &amp;lt;code&amp;gt; participants_controller.rb &amp;lt;/code&amp;gt; Methods: Fully implement each controller method with the same functionality as the current controller. &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Import from &amp;lt;code&amp;gt; participants_helper.rb &amp;lt;/code&amp;gt;: Integrate relevant helper methods to streamline functionality and remove redundancy. &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; API Creation: Expose API endpoints for all necessary methods to enable seamless access and integration from the frontend. Ensure that each endpoint follows best practices for RESTful API design, including proper error handling and secure data access. &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Testing with rswag: Create test cases for all methods, focusing on edge cases, and generate rswag documentation. &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Swagger UI Video Documentation: Record a video walkthrough of API endpoints in Swagger UI, showcasing each method’s functionality. &amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Existing Issues==&lt;br /&gt;
Reimplement &amp;lt;code&amp;gt; [https://github.com/expertiza/expertiza/blob/main/app/controllers/participants_controller.rb participants_controller.rb] &amp;lt;/code&amp;gt; while addressing the following:&lt;br /&gt;
&amp;lt;li&amp;gt; Refactor code to comply with the Open-Closed Principle and the Single Responsibility Principle. &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Introduce dependency injection where necessary. &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Reduce excessive conditional statements. &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Include sufficient code tests to verify functionality. &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Enhance comments to better explain each method's functionality, purpose, and rationale for keeping or modifying particular aspects of the code. &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Provide a more detailed explanation of design choices and refactoring steps. &amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Design / Proposed Solution ==&lt;br /&gt;
===Controller Diagram===&lt;br /&gt;
[[File:Participants Controller UML Diagram.png]]&lt;br /&gt;
&lt;br /&gt;
===&amp;lt;code&amp;gt; participants_controller.rb &amp;lt;/code&amp;gt; Methods / API Calls===&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;width: 100%;&lt;br /&gt;
! &amp;amp;nbsp;#&amp;amp;nbsp; !! Method !! Endpoint !! Description &lt;br /&gt;
|-&lt;br /&gt;
|1&lt;br /&gt;
|user_index&lt;br /&gt;
|GET &amp;lt;code&amp;gt; /participants/user/:user_id &amp;lt;/code&amp;gt;&lt;br /&gt;
|Return a list of participants for a given user&lt;br /&gt;
|-&lt;br /&gt;
|2&lt;br /&gt;
|assignment_index&lt;br /&gt;
|GET &amp;lt;code&amp;gt; /participants/assignment/:assignment_id &amp;lt;/code&amp;gt;&lt;br /&gt;
|Return a list of participants for a given assignment&lt;br /&gt;
|-&lt;br /&gt;
|3&lt;br /&gt;
|show&lt;br /&gt;
|GET &amp;lt;code&amp;gt; /participants/:id &amp;lt;/code&amp;gt;&lt;br /&gt;
|Return a specified participant&lt;br /&gt;
|-&lt;br /&gt;
|4&lt;br /&gt;
|add&lt;br /&gt;
|POST &amp;lt;code&amp;gt; /participants/:authorization &amp;lt;/code&amp;gt;&lt;br /&gt;
|Assign the specified authorization to the participant and add them to an assignment&lt;br /&gt;
|-&lt;br /&gt;
|5&lt;br /&gt;
|update_authorization&lt;br /&gt;
|PATCH &amp;lt;code&amp;gt; /participants/:id/:authorization &amp;lt;/code&amp;gt;&lt;br /&gt;
|Update the specified participant to the specified authorization&lt;br /&gt;
|-&lt;br /&gt;
|6&lt;br /&gt;
|destroy&lt;br /&gt;
|DELETE &amp;lt;code&amp;gt; /participants/:id &amp;lt;/code&amp;gt;&lt;br /&gt;
|Delete a participant&lt;br /&gt;
|-&lt;br /&gt;
|7&lt;br /&gt;
|participant_params&lt;br /&gt;
| -&lt;br /&gt;
|Permitted parameters for creating a Participant object&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
The following methods were removed from &amp;lt;code&amp;gt; participants_controller.rb &amp;lt;/code&amp;gt;:&lt;br /&gt;
&amp;lt;li&amp;gt; &amp;lt;code&amp;gt; action_allowed? &amp;lt;/code&amp;gt; - No impact on functionality &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; &amp;lt;code&amp;gt; controller_locale &amp;lt;/code&amp;gt; - No impact on functionality &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; &amp;lt;code&amp;gt; inherit &amp;lt;/code&amp;gt; - Since there is no direct relationship between the Participant and Course classes, this logic is redundant and no longer necessary &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; &amp;lt;code&amp;gt; bequeath_all &amp;lt;/code&amp;gt; - Since there is no direct relationship between the Participant and Course classes, this logic is redundant and no longer necessary &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; &amp;lt;code&amp;gt; change_handle &amp;lt;/code&amp;gt; - The User class has a `handle` field already. It would be redundant to have one in Participant as well.&lt;br /&gt;
&amp;lt;li&amp;gt; &amp;lt;code&amp;gt; delete &amp;lt;/code&amp;gt; - Handled in the &amp;lt;i&amp;gt; remove_participant &amp;lt;/i&amp;gt; method of the AssignmentsController (&amp;lt;code&amp;gt; assignments_controller.rb &amp;lt;/code&amp;gt;) &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; &amp;lt;code&amp;gt; view_copyright_grants &amp;lt;/code&amp;gt; - Incorrectly implemented in the old implementation &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; &amp;lt;code&amp;gt; get_user_info &amp;lt;/code&amp;gt; - All needed user data can be accessed by leveraging the Participant model's &amp;lt;i&amp;gt; belongs_to &amp;lt;/i&amp;gt; relationship to the User model &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; &amp;lt;code&amp;gt; get_signup_topics_for_assignment &amp;lt;/code&amp;gt; - Handled in the &amp;lt;i&amp;gt; index &amp;lt;/i&amp;gt; method of the SignUpTopicsController (&amp;lt;code&amp;gt; sign_up_topics_controller.rb &amp;lt;/code&amp;gt;) &amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===&amp;lt;code&amp;gt; participants_helper.rb &amp;lt;/code&amp;gt; Methods===&lt;br /&gt;
Almost all of the methods in &amp;lt;code&amp;gt;participants_helper.rb&amp;lt;/code&amp;gt; are outdated and do not impact any functionality in &amp;lt;code&amp;gt;participants_controller.rb&amp;lt;/code&amp;gt;. &amp;lt;br/&amp;gt;&lt;br /&gt;
As a result, these methods will not be carried forward to the new implementation:&lt;br /&gt;
&amp;lt;li&amp;gt; &amp;lt;code&amp;gt; upload_users &amp;lt;/code&amp;gt; - Logic for creating a User specifically for the Assignment and Course classes. Since there is no direct relationship between the User and these classes, this logic is redundant and no longer necessary &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; &amp;lt;code&amp;gt; define_attributes &amp;lt;/code&amp;gt; - &amp;lt;i&amp;gt; Same reason as above &amp;lt;/i&amp;gt; &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; &amp;lt;code&amp;gt; define_user &amp;lt;/code&amp;gt; - &amp;lt;i&amp;gt; Same reason as above &amp;lt;/i&amp;gt; &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; &amp;lt;code&amp;gt; create_new_user &amp;lt;/code&amp;gt; - &amp;lt;i&amp;gt; Same reason as above &amp;lt;/i&amp;gt; &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; &amp;lt;code&amp;gt; add_user_to_assignment &amp;lt;/code&amp;gt; - &amp;lt;i&amp;gt; Same reason as above. &amp;lt;/i&amp;gt; Furthermore, since the Participant and Assignment classes are directly related, this functionality has been replaced by the &amp;lt;i&amp;gt; add_participant &amp;lt;/i&amp;gt; method in AssignmentsController (&amp;lt;code&amp;gt;assignments_controller.rb&amp;lt;/code&amp;gt;) &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; &amp;lt;code&amp;gt; add_user_to_course &amp;lt;/code&amp;gt; - &amp;lt;i&amp;gt; Same reason as above &amp;lt;/i&amp;gt; &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; &amp;lt;code&amp;gt; get_config &amp;lt;/code&amp;gt; - &amp;lt;i&amp;gt; Same reason as above &amp;lt;/i&amp;gt; &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; &amp;lt;code&amp;gt; store_item &amp;lt;/code&amp;gt; - &amp;lt;i&amp;gt; Same reason as above &amp;lt;/i&amp;gt; &amp;lt;/li&amp;gt;&lt;br /&gt;
The only method being kept is &amp;lt;code&amp;gt;participant_permissions&amp;lt;/code&amp;gt; as it is responsible for handling the assignment of permissions to a Participant.&lt;br /&gt;
&lt;br /&gt;
===Pattern(s)===&lt;br /&gt;
'''Facade''': &amp;quot;A simplified interface that performs many other actions behind the scenes.&amp;quot; &amp;lt;br/&amp;gt;&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
===SOLID Principle(s)===&lt;br /&gt;
'''Open and Closed Principle''': &amp;quot;Software entities should be open for extension, but closed for modification.&amp;quot;&amp;lt;br/&amp;gt;&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
'''Single Responsibility Principle''': &amp;quot;A class should only have one responsibility and should never have more than one reason to change.&amp;quot;&amp;lt;br/&amp;gt;&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
==Implementation==&lt;br /&gt;
===Implement &amp;lt;code&amp;gt; participants_controller.rb &amp;lt;/code&amp;gt; Methods===&lt;br /&gt;
Refer to the [https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2024_-_E2484._Reimplement_participants_controller.rb#participants_controller.rb_Methods_/_API_Calls &amp;lt;code&amp;gt; participants_controller.rb &amp;lt;/code&amp;gt; Methods / API Calls] section for a brief overview of its use &amp;lt;br/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|+&lt;br /&gt;
! Old Method Name !! Action !! New Method Name&lt;br /&gt;
|-&lt;br /&gt;
| action_allowed? || Removed || -&lt;br /&gt;
|-&lt;br /&gt;
| controller_locale || Removed || -&lt;br /&gt;
|-&lt;br /&gt;
| list || Renamed and Separated || user_index&lt;br /&gt;
|-&lt;br /&gt;
| - || - || assignment_index&lt;br /&gt;
|-&lt;br /&gt;
| add || No Change || add&lt;br /&gt;
|-&lt;br /&gt;
| update_authorizations || Renamed || update_authorization&lt;br /&gt;
|-&lt;br /&gt;
| destroy || No Change || destroy&lt;br /&gt;
|-&lt;br /&gt;
| inherit || Removed || -&lt;br /&gt;
|-&lt;br /&gt;
| bequeath_all || Removed || -&lt;br /&gt;
|-&lt;br /&gt;
| change_handle || Removed || -&lt;br /&gt;
|-&lt;br /&gt;
| delete || Removed || -&lt;br /&gt;
|-&lt;br /&gt;
| view_copyright_grants || Removed || -&lt;br /&gt;
|-&lt;br /&gt;
| participant_params || No Change || participant_params&lt;br /&gt;
|-&lt;br /&gt;
| get_user_info || Removed || -&lt;br /&gt;
|-&lt;br /&gt;
| get_signup_topics_for_assignment || Removed || -&lt;br /&gt;
|-&lt;br /&gt;
| - || Added || show&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;code&amp;gt;user_index&amp;lt;/code&amp;gt; Method====&lt;br /&gt;
Description:&lt;br /&gt;
&lt;br /&gt;
This method retrieves a list of participants associated with a specific user. If a valid user_id is provided in the request, the system searches for the corresponding user and returns the list of participants linked to that user. If no participants are found, or if the user is invalid, an appropriate error response is returned.&lt;br /&gt;
Parameters:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;user_id&amp;lt;/code&amp;gt;: The ID of the user whose participants you want to retrieve. If the user does not exist, the method returns without further action. &amp;lt;br/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Behavior:&lt;br /&gt;
&lt;br /&gt;
*The method validates the presence and existence of the &amp;lt;code&amp;gt;user_id&amp;lt;/code&amp;gt;.&lt;br /&gt;
**If the user_id is invalid, the method then stops execution and does not proceed with participant retrieval. &lt;br /&gt;
**If a valid user is provided, then it will retrieve all participants and filter in the ones of the provided user.&lt;br /&gt;
***The final filtered list of participants is returned as a JSON response.&lt;br /&gt;
***If the final list would be empty, then it will return with error 422&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;code&amp;gt;assignment_index&amp;lt;/code&amp;gt; Method====&lt;br /&gt;
Description:&lt;br /&gt;
&lt;br /&gt;
This method retrieves a list of participants associated with a specific assignment. If a valid assignment_id is provided in the request, the system searches for the corresponding assignment and returns the list of participants linked to that assignment. If no participants are found, or if the assignment is invalid, an appropriate error response is returned.&lt;br /&gt;
Parameters:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;assignment_id&amp;lt;/code&amp;gt;: The ID of the assignment whose participants you want to retrieve. If the assignment does not exist, the method returns without further action. &amp;lt;br/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Behavior:&lt;br /&gt;
&lt;br /&gt;
*The method validates the presence and existence of the &amp;lt;code&amp;gt;assignment_id&amp;lt;/code&amp;gt;.&lt;br /&gt;
**If the assignment_id is invalid, the method then stops execution and does not proceed with participant retrieval. &lt;br /&gt;
**If a valid assignment is provided, then it will retrieve all participants and filter in the ones of the provided assignment.&lt;br /&gt;
***The final filtered list of participants is returned as a JSON response.&lt;br /&gt;
***If the final list would be empty, then it will return with error 422&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;code&amp;gt;add&amp;lt;/code&amp;gt; Method====&lt;br /&gt;
&lt;br /&gt;
Description:&lt;br /&gt;
&lt;br /&gt;
Assigns the specified authorization to a participant and adds them to a given assignment. It performs the necessary validations to ensure that the user, assignment, and authorization are valid before proceeding. If all validations pass, it associates the participant with the assignment and applies the relevant permissions based on the authorization.&lt;br /&gt;
&lt;br /&gt;
Parameters:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;user_id&amp;lt;/code&amp;gt; (required): The ID of the user to be added as a participant.&lt;br /&gt;
&amp;lt;code&amp;gt;assignment_id&amp;lt;/code&amp;gt; (required): The ID of the assignment the user will be added to.&lt;br /&gt;
&amp;lt;code&amp;gt;authorization&amp;lt;/code&amp;gt; (required): The authorization ID to define the user's permissions within the assignment.&lt;br /&gt;
&lt;br /&gt;
Behavior:&lt;br /&gt;
&lt;br /&gt;
*Validates and retrieves the user based on the provided &amp;lt;code&amp;gt;user_id&amp;lt;/code&amp;gt;. If the user is not found, the method terminates.&lt;br /&gt;
*Validates and retrieves the assignment based on the provided &amp;lt;code&amp;gt;assignment_id&amp;lt;/code&amp;gt;. If the assignment is not found, the method terminates.&lt;br /&gt;
*Validates and retrieves the authorization based on the provided &amp;lt;code&amp;gt;assignment_id&amp;lt;/code&amp;gt;. If the authorization is not found, the method terminates.&lt;br /&gt;
*Builds a new Participant instance linked to the validated user and assignment, with the appropriate permissions obtained from authorization.&lt;br /&gt;
*Attempts to save the Participant:&lt;br /&gt;
**If successful: Returns a JSON response containing the created Participant and a 201 Created status.&lt;br /&gt;
**If unsuccessful: Returns a JSON response containing validation errors and a 422 Unprocessable Entity status.&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;code&amp;gt;update_authorization&amp;lt;/code&amp;gt; Method ====&lt;br /&gt;
Description:&lt;br /&gt;
&lt;br /&gt;
Updates the authorization and associated permissions for an existing participant.&lt;br /&gt;
&lt;br /&gt;
Parameters:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;participant_id&amp;lt;/code&amp;gt; (required): The ID of the participant whose authorization is being updated.&lt;br /&gt;
&amp;lt;code&amp;gt;authorization&amp;lt;/code&amp;gt; (required): The new authorization ID to assign to the participant.&lt;br /&gt;
&lt;br /&gt;
Behavior:&lt;br /&gt;
*Validates the provided authorization using validate_authorization after finding the participant. If the authorization is missing, the method halts and returns 422.&lt;br /&gt;
*Upon successful validation of the authorization, the method retrieves the permissions associated with the authorization by calling retrieve_participant_permissions.&lt;br /&gt;
*Updates the participant's authorization field with the new authorization. Relevant permissions (can_submit, can_review, can_take_quiz, and can_mentor) are also updated based on the authorization’s values.&lt;br /&gt;
*Attempts to save the updated participant&lt;br /&gt;
**If the participant is successfully updated and saved to the database, a JSON response with the updated participant details and a 201 Created status is returned.&lt;br /&gt;
**If there are validation errors or the update fails, a JSON response with error details and a 422 Unprocessable Entity status is returned.&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;code&amp;gt;destroy&amp;lt;/code&amp;gt; Method====&lt;br /&gt;
&lt;br /&gt;
Description:&lt;br /&gt;
&lt;br /&gt;
Deletes a specified Participant based on the provided ID.&lt;br /&gt;
&lt;br /&gt;
Parameters:&lt;br /&gt;
&lt;br /&gt;
*&amp;lt;code&amp;gt;id&amp;lt;/code&amp;gt; (required): The ID of the Participant to be deleted.&lt;br /&gt;
&lt;br /&gt;
Behavior:&lt;br /&gt;
&lt;br /&gt;
*Retrieves the Participant using the provided &amp;lt;code&amp;gt;id&amp;lt;/code&amp;gt;.&lt;br /&gt;
*Attempts to delete the Participant:&lt;br /&gt;
**If successful: Returns a JSON response containing a confirmation message and a 200 OK status.&lt;br /&gt;
**If unsuccessful: Returns a JSON response containing validation errors and a 422 Unprocessable Entity status.&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;code&amp;gt;show&amp;lt;/code&amp;gt; Method====&lt;br /&gt;
&lt;br /&gt;
Description:&lt;br /&gt;
&lt;br /&gt;
Retrieves and returns a specific Participant based on the provided ID.&lt;br /&gt;
&lt;br /&gt;
Parameters:&lt;br /&gt;
&lt;br /&gt;
*&amp;lt;code&amp;gt;id&amp;lt;/code&amp;gt; (required): The ID of the Participant to be retrieved.&lt;br /&gt;
&lt;br /&gt;
Behavior:&lt;br /&gt;
&lt;br /&gt;
*Fetches the Participant from the database using the provided &amp;lt;code&amp;gt;id&amp;lt;/code&amp;gt;.&lt;br /&gt;
*Attempts to fetch the Participant:&lt;br /&gt;
**If successful: Returns a JSON response containing a confirmation message and a 200 OK status.&lt;br /&gt;
**If unsuccessful: Returns a JSON response containing validation errors and a 422 Unprocessable Entity status.&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;code&amp;gt;participant_params&amp;lt;/code&amp;gt; Method====&lt;br /&gt;
&lt;br /&gt;
Description:&lt;br /&gt;
&lt;br /&gt;
Defines the permitted parameters for creating or updating a Participant object.&lt;br /&gt;
&lt;br /&gt;
Parameters:&lt;br /&gt;
&lt;br /&gt;
The method expects a Participant object within the request parameters. It permits the following attributes:&lt;br /&gt;
&lt;br /&gt;
*&amp;lt;code&amp;gt;user_id&amp;lt;/code&amp;gt; (required): The ID of the user associated with the Participant.&lt;br /&gt;
*&amp;lt;code&amp;gt;assignment_id&amp;lt;/code&amp;gt; (required): The ID of the assignment linked to the Participant.&lt;br /&gt;
*&amp;lt;code&amp;gt;team_id&amp;lt;/code&amp;gt; (optional): The ID of the team the Participant belongs to.&lt;br /&gt;
*&amp;lt;code&amp;gt;can_submit&amp;lt;/code&amp;gt;: A boolean indicating whether the Participant has submit permissions granted.&lt;br /&gt;
*&amp;lt;code&amp;gt;can_review&amp;lt;/code&amp;gt;: A boolean indicating whether the Participant has review permissions granted.&lt;br /&gt;
*&amp;lt;code&amp;gt;can_take_quiz&amp;lt;/code&amp;gt;: A boolean indicating whether the Participant has take_quiz permissions granted.&lt;br /&gt;
*&amp;lt;code&amp;gt;can_mentor&amp;lt;/code&amp;gt;: A boolean indicating whether the Participant has mentor permissions granted.&lt;br /&gt;
*&amp;lt;code&amp;gt;join_team_request_id&amp;lt;/code&amp;gt; (optional): The ID of any pending team join request related to the Participant.&lt;br /&gt;
*&amp;lt;code&amp;gt;permission_granted&amp;lt;/code&amp;gt; (optional): A boolean indicating whether the Participant has specific permissions granted.&lt;br /&gt;
*&amp;lt;code&amp;gt;topic&amp;lt;/code&amp;gt; (optional): The topic assigned to the Participant (could be a string or other data type depending on the application context).&lt;br /&gt;
*&amp;lt;code&amp;gt;current_stage&amp;lt;/code&amp;gt; (optional): The current progress stage of the Participant.&lt;br /&gt;
*&amp;lt;code&amp;gt;stage_deadline&amp;lt;/code&amp;gt; (optional): The deadline for the current stage.&lt;br /&gt;
&lt;br /&gt;
Behavior:&lt;br /&gt;
&lt;br /&gt;
*Ensures that only allowed parameters are passed when creating a Participant object.&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;code&amp;gt;filter_user_participants&amp;lt;/code&amp;gt; Method ====&lt;br /&gt;
Description:&lt;br /&gt;
&lt;br /&gt;
Retrieves and filters participants based on the provided user.&lt;br /&gt;
&lt;br /&gt;
Parameters:&lt;br /&gt;
&lt;br /&gt;
*&amp;lt;code&amp;gt;user&amp;lt;/code&amp;gt; (required): An instance of the User model. If provided, the method filters participants associated with this user.&lt;br /&gt;
&lt;br /&gt;
Behavior:&lt;br /&gt;
&lt;br /&gt;
*Fetches all participants from the database.&lt;br /&gt;
*The method filters participants where the user_id matches the given user's ID.&lt;br /&gt;
*The final list of participants is then ordered by their id in ascending order.&lt;br /&gt;
====&amp;lt;code&amp;gt;filter_assignment_participants&amp;lt;/code&amp;gt; Method ====&lt;br /&gt;
Description:&lt;br /&gt;
&lt;br /&gt;
Retrieves and filters participants based on the provided assignment.&lt;br /&gt;
&lt;br /&gt;
Parameters:&lt;br /&gt;
&lt;br /&gt;
*&amp;lt;code&amp;gt;assignment&amp;lt;/code&amp;gt; (required): An instance of the assignment model. If provided, the method filters participants associated with this assignment.&lt;br /&gt;
&lt;br /&gt;
Behavior:&lt;br /&gt;
&lt;br /&gt;
*Fetches all participants from the database.&lt;br /&gt;
*The method filters participants where the assignment_id matches the given assignment's ID.&lt;br /&gt;
*The final list of participants is then ordered by their id in ascending order.&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;code&amp;gt;find_user&amp;lt;/code&amp;gt; Method ====&lt;br /&gt;
&lt;br /&gt;
Description:&lt;br /&gt;
Retrieves a User object based on the user_id provided. If the user is not found, it returns an error response and halts further execution.&lt;br /&gt;
&lt;br /&gt;
Parameters:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;user_id&amp;lt;/code&amp;gt; (optional): The ID of the user to be retrieved. Extracted from the permitted parameters.&lt;br /&gt;
&lt;br /&gt;
Behavior:&lt;br /&gt;
&lt;br /&gt;
*Attempts to find the user in the database using the provided user_id.&lt;br /&gt;
**If the user is not found (nil), it renders a JSON response with an error message and 404 Not found status&lt;br /&gt;
**If the user exists, it returns the user object with 200 ok status.&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;code&amp;gt;find_assignment&amp;lt;/code&amp;gt; Method ====&lt;br /&gt;
&lt;br /&gt;
Description:&lt;br /&gt;
&lt;br /&gt;
Retrieves an Assignment object based on the assignment_id provided. If the Assignment is not found, it returns an error response and halts further execution.&lt;br /&gt;
&lt;br /&gt;
Parameters:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;assignment_id&amp;lt;/code&amp;gt; (optional): The ID of the assignment to be retrieved. Extracted from the permitted parameters.&lt;br /&gt;
&lt;br /&gt;
Behavior:&lt;br /&gt;
&lt;br /&gt;
*Attempts to find the assignment in the database using the provided assignment_id.&lt;br /&gt;
**If the assignment is not found (nil), it renders a JSON response with an error message and 404 Not found status&lt;br /&gt;
**If the assignment exists, it returns the assignment object with 200 ok status.&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;code&amp;gt;find_participant&amp;lt;/code&amp;gt; Method ====&lt;br /&gt;
&lt;br /&gt;
Description:&lt;br /&gt;
&lt;br /&gt;
Retrieves an participant object based on the participant_id provided. If the participant is not found, it returns an error response and halts further execution.&lt;br /&gt;
&lt;br /&gt;
Parameters:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;participant_id&amp;lt;/code&amp;gt; (optional): The ID of the participant to be retrieved. Extracted from the permitted parameters.&lt;br /&gt;
&lt;br /&gt;
Behavior:&lt;br /&gt;
&lt;br /&gt;
*Attempts to find the participant in the database using the provided participant_id.&lt;br /&gt;
**If the participant is not found (nil), it renders a JSON response with an error message and 404 Not found status&lt;br /&gt;
**If the participant exists, it returns the participant object with 200 ok status.&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;code&amp;gt;validate_authorization&amp;lt;/code&amp;gt; Method ====&lt;br /&gt;
Description:&lt;br /&gt;
*Validates the authorization parameter provided in the request. Ensures that the authorization value is one of the accepted roles: reader, reviewer, submitter, or mentor.&lt;br /&gt;
&lt;br /&gt;
Parameters:&lt;br /&gt;
*&amp;lt;code&amp;gt;authorization&amp;lt;/code&amp;gt; (required): A string representing the participant’s authorization role. This value must be one of the following: reader, reviewer, submitter, or mentor.&lt;br /&gt;
&lt;br /&gt;
Behavior:&lt;br /&gt;
*If the authorization parameter is present, it is converted to lowercase to ensure case-insensitive comparison.&lt;br /&gt;
*If the authorization parameter is not provided, the method renders a 422 Unprocessable Entity response with an error message indicating that a participant must have an authorization.&lt;br /&gt;
*If the authorization value is provided but does not match one of the valid roles (reader, reviewer, submitter, or mentor), the method renders a 422 Unprocessable Entity response with an error message listing the valid options.&lt;br /&gt;
*If the authorization value is valid, the method returns the authorization string.&lt;br /&gt;
&lt;br /&gt;
===Import from &amp;lt;code&amp;gt; participants_helper.rb &amp;lt;/code&amp;gt;===&lt;br /&gt;
Refer to the [https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2024_-_E2484._Reimplement_participants_controller.rb#participants_helper.rb_Methods &amp;lt;code&amp;gt; participants_helper.rb &amp;lt;/code&amp;gt; Methods] section for all design-related inquiries &amp;lt;br/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|+&lt;br /&gt;
! Old Method Name !! Action !! New Method Name&lt;br /&gt;
|-&lt;br /&gt;
| upload_users || Removed || -&lt;br /&gt;
|-&lt;br /&gt;
| define_attributes || Removed || -&lt;br /&gt;
|-&lt;br /&gt;
| define_user || Removed || -&lt;br /&gt;
|-&lt;br /&gt;
| create_new_user || Removed || -&lt;br /&gt;
|-&lt;br /&gt;
| add_user_to_assignment || Removed || -&lt;br /&gt;
|-&lt;br /&gt;
| add_user_to_course || Removed || -&lt;br /&gt;
|-&lt;br /&gt;
| get_config || Removed || -&lt;br /&gt;
|-&lt;br /&gt;
| store_item || Removed || -&lt;br /&gt;
|-&lt;br /&gt;
| participant_permissions || Renamed || retrieve_participant_permissions&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;code&amp;gt;retrieve_participant_permissions&amp;lt;/code&amp;gt; Method====&lt;br /&gt;
&lt;br /&gt;
Description:&lt;br /&gt;
*Retrieves the permissions associated with a given authorization role. The permissions determine the actions a participant can perform (e.g., submitting, reviewing, taking quizzes, or mentoring). The method merges default permissions with role-specific overrides and returns the final set of permissions for the specified authorization.&lt;br /&gt;
&lt;br /&gt;
Parameters:&lt;br /&gt;
&lt;br /&gt;
*&amp;lt;code&amp;gt;authorization&amp;lt;/code&amp;gt; (required): A string representing the participant's authorization role. This value should be one of the following: reader, reviewer, submitter, or mentor.&lt;br /&gt;
Behavior:&lt;br /&gt;
*The method defines a set of default permissions that are assigned to all participants unless overridden by their specific authorization role. The default permissions allow submitting, reviewing, and taking quizzes, while disallowing mentoring.&lt;br /&gt;
*A permissions_map is used to define role-specific overrides for the default permissions:&lt;br /&gt;
**reader: Cannot submit, but can review and take quizzes.&lt;br /&gt;
**reviewer: Cannot submit or take quizzes, but can review.&lt;br /&gt;
**submitter: Cannot review or take quizzes, but can submit.&lt;br /&gt;
**mentor: Can mentor, and has the same permissions as a reader for other actions.&lt;br /&gt;
*The method merges the default permissions with the overrides for the specified authorization. The final set of permissions is returned.&lt;br /&gt;
&lt;br /&gt;
===API Creation===&lt;br /&gt;
Refer to the [https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2024_-_E2484._Reimplement_participants_controller.rb#participants_controller.rb_Methods_/_API_Calls &amp;lt;code&amp;gt; participants_controller.rb &amp;lt;/code&amp;gt; Methods / API Calls] section for all design-related inquiries &amp;lt;br/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Testing with rswag===&lt;br /&gt;
Refer to the [https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2024_-_E2484._Reimplement_participants_controller.rb#Testing_Plan Testing Plan] section &amp;lt;br/&amp;gt;&lt;br /&gt;
&amp;lt;i&amp;gt; To be expanded upon during implementation &amp;lt;/i&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Swagger UI Video Documentation===&lt;br /&gt;
&amp;lt;i&amp;gt; To be added at a later time &amp;lt;/i&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Testing Plan==&lt;br /&gt;
'''rswag'''&amp;lt;br/&amp;gt;&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
====Tests====&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;margin-left:40px&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Test ID !! Test Description &lt;br /&gt;
|-&lt;br /&gt;
| 1 || Test 'assignment_index' with valid assignment ID - Should list participants&lt;br /&gt;
|-&lt;br /&gt;
| 2 || Test 'assignment_index' with invalid assignment ID - Should return an 'Assignment not found' error&lt;br /&gt;
|-&lt;br /&gt;
| 3 || Test unauthorized bearer token access to 'assignment_index' endpoint - Should return a 'Not Authorized' message&lt;br /&gt;
|-&lt;br /&gt;
| 4 || Test 'user_index' with valid user ID - Should list participants&lt;br /&gt;
|-&lt;br /&gt;
| 5 || Test 'user_index' with valid user ID but no participants - Should return an empty list&lt;br /&gt;
|-&lt;br /&gt;
| 6 || Test 'user_index' with invalid user ID - Should return a 'User not found' error&lt;br /&gt;
|-&lt;br /&gt;
| 7 || Test unauthorized bearer token access to 'user_index' endpoint - Should return a 'Not Authorized' message&lt;br /&gt;
|-&lt;br /&gt;
| 8 || Test 'show' with valid participant ID - Should return the specified participant details&lt;br /&gt;
|-&lt;br /&gt;
| 9 || Test 'show' with invalid participant ID - Should return participant not found&lt;br /&gt;
|-&lt;br /&gt;
| 10 || Test unauthorized bearer token access to 'show' endpoint - Should return a 'Not Authorized' message&lt;br /&gt;
|-&lt;br /&gt;
| 11 || Test 'add' with valid user, assignment details, and authorization - Should successfully create a new participant&lt;br /&gt;
|-&lt;br /&gt;
| 12 || Test 'add' with duplicate user and assignment details - Should return an error indicating participant already exists&lt;br /&gt;
|-&lt;br /&gt;
| 13 || Test 'add' with invalid user ID - Should return a 'User not found' error&lt;br /&gt;
|-&lt;br /&gt;
| 14 || Test 'add' with invalid assignment ID - Should return an 'Assignment not found' error&lt;br /&gt;
|-&lt;br /&gt;
| 15 || Test 'add' with invalid authorization - Should return an error specifying valid authorizations (Reader, Reviewer, etc.)&lt;br /&gt;
|-&lt;br /&gt;
| 16 || Test unauthorized bearer token access to 'add' endpoint - Should return a 'Not Authorized' message&lt;br /&gt;
|-&lt;br /&gt;
| 17 || Test 'destroy' with valid participant ID - Should delete the specified participant&lt;br /&gt;
|-&lt;br /&gt;
| 18 || Test 'destroy' with invalid participant ID - Should return participant not found message&lt;br /&gt;
|-&lt;br /&gt;
| 19 || Test unauthorized bearer token access to 'destroy' endpoint - Should return a 'Not Authorized' message&lt;br /&gt;
|-&lt;br /&gt;
| 20 || Test 'update_authorization' participant authorization with valid participant ID and authorization - Should update the authorization level successfully&lt;br /&gt;
|-&lt;br /&gt;
| 21 || Test 'update_authorization' participant authorization with invalid participant ID - Should return a 'Participant not found' message&lt;br /&gt;
|-&lt;br /&gt;
| 22 || Test 'update_authorization' participant authorization with invalid participant ID and invalid authorization - Should return a 'Participant not found' message&lt;br /&gt;
|-&lt;br /&gt;
| 23 || Test 'update_authorization' participant authorization with invalid authorization - Should return a validation error for authorization  &lt;br /&gt;
|-&lt;br /&gt;
| 24 || Test unauthorized bearer token access to 'update_authorization' endpoint - Should return a 'Not Authorized' message&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==Next Steps==&lt;br /&gt;
Our goal throughout this implementation was to reduce the bloat and refactor the controller to something significantly cleaner. Originally, we had a design that we believed to be fairly clean, cutting out nearly 80% of the functions and almost half of the database columns. However, we were made aware that the new, significantly cut down implementation would not work within the current system, and we feel that we ended up re adding a lot of the bloat that we had just cut out. Roles are connected to the participant, but these participant roles are different than User roles. Permissions are handled by the participant, which while not bad, we believe it could be improved. The links between assignment and course is hardly fleshed out at all, and participant handles a lot of logic that could be better distributed. We were also made aware of an AssignmentParticipant and a CourseParticipant, which we believe to be unnecessarily specific. &lt;br /&gt;
&lt;br /&gt;
===Proposal===&lt;br /&gt;
We propose that the entire hierarchy and structure of the Course, Assignment, and Participant be re-designed from the ground up alongside each other to delegate tasks in a much more reasonable way. One way to do so would be a system that could look something like the following diagram.&lt;br /&gt;
&lt;br /&gt;
Diagram:&lt;br /&gt;
[[File:NewStructureProposal.png]]&lt;br /&gt;
&lt;br /&gt;
The primary change here would be a slight decoupling of participant from assignment and a unification of the AssignmentParticipant and CourseParticipant classes. We cant really see a logical reason for distinction between the two, and this would significantly reduce the amount of code bloat in the system. Instead, Participants will be the avatar through which a User interacts with the Course hierarchy. User would just be an account that accesses a participant for each class they are in.&lt;br /&gt;
&lt;br /&gt;
There would no longer be a need to create a participant object for every single user in every single assignment in a course, significantly reducing the bloat that creating an assignment for an entire class could cause under the current system.&lt;br /&gt;
&lt;br /&gt;
Roles would be assigned to participants, and then assignments would handle the logic behind permissions. This provides the advantage that different assignments can control how different roles can interact with themselves independently of each other. If they could already do that, then this resolves a DRY violation where permission information is logically acted upon in both Participant and Assignment.&lt;br /&gt;
&lt;br /&gt;
Incidentally, if you were to delegate some of User's roles to participant's roles, such as instructor, then instructors could then also become participants in classes without needing to create another account with student level permissions. If you were to adopt this structure even further out to include universities, Users that are admins of one university can be students of another all under one User account.&lt;br /&gt;
&lt;br /&gt;
However, this is likely to have cascading effects on other critical systems as well. Teams may need to be entirely re organized since there are no longer unique participants per user for each assignment, as well as many other implications that we may not have been able to anticipate.&lt;br /&gt;
&lt;br /&gt;
This is not the solution that has to be used, however, we believe that it would be an improvement on the current system.&lt;br /&gt;
&lt;br /&gt;
==Team==&lt;br /&gt;
'''Mentor''' &lt;br /&gt;
&lt;br /&gt;
*Jay Patel &amp;lt;jhpatel9@ncsu.edu&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Students'''&lt;br /&gt;
&lt;br /&gt;
*Pierce Whelan &amp;lt;pwwhelan@ncsu.edu&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*Calvin Jiang &amp;lt;crjiang@ncsu.edu&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*Hechun Zhang &amp;lt;hzhang56@ncsu.edu&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Relevant Links ==&lt;br /&gt;
Pull Request [https://github.com/expertiza/reimplementation-back-end/pull/135] &amp;lt;br/&amp;gt;&lt;br /&gt;
GitHub Repository [https://github.com/Pierce57/participant_controller_reimplementation.git] &amp;lt;br/&amp;gt;&lt;br /&gt;
GitHub Project Board [https://github.com/users/Pierce57/projects/3] &amp;lt;br/&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt; participants_controller.rb &amp;lt;/code&amp;gt; in Old Expertiza [https://github.com/expertiza/expertiza/blob/main/app/controllers/participants_controller.rb] &amp;lt;br/&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt; participants_helper.rb &amp;lt;/code&amp;gt; in Old Expertiza [https://github.com/expertiza/expertiza/blob/main/app/helpers/participants_helper.rb]&lt;/div&gt;</summary>
		<author><name>Hzhang56</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2024_-_E2484._Reimplement_participants_controller.rb&amp;diff=160167</id>
		<title>CSC/ECE 517 Fall 2024 - E2484. Reimplement participants controller.rb</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2024_-_E2484._Reimplement_participants_controller.rb&amp;diff=160167"/>
		<updated>2024-12-03T17:24:26Z</updated>

		<summary type="html">&lt;p&gt;Hzhang56: /* Tests */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==About Expertiza==&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is an open source project based on [http://rubyonrails.org/ 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.&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
This project aims to reimplement the &amp;lt;code&amp;gt; participants_controller.rb &amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt; participants_helper.rb &amp;lt;/code&amp;gt; in the new Expertiza system. The &amp;lt;code&amp;gt; participants_controller.rb &amp;lt;/code&amp;gt; manages participants within assignments, and this reimplementation focuses on streamlining its methods, eliminating redundancy, and enhancing code readability and maintainability.&lt;br /&gt;
&lt;br /&gt;
==Requirements==&lt;br /&gt;
&amp;lt;li&amp;gt; Implement &amp;lt;code&amp;gt; participants_controller.rb &amp;lt;/code&amp;gt; Methods: Fully implement each controller method with the same functionality as the current controller. &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Import from &amp;lt;code&amp;gt; participants_helper.rb &amp;lt;/code&amp;gt;: Integrate relevant helper methods to streamline functionality and remove redundancy. &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; API Creation: Expose API endpoints for all necessary methods to enable seamless access and integration from the frontend. Ensure that each endpoint follows best practices for RESTful API design, including proper error handling and secure data access. &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Testing with rswag: Create test cases for all methods, focusing on edge cases, and generate rswag documentation. &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Swagger UI Video Documentation: Record a video walkthrough of API endpoints in Swagger UI, showcasing each method’s functionality. &amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Existing Issues==&lt;br /&gt;
Reimplement &amp;lt;code&amp;gt; [https://github.com/expertiza/expertiza/blob/main/app/controllers/participants_controller.rb participants_controller.rb] &amp;lt;/code&amp;gt; while addressing the following:&lt;br /&gt;
&amp;lt;li&amp;gt; Refactor code to comply with the Open-Closed Principle and the Single Responsibility Principle. &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Introduce dependency injection where necessary. &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Reduce excessive conditional statements. &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Include sufficient code tests to verify functionality. &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Enhance comments to better explain each method's functionality, purpose, and rationale for keeping or modifying particular aspects of the code. &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Provide a more detailed explanation of design choices and refactoring steps. &amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Design / Proposed Solution ==&lt;br /&gt;
===Controller Diagram===&lt;br /&gt;
[[File:Participants Controller UML Diagram.png]]&lt;br /&gt;
&lt;br /&gt;
===&amp;lt;code&amp;gt; participants_controller.rb &amp;lt;/code&amp;gt; Methods / API Calls===&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;width: 100%;&lt;br /&gt;
! &amp;amp;nbsp;#&amp;amp;nbsp; !! Method !! Endpoint !! Description &lt;br /&gt;
|-&lt;br /&gt;
|1&lt;br /&gt;
|user_index&lt;br /&gt;
|GET &amp;lt;code&amp;gt; /participants/user/:user_id &amp;lt;/code&amp;gt;&lt;br /&gt;
|Return a list of participants for a given user&lt;br /&gt;
|-&lt;br /&gt;
|2&lt;br /&gt;
|assignment_index&lt;br /&gt;
|GET &amp;lt;code&amp;gt; /participants/assignment/:assignment_id &amp;lt;/code&amp;gt;&lt;br /&gt;
|Return a list of participants for a given assignment&lt;br /&gt;
|-&lt;br /&gt;
|3&lt;br /&gt;
|show&lt;br /&gt;
|GET &amp;lt;code&amp;gt; /participants/:id &amp;lt;/code&amp;gt;&lt;br /&gt;
|Return a specified participant&lt;br /&gt;
|-&lt;br /&gt;
|4&lt;br /&gt;
|add&lt;br /&gt;
|POST &amp;lt;code&amp;gt; /participants/:authorization &amp;lt;/code&amp;gt;&lt;br /&gt;
|Assign the specified authorization to the participant and add them to an assignment&lt;br /&gt;
|-&lt;br /&gt;
|5&lt;br /&gt;
|update_authorization&lt;br /&gt;
|PATCH &amp;lt;code&amp;gt; /participants/:id/:authorization &amp;lt;/code&amp;gt;&lt;br /&gt;
|Update the specified participant to the specified authorization&lt;br /&gt;
|-&lt;br /&gt;
|6&lt;br /&gt;
|destroy&lt;br /&gt;
|DELETE &amp;lt;code&amp;gt; /participants/:id &amp;lt;/code&amp;gt;&lt;br /&gt;
|Delete a participant&lt;br /&gt;
|-&lt;br /&gt;
|7&lt;br /&gt;
|participant_params&lt;br /&gt;
| -&lt;br /&gt;
|Permitted parameters for creating a Participant object&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
The following methods were removed from &amp;lt;code&amp;gt; participants_controller.rb &amp;lt;/code&amp;gt;:&lt;br /&gt;
&amp;lt;li&amp;gt; &amp;lt;code&amp;gt; action_allowed? &amp;lt;/code&amp;gt; - No impact on functionality &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; &amp;lt;code&amp;gt; controller_locale &amp;lt;/code&amp;gt; - No impact on functionality &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; &amp;lt;code&amp;gt; inherit &amp;lt;/code&amp;gt; - Since there is no direct relationship between the Participant and Course classes, this logic is redundant and no longer necessary &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; &amp;lt;code&amp;gt; bequeath_all &amp;lt;/code&amp;gt; - Since there is no direct relationship between the Participant and Course classes, this logic is redundant and no longer necessary &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; &amp;lt;code&amp;gt; change_handle &amp;lt;/code&amp;gt; - The User class has a `handle` field already. It would be redundant to have one in Participant as well.&lt;br /&gt;
&amp;lt;li&amp;gt; &amp;lt;code&amp;gt; delete &amp;lt;/code&amp;gt; - Handled in the &amp;lt;i&amp;gt; remove_participant &amp;lt;/i&amp;gt; method of the AssignmentsController (&amp;lt;code&amp;gt; assignments_controller.rb &amp;lt;/code&amp;gt;) &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; &amp;lt;code&amp;gt; view_copyright_grants &amp;lt;/code&amp;gt; - Incorrectly implemented in the old implementation &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; &amp;lt;code&amp;gt; get_user_info &amp;lt;/code&amp;gt; - All needed user data can be accessed by leveraging the Participant model's &amp;lt;i&amp;gt; belongs_to &amp;lt;/i&amp;gt; relationship to the User model &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; &amp;lt;code&amp;gt; get_signup_topics_for_assignment &amp;lt;/code&amp;gt; - Handled in the &amp;lt;i&amp;gt; index &amp;lt;/i&amp;gt; method of the SignUpTopicsController (&amp;lt;code&amp;gt; sign_up_topics_controller.rb &amp;lt;/code&amp;gt;) &amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===&amp;lt;code&amp;gt; participants_helper.rb &amp;lt;/code&amp;gt; Methods===&lt;br /&gt;
Almost all of the methods in &amp;lt;code&amp;gt;participants_helper.rb&amp;lt;/code&amp;gt; are outdated and do not impact any functionality in &amp;lt;code&amp;gt;participants_controller.rb&amp;lt;/code&amp;gt;. &amp;lt;br/&amp;gt;&lt;br /&gt;
As a result, these methods will not be carried forward to the new implementation:&lt;br /&gt;
&amp;lt;li&amp;gt; &amp;lt;code&amp;gt; upload_users &amp;lt;/code&amp;gt; - Logic for creating a User specifically for the Assignment and Course classes. Since there is no direct relationship between the User and these classes, this logic is redundant and no longer necessary &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; &amp;lt;code&amp;gt; define_attributes &amp;lt;/code&amp;gt; - &amp;lt;i&amp;gt; Same reason as above &amp;lt;/i&amp;gt; &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; &amp;lt;code&amp;gt; define_user &amp;lt;/code&amp;gt; - &amp;lt;i&amp;gt; Same reason as above &amp;lt;/i&amp;gt; &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; &amp;lt;code&amp;gt; create_new_user &amp;lt;/code&amp;gt; - &amp;lt;i&amp;gt; Same reason as above &amp;lt;/i&amp;gt; &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; &amp;lt;code&amp;gt; add_user_to_assignment &amp;lt;/code&amp;gt; - &amp;lt;i&amp;gt; Same reason as above. &amp;lt;/i&amp;gt; Furthermore, since the Participant and Assignment classes are directly related, this functionality has been replaced by the &amp;lt;i&amp;gt; add_participant &amp;lt;/i&amp;gt; method in AssignmentsController (&amp;lt;code&amp;gt;assignments_controller.rb&amp;lt;/code&amp;gt;) &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; &amp;lt;code&amp;gt; add_user_to_course &amp;lt;/code&amp;gt; - &amp;lt;i&amp;gt; Same reason as above &amp;lt;/i&amp;gt; &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; &amp;lt;code&amp;gt; get_config &amp;lt;/code&amp;gt; - &amp;lt;i&amp;gt; Same reason as above &amp;lt;/i&amp;gt; &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; &amp;lt;code&amp;gt; store_item &amp;lt;/code&amp;gt; - &amp;lt;i&amp;gt; Same reason as above &amp;lt;/i&amp;gt; &amp;lt;/li&amp;gt;&lt;br /&gt;
The only method being kept is &amp;lt;code&amp;gt;participant_permissions&amp;lt;/code&amp;gt; as it is responsible for handling the assignment of permissions to a Participant.&lt;br /&gt;
&lt;br /&gt;
===Pattern(s)===&lt;br /&gt;
'''Facade''': &amp;quot;A simplified interface that performs many other actions behind the scenes.&amp;quot; &amp;lt;br/&amp;gt;&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
===SOLID Principle(s)===&lt;br /&gt;
'''Open and Closed Principle''': &amp;quot;Software entities should be open for extension, but closed for modification.&amp;quot;&amp;lt;br/&amp;gt;&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
'''Single Responsibility Principle''': &amp;quot;A class should only have one responsibility and should never have more than one reason to change.&amp;quot;&amp;lt;br/&amp;gt;&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
==Implementation==&lt;br /&gt;
===Implement &amp;lt;code&amp;gt; participants_controller.rb &amp;lt;/code&amp;gt; Methods===&lt;br /&gt;
Refer to the [https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2024_-_E2484._Reimplement_participants_controller.rb#participants_controller.rb_Methods_/_API_Calls &amp;lt;code&amp;gt; participants_controller.rb &amp;lt;/code&amp;gt; Methods / API Calls] section for a brief overview of its use &amp;lt;br/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|+&lt;br /&gt;
! Old Method Name !! Action !! New Method Name&lt;br /&gt;
|-&lt;br /&gt;
| action_allowed? || Removed || -&lt;br /&gt;
|-&lt;br /&gt;
| controller_locale || Removed || -&lt;br /&gt;
|-&lt;br /&gt;
| list || Renamed and Separated || user_index&lt;br /&gt;
|-&lt;br /&gt;
| - || - || assignment_index&lt;br /&gt;
|-&lt;br /&gt;
| add || No Change || add&lt;br /&gt;
|-&lt;br /&gt;
| update_authorizations || Renamed || update_authorization&lt;br /&gt;
|-&lt;br /&gt;
| destroy || No Change || destroy&lt;br /&gt;
|-&lt;br /&gt;
| inherit || Removed || -&lt;br /&gt;
|-&lt;br /&gt;
| bequeath_all || Removed || -&lt;br /&gt;
|-&lt;br /&gt;
| change_handle || Removed || -&lt;br /&gt;
|-&lt;br /&gt;
| delete || Removed || -&lt;br /&gt;
|-&lt;br /&gt;
| view_copyright_grants || Removed || -&lt;br /&gt;
|-&lt;br /&gt;
| participant_params || No Change || participant_params&lt;br /&gt;
|-&lt;br /&gt;
| get_user_info || Removed || -&lt;br /&gt;
|-&lt;br /&gt;
| get_signup_topics_for_assignment || Removed || -&lt;br /&gt;
|-&lt;br /&gt;
| - || Added || show&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;code&amp;gt;user_index&amp;lt;/code&amp;gt; Method====&lt;br /&gt;
Description:&lt;br /&gt;
&lt;br /&gt;
This method retrieves a list of participants associated with a specific user. If a valid user_id is provided in the request, the system searches for the corresponding user and returns the list of participants linked to that user. If no participants are found, or if the user is invalid, an appropriate error response is returned.&lt;br /&gt;
Parameters:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;user_id&amp;lt;/code&amp;gt;: The ID of the user whose participants you want to retrieve. If the user does not exist, the method returns without further action. &amp;lt;br/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Behavior:&lt;br /&gt;
&lt;br /&gt;
*The method validates the presence and existence of the &amp;lt;code&amp;gt;user_id&amp;lt;/code&amp;gt;.&lt;br /&gt;
**If the user_id is invalid, the method then stops execution and does not proceed with participant retrieval. &lt;br /&gt;
**If a valid user is provided, then it will retrieve all participants and filter in the ones of the provided user.&lt;br /&gt;
***The final filtered list of participants is returned as a JSON response.&lt;br /&gt;
***If the final list would be empty, then it will return with error 422&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;code&amp;gt;assignment_index&amp;lt;/code&amp;gt; Method====&lt;br /&gt;
Description:&lt;br /&gt;
&lt;br /&gt;
This method retrieves a list of participants associated with a specific assignment. If a valid assignment_id is provided in the request, the system searches for the corresponding assignment and returns the list of participants linked to that assignment. If no participants are found, or if the assignment is invalid, an appropriate error response is returned.&lt;br /&gt;
Parameters:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;assignment_id&amp;lt;/code&amp;gt;: The ID of the assignment whose participants you want to retrieve. If the assignment does not exist, the method returns without further action. &amp;lt;br/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Behavior:&lt;br /&gt;
&lt;br /&gt;
*The method validates the presence and existence of the &amp;lt;code&amp;gt;assignment_id&amp;lt;/code&amp;gt;.&lt;br /&gt;
**If the assignment_id is invalid, the method then stops execution and does not proceed with participant retrieval. &lt;br /&gt;
**If a valid assignment is provided, then it will retrieve all participants and filter in the ones of the provided assignment.&lt;br /&gt;
***The final filtered list of participants is returned as a JSON response.&lt;br /&gt;
***If the final list would be empty, then it will return with error 422&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;code&amp;gt;add&amp;lt;/code&amp;gt; Method====&lt;br /&gt;
&lt;br /&gt;
Description:&lt;br /&gt;
&lt;br /&gt;
Assigns the specified authorization to a participant and adds them to a given assignment. It performs the necessary validations to ensure that the user, assignment, and authorization are valid before proceeding. If all validations pass, it associates the participant with the assignment and applies the relevant permissions based on the authorization.&lt;br /&gt;
&lt;br /&gt;
Parameters:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;user_id&amp;lt;/code&amp;gt; (required): The ID of the user to be added as a participant.&lt;br /&gt;
&amp;lt;code&amp;gt;assignment_id&amp;lt;/code&amp;gt; (required): The ID of the assignment the user will be added to.&lt;br /&gt;
&amp;lt;code&amp;gt;authorization&amp;lt;/code&amp;gt; (required): The authorization ID to define the user's permissions within the assignment.&lt;br /&gt;
&lt;br /&gt;
Behavior:&lt;br /&gt;
&lt;br /&gt;
*Validates and retrieves the user based on the provided &amp;lt;code&amp;gt;user_id&amp;lt;/code&amp;gt;. If the user is not found, the method terminates.&lt;br /&gt;
*Validates and retrieves the assignment based on the provided &amp;lt;code&amp;gt;assignment_id&amp;lt;/code&amp;gt;. If the assignment is not found, the method terminates.&lt;br /&gt;
*Validates and retrieves the authorization based on the provided &amp;lt;code&amp;gt;assignment_id&amp;lt;/code&amp;gt;. If the authorization is not found, the method terminates.&lt;br /&gt;
*Builds a new Participant instance linked to the validated user and assignment, with the appropriate permissions obtained from authorization.&lt;br /&gt;
*Attempts to save the Participant:&lt;br /&gt;
**If successful: Returns a JSON response containing the created Participant and a 201 Created status.&lt;br /&gt;
**If unsuccessful: Returns a JSON response containing validation errors and a 422 Unprocessable Entity status.&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;code&amp;gt;update_authorization&amp;lt;/code&amp;gt; Method ====&lt;br /&gt;
Description:&lt;br /&gt;
&lt;br /&gt;
Updates the authorization and associated permissions for an existing participant.&lt;br /&gt;
&lt;br /&gt;
Parameters:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;participant_id&amp;lt;/code&amp;gt; (required): The ID of the participant whose authorization is being updated.&lt;br /&gt;
&amp;lt;code&amp;gt;authorization&amp;lt;/code&amp;gt; (required): The new authorization ID to assign to the participant.&lt;br /&gt;
&lt;br /&gt;
Behavior:&lt;br /&gt;
*Validates the provided authorization using validate_authorization after finding the participant. If the authorization is missing, the method halts and returns 422.&lt;br /&gt;
*Upon successful validation of the authorization, the method retrieves the permissions associated with the authorization by calling retrieve_participant_permissions.&lt;br /&gt;
*Updates the participant's authorization field with the new authorization. Relevant permissions (can_submit, can_review, can_take_quiz, and can_mentor) are also updated based on the authorization’s values.&lt;br /&gt;
*Attempts to save the updated participant&lt;br /&gt;
**If the participant is successfully updated and saved to the database, a JSON response with the updated participant details and a 201 Created status is returned.&lt;br /&gt;
**If there are validation errors or the update fails, a JSON response with error details and a 422 Unprocessable Entity status is returned.&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;code&amp;gt;destroy&amp;lt;/code&amp;gt; Method====&lt;br /&gt;
&lt;br /&gt;
Description:&lt;br /&gt;
&lt;br /&gt;
Deletes a specified Participant based on the provided ID.&lt;br /&gt;
&lt;br /&gt;
Parameters:&lt;br /&gt;
&lt;br /&gt;
*&amp;lt;code&amp;gt;id&amp;lt;/code&amp;gt; (required): The ID of the Participant to be deleted.&lt;br /&gt;
&lt;br /&gt;
Behavior:&lt;br /&gt;
&lt;br /&gt;
*Retrieves the Participant using the provided &amp;lt;code&amp;gt;id&amp;lt;/code&amp;gt;.&lt;br /&gt;
*Attempts to delete the Participant:&lt;br /&gt;
**If successful: Returns a JSON response containing a confirmation message and a 200 OK status.&lt;br /&gt;
**If unsuccessful: Returns a JSON response containing validation errors and a 422 Unprocessable Entity status.&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;code&amp;gt;show&amp;lt;/code&amp;gt; Method====&lt;br /&gt;
&lt;br /&gt;
Description:&lt;br /&gt;
&lt;br /&gt;
Retrieves and returns a specific Participant based on the provided ID.&lt;br /&gt;
&lt;br /&gt;
Parameters:&lt;br /&gt;
&lt;br /&gt;
*&amp;lt;code&amp;gt;id&amp;lt;/code&amp;gt; (required): The ID of the Participant to be retrieved.&lt;br /&gt;
&lt;br /&gt;
Behavior:&lt;br /&gt;
&lt;br /&gt;
*Fetches the Participant from the database using the provided &amp;lt;code&amp;gt;id&amp;lt;/code&amp;gt;.&lt;br /&gt;
*Attempts to fetch the Participant:&lt;br /&gt;
**If successful: Returns a JSON response containing a confirmation message and a 200 OK status.&lt;br /&gt;
**If unsuccessful: Returns a JSON response containing validation errors and a 422 Unprocessable Entity status.&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;code&amp;gt;participant_params&amp;lt;/code&amp;gt; Method====&lt;br /&gt;
&lt;br /&gt;
Description:&lt;br /&gt;
&lt;br /&gt;
Defines the permitted parameters for creating or updating a Participant object.&lt;br /&gt;
&lt;br /&gt;
Parameters:&lt;br /&gt;
&lt;br /&gt;
The method expects a Participant object within the request parameters. It permits the following attributes:&lt;br /&gt;
&lt;br /&gt;
*&amp;lt;code&amp;gt;user_id&amp;lt;/code&amp;gt; (required): The ID of the user associated with the Participant.&lt;br /&gt;
*&amp;lt;code&amp;gt;assignment_id&amp;lt;/code&amp;gt; (required): The ID of the assignment linked to the Participant.&lt;br /&gt;
*&amp;lt;code&amp;gt;team_id&amp;lt;/code&amp;gt; (optional): The ID of the team the Participant belongs to.&lt;br /&gt;
*&amp;lt;code&amp;gt;can_submit&amp;lt;/code&amp;gt;: A boolean indicating whether the Participant has submit permissions granted.&lt;br /&gt;
*&amp;lt;code&amp;gt;can_review&amp;lt;/code&amp;gt;: A boolean indicating whether the Participant has review permissions granted.&lt;br /&gt;
*&amp;lt;code&amp;gt;can_take_quiz&amp;lt;/code&amp;gt;: A boolean indicating whether the Participant has take_quiz permissions granted.&lt;br /&gt;
*&amp;lt;code&amp;gt;can_mentor&amp;lt;/code&amp;gt;: A boolean indicating whether the Participant has mentor permissions granted.&lt;br /&gt;
*&amp;lt;code&amp;gt;join_team_request_id&amp;lt;/code&amp;gt; (optional): The ID of any pending team join request related to the Participant.&lt;br /&gt;
*&amp;lt;code&amp;gt;permission_granted&amp;lt;/code&amp;gt; (optional): A boolean indicating whether the Participant has specific permissions granted.&lt;br /&gt;
*&amp;lt;code&amp;gt;topic&amp;lt;/code&amp;gt; (optional): The topic assigned to the Participant (could be a string or other data type depending on the application context).&lt;br /&gt;
*&amp;lt;code&amp;gt;current_stage&amp;lt;/code&amp;gt; (optional): The current progress stage of the Participant.&lt;br /&gt;
*&amp;lt;code&amp;gt;stage_deadline&amp;lt;/code&amp;gt; (optional): The deadline for the current stage.&lt;br /&gt;
&lt;br /&gt;
Behavior:&lt;br /&gt;
&lt;br /&gt;
*Ensures that only allowed parameters are passed when creating a Participant object.&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;code&amp;gt;filter_user_participants&amp;lt;/code&amp;gt; Method ====&lt;br /&gt;
Description:&lt;br /&gt;
&lt;br /&gt;
Retrieves and filters participants based on the provided user.&lt;br /&gt;
&lt;br /&gt;
Parameters:&lt;br /&gt;
&lt;br /&gt;
*&amp;lt;code&amp;gt;user&amp;lt;/code&amp;gt; (required): An instance of the User model. If provided, the method filters participants associated with this user.&lt;br /&gt;
&lt;br /&gt;
Behavior:&lt;br /&gt;
&lt;br /&gt;
*Fetches all participants from the database.&lt;br /&gt;
*The method filters participants where the user_id matches the given user's ID.&lt;br /&gt;
*The final list of participants is then ordered by their id in ascending order.&lt;br /&gt;
====&amp;lt;code&amp;gt;filter_assignment_participants&amp;lt;/code&amp;gt; Method ====&lt;br /&gt;
Description:&lt;br /&gt;
&lt;br /&gt;
Retrieves and filters participants based on the provided assignment.&lt;br /&gt;
&lt;br /&gt;
Parameters:&lt;br /&gt;
&lt;br /&gt;
*&amp;lt;code&amp;gt;assignment&amp;lt;/code&amp;gt; (required): An instance of the assignment model. If provided, the method filters participants associated with this assignment.&lt;br /&gt;
&lt;br /&gt;
Behavior:&lt;br /&gt;
&lt;br /&gt;
*Fetches all participants from the database.&lt;br /&gt;
*The method filters participants where the assignment_id matches the given assignment's ID.&lt;br /&gt;
*The final list of participants is then ordered by their id in ascending order.&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;code&amp;gt;find_user&amp;lt;/code&amp;gt; Method ====&lt;br /&gt;
&lt;br /&gt;
Description:&lt;br /&gt;
Retrieves a User object based on the user_id provided. If the user is not found, it returns an error response and halts further execution.&lt;br /&gt;
&lt;br /&gt;
Parameters:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;user_id&amp;lt;/code&amp;gt; (optional): The ID of the user to be retrieved. Extracted from the permitted parameters.&lt;br /&gt;
&lt;br /&gt;
Behavior:&lt;br /&gt;
&lt;br /&gt;
*Attempts to find the user in the database using the provided user_id.&lt;br /&gt;
**If the user is not found (nil), it renders a JSON response with an error message and 404 Not found status&lt;br /&gt;
**If the user exists, it returns the user object with 200 ok status.&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;code&amp;gt;find_assignment&amp;lt;/code&amp;gt; Method ====&lt;br /&gt;
&lt;br /&gt;
Description:&lt;br /&gt;
&lt;br /&gt;
Retrieves an Assignment object based on the assignment_id provided. If the Assignment is not found, it returns an error response and halts further execution.&lt;br /&gt;
&lt;br /&gt;
Parameters:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;assignment_id&amp;lt;/code&amp;gt; (optional): The ID of the assignment to be retrieved. Extracted from the permitted parameters.&lt;br /&gt;
&lt;br /&gt;
Behavior:&lt;br /&gt;
&lt;br /&gt;
*Attempts to find the assignment in the database using the provided assignment_id.&lt;br /&gt;
**If the assignment is not found (nil), it renders a JSON response with an error message and 404 Not found status&lt;br /&gt;
**If the assignment exists, it returns the assignment object with 200 ok status.&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;code&amp;gt;find_participant&amp;lt;/code&amp;gt; Method ====&lt;br /&gt;
&lt;br /&gt;
Description:&lt;br /&gt;
&lt;br /&gt;
Retrieves an participant object based on the participant_id provided. If the participant is not found, it returns an error response and halts further execution.&lt;br /&gt;
&lt;br /&gt;
Parameters:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;participant_id&amp;lt;/code&amp;gt; (optional): The ID of the participant to be retrieved. Extracted from the permitted parameters.&lt;br /&gt;
&lt;br /&gt;
Behavior:&lt;br /&gt;
&lt;br /&gt;
*Attempts to find the participant in the database using the provided participant_id.&lt;br /&gt;
**If the participant is not found (nil), it renders a JSON response with an error message and 404 Not found status&lt;br /&gt;
**If the participant exists, it returns the participant object with 200 ok status.&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;code&amp;gt;validate_authorization&amp;lt;/code&amp;gt; Method ====&lt;br /&gt;
Description:&lt;br /&gt;
*Validates the authorization parameter provided in the request. Ensures that the authorization value is one of the accepted roles: reader, reviewer, submitter, or mentor.&lt;br /&gt;
&lt;br /&gt;
Parameters:&lt;br /&gt;
*&amp;lt;code&amp;gt;authorization&amp;lt;/code&amp;gt; (required): A string representing the participant’s authorization role. This value must be one of the following: reader, reviewer, submitter, or mentor.&lt;br /&gt;
&lt;br /&gt;
Behavior:&lt;br /&gt;
*If the authorization parameter is present, it is converted to lowercase to ensure case-insensitive comparison.&lt;br /&gt;
*If the authorization parameter is not provided, the method renders a 422 Unprocessable Entity response with an error message indicating that a participant must have an authorization.&lt;br /&gt;
*If the authorization value is provided but does not match one of the valid roles (reader, reviewer, submitter, or mentor), the method renders a 422 Unprocessable Entity response with an error message listing the valid options.&lt;br /&gt;
*If the authorization value is valid, the method returns the authorization string.&lt;br /&gt;
&lt;br /&gt;
===Import from &amp;lt;code&amp;gt; participants_helper.rb &amp;lt;/code&amp;gt;===&lt;br /&gt;
Refer to the [https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2024_-_E2484._Reimplement_participants_controller.rb#participants_helper.rb_Methods &amp;lt;code&amp;gt; participants_helper.rb &amp;lt;/code&amp;gt; Methods] section for all design-related inquiries &amp;lt;br/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|+&lt;br /&gt;
! Old Method Name !! Action !! New Method Name&lt;br /&gt;
|-&lt;br /&gt;
| upload_users || Removed || -&lt;br /&gt;
|-&lt;br /&gt;
| define_attributes || Removed || -&lt;br /&gt;
|-&lt;br /&gt;
| define_user || Removed || -&lt;br /&gt;
|-&lt;br /&gt;
| create_new_user || Removed || -&lt;br /&gt;
|-&lt;br /&gt;
| add_user_to_assignment || Removed || -&lt;br /&gt;
|-&lt;br /&gt;
| add_user_to_course || Removed || -&lt;br /&gt;
|-&lt;br /&gt;
| get_config || Removed || -&lt;br /&gt;
|-&lt;br /&gt;
| store_item || Removed || -&lt;br /&gt;
|-&lt;br /&gt;
| participant_permissions || Renamed || retrieve_participant_permissions&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;code&amp;gt;retrieve_participant_permissions&amp;lt;/code&amp;gt; Method====&lt;br /&gt;
&lt;br /&gt;
Description:&lt;br /&gt;
*Retrieves the permissions associated with a given authorization role. The permissions determine the actions a participant can perform (e.g., submitting, reviewing, taking quizzes, or mentoring). The method merges default permissions with role-specific overrides and returns the final set of permissions for the specified authorization.&lt;br /&gt;
&lt;br /&gt;
Parameters:&lt;br /&gt;
&lt;br /&gt;
*&amp;lt;code&amp;gt;authorization&amp;lt;/code&amp;gt; (required): A string representing the participant's authorization role. This value should be one of the following: reader, reviewer, submitter, or mentor.&lt;br /&gt;
Behavior:&lt;br /&gt;
*The method defines a set of default permissions that are assigned to all participants unless overridden by their specific authorization role. The default permissions allow submitting, reviewing, and taking quizzes, while disallowing mentoring.&lt;br /&gt;
*A permissions_map is used to define role-specific overrides for the default permissions:&lt;br /&gt;
**reader: Cannot submit, but can review and take quizzes.&lt;br /&gt;
**reviewer: Cannot submit or take quizzes, but can review.&lt;br /&gt;
**submitter: Cannot review or take quizzes, but can submit.&lt;br /&gt;
**mentor: Can mentor, and has the same permissions as a reader for other actions.&lt;br /&gt;
*The method merges the default permissions with the overrides for the specified authorization. The final set of permissions is returned.&lt;br /&gt;
&lt;br /&gt;
===API Creation===&lt;br /&gt;
Refer to the [https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2024_-_E2484._Reimplement_participants_controller.rb#participants_controller.rb_Methods_/_API_Calls &amp;lt;code&amp;gt; participants_controller.rb &amp;lt;/code&amp;gt; Methods / API Calls] section for all design-related inquiries &amp;lt;br/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Testing with rswag===&lt;br /&gt;
Refer to the [https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2024_-_E2484._Reimplement_participants_controller.rb#Testing_Plan Testing Plan] section &amp;lt;br/&amp;gt;&lt;br /&gt;
&amp;lt;i&amp;gt; To be expanded upon during implementation &amp;lt;/i&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Swagger UI Video Documentation===&lt;br /&gt;
&amp;lt;i&amp;gt; To be added at a later time &amp;lt;/i&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Testing Plan==&lt;br /&gt;
'''rswag'''&amp;lt;br/&amp;gt;&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
====Tests====&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;margin-left:40px&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Test ID !! Test Description &lt;br /&gt;
|-&lt;br /&gt;
| 1 || Test 'assignment_index' with valid assignment ID - Should list participants&lt;br /&gt;
|-&lt;br /&gt;
| 2 || Test 'assignment_index' with invalid assignment ID - Should return an 'Assignment not found' error&lt;br /&gt;
|-&lt;br /&gt;
| 3 || Test unauthorized bearer token access to 'assignment_index' endpoint - Should return a 'Not Authorized' message&lt;br /&gt;
|-&lt;br /&gt;
| 4 || Test 'user_index' with valid user ID - Should list participants&lt;br /&gt;
|-&lt;br /&gt;
| 5 || Test 'user_index' with valid user ID but no participants - Should return an empty list&lt;br /&gt;
|-&lt;br /&gt;
| 6 || Test 'user_index' with invalid user ID - Should return a 'User not found' error&lt;br /&gt;
|-&lt;br /&gt;
| 7 || Test unauthorized bearer token access to 'user_index' endpoint - Should return a 'Not Authorized' message&lt;br /&gt;
|-&lt;br /&gt;
| 8 || Test 'show' with valid participant ID - Should return the specified participant details&lt;br /&gt;
|-&lt;br /&gt;
| 9 || Test 'show' with invalid participant ID - Should return participant not found&lt;br /&gt;
|-&lt;br /&gt;
| 10 || Test unauthorized bearer token access to 'show' endpoint - Should return a 'Not Authorized' message&lt;br /&gt;
|-&lt;br /&gt;
| 11 || Test 'add' with valid user, assignment details, and authorization - Should successfully create a new participant&lt;br /&gt;
|-&lt;br /&gt;
| 12 || Test 'add' with duplicate user and assignment details - Should return an error indicating participant already exists&lt;br /&gt;
|-&lt;br /&gt;
| 13 || Test 'add' with invalid user ID - Should return a 'User not found' error&lt;br /&gt;
|-&lt;br /&gt;
| 14 || Test 'add' with invalid assignment ID - Should return an 'Assignment not found' error&lt;br /&gt;
|-&lt;br /&gt;
| 15 || Test 'add' with invalid authorization - Should return an error specifying valid roles (Reader, Reviewer, etc.)&lt;br /&gt;
|-&lt;br /&gt;
| 16 || Test unauthorized bearer token access to 'add' endpoint - Should return a 'Not Authorized' message&lt;br /&gt;
|-&lt;br /&gt;
| 17 || Test 'destroy' with valid participant ID - Should delete the specified participant&lt;br /&gt;
|-&lt;br /&gt;
| 18 || Test 'destroy' with invalid participant ID - Should return participant not found message&lt;br /&gt;
|-&lt;br /&gt;
| 19 || Test unauthorized bearer token access to 'destroy' endpoint - Should return a 'Not Authorized' message&lt;br /&gt;
|-&lt;br /&gt;
| 20 || Test 'update_authorization' participant authorization with valid participant ID and authorization - Should update the authorization level successfully&lt;br /&gt;
|-&lt;br /&gt;
| 21 || Test 'update_authorization' participant authorization with invalid participant ID - Should return a 'Participant not found' message&lt;br /&gt;
|-&lt;br /&gt;
| 22 || Test 'update_authorization' participant authorization with invalid participant ID and invalid authorization - Should return a 'Participant not found' message&lt;br /&gt;
|-&lt;br /&gt;
| 23 || Test 'update_authorization' participant authorization with invalid authorization - Should return a validation error for authorization  &lt;br /&gt;
|-&lt;br /&gt;
| 24 || Test unauthorized bearer token access to 'update_authorization' endpoint - Should return a 'Not Authorized' message&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==Next Steps==&lt;br /&gt;
Our goal throughout this implementation was to reduce the bloat and refactor the controller to something significantly cleaner. Originally, we had a design that we believed to be fairly clean, cutting out nearly 80% of the functions and almost half of the database columns. However, we were made aware that the new, significantly cut down implementation would not work within the current system, and we feel that we ended up re adding a lot of the bloat that we had just cut out. Roles are connected to the participant, but these participant roles are different than User roles. Permissions are handled by the participant, which while not bad, we believe it could be improved. The links between assignment and course is hardly fleshed out at all, and participant handles a lot of logic that could be better distributed. We were also made aware of an AssignmentParticipant and a CourseParticipant, which we believe to be unnecessarily specific. &lt;br /&gt;
&lt;br /&gt;
===Proposal===&lt;br /&gt;
We propose that the entire hierarchy and structure of the Course, Assignment, and Participant be re-designed from the ground up alongside each other to delegate tasks in a much more reasonable way. One way to do so would be a system that could look something like the following diagram.&lt;br /&gt;
&lt;br /&gt;
Diagram:&lt;br /&gt;
[[File:NewStructureProposal.png]]&lt;br /&gt;
&lt;br /&gt;
The primary change here would be a slight decoupling of participant from assignment and a unification of the AssignmentParticipant and CourseParticipant classes. We cant really see a logical reason for distinction between the two, and this would significantly reduce the amount of code bloat in the system. Instead, Participants will be the avatar through which a User interacts with the Course hierarchy. User would just be an account that accesses a participant for each class they are in.&lt;br /&gt;
&lt;br /&gt;
There would no longer be a need to create a participant object for every single user in every single assignment in a course, significantly reducing the bloat that creating an assignment for an entire class could cause under the current system.&lt;br /&gt;
&lt;br /&gt;
Roles would be assigned to participants, and then assignments would handle the logic behind permissions. This provides the advantage that different assignments can control how different roles can interact with themselves independently of each other. If they could already do that, then this resolves a DRY violation where permission information is logically acted upon in both Participant and Assignment.&lt;br /&gt;
&lt;br /&gt;
Incidentally, if you were to delegate some of User's roles to participant's roles, such as instructor, then instructors could then also become participants in classes without needing to create another account with student level permissions. If you were to adopt this structure even further out to include universities, Users that are admins of one university can be students of another all under one User account.&lt;br /&gt;
&lt;br /&gt;
However, this is likely to have cascading effects on other critical systems as well. Teams may need to be entirely re organized since there are no longer unique participants per user for each assignment, as well as many other implications that we may not have been able to anticipate.&lt;br /&gt;
&lt;br /&gt;
This is not the solution that has to be used, however, we believe that it would be an improvement on the current system.&lt;br /&gt;
&lt;br /&gt;
==Team==&lt;br /&gt;
'''Mentor''' &lt;br /&gt;
&lt;br /&gt;
*Jay Patel &amp;lt;jhpatel9@ncsu.edu&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Students'''&lt;br /&gt;
&lt;br /&gt;
*Pierce Whelan &amp;lt;pwwhelan@ncsu.edu&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*Calvin Jiang &amp;lt;crjiang@ncsu.edu&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*Hechun Zhang &amp;lt;hzhang56@ncsu.edu&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Relevant Links ==&lt;br /&gt;
Pull Request [https://github.com/expertiza/reimplementation-back-end/pull/135] &amp;lt;br/&amp;gt;&lt;br /&gt;
GitHub Repository [https://github.com/Pierce57/participant_controller_reimplementation.git] &amp;lt;br/&amp;gt;&lt;br /&gt;
GitHub Project Board [https://github.com/users/Pierce57/projects/3] &amp;lt;br/&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt; participants_controller.rb &amp;lt;/code&amp;gt; in Old Expertiza [https://github.com/expertiza/expertiza/blob/main/app/controllers/participants_controller.rb] &amp;lt;br/&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt; participants_helper.rb &amp;lt;/code&amp;gt; in Old Expertiza [https://github.com/expertiza/expertiza/blob/main/app/helpers/participants_helper.rb]&lt;/div&gt;</summary>
		<author><name>Hzhang56</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2024_-_E2484._Reimplement_participants_controller.rb&amp;diff=160166</id>
		<title>CSC/ECE 517 Fall 2024 - E2484. Reimplement participants controller.rb</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2024_-_E2484._Reimplement_participants_controller.rb&amp;diff=160166"/>
		<updated>2024-12-03T17:20:44Z</updated>

		<summary type="html">&lt;p&gt;Hzhang56: /* Tests */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==About Expertiza==&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is an open source project based on [http://rubyonrails.org/ 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.&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
This project aims to reimplement the &amp;lt;code&amp;gt; participants_controller.rb &amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt; participants_helper.rb &amp;lt;/code&amp;gt; in the new Expertiza system. The &amp;lt;code&amp;gt; participants_controller.rb &amp;lt;/code&amp;gt; manages participants within assignments, and this reimplementation focuses on streamlining its methods, eliminating redundancy, and enhancing code readability and maintainability.&lt;br /&gt;
&lt;br /&gt;
==Requirements==&lt;br /&gt;
&amp;lt;li&amp;gt; Implement &amp;lt;code&amp;gt; participants_controller.rb &amp;lt;/code&amp;gt; Methods: Fully implement each controller method with the same functionality as the current controller. &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Import from &amp;lt;code&amp;gt; participants_helper.rb &amp;lt;/code&amp;gt;: Integrate relevant helper methods to streamline functionality and remove redundancy. &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; API Creation: Expose API endpoints for all necessary methods to enable seamless access and integration from the frontend. Ensure that each endpoint follows best practices for RESTful API design, including proper error handling and secure data access. &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Testing with rswag: Create test cases for all methods, focusing on edge cases, and generate rswag documentation. &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Swagger UI Video Documentation: Record a video walkthrough of API endpoints in Swagger UI, showcasing each method’s functionality. &amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Existing Issues==&lt;br /&gt;
Reimplement &amp;lt;code&amp;gt; [https://github.com/expertiza/expertiza/blob/main/app/controllers/participants_controller.rb participants_controller.rb] &amp;lt;/code&amp;gt; while addressing the following:&lt;br /&gt;
&amp;lt;li&amp;gt; Refactor code to comply with the Open-Closed Principle and the Single Responsibility Principle. &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Introduce dependency injection where necessary. &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Reduce excessive conditional statements. &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Include sufficient code tests to verify functionality. &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Enhance comments to better explain each method's functionality, purpose, and rationale for keeping or modifying particular aspects of the code. &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Provide a more detailed explanation of design choices and refactoring steps. &amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Design / Proposed Solution ==&lt;br /&gt;
===Controller Diagram===&lt;br /&gt;
[[File:Participants Controller UML Diagram.png]]&lt;br /&gt;
&lt;br /&gt;
===&amp;lt;code&amp;gt; participants_controller.rb &amp;lt;/code&amp;gt; Methods / API Calls===&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;width: 100%;&lt;br /&gt;
! &amp;amp;nbsp;#&amp;amp;nbsp; !! Method !! Endpoint !! Description &lt;br /&gt;
|-&lt;br /&gt;
|1&lt;br /&gt;
|user_index&lt;br /&gt;
|GET &amp;lt;code&amp;gt; /participants/user/:user_id &amp;lt;/code&amp;gt;&lt;br /&gt;
|Return a list of participants for a given user&lt;br /&gt;
|-&lt;br /&gt;
|2&lt;br /&gt;
|assignment_index&lt;br /&gt;
|GET &amp;lt;code&amp;gt; /participants/assignment/:assignment_id &amp;lt;/code&amp;gt;&lt;br /&gt;
|Return a list of participants for a given assignment&lt;br /&gt;
|-&lt;br /&gt;
|3&lt;br /&gt;
|show&lt;br /&gt;
|GET &amp;lt;code&amp;gt; /participants/:id &amp;lt;/code&amp;gt;&lt;br /&gt;
|Return a specified participant&lt;br /&gt;
|-&lt;br /&gt;
|4&lt;br /&gt;
|add&lt;br /&gt;
|POST &amp;lt;code&amp;gt; /participants/:authorization &amp;lt;/code&amp;gt;&lt;br /&gt;
|Assign the specified authorization to the participant and add them to an assignment&lt;br /&gt;
|-&lt;br /&gt;
|5&lt;br /&gt;
|update_authorization&lt;br /&gt;
|PATCH &amp;lt;code&amp;gt; /participants/:id/:authorization &amp;lt;/code&amp;gt;&lt;br /&gt;
|Update the specified participant to the specified authorization&lt;br /&gt;
|-&lt;br /&gt;
|6&lt;br /&gt;
|destroy&lt;br /&gt;
|DELETE &amp;lt;code&amp;gt; /participants/:id &amp;lt;/code&amp;gt;&lt;br /&gt;
|Delete a participant&lt;br /&gt;
|-&lt;br /&gt;
|7&lt;br /&gt;
|participant_params&lt;br /&gt;
| -&lt;br /&gt;
|Permitted parameters for creating a Participant object&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
The following methods were removed from &amp;lt;code&amp;gt; participants_controller.rb &amp;lt;/code&amp;gt;:&lt;br /&gt;
&amp;lt;li&amp;gt; &amp;lt;code&amp;gt; action_allowed? &amp;lt;/code&amp;gt; - No impact on functionality &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; &amp;lt;code&amp;gt; controller_locale &amp;lt;/code&amp;gt; - No impact on functionality &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; &amp;lt;code&amp;gt; inherit &amp;lt;/code&amp;gt; - Since there is no direct relationship between the Participant and Course classes, this logic is redundant and no longer necessary &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; &amp;lt;code&amp;gt; bequeath_all &amp;lt;/code&amp;gt; - Since there is no direct relationship between the Participant and Course classes, this logic is redundant and no longer necessary &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; &amp;lt;code&amp;gt; change_handle &amp;lt;/code&amp;gt; - The User class has a `handle` field already. It would be redundant to have one in Participant as well.&lt;br /&gt;
&amp;lt;li&amp;gt; &amp;lt;code&amp;gt; delete &amp;lt;/code&amp;gt; - Handled in the &amp;lt;i&amp;gt; remove_participant &amp;lt;/i&amp;gt; method of the AssignmentsController (&amp;lt;code&amp;gt; assignments_controller.rb &amp;lt;/code&amp;gt;) &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; &amp;lt;code&amp;gt; view_copyright_grants &amp;lt;/code&amp;gt; - Incorrectly implemented in the old implementation &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; &amp;lt;code&amp;gt; get_user_info &amp;lt;/code&amp;gt; - All needed user data can be accessed by leveraging the Participant model's &amp;lt;i&amp;gt; belongs_to &amp;lt;/i&amp;gt; relationship to the User model &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; &amp;lt;code&amp;gt; get_signup_topics_for_assignment &amp;lt;/code&amp;gt; - Handled in the &amp;lt;i&amp;gt; index &amp;lt;/i&amp;gt; method of the SignUpTopicsController (&amp;lt;code&amp;gt; sign_up_topics_controller.rb &amp;lt;/code&amp;gt;) &amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===&amp;lt;code&amp;gt; participants_helper.rb &amp;lt;/code&amp;gt; Methods===&lt;br /&gt;
Almost all of the methods in &amp;lt;code&amp;gt;participants_helper.rb&amp;lt;/code&amp;gt; are outdated and do not impact any functionality in &amp;lt;code&amp;gt;participants_controller.rb&amp;lt;/code&amp;gt;. &amp;lt;br/&amp;gt;&lt;br /&gt;
As a result, these methods will not be carried forward to the new implementation:&lt;br /&gt;
&amp;lt;li&amp;gt; &amp;lt;code&amp;gt; upload_users &amp;lt;/code&amp;gt; - Logic for creating a User specifically for the Assignment and Course classes. Since there is no direct relationship between the User and these classes, this logic is redundant and no longer necessary &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; &amp;lt;code&amp;gt; define_attributes &amp;lt;/code&amp;gt; - &amp;lt;i&amp;gt; Same reason as above &amp;lt;/i&amp;gt; &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; &amp;lt;code&amp;gt; define_user &amp;lt;/code&amp;gt; - &amp;lt;i&amp;gt; Same reason as above &amp;lt;/i&amp;gt; &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; &amp;lt;code&amp;gt; create_new_user &amp;lt;/code&amp;gt; - &amp;lt;i&amp;gt; Same reason as above &amp;lt;/i&amp;gt; &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; &amp;lt;code&amp;gt; add_user_to_assignment &amp;lt;/code&amp;gt; - &amp;lt;i&amp;gt; Same reason as above. &amp;lt;/i&amp;gt; Furthermore, since the Participant and Assignment classes are directly related, this functionality has been replaced by the &amp;lt;i&amp;gt; add_participant &amp;lt;/i&amp;gt; method in AssignmentsController (&amp;lt;code&amp;gt;assignments_controller.rb&amp;lt;/code&amp;gt;) &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; &amp;lt;code&amp;gt; add_user_to_course &amp;lt;/code&amp;gt; - &amp;lt;i&amp;gt; Same reason as above &amp;lt;/i&amp;gt; &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; &amp;lt;code&amp;gt; get_config &amp;lt;/code&amp;gt; - &amp;lt;i&amp;gt; Same reason as above &amp;lt;/i&amp;gt; &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; &amp;lt;code&amp;gt; store_item &amp;lt;/code&amp;gt; - &amp;lt;i&amp;gt; Same reason as above &amp;lt;/i&amp;gt; &amp;lt;/li&amp;gt;&lt;br /&gt;
The only method being kept is &amp;lt;code&amp;gt;participant_permissions&amp;lt;/code&amp;gt; as it is responsible for handling the assignment of permissions to a Participant.&lt;br /&gt;
&lt;br /&gt;
===Pattern(s)===&lt;br /&gt;
'''Facade''': &amp;quot;A simplified interface that performs many other actions behind the scenes.&amp;quot; &amp;lt;br/&amp;gt;&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
===SOLID Principle(s)===&lt;br /&gt;
'''Open and Closed Principle''': &amp;quot;Software entities should be open for extension, but closed for modification.&amp;quot;&amp;lt;br/&amp;gt;&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
'''Single Responsibility Principle''': &amp;quot;A class should only have one responsibility and should never have more than one reason to change.&amp;quot;&amp;lt;br/&amp;gt;&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
==Implementation==&lt;br /&gt;
===Implement &amp;lt;code&amp;gt; participants_controller.rb &amp;lt;/code&amp;gt; Methods===&lt;br /&gt;
Refer to the [https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2024_-_E2484._Reimplement_participants_controller.rb#participants_controller.rb_Methods_/_API_Calls &amp;lt;code&amp;gt; participants_controller.rb &amp;lt;/code&amp;gt; Methods / API Calls] section for a brief overview of its use &amp;lt;br/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|+&lt;br /&gt;
! Old Method Name !! Action !! New Method Name&lt;br /&gt;
|-&lt;br /&gt;
| action_allowed? || Removed || -&lt;br /&gt;
|-&lt;br /&gt;
| controller_locale || Removed || -&lt;br /&gt;
|-&lt;br /&gt;
| list || Renamed and Separated || user_index&lt;br /&gt;
|-&lt;br /&gt;
| - || - || assignment_index&lt;br /&gt;
|-&lt;br /&gt;
| add || No Change || add&lt;br /&gt;
|-&lt;br /&gt;
| update_authorizations || Renamed || update_authorization&lt;br /&gt;
|-&lt;br /&gt;
| destroy || No Change || destroy&lt;br /&gt;
|-&lt;br /&gt;
| inherit || Removed || -&lt;br /&gt;
|-&lt;br /&gt;
| bequeath_all || Removed || -&lt;br /&gt;
|-&lt;br /&gt;
| change_handle || Removed || -&lt;br /&gt;
|-&lt;br /&gt;
| delete || Removed || -&lt;br /&gt;
|-&lt;br /&gt;
| view_copyright_grants || Removed || -&lt;br /&gt;
|-&lt;br /&gt;
| participant_params || No Change || participant_params&lt;br /&gt;
|-&lt;br /&gt;
| get_user_info || Removed || -&lt;br /&gt;
|-&lt;br /&gt;
| get_signup_topics_for_assignment || Removed || -&lt;br /&gt;
|-&lt;br /&gt;
| - || Added || show&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;code&amp;gt;user_index&amp;lt;/code&amp;gt; Method====&lt;br /&gt;
Description:&lt;br /&gt;
&lt;br /&gt;
This method retrieves a list of participants associated with a specific user. If a valid user_id is provided in the request, the system searches for the corresponding user and returns the list of participants linked to that user. If no participants are found, or if the user is invalid, an appropriate error response is returned.&lt;br /&gt;
Parameters:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;user_id&amp;lt;/code&amp;gt;: The ID of the user whose participants you want to retrieve. If the user does not exist, the method returns without further action. &amp;lt;br/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Behavior:&lt;br /&gt;
&lt;br /&gt;
*The method validates the presence and existence of the &amp;lt;code&amp;gt;user_id&amp;lt;/code&amp;gt;.&lt;br /&gt;
**If the user_id is invalid, the method then stops execution and does not proceed with participant retrieval. &lt;br /&gt;
**If a valid user is provided, then it will retrieve all participants and filter in the ones of the provided user.&lt;br /&gt;
***The final filtered list of participants is returned as a JSON response.&lt;br /&gt;
***If the final list would be empty, then it will return with error 422&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;code&amp;gt;assignment_index&amp;lt;/code&amp;gt; Method====&lt;br /&gt;
Description:&lt;br /&gt;
&lt;br /&gt;
This method retrieves a list of participants associated with a specific assignment. If a valid assignment_id is provided in the request, the system searches for the corresponding assignment and returns the list of participants linked to that assignment. If no participants are found, or if the assignment is invalid, an appropriate error response is returned.&lt;br /&gt;
Parameters:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;assignment_id&amp;lt;/code&amp;gt;: The ID of the assignment whose participants you want to retrieve. If the assignment does not exist, the method returns without further action. &amp;lt;br/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Behavior:&lt;br /&gt;
&lt;br /&gt;
*The method validates the presence and existence of the &amp;lt;code&amp;gt;assignment_id&amp;lt;/code&amp;gt;.&lt;br /&gt;
**If the assignment_id is invalid, the method then stops execution and does not proceed with participant retrieval. &lt;br /&gt;
**If a valid assignment is provided, then it will retrieve all participants and filter in the ones of the provided assignment.&lt;br /&gt;
***The final filtered list of participants is returned as a JSON response.&lt;br /&gt;
***If the final list would be empty, then it will return with error 422&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;code&amp;gt;add&amp;lt;/code&amp;gt; Method====&lt;br /&gt;
&lt;br /&gt;
Description:&lt;br /&gt;
&lt;br /&gt;
Assigns the specified authorization to a participant and adds them to a given assignment. It performs the necessary validations to ensure that the user, assignment, and authorization are valid before proceeding. If all validations pass, it associates the participant with the assignment and applies the relevant permissions based on the authorization.&lt;br /&gt;
&lt;br /&gt;
Parameters:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;user_id&amp;lt;/code&amp;gt; (required): The ID of the user to be added as a participant.&lt;br /&gt;
&amp;lt;code&amp;gt;assignment_id&amp;lt;/code&amp;gt; (required): The ID of the assignment the user will be added to.&lt;br /&gt;
&amp;lt;code&amp;gt;authorization&amp;lt;/code&amp;gt; (required): The authorization ID to define the user's permissions within the assignment.&lt;br /&gt;
&lt;br /&gt;
Behavior:&lt;br /&gt;
&lt;br /&gt;
*Validates and retrieves the user based on the provided &amp;lt;code&amp;gt;user_id&amp;lt;/code&amp;gt;. If the user is not found, the method terminates.&lt;br /&gt;
*Validates and retrieves the assignment based on the provided &amp;lt;code&amp;gt;assignment_id&amp;lt;/code&amp;gt;. If the assignment is not found, the method terminates.&lt;br /&gt;
*Validates and retrieves the authorization based on the provided &amp;lt;code&amp;gt;assignment_id&amp;lt;/code&amp;gt;. If the authorization is not found, the method terminates.&lt;br /&gt;
*Builds a new Participant instance linked to the validated user and assignment, with the appropriate permissions obtained from authorization.&lt;br /&gt;
*Attempts to save the Participant:&lt;br /&gt;
**If successful: Returns a JSON response containing the created Participant and a 201 Created status.&lt;br /&gt;
**If unsuccessful: Returns a JSON response containing validation errors and a 422 Unprocessable Entity status.&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;code&amp;gt;update_authorization&amp;lt;/code&amp;gt; Method ====&lt;br /&gt;
Description:&lt;br /&gt;
&lt;br /&gt;
Updates the authorization and associated permissions for an existing participant.&lt;br /&gt;
&lt;br /&gt;
Parameters:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;participant_id&amp;lt;/code&amp;gt; (required): The ID of the participant whose authorization is being updated.&lt;br /&gt;
&amp;lt;code&amp;gt;authorization&amp;lt;/code&amp;gt; (required): The new authorization ID to assign to the participant.&lt;br /&gt;
&lt;br /&gt;
Behavior:&lt;br /&gt;
*Validates the provided authorization using validate_authorization after finding the participant. If the authorization is missing, the method halts and returns 422.&lt;br /&gt;
*Upon successful validation of the authorization, the method retrieves the permissions associated with the authorization by calling retrieve_participant_permissions.&lt;br /&gt;
*Updates the participant's authorization field with the new authorization. Relevant permissions (can_submit, can_review, can_take_quiz, and can_mentor) are also updated based on the authorization’s values.&lt;br /&gt;
*Attempts to save the updated participant&lt;br /&gt;
**If the participant is successfully updated and saved to the database, a JSON response with the updated participant details and a 201 Created status is returned.&lt;br /&gt;
**If there are validation errors or the update fails, a JSON response with error details and a 422 Unprocessable Entity status is returned.&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;code&amp;gt;destroy&amp;lt;/code&amp;gt; Method====&lt;br /&gt;
&lt;br /&gt;
Description:&lt;br /&gt;
&lt;br /&gt;
Deletes a specified Participant based on the provided ID.&lt;br /&gt;
&lt;br /&gt;
Parameters:&lt;br /&gt;
&lt;br /&gt;
*&amp;lt;code&amp;gt;id&amp;lt;/code&amp;gt; (required): The ID of the Participant to be deleted.&lt;br /&gt;
&lt;br /&gt;
Behavior:&lt;br /&gt;
&lt;br /&gt;
*Retrieves the Participant using the provided &amp;lt;code&amp;gt;id&amp;lt;/code&amp;gt;.&lt;br /&gt;
*Attempts to delete the Participant:&lt;br /&gt;
**If successful: Returns a JSON response containing a confirmation message and a 200 OK status.&lt;br /&gt;
**If unsuccessful: Returns a JSON response containing validation errors and a 422 Unprocessable Entity status.&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;code&amp;gt;show&amp;lt;/code&amp;gt; Method====&lt;br /&gt;
&lt;br /&gt;
Description:&lt;br /&gt;
&lt;br /&gt;
Retrieves and returns a specific Participant based on the provided ID.&lt;br /&gt;
&lt;br /&gt;
Parameters:&lt;br /&gt;
&lt;br /&gt;
*&amp;lt;code&amp;gt;id&amp;lt;/code&amp;gt; (required): The ID of the Participant to be retrieved.&lt;br /&gt;
&lt;br /&gt;
Behavior:&lt;br /&gt;
&lt;br /&gt;
*Fetches the Participant from the database using the provided &amp;lt;code&amp;gt;id&amp;lt;/code&amp;gt;.&lt;br /&gt;
*Attempts to fetch the Participant:&lt;br /&gt;
**If successful: Returns a JSON response containing a confirmation message and a 200 OK status.&lt;br /&gt;
**If unsuccessful: Returns a JSON response containing validation errors and a 422 Unprocessable Entity status.&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;code&amp;gt;participant_params&amp;lt;/code&amp;gt; Method====&lt;br /&gt;
&lt;br /&gt;
Description:&lt;br /&gt;
&lt;br /&gt;
Defines the permitted parameters for creating or updating a Participant object.&lt;br /&gt;
&lt;br /&gt;
Parameters:&lt;br /&gt;
&lt;br /&gt;
The method expects a Participant object within the request parameters. It permits the following attributes:&lt;br /&gt;
&lt;br /&gt;
*&amp;lt;code&amp;gt;user_id&amp;lt;/code&amp;gt; (required): The ID of the user associated with the Participant.&lt;br /&gt;
*&amp;lt;code&amp;gt;assignment_id&amp;lt;/code&amp;gt; (required): The ID of the assignment linked to the Participant.&lt;br /&gt;
*&amp;lt;code&amp;gt;team_id&amp;lt;/code&amp;gt; (optional): The ID of the team the Participant belongs to.&lt;br /&gt;
*&amp;lt;code&amp;gt;can_submit&amp;lt;/code&amp;gt;: A boolean indicating whether the Participant has submit permissions granted.&lt;br /&gt;
*&amp;lt;code&amp;gt;can_review&amp;lt;/code&amp;gt;: A boolean indicating whether the Participant has review permissions granted.&lt;br /&gt;
*&amp;lt;code&amp;gt;can_take_quiz&amp;lt;/code&amp;gt;: A boolean indicating whether the Participant has take_quiz permissions granted.&lt;br /&gt;
*&amp;lt;code&amp;gt;can_mentor&amp;lt;/code&amp;gt;: A boolean indicating whether the Participant has mentor permissions granted.&lt;br /&gt;
*&amp;lt;code&amp;gt;join_team_request_id&amp;lt;/code&amp;gt; (optional): The ID of any pending team join request related to the Participant.&lt;br /&gt;
*&amp;lt;code&amp;gt;permission_granted&amp;lt;/code&amp;gt; (optional): A boolean indicating whether the Participant has specific permissions granted.&lt;br /&gt;
*&amp;lt;code&amp;gt;topic&amp;lt;/code&amp;gt; (optional): The topic assigned to the Participant (could be a string or other data type depending on the application context).&lt;br /&gt;
*&amp;lt;code&amp;gt;current_stage&amp;lt;/code&amp;gt; (optional): The current progress stage of the Participant.&lt;br /&gt;
*&amp;lt;code&amp;gt;stage_deadline&amp;lt;/code&amp;gt; (optional): The deadline for the current stage.&lt;br /&gt;
&lt;br /&gt;
Behavior:&lt;br /&gt;
&lt;br /&gt;
*Ensures that only allowed parameters are passed when creating a Participant object.&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;code&amp;gt;filter_user_participants&amp;lt;/code&amp;gt; Method ====&lt;br /&gt;
Description:&lt;br /&gt;
&lt;br /&gt;
Retrieves and filters participants based on the provided user.&lt;br /&gt;
&lt;br /&gt;
Parameters:&lt;br /&gt;
&lt;br /&gt;
*&amp;lt;code&amp;gt;user&amp;lt;/code&amp;gt; (required): An instance of the User model. If provided, the method filters participants associated with this user.&lt;br /&gt;
&lt;br /&gt;
Behavior:&lt;br /&gt;
&lt;br /&gt;
*Fetches all participants from the database.&lt;br /&gt;
*The method filters participants where the user_id matches the given user's ID.&lt;br /&gt;
*The final list of participants is then ordered by their id in ascending order.&lt;br /&gt;
====&amp;lt;code&amp;gt;filter_assignment_participants&amp;lt;/code&amp;gt; Method ====&lt;br /&gt;
Description:&lt;br /&gt;
&lt;br /&gt;
Retrieves and filters participants based on the provided assignment.&lt;br /&gt;
&lt;br /&gt;
Parameters:&lt;br /&gt;
&lt;br /&gt;
*&amp;lt;code&amp;gt;assignment&amp;lt;/code&amp;gt; (required): An instance of the assignment model. If provided, the method filters participants associated with this assignment.&lt;br /&gt;
&lt;br /&gt;
Behavior:&lt;br /&gt;
&lt;br /&gt;
*Fetches all participants from the database.&lt;br /&gt;
*The method filters participants where the assignment_id matches the given assignment's ID.&lt;br /&gt;
*The final list of participants is then ordered by their id in ascending order.&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;code&amp;gt;find_user&amp;lt;/code&amp;gt; Method ====&lt;br /&gt;
&lt;br /&gt;
Description:&lt;br /&gt;
Retrieves a User object based on the user_id provided. If the user is not found, it returns an error response and halts further execution.&lt;br /&gt;
&lt;br /&gt;
Parameters:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;user_id&amp;lt;/code&amp;gt; (optional): The ID of the user to be retrieved. Extracted from the permitted parameters.&lt;br /&gt;
&lt;br /&gt;
Behavior:&lt;br /&gt;
&lt;br /&gt;
*Attempts to find the user in the database using the provided user_id.&lt;br /&gt;
**If the user is not found (nil), it renders a JSON response with an error message and 404 Not found status&lt;br /&gt;
**If the user exists, it returns the user object with 200 ok status.&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;code&amp;gt;find_assignment&amp;lt;/code&amp;gt; Method ====&lt;br /&gt;
&lt;br /&gt;
Description:&lt;br /&gt;
&lt;br /&gt;
Retrieves an Assignment object based on the assignment_id provided. If the Assignment is not found, it returns an error response and halts further execution.&lt;br /&gt;
&lt;br /&gt;
Parameters:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;assignment_id&amp;lt;/code&amp;gt; (optional): The ID of the assignment to be retrieved. Extracted from the permitted parameters.&lt;br /&gt;
&lt;br /&gt;
Behavior:&lt;br /&gt;
&lt;br /&gt;
*Attempts to find the assignment in the database using the provided assignment_id.&lt;br /&gt;
**If the assignment is not found (nil), it renders a JSON response with an error message and 404 Not found status&lt;br /&gt;
**If the assignment exists, it returns the assignment object with 200 ok status.&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;code&amp;gt;find_participant&amp;lt;/code&amp;gt; Method ====&lt;br /&gt;
&lt;br /&gt;
Description:&lt;br /&gt;
&lt;br /&gt;
Retrieves an participant object based on the participant_id provided. If the participant is not found, it returns an error response and halts further execution.&lt;br /&gt;
&lt;br /&gt;
Parameters:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;participant_id&amp;lt;/code&amp;gt; (optional): The ID of the participant to be retrieved. Extracted from the permitted parameters.&lt;br /&gt;
&lt;br /&gt;
Behavior:&lt;br /&gt;
&lt;br /&gt;
*Attempts to find the participant in the database using the provided participant_id.&lt;br /&gt;
**If the participant is not found (nil), it renders a JSON response with an error message and 404 Not found status&lt;br /&gt;
**If the participant exists, it returns the participant object with 200 ok status.&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;code&amp;gt;validate_authorization&amp;lt;/code&amp;gt; Method ====&lt;br /&gt;
Description:&lt;br /&gt;
*Validates the authorization parameter provided in the request. Ensures that the authorization value is one of the accepted roles: reader, reviewer, submitter, or mentor.&lt;br /&gt;
&lt;br /&gt;
Parameters:&lt;br /&gt;
*&amp;lt;code&amp;gt;authorization&amp;lt;/code&amp;gt; (required): A string representing the participant’s authorization role. This value must be one of the following: reader, reviewer, submitter, or mentor.&lt;br /&gt;
&lt;br /&gt;
Behavior:&lt;br /&gt;
*If the authorization parameter is present, it is converted to lowercase to ensure case-insensitive comparison.&lt;br /&gt;
*If the authorization parameter is not provided, the method renders a 422 Unprocessable Entity response with an error message indicating that a participant must have an authorization.&lt;br /&gt;
*If the authorization value is provided but does not match one of the valid roles (reader, reviewer, submitter, or mentor), the method renders a 422 Unprocessable Entity response with an error message listing the valid options.&lt;br /&gt;
*If the authorization value is valid, the method returns the authorization string.&lt;br /&gt;
&lt;br /&gt;
===Import from &amp;lt;code&amp;gt; participants_helper.rb &amp;lt;/code&amp;gt;===&lt;br /&gt;
Refer to the [https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2024_-_E2484._Reimplement_participants_controller.rb#participants_helper.rb_Methods &amp;lt;code&amp;gt; participants_helper.rb &amp;lt;/code&amp;gt; Methods] section for all design-related inquiries &amp;lt;br/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|+&lt;br /&gt;
! Old Method Name !! Action !! New Method Name&lt;br /&gt;
|-&lt;br /&gt;
| upload_users || Removed || -&lt;br /&gt;
|-&lt;br /&gt;
| define_attributes || Removed || -&lt;br /&gt;
|-&lt;br /&gt;
| define_user || Removed || -&lt;br /&gt;
|-&lt;br /&gt;
| create_new_user || Removed || -&lt;br /&gt;
|-&lt;br /&gt;
| add_user_to_assignment || Removed || -&lt;br /&gt;
|-&lt;br /&gt;
| add_user_to_course || Removed || -&lt;br /&gt;
|-&lt;br /&gt;
| get_config || Removed || -&lt;br /&gt;
|-&lt;br /&gt;
| store_item || Removed || -&lt;br /&gt;
|-&lt;br /&gt;
| participant_permissions || Renamed || retrieve_participant_permissions&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;code&amp;gt;retrieve_participant_permissions&amp;lt;/code&amp;gt; Method====&lt;br /&gt;
&lt;br /&gt;
Description:&lt;br /&gt;
*Retrieves the permissions associated with a given authorization role. The permissions determine the actions a participant can perform (e.g., submitting, reviewing, taking quizzes, or mentoring). The method merges default permissions with role-specific overrides and returns the final set of permissions for the specified authorization.&lt;br /&gt;
&lt;br /&gt;
Parameters:&lt;br /&gt;
&lt;br /&gt;
*&amp;lt;code&amp;gt;authorization&amp;lt;/code&amp;gt; (required): A string representing the participant's authorization role. This value should be one of the following: reader, reviewer, submitter, or mentor.&lt;br /&gt;
Behavior:&lt;br /&gt;
*The method defines a set of default permissions that are assigned to all participants unless overridden by their specific authorization role. The default permissions allow submitting, reviewing, and taking quizzes, while disallowing mentoring.&lt;br /&gt;
*A permissions_map is used to define role-specific overrides for the default permissions:&lt;br /&gt;
**reader: Cannot submit, but can review and take quizzes.&lt;br /&gt;
**reviewer: Cannot submit or take quizzes, but can review.&lt;br /&gt;
**submitter: Cannot review or take quizzes, but can submit.&lt;br /&gt;
**mentor: Can mentor, and has the same permissions as a reader for other actions.&lt;br /&gt;
*The method merges the default permissions with the overrides for the specified authorization. The final set of permissions is returned.&lt;br /&gt;
&lt;br /&gt;
===API Creation===&lt;br /&gt;
Refer to the [https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2024_-_E2484._Reimplement_participants_controller.rb#participants_controller.rb_Methods_/_API_Calls &amp;lt;code&amp;gt; participants_controller.rb &amp;lt;/code&amp;gt; Methods / API Calls] section for all design-related inquiries &amp;lt;br/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Testing with rswag===&lt;br /&gt;
Refer to the [https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2024_-_E2484._Reimplement_participants_controller.rb#Testing_Plan Testing Plan] section &amp;lt;br/&amp;gt;&lt;br /&gt;
&amp;lt;i&amp;gt; To be expanded upon during implementation &amp;lt;/i&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Swagger UI Video Documentation===&lt;br /&gt;
&amp;lt;i&amp;gt; To be added at a later time &amp;lt;/i&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Testing Plan==&lt;br /&gt;
'''rswag'''&amp;lt;br/&amp;gt;&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
====Tests====&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;margin-left:40px&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Test ID !! Test Description &lt;br /&gt;
|-&lt;br /&gt;
| 1 || Test 'assignment_index' with valid assignment ID - Should list participants&lt;br /&gt;
|-&lt;br /&gt;
| 2 || Test 'assignment_index' with invalid assignment ID - Should return an 'Assignment not found' error&lt;br /&gt;
|-&lt;br /&gt;
| 3 || Test unauthorized bearer token access to 'assignment_index' endpoint - Should return a 'Not Authorized' message&lt;br /&gt;
|-&lt;br /&gt;
| 4 || Test 'user_index' with valid user ID but no participants - Should return an empty list&lt;br /&gt;
|-&lt;br /&gt;
| 5 || Test 'user_index' with invalid user ID - Should return a 'User not found' error&lt;br /&gt;
|-&lt;br /&gt;
| 6 || Test unauthorized bearer token access to 'user_index' endpoint - Should return a 'Not Authorized' message&lt;br /&gt;
|-&lt;br /&gt;
| 7 || Test 'show' with valid participant ID - Should return the specified participant details&lt;br /&gt;
|-&lt;br /&gt;
| 8 || Test 'show' with invalid participant ID - Should return participant not found&lt;br /&gt;
|-&lt;br /&gt;
| 9 || Test unauthorized bearer token access to 'show' endpoint - Should return a 'Not Authorized' message&lt;br /&gt;
|-&lt;br /&gt;
| 10 || Test 'add' with valid user, assignment details, and authorization - Should successfully create a new participant&lt;br /&gt;
|-&lt;br /&gt;
| 11 || Test 'add' with duplicate user and assignment details - Should return an error indicating participant already exists&lt;br /&gt;
|-&lt;br /&gt;
| 12 || Test 'add' with invalid user ID - Should return a 'User not found' error&lt;br /&gt;
|-&lt;br /&gt;
| 13 || Test 'add' with invalid assignment ID - Should return an 'Assignment not found' error&lt;br /&gt;
|-&lt;br /&gt;
| 14 || Test 'add' with invalid authorization - Should return an error specifying valid roles (Reader, Reviewer, etc.)&lt;br /&gt;
|-&lt;br /&gt;
| 15 || Test 'add' with invalid data format - Should return a validation error&lt;br /&gt;
|-&lt;br /&gt;
| 16 || Test unauthorized bearer token access to 'add' endpoint - Should return a 'Not Authorized' message&lt;br /&gt;
|-&lt;br /&gt;
| 17 || Test 'destroy' with valid participant ID - Should delete the specified participant&lt;br /&gt;
|-&lt;br /&gt;
| 18 || Test 'destroy' with invalid participant ID - Should return participant not found message&lt;br /&gt;
|-&lt;br /&gt;
| 19 || Test unauthorized bearer token access to 'destroy' endpoint - Should return a 'Not Authorized' message&lt;br /&gt;
|-&lt;br /&gt;
| 20 || Test 'update_authorization' participant authorization with valid participant ID and authorization - Should update the authorization level successfully&lt;br /&gt;
|-&lt;br /&gt;
| 21 || Test 'update_authorization' participant authorization with invalid participant ID - Should return a 'Participant not found' message&lt;br /&gt;
|-&lt;br /&gt;
| 22 || Test 'update_authorization' participant authorization with invalid participant ID and invalid authorization - Should return a 'Participant not found' message&lt;br /&gt;
|-&lt;br /&gt;
| 23 || Test 'update_authorization' participant authorization with invalid authorization - Should return a validation error for authorization  &lt;br /&gt;
|-&lt;br /&gt;
| 24 || Test unauthorized bearer token access to 'update_authorization' endpoint - Should return a 'Not Authorized' message&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==Next Steps==&lt;br /&gt;
Our goal throughout this implementation was to reduce the bloat and refactor the controller to something significantly cleaner. Originally, we had a design that we believed to be fairly clean, cutting out nearly 80% of the functions and almost half of the database columns. However, we were made aware that the new, significantly cut down implementation would not work within the current system, and we feel that we ended up re adding a lot of the bloat that we had just cut out. Roles are connected to the participant, but these participant roles are different than User roles. Permissions are handled by the participant, which while not bad, we believe it could be improved. The links between assignment and course is hardly fleshed out at all, and participant handles a lot of logic that could be better distributed. We were also made aware of an AssignmentParticipant and a CourseParticipant, which we believe to be unnecessarily specific. &lt;br /&gt;
&lt;br /&gt;
===Proposal===&lt;br /&gt;
We propose that the entire hierarchy and structure of the Course, Assignment, and Participant be re-designed from the ground up alongside each other to delegate tasks in a much more reasonable way. One way to do so would be a system that could look something like the following diagram.&lt;br /&gt;
&lt;br /&gt;
Diagram:&lt;br /&gt;
[[File:NewStructureProposal.png]]&lt;br /&gt;
&lt;br /&gt;
The primary change here would be a slight decoupling of participant from assignment and a unification of the AssignmentParticipant and CourseParticipant classes. We cant really see a logical reason for distinction between the two, and this would significantly reduce the amount of code bloat in the system. Instead, Participants will be the avatar through which a User interacts with the Course hierarchy. User would just be an account that accesses a participant for each class they are in.&lt;br /&gt;
&lt;br /&gt;
There would no longer be a need to create a participant object for every single user in every single assignment in a course, significantly reducing the bloat that creating an assignment for an entire class could cause under the current system.&lt;br /&gt;
&lt;br /&gt;
Roles would be assigned to participants, and then assignments would handle the logic behind permissions. This provides the advantage that different assignments can control how different roles can interact with themselves independently of each other. If they could already do that, then this resolves a DRY violation where permission information is logically acted upon in both Participant and Assignment.&lt;br /&gt;
&lt;br /&gt;
Incidentally, if you were to delegate some of User's roles to participant's roles, such as instructor, then instructors could then also become participants in classes without needing to create another account with student level permissions. If you were to adopt this structure even further out to include universities, Users that are admins of one university can be students of another all under one User account.&lt;br /&gt;
&lt;br /&gt;
However, this is likely to have cascading effects on other critical systems as well. Teams may need to be entirely re organized since there are no longer unique participants per user for each assignment, as well as many other implications that we may not have been able to anticipate.&lt;br /&gt;
&lt;br /&gt;
This is not the solution that has to be used, however, we believe that it would be an improvement on the current system.&lt;br /&gt;
&lt;br /&gt;
==Team==&lt;br /&gt;
'''Mentor''' &lt;br /&gt;
&lt;br /&gt;
*Jay Patel &amp;lt;jhpatel9@ncsu.edu&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Students'''&lt;br /&gt;
&lt;br /&gt;
*Pierce Whelan &amp;lt;pwwhelan@ncsu.edu&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*Calvin Jiang &amp;lt;crjiang@ncsu.edu&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*Hechun Zhang &amp;lt;hzhang56@ncsu.edu&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Relevant Links ==&lt;br /&gt;
Pull Request [https://github.com/expertiza/reimplementation-back-end/pull/135] &amp;lt;br/&amp;gt;&lt;br /&gt;
GitHub Repository [https://github.com/Pierce57/participant_controller_reimplementation.git] &amp;lt;br/&amp;gt;&lt;br /&gt;
GitHub Project Board [https://github.com/users/Pierce57/projects/3] &amp;lt;br/&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt; participants_controller.rb &amp;lt;/code&amp;gt; in Old Expertiza [https://github.com/expertiza/expertiza/blob/main/app/controllers/participants_controller.rb] &amp;lt;br/&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt; participants_helper.rb &amp;lt;/code&amp;gt; in Old Expertiza [https://github.com/expertiza/expertiza/blob/main/app/helpers/participants_helper.rb]&lt;/div&gt;</summary>
		<author><name>Hzhang56</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2024_-_E2484._Reimplement_participants_controller.rb&amp;diff=159872</id>
		<title>CSC/ECE 517 Fall 2024 - E2484. Reimplement participants controller.rb</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2024_-_E2484._Reimplement_participants_controller.rb&amp;diff=159872"/>
		<updated>2024-12-01T03:36:12Z</updated>

		<summary type="html">&lt;p&gt;Hzhang56: /* Tests */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==About Expertiza==&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is an open source project based on [http://rubyonrails.org/ 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.&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
This project aims to reimplement the &amp;lt;code&amp;gt; participants_controller.rb &amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt; participants_helper.rb &amp;lt;/code&amp;gt; in the new Expertiza system. The &amp;lt;code&amp;gt; participants_controller.rb &amp;lt;/code&amp;gt; manages participants within assignments, and this reimplementation focuses on streamlining its methods, eliminating redundancy, and enhancing code readability and maintainability.&lt;br /&gt;
&lt;br /&gt;
==Requirements==&lt;br /&gt;
&amp;lt;li&amp;gt; Implement &amp;lt;code&amp;gt; participants_controller.rb &amp;lt;/code&amp;gt; Methods: Fully implement each controller method with the same functionality as the current controller. &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Import from &amp;lt;code&amp;gt; participants_helper.rb &amp;lt;/code&amp;gt;: Integrate relevant helper methods to streamline functionality and remove redundancy. &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; API Creation: Expose API endpoints for all necessary methods to enable seamless access and integration from the frontend. Ensure that each endpoint follows best practices for RESTful API design, including proper error handling and secure data access. &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Testing with rswag: Create test cases for all methods, focusing on edge cases, and generate rswag documentation. &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Swagger UI Video Documentation: Record a video walkthrough of API endpoints in Swagger UI, showcasing each method’s functionality. &amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Existing Issues==&lt;br /&gt;
Reimplement &amp;lt;code&amp;gt; [https://github.com/expertiza/expertiza/blob/main/app/controllers/participants_controller.rb participants_controller.rb] &amp;lt;/code&amp;gt; while addressing the following:&lt;br /&gt;
&amp;lt;li&amp;gt; Refactor code to comply with the Open-Closed Principle and the Single Responsibility Principle. &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Introduce dependency injection where necessary. &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Reduce excessive conditional statements. &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Include sufficient code tests to verify functionality. &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Enhance comments to better explain each method's functionality, purpose, and rationale for keeping or modifying particular aspects of the code. &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Provide a more detailed explanation of design choices and refactoring steps. &amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Design / Proposed Solution ==&lt;br /&gt;
===Controller Diagram===&lt;br /&gt;
[[File:Participants Controller UML Diagram.png]]&lt;br /&gt;
&lt;br /&gt;
===&amp;lt;code&amp;gt; participants_controller.rb &amp;lt;/code&amp;gt; Methods / API Calls===&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;width: 100%;&lt;br /&gt;
! &amp;amp;nbsp;#&amp;amp;nbsp; !! Method !! Endpoint !! Description &lt;br /&gt;
|-&lt;br /&gt;
|1&lt;br /&gt;
|index&lt;br /&gt;
|GET &amp;lt;code&amp;gt; /participants/user/:user_id &amp;lt;/code&amp;gt; OR &amp;lt;code&amp;gt; /participants/assignment/:assignment_id &amp;lt;/code&amp;gt;&lt;br /&gt;
|Return a list of participants for a given user or assignment&lt;br /&gt;
|-&lt;br /&gt;
|2&lt;br /&gt;
|show&lt;br /&gt;
|GET &amp;lt;code&amp;gt; /participants/:id &amp;lt;/code&amp;gt;&lt;br /&gt;
|Return a specified participant&lt;br /&gt;
|-&lt;br /&gt;
|3&lt;br /&gt;
|create&lt;br /&gt;
|POST &amp;lt;code&amp;gt; /participants &amp;lt;/code&amp;gt;&lt;br /&gt;
|Create a participant&lt;br /&gt;
|-&lt;br /&gt;
|4&lt;br /&gt;
|destroy&lt;br /&gt;
|DELETE &amp;lt;code&amp;gt; /participants/:id &amp;lt;/code&amp;gt;&lt;br /&gt;
|Delete a specified participant&lt;br /&gt;
|-&lt;br /&gt;
|5&lt;br /&gt;
|participant_params&lt;br /&gt;
| -&lt;br /&gt;
|Permitted parameters for creating a Participant object&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
The following methods were removed from &amp;lt;code&amp;gt; participants_controller.rb &amp;lt;/code&amp;gt;:&lt;br /&gt;
&amp;lt;li&amp;gt; &amp;lt;code&amp;gt; action_allowed? &amp;lt;/code&amp;gt; - No impact on functionality &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; &amp;lt;code&amp;gt; controller_locale &amp;lt;/code&amp;gt; - No impact on functionality &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; &amp;lt;code&amp;gt; update_authorizations &amp;lt;/code&amp;gt; - Since there is a direct relationship between the User and Role classes, and therefore the Participant and Role classes, it would be redundant to handle anything permissions-related here.&lt;br /&gt;
&amp;lt;li&amp;gt; &amp;lt;code&amp;gt; inherit &amp;lt;/code&amp;gt; - Since there is no direct relationship between the Participant and Course classes, this logic is redundant and no longer necessary &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; &amp;lt;code&amp;gt; bequeath_all &amp;lt;/code&amp;gt; - Since there is no direct relationship between the Participant and Course classes, this logic is redundant and no longer necessary &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; &amp;lt;code&amp;gt; change_handle &amp;lt;/code&amp;gt; - The User class has a `handle` field already. It would be redundant to have one in Participant as well.&lt;br /&gt;
&amp;lt;li&amp;gt; &amp;lt;code&amp;gt; delete &amp;lt;/code&amp;gt; - Handled in the &amp;lt;i&amp;gt; remove_participant &amp;lt;/i&amp;gt; method of the AssignmentsController (&amp;lt;code&amp;gt; assignments_controller.rb &amp;lt;/code&amp;gt;) &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; &amp;lt;code&amp;gt; view_copyright_grants &amp;lt;/code&amp;gt; - Incorrectly implemented in the old implementation &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; &amp;lt;code&amp;gt; get_user_info &amp;lt;/code&amp;gt; - All needed user data can be accessed by leveraging the Participant model's &amp;lt;i&amp;gt; belongs_to &amp;lt;/i&amp;gt; relationship to the User model &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; &amp;lt;code&amp;gt; get_signup_topics_for_assignment &amp;lt;/code&amp;gt; - Handled in the &amp;lt;i&amp;gt; index &amp;lt;/i&amp;gt; method of the SignUpTopicsController (&amp;lt;code&amp;gt; sign_up_topics_controller.rb &amp;lt;/code&amp;gt;) &amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===&amp;lt;code&amp;gt; participants_helper.rb &amp;lt;/code&amp;gt; Methods===&lt;br /&gt;
The methods in &amp;lt;code&amp;gt;participants_helper.rb&amp;lt;/code&amp;gt; are outdated and do not impact any functionality in &amp;lt;code&amp;gt;participants_controller.rb&amp;lt;/code&amp;gt;. &amp;lt;br/&amp;gt;&lt;br /&gt;
As a result, these methods will not be carried forward to the new implementation:&lt;br /&gt;
&amp;lt;li&amp;gt; &amp;lt;code&amp;gt; upload_users &amp;lt;/code&amp;gt; - Logic for creating a User specifically for the Assignment and Course classes. Since there is no direct relationship between the User and these classes, this logic is redundant and no longer necessary &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; &amp;lt;code&amp;gt; define_attributes &amp;lt;/code&amp;gt; - &amp;lt;i&amp;gt; Same reason as above &amp;lt;/i&amp;gt; &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; &amp;lt;code&amp;gt; define_user &amp;lt;/code&amp;gt; - &amp;lt;i&amp;gt; Same reason as above &amp;lt;/i&amp;gt; &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; &amp;lt;code&amp;gt; create_new_user &amp;lt;/code&amp;gt; - &amp;lt;i&amp;gt; Same reason as above &amp;lt;/i&amp;gt; &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; &amp;lt;code&amp;gt; add_user_to_assignment &amp;lt;/code&amp;gt; - &amp;lt;i&amp;gt; Same reason as above. &amp;lt;/i&amp;gt; Furthermore, since the Participant and Assignment classes are directly related, this functionality has been replaced by the &amp;lt;i&amp;gt; add_participant &amp;lt;/i&amp;gt; method in AssignmentsController (&amp;lt;code&amp;gt;assignments_controller.rb&amp;lt;/code&amp;gt;) &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; &amp;lt;code&amp;gt; add_user_to_course &amp;lt;/code&amp;gt; - &amp;lt;i&amp;gt; Same reason as above &amp;lt;/i&amp;gt; &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; &amp;lt;code&amp;gt; get_config &amp;lt;/code&amp;gt; - &amp;lt;i&amp;gt; Same reason as above &amp;lt;/i&amp;gt; &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; &amp;lt;code&amp;gt; store_item &amp;lt;/code&amp;gt; - &amp;lt;i&amp;gt; Same reason as above &amp;lt;/i&amp;gt; &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; &amp;lt;code&amp;gt; participant_permissions &amp;lt;/code&amp;gt; - Outdated way of updating permissions, handled more effectively by the &amp;lt;code&amp;gt;update_permissions&amp;lt;/code&amp;gt; method in ParticipantsController (&amp;lt;code&amp;gt;participants_controller.rb&amp;lt;/code&amp;gt;) &amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Pattern(s)===&lt;br /&gt;
'''Facade''': &amp;quot;A simplified interface that performs many other actions behind the scenes.&amp;quot; &amp;lt;br/&amp;gt;&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
===SOLID Principle(s)===&lt;br /&gt;
'''Open and Closed Principle''': &amp;quot;Software entities should be open for extension, but closed for modification.&amp;quot;&amp;lt;br/&amp;gt;&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
'''Single Responsibility Principle''': &amp;quot;A class should only have one responsibility and should never have more than one reason to change.&amp;quot;&amp;lt;br/&amp;gt;&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
==Implementation==&lt;br /&gt;
===Implement &amp;lt;code&amp;gt; participants_controller.rb &amp;lt;/code&amp;gt; Methods===&lt;br /&gt;
Refer to the [https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2024_-_E2484._Reimplement_participants_controller.rb#participants_controller.rb_Methods_/_API_Calls &amp;lt;code&amp;gt; participants_controller.rb &amp;lt;/code&amp;gt; Methods / API Calls] section for a brief overview of its use &amp;lt;br/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|+&lt;br /&gt;
! Old Method Name !! Action !! New Method Name&lt;br /&gt;
|-&lt;br /&gt;
| action_allowed? || Removed || -&lt;br /&gt;
|-&lt;br /&gt;
| controller_locale || Removed || -&lt;br /&gt;
|-&lt;br /&gt;
| list || Renamed || index&lt;br /&gt;
|-&lt;br /&gt;
| add || Renamed || create&lt;br /&gt;
|-&lt;br /&gt;
| update_authorizations || Removed || -&lt;br /&gt;
|-&lt;br /&gt;
| destroy || No Change || destroy&lt;br /&gt;
|-&lt;br /&gt;
| inherit || Removed || -&lt;br /&gt;
|-&lt;br /&gt;
| bequeath_all || Removed || -&lt;br /&gt;
|-&lt;br /&gt;
| change_handle || Removed || -&lt;br /&gt;
|-&lt;br /&gt;
| delete || Removed || -&lt;br /&gt;
|-&lt;br /&gt;
| view_copyright_grants || Removed || -&lt;br /&gt;
|-&lt;br /&gt;
| participant_params || No Change || participant_params&lt;br /&gt;
|-&lt;br /&gt;
| get_user_info || Removed || -&lt;br /&gt;
|-&lt;br /&gt;
| get_signup_topics_for_assignment || Removed || -&lt;br /&gt;
|-&lt;br /&gt;
| - || Added || show&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;code&amp;gt;index&amp;lt;/code&amp;gt; Method====&lt;br /&gt;
Description:&lt;br /&gt;
&lt;br /&gt;
Retrieves and returns a list of participant objects. The returned participants depend on the provided filters. Specifically:&lt;br /&gt;
* If a &amp;lt;code&amp;gt;user_id&amp;lt;/code&amp;gt; (optional) is provided in the parameters, it returns all participants associated with that user.&lt;br /&gt;
* If an &amp;lt;code&amp;gt;assignment_id&amp;lt;/code&amp;gt; (optional) is provided, it returns all participants related to that assignment.&lt;br /&gt;
&lt;br /&gt;
Parameters:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;user_id&amp;lt;/code&amp;gt;: The ID of the user whose participants you want to retrieve. If the user does not exist, the method returns without further action. &amp;lt;br/&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;assignment_id&amp;lt;/code&amp;gt;: The ID of the assignment whose participants you want to retrieve. If the assignment does not exist, the method returns without further action.&lt;br /&gt;
&lt;br /&gt;
Behavior:&lt;br /&gt;
&lt;br /&gt;
The method validates the presence and existence of the &amp;lt;code&amp;gt;user_id&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;assignment_id&amp;lt;/code&amp;gt;. If either is invalid (i.e., the corresponding user or assignment doesn't exist), the method stops execution and does not proceed with participant retrieval. If a valid user or assignment is provided, then it will retrieve all participants and filter in the ones of the provided user or assignment. The final filtered list of participants is returned as a JSON response.&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;code&amp;gt;create&amp;lt;/code&amp;gt; Method====&lt;br /&gt;
&lt;br /&gt;
Description:&lt;br /&gt;
&lt;br /&gt;
Creates a new participant associated with a specific user and assignment. This method validates the presence of the user and assignment before creating the participant.&lt;br /&gt;
&lt;br /&gt;
Parameters:&lt;br /&gt;
&lt;br /&gt;
*&amp;lt;code&amp;gt;user_id&amp;lt;/code&amp;gt; (required, from request parameters): The ID of the user who will be associated with the participant.&lt;br /&gt;
*&amp;lt;code&amp;gt;assignment_id&amp;lt;/code&amp;gt; (required, from request parameters): The ID of the assignment to link with the participant.&lt;br /&gt;
&lt;br /&gt;
Behavior:&lt;br /&gt;
&lt;br /&gt;
*Validates and retrieves the user based on the provided &amp;lt;code&amp;gt;user_id&amp;lt;/code&amp;gt;. If the user is not found, the method terminates.&lt;br /&gt;
*Validates and retrieves the assignment based on the provided &amp;lt;code&amp;gt;assignment_id&amp;lt;/code&amp;gt;. If the assignment is not found, the method terminates.&lt;br /&gt;
*Builds a new Participant instance linked to the validated user and assignment.&lt;br /&gt;
*Attempts to save the Participant:&lt;br /&gt;
**If successful: Returns a JSON response containing the created Participant and a 201 Created status.&lt;br /&gt;
**If unsuccessful: Returns a JSON response containing validation errors and a 422 Unprocessable Entity status.&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;code&amp;gt;destroy&amp;lt;/code&amp;gt; Method====&lt;br /&gt;
&lt;br /&gt;
Description:&lt;br /&gt;
&lt;br /&gt;
Deletes a specified Participant based on the provided ID.&lt;br /&gt;
&lt;br /&gt;
Parameters:&lt;br /&gt;
&lt;br /&gt;
*&amp;lt;code&amp;gt;id&amp;lt;/code&amp;gt; (required): The ID of the Participant to be deleted.&lt;br /&gt;
&lt;br /&gt;
Behavior:&lt;br /&gt;
&lt;br /&gt;
*Retrieves the Participant using the provided &amp;lt;code&amp;gt;id&amp;lt;/code&amp;gt;.&lt;br /&gt;
*Attempts to delete the Participant:&lt;br /&gt;
**If successful: Returns a JSON response containing a confirmation message and a 200 OK status.&lt;br /&gt;
**If unsuccessful: Returns a JSON response containing validation errors and a 422 Unprocessable Entity status.&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;code&amp;gt;show&amp;lt;/code&amp;gt; Method====&lt;br /&gt;
&lt;br /&gt;
Description:&lt;br /&gt;
&lt;br /&gt;
Retrieves and returns a specific Participant based on the provided ID.&lt;br /&gt;
&lt;br /&gt;
Parameters:&lt;br /&gt;
&lt;br /&gt;
*&amp;lt;code&amp;gt;id&amp;lt;/code&amp;gt; (required): The ID of the Participant to be retrieved.&lt;br /&gt;
&lt;br /&gt;
Behavior:&lt;br /&gt;
&lt;br /&gt;
*Fetches the Participant from the database using the provided &amp;lt;code&amp;gt;id&amp;lt;/code&amp;gt;.&lt;br /&gt;
*Attempts to fetch the Participant:&lt;br /&gt;
**If successful: Returns a JSON response containing a confirmation message and a 200 OK status.&lt;br /&gt;
**If unsuccessful: Returns a JSON response containing validation errors and a 422 Unprocessable Entity status.&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;code&amp;gt;participant_params&amp;lt;/code&amp;gt; Method====&lt;br /&gt;
&lt;br /&gt;
Description:&lt;br /&gt;
&lt;br /&gt;
Defines the permitted parameters for creating or updating a Participant object.&lt;br /&gt;
&lt;br /&gt;
Parameters:&lt;br /&gt;
&lt;br /&gt;
The method expects a Participant object within the request parameters. It permits the following attributes:&lt;br /&gt;
&lt;br /&gt;
*&amp;lt;code&amp;gt;user_id&amp;lt;/code&amp;gt; (required): The ID of the user associated with the Participant.&lt;br /&gt;
*&amp;lt;code&amp;gt;assignment_id&amp;lt;/code&amp;gt; (required): The ID of the assignment linked to the Participant.&lt;br /&gt;
*&amp;lt;code&amp;gt;team_id&amp;lt;/code&amp;gt; (optional): The ID of the team the Participant belongs to.&lt;br /&gt;
*&amp;lt;code&amp;gt;join_team_request_id&amp;lt;/code&amp;gt; (optional): The ID of any pending team join request related to the Participant.&lt;br /&gt;
*&amp;lt;code&amp;gt;permission_granted&amp;lt;/code&amp;gt; (optional): A boolean indicating whether the Participant has specific permissions granted.&lt;br /&gt;
*&amp;lt;code&amp;gt;topic&amp;lt;/code&amp;gt; (optional): The topic assigned to the Participant (could be a string or other data type depending on the application context).&lt;br /&gt;
*&amp;lt;code&amp;gt;current_stage&amp;lt;/code&amp;gt; (optional): The current progress stage of the Participant.&lt;br /&gt;
*&amp;lt;code&amp;gt;stage_deadline&amp;lt;/code&amp;gt; (optional): The deadline for the current stage.&lt;br /&gt;
&lt;br /&gt;
Behavior:&lt;br /&gt;
&lt;br /&gt;
*Ensures that only allowed parameters are passed when creating a Participant object.&lt;br /&gt;
&lt;br /&gt;
===Import from &amp;lt;code&amp;gt; participants_helper.rb &amp;lt;/code&amp;gt;===&lt;br /&gt;
Refer to the [https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2024_-_E2484._Reimplement_participants_controller.rb#participants_helper.rb_Methods &amp;lt;code&amp;gt; participants_helper.rb &amp;lt;/code&amp;gt; Methods] section for all design-related inquiries &amp;lt;br/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|+&lt;br /&gt;
! Old Method Name !! Action !! New Method Name&lt;br /&gt;
|-&lt;br /&gt;
| upload_users || Removed || -&lt;br /&gt;
|-&lt;br /&gt;
| define_attributes || Removed || -&lt;br /&gt;
|-&lt;br /&gt;
| define_user || Removed || -&lt;br /&gt;
|-&lt;br /&gt;
| create_new_user || Removed || -&lt;br /&gt;
|-&lt;br /&gt;
| add_user_to_assignment || Removed || -&lt;br /&gt;
|-&lt;br /&gt;
| add_user_to_course || Removed || -&lt;br /&gt;
|-&lt;br /&gt;
| get_config || Removed || -&lt;br /&gt;
|-&lt;br /&gt;
| store_item || Removed || -&lt;br /&gt;
|-&lt;br /&gt;
| participant_permissions || Removed || -&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===Model===&lt;br /&gt;
The following unnecessary and redundant database columns have been removed from the participants model entirely.&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|+&lt;br /&gt;
! Column Name !! Reason for removal&lt;br /&gt;
|-&lt;br /&gt;
|can_submit || Redundant as this is already handled by Role.&lt;br /&gt;
|-&lt;br /&gt;
|can_review || Redundant as this is already handled by Role.&lt;br /&gt;
|-&lt;br /&gt;
|handle || Redundant as this is already handled by User.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===API Creation===&lt;br /&gt;
Refer to the [https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2024_-_E2484._Reimplement_participants_controller.rb#participants_controller.rb_Methods_/_API_Calls &amp;lt;code&amp;gt; participants_controller.rb &amp;lt;/code&amp;gt; Methods / API Calls] section for all design-related inquiries &amp;lt;br/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Testing with rswag===&lt;br /&gt;
Refer to the [https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2024_-_E2484._Reimplement_participants_controller.rb#Testing_Plan Testing Plan] section &amp;lt;br/&amp;gt;&lt;br /&gt;
&amp;lt;i&amp;gt; To be expanded upon during implementation &amp;lt;/i&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Swagger UI Video Documentation===&lt;br /&gt;
&amp;lt;i&amp;gt; To be added at a later time &amp;lt;/i&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Testing Plan==&lt;br /&gt;
'''rswag'''&amp;lt;br/&amp;gt;&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
====Tests====&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;margin-left:40px&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Test ID !! Test Description &lt;br /&gt;
|-&lt;br /&gt;
| 1 || Test 'index' with valid model (Assignment) and ID - Should list participants&lt;br /&gt;
|-&lt;br /&gt;
| 2 || Test 'index' with invalid model (Assignment) and ID - Should return an error message&lt;br /&gt;
|-&lt;br /&gt;
| 3 || Test 'index' when there are no participants - Should return an empty list&lt;br /&gt;
|-&lt;br /&gt;
| 4 || Test 'show' with valid participant ID - Should return the specified participant details&lt;br /&gt;
|-&lt;br /&gt;
| 5 || Test 'show' with invalid participant ID - Should return participant not found&lt;br /&gt;
|-&lt;br /&gt;
| 6 || Test 'create' with valid user detail - Should successfully create a new participant&lt;br /&gt;
|-&lt;br /&gt;
| 7 || Test 'create' with duplicate user information - Should return an error message indicating that the participant already exists&lt;br /&gt;
|-&lt;br /&gt;
| 8 || Test 'create' with invalid data format - Should return a validation error&lt;br /&gt;
|-&lt;br /&gt;
| 9 || Test 'destroy' with valid participant ID - Should delete the specified participant&lt;br /&gt;
|-&lt;br /&gt;
| 10 || Test 'destroy' with invalid participant ID - Should return participant not found message&lt;br /&gt;
|-&lt;br /&gt;
| 11 || Test 'destroy for participant who has associated records - Should return an error message or handle the cascading deletions&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==Team==&lt;br /&gt;
'''Mentor''' &lt;br /&gt;
&lt;br /&gt;
*Jay Patel &amp;lt;jhpatel9@ncsu.edu&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Students'''&lt;br /&gt;
&lt;br /&gt;
*Pierce Whelan &amp;lt;pwwhelan@ncsu.edu&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*Calvin Jiang &amp;lt;crjiang@ncsu.edu&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*Hechun Zhang &amp;lt;hzhang56@ncsu.edu&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Relevant Links ==&lt;br /&gt;
Pull Request [https://github.com/expertiza/reimplementation-back-end/pull/135] &amp;lt;br/&amp;gt;&lt;br /&gt;
GitHub Repository [https://github.com/Pierce57/participant_controller_reimplementation.git] &amp;lt;br/&amp;gt;&lt;br /&gt;
GitHub Project Board [https://github.com/users/Pierce57/projects/3] &amp;lt;br/&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt; participants_controller.rb &amp;lt;/code&amp;gt; in Old Expertiza [https://github.com/expertiza/expertiza/blob/main/app/controllers/participants_controller.rb] &amp;lt;br/&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt; participants_helper.rb &amp;lt;/code&amp;gt; in Old Expertiza [https://github.com/expertiza/expertiza/blob/main/app/helpers/participants_helper.rb]&lt;/div&gt;</summary>
		<author><name>Hzhang56</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2024_-_E2484._Reimplement_participants_controller.rb&amp;diff=159871</id>
		<title>CSC/ECE 517 Fall 2024 - E2484. Reimplement participants controller.rb</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2024_-_E2484._Reimplement_participants_controller.rb&amp;diff=159871"/>
		<updated>2024-12-01T03:33:16Z</updated>

		<summary type="html">&lt;p&gt;Hzhang56: /*  participants_controller.rb  Methods / API Calls */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==About Expertiza==&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is an open source project based on [http://rubyonrails.org/ 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.&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
This project aims to reimplement the &amp;lt;code&amp;gt; participants_controller.rb &amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt; participants_helper.rb &amp;lt;/code&amp;gt; in the new Expertiza system. The &amp;lt;code&amp;gt; participants_controller.rb &amp;lt;/code&amp;gt; manages participants within assignments, and this reimplementation focuses on streamlining its methods, eliminating redundancy, and enhancing code readability and maintainability.&lt;br /&gt;
&lt;br /&gt;
==Requirements==&lt;br /&gt;
&amp;lt;li&amp;gt; Implement &amp;lt;code&amp;gt; participants_controller.rb &amp;lt;/code&amp;gt; Methods: Fully implement each controller method with the same functionality as the current controller. &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Import from &amp;lt;code&amp;gt; participants_helper.rb &amp;lt;/code&amp;gt;: Integrate relevant helper methods to streamline functionality and remove redundancy. &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; API Creation: Expose API endpoints for all necessary methods to enable seamless access and integration from the frontend. Ensure that each endpoint follows best practices for RESTful API design, including proper error handling and secure data access. &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Testing with rswag: Create test cases for all methods, focusing on edge cases, and generate rswag documentation. &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Swagger UI Video Documentation: Record a video walkthrough of API endpoints in Swagger UI, showcasing each method’s functionality. &amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Existing Issues==&lt;br /&gt;
Reimplement &amp;lt;code&amp;gt; [https://github.com/expertiza/expertiza/blob/main/app/controllers/participants_controller.rb participants_controller.rb] &amp;lt;/code&amp;gt; while addressing the following:&lt;br /&gt;
&amp;lt;li&amp;gt; Refactor code to comply with the Open-Closed Principle and the Single Responsibility Principle. &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Introduce dependency injection where necessary. &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Reduce excessive conditional statements. &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Include sufficient code tests to verify functionality. &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Enhance comments to better explain each method's functionality, purpose, and rationale for keeping or modifying particular aspects of the code. &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Provide a more detailed explanation of design choices and refactoring steps. &amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Design / Proposed Solution ==&lt;br /&gt;
===Controller Diagram===&lt;br /&gt;
[[File:Participants Controller UML Diagram.png]]&lt;br /&gt;
&lt;br /&gt;
===&amp;lt;code&amp;gt; participants_controller.rb &amp;lt;/code&amp;gt; Methods / API Calls===&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;width: 100%;&lt;br /&gt;
! &amp;amp;nbsp;#&amp;amp;nbsp; !! Method !! Endpoint !! Description &lt;br /&gt;
|-&lt;br /&gt;
|1&lt;br /&gt;
|index&lt;br /&gt;
|GET &amp;lt;code&amp;gt; /participants/user/:user_id &amp;lt;/code&amp;gt; OR &amp;lt;code&amp;gt; /participants/assignment/:assignment_id &amp;lt;/code&amp;gt;&lt;br /&gt;
|Return a list of participants for a given user or assignment&lt;br /&gt;
|-&lt;br /&gt;
|2&lt;br /&gt;
|show&lt;br /&gt;
|GET &amp;lt;code&amp;gt; /participants/:id &amp;lt;/code&amp;gt;&lt;br /&gt;
|Return a specified participant&lt;br /&gt;
|-&lt;br /&gt;
|3&lt;br /&gt;
|create&lt;br /&gt;
|POST &amp;lt;code&amp;gt; /participants &amp;lt;/code&amp;gt;&lt;br /&gt;
|Create a participant&lt;br /&gt;
|-&lt;br /&gt;
|4&lt;br /&gt;
|destroy&lt;br /&gt;
|DELETE &amp;lt;code&amp;gt; /participants/:id &amp;lt;/code&amp;gt;&lt;br /&gt;
|Delete a specified participant&lt;br /&gt;
|-&lt;br /&gt;
|5&lt;br /&gt;
|participant_params&lt;br /&gt;
| -&lt;br /&gt;
|Permitted parameters for creating a Participant object&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
The following methods were removed from &amp;lt;code&amp;gt; participants_controller.rb &amp;lt;/code&amp;gt;:&lt;br /&gt;
&amp;lt;li&amp;gt; &amp;lt;code&amp;gt; action_allowed? &amp;lt;/code&amp;gt; - No impact on functionality &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; &amp;lt;code&amp;gt; controller_locale &amp;lt;/code&amp;gt; - No impact on functionality &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; &amp;lt;code&amp;gt; update_authorizations &amp;lt;/code&amp;gt; - Since there is a direct relationship between the User and Role classes, and therefore the Participant and Role classes, it would be redundant to handle anything permissions-related here.&lt;br /&gt;
&amp;lt;li&amp;gt; &amp;lt;code&amp;gt; inherit &amp;lt;/code&amp;gt; - Since there is no direct relationship between the Participant and Course classes, this logic is redundant and no longer necessary &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; &amp;lt;code&amp;gt; bequeath_all &amp;lt;/code&amp;gt; - Since there is no direct relationship between the Participant and Course classes, this logic is redundant and no longer necessary &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; &amp;lt;code&amp;gt; change_handle &amp;lt;/code&amp;gt; - The User class has a `handle` field already. It would be redundant to have one in Participant as well.&lt;br /&gt;
&amp;lt;li&amp;gt; &amp;lt;code&amp;gt; delete &amp;lt;/code&amp;gt; - Handled in the &amp;lt;i&amp;gt; remove_participant &amp;lt;/i&amp;gt; method of the AssignmentsController (&amp;lt;code&amp;gt; assignments_controller.rb &amp;lt;/code&amp;gt;) &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; &amp;lt;code&amp;gt; view_copyright_grants &amp;lt;/code&amp;gt; - Incorrectly implemented in the old implementation &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; &amp;lt;code&amp;gt; get_user_info &amp;lt;/code&amp;gt; - All needed user data can be accessed by leveraging the Participant model's &amp;lt;i&amp;gt; belongs_to &amp;lt;/i&amp;gt; relationship to the User model &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; &amp;lt;code&amp;gt; get_signup_topics_for_assignment &amp;lt;/code&amp;gt; - Handled in the &amp;lt;i&amp;gt; index &amp;lt;/i&amp;gt; method of the SignUpTopicsController (&amp;lt;code&amp;gt; sign_up_topics_controller.rb &amp;lt;/code&amp;gt;) &amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===&amp;lt;code&amp;gt; participants_helper.rb &amp;lt;/code&amp;gt; Methods===&lt;br /&gt;
The methods in &amp;lt;code&amp;gt;participants_helper.rb&amp;lt;/code&amp;gt; are outdated and do not impact any functionality in &amp;lt;code&amp;gt;participants_controller.rb&amp;lt;/code&amp;gt;. &amp;lt;br/&amp;gt;&lt;br /&gt;
As a result, these methods will not be carried forward to the new implementation:&lt;br /&gt;
&amp;lt;li&amp;gt; &amp;lt;code&amp;gt; upload_users &amp;lt;/code&amp;gt; - Logic for creating a User specifically for the Assignment and Course classes. Since there is no direct relationship between the User and these classes, this logic is redundant and no longer necessary &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; &amp;lt;code&amp;gt; define_attributes &amp;lt;/code&amp;gt; - &amp;lt;i&amp;gt; Same reason as above &amp;lt;/i&amp;gt; &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; &amp;lt;code&amp;gt; define_user &amp;lt;/code&amp;gt; - &amp;lt;i&amp;gt; Same reason as above &amp;lt;/i&amp;gt; &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; &amp;lt;code&amp;gt; create_new_user &amp;lt;/code&amp;gt; - &amp;lt;i&amp;gt; Same reason as above &amp;lt;/i&amp;gt; &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; &amp;lt;code&amp;gt; add_user_to_assignment &amp;lt;/code&amp;gt; - &amp;lt;i&amp;gt; Same reason as above. &amp;lt;/i&amp;gt; Furthermore, since the Participant and Assignment classes are directly related, this functionality has been replaced by the &amp;lt;i&amp;gt; add_participant &amp;lt;/i&amp;gt; method in AssignmentsController (&amp;lt;code&amp;gt;assignments_controller.rb&amp;lt;/code&amp;gt;) &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; &amp;lt;code&amp;gt; add_user_to_course &amp;lt;/code&amp;gt; - &amp;lt;i&amp;gt; Same reason as above &amp;lt;/i&amp;gt; &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; &amp;lt;code&amp;gt; get_config &amp;lt;/code&amp;gt; - &amp;lt;i&amp;gt; Same reason as above &amp;lt;/i&amp;gt; &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; &amp;lt;code&amp;gt; store_item &amp;lt;/code&amp;gt; - &amp;lt;i&amp;gt; Same reason as above &amp;lt;/i&amp;gt; &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; &amp;lt;code&amp;gt; participant_permissions &amp;lt;/code&amp;gt; - Outdated way of updating permissions, handled more effectively by the &amp;lt;code&amp;gt;update_permissions&amp;lt;/code&amp;gt; method in ParticipantsController (&amp;lt;code&amp;gt;participants_controller.rb&amp;lt;/code&amp;gt;) &amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Pattern(s)===&lt;br /&gt;
'''Facade''': &amp;quot;A simplified interface that performs many other actions behind the scenes.&amp;quot; &amp;lt;br/&amp;gt;&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
===SOLID Principle(s)===&lt;br /&gt;
'''Open and Closed Principle''': &amp;quot;Software entities should be open for extension, but closed for modification.&amp;quot;&amp;lt;br/&amp;gt;&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
'''Single Responsibility Principle''': &amp;quot;A class should only have one responsibility and should never have more than one reason to change.&amp;quot;&amp;lt;br/&amp;gt;&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
==Implementation==&lt;br /&gt;
===Implement &amp;lt;code&amp;gt; participants_controller.rb &amp;lt;/code&amp;gt; Methods===&lt;br /&gt;
Refer to the [https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2024_-_E2484._Reimplement_participants_controller.rb#participants_controller.rb_Methods_/_API_Calls &amp;lt;code&amp;gt; participants_controller.rb &amp;lt;/code&amp;gt; Methods / API Calls] section for a brief overview of its use &amp;lt;br/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|+&lt;br /&gt;
! Old Method Name !! Action !! New Method Name&lt;br /&gt;
|-&lt;br /&gt;
| action_allowed? || Removed || -&lt;br /&gt;
|-&lt;br /&gt;
| controller_locale || Removed || -&lt;br /&gt;
|-&lt;br /&gt;
| list || Renamed || index&lt;br /&gt;
|-&lt;br /&gt;
| add || Renamed || create&lt;br /&gt;
|-&lt;br /&gt;
| update_authorizations || Removed || -&lt;br /&gt;
|-&lt;br /&gt;
| destroy || No Change || destroy&lt;br /&gt;
|-&lt;br /&gt;
| inherit || Removed || -&lt;br /&gt;
|-&lt;br /&gt;
| bequeath_all || Removed || -&lt;br /&gt;
|-&lt;br /&gt;
| change_handle || Removed || -&lt;br /&gt;
|-&lt;br /&gt;
| delete || Removed || -&lt;br /&gt;
|-&lt;br /&gt;
| view_copyright_grants || Removed || -&lt;br /&gt;
|-&lt;br /&gt;
| participant_params || No Change || participant_params&lt;br /&gt;
|-&lt;br /&gt;
| get_user_info || Removed || -&lt;br /&gt;
|-&lt;br /&gt;
| get_signup_topics_for_assignment || Removed || -&lt;br /&gt;
|-&lt;br /&gt;
| - || Added || show&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;code&amp;gt;index&amp;lt;/code&amp;gt; Method====&lt;br /&gt;
Description:&lt;br /&gt;
&lt;br /&gt;
Retrieves and returns a list of participant objects. The returned participants depend on the provided filters. Specifically:&lt;br /&gt;
* If a &amp;lt;code&amp;gt;user_id&amp;lt;/code&amp;gt; (optional) is provided in the parameters, it returns all participants associated with that user.&lt;br /&gt;
* If an &amp;lt;code&amp;gt;assignment_id&amp;lt;/code&amp;gt; (optional) is provided, it returns all participants related to that assignment.&lt;br /&gt;
&lt;br /&gt;
Parameters:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;user_id&amp;lt;/code&amp;gt;: The ID of the user whose participants you want to retrieve. If the user does not exist, the method returns without further action. &amp;lt;br/&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;assignment_id&amp;lt;/code&amp;gt;: The ID of the assignment whose participants you want to retrieve. If the assignment does not exist, the method returns without further action.&lt;br /&gt;
&lt;br /&gt;
Behavior:&lt;br /&gt;
&lt;br /&gt;
The method validates the presence and existence of the &amp;lt;code&amp;gt;user_id&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;assignment_id&amp;lt;/code&amp;gt;. If either is invalid (i.e., the corresponding user or assignment doesn't exist), the method stops execution and does not proceed with participant retrieval. If a valid user or assignment is provided, then it will retrieve all participants and filter in the ones of the provided user or assignment. The final filtered list of participants is returned as a JSON response.&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;code&amp;gt;create&amp;lt;/code&amp;gt; Method====&lt;br /&gt;
&lt;br /&gt;
Description:&lt;br /&gt;
&lt;br /&gt;
Creates a new participant associated with a specific user and assignment. This method validates the presence of the user and assignment before creating the participant.&lt;br /&gt;
&lt;br /&gt;
Parameters:&lt;br /&gt;
&lt;br /&gt;
*&amp;lt;code&amp;gt;user_id&amp;lt;/code&amp;gt; (required, from request parameters): The ID of the user who will be associated with the participant.&lt;br /&gt;
*&amp;lt;code&amp;gt;assignment_id&amp;lt;/code&amp;gt; (required, from request parameters): The ID of the assignment to link with the participant.&lt;br /&gt;
&lt;br /&gt;
Behavior:&lt;br /&gt;
&lt;br /&gt;
*Validates and retrieves the user based on the provided &amp;lt;code&amp;gt;user_id&amp;lt;/code&amp;gt;. If the user is not found, the method terminates.&lt;br /&gt;
*Validates and retrieves the assignment based on the provided &amp;lt;code&amp;gt;assignment_id&amp;lt;/code&amp;gt;. If the assignment is not found, the method terminates.&lt;br /&gt;
*Builds a new Participant instance linked to the validated user and assignment.&lt;br /&gt;
*Attempts to save the Participant:&lt;br /&gt;
**If successful: Returns a JSON response containing the created Participant and a 201 Created status.&lt;br /&gt;
**If unsuccessful: Returns a JSON response containing validation errors and a 422 Unprocessable Entity status.&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;code&amp;gt;destroy&amp;lt;/code&amp;gt; Method====&lt;br /&gt;
&lt;br /&gt;
Description:&lt;br /&gt;
&lt;br /&gt;
Deletes a specified Participant based on the provided ID.&lt;br /&gt;
&lt;br /&gt;
Parameters:&lt;br /&gt;
&lt;br /&gt;
*&amp;lt;code&amp;gt;id&amp;lt;/code&amp;gt; (required): The ID of the Participant to be deleted.&lt;br /&gt;
&lt;br /&gt;
Behavior:&lt;br /&gt;
&lt;br /&gt;
*Retrieves the Participant using the provided &amp;lt;code&amp;gt;id&amp;lt;/code&amp;gt;.&lt;br /&gt;
*Attempts to delete the Participant:&lt;br /&gt;
**If successful: Returns a JSON response containing a confirmation message and a 200 OK status.&lt;br /&gt;
**If unsuccessful: Returns a JSON response containing validation errors and a 422 Unprocessable Entity status.&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;code&amp;gt;show&amp;lt;/code&amp;gt; Method====&lt;br /&gt;
&lt;br /&gt;
Description:&lt;br /&gt;
&lt;br /&gt;
Retrieves and returns a specific Participant based on the provided ID.&lt;br /&gt;
&lt;br /&gt;
Parameters:&lt;br /&gt;
&lt;br /&gt;
*&amp;lt;code&amp;gt;id&amp;lt;/code&amp;gt; (required): The ID of the Participant to be retrieved.&lt;br /&gt;
&lt;br /&gt;
Behavior:&lt;br /&gt;
&lt;br /&gt;
*Fetches the Participant from the database using the provided &amp;lt;code&amp;gt;id&amp;lt;/code&amp;gt;.&lt;br /&gt;
*Attempts to fetch the Participant:&lt;br /&gt;
**If successful: Returns a JSON response containing a confirmation message and a 200 OK status.&lt;br /&gt;
**If unsuccessful: Returns a JSON response containing validation errors and a 422 Unprocessable Entity status.&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;code&amp;gt;participant_params&amp;lt;/code&amp;gt; Method====&lt;br /&gt;
&lt;br /&gt;
Description:&lt;br /&gt;
&lt;br /&gt;
Defines the permitted parameters for creating or updating a Participant object.&lt;br /&gt;
&lt;br /&gt;
Parameters:&lt;br /&gt;
&lt;br /&gt;
The method expects a Participant object within the request parameters. It permits the following attributes:&lt;br /&gt;
&lt;br /&gt;
*&amp;lt;code&amp;gt;user_id&amp;lt;/code&amp;gt; (required): The ID of the user associated with the Participant.&lt;br /&gt;
*&amp;lt;code&amp;gt;assignment_id&amp;lt;/code&amp;gt; (required): The ID of the assignment linked to the Participant.&lt;br /&gt;
*&amp;lt;code&amp;gt;team_id&amp;lt;/code&amp;gt; (optional): The ID of the team the Participant belongs to.&lt;br /&gt;
*&amp;lt;code&amp;gt;join_team_request_id&amp;lt;/code&amp;gt; (optional): The ID of any pending team join request related to the Participant.&lt;br /&gt;
*&amp;lt;code&amp;gt;permission_granted&amp;lt;/code&amp;gt; (optional): A boolean indicating whether the Participant has specific permissions granted.&lt;br /&gt;
*&amp;lt;code&amp;gt;topic&amp;lt;/code&amp;gt; (optional): The topic assigned to the Participant (could be a string or other data type depending on the application context).&lt;br /&gt;
*&amp;lt;code&amp;gt;current_stage&amp;lt;/code&amp;gt; (optional): The current progress stage of the Participant.&lt;br /&gt;
*&amp;lt;code&amp;gt;stage_deadline&amp;lt;/code&amp;gt; (optional): The deadline for the current stage.&lt;br /&gt;
&lt;br /&gt;
Behavior:&lt;br /&gt;
&lt;br /&gt;
*Ensures that only allowed parameters are passed when creating a Participant object.&lt;br /&gt;
&lt;br /&gt;
===Import from &amp;lt;code&amp;gt; participants_helper.rb &amp;lt;/code&amp;gt;===&lt;br /&gt;
Refer to the [https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2024_-_E2484._Reimplement_participants_controller.rb#participants_helper.rb_Methods &amp;lt;code&amp;gt; participants_helper.rb &amp;lt;/code&amp;gt; Methods] section for all design-related inquiries &amp;lt;br/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|+&lt;br /&gt;
! Old Method Name !! Action !! New Method Name&lt;br /&gt;
|-&lt;br /&gt;
| upload_users || Removed || -&lt;br /&gt;
|-&lt;br /&gt;
| define_attributes || Removed || -&lt;br /&gt;
|-&lt;br /&gt;
| define_user || Removed || -&lt;br /&gt;
|-&lt;br /&gt;
| create_new_user || Removed || -&lt;br /&gt;
|-&lt;br /&gt;
| add_user_to_assignment || Removed || -&lt;br /&gt;
|-&lt;br /&gt;
| add_user_to_course || Removed || -&lt;br /&gt;
|-&lt;br /&gt;
| get_config || Removed || -&lt;br /&gt;
|-&lt;br /&gt;
| store_item || Removed || -&lt;br /&gt;
|-&lt;br /&gt;
| participant_permissions || Removed || -&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===Model===&lt;br /&gt;
The following unnecessary and redundant database columns have been removed from the participants model entirely.&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|+&lt;br /&gt;
! Column Name !! Reason for removal&lt;br /&gt;
|-&lt;br /&gt;
|can_submit || Redundant as this is already handled by Role.&lt;br /&gt;
|-&lt;br /&gt;
|can_review || Redundant as this is already handled by Role.&lt;br /&gt;
|-&lt;br /&gt;
|handle || Redundant as this is already handled by User.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===API Creation===&lt;br /&gt;
Refer to the [https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2024_-_E2484._Reimplement_participants_controller.rb#participants_controller.rb_Methods_/_API_Calls &amp;lt;code&amp;gt; participants_controller.rb &amp;lt;/code&amp;gt; Methods / API Calls] section for all design-related inquiries &amp;lt;br/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Testing with rswag===&lt;br /&gt;
Refer to the [https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2024_-_E2484._Reimplement_participants_controller.rb#Testing_Plan Testing Plan] section &amp;lt;br/&amp;gt;&lt;br /&gt;
&amp;lt;i&amp;gt; To be expanded upon during implementation &amp;lt;/i&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Swagger UI Video Documentation===&lt;br /&gt;
&amp;lt;i&amp;gt; To be added at a later time &amp;lt;/i&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Testing Plan==&lt;br /&gt;
'''rswag'''&amp;lt;br/&amp;gt;&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
====Tests====&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;margin-left:40px&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Test ID !! Test Description &lt;br /&gt;
|-&lt;br /&gt;
| 1 || Test 'index' with valid model (Assignment) and ID - Should list participants&lt;br /&gt;
|-&lt;br /&gt;
| 2 || Test 'index' with invalid model (Assignment) and ID - Should return an error message&lt;br /&gt;
|-&lt;br /&gt;
| 3 || Test 'index' when there are no participants - Should return an empty list&lt;br /&gt;
|-&lt;br /&gt;
| 4 || Test 'show' with valid participant ID - Should return the specified participant details&lt;br /&gt;
|-&lt;br /&gt;
| 5 || Test 'show' with invalid participant ID - Should return participant not found&lt;br /&gt;
|-&lt;br /&gt;
| 6 || Test 'create' with valid user detail - Should successfully create a new participant&lt;br /&gt;
|-&lt;br /&gt;
| 7 || Test 'create' with duplicate user information - Should return an error message indicating that the participant already exists&lt;br /&gt;
|-&lt;br /&gt;
| 8 || Test 'create' with invalid data format - Should return a validation error&lt;br /&gt;
|-&lt;br /&gt;
| 9 || Test 'update_permissions' with valid participant ID and permissions - Should update participant’s permissions successfully&lt;br /&gt;
|-&lt;br /&gt;
| 10 || Test 'update_permissions' with valid participant ID and invalid permissions - Should return a validation error&lt;br /&gt;
|-&lt;br /&gt;
| 11 || Test `update_permissions` with invalid participant ID - Should return participant not found message&lt;br /&gt;
|-&lt;br /&gt;
| 12 || Test 'update_handle' with valid participant ID and unique handle - Should successfully update&lt;br /&gt;
|-&lt;br /&gt;
| 13 || Test 'update_handle' with duplicate handle - Should return an error message indicating handle is in use&lt;br /&gt;
|-&lt;br /&gt;
| 14 || Test 'update_handle' with invalid participant ID - Should return participant not found message&lt;br /&gt;
|-&lt;br /&gt;
| 15 || Test 'destroy' with valid participant ID - Should delete the specified participant&lt;br /&gt;
|-&lt;br /&gt;
| 16 || Test 'destroy' with invalid participant ID - Should return participant not found message&lt;br /&gt;
|-&lt;br /&gt;
| 17 || Test 'destroy for participant who has associated records - Should return an error message or handle the cascading deletions&lt;br /&gt;
|-&lt;br /&gt;
| 18 || Test 'participant_params' with all required parameters - Should proceed with the action&lt;br /&gt;
|-&lt;br /&gt;
| 19 || Test 'participant_params' with missing required parameters - Should return an error message&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==Team==&lt;br /&gt;
'''Mentor''' &lt;br /&gt;
&lt;br /&gt;
*Jay Patel &amp;lt;jhpatel9@ncsu.edu&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Students'''&lt;br /&gt;
&lt;br /&gt;
*Pierce Whelan &amp;lt;pwwhelan@ncsu.edu&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*Calvin Jiang &amp;lt;crjiang@ncsu.edu&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*Hechun Zhang &amp;lt;hzhang56@ncsu.edu&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Relevant Links ==&lt;br /&gt;
Pull Request [https://github.com/expertiza/reimplementation-back-end/pull/135] &amp;lt;br/&amp;gt;&lt;br /&gt;
GitHub Repository [https://github.com/Pierce57/participant_controller_reimplementation.git] &amp;lt;br/&amp;gt;&lt;br /&gt;
GitHub Project Board [https://github.com/users/Pierce57/projects/3] &amp;lt;br/&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt; participants_controller.rb &amp;lt;/code&amp;gt; in Old Expertiza [https://github.com/expertiza/expertiza/blob/main/app/controllers/participants_controller.rb] &amp;lt;br/&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt; participants_helper.rb &amp;lt;/code&amp;gt; in Old Expertiza [https://github.com/expertiza/expertiza/blob/main/app/helpers/participants_helper.rb]&lt;/div&gt;</summary>
		<author><name>Hzhang56</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2024_-_E2484._Reimplement_participants_controller.rb&amp;diff=159759</id>
		<title>CSC/ECE 517 Fall 2024 - E2484. Reimplement participants controller.rb</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2024_-_E2484._Reimplement_participants_controller.rb&amp;diff=159759"/>
		<updated>2024-11-18T14:31:43Z</updated>

		<summary type="html">&lt;p&gt;Hzhang56: /* Tests */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==About Expertiza==&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is an open source project based on [http://rubyonrails.org/ 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.&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
This project aims to reimplement the &amp;lt;code&amp;gt; participants_controller.rb &amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt; participants_helper.rb &amp;lt;/code&amp;gt; in the new Expertiza system. The &amp;lt;code&amp;gt; participants_controller.rb &amp;lt;/code&amp;gt; manages participants within assignments, and this reimplementation focuses on streamlining its methods, eliminating redundancy, and enhancing code readability and maintainability.&lt;br /&gt;
&lt;br /&gt;
==Requirements==&lt;br /&gt;
&amp;lt;li&amp;gt; Implement &amp;lt;code&amp;gt; participants_controller.rb &amp;lt;/code&amp;gt; Methods: Fully implement each controller method with the same functionality as the current controller. &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Import from &amp;lt;code&amp;gt; participants_helper.rb &amp;lt;/code&amp;gt;: Integrate relevant helper methods to streamline functionality and remove redundancy. &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; API Creation: Expose API endpoints for all necessary methods to enable seamless access and integration from the frontend. Ensure that each endpoint follows best practices for RESTful API design, including proper error handling and secure data access. &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Testing with rswag: Create test cases for all methods, focusing on edge cases, and generate rswag documentation. &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Swagger UI Video Documentation: Record a video walkthrough of API endpoints in Swagger UI, showcasing each method’s functionality. &amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Existing Issues==&lt;br /&gt;
Reimplement &amp;lt;code&amp;gt; [https://github.com/expertiza/expertiza/blob/main/app/controllers/participants_controller.rb participants_controller.rb] &amp;lt;/code&amp;gt; while addressing the following:&lt;br /&gt;
&amp;lt;li&amp;gt; Refactor code to comply with the Open-Closed Principle and the Single Responsibility Principle. &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Introduce dependency injection where necessary. &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Reduce excessive conditional statements. &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Include sufficient code tests to verify functionality. &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Enhance comments to better explain each method's functionality, purpose, and rationale for keeping or modifying particular aspects of the code. &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Provide a more detailed explanation of design choices and refactoring steps. &amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Design / Proposed Solution ==&lt;br /&gt;
===Controller Diagram===&lt;br /&gt;
[[File:Participants Controller UML Diagram.png]]&lt;br /&gt;
&lt;br /&gt;
===&amp;lt;code&amp;gt; participants_controller.rb &amp;lt;/code&amp;gt; Methods / API Calls===&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;width: 100%;&lt;br /&gt;
! &amp;amp;nbsp;#&amp;amp;nbsp; !! Method !! Endpoint !! Description &lt;br /&gt;
|-&lt;br /&gt;
|1&lt;br /&gt;
|index&lt;br /&gt;
|GET &amp;lt;code&amp;gt; /participants &amp;lt;/code&amp;gt;&lt;br /&gt;
|Return a list of participants&lt;br /&gt;
|-&lt;br /&gt;
|2&lt;br /&gt;
|show&lt;br /&gt;
|GET &amp;lt;code&amp;gt; /participants/:id &amp;lt;/code&amp;gt;&lt;br /&gt;
|Return a specified participant&lt;br /&gt;
|-&lt;br /&gt;
|3&lt;br /&gt;
|create&lt;br /&gt;
|POST &amp;lt;code&amp;gt; /participants &amp;lt;/code&amp;gt;&lt;br /&gt;
|Create a participant&lt;br /&gt;
|-&lt;br /&gt;
|4&lt;br /&gt;
|update_permissions&lt;br /&gt;
|PATCH &amp;lt;code&amp;gt; /participants/:id/permissions &amp;lt;/code&amp;gt;&lt;br /&gt;
|Update the permissions of a participant&lt;br /&gt;
|-&lt;br /&gt;
|5&lt;br /&gt;
|update_handle&lt;br /&gt;
|PATCH &amp;lt;code&amp;gt; /participants/:id/handle &amp;lt;/code&amp;gt;&lt;br /&gt;
|Update the handle of a participant&lt;br /&gt;
|-&lt;br /&gt;
|6&lt;br /&gt;
|destroy&lt;br /&gt;
|DELETE &amp;lt;code&amp;gt; /participants/:id &amp;lt;/code&amp;gt;&lt;br /&gt;
|Delete a specified participant&lt;br /&gt;
|-&lt;br /&gt;
|7&lt;br /&gt;
|participant_params&lt;br /&gt;
| -&lt;br /&gt;
|Permitted parameters for creating or updating a Participant object&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
The following methods were removed from &amp;lt;code&amp;gt; participants_controller.rb &amp;lt;/code&amp;gt;:&lt;br /&gt;
&amp;lt;li&amp;gt; &amp;lt;code&amp;gt; action_allowed? &amp;lt;/code&amp;gt; - No impact on functionality &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; &amp;lt;code&amp;gt; controller_locale &amp;lt;/code&amp;gt; - No impact on functionality &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; &amp;lt;code&amp;gt; inherit &amp;lt;/code&amp;gt; - Since there is no direct relationship between the Participant and Course classes, this logic is redundant and no longer necessary &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; &amp;lt;code&amp;gt; bequeath_all &amp;lt;/code&amp;gt; - Since there is no direct relationship between the Participant and Course classes, this logic is redundant and no longer necessary &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; &amp;lt;code&amp;gt; delete &amp;lt;/code&amp;gt; - Handled in the &amp;lt;i&amp;gt; remove_participant &amp;lt;/i&amp;gt; method of the AssignmentsController (&amp;lt;code&amp;gt; assignments_controller.rb &amp;lt;/code&amp;gt;) &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; &amp;lt;code&amp;gt; view_copyright_grants &amp;lt;/code&amp;gt; - Incorrectly implemented in the old implementation &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; &amp;lt;code&amp;gt; get_user_info &amp;lt;/code&amp;gt; - All needed user data can be accessed by leveraging the Participant model's &amp;lt;i&amp;gt; belongs_to &amp;lt;/i&amp;gt; relationship to the User model &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; &amp;lt;code&amp;gt; get_signup_topics_for_assignment &amp;lt;/code&amp;gt; - Handled in the &amp;lt;i&amp;gt; index &amp;lt;/i&amp;gt; method of the SignUpTopicsController (&amp;lt;code&amp;gt; sign_up_topics_controller.rb &amp;lt;/code&amp;gt;) &amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===&amp;lt;code&amp;gt; participants_helper.rb &amp;lt;/code&amp;gt; Methods===&lt;br /&gt;
The methods in &amp;lt;code&amp;gt;participants_helper.rb&amp;lt;/code&amp;gt; are outdated and do not impact any functionality in &amp;lt;code&amp;gt;participants_controller.rb&amp;lt;/code&amp;gt;. &amp;lt;br/&amp;gt;&lt;br /&gt;
As a result, these methods will not be carried forward to the new implementation:&lt;br /&gt;
&amp;lt;li&amp;gt; &amp;lt;code&amp;gt; upload_users &amp;lt;/code&amp;gt; - Logic for creating a User specifically for the Assignment and Course classes. Since there is no direct relationship between the User and these classes, this logic is redundant and no longer necessary &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; &amp;lt;code&amp;gt; define_attributes &amp;lt;/code&amp;gt; - &amp;lt;i&amp;gt; Same reason as above &amp;lt;/i&amp;gt; &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; &amp;lt;code&amp;gt; define_user &amp;lt;/code&amp;gt; - &amp;lt;i&amp;gt; Same reason as above &amp;lt;/i&amp;gt; &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; &amp;lt;code&amp;gt; create_new_user &amp;lt;/code&amp;gt; - &amp;lt;i&amp;gt; Same reason as above &amp;lt;/i&amp;gt; &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; &amp;lt;code&amp;gt; add_user_to_assignment &amp;lt;/code&amp;gt; - &amp;lt;i&amp;gt; Same reason as above. &amp;lt;/i&amp;gt; Furthermore, since the Participant and Assignment classes are directly related, this functionality has been replaced by the &amp;lt;i&amp;gt; add_participant &amp;lt;/i&amp;gt; method in AssignmentsController (&amp;lt;code&amp;gt;assignments_controller.rb&amp;lt;/code&amp;gt;) &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; &amp;lt;code&amp;gt; add_user_to_course &amp;lt;/code&amp;gt; - &amp;lt;i&amp;gt; Same reason as above &amp;lt;/i&amp;gt; &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; &amp;lt;code&amp;gt; get_config &amp;lt;/code&amp;gt; - &amp;lt;i&amp;gt; Same reason as above &amp;lt;/i&amp;gt; &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; &amp;lt;code&amp;gt; store_item &amp;lt;/code&amp;gt; - &amp;lt;i&amp;gt; Same reason as above &amp;lt;/i&amp;gt; &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; &amp;lt;code&amp;gt; participant_permissions &amp;lt;/code&amp;gt; - Outdated way of updating permissions, handled more effectively by the &amp;lt;code&amp;gt;update_permissions&amp;lt;/code&amp;gt; method in ParticipantsController (&amp;lt;code&amp;gt;participants_controller.rb&amp;lt;/code&amp;gt;) &amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Pattern(s)===&lt;br /&gt;
'''Facade''': &amp;quot;A simplified interface that performs many other actions behind the scenes.&amp;quot; &amp;lt;br/&amp;gt;&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
===SOLID Principle(s)===&lt;br /&gt;
'''Open and Closed Principle''': &amp;quot;Software entities should be open for extension, but closed for modification.&amp;quot;&amp;lt;br/&amp;gt;&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
'''Single Responsibility Principle''': &amp;quot;A class should only have one responsibility and should never have more than one reason to change.&amp;quot;&amp;lt;br/&amp;gt;&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
==Implementation==&lt;br /&gt;
===Implement &amp;lt;code&amp;gt; participants_controller.rb &amp;lt;/code&amp;gt; Methods===&lt;br /&gt;
Refer to the [https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2024_-_E2484._Reimplement_participants_controller.rb#participants_controller.rb_Methods_/_API_Calls &amp;lt;code&amp;gt; participants_controller.rb &amp;lt;/code&amp;gt; Methods / API Calls] section for all design-related inquiries &amp;lt;br/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|+&lt;br /&gt;
! Old Method Name !! Action !! New Method Name&lt;br /&gt;
|-&lt;br /&gt;
| action_allowed? || Removed || -&lt;br /&gt;
|-&lt;br /&gt;
| controller_locale || Removed || -&lt;br /&gt;
|-&lt;br /&gt;
| list || Renamed || index&lt;br /&gt;
|-&lt;br /&gt;
| add || Renamed || create&lt;br /&gt;
|-&lt;br /&gt;
| update_authorizations || Renamed || update_permissions&lt;br /&gt;
|-&lt;br /&gt;
| destroy || No Change || destroy&lt;br /&gt;
|-&lt;br /&gt;
| inherit || Removed || -&lt;br /&gt;
|-&lt;br /&gt;
| bequeath_all || Removed || -&lt;br /&gt;
|-&lt;br /&gt;
| change_handle || Renamed || update_handle&lt;br /&gt;
|-&lt;br /&gt;
| delete || Removed || -&lt;br /&gt;
|-&lt;br /&gt;
| view_copyright_grants || Removed || -&lt;br /&gt;
|-&lt;br /&gt;
| participant_params || No Change || participant_params&lt;br /&gt;
|-&lt;br /&gt;
| get_user_info || Removed || -&lt;br /&gt;
|-&lt;br /&gt;
| get_signup_topics_for_assignment || Removed || -&lt;br /&gt;
|-&lt;br /&gt;
| - || Added || show&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;i&amp;gt; To be expanded upon during implementation &amp;lt;/i&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Import from &amp;lt;code&amp;gt; participants_helper.rb &amp;lt;/code&amp;gt;===&lt;br /&gt;
Refer to the [https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2024_-_E2484._Reimplement_participants_controller.rb#participants_helper.rb_Methods &amp;lt;code&amp;gt; participants_helper.rb &amp;lt;/code&amp;gt; Methods] section for all design-related inquiries &amp;lt;br/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|+&lt;br /&gt;
! Old Method Name !! Action !! New Method Name&lt;br /&gt;
|-&lt;br /&gt;
| upload_users || Removed || -&lt;br /&gt;
|-&lt;br /&gt;
| define_attributes || Removed || -&lt;br /&gt;
|-&lt;br /&gt;
| define_user || Removed || -&lt;br /&gt;
|-&lt;br /&gt;
| create_new_user || Removed || -&lt;br /&gt;
|-&lt;br /&gt;
| add_user_to_assignment || Removed || -&lt;br /&gt;
|-&lt;br /&gt;
| add_user_to_course || Removed || -&lt;br /&gt;
|-&lt;br /&gt;
| get_config || Removed || -&lt;br /&gt;
|-&lt;br /&gt;
| store_item || Removed || -&lt;br /&gt;
|-&lt;br /&gt;
| participant_permissions || Removed || -&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===API Creation===&lt;br /&gt;
Refer to the [https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2024_-_E2484._Reimplement_participants_controller.rb#participants_controller.rb_Methods_/_API_Calls &amp;lt;code&amp;gt; participants_controller.rb &amp;lt;/code&amp;gt; Methods / API Calls] section for all design-related inquiries &amp;lt;br/&amp;gt;&lt;br /&gt;
&amp;lt;i&amp;gt; To be expanded upon during implementation &amp;lt;/i&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Testing with rswag===&lt;br /&gt;
Refer to the [https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2024_-_E2484._Reimplement_participants_controller.rb#Testing_Plan Testing Plan] section &amp;lt;br/&amp;gt;&lt;br /&gt;
&amp;lt;i&amp;gt; To be expanded upon during implementation &amp;lt;/i&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Swagger UI Video Documentation===&lt;br /&gt;
&amp;lt;i&amp;gt; To be added at a later time &amp;lt;/i&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Testing Plan==&lt;br /&gt;
'''rswag'''&amp;lt;br/&amp;gt;&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
====Tests====&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;margin-left:40px&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Test ID !! Test Description &lt;br /&gt;
|-&lt;br /&gt;
| 1 || Test 'index' with valid model (Assignment) and ID - Should list participants&lt;br /&gt;
|-&lt;br /&gt;
| 2 || Test 'index' with invalid model (Assignment) and ID - Should return an error message&lt;br /&gt;
|-&lt;br /&gt;
| 3 || Test 'index' when there are no participants - Should return an empty list&lt;br /&gt;
|-&lt;br /&gt;
| 4 || Test 'show' with valid participant ID - Should return the specified participant details&lt;br /&gt;
|-&lt;br /&gt;
| 5 || Test 'show' with invalid participant ID - Should return participant not found&lt;br /&gt;
|-&lt;br /&gt;
| 6 || Test 'create' with valid user detail - Should successfully create a new participant&lt;br /&gt;
|-&lt;br /&gt;
| 7 || Test 'create' with duplicate user information - Should return an error message indicating that the participant already exists&lt;br /&gt;
|-&lt;br /&gt;
| 8 || Test 'create' with invalid data format - Should return a validation error&lt;br /&gt;
|-&lt;br /&gt;
| 9 || Test 'update_permissions' with valid participant ID and permissions - Should update participant’s permissions successfully&lt;br /&gt;
|-&lt;br /&gt;
| 10 || Test 'update_permissions' with valid participant ID and invalid permissions - Should return a validation error&lt;br /&gt;
|-&lt;br /&gt;
| 11 || Test `update_permissions` with invalid participant ID - Should return participant not found message&lt;br /&gt;
|-&lt;br /&gt;
| 12 || Test 'update_handle' with valid participant ID and unique handle - Should successfully update&lt;br /&gt;
|-&lt;br /&gt;
| 13 || Test 'update_handle' with duplicate handle - Should return an error message indicating handle is in use&lt;br /&gt;
|-&lt;br /&gt;
| 14 || Test 'update_handle' with invalid participant ID - Should return participant not found message&lt;br /&gt;
|-&lt;br /&gt;
| 15 || Test 'destroy' with valid participant ID - Should delete the specified participant&lt;br /&gt;
|-&lt;br /&gt;
| 16 || Test 'destroy' with invalid participant ID - Should return participant not found message&lt;br /&gt;
|-&lt;br /&gt;
| 17 || Test 'destroy for participant who has associated records - Should return an error message or handle the cascading deletions&lt;br /&gt;
|-&lt;br /&gt;
| 18 || Test 'participant_params' with all required parameters - Should proceed with the action&lt;br /&gt;
|-&lt;br /&gt;
| 19 || Test 'participant_params' with missing required parameters - Should return an error message&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==Team==&lt;br /&gt;
'''Mentor''' &lt;br /&gt;
&lt;br /&gt;
*Jay Patel &amp;lt;jhpatel9@ncsu.edu&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Students'''&lt;br /&gt;
&lt;br /&gt;
*Pierce Whelan &amp;lt;pwwhelan@ncsu.edu&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*Calvin Jiang &amp;lt;crjiang@ncsu.edu&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*Hechun Zhang &amp;lt;hzhang56@ncsu.edu&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Relevant Links ==&lt;br /&gt;
Pull Request [https://github.com/expertiza/reimplementation-back-end/pull/135] &amp;lt;br/&amp;gt;&lt;br /&gt;
GitHub Repository [https://github.com/Pierce57/participant_controller_reimplementation.git] &amp;lt;br/&amp;gt;&lt;br /&gt;
GitHub Project Board [https://github.com/users/Pierce57/projects/3] &amp;lt;br/&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt; participants_controller.rb &amp;lt;/code&amp;gt; in Old Expertiza [https://github.com/expertiza/expertiza/blob/main/app/controllers/participants_controller.rb] &amp;lt;br/&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt; participants_helper.rb &amp;lt;/code&amp;gt; in Old Expertiza [https://github.com/expertiza/expertiza/blob/main/app/helpers/participants_helper.rb]&lt;/div&gt;</summary>
		<author><name>Hzhang56</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2024_-_E2484._Reimplement_participants_controller.rb&amp;diff=159758</id>
		<title>CSC/ECE 517 Fall 2024 - E2484. Reimplement participants controller.rb</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2024_-_E2484._Reimplement_participants_controller.rb&amp;diff=159758"/>
		<updated>2024-11-18T14:31:07Z</updated>

		<summary type="html">&lt;p&gt;Hzhang56: /* Tests */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==About Expertiza==&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is an open source project based on [http://rubyonrails.org/ 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.&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
This project aims to reimplement the &amp;lt;code&amp;gt; participants_controller.rb &amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt; participants_helper.rb &amp;lt;/code&amp;gt; in the new Expertiza system. The &amp;lt;code&amp;gt; participants_controller.rb &amp;lt;/code&amp;gt; manages participants within assignments, and this reimplementation focuses on streamlining its methods, eliminating redundancy, and enhancing code readability and maintainability.&lt;br /&gt;
&lt;br /&gt;
==Requirements==&lt;br /&gt;
&amp;lt;li&amp;gt; Implement &amp;lt;code&amp;gt; participants_controller.rb &amp;lt;/code&amp;gt; Methods: Fully implement each controller method with the same functionality as the current controller. &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Import from &amp;lt;code&amp;gt; participants_helper.rb &amp;lt;/code&amp;gt;: Integrate relevant helper methods to streamline functionality and remove redundancy. &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; API Creation: Expose API endpoints for all necessary methods to enable seamless access and integration from the frontend. Ensure that each endpoint follows best practices for RESTful API design, including proper error handling and secure data access. &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Testing with rswag: Create test cases for all methods, focusing on edge cases, and generate rswag documentation. &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Swagger UI Video Documentation: Record a video walkthrough of API endpoints in Swagger UI, showcasing each method’s functionality. &amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Existing Issues==&lt;br /&gt;
Reimplement &amp;lt;code&amp;gt; [https://github.com/expertiza/expertiza/blob/main/app/controllers/participants_controller.rb participants_controller.rb] &amp;lt;/code&amp;gt; while addressing the following:&lt;br /&gt;
&amp;lt;li&amp;gt; Refactor code to comply with the Open-Closed Principle and the Single Responsibility Principle. &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Introduce dependency injection where necessary. &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Reduce excessive conditional statements. &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Include sufficient code tests to verify functionality. &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Enhance comments to better explain each method's functionality, purpose, and rationale for keeping or modifying particular aspects of the code. &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Provide a more detailed explanation of design choices and refactoring steps. &amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Design / Proposed Solution ==&lt;br /&gt;
===Controller Diagram===&lt;br /&gt;
[[File:Participants Controller UML Diagram.png]]&lt;br /&gt;
&lt;br /&gt;
===&amp;lt;code&amp;gt; participants_controller.rb &amp;lt;/code&amp;gt; Methods / API Calls===&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;width: 100%;&lt;br /&gt;
! &amp;amp;nbsp;#&amp;amp;nbsp; !! Method !! Endpoint !! Description &lt;br /&gt;
|-&lt;br /&gt;
|1&lt;br /&gt;
|index&lt;br /&gt;
|GET &amp;lt;code&amp;gt; /participants &amp;lt;/code&amp;gt;&lt;br /&gt;
|Return a list of participants&lt;br /&gt;
|-&lt;br /&gt;
|2&lt;br /&gt;
|show&lt;br /&gt;
|GET &amp;lt;code&amp;gt; /participants/:id &amp;lt;/code&amp;gt;&lt;br /&gt;
|Return a specified participant&lt;br /&gt;
|-&lt;br /&gt;
|3&lt;br /&gt;
|create&lt;br /&gt;
|POST &amp;lt;code&amp;gt; /participants &amp;lt;/code&amp;gt;&lt;br /&gt;
|Create a participant&lt;br /&gt;
|-&lt;br /&gt;
|4&lt;br /&gt;
|update_permissions&lt;br /&gt;
|PATCH &amp;lt;code&amp;gt; /participants/:id/permissions &amp;lt;/code&amp;gt;&lt;br /&gt;
|Update the permissions of a participant&lt;br /&gt;
|-&lt;br /&gt;
|5&lt;br /&gt;
|update_handle&lt;br /&gt;
|PATCH &amp;lt;code&amp;gt; /participants/:id/handle &amp;lt;/code&amp;gt;&lt;br /&gt;
|Update the handle of a participant&lt;br /&gt;
|-&lt;br /&gt;
|6&lt;br /&gt;
|destroy&lt;br /&gt;
|DELETE &amp;lt;code&amp;gt; /participants/:id &amp;lt;/code&amp;gt;&lt;br /&gt;
|Delete a specified participant&lt;br /&gt;
|-&lt;br /&gt;
|7&lt;br /&gt;
|participant_params&lt;br /&gt;
| -&lt;br /&gt;
|Permitted parameters for creating or updating a Participant object&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
The following methods were removed from &amp;lt;code&amp;gt; participants_controller.rb &amp;lt;/code&amp;gt;:&lt;br /&gt;
&amp;lt;li&amp;gt; &amp;lt;code&amp;gt; action_allowed? &amp;lt;/code&amp;gt; - No impact on functionality &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; &amp;lt;code&amp;gt; controller_locale &amp;lt;/code&amp;gt; - No impact on functionality &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; &amp;lt;code&amp;gt; inherit &amp;lt;/code&amp;gt; - Since there is no direct relationship between the Participant and Course classes, this logic is redundant and no longer necessary &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; &amp;lt;code&amp;gt; bequeath_all &amp;lt;/code&amp;gt; - Since there is no direct relationship between the Participant and Course classes, this logic is redundant and no longer necessary &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; &amp;lt;code&amp;gt; delete &amp;lt;/code&amp;gt; - Handled in the &amp;lt;i&amp;gt; remove_participant &amp;lt;/i&amp;gt; method of the AssignmentsController (&amp;lt;code&amp;gt; assignments_controller.rb &amp;lt;/code&amp;gt;) &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; &amp;lt;code&amp;gt; view_copyright_grants &amp;lt;/code&amp;gt; - Incorrectly implemented in the old implementation &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; &amp;lt;code&amp;gt; get_user_info &amp;lt;/code&amp;gt; - All needed user data can be accessed by leveraging the Participant model's &amp;lt;i&amp;gt; belongs_to &amp;lt;/i&amp;gt; relationship to the User model &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; &amp;lt;code&amp;gt; get_signup_topics_for_assignment &amp;lt;/code&amp;gt; - Handled in the &amp;lt;i&amp;gt; index &amp;lt;/i&amp;gt; method of the SignUpTopicsController (&amp;lt;code&amp;gt; sign_up_topics_controller.rb &amp;lt;/code&amp;gt;) &amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===&amp;lt;code&amp;gt; participants_helper.rb &amp;lt;/code&amp;gt; Methods===&lt;br /&gt;
The methods in &amp;lt;code&amp;gt;participants_helper.rb&amp;lt;/code&amp;gt; are outdated and do not impact any functionality in &amp;lt;code&amp;gt;participants_controller.rb&amp;lt;/code&amp;gt;. &amp;lt;br/&amp;gt;&lt;br /&gt;
As a result, these methods will not be carried forward to the new implementation:&lt;br /&gt;
&amp;lt;li&amp;gt; &amp;lt;code&amp;gt; upload_users &amp;lt;/code&amp;gt; - Logic for creating a User specifically for the Assignment and Course classes. Since there is no direct relationship between the User and these classes, this logic is redundant and no longer necessary &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; &amp;lt;code&amp;gt; define_attributes &amp;lt;/code&amp;gt; - &amp;lt;i&amp;gt; Same reason as above &amp;lt;/i&amp;gt; &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; &amp;lt;code&amp;gt; define_user &amp;lt;/code&amp;gt; - &amp;lt;i&amp;gt; Same reason as above &amp;lt;/i&amp;gt; &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; &amp;lt;code&amp;gt; create_new_user &amp;lt;/code&amp;gt; - &amp;lt;i&amp;gt; Same reason as above &amp;lt;/i&amp;gt; &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; &amp;lt;code&amp;gt; add_user_to_assignment &amp;lt;/code&amp;gt; - &amp;lt;i&amp;gt; Same reason as above. &amp;lt;/i&amp;gt; Furthermore, since the Participant and Assignment classes are directly related, this functionality has been replaced by the &amp;lt;i&amp;gt; add_participant &amp;lt;/i&amp;gt; method in AssignmentsController (&amp;lt;code&amp;gt;assignments_controller.rb&amp;lt;/code&amp;gt;) &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; &amp;lt;code&amp;gt; add_user_to_course &amp;lt;/code&amp;gt; - &amp;lt;i&amp;gt; Same reason as above &amp;lt;/i&amp;gt; &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; &amp;lt;code&amp;gt; get_config &amp;lt;/code&amp;gt; - &amp;lt;i&amp;gt; Same reason as above &amp;lt;/i&amp;gt; &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; &amp;lt;code&amp;gt; store_item &amp;lt;/code&amp;gt; - &amp;lt;i&amp;gt; Same reason as above &amp;lt;/i&amp;gt; &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; &amp;lt;code&amp;gt; participant_permissions &amp;lt;/code&amp;gt; - Outdated way of updating permissions, handled more effectively by the &amp;lt;code&amp;gt;update_permissions&amp;lt;/code&amp;gt; method in ParticipantsController (&amp;lt;code&amp;gt;participants_controller.rb&amp;lt;/code&amp;gt;) &amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Pattern(s)===&lt;br /&gt;
'''Facade''': &amp;quot;A simplified interface that performs many other actions behind the scenes.&amp;quot; &amp;lt;br/&amp;gt;&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
===SOLID Principle(s)===&lt;br /&gt;
'''Open and Closed Principle''': &amp;quot;Software entities should be open for extension, but closed for modification.&amp;quot;&amp;lt;br/&amp;gt;&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
'''Single Responsibility Principle''': &amp;quot;A class should only have one responsibility and should never have more than one reason to change.&amp;quot;&amp;lt;br/&amp;gt;&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
==Implementation==&lt;br /&gt;
===Implement &amp;lt;code&amp;gt; participants_controller.rb &amp;lt;/code&amp;gt; Methods===&lt;br /&gt;
Refer to the [https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2024_-_E2484._Reimplement_participants_controller.rb#participants_controller.rb_Methods_/_API_Calls &amp;lt;code&amp;gt; participants_controller.rb &amp;lt;/code&amp;gt; Methods / API Calls] section for all design-related inquiries &amp;lt;br/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|+&lt;br /&gt;
! Old Method Name !! Action !! New Method Name&lt;br /&gt;
|-&lt;br /&gt;
| action_allowed? || Removed || -&lt;br /&gt;
|-&lt;br /&gt;
| controller_locale || Removed || -&lt;br /&gt;
|-&lt;br /&gt;
| list || Renamed || index&lt;br /&gt;
|-&lt;br /&gt;
| add || Renamed || create&lt;br /&gt;
|-&lt;br /&gt;
| update_authorizations || Renamed || update_permissions&lt;br /&gt;
|-&lt;br /&gt;
| destroy || No Change || destroy&lt;br /&gt;
|-&lt;br /&gt;
| inherit || Removed || -&lt;br /&gt;
|-&lt;br /&gt;
| bequeath_all || Removed || -&lt;br /&gt;
|-&lt;br /&gt;
| change_handle || Renamed || update_handle&lt;br /&gt;
|-&lt;br /&gt;
| delete || Removed || -&lt;br /&gt;
|-&lt;br /&gt;
| view_copyright_grants || Removed || -&lt;br /&gt;
|-&lt;br /&gt;
| participant_params || No Change || participant_params&lt;br /&gt;
|-&lt;br /&gt;
| get_user_info || Removed || -&lt;br /&gt;
|-&lt;br /&gt;
| get_signup_topics_for_assignment || Removed || -&lt;br /&gt;
|-&lt;br /&gt;
| - || Added || show&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;i&amp;gt; To be expanded upon during implementation &amp;lt;/i&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Import from &amp;lt;code&amp;gt; participants_helper.rb &amp;lt;/code&amp;gt;===&lt;br /&gt;
Refer to the [https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2024_-_E2484._Reimplement_participants_controller.rb#participants_helper.rb_Methods &amp;lt;code&amp;gt; participants_helper.rb &amp;lt;/code&amp;gt; Methods] section for all design-related inquiries &amp;lt;br/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|+&lt;br /&gt;
! Old Method Name !! Action !! New Method Name&lt;br /&gt;
|-&lt;br /&gt;
| upload_users || Removed || -&lt;br /&gt;
|-&lt;br /&gt;
| define_attributes || Removed || -&lt;br /&gt;
|-&lt;br /&gt;
| define_user || Removed || -&lt;br /&gt;
|-&lt;br /&gt;
| create_new_user || Removed || -&lt;br /&gt;
|-&lt;br /&gt;
| add_user_to_assignment || Removed || -&lt;br /&gt;
|-&lt;br /&gt;
| add_user_to_course || Removed || -&lt;br /&gt;
|-&lt;br /&gt;
| get_config || Removed || -&lt;br /&gt;
|-&lt;br /&gt;
| store_item || Removed || -&lt;br /&gt;
|-&lt;br /&gt;
| participant_permissions || Removed || -&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===API Creation===&lt;br /&gt;
Refer to the [https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2024_-_E2484._Reimplement_participants_controller.rb#participants_controller.rb_Methods_/_API_Calls &amp;lt;code&amp;gt; participants_controller.rb &amp;lt;/code&amp;gt; Methods / API Calls] section for all design-related inquiries &amp;lt;br/&amp;gt;&lt;br /&gt;
&amp;lt;i&amp;gt; To be expanded upon during implementation &amp;lt;/i&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Testing with rswag===&lt;br /&gt;
Refer to the [https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2024_-_E2484._Reimplement_participants_controller.rb#Testing_Plan Testing Plan] section &amp;lt;br/&amp;gt;&lt;br /&gt;
&amp;lt;i&amp;gt; To be expanded upon during implementation &amp;lt;/i&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Swagger UI Video Documentation===&lt;br /&gt;
&amp;lt;i&amp;gt; To be added at a later time &amp;lt;/i&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Testing Plan==&lt;br /&gt;
'''rswag'''&amp;lt;br/&amp;gt;&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
====Tests====&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;margin-left:40px&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Test ID !! Test Description &lt;br /&gt;
|-&lt;br /&gt;
| 1 || Test 'index' with valid model (Assignment) and ID - Should list participants&lt;br /&gt;
|-&lt;br /&gt;
| 2 || Test 'index' with invalid model (Assignment) and ID - Should return an error message&lt;br /&gt;
|-&lt;br /&gt;
| 3 || Test 'index' when there are no participants - Should return an empty list&lt;br /&gt;
|-&lt;br /&gt;
| 4 || Test 'show' with valid participant ID - Should return the specified participant details&lt;br /&gt;
|-&lt;br /&gt;
| 5 || Test 'show' with invalid participant ID - Should return participant not found&lt;br /&gt;
|-&lt;br /&gt;
| 6 || Test 'create' with valid user detail - Should successfully create a new participant&lt;br /&gt;
|-&lt;br /&gt;
| 7 || Test 'create' with duplicate user information - Should return an error message indicating that the participant already exists&lt;br /&gt;
|-&lt;br /&gt;
| 8 || Test 'create' with invalid data format - Should return a validation error&lt;br /&gt;
|-&lt;br /&gt;
| 9 || Test 'update_permissions' with valid participant ID and permissions - Should update participant’s permissions successfully&lt;br /&gt;
|-&lt;br /&gt;
| 10 || Test 'update_permissions' with valid participant ID and invalid permissions - Should return a validation error&lt;br /&gt;
|-&lt;br /&gt;
| 11 || Test `update_permissions` with invalid participant ID - Should return participant not found message&lt;br /&gt;
|-&lt;br /&gt;
| 12 || Test 'update_handle' with valid participant ID and unique handle - Should successfully update&lt;br /&gt;
|-&lt;br /&gt;
| 13 || Test 'update_handle' with duplicate handle - Should return an error message indicating handle is in use&lt;br /&gt;
|-&lt;br /&gt;
| 14 || Test 'update_handle' with invalid participant ID - Should return participant not found message&lt;br /&gt;
|-&lt;br /&gt;
| 15 || Test 'destroy' with valid participant ID - Should delete the specified participant&lt;br /&gt;
|-&lt;br /&gt;
| 16 || Test 'destroy' with invalid participant ID - Should return participant not found message&lt;br /&gt;
|-&lt;br /&gt;
| 17 || Test 'destroy for participant who has associated records - Should return an error message or handle the cascading deletions&lt;br /&gt;
|-&lt;br /&gt;
| 18 || Test 'participant_params' with all required parameters – Should proceed with the action&lt;br /&gt;
|-&lt;br /&gt;
| 19 || Test 'participant_params' with missing required parameters – Should return an error message&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==Team==&lt;br /&gt;
'''Mentor''' &lt;br /&gt;
&lt;br /&gt;
*Jay Patel &amp;lt;jhpatel9@ncsu.edu&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Students'''&lt;br /&gt;
&lt;br /&gt;
*Pierce Whelan &amp;lt;pwwhelan@ncsu.edu&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*Calvin Jiang &amp;lt;crjiang@ncsu.edu&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*Hechun Zhang &amp;lt;hzhang56@ncsu.edu&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Relevant Links ==&lt;br /&gt;
Pull Request [https://github.com/expertiza/reimplementation-back-end/pull/135] &amp;lt;br/&amp;gt;&lt;br /&gt;
GitHub Repository [https://github.com/Pierce57/participant_controller_reimplementation.git] &amp;lt;br/&amp;gt;&lt;br /&gt;
GitHub Project Board [https://github.com/users/Pierce57/projects/3] &amp;lt;br/&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt; participants_controller.rb &amp;lt;/code&amp;gt; in Old Expertiza [https://github.com/expertiza/expertiza/blob/main/app/controllers/participants_controller.rb] &amp;lt;br/&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt; participants_helper.rb &amp;lt;/code&amp;gt; in Old Expertiza [https://github.com/expertiza/expertiza/blob/main/app/helpers/participants_helper.rb]&lt;/div&gt;</summary>
		<author><name>Hzhang56</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2024_-_E2484._Reimplement_participants_controller.rb&amp;diff=159757</id>
		<title>CSC/ECE 517 Fall 2024 - E2484. Reimplement participants controller.rb</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2024_-_E2484._Reimplement_participants_controller.rb&amp;diff=159757"/>
		<updated>2024-11-18T14:29:12Z</updated>

		<summary type="html">&lt;p&gt;Hzhang56: /* Tests */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==About Expertiza==&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is an open source project based on [http://rubyonrails.org/ 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.&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
This project aims to reimplement the &amp;lt;code&amp;gt; participants_controller.rb &amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt; participants_helper.rb &amp;lt;/code&amp;gt; in the new Expertiza system. The &amp;lt;code&amp;gt; participants_controller.rb &amp;lt;/code&amp;gt; manages participants within assignments, and this reimplementation focuses on streamlining its methods, eliminating redundancy, and enhancing code readability and maintainability.&lt;br /&gt;
&lt;br /&gt;
==Requirements==&lt;br /&gt;
&amp;lt;li&amp;gt; Implement &amp;lt;code&amp;gt; participants_controller.rb &amp;lt;/code&amp;gt; Methods: Fully implement each controller method with the same functionality as the current controller. &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Import from &amp;lt;code&amp;gt; participants_helper.rb &amp;lt;/code&amp;gt;: Integrate relevant helper methods to streamline functionality and remove redundancy. &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; API Creation: Expose API endpoints for all necessary methods to enable seamless access and integration from the frontend. Ensure that each endpoint follows best practices for RESTful API design, including proper error handling and secure data access. &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Testing with rswag: Create test cases for all methods, focusing on edge cases, and generate rswag documentation. &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Swagger UI Video Documentation: Record a video walkthrough of API endpoints in Swagger UI, showcasing each method’s functionality. &amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Existing Issues==&lt;br /&gt;
Reimplement &amp;lt;code&amp;gt; [https://github.com/expertiza/expertiza/blob/main/app/controllers/participants_controller.rb participants_controller.rb] &amp;lt;/code&amp;gt; while addressing the following:&lt;br /&gt;
&amp;lt;li&amp;gt; Refactor code to comply with the Open-Closed Principle and the Single Responsibility Principle. &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Introduce dependency injection where necessary. &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Reduce excessive conditional statements. &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Include sufficient code tests to verify functionality. &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Enhance comments to better explain each method's functionality, purpose, and rationale for keeping or modifying particular aspects of the code. &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Provide a more detailed explanation of design choices and refactoring steps. &amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Design / Proposed Solution ==&lt;br /&gt;
===Controller Diagram===&lt;br /&gt;
[[File:Participants Controller UML Diagram.png]]&lt;br /&gt;
&lt;br /&gt;
===&amp;lt;code&amp;gt; participants_controller.rb &amp;lt;/code&amp;gt; Methods / API Calls===&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;width: 100%;&lt;br /&gt;
! &amp;amp;nbsp;#&amp;amp;nbsp; !! Method !! Endpoint !! Description &lt;br /&gt;
|-&lt;br /&gt;
|1&lt;br /&gt;
|index&lt;br /&gt;
|GET &amp;lt;code&amp;gt; /participants &amp;lt;/code&amp;gt;&lt;br /&gt;
|Return a list of participants&lt;br /&gt;
|-&lt;br /&gt;
|2&lt;br /&gt;
|show&lt;br /&gt;
|GET &amp;lt;code&amp;gt; /participants/:id &amp;lt;/code&amp;gt;&lt;br /&gt;
|Return a specified participant&lt;br /&gt;
|-&lt;br /&gt;
|3&lt;br /&gt;
|create&lt;br /&gt;
|POST &amp;lt;code&amp;gt; /participants &amp;lt;/code&amp;gt;&lt;br /&gt;
|Create a participant&lt;br /&gt;
|-&lt;br /&gt;
|4&lt;br /&gt;
|update_permissions&lt;br /&gt;
|PATCH &amp;lt;code&amp;gt; /participants/:id/permissions &amp;lt;/code&amp;gt;&lt;br /&gt;
|Update the permissions of a participant&lt;br /&gt;
|-&lt;br /&gt;
|5&lt;br /&gt;
|update_handle&lt;br /&gt;
|PATCH &amp;lt;code&amp;gt; /participants/:id/handle &amp;lt;/code&amp;gt;&lt;br /&gt;
|Update the handle of a participant&lt;br /&gt;
|-&lt;br /&gt;
|6&lt;br /&gt;
|destroy&lt;br /&gt;
|DELETE &amp;lt;code&amp;gt; /participants/:id &amp;lt;/code&amp;gt;&lt;br /&gt;
|Delete a specified participant&lt;br /&gt;
|-&lt;br /&gt;
|7&lt;br /&gt;
|participant_params&lt;br /&gt;
| -&lt;br /&gt;
|Permitted parameters for creating or updating a Participant object&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
The following methods were removed from &amp;lt;code&amp;gt; participants_controller.rb &amp;lt;/code&amp;gt;:&lt;br /&gt;
&amp;lt;li&amp;gt; &amp;lt;code&amp;gt; action_allowed? &amp;lt;/code&amp;gt; - No impact on functionality &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; &amp;lt;code&amp;gt; controller_locale &amp;lt;/code&amp;gt; - No impact on functionality &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; &amp;lt;code&amp;gt; inherit &amp;lt;/code&amp;gt; - Since there is no direct relationship between the Participant and Course classes, this logic is redundant and no longer necessary &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; &amp;lt;code&amp;gt; bequeath_all &amp;lt;/code&amp;gt; - Since there is no direct relationship between the Participant and Course classes, this logic is redundant and no longer necessary &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; &amp;lt;code&amp;gt; delete &amp;lt;/code&amp;gt; - Handled in the &amp;lt;i&amp;gt; remove_participant &amp;lt;/i&amp;gt; method of the AssignmentsController (&amp;lt;code&amp;gt; assignments_controller.rb &amp;lt;/code&amp;gt;) &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; &amp;lt;code&amp;gt; view_copyright_grants &amp;lt;/code&amp;gt; - Incorrectly implemented in the old implementation &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; &amp;lt;code&amp;gt; get_user_info &amp;lt;/code&amp;gt; - All needed user data can be accessed by leveraging the Participant model's &amp;lt;i&amp;gt; belongs_to &amp;lt;/i&amp;gt; relationship to the User model &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; &amp;lt;code&amp;gt; get_signup_topics_for_assignment &amp;lt;/code&amp;gt; - Handled in the &amp;lt;i&amp;gt; index &amp;lt;/i&amp;gt; method of the SignUpTopicsController (&amp;lt;code&amp;gt; sign_up_topics_controller.rb &amp;lt;/code&amp;gt;) &amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===&amp;lt;code&amp;gt; participants_helper.rb &amp;lt;/code&amp;gt; Methods===&lt;br /&gt;
The methods in &amp;lt;code&amp;gt;participants_helper.rb&amp;lt;/code&amp;gt; are outdated and do not impact any functionality in &amp;lt;code&amp;gt;participants_controller.rb&amp;lt;/code&amp;gt;. &amp;lt;br/&amp;gt;&lt;br /&gt;
As a result, these methods will not be carried forward to the new implementation:&lt;br /&gt;
&amp;lt;li&amp;gt; &amp;lt;code&amp;gt; upload_users &amp;lt;/code&amp;gt; - Logic for creating a User specifically for the Assignment and Course classes. Since there is no direct relationship between the User and these classes, this logic is redundant and no longer necessary &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; &amp;lt;code&amp;gt; define_attributes &amp;lt;/code&amp;gt; - &amp;lt;i&amp;gt; Same reason as above &amp;lt;/i&amp;gt; &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; &amp;lt;code&amp;gt; define_user &amp;lt;/code&amp;gt; - &amp;lt;i&amp;gt; Same reason as above &amp;lt;/i&amp;gt; &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; &amp;lt;code&amp;gt; create_new_user &amp;lt;/code&amp;gt; - &amp;lt;i&amp;gt; Same reason as above &amp;lt;/i&amp;gt; &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; &amp;lt;code&amp;gt; add_user_to_assignment &amp;lt;/code&amp;gt; - &amp;lt;i&amp;gt; Same reason as above. &amp;lt;/i&amp;gt; Furthermore, since the Participant and Assignment classes are directly related, this functionality has been replaced by the &amp;lt;i&amp;gt; add_participant &amp;lt;/i&amp;gt; method in AssignmentsController (&amp;lt;code&amp;gt;assignments_controller.rb&amp;lt;/code&amp;gt;) &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; &amp;lt;code&amp;gt; add_user_to_course &amp;lt;/code&amp;gt; - &amp;lt;i&amp;gt; Same reason as above &amp;lt;/i&amp;gt; &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; &amp;lt;code&amp;gt; get_config &amp;lt;/code&amp;gt; - &amp;lt;i&amp;gt; Same reason as above &amp;lt;/i&amp;gt; &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; &amp;lt;code&amp;gt; store_item &amp;lt;/code&amp;gt; - &amp;lt;i&amp;gt; Same reason as above &amp;lt;/i&amp;gt; &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; &amp;lt;code&amp;gt; participant_permissions &amp;lt;/code&amp;gt; - Outdated way of updating permissions, handled more effectively by the &amp;lt;code&amp;gt;update_permissions&amp;lt;/code&amp;gt; method in ParticipantsController (&amp;lt;code&amp;gt;participants_controller.rb&amp;lt;/code&amp;gt;) &amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Pattern(s)===&lt;br /&gt;
'''Facade''': &amp;quot;A simplified interface that performs many other actions behind the scenes.&amp;quot; &amp;lt;br/&amp;gt;&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
===SOLID Principle(s)===&lt;br /&gt;
'''Open and Closed Principle''': &amp;quot;Software entities should be open for extension, but closed for modification.&amp;quot;&amp;lt;br/&amp;gt;&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
'''Single Responsibility Principle''': &amp;quot;A class should only have one responsibility and should never have more than one reason to change.&amp;quot;&amp;lt;br/&amp;gt;&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
==Implementation==&lt;br /&gt;
===Implement &amp;lt;code&amp;gt; participants_controller.rb &amp;lt;/code&amp;gt; Methods===&lt;br /&gt;
Refer to the [https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2024_-_E2484._Reimplement_participants_controller.rb#participants_controller.rb_Methods_/_API_Calls &amp;lt;code&amp;gt; participants_controller.rb &amp;lt;/code&amp;gt; Methods / API Calls] section for all design-related inquiries &amp;lt;br/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|+&lt;br /&gt;
! Old Method Name !! Action !! New Method Name&lt;br /&gt;
|-&lt;br /&gt;
| action_allowed? || Removed || -&lt;br /&gt;
|-&lt;br /&gt;
| controller_locale || Removed || -&lt;br /&gt;
|-&lt;br /&gt;
| list || Renamed || index&lt;br /&gt;
|-&lt;br /&gt;
| add || Renamed || create&lt;br /&gt;
|-&lt;br /&gt;
| update_authorizations || Renamed || update_permissions&lt;br /&gt;
|-&lt;br /&gt;
| destroy || No Change || destroy&lt;br /&gt;
|-&lt;br /&gt;
| inherit || Removed || -&lt;br /&gt;
|-&lt;br /&gt;
| bequeath_all || Removed || -&lt;br /&gt;
|-&lt;br /&gt;
| change_handle || Renamed || update_handle&lt;br /&gt;
|-&lt;br /&gt;
| delete || Removed || -&lt;br /&gt;
|-&lt;br /&gt;
| view_copyright_grants || Removed || -&lt;br /&gt;
|-&lt;br /&gt;
| participant_params || No Change || participant_params&lt;br /&gt;
|-&lt;br /&gt;
| get_user_info || Removed || -&lt;br /&gt;
|-&lt;br /&gt;
| get_signup_topics_for_assignment || Removed || -&lt;br /&gt;
|-&lt;br /&gt;
| - || Added || show&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;i&amp;gt; To be expanded upon during implementation &amp;lt;/i&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Import from &amp;lt;code&amp;gt; participants_helper.rb &amp;lt;/code&amp;gt;===&lt;br /&gt;
Refer to the [https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2024_-_E2484._Reimplement_participants_controller.rb#participants_helper.rb_Methods &amp;lt;code&amp;gt; participants_helper.rb &amp;lt;/code&amp;gt; Methods] section for all design-related inquiries &amp;lt;br/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|+&lt;br /&gt;
! Old Method Name !! Action !! New Method Name&lt;br /&gt;
|-&lt;br /&gt;
| upload_users || Removed || -&lt;br /&gt;
|-&lt;br /&gt;
| define_attributes || Removed || -&lt;br /&gt;
|-&lt;br /&gt;
| define_user || Removed || -&lt;br /&gt;
|-&lt;br /&gt;
| create_new_user || Removed || -&lt;br /&gt;
|-&lt;br /&gt;
| add_user_to_assignment || Removed || -&lt;br /&gt;
|-&lt;br /&gt;
| add_user_to_course || Removed || -&lt;br /&gt;
|-&lt;br /&gt;
| get_config || Removed || -&lt;br /&gt;
|-&lt;br /&gt;
| store_item || Removed || -&lt;br /&gt;
|-&lt;br /&gt;
| participant_permissions || Removed || -&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===API Creation===&lt;br /&gt;
Refer to the [https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2024_-_E2484._Reimplement_participants_controller.rb#participants_controller.rb_Methods_/_API_Calls &amp;lt;code&amp;gt; participants_controller.rb &amp;lt;/code&amp;gt; Methods / API Calls] section for all design-related inquiries &amp;lt;br/&amp;gt;&lt;br /&gt;
&amp;lt;i&amp;gt; To be expanded upon during implementation &amp;lt;/i&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Testing with rswag===&lt;br /&gt;
Refer to the [https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2024_-_E2484._Reimplement_participants_controller.rb#Testing_Plan Testing Plan] section &amp;lt;br/&amp;gt;&lt;br /&gt;
&amp;lt;i&amp;gt; To be expanded upon during implementation &amp;lt;/i&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Swagger UI Video Documentation===&lt;br /&gt;
&amp;lt;i&amp;gt; To be added at a later time &amp;lt;/i&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Testing Plan==&lt;br /&gt;
'''rswag'''&amp;lt;br/&amp;gt;&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
====Tests====&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;margin-left:40px&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Test ID !! Test Description &lt;br /&gt;
|-&lt;br /&gt;
| 1 || Test 'index' with valid model (Assignment) and ID - Should list participants&lt;br /&gt;
|-&lt;br /&gt;
| 2 || Test 'index' with invalid model (Assignment) and ID - Should return an error message&lt;br /&gt;
|-&lt;br /&gt;
| 3 || Test 'index' when there are no participants - Should return an empty list&lt;br /&gt;
|-&lt;br /&gt;
| 4 || Test 'show' with valid participant ID - Should return the specified participant details&lt;br /&gt;
|-&lt;br /&gt;
| 5 || Test 'show' with invalid participant ID - Should return participant not found&lt;br /&gt;
|-&lt;br /&gt;
| 6 || Test 'create' with valid user detail - Should successfully create a new participant&lt;br /&gt;
|-&lt;br /&gt;
| 7 || Test 'create' with duplicate user information - Should return an error message indicating that the participant already exists&lt;br /&gt;
|-&lt;br /&gt;
| 8 || Test 'create' with invalid data format - Should return a validation error&lt;br /&gt;
|-&lt;br /&gt;
| 9 || Test 'update_permissions' with valid participant ID and permissions - Should update participant’s permissions successfully&lt;br /&gt;
|-&lt;br /&gt;
| 10 || Test 'update_permissions' with valid participant ID and invalid permissions - Should return a validation error&lt;br /&gt;
|-&lt;br /&gt;
| 11 || Test `update_permissions` with invalid participant ID - Should return not found message&lt;br /&gt;
|-&lt;br /&gt;
| 12 || Test 'update_handle' with valid participant ID and unique handle - Should successfully update&lt;br /&gt;
|-&lt;br /&gt;
| 13 || Test 'update_handle' with duplicate handle - Should return an error message indicating handle is in use&lt;br /&gt;
|-&lt;br /&gt;
| 14 || Test 'update_handle' with invalid participant ID - Should return participant not found message&lt;br /&gt;
|-&lt;br /&gt;
| 15 || Test 'destroy' with valid participant ID - Should delete the specified participant&lt;br /&gt;
|-&lt;br /&gt;
| 16 || Test 'destroy' with invalid participant ID - Should return participant not found message&lt;br /&gt;
|-&lt;br /&gt;
| 17 || Test 'destroy for participant who has associated records - Should return an error message or handle the cascading deletions&lt;br /&gt;
|-&lt;br /&gt;
| 18 || Test 'participant_params' with all required parameters – Should proceed with the action&lt;br /&gt;
|-&lt;br /&gt;
| 19 || Test 'participant_params' with missing required parameters – Should return an error message&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==Team==&lt;br /&gt;
'''Mentor''' &lt;br /&gt;
&lt;br /&gt;
*Jay Patel &amp;lt;jhpatel9@ncsu.edu&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Students'''&lt;br /&gt;
&lt;br /&gt;
*Pierce Whelan &amp;lt;pwwhelan@ncsu.edu&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*Calvin Jiang &amp;lt;crjiang@ncsu.edu&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*Hechun Zhang &amp;lt;hzhang56@ncsu.edu&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Relevant Links ==&lt;br /&gt;
Pull Request [https://github.com/expertiza/reimplementation-back-end/pull/135] &amp;lt;br/&amp;gt;&lt;br /&gt;
GitHub Repository [https://github.com/Pierce57/participant_controller_reimplementation.git] &amp;lt;br/&amp;gt;&lt;br /&gt;
GitHub Project Board [https://github.com/users/Pierce57/projects/3] &amp;lt;br/&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt; participants_controller.rb &amp;lt;/code&amp;gt; in Old Expertiza [https://github.com/expertiza/expertiza/blob/main/app/controllers/participants_controller.rb] &amp;lt;br/&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt; participants_helper.rb &amp;lt;/code&amp;gt; in Old Expertiza [https://github.com/expertiza/expertiza/blob/main/app/helpers/participants_helper.rb]&lt;/div&gt;</summary>
		<author><name>Hzhang56</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2024_-_E2484._Reimplement_participants_controller.rb&amp;diff=159710</id>
		<title>CSC/ECE 517 Fall 2024 - E2484. Reimplement participants controller.rb</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2024_-_E2484._Reimplement_participants_controller.rb&amp;diff=159710"/>
		<updated>2024-11-18T04:07:01Z</updated>

		<summary type="html">&lt;p&gt;Hzhang56: /* SOLID Principle(s) */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==About Expertiza==&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is an open source project based on [http://rubyonrails.org/ 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.&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
This project aims to reimplement the &amp;lt;code&amp;gt; participants_controller.rb &amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt; participants_helper.rb &amp;lt;/code&amp;gt; in the new Expertiza system. The &amp;lt;code&amp;gt; participants_controller.rb &amp;lt;/code&amp;gt; manages participants within assignments, and this reimplementation focuses on streamlining its methods, eliminating redundancy, and enhancing code readability and maintainability.&lt;br /&gt;
&lt;br /&gt;
==Requirements==&lt;br /&gt;
&amp;lt;li&amp;gt; Implement &amp;lt;code&amp;gt; participants_controller.rb &amp;lt;/code&amp;gt; Methods: Fully implement each controller method with the same functionality as the current controller. &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Import from &amp;lt;code&amp;gt; participants_helper.rb &amp;lt;/code&amp;gt;: Integrate relevant helper methods to streamline functionality and remove redundancy. &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; API Creation: Expose API endpoints for all necessary methods to enable seamless access and integration from the frontend. Ensure that each endpoint follows best practices for RESTful API design, including proper error handling and secure data access. &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Testing with rswag: Create test cases for all methods, focusing on edge cases, and generate rswag documentation. &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Swagger UI Video Documentation: Record a video walkthrough of API endpoints in Swagger UI, showcasing each method’s functionality. &amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Existing Issues==&lt;br /&gt;
Reimplement &amp;lt;code&amp;gt; [https://github.com/expertiza/expertiza/blob/main/app/controllers/participants_controller.rb participants_controller.rb] &amp;lt;/code&amp;gt; while addressing the following:&lt;br /&gt;
&amp;lt;li&amp;gt; Refactor code to comply with the Open-Closed Principle and the Single Responsibility Principle. &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Introduce dependency injection where necessary. &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Reduce excessive conditional statements. &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Include sufficient code tests to verify functionality. &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Enhance comments to better explain each method's functionality, purpose, and rationale for keeping or modifying particular aspects of the code. &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Provide a more detailed explanation of design choices and refactoring steps. &amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Design / Proposed Solution ==&lt;br /&gt;
===Controller Diagram===&lt;br /&gt;
[[File:Participants Controller UML Diagram.png]]&lt;br /&gt;
&lt;br /&gt;
===API Calls===&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;width: 100%;&lt;br /&gt;
! &amp;amp;nbsp;#&amp;amp;nbsp; !! Method !! Endpoint !! Description &lt;br /&gt;
|-&lt;br /&gt;
|1&lt;br /&gt;
|index&lt;br /&gt;
|GET &amp;lt;code&amp;gt; /participants &amp;lt;/code&amp;gt;&lt;br /&gt;
|Return a list of participants&lt;br /&gt;
|-&lt;br /&gt;
|2&lt;br /&gt;
|show&lt;br /&gt;
|GET &amp;lt;code&amp;gt; /participants/:id &amp;lt;/code&amp;gt;&lt;br /&gt;
|Return a specified participant&lt;br /&gt;
|-&lt;br /&gt;
|3&lt;br /&gt;
|inherit&lt;br /&gt;
|GET &amp;lt;code&amp;gt; /participants/inherit &amp;lt;/code&amp;gt;&lt;br /&gt;
|Copy all participants from a course to an assignment&lt;br /&gt;
|-&lt;br /&gt;
|4&lt;br /&gt;
|bequeath&lt;br /&gt;
|GET &amp;lt;code&amp;gt; /participants/bequeath &amp;lt;/code&amp;gt;&lt;br /&gt;
|Copy all participants from an assignment to a course&lt;br /&gt;
|-&lt;br /&gt;
|5&lt;br /&gt;
|create&lt;br /&gt;
|POST &amp;lt;code&amp;gt; /participants &amp;lt;/code&amp;gt;&lt;br /&gt;
|Create a participant&lt;br /&gt;
|-&lt;br /&gt;
|6&lt;br /&gt;
|update_authorization&lt;br /&gt;
|PATCH &amp;lt;code&amp;gt; /participants/:id/authorization &amp;lt;/code&amp;gt;&lt;br /&gt;
|Update the permissions of a participant&lt;br /&gt;
|-&lt;br /&gt;
|7&lt;br /&gt;
|update_handle&lt;br /&gt;
|PATCH &amp;lt;code&amp;gt; /participants/:id/handle &amp;lt;/code&amp;gt;&lt;br /&gt;
|Update the handle of a participant&lt;br /&gt;
|-&lt;br /&gt;
|8&lt;br /&gt;
|destroy&lt;br /&gt;
|DELETE &amp;lt;code&amp;gt; /participants/:id &amp;lt;/code&amp;gt;&lt;br /&gt;
|Delete a specified participant&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
It is worth mentioning that the &amp;lt;code&amp;gt; view_copyright_grants &amp;lt;/code&amp;gt; method from the old implementation will not be brought forward as it was incorrectly implemented.&lt;br /&gt;
&lt;br /&gt;
===Helper Method(s)===&lt;br /&gt;
The methods in &amp;lt;code&amp;gt;participants_helper.rb&amp;lt;/code&amp;gt; are outdated and do not impact any functionality in &amp;lt;code&amp;gt;participants_controller.rb&amp;lt;/code&amp;gt;. Most of these methods pertain to retrieving user data and managing permissions—tasks that no longer require separate methods due to improved associations and centralized authorization management.&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
In addition, &amp;lt;code&amp;gt;authorization_helper.rb&amp;lt;/code&amp;gt; centralizes and manages all aspects of permissions and access control. This significantly simplifies the implementation, rendering much of the legacy logic redundant.&lt;br /&gt;
&lt;br /&gt;
As a result, the methods in &amp;lt;code&amp;gt;participants_helper.rb&amp;lt;/code&amp;gt; will not be carried forward to the new implementation. However, one method from the old Expertiza &amp;lt;code&amp;gt;participants_controller.rb&amp;lt;/code&amp;gt; implementation remains useful and will be retained:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;width: 50%;&amp;quot;&lt;br /&gt;
! # !! Method !! Description &lt;br /&gt;
|-&lt;br /&gt;
|1&lt;br /&gt;
|participant_params&lt;br /&gt;
|Permitted parameters for creating or updating a Participant object&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===Pattern(s)===&lt;br /&gt;
'''Facade''': &amp;quot;A simplified interface that performs many other actions behind the scenes.&amp;quot; &amp;lt;br/&amp;gt;&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
===SOLID Principle(s)===&lt;br /&gt;
'''Open and Closed Principle''': &amp;quot;Software entities should be open for extension, but closed for modification.&amp;quot;&amp;lt;br/&amp;gt;&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
'''Single Responsibility Principle''': &amp;quot;A class should only have one responsibility and should never have more than one reason to change.&amp;quot;&amp;lt;br/&amp;gt;&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
==Implementation==&lt;br /&gt;
===Implement &amp;lt;code&amp;gt; participants_controller.rb &amp;lt;/code&amp;gt; Methods===&lt;br /&gt;
Refer to the [https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2024_-_E2484._Reimplement_participants_controller.rb#API_Calls API Call] section for all design-related inquiries &amp;lt;br/&amp;gt;&lt;br /&gt;
&amp;lt;i&amp;gt; To be expanded upon during implementation &amp;lt;/i&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Import from &amp;lt;code&amp;gt; participants_helper.rb &amp;lt;/code&amp;gt;===&lt;br /&gt;
Refer to the [https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2024_-_E2484._Reimplement_participants_controller.rb#Helper_Method(s) Helper Methods] section for all design-related inquiries &amp;lt;br/&amp;gt;&lt;br /&gt;
&amp;lt;i&amp;gt; To be expanded upon during implementation &amp;lt;/i&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===API Creation===&lt;br /&gt;
Refer to the [https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2024_-_E2484._Reimplement_participants_controller.rb#API_Calls API Call] section for all design-related inquiries &amp;lt;br/&amp;gt;&lt;br /&gt;
&amp;lt;i&amp;gt; To be expanded upon during implementation &amp;lt;/i&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Testing with rswag===&lt;br /&gt;
Refer to the [https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2024_-_E2484._Reimplement_participants_controller.rb#Testing_Plan Testing Plan] section &amp;lt;br/&amp;gt;&lt;br /&gt;
&amp;lt;i&amp;gt; To be expanded upon during implementation &amp;lt;/i&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Swagger UI Video Documentation===&lt;br /&gt;
&amp;lt;i&amp;gt; To be added at a later time &amp;lt;/i&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Testing Plan==&lt;br /&gt;
'''rswag'''&amp;lt;br/&amp;gt;&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
====Tests====&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;margin-left:40px&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Test ID !! Test Description &lt;br /&gt;
|-&lt;br /&gt;
| 1 || Test 'index' with valid model (Assignment) and ID - Should list participants&lt;br /&gt;
|-&lt;br /&gt;
| 2 || Test 'index' with invalid model (Assignment) and ID - Should return an error message&lt;br /&gt;
|-&lt;br /&gt;
| 3 || Test 'show' with valid participant ID - Should return the specified participant details&lt;br /&gt;
|-&lt;br /&gt;
| 4 || Test 'show' with invalid participant ID - Should return participant not found&lt;br /&gt;
|-&lt;br /&gt;
| 5 || Test 'inherit' with valid assignment ID but no course participants - Should display a message indicating no participants were found to inherit&lt;br /&gt;
|-&lt;br /&gt;
| 6 || Test 'inherit' with invalid assignment ID - Should return assignment not found message&lt;br /&gt;
|-&lt;br /&gt;
| 7 || Test 'inherit' with valid assignment ID and course with participants - Should copy participants from course to assignment&lt;br /&gt;
|-&lt;br /&gt;
| 8 || Test 'bequeath' with valid assignment ID with no assignment participants - Should display a message indicating no participants were found&lt;br /&gt;
|-&lt;br /&gt;
| 9 || Test 'bequeath' with invalid assignment ID - Should return assignment not found message&lt;br /&gt;
|-&lt;br /&gt;
| 10 || Test 'bequeath' with valid assignment ID and course with participants - Should copy participants from assignment to course&lt;br /&gt;
|-&lt;br /&gt;
| 11 || Test 'create' with valid user detail - Should successfully create a new participant&lt;br /&gt;
|-&lt;br /&gt;
| 12 || Test 'create' with duplicate user information - Should return an error message indicating that the participant already exists&lt;br /&gt;
|-&lt;br /&gt;
| 13 || Test 'update_authorization' with valid participant ID and permissions - Should update participant’s permissions successfully&lt;br /&gt;
|-&lt;br /&gt;
| 14 || Test `update_authorization` with invalid participant ID - Should return not found message&lt;br /&gt;
|-&lt;br /&gt;
| 15 || Test 'update_handle' with valid participant ID and unique handle - Should successfully update&lt;br /&gt;
|-&lt;br /&gt;
| 16 || Test 'update_handle' with duplicate handle - Should return an error message indicating handle is in use&lt;br /&gt;
|-&lt;br /&gt;
| 17 || Test 'destroy' with valid participant ID - Should delete the specified participant&lt;br /&gt;
|-&lt;br /&gt;
| 18 || Test 'destroy' with invalid participant ID - Should return participant not found message&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==Team==&lt;br /&gt;
'''Mentor''' &lt;br /&gt;
&lt;br /&gt;
*Jay Patel &amp;lt;jhpatel9@ncsu.edu&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Students'''&lt;br /&gt;
&lt;br /&gt;
*Pierce Whelan &amp;lt;pwwhelan@ncsu.edu&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*Calvin Jiang &amp;lt;crjiang@ncsu.edu&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*Hechun Zhang &amp;lt;hzhang56@ncsu.edu&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Relevant Links ==&lt;br /&gt;
Pull Request [https://github.com/expertiza/reimplementation-back-end/pull/135] &amp;lt;br/&amp;gt;&lt;br /&gt;
GitHub Repository [https://github.com/Pierce57/participant_controller_reimplementation.git] &amp;lt;br/&amp;gt;&lt;br /&gt;
GitHub Project Board [https://github.com/users/Pierce57/projects/3] &amp;lt;br/&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt; participants_controller.rb &amp;lt;/code&amp;gt; in Old Expertiza [https://github.com/expertiza/expertiza/blob/main/app/controllers/participants_controller.rb] &amp;lt;br/&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt; participants_helper.rb &amp;lt;/code&amp;gt; in Old Expertiza [https://github.com/expertiza/expertiza/blob/main/app/helpers/participants_helper.rb]&lt;/div&gt;</summary>
		<author><name>Hzhang56</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2024_-_E2484._Reimplement_participants_controller.rb&amp;diff=159709</id>
		<title>CSC/ECE 517 Fall 2024 - E2484. Reimplement participants controller.rb</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2024_-_E2484._Reimplement_participants_controller.rb&amp;diff=159709"/>
		<updated>2024-11-18T04:06:35Z</updated>

		<summary type="html">&lt;p&gt;Hzhang56: /* SOLID Principle(s) */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==About Expertiza==&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is an open source project based on [http://rubyonrails.org/ 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.&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
This project aims to reimplement the &amp;lt;code&amp;gt; participants_controller.rb &amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt; participants_helper.rb &amp;lt;/code&amp;gt; in the new Expertiza system. The &amp;lt;code&amp;gt; participants_controller.rb &amp;lt;/code&amp;gt; manages participants within assignments, and this reimplementation focuses on streamlining its methods, eliminating redundancy, and enhancing code readability and maintainability.&lt;br /&gt;
&lt;br /&gt;
==Requirements==&lt;br /&gt;
&amp;lt;li&amp;gt; Implement &amp;lt;code&amp;gt; participants_controller.rb &amp;lt;/code&amp;gt; Methods: Fully implement each controller method with the same functionality as the current controller. &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Import from &amp;lt;code&amp;gt; participants_helper.rb &amp;lt;/code&amp;gt;: Integrate relevant helper methods to streamline functionality and remove redundancy. &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; API Creation: Expose API endpoints for all necessary methods to enable seamless access and integration from the frontend. Ensure that each endpoint follows best practices for RESTful API design, including proper error handling and secure data access. &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Testing with rswag: Create test cases for all methods, focusing on edge cases, and generate rswag documentation. &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Swagger UI Video Documentation: Record a video walkthrough of API endpoints in Swagger UI, showcasing each method’s functionality. &amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Existing Issues==&lt;br /&gt;
Reimplement &amp;lt;code&amp;gt; [https://github.com/expertiza/expertiza/blob/main/app/controllers/participants_controller.rb participants_controller.rb] &amp;lt;/code&amp;gt; while addressing the following:&lt;br /&gt;
&amp;lt;li&amp;gt; Refactor code to comply with the Open-Closed Principle and the Single Responsibility Principle. &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Introduce dependency injection where necessary. &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Reduce excessive conditional statements. &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Include sufficient code tests to verify functionality. &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Enhance comments to better explain each method's functionality, purpose, and rationale for keeping or modifying particular aspects of the code. &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Provide a more detailed explanation of design choices and refactoring steps. &amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Design / Proposed Solution ==&lt;br /&gt;
===Controller Diagram===&lt;br /&gt;
[[File:Participants Controller UML Diagram.png]]&lt;br /&gt;
&lt;br /&gt;
===API Calls===&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;width: 100%;&lt;br /&gt;
! &amp;amp;nbsp;#&amp;amp;nbsp; !! Method !! Endpoint !! Description &lt;br /&gt;
|-&lt;br /&gt;
|1&lt;br /&gt;
|index&lt;br /&gt;
|GET &amp;lt;code&amp;gt; /participants &amp;lt;/code&amp;gt;&lt;br /&gt;
|Return a list of participants&lt;br /&gt;
|-&lt;br /&gt;
|2&lt;br /&gt;
|show&lt;br /&gt;
|GET &amp;lt;code&amp;gt; /participants/:id &amp;lt;/code&amp;gt;&lt;br /&gt;
|Return a specified participant&lt;br /&gt;
|-&lt;br /&gt;
|3&lt;br /&gt;
|inherit&lt;br /&gt;
|GET &amp;lt;code&amp;gt; /participants/inherit &amp;lt;/code&amp;gt;&lt;br /&gt;
|Copy all participants from a course to an assignment&lt;br /&gt;
|-&lt;br /&gt;
|4&lt;br /&gt;
|bequeath&lt;br /&gt;
|GET &amp;lt;code&amp;gt; /participants/bequeath &amp;lt;/code&amp;gt;&lt;br /&gt;
|Copy all participants from an assignment to a course&lt;br /&gt;
|-&lt;br /&gt;
|5&lt;br /&gt;
|create&lt;br /&gt;
|POST &amp;lt;code&amp;gt; /participants &amp;lt;/code&amp;gt;&lt;br /&gt;
|Create a participant&lt;br /&gt;
|-&lt;br /&gt;
|6&lt;br /&gt;
|update_authorization&lt;br /&gt;
|PATCH &amp;lt;code&amp;gt; /participants/:id/authorization &amp;lt;/code&amp;gt;&lt;br /&gt;
|Update the permissions of a participant&lt;br /&gt;
|-&lt;br /&gt;
|7&lt;br /&gt;
|update_handle&lt;br /&gt;
|PATCH &amp;lt;code&amp;gt; /participants/:id/handle &amp;lt;/code&amp;gt;&lt;br /&gt;
|Update the handle of a participant&lt;br /&gt;
|-&lt;br /&gt;
|8&lt;br /&gt;
|destroy&lt;br /&gt;
|DELETE &amp;lt;code&amp;gt; /participants/:id &amp;lt;/code&amp;gt;&lt;br /&gt;
|Delete a specified participant&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
It is worth mentioning that the &amp;lt;code&amp;gt; view_copyright_grants &amp;lt;/code&amp;gt; method from the old implementation will not be brought forward as it was incorrectly implemented.&lt;br /&gt;
&lt;br /&gt;
===Helper Method(s)===&lt;br /&gt;
The methods in &amp;lt;code&amp;gt;participants_helper.rb&amp;lt;/code&amp;gt; are outdated and do not impact any functionality in &amp;lt;code&amp;gt;participants_controller.rb&amp;lt;/code&amp;gt;. Most of these methods pertain to retrieving user data and managing permissions—tasks that no longer require separate methods due to improved associations and centralized authorization management.&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
In addition, &amp;lt;code&amp;gt;authorization_helper.rb&amp;lt;/code&amp;gt; centralizes and manages all aspects of permissions and access control. This significantly simplifies the implementation, rendering much of the legacy logic redundant.&lt;br /&gt;
&lt;br /&gt;
As a result, the methods in &amp;lt;code&amp;gt;participants_helper.rb&amp;lt;/code&amp;gt; will not be carried forward to the new implementation. However, one method from the old Expertiza &amp;lt;code&amp;gt;participants_controller.rb&amp;lt;/code&amp;gt; implementation remains useful and will be retained:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;width: 50%;&amp;quot;&lt;br /&gt;
! # !! Method !! Description &lt;br /&gt;
|-&lt;br /&gt;
|1&lt;br /&gt;
|participant_params&lt;br /&gt;
|Permitted parameters for creating or updating a Participant object&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===Pattern(s)===&lt;br /&gt;
'''Facade''': &amp;quot;A simplified interface that performs many other actions behind the scenes.&amp;quot; &amp;lt;br/&amp;gt;&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
===SOLID Principle(s)===&lt;br /&gt;
'''Open and Closed Principle''': &amp;quot;Software entities should be open for extension, but closed for modification.&amp;quot;&amp;lt;br/&amp;gt;&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
'''Single Responsibility Principle''': &amp;quot;A class should only have one responsibility and should never have more than one reason to change.&amp;quot;&amp;lt;br/&amp;gt;&lt;br /&gt;
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 method. 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 help 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.&lt;br /&gt;
&lt;br /&gt;
==Implementation==&lt;br /&gt;
===Implement &amp;lt;code&amp;gt; participants_controller.rb &amp;lt;/code&amp;gt; Methods===&lt;br /&gt;
Refer to the [https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2024_-_E2484._Reimplement_participants_controller.rb#API_Calls API Call] section for all design-related inquiries &amp;lt;br/&amp;gt;&lt;br /&gt;
&amp;lt;i&amp;gt; To be expanded upon during implementation &amp;lt;/i&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Import from &amp;lt;code&amp;gt; participants_helper.rb &amp;lt;/code&amp;gt;===&lt;br /&gt;
Refer to the [https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2024_-_E2484._Reimplement_participants_controller.rb#Helper_Method(s) Helper Methods] section for all design-related inquiries &amp;lt;br/&amp;gt;&lt;br /&gt;
&amp;lt;i&amp;gt; To be expanded upon during implementation &amp;lt;/i&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===API Creation===&lt;br /&gt;
Refer to the [https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2024_-_E2484._Reimplement_participants_controller.rb#API_Calls API Call] section for all design-related inquiries &amp;lt;br/&amp;gt;&lt;br /&gt;
&amp;lt;i&amp;gt; To be expanded upon during implementation &amp;lt;/i&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Testing with rswag===&lt;br /&gt;
Refer to the [https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2024_-_E2484._Reimplement_participants_controller.rb#Testing_Plan Testing Plan] section &amp;lt;br/&amp;gt;&lt;br /&gt;
&amp;lt;i&amp;gt; To be expanded upon during implementation &amp;lt;/i&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Swagger UI Video Documentation===&lt;br /&gt;
&amp;lt;i&amp;gt; To be added at a later time &amp;lt;/i&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Testing Plan==&lt;br /&gt;
'''rswag'''&amp;lt;br/&amp;gt;&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
====Tests====&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;margin-left:40px&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Test ID !! Test Description &lt;br /&gt;
|-&lt;br /&gt;
| 1 || Test 'index' with valid model (Assignment) and ID - Should list participants&lt;br /&gt;
|-&lt;br /&gt;
| 2 || Test 'index' with invalid model (Assignment) and ID - Should return an error message&lt;br /&gt;
|-&lt;br /&gt;
| 3 || Test 'show' with valid participant ID - Should return the specified participant details&lt;br /&gt;
|-&lt;br /&gt;
| 4 || Test 'show' with invalid participant ID - Should return participant not found&lt;br /&gt;
|-&lt;br /&gt;
| 5 || Test 'inherit' with valid assignment ID but no course participants - Should display a message indicating no participants were found to inherit&lt;br /&gt;
|-&lt;br /&gt;
| 6 || Test 'inherit' with invalid assignment ID - Should return assignment not found message&lt;br /&gt;
|-&lt;br /&gt;
| 7 || Test 'inherit' with valid assignment ID and course with participants - Should copy participants from course to assignment&lt;br /&gt;
|-&lt;br /&gt;
| 8 || Test 'bequeath' with valid assignment ID with no assignment participants - Should display a message indicating no participants were found&lt;br /&gt;
|-&lt;br /&gt;
| 9 || Test 'bequeath' with invalid assignment ID - Should return assignment not found message&lt;br /&gt;
|-&lt;br /&gt;
| 10 || Test 'bequeath' with valid assignment ID and course with participants - Should copy participants from assignment to course&lt;br /&gt;
|-&lt;br /&gt;
| 11 || Test 'create' with valid user detail - Should successfully create a new participant&lt;br /&gt;
|-&lt;br /&gt;
| 12 || Test 'create' with duplicate user information - Should return an error message indicating that the participant already exists&lt;br /&gt;
|-&lt;br /&gt;
| 13 || Test 'update_authorization' with valid participant ID and permissions - Should update participant’s permissions successfully&lt;br /&gt;
|-&lt;br /&gt;
| 14 || Test `update_authorization` with invalid participant ID - Should return not found message&lt;br /&gt;
|-&lt;br /&gt;
| 15 || Test 'update_handle' with valid participant ID and unique handle - Should successfully update&lt;br /&gt;
|-&lt;br /&gt;
| 16 || Test 'update_handle' with duplicate handle - Should return an error message indicating handle is in use&lt;br /&gt;
|-&lt;br /&gt;
| 17 || Test 'destroy' with valid participant ID - Should delete the specified participant&lt;br /&gt;
|-&lt;br /&gt;
| 18 || Test 'destroy' with invalid participant ID - Should return participant not found message&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==Team==&lt;br /&gt;
'''Mentor''' &lt;br /&gt;
&lt;br /&gt;
*Jay Patel &amp;lt;jhpatel9@ncsu.edu&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Students'''&lt;br /&gt;
&lt;br /&gt;
*Pierce Whelan &amp;lt;pwwhelan@ncsu.edu&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*Calvin Jiang &amp;lt;crjiang@ncsu.edu&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*Hechun Zhang &amp;lt;hzhang56@ncsu.edu&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Relevant Links ==&lt;br /&gt;
Pull Request [https://github.com/expertiza/reimplementation-back-end/pull/135] &amp;lt;br/&amp;gt;&lt;br /&gt;
GitHub Repository [https://github.com/Pierce57/participant_controller_reimplementation.git] &amp;lt;br/&amp;gt;&lt;br /&gt;
GitHub Project Board [https://github.com/users/Pierce57/projects/3] &amp;lt;br/&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt; participants_controller.rb &amp;lt;/code&amp;gt; in Old Expertiza [https://github.com/expertiza/expertiza/blob/main/app/controllers/participants_controller.rb] &amp;lt;br/&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt; participants_helper.rb &amp;lt;/code&amp;gt; in Old Expertiza [https://github.com/expertiza/expertiza/blob/main/app/helpers/participants_helper.rb]&lt;/div&gt;</summary>
		<author><name>Hzhang56</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2024_-_E2484._Reimplement_participants_controller.rb&amp;diff=159708</id>
		<title>CSC/ECE 517 Fall 2024 - E2484. Reimplement participants controller.rb</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2024_-_E2484._Reimplement_participants_controller.rb&amp;diff=159708"/>
		<updated>2024-11-18T04:05:41Z</updated>

		<summary type="html">&lt;p&gt;Hzhang56: /* SOLID Principle(s) */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==About Expertiza==&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is an open source project based on [http://rubyonrails.org/ 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.&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
This project aims to reimplement the &amp;lt;code&amp;gt; participants_controller.rb &amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt; participants_helper.rb &amp;lt;/code&amp;gt; in the new Expertiza system. The &amp;lt;code&amp;gt; participants_controller.rb &amp;lt;/code&amp;gt; manages participants within assignments, and this reimplementation focuses on streamlining its methods, eliminating redundancy, and enhancing code readability and maintainability.&lt;br /&gt;
&lt;br /&gt;
==Requirements==&lt;br /&gt;
&amp;lt;li&amp;gt; Implement &amp;lt;code&amp;gt; participants_controller.rb &amp;lt;/code&amp;gt; Methods: Fully implement each controller method with the same functionality as the current controller. &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Import from &amp;lt;code&amp;gt; participants_helper.rb &amp;lt;/code&amp;gt;: Integrate relevant helper methods to streamline functionality and remove redundancy. &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; API Creation: Expose API endpoints for all necessary methods to enable seamless access and integration from the frontend. Ensure that each endpoint follows best practices for RESTful API design, including proper error handling and secure data access. &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Testing with rswag: Create test cases for all methods, focusing on edge cases, and generate rswag documentation. &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Swagger UI Video Documentation: Record a video walkthrough of API endpoints in Swagger UI, showcasing each method’s functionality. &amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Existing Issues==&lt;br /&gt;
Reimplement &amp;lt;code&amp;gt; [https://github.com/expertiza/expertiza/blob/main/app/controllers/participants_controller.rb participants_controller.rb] &amp;lt;/code&amp;gt; while addressing the following:&lt;br /&gt;
&amp;lt;li&amp;gt; Refactor code to comply with the Open-Closed Principle and the Single Responsibility Principle. &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Introduce dependency injection where necessary. &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Reduce excessive conditional statements. &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Include sufficient code tests to verify functionality. &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Enhance comments to better explain each method's functionality, purpose, and rationale for keeping or modifying particular aspects of the code. &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Provide a more detailed explanation of design choices and refactoring steps. &amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Design / Proposed Solution ==&lt;br /&gt;
===Controller Diagram===&lt;br /&gt;
[[File:Participants Controller UML Diagram.png]]&lt;br /&gt;
&lt;br /&gt;
===API Calls===&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;width: 100%;&lt;br /&gt;
! &amp;amp;nbsp;#&amp;amp;nbsp; !! Method !! Endpoint !! Description &lt;br /&gt;
|-&lt;br /&gt;
|1&lt;br /&gt;
|index&lt;br /&gt;
|GET &amp;lt;code&amp;gt; /participants &amp;lt;/code&amp;gt;&lt;br /&gt;
|Return a list of participants&lt;br /&gt;
|-&lt;br /&gt;
|2&lt;br /&gt;
|show&lt;br /&gt;
|GET &amp;lt;code&amp;gt; /participants/:id &amp;lt;/code&amp;gt;&lt;br /&gt;
|Return a specified participant&lt;br /&gt;
|-&lt;br /&gt;
|3&lt;br /&gt;
|inherit&lt;br /&gt;
|GET &amp;lt;code&amp;gt; /participants/inherit &amp;lt;/code&amp;gt;&lt;br /&gt;
|Copy all participants from a course to an assignment&lt;br /&gt;
|-&lt;br /&gt;
|4&lt;br /&gt;
|bequeath&lt;br /&gt;
|GET &amp;lt;code&amp;gt; /participants/bequeath &amp;lt;/code&amp;gt;&lt;br /&gt;
|Copy all participants from an assignment to a course&lt;br /&gt;
|-&lt;br /&gt;
|5&lt;br /&gt;
|create&lt;br /&gt;
|POST &amp;lt;code&amp;gt; /participants &amp;lt;/code&amp;gt;&lt;br /&gt;
|Create a participant&lt;br /&gt;
|-&lt;br /&gt;
|6&lt;br /&gt;
|update_authorization&lt;br /&gt;
|PATCH &amp;lt;code&amp;gt; /participants/:id/authorization &amp;lt;/code&amp;gt;&lt;br /&gt;
|Update the permissions of a participant&lt;br /&gt;
|-&lt;br /&gt;
|7&lt;br /&gt;
|update_handle&lt;br /&gt;
|PATCH &amp;lt;code&amp;gt; /participants/:id/handle &amp;lt;/code&amp;gt;&lt;br /&gt;
|Update the handle of a participant&lt;br /&gt;
|-&lt;br /&gt;
|8&lt;br /&gt;
|destroy&lt;br /&gt;
|DELETE &amp;lt;code&amp;gt; /participants/:id &amp;lt;/code&amp;gt;&lt;br /&gt;
|Delete a specified participant&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
It is worth mentioning that the &amp;lt;code&amp;gt; view_copyright_grants &amp;lt;/code&amp;gt; method from the old implementation will not be brought forward as it was incorrectly implemented.&lt;br /&gt;
&lt;br /&gt;
===Helper Method(s)===&lt;br /&gt;
The methods in &amp;lt;code&amp;gt;participants_helper.rb&amp;lt;/code&amp;gt; are outdated and do not impact any functionality in &amp;lt;code&amp;gt;participants_controller.rb&amp;lt;/code&amp;gt;. Most of these methods pertain to retrieving user data and managing permissions—tasks that no longer require separate methods due to improved associations and centralized authorization management.&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
In addition, &amp;lt;code&amp;gt;authorization_helper.rb&amp;lt;/code&amp;gt; centralizes and manages all aspects of permissions and access control. This significantly simplifies the implementation, rendering much of the legacy logic redundant.&lt;br /&gt;
&lt;br /&gt;
As a result, the methods in &amp;lt;code&amp;gt;participants_helper.rb&amp;lt;/code&amp;gt; will not be carried forward to the new implementation. However, one method from the old Expertiza &amp;lt;code&amp;gt;participants_controller.rb&amp;lt;/code&amp;gt; implementation remains useful and will be retained:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;width: 50%;&amp;quot;&lt;br /&gt;
! # !! Method !! Description &lt;br /&gt;
|-&lt;br /&gt;
|1&lt;br /&gt;
|participant_params&lt;br /&gt;
|Permitted parameters for creating or updating a Participant object&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===Pattern(s)===&lt;br /&gt;
'''Facade''': &amp;quot;A simplified interface that performs many other actions behind the scenes.&amp;quot; &amp;lt;br/&amp;gt;&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
===SOLID Principle(s)===&lt;br /&gt;
'''Open and Closed Principle''': &amp;quot;Software entities should be open for extension, but closed for modification.&amp;quot;&amp;lt;br/&amp;gt;&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
'''Single Responsibility Principle''': &amp;quot;A class should only have one responsibility and should never have more than one reason to change.&amp;quot;&amp;lt;br/&amp;gt;&lt;br /&gt;
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. 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 help 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.&lt;br /&gt;
&lt;br /&gt;
==Implementation==&lt;br /&gt;
===Implement &amp;lt;code&amp;gt; participants_controller.rb &amp;lt;/code&amp;gt; Methods===&lt;br /&gt;
Refer to the [https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2024_-_E2484._Reimplement_participants_controller.rb#API_Calls API Call] section for all design-related inquiries &amp;lt;br/&amp;gt;&lt;br /&gt;
&amp;lt;i&amp;gt; To be expanded upon during implementation &amp;lt;/i&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Import from &amp;lt;code&amp;gt; participants_helper.rb &amp;lt;/code&amp;gt;===&lt;br /&gt;
Refer to the [https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2024_-_E2484._Reimplement_participants_controller.rb#Helper_Method(s) Helper Methods] section for all design-related inquiries &amp;lt;br/&amp;gt;&lt;br /&gt;
&amp;lt;i&amp;gt; To be expanded upon during implementation &amp;lt;/i&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===API Creation===&lt;br /&gt;
Refer to the [https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2024_-_E2484._Reimplement_participants_controller.rb#API_Calls API Call] section for all design-related inquiries &amp;lt;br/&amp;gt;&lt;br /&gt;
&amp;lt;i&amp;gt; To be expanded upon during implementation &amp;lt;/i&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Testing with rswag===&lt;br /&gt;
Refer to the [https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2024_-_E2484._Reimplement_participants_controller.rb#Testing_Plan Testing Plan] section &amp;lt;br/&amp;gt;&lt;br /&gt;
&amp;lt;i&amp;gt; To be expanded upon during implementation &amp;lt;/i&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Swagger UI Video Documentation===&lt;br /&gt;
&amp;lt;i&amp;gt; To be added at a later time &amp;lt;/i&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Testing Plan==&lt;br /&gt;
'''rswag'''&amp;lt;br/&amp;gt;&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
====Tests====&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;margin-left:40px&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Test ID !! Test Description &lt;br /&gt;
|-&lt;br /&gt;
| 1 || Test 'index' with valid model (Assignment) and ID - Should list participants&lt;br /&gt;
|-&lt;br /&gt;
| 2 || Test 'index' with invalid model (Assignment) and ID - Should return an error message&lt;br /&gt;
|-&lt;br /&gt;
| 3 || Test 'show' with valid participant ID - Should return the specified participant details&lt;br /&gt;
|-&lt;br /&gt;
| 4 || Test 'show' with invalid participant ID - Should return participant not found&lt;br /&gt;
|-&lt;br /&gt;
| 5 || Test 'inherit' with valid assignment ID but no course participants - Should display a message indicating no participants were found to inherit&lt;br /&gt;
|-&lt;br /&gt;
| 6 || Test 'inherit' with invalid assignment ID - Should return assignment not found message&lt;br /&gt;
|-&lt;br /&gt;
| 7 || Test 'inherit' with valid assignment ID and course with participants - Should copy participants from course to assignment&lt;br /&gt;
|-&lt;br /&gt;
| 8 || Test 'bequeath' with valid assignment ID with no assignment participants - Should display a message indicating no participants were found&lt;br /&gt;
|-&lt;br /&gt;
| 9 || Test 'bequeath' with invalid assignment ID - Should return assignment not found message&lt;br /&gt;
|-&lt;br /&gt;
| 10 || Test 'bequeath' with valid assignment ID and course with participants - Should copy participants from assignment to course&lt;br /&gt;
|-&lt;br /&gt;
| 11 || Test 'create' with valid user detail - Should successfully create a new participant&lt;br /&gt;
|-&lt;br /&gt;
| 12 || Test 'create' with duplicate user information - Should return an error message indicating that the participant already exists&lt;br /&gt;
|-&lt;br /&gt;
| 13 || Test 'update_authorization' with valid participant ID and permissions - Should update participant’s permissions successfully&lt;br /&gt;
|-&lt;br /&gt;
| 14 || Test `update_authorization` with invalid participant ID - Should return not found message&lt;br /&gt;
|-&lt;br /&gt;
| 15 || Test 'update_handle' with valid participant ID and unique handle - Should successfully update&lt;br /&gt;
|-&lt;br /&gt;
| 16 || Test 'update_handle' with duplicate handle - Should return an error message indicating handle is in use&lt;br /&gt;
|-&lt;br /&gt;
| 17 || Test 'destroy' with valid participant ID - Should delete the specified participant&lt;br /&gt;
|-&lt;br /&gt;
| 18 || Test 'destroy' with invalid participant ID - Should return participant not found message&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==Team==&lt;br /&gt;
'''Mentor''' &lt;br /&gt;
&lt;br /&gt;
*Jay Patel &amp;lt;jhpatel9@ncsu.edu&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Students'''&lt;br /&gt;
&lt;br /&gt;
*Pierce Whelan &amp;lt;pwwhelan@ncsu.edu&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*Calvin Jiang &amp;lt;crjiang@ncsu.edu&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*Hechun Zhang &amp;lt;hzhang56@ncsu.edu&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Relevant Links ==&lt;br /&gt;
Pull Request [https://github.com/expertiza/reimplementation-back-end/pull/135] &amp;lt;br/&amp;gt;&lt;br /&gt;
GitHub Repository [https://github.com/Pierce57/participant_controller_reimplementation.git] &amp;lt;br/&amp;gt;&lt;br /&gt;
GitHub Project Board [https://github.com/users/Pierce57/projects/3] &amp;lt;br/&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt; participants_controller.rb &amp;lt;/code&amp;gt; in Old Expertiza [https://github.com/expertiza/expertiza/blob/main/app/controllers/participants_controller.rb] &amp;lt;br/&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt; participants_helper.rb &amp;lt;/code&amp;gt; in Old Expertiza [https://github.com/expertiza/expertiza/blob/main/app/helpers/participants_helper.rb]&lt;/div&gt;</summary>
		<author><name>Hzhang56</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2024_-_E2484._Reimplement_participants_controller.rb&amp;diff=159696</id>
		<title>CSC/ECE 517 Fall 2024 - E2484. Reimplement participants controller.rb</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2024_-_E2484._Reimplement_participants_controller.rb&amp;diff=159696"/>
		<updated>2024-11-18T03:51:57Z</updated>

		<summary type="html">&lt;p&gt;Hzhang56: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==About Expertiza==&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is an open source project based on [http://rubyonrails.org/ 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.&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
This project aims to reimplement the &amp;lt;code&amp;gt; participants_controller.rb &amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt; participants_helper.rb &amp;lt;/code&amp;gt; in the new Expertiza system. The &amp;lt;code&amp;gt; participants_controller.rb &amp;lt;/code&amp;gt; manages participants within assignments, and this reimplementation focuses on streamlining its methods, eliminating redundancy, and enhancing code readability and maintainability.&lt;br /&gt;
&lt;br /&gt;
==Requirements==&lt;br /&gt;
&amp;lt;li&amp;gt; Implement &amp;lt;code&amp;gt; participants_controller.rb &amp;lt;/code&amp;gt; Methods: Fully implement each controller method with the same functionality as the current controller. &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Import from &amp;lt;code&amp;gt; participants_helper.rb &amp;lt;/code&amp;gt;: Integrate relevant helper methods to streamline functionality and remove redundancy. &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; API Creation: Expose API endpoints for all necessary methods to enable seamless access and integration from the frontend. Ensure that each endpoint follows best practices for RESTful API design, including proper error handling and secure data access. &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Testing with rswag: Create test cases for all methods, focusing on edge cases, and generate rswag documentation. &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Swagger UI Video Documentation: Record a video walkthrough of API endpoints in Swagger UI, showcasing each method’s functionality. &amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Existing Issues==&lt;br /&gt;
Reimplement &amp;lt;code&amp;gt; [https://github.com/expertiza/expertiza/blob/main/app/controllers/participants_controller.rb participants_controller.rb] &amp;lt;/code&amp;gt; while addressing the following:&lt;br /&gt;
&amp;lt;li&amp;gt; Refactor code to comply with the Open-Closed Principle and the Single Responsibility Principle. &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Introduce dependency injection where necessary. &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Reduce excessive conditional statements. &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Include sufficient code tests to verify functionality. &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Enhance comments to better explain each method's functionality, purpose, and rationale for keeping or modifying particular aspects of the code. &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Provide a more detailed explanation of design choices and refactoring steps. &amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Design / Proposed Solution ==&lt;br /&gt;
===Controller Diagram===&lt;br /&gt;
&lt;br /&gt;
[[File:Participants Controller UML Diagram.png]]&lt;br /&gt;
&lt;br /&gt;
===API Calls===&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;width: 100%;&lt;br /&gt;
! &amp;amp;nbsp;#&amp;amp;nbsp; !! Method !! Endpoint !! Description &lt;br /&gt;
|-&lt;br /&gt;
|1&lt;br /&gt;
|index&lt;br /&gt;
|GET &amp;lt;code&amp;gt; /participants &amp;lt;/code&amp;gt;&lt;br /&gt;
|Return a list of participants&lt;br /&gt;
|-&lt;br /&gt;
|2&lt;br /&gt;
|show&lt;br /&gt;
|GET &amp;lt;code&amp;gt; /participants/:id &amp;lt;/code&amp;gt;&lt;br /&gt;
|Return a specified participant&lt;br /&gt;
|-&lt;br /&gt;
|3&lt;br /&gt;
|inherit&lt;br /&gt;
|GET &amp;lt;code&amp;gt; /participants/inherit &amp;lt;/code&amp;gt;&lt;br /&gt;
|Copy all participants from a course to an assignment&lt;br /&gt;
|-&lt;br /&gt;
|4&lt;br /&gt;
|bequeath&lt;br /&gt;
|GET &amp;lt;code&amp;gt; /participants/bequeath &amp;lt;/code&amp;gt;&lt;br /&gt;
|Copy all participants from an assignment to a course&lt;br /&gt;
|-&lt;br /&gt;
|5&lt;br /&gt;
|create&lt;br /&gt;
|POST &amp;lt;code&amp;gt; /participants &amp;lt;/code&amp;gt;&lt;br /&gt;
|Create a participant&lt;br /&gt;
|-&lt;br /&gt;
|6&lt;br /&gt;
|update_authorization&lt;br /&gt;
|PATCH &amp;lt;code&amp;gt; /participants/:id/authorization &amp;lt;/code&amp;gt;&lt;br /&gt;
|Update the permissions of a participant&lt;br /&gt;
|-&lt;br /&gt;
|7&lt;br /&gt;
|update_handle&lt;br /&gt;
|PATCH &amp;lt;code&amp;gt; /participants/:id/handle &amp;lt;/code&amp;gt;&lt;br /&gt;
|Update the handle of a participant&lt;br /&gt;
|-&lt;br /&gt;
|8&lt;br /&gt;
|destroy&lt;br /&gt;
|DELETE &amp;lt;code&amp;gt; /participants/:id &amp;lt;/code&amp;gt;&lt;br /&gt;
|Delete a specified participant&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
It is worth mentioning that the &amp;lt;code&amp;gt; view_copyright_grants &amp;lt;/code&amp;gt; method from the old implementation will not be brought forward as it was incorrectly implemented.&lt;br /&gt;
&lt;br /&gt;
===Helper Method(s)===&lt;br /&gt;
The methods in &amp;lt;code&amp;gt;participants_helper.rb&amp;lt;/code&amp;gt; are outdated and do not impact any functionality in &amp;lt;code&amp;gt;participants_controller.rb&amp;lt;/code&amp;gt;. Most of these methods pertain to retrieving user data and managing permissions—tasks that no longer require separate methods due to improved associations and centralized authorization management.&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
In addition, &amp;lt;code&amp;gt;authorization_helper.rb&amp;lt;/code&amp;gt; centralizes and manages all aspects of permissions and access control. This significantly simplifies the implementation, rendering much of the legacy logic redundant.&lt;br /&gt;
&lt;br /&gt;
As a result, the methods in &amp;lt;code&amp;gt;participants_helper.rb&amp;lt;/code&amp;gt; will not be carried forward to the new implementation. However, one method from the old Expertiza &amp;lt;code&amp;gt;participants_controller.rb&amp;lt;/code&amp;gt; implementation remains useful and will be retained:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;width: 50%;&amp;quot;&lt;br /&gt;
! # !! Method !! Description &lt;br /&gt;
|-&lt;br /&gt;
|1&lt;br /&gt;
|participant_params&lt;br /&gt;
|Permitted parameters for creating or updating a Participant object&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===Pattern(s)===&lt;br /&gt;
&lt;br /&gt;
'''Facade''': &amp;quot;A simplified interface that performs many other actions behind the scenes.&amp;quot; &amp;lt;br/&amp;gt;&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
===SOLID Principle(s)===&lt;br /&gt;
&lt;br /&gt;
'''Open and Closed Principle''': &amp;quot;Software entities should be open for extension, but closed for modification.&amp;quot;&amp;lt;br/&amp;gt;&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
'''Single Responsibility Principle''': &amp;quot;A class should only have one responsibility and should never have more than one reason to change.&amp;quot;&amp;lt;br/&amp;gt;&lt;br /&gt;
The current implementation of the participant controller mixes many responsibilities, such as authorization, handling different object types, and managing participants. We plan to use the Single Responsibility Principle to delegate each responsibility to separate classes and ensure each class has a single responsibility, with the participant controller as their coordinator. For instance, we can create an AuthorizationService Class that handles all the authorizations and permissions logic. Furthermore, we could also create a TeamService for team-related operations. By making these modifications, we 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.&lt;br /&gt;
&lt;br /&gt;
==Implementation==&lt;br /&gt;
&amp;lt;i&amp;gt;In progress&amp;lt;/i&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Testing Plan==&lt;br /&gt;
'''rswag'''&amp;lt;br/&amp;gt;&lt;br /&gt;
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.&lt;br /&gt;
====Tests====&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;margin-left:40px&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Test ID !! Test Description &lt;br /&gt;
|-&lt;br /&gt;
| 1 || Test 'index' with valid model (Assignment) and ID - Should list participants&lt;br /&gt;
|-&lt;br /&gt;
| 2 || Test 'index' with invalid model (Assignment) and ID - Should return an error message&lt;br /&gt;
|-&lt;br /&gt;
| 3 || Test 'show' with valid participant ID - Should return the specified participant details&lt;br /&gt;
|-&lt;br /&gt;
| 4 || Test 'show' with invalid participant ID - Should return participant not found&lt;br /&gt;
|-&lt;br /&gt;
| 5 || Test 'inherit' with valid assignment ID but no course participants - Should display a message indicating no participants were found to inherit&lt;br /&gt;
|-&lt;br /&gt;
| 6 || Test 'inherit' with invalid assignment ID - Should return assignment not found message&lt;br /&gt;
|-&lt;br /&gt;
| 7 || Test 'inherit' with valid assignment ID and course with participants - Should copy participants from course to assignment&lt;br /&gt;
|-&lt;br /&gt;
| 8 || Test 'bequeath' with valid assignment ID with no assignment participants - Should display a message indicating no participants were found&lt;br /&gt;
|-&lt;br /&gt;
| 9 || Test 'bequeath' with invalid assignment ID - Should return assignment not found message&lt;br /&gt;
|-&lt;br /&gt;
| 10 || Test 'bequeath' with valid assignment ID and course with participants - Should copy participants from assignment to course&lt;br /&gt;
|-&lt;br /&gt;
| 11 || Test 'create' with valid user detail - Should successfully create a new participant&lt;br /&gt;
|-&lt;br /&gt;
| 12 || Test 'create' with duplicate user information - Should return an error message indicating that the participant already exists&lt;br /&gt;
|-&lt;br /&gt;
| 13 || Test 'update_authorization' with valid participant ID and permissions - Should update participant’s permissions successfully&lt;br /&gt;
|-&lt;br /&gt;
| 14 || Test `update_authorization` with invalid participant ID - Should return not found message&lt;br /&gt;
|-&lt;br /&gt;
| 15 || Test 'update_handle' with valid participant ID and unique handle - Should successfully update&lt;br /&gt;
|-&lt;br /&gt;
| 16 || Test 'update_handle' with duplicate handle - Should return an error message indicating handle is in use&lt;br /&gt;
|-&lt;br /&gt;
| 17 || Test 'destroy' with valid participant ID - Should delete the specified participant&lt;br /&gt;
|-&lt;br /&gt;
| 18 || Test 'destroy' with invalid participant ID - Should return participant not found message&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==Team==&lt;br /&gt;
'''Mentor''' &lt;br /&gt;
&lt;br /&gt;
*Jay Patel &amp;lt;jhpatel9@ncsu.edu&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Students'''&lt;br /&gt;
&lt;br /&gt;
*Pierce Whelan &amp;lt;pwwhelan@ncsu.edu&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*Calvin Jiang &amp;lt;crjiang@ncsu.edu&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*Hechun Zhang &amp;lt;hzhang56@ncsu.edu&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Relevant Links ==&lt;br /&gt;
Pull Request [https://github.com/expertiza/reimplementation-back-end/pull/135] &amp;lt;br/&amp;gt;&lt;br /&gt;
GitHub Repository [https://github.com/Pierce57/participant_controller_reimplementation.git] &amp;lt;br/&amp;gt;&lt;br /&gt;
GitHub Project Board [https://github.com/users/Pierce57/projects/3] &amp;lt;br/&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt; participants_controller.rb &amp;lt;/code&amp;gt; in Old Expertiza [https://github.com/expertiza/expertiza/blob/main/app/controllers/participants_controller.rb] &amp;lt;br/&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt; participants_helper.rb &amp;lt;/code&amp;gt; in Old Expertiza [https://github.com/expertiza/expertiza/blob/main/app/helpers/participants_helper.rb]&lt;/div&gt;</summary>
		<author><name>Hzhang56</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2024_-_E2484._Reimplement_participants_controller.rb&amp;diff=159644</id>
		<title>CSC/ECE 517 Fall 2024 - E2484. Reimplement participants controller.rb</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2024_-_E2484._Reimplement_participants_controller.rb&amp;diff=159644"/>
		<updated>2024-11-18T00:23:35Z</updated>

		<summary type="html">&lt;p&gt;Hzhang56: /* SOLID Principle(s) */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==About Expertiza==&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is an open source project based on [http://rubyonrails.org/ 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.&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
This project aims to reimplement the &amp;lt;code&amp;gt; participants_controller.rb &amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt; participants_helper.rb &amp;lt;/code&amp;gt; in the new Expertiza system. The &amp;lt;code&amp;gt; participants_controller.rb &amp;lt;/code&amp;gt; manages participants within assignments, and this reimplementation focuses on streamlining its methods, eliminating redundancy, and enhancing code readability and maintainability.&lt;br /&gt;
&lt;br /&gt;
==Requirements==&lt;br /&gt;
&amp;lt;li&amp;gt; Implement &amp;lt;code&amp;gt; participants_controller.rb &amp;lt;/code&amp;gt; Methods: Fully implement each controller method with the same functionality as the current controller. &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Import from &amp;lt;code&amp;gt; participants_helper.rb &amp;lt;/code&amp;gt;: Integrate relevant helper methods to streamline functionality and remove redundancy. &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; API Creation: Expose API endpoints for all necessary methods to enable seamless access and integration from the frontend. Ensure that each endpoint follows best practices for RESTful API design, including proper error handling and secure data access. &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Testing with rswag: Create test cases for all methods, focusing on edge cases, and generate rswag documentation. &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Swagger UI Video Documentation: Record a video walkthrough of API endpoints in Swagger UI, showcasing each method’s functionality. &amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Existing Issues==&lt;br /&gt;
Reimplement &amp;lt;code&amp;gt; [https://github.com/expertiza/expertiza/blob/main/app/controllers/participants_controller.rb participants_controller.rb] &amp;lt;/code&amp;gt; while addressing the following:&lt;br /&gt;
&amp;lt;li&amp;gt; Refactor code to comply with the Open-Closed Principle and the Single Responsibility Principle. &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Introduce dependency injection where necessary. &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Reduce excessive conditional statements. &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Include sufficient code tests to verify functionality. &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Enhance comments to better explain each method's functionality, purpose, and rationale for keeping or modifying particular aspects of the code. &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Provide a more detailed explanation of design choices and refactoring steps. &amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Design==&lt;br /&gt;
===Pattern(s)===&lt;br /&gt;
&lt;br /&gt;
'''Facade''': &amp;quot;A simplified interface that performs many other actions behind the scenes.&amp;quot; &amp;lt;br/&amp;gt;&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
===SOLID Principle(s)===&lt;br /&gt;
&lt;br /&gt;
'''Open and Closed Principle''': &amp;quot;Software entities should be open for extension, but closed for modification.&amp;quot;&amp;lt;br/&amp;gt;&lt;br /&gt;
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 update_authorization, inherit, bequeath, 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.&lt;br /&gt;
&lt;br /&gt;
'''Single Responsibility Principle''': &amp;quot;A class should only have one responsibility and should never have more than one reason to change.&amp;quot;&amp;lt;br/&amp;gt;&lt;br /&gt;
The current implementation of the participant controller mixes many responsibilities, such as authorization, handling different object types, and managing participants. We plan to use the Single Responsibility Principle to delegate each responsibility to separate classes and ensure each class has a single responsibility, with the participant controller as their coordinator. For instance, we can create an AuthorizationService Class that handles all the authorizations and permissions logic. Furthermore, we could also create a TeamService for team-related operations. By making these modifications, we 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.&lt;br /&gt;
&lt;br /&gt;
===API Calls===&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;width: 100%;&lt;br /&gt;
! &amp;amp;nbsp;#&amp;amp;nbsp; !! Method !! Endpoint !! Description &lt;br /&gt;
|-&lt;br /&gt;
|1&lt;br /&gt;
|index&lt;br /&gt;
|GET &amp;lt;code&amp;gt; /participants &amp;lt;/code&amp;gt;&lt;br /&gt;
|Return a list of participants&lt;br /&gt;
|-&lt;br /&gt;
|2&lt;br /&gt;
|show&lt;br /&gt;
|GET &amp;lt;code&amp;gt; /participants/:id &amp;lt;/code&amp;gt;&lt;br /&gt;
|Return a specified participant&lt;br /&gt;
|-&lt;br /&gt;
|3&lt;br /&gt;
|inherit&lt;br /&gt;
|GET &amp;lt;code&amp;gt; /participants/inherit &amp;lt;/code&amp;gt;&lt;br /&gt;
|Copy all participants from a course to an assignment&lt;br /&gt;
|-&lt;br /&gt;
|4&lt;br /&gt;
|bequeath&lt;br /&gt;
|GET &amp;lt;code&amp;gt; /participants/bequeath &amp;lt;/code&amp;gt;&lt;br /&gt;
|Copy all participants from an assignment to a course&lt;br /&gt;
|-&lt;br /&gt;
|5&lt;br /&gt;
|create&lt;br /&gt;
|POST &amp;lt;code&amp;gt; /participants &amp;lt;/code&amp;gt;&lt;br /&gt;
|Create a participant&lt;br /&gt;
|-&lt;br /&gt;
|6&lt;br /&gt;
|update_authorization&lt;br /&gt;
|PATCH &amp;lt;code&amp;gt; /participants/:id/authorization &amp;lt;/code&amp;gt;&lt;br /&gt;
|Update the permissions of a participant&lt;br /&gt;
|-&lt;br /&gt;
|7&lt;br /&gt;
|update_handle&lt;br /&gt;
|PATCH &amp;lt;code&amp;gt; /participants/:id/handle &amp;lt;/code&amp;gt;&lt;br /&gt;
|Update the handle of a participant&lt;br /&gt;
|-&lt;br /&gt;
|8&lt;br /&gt;
|destroy&lt;br /&gt;
|DELETE &amp;lt;code&amp;gt; /participants/:id &amp;lt;/code&amp;gt;&lt;br /&gt;
|Delete a specified participant&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==Testing Plan==&lt;br /&gt;
'''rswag'''&amp;lt;br/&amp;gt;&lt;br /&gt;
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.&lt;br /&gt;
====Tests====&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;margin-left:40px&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Test ID !! Test Description &lt;br /&gt;
|-&lt;br /&gt;
| 1 || Test 'index' with valid model (Assignment) and ID - Should list participants&lt;br /&gt;
|-&lt;br /&gt;
| 2 || Test 'index' with invalid model (Assignment) and ID - Should return an error message&lt;br /&gt;
|-&lt;br /&gt;
| 3 || Test 'show' with valid participant ID - Should return the specified participant details&lt;br /&gt;
|-&lt;br /&gt;
| 4 || Test 'show' with invalid participant ID - Should return participant not found&lt;br /&gt;
|-&lt;br /&gt;
| 5 || Test 'inherit' with valid assignment ID but no course participants - Should display a message indicating no participants were found to inherit&lt;br /&gt;
|-&lt;br /&gt;
| 6 || Test 'inherit' with invalid assignment ID - Should return assignment not found message&lt;br /&gt;
|-&lt;br /&gt;
| 7 || Test 'inherit' with valid assignment ID and course with participants - Should copy participants from course to assignment&lt;br /&gt;
|-&lt;br /&gt;
| 8 || Test 'bequeath' with valid assignment ID with no assignment participants - Should display a message indicating no participants were found&lt;br /&gt;
|-&lt;br /&gt;
| 9 || Test 'bequeath' with invalid assignment ID - Should return assignment not found message&lt;br /&gt;
|-&lt;br /&gt;
| 10 || Test 'bequeath' with valid assignment ID and course with participants - Should copy participants from assignment to course&lt;br /&gt;
|-&lt;br /&gt;
| 11 || Test 'create' with valid user detail - Should successfully create a new participant&lt;br /&gt;
|-&lt;br /&gt;
| 12 || Test 'create' with duplicate user information - Should return an error message indicating that the participant already exists&lt;br /&gt;
|-&lt;br /&gt;
| 13 || Test 'update_authorization' with valid participant ID and permissions - Should update participant’s permissions successfully&lt;br /&gt;
|-&lt;br /&gt;
| 14 || Test `update_authorization` with invalid participant ID - Should return not found message&lt;br /&gt;
|-&lt;br /&gt;
| 15 || Test 'update_handle' with valid participant ID and unique handle - Should successfully update&lt;br /&gt;
|-&lt;br /&gt;
| 16 || Test 'update_handle' with duplicate handle - Should return an error message indicating handle is in use&lt;br /&gt;
|-&lt;br /&gt;
| 17 || Test 'destroy' with valid participant ID - Should delete the specified participant&lt;br /&gt;
|-&lt;br /&gt;
| 18 || Test 'destroy' with invalid participant ID - Should return participant not found message&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==Team==&lt;br /&gt;
'''Mentor''' &lt;br /&gt;
&lt;br /&gt;
*Jay Patel &amp;lt;jhpatel9@ncsu.edu&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Students'''&lt;br /&gt;
&lt;br /&gt;
*Pierce Whelan &amp;lt;pwwhelan@ncsu.edu&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*Calvin Jiang &amp;lt;crjiang@ncsu.edu&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*Hechun Zhang &amp;lt;hzhang56@ncsu.edu&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Relevant Links ==&lt;br /&gt;
Pull Request [https://github.com/expertiza/reimplementation-back-end/pull/135] &amp;lt;br/&amp;gt;&lt;br /&gt;
GitHub Repository [https://github.com/Pierce57/participant_controller_reimplementation.git] &amp;lt;br/&amp;gt;&lt;br /&gt;
GitHub Project Board [https://github.com/users/Pierce57/projects/3] &amp;lt;br/&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt; participants_controller.rb &amp;lt;/code&amp;gt; in Old Expertiza [https://github.com/expertiza/expertiza/blob/main/app/controllers/participants_controller.rb]&lt;/div&gt;</summary>
		<author><name>Hzhang56</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2024_-_E2484._Reimplement_participants_controller.rb&amp;diff=159643</id>
		<title>CSC/ECE 517 Fall 2024 - E2484. Reimplement participants controller.rb</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2024_-_E2484._Reimplement_participants_controller.rb&amp;diff=159643"/>
		<updated>2024-11-18T00:22:19Z</updated>

		<summary type="html">&lt;p&gt;Hzhang56: /* SOLID Principle(s) */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==About Expertiza==&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is an open source project based on [http://rubyonrails.org/ 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.&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
This project aims to reimplement the &amp;lt;code&amp;gt; participants_controller.rb &amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt; participants_helper.rb &amp;lt;/code&amp;gt; in the new Expertiza system. The &amp;lt;code&amp;gt; participants_controller.rb &amp;lt;/code&amp;gt; manages participants within assignments, and this reimplementation focuses on streamlining its methods, eliminating redundancy, and enhancing code readability and maintainability.&lt;br /&gt;
&lt;br /&gt;
==Requirements==&lt;br /&gt;
&amp;lt;li&amp;gt; Implement &amp;lt;code&amp;gt; participants_controller.rb &amp;lt;/code&amp;gt; Methods: Fully implement each controller method with the same functionality as the current controller. &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Import from &amp;lt;code&amp;gt; participants_helper.rb &amp;lt;/code&amp;gt;: Integrate relevant helper methods to streamline functionality and remove redundancy. &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; API Creation: Expose API endpoints for all necessary methods to enable seamless access and integration from the frontend. Ensure that each endpoint follows best practices for RESTful API design, including proper error handling and secure data access. &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Testing with rswag: Create test cases for all methods, focusing on edge cases, and generate rswag documentation. &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Swagger UI Video Documentation: Record a video walkthrough of API endpoints in Swagger UI, showcasing each method’s functionality. &amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Existing Issues==&lt;br /&gt;
Reimplement &amp;lt;code&amp;gt; [https://github.com/expertiza/expertiza/blob/main/app/controllers/participants_controller.rb participants_controller.rb] &amp;lt;/code&amp;gt; while addressing the following:&lt;br /&gt;
&amp;lt;li&amp;gt; Refactor code to comply with the Open-Closed Principle and the Single Responsibility Principle. &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Introduce dependency injection where necessary. &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Reduce excessive conditional statements. &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Include sufficient code tests to verify functionality. &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Enhance comments to better explain each method's functionality, purpose, and rationale for keeping or modifying particular aspects of the code. &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Provide a more detailed explanation of design choices and refactoring steps. &amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Design==&lt;br /&gt;
===Pattern(s)===&lt;br /&gt;
&lt;br /&gt;
'''Facade''': &amp;quot;A simplified interface that performs many other actions behind the scenes.&amp;quot; &amp;lt;br/&amp;gt;&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
===SOLID Principle(s)===&lt;br /&gt;
&lt;br /&gt;
'''Open and Closed Principle''': &amp;quot;Software entities should be open for extension, but closed for modification.&amp;quot;&amp;lt;br/&amp;gt;&lt;br /&gt;
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 update_authorization, inherit, bequeath, 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.&lt;br /&gt;
&lt;br /&gt;
'''Single Responsibility Principle''': &amp;quot;A class should only have one responsibility and should never have more than one reason to change.&amp;quot;&amp;lt;br/&amp;gt;&lt;br /&gt;
The current implementation of the participant controller mixes many responsibilities, such as authorization, handling different object types, and managing participants. We plan to use the Single Responsibility Principle to delegate each responsibility to separate classes and ensure each class has a single responsibility, and the participant controller will be their coordinator. For instance, we can create an AuthorizationService Class that handles all the authorizations and permissions logic. Furthermore, we could also create a TeamService for team-related operations. By making these modifications, we 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.&lt;br /&gt;
&lt;br /&gt;
===API Calls===&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;width: 100%;&lt;br /&gt;
! &amp;amp;nbsp;#&amp;amp;nbsp; !! Method !! Endpoint !! Description &lt;br /&gt;
|-&lt;br /&gt;
|1&lt;br /&gt;
|index&lt;br /&gt;
|GET &amp;lt;code&amp;gt; /participants &amp;lt;/code&amp;gt;&lt;br /&gt;
|Return a list of participants&lt;br /&gt;
|-&lt;br /&gt;
|2&lt;br /&gt;
|show&lt;br /&gt;
|GET &amp;lt;code&amp;gt; /participants/:id &amp;lt;/code&amp;gt;&lt;br /&gt;
|Return a specified participant&lt;br /&gt;
|-&lt;br /&gt;
|3&lt;br /&gt;
|inherit&lt;br /&gt;
|GET &amp;lt;code&amp;gt; /participants/inherit &amp;lt;/code&amp;gt;&lt;br /&gt;
|Copy all participants from a course to an assignment&lt;br /&gt;
|-&lt;br /&gt;
|4&lt;br /&gt;
|bequeath&lt;br /&gt;
|GET &amp;lt;code&amp;gt; /participants/bequeath &amp;lt;/code&amp;gt;&lt;br /&gt;
|Copy all participants from an assignment to a course&lt;br /&gt;
|-&lt;br /&gt;
|5&lt;br /&gt;
|create&lt;br /&gt;
|POST &amp;lt;code&amp;gt; /participants &amp;lt;/code&amp;gt;&lt;br /&gt;
|Create a participant&lt;br /&gt;
|-&lt;br /&gt;
|6&lt;br /&gt;
|update_authorization&lt;br /&gt;
|PATCH &amp;lt;code&amp;gt; /participants/:id/authorization &amp;lt;/code&amp;gt;&lt;br /&gt;
|Update the permissions of a participant&lt;br /&gt;
|-&lt;br /&gt;
|7&lt;br /&gt;
|update_handle&lt;br /&gt;
|PATCH &amp;lt;code&amp;gt; /participants/:id/handle &amp;lt;/code&amp;gt;&lt;br /&gt;
|Update the handle of a participant&lt;br /&gt;
|-&lt;br /&gt;
|8&lt;br /&gt;
|destroy&lt;br /&gt;
|DELETE &amp;lt;code&amp;gt; /participants/:id &amp;lt;/code&amp;gt;&lt;br /&gt;
|Delete a specified participant&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==Testing Plan==&lt;br /&gt;
'''rswag'''&amp;lt;br/&amp;gt;&lt;br /&gt;
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.&lt;br /&gt;
====Tests====&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;margin-left:40px&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Test ID !! Test Description &lt;br /&gt;
|-&lt;br /&gt;
| 1 || Test 'index' with valid model (Assignment) and ID - Should list participants&lt;br /&gt;
|-&lt;br /&gt;
| 2 || Test 'index' with invalid model (Assignment) and ID - Should return an error message&lt;br /&gt;
|-&lt;br /&gt;
| 3 || Test 'show' with valid participant ID - Should return the specified participant details&lt;br /&gt;
|-&lt;br /&gt;
| 4 || Test 'show' with invalid participant ID - Should return participant not found&lt;br /&gt;
|-&lt;br /&gt;
| 5 || Test 'inherit' with valid assignment ID but no course participants - Should display a message indicating no participants were found to inherit&lt;br /&gt;
|-&lt;br /&gt;
| 6 || Test 'inherit' with invalid assignment ID - Should return assignment not found message&lt;br /&gt;
|-&lt;br /&gt;
| 7 || Test 'inherit' with valid assignment ID and course with participants - Should copy participants from course to assignment&lt;br /&gt;
|-&lt;br /&gt;
| 8 || Test 'bequeath' with valid assignment ID with no assignment participants - Should display a message indicating no participants were found&lt;br /&gt;
|-&lt;br /&gt;
| 9 || Test 'bequeath' with invalid assignment ID - Should return assignment not found message&lt;br /&gt;
|-&lt;br /&gt;
| 10 || Test 'bequeath' with valid assignment ID and course with participants - Should copy participants from assignment to course&lt;br /&gt;
|-&lt;br /&gt;
| 11 || Test 'create' with valid user detail - Should successfully create a new participant&lt;br /&gt;
|-&lt;br /&gt;
| 12 || Test 'create' with duplicate user information - Should return an error message indicating that the participant already exists&lt;br /&gt;
|-&lt;br /&gt;
| 13 || Test 'update_authorization' with valid participant ID and permissions - Should update participant’s permissions successfully&lt;br /&gt;
|-&lt;br /&gt;
| 14 || Test `update_authorization` with invalid participant ID - Should return not found message&lt;br /&gt;
|-&lt;br /&gt;
| 15 || Test 'update_handle' with valid participant ID and unique handle - Should successfully update&lt;br /&gt;
|-&lt;br /&gt;
| 16 || Test 'update_handle' with duplicate handle - Should return an error message indicating handle is in use&lt;br /&gt;
|-&lt;br /&gt;
| 17 || Test 'destroy' with valid participant ID - Should delete the specified participant&lt;br /&gt;
|-&lt;br /&gt;
| 18 || Test 'destroy' with invalid participant ID - Should return participant not found message&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==Team==&lt;br /&gt;
'''Mentor''' &lt;br /&gt;
&lt;br /&gt;
*Jay Patel &amp;lt;jhpatel9@ncsu.edu&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Students'''&lt;br /&gt;
&lt;br /&gt;
*Pierce Whelan &amp;lt;pwwhelan@ncsu.edu&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*Calvin Jiang &amp;lt;crjiang@ncsu.edu&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*Hechun Zhang &amp;lt;hzhang56@ncsu.edu&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Relevant Links ==&lt;br /&gt;
Pull Request [https://github.com/expertiza/reimplementation-back-end/pull/135] &amp;lt;br/&amp;gt;&lt;br /&gt;
GitHub Repository [https://github.com/Pierce57/participant_controller_reimplementation.git] &amp;lt;br/&amp;gt;&lt;br /&gt;
GitHub Project Board [https://github.com/users/Pierce57/projects/3] &amp;lt;br/&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt; participants_controller.rb &amp;lt;/code&amp;gt; in Old Expertiza [https://github.com/expertiza/expertiza/blob/main/app/controllers/participants_controller.rb]&lt;/div&gt;</summary>
		<author><name>Hzhang56</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2024_-_E2484._Reimplement_participants_controller.rb&amp;diff=159634</id>
		<title>CSC/ECE 517 Fall 2024 - E2484. Reimplement participants controller.rb</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2024_-_E2484._Reimplement_participants_controller.rb&amp;diff=159634"/>
		<updated>2024-11-17T21:17:39Z</updated>

		<summary type="html">&lt;p&gt;Hzhang56: /* SOLID Principle(s) */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==About Expertiza==&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is an open source project based on [http://rubyonrails.org/ 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.&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
This project aims to reimplement the &amp;lt;code&amp;gt; participants_controller.rb &amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt; participants_helper.rb &amp;lt;/code&amp;gt; in the new Expertiza system. The &amp;lt;code&amp;gt; participants_controller.rb &amp;lt;/code&amp;gt; manages participants within assignments, and this reimplementation focuses on streamlining its methods, eliminating redundancy, and enhancing code readability and maintainability.&lt;br /&gt;
&lt;br /&gt;
==Requirements==&lt;br /&gt;
&amp;lt;li&amp;gt; Implement &amp;lt;code&amp;gt; participants_controller.rb &amp;lt;/code&amp;gt; Methods: Fully implement each controller method with the same functionality as the current controller. &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Import from &amp;lt;code&amp;gt; participants_helper.rb &amp;lt;/code&amp;gt;: Integrate relevant helper methods to streamline functionality and remove redundancy. &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; API Creation: Expose API endpoints for all necessary methods to enable seamless access and integration from the frontend. Ensure that each endpoint follows best practices for RESTful API design, including proper error handling and secure data access. &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Testing with rswag: Create test cases for all methods, focusing on edge cases, and generate rswag documentation. &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Swagger UI Video Documentation: Record a video walkthrough of API endpoints in Swagger UI, showcasing each method’s functionality. &amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Existing Issues==&lt;br /&gt;
Reimplement &amp;lt;code&amp;gt; [https://github.com/expertiza/expertiza/blob/main/app/controllers/participants_controller.rb participants_controller.rb] &amp;lt;/code&amp;gt; while addressing the following:&lt;br /&gt;
&amp;lt;li&amp;gt; Refactor code to comply with the Open-Closed Principle and the Single Responsibility Principle. &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Introduce dependency injection where necessary. &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Reduce excessive conditional statements. &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Include sufficient code tests to verify functionality. &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Enhance comments to better explain each method's functionality, purpose, and rationale for keeping or modifying particular aspects of the code. &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Provide a more detailed explanation of design choices and refactoring steps. &amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Design==&lt;br /&gt;
===Pattern(s)===&lt;br /&gt;
&lt;br /&gt;
'''Facade''': &amp;quot;A simplified interface that performs many other actions behind the scenes.&amp;quot; &amp;lt;br/&amp;gt;&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
===SOLID Principle(s)===&lt;br /&gt;
&lt;br /&gt;
'''Open and Closed Principle''': &amp;quot;Software entities should be open for extension, but closed for modification.&amp;quot;&amp;lt;br/&amp;gt;&lt;br /&gt;
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. We plan on implementing polymorphism which could allow each class (e.g., Assignment, Course) to handle participant-related logic through inheritance or composition.&amp;lt;br/&amp;gt;&amp;lt;br/&amp;gt;&lt;br /&gt;
'''Single Responsibility Principle''': &amp;quot;A class should only have one responsibility and should never have more than one reason to change.&amp;quot;&amp;lt;br/&amp;gt;&lt;br /&gt;
The current implementation of the participant controller mixes many responsibilities, such as authorization, handling different object types, and managing participants. We plan to use the Single Responsibility Principle to delegate each responsibility to separate classes and ensure each class has a single responsibility, and the participant controller will be their coordinator.&lt;br /&gt;
&lt;br /&gt;
===API Calls===&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;width: 100%;&lt;br /&gt;
! &amp;amp;nbsp;#&amp;amp;nbsp; !! Method !! Endpoint !! Description &lt;br /&gt;
|-&lt;br /&gt;
|1&lt;br /&gt;
|index&lt;br /&gt;
|GET &amp;lt;code&amp;gt; /participants &amp;lt;/code&amp;gt;&lt;br /&gt;
|Return a list of participants&lt;br /&gt;
|-&lt;br /&gt;
|2&lt;br /&gt;
|show&lt;br /&gt;
|GET &amp;lt;code&amp;gt; /participants/:id &amp;lt;/code&amp;gt;&lt;br /&gt;
|Return a specified participant&lt;br /&gt;
|-&lt;br /&gt;
|3&lt;br /&gt;
|inherit&lt;br /&gt;
|GET &amp;lt;code&amp;gt; /participants/inherit &amp;lt;/code&amp;gt;&lt;br /&gt;
|Copy all participants from a course to an assignment&lt;br /&gt;
|-&lt;br /&gt;
|4&lt;br /&gt;
|bequeath&lt;br /&gt;
|GET &amp;lt;code&amp;gt; /participants/bequeath &amp;lt;/code&amp;gt;&lt;br /&gt;
|Copy all participants from an assignment to a course&lt;br /&gt;
|-&lt;br /&gt;
|5&lt;br /&gt;
|create&lt;br /&gt;
|POST &amp;lt;code&amp;gt; /participants &amp;lt;/code&amp;gt;&lt;br /&gt;
|Create a participant&lt;br /&gt;
|-&lt;br /&gt;
|6&lt;br /&gt;
|update_authorization&lt;br /&gt;
|PATCH &amp;lt;code&amp;gt; /participants/:id/authorization &amp;lt;/code&amp;gt;&lt;br /&gt;
|Update the permissions of a participant&lt;br /&gt;
|-&lt;br /&gt;
|7&lt;br /&gt;
|update_handle&lt;br /&gt;
|PATCH &amp;lt;code&amp;gt; /participants/:id/handle &amp;lt;/code&amp;gt;&lt;br /&gt;
|Update the handle of a participant&lt;br /&gt;
|-&lt;br /&gt;
|8&lt;br /&gt;
|destroy&lt;br /&gt;
|DELETE &amp;lt;code&amp;gt; /participants/:id &amp;lt;/code&amp;gt;&lt;br /&gt;
|Delete a specified participant&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==Testing Plan==&lt;br /&gt;
'''rswag'''&amp;lt;br/&amp;gt;&lt;br /&gt;
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.&lt;br /&gt;
====Tests====&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;margin-left:40px&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Test ID !! Test Description &lt;br /&gt;
|-&lt;br /&gt;
| 1 || Test 'index' with valid model (Assignment) and ID - Should list participants&lt;br /&gt;
|-&lt;br /&gt;
| 2 || Test 'index' with invalid model (Assignment) and ID - Should return an error message&lt;br /&gt;
|-&lt;br /&gt;
| 3 || Test 'show' with valid participant ID - Should return the specified participant details&lt;br /&gt;
|-&lt;br /&gt;
| 4 || Test 'show' with invalid participant ID - Should return participant not found&lt;br /&gt;
|-&lt;br /&gt;
| 5 || Test 'inherit' with valid assignment ID but no course participants - Should display a message indicating no participants were found to inherit&lt;br /&gt;
|-&lt;br /&gt;
| 6 || Test 'inherit' with invalid assignment ID - Should return assignment not found message&lt;br /&gt;
|-&lt;br /&gt;
| 7 || Test 'inherit' with valid assignment ID and course with participants - Should copy participants from course to assignment&lt;br /&gt;
|-&lt;br /&gt;
| 8 || Test 'bequeath' with valid assignment ID with no assignment participants - Should display a message indicating no participants were found&lt;br /&gt;
|-&lt;br /&gt;
| 9 || Test 'bequeath' with invalid assignment ID - Should return assignment not found message&lt;br /&gt;
|-&lt;br /&gt;
| 10 || Test 'bequeath' with valid assignment ID and course with participants - Should copy participants from assignment to course&lt;br /&gt;
|-&lt;br /&gt;
| 11 || Test 'create' with valid user detail - Should successfully create a new participant&lt;br /&gt;
|-&lt;br /&gt;
| 12 || Test 'create' with duplicate user information - Should return an error message indicating that the participant already exists&lt;br /&gt;
|-&lt;br /&gt;
| 13 || Test 'update_authorization' with valid participant ID and permissions - Should update participant’s permissions successfully&lt;br /&gt;
|-&lt;br /&gt;
| 14 || Test `update_authorization` with invalid participant ID - Should return not found message&lt;br /&gt;
|-&lt;br /&gt;
| 15 || Test 'update_handle' with valid participant ID and unique handle - Should successfully update&lt;br /&gt;
|-&lt;br /&gt;
| 16 || Test 'update_handle' with duplicate handle - Should return an error message indicating handle is in use&lt;br /&gt;
|-&lt;br /&gt;
| 17 || Test 'destroy' with valid participant ID - Should delete the specified participant&lt;br /&gt;
|-&lt;br /&gt;
| 18 || Test 'destroy' with invalid participant ID - Should return participant not found message&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==Team==&lt;br /&gt;
'''Mentor''' &lt;br /&gt;
&lt;br /&gt;
*Jay Patel &amp;lt;jhpatel9@ncsu.edu&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Students'''&lt;br /&gt;
&lt;br /&gt;
*Pierce Whelan &amp;lt;pwwhelan@ncsu.edu&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*Calvin Jiang &amp;lt;crjiang@ncsu.edu&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*Hechun Zhang &amp;lt;hzhang56@ncsu.edu&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Relevant Links ==&lt;br /&gt;
Pull Request [https://github.com/expertiza/reimplementation-back-end/pull/135] &amp;lt;br/&amp;gt;&lt;br /&gt;
GitHub Repository [https://github.com/Pierce57/participant_controller_reimplementation.git] &amp;lt;br/&amp;gt;&lt;br /&gt;
GitHub Project Board [https://github.com/users/Pierce57/projects/3] &amp;lt;br/&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt; participants_controller.rb &amp;lt;/code&amp;gt; in Old Expertiza [https://github.com/expertiza/expertiza/blob/main/app/controllers/participants_controller.rb]&lt;/div&gt;</summary>
		<author><name>Hzhang56</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2024_-_E2484._Reimplement_participants_controller.rb&amp;diff=159633</id>
		<title>CSC/ECE 517 Fall 2024 - E2484. Reimplement participants controller.rb</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2024_-_E2484._Reimplement_participants_controller.rb&amp;diff=159633"/>
		<updated>2024-11-17T21:17:24Z</updated>

		<summary type="html">&lt;p&gt;Hzhang56: /* SOLID Principle(s) */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==About Expertiza==&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is an open source project based on [http://rubyonrails.org/ 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.&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
This project aims to reimplement the &amp;lt;code&amp;gt; participants_controller.rb &amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt; participants_helper.rb &amp;lt;/code&amp;gt; in the new Expertiza system. The &amp;lt;code&amp;gt; participants_controller.rb &amp;lt;/code&amp;gt; manages participants within assignments, and this reimplementation focuses on streamlining its methods, eliminating redundancy, and enhancing code readability and maintainability.&lt;br /&gt;
&lt;br /&gt;
==Requirements==&lt;br /&gt;
&amp;lt;li&amp;gt; Implement &amp;lt;code&amp;gt; participants_controller.rb &amp;lt;/code&amp;gt; Methods: Fully implement each controller method with the same functionality as the current controller. &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Import from &amp;lt;code&amp;gt; participants_helper.rb &amp;lt;/code&amp;gt;: Integrate relevant helper methods to streamline functionality and remove redundancy. &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; API Creation: Expose API endpoints for all necessary methods to enable seamless access and integration from the frontend. Ensure that each endpoint follows best practices for RESTful API design, including proper error handling and secure data access. &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Testing with rswag: Create test cases for all methods, focusing on edge cases, and generate rswag documentation. &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Swagger UI Video Documentation: Record a video walkthrough of API endpoints in Swagger UI, showcasing each method’s functionality. &amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Existing Issues==&lt;br /&gt;
Reimplement &amp;lt;code&amp;gt; [https://github.com/expertiza/expertiza/blob/main/app/controllers/participants_controller.rb participants_controller.rb] &amp;lt;/code&amp;gt; while addressing the following:&lt;br /&gt;
&amp;lt;li&amp;gt; Refactor code to comply with the Open-Closed Principle and the Single Responsibility Principle. &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Introduce dependency injection where necessary. &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Reduce excessive conditional statements. &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Include sufficient code tests to verify functionality. &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Enhance comments to better explain each method's functionality, purpose, and rationale for keeping or modifying particular aspects of the code. &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Provide a more detailed explanation of design choices and refactoring steps. &amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Design==&lt;br /&gt;
===Pattern(s)===&lt;br /&gt;
&lt;br /&gt;
'''Facade''': &amp;quot;A simplified interface that performs many other actions behind the scenes.&amp;quot; &amp;lt;br/&amp;gt;&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
===SOLID Principle(s)===&lt;br /&gt;
&lt;br /&gt;
'''Open and Closed Principle''': &amp;quot;Software entities should be open for extension, but closed for modification.&amp;quot;&amp;lt;br/&amp;gt;&lt;br /&gt;
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. We plan on implementing polymorphism which could allow each class (e.g., Assignment, Course) to handle participant-related logic through inheritance or composition.&amp;lt;br/&amp;gt;&lt;br /&gt;
'''Single Responsibility Principle''': &amp;quot;A class should only have one responsibility and should never have more than one reason to change.&amp;quot;&amp;lt;br/&amp;gt;&lt;br /&gt;
The current implementation of the participant controller mixes many responsibilities, such as authorization, handling different object types, and managing participants. We plan to use the Single Responsibility Principle to delegate each responsibility to separate classes and ensure each class has a single responsibility, and the participant controller will be their coordinator.&lt;br /&gt;
&lt;br /&gt;
===API Calls===&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;width: 100%;&lt;br /&gt;
! &amp;amp;nbsp;#&amp;amp;nbsp; !! Method !! Endpoint !! Description &lt;br /&gt;
|-&lt;br /&gt;
|1&lt;br /&gt;
|index&lt;br /&gt;
|GET &amp;lt;code&amp;gt; /participants &amp;lt;/code&amp;gt;&lt;br /&gt;
|Return a list of participants&lt;br /&gt;
|-&lt;br /&gt;
|2&lt;br /&gt;
|show&lt;br /&gt;
|GET &amp;lt;code&amp;gt; /participants/:id &amp;lt;/code&amp;gt;&lt;br /&gt;
|Return a specified participant&lt;br /&gt;
|-&lt;br /&gt;
|3&lt;br /&gt;
|inherit&lt;br /&gt;
|GET &amp;lt;code&amp;gt; /participants/inherit &amp;lt;/code&amp;gt;&lt;br /&gt;
|Copy all participants from a course to an assignment&lt;br /&gt;
|-&lt;br /&gt;
|4&lt;br /&gt;
|bequeath&lt;br /&gt;
|GET &amp;lt;code&amp;gt; /participants/bequeath &amp;lt;/code&amp;gt;&lt;br /&gt;
|Copy all participants from an assignment to a course&lt;br /&gt;
|-&lt;br /&gt;
|5&lt;br /&gt;
|create&lt;br /&gt;
|POST &amp;lt;code&amp;gt; /participants &amp;lt;/code&amp;gt;&lt;br /&gt;
|Create a participant&lt;br /&gt;
|-&lt;br /&gt;
|6&lt;br /&gt;
|update_authorization&lt;br /&gt;
|PATCH &amp;lt;code&amp;gt; /participants/:id/authorization &amp;lt;/code&amp;gt;&lt;br /&gt;
|Update the permissions of a participant&lt;br /&gt;
|-&lt;br /&gt;
|7&lt;br /&gt;
|update_handle&lt;br /&gt;
|PATCH &amp;lt;code&amp;gt; /participants/:id/handle &amp;lt;/code&amp;gt;&lt;br /&gt;
|Update the handle of a participant&lt;br /&gt;
|-&lt;br /&gt;
|8&lt;br /&gt;
|destroy&lt;br /&gt;
|DELETE &amp;lt;code&amp;gt; /participants/:id &amp;lt;/code&amp;gt;&lt;br /&gt;
|Delete a specified participant&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==Testing Plan==&lt;br /&gt;
'''rswag'''&amp;lt;br/&amp;gt;&lt;br /&gt;
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.&lt;br /&gt;
====Tests====&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;margin-left:40px&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Test ID !! Test Description &lt;br /&gt;
|-&lt;br /&gt;
| 1 || Test 'index' with valid model (Assignment) and ID - Should list participants&lt;br /&gt;
|-&lt;br /&gt;
| 2 || Test 'index' with invalid model (Assignment) and ID - Should return an error message&lt;br /&gt;
|-&lt;br /&gt;
| 3 || Test 'show' with valid participant ID - Should return the specified participant details&lt;br /&gt;
|-&lt;br /&gt;
| 4 || Test 'show' with invalid participant ID - Should return participant not found&lt;br /&gt;
|-&lt;br /&gt;
| 5 || Test 'inherit' with valid assignment ID but no course participants - Should display a message indicating no participants were found to inherit&lt;br /&gt;
|-&lt;br /&gt;
| 6 || Test 'inherit' with invalid assignment ID - Should return assignment not found message&lt;br /&gt;
|-&lt;br /&gt;
| 7 || Test 'inherit' with valid assignment ID and course with participants - Should copy participants from course to assignment&lt;br /&gt;
|-&lt;br /&gt;
| 8 || Test 'bequeath' with valid assignment ID with no assignment participants - Should display a message indicating no participants were found&lt;br /&gt;
|-&lt;br /&gt;
| 9 || Test 'bequeath' with invalid assignment ID - Should return assignment not found message&lt;br /&gt;
|-&lt;br /&gt;
| 10 || Test 'bequeath' with valid assignment ID and course with participants - Should copy participants from assignment to course&lt;br /&gt;
|-&lt;br /&gt;
| 11 || Test 'create' with valid user detail - Should successfully create a new participant&lt;br /&gt;
|-&lt;br /&gt;
| 12 || Test 'create' with duplicate user information - Should return an error message indicating that the participant already exists&lt;br /&gt;
|-&lt;br /&gt;
| 13 || Test 'update_authorization' with valid participant ID and permissions - Should update participant’s permissions successfully&lt;br /&gt;
|-&lt;br /&gt;
| 14 || Test `update_authorization` with invalid participant ID - Should return not found message&lt;br /&gt;
|-&lt;br /&gt;
| 15 || Test 'update_handle' with valid participant ID and unique handle - Should successfully update&lt;br /&gt;
|-&lt;br /&gt;
| 16 || Test 'update_handle' with duplicate handle - Should return an error message indicating handle is in use&lt;br /&gt;
|-&lt;br /&gt;
| 17 || Test 'destroy' with valid participant ID - Should delete the specified participant&lt;br /&gt;
|-&lt;br /&gt;
| 18 || Test 'destroy' with invalid participant ID - Should return participant not found message&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==Team==&lt;br /&gt;
'''Mentor''' &lt;br /&gt;
&lt;br /&gt;
*Jay Patel &amp;lt;jhpatel9@ncsu.edu&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Students'''&lt;br /&gt;
&lt;br /&gt;
*Pierce Whelan &amp;lt;pwwhelan@ncsu.edu&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*Calvin Jiang &amp;lt;crjiang@ncsu.edu&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*Hechun Zhang &amp;lt;hzhang56@ncsu.edu&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Relevant Links ==&lt;br /&gt;
Pull Request [https://github.com/expertiza/reimplementation-back-end/pull/135] &amp;lt;br/&amp;gt;&lt;br /&gt;
GitHub Repository [https://github.com/Pierce57/participant_controller_reimplementation.git] &amp;lt;br/&amp;gt;&lt;br /&gt;
GitHub Project Board [https://github.com/users/Pierce57/projects/3] &amp;lt;br/&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt; participants_controller.rb &amp;lt;/code&amp;gt; in Old Expertiza [https://github.com/expertiza/expertiza/blob/main/app/controllers/participants_controller.rb]&lt;/div&gt;</summary>
		<author><name>Hzhang56</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2024_-_E2484._Reimplement_participants_controller.rb&amp;diff=159632</id>
		<title>CSC/ECE 517 Fall 2024 - E2484. Reimplement participants controller.rb</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2024_-_E2484._Reimplement_participants_controller.rb&amp;diff=159632"/>
		<updated>2024-11-17T21:17:03Z</updated>

		<summary type="html">&lt;p&gt;Hzhang56: /* Design */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==About Expertiza==&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is an open source project based on [http://rubyonrails.org/ 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.&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
This project aims to reimplement the &amp;lt;code&amp;gt; participants_controller.rb &amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt; participants_helper.rb &amp;lt;/code&amp;gt; in the new Expertiza system. The &amp;lt;code&amp;gt; participants_controller.rb &amp;lt;/code&amp;gt; manages participants within assignments, and this reimplementation focuses on streamlining its methods, eliminating redundancy, and enhancing code readability and maintainability.&lt;br /&gt;
&lt;br /&gt;
==Requirements==&lt;br /&gt;
&amp;lt;li&amp;gt; Implement &amp;lt;code&amp;gt; participants_controller.rb &amp;lt;/code&amp;gt; Methods: Fully implement each controller method with the same functionality as the current controller. &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Import from &amp;lt;code&amp;gt; participants_helper.rb &amp;lt;/code&amp;gt;: Integrate relevant helper methods to streamline functionality and remove redundancy. &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; API Creation: Expose API endpoints for all necessary methods to enable seamless access and integration from the frontend. Ensure that each endpoint follows best practices for RESTful API design, including proper error handling and secure data access. &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Testing with rswag: Create test cases for all methods, focusing on edge cases, and generate rswag documentation. &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Swagger UI Video Documentation: Record a video walkthrough of API endpoints in Swagger UI, showcasing each method’s functionality. &amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Existing Issues==&lt;br /&gt;
Reimplement &amp;lt;code&amp;gt; [https://github.com/expertiza/expertiza/blob/main/app/controllers/participants_controller.rb participants_controller.rb] &amp;lt;/code&amp;gt; while addressing the following:&lt;br /&gt;
&amp;lt;li&amp;gt; Refactor code to comply with the Open-Closed Principle and the Single Responsibility Principle. &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Introduce dependency injection where necessary. &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Reduce excessive conditional statements. &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Include sufficient code tests to verify functionality. &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Enhance comments to better explain each method's functionality, purpose, and rationale for keeping or modifying particular aspects of the code. &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Provide a more detailed explanation of design choices and refactoring steps. &amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Design==&lt;br /&gt;
===Pattern(s)===&lt;br /&gt;
&lt;br /&gt;
'''Facade''': &amp;quot;A simplified interface that performs many other actions behind the scenes.&amp;quot; &amp;lt;br/&amp;gt;&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
===SOLID Principle(s)===&lt;br /&gt;
&lt;br /&gt;
'''Open and Closed Principle''': &amp;quot;Software entities should be open for extension, but closed for modification.&amp;quot;&amp;lt;br/&amp;gt;&lt;br /&gt;
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. We plan on implementing polymorphism which could allow each class (e.g., Assignment, Course) to handle participant-related logic through inheritance or composition.&lt;br /&gt;
'''Single Responsibility Principle''': &amp;quot;A class should only have one responsibility and should never have more than one reason to change.&amp;quot;&amp;lt;br/&amp;gt;&lt;br /&gt;
The current implementation of the participant controller mixes many responsibilities, such as authorization, handling different object types, and managing participants. We plan to use the Single Responsibility Principle to delegate each responsibility to separate classes and ensure each class has a single responsibility, and the participant controller will be their coordinator. &lt;br /&gt;
&lt;br /&gt;
===API Calls===&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;width: 100%;&lt;br /&gt;
! &amp;amp;nbsp;#&amp;amp;nbsp; !! Method !! Endpoint !! Description &lt;br /&gt;
|-&lt;br /&gt;
|1&lt;br /&gt;
|index&lt;br /&gt;
|GET &amp;lt;code&amp;gt; /participants &amp;lt;/code&amp;gt;&lt;br /&gt;
|Return a list of participants&lt;br /&gt;
|-&lt;br /&gt;
|2&lt;br /&gt;
|show&lt;br /&gt;
|GET &amp;lt;code&amp;gt; /participants/:id &amp;lt;/code&amp;gt;&lt;br /&gt;
|Return a specified participant&lt;br /&gt;
|-&lt;br /&gt;
|3&lt;br /&gt;
|inherit&lt;br /&gt;
|GET &amp;lt;code&amp;gt; /participants/inherit &amp;lt;/code&amp;gt;&lt;br /&gt;
|Copy all participants from a course to an assignment&lt;br /&gt;
|-&lt;br /&gt;
|4&lt;br /&gt;
|bequeath&lt;br /&gt;
|GET &amp;lt;code&amp;gt; /participants/bequeath &amp;lt;/code&amp;gt;&lt;br /&gt;
|Copy all participants from an assignment to a course&lt;br /&gt;
|-&lt;br /&gt;
|5&lt;br /&gt;
|create&lt;br /&gt;
|POST &amp;lt;code&amp;gt; /participants &amp;lt;/code&amp;gt;&lt;br /&gt;
|Create a participant&lt;br /&gt;
|-&lt;br /&gt;
|6&lt;br /&gt;
|update_authorization&lt;br /&gt;
|PATCH &amp;lt;code&amp;gt; /participants/:id/authorization &amp;lt;/code&amp;gt;&lt;br /&gt;
|Update the permissions of a participant&lt;br /&gt;
|-&lt;br /&gt;
|7&lt;br /&gt;
|update_handle&lt;br /&gt;
|PATCH &amp;lt;code&amp;gt; /participants/:id/handle &amp;lt;/code&amp;gt;&lt;br /&gt;
|Update the handle of a participant&lt;br /&gt;
|-&lt;br /&gt;
|8&lt;br /&gt;
|destroy&lt;br /&gt;
|DELETE &amp;lt;code&amp;gt; /participants/:id &amp;lt;/code&amp;gt;&lt;br /&gt;
|Delete a specified participant&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==Testing Plan==&lt;br /&gt;
'''rswag'''&amp;lt;br/&amp;gt;&lt;br /&gt;
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.&lt;br /&gt;
====Tests====&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;margin-left:40px&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Test ID !! Test Description &lt;br /&gt;
|-&lt;br /&gt;
| 1 || Test 'index' with valid model (Assignment) and ID - Should list participants&lt;br /&gt;
|-&lt;br /&gt;
| 2 || Test 'index' with invalid model (Assignment) and ID - Should return an error message&lt;br /&gt;
|-&lt;br /&gt;
| 3 || Test 'show' with valid participant ID - Should return the specified participant details&lt;br /&gt;
|-&lt;br /&gt;
| 4 || Test 'show' with invalid participant ID - Should return participant not found&lt;br /&gt;
|-&lt;br /&gt;
| 5 || Test 'inherit' with valid assignment ID but no course participants - Should display a message indicating no participants were found to inherit&lt;br /&gt;
|-&lt;br /&gt;
| 6 || Test 'inherit' with invalid assignment ID - Should return assignment not found message&lt;br /&gt;
|-&lt;br /&gt;
| 7 || Test 'inherit' with valid assignment ID and course with participants - Should copy participants from course to assignment&lt;br /&gt;
|-&lt;br /&gt;
| 8 || Test 'bequeath' with valid assignment ID with no assignment participants - Should display a message indicating no participants were found&lt;br /&gt;
|-&lt;br /&gt;
| 9 || Test 'bequeath' with invalid assignment ID - Should return assignment not found message&lt;br /&gt;
|-&lt;br /&gt;
| 10 || Test 'bequeath' with valid assignment ID and course with participants - Should copy participants from assignment to course&lt;br /&gt;
|-&lt;br /&gt;
| 11 || Test 'create' with valid user detail - Should successfully create a new participant&lt;br /&gt;
|-&lt;br /&gt;
| 12 || Test 'create' with duplicate user information - Should return an error message indicating that the participant already exists&lt;br /&gt;
|-&lt;br /&gt;
| 13 || Test 'update_authorization' with valid participant ID and permissions - Should update participant’s permissions successfully&lt;br /&gt;
|-&lt;br /&gt;
| 14 || Test `update_authorization` with invalid participant ID - Should return not found message&lt;br /&gt;
|-&lt;br /&gt;
| 15 || Test 'update_handle' with valid participant ID and unique handle - Should successfully update&lt;br /&gt;
|-&lt;br /&gt;
| 16 || Test 'update_handle' with duplicate handle - Should return an error message indicating handle is in use&lt;br /&gt;
|-&lt;br /&gt;
| 17 || Test 'destroy' with valid participant ID - Should delete the specified participant&lt;br /&gt;
|-&lt;br /&gt;
| 18 || Test 'destroy' with invalid participant ID - Should return participant not found message&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==Team==&lt;br /&gt;
'''Mentor''' &lt;br /&gt;
&lt;br /&gt;
*Jay Patel &amp;lt;jhpatel9@ncsu.edu&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Students'''&lt;br /&gt;
&lt;br /&gt;
*Pierce Whelan &amp;lt;pwwhelan@ncsu.edu&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*Calvin Jiang &amp;lt;crjiang@ncsu.edu&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*Hechun Zhang &amp;lt;hzhang56@ncsu.edu&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Relevant Links ==&lt;br /&gt;
Pull Request [https://github.com/expertiza/reimplementation-back-end/pull/135] &amp;lt;br/&amp;gt;&lt;br /&gt;
GitHub Repository [https://github.com/Pierce57/participant_controller_reimplementation.git] &amp;lt;br/&amp;gt;&lt;br /&gt;
GitHub Project Board [https://github.com/users/Pierce57/projects/3] &amp;lt;br/&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt; participants_controller.rb &amp;lt;/code&amp;gt; in Old Expertiza [https://github.com/expertiza/expertiza/blob/main/app/controllers/participants_controller.rb]&lt;/div&gt;</summary>
		<author><name>Hzhang56</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2024_-_E2484._Reimplement_participants_controller.rb&amp;diff=159621</id>
		<title>CSC/ECE 517 Fall 2024 - E2484. Reimplement participants controller.rb</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2024_-_E2484._Reimplement_participants_controller.rb&amp;diff=159621"/>
		<updated>2024-11-17T20:49:53Z</updated>

		<summary type="html">&lt;p&gt;Hzhang56: /* Existing Issues */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==About Expertiza==&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is an open source project based on [http://rubyonrails.org/ 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.&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
This project aims to reimplement the &amp;lt;code&amp;gt; participants_controller.rb &amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt; participants_helper.rb &amp;lt;/code&amp;gt; in the new Expertiza system. The &amp;lt;code&amp;gt; participants_controller.rb &amp;lt;/code&amp;gt; manages participants within assignments, and this reimplementation focuses on streamlining its methods, eliminating redundancy, and enhancing code readability and maintainability.&lt;br /&gt;
&lt;br /&gt;
==Requirements==&lt;br /&gt;
&amp;lt;li&amp;gt; Implement &amp;lt;code&amp;gt; participants_controller.rb &amp;lt;/code&amp;gt; Methods: Fully implement each controller method with the same functionality as the current controller. &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Import from &amp;lt;code&amp;gt; participants_helper.rb &amp;lt;/code&amp;gt;: Integrate relevant helper methods to streamline functionality and remove redundancy. &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; API Creation: Expose API endpoints for all necessary methods to enable seamless access and integration from the frontend. Ensure that each endpoint follows best practices for RESTful API design, including proper error handling and secure data access. &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Testing with rswag: Create test cases for all methods, focusing on edge cases, and generate rswag documentation. &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Swagger UI Video Documentation: Record a video walkthrough of API endpoints in Swagger UI, showcasing each method’s functionality. &amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Existing Issues==&lt;br /&gt;
Reimplement &amp;lt;code&amp;gt; [https://github.com/expertiza/expertiza/blob/main/app/controllers/participants_controller.rb participants_controller.rb] &amp;lt;/code&amp;gt; while addressing the following:&lt;br /&gt;
&amp;lt;li&amp;gt; Refactor code to comply with the Open-Closed Principle and the Single Responsibility Principle. &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Introduce dependency injection where necessary. &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Reduce excessive conditional statements. &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Include sufficient code tests to verify functionality. &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Enhance comments to better explain each method's functionality, purpose, and rationale for keeping or modifying particular aspects of the code. &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Provide a more detailed explanation of design choices and refactoring steps. &amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Design==&lt;br /&gt;
===Pattern(s)===&lt;br /&gt;
&lt;br /&gt;
'''Facade''': &amp;quot;A simplified interface that performs many other actions behind the scenes.&amp;quot; &amp;lt;br/&amp;gt;&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
===SOLID Principle(s)===&lt;br /&gt;
&lt;br /&gt;
'''Open and Closed Principle''': &amp;quot;Software entities should be open for extension, but closed for modification.&amp;quot;&amp;lt;br/&amp;gt;&lt;br /&gt;
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. We plan on implementing polymorphism which could allow each class (e.g., Assignment, Course) to handle participant-related logic through inheritance or composition.&lt;br /&gt;
&lt;br /&gt;
===API Calls===&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;width: 100%;&lt;br /&gt;
! &amp;amp;nbsp;#&amp;amp;nbsp; !! Method !! Endpoint !! Description &lt;br /&gt;
|-&lt;br /&gt;
|1&lt;br /&gt;
|index&lt;br /&gt;
|GET &amp;lt;code&amp;gt; /participants &amp;lt;/code&amp;gt;&lt;br /&gt;
|Return a list of participants&lt;br /&gt;
|-&lt;br /&gt;
|2&lt;br /&gt;
|show&lt;br /&gt;
|GET &amp;lt;code&amp;gt; /participants/:id &amp;lt;/code&amp;gt;&lt;br /&gt;
|Return a specified participant&lt;br /&gt;
|-&lt;br /&gt;
|3&lt;br /&gt;
|inherit&lt;br /&gt;
|GET &amp;lt;code&amp;gt; /participants/inherit &amp;lt;/code&amp;gt;&lt;br /&gt;
|Copy all participants from a course to an assignment&lt;br /&gt;
|-&lt;br /&gt;
|4&lt;br /&gt;
|bequeath&lt;br /&gt;
|GET &amp;lt;code&amp;gt; /participants/bequeath &amp;lt;/code&amp;gt;&lt;br /&gt;
|Copy all participants from an assignment to a course&lt;br /&gt;
|-&lt;br /&gt;
|5&lt;br /&gt;
|create&lt;br /&gt;
|POST &amp;lt;code&amp;gt; /participants &amp;lt;/code&amp;gt;&lt;br /&gt;
|Create a participant&lt;br /&gt;
|-&lt;br /&gt;
|6&lt;br /&gt;
|update_authorization&lt;br /&gt;
|PATCH &amp;lt;code&amp;gt; /participants/:id/authorization &amp;lt;/code&amp;gt;&lt;br /&gt;
|Update the permissions of a participant&lt;br /&gt;
|-&lt;br /&gt;
|7&lt;br /&gt;
|update_handle&lt;br /&gt;
|PATCH &amp;lt;code&amp;gt; /participants/:id/handle &amp;lt;/code&amp;gt;&lt;br /&gt;
|Update the handle of a participant&lt;br /&gt;
|-&lt;br /&gt;
|8&lt;br /&gt;
|destroy&lt;br /&gt;
|DELETE &amp;lt;code&amp;gt; /participants/:id &amp;lt;/code&amp;gt;&lt;br /&gt;
|Delete a specified participant&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==Testing Plan==&lt;br /&gt;
'''rswag'''&amp;lt;br/&amp;gt;&lt;br /&gt;
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.&lt;br /&gt;
====Tests====&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;margin-left:40px&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Test ID !! Test Description &lt;br /&gt;
|-&lt;br /&gt;
| 1 || Test 'index' with valid model (Assignment) and ID - Should list participants&lt;br /&gt;
|-&lt;br /&gt;
| 2 || Test 'index' with invalid model (Assignment) and ID - Should return an error message&lt;br /&gt;
|-&lt;br /&gt;
| 3 || Test 'show' with valid participant ID - Should return the specified participant details&lt;br /&gt;
|-&lt;br /&gt;
| 4 || Test 'show' with invalid participant ID - Should return participant not found&lt;br /&gt;
|-&lt;br /&gt;
| 5 || Test 'inherit' with valid assignment ID but no course participants - Should display a message indicating no participants were found to inherit&lt;br /&gt;
|-&lt;br /&gt;
| 6 || Test 'inherit' with invalid assignment ID - Should return assignment not found message&lt;br /&gt;
|-&lt;br /&gt;
| 7 || Test 'inherit' with valid assignment ID and course with participants - Should copy participants from course to assignment&lt;br /&gt;
|-&lt;br /&gt;
| 8 || Test 'bequeath' with valid assignment ID with no assignment participants - Should display a message indicating no participants were found&lt;br /&gt;
|-&lt;br /&gt;
| 9 || Test 'bequeath' with invalid assignment ID - Should return assignment not found message&lt;br /&gt;
|-&lt;br /&gt;
| 10 || Test 'bequeath' with valid assignment ID and course with participants - Should copy participants from assignment to course&lt;br /&gt;
|-&lt;br /&gt;
| 11 || Test 'create' with valid user detail - Should successfully create a new participant&lt;br /&gt;
|-&lt;br /&gt;
| 12 || Test 'create' with duplicate user information - Should return an error message indicating that the participant already exists&lt;br /&gt;
|-&lt;br /&gt;
| 13 || Test 'update_authorization' with valid participant ID and permissions - Should update participant’s permissions successfully&lt;br /&gt;
|-&lt;br /&gt;
| 14 || Test `update_authorization` with invalid participant ID - Should return not found message&lt;br /&gt;
|-&lt;br /&gt;
| 15 || Test 'update_handle' with valid participant ID and unique handle - Should successfully update&lt;br /&gt;
|-&lt;br /&gt;
| 16 || Test 'update_handle' with duplicate handle - Should return an error message indicating handle is in use&lt;br /&gt;
|-&lt;br /&gt;
| 17 || Test 'destroy' with valid participant ID - Should delete the specified participant&lt;br /&gt;
|-&lt;br /&gt;
| 18 || Test 'destroy' with invalid participant ID - Should return participant not found message&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==Team==&lt;br /&gt;
'''Mentor''' &lt;br /&gt;
&lt;br /&gt;
*Jay Patel &amp;lt;jhpatel9@ncsu.edu&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Students'''&lt;br /&gt;
&lt;br /&gt;
*Pierce Whelan &amp;lt;pwwhelan@ncsu.edu&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*Calvin Jiang &amp;lt;crjiang@ncsu.edu&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*Hechun Zhang &amp;lt;hzhang56@ncsu.edu&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Relevant Links ==&lt;br /&gt;
Pull Request [https://github.com/expertiza/reimplementation-back-end/pull/135] &amp;lt;br/&amp;gt;&lt;br /&gt;
GitHub Repository [https://github.com/Pierce57/participant_controller_reimplementation.git] &amp;lt;br/&amp;gt;&lt;br /&gt;
GitHub Project Board [https://github.com/users/Pierce57/projects/3] &amp;lt;br/&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt; participants_controller.rb &amp;lt;/code&amp;gt; in Old Expertiza [https://github.com/expertiza/expertiza/blob/main/app/controllers/participants_controller.rb]&lt;/div&gt;</summary>
		<author><name>Hzhang56</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2024_-_E2484._Reimplement_participants_controller.rb&amp;diff=158872</id>
		<title>CSC/ECE 517 Fall 2024 - E2484. Reimplement participants controller.rb</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2024_-_E2484._Reimplement_participants_controller.rb&amp;diff=158872"/>
		<updated>2024-11-11T20:38:52Z</updated>

		<summary type="html">&lt;p&gt;Hzhang56: /* Testing Plan */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==About Expertiza==&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is an open source project based on [http://rubyonrails.org/ 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.&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
This project aims to reimplement the &amp;lt;code&amp;gt; participants_controller.rb &amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt; participants_helper.rb &amp;lt;/code&amp;gt; in the new Expertiza system. The &amp;lt;code&amp;gt; participants_controller.rb &amp;lt;/code&amp;gt; manages participants within assignments, and this reimplementation focuses on streamlining its methods, eliminating redundancy, and enhancing code readability and maintainability.&lt;br /&gt;
&lt;br /&gt;
==Requirements==&lt;br /&gt;
&amp;lt;li&amp;gt; Implement &amp;lt;code&amp;gt; participants_controller.rb &amp;lt;/code&amp;gt; Methods: Fully implement each controller method with the same functionality as the current controller. &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Import from &amp;lt;code&amp;gt; participants_helper.rb &amp;lt;/code&amp;gt;: Integrate relevant helper methods to streamline functionality and remove redundancy. &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; API Creation: Expose API endpoints for all necessary methods to enable seamless access and integration from the frontend. Ensure that each endpoint follows best practices for RESTful API design, including proper error handling and secure data access. &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Testing with rswag: Create test cases for all methods, focusing on edge cases, and generate rswag documentation. &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Swagger UI Video Documentation: Record a video walkthrough of API endpoints in Swagger UI, showcasing each method’s functionality. &amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Existing Issues==&lt;br /&gt;
Reimplement &amp;lt;code&amp;gt; [https://github.com/expertiza/expertiza/blob/main/app/controllers/participants_controller.rb participants_controller.rb] &amp;lt;/code&amp;gt; while addressing the following:&lt;br /&gt;
&amp;lt;li&amp;gt; Refactor code to comply with the Open-Closed Principle. &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Introduce dependency injection where necessary. &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Reduce excessive conditional statements. &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Include sufficient code tests to verify functionality. &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Enhance comments to better explain each method's functionality, purpose, and rationale for keeping or modifying particular aspects of the code. &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Provide a more detailed explanation of design choices and refactoring steps. &amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Design==&lt;br /&gt;
===Pattern(s)===&lt;br /&gt;
&lt;br /&gt;
'''Facade''': &amp;quot;A simplified interface that performs many other actions behind the scenes.&amp;quot; &amp;lt;br/&amp;gt;&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
===SOLID Principle(s)===&lt;br /&gt;
&lt;br /&gt;
'''Open and Closed Principle''': &amp;quot;Software entities should be open for extension, but closed for modification.&amp;quot;&amp;lt;br/&amp;gt;&lt;br /&gt;
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. We plan on implementing polymorphism which could allow each class (e.g., Assignment, Course) to handle participant-related logic through inheritance or composition.&lt;br /&gt;
&lt;br /&gt;
===API Calls===&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;width: 100%;&lt;br /&gt;
! &amp;amp;nbsp;#&amp;amp;nbsp; !! Method !! Endpoint !! Description &lt;br /&gt;
|-&lt;br /&gt;
|1&lt;br /&gt;
|index&lt;br /&gt;
|GET &amp;lt;code&amp;gt; /participants &amp;lt;/code&amp;gt;&lt;br /&gt;
|Return a list of participants&lt;br /&gt;
|-&lt;br /&gt;
|2&lt;br /&gt;
|show&lt;br /&gt;
|GET &amp;lt;code&amp;gt; /participant/:id &amp;lt;/code&amp;gt;&lt;br /&gt;
|Return a specified participant&lt;br /&gt;
|-&lt;br /&gt;
|3&lt;br /&gt;
|inherit&lt;br /&gt;
|GET &amp;lt;code&amp;gt; /participants/inherit &amp;lt;/code&amp;gt;&lt;br /&gt;
|Copy all participants from a course to an assignment&lt;br /&gt;
|-&lt;br /&gt;
|4&lt;br /&gt;
|bequeath&lt;br /&gt;
|GET &amp;lt;code&amp;gt; /participants/bequeath &amp;lt;/code&amp;gt;&lt;br /&gt;
|Copy all participants from an assignment to a course&lt;br /&gt;
|-&lt;br /&gt;
|5&lt;br /&gt;
|create&lt;br /&gt;
|POST &amp;lt;code&amp;gt; /participant &amp;lt;/code&amp;gt;&lt;br /&gt;
|Create a participant&lt;br /&gt;
|-&lt;br /&gt;
|6&lt;br /&gt;
|update_authorization&lt;br /&gt;
|PATCH &amp;lt;code&amp;gt; /participant/:id/authorization &amp;lt;/code&amp;gt;&lt;br /&gt;
|Update the permissions of a participant&lt;br /&gt;
|-&lt;br /&gt;
|7&lt;br /&gt;
|update_handle&lt;br /&gt;
|PATCH &amp;lt;code&amp;gt; /participant/:id/handle &amp;lt;/code&amp;gt;&lt;br /&gt;
|Update the handle of a participant&lt;br /&gt;
|-&lt;br /&gt;
|8&lt;br /&gt;
|destroy&lt;br /&gt;
|DELETE &amp;lt;code&amp;gt; /participant/:id &amp;lt;/code&amp;gt;&lt;br /&gt;
|Delete a specified participant&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==Testing Plan==&lt;br /&gt;
'''Rswag'''&amp;lt;br/&amp;gt;&lt;br /&gt;
We will be using Rswag to test our project. Rswag is a Ruby library that integrates Rspec testing with Swagger to document and test API endpoints. With Rswag, we can define test cases using Rspec code that validates our project's functionality. It will also help us automatically generate Swagger documentation, which in turn can be displayed in a user-friendly interface. The reason for using Rswag is to create detailed documentation that developers and stakeholders can interact with and test through Swagger UI.&lt;br /&gt;
====Tests====&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;margin-left:40px&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Test ID !! Test Description &lt;br /&gt;
|-&lt;br /&gt;
| 1 || Test 'index' with valid model (Assignment) and ID - Should list participants&lt;br /&gt;
|-&lt;br /&gt;
| 2 || Test 'index' with invalid model (Assignment) and ID - Should return an error message&lt;br /&gt;
|-&lt;br /&gt;
| 3 || Test 'show' with valid participant ID - Should return the specified participant details&lt;br /&gt;
|-&lt;br /&gt;
| 4 || Test 'show' with invalid participant ID - Should return participant not found&lt;br /&gt;
|-&lt;br /&gt;
| 5 || Test 'inherit' with valid assignment ID but no course participants - Should display a message indicating no participants were found to inherit&lt;br /&gt;
|-&lt;br /&gt;
| 6 || Test 'inherit' with invalid assignment ID - Should return assignment not found message&lt;br /&gt;
|-&lt;br /&gt;
| 7 || Test 'inherit' with valid assignment ID and course with participants - Should copy participants from course to assignment&lt;br /&gt;
|-&lt;br /&gt;
| 8 || Test 'bequeath' with valid assignment ID with no assignment participants - Should display a message indicating no participants were found&lt;br /&gt;
|-&lt;br /&gt;
| 9 || Test 'bequeath' with invalid assignment ID - Should return assignment not found message&lt;br /&gt;
|-&lt;br /&gt;
| 10 || Test 'bequeath' with valid assignment ID and course with participants - Should copy participants from assignment to course&lt;br /&gt;
|-&lt;br /&gt;
| 11 || Test 'create' with valid user detail - Should successfully create a new participant&lt;br /&gt;
|-&lt;br /&gt;
| 12 || Test 'create' with duplicate user information - Should return an error message indicating that the participant already exists&lt;br /&gt;
|-&lt;br /&gt;
| 13 || Test 'update_authorization' with valid participant ID and permissions - Should update participant’s permissions successfully&lt;br /&gt;
|-&lt;br /&gt;
| 14 || Test `update_authorization` with invalid participant ID - Should return not found message&lt;br /&gt;
|-&lt;br /&gt;
| 15 || Test 'update_handle' with valid participant ID and unique handle - Should successfully update&lt;br /&gt;
|-&lt;br /&gt;
| 16 || Test 'update_handle' with duplicate handle - Should return an error message indicating handle is in use&lt;br /&gt;
|-&lt;br /&gt;
| 17 || Test 'destroy' with valid participant ID - Should delete the specified participant&lt;br /&gt;
|-&lt;br /&gt;
| 18 || Test 'destroy' with invalid participant ID - Should return participant not found message&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==Team==&lt;br /&gt;
'''Mentor''' &lt;br /&gt;
&lt;br /&gt;
*Jay Patel &amp;lt;jhpatel9@ncsu.edu&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Students'''&lt;br /&gt;
&lt;br /&gt;
*Pierce Whelan &amp;lt;pwwhelan@ncsu.edu&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*Calvin Jiang &amp;lt;crjiang@ncsu.edu&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*Hechun Zhang &amp;lt;hzhang56@ncsu.edu&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Relevant Links ==&lt;br /&gt;
Pull Request [https://github.com/expertiza/reimplementation-back-end/pull/135] &amp;lt;br/&amp;gt;&lt;br /&gt;
GitHub Repository [https://github.com/Pierce57/participant_controller_reimplementation.git] &amp;lt;br/&amp;gt;&lt;br /&gt;
GitHub Project Board [https://github.com/users/Pierce57/projects/3] &amp;lt;br/&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt; participants_controller.rb &amp;lt;/code&amp;gt; in Old Expertiza [https://github.com/expertiza/expertiza/blob/main/app/controllers/participants_controller.rb]&lt;/div&gt;</summary>
		<author><name>Hzhang56</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2024_-_E2484._Reimplement_participants_controller.rb&amp;diff=158863</id>
		<title>CSC/ECE 517 Fall 2024 - E2484. Reimplement participants controller.rb</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2024_-_E2484._Reimplement_participants_controller.rb&amp;diff=158863"/>
		<updated>2024-11-11T19:00:40Z</updated>

		<summary type="html">&lt;p&gt;Hzhang56: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==About Expertiza==&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is an open source project based on [http://rubyonrails.org/ 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.&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
This project aims to reimplement the &amp;lt;code&amp;gt; participants_controller.rb &amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt; participants_helper.rb &amp;lt;/code&amp;gt; in the new Expertiza system. The &amp;lt;code&amp;gt; participants_controller.rb &amp;lt;/code&amp;gt; manages participants within assignments, and this reimplementation focuses on streamlining its methods, eliminating redundancy, and enhancing code readability and maintainability.&lt;br /&gt;
&lt;br /&gt;
==Requirements==&lt;br /&gt;
&amp;lt;li&amp;gt; Implement &amp;lt;code&amp;gt; participants_controller.rb &amp;lt;/code&amp;gt; Methods: Fully implement each controller method with the same functionality as the current controller. &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Import from &amp;lt;code&amp;gt; participants_helper.rb &amp;lt;/code&amp;gt;: Integrate relevant helper methods to streamline functionality and remove redundancy. &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; API Creation: Expose API endpoints for all necessary methods to enable seamless access and integration from the frontend. Ensure that each endpoint follows best practices for RESTful API design, including proper error handling and secure data access. &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Testing with rswag: Create test cases for all methods, focusing on edge cases, and generate rswag documentation. &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Swagger UI Video Documentation: Record a video walkthrough of API endpoints in Swagger UI, showcasing each method’s functionality. &amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Existing Issues==&lt;br /&gt;
Reimplement &amp;lt;code&amp;gt; [https://github.com/expertiza/expertiza/blob/main/app/controllers/participants_controller.rb participants_controller.rb] &amp;lt;/code&amp;gt; while addressing the following:&lt;br /&gt;
&amp;lt;li&amp;gt; Refactor code to comply with the Open-Closed Principle. &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Introduce dependency injection where necessary. &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Reduce excessive conditional statements. &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Include sufficient code tests to verify functionality. &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Enhance comments to better explain each method's functionality, purpose, and rationale for keeping or modifying particular aspects of the code. &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Provide a more detailed explanation of design choices and refactoring steps. &amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Design==&lt;br /&gt;
===Pattern(s)===&lt;br /&gt;
&lt;br /&gt;
'''Facade''': 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.&lt;br /&gt;
&lt;br /&gt;
===SOLID Principle(s)===&lt;br /&gt;
&lt;br /&gt;
'''Open and Closed Principle''': &amp;quot;Software entities should be open for extension, but closed for modification.&amp;quot;&amp;lt;br/&amp;gt;&lt;br /&gt;
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. We plan on implementing polymorphism which could allow each class (e.g., Assignment, Course) to handle participant-related logic through inheritance or composition.&lt;br /&gt;
&lt;br /&gt;
===API Calls===&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;width: 100%;&lt;br /&gt;
! &amp;amp;nbsp;#&amp;amp;nbsp; !! Method !! Endpoint !! Description &lt;br /&gt;
|-&lt;br /&gt;
|1&lt;br /&gt;
|index&lt;br /&gt;
|GET &amp;lt;code&amp;gt; /participants &amp;lt;/code&amp;gt;&lt;br /&gt;
|Return a list of participants&lt;br /&gt;
|-&lt;br /&gt;
|2&lt;br /&gt;
|show&lt;br /&gt;
|GET &amp;lt;code&amp;gt; /participant/:id &amp;lt;/code&amp;gt;&lt;br /&gt;
|Return a specified participant&lt;br /&gt;
|-&lt;br /&gt;
|3&lt;br /&gt;
|inherit&lt;br /&gt;
|GET &amp;lt;code&amp;gt; /participants/inherit &amp;lt;/code&amp;gt;&lt;br /&gt;
|Copy all participants from a course to an assignment&lt;br /&gt;
|-&lt;br /&gt;
|4&lt;br /&gt;
|bequeath&lt;br /&gt;
|GET &amp;lt;code&amp;gt; /participants/bequeath &amp;lt;/code&amp;gt;&lt;br /&gt;
|Copy all participants from an assignment to a course&lt;br /&gt;
|-&lt;br /&gt;
|5&lt;br /&gt;
|create&lt;br /&gt;
|POST &amp;lt;code&amp;gt; /participant &amp;lt;/code&amp;gt;&lt;br /&gt;
|Create a participant&lt;br /&gt;
|-&lt;br /&gt;
|5&lt;br /&gt;
|update_authorization&lt;br /&gt;
|PATCH &amp;lt;code&amp;gt; /participant/:id/authorization &amp;lt;/code&amp;gt;&lt;br /&gt;
|Update the permissions of a participant&lt;br /&gt;
|-&lt;br /&gt;
|6&lt;br /&gt;
|update_handle&lt;br /&gt;
|PATCH &amp;lt;code&amp;gt; /participant/:id/handle &amp;lt;/code&amp;gt;&lt;br /&gt;
|Update the handle of a participant&lt;br /&gt;
|-&lt;br /&gt;
|7&lt;br /&gt;
|destroy&lt;br /&gt;
|DELETE &amp;lt;code&amp;gt; /participant/:id &amp;lt;/code&amp;gt;&lt;br /&gt;
|Destroy a specified participant&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==Testing Plan==&lt;br /&gt;
We will be using Rswag to test our project. Rswag is a Ruby library that integrates Rspec testing with Swagger to document and test API endpoints. &lt;br /&gt;
==Team==&lt;br /&gt;
'''Mentor''' &lt;br /&gt;
&lt;br /&gt;
*Jay Patel &amp;lt;jhpatel9@ncsu.edu&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Students'''&lt;br /&gt;
&lt;br /&gt;
*Pierce Whelan &amp;lt;pwwhelan@ncsu.edu&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*Calvin Jiang &amp;lt;crjiang@ncsu.edu&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*Hechun Zhang &amp;lt;hzhang56@ncsu.edu&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Relevant Links ==&lt;br /&gt;
Pull Request [https://github.com/expertiza/reimplementation-back-end/pull/135] &amp;lt;br/&amp;gt;&lt;br /&gt;
GitHub Repository [https://github.com/Pierce57/participant_controller_reimplementation.git] &amp;lt;br/&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt; participants_controller.rb &amp;lt;/code&amp;gt; in Old Expertiza [https://github.com/expertiza/expertiza/blob/main/app/controllers/participants_controller.rb]&lt;/div&gt;</summary>
		<author><name>Hzhang56</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2024_-_E2484._Reimplement_participants_controller.rb&amp;diff=158738</id>
		<title>CSC/ECE 517 Fall 2024 - E2484. Reimplement participants controller.rb</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2024_-_E2484._Reimplement_participants_controller.rb&amp;diff=158738"/>
		<updated>2024-11-07T22:33:21Z</updated>

		<summary type="html">&lt;p&gt;Hzhang56: Created page with &amp;quot;==Team== '''Mentor'''   *Jay Patel &amp;lt;jhpatel9@ncsu.edu&amp;gt;  '''Students'''  *Pierce Whelan &amp;lt;pwwhelan@ncsu.edu&amp;gt;  *Calvin Jiang &amp;lt;crjiang@ncsu.edu&amp;gt;  *Hechun Zhang &amp;lt;hzhang56@ncsu.edu&amp;gt;&amp;quot;&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Team==&lt;br /&gt;
'''Mentor''' &lt;br /&gt;
&lt;br /&gt;
*Jay Patel &amp;lt;jhpatel9@ncsu.edu&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Students'''&lt;br /&gt;
&lt;br /&gt;
*Pierce Whelan &amp;lt;pwwhelan@ncsu.edu&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*Calvin Jiang &amp;lt;crjiang@ncsu.edu&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*Hechun Zhang &amp;lt;hzhang56@ncsu.edu&amp;gt;&lt;/div&gt;</summary>
		<author><name>Hzhang56</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2024&amp;diff=158737</id>
		<title>CSC/ECE 517 Fall 2024</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2024&amp;diff=158737"/>
		<updated>2024-11-07T22:32:26Z</updated>

		<summary type="html">&lt;p&gt;Hzhang56: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;* [[CSC/ECE 517 Fall 2024 - E2450. Refactor assignments_controller.rb]]&lt;br /&gt;
* [[CSC/ECE 517 Fall 2024 - E2452. Refactor review_mapping_controller.rb]]&lt;br /&gt;
* [[CSC/ECE 517 Fall 2024 - E2453. Refactor review_mapping_helper.rb]]&lt;br /&gt;
* [[CSC/ECE 517 Fall 2024 - E2454. Refactor student_task.rb]]&lt;br /&gt;
* [[CSC/ECE 517 Fall 2024 - E2455. Refactor sign_up_sheet_controller.rb]]&lt;br /&gt;
* [[CSC/ECE 517 Fall 2024 - E2456. Refactor teams_user.rb]]&lt;br /&gt;
* [[CSC/ECE 517 Fall 2024 - E2458. User management and users table]]&lt;br /&gt;
* [[CSC/ECE 517 Fall 2024 - E2459. View for results of bidding]]&lt;br /&gt;
* [[CSC/ECE 517 Fall 2024 - E2460 Mentor-Meeting Management]]&lt;br /&gt;
* [[CSC/ECE 517 Fall 2024 - E2461. UI for Courses]]&lt;br /&gt;
* [https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2024_-_E2462._UI_for_Questionnaires CSC/ECE 517 Fall 2024 - E2462. UI for Questionnaire.rb]&lt;br /&gt;
* [https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2024_-_E2463_Implement_Front_End_for_Student_Task_List CSC/ECE 517 Fall 2024 - E2463. UI for Student Task List]&lt;br /&gt;
* [[CSC/ECE 517 Fall 2024 - E2464 UI for Project Topics (was: Sign_up_Topics)]]&lt;br /&gt;
* [[CSC/ECE 517 Fall 2024 - E2465. UI for Institutions and Notification]]&lt;br /&gt;
* [[CSC/ECE 517 Fall 2024 - E2466. UI for Impersonate User]]&lt;br /&gt;
* [[CSC/ECE 517 Fall 2024 - E2467. UI for View Submissions]]&lt;br /&gt;
* [[CSC/ECE 517 Fall 2024 - E2468. Reimplement due_date]]&lt;br /&gt;
* [[CSC/ECE 517 Fall 2024 - E2469. Reimplement grades/view_team]]&lt;br /&gt;
* [[CSC/ECE 517 Fall 2024 - E2470. Reimplement grades_controller]]&lt;br /&gt;
* [[CSC/ECE 517 Fall 2024 - E2471. Reimplement logger]]&lt;br /&gt;
* [[CSC/ECE 517 Fall 2024 - E2472. Reimplement responses_controller.rb]]&lt;br /&gt;
* [[CSC/ECE 517 Fall 2024 - E2475. Reimplement student_task view]]&lt;br /&gt;
* [[CSC/ECE 517 Fall 2024 - E2478. Reimplement the Question hierarchy as Item hierarchy]]&lt;br /&gt;
* [[CSC/ECE 517 Fall 2024 - E2480. Implement testing for new Bookmarks Controller]]&lt;br /&gt;
* [[CSC/ECE 517 Fall 2024 - E2481 Reimplement response_map.rb]]&lt;br /&gt;
* [[CSC/ECE 517 Fall 2024 - E2482. Reimplement heatgrid for reviews]]&lt;br /&gt;
* [[CSC/ECE 517 Fall 2024 - G2401 Refactor Graphql API endpoint for contribution metrics]]&lt;br /&gt;
* [[CSC/ECE 517 Fall 2024 - G2402 Refactor Graphql API endpoint for repositories]]&lt;br /&gt;
* [[CSC/ECE 517 Fall 2024 - E2484. Reimplement participants_controller.rb]]&lt;/div&gt;</summary>
		<author><name>Hzhang56</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=File:AdminError.jpg&amp;diff=158530</id>
		<title>File:AdminError.jpg</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=File:AdminError.jpg&amp;diff=158530"/>
		<updated>2024-10-30T03:50:04Z</updated>

		<summary type="html">&lt;p&gt;Hzhang56: Hzhang56 uploaded a new version of File:AdminError.jpg&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Hzhang56</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2024_-_E2466._UI_for_Impersonate_User&amp;diff=158517</id>
		<title>CSC/ECE 517 Fall 2024 - E2466. UI for Impersonate User</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2024_-_E2466._UI_for_Impersonate_User&amp;diff=158517"/>
		<updated>2024-10-30T03:47:12Z</updated>

		<summary type="html">&lt;p&gt;Hzhang56: /* Failed Impersonation Workflow */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Expertiza==&lt;br /&gt;
&lt;br /&gt;
Expertiza is an open-source web application developed using Ruby on Rails. The Expertiza platform is supported by the National Science Foundation, and it is used by instructors and students from selected courses. It enables students and instructors to manage, submit, and evaluate assignments efficiently. This application makes it possible for student collaboration and learning, allowing students to form teams, submit projects, and do peer assessments.&lt;br /&gt;
&lt;br /&gt;
Expertiza [http://expertiza.ncsu.edu/] is a Ruby on Rails [http://rubyonrails.org/] based open source project.&lt;br /&gt;
&lt;br /&gt;
==Problem Statement==&lt;br /&gt;
&lt;br /&gt;
The current Expertiza platform, implemented in Ruby on Rails, requires a re-implementation using TypeScript and ReactJS to modernize the user impersonation feature for administrators. This project focuses on developing an advanced impersonation interface, allowing authenticated users to assume identities of accounts they have authority over, either directly or through a defined creation hierarchy. Core elements include a responsive UI with optimized autocomplete and debounce, secure JWT token management, and APIs to facilitate controlled user access for enhanced system support and administration.&lt;br /&gt;
&lt;br /&gt;
==Terminology Explanation==&lt;br /&gt;
* '''TypeScript -''' Built on JavaScript, TypeScript enhances the language by adding static typing. It helps catch type errors during development, allowing programmers to write more robust and maintainable code.&lt;br /&gt;
* '''ReactJS -''' A JavaScript library for building user interfaces. It allows developers to create reusable UI components and manage states in web applications. &lt;br /&gt;
* '''JWT (JSON Web Token) -''' A compact and secure token used to transmit information between different parts of a system as a JSON object. It is used for authentication.&lt;br /&gt;
&lt;br /&gt;
==Component Details==&lt;br /&gt;
* '''package.json -''' This file was changed to include the lodash library and its debounce function. This addition was done to help TypeScript understand the structure of the debounce function, allowing features such as type checks and autocompletion. &lt;br /&gt;
* '''App.tsx -''' The file was changed to set up a route ''/impersonate'' in the Expertiza Application. When a user accesses this route, it will check if the user has the correct permission. If the user passes the check, then it will render the '''ImpersonateUser''' component. &lt;br /&gt;
* '''masquerade-mask.png -''' Image added to show a user is using the Impersonate feature.&lt;br /&gt;
* '''Header.tsx -''' This file was changed to include an impersonation banner indicating that a user is being impersonated and the impersonation session is active. The banner also has a cancel button that, when pressed, will reset the authentication state to the original user's credentials and clear the impersonation data.&lt;br /&gt;
* '''ImpersonateUser.css -''' A CSS file used by ImpersonateUser.tsx to display a spinning circle while the user is typing in the search field.&lt;br /&gt;
* '''ImpersonateUser.tsx -''' Allows the currently authenticated user to impersonate the identity of another user with roles lower than the current user. This is done by searching for their username and selecting them from a dynamically filtered dropdown list. The search field uses debouncing to decrease the number of API calls to the backend while the user types. Once a user is selected, the component sends an impersonation request with a JWT (JSON Web Token) to securely switch the active user session and displays a customized banner in the header to clearly indicate which user is currently being impersonated. The original user credentials are stored in LocalStorage, and it will be used when the user stops impersonating and wants to return to their default session.&lt;br /&gt;
&lt;br /&gt;
==Files Modified==&lt;br /&gt;
* package.json [https://github.com/augentism/reimplementation-front-end-impersonate-user/blob/main/package.json]&lt;br /&gt;
* App.tsx [https://github.com/augentism/reimplementation-front-end-impersonate-user/blob/main/src/App.tsx]&lt;br /&gt;
* masquerade-mask.png [https://github.com/augentism/reimplementation-front-end-impersonate-user/blob/main/src/assets/masquerade-mask.png]&lt;br /&gt;
* Header.tsx [https://github.com/augentism/reimplementation-front-end-impersonate-user/blob/main/src/layout/Header.tsx]&lt;br /&gt;
* ImpersonateUser.css [https://github.com/augentism/reimplementation-front-end-impersonate-user/blob/main/src/pages/Impersonate/ImpersonateUser.css]&lt;br /&gt;
* ImpersonateUser.tsx [https://github.com/augentism/reimplementation-front-end-impersonate-user/blob/main/src/pages/Impersonate/ImpersonateUser.tsx];&lt;br /&gt;
&lt;br /&gt;
==Design Patterns==&lt;br /&gt;
'''Command Pattern'''&amp;lt;/br&amp;gt;&lt;br /&gt;
The Command Pattern encapsulates a request (or an action) into a separate object. This allows the user to pass the command as a parameter so the user can save it or execute it later. The design pattern separates what needs to be done (in this case, the command) from the requester. &amp;lt;/br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The Command Pattern can be seen within the code, functions such as ''fetchUsers'', ''selectedUser'', and ''impersonateUser'' each encapsulate the logic for a specific action. These actions include fetching a list of users, retrieving a selected user, or initiating an impersonation of a selected user. These functions receive parameters as an input and execute their tasks.&amp;lt;/br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
''handleImpersonate'' function is the invoker, which calls the ''{BASE_URL}/api/v1/impersonate'' POST API. The code below shows this pattern:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  const handleImpersonate = () =&amp;gt; {&lt;br /&gt;
    // Store only the initial User's JWT token and information&lt;br /&gt;
    if (!localStorage.getItem(&amp;quot;originalUserToken&amp;quot;)) {&lt;br /&gt;
      localStorage.setItem(&amp;quot;originalUserToken&amp;quot;, auth.authToken);&lt;br /&gt;
    }&lt;br /&gt;
    const impersonateMessage =&lt;br /&gt;
      &amp;quot;Impersonating a &amp;quot; +&lt;br /&gt;
      fetchSelectedUser?.data.userList[0].role.name +&lt;br /&gt;
      &amp;quot; with name &amp;quot; +&lt;br /&gt;
      fetchSelectedUser?.data.userList[0].name;&lt;br /&gt;
    localStorage.setItem(&amp;quot;impersonateBannerMessage&amp;quot;, impersonateMessage);&lt;br /&gt;
    impersonateUser({&lt;br /&gt;
      method: &amp;quot;post&amp;quot;,&lt;br /&gt;
      url: `/impersonate`,&lt;br /&gt;
      data: {&lt;br /&gt;
        impersonate_id: fetchSelectedUser?.data.userList[0]?.id,&lt;br /&gt;
      },&lt;br /&gt;
    });&lt;br /&gt;
  };&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
'''Facade Pattern'''&amp;lt;/br&amp;gt;&lt;br /&gt;
The Facade Pattern provides a simple interface to a set of classes. It hides the inner workings of a complex system by providing a simple interface, making it easier to work with without knowing the inner details.&amp;lt;/br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
A clear example of a Facade Design pattern within our code is the use of the ''useAPI'' hook. The API handles all the complexity involved in making HTTP requests. The rest of the code can interact with useAPI, focusing only on what data needs to be fetched or updated without needing to know the details of how it is done. The code below shows this pattern:&amp;lt;/br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
const { data: userResponse, sendRequest: fetchUsers } = useAPI();&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
In the code snippet, ''userResponse'' is used to store the data returned by the useAPI hook after an API request, while ''fetchUsers'' is a function provided by useAPI for making the actual API call.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  useEffect(() =&amp;gt; {&lt;br /&gt;
    fetchUsers({&lt;br /&gt;
      method: &amp;quot;get&amp;quot;,&lt;br /&gt;
      url: `/users/${auth.user.id}/managed`,&lt;br /&gt;
    });&lt;br /&gt;
  }, [fetchUsers, auth.user.id]);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The useEffect triggers an API call to fetch a list of users whose roles can be impersonated by the currently authenticated user when the component mounts.&lt;br /&gt;
&lt;br /&gt;
==Tasks Completed==&lt;br /&gt;
'''1. Impersonation User Interface'''&lt;br /&gt;
*A ''ImpersonateUser.tsx'' webpage was created within the Expertiza front-end to allow authorized users, such as administrators and higher roles, to access the impersonation feature.&lt;br /&gt;
*Upon a successful impersonation, the user will be redirected to the homepage, and the authentication session will be switched to the impersonated user (using their JWT token). This will prompt a banner to appear at the top of the screen, indicating the active impersonation session. This banner includes details about the impersonated user's role and name, and it will also have the option to end the impersonation session.&lt;br /&gt;
&lt;br /&gt;
'''2. Efficient User Search'''&lt;br /&gt;
*A debounce function was integrated into the search field on the ''Impersonate User'' page to display filtered users in a dropdown that matches the entered query. The purpose of this debounce function is to ensure API calls are only triggered when the user is typing.&lt;br /&gt;
**An autocomplete entry feature was implemented in the dropdown. Now, the user can click on the autocomplete entries, and the search field will autofill with the selected user username.&lt;br /&gt;
**A feature was added to the impersonate button. The impersonate button will stay disabled until a valid username is entered into the search bar.&lt;br /&gt;
**A spinner icon was integrated into this debounce. It will spin when a user is typing in the search field. This indicates that results are being fetched actively. The spinner stops when the user is no longer typing. &lt;br /&gt;
&lt;br /&gt;
'''3. API Integration'''&lt;br /&gt;
*Made API calls to the user impersonation backend. &lt;br /&gt;
**GET a selected user's information. The response will be a ''userList'' object with details about the user, such as their ID, full name, role, etc.&lt;br /&gt;
**POST to retrieve a selected user's JWT token. This is used to facilitate the impersonation.&lt;br /&gt;
&lt;br /&gt;
'''4. Secure Management and Handling of JWT Tokens'''&lt;br /&gt;
*Implemented effective handling of JWT tokens for the original user and the impersonated user. &lt;br /&gt;
**The original user's token is stored using LocalStorage before impersonation, while the impersonated user's token is used only once to switch to the authentication token. This allows for successive impersonations (if the user's role allows). This method of storage allows the user to revert back to their default session once the impersonation session is canceled.&lt;br /&gt;
&lt;br /&gt;
==Impersonation UI Walkthrough==&lt;br /&gt;
&amp;lt;li&amp;gt;First, login to the admin account.&amp;lt;/li&amp;gt;&lt;br /&gt;
It will bring you to this homepage.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&lt;br /&gt;
[[File:Screenshot 2024-10-28 111449.png|900px]]&amp;lt;br/&amp;gt;&lt;br /&gt;
''Expertiza homepage''&lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;li&amp;gt;Then, click on &amp;quot;Manage&amp;quot;&amp;lt;/li&amp;gt;&lt;br /&gt;
It will display this dropdown.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&lt;br /&gt;
[[File:Screenshot 2024-10-28 111540.png|900px]]&amp;lt;br/&amp;gt;&lt;br /&gt;
''Dropdown menu''&lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;li&amp;gt;Click on &amp;quot;Impersonate User&amp;quot;&amp;lt;/li&amp;gt;&lt;br /&gt;
It will bring you to this Impersonate User page. &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&lt;br /&gt;
[[File:ImpersonateUserPage.jpg|900px]]&amp;lt;br/&amp;gt;&lt;br /&gt;
''Impersonate User page''&lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;li&amp;gt;Type out the username of the user you wish to impersonate&amp;lt;/li&amp;gt;&lt;br /&gt;
You will see that a list of matching users will appear in a dropdown. You can select the one you want to impersonate or finish typing out their username. &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&lt;br /&gt;
[[File:ShowDropdown.jpg|900px]]&amp;lt;br/&amp;gt;&lt;br /&gt;
''Shows the dropdown is working and getting users with matching letters''&lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
&amp;lt;center&amp;gt;&lt;br /&gt;
[[File:Spinning circle.jpg|900px]]&amp;lt;br/&amp;gt;&lt;br /&gt;
''Shows the Impersonate User page and the spinning wheel working''&lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;li&amp;gt;Click the &amp;quot;Impersonate&amp;quot; button.&amp;lt;/li&amp;gt;&lt;br /&gt;
After you have entered the user you wish to impersonate, the &amp;quot;Impersonate&amp;quot; button will be enabled. &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&lt;br /&gt;
[[File:ImpersonateButton.jpg|900px]]&amp;lt;br/&amp;gt;&lt;br /&gt;
''Shows the Impersonate Button is enabled, and we can click to impersonate''&lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You are now impersonating the selected user. A banner will be present in the header while the impersonation session is live.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&lt;br /&gt;
[[File:Admin.jpg|900px]]&amp;lt;br/&amp;gt;&lt;br /&gt;
''Shows the successful impersonation of Admin with name zachery''&lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;li&amp;gt;The following steps show you can continue to impersonate the users whose roles are below your current role.&amp;lt;/li&amp;gt;&lt;br /&gt;
Note, margarite (Instructor) is a role below zachery (Admin)&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&lt;br /&gt;
[[File:InstructorImpersonate.jpg|900px]]&amp;lt;br/&amp;gt;&lt;br /&gt;
''Shows Admin can impersonate an Instructor and that the banner changes based on the impersonated user''&lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;li&amp;gt;When you are done impersonating, you can click the ''X'' button, and it will send you back to the homepage. Your role will be reset to your original session.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;center&amp;gt;&lt;br /&gt;
[[File:HomepageAdmin.jpg|900px]]&amp;lt;br/&amp;gt;&lt;br /&gt;
''Shows the Super Admin is restored and successfully returns to the homepage''&lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Failed Impersonation Workflow - Scenario One===&lt;br /&gt;
The user zachery (Admin) is trying to impersonate zech (another Admin); however, this is not allowed.&lt;br /&gt;
&amp;lt;center&amp;gt;&lt;br /&gt;
[[File:ImpersonateAdmin.jpg|900px]]&amp;lt;br/&amp;gt;&lt;br /&gt;
''An Admin is trying to impersonate another Admin''&lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
When the user clicks the &amp;quot;Impersonate&amp;quot; button, an error message pops up. This indicates that the user cannot impersonate the selected user due to a permission error.&lt;br /&gt;
&amp;lt;center&amp;gt;&lt;br /&gt;
[[File:AdminError.jpg|900px]]&amp;lt;br/&amp;gt;&lt;br /&gt;
''Impersonation Permission Error''&lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Failed Impersonation Workflow - Scenario Two===&lt;br /&gt;
The user zachery (Admin) is trying to impersonate admin (superAdmin); however, this is not allowed.&lt;br /&gt;
&amp;lt;center&amp;gt;&lt;br /&gt;
[[File:AdminSuperAdmin.jpg|900px]]&amp;lt;br/&amp;gt;&lt;br /&gt;
''An Admin is trying to impersonate Super Admin''&lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
When the user clicks the &amp;quot;Impersonate&amp;quot; button, an error message pops up. This indicates that the user cannot impersonate the selected user due to a permission error.&lt;br /&gt;
&amp;lt;center&amp;gt;&lt;br /&gt;
[[File:SuperError.jpg|900px]]&amp;lt;br/&amp;gt;&lt;br /&gt;
''Impersonation Permission Error''&lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Impersonation UI Testing==&lt;br /&gt;
Since this project is a front-end implementation, we manually tested the functionality by navigating through the UI - [https://drive.google.com/file/d/1Ph_ShpjxVaBVnIon7CqAOr8NWN-0u04V/view?usp=sharing]&amp;lt;br&amp;gt;&lt;br /&gt;
''Note - We were unable to deploy this application since the Impersonation Backend PR [https://github.com/expertiza/reimplementation-back-end/pull/88] has yet to be merged into the Reimplementation Expertiza Backend [https://github.com/expertiza/reimplementation-back-end]''&lt;br /&gt;
&lt;br /&gt;
==Team==&lt;br /&gt;
'''Mentor''' &lt;br /&gt;
&lt;br /&gt;
*Jay Patel &amp;lt;jhpatel9@ncsu.edu&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Students'''&lt;br /&gt;
&lt;br /&gt;
*Pierce Whelan &amp;lt;pwwhelan@ncsu.edu&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*Calvin Jiang &amp;lt;crjiang@ncsu.edu&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*Hechun Zhang &amp;lt;hzhang56@ncsu.edu&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Pull Request==&lt;br /&gt;
[https://github.com/expertiza/reimplementation-front-end/pull/58]&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
Project Instructions [https://docs.google.com/document/d/1fB9nHsop_yptjcj3CFn80BcZjXcSDbzcWwKvBDUTVrQ/edit?usp=sharing] &amp;lt;br&amp;gt;&lt;br /&gt;
Impersonation Backend (New Expertiza) [https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2024_-_E2421._Reimplement_impersonating_users_(within_impersonate_controller.rb)_-_Final_Project] &amp;lt;br&amp;gt;&lt;br /&gt;
Impersonation Backend (Old Expertiza) [https://wiki.expertiza.ncsu.edu/index.php?title=CSE/ECE_517_Spring_2021_-_E2108._Impersonate_controller.rb]&lt;/div&gt;</summary>
		<author><name>Hzhang56</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=File:SuperError.jpg&amp;diff=158504</id>
		<title>File:SuperError.jpg</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=File:SuperError.jpg&amp;diff=158504"/>
		<updated>2024-10-30T03:41:28Z</updated>

		<summary type="html">&lt;p&gt;Hzhang56: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Hzhang56</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=File:AdminSuperAdmin.jpg&amp;diff=158503</id>
		<title>File:AdminSuperAdmin.jpg</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=File:AdminSuperAdmin.jpg&amp;diff=158503"/>
		<updated>2024-10-30T03:41:15Z</updated>

		<summary type="html">&lt;p&gt;Hzhang56: Hzhang56 uploaded a new version of File:AdminSuperAdmin.jpg&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Hzhang56</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=File:AdminSuperAdmin.jpg&amp;diff=158499</id>
		<title>File:AdminSuperAdmin.jpg</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=File:AdminSuperAdmin.jpg&amp;diff=158499"/>
		<updated>2024-10-30T03:38:47Z</updated>

		<summary type="html">&lt;p&gt;Hzhang56: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Hzhang56</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2024_-_E2466._UI_for_Impersonate_User&amp;diff=158443</id>
		<title>CSC/ECE 517 Fall 2024 - E2466. UI for Impersonate User</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2024_-_E2466._UI_for_Impersonate_User&amp;diff=158443"/>
		<updated>2024-10-30T03:20:33Z</updated>

		<summary type="html">&lt;p&gt;Hzhang56: /* Impersonation UI Walkthrough */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Expertiza==&lt;br /&gt;
&lt;br /&gt;
Expertiza is an open-source web application developed using Ruby on Rails. The Expertiza platform is supported by the National Science Foundation, and it is used by instructors and students from selected courses. It enables students and instructors to manage, submit, and evaluate assignments efficiently. This application makes it possible for student collaboration and learning, allowing students to form teams, submit projects, and do peer assessments.&lt;br /&gt;
&lt;br /&gt;
Expertiza [http://expertiza.ncsu.edu/] is a Ruby on Rails [http://rubyonrails.org/] based open source project.&lt;br /&gt;
&lt;br /&gt;
==Problem Statement==&lt;br /&gt;
&lt;br /&gt;
The current Expertiza platform, implemented in Ruby on Rails, requires a re-implementation using TypeScript and ReactJS to modernize the user impersonation feature for administrators. This project focuses on developing an advanced impersonation interface, allowing authenticated users to assume identities of accounts they have authority over, either directly or through a defined creation hierarchy. Core elements include a responsive UI with optimized autocomplete and debounce, secure JWT token management, and APIs to facilitate controlled user access for enhanced system support and administration.&lt;br /&gt;
&lt;br /&gt;
==Terminology Explanation==&lt;br /&gt;
* '''TypeScript -''' Built on JavaScript, TypeScript enhances the language by adding static typing. It helps catch type errors during development, allowing programmers to write more robust and maintainable code.&lt;br /&gt;
* '''ReactJS -''' A JavaScript library for building user interfaces. It allows developers to create reusable UI components and manage states in web applications. &lt;br /&gt;
* '''JWT (JSON Web Token) -''' A compact and secure token used to transmit information between different parts of a system as a JSON object. It is used for authentication.&lt;br /&gt;
&lt;br /&gt;
==Component Details==&lt;br /&gt;
* '''package.json -''' This file was changed to include the lodash library and its debounce function. This addition was done to help TypeScript understand the structure of the debounce function, allowing features such as type checks and autocompletion. &lt;br /&gt;
* '''App.tsx -''' The file was changed to set up a route ''/impersonate'' in the Expertiza Application. When a user accesses this route, it will check if the user has the correct permission. If the user passes the check, then it will render the '''ImpersonateUser''' component. &lt;br /&gt;
* '''masquerade-mask.png -''' Image added to show a user is using the Impersonate feature.&lt;br /&gt;
* '''Header.tsx -''' This file was changed to include an impersonation banner indicating that a user is being impersonated and the impersonation session is active. The banner also has a cancel button that, when pressed, will reset the authentication state to the original user's credentials and clear the impersonation data.&lt;br /&gt;
* '''ImpersonateUser.css -''' A CSS file used by ImpersonateUser.tsx to display a spinning circle while the user is typing in the search field.&lt;br /&gt;
* '''ImpersonateUser.tsx -''' Allows the currently authenticated user to impersonate the identity of another user with roles lower than the current user. This is done by searching for their username and selecting them from a dynamically filtered dropdown list. The search field uses debouncing to decrease the number of API calls to the backend while the user types. Once a user is selected, the component sends an impersonation request with a JWT (JSON Web Token) to securely switch the active user session and displays a customized banner in the header to clearly indicate which user is currently being impersonated. The original user credentials are stored in LocalStorage, and it will be used when the user stops impersonating and wants to return to their default session.&lt;br /&gt;
&lt;br /&gt;
==Files Modified==&lt;br /&gt;
* package.json [https://github.com/augentism/reimplementation-front-end-impersonate-user/blob/main/package.json]&lt;br /&gt;
* App.tsx [https://github.com/augentism/reimplementation-front-end-impersonate-user/blob/main/src/App.tsx]&lt;br /&gt;
* masquerade-mask.png [https://github.com/augentism/reimplementation-front-end-impersonate-user/blob/main/src/assets/masquerade-mask.png]&lt;br /&gt;
* Header.tsx [https://github.com/augentism/reimplementation-front-end-impersonate-user/blob/main/src/layout/Header.tsx]&lt;br /&gt;
* ImpersonateUser.css [https://github.com/augentism/reimplementation-front-end-impersonate-user/blob/main/src/pages/Impersonate/ImpersonateUser.css]&lt;br /&gt;
* ImpersonateUser.tsx [https://github.com/augentism/reimplementation-front-end-impersonate-user/blob/main/src/pages/Impersonate/ImpersonateUser.tsx];&lt;br /&gt;
&lt;br /&gt;
==Design Patterns==&lt;br /&gt;
'''Command Pattern'''&amp;lt;/br&amp;gt;&lt;br /&gt;
The Command Pattern encapsulates a request (or an action) into a separate object. This allows the user to pass the command as a parameter so the user can save it or execute it later. The design pattern separates what needs to be done (in this case, the command) from the requester. &amp;lt;/br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The Command Pattern can be seen within the code, functions such as ''fetchUsers'', ''selectedUser'', and ''impersonateUser'' each encapsulate the logic for a specific action. These actions include fetching a list of users, retrieving a selected user, or initiating an impersonation of a selected user. These functions receive parameters as an input and execute their tasks.&amp;lt;/br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
''handleImpersonate'' function is the invoker, which calls the ''{BASE_URL}/api/v1/impersonate'' POST API. The code below shows this pattern:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  const handleImpersonate = () =&amp;gt; {&lt;br /&gt;
    // Store only the initial User's JWT token and information&lt;br /&gt;
    if (!localStorage.getItem(&amp;quot;originalUserToken&amp;quot;)) {&lt;br /&gt;
      localStorage.setItem(&amp;quot;originalUserToken&amp;quot;, auth.authToken);&lt;br /&gt;
    }&lt;br /&gt;
    const impersonateMessage =&lt;br /&gt;
      &amp;quot;Impersonating a &amp;quot; +&lt;br /&gt;
      fetchSelectedUser?.data.userList[0].role.name +&lt;br /&gt;
      &amp;quot; with name &amp;quot; +&lt;br /&gt;
      fetchSelectedUser?.data.userList[0].name;&lt;br /&gt;
    localStorage.setItem(&amp;quot;impersonateBannerMessage&amp;quot;, impersonateMessage);&lt;br /&gt;
    impersonateUser({&lt;br /&gt;
      method: &amp;quot;post&amp;quot;,&lt;br /&gt;
      url: `/impersonate`,&lt;br /&gt;
      data: {&lt;br /&gt;
        impersonate_id: fetchSelectedUser?.data.userList[0]?.id,&lt;br /&gt;
      },&lt;br /&gt;
    });&lt;br /&gt;
  };&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
'''Facade Pattern'''&amp;lt;/br&amp;gt;&lt;br /&gt;
The Facade Pattern provides a simple interface to a set of classes. It hides the inner workings of a complex system by providing a simple interface, making it easier to work with without knowing the inner details.&amp;lt;/br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
A clear example of a Facade Design pattern within our code is the use of the ''useAPI'' hook. The API handles all the complexity involved in making HTTP requests. The rest of the code can interact with useAPI, focusing only on what data needs to be fetched or updated without needing to know the details of how it is done. The code below shows this pattern:&amp;lt;/br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
const { data: userResponse, sendRequest: fetchUsers } = useAPI();&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
In the code snippet, ''userResponse'' is used to store the data returned by the useAPI hook after an API request, while ''fetchUsers'' is a function provided by useAPI for making the actual API call.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  useEffect(() =&amp;gt; {&lt;br /&gt;
    fetchUsers({&lt;br /&gt;
      method: &amp;quot;get&amp;quot;,&lt;br /&gt;
      url: `/users/${auth.user.id}/managed`,&lt;br /&gt;
    });&lt;br /&gt;
  }, [fetchUsers, auth.user.id]);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The useEffect triggers an API call to fetch a list of users whose roles can be impersonated by the currently authenticated user when the component mounts.&lt;br /&gt;
&lt;br /&gt;
==Tasks Completed==&lt;br /&gt;
'''1. Impersonation User Interface'''&lt;br /&gt;
*A ''ImpersonateUser.tsx'' webpage was created within the Expertiza front-end to allow authorized users, such as administrators and higher roles, to access the impersonation feature.&lt;br /&gt;
*Upon a successful impersonation, the user will be redirected to the homepage, and the authentication session will be switched to the impersonated user (using their JWT token). This will prompt a banner to appear at the top of the screen, indicating the active impersonation session. This banner includes details about the impersonated user's role and name, and it will also have the option to end the impersonation session.&lt;br /&gt;
&lt;br /&gt;
'''2. Efficient User Search'''&lt;br /&gt;
*A debounce function was integrated into the search field on the ''Impersonate User'' page to display filtered users in a dropdown that matches the entered query. The purpose of this debounce function is to ensure API calls are only triggered when the user is typing.&lt;br /&gt;
**An autocomplete entry feature was implemented in the dropdown. Now, the user can click on the autocomplete entries, and the search field will autofill with the selected user username.&lt;br /&gt;
**A feature was added to the impersonate button. The impersonate button will stay disabled until a valid username is entered into the search bar.&lt;br /&gt;
**A spinner icon was integrated into this debounce. It will spin when a user is typing in the search field. This indicates that results are being fetched actively. The spinner stops when the user is no longer typing. &lt;br /&gt;
&lt;br /&gt;
'''3. API Integration'''&lt;br /&gt;
*Made API calls to the user impersonation backend. &lt;br /&gt;
**GET a selected user's information. The response will be a ''userList'' object with details about the user, such as their ID, full name, role, etc.&lt;br /&gt;
**POST to retrieve a selected user's JWT token. This is used to facilitate the impersonation.&lt;br /&gt;
&lt;br /&gt;
'''4. Secure Management and Handling of JWT Tokens'''&lt;br /&gt;
*Implemented effective handling of JWT tokens for the original user and the impersonated user. &lt;br /&gt;
**The original user's token is stored using LocalStorage before impersonation, while the impersonated user's token is used only once to switch to the authentication token. This allows for successive impersonations (if the user's role allows). This method of storage allows the user to revert back to their default session once the impersonation session is canceled.&lt;br /&gt;
&lt;br /&gt;
==Impersonation UI Walkthrough==&lt;br /&gt;
&amp;lt;li&amp;gt;First, login to the admin account.&amp;lt;/li&amp;gt;&lt;br /&gt;
It will bring you to this homepage.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&lt;br /&gt;
[[File:Screenshot 2024-10-28 111449.png|900px]]&amp;lt;br/&amp;gt;&lt;br /&gt;
''Expertiza homepage''&lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;li&amp;gt;Then, click on &amp;quot;Manage&amp;quot;&amp;lt;/li&amp;gt;&lt;br /&gt;
It will display this dropdown.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&lt;br /&gt;
[[File:Screenshot 2024-10-28 111540.png|900px]]&amp;lt;br/&amp;gt;&lt;br /&gt;
''Dropdown menu''&lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;li&amp;gt;Click on &amp;quot;Impersonate User&amp;quot;&amp;lt;/li&amp;gt;&lt;br /&gt;
It will bring you to this Impersonate User page. &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&lt;br /&gt;
[[File:ImpersonateUserPage.jpg|900px]]&amp;lt;br/&amp;gt;&lt;br /&gt;
''Impersonate User page''&lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;li&amp;gt;Type out the username of the user you wish to impersonate&amp;lt;/li&amp;gt;&lt;br /&gt;
You will see that a list of matching users will appear in a dropdown. You can select the one you want to impersonate or finish typing out their username. &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&lt;br /&gt;
[[File:ShowDropdown.jpg|900px]]&amp;lt;br/&amp;gt;&lt;br /&gt;
''Shows the dropdown is working and getting users with matching letters''&lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
&amp;lt;center&amp;gt;&lt;br /&gt;
[[File:Spinning circle.jpg|900px]]&amp;lt;br/&amp;gt;&lt;br /&gt;
''Shows the Impersonate User page and the spinning wheel working''&lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;li&amp;gt;Click the &amp;quot;Impersonate&amp;quot; button.&amp;lt;/li&amp;gt;&lt;br /&gt;
After you have entered the user you wish to impersonate, the &amp;quot;Impersonate&amp;quot; button will be enabled. &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&lt;br /&gt;
[[File:ImpersonateButton.jpg|900px]]&amp;lt;br/&amp;gt;&lt;br /&gt;
''Shows the Impersonate Button is enabled, and we can click to impersonate''&lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You are now impersonating the selected user. A banner will be present in the header while the impersonation session is live.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&lt;br /&gt;
[[File:Admin.jpg|900px]]&amp;lt;br/&amp;gt;&lt;br /&gt;
''Shows the successful impersonation of Admin with name zachery''&lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;li&amp;gt;The following steps show you can continue to impersonate the users whose roles are below your current role.&amp;lt;/li&amp;gt;&lt;br /&gt;
Note, margarite (Instructor) is a role below zachery (Admin)&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&lt;br /&gt;
[[File:InstructorImpersonate.jpg|900px]]&amp;lt;br/&amp;gt;&lt;br /&gt;
''Shows Admin can impersonate an Instructor and that the banner changes based on the impersonated user''&lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;li&amp;gt;When you are done impersonating, you can click the ''X'' button, and it will send you back to the homepage. Your role will be reset to your original session.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;center&amp;gt;&lt;br /&gt;
[[File:HomepageAdmin.jpg|900px]]&amp;lt;br/&amp;gt;&lt;br /&gt;
''Shows the Super Admin is restored and successfully returns to the homepage''&lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Showing Failed Impersonation Logic===&lt;br /&gt;
The Picture below shows zachery(admin) trying to impersonate zech another admin; the impersonate button is active.&lt;br /&gt;
&amp;lt;center&amp;gt;&lt;br /&gt;
[[File:ImpersonateAdmin.jpg|900px]]&amp;lt;br/&amp;gt;&lt;br /&gt;
''Shows the Admin trying to impersonate another Admin''&lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
The picture below shows an error message pop-up appearing after the impersonate button has been pressed.&lt;br /&gt;
&amp;lt;center&amp;gt;&lt;br /&gt;
[[File:AdminError.jpg|900px]]&amp;lt;br/&amp;gt;&lt;br /&gt;
''Shows the Error message''&lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Impersonation UI Testing==&lt;br /&gt;
Since this project is a front-end implementation, we manually tested the functionality by navigating through the UI - [https://drive.google.com/file/d/1Ph_ShpjxVaBVnIon7CqAOr8NWN-0u04V/view?usp=sharing]&amp;lt;br&amp;gt;&lt;br /&gt;
''Note - We were unable to deploy this application since the Impersonation Backend PR [https://github.com/expertiza/reimplementation-back-end/pull/88] has yet to be merged into the Reimplementation Expertiza Backend [https://github.com/expertiza/reimplementation-back-end]''&lt;br /&gt;
&lt;br /&gt;
==Team==&lt;br /&gt;
'''Mentor''' &lt;br /&gt;
&lt;br /&gt;
*Jay Patel &amp;lt;jhpatel9@ncsu.edu&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Students'''&lt;br /&gt;
&lt;br /&gt;
*Pierce Whelan &amp;lt;pwwhelan@ncsu.edu&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*Calvin Jiang &amp;lt;crjiang@ncsu.edu&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*Hechun Zhang &amp;lt;hzhang56@ncsu.edu&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Pull Request==&lt;br /&gt;
[https://github.com/expertiza/reimplementation-front-end/pull/58]&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
Project Instructions [https://docs.google.com/document/d/1fB9nHsop_yptjcj3CFn80BcZjXcSDbzcWwKvBDUTVrQ/edit?usp=sharing] &amp;lt;br&amp;gt;&lt;br /&gt;
Impersonation Backend (New Expertiza) [https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2024_-_E2421._Reimplement_impersonating_users_(within_impersonate_controller.rb)_-_Final_Project] &amp;lt;br&amp;gt;&lt;br /&gt;
Impersonation Backend (Old Expertiza) [https://wiki.expertiza.ncsu.edu/index.php?title=CSE/ECE_517_Spring_2021_-_E2108._Impersonate_controller.rb]&lt;/div&gt;</summary>
		<author><name>Hzhang56</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=File:AdminError.jpg&amp;diff=158425</id>
		<title>File:AdminError.jpg</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=File:AdminError.jpg&amp;diff=158425"/>
		<updated>2024-10-30T03:14:51Z</updated>

		<summary type="html">&lt;p&gt;Hzhang56: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Hzhang56</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=File:ImpersonateAdmin.jpg&amp;diff=158424</id>
		<title>File:ImpersonateAdmin.jpg</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=File:ImpersonateAdmin.jpg&amp;diff=158424"/>
		<updated>2024-10-30T03:14:40Z</updated>

		<summary type="html">&lt;p&gt;Hzhang56: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Hzhang56</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2024_-_E2466._UI_for_Impersonate_User&amp;diff=158349</id>
		<title>CSC/ECE 517 Fall 2024 - E2466. UI for Impersonate User</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2024_-_E2466._UI_for_Impersonate_User&amp;diff=158349"/>
		<updated>2024-10-30T02:52:47Z</updated>

		<summary type="html">&lt;p&gt;Hzhang56: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Expertiza==&lt;br /&gt;
&lt;br /&gt;
Expertiza is an open-source web application developed using Ruby on Rails. The Expertiza platform is supported by the National Science Foundation, and it is used by instructors and students from selected courses. It enables students and instructors to manage, submit, and evaluate assignments efficiently. This application makes it possible for student collaboration and learning, allowing students to form teams, submit projects, and do peer assessments.&lt;br /&gt;
&lt;br /&gt;
Expertiza [http://expertiza.ncsu.edu/] is a Ruby on Rails [http://rubyonrails.org/] based open source project.&lt;br /&gt;
&lt;br /&gt;
==Problem Statement==&lt;br /&gt;
&lt;br /&gt;
The current Expertiza platform, implemented in Ruby on Rails, requires a re-implementation using TypeScript and ReactJS to modernize the user impersonation feature for administrators. This project focuses on developing an advanced impersonation interface, allowing authenticated users to assume identities of accounts they have authority over, either directly or through a defined creation hierarchy. Core elements include a responsive UI with optimized autocomplete and debounce, secure JWT token management, and APIs to facilitate controlled user access for enhanced system support and administration.&lt;br /&gt;
&lt;br /&gt;
==Terminology Explanation==&lt;br /&gt;
* '''TypeScript -''' Built on JavaScript, TypeScript enhances the language by adding static typing. It helps catch type errors during development, allowing programmers to write more robust and maintainable code.&lt;br /&gt;
* '''ReactJS -''' A JavaScript library for building user interfaces. It allows developers to create reusable UI components and manage states in web applications. &lt;br /&gt;
* '''JWT (JSON Web Token) -''' A compact and secure token used to transmit information between different parts of a system as a JSON object. It is used for authentication.&lt;br /&gt;
&lt;br /&gt;
==Component Details==&lt;br /&gt;
* '''package.json -''' This file was changed to include the lodash library and its debounce function. This addition was done to help TypeScript understand the structure of the debounce function, allowing features such as type checks and autocompletion. &lt;br /&gt;
* '''App.tsx -''' The file was changed to set up a route ''/impersonate'' in the Expertiza Application. When a user accesses this route, it will check if the user has the correct permission. If the user passes the check, then it will render the '''ImpersonateUser''' component. &lt;br /&gt;
* '''masquerade-mask.png -''' Image added to show a user is using the Impersonate feature.&lt;br /&gt;
* '''Header.tsx -''' This file was changed to include an impersonation banner indicating that a user is being impersonated and the impersonation session is active. The banner also has a cancel button that, when pressed, will reset the authentication state to the original user's credentials and clear the impersonation data.&lt;br /&gt;
* '''ImpersonateUser.css -''' A CSS file used by ImpersonateUser.tsx to display a spinning circle while the user is typing in the search field.&lt;br /&gt;
* '''ImpersonateUser.tsx -''' Allows the currently authenticated user to impersonate the identity of another user with roles lower than the current user. This is done by searching for their username and selecting them from a dynamically filtered dropdown list. The search field uses debouncing to decrease the number of API calls to the backend while the user types. Once a user is selected, the component sends an impersonation request with a JWT (JSON Web Token) to securely switch the active user session and displays a customized banner in the header to clearly indicate which user is currently being impersonated. The original user credentials are stored in LocalStorage, and it will be used when the user stops impersonating and wants to return to their default session.&lt;br /&gt;
&lt;br /&gt;
==Files Modified==&lt;br /&gt;
* package.json [https://github.com/augentism/reimplementation-front-end-impersonate-user/blob/main/package.json]&lt;br /&gt;
* App.tsx [https://github.com/augentism/reimplementation-front-end-impersonate-user/blob/main/src/App.tsx]&lt;br /&gt;
* masquerade-mask.png [https://github.com/augentism/reimplementation-front-end-impersonate-user/blob/main/src/assets/masquerade-mask.png]&lt;br /&gt;
* Header.tsx [https://github.com/augentism/reimplementation-front-end-impersonate-user/blob/main/src/layout/Header.tsx]&lt;br /&gt;
* ImpersonateUser.css [https://github.com/augentism/reimplementation-front-end-impersonate-user/blob/main/src/pages/Impersonate/ImpersonateUser.css]&lt;br /&gt;
* ImpersonateUser.tsx [https://github.com/augentism/reimplementation-front-end-impersonate-user/blob/main/src/pages/Impersonate/ImpersonateUser.tsx];&lt;br /&gt;
&lt;br /&gt;
==Design Patterns==&lt;br /&gt;
'''Command Pattern'''&amp;lt;/br&amp;gt;&lt;br /&gt;
The Command Pattern encapsulates a request (or an action) into a separate object. This allows the user to pass the command as a parameter so the user can save it or execute it later. The design pattern separates what needs to be done (in this case, the command) from the requester. &amp;lt;/br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The Command Pattern can be seen within the code, functions such as ''fetchUsers'', ''selectedUser'', and ''impersonateUser'' each encapsulate the logic for a specific action. These actions include fetching a list of users, retrieving a selected user, or initiating an impersonation of a selected user. These functions receive parameters as an input and execute their tasks.&amp;lt;/br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
''handleImpersonate'' function is the invoker, which calls the ''{BASE_URL}/api/v1/impersonate'' POST API. The code below shows this pattern:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  const handleImpersonate = () =&amp;gt; {&lt;br /&gt;
    // Store only the initial User's JWT token and information&lt;br /&gt;
    if (!localStorage.getItem(&amp;quot;originalUserToken&amp;quot;)) {&lt;br /&gt;
      localStorage.setItem(&amp;quot;originalUserToken&amp;quot;, auth.authToken);&lt;br /&gt;
    }&lt;br /&gt;
    const impersonateMessage =&lt;br /&gt;
      &amp;quot;Impersonating a &amp;quot; +&lt;br /&gt;
      fetchSelectedUser?.data.userList[0].role.name +&lt;br /&gt;
      &amp;quot; with name &amp;quot; +&lt;br /&gt;
      fetchSelectedUser?.data.userList[0].name;&lt;br /&gt;
    localStorage.setItem(&amp;quot;impersonateBannerMessage&amp;quot;, impersonateMessage);&lt;br /&gt;
    impersonateUser({&lt;br /&gt;
      method: &amp;quot;post&amp;quot;,&lt;br /&gt;
      url: `/impersonate`,&lt;br /&gt;
      data: {&lt;br /&gt;
        impersonate_id: fetchSelectedUser?.data.userList[0]?.id,&lt;br /&gt;
      },&lt;br /&gt;
    });&lt;br /&gt;
  };&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
'''Facade Pattern'''&amp;lt;/br&amp;gt;&lt;br /&gt;
The Facade Pattern provides a simple interface to a set of classes. It hides the inner workings of a complex system by providing a simple interface, making it easier to work with without knowing the inner details.&amp;lt;/br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
A clear example of a Facade Design pattern within our code is the use of the ''useAPI'' hook. The API handles all the complexity involved in making HTTP requests. The rest of the code can interact with useAPI, focusing only on what data needs to be fetched or updated without needing to know the details of how it is done. The code below shows this pattern:&amp;lt;/br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
const { data: userResponse, sendRequest: fetchUsers } = useAPI();&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
In the code snippet, ''userResponse'' is used to store the data returned by the useAPI hook after an API request, while ''fetchUsers'' is a function provided by useAPI for making the actual API call.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  useEffect(() =&amp;gt; {&lt;br /&gt;
    fetchUsers({&lt;br /&gt;
      method: &amp;quot;get&amp;quot;,&lt;br /&gt;
      url: `/users/${auth.user.id}/managed`,&lt;br /&gt;
    });&lt;br /&gt;
  }, [fetchUsers, auth.user.id]);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The useEffect triggers an API call to fetch a list of users whose roles can be impersonated by the currently authenticated user when the component mounts.&lt;br /&gt;
&lt;br /&gt;
==Tasks Completed==&lt;br /&gt;
'''1. Impersonation User Interface'''&lt;br /&gt;
*A ''ImpersonateUser.tsx'' webpage was created within the Expertiza front-end to allow authorized users, such as administrators and higher roles, to access the impersonation feature.&lt;br /&gt;
*Upon a successful impersonation, the user will be redirected to the homepage, and the authentication session will be switched to the impersonated user (using their JWT token). This will prompt a banner to appear at the top of the screen, indicating the active impersonation session. This banner includes details about the impersonated user's role and name, and it will also have the option to end the impersonation session.&lt;br /&gt;
&lt;br /&gt;
'''2. Efficient User Search'''&lt;br /&gt;
*A debounce function was integrated into the search field on the ''Impersonate User'' page to display filtered users in a dropdown that matches the entered query. The purpose of this debounce function is to ensure API calls are only triggered when the user is typing.&lt;br /&gt;
**An autocomplete entry feature was implemented in the dropdown. Now, the user can click on the autocomplete entries, and the search field will autofill with the selected user username.&lt;br /&gt;
**A feature was added to the impersonate button. The impersonate button will stay disabled until a valid username is entered into the search bar.&lt;br /&gt;
**A spinner icon was integrated into this debounce. It will spin when a user is typing in the search field. This indicates that results are being fetched actively. The spinner stops when the user is no longer typing. &lt;br /&gt;
&lt;br /&gt;
'''3. API Integration'''&lt;br /&gt;
*Made API calls to the user impersonation backend. &lt;br /&gt;
**GET a selected user's information. The response will be a ''userList'' object with details about the user, such as their ID, full name, role, etc.&lt;br /&gt;
**POST to retrieve a selected user's JWT token. This is used to facilitate the impersonation.&lt;br /&gt;
&lt;br /&gt;
'''4. Secure Management and Handling of JWT Tokens'''&lt;br /&gt;
*Implemented effective handling of JWT tokens for the original user and the impersonated user. &lt;br /&gt;
**The original user's token is stored using LocalStorage before impersonation, while the impersonated user's token is used only once to switch to the authentication token. This allows for successive impersonations (if the user's role allows). This method of storage allows the user to revert back to their default session once the impersonation session is canceled.&lt;br /&gt;
&lt;br /&gt;
==Impersonation UI Walkthrough==&lt;br /&gt;
&amp;lt;li&amp;gt;First, login to the admin account.&amp;lt;/li&amp;gt;&lt;br /&gt;
It will bring you to this homepage.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&lt;br /&gt;
[[File:Screenshot 2024-10-28 111449.png|900px]]&amp;lt;br/&amp;gt;&lt;br /&gt;
''Expertiza homepage''&lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;li&amp;gt;Then, click on &amp;quot;Manage&amp;quot;&amp;lt;/li&amp;gt;&lt;br /&gt;
It will display this dropdown.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&lt;br /&gt;
[[File:Screenshot 2024-10-28 111540.png|900px]]&amp;lt;br/&amp;gt;&lt;br /&gt;
''Dropdown menu''&lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;li&amp;gt;Click on &amp;quot;Impersonate User&amp;quot;&amp;lt;/li&amp;gt;&lt;br /&gt;
It will bring you to this impersonate user page. &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&lt;br /&gt;
[[File:ImpersonateUserPage.jpg|900px]]&amp;lt;br/&amp;gt;&lt;br /&gt;
''Impersonate User Page''&lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Type out the username of the user you wish to impersonate. You will see that a list of matching users will appear in a dropdown. You can select the one you want to impersonate or finish typing out their username. &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&lt;br /&gt;
[[File:ShowDropdown.jpg|900px]]&amp;lt;br/&amp;gt;&lt;br /&gt;
''Shows the dropdown is working and getting users with similar username.''&lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
&amp;lt;center&amp;gt;&lt;br /&gt;
[[File:Spinning circle.jpg|900px]]&amp;lt;br/&amp;gt;&lt;br /&gt;
''Shows the Impersonate user page and the spinning wheel working.''&lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
After you have entered the user you wish to impersonate, the &amp;quot;Impersonate&amp;quot; button will be enabled. &amp;lt;br&amp;gt;&lt;br /&gt;
Click the &amp;quot;Impersonate&amp;quot; button.&lt;br /&gt;
&amp;lt;center&amp;gt;&lt;br /&gt;
[[File:ImpersonateButton.jpg|900px]]&amp;lt;br/&amp;gt;&lt;br /&gt;
''Shows the Impersonate Button is enabled, and we can click to impersonate.''&lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You are now impersonating the selected user. A banner will be present in the header while the impersonation session is live.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&lt;br /&gt;
[[File:Admin.jpg|900px]]&amp;lt;br/&amp;gt;&lt;br /&gt;
''Shows the successful impersonation of Admin with name zachery''&lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Go to the impersonate page again and begin typing the user you want to impersonate into the search bar. &amp;lt;br&amp;gt;&lt;br /&gt;
Note, your current role is admin, so you should be able to impersonate an instructor or any role lower than that.&lt;br /&gt;
&amp;lt;center&amp;gt;&lt;br /&gt;
[[File:ListUser.jpg|900px]]&amp;lt;br/&amp;gt;&lt;br /&gt;
''Shows the dropdown is the correct users''&lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The following steps show you can continue to impersonate the users whose roles are below your current role.&amp;lt;br&amp;gt;&lt;br /&gt;
The picture below shows zachery trying to impersonate margarite, and the impersonate button is active.&amp;lt;br&amp;gt;&lt;br /&gt;
Note, margarite(Instructor) is a role below zachery(admin)&lt;br /&gt;
&amp;lt;center&amp;gt;&lt;br /&gt;
[[File:ImpersonateMarg.jpg|900px]]&amp;lt;br/&amp;gt;&lt;br /&gt;
''Shows super admin can impersonate admin, then can impersonate instructor''&lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The picture below shows impersonating the instructor was successful.&lt;br /&gt;
&amp;lt;center&amp;gt;&lt;br /&gt;
[[File:InstructorImpersonate.jpg|900px]]&amp;lt;br/&amp;gt;&lt;br /&gt;
''Shows Admin can impersonate an Instructor''&lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;li&amp;gt;Whenever you impersonate a role, the banner will display the username of the user you impersonated and their role.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;center&amp;gt;&lt;br /&gt;
[[File:Cancel.jpg|900px]]&amp;lt;br/&amp;gt;&lt;br /&gt;
''Shows the banner change as a user impersonates''&lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;li&amp;gt;When you are done impersonating, you can click the cancel button, and it will send you back to the homepage, and your role will be reset to default.&amp;lt;/li&amp;gt;&lt;br /&gt;
The picture below shows when the super admin is done impersonating the instructor, their role will be reset to their original role, and the homepage will display.&lt;br /&gt;
&amp;lt;center&amp;gt;&lt;br /&gt;
[[File:HomepageAdmin.jpg|900px]]&amp;lt;br/&amp;gt;&lt;br /&gt;
''Shows Super Admin successfully return to homepage''&lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Impersonation UI Testing==&lt;br /&gt;
Since this project is a front-end implementation, we manually tested the functionality by navigating through the UI - [https://drive.google.com/file/d/1Ph_ShpjxVaBVnIon7CqAOr8NWN-0u04V/view?usp=sharing]&amp;lt;br&amp;gt;&lt;br /&gt;
''Note - We were unable to deploy this application since the Impersonation Backend PR [https://github.com/expertiza/reimplementation-back-end/pull/88] has yet to be merged into the Reimplementation Expertiza Backend [https://github.com/expertiza/reimplementation-back-end]''&lt;br /&gt;
&lt;br /&gt;
==Team==&lt;br /&gt;
'''Mentor''' &lt;br /&gt;
&lt;br /&gt;
*Jay Patel &amp;lt;jhpatel9@ncsu.edu&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Students'''&lt;br /&gt;
&lt;br /&gt;
*Pierce Whelan &amp;lt;pwwhelan@ncsu.edu&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*Calvin Jiang &amp;lt;crjiang@ncsu.edu&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*Hechun Zhang &amp;lt;hzhang56@ncsu.edu&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Pull Request==&lt;br /&gt;
[https://github.com/expertiza/reimplementation-front-end/pull/58]&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
Project Instructions [https://docs.google.com/document/d/1fB9nHsop_yptjcj3CFn80BcZjXcSDbzcWwKvBDUTVrQ/edit?usp=sharing] &amp;lt;br&amp;gt;&lt;br /&gt;
Impersonation Backend (New Expertiza) [https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2024_-_E2421._Reimplement_impersonating_users_(within_impersonate_controller.rb)_-_Final_Project] &amp;lt;br&amp;gt;&lt;br /&gt;
Impersonation Backend (Old Expertiza) [https://wiki.expertiza.ncsu.edu/index.php?title=CSE/ECE_517_Spring_2021_-_E2108._Impersonate_controller.rb]&lt;/div&gt;</summary>
		<author><name>Hzhang56</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2024_-_E2466._UI_for_Impersonate_User&amp;diff=158320</id>
		<title>CSC/ECE 517 Fall 2024 - E2466. UI for Impersonate User</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2024_-_E2466._UI_for_Impersonate_User&amp;diff=158320"/>
		<updated>2024-10-30T02:48:36Z</updated>

		<summary type="html">&lt;p&gt;Hzhang56: /* Tasks Completed */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Expertiza==&lt;br /&gt;
&lt;br /&gt;
Expertiza is an open-source web application developed using Ruby on Rails. The Expertiza platform is supported by the National Science Foundation, and it is used by instructors and students from selected courses. It enables students and instructors to manage, submit, and evaluate assignments efficiently. This application makes it possible for student collaboration and learning, allowing students to form teams, submit projects, and do peer assessments.&lt;br /&gt;
&lt;br /&gt;
Expertiza [http://expertiza.ncsu.edu/] is a Ruby on Rails [http://rubyonrails.org/] based open source project.&lt;br /&gt;
&lt;br /&gt;
==Problem Statement==&lt;br /&gt;
&lt;br /&gt;
The current Expertiza platform, implemented in Ruby on Rails, requires a re-implementation using TypeScript and ReactJS to modernize the user impersonation feature for administrators. This project focuses on developing an advanced impersonation interface, allowing authenticated users to assume identities of accounts they have authority over, either directly or through a defined creation hierarchy. Core elements include a responsive UI with optimized autocomplete and debounce, secure JWT token management, and APIs to facilitate controlled user access for enhanced system support and administration.&lt;br /&gt;
&lt;br /&gt;
==Terminology Explanation==&lt;br /&gt;
* '''TypeScript -''' Built on JavaScript, TypeScript enhances the language by adding static typing. It helps catch type errors during development, allowing programmers to write more robust and maintainable code.&lt;br /&gt;
* '''ReactJS -''' A JavaScript library for building user interfaces. It allows developers to create reusable UI components and manage states in web applications. &lt;br /&gt;
* '''JWT (JSON Web Token) -''' A compact and secure token used to transmit information between different parts of a system as a JSON object. It is used for authentication.&lt;br /&gt;
&lt;br /&gt;
==Component Details==&lt;br /&gt;
* '''package.json -''' This file was changed to include the lodash library and its debounce function. This addition was done to help TypeScript understand the structure of the debounce function, allowing features such as type checks and autocompletion. &lt;br /&gt;
* '''App.tsx -''' The file was changed to set up a route ''/impersonate'' in the Expertiza Application. When a user accesses this route, it will check if the user has the correct permission. If the user passes the check, then it will render the '''ImpersonateUser''' component. &lt;br /&gt;
* '''masquerade-mask.png -''' Image added to show a user is using the Impersonate feature.&lt;br /&gt;
* '''Header.tsx -''' This file was changed to include an impersonation banner indicating that a user is being impersonated and the impersonation session is active. The banner also has a cancel button that, when pressed, will reset the authentication state to the original user's credentials and clear the impersonation data.&lt;br /&gt;
* '''ImpersonateUser.css -''' A CSS file used by ImpersonateUser.tsx to display a spinning circle while the user is typing in the search field.&lt;br /&gt;
* '''ImpersonateUser.tsx -''' Allows the currently authenticated user to impersonate the identity of another user with roles lower than the current user. This is done by searching for their username and selecting them from a dynamically filtered dropdown list. The search field uses debouncing to decrease the number of API calls to the backend while the user types. Once a user is selected, the component sends an impersonation request with a JWT (JSON Web Token) to securely switch the active user session and displays a customized banner in the header to clearly indicate which user is currently being impersonated. The original user credentials are stored in LocalStorage, and it will be used when the user stops impersonating and wants to return to their default session.&lt;br /&gt;
&lt;br /&gt;
==Files Modified==&lt;br /&gt;
* package.json [https://github.com/augentism/reimplementation-front-end-impersonate-user/blob/main/package.json]&lt;br /&gt;
* App.tsx [https://github.com/augentism/reimplementation-front-end-impersonate-user/blob/main/src/App.tsx]&lt;br /&gt;
* masquerade-mask.png [https://github.com/augentism/reimplementation-front-end-impersonate-user/blob/main/src/assets/masquerade-mask.png]&lt;br /&gt;
* Header.tsx [https://github.com/augentism/reimplementation-front-end-impersonate-user/blob/main/src/layout/Header.tsx]&lt;br /&gt;
* ImpersonateUser.css [https://github.com/augentism/reimplementation-front-end-impersonate-user/blob/main/src/pages/Impersonate/ImpersonateUser.css]&lt;br /&gt;
* ImpersonateUser.tsx [https://github.com/augentism/reimplementation-front-end-impersonate-user/blob/main/src/pages/Impersonate/ImpersonateUser.tsx];&lt;br /&gt;
&lt;br /&gt;
==Design Patterns==&lt;br /&gt;
'''Command Pattern'''&amp;lt;/br&amp;gt;&lt;br /&gt;
The Command Pattern encapsulates a request (or an action) into a separate object. This allows the user to pass the command as a parameter so the user can save it or execute it later. The design pattern separates what needs to be done (in this case, the command) from the requester. &amp;lt;/br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The Command Pattern can be seen within the code, functions such as ''fetchUsers'', ''selectedUser'', and ''impersonateUser'' each encapsulate the logic for a specific action. These actions include fetching a list of users, retrieving a selected user, or initiating an impersonation of a selected user. These functions receive parameters as an input and execute their tasks.&amp;lt;/br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
''handleImpersonate'' function is the invoker, which calls the ''{BASE_URL}/api/v1/impersonate'' POST API. The code below shows this pattern:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  const handleImpersonate = () =&amp;gt; {&lt;br /&gt;
    // Store only the initial User's JWT token and information&lt;br /&gt;
    if (!localStorage.getItem(&amp;quot;originalUserToken&amp;quot;)) {&lt;br /&gt;
      localStorage.setItem(&amp;quot;originalUserToken&amp;quot;, auth.authToken);&lt;br /&gt;
    }&lt;br /&gt;
    const impersonateMessage =&lt;br /&gt;
      &amp;quot;Impersonating a &amp;quot; +&lt;br /&gt;
      fetchSelectedUser?.data.userList[0].role.name +&lt;br /&gt;
      &amp;quot; with name &amp;quot; +&lt;br /&gt;
      fetchSelectedUser?.data.userList[0].name;&lt;br /&gt;
    localStorage.setItem(&amp;quot;impersonateBannerMessage&amp;quot;, impersonateMessage);&lt;br /&gt;
    impersonateUser({&lt;br /&gt;
      method: &amp;quot;post&amp;quot;,&lt;br /&gt;
      url: `/impersonate`,&lt;br /&gt;
      data: {&lt;br /&gt;
        impersonate_id: fetchSelectedUser?.data.userList[0]?.id,&lt;br /&gt;
      },&lt;br /&gt;
    });&lt;br /&gt;
  };&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
'''Facade Pattern'''&amp;lt;/br&amp;gt;&lt;br /&gt;
The Facade Pattern provides a simple interface to a set of classes. It hides the inner workings of a complex system by providing a simple interface, making it easier to work with without knowing the inner details.&amp;lt;/br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
A clear example of a Facade Design pattern within our code is the use of the ''useAPI'' hook. The API handles all the complexity involved in making HTTP requests. The rest of the code can interact with useAPI, focusing only on what data needs to be fetched or updated without needing to know the details of how it is done. The code below shows this pattern:&amp;lt;/br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
const { data: userResponse, sendRequest: fetchUsers } = useAPI();&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
In the code snippet, ''userResponse'' is used to store the data returned by the useAPI hook after an API request, while ''fetchUsers'' is a function provided by useAPI for making the actual API call.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  useEffect(() =&amp;gt; {&lt;br /&gt;
    fetchUsers({&lt;br /&gt;
      method: &amp;quot;get&amp;quot;,&lt;br /&gt;
      url: `/users/${auth.user.id}/managed`,&lt;br /&gt;
    });&lt;br /&gt;
  }, [fetchUsers, auth.user.id]);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The useEffect triggers an API call to fetch a list of users whose roles can be impersonated by the currently authenticated user when the component mounts.&lt;br /&gt;
&lt;br /&gt;
==Tasks Completed==&lt;br /&gt;
'''1. Impersonation User Interface'''&lt;br /&gt;
*A ''ImpersonateUser.tsx'' webpage was created within the Expertiza front-end to allow authorized users, such as administrators and higher roles, to access the impersonation feature.&lt;br /&gt;
*Upon a successful impersonation, the user will be redirected to the homepage, and the authentication session will be switched to the impersonated user (using their JWT token). This will prompt a banner to appear at the top of the screen, indicating the active impersonation session. This banner includes details about the impersonated user's role and name, and it will also have the option to end the impersonation session.&lt;br /&gt;
&lt;br /&gt;
'''2. Efficient User Search'''&lt;br /&gt;
*A debounce function was integrated into the search field on the ''Impersonate User'' page to display filtered users in a dropdown that matches the entered query. The purpose of this debounce function is to ensure API calls are only triggered when the user is typing.&lt;br /&gt;
**An autocomplete entry feature was implemented in the dropdown. Now, the user can click on the autocomplete entries, and the search field will autofill with the selected user username.&lt;br /&gt;
**A feature was added to the impersonate button. The impersonate button will stay disabled until a valid username is entered into the search bar.&lt;br /&gt;
**A spinner icon was integrated into this debounce. It will spin when a user is typing in the search field. This indicates that results are being fetched actively. The spinner stops when the user is no longer typing. &lt;br /&gt;
&lt;br /&gt;
'''3. API Integration'''&lt;br /&gt;
*Made API calls to the user impersonation backend. &lt;br /&gt;
**GET a selected user's information. The response will be a ''userList'' object with details about the user, such as their ID, full name, role, etc.&lt;br /&gt;
**POST to retrieve a selected user's JWT token. This is used to facilitate the impersonation.&lt;br /&gt;
&lt;br /&gt;
'''4. Secure Management and Handling of JWT Tokens'''&lt;br /&gt;
*Implemented effective handling of JWT tokens for the original user and the impersonated user. &lt;br /&gt;
**The original user's token is stored using LocalStorage before impersonation, while the impersonated user's token is used only once to switch to the authentication token. This allows for successive impersonations (if the user's role allows). This method of storage allows the user to revert back to their default session once the impersonation session is canceled.&lt;br /&gt;
&lt;br /&gt;
==Impersonation UI Walkthrough==&lt;br /&gt;
&amp;lt;li&amp;gt;First, login to the admin account.&amp;lt;/li&amp;gt;&lt;br /&gt;
It will bring you to this home page.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&lt;br /&gt;
[[File:Screenshot 2024-10-28 111449.png|900px]]&amp;lt;br/&amp;gt;&lt;br /&gt;
''Expertiza homepage''&lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;li&amp;gt;Then, click on &amp;quot;Manage&amp;quot;&amp;lt;/li&amp;gt;&lt;br /&gt;
It will display this dropdown.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&lt;br /&gt;
[[File:Screenshot 2024-10-28 111540.png|900px]]&amp;lt;br/&amp;gt;&lt;br /&gt;
''Dropdown menu''&lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;li&amp;gt;Click on &amp;quot;Impersonate User&amp;quot;&amp;lt;/li&amp;gt;&lt;br /&gt;
It will bring you to this impersonate user page. &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&lt;br /&gt;
[[File:ImpersonateUserPage.jpg|900px]]&amp;lt;br/&amp;gt;&lt;br /&gt;
''Impersonate User Page''&lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Type out the username of the user you wish to impersonate. You will see that a list of matching users will appear in a dropdown. You can select the one you want to impersonate or finish typing out their username. &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&lt;br /&gt;
[[File:ShowDropdown.jpg|900px]]&amp;lt;br/&amp;gt;&lt;br /&gt;
''Shows the dropdown is working and getting users with similar username.''&lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
&amp;lt;center&amp;gt;&lt;br /&gt;
[[File:Spinning circle.jpg|900px]]&amp;lt;br/&amp;gt;&lt;br /&gt;
''Shows the Impersonate user page and the spinning wheel working.''&lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
After you have entered the user you wish to impersonate, the &amp;quot;Impersonate&amp;quot; button will be enabled. &amp;lt;br&amp;gt;&lt;br /&gt;
Click the &amp;quot;Impersonate&amp;quot; button.&lt;br /&gt;
&amp;lt;center&amp;gt;&lt;br /&gt;
[[File:ImpersonateButton.jpg|900px]]&amp;lt;br/&amp;gt;&lt;br /&gt;
''Shows the Impersonate Button is enabled, and we can click to impersonate.''&lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You are now impersonating the selected user. A banner will be present in the header while the impersonation session is live.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&lt;br /&gt;
[[File:Admin.jpg|900px]]&amp;lt;br/&amp;gt;&lt;br /&gt;
''Shows the successful impersonation of Admin with name zachery''&lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Go to the impersonate page again and begin typing the user you want to impersonate into the search bar. &amp;lt;br&amp;gt;&lt;br /&gt;
Note, your current role is admin, so you should be able to impersonate an instructor or any role lower than that.&lt;br /&gt;
&amp;lt;center&amp;gt;&lt;br /&gt;
[[File:ListUser.jpg|900px]]&amp;lt;br/&amp;gt;&lt;br /&gt;
''Shows the dropdown is the correct users''&lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The following steps show you can continue to impersonate the users whose roles are below your current role.&amp;lt;br&amp;gt;&lt;br /&gt;
Note, margarite(Instructor) is a role below zachery(admin)&amp;lt;br&amp;gt;&lt;br /&gt;
The picture below shows zachery trying to impersonate margarite, and the impersonate button is active.&lt;br /&gt;
&amp;lt;center&amp;gt;&lt;br /&gt;
[[File:ImpersonateMarg.jpg|900px]]&amp;lt;br/&amp;gt;&lt;br /&gt;
''Shows super admin can impersonate admin, then can impersonate instructor''&lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The picture below shows impersonating the instructor was successful.&lt;br /&gt;
&amp;lt;center&amp;gt;&lt;br /&gt;
[[File:InstructorImpersonate.jpg|900px]]&amp;lt;br/&amp;gt;&lt;br /&gt;
''Shows Admin can impersonate an Instructor''&lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;li&amp;gt;Whenever you impersonate a role, the banner will display the username of the user you impersonated and their role.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;center&amp;gt;&lt;br /&gt;
[[File:Cancel.jpg|900px]]&amp;lt;br/&amp;gt;&lt;br /&gt;
''Shows the banner change as a user impersonates''&lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;li&amp;gt;When you are done impersonating, you can click the cancel button, and it will send you back to the homepage, and your role will be reset to default.&amp;lt;/li&amp;gt;&lt;br /&gt;
The picture below shows when the super admin is done impersonating the instructor, their role will be reset to their original role, and the homepage will display.&lt;br /&gt;
&amp;lt;center&amp;gt;&lt;br /&gt;
[[File:HomepageAdmin.jpg|900px]]&amp;lt;br/&amp;gt;&lt;br /&gt;
''Shows Super Admin successfully return to homepage''&lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Impersonation UI Testing==&lt;br /&gt;
Since this project is a front-end implementation, we manually tested the functionality by navigating through the UI - [https://drive.google.com/file/d/1Ph_ShpjxVaBVnIon7CqAOr8NWN-0u04V/view?usp=sharing]&amp;lt;br&amp;gt;&lt;br /&gt;
''Note - We were unable to deploy this application since the Impersonation Backend PR [https://github.com/expertiza/reimplementation-back-end/pull/88] has yet to be merged into the Reimplementation Expertiza Backend [https://github.com/expertiza/reimplementation-back-end]''&lt;br /&gt;
&lt;br /&gt;
==Team==&lt;br /&gt;
'''Mentor''' &lt;br /&gt;
&lt;br /&gt;
*Jay Patel &amp;lt;jhpatel9@ncsu.edu&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Students'''&lt;br /&gt;
&lt;br /&gt;
*Pierce Whelan &amp;lt;pwwhelan@ncsu.edu&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*Calvin Jiang &amp;lt;crjiang@ncsu.edu&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*Hechun Zhang &amp;lt;hzhang56@ncsu.edu&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Pull Request==&lt;br /&gt;
[https://github.com/expertiza/reimplementation-front-end/pull/58]&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
Project Instructions [https://docs.google.com/document/d/1fB9nHsop_yptjcj3CFn80BcZjXcSDbzcWwKvBDUTVrQ/edit?usp=sharing] &amp;lt;br&amp;gt;&lt;br /&gt;
Impersonation Backend (New Expertiza) [https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2024_-_E2421._Reimplement_impersonating_users_(within_impersonate_controller.rb)_-_Final_Project] &amp;lt;br&amp;gt;&lt;br /&gt;
Impersonation Backend (Old Expertiza) [https://wiki.expertiza.ncsu.edu/index.php?title=CSE/ECE_517_Spring_2021_-_E2108._Impersonate_controller.rb]&lt;/div&gt;</summary>
		<author><name>Hzhang56</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2024_-_E2466._UI_for_Impersonate_User&amp;diff=158265</id>
		<title>CSC/ECE 517 Fall 2024 - E2466. UI for Impersonate User</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2024_-_E2466._UI_for_Impersonate_User&amp;diff=158265"/>
		<updated>2024-10-30T02:33:26Z</updated>

		<summary type="html">&lt;p&gt;Hzhang56: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Expertiza==&lt;br /&gt;
&lt;br /&gt;
Expertiza is an open-source web application developed using Ruby on Rails. The Expertiza platform is supported by the National Science Foundation, and it is used by instructors and students from selected courses. It enables students and instructors to manage, submit, and evaluate assignments efficiently. This application makes it possible for student collaboration and learning, allowing students to form teams, submit projects, and do peer assessments.&lt;br /&gt;
&lt;br /&gt;
Expertiza [http://expertiza.ncsu.edu/] is a Ruby on Rails [http://rubyonrails.org/] based open source project.&lt;br /&gt;
&lt;br /&gt;
==Problem Statement==&lt;br /&gt;
&lt;br /&gt;
The current Expertiza platform, implemented in Ruby on Rails, requires a re-implementation using TypeScript and ReactJS to modernize the user impersonation feature for administrators. This project focuses on developing an advanced impersonation interface, allowing authenticated users to assume identities of accounts they have authority over, either directly or through a defined creation hierarchy. Core elements include a responsive UI with optimized autocomplete and debounce, secure JWT token management, and APIs to facilitate controlled user access for enhanced system support and administration.&lt;br /&gt;
&lt;br /&gt;
==Terminology Explanation==&lt;br /&gt;
* '''TypeScript -''' Built on JavaScript, TypeScript enhances the language by adding static typing. It helps catch type errors during development, allowing programmers to write more robust and maintainable code.&lt;br /&gt;
* '''ReactJS -''' A JavaScript library for building user interfaces. It allows developers to create reusable UI components and manage states in web applications. &lt;br /&gt;
* '''JWT (JSON Web Token) -''' A compact and secure token used to transmit information between different parts of a system as a JSON object. It is used for authentication.&lt;br /&gt;
&lt;br /&gt;
==Component Details==&lt;br /&gt;
* '''package.json -''' This file was changed to include the lodash library and its debounce function. This addition was done to help TypeScript understand the structure of the debounce function, allowing features such as type checks and autocompletion. &lt;br /&gt;
* '''App.tsx -''' The file was changed to set up a route ''/impersonate'' in the Expertiza Application. When a user accesses this route, it will check if the user has the correct permission. If the user passes the check, then it will render the '''ImpersonateUser''' component. &lt;br /&gt;
* '''masquerade-mask.png -''' Image added to show a user is using the Impersonate feature.&lt;br /&gt;
* '''Header.tsx -''' This file was changed to include an impersonation banner indicating that a user is being impersonated and the impersonation session is active. The banner also has a cancel button that, when pressed, will reset the authentication state to the original user's credentials and clear the impersonation data.&lt;br /&gt;
* '''ImpersonateUser.css -''' A CSS file used by ImpersonateUser.tsx to display a spinning circle while the user is typing in the search field.&lt;br /&gt;
* '''ImpersonateUser.tsx -''' Allows the currently authenticated user to impersonate the identity of another user with roles lower than the current user. This is done by searching for their username and selecting them from a dynamically filtered dropdown list. The search field uses debouncing to decrease the number of API calls to the backend while the user types. Once a user is selected, the component sends an impersonation request with a JWT (JSON Web Token) to securely switch the active user session and displays a customized banner in the header to clearly indicate which user is currently being impersonated. The original user credentials are stored in LocalStorage, and it will be used when the user stops impersonating and wants to return to their default session.&lt;br /&gt;
&lt;br /&gt;
==Files Modified==&lt;br /&gt;
* package.json [https://github.com/augentism/reimplementation-front-end-impersonate-user/blob/main/package.json]&lt;br /&gt;
* App.tsx [https://github.com/augentism/reimplementation-front-end-impersonate-user/blob/main/src/App.tsx]&lt;br /&gt;
* masquerade-mask.png [https://github.com/augentism/reimplementation-front-end-impersonate-user/blob/main/src/assets/masquerade-mask.png]&lt;br /&gt;
* Header.tsx [https://github.com/augentism/reimplementation-front-end-impersonate-user/blob/main/src/layout/Header.tsx]&lt;br /&gt;
* ImpersonateUser.css [https://github.com/augentism/reimplementation-front-end-impersonate-user/blob/main/src/pages/Impersonate/ImpersonateUser.css]&lt;br /&gt;
* ImpersonateUser.tsx [https://github.com/augentism/reimplementation-front-end-impersonate-user/blob/main/src/pages/Impersonate/ImpersonateUser.tsx];&lt;br /&gt;
&lt;br /&gt;
==Design Patterns==&lt;br /&gt;
'''Command Pattern'''&amp;lt;/br&amp;gt;&lt;br /&gt;
The Command Pattern encapsulates a request (or an action) into a separate object. This allows the user to pass the command as a parameter so the user can save it or execute it later. The design pattern separates what needs to be done (in this case, the command) from the requester. &amp;lt;/br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The Command Pattern can be seen within the code, functions such as ''fetchUsers'', ''selectedUser'', and ''impersonateUser'' each encapsulate the logic for a specific action. These actions include fetching a list of users, retrieving a selected user, or initiating an impersonation of a selected user. These functions receive parameters as an input and execute their tasks.&amp;lt;/br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
''handleImpersonate'' function is the invoker, which calls the ''{BASE_URL}/api/v1/impersonate'' POST API. The code below shows this pattern:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  const handleImpersonate = () =&amp;gt; {&lt;br /&gt;
    // Store only the initial User's JWT token and information&lt;br /&gt;
    if (!localStorage.getItem(&amp;quot;originalUserToken&amp;quot;)) {&lt;br /&gt;
      localStorage.setItem(&amp;quot;originalUserToken&amp;quot;, auth.authToken);&lt;br /&gt;
    }&lt;br /&gt;
    const impersonateMessage =&lt;br /&gt;
      &amp;quot;Impersonating a &amp;quot; +&lt;br /&gt;
      fetchSelectedUser?.data.userList[0].role.name +&lt;br /&gt;
      &amp;quot; with name &amp;quot; +&lt;br /&gt;
      fetchSelectedUser?.data.userList[0].name;&lt;br /&gt;
    localStorage.setItem(&amp;quot;impersonateBannerMessage&amp;quot;, impersonateMessage);&lt;br /&gt;
    impersonateUser({&lt;br /&gt;
      method: &amp;quot;post&amp;quot;,&lt;br /&gt;
      url: `/impersonate`,&lt;br /&gt;
      data: {&lt;br /&gt;
        impersonate_id: fetchSelectedUser?.data.userList[0]?.id,&lt;br /&gt;
      },&lt;br /&gt;
    });&lt;br /&gt;
  };&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
'''Facade Pattern'''&amp;lt;/br&amp;gt;&lt;br /&gt;
The Facade Pattern provides a simple interface to a set of classes. It hides the inner workings of a complex system by providing a simple interface, making it easier to work with without knowing the inner details.&amp;lt;/br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
A clear example of a Facade Design pattern within our code is the use of the ''useAPI'' hook. The API handles all the complexity involved in making HTTP requests. The rest of the code can interact with useAPI, focusing only on what data needs to be fetched or updated without needing to know the details of how it is done. The code below shows this pattern:&amp;lt;/br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
const { data: userResponse, sendRequest: fetchUsers } = useAPI();&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
In the code snippet, ''userResponse'' is used to store the data returned by the useAPI hook after an API request, while ''fetchUsers'' is a function provided by useAPI for making the actual API call.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  useEffect(() =&amp;gt; {&lt;br /&gt;
    fetchUsers({&lt;br /&gt;
      method: &amp;quot;get&amp;quot;,&lt;br /&gt;
      url: `/users/${auth.user.id}/managed`,&lt;br /&gt;
    });&lt;br /&gt;
  }, [fetchUsers, auth.user.id]);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The useEffect triggers an API call to fetch a list of users whose roles can be impersonated by the currently authenticated user when the component mounts.&lt;br /&gt;
&lt;br /&gt;
==Tasks Completed==&lt;br /&gt;
'''1. Impersonation User Interface'''&lt;br /&gt;
*A ''ImpersonateUser.tsx'' webpage was created within the Expertiza front-end to allow authorized users, such as administrators and higher roles, to access the impersonation feature.&lt;br /&gt;
*Upon a successful impersonation, the user will be redirected to the homepage and the authentication session will be switched to the impersonated user (using their JWT token). This will prompt a banner to appear at the top of the screen indicating the active impersonation session. This banner includes details about the impersonated user's role and name, and it will also have an option to end the impersonation session.&lt;br /&gt;
&lt;br /&gt;
'''2. Efficient User Search'''&lt;br /&gt;
*A debounce function was integrated into the search field on the ''Impersonate User'' page to display filtered users in a dropdown that match the entered query. The purpose of this debounce function is to ensure API calls are only triggered when the user is typing.&lt;br /&gt;
**A spinner icon was integrated into this debounce. It will spin when a user is typing in the search field. This indicates that results are being fetched actively. The spinner stops when the user is no longer typing. &lt;br /&gt;
&lt;br /&gt;
'''3. API Integration'''&lt;br /&gt;
*Made API calls to the user impersonation backend. &lt;br /&gt;
**GET a selected user's information. The response will be a ''userList'' object with details about the user, such as their ID, full name, role, etc.&lt;br /&gt;
**POST to retrieve a selected user's JWT token. This is used to facilitate the impersonation.&lt;br /&gt;
&lt;br /&gt;
'''4. Secure Management and Handling of JWT Tokens'''&lt;br /&gt;
*Implemented effective handling of JWT tokens for the original user and the impersonated user. &lt;br /&gt;
**The original user's token is stored used LocalStorage before impersonation, while the impersonated user's token is used only once to switch to the authentication token. This allows for successive impersonations (if the user's role allows). This method of storage allows the user to revert back to their default session once the impersonation session is cancelled.&lt;br /&gt;
&lt;br /&gt;
==Impersonation UI Walkthrough==&lt;br /&gt;
&amp;lt;li&amp;gt;First, login to the admin account.&amp;lt;/li&amp;gt;&lt;br /&gt;
It will bring you to this home page.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&lt;br /&gt;
[[File:Screenshot 2024-10-28 111449.png|900px]]&amp;lt;br/&amp;gt;&lt;br /&gt;
''Expertiza homepage''&lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;li&amp;gt;Then, click on &amp;quot;Manage&amp;quot;&amp;lt;/li&amp;gt;&lt;br /&gt;
It will display this dropdown.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&lt;br /&gt;
[[File:Screenshot 2024-10-28 111540.png|900px]]&amp;lt;br/&amp;gt;&lt;br /&gt;
''Dropdown menu''&lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;li&amp;gt;Click on &amp;quot;Impersonate User&amp;quot;&amp;lt;/li&amp;gt;&lt;br /&gt;
It will bring you to this impersonate user page. &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&lt;br /&gt;
[[File:ImpersonateUserPage.jpg|900px]]&amp;lt;br/&amp;gt;&lt;br /&gt;
''Impersonate User Page''&lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Type out the username of the user you wish to impersonate. You will see that a list of matching users will appear in a dropdown. You can select the one you want to impersonate or finish typing out their username. &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&lt;br /&gt;
[[File:ShowDropdown.jpg|900px]]&amp;lt;br/&amp;gt;&lt;br /&gt;
''Shows the dropdown is working and getting users with similar username.''&lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
&amp;lt;center&amp;gt;&lt;br /&gt;
[[File:Spinning circle.jpg|900px]]&amp;lt;br/&amp;gt;&lt;br /&gt;
''Shows the Impersonate user page and the spinning wheel working.''&lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
After you have entered the user you wish to impersonate, the &amp;quot;Impersonate&amp;quot; button will be enabled. &amp;lt;br&amp;gt;&lt;br /&gt;
Click the &amp;quot;Impersonate&amp;quot; button.&lt;br /&gt;
&amp;lt;center&amp;gt;&lt;br /&gt;
[[File:ImpersonateButton.jpg|900px]]&amp;lt;br/&amp;gt;&lt;br /&gt;
''Shows the Impersonate Button is enabled, and we can click to impersonate.''&lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You are now impersonating the selected user. A banner will be present in the header while the impersonation session is live.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&lt;br /&gt;
[[File:Admin.jpg|900px]]&amp;lt;br/&amp;gt;&lt;br /&gt;
''Shows the successful impersonation of Admin with name zachery''&lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Go to the impersonate page again and begin typing the user you want to impersonate into the search bar. &amp;lt;br&amp;gt;&lt;br /&gt;
Note, your current role is admin, so you should be able to impersonate an instructor or any role lower than that.&lt;br /&gt;
&amp;lt;center&amp;gt;&lt;br /&gt;
[[File:ListUser.jpg|900px]]&amp;lt;br/&amp;gt;&lt;br /&gt;
''Shows the dropdown is the correct users''&lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The following steps show you can continue to impersonate the users whose roles are below your current role.&amp;lt;br&amp;gt;&lt;br /&gt;
Note, margarite(Instructor) is a role below zachery(admin)&amp;lt;br&amp;gt;&lt;br /&gt;
The picture below shows zachery trying to impersonate margarite, and the impersonate button is active.&lt;br /&gt;
&amp;lt;center&amp;gt;&lt;br /&gt;
[[File:ImpersonateMarg.jpg|900px]]&amp;lt;br/&amp;gt;&lt;br /&gt;
''Shows super admin can impersonate admin, then can impersonate instructor''&lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The picture below shows impersonating the instructor was successful.&lt;br /&gt;
&amp;lt;center&amp;gt;&lt;br /&gt;
[[File:InstructorImpersonate.jpg|900px]]&amp;lt;br/&amp;gt;&lt;br /&gt;
''Shows Admin can impersonate an Instructor''&lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;li&amp;gt;Whenever you impersonate a role, the banner will display the username of the user you impersonated and their role.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;center&amp;gt;&lt;br /&gt;
[[File:Cancel.jpg|900px]]&amp;lt;br/&amp;gt;&lt;br /&gt;
''Shows the banner change as a user impersonates''&lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;li&amp;gt;When you are done impersonating, you can click the cancel button, and it will send you back to the homepage, and your role will be reset to default.&amp;lt;/li&amp;gt;&lt;br /&gt;
The picture below shows when the super admin is done impersonating the instructor, their role will be reset to their original role, and the homepage will display.&lt;br /&gt;
&amp;lt;center&amp;gt;&lt;br /&gt;
[[File:HomepageAdmin.jpg|900px]]&amp;lt;br/&amp;gt;&lt;br /&gt;
''Shows Super Admin successfully return to homepage''&lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Impersonation UI Testing==&lt;br /&gt;
Since this project is a front-end implementation, we manually tested the functionality by navigating through the UI - [https://drive.google.com/file/d/1Ph_ShpjxVaBVnIon7CqAOr8NWN-0u04V/view?usp=sharing]&amp;lt;br&amp;gt;&lt;br /&gt;
''Note - We were unable to deploy this application since the Impersonation Backend PR [https://github.com/expertiza/reimplementation-back-end/pull/88] has yet to be merged into the Reimplementation Expertiza Backend [https://github.com/expertiza/reimplementation-back-end]''&lt;br /&gt;
&lt;br /&gt;
==Team==&lt;br /&gt;
'''Mentor''' &lt;br /&gt;
&lt;br /&gt;
*Jay Patel &amp;lt;jhpatel9@ncsu.edu&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Students'''&lt;br /&gt;
&lt;br /&gt;
*Pierce Whelan &amp;lt;pwwhelan@ncsu.edu&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*Calvin Jiang &amp;lt;crjiang@ncsu.edu&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*Hechun Zhang &amp;lt;hzhang56@ncsu.edu&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Pull Request==&lt;br /&gt;
[https://github.com/expertiza/reimplementation-front-end/pull/58]&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
Project Instructions [https://docs.google.com/document/d/1fB9nHsop_yptjcj3CFn80BcZjXcSDbzcWwKvBDUTVrQ/edit?usp=sharing] &amp;lt;br&amp;gt;&lt;br /&gt;
Impersonation Backend (New Expertiza) [https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2024_-_E2421._Reimplement_impersonating_users_(within_impersonate_controller.rb)_-_Final_Project] &amp;lt;br&amp;gt;&lt;br /&gt;
Impersonation Backend (Old Expertiza) [https://wiki.expertiza.ncsu.edu/index.php?title=CSE/ECE_517_Spring_2021_-_E2108._Impersonate_controller.rb]&lt;/div&gt;</summary>
		<author><name>Hzhang56</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=File:ImpersonateMarg.jpg&amp;diff=158233</id>
		<title>File:ImpersonateMarg.jpg</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=File:ImpersonateMarg.jpg&amp;diff=158233"/>
		<updated>2024-10-30T02:27:36Z</updated>

		<summary type="html">&lt;p&gt;Hzhang56: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Hzhang56</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=File:ShowDropdown.jpg&amp;diff=158151</id>
		<title>File:ShowDropdown.jpg</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=File:ShowDropdown.jpg&amp;diff=158151"/>
		<updated>2024-10-30T02:03:37Z</updated>

		<summary type="html">&lt;p&gt;Hzhang56: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Hzhang56</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=File:ImpersonateButton.jpg&amp;diff=158149</id>
		<title>File:ImpersonateButton.jpg</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=File:ImpersonateButton.jpg&amp;diff=158149"/>
		<updated>2024-10-30T02:03:31Z</updated>

		<summary type="html">&lt;p&gt;Hzhang56: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Hzhang56</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=File:ImpersonateUserPage.jpg&amp;diff=158146</id>
		<title>File:ImpersonateUserPage.jpg</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=File:ImpersonateUserPage.jpg&amp;diff=158146"/>
		<updated>2024-10-30T02:03:17Z</updated>

		<summary type="html">&lt;p&gt;Hzhang56: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Hzhang56</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2024_-_E2466._UI_for_Impersonate_User&amp;diff=157979</id>
		<title>CSC/ECE 517 Fall 2024 - E2466. UI for Impersonate User</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2024_-_E2466._UI_for_Impersonate_User&amp;diff=157979"/>
		<updated>2024-10-30T00:52:38Z</updated>

		<summary type="html">&lt;p&gt;Hzhang56: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Expertiza==&lt;br /&gt;
&lt;br /&gt;
Expertiza is an open-source web application developed using Ruby on Rails. The Expertiza platform is supported by the National Science Foundation, and it is used by instructors and students from selected courses. It enables students and instructors to manage, submit, and evaluate assignments efficiently. This application makes it possible for student collaboration and learning, allowing students to form teams, submit projects, and do peer assessments.&lt;br /&gt;
&lt;br /&gt;
Expertiza [http://expertiza.ncsu.edu/] is a Ruby on Rails [http://rubyonrails.org/] based open source project.&lt;br /&gt;
&lt;br /&gt;
==Problem Statement==&lt;br /&gt;
&lt;br /&gt;
Currently, the Expertiza platform needs an updated user impersonation feature for administrators. This project aims to re-implement the platform using TypeScript and ReactJS, focusing on creating a sophisticated user interface for impersonation. Key features will include optimized autocomplete search with debounce, APIs for fetching user lists, and secure JWT token management for handling impersonation.&lt;br /&gt;
&lt;br /&gt;
==Terminology Explanation==&lt;br /&gt;
* '''TypeScript -''' Built on JavaScript, TypeScript enhances the language by adding static typing. It helps catch type errors during development, allowing programmers to write more robust and maintainable code.&lt;br /&gt;
* '''ReactJS -''' a JavaScript library for building user interfaces. It allows developers to create reusable UI components and manage states in web applications. &lt;br /&gt;
* '''JWT(JSON Web Token) -''' a compact and secure token used to transmit information between different parts of a system as JSON object, used for authentication.&lt;br /&gt;
&lt;br /&gt;
==Component Details==&lt;br /&gt;
* '''package.json -''' this file was changed to include the lodash library and its debounce function. This addition was done to help TypeScript understand the structure of the debounce function, allowing features such as type checks and autocompletion. &lt;br /&gt;
* '''App.tsx -''' the file was changed to set up a route ''/impersonate'' in the Expertiza Application. When a user accesses this rote, it will check if the user has the correct permission. If the user passes the check, then it will render the '''ImpersonateUser''' component. &lt;br /&gt;
* '''masquerade-mask.png -''' image added to show a user is using the Impersonate feature.&lt;br /&gt;
* '''Header.tsx -''' this file was changed to include an impersonation banner indicating that a user is being impersonated and the impersonation session is active. The banner also has a cancel button that, when pressed, will reset the authentication state to the original user's credentials and clear the impersonation data.&lt;br /&gt;
* '''ImpersonateUser.css -''' a CSS file used by ImpersonateUser.tsx to display a spinning circle while the user is typing in the search field.&lt;br /&gt;
* '''ImpersonateUser.tsx -''' allows the currently authenticated user to impersonate the identity of another user with roles lower than the current user. This is done by searching for their username and selecting them from a dynamically filtered dropdown list. The search textbox uses debouncing to decrease the number of API calls to the backend while the user types. Once a user is selected, the component sends an impersonation request with a JWT (JSON Web Token) to securely switch the active user session and displays a customized banner in the header to clearly indicate which user is currently being impersonated. The original user credentials are stored, and it will be used when the user stops impersonating and wants to return to their default session.&lt;br /&gt;
&lt;br /&gt;
==Files Modified==&lt;br /&gt;
* package.json [https://github.com/augentism/reimplementation-front-end-impersonate-user/blob/main/package.json]&lt;br /&gt;
* App.tsx [https://github.com/augentism/reimplementation-front-end-impersonate-user/blob/main/src/App.tsx]&lt;br /&gt;
* masquerade-mask.png [https://github.com/augentism/reimplementation-front-end-impersonate-user/blob/main/src/assets/masquerade-mask.png]&lt;br /&gt;
* Header.tsx [https://github.com/augentism/reimplementation-front-end-impersonate-user/blob/main/src/layout/Header.tsx]&lt;br /&gt;
* ImpersonateUser.css [https://github.com/augentism/reimplementation-front-end-impersonate-user/blob/main/src/pages/Impersonate/ImpersonateUser.css]&lt;br /&gt;
* ImpersonateUser.tsx [https://github.com/augentism/reimplementation-front-end-impersonate-user/blob/main/src/pages/Impersonate/ImpersonateUser.tsx];&lt;br /&gt;
&lt;br /&gt;
==Design Pattern==&lt;br /&gt;
'''Command Pattern'''&amp;lt;/br&amp;gt;&lt;br /&gt;
The Command Pattern encapsulates a request(or an action) into a separate object. This allows the user to pass the command as a parameter so the user can save it or execute it later. The design pattern separates what needs to be done (in this case, the command) from the requester. &amp;lt;/br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The Command Pattern can be seen within the code, functions such as ''fetchUsers'', ''selectedUser'', and ''impersonateUser'' each function encapsulates the logic for a specific action. These actions include fetching user data, retrieving a selected user, or initiating impersonation. These functions receive parameters as input and execute their tasks.&amp;lt;/br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
''handleImpersonate'' function is the invoker, which calls these commands.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  const handleImpersonate = () =&amp;gt; {&lt;br /&gt;
    // Store only the initial User's JWT token and information&lt;br /&gt;
    if (!localStorage.getItem(&amp;quot;originalUserToken&amp;quot;)) {&lt;br /&gt;
      localStorage.setItem(&amp;quot;originalUserToken&amp;quot;, auth.authToken);&lt;br /&gt;
    }&lt;br /&gt;
    const impersonateMessage =&lt;br /&gt;
      &amp;quot;Impersonating a &amp;quot; +&lt;br /&gt;
      fetchSelectedUser?.data.userList[0].role.name +&lt;br /&gt;
      &amp;quot; with name &amp;quot; +&lt;br /&gt;
      fetchSelectedUser?.data.userList[0].name;&lt;br /&gt;
    localStorage.setItem(&amp;quot;impersonateBannerMessage&amp;quot;, impersonateMessage);&lt;br /&gt;
    impersonateUser({&lt;br /&gt;
      method: &amp;quot;post&amp;quot;,&lt;br /&gt;
      url: `/impersonate`,&lt;br /&gt;
      data: {&lt;br /&gt;
        impersonate_id: fetchSelectedUser?.data.userList[0]?.id,&lt;br /&gt;
      },&lt;br /&gt;
    });&lt;br /&gt;
  };&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
'''Facade Pattern'''&amp;lt;/br&amp;gt;&lt;br /&gt;
The Facade Pattern provides a simple interface to a set of classes. It hides the inner workings of a complex system by providing a simple interface, making it easier to work with without knowing the inner details.&amp;lt;/br&amp;gt;&lt;br /&gt;
A clear example of a Facade Design pattern within our code is the use of the ''useAPI'' hook. The API handles all the complexity involved in making HTTP requests. The rest of the code can interact with useAPI, focusing only on what data needs to be fetched or updated without needing to understand the details of how it is done. The code below shows this pattern.&amp;lt;/br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
const { data: userResponse, sendRequest: fetchUsers } = useAPI();&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The code above makes a variable called userResponse to store the API response managed by the useAPI hook. It also creates a function called fetchUsers that triggers an API request when called.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  useEffect(() =&amp;gt; {&lt;br /&gt;
    fetchUsers({&lt;br /&gt;
      method: &amp;quot;get&amp;quot;,&lt;br /&gt;
      url: `/users/${auth.user.id}/managed`,&lt;br /&gt;
    });&lt;br /&gt;
  }, [fetchUsers, auth.user.id]);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The useEffect triggers an API call to fetch a list of users whose roles can be impersonated by the currently authenticated user when the component mounts.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
const { data: fetchSelectedUser, sendRequest: selectedUser } = useAPI();&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The code above makes a variable called fetchSelectedUserto store the API response managed by the useAPI hook. It also creates a function called selectedUser that triggers an API request when called.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  // Fetch selected user based on the Search Query&lt;br /&gt;
  useEffect(() =&amp;gt; {&lt;br /&gt;
    const userArray = Array.isArray(userResponse?.data) ? userResponse?.data : [userResponse?.data];&lt;br /&gt;
&lt;br /&gt;
    const validUser = userArray?.find(&lt;br /&gt;
      (user: any) =&amp;gt; searchQuery.toLowerCase() === (user?.name?.toLowerCase() || &amp;quot;&amp;quot;)&lt;br /&gt;
    );&lt;br /&gt;
&lt;br /&gt;
    // Don't initiate a GET if the searchQuery is empty&lt;br /&gt;
    if (searchQuery.trim() &amp;amp;&amp;amp; validUser) {&lt;br /&gt;
      setSelectedValidUser(true);&lt;br /&gt;
      selectedUser({&lt;br /&gt;
        method: &amp;quot;get&amp;quot;,&lt;br /&gt;
        url: `/impersonate/${encodeURIComponent(validUser.full_name)}`,&lt;br /&gt;
      });&lt;br /&gt;
    } else {&lt;br /&gt;
      setSelectedValidUser(false);&lt;br /&gt;
    }&lt;br /&gt;
  }, [selectedUser, searchQuery, userResponse]);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The code above checks if the search matches a valid user from the fetched user list. If a match is found, it will trigger an API call to fetch additional details about that selected user; otherwise, it sets the selection state to invalid.&lt;br /&gt;
&lt;br /&gt;
==Tasks Completed==&lt;br /&gt;
'''1. Impersonation User interface'''&lt;br /&gt;
*A specific webpage was created within the Expertiza to allow only authorized users, such as administrators and higher roles, to access the impersonation feature.&lt;br /&gt;
*The impersonation feature will not be available for unauthorized users.&lt;br /&gt;
*Upon successful impersonation, the component will update the authentication state with the new user's credentials then it will display a banner at the top of the screen indicating the active impersonation session. This banner will include details about the impersonated user's role and name, and it will also have the option to end the session.&lt;br /&gt;
&lt;br /&gt;
'''2. Efficient user search'''&lt;br /&gt;
*A debounce function was integrated with the search field to display filtered users in the dropdown when typing. The purpose of this debounce function is to ensure API calls are only triggered when the user is typing. The debounce logic was set with a delay of 300ms, reducing unnecessary API calls.&lt;br /&gt;
*A spinner indicated was added beside the impersonate button to show the user the results are being fetched. The spinner stops when the user is no longer typing. &lt;br /&gt;
'''3. API Integration'''&lt;br /&gt;
*Make API calls to the user impersonation backend to retrieve a list of users that the current user can manage and impersonate. This API fetches the relevant user list based on the current authenticated user's role.&lt;br /&gt;
*Retrieve impersonated user information, which includes detailed information, such as their ID, full name, role, permissions, and other details for impersonation.&lt;br /&gt;
&lt;br /&gt;
'''4. Managing and storing JWT tokens'''&lt;br /&gt;
*Implemented effective handling of JWT tokens for the original user and the impersonated user. The original token is stored, and a new token is generated for the impersonated session. This way, when the user wants to cancel their impersonation session, they will be sent back to their default session.&lt;br /&gt;
&lt;br /&gt;
'''5. Testing and seeding'''&lt;br /&gt;
*Seeded database with a randomly generated set of users.&lt;br /&gt;
*Testing was done manually, as shown in the Result Section below&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
  &amp;lt;li&amp;gt;Tested impersonation from a super admin account with a randomly generated dataset of users.&amp;lt;/li&amp;gt;&lt;br /&gt;
  &amp;lt;li&amp;gt;Tested impersonation from administrators, instructors, and TA accounts.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Results (Step-by-Step Screenshots)==&lt;br /&gt;
&amp;lt;li&amp;gt;First, login to the admin account.&amp;lt;/li&amp;gt;&lt;br /&gt;
It will bring you to this home page.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&lt;br /&gt;
[[File:Screenshot 2024-10-28 111449.png|900px]]&amp;lt;br/&amp;gt;&lt;br /&gt;
''Expertiza home page.''&lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;li&amp;gt;Then, click on &amp;quot;Manage&amp;quot;&amp;lt;/li&amp;gt;&lt;br /&gt;
It will display this drop-down.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&lt;br /&gt;
[[File:Screenshot 2024-10-28 111540.png|900px]]&amp;lt;br/&amp;gt;&lt;br /&gt;
''Drop-down menu''&lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;li&amp;gt;Click on &amp;quot;Impersonate User&amp;quot;&amp;lt;/li&amp;gt;&lt;br /&gt;
Then, it will bring you to this impersonate user page.&lt;br /&gt;
Either select or type out the user you intend to impersonate. After clicking &amp;quot;Impersonate&amp;quot; you should see something similar to the following screen:&lt;br /&gt;
&amp;lt;center&amp;gt;&lt;br /&gt;
[[File:Spinning circle.jpg|900px]]&amp;lt;br/&amp;gt;&lt;br /&gt;
''Shows the Impersonate user page and the spinning wheel working.''&lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You should have successfully impersonated a user, and the banner pictured above should be visible at all times, as shown in the picture below.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&lt;br /&gt;
[[File:Admin.jpg|900px]]&amp;lt;br/&amp;gt;&lt;br /&gt;
''Shows the successful impersonation of Admin with banner active''&lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;li&amp;gt;Go to the impersonate page again and begin typing the user you want to impersonate into the search bar.&amp;lt;/li&amp;gt;&lt;br /&gt;
Suggestions should appear in the dropdown pictured above when you stop typing. Currently, the debounce time is 300ms.&lt;br /&gt;
&amp;lt;center&amp;gt;&lt;br /&gt;
[[File:ListUser.jpg|900px]]&amp;lt;br/&amp;gt;&lt;br /&gt;
''Shows the dropdown is working''&lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;li&amp;gt;Your current role is admin, so you should be able to impersonate an instructor, as shown in the picture below.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;center&amp;gt;&lt;br /&gt;
[[File:InstructorImpersonate.jpg|900px]]&amp;lt;br/&amp;gt;&lt;br /&gt;
''Shows Admin can impersonate an Instructor''&lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;li&amp;gt;Whenever you impersonate a role, the banner will display the username of the user you impersonated and their role.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;center&amp;gt;&lt;br /&gt;
[[File:Cancel.jpg|900px]]&amp;lt;br/&amp;gt;&lt;br /&gt;
''Shows the banner change as a user impersonates''&lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;li&amp;gt;When you are done impersonating, you can click the cancel button, and it will send you back to the homepage, and your role will be reset to default.&amp;lt;/li&amp;gt;&lt;br /&gt;
The picture below shows when the super admin is done impersonating the instructor, their role will be reset to their original role, and the homepage will display.&lt;br /&gt;
&amp;lt;center&amp;gt;&lt;br /&gt;
[[File:HomepageAdmin.jpg|900px]]&amp;lt;br/&amp;gt;&lt;br /&gt;
''Shows Super Admin successfully return to homepage''&lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Video Showcasing Impersonation Features==&lt;br /&gt;
*Link: [https://drive.google.com/file/d/1Ph_ShpjxVaBVnIon7CqAOr8NWN-0u04V/view?usp=sharing]&lt;br /&gt;
&lt;br /&gt;
==Team==&lt;br /&gt;
'''Mentor''' &lt;br /&gt;
&lt;br /&gt;
*Jay Patel &amp;lt;jhpatel9@ncsu.edu&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Students'''&lt;br /&gt;
&lt;br /&gt;
*Pierce Whelan &amp;lt;pwwhelan@ncsu.edu&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*Calvin Jiang &amp;lt;crjiang@ncsu.edu&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*Hechun Zhang &amp;lt;hzhang56@ncsu.edu&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Pull Request==&lt;br /&gt;
Link: [https://github.com/expertiza/reimplementation-front-end/pull/58] &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
Project Instructions [https://docs.google.com/document/d/1fB9nHsop_yptjcj3CFn80BcZjXcSDbzcWwKvBDUTVrQ/edit?usp=sharing] &amp;lt;br&amp;gt;&lt;br /&gt;
Previous Backend Project (New Expertiza) - Impersonating New Backend [https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2024_-_E2421._Reimplement_impersonating_users_(within_impersonate_controller.rb)_-_Final_Project] &amp;lt;br&amp;gt;&lt;br /&gt;
Previous Backend Project (Old Expertiza) - Impersonating Expertiza [https://wiki.expertiza.ncsu.edu/index.php?title=CSE/ECE_517_Spring_2021_-_E2108._Impersonate_controller.rb]&lt;/div&gt;</summary>
		<author><name>Hzhang56</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2024_-_E2466._UI_for_Impersonate_User&amp;diff=157977</id>
		<title>CSC/ECE 517 Fall 2024 - E2466. UI for Impersonate User</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2024_-_E2466._UI_for_Impersonate_User&amp;diff=157977"/>
		<updated>2024-10-30T00:51:19Z</updated>

		<summary type="html">&lt;p&gt;Hzhang56: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Expertiza==&lt;br /&gt;
&lt;br /&gt;
Expertiza is an open-source web application developed using Ruby on Rails. The Expertiza platform is supported by the National Science Foundation, and it is used by instructors and students from selected courses. It enables students and instructors to manage, submit, and evaluate assignments efficiently. This application makes it possible for student collaboration and learning, allowing students to form teams, submit projects, and do peer assessments.&lt;br /&gt;
&lt;br /&gt;
Expertiza [http://expertiza.ncsu.edu/] is a Ruby on Rails [http://rubyonrails.org/] based open source project.&lt;br /&gt;
&lt;br /&gt;
==Problem Statement==&lt;br /&gt;
&lt;br /&gt;
Currently, the Expertiza platform needs an updated user impersonation feature for administrators. This project aims to re-implement the platform using TypeScript and ReactJS, focusing on creating a sophisticated user interface for impersonation. Key features will include optimized autocomplete search with debounce, APIs for fetching user lists, and secure JWT token management for handling impersonation.&lt;br /&gt;
&lt;br /&gt;
==Terminology Explanation==&lt;br /&gt;
* '''TypeScript -''' Built on JavaScript, TypeScript enhances the language by adding static typing. It helps catch type errors during development, allowing programmers to write more robust and maintainable code.&lt;br /&gt;
* '''ReactJS -''' a JavaScript library for building user interfaces. It allows developers to create reusable UI components and manage states in web applications. &lt;br /&gt;
* '''JWT(JSON Web Token) -''' a compact and secure token used to transmit information between different parts of a system as JSON object, used for authentication.&lt;br /&gt;
&lt;br /&gt;
==Component Details==&lt;br /&gt;
* '''package.json -''' this file was changed to include the lodash library and its debounce function. This addition was done to help TypeScript understand the structure of the debounce function, allowing features such as type checks and autocompletion. &lt;br /&gt;
* '''App.tsx -''' the file was changed to set up a route ''/impersonate'' in the Expertiza Application. When a user accesses this rote, it will check if the user has the correct permission. If the user passes the check, then it will render the '''ImpersonateUser''' component. &lt;br /&gt;
* '''masquerade-mask.png -''' image added to show a user is using the Impersonate feature.&lt;br /&gt;
* '''Header.tsx -''' this file was changed to include an impersonation banner indicating that a user is being impersonated and the impersonation session is active. The banner also has a cancel button that, when pressed, will reset the authentication state to the original user's credentials and clear the impersonation data.&lt;br /&gt;
* '''ImpersonateUser.css -''' a CSS file used by ImpersonateUser.tsx to display a spinning circle while the user is typing in the search field.&lt;br /&gt;
* '''ImpersonateUser.tsx -''' allows the currently authenticated user to impersonate the identity of another user with roles lower than the current user. This is done by searching for their username and selecting them from a dynamically filtered dropdown list. The search textbox uses debouncing to decrease the number of API calls to the backend while the user types. Once a user is selected, the component sends an impersonation request with a JWT (JSON Web Token) to securely switch the active user session and displays a customized banner in the header to clearly indicate which user is currently being impersonated. The original user credentials are stored, and it will be used when the user stops impersonating and wants to return to their default session.&lt;br /&gt;
&lt;br /&gt;
==Files Modified==&lt;br /&gt;
* package.json [https://github.com/augentism/reimplementation-front-end-impersonate-user/blob/main/package.json]&lt;br /&gt;
* App.tsx [https://github.com/augentism/reimplementation-front-end-impersonate-user/blob/main/src/App.tsx]&lt;br /&gt;
* masquerade-mask.png [https://github.com/augentism/reimplementation-front-end-impersonate-user/blob/main/src/assets/masquerade-mask.png]&lt;br /&gt;
* Header.tsx [https://github.com/augentism/reimplementation-front-end-impersonate-user/blob/main/src/layout/Header.tsx]&lt;br /&gt;
* ImpersonateUser.css [https://github.com/augentism/reimplementation-front-end-impersonate-user/blob/main/src/pages/Impersonate/ImpersonateUser.css]&lt;br /&gt;
* ImpersonateUser.tsx [https://github.com/augentism/reimplementation-front-end-impersonate-user/blob/main/src/pages/Impersonate/ImpersonateUser.tsx];&lt;br /&gt;
&lt;br /&gt;
==Design Pattern==&lt;br /&gt;
'''Command Pattern'''&amp;lt;/br&amp;gt;&lt;br /&gt;
The Command Pattern encapsulates a request(or an action) into a separate object. This allows the user to pass the command as a parameter so the user can save it or execute it later. The design pattern separates what needs to be done (in this case, the command) from the requester. &amp;lt;/br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The Command Pattern can be seen within the code, functions such as '''fetchUsers''', '''selectedUser''', and '''impersonateUser''' each function encapsulates the logic for a specific action. These actions include fetching user data, retrieving a selected user, or initiating impersonation. These functions receive parameters as input and execute their tasks.&amp;lt;/br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''handleImpersonate''' function is the invoker, which calls these commands.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  const handleImpersonate = () =&amp;gt; {&lt;br /&gt;
    // Store only the initial User's JWT token and information&lt;br /&gt;
    if (!localStorage.getItem(&amp;quot;originalUserToken&amp;quot;)) {&lt;br /&gt;
      localStorage.setItem(&amp;quot;originalUserToken&amp;quot;, auth.authToken);&lt;br /&gt;
    }&lt;br /&gt;
    const impersonateMessage =&lt;br /&gt;
      &amp;quot;Impersonating a &amp;quot; +&lt;br /&gt;
      fetchSelectedUser?.data.userList[0].role.name +&lt;br /&gt;
      &amp;quot; with name &amp;quot; +&lt;br /&gt;
      fetchSelectedUser?.data.userList[0].name;&lt;br /&gt;
    localStorage.setItem(&amp;quot;impersonateBannerMessage&amp;quot;, impersonateMessage);&lt;br /&gt;
    impersonateUser({&lt;br /&gt;
      method: &amp;quot;post&amp;quot;,&lt;br /&gt;
      url: `/impersonate`,&lt;br /&gt;
      data: {&lt;br /&gt;
        impersonate_id: fetchSelectedUser?.data.userList[0]?.id,&lt;br /&gt;
      },&lt;br /&gt;
    });&lt;br /&gt;
  };&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
'''Facade Pattern'''&amp;lt;/br&amp;gt;&lt;br /&gt;
The Facade Pattern provides a simple interface to a set of classes. It hides the inner workings of a complex system by providing a simple interface, making it easier to work with without knowing the inner details.&amp;lt;/br&amp;gt;&lt;br /&gt;
A clear example of a Facade Design pattern within our code is the use of the ''useAPI'' hook. The API handles all the complexity involved in making HTTP requests. The rest of the code can interact with useAPI, focusing only on what data needs to be fetched or updated without needing to understand the details of how it is done. The code below shows this pattern.&amp;lt;/br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
const { data: userResponse, sendRequest: fetchUsers } = useAPI();&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The code above makes a variable called userResponse to store the API response managed by the useAPI hook. It also creates a function called fetchUsers that triggers an API request when called.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  useEffect(() =&amp;gt; {&lt;br /&gt;
    fetchUsers({&lt;br /&gt;
      method: &amp;quot;get&amp;quot;,&lt;br /&gt;
      url: `/users/${auth.user.id}/managed`,&lt;br /&gt;
    });&lt;br /&gt;
  }, [fetchUsers, auth.user.id]);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The useEffect triggers an API call to fetch a list of users whose roles can be impersonated by the currently authenticated user when the component mounts.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
const { data: fetchSelectedUser, sendRequest: selectedUser } = useAPI();&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The code above makes a variable called fetchSelectedUserto store the API response managed by the useAPI hook. It also creates a function called selectedUser that triggers an API request when called.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  // Fetch selected user based on the Search Query&lt;br /&gt;
  useEffect(() =&amp;gt; {&lt;br /&gt;
    const userArray = Array.isArray(userResponse?.data) ? userResponse?.data : [userResponse?.data];&lt;br /&gt;
&lt;br /&gt;
    const validUser = userArray?.find(&lt;br /&gt;
      (user: any) =&amp;gt; searchQuery.toLowerCase() === (user?.name?.toLowerCase() || &amp;quot;&amp;quot;)&lt;br /&gt;
    );&lt;br /&gt;
&lt;br /&gt;
    // Don't initiate a GET if the searchQuery is empty&lt;br /&gt;
    if (searchQuery.trim() &amp;amp;&amp;amp; validUser) {&lt;br /&gt;
      setSelectedValidUser(true);&lt;br /&gt;
      selectedUser({&lt;br /&gt;
        method: &amp;quot;get&amp;quot;,&lt;br /&gt;
        url: `/impersonate/${encodeURIComponent(validUser.full_name)}`,&lt;br /&gt;
      });&lt;br /&gt;
    } else {&lt;br /&gt;
      setSelectedValidUser(false);&lt;br /&gt;
    }&lt;br /&gt;
  }, [selectedUser, searchQuery, userResponse]);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The code above checks if the search matches a valid user from the fetched user list. If a match is found, it will trigger an API call to fetch additional details about that selected user; otherwise, it sets the selection state to invalid.&lt;br /&gt;
&lt;br /&gt;
==Tasks Completed==&lt;br /&gt;
'''1. Impersonation User interface'''&lt;br /&gt;
*A specific webpage was created within the Expertiza to allow only authorized users, such as administrators and higher roles, to access the impersonation feature.&lt;br /&gt;
*The impersonation feature will not be available for unauthorized users.&lt;br /&gt;
*Upon successful impersonation, the component will update the authentication state with the new user's credentials then it will display a banner at the top of the screen indicating the active impersonation session. This banner will include details about the impersonated user's role and name, and it will also have the option to end the session.&lt;br /&gt;
&lt;br /&gt;
'''2. Efficient user search'''&lt;br /&gt;
*A debounce function was integrated with the search field to display filtered users in the dropdown when typing. The purpose of this debounce function is to ensure API calls are only triggered when the user is typing. The debounce logic was set with a delay of 300ms, reducing unnecessary API calls.&lt;br /&gt;
*A spinner indicated was added beside the impersonate button to show the user the results are being fetched. The spinner stops when the user is no longer typing. &lt;br /&gt;
'''3. API Integration'''&lt;br /&gt;
*Make API calls to the user impersonation backend to retrieve a list of users that the current user can manage and impersonate. This API fetches the relevant user list based on the current authenticated user's role.&lt;br /&gt;
*Retrieve impersonated user information, which includes detailed information, such as their ID, full name, role, permissions, and other details for impersonation.&lt;br /&gt;
&lt;br /&gt;
'''4. Managing and storing JWT tokens'''&lt;br /&gt;
*Implemented effective handling of JWT tokens for the original user and the impersonated user. The original token is stored, and a new token is generated for the impersonated session. This way, when the user wants to cancel their impersonation session, they will be sent back to their default session.&lt;br /&gt;
&lt;br /&gt;
'''5. Testing and seeding'''&lt;br /&gt;
*Seeded database with a randomly generated set of users.&lt;br /&gt;
*Testing was done manually, as shown in the Result Section below&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
  &amp;lt;li&amp;gt;Tested impersonation from a super admin account with a randomly generated dataset of users.&amp;lt;/li&amp;gt;&lt;br /&gt;
  &amp;lt;li&amp;gt;Tested impersonation from administrators, instructors, and TA accounts.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Results (Step-by-Step Screenshots)==&lt;br /&gt;
&amp;lt;li&amp;gt;First, login to the admin account.&amp;lt;/li&amp;gt;&lt;br /&gt;
It will bring you to this home page.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&lt;br /&gt;
[[File:Screenshot 2024-10-28 111449.png|900px]]&amp;lt;br/&amp;gt;&lt;br /&gt;
''Expertiza home page.''&lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;li&amp;gt;Then, click on &amp;quot;Manage&amp;quot;&amp;lt;/li&amp;gt;&lt;br /&gt;
It will display this drop-down.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&lt;br /&gt;
[[File:Screenshot 2024-10-28 111540.png|900px]]&amp;lt;br/&amp;gt;&lt;br /&gt;
''Drop-down menu''&lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;li&amp;gt;Click on &amp;quot;Impersonate User&amp;quot;&amp;lt;/li&amp;gt;&lt;br /&gt;
Then, it will bring you to this impersonate user page.&lt;br /&gt;
Either select or type out the user you intend to impersonate. After clicking &amp;quot;Impersonate&amp;quot; you should see something similar to the following screen:&lt;br /&gt;
&amp;lt;center&amp;gt;&lt;br /&gt;
[[File:Spinning circle.jpg|900px]]&amp;lt;br/&amp;gt;&lt;br /&gt;
''Shows the Impersonate user page and the spinning wheel working.''&lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You should have successfully impersonated a user, and the banner pictured above should be visible at all times, as shown in the picture below.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&lt;br /&gt;
[[File:Admin.jpg|900px]]&amp;lt;br/&amp;gt;&lt;br /&gt;
''Shows the successful impersonation of Admin with banner active''&lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;li&amp;gt;Go to the impersonate page again and begin typing the user you want to impersonate into the search bar.&amp;lt;/li&amp;gt;&lt;br /&gt;
Suggestions should appear in the dropdown pictured above when you stop typing. Currently, the debounce time is 300ms.&lt;br /&gt;
&amp;lt;center&amp;gt;&lt;br /&gt;
[[File:ListUser.jpg|900px]]&amp;lt;br/&amp;gt;&lt;br /&gt;
''Shows the dropdown is working''&lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;li&amp;gt;Your current role is admin, so you should be able to impersonate an instructor, as shown in the picture below.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;center&amp;gt;&lt;br /&gt;
[[File:InstructorImpersonate.jpg|900px]]&amp;lt;br/&amp;gt;&lt;br /&gt;
''Shows Admin can impersonate an Instructor''&lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;li&amp;gt;Whenever you impersonate a role, the banner will display the username of the user you impersonated and their role.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;center&amp;gt;&lt;br /&gt;
[[File:Cancel.jpg|900px]]&amp;lt;br/&amp;gt;&lt;br /&gt;
''Shows the banner change as a user impersonates''&lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;li&amp;gt;When you are done impersonating, you can click the cancel button, and it will send you back to the homepage, and your role will be reset to default.&amp;lt;/li&amp;gt;&lt;br /&gt;
The picture below shows when the super admin is done impersonating the instructor, their role will be reset to their original role, and the homepage will display.&lt;br /&gt;
&amp;lt;center&amp;gt;&lt;br /&gt;
[[File:HomepageAdmin.jpg|900px]]&amp;lt;br/&amp;gt;&lt;br /&gt;
''Shows Super Admin successfully return to homepage''&lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Video Showcasing Impersonation Features==&lt;br /&gt;
*Link: [https://drive.google.com/file/d/1Ph_ShpjxVaBVnIon7CqAOr8NWN-0u04V/view?usp=sharing]&lt;br /&gt;
&lt;br /&gt;
==Team==&lt;br /&gt;
'''Mentor''' &lt;br /&gt;
&lt;br /&gt;
*Jay Patel &amp;lt;jhpatel9@ncsu.edu&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Students'''&lt;br /&gt;
&lt;br /&gt;
*Pierce Whelan &amp;lt;pwwhelan@ncsu.edu&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*Calvin Jiang &amp;lt;crjiang@ncsu.edu&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*Hechun Zhang &amp;lt;hzhang56@ncsu.edu&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Pull Request==&lt;br /&gt;
Link: [https://github.com/expertiza/reimplementation-front-end/pull/58] &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
Project Instructions [https://docs.google.com/document/d/1fB9nHsop_yptjcj3CFn80BcZjXcSDbzcWwKvBDUTVrQ/edit?usp=sharing] &amp;lt;br&amp;gt;&lt;br /&gt;
Previous Backend Project (New Expertiza) - Impersonating New Backend [https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2024_-_E2421._Reimplement_impersonating_users_(within_impersonate_controller.rb)_-_Final_Project] &amp;lt;br&amp;gt;&lt;br /&gt;
Previous Backend Project (Old Expertiza) - Impersonating Expertiza [https://wiki.expertiza.ncsu.edu/index.php?title=CSE/ECE_517_Spring_2021_-_E2108._Impersonate_controller.rb]&lt;/div&gt;</summary>
		<author><name>Hzhang56</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2024_-_E2466._UI_for_Impersonate_User&amp;diff=157555</id>
		<title>CSC/ECE 517 Fall 2024 - E2466. UI for Impersonate User</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2024_-_E2466._UI_for_Impersonate_User&amp;diff=157555"/>
		<updated>2024-10-29T19:21:00Z</updated>

		<summary type="html">&lt;p&gt;Hzhang56: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Expertiza==&lt;br /&gt;
&lt;br /&gt;
Expertiza is an open-source web application developed using Ruby on Rails. The Expertiza platform is supported by the National Science Foundation, and it is used by instructors and students from selected courses. It enables students and instructors to manage, submit, and evaluate assignments efficiently. This application makes it possible for student collaboration and learning, allowing students to form teams, submit projects, and do peer assessments.&lt;br /&gt;
&lt;br /&gt;
[Expertiza](http://expertiza.ncsu.edu/) is a [Ruby on Rails](http://rubyonrails.org/) based open source project.&lt;br /&gt;
&lt;br /&gt;
==Problem Statement==&lt;br /&gt;
&lt;br /&gt;
Currently, the Expertiza platform needs an updated user impersonation feature for administrators. This project aims to re-implement the platform using TypeScript and ReactJS, focusing on creating a sophisticated user interface for impersonation. Key features will include optimized autocomplete search with debounce, APIs for fetching user lists, and secure JWT token management for handling impersonation.&lt;br /&gt;
&lt;br /&gt;
==Terminology Explanation==&lt;br /&gt;
* '''TypeScript -''' Built on JavaScript, TypeScript enhances the language by adding static typing. It helps catch type errors during development, allowing programmers to write more robust and maintainable code.&lt;br /&gt;
* '''ReactJS -''' a JavaScript library for building user interfaces. It allows developers to create reusable UI components and manage states in web applications. &lt;br /&gt;
* '''JWT(JSON Web Token) -''' a compact and secure token used to transmit information between different parts of a system as JSON object, used for authentication.&lt;br /&gt;
&lt;br /&gt;
==Component Details==&lt;br /&gt;
* '''package.json -''' this file was changed to include the lodash library and its debounce function. This addition was done to help TypeScript understand the structure of the debounce function, allowing features such as type checks and autocompletion. &lt;br /&gt;
* '''App.tsx -''' the file was changed to set up a route ''/impersonate'' in the Expertiza Application. When a user accesses this rote, it will check if the user has the correct permission. If the user passes the check, then it will render the '''ImpersonateUser''' component. &lt;br /&gt;
* '''masquerade-mask.png -''' image added to show a user is using the Impersonate feature.&lt;br /&gt;
* '''Header.tsx -''' this file was changed to include an impersonation banner indicating that a user is being impersonated and the impersonation session is active. The banner also has a cancel button that, when pressed, will reset the authentication state to the original user's credentials and clear the impersonation data.&lt;br /&gt;
* '''ImpersonateUser.css -''' a CSS file used by ImpersonateUser.tsx to display a spinning circle while the user is typing in the search field.&lt;br /&gt;
* '''ImpersonateUser.tsx -''' allows the currently authenticated user to impersonate the identity of another user with roles lower than the current user. This is done by searching for their username and selecting them from a dynamically filtered dropdown list. The search textbox uses debouncing to decrease the number of API calls to the backend while the user types. Once a user is selected, the component sends an impersonation request with a JWT (JSON Web Token) to securely switch the active user session and displays a customized banner in the header to clearly indicate which user is currently being impersonated. The original user credentials are stored, and it will be used when the user stops impersonating and wants to return to their default session.&lt;br /&gt;
&lt;br /&gt;
==Files Modified==&lt;br /&gt;
* package.json [https://github.com/augentism/reimplementation-front-end-impersonate-user/blob/main/package.json]&lt;br /&gt;
* App.tsx [https://github.com/augentism/reimplementation-front-end-impersonate-user/blob/main/src/App.tsx]&lt;br /&gt;
* masquerade-mask.png [https://github.com/augentism/reimplementation-front-end-impersonate-user/blob/main/src/assets/masquerade-mask.png]&lt;br /&gt;
* Header.tsx [https://github.com/augentism/reimplementation-front-end-impersonate-user/blob/main/src/layout/Header.tsx]&lt;br /&gt;
* ImpersonateUser.css [https://github.com/augentism/reimplementation-front-end-impersonate-user/blob/main/src/pages/Impersonate/ImpersonateUser.css]&lt;br /&gt;
* ImpersonateUser.tsx [https://github.com/augentism/reimplementation-front-end-impersonate-user/blob/main/src/pages/Impersonate/ImpersonateUser.tsx]&lt;br /&gt;
&lt;br /&gt;
==Tasks Completed==&lt;br /&gt;
'''1. Impersonation User interface'''&lt;br /&gt;
*A specific webpage was created within the Expertiza to allow only authorized users, such as administrators and higher roles, to access the impersonation feature.&lt;br /&gt;
*The impersonation feature will not be available for unauthorized users.&lt;br /&gt;
*Upon successful impersonation, the component will update the authentication state with the new user's credentials then it will display a banner at the top of the screen indicating the active impersonation session. This banner will include details about the impersonated user's role and name, and it will also have the option to end the session.&lt;br /&gt;
&lt;br /&gt;
'''2. Efficient user search'''&lt;br /&gt;
*A debounce function was integrated with the search field to display filtered users in the dropdown when typing. The purpose of this debounce function is to ensure API calls are only triggered when the user is typing. The debounce logic was set with a delay of 300ms, reducing unnecessary API calls.&lt;br /&gt;
*A spinner indicated was added beside the impersonate button to show the user the results are being fetched. The spinner stops when the user is no longer typing. &lt;br /&gt;
'''3. API Integration'''&lt;br /&gt;
*Make API calls to the user impersonation backend to retrieve a list of users that the current user can manage and impersonate. This API fetches the relevant user list based on the current authenticated user's role.&lt;br /&gt;
*Retrieve impersonated user information, which includes detailed information, such as their ID, full name, role, permissions, and other details for impersonation.&lt;br /&gt;
&lt;br /&gt;
'''4. Managing and storing JWT tokens'''&lt;br /&gt;
*Implemented effective handling of JWT tokens for the original user and the impersonated user. The original token is stored, and a new token is generated for the impersonated session. This way, when the user wants to cancel their impersonation session, they will be sent back to their default session.&lt;br /&gt;
&lt;br /&gt;
'''5. Testing and seeding'''&lt;br /&gt;
*Seeded database with a randomly generated set of users.&lt;br /&gt;
*Testing was done manually, as shown in the Result Section below&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
  &amp;lt;li&amp;gt;Tested impersonation from a super admin account with a randomly generated dataset of users.&amp;lt;/li&amp;gt;&lt;br /&gt;
  &amp;lt;li&amp;gt;Tested impersonation from administrators, instructors, and TA accounts.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Results (Step-by-Step Screenshots)==&lt;br /&gt;
&amp;lt;li&amp;gt;First, login to the admin account.&amp;lt;/li&amp;gt;&lt;br /&gt;
It will bring you to this home page.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&lt;br /&gt;
[[File:Screenshot 2024-10-28 111449.png|900px]]&amp;lt;br/&amp;gt;&lt;br /&gt;
''Expertiza home page.''&lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;li&amp;gt;Then, click on &amp;quot;Manage&amp;quot;&amp;lt;/li&amp;gt;&lt;br /&gt;
It will display this drop-down.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&lt;br /&gt;
[[File:Screenshot 2024-10-28 111540.png|900px]]&amp;lt;br/&amp;gt;&lt;br /&gt;
''Drop-down menu''&lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;li&amp;gt;Click on &amp;quot;Impersonate User&amp;quot;&amp;lt;/li&amp;gt;&lt;br /&gt;
Then, it will bring you to this impersonate user page.&lt;br /&gt;
Either select or type out the user you intend to impersonate. After clicking &amp;quot;Impersonate&amp;quot; you should see something similar to the following screen:&lt;br /&gt;
&amp;lt;center&amp;gt;&lt;br /&gt;
[[File:Spinning circle.jpg|900px]]&amp;lt;br/&amp;gt;&lt;br /&gt;
''Shows the Impersonate user page and the spinning wheel working.''&lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You should have successfully impersonated a user, and the banner pictured above should be visible at all times, as shown in the picture below.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&lt;br /&gt;
[[File:Admin.jpg|900px]]&amp;lt;br/&amp;gt;&lt;br /&gt;
''Shows the successful impersonation of Admin with banner active''&lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;li&amp;gt;Go to the impersonate page again and begin typing the user you want to impersonate into the search bar.&amp;lt;/li&amp;gt;&lt;br /&gt;
Suggestions should appear in the dropdown pictured above when you stop typing. Currently, the debounce time is 300ms.&lt;br /&gt;
&amp;lt;center&amp;gt;&lt;br /&gt;
[[File:ListUser.jpg|900px]]&amp;lt;br/&amp;gt;&lt;br /&gt;
''Shows the dropdown is working''&lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;li&amp;gt;Your current role is admin, so you should be able to impersonate an instructor, as shown in the picture below.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;center&amp;gt;&lt;br /&gt;
[[File:InstructorImpersonate.jpg|900px]]&amp;lt;br/&amp;gt;&lt;br /&gt;
''Shows Admin can impersonate an Instructor''&lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;li&amp;gt;Whenever you impersonate a role, the banner will display the username of the user you impersonated and their role.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;center&amp;gt;&lt;br /&gt;
[[File:Cancel.jpg|900px]]&amp;lt;br/&amp;gt;&lt;br /&gt;
''Shows the banner change as a user impersonates''&lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;li&amp;gt;When you are done impersonating, you can click the cancel button, and it will send you back to the homepage, and your role will be reset to default.&amp;lt;/li&amp;gt;&lt;br /&gt;
The picture below shows when the super admin is done impersonating the instructor, their role will be reset to their original role, and the homepage will display.&lt;br /&gt;
&amp;lt;center&amp;gt;&lt;br /&gt;
[[File:HomepageAdmin.jpg|900px]]&amp;lt;br/&amp;gt;&lt;br /&gt;
''Shows Super Admin successfully return to homepage''&lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Video showcasing Impersonation features===&lt;br /&gt;
*Google Drive Link: [https://drive.google.com/file/d/1Ph_ShpjxVaBVnIon7CqAOr8NWN-0u04V/view?usp=sharing]&lt;br /&gt;
&lt;br /&gt;
==Team==&lt;br /&gt;
'''Mentor''' &lt;br /&gt;
&lt;br /&gt;
*Jay Patel &amp;lt;jhpatel9@ncsu.edu&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Students'''&lt;br /&gt;
&lt;br /&gt;
*Pierce Whelan &amp;lt;pwwhelan@ncsu.edu&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*Calvin Jiang &amp;lt;crjiang@ncsu.edu&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*Hechun Zhang &amp;lt;hzhang56@ncsu.edu&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Relevant Links==&lt;br /&gt;
PR [https://github.com/expertiza/reimplementation-front-end/pull/58] &amp;lt;br&amp;gt;&lt;br /&gt;
Impersonating New Backend [https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2024_-_E2421._Reimplement_impersonating_users_(within_impersonate_controller.rb)_-_Final_Project] &amp;lt;br&amp;gt;&lt;br /&gt;
Impersonating Expertiza [https://wiki.expertiza.ncsu.edu/index.php?title=CSE/ECE_517_Spring_2021_-_E2108._Impersonate_controller.rb]&lt;/div&gt;</summary>
		<author><name>Hzhang56</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2024_-_E2466._UI_for_Impersonate_User&amp;diff=157550</id>
		<title>CSC/ECE 517 Fall 2024 - E2466. UI for Impersonate User</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2024_-_E2466._UI_for_Impersonate_User&amp;diff=157550"/>
		<updated>2024-10-29T19:19:14Z</updated>

		<summary type="html">&lt;p&gt;Hzhang56: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Expertiza==&lt;br /&gt;
&lt;br /&gt;
Expertiza is an open-source web application developed using Ruby on Rails. The Expertiza platform is supported by the National Science Foundation, and it is used by instructors and students from selected courses. It enables students and instructors to manage, submit, and evaluate assignments efficiently. This application makes it possible for student collaboration and learning, allowing students to form teams, submit projects, and do peer assessments.&lt;br /&gt;
&lt;br /&gt;
[Expertiza](http://expertiza.ncsu.edu/) is a [Ruby on Rails](http://rubyonrails.org/) based open source project.&lt;br /&gt;
&lt;br /&gt;
==Problem Statement==&lt;br /&gt;
&lt;br /&gt;
Currently, the Expertiza platform needs an updated user impersonation feature for administrators. This project aims to re-implement the platform using TypeScript and ReactJS, focusing on creating a sophisticated user interface for impersonation. Key features will include optimized autocomplete search with debounce, APIs for fetching user lists, and secure JWT token management for handling impersonation.&lt;br /&gt;
&lt;br /&gt;
==Terminology Explanation==&lt;br /&gt;
* '''TypeScript -''' Built on JavaScript, TypeScript enhances the language by adding static typing. It helps catch type errors during development, allowing programmers to write more robust and maintainable code.&lt;br /&gt;
* '''ReactJS -''' a JavaScript library for building user interfaces. It allows developers to create reusable UI components and manage states in web applications. &lt;br /&gt;
* '''JWT(JSON Web Token) -''' a compact and secure token used to transmit information between different parts of a system as JSON object, used for authentication.&lt;br /&gt;
&lt;br /&gt;
==Component Details==&lt;br /&gt;
* '''package.json -''' this file was changed to include the lodash library and its debounce function. This addition was done to help TypeScript understand the structure of the debounce function, allowing features such as type checks and autocompletion. &lt;br /&gt;
* '''App.tsx -''' the file was changed to set up a route ''/impersonate'' in the Expertiza Application. When a user accesses this rote, it will check if the user has the correct permission. If the user passes the check, then it will render the '''ImpersonateUser''' component. &lt;br /&gt;
* '''masquerade-mask.png -''' image added to show a user is using the Impersonate feature.&lt;br /&gt;
* '''Header.tsx -''' this file was changed to include an impersonation banner indicating that a user is being impersonated and the impersonation session is active. The banner also has a cancel button that, when pressed, will reset the authentication state to the original user's credentials and clear the impersonation data.&lt;br /&gt;
* '''ImpersonateUser.css -''' a CSS file used by ImpersonateUser.tsx to display a spinning circle while the user is typing in the search field.&lt;br /&gt;
* '''ImpersonateUser.tsx -''' allows the currently authenticated user to impersonate the identity of another user with roles lower than the current user. This is done by searching for their username and selecting them from a dynamically filtered dropdown list. The search textbox uses debouncing to decrease the number of API calls to the backend while the user types. Once a user is selected, the component sends an impersonation request with a JWT (JSON Web Token) to securely switch the active user session and displays a customized banner in the header to clearly indicate which user is currently being impersonated. The original user credentials are stored, and it will be used when the user stops impersonating and wants to return to their default session.&lt;br /&gt;
&lt;br /&gt;
==Files Modified==&lt;br /&gt;
* package.json [https://github.com/augentism/reimplementation-front-end-impersonate-user/blob/main/package.json]&lt;br /&gt;
* App.tsx [https://github.com/augentism/reimplementation-front-end-impersonate-user/blob/main/src/App.tsx]&lt;br /&gt;
* masquerade-mask.png [https://github.com/augentism/reimplementation-front-end-impersonate-user/blob/main/src/assets/masquerade-mask.png]&lt;br /&gt;
* Header.tsx [https://github.com/augentism/reimplementation-front-end-impersonate-user/blob/main/src/layout/Header.tsx]&lt;br /&gt;
* ImpersonateUser.css [https://github.com/augentism/reimplementation-front-end-impersonate-user/blob/main/src/pages/Impersonate/ImpersonateUser.css]&lt;br /&gt;
* ImpersonateUser.tsx [https://github.com/augentism/reimplementation-front-end-impersonate-user/blob/main/src/pages/Impersonate/ImpersonateUser.tsx]&lt;br /&gt;
&lt;br /&gt;
==Tasks Completed==&lt;br /&gt;
'''1. Impersonation User interface'''&lt;br /&gt;
*A specific webpage was created within the Expertiza to allow only authorized users, such as administrators and higher roles, to access the impersonation feature.&lt;br /&gt;
*The impersonation feature will not be available for unauthorized users.&lt;br /&gt;
*Upon successful impersonation, the component will update the authentication state with the new user's credentials then it will display a banner at the top of the screen indicating the active impersonation session. This banner will include details about the impersonated user's role and name, and it will also have the option to end the session.&lt;br /&gt;
&lt;br /&gt;
'''2. Efficient user search'''&lt;br /&gt;
*A debounce function was integrated with the search field to display filtered users in the dropdown when typing. The purpose of this debounce function is to ensure API calls are only triggered when the user is typing. The debounce logic was set with a delay of 300ms, reducing unnecessary API calls.&lt;br /&gt;
*A spinner indicated was added beside the impersonate button to show the user the results are being fetched. The spinner stops when the user is no longer typing. &lt;br /&gt;
'''3. API Integration'''&lt;br /&gt;
*Make API calls to the user impersonation backend to retrieve a list of users that the current user can manage and impersonate. This API fetches the relevant user list based on the current authenticated user's role.&lt;br /&gt;
*Retrieve impersonated user information, which includes detailed information, such as their ID, full name, role, permissions, and other details for impersonation.&lt;br /&gt;
&lt;br /&gt;
'''4. Managing and storing JWT tokens'''&lt;br /&gt;
*Implemented effective handling of JWT tokens for the original user and the impersonated user. The original token is stored, and a new token is generated for the impersonated session. This way, when the user wants to cancel their impersonation session, they will be sent back to their default session.&lt;br /&gt;
&lt;br /&gt;
'''5. Testing and seeding'''&lt;br /&gt;
*Seeded database with a randomly generated set of users.&lt;br /&gt;
*Testing was done manually, as shown in the Result Section below&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
  &amp;lt;li&amp;gt;Tested impersonation from a super admin account with a randomly generated dataset of users.&amp;lt;/li&amp;gt;&lt;br /&gt;
  &amp;lt;li&amp;gt;Tested impersonation from administrators, instructors, and TA accounts.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Results (Step-by-Step Screenshots)==&lt;br /&gt;
&amp;lt;li&amp;gt;First, login to the admin account.&amp;lt;/li&amp;gt;&lt;br /&gt;
It will bring you to this home page.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&lt;br /&gt;
[[File:Screenshot 2024-10-28 111449.png|900px]]&amp;lt;br/&amp;gt;&lt;br /&gt;
''Expertiza home page.''&lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;li&amp;gt;Then, click on &amp;quot;Manage&amp;quot;&amp;lt;/li&amp;gt;&lt;br /&gt;
It will display this drop-down.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&lt;br /&gt;
[[File:Screenshot 2024-10-28 111540.png|900px]]&amp;lt;br/&amp;gt;&lt;br /&gt;
''Drop-down menu''&lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;li&amp;gt;Click on &amp;quot;Impersonate User&amp;quot;&amp;lt;/li&amp;gt;&lt;br /&gt;
Then, it will bring you to this impersonate user page.&lt;br /&gt;
Either select or type out the user you intend to impersonate. After clicking &amp;quot;Impersonate&amp;quot; you should see something similar to the following screen:&lt;br /&gt;
&amp;lt;center&amp;gt;&lt;br /&gt;
[[File:Spinning circle.jpg|900px]]&amp;lt;br/&amp;gt;&lt;br /&gt;
''Shows the Impersonate user page and the spinning wheel working.''&lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You should have successfully impersonated a user, and the banner pictured above should be visible at all times, as shown in the picture below.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&lt;br /&gt;
[[File:Admin.jpg|900px]]&amp;lt;br/&amp;gt;&lt;br /&gt;
''Shows the successful impersonation of Admin with banner active''&lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Go to the impersonate page again and begin typing the user you want to impersonate into the search bar.&lt;br /&gt;
Suggestions should appear in the dropdown pictured above when you stop typing. Currently, the debounce time is 300ms.&lt;br /&gt;
&amp;lt;center&amp;gt;&lt;br /&gt;
[[File:ListUser.jpg|900px]]&amp;lt;br/&amp;gt;&lt;br /&gt;
''Shows the dropdown is working''&lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*Your current role is admin, so you should be able to impersonate an instructor, as shown in the picture below.&lt;br /&gt;
&amp;lt;center&amp;gt;&lt;br /&gt;
[[File:InstructorImpersonate.jpg|900px]]&amp;lt;br/&amp;gt;&lt;br /&gt;
''Shows Admin can impersonate an Instructor''&lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*Whenever you impersonate a role, the banner will display the username of the user you impersonated and their role.&lt;br /&gt;
&amp;lt;center&amp;gt;&lt;br /&gt;
[[File:Cancel.jpg|900px]]&amp;lt;br/&amp;gt;&lt;br /&gt;
''Shows the banner change as a user impersonates''&lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*When you are done impersonating, you can click the cancel button, and it will send you back to the homepage, and your role will be reset to default.&lt;br /&gt;
The picture below shows when the super admin is done impersonating the instructor, their role will be reset to their original role, and the homepage will display.&lt;br /&gt;
&amp;lt;center&amp;gt;&lt;br /&gt;
[[File:HomepageAdmin.jpg|900px]]&amp;lt;br/&amp;gt;&lt;br /&gt;
''Shows Super Admin successfully return to homepage''&lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Video showcasing Impersonation features===&lt;br /&gt;
*Google Drive Link: [https://drive.google.com/file/d/1Ph_ShpjxVaBVnIon7CqAOr8NWN-0u04V/view?usp=sharing]&lt;br /&gt;
&lt;br /&gt;
==Team==&lt;br /&gt;
'''Mentor''' &lt;br /&gt;
&lt;br /&gt;
*Jay Patel &amp;lt;jhpatel9@ncsu.edu&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Students'''&lt;br /&gt;
&lt;br /&gt;
*Pierce Whelan &amp;lt;pwwhelan@ncsu.edu&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*Calvin Jiang &amp;lt;crjiang@ncsu.edu&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*Hechun Zhang &amp;lt;hzhang56@ncsu.edu&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Relevant Links==&lt;br /&gt;
PR [https://github.com/expertiza/reimplementation-front-end/pull/58] &amp;lt;br&amp;gt;&lt;br /&gt;
Impersonating New Backend [https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2024_-_E2421._Reimplement_impersonating_users_(within_impersonate_controller.rb)_-_Final_Project] &amp;lt;br&amp;gt;&lt;br /&gt;
Impersonating Expertiza [https://wiki.expertiza.ncsu.edu/index.php?title=CSE/ECE_517_Spring_2021_-_E2108._Impersonate_controller.rb]&lt;/div&gt;</summary>
		<author><name>Hzhang56</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2024_-_E2466._UI_for_Impersonate_User&amp;diff=157535</id>
		<title>CSC/ECE 517 Fall 2024 - E2466. UI for Impersonate User</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2024_-_E2466._UI_for_Impersonate_User&amp;diff=157535"/>
		<updated>2024-10-29T19:02:38Z</updated>

		<summary type="html">&lt;p&gt;Hzhang56: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Expertiza==&lt;br /&gt;
&lt;br /&gt;
Expertiza is an open-source web application developed using Ruby on Rails. The Expertiza platform is supported by the National Science Foundation, and it is used by instructors and students from selected courses. It enables students and instructors to manage, submit, and evaluate assignments efficiently. This application makes it possible for student collaboration and learning, allowing students to form teams, submit projects, and do peer assessments.&lt;br /&gt;
&lt;br /&gt;
[Expertiza](http://expertiza.ncsu.edu/) is a [Ruby on Rails](http://rubyonrails.org/) based open source project.&lt;br /&gt;
&lt;br /&gt;
==Problem Statement==&lt;br /&gt;
&lt;br /&gt;
Currently, the Expertiza platform needs an updated user impersonation feature for administrators. This project aims to re-implement the platform using TypeScript and ReactJS, focusing on creating a sophisticated user interface for impersonation. Key features will include optimized autocomplete search with debounce, APIs for fetching user lists, and secure JWT token management for handling impersonation.&lt;br /&gt;
&lt;br /&gt;
==Terminology Explanation==&lt;br /&gt;
* '''TypeScript -''' Built on JavaScript, TypeScript enhances the language by adding static typing. It helps catch type errors during development, allowing programmers to write more robust and maintainable code.&lt;br /&gt;
* '''ReactJS -''' a JavaScript library for building user interfaces. It allows developers to create reusable UI components and manage states in web applications. &lt;br /&gt;
* '''JWT(JSON Web Token) -''' a compact and secure token used to transmit information between different parts of a system as JSON object, used for authentication.&lt;br /&gt;
&lt;br /&gt;
==Component Details==&lt;br /&gt;
* '''package.json -''' this file was changed to include the lodash library and its debounce function. This addition was done to help TypeScript understand the structure of the debounce function, allowing features such as type checks and autocompletion. &lt;br /&gt;
* '''App.tsx -''' the file was changed to set up a route ''/impersonate'' in the Expertiza Application. When a user accesses this rote, it will check if the user has the correct permission. If the user passes the check, then it will render the '''ImpersonateUser''' component. &lt;br /&gt;
* '''masquerade-mask.png -''' image added to show a user is using the Impersonate feature.&lt;br /&gt;
* '''Header.tsx -''' this file was changed to include an impersonation banner indicating that a user is being impersonated and the impersonation session is active. The banner also has a cancel button that, when pressed, will reset the authentication state to the original user's credentials and clear the impersonation data.&lt;br /&gt;
* '''ImpersonateUser.css -''' a CSS file used by ImpersonateUser.tsx to display a spinning circle while the user is typing in the search field.&lt;br /&gt;
* '''ImpersonateUser.tsx -''' allows the currently authenticated user to impersonate the identity of another user with roles lower than the current user. This is done by searching for their username and selecting them from a dynamically filtered dropdown list. The search textbox uses debouncing to decrease the number of API calls to the backend while the user types. Once a user is selected, the component sends an impersonation request with a JWT (JSON Web Token) to securely switch the active user session and displays a customized banner in the header to clearly indicate which user is currently being impersonated. The original user credentials are stored, and it will be used when the user stops impersonating and wants to return to their default session.&lt;br /&gt;
&lt;br /&gt;
==Files Modified==&lt;br /&gt;
* package.json [https://github.com/augentism/reimplementation-front-end-impersonate-user/blob/main/package.json]&lt;br /&gt;
* App.tsx [https://github.com/augentism/reimplementation-front-end-impersonate-user/blob/main/src/App.tsx]&lt;br /&gt;
* masquerade-mask.png [https://github.com/augentism/reimplementation-front-end-impersonate-user/blob/main/src/assets/masquerade-mask.png]&lt;br /&gt;
* Header.tsx [https://github.com/augentism/reimplementation-front-end-impersonate-user/blob/main/src/layout/Header.tsx]&lt;br /&gt;
* ImpersonateUser.css [https://github.com/augentism/reimplementation-front-end-impersonate-user/blob/main/src/pages/Impersonate/ImpersonateUser.css]&lt;br /&gt;
* ImpersonateUser.tsx [https://github.com/augentism/reimplementation-front-end-impersonate-user/blob/main/src/pages/Impersonate/ImpersonateUser.tsx]&lt;br /&gt;
&lt;br /&gt;
==Tasks Completed==&lt;br /&gt;
'''1. Impersonation User interface'''&lt;br /&gt;
*A specific webpage was created within the Expertiza to allow only authorized users, such as administrators and higher roles, to access the impersonation feature.&lt;br /&gt;
*The impersonation feature will not be available for unauthorized users.&lt;br /&gt;
*Upon successful impersonation, the component will update the authentication state with the new user's credentials then it will display a banner at the top of the screen indicating the active impersonation session. This banner will include details about the impersonated user's role and name, and it will also have the option to end the session.&lt;br /&gt;
&lt;br /&gt;
'''2. Efficient user search'''&lt;br /&gt;
*A debounce function was integrated with the search field to display filtered users in the dropdown when typing. The purpose of this debounce function is to ensure API calls are only triggered when the user is typing. The debounce logic was set with a delay of 300ms, reducing unnecessary API calls.&lt;br /&gt;
*A spinner indicated was added beside the impersonate button to show the user the results are being fetched. The spinner stops when the user is no longer typing. &lt;br /&gt;
'''3. API Integration'''&lt;br /&gt;
*Make API calls to the user impersonation backend to retrieve a list of users that the current user can manage and impersonate. This API fetches the relevant user list based on the current authenticated user's role.&lt;br /&gt;
*Retrieve impersonated user information, which includes detailed information, such as their ID, full name, role, permissions, and other details for impersonation.&lt;br /&gt;
&lt;br /&gt;
'''4. Managing and storing JWT tokens'''&lt;br /&gt;
*Implemented effective handling of JWT tokens for the original user and the impersonated user. The original token is stored, and a new token is generated for the impersonated session. This way, when the user wants to cancel their impersonation session, they will be sent back to their default session.&lt;br /&gt;
&lt;br /&gt;
'''5. Testing and seeding'''&lt;br /&gt;
*Seeded database with a randomly generated set of users.&lt;br /&gt;
*Testing was done manually, as shown in the Result Section below&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
  &amp;lt;li&amp;gt;Tested impersonation from a super admin account with a randomly generated dataset of users.&amp;lt;/li&amp;gt;&lt;br /&gt;
  &amp;lt;li&amp;gt;Tested impersonation from administrators, instructors, and TA accounts.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Results (Step-by-Step Screenshots)==&lt;br /&gt;
First, login to the admin account.&amp;lt;br/&amp;gt;&lt;br /&gt;
It will bring you to this home page.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&lt;br /&gt;
[[File:Screenshot 2024-10-28 111449.png|900px]]&amp;lt;br/&amp;gt;&lt;br /&gt;
''Expertiza home page.''&lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then, click on &amp;quot;Manage&amp;quot;&amp;lt;br/&amp;gt;&lt;br /&gt;
It will display this drop-down.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&lt;br /&gt;
[[File:Screenshot 2024-10-28 111540.png|900px]]&amp;lt;br/&amp;gt;&lt;br /&gt;
''Drop-down menu''&lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Click on &amp;quot;Impersonate User&amp;quot;&amp;lt;br/&amp;gt;&lt;br /&gt;
Then, it will bring you to this impersonate user page.&lt;br /&gt;
&lt;br /&gt;
Either select or type out the user you intend to impersonate. After clicking &amp;quot;Impersonate&amp;quot; you should see something similar to the following screen:&lt;br /&gt;
&amp;lt;center&amp;gt;&lt;br /&gt;
[[File:Spinning circle.jpg|900px]]&amp;lt;br/&amp;gt;&lt;br /&gt;
''Shows the Impersonate user page and the spinning wheel working.''&lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
You should have successfully impersonated a user, and the banner pictured above should be visible at all times.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&lt;br /&gt;
[[File:Admin.jpg|900px]]&amp;lt;br/&amp;gt;&lt;br /&gt;
''Shows the successful impersonation of Admin''&lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Begin typing the user you want to impersonate into the search bar.&lt;br /&gt;
Suggestions should appear in the dropdown pictured above when you stop typing. Currently, the debounce time is 300ms.&lt;br /&gt;
&amp;lt;center&amp;gt;&lt;br /&gt;
[[File:ListUser.jpg|900px]]&amp;lt;br/&amp;gt;&lt;br /&gt;
''Shows the dropdown is working''&lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&lt;br /&gt;
[[File:InstructorImpersonate.jpg|900px]]&amp;lt;br/&amp;gt;&lt;br /&gt;
''Shows Admin can impersonate an Instructor''&lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&lt;br /&gt;
[[File:Cancel.jpg|900px]]&amp;lt;br/&amp;gt;&lt;br /&gt;
''Shows the banner change as a user impersonates''&lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&lt;br /&gt;
[[File:HomepageAdmin.jpg|900px]]&amp;lt;br/&amp;gt;&lt;br /&gt;
''Shows Super Admin successfully return to homepage''&lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Video showcasing Impersonation features===&lt;br /&gt;
*Google Drive Link: [https://drive.google.com/file/d/1Ph_ShpjxVaBVnIon7CqAOr8NWN-0u04V/view?usp=sharing]&lt;br /&gt;
&lt;br /&gt;
==Team==&lt;br /&gt;
'''Mentor''' &lt;br /&gt;
&lt;br /&gt;
*Jay Patel &amp;lt;jhpatel9@ncsu.edu&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Students'''&lt;br /&gt;
&lt;br /&gt;
*Pierce Whelan &amp;lt;pwwhelan@ncsu.edu&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*Calvin Jiang &amp;lt;crjiang@ncsu.edu&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*Hechun Zhang &amp;lt;hzhang56@ncsu.edu&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Relevant Links==&lt;br /&gt;
PR [https://github.com/expertiza/reimplementation-front-end/pull/58] &amp;lt;br&amp;gt;&lt;br /&gt;
Impersonating New Backend [https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2024_-_E2421._Reimplement_impersonating_users_(within_impersonate_controller.rb)_-_Final_Project] &amp;lt;br&amp;gt;&lt;br /&gt;
Impersonating Expertiza [https://wiki.expertiza.ncsu.edu/index.php?title=CSE/ECE_517_Spring_2021_-_E2108._Impersonate_controller.rb]&lt;/div&gt;</summary>
		<author><name>Hzhang56</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2024_-_E2466._UI_for_Impersonate_User&amp;diff=157509</id>
		<title>CSC/ECE 517 Fall 2024 - E2466. UI for Impersonate User</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2024_-_E2466._UI_for_Impersonate_User&amp;diff=157509"/>
		<updated>2024-10-29T18:08:17Z</updated>

		<summary type="html">&lt;p&gt;Hzhang56: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Expertiza==&lt;br /&gt;
&lt;br /&gt;
Expertiza is an open-source web application developed using Ruby on Rails. The Expertiza platform is supported by the National Science Foundation, and it is used by instructors and students from selected courses. It enables students and instructors to manage, submit, and evaluate assignments efficiently. This application makes it possible for student collaboration and learning, allowing students to form teams, submit projects, and do peer assessments.&lt;br /&gt;
&lt;br /&gt;
[Expertiza](http://expertiza.ncsu.edu/) is a [Ruby on Rails](http://rubyonrails.org/) based open source project.&lt;br /&gt;
&lt;br /&gt;
==Problem Statement==&lt;br /&gt;
&lt;br /&gt;
Currently, the Expertiza platform needs an updated user impersonation feature for administrators. This project aims to re-implement the platform using TypeScript and ReactJS, focusing on creating a sophisticated user interface for impersonation. Key features will include optimized autocomplete search with debounce, APIs for fetching user lists, and secure JWT token management for handling impersonation.&lt;br /&gt;
&lt;br /&gt;
==Terminology Explanation==&lt;br /&gt;
* '''TypeScript -''' Built on JavaScript, TypeScript enhances the language by adding static typing. It helps catch type errors during development, allowing programmers to write more robust and maintainable code.&lt;br /&gt;
* '''ReactJS -''' a JavaScript library for building user interfaces. It allows developers to create reusable UI components and manage states in web applications. &lt;br /&gt;
* '''JWT(JSON Web Token) -''' a compact and secure token used to transmit information between different parts of a system as JSON object, used for authentication.&lt;br /&gt;
&lt;br /&gt;
==Component Details==&lt;br /&gt;
* '''package.json -''' this file was changed to include the lodash library and its debounce function. This addition was done to help TypeScript understand the structure of the debounce function, allowing features such as type checks and autocompletion. &lt;br /&gt;
* '''App.tsx -''' the file was changed to set up a route ''/impersonate'' in the Expertiza Application. When a user accesses this rote, it will check if the user has the correct permission. If the user passes the check, then it will render the '''ImpersonateUser''' component. &lt;br /&gt;
* '''masquerade-mask.png -''' image added to show a user is using the Impersonate feature.&lt;br /&gt;
* '''Header.tsx -''' this file was changed to include an impersonation banner indicating that a user is being impersonated and the impersonation session is active. The banner also has a cancel button that, when pressed, will reset the authentication state to the original user's credentials and clear the impersonation data.&lt;br /&gt;
* '''ImpersonateUser.css -''' a CSS file used by ImpersonateUser.tsx to display a spinning circle while the user is typing in the search field.&lt;br /&gt;
* '''ImpersonateUser.tsx -''' allows the currently authenticated user to impersonate the identity of another user with roles lower than the current user. This is done by searching for their username and selecting them from a dynamically filtered dropdown list. The search textbox uses debouncing to decrease the number of API calls to the backend while the user types. Once a user is selected, the component sends an impersonation request with a JWT (JSON Web Token) to securely switch the active user session and displays a customized banner in the header to clearly indicate which user is currently being impersonated. The original user credentials are stored, and it will be used when the user stops impersonating and wants to return to their default session.&lt;br /&gt;
&lt;br /&gt;
==Files Modified==&lt;br /&gt;
* package.json [https://github.com/augentism/reimplementation-front-end-impersonate-user/blob/main/package.json]&lt;br /&gt;
* App.tsx [https://github.com/augentism/reimplementation-front-end-impersonate-user/blob/main/src/App.tsx]&lt;br /&gt;
* masquerade-mask.png [https://github.com/augentism/reimplementation-front-end-impersonate-user/blob/main/src/assets/masquerade-mask.png]&lt;br /&gt;
* Header.tsx [https://github.com/augentism/reimplementation-front-end-impersonate-user/blob/main/src/layout/Header.tsx]&lt;br /&gt;
* ImpersonateUser.css [https://github.com/augentism/reimplementation-front-end-impersonate-user/blob/main/src/pages/Impersonate/ImpersonateUser.css]&lt;br /&gt;
* ImpersonateUser.tsx [https://github.com/augentism/reimplementation-front-end-impersonate-user/blob/main/src/pages/Impersonate/ImpersonateUser.tsx]&lt;br /&gt;
&lt;br /&gt;
==Tasks Completed==&lt;br /&gt;
'''1. Impersonation User interface'''&lt;br /&gt;
*A specific webpage was created within the Expertiza to allow only authorized users, such as administrators and higher roles, to access the impersonation feature.&lt;br /&gt;
*The impersonation feature will not be available for unauthorized users.&lt;br /&gt;
*Upon successful impersonation, the component will update the authentication state with the new user's credentials then it will display a banner at the top of the screen indicating the active impersonation session. This banner will include details about the impersonated user's role and name, and it will also have the option to end the session.&lt;br /&gt;
&lt;br /&gt;
'''2. Efficient user search'''&lt;br /&gt;
*A debounce function was integrated with the search field to display filtered users in the dropdown when typing. The purpose of this debounce function is to ensure API calls are only triggered when the user is typing. The debounce logic was set with a delay of 300ms, reducing unnecessary API calls.&lt;br /&gt;
*A spinner indicated was added beside the impersonate button to show the user the results are being fetched. The spinner stops when the user is no longer typing. &lt;br /&gt;
'''3. API Integration'''&lt;br /&gt;
*Make API calls to the user impersonation backend to retrieve a list of users that the current user can manage and impersonate. This API fetches the relevant user list based on the current authenticated user's role.&lt;br /&gt;
*Retrieve impersonated user information, which includes detailed information, such as their ID, full name, role, permissions, and other details for impersonation.&lt;br /&gt;
&lt;br /&gt;
'''4. Managing and storing JWT tokens'''&lt;br /&gt;
*Implemented effective handling of JWT tokens for the original user and the impersonated user. The original token is stored, and a new token is generated for the impersonated session. This way, when the user wants to cancel their impersonation session, they will be sent back to their default session.&lt;br /&gt;
&lt;br /&gt;
'''5. Testing and seeding'''&lt;br /&gt;
*Seeded database with a randomly generated set of users.&lt;br /&gt;
*Testing was done manually, as shown in the Result Section below&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
  &amp;lt;li&amp;gt;Tested impersonation from a super admin account with a randomly generated dataset of users.&amp;lt;/li&amp;gt;&lt;br /&gt;
  &amp;lt;li&amp;gt;Tested impersonation from administrators, instructors, and TA accounts.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Results (Step-by-Step Screenshots)==&lt;br /&gt;
First, login to the admin account.&amp;lt;br/&amp;gt;&lt;br /&gt;
It will bring you to this home page.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&lt;br /&gt;
[[File:Screenshot 2024-10-28 111449.png|900px]]&amp;lt;br/&amp;gt;&lt;br /&gt;
''Expertiza home page.''&lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then, click on &amp;quot;Manage&amp;quot;&amp;lt;br/&amp;gt;&lt;br /&gt;
It will display this drop-down.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&lt;br /&gt;
[[File:Screenshot 2024-10-28 111540.png|900px]]&amp;lt;br/&amp;gt;&lt;br /&gt;
''Drop-down menu''&lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Click on &amp;quot;Impersonate User&amp;quot;&amp;lt;br/&amp;gt;&lt;br /&gt;
Then, it will bring you to this impersonate user page.&lt;br /&gt;
&lt;br /&gt;
Either select or type out the user you intend to impersonate. After clicking &amp;quot;Impersonate&amp;quot; you should see something similar to the following screen:&lt;br /&gt;
&amp;lt;center&amp;gt;&lt;br /&gt;
[[File:Spinning circle.jpg|900px]]&amp;lt;br/&amp;gt;&lt;br /&gt;
''Shows the Impersonate user page and the spinning wheel working.''&lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
You should have successfully impersonated a user, and the banner pictured above should be visible at all times.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&lt;br /&gt;
[[File:Admin.jpg|900px]]&amp;lt;br/&amp;gt;&lt;br /&gt;
''Shows the successful impersonation of Admin''&lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Begin typing the user you want to impersonate into the search bar.&lt;br /&gt;
Suggestions should appear in the dropdown pictured above when you stop typing. Currently, the debounce time is 300ms.&lt;br /&gt;
&amp;lt;center&amp;gt;&lt;br /&gt;
[[File:ListUser.jpg|900px]]&amp;lt;br/&amp;gt;&lt;br /&gt;
''Shows the dropdown is working''&lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&lt;br /&gt;
[[File:InstructorImpersonate.jpg|900px]]&amp;lt;br/&amp;gt;&lt;br /&gt;
''Shows Admin can impersonate an Instructor''&lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&lt;br /&gt;
[[File:Cancel.jpg|900px]]&amp;lt;br/&amp;gt;&lt;br /&gt;
''Shows the banner change as a user impersonates''&lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&lt;br /&gt;
[[File:HomepageAdmin.jpg|900px]]&amp;lt;br/&amp;gt;&lt;br /&gt;
''Shows Super Admin successfully return to homepage''&lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Team==&lt;br /&gt;
'''Mentor''' &lt;br /&gt;
&lt;br /&gt;
*Jay Patel &amp;lt;jhpatel9@ncsu.edu&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Students'''&lt;br /&gt;
&lt;br /&gt;
*Pierce Whelan &amp;lt;pwwhelan@ncsu.edu&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*Calvin Jiang &amp;lt;crjiang@ncsu.edu&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*Hechun Zhang &amp;lt;hzhang56@ncsu.edu&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Relevant Links==&lt;br /&gt;
PR [https://github.com/expertiza/reimplementation-front-end/pull/58] &amp;lt;br&amp;gt;&lt;br /&gt;
Impersonating New Backend [https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2024_-_E2421._Reimplement_impersonating_users_(within_impersonate_controller.rb)_-_Final_Project] &amp;lt;br&amp;gt;&lt;br /&gt;
Impersonating Expertiza [https://wiki.expertiza.ncsu.edu/index.php?title=CSE/ECE_517_Spring_2021_-_E2108._Impersonate_controller.rb]&lt;/div&gt;</summary>
		<author><name>Hzhang56</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2024_-_E2466._UI_for_Impersonate_User&amp;diff=157505</id>
		<title>CSC/ECE 517 Fall 2024 - E2466. UI for Impersonate User</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2024_-_E2466._UI_for_Impersonate_User&amp;diff=157505"/>
		<updated>2024-10-29T18:05:39Z</updated>

		<summary type="html">&lt;p&gt;Hzhang56: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Expertiza==&lt;br /&gt;
&lt;br /&gt;
Expertiza is an open-source web application developed using Ruby on Rails. The Expertiza platform is supported by the National Science Foundation, and it is used by instructors and students from selected courses. It enables students and instructors to manage, submit, and evaluate assignments efficiently. This application makes it possible for student collaboration and learning, allowing students to form teams, submit projects, and do peer assessments.&lt;br /&gt;
&lt;br /&gt;
[Expertiza](http://expertiza.ncsu.edu/) is a [Ruby on Rails](http://rubyonrails.org/) based open source project.&lt;br /&gt;
&lt;br /&gt;
==Problem Statement==&lt;br /&gt;
&lt;br /&gt;
Currently, the Expertiza platform needs an updated user impersonation feature for administrators. This project aims to re-implement the platform using TypeScript and ReactJS, focusing on creating a sophisticated user interface for impersonation. Key features will include optimized autocomplete search with debounce, APIs for fetching user lists, and secure JWT token management for handling impersonation.&lt;br /&gt;
&lt;br /&gt;
==Terminology Explanation==&lt;br /&gt;
* '''TypeScript -''' Built on JavaScript, TypeScript enhances the language by adding static typing. It helps catch type errors during development, allowing programmers to write more robust and maintainable code.&lt;br /&gt;
* '''ReactJS -''' a JavaScript library for building user interfaces. It allows developers to create reusable UI components and manage states in web applications. &lt;br /&gt;
* '''JWT(JSON Web Token) -''' a compact and secure token used to transmit information between different parts of a system as JSON object, used for authentication.&lt;br /&gt;
&lt;br /&gt;
==Component Details==&lt;br /&gt;
* '''package.json -''' this file was changed to include the lodash library and its debounce function. This addition was done to help TypeScript understand the structure of the debounce function, allowing features such as type checks and autocompletion. &lt;br /&gt;
* '''App.tsx -''' the file was changed to set up a route ''/impersonate'' in the Expertiza Application. When a user accesses this rote, it will check if the user has the correct permission. If the user passes the check, then it will render the '''ImpersonateUser''' component. &lt;br /&gt;
* '''masquerade-mask.png -''' image added to show a user is using the Impersonate feature.&lt;br /&gt;
* '''Header.tsx -''' this file was changed to include an impersonation banner indicating that a user is being impersonated and the impersonation session is active. The banner also has a cancel button that, when pressed, will reset the authentication state to the original user's credentials and clear the impersonation data.&lt;br /&gt;
* '''ImpersonateUser.css -''' a CSS file used by ImpersonateUser.tsx to display a spinning circle while the user is typing in the search field.&lt;br /&gt;
* '''ImpersonateUser.tsx -''' allows the currently authenticated user to impersonate the identity of another user with roles lower than the current user. This is done by searching for their username and selecting them from a dynamically filtered dropdown list. The search textbox uses debouncing to decrease the number of API calls to the backend while the user types. Once a user is selected, the component sends an impersonation request with a JWT (JSON Web Token) to securely switch the active user session and displays a customized banner in the header to clearly indicate which user is currently being impersonated. The original user credentials are stored, and it will be used when the user stops impersonating and wants to return to their default session.&lt;br /&gt;
&lt;br /&gt;
==Files Modified==&lt;br /&gt;
* package.json [https://github.com/augentism/reimplementation-front-end-impersonate-user/blob/main/package.json]&lt;br /&gt;
* App.tsx [https://github.com/augentism/reimplementation-front-end-impersonate-user/blob/main/src/App.tsx]&lt;br /&gt;
* masquerade-mask.png [https://github.com/augentism/reimplementation-front-end-impersonate-user/blob/main/src/assets/masquerade-mask.png]&lt;br /&gt;
* Header.tsx [https://github.com/augentism/reimplementation-front-end-impersonate-user/blob/main/src/layout/Header.tsx]&lt;br /&gt;
* ImpersonateUser.css [https://github.com/augentism/reimplementation-front-end-impersonate-user/blob/main/src/pages/Impersonate/ImpersonateUser.css]&lt;br /&gt;
* ImpersonateUser.tsx [https://github.com/augentism/reimplementation-front-end-impersonate-user/blob/main/src/pages/Impersonate/ImpersonateUser.tsx]&lt;br /&gt;
&lt;br /&gt;
==Tasks Completed==&lt;br /&gt;
'''1. Impersonation User interface'''&lt;br /&gt;
*A specific webpage was created within the Expertiza to allow only authorized users, such as administrators and higher roles, to access the impersonation feature.&lt;br /&gt;
*The impersonation feature will not be available for unauthorized users.&lt;br /&gt;
*Upon successful impersonation, the component will update the authentication state with the new user's credentials then it will display a banner at the top of the screen indicating the active impersonation session. This banner will include details about the impersonated user's role and name, and it will also have the option to end the session.&lt;br /&gt;
&lt;br /&gt;
'''2. Efficient user search'''&lt;br /&gt;
*A debounce function was integrated with the search field to display filtered users in the dropdown when typing. The purpose of this debounce function is to ensure API calls are only triggered when the user is typing. The debounce logic was set with a delay of 300ms, reducing unnecessary API calls.&lt;br /&gt;
*A spinner indicated was added beside the impersonate button to show the user the results are being fetched. The spinner stops when the user is no longer typing. &lt;br /&gt;
'''3. API Integration'''&lt;br /&gt;
*Make API calls to the user impersonation backend to retrieve a list of users that the current user can manage and impersonate. This API fetches the relevant user list based on the current authenticated user's role.&lt;br /&gt;
*Retrieve impersonated user information, which includes detailed information, such as their ID, full name, role, permissions, and other details for impersonation.&lt;br /&gt;
&lt;br /&gt;
'''4. Managing and storing JWT tokens'''&lt;br /&gt;
*Implemented effective handling of JWT tokens for the original user and the impersonated user. The original token is stored, and a new token is generated for the impersonated session. This way, when the user wants to cancel their impersonation session, they will be sent back to their default session.&lt;br /&gt;
&lt;br /&gt;
'''5. Testing and seeding'''&lt;br /&gt;
*Seeded database with a randomly generated set of users.&lt;br /&gt;
*Testing was done manually, as shown in the Result Section below&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
  &amp;lt;li&amp;gt;Tested impersonation from a super admin account with a randomly generated dataset of users.&amp;lt;/li&amp;gt;&lt;br /&gt;
  &amp;lt;li&amp;gt;Tested impersonation from administrators, instructors, and TA accounts.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Results (Step-by-Step Screenshots)==&lt;br /&gt;
First, login to the admin account.&amp;lt;br/&amp;gt;&lt;br /&gt;
It will bring you to this home page.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&lt;br /&gt;
[[File:Screenshot 2024-10-28 111449.png|900px]]&lt;br /&gt;
''Expertiza home page.''&lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then, click on &amp;quot;Manage&amp;quot;&amp;lt;br/&amp;gt;&lt;br /&gt;
It will display this drop-down.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&lt;br /&gt;
[[File:Screenshot 2024-10-28 111540.png|900px]]&lt;br /&gt;
''Drop-down menu''&lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Click on &amp;quot;Impersonate User&amp;quot;&amp;lt;br/&amp;gt;&lt;br /&gt;
Then, it will bring you to this impersonate user page.&lt;br /&gt;
&lt;br /&gt;
Either select or type out the user you intend to impersonate. After clicking &amp;quot;Impersonate&amp;quot; you should see something similar to the following screen:&lt;br /&gt;
&amp;lt;center&amp;gt;&lt;br /&gt;
[[File:Spinning circle.jpg|900px]]&lt;br /&gt;
''Shows the Impersonate user page and the spinning wheel working.''&lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
You should have successfully impersonated a user, and the banner pictured above should be visible at all times.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&lt;br /&gt;
[[File:Admin.jpg|900px]]&lt;br /&gt;
''Shows the successful impersonation of Admin''&lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Begin typing the user you want to impersonate into the search bar.&lt;br /&gt;
Suggestions should appear in the dropdown pictured above when you stop typing. Currently, the debounce time is 300ms.&lt;br /&gt;
&amp;lt;center&amp;gt;&lt;br /&gt;
[[File:ListUser.jpg|900px]]&lt;br /&gt;
''Shows the dropdown is working''&lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&lt;br /&gt;
[[File:InstructorImpersonate.jpg|900px]]&lt;br /&gt;
''Shows Admin can impersonate an Instructor''&lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&lt;br /&gt;
[[File:Cancel.jpg|900px]]&lt;br /&gt;
''Shows the banner change as a user impersonates''&lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&lt;br /&gt;
[[File:HomepageAdmin.jpg|900px]]&lt;br /&gt;
''Shows Super Admin successfully return to homepage''&lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Team==&lt;br /&gt;
'''Mentor''' &lt;br /&gt;
&lt;br /&gt;
*Jay Patel &amp;lt;jhpatel9@ncsu.edu&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Students'''&lt;br /&gt;
&lt;br /&gt;
*Pierce Whelan &amp;lt;pwwhelan@ncsu.edu&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*Calvin Jiang &amp;lt;crjiang@ncsu.edu&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*Hechun Zhang &amp;lt;hzhang56@ncsu.edu&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Relevant Links==&lt;br /&gt;
PR [https://github.com/expertiza/reimplementation-front-end/pull/58] &amp;lt;br&amp;gt;&lt;br /&gt;
Impersonating New Backend [https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2024_-_E2421._Reimplement_impersonating_users_(within_impersonate_controller.rb)_-_Final_Project] &amp;lt;br&amp;gt;&lt;br /&gt;
Impersonating Expertiza [https://wiki.expertiza.ncsu.edu/index.php?title=CSE/ECE_517_Spring_2021_-_E2108._Impersonate_controller.rb]&lt;/div&gt;</summary>
		<author><name>Hzhang56</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=File:Admin.jpg&amp;diff=157492</id>
		<title>File:Admin.jpg</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=File:Admin.jpg&amp;diff=157492"/>
		<updated>2024-10-29T17:52:25Z</updated>

		<summary type="html">&lt;p&gt;Hzhang56: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Hzhang56</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=File:Cancel.jpg&amp;diff=157491</id>
		<title>File:Cancel.jpg</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=File:Cancel.jpg&amp;diff=157491"/>
		<updated>2024-10-29T17:52:13Z</updated>

		<summary type="html">&lt;p&gt;Hzhang56: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Hzhang56</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=File:HomepageAdmin.jpg&amp;diff=157490</id>
		<title>File:HomepageAdmin.jpg</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=File:HomepageAdmin.jpg&amp;diff=157490"/>
		<updated>2024-10-29T17:51:59Z</updated>

		<summary type="html">&lt;p&gt;Hzhang56: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Hzhang56</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=File:InstructorImpersonate.jpg&amp;diff=157489</id>
		<title>File:InstructorImpersonate.jpg</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=File:InstructorImpersonate.jpg&amp;diff=157489"/>
		<updated>2024-10-29T17:51:41Z</updated>

		<summary type="html">&lt;p&gt;Hzhang56: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Hzhang56</name></author>
	</entry>
</feed>