<?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=Mbhande2</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=Mbhande2"/>
	<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=Special:Contributions/Mbhande2"/>
	<updated>2026-05-10T17:22:48Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.41.0</generator>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2024&amp;diff=156255</id>
		<title>CSC/ECE 517 Spring 2024</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2024&amp;diff=156255"/>
		<updated>2024-04-23T23:55:46Z</updated>

		<summary type="html">&lt;p&gt;Mbhande2: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;* [[CSC/ECE 517 Spring 2024 - E2401 Implementing and testing import &amp;amp; export controllers]]&lt;br /&gt;
* [[CSC/ECE 517 Spring 2024 - E2405 Refactor review_mapping_helper.rb]]&lt;br /&gt;
* [[CSC/ECE 517 Spring 2024 - E2407 Refactor review_mapping_controller.rb]]&lt;br /&gt;
* [[CSC/ECE 517 Spring 2024 - E2418. Reimplement of due date.rb]]&lt;br /&gt;
* [[CSC/ECE 517 Spring 2024 - E2428 Replicate Roles and Institution UIs ReactJS]]&lt;br /&gt;
* [[CSC/ECE 517 Spring 2024 - E2429 Reimplement student_task list]]&lt;br /&gt;
* [[CSC/ECE 517 Spring 2024 - E2430 Reimplement student_task view]]&lt;br /&gt;
* [[CSC/ECE 517 Spring 2024 - E2410. View for Results of Bidding ]]&lt;br /&gt;
* [[CSC/ECE 517 Spring 2024 - E2414 Grading Audit Trail]]&lt;br /&gt;
* [[CSC/ECE 517 Spring 2024 - NTNX-1 : Extend NDB Operator to Support Postgres HA]]&lt;br /&gt;
* [[CSC/ECE 517 Spring 2024 - ‬NTNX-2‬‭ : Snapshot Functionality for provisioned databases]]&lt;br /&gt;
* [[CSC/ECE 517 Spring 2024 - E2411 : Fix &amp;quot;Back&amp;quot; link on “New Late Policy” page]]&lt;br /&gt;
* [[CSC/ECE 517 Spring 2024 - E2416.  Reimplement the Question hierarchy]]&lt;br /&gt;
* [[CSC/ECE 517 Spring 2024 - E2420. Reimplement student_quizzes_controller]]&lt;br /&gt;
* [[CSC/ECE 517 Spring 2024 - E2424. Reimplement the Bookmarks Controller]]&lt;br /&gt;
* [[CSC/ECE 517 Spring 2024 - E2426. Create a UI for Assignment Edit page &amp;quot;Etc&amp;quot; tab in ReactJS]]&lt;br /&gt;
* [[CSC/ECE 517 Spring 2024 - E2417. Reimplement submitted content controller.rb]]&lt;br /&gt;
* [[CSC/ECE 517 Spring 2024 - E2417. Reimplement submitted content controller.rb (Phase 2)]]&lt;br /&gt;
* [[CSC/ECE 517 Spring 2024 - E2425. Create a Courses user interface in ReactJS]]&lt;br /&gt;
* [[CSC/ECE 517 Spring 2024 - E2431. Reimplement  grades/view_team]]&lt;br /&gt;
* [[CSC/ECE 517 Spring 2024 - E2404 Refactor student teams functionality]]&lt;br /&gt;
* [[CSC/ECE 517 Spring 2024 - E2406 Refactor review_mapping_helper.rb]]&lt;br /&gt;
* [[CSC/ECE 517 Spring 2024 - E2403 Mentor-Meeting Management]]&lt;br /&gt;
* [[CSC/ECE 517 Spring 2024 - E2421. Reimplement impersonating users (within impersonate controller.rb) - Final Project]]&lt;br /&gt;
* [[CSC/ECE 517 Spring 2024 - E2413. Testing - Answer Tagging]]&lt;br /&gt;
* [[CSC/ECE 517 Spring 2024 - E2412. Testing for hamer.rb]]&lt;br /&gt;
* [[CSC/ECE 517 Spring 2024 - E2427. UI for questionnaire.rb]]&lt;br /&gt;
* [[CSC/ECE 517 Spring 2024 - E2419. Reimplement duties controller.rb and badges controller.rb]]&lt;br /&gt;
* [[CSC/ECE 517 Spring 2024 - E2432. UI for Participants.rb]]&lt;br /&gt;
* [[CSC/ECE 517 Spring 2024 - G2402 Implement REST client, REST API, and Graphql API endpoint for repositories]]&lt;br /&gt;
* [[CSC/ECE 517 Spring 2024 - G2400 DevOp for GitHub Miner app]]&lt;br /&gt;
* [[CSC/ECE 517 Spring 2024 - E2439 Testing for view_translation_substitutor.rb]]&lt;br /&gt;
* [[CSC/ECE 517 Spring 2024 - E2442 Reimplement student task controller]]&lt;br /&gt;
* [[CSC/ECE 517 Spring 2024 - E2443 Reimplement grades_controller]]&lt;br /&gt;
* [[CSC/ECE 517 Spring 2024 - E2434 Reimplement Frontend for the Grades view]]&lt;br /&gt;
* [[CSC/ECE 517 Spring 2024 - E2435 Implement Frontend for the My Profile]]&lt;br /&gt;
* [[CSC/ECE 517 Spring 2024 - E2446 Implement Front End for Student Task List]]&lt;br /&gt;
* [[CSC/ECE 517 Spring 2024 - E2444 Implement Frontend for the Review]]&lt;br /&gt;
* [[CSC/ECE 517 Spring 2024 - E2440 Testing for questionnaire_helper, review_bids_helper]]&lt;br /&gt;
* [[CSC/ECE 517 Spring 2024 - E2433 Implement UI for the Student Teams]]&lt;br /&gt;
* [[CSC/ECE 517 Spring 2024 - E2415. Reimplement responses controller.rb (Design Document)]]&lt;br /&gt;
* [[CSC/ECE 517 Spring 2024 - E2445. Implement BackEnd for participants.rb (Design Document)]]&lt;br /&gt;
* [[CSC/ECE 517 Spring 2024 - E2445. Implement BackEnd for participants.rb]]&lt;br /&gt;
* [[CSC/ECE 517 Spring 2024 - E2441 Reimplement grades/view_team (Phase 2)]]&lt;br /&gt;
* [[CSC/ECE 517 Spring 2024 - E2418. Reimplement of due date.rb (Phase 2)]]&lt;/div&gt;</summary>
		<author><name>Mbhande2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2024_-_E2421._Reimplement_impersonating_users_(within_impersonate_controller.rb)_-_Final_Project&amp;diff=156245</id>
		<title>CSC/ECE 517 Spring 2024 - E2421. Reimplement impersonating users (within impersonate controller.rb) - Final Project</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2024_-_E2421._Reimplement_impersonating_users_(within_impersonate_controller.rb)_-_Final_Project&amp;diff=156245"/>
		<updated>2024-04-23T23:49:14Z</updated>

		<summary type="html">&lt;p&gt;Mbhande2: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Expertiza==&lt;br /&gt;
&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is a [http://rubyonrails.org/ Ruby on Rails] based open source project. Instructors have the ability to add new projects, assignments, etc., as well as edit existing ones. Later on, they can view student submissions and grade them. Students can also use Expertiza to organize into teams to work on different projects and assignments and submit their work. They can also review other students' submissions.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Project Overview==&lt;br /&gt;
&lt;br /&gt;
The goal of this project is to update the backend code for the user impersonation feature in the new version of Expertiza. The existing implementation relies on sessions, which is incompatible with the new implementation that uses JWT (JSON Web Tokens) for authentication and JSON responses. The primary challenge is to migrate the impersonation logic from session-based management to JWT-based authentication while preserving the same functionality. This reimplementation requires planning for the communication between the backend and frontend, which may necessitate modifications to existing files or the creation of new files beyond the impersonate_controller.rb file.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Implementation==&lt;br /&gt;
&lt;br /&gt;
===UML Diagram===&lt;br /&gt;
The following UML diagram shows the association between models we will be working on&lt;br /&gt;
&lt;br /&gt;
[[File:UML-Diagram-E2421.jpeg]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Hierarchy Diagram===&lt;br /&gt;
Visualization of the hierarchical structure&lt;br /&gt;
&lt;br /&gt;
[[File:Hierarchy-diagram E2421.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Request===&lt;br /&gt;
&lt;br /&gt;
*GET: {BASE_URL}/api/v1/impersonate/:username&lt;br /&gt;
   - Response:&lt;br /&gt;
&lt;br /&gt;
    &amp;quot;message&amp;quot;: &amp;quot;Successfully Fetched User List!&amp;quot;,&lt;br /&gt;
    &amp;quot;userList&amp;quot;: [&lt;br /&gt;
        {&lt;br /&gt;
            &amp;quot;id&amp;quot;: 4,&lt;br /&gt;
            &amp;quot;name&amp;quot;: &amp;quot;Mihir&amp;quot;,&lt;br /&gt;
            &amp;quot;full_name&amp;quot;: &amp;quot;Mihir BHanderi&amp;quot;,&lt;br /&gt;
            &amp;quot;email&amp;quot;: &amp;quot;mbhande@example.com&amp;quot;,&lt;br /&gt;
            &amp;quot;email_on_review&amp;quot;: false,&lt;br /&gt;
            &amp;quot;email_on_submission&amp;quot;: false,&lt;br /&gt;
            &amp;quot;email_on_review_of_review&amp;quot;: false,&lt;br /&gt;
            &amp;quot;role&amp;quot;: {&lt;br /&gt;
                &amp;quot;id&amp;quot;: 4,&lt;br /&gt;
                &amp;quot;name&amp;quot;: &amp;quot;Teaching Assistant&amp;quot;&lt;br /&gt;
            },&lt;br /&gt;
            &amp;quot;institution&amp;quot;: {&lt;br /&gt;
                &amp;quot;id&amp;quot;: 1,&lt;br /&gt;
                &amp;quot;name&amp;quot;: &amp;quot;North Carolina State University&amp;quot;&lt;br /&gt;
            },&lt;br /&gt;
            &amp;quot;parent&amp;quot;: {&lt;br /&gt;
                &amp;quot;id&amp;quot;: null,&lt;br /&gt;
                &amp;quot;name&amp;quot;: null&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
    ],&lt;br /&gt;
    &amp;quot;success&amp;quot;: true&lt;br /&gt;
&lt;br /&gt;
*POST: {BASE_URL}/api/v1/impersonate&lt;br /&gt;
   - Payload: impersonate_id&lt;br /&gt;
   - Response: &lt;br /&gt;
&lt;br /&gt;
     &amp;quot;message&amp;quot;: &amp;quot;Successfully Impersonated Ketul!&amp;quot;,&lt;br /&gt;
     &amp;quot;token&amp;quot;: &amp;quot;eyJhbGciOiJSUzI1NiJ9.eyJpZCI6MywibmFtZSI6IktldHVsIiwiZnVsbF9uYW1lIjoiS2V0dWwgQ2hheXlhIiwicm9sZSI6Ikluc3RydWN0b3IiLCJpbnN0aXR1dGlvbl9pZCI6MSwiaW1wZXJzb25hdGVkIjp0cnVlLCJvcmlnaW5hbF91c2VyIjoiIzxVc2VyOjB4MDAwMDdmMzVmYTc5YjVmOD4iLCJleHAiOjE3MTEzMjc0MTV9.U9wDOT618UCkf25MnCiK8W3ybeZv5BSQDNTEPOMUDABAvDd0HWSj3kIGccITHaoVsIykZFsyUDY3rL_M32zmfEXvxZuEleWSqUZGxbjQRIFP1bR_Q5sPESoBdlxVJ4QG8sUGQtuhOzMyH3z4R4ruhz1JpsQlalVZQHCbdtJOI9B4WKhNJ98Dls1fefnzYwLMnTr6e3ttbGGGK5Bm8zSpPvIWmCVNoueKHNptFcNejbU4Mt9RHWHLsTwdAtuywNLCu7li7RRNXo00D5JOUMxL7eB5AiQRpxah8BF7b0lM_Xh7bB56WvD5JTjoNZu3c3AK_EJksGXiFxwlPzNRc8Q&amp;quot;,&lt;br /&gt;
    &amp;quot;success&amp;quot;: true&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Impersonate Controller===&lt;br /&gt;
The ImpersonateController facilitates user impersonation functionality. It includes methods to fetch a list of users available for impersonation based on a provided username parameter and to impersonate a selected user by generating a new JWT token with the necessary user information. The controller ensures that impersonation requests are handled securely, validating permissions before allowing impersonation to occur.&lt;br /&gt;
&lt;br /&gt;
*impersonate_controller.rb file&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 class Api::V1::ImpersonateController &amp;lt; ApplicationController&lt;br /&gt;
&lt;br /&gt;
  # Fetches users to impersonate whose name match the passed parameter&lt;br /&gt;
  def get_users_list&lt;br /&gt;
    users = current_user.get_available_users(params[:user_name])&lt;br /&gt;
    render json: { message: &amp;quot;Successfully Fetched User List!&amp;quot;, userList:users, success:true }, status: :ok&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def is_user_impersonateable?&lt;br /&gt;
    impersonate_user = User.find_by(id: params[:impersonate_id])&lt;br /&gt;
    if impersonate_user&lt;br /&gt;
      return current_user.can_impersonate? impersonate_user&lt;br /&gt;
    end&lt;br /&gt;
    false&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # Impersonates a new user and returns new jwt token&lt;br /&gt;
  def impersonate&lt;br /&gt;
    unless params[:impersonate_id].present?&lt;br /&gt;
      render json: { error: &amp;quot;impersonate_id is required&amp;quot;, success:false }, status: :unprocessable_entity&lt;br /&gt;
      return&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    if is_user_impersonateable?&lt;br /&gt;
      impersonate_user = User.find_by(id: params[:impersonate_id])&lt;br /&gt;
&lt;br /&gt;
      payload = { id: impersonate_user.id, name: impersonate_user.name, full_name: impersonate_user.full_name, role: impersonate_user.role.name,&lt;br /&gt;
                  institution_id: impersonate_user.institution.id, impersonated:true, original_user: current_user }&lt;br /&gt;
      impersonate_user_token = JsonWebToken.encode(payload, 24.hours.from_now)&lt;br /&gt;
&lt;br /&gt;
      render json: { message: &amp;quot;Successfully Impersonated #{impersonate_user.name}!&amp;quot;, token:impersonate_user_token, success:true }, status: :ok&lt;br /&gt;
&lt;br /&gt;
    else&lt;br /&gt;
      render json: { error: &amp;quot;You do not have permission to impersonate this user&amp;quot;, success:false }, status: :forbidden&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===User===&lt;br /&gt;
These methods extend the functionality of the User model. The get_available_users method retrieves users whose full names match a provided parameter. can_impersonate? determines whether the user has the authority to impersonate another user based on their role hierarchy. teaching_assistant_for? checks if the user is a teaching assistant for a given student, and teaching_assistant? determines if the user is a teaching assistant based on their role. Lastly, recursively_parent_of recursively checks for parent-child relationships between user roles.&lt;br /&gt;
&lt;br /&gt;
*user.rb file&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  has_many :assignments, through: :participants&lt;br /&gt;
&lt;br /&gt;
  # Fetches available users whose full names match the provided name prefix (case-insensitive).&lt;br /&gt;
  # Returns a limited list of users (up to 10) who have roles similar or subordinate to the current user's role.&lt;br /&gt;
  def get_available_users(name)&lt;br /&gt;
    lesser_roles = role.subordinate_roles_and_self&lt;br /&gt;
    all_users = User.where('full_name LIKE ?', &amp;quot;%#{name}%&amp;quot;).limit(20)&lt;br /&gt;
    visible_users = all_users.select { |user| lesser_roles.include? user.role }&lt;br /&gt;
    visible_users[0, 10] # the first 10&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # Check if the user can impersonate another user&lt;br /&gt;
  def can_impersonate?(user)&lt;br /&gt;
    return true if role.super_administrator?&lt;br /&gt;
    return true if instructor_for?(user)&lt;br /&gt;
    # Skip below check if user's role is &amp;quot;Instructor&amp;quot;&lt;br /&gt;
    return false if instructor?&lt;br /&gt;
    return true if teaching_assistant_for?(user)&lt;br /&gt;
    # Skip recursively_parent_of check if user's role is &amp;quot;Teaching Assistant&amp;quot;&lt;br /&gt;
    return false if teaching_assistant?&lt;br /&gt;
    return true if recursively_parent_of(user.role)&lt;br /&gt;
    false&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # Check if the current user is an instructor and has any relationship with the given user (student or TA)&lt;br /&gt;
  def instructor_for?(user)&lt;br /&gt;
    return false unless instructor?&lt;br /&gt;
    return true if instructor_for_student?(user)&lt;br /&gt;
    return true if instructor_for_ta?(user)&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # Helper method to check if there are any courses where a student is enrolled in assignments&lt;br /&gt;
  def courses_with_student_participation(courses, student)&lt;br /&gt;
    courses.any? do |course|&lt;br /&gt;
      course.assignments.any? do |assignment|&lt;br /&gt;
        assignment.participants.map(&amp;amp;:user_id).include?(student.id)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # Check if the instructor has any relationship with the given student&lt;br /&gt;
  def instructor_for_student?(student)&lt;br /&gt;
    return false unless student.role.name == 'Student'  # Ensure the role is 'Student'&lt;br /&gt;
&lt;br /&gt;
    instructor = Instructor.find(id)&lt;br /&gt;
&lt;br /&gt;
    # Check if the instructor has any courses where the student is enrolled in an assignment&lt;br /&gt;
    return courses_with_student_participation(Instructor.list_all(Course, instructor),student)&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # Check if the instructor has common courses with the given teaching assistant&lt;br /&gt;
  def instructor_for_ta?(ta)&lt;br /&gt;
    return false unless ta.role.name == 'Teaching Assistant'  # Ensure the role is 'Teaching Assistant'&lt;br /&gt;
&lt;br /&gt;
    instructor = Instructor.find(id)&lt;br /&gt;
&lt;br /&gt;
    # Get all courses taught by the instructor&lt;br /&gt;
    instructor_courses = Instructor.list_all(Course, instructor)&lt;br /&gt;
&lt;br /&gt;
    # Get all courses associated with the TA&lt;br /&gt;
    ta_courses = TaMapping.get_courses(ta)&lt;br /&gt;
&lt;br /&gt;
    # Convert lists to sets for efficient intersection&lt;br /&gt;
    instructor_course_set = instructor_courses.to_set&lt;br /&gt;
    ta_course_set = ta_courses.to_set&lt;br /&gt;
&lt;br /&gt;
    # Check for common courses using set intersection&lt;br /&gt;
    has_common_course = !(instructor_course_set &amp;amp; ta_course_set).empty?&lt;br /&gt;
&lt;br /&gt;
    return has_common_course&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # Check if the user is a teaching assistant for the student's course&lt;br /&gt;
  def teaching_assistant_for?(student)&lt;br /&gt;
    return false unless teaching_assistant?&lt;br /&gt;
    return false unless student.role.name == 'Student'&lt;br /&gt;
&lt;br /&gt;
    # We have to use the Ta object instead of User object&lt;br /&gt;
    # because single table inheritance is not currently functioning&lt;br /&gt;
    ta = Ta.find(id)&lt;br /&gt;
&lt;br /&gt;
    # Check if the TA has any courses where the student is enrolled in an assignment&lt;br /&gt;
    return courses_with_student_participation(TaMapping.get_courses(ta),student)&lt;br /&gt;
&lt;br /&gt;
    false&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # Check if the user is a teaching assistant&lt;br /&gt;
  def teaching_assistant?&lt;br /&gt;
    true if role.ta?&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # Recursively check if parent child relationship exists&lt;br /&gt;
  def recursively_parent_of(user_role)&lt;br /&gt;
    p = user_role.parent&lt;br /&gt;
    return false if p.nil?&lt;br /&gt;
    return true if p == self.role&lt;br /&gt;
    return false if p.super_administrator?&lt;br /&gt;
    recursively_parent_of(p)&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Assignment===&lt;br /&gt;
The Assignment model represents a task or project that is associated with a course. It is linked to a specific course and involves multiple participants (users) who are involved in or responsible for completing the assignment. Each assignment may have various users associated with it, depending on their role or participation within the course.&lt;br /&gt;
&lt;br /&gt;
*assignment.rb file&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  belongs_to :course&lt;br /&gt;
  has_many :participants, dependent: :destroy&lt;br /&gt;
  has_many :users, through: :participants, inverse_of: :assignment&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Course===&lt;br /&gt;
Fixed the assignment mapping&lt;br /&gt;
&lt;br /&gt;
*course.rb file&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  has_many :assignments, dependent: :destroy&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Instructor===&lt;br /&gt;
Created a method to get all the courses assigned to the specific instructor&lt;br /&gt;
&lt;br /&gt;
*instructor.rb file&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def self.list_all(object_type, user_id)&lt;br /&gt;
    object_type.where('instructor_id = ? AND private = 0', user_id)&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===TA===&lt;br /&gt;
Refactored the code to handle a error if TA is not assigned to any course.&lt;br /&gt;
&lt;br /&gt;
*ta.rb file&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  class Ta &amp;lt; User&lt;br /&gt;
    has_many :ta_mappings, dependent: :destroy&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*ta_mapping.rb file&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  #Returns course ids of the TA&lt;br /&gt;
  def self.get_course_ids(user_id)&lt;br /&gt;
    TaMapping.find_by(ta_id: user_id).course_id&lt;br /&gt;
    ta_mapping = TaMapping.find_by(user_id: user_id)&lt;br /&gt;
    ta_mapping&amp;amp;.course_id&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  #Returns courses of the TA&lt;br /&gt;
  def self.get_courses(user_id)&lt;br /&gt;
    Course.where('id = ?', get_course_ids(user_id))&lt;br /&gt;
    course_ids = get_course_ids(user_id)&lt;br /&gt;
&lt;br /&gt;
    return Course.none unless course_ids  # Return Course.none if course_ids is nil&lt;br /&gt;
&lt;br /&gt;
    Course.where(id: course_ids)&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Design Pattern==&lt;br /&gt;
===Facade Design Pattern===&lt;br /&gt;
The Api::V1::ImpersonateController acts as a facade by providing a simplified interface to interact with more complex subsystems (such as user authentication, authorization, and user management) within the application. It encapsulates the logic for impersonating users and fetching user lists behind a single interface.&lt;br /&gt;
&lt;br /&gt;
===Strategy Design Pattern===&lt;br /&gt;
The is_user_impersonateable? method implements a strategy for determining whether the current user has permission to impersonate another user. It checks if the impersonated user exists and if the current user has the necessary permissions to impersonate them. This method encapsulates a specific algorithm for evaluating impersonation permissions, which can be changed or extended independently of the controller logic.&lt;br /&gt;
Overall, these design pattern principles contribute to a modular and maintainable design by promoting encapsulation, separation of concerns, and flexibility in the implementation of complex behaviors.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Files added / modified ==&lt;br /&gt;
&lt;br /&gt;
*reimplementation-back-end/app/models/user.rb&lt;br /&gt;
*reimplementation-back-end/app/controllers/api/v1/impersonate_controller.rb&lt;br /&gt;
*reimplementation-back-end/app/models/course.rb&lt;br /&gt;
*reimplementation-back-end/app/models/instructor.rb&lt;br /&gt;
*reimplementation-back-end/app/models/ta.rb&lt;br /&gt;
*reimplementation-back-end/app/models/ta_mapping.rb&lt;br /&gt;
*reimplementation-back-end/config/routes.rb&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==List of Users in Database==&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! ID !! Email !! Password !! Role&lt;br /&gt;
|-&lt;br /&gt;
| 1 || admin2@example.com || password123 || Super-Administrator&lt;br /&gt;
|-&lt;br /&gt;
| 2 || jay@example.com || password123 || Administration&lt;br /&gt;
|-&lt;br /&gt;
| 3 || k2l@example.com || password123 || Instructor&lt;br /&gt;
|-&lt;br /&gt;
| 4 || mbhande@example.com || password123 || TA&lt;br /&gt;
|-&lt;br /&gt;
| 7 || dpatesl@example.com || password123 || Student&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Testing on Postman==&lt;br /&gt;
&lt;br /&gt;
Postman was used to manually test the additional method in impersonate_controller.rb, as well as the actions and routes of the corresponding controllers. Before testing any of these methods with Postman, submit a request to /login using the user_name and password fields, which will send an authentication token. This token must be added to Postman's 'Authorization' tab as a 'Bearer token' before any further requests can be made. Postman collection [https://www.postman.com/blue-water-189861/workspace/oodd-project-3/collection/13428669-4d663583-0b90-4316-bd6c-9441ea576085?action=share&amp;amp;creator=13428669 link]&lt;br /&gt;
&lt;br /&gt;
*First of all, fork the expertiza workspace in order to work upon it&lt;br /&gt;
[[File:Fork-expertiza-postman.png | 800px]]&lt;br /&gt;
&lt;br /&gt;
*Fetch User List which can be impersonated (For eg: If Instructor fetches list he can see matched TAs and Students only)&lt;br /&gt;
[[File:Userlist.jpg | 800px]]&lt;br /&gt;
&lt;br /&gt;
* Login with provided credentials and copy the token&lt;br /&gt;
[[File:Postman-1.jpg | 800px]]&lt;br /&gt;
&lt;br /&gt;
*In the Expertiza/Authorization paste the token and save&lt;br /&gt;
[[File:Postman-2.jpg | 800px]]&lt;br /&gt;
&lt;br /&gt;
*Put the id for the user to be impersonated&lt;br /&gt;
[[File:Postman-3.jpg | 800px]]&lt;br /&gt;
&lt;br /&gt;
*Success message if the user is impersonable&lt;br /&gt;
[[File:Postman-4.jpg | 800px]]&lt;br /&gt;
&lt;br /&gt;
*Failure message if the user is not impersonable (Here instructor is trying to impersonate admin)&lt;br /&gt;
[[File:Inst-admin.jpg | 800px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Swagger UI Documentation==&lt;br /&gt;
[[File:Swagger E2421.png | 1000px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Here is the demo video of working of the project [https://youtu.be/cq6k05-q8UI]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Team==&lt;br /&gt;
'''Mentor''' &amp;lt;br&amp;gt;&lt;br /&gt;
*Chetana Chunduru &amp;lt;cchetan2@ncsu.edu&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Students'''&amp;lt;br&amp;gt;&lt;br /&gt;
*Devansh Shah &amp;lt;dshah8@ncsu.edu&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
*Jay Patel &amp;lt;jhpatel9@ncsu.edu&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
*Mihir Bhanderi &amp;lt;mbhande2@ncsu.edu&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Pull Request==&lt;br /&gt;
*[https://github.com/expertiza/reimplementation-back-end/pull/88]&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
*[https://docs.google.com/document/d/1MzdTjsULAMI1ZJRbf-xvThkSxxUXjk-hNMQ9DPdhmrI/edit#heading=h.vh7jk2b6nlb2 Project Instructions]&lt;/div&gt;</summary>
		<author><name>Mbhande2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2024_-_E2421._Reimplement_impersonating_users_(within_impersonate_controller.rb)_-_Final_Project&amp;diff=156201</id>
		<title>CSC/ECE 517 Spring 2024 - E2421. Reimplement impersonating users (within impersonate controller.rb) - Final Project</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2024_-_E2421._Reimplement_impersonating_users_(within_impersonate_controller.rb)_-_Final_Project&amp;diff=156201"/>
		<updated>2024-04-23T23:09:52Z</updated>

		<summary type="html">&lt;p&gt;Mbhande2: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Expertiza==&lt;br /&gt;
&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is a [http://rubyonrails.org/ Ruby on Rails] based open source project. Instructors have the ability to add new projects, assignments, etc., as well as edit existing ones. Later on, they can view student submissions and grade them. Students can also use Expertiza to organize into teams to work on different projects and assignments and submit their work. They can also review other students' submissions.&lt;br /&gt;
&lt;br /&gt;
==Project Overview==&lt;br /&gt;
&lt;br /&gt;
The goal of this project is to update the backend code for the user impersonation feature in the new version of Expertiza. The existing implementation relies on sessions, which is incompatible with the new implementation that uses JWT (JSON Web Tokens) for authentication and JSON responses. The primary challenge is to migrate the impersonation logic from session-based management to JWT-based authentication while preserving the same functionality. This reimplementation requires planning for the communication between the backend and frontend, which may necessitate modifications to existing files or the creation of new files beyond the impersonate_controller.rb file.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Design Pattern==&lt;br /&gt;
===Facade Design Pattern===&lt;br /&gt;
The Api::V1::ImpersonateController acts as a facade by providing a simplified interface to interact with more complex subsystems (such as user authentication, authorization, and user management) within the application. It encapsulates the logic for impersonating users and fetching user lists behind a single interface.&lt;br /&gt;
&lt;br /&gt;
===Strategy Design Pattern===&lt;br /&gt;
The is_user_impersonateable? method implements a strategy for determining whether the current user has permission to impersonate another user. It checks if the impersonated user exists and if the current user has the necessary permissions to impersonate them. This method encapsulates a specific algorithm for evaluating impersonation permissions, which can be changed or extended independently of the controller logic.&lt;br /&gt;
Overall, these design pattern principles contribute to a modular and maintainable design by promoting encapsulation, separation of concerns, and flexibility in the implementation of complex behaviors.&lt;br /&gt;
&lt;br /&gt;
==Implementation==&lt;br /&gt;
&lt;br /&gt;
===UML Diagram===&lt;br /&gt;
The following UML diagram shows the association between models we will be working on&lt;br /&gt;
&lt;br /&gt;
[[File:UML-Diagram-E2421.jpeg]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Hierarchy Diagram===&lt;br /&gt;
Visualization of the hierarchical structure&lt;br /&gt;
&lt;br /&gt;
[[File:Hierarchy-diagram E2421.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Request===&lt;br /&gt;
&lt;br /&gt;
*GET: {BASE_URL}/api/v1/impersonate/:username&lt;br /&gt;
   - Response:&lt;br /&gt;
&lt;br /&gt;
    &amp;quot;message&amp;quot;: &amp;quot;Successfully Fetched User List!&amp;quot;,&lt;br /&gt;
    &amp;quot;userList&amp;quot;: [&lt;br /&gt;
        {&lt;br /&gt;
            &amp;quot;id&amp;quot;: 4,&lt;br /&gt;
            &amp;quot;name&amp;quot;: &amp;quot;Mihir&amp;quot;,&lt;br /&gt;
            &amp;quot;full_name&amp;quot;: &amp;quot;Mihir BHanderi&amp;quot;,&lt;br /&gt;
            &amp;quot;email&amp;quot;: &amp;quot;mbhande@example.com&amp;quot;,&lt;br /&gt;
            &amp;quot;email_on_review&amp;quot;: false,&lt;br /&gt;
            &amp;quot;email_on_submission&amp;quot;: false,&lt;br /&gt;
            &amp;quot;email_on_review_of_review&amp;quot;: false,&lt;br /&gt;
            &amp;quot;role&amp;quot;: {&lt;br /&gt;
                &amp;quot;id&amp;quot;: 4,&lt;br /&gt;
                &amp;quot;name&amp;quot;: &amp;quot;Teaching Assistant&amp;quot;&lt;br /&gt;
            },&lt;br /&gt;
            &amp;quot;institution&amp;quot;: {&lt;br /&gt;
                &amp;quot;id&amp;quot;: 1,&lt;br /&gt;
                &amp;quot;name&amp;quot;: &amp;quot;North Carolina State University&amp;quot;&lt;br /&gt;
            },&lt;br /&gt;
            &amp;quot;parent&amp;quot;: {&lt;br /&gt;
                &amp;quot;id&amp;quot;: null,&lt;br /&gt;
                &amp;quot;name&amp;quot;: null&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
    ],&lt;br /&gt;
    &amp;quot;success&amp;quot;: true&lt;br /&gt;
&lt;br /&gt;
*POST: {BASE_URL}/api/v1/impersonate&lt;br /&gt;
   - Payload: impersonate_id&lt;br /&gt;
   - Response: &lt;br /&gt;
&lt;br /&gt;
     &amp;quot;message&amp;quot;: &amp;quot;Successfully Impersonated Ketul!&amp;quot;,&lt;br /&gt;
     &amp;quot;token&amp;quot;: &amp;quot;eyJhbGciOiJSUzI1NiJ9.eyJpZCI6MywibmFtZSI6IktldHVsIiwiZnVsbF9uYW1lIjoiS2V0dWwgQ2hheXlhIiwicm9sZSI6Ikluc3RydWN0b3IiLCJpbnN0aXR1dGlvbl9pZCI6MSwiaW1wZXJzb25hdGVkIjp0cnVlLCJvcmlnaW5hbF91c2VyIjoiIzxVc2VyOjB4MDAwMDdmMzVmYTc5YjVmOD4iLCJleHAiOjE3MTEzMjc0MTV9.U9wDOT618UCkf25MnCiK8W3ybeZv5BSQDNTEPOMUDABAvDd0HWSj3kIGccITHaoVsIykZFsyUDY3rL_M32zmfEXvxZuEleWSqUZGxbjQRIFP1bR_Q5sPESoBdlxVJ4QG8sUGQtuhOzMyH3z4R4ruhz1JpsQlalVZQHCbdtJOI9B4WKhNJ98Dls1fefnzYwLMnTr6e3ttbGGGK5Bm8zSpPvIWmCVNoueKHNptFcNejbU4Mt9RHWHLsTwdAtuywNLCu7li7RRNXo00D5JOUMxL7eB5AiQRpxah8BF7b0lM_Xh7bB56WvD5JTjoNZu3c3AK_EJksGXiFxwlPzNRc8Q&amp;quot;,&lt;br /&gt;
    &amp;quot;success&amp;quot;: true&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Impersonate Controller===&lt;br /&gt;
The ImpersonateController facilitates user impersonation functionality. It includes methods to fetch a list of users available for impersonation based on a provided username parameter and to impersonate a selected user by generating a new JWT token with the necessary user information. The controller ensures that impersonation requests are handled securely, validating permissions before allowing impersonation to occur.&lt;br /&gt;
&lt;br /&gt;
*impersonate_controller.rb file&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 class Api::V1::ImpersonateController &amp;lt; ApplicationController&lt;br /&gt;
&lt;br /&gt;
  # Fetches users to impersonate whose name match the passed parameter&lt;br /&gt;
  def get_users_list&lt;br /&gt;
    users = current_user.get_available_users(params[:user_name])&lt;br /&gt;
    render json: { message: &amp;quot;Successfully Fetched User List!&amp;quot;, userList:users, success:true }, status: :ok&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def is_user_impersonateable?&lt;br /&gt;
    impersonate_user = User.find_by(id: params[:impersonate_id])&lt;br /&gt;
    if impersonate_user&lt;br /&gt;
      return current_user.can_impersonate? impersonate_user&lt;br /&gt;
    end&lt;br /&gt;
    false&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # Impersonates a new user and returns new jwt token&lt;br /&gt;
  def impersonate&lt;br /&gt;
    unless params[:impersonate_id].present?&lt;br /&gt;
      render json: { error: &amp;quot;impersonate_id is required&amp;quot;, success:false }, status: :unprocessable_entity&lt;br /&gt;
      return&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    if is_user_impersonateable?&lt;br /&gt;
      impersonate_user = User.find_by(id: params[:impersonate_id])&lt;br /&gt;
&lt;br /&gt;
      payload = { id: impersonate_user.id, name: impersonate_user.name, full_name: impersonate_user.full_name, role: impersonate_user.role.name,&lt;br /&gt;
                  institution_id: impersonate_user.institution.id, impersonated:true, original_user: current_user }&lt;br /&gt;
      impersonate_user_token = JsonWebToken.encode(payload, 24.hours.from_now)&lt;br /&gt;
&lt;br /&gt;
      render json: { message: &amp;quot;Successfully Impersonated #{impersonate_user.name}!&amp;quot;, token:impersonate_user_token, success:true }, status: :ok&lt;br /&gt;
&lt;br /&gt;
    else&lt;br /&gt;
      render json: { error: &amp;quot;You do not have permission to impersonate this user&amp;quot;, success:false }, status: :forbidden&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===User===&lt;br /&gt;
These methods extend the functionality of the User model. The get_available_users method retrieves users whose full names match a provided parameter. can_impersonate? determines whether the user has the authority to impersonate another user based on their role hierarchy. teaching_assistant_for? checks if the user is a teaching assistant for a given student, and teaching_assistant? determines if the user is a teaching assistant based on their role. Lastly, recursively_parent_of recursively checks for parent-child relationships between user roles.&lt;br /&gt;
&lt;br /&gt;
*user.rb file&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  has_many :assignments, through: :participants&lt;br /&gt;
&lt;br /&gt;
  # Fetches available users whose full names match the provided name prefix (case-insensitive).&lt;br /&gt;
  # Returns a limited list of users (up to 10) who have roles similar or subordinate to the current user's role.&lt;br /&gt;
  def get_available_users(name)&lt;br /&gt;
    lesser_roles = role.subordinate_roles_and_self&lt;br /&gt;
    all_users = User.where('full_name LIKE ?', &amp;quot;%#{name}%&amp;quot;).limit(20)&lt;br /&gt;
    visible_users = all_users.select { |user| lesser_roles.include? user.role }&lt;br /&gt;
    visible_users[0, 10] # the first 10&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # Check if the user can impersonate another user&lt;br /&gt;
  def can_impersonate?(user)&lt;br /&gt;
    return true if role.super_administrator?&lt;br /&gt;
    return true if instructor_for?(user)&lt;br /&gt;
    # Skip below check if user's role is &amp;quot;Instructor&amp;quot;&lt;br /&gt;
    return false if instructor?&lt;br /&gt;
    return true if teaching_assistant_for?(user)&lt;br /&gt;
    # Skip recursively_parent_of check if user's role is &amp;quot;Teaching Assistant&amp;quot;&lt;br /&gt;
    return false if teaching_assistant?&lt;br /&gt;
    return true if recursively_parent_of(user.role)&lt;br /&gt;
    false&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # Check if the current user is an instructor and has any relationship with the given user (student or TA)&lt;br /&gt;
  def instructor_for?(user)&lt;br /&gt;
    return false unless instructor?&lt;br /&gt;
    return true if instructor_for_student?(user)&lt;br /&gt;
    return true if instructor_for_ta?(user)&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # Helper method to check if there are any courses where a student is enrolled in assignments&lt;br /&gt;
  def courses_with_student_participation(courses, student)&lt;br /&gt;
    courses.any? do |course|&lt;br /&gt;
      course.assignments.any? do |assignment|&lt;br /&gt;
        assignment.participants.map(&amp;amp;:user_id).include?(student.id)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # Check if the instructor has any relationship with the given student&lt;br /&gt;
  def instructor_for_student?(student)&lt;br /&gt;
    return false unless student.role.name == 'Student'  # Ensure the role is 'Student'&lt;br /&gt;
&lt;br /&gt;
    instructor = Instructor.find(id)&lt;br /&gt;
&lt;br /&gt;
    # Check if the instructor has any courses where the student is enrolled in an assignment&lt;br /&gt;
    return courses_with_student_participation(Instructor.list_all(Course, instructor),student)&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # Check if the instructor has common courses with the given teaching assistant&lt;br /&gt;
  def instructor_for_ta?(ta)&lt;br /&gt;
    return false unless ta.role.name == 'Teaching Assistant'  # Ensure the role is 'Teaching Assistant'&lt;br /&gt;
&lt;br /&gt;
    instructor = Instructor.find(id)&lt;br /&gt;
&lt;br /&gt;
    # Get all courses taught by the instructor&lt;br /&gt;
    instructor_courses = Instructor.list_all(Course, instructor)&lt;br /&gt;
&lt;br /&gt;
    # Get all courses associated with the TA&lt;br /&gt;
    ta_courses = TaMapping.get_courses(ta)&lt;br /&gt;
&lt;br /&gt;
    # Convert lists to sets for efficient intersection&lt;br /&gt;
    instructor_course_set = instructor_courses.to_set&lt;br /&gt;
    ta_course_set = ta_courses.to_set&lt;br /&gt;
&lt;br /&gt;
    # Check for common courses using set intersection&lt;br /&gt;
    has_common_course = !(instructor_course_set &amp;amp; ta_course_set).empty?&lt;br /&gt;
&lt;br /&gt;
    return has_common_course&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # Check if the user is a teaching assistant for the student's course&lt;br /&gt;
  def teaching_assistant_for?(student)&lt;br /&gt;
    return false unless teaching_assistant?&lt;br /&gt;
    return false unless student.role.name == 'Student'&lt;br /&gt;
&lt;br /&gt;
    # We have to use the Ta object instead of User object&lt;br /&gt;
    # because single table inheritance is not currently functioning&lt;br /&gt;
    ta = Ta.find(id)&lt;br /&gt;
&lt;br /&gt;
    # Check if the TA has any courses where the student is enrolled in an assignment&lt;br /&gt;
    return courses_with_student_participation(TaMapping.get_courses(ta),student)&lt;br /&gt;
&lt;br /&gt;
    false&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # Check if the user is a teaching assistant&lt;br /&gt;
  def teaching_assistant?&lt;br /&gt;
    true if role.ta?&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # Recursively check if parent child relationship exists&lt;br /&gt;
  def recursively_parent_of(user_role)&lt;br /&gt;
    p = user_role.parent&lt;br /&gt;
    return false if p.nil?&lt;br /&gt;
    return true if p == self.role&lt;br /&gt;
    return false if p.super_administrator?&lt;br /&gt;
    recursively_parent_of(p)&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Assignment===&lt;br /&gt;
The Assignment model represents a task or project that is associated with a course. It is linked to a specific course and involves multiple participants (users) who are involved in or responsible for completing the assignment. Each assignment may have various users associated with it, depending on their role or participation within the course.&lt;br /&gt;
&lt;br /&gt;
*assignment.rb file&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  belongs_to :course&lt;br /&gt;
  has_many :participants, dependent: :destroy&lt;br /&gt;
  has_many :users, through: :participants, inverse_of: :assignment&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Course===&lt;br /&gt;
Fixed the assignment mapping&lt;br /&gt;
&lt;br /&gt;
*course.rb file&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  has_many :assignments, dependent: :destroy&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Instructor===&lt;br /&gt;
Created a method to get all the courses assigned to the specific instructor&lt;br /&gt;
&lt;br /&gt;
*instructor.rb file&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def self.list_all(object_type, user_id)&lt;br /&gt;
    object_type.where('instructor_id = ? AND private = 0', user_id)&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===TA===&lt;br /&gt;
Refactored the code to handle a error if TA is not assigned to any course.&lt;br /&gt;
&lt;br /&gt;
*ta.rb file&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  class Ta &amp;lt; User&lt;br /&gt;
    has_many :ta_mappings, dependent: :destroy&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*ta_mapping.rb file&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  #Returns course ids of the TA&lt;br /&gt;
  def self.get_course_ids(user_id)&lt;br /&gt;
    TaMapping.find_by(ta_id: user_id).course_id&lt;br /&gt;
    ta_mapping = TaMapping.find_by(user_id: user_id)&lt;br /&gt;
    ta_mapping&amp;amp;.course_id&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  #Returns courses of the TA&lt;br /&gt;
  def self.get_courses(user_id)&lt;br /&gt;
    Course.where('id = ?', get_course_ids(user_id))&lt;br /&gt;
    course_ids = get_course_ids(user_id)&lt;br /&gt;
&lt;br /&gt;
    return Course.none unless course_ids  # Return Course.none if course_ids is nil&lt;br /&gt;
&lt;br /&gt;
    Course.where(id: course_ids)&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Files added / modified ==&lt;br /&gt;
&lt;br /&gt;
*reimplementation-back-end/app/models/user.rb&lt;br /&gt;
*reimplementation-back-end/app/controllers/api/v1/impersonate_controller.rb&lt;br /&gt;
*reimplementation-back-end/app/models/course.rb&lt;br /&gt;
*reimplementation-back-end/app/models/instructor.rb&lt;br /&gt;
*reimplementation-back-end/app/models/ta.rb&lt;br /&gt;
*reimplementation-back-end/app/models/ta_mapping.rb&lt;br /&gt;
*reimplementation-back-end/config/routes.rb&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==List of Users in Database==&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! ID !! Email !! Password !! Role&lt;br /&gt;
|-&lt;br /&gt;
| 1 || admin2@example.com || password123 || Super-Administrator&lt;br /&gt;
|-&lt;br /&gt;
| 2 || jay@example.com || password123 || Administration&lt;br /&gt;
|-&lt;br /&gt;
| 3 || k2l@example.com || password123 || Instructor&lt;br /&gt;
|-&lt;br /&gt;
| 4 || mbhande@example.com || password123 || TA&lt;br /&gt;
|-&lt;br /&gt;
| 7 || dpatesl@example.com || password123 || Student&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==Testing on Postman==&lt;br /&gt;
&lt;br /&gt;
Postman was used to manually test the additional method in impersonate_controller.rb, as well as the actions and routes of the corresponding controllers. Before testing any of these methods with Postman, submit a request to /login using the user_name and password fields, which will send an authentication token. This token must be added to Postman's 'Authorization' tab as a 'Bearer token' before any further requests can be made. Postman collection [https://www.postman.com/blue-water-189861/workspace/oodd-project-3/collection/13428669-4d663583-0b90-4316-bd6c-9441ea576085?action=share&amp;amp;creator=13428669 link]&lt;br /&gt;
&lt;br /&gt;
*First of all, fork the expertiza workspace in order to work upon it&lt;br /&gt;
[[File:Fork-expertiza-postman.png | 800px]]&lt;br /&gt;
&lt;br /&gt;
*Fetch User List which can be impersonated (For eg: If Instructor fetches list he can see matched TAs and Students only)&lt;br /&gt;
[[File:Userlist.jpg | 800px]]&lt;br /&gt;
&lt;br /&gt;
* Login with provided credentials and copy the token&lt;br /&gt;
[[File:Postman-1.jpg | 800px]]&lt;br /&gt;
&lt;br /&gt;
*In the Expertiza/Authorization paste the token and save&lt;br /&gt;
[[File:Postman-2.jpg | 800px]]&lt;br /&gt;
&lt;br /&gt;
*Put the id for the user to be impersonated&lt;br /&gt;
[[File:Postman-3.jpg | 800px]]&lt;br /&gt;
&lt;br /&gt;
*Success message if the user is impersonable&lt;br /&gt;
[[File:Postman-4.jpg | 800px]]&lt;br /&gt;
&lt;br /&gt;
*Failure message if the user is not impersonable (Here instructor is trying to impersonate admin)&lt;br /&gt;
[[File:Inst-admin.jpg | 800px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Swagger UI Documentation==&lt;br /&gt;
[[File:Swagger E2421.png | 1000px]]&lt;br /&gt;
&lt;br /&gt;
Here is the video of successfully running the tests [https://www.loom.com/share/b1b6b7e52a884a2f8e097e25a53e77f3?sid=e80f4d44-4667-4874-8ef8-de10f8ac1bb2]&lt;br /&gt;
&lt;br /&gt;
Here is the demo video of working of the project [https://youtu.be/cq6k05-q8UI]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Team==&lt;br /&gt;
'''Mentor''' &amp;lt;br&amp;gt;&lt;br /&gt;
*Chetana Chunduru &amp;lt;cchetan2@ncsu.edu&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Students'''&amp;lt;br&amp;gt;&lt;br /&gt;
*Devansh Shah &amp;lt;dshah8@ncsu.edu&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
*Jay Patel &amp;lt;jhpatel9@ncsu.edu&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
*Mihir Bhanderi &amp;lt;mbhande2@ncsu.edu&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Pull Request==&lt;br /&gt;
*[https://github.com/expertiza/reimplementation-back-end/pull/88]&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
*[https://docs.google.com/document/d/1MzdTjsULAMI1ZJRbf-xvThkSxxUXjk-hNMQ9DPdhmrI/edit#heading=h.vh7jk2b6nlb2 Project Instructions]&lt;/div&gt;</summary>
		<author><name>Mbhande2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=File:Swagger_E2421.png&amp;diff=156196</id>
		<title>File:Swagger E2421.png</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=File:Swagger_E2421.png&amp;diff=156196"/>
		<updated>2024-04-23T23:06:44Z</updated>

		<summary type="html">&lt;p&gt;Mbhande2: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Mbhande2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=File:Swagger.png&amp;diff=156195</id>
		<title>File:Swagger.png</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=File:Swagger.png&amp;diff=156195"/>
		<updated>2024-04-23T23:06:12Z</updated>

		<summary type="html">&lt;p&gt;Mbhande2: Mbhande2 reverted File:Swagger.png to an old version&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Mbhande2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=File:Swagger.png&amp;diff=156191</id>
		<title>File:Swagger.png</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=File:Swagger.png&amp;diff=156191"/>
		<updated>2024-04-23T23:02:34Z</updated>

		<summary type="html">&lt;p&gt;Mbhande2: Mbhande2 uploaded a new version of File:Swagger.png&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Mbhande2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=File:Hierarchy-diagram_E2421.png&amp;diff=156156</id>
		<title>File:Hierarchy-diagram E2421.png</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=File:Hierarchy-diagram_E2421.png&amp;diff=156156"/>
		<updated>2024-04-23T22:29:40Z</updated>

		<summary type="html">&lt;p&gt;Mbhande2: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Mbhande2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=File:UML-Diagram-E2421.jpeg&amp;diff=156142</id>
		<title>File:UML-Diagram-E2421.jpeg</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=File:UML-Diagram-E2421.jpeg&amp;diff=156142"/>
		<updated>2024-04-23T22:24:37Z</updated>

		<summary type="html">&lt;p&gt;Mbhande2: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Mbhande2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2024_-_E2421._Reimplement_impersonating_users_(within_impersonate_controller.rb)_-_Final_Project&amp;diff=155106</id>
		<title>CSC/ECE 517 Spring 2024 - E2421. Reimplement impersonating users (within impersonate controller.rb) - Final Project</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2024_-_E2421._Reimplement_impersonating_users_(within_impersonate_controller.rb)_-_Final_Project&amp;diff=155106"/>
		<updated>2024-04-08T20:51:29Z</updated>

		<summary type="html">&lt;p&gt;Mbhande2: Created page with &amp;quot;==Expertiza==  [http://expertiza.ncsu.edu/ Expertiza] is a [http://rubyonrails.org/ Ruby on Rails] based open source project. Instructors have the ability to add new projects, assignments, etc., as well as edit existing ones. Later on, they can view student submissions and grade them. Students can also use Expertiza to organize into teams to work on different projects and assignments and submit their work. They can also review other students' submissions.  ==Project Over...&amp;quot;&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Expertiza==&lt;br /&gt;
&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is a [http://rubyonrails.org/ Ruby on Rails] based open source project. Instructors have the ability to add new projects, assignments, etc., as well as edit existing ones. Later on, they can view student submissions and grade them. Students can also use Expertiza to organize into teams to work on different projects and assignments and submit their work. They can also review other students' submissions.&lt;br /&gt;
&lt;br /&gt;
==Project Overview==&lt;br /&gt;
&lt;br /&gt;
The goal of this project is to update the backend code for the user impersonation feature in the new version of Expertiza. The existing implementation relies on sessions, which is incompatible with the new implementation that uses JWT (JSON Web Tokens) for authentication and JSON responses. The primary challenge is to migrate the impersonation logic from session-based management to JWT-based authentication while preserving the same functionality. This reimplementation requires planning for the communication between the backend and frontend, which may necessitate modifications to existing files or the creation of new files beyond the impersonate_controller.rb file.&lt;br /&gt;
&lt;br /&gt;
==Design Document==&lt;br /&gt;
===Current Status===&lt;br /&gt;
We have successfully implemented the impersonate_users.controller and the necessary methods to generate a new JWT token with the required user information. The can_impersonate method in the user.rb file has been implemented to determine which roles have the authority to impersonate other users.&lt;br /&gt;
&lt;br /&gt;
We have also thoroughly tested the API and functionality using Postman and created a detailed video showcasing the tests performed.&lt;br /&gt;
&lt;br /&gt;
===Issues and Plan of Action===&lt;br /&gt;
'''Updated UML Diagram'''&lt;br /&gt;
&lt;br /&gt;
[[File:E2421-Updated UML.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
1. TA-Student Mapping: The current implementation does not have a mapping between Teaching Assistants (TAs) and students, which is preventing TAs from accessing specific courses for the students they are impersonating. Currently, TAs have access to all courses, which needed to be fixed. So, we will work on implementing a mapping between TAs and students to ensure that TAs can only access courses for the students they are assigned to.&lt;br /&gt;
&lt;br /&gt;
2. Refactoring Code: We will work on refactoring some of the code, including changing naming conventions based on the feedback received from the first project.&lt;br /&gt;
&lt;br /&gt;
3. Testing Improvement: We will enhance the testing process by:&lt;br /&gt;
* Incorporating Swagger UI to test the API endpoints.&lt;br /&gt;
* Recording and uploading a video demonstrating the execution of automated test cases.&lt;br /&gt;
4. Documentation Update: We will update the wiki page to address the following issues:&lt;br /&gt;
* Update the Role Hierarchy diagram to accurately reflect each role's permissions and get a clear idea of impersonating Hierarchy.&lt;br /&gt;
* Improve the flow between the five sections under Implementation and provide an explanation for the order in which these topics are covered.&lt;br /&gt;
* Include more detailed information about the tests performed, such as the conditions tested for.&lt;br /&gt;
* Replace the illegible code snippets in the screenshots with larger, more readable images or code blocks.&lt;br /&gt;
&lt;br /&gt;
By addressing these issues and implementing the necessary improvements, we will aim to deliver a comprehensive and well-documented implementation of the impersonate_users functionality.&lt;br /&gt;
&lt;br /&gt;
=Previous Work=&lt;br /&gt;
==Implementation==&lt;br /&gt;
&lt;br /&gt;
===UML Diagram===&lt;br /&gt;
The following UML diagram shows the association between models we will be working on&lt;br /&gt;
&lt;br /&gt;
[[File:Uml reimplement impersonate.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Hierarchy Diagram===&lt;br /&gt;
Visualization of the hierarchical structure&lt;br /&gt;
&lt;br /&gt;
[[File:User-hierarchy.jpg]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Request===&lt;br /&gt;
&lt;br /&gt;
*GET: {BASE_URL}/api/v1/impersonate/:username&lt;br /&gt;
   - Response:&lt;br /&gt;
&lt;br /&gt;
    &amp;quot;message&amp;quot;: &amp;quot;Successfully Fetched User List!&amp;quot;,&lt;br /&gt;
    &amp;quot;userList&amp;quot;: [&lt;br /&gt;
        {&lt;br /&gt;
            &amp;quot;id&amp;quot;: 4,&lt;br /&gt;
            &amp;quot;name&amp;quot;: &amp;quot;Mihir&amp;quot;,&lt;br /&gt;
            &amp;quot;full_name&amp;quot;: &amp;quot;Mihir BHanderi&amp;quot;,&lt;br /&gt;
            &amp;quot;email&amp;quot;: &amp;quot;mbhande@example.com&amp;quot;,&lt;br /&gt;
            &amp;quot;email_on_review&amp;quot;: false,&lt;br /&gt;
            &amp;quot;email_on_submission&amp;quot;: false,&lt;br /&gt;
            &amp;quot;email_on_review_of_review&amp;quot;: false,&lt;br /&gt;
            &amp;quot;role&amp;quot;: {&lt;br /&gt;
                &amp;quot;id&amp;quot;: 4,&lt;br /&gt;
                &amp;quot;name&amp;quot;: &amp;quot;Teaching Assistant&amp;quot;&lt;br /&gt;
            },&lt;br /&gt;
            &amp;quot;institution&amp;quot;: {&lt;br /&gt;
                &amp;quot;id&amp;quot;: 1,&lt;br /&gt;
                &amp;quot;name&amp;quot;: &amp;quot;North Carolina State University&amp;quot;&lt;br /&gt;
            },&lt;br /&gt;
            &amp;quot;parent&amp;quot;: {&lt;br /&gt;
                &amp;quot;id&amp;quot;: null,&lt;br /&gt;
                &amp;quot;name&amp;quot;: null&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
    ],&lt;br /&gt;
    &amp;quot;success&amp;quot;: true&lt;br /&gt;
&lt;br /&gt;
*POST: {BASE_URL}/api/v1/impersonate&lt;br /&gt;
   - Payload: impersonate_id&lt;br /&gt;
   - Response: &lt;br /&gt;
&lt;br /&gt;
     &amp;quot;message&amp;quot;: &amp;quot;Successfully Impersonated Ketul!&amp;quot;,&lt;br /&gt;
     &amp;quot;token&amp;quot;: &amp;quot;eyJhbGciOiJSUzI1NiJ9.eyJpZCI6MywibmFtZSI6IktldHVsIiwiZnVsbF9uYW1lIjoiS2V0dWwgQ2hheXlhIiwicm9sZSI6Ikluc3RydWN0b3IiLCJpbnN0aXR1dGlvbl9pZCI6MSwiaW1wZXJzb25hdGVkIjp0cnVlLCJvcmlnaW5hbF91c2VyIjoiIzxVc2VyOjB4MDAwMDdmMzVmYTc5YjVmOD4iLCJleHAiOjE3MTEzMjc0MTV9.U9wDOT618UCkf25MnCiK8W3ybeZv5BSQDNTEPOMUDABAvDd0HWSj3kIGccITHaoVsIykZFsyUDY3rL_M32zmfEXvxZuEleWSqUZGxbjQRIFP1bR_Q5sPESoBdlxVJ4QG8sUGQtuhOzMyH3z4R4ruhz1JpsQlalVZQHCbdtJOI9B4WKhNJ98Dls1fefnzYwLMnTr6e3ttbGGGK5Bm8zSpPvIWmCVNoueKHNptFcNejbU4Mt9RHWHLsTwdAtuywNLCu7li7RRNXo00D5JOUMxL7eB5AiQRpxah8BF7b0lM_Xh7bB56WvD5JTjoNZu3c3AK_EJksGXiFxwlPzNRc8Q&amp;quot;,&lt;br /&gt;
    &amp;quot;success&amp;quot;: true&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Impersonate Controller===&lt;br /&gt;
The ImpersonateController facilitates user impersonation functionality. It includes methods to fetch a list of users available for impersonation based on a provided username parameter and to impersonate a selected user by generating a new JWT token with the necessary user information. The controller ensures that impersonation requests are handled securely, validating permissions before allowing impersonation to occur.&lt;br /&gt;
&lt;br /&gt;
*impersonate_controller.rb file&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 class Api::V1::ImpersonateController &amp;lt; ApplicationController&lt;br /&gt;
&lt;br /&gt;
  # Fetches users to impersonate whose name match the passed parameter&lt;br /&gt;
  def get_users_list&lt;br /&gt;
    users = current_user.get_available_users(params[:user_name])&lt;br /&gt;
    render json: { message: &amp;quot;Successfully Fetched User List!&amp;quot;, userList:users, success:true }, status: :ok&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def check_if_user_impersonateable?&lt;br /&gt;
    impersonate_user = User.find_by(id: params[:impersonate_id])&lt;br /&gt;
    if impersonate_user&lt;br /&gt;
      return current_user.can_impersonate? impersonate_user&lt;br /&gt;
    end&lt;br /&gt;
    false&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # Impersonates a new user and returns new jwt token&lt;br /&gt;
  def impersonate&lt;br /&gt;
    unless params[:impersonate_id].present?&lt;br /&gt;
      render json: { error: &amp;quot;impersonate_id is required&amp;quot;, success:false }, status: :unprocessable_entity&lt;br /&gt;
      return&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    if check_if_user_impersonateable?&lt;br /&gt;
      impersonate_user = User.find_by(id: params[:impersonate_id])&lt;br /&gt;
&lt;br /&gt;
      payload = { id: impersonate_user.id, name: impersonate_user.name, full_name: impersonate_user.full_name, role: impersonate_user.role.name,&lt;br /&gt;
                  institution_id: impersonate_user.institution.id, impersonated:true, original_user: current_user }&lt;br /&gt;
      impersonate_user_token = JsonWebToken.encode(payload, 24.hours.from_now)&lt;br /&gt;
&lt;br /&gt;
      render json: { message: &amp;quot;Successfully Impersonated #{impersonate_user.name}!&amp;quot;, token:impersonate_user_token, success:true }, status: :ok&lt;br /&gt;
&lt;br /&gt;
    else&lt;br /&gt;
      render json: { error: &amp;quot;You do not have permission to impersonate this user&amp;quot;, success:false }, status: :forbidden&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===User===&lt;br /&gt;
These methods extend the functionality of the User model. The get_available_users method retrieves users whose full names match a provided parameter. can_impersonate? determines whether the user has the authority to impersonate another user based on their role hierarchy. teaching_assistant_for? checks if the user is a teaching assistant for a given student, and teaching_assistant? determines if the user is a teaching assistant based on their role. Lastly, recursively_parent_of recursively checks for parent-child relationships between user roles.&lt;br /&gt;
&lt;br /&gt;
*user.rb file&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  # Check if the user can impersonate another user&lt;br /&gt;
  def can_impersonate?(user)&lt;br /&gt;
    return true if role.super_administrator?&lt;br /&gt;
    return true if recursively_parent_of(user.role)&lt;br /&gt;
    false&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # Check if the user is a teaching assistant for the student's course&lt;br /&gt;
  def teaching_assistant_for?(student)&lt;br /&gt;
    return false unless teaching_assistant?&lt;br /&gt;
    return false unless student.role.name == 'Student'&lt;br /&gt;
&lt;br /&gt;
    # We have to use the Ta object instead of User object&lt;br /&gt;
    # because single table inheritance is not currently functioning&lt;br /&gt;
    ta = Ta.find(id)&lt;br /&gt;
    ta.managed_users.each do |user|&lt;br /&gt;
      return true if user.id == student.id&lt;br /&gt;
    end&lt;br /&gt;
    false&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # Check if the user is a teaching assistant&lt;br /&gt;
  def teaching_assistant?&lt;br /&gt;
    true if role.ta?&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # Recursively check if parent child relationship exists&lt;br /&gt;
  def recursively_parent_of(user_role)&lt;br /&gt;
    p = user_role.parent&lt;br /&gt;
    return false if p.nil?&lt;br /&gt;
    return true if p == self.role&lt;br /&gt;
    return false if p.super_administrator?&lt;br /&gt;
    recursively_parent_of(p)&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Files added / modified ==&lt;br /&gt;
&lt;br /&gt;
*reimplementation-back-end/app/models/user.rb&lt;br /&gt;
*reimplementation-back-end/app/controllers/api/v1/impersonate_controller.rb&lt;br /&gt;
*reimplementation-back-end/config/routes.rb&lt;br /&gt;
&lt;br /&gt;
==List of Users in Database==&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! ID !! Email !! Password !! Role&lt;br /&gt;
|-&lt;br /&gt;
| 1 || admin2@example.com || password123 || Super-Administrator&lt;br /&gt;
|-&lt;br /&gt;
| 2 || jay@example.com || password123 || Administration&lt;br /&gt;
|-&lt;br /&gt;
| 3 || k2l@example.com || password123 || Instructor&lt;br /&gt;
|-&lt;br /&gt;
| 4 || mbhande@example.com || password123 || TA&lt;br /&gt;
|-&lt;br /&gt;
| 7 || dpatesl@example.com || password123 || Student&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==Testing on Postman==&lt;br /&gt;
&lt;br /&gt;
Postman was used to manually test the additional method in impersonate_controller.rb, as well as the actions and routes of the corresponding controllers. Before testing any of these methods with Postman, submit a request to /login using the user_name and password fields, which will send an authentication token. This token must be added to Postman's 'Authorization' tab as a 'Bearer token' before any further requests can be made. Postman collection [https://www.postman.com/blue-water-189861/workspace/oodd-project-3/collection/13428669-4d663583-0b90-4316-bd6c-9441ea576085?action=share&amp;amp;creator=13428669 link]&lt;br /&gt;
&lt;br /&gt;
*First of all, fork the expertiza workspace in order to work upon it&lt;br /&gt;
[[File:Fork-expertiza-postman.png | 500px]]&lt;br /&gt;
&lt;br /&gt;
*Fetch User List which can be impersonated (For eg: If Instructor fetches list he can see matched TAs and Students only)&lt;br /&gt;
[[File:Userlist.jpg | 500px]]&lt;br /&gt;
&lt;br /&gt;
* Login with provided credentials and copy the token&lt;br /&gt;
[[File:Postman-1.jpg | 500px]]&lt;br /&gt;
&lt;br /&gt;
*In the Expertiza/Authorization paste the token and save&lt;br /&gt;
[[File:Postman-2.jpg | 500px]]&lt;br /&gt;
&lt;br /&gt;
*Put the id for the user to be impersonated&lt;br /&gt;
[[File:Postman-3.jpg | 500px]]&lt;br /&gt;
&lt;br /&gt;
*Success message if the user is impersonable&lt;br /&gt;
[[File:Postman-4.jpg | 500px]]&lt;br /&gt;
&lt;br /&gt;
*Failure message if the user is not impersonable (Here instructor is trying to impersonate admin)&lt;br /&gt;
[[File:Inst-admin.jpg | 500px]]&lt;br /&gt;
&lt;br /&gt;
Here is the video of successfully running the tests [https://www.loom.com/share/b1b6b7e52a884a2f8e097e25a53e77f3?sid=e80f4d44-4667-4874-8ef8-de10f8ac1bb2]&lt;br /&gt;
&lt;br /&gt;
==Team==&lt;br /&gt;
'''Mentor''' &amp;lt;br&amp;gt;&lt;br /&gt;
*Chetana Chunduru &amp;lt;cchetan2@ncsu.edu&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Students'''&amp;lt;br&amp;gt;&lt;br /&gt;
*Devansh Shah &amp;lt;dshah8@ncsu.edu&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
*Jay Patel &amp;lt;jhpatel9@ncsu.edu&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
*Mihir Bhanderi &amp;lt;mbhande2@ncsu.edu&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Pull Request==&lt;br /&gt;
*[https://github.com/expertiza/reimplementation-back-end/pull/88]&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
*[https://docs.google.com/document/d/1MzdTjsULAMI1ZJRbf-xvThkSxxUXjk-hNMQ9DPdhmrI/edit#heading=h.vh7jk2b6nlb2 Project Instructions]&lt;/div&gt;</summary>
		<author><name>Mbhande2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=File:E2421-Updated_UML.png&amp;diff=155104</id>
		<title>File:E2421-Updated UML.png</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=File:E2421-Updated_UML.png&amp;diff=155104"/>
		<updated>2024-04-08T20:47:38Z</updated>

		<summary type="html">&lt;p&gt;Mbhande2: Mbhande2 uploaded a new version of File:E2421-Updated UML.png&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Mbhande2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=File:E2421-Updated_UML.png&amp;diff=155101</id>
		<title>File:E2421-Updated UML.png</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=File:E2421-Updated_UML.png&amp;diff=155101"/>
		<updated>2024-04-08T20:45:38Z</updated>

		<summary type="html">&lt;p&gt;Mbhande2: Mbhande2 uploaded a new version of File:E2421-Updated UML.png&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Mbhande2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=File:E2421-Updated_UML.png&amp;diff=155100</id>
		<title>File:E2421-Updated UML.png</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=File:E2421-Updated_UML.png&amp;diff=155100"/>
		<updated>2024-04-08T20:42:06Z</updated>

		<summary type="html">&lt;p&gt;Mbhande2: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Mbhande2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2024_-_E2421._Reimplement_impersonating_users_(within_impersonate_controller.rb)&amp;diff=153995</id>
		<title>CSC/ECE 517 Spring 2024 - E2421. Reimplement impersonating users (within impersonate controller.rb)</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2024_-_E2421._Reimplement_impersonating_users_(within_impersonate_controller.rb)&amp;diff=153995"/>
		<updated>2024-03-24T23:42:06Z</updated>

		<summary type="html">&lt;p&gt;Mbhande2: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Expertiza==&lt;br /&gt;
&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is a [http://rubyonrails.org/ Ruby on Rails] based open source project. Instructors have the ability to add new projects, assignments, etc., as well as edit existing ones. Later on, they can view student submissions and grade them. Students can also use Expertiza to organize into teams to work on different projects and assignments and submit their work. They can also review other students' submissions.&lt;br /&gt;
&lt;br /&gt;
==Project Overview==&lt;br /&gt;
&lt;br /&gt;
The objective is to reimplement the backend code for the impersonation feature in the new implementation of Expertiza. The current implementation relies on sessions, which won't be compatible with the new implementation using JWT tokens for authentication and returning JSON responses. The challenge lies in transitioning the logic from session-based management to JWT-based authentication while maintaining the functionality of impersonating users. The reimplementation involves planning how the backend will communicate with the frontend, potentially requiring changes in existing or new files beyond the impersonate_controller.rb.&lt;br /&gt;
&lt;br /&gt;
==Implementation==&lt;br /&gt;
&lt;br /&gt;
===UML Diagram===&lt;br /&gt;
The following UML diagram shows the association between models we will be working on&lt;br /&gt;
&lt;br /&gt;
[[File:Uml reimplement impersonate.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Hierarchy Diagram===&lt;br /&gt;
Visualization of the hierarchical structure&lt;br /&gt;
&lt;br /&gt;
[[File:User-hierarchy.jpg]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Request===&lt;br /&gt;
&lt;br /&gt;
*GET: {BASE_URL}/api/v1/impersonate/:username&lt;br /&gt;
   - Response:&lt;br /&gt;
&lt;br /&gt;
    &amp;quot;message&amp;quot;: &amp;quot;Successfully Fetched User List!&amp;quot;,&lt;br /&gt;
    &amp;quot;userList&amp;quot;: [&lt;br /&gt;
        {&lt;br /&gt;
            &amp;quot;id&amp;quot;: 4,&lt;br /&gt;
            &amp;quot;name&amp;quot;: &amp;quot;Mihir&amp;quot;,&lt;br /&gt;
            &amp;quot;full_name&amp;quot;: &amp;quot;Mihir BHanderi&amp;quot;,&lt;br /&gt;
            &amp;quot;email&amp;quot;: &amp;quot;mbhande@example.com&amp;quot;,&lt;br /&gt;
            &amp;quot;email_on_review&amp;quot;: false,&lt;br /&gt;
            &amp;quot;email_on_submission&amp;quot;: false,&lt;br /&gt;
            &amp;quot;email_on_review_of_review&amp;quot;: false,&lt;br /&gt;
            &amp;quot;role&amp;quot;: {&lt;br /&gt;
                &amp;quot;id&amp;quot;: 4,&lt;br /&gt;
                &amp;quot;name&amp;quot;: &amp;quot;Teaching Assistant&amp;quot;&lt;br /&gt;
            },&lt;br /&gt;
            &amp;quot;institution&amp;quot;: {&lt;br /&gt;
                &amp;quot;id&amp;quot;: 1,&lt;br /&gt;
                &amp;quot;name&amp;quot;: &amp;quot;North Carolina State University&amp;quot;&lt;br /&gt;
            },&lt;br /&gt;
            &amp;quot;parent&amp;quot;: {&lt;br /&gt;
                &amp;quot;id&amp;quot;: null,&lt;br /&gt;
                &amp;quot;name&amp;quot;: null&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
    ],&lt;br /&gt;
    &amp;quot;success&amp;quot;: true&lt;br /&gt;
&lt;br /&gt;
*POST: {BASE_URL}/api/v1/impersonate&lt;br /&gt;
   - Payload: impersonate_id&lt;br /&gt;
   - Response: &lt;br /&gt;
&lt;br /&gt;
     &amp;quot;message&amp;quot;: &amp;quot;Successfully Impersonated Ketul!&amp;quot;,&lt;br /&gt;
     &amp;quot;token&amp;quot;: &amp;quot;eyJhbGciOiJSUzI1NiJ9.eyJpZCI6MywibmFtZSI6IktldHVsIiwiZnVsbF9uYW1lIjoiS2V0dWwgQ2hheXlhIiwicm9sZSI6Ikluc3RydWN0b3IiLCJpbnN0aXR1dGlvbl9pZCI6MSwiaW1wZXJzb25hdGVkIjp0cnVlLCJvcmlnaW5hbF91c2VyIjoiIzxVc2VyOjB4MDAwMDdmMzVmYTc5YjVmOD4iLCJleHAiOjE3MTEzMjc0MTV9.U9wDOT618UCkf25MnCiK8W3ybeZv5BSQDNTEPOMUDABAvDd0HWSj3kIGccITHaoVsIykZFsyUDY3rL_M32zmfEXvxZuEleWSqUZGxbjQRIFP1bR_Q5sPESoBdlxVJ4QG8sUGQtuhOzMyH3z4R4ruhz1JpsQlalVZQHCbdtJOI9B4WKhNJ98Dls1fefnzYwLMnTr6e3ttbGGGK5Bm8zSpPvIWmCVNoueKHNptFcNejbU4Mt9RHWHLsTwdAtuywNLCu7li7RRNXo00D5JOUMxL7eB5AiQRpxah8BF7b0lM_Xh7bB56WvD5JTjoNZu3c3AK_EJksGXiFxwlPzNRc8Q&amp;quot;,&lt;br /&gt;
    &amp;quot;success&amp;quot;: true&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Impersonate Controller===&lt;br /&gt;
The ImpersonateController facilitates user impersonation functionality. It includes methods to fetch a list of users available for impersonation based on a provided username parameter and to impersonate a selected user by generating a new JWT token with the necessary user information. The controller ensures that impersonation requests are handled securely, validating permissions before allowing impersonation to occur.&lt;br /&gt;
&lt;br /&gt;
*impersonate_controller.rb file&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 class Api::V1::ImpersonateController &amp;lt; ApplicationController&lt;br /&gt;
&lt;br /&gt;
  # Fetches users to impersonate whose name match the passed parameter&lt;br /&gt;
  def get_users_list&lt;br /&gt;
    users = current_user.get_available_users(params[:user_name])&lt;br /&gt;
    render json: { message: &amp;quot;Successfully Fetched User List!&amp;quot;, userList:users, success:true }, status: :ok&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def check_if_user_impersonateable?&lt;br /&gt;
    impersonate_user = User.find_by(id: params[:impersonate_id])&lt;br /&gt;
    if impersonate_user&lt;br /&gt;
      return current_user.can_impersonate? impersonate_user&lt;br /&gt;
    end&lt;br /&gt;
    false&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # Impersonates a new user and returns new jwt token&lt;br /&gt;
  def impersonate&lt;br /&gt;
    unless params[:impersonate_id].present?&lt;br /&gt;
      render json: { error: &amp;quot;impersonate_id is required&amp;quot;, success:false }, status: :unprocessable_entity&lt;br /&gt;
      return&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    if check_if_user_impersonateable?&lt;br /&gt;
      impersonate_user = User.find_by(id: params[:impersonate_id])&lt;br /&gt;
&lt;br /&gt;
      payload = { id: impersonate_user.id, name: impersonate_user.name, full_name: impersonate_user.full_name, role: impersonate_user.role.name,&lt;br /&gt;
                  institution_id: impersonate_user.institution.id, impersonated:true, original_user: current_user }&lt;br /&gt;
      impersonate_user_token = JsonWebToken.encode(payload, 24.hours.from_now)&lt;br /&gt;
&lt;br /&gt;
      render json: { message: &amp;quot;Successfully Impersonated #{impersonate_user.name}!&amp;quot;, token:impersonate_user_token, success:true }, status: :ok&lt;br /&gt;
&lt;br /&gt;
    else&lt;br /&gt;
      render json: { error: &amp;quot;You do not have permission to impersonate this user&amp;quot;, success:false }, status: :forbidden&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===User===&lt;br /&gt;
These methods extend the functionality of the User model. The get_available_users method retrieves users whose full names match a provided parameter. can_impersonate? determines whether the user has the authority to impersonate another user based on their role hierarchy. teaching_assistant_for? checks if the user is a teaching assistant for a given student, and teaching_assistant? determines if the user is a teaching assistant based on their role. Lastly, recursively_parent_of recursively checks for parent-child relationships between user roles.&lt;br /&gt;
&lt;br /&gt;
*user.rb file&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  # Check if the user can impersonate another user&lt;br /&gt;
  def can_impersonate?(user)&lt;br /&gt;
    return true if role.super_administrator?&lt;br /&gt;
    return true if recursively_parent_of(user.role)&lt;br /&gt;
    false&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # Check if the user is a teaching assistant for the student's course&lt;br /&gt;
  def teaching_assistant_for?(student)&lt;br /&gt;
    return false unless teaching_assistant?&lt;br /&gt;
    return false unless student.role.name == 'Student'&lt;br /&gt;
&lt;br /&gt;
    # We have to use the Ta object instead of User object&lt;br /&gt;
    # because single table inheritance is not currently functioning&lt;br /&gt;
    ta = Ta.find(id)&lt;br /&gt;
    ta.managed_users.each do |user|&lt;br /&gt;
      return true if user.id == student.id&lt;br /&gt;
    end&lt;br /&gt;
    false&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # Check if the user is a teaching assistant&lt;br /&gt;
  def teaching_assistant?&lt;br /&gt;
    true if role.ta?&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # Recursively check if parent child relationship exists&lt;br /&gt;
  def recursively_parent_of(user_role)&lt;br /&gt;
    p = user_role.parent&lt;br /&gt;
    return false if p.nil?&lt;br /&gt;
    return true if p == self.role&lt;br /&gt;
    return false if p.super_administrator?&lt;br /&gt;
    recursively_parent_of(p)&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Files added / modified ==&lt;br /&gt;
&lt;br /&gt;
*reimplementation-back-end/app/models/user.rb&lt;br /&gt;
*reimplementation-back-end/app/controllers/api/v1/impersonate_controller.rb&lt;br /&gt;
*reimplementation-back-end/config/routes.rb&lt;br /&gt;
&lt;br /&gt;
==List of Users in Database==&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! ID !! Email !! Password !! Role&lt;br /&gt;
|-&lt;br /&gt;
| 1 || admin2@example.com || password123 || Super-Administrator&lt;br /&gt;
|-&lt;br /&gt;
| 2 || jay@example.com || password123 || Administration&lt;br /&gt;
|-&lt;br /&gt;
| 3 || k2l@example.com || password123 || Instructor&lt;br /&gt;
|-&lt;br /&gt;
| 4 || mbhande@example.com || password123 || TA&lt;br /&gt;
|-&lt;br /&gt;
| 7 || dpatesl@example.com || password123 || Student&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==Testing on Postman==&lt;br /&gt;
&lt;br /&gt;
Postman was used to manually test the additional method in impersonate_controller.rb, as well as the actions and routes of the corresponding controllers. Before testing any of these methods with Postman, submit a request to /login using the user_name and password fields, which will send an authentication token. This token must be added to Postman's 'Authorization' tab as a 'Bearer token' before any further requests can be made. Postman collection [https://www.postman.com/blue-water-189861/workspace/oodd-project-3/collection/13428669-4d663583-0b90-4316-bd6c-9441ea576085?action=share&amp;amp;creator=13428669 link]&lt;br /&gt;
&lt;br /&gt;
*First of all, fork the expertiza workspace in order to work upon it&lt;br /&gt;
[[File:Fork-expertiza-postman.png | 500px]]&lt;br /&gt;
&lt;br /&gt;
*Fetch User List which can be impersonated (For eg: If Instructor fetches list he can see matched TAs and Students only)&lt;br /&gt;
[[File:Userlist.jpg | 500px]]&lt;br /&gt;
&lt;br /&gt;
* Login with provided credentials and copy the token&lt;br /&gt;
[[File:Postman-1.jpg | 500px]]&lt;br /&gt;
&lt;br /&gt;
*In the Expertiza/Authorization paste the token and save&lt;br /&gt;
[[File:Postman-2.jpg | 500px]]&lt;br /&gt;
&lt;br /&gt;
*Put the id for the user to be impersonated&lt;br /&gt;
[[File:Postman-3.jpg | 500px]]&lt;br /&gt;
&lt;br /&gt;
*Success message if the user is impersonable&lt;br /&gt;
[[File:Postman-4.jpg | 500px]]&lt;br /&gt;
&lt;br /&gt;
*Failure message if the user is not impersonable (Here instructor is trying to impersonate admin)&lt;br /&gt;
[[File:Inst-admin.jpg | 500px]]&lt;br /&gt;
&lt;br /&gt;
Here is the video of successfully running the tests [https://www.loom.com/share/b1b6b7e52a884a2f8e097e25a53e77f3?sid=e80f4d44-4667-4874-8ef8-de10f8ac1bb2]&lt;br /&gt;
&lt;br /&gt;
==Team==&lt;br /&gt;
'''Mentor''' &amp;lt;br&amp;gt;&lt;br /&gt;
*Chetana Chunduru &amp;lt;cchetan2@ncsu.edu&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Students'''&amp;lt;br&amp;gt;&lt;br /&gt;
*Devansh Shah &amp;lt;dshah8@ncsu.edu&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
*Jay Patel &amp;lt;jhpatel9@ncsu.edu&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
*Mihir Bhanderi &amp;lt;mbhande2@ncsu.edu&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Pull Request==&lt;br /&gt;
*[https://github.com/expertiza/reimplementation-back-end/pull/88]&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
*[https://docs.google.com/document/d/1MzdTjsULAMI1ZJRbf-xvThkSxxUXjk-hNMQ9DPdhmrI/edit#heading=h.vh7jk2b6nlb2 Project Instructions]&lt;/div&gt;</summary>
		<author><name>Mbhande2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2024_-_E2421._Reimplement_impersonating_users_(within_impersonate_controller.rb)&amp;diff=153989</id>
		<title>CSC/ECE 517 Spring 2024 - E2421. Reimplement impersonating users (within impersonate controller.rb)</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2024_-_E2421._Reimplement_impersonating_users_(within_impersonate_controller.rb)&amp;diff=153989"/>
		<updated>2024-03-24T23:36:51Z</updated>

		<summary type="html">&lt;p&gt;Mbhande2: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Expertiza==&lt;br /&gt;
&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is a [http://rubyonrails.org/ Ruby on Rails] based open source project. Instructors have the ability to add new projects, assignments, etc., as well as edit existing ones. Later on, they can view student submissions and grade them. Students can also use Expertiza to organize into teams to work on different projects and assignments and submit their work. They can also review other students' submissions.&lt;br /&gt;
&lt;br /&gt;
==Project Overview==&lt;br /&gt;
&lt;br /&gt;
The objective is to reimplement the backend code for the impersonation feature in the new implementation of Expertiza. The current implementation relies on sessions, which won't be compatible with the new implementation using JWT tokens for authentication and returning JSON responses. The challenge lies in transitioning the logic from session-based management to JWT-based authentication while maintaining the functionality of impersonating users. The reimplementation involves planning how the backend will communicate with the frontend, potentially requiring changes in existing or new files beyond the impersonate_controller.rb.&lt;br /&gt;
&lt;br /&gt;
==Implementation==&lt;br /&gt;
&lt;br /&gt;
===UML Diagram===&lt;br /&gt;
The following UML diagram shows the association between models we will be working on&lt;br /&gt;
&lt;br /&gt;
[[File:Uml reimplement impersonate.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Hierarchy Diagram===&lt;br /&gt;
Visualization of the hierarchical structure&lt;br /&gt;
&lt;br /&gt;
[[File:User-hierarchy.jpg]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Request===&lt;br /&gt;
&lt;br /&gt;
*GET: {BASE_URL}/api/v1/impersonate/:username&lt;br /&gt;
   - Response:&lt;br /&gt;
&lt;br /&gt;
    &amp;quot;message&amp;quot;: &amp;quot;Successfully Fetched User List!&amp;quot;,&lt;br /&gt;
    &amp;quot;userList&amp;quot;: [&lt;br /&gt;
        {&lt;br /&gt;
            &amp;quot;id&amp;quot;: 4,&lt;br /&gt;
            &amp;quot;name&amp;quot;: &amp;quot;Mihir&amp;quot;,&lt;br /&gt;
            &amp;quot;full_name&amp;quot;: &amp;quot;Mihir BHanderi&amp;quot;,&lt;br /&gt;
            &amp;quot;email&amp;quot;: &amp;quot;mbhande@example.com&amp;quot;,&lt;br /&gt;
            &amp;quot;email_on_review&amp;quot;: false,&lt;br /&gt;
            &amp;quot;email_on_submission&amp;quot;: false,&lt;br /&gt;
            &amp;quot;email_on_review_of_review&amp;quot;: false,&lt;br /&gt;
            &amp;quot;role&amp;quot;: {&lt;br /&gt;
                &amp;quot;id&amp;quot;: 4,&lt;br /&gt;
                &amp;quot;name&amp;quot;: &amp;quot;Teaching Assistant&amp;quot;&lt;br /&gt;
            },&lt;br /&gt;
            &amp;quot;institution&amp;quot;: {&lt;br /&gt;
                &amp;quot;id&amp;quot;: 1,&lt;br /&gt;
                &amp;quot;name&amp;quot;: &amp;quot;North Carolina State University&amp;quot;&lt;br /&gt;
            },&lt;br /&gt;
            &amp;quot;parent&amp;quot;: {&lt;br /&gt;
                &amp;quot;id&amp;quot;: null,&lt;br /&gt;
                &amp;quot;name&amp;quot;: null&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
    ],&lt;br /&gt;
    &amp;quot;success&amp;quot;: true&lt;br /&gt;
&lt;br /&gt;
*POST: {BASE_URL}/api/v1/impersonate&lt;br /&gt;
   - Payload: impersonate_id&lt;br /&gt;
   - Response: &lt;br /&gt;
&lt;br /&gt;
     &amp;quot;message&amp;quot;: &amp;quot;Successfully Impersonated Ketul!&amp;quot;,&lt;br /&gt;
     &amp;quot;token&amp;quot;: &amp;quot;eyJhbGciOiJSUzI1NiJ9.eyJpZCI6MywibmFtZSI6IktldHVsIiwiZnVsbF9uYW1lIjoiS2V0dWwgQ2hheXlhIiwicm9sZSI6Ikluc3RydWN0b3IiLCJpbnN0aXR1dGlvbl9pZCI6MSwiaW1wZXJzb25hdGVkIjp0cnVlLCJvcmlnaW5hbF91c2VyIjoiIzxVc2VyOjB4MDAwMDdmMzVmYTc5YjVmOD4iLCJleHAiOjE3MTEzMjc0MTV9.U9wDOT618UCkf25MnCiK8W3ybeZv5BSQDNTEPOMUDABAvDd0HWSj3kIGccITHaoVsIykZFsyUDY3rL_M32zmfEXvxZuEleWSqUZGxbjQRIFP1bR_Q5sPESoBdlxVJ4QG8sUGQtuhOzMyH3z4R4ruhz1JpsQlalVZQHCbdtJOI9B4WKhNJ98Dls1fefnzYwLMnTr6e3ttbGGGK5Bm8zSpPvIWmCVNoueKHNptFcNejbU4Mt9RHWHLsTwdAtuywNLCu7li7RRNXo00D5JOUMxL7eB5AiQRpxah8BF7b0lM_Xh7bB56WvD5JTjoNZu3c3AK_EJksGXiFxwlPzNRc8Q&amp;quot;,&lt;br /&gt;
    &amp;quot;success&amp;quot;: true&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Impersonate Controller===&lt;br /&gt;
The ImpersonateController facilitates user impersonation functionality. It includes methods to fetch a list of users available for impersonation based on a provided username parameter and to impersonate a selected user by generating a new JWT token with the necessary user information. The controller ensures that impersonation requests are handled securely, validating permissions before allowing impersonation to occur.&lt;br /&gt;
&lt;br /&gt;
*impersonate_controller.rb file&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 class Api::V1::ImpersonateController &amp;lt; ApplicationController&lt;br /&gt;
&lt;br /&gt;
  # Fetches users to impersonate whose name match the passed parameter&lt;br /&gt;
  def get_users_list&lt;br /&gt;
    users = current_user.get_available_users(params[:user_name])&lt;br /&gt;
    render json: { message: &amp;quot;Successfully Fetched User List!&amp;quot;, userList:users, success:true }, status: :ok&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def check_if_user_impersonateable?&lt;br /&gt;
    impersonate_user = User.find_by(id: params[:impersonate_id])&lt;br /&gt;
    if impersonate_user&lt;br /&gt;
      return current_user.can_impersonate? impersonate_user&lt;br /&gt;
    end&lt;br /&gt;
    false&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # Impersonates a new user and returns new jwt token&lt;br /&gt;
  def impersonate&lt;br /&gt;
    unless params[:impersonate_id].present?&lt;br /&gt;
      render json: { error: &amp;quot;impersonate_id is required&amp;quot;, success:false }, status: :unprocessable_entity&lt;br /&gt;
      return&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    if check_if_user_impersonateable?&lt;br /&gt;
      impersonate_user = User.find_by(id: params[:impersonate_id])&lt;br /&gt;
&lt;br /&gt;
      payload = { id: impersonate_user.id, name: impersonate_user.name, full_name: impersonate_user.full_name, role: impersonate_user.role.name,&lt;br /&gt;
                  institution_id: impersonate_user.institution.id, impersonated:true, original_user: current_user }&lt;br /&gt;
      impersonate_user_token = JsonWebToken.encode(payload, 24.hours.from_now)&lt;br /&gt;
&lt;br /&gt;
      render json: { message: &amp;quot;Successfully Impersonated #{impersonate_user.name}!&amp;quot;, token:impersonate_user_token, success:true }, status: :ok&lt;br /&gt;
&lt;br /&gt;
    else&lt;br /&gt;
      render json: { error: &amp;quot;You do not have permission to impersonate this user&amp;quot;, success:false }, status: :forbidden&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===User===&lt;br /&gt;
These methods extend the functionality of the User model. The get_available_users method retrieves users whose full names match a provided parameter. can_impersonate? determines whether the user has the authority to impersonate another user based on their role hierarchy. teaching_assistant_for? checks if the user is a teaching assistant for a given student, and teaching_assistant? determines if the user is a teaching assistant based on their role. Lastly, recursively_parent_of recursively checks for parent-child relationships between user roles.&lt;br /&gt;
&lt;br /&gt;
*user.rb file&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  # Check if the user can impersonate another user&lt;br /&gt;
  def can_impersonate?(user)&lt;br /&gt;
    return true if role.super_administrator?&lt;br /&gt;
    return true if recursively_parent_of(user.role)&lt;br /&gt;
    false&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # Check if the user is a teaching assistant for the student's course&lt;br /&gt;
  def teaching_assistant_for?(student)&lt;br /&gt;
    return false unless teaching_assistant?&lt;br /&gt;
    return false unless student.role.name == 'Student'&lt;br /&gt;
&lt;br /&gt;
    # We have to use the Ta object instead of User object&lt;br /&gt;
    # because single table inheritance is not currently functioning&lt;br /&gt;
    ta = Ta.find(id)&lt;br /&gt;
    ta.managed_users.each do |user|&lt;br /&gt;
      return true if user.id == student.id&lt;br /&gt;
    end&lt;br /&gt;
    false&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # Check if the user is a teaching assistant&lt;br /&gt;
  def teaching_assistant?&lt;br /&gt;
    true if role.ta?&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # Recursively check if parent child relationship exists&lt;br /&gt;
  def recursively_parent_of(user_role)&lt;br /&gt;
    p = user_role.parent&lt;br /&gt;
    return false if p.nil?&lt;br /&gt;
    return true if p == self.role&lt;br /&gt;
    return false if p.super_administrator?&lt;br /&gt;
    recursively_parent_of(p)&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Files added / modified ==&lt;br /&gt;
&lt;br /&gt;
*reimplementation-back-end/app/models/user.rb&lt;br /&gt;
*reimplementation-back-end/app/controllers/api/v1/impersonate_controller.rb&lt;br /&gt;
*reimplementation-back-end/config/routes.rb&lt;br /&gt;
&lt;br /&gt;
==List of Users in Database==&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! ID !! Email !! Password !! Role&lt;br /&gt;
|-&lt;br /&gt;
| 1 || admin2@example.com || password123 || Super-Administrator&lt;br /&gt;
|-&lt;br /&gt;
| 2 || jay@example.com || password123 || Administration&lt;br /&gt;
|-&lt;br /&gt;
| 3 || k2l@example.com || password123 || Instructor&lt;br /&gt;
|-&lt;br /&gt;
| 4 || mbhande@example.com || password123 || TA&lt;br /&gt;
|-&lt;br /&gt;
| 7 || dpatesl@example.com || password123 || Student&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==Testing on Postman==&lt;br /&gt;
&lt;br /&gt;
Postman was used to manually test the additional method in impersonate_controller.rb, as well as the actions and routes of the corresponding controllers. Before testing any of these methods with Postman, submit a request to /login using the user_name and password fields, which will send an authentication token. This token must be added to Postman's 'Authorization' tab as a 'Bearer token' before any further requests can be made. Postman collection [https://www.postman.com/blue-water-189861/workspace/oodd-project-3/collection/13428669-4d663583-0b90-4316-bd6c-9441ea576085?action=share&amp;amp;creator=13428669 link]&lt;br /&gt;
&lt;br /&gt;
*First of all, fork the expertiza workspace in order to work upon it&lt;br /&gt;
[[File:Fork-expertiza-postman.png | 500px]]&lt;br /&gt;
&lt;br /&gt;
*Fetch User List which can be impersonated (For eg: If Instructor fetches list he can see matched TAs and Students only)&lt;br /&gt;
[[File:Userlist.jpg | 500px]]&lt;br /&gt;
&lt;br /&gt;
* Login with provided credentials and copy the token&lt;br /&gt;
[[File:Postman-1.jpg | 500px]]&lt;br /&gt;
&lt;br /&gt;
*In the Expertiza/Authorization paste the token and save&lt;br /&gt;
[[File:Postman-2.jpg | 500px]]&lt;br /&gt;
&lt;br /&gt;
*Put the id for the user to be impersonated&lt;br /&gt;
[[File:Postman-3.jpg | 500px]]&lt;br /&gt;
&lt;br /&gt;
*Success message if the user is impersonable&lt;br /&gt;
[[File:Postman-4.jpg | 500px]]&lt;br /&gt;
&lt;br /&gt;
*Failure message if the user is not impersonable (Here instructor is trying to impersonate admin)&lt;br /&gt;
[[File:Inst-admin.jpg | 500px]]&lt;br /&gt;
&lt;br /&gt;
Here is the video of successfully running the tests [https://www.loom.com/share/b1b6b7e52a884a2f8e097e25a53e77f3?sid=e80f4d44-4667-4874-8ef8-de10f8ac1bb2]&lt;br /&gt;
&lt;br /&gt;
==Team==&lt;br /&gt;
'''Mentor''' &amp;lt;br&amp;gt;&lt;br /&gt;
*Chetana Chunduru &amp;lt;cchetan2@ncsu.edu&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Students'''&amp;lt;br&amp;gt;&lt;br /&gt;
*Devansh Shah &amp;lt;dshah8@ncsu.edu&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
*Jay Patel &amp;lt;jhpatel9@ncsu.edu&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
*Mihir Bhanderi &amp;lt;mbhande2@ncsu.edu&amp;gt;&amp;lt;br&amp;gt;&lt;/div&gt;</summary>
		<author><name>Mbhande2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2024&amp;diff=153434</id>
		<title>CSC/ECE 517 Spring 2024</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2024&amp;diff=153434"/>
		<updated>2024-03-24T16:20:33Z</updated>

		<summary type="html">&lt;p&gt;Mbhande2: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;* [[CSC/ECE 517 Spring 2024 - E2407 Refactor review_mapping_controller.rb]]&lt;br /&gt;
* [[CSC/ECE 517 Spring 2024 - E2428 Replicate Roles and Institution UIs ReactJS]]&lt;br /&gt;
* [[CSC/ECE 517 Spring 2024 - E2429 Reimplement student_task list]]&lt;br /&gt;
* [[CSC/ECE 517 Spring 2024 - E2414 Grading Audit Trail]]&lt;br /&gt;
* [[CSC/ECE 517 Spring 2024 - ‬NTNX-2‬‭ : Snapshot Functionality for provisioned databases]]&lt;br /&gt;
* [[CSC/ECE 517 Spring 2024 - E2411 : Fix &amp;quot;Back&amp;quot; link on “New Late Policy” page]]&lt;br /&gt;
* [[CSC/ECE 517 Spring 2024 - E2416.  Reimplement the Question hierarchy]]&lt;br /&gt;
* [[CSC/ECE 517 Spring 2024 - E2420. Reimplement student_quizzes_controller]]&lt;br /&gt;
* [[CSC/ECE 517 Spring 2024 - E2424. Reimplement the Bookmarks Controller]]&lt;br /&gt;
* [[CSC/ECE 517 Spring 2024 - E2426. Create a UI for Assignment Edit page &amp;quot;Etc&amp;quot; tab in ReactJS]]&lt;br /&gt;
* [[CSC/ECE 517 Spring 2024 - E2417. Reimplement submitted content controller.rb]]&lt;br /&gt;
* [[CSC/ECE 517 Spring 2024 - E2425. Create a Courses user interface in ReactJS]]&lt;br /&gt;
* [[CSC/ECE 517 Spring 2024 - E2431. Reimplement  grades/view_team]]&lt;br /&gt;
* [[CSC/ECE 517 Spring 2024 - E2404 Refactor student teams functionality]]&lt;br /&gt;
* [[CSC/ECE 517 Spring 2024 - E2403 Mentor-Meeting Management]]&lt;br /&gt;
* [[CSC/ECE 517 Spring 2024 - E2421. Reimplement impersonating users (within impersonate controller.rb)]]&lt;/div&gt;</summary>
		<author><name>Mbhande2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2024_-_E2421._Reimplement_impersonating_users_(within_impersonate_controller.rb)&amp;diff=153426</id>
		<title>CSC/ECE 517 Spring 2024 - E2421. Reimplement impersonating users (within impersonate controller.rb)</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2024_-_E2421._Reimplement_impersonating_users_(within_impersonate_controller.rb)&amp;diff=153426"/>
		<updated>2024-03-24T16:16:43Z</updated>

		<summary type="html">&lt;p&gt;Mbhande2: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Expertiza==&lt;br /&gt;
&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is a [http://rubyonrails.org/ Ruby on Rails] based open source project. Instructors have the ability to add new projects, assignments, etc., as well as edit existing ones. Later on, they can view student submissions and grade them. Students can also use Expertiza to organize into teams to work on different projects and assignments and submit their work. They can also review other students' submissions.&lt;br /&gt;
&lt;br /&gt;
==Project Overview==&lt;br /&gt;
&lt;br /&gt;
The objective is to reimplement the backend code for the impersonation feature in the new implementation of Expertiza. The current implementation relies on sessions, which won't be compatible with the new implementation using JWT tokens for authentication and returning JSON responses. The challenge lies in transitioning the logic from session-based management to JWT-based authentication while maintaining the functionality of impersonating users. The reimplementation involves planning how the backend will communicate with the frontend, potentially requiring changes in existing or new files beyond the impersonate_controller.rb.&lt;br /&gt;
&lt;br /&gt;
==Implementation==&lt;br /&gt;
&lt;br /&gt;
===UML Diagram===&lt;br /&gt;
The following UML diagram shows the association between models we will be working on&lt;br /&gt;
&lt;br /&gt;
[[File:Uml reimplement impersonate.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Hierarchy Diagram===&lt;br /&gt;
Visualization of the hierarchical structure&lt;br /&gt;
&lt;br /&gt;
[[File:User-hierarchy.jpg]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Request===&lt;br /&gt;
&lt;br /&gt;
*GET: {BASE_URL}/api/v1/impersonate/:username&lt;br /&gt;
   - Response:&lt;br /&gt;
&lt;br /&gt;
    &amp;quot;message&amp;quot;: &amp;quot;Successfully Fetched User List!&amp;quot;,&lt;br /&gt;
    &amp;quot;userList&amp;quot;: [&lt;br /&gt;
        {&lt;br /&gt;
            &amp;quot;id&amp;quot;: 4,&lt;br /&gt;
            &amp;quot;name&amp;quot;: &amp;quot;Mihir&amp;quot;,&lt;br /&gt;
            &amp;quot;full_name&amp;quot;: &amp;quot;Mihir BHanderi&amp;quot;,&lt;br /&gt;
            &amp;quot;email&amp;quot;: &amp;quot;mbhande@example.com&amp;quot;,&lt;br /&gt;
            &amp;quot;email_on_review&amp;quot;: false,&lt;br /&gt;
            &amp;quot;email_on_submission&amp;quot;: false,&lt;br /&gt;
            &amp;quot;email_on_review_of_review&amp;quot;: false,&lt;br /&gt;
            &amp;quot;role&amp;quot;: {&lt;br /&gt;
                &amp;quot;id&amp;quot;: 4,&lt;br /&gt;
                &amp;quot;name&amp;quot;: &amp;quot;Teaching Assistant&amp;quot;&lt;br /&gt;
            },&lt;br /&gt;
            &amp;quot;institution&amp;quot;: {&lt;br /&gt;
                &amp;quot;id&amp;quot;: 1,&lt;br /&gt;
                &amp;quot;name&amp;quot;: &amp;quot;North Carolina State University&amp;quot;&lt;br /&gt;
            },&lt;br /&gt;
            &amp;quot;parent&amp;quot;: {&lt;br /&gt;
                &amp;quot;id&amp;quot;: null,&lt;br /&gt;
                &amp;quot;name&amp;quot;: null&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
    ],&lt;br /&gt;
    &amp;quot;success&amp;quot;: true&lt;br /&gt;
&lt;br /&gt;
*POST: {BASE_URL}/api/v1/impersonate&lt;br /&gt;
   - Payload: impersonate_id&lt;br /&gt;
   - Response: &lt;br /&gt;
&lt;br /&gt;
     &amp;quot;message&amp;quot;: &amp;quot;Successfully Impersonated Ketul!&amp;quot;,&lt;br /&gt;
     &amp;quot;token&amp;quot;: &amp;quot;eyJhbGciOiJSUzI1NiJ9.eyJpZCI6MywibmFtZSI6IktldHVsIiwiZnVsbF9uYW1lIjoiS2V0dWwgQ2hheXlhIiwicm9sZSI6Ikluc3RydWN0b3IiLCJpbnN0aXR1dGlvbl9pZCI6MSwiaW1wZXJzb25hdGVkIjp0cnVlLCJvcmlnaW5hbF91c2VyIjoiIzxVc2VyOjB4MDAwMDdmMzVmYTc5YjVmOD4iLCJleHAiOjE3MTEzMjc0MTV9.U9wDOT618UCkf25MnCiK8W3ybeZv5BSQDNTEPOMUDABAvDd0HWSj3kIGccITHaoVsIykZFsyUDY3rL_M32zmfEXvxZuEleWSqUZGxbjQRIFP1bR_Q5sPESoBdlxVJ4QG8sUGQtuhOzMyH3z4R4ruhz1JpsQlalVZQHCbdtJOI9B4WKhNJ98Dls1fefnzYwLMnTr6e3ttbGGGK5Bm8zSpPvIWmCVNoueKHNptFcNejbU4Mt9RHWHLsTwdAtuywNLCu7li7RRNXo00D5JOUMxL7eB5AiQRpxah8BF7b0lM_Xh7bB56WvD5JTjoNZu3c3AK_EJksGXiFxwlPzNRc8Q&amp;quot;,&lt;br /&gt;
    &amp;quot;success&amp;quot;: true&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Impersonate Controller===&lt;br /&gt;
The ImpersonateController facilitates user impersonation functionality. It includes methods to fetch a list of users available for impersonation based on a provided username parameter and to impersonate a selected user by generating a new JWT token with the necessary user information. The controller ensures that impersonation requests are handled securely, validating permissions before allowing impersonation to occur.&lt;br /&gt;
&lt;br /&gt;
*impersonate_controller.rb file&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 class Api::V1::ImpersonateController &amp;lt; ApplicationController&lt;br /&gt;
&lt;br /&gt;
  # Fetches users to impersonate whose name match the passed parameter&lt;br /&gt;
  def get_users_list&lt;br /&gt;
    users = current_user.get_available_users(params[:user_name])&lt;br /&gt;
    render json: { message: &amp;quot;Successfully Fetched User List!&amp;quot;, userList:users, success:true }, status: :ok&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def check_if_user_impersonateable?&lt;br /&gt;
    impersonate_user = User.find_by(id: params[:impersonate_id])&lt;br /&gt;
    if impersonate_user&lt;br /&gt;
      return current_user.can_impersonate? impersonate_user&lt;br /&gt;
    end&lt;br /&gt;
    false&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # Impersonates a new user and returns new jwt token&lt;br /&gt;
  def impersonate&lt;br /&gt;
    unless params[:impersonate_id].present?&lt;br /&gt;
      render json: { error: &amp;quot;impersonate_id is required&amp;quot;, success:false }, status: :unprocessable_entity&lt;br /&gt;
      return&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    if check_if_user_impersonateable?&lt;br /&gt;
      impersonate_user = User.find_by(id: params[:impersonate_id])&lt;br /&gt;
&lt;br /&gt;
      payload = { id: impersonate_user.id, name: impersonate_user.name, full_name: impersonate_user.full_name, role: impersonate_user.role.name,&lt;br /&gt;
                  institution_id: impersonate_user.institution.id, impersonated:true, original_user: current_user }&lt;br /&gt;
      impersonate_user_token = JsonWebToken.encode(payload, 24.hours.from_now)&lt;br /&gt;
&lt;br /&gt;
      render json: { message: &amp;quot;Successfully Impersonated #{impersonate_user.name}!&amp;quot;, token:impersonate_user_token, success:true }, status: :ok&lt;br /&gt;
&lt;br /&gt;
    else&lt;br /&gt;
      render json: { error: &amp;quot;You do not have permission to impersonate this user&amp;quot;, success:false }, status: :forbidden&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===User===&lt;br /&gt;
These methods extend the functionality of the User model. The get_available_users method retrieves users whose full names match a provided parameter. can_impersonate? determines whether the user has the authority to impersonate another user based on their role hierarchy. teaching_assistant_for? checks if the user is a teaching assistant for a given student, and teaching_assistant? determines if the user is a teaching assistant based on their role. Lastly, recursively_parent_of recursively checks for parent-child relationships between user roles.&lt;br /&gt;
&lt;br /&gt;
*user.rb file&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  # Check if the user can impersonate another user&lt;br /&gt;
  def can_impersonate?(user)&lt;br /&gt;
    return true if role.super_administrator?&lt;br /&gt;
    return true if recursively_parent_of(user.role)&lt;br /&gt;
    false&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # Check if the user is a teaching assistant for the student's course&lt;br /&gt;
  def teaching_assistant_for?(student)&lt;br /&gt;
    return false unless teaching_assistant?&lt;br /&gt;
    return false unless student.role.name == 'Student'&lt;br /&gt;
&lt;br /&gt;
    # We have to use the Ta object instead of User object&lt;br /&gt;
    # because single table inheritance is not currently functioning&lt;br /&gt;
    ta = Ta.find(id)&lt;br /&gt;
    ta.managed_users.each do |user|&lt;br /&gt;
      return true if user.id == student.id&lt;br /&gt;
    end&lt;br /&gt;
    false&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # Check if the user is a teaching assistant&lt;br /&gt;
  def teaching_assistant?&lt;br /&gt;
    true if role.ta?&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # Recursively check if parent child relationship exists&lt;br /&gt;
  def recursively_parent_of(user_role)&lt;br /&gt;
    p = user_role.parent&lt;br /&gt;
    return false if p.nil?&lt;br /&gt;
    return true if p == self.role&lt;br /&gt;
    return false if p.super_administrator?&lt;br /&gt;
    recursively_parent_of(p)&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Files added / modified ==&lt;br /&gt;
&lt;br /&gt;
*reimplementation-back-end/app/models/user.rb&lt;br /&gt;
*reimplementation-back-end/app/controllers/api/v1/impersonate_controller.rb&lt;br /&gt;
*reimplementation-back-end/config/routes.rb&lt;br /&gt;
&lt;br /&gt;
==List of Users in Database==&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! ID !! Email !! Password !! Role&lt;br /&gt;
|-&lt;br /&gt;
| 1 || admin2@example.com || password123 || Super-Administrator&lt;br /&gt;
|-&lt;br /&gt;
| 2 || jay@example.com || password123 || Administration&lt;br /&gt;
|-&lt;br /&gt;
| 3 || k2l@example.com || password123 || Instructor&lt;br /&gt;
|-&lt;br /&gt;
| 4 || mbhande@example.com || password123 || TA&lt;br /&gt;
|-&lt;br /&gt;
| 7 || dpatesl@example.com || password123 || Student&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==Testing on Postman==&lt;br /&gt;
&lt;br /&gt;
Postman was used to manually test the additional method in impersonate_controller.rb, as well as the actions and routes of the corresponding controllers. Before testing any of these methods with Postman, submit a request to /login using the user_name and password fields, which will send an authentication token. This token must be added to Postman's 'Authorization' tab as a 'Bearer token' before any further requests can be made. Postman collection [https://www.postman.com/blue-water-189861/workspace/oodd-project-3/collection/13428669-4d663583-0b90-4316-bd6c-9441ea576085?action=share&amp;amp;creator=13428669 link]&lt;br /&gt;
&lt;br /&gt;
*First of all, fork the expertiza workspace in order to work upon it&lt;br /&gt;
[[File:Fork-expertiza-postman.png | 500px]]&lt;br /&gt;
&lt;br /&gt;
*Fetch User List which can be impersonated (For eg: If Instructor fetches list he can see matched TAs and Students only)&lt;br /&gt;
[[File:Userlist.jpg | 500px]]&lt;br /&gt;
&lt;br /&gt;
* Login with provided credentials and copy the token&lt;br /&gt;
[[File:Postman-1.jpg | 500px]]&lt;br /&gt;
&lt;br /&gt;
*In the Expertiza/Authorization paste the token and save&lt;br /&gt;
[[File:Postman-2.jpg | 500px]]&lt;br /&gt;
&lt;br /&gt;
*Put the id for the user to be impersonated&lt;br /&gt;
[[File:Postman-3.jpg | 500px]]&lt;br /&gt;
&lt;br /&gt;
*Success message if the user is impersonable&lt;br /&gt;
[[File:Postman-4.jpg | 500px]]&lt;br /&gt;
&lt;br /&gt;
*Failure message if the user is not impersonable (Here instructor is trying to impersonate admin)&lt;br /&gt;
[[File:Inst-admin.jpg | 500px]]&lt;br /&gt;
&lt;br /&gt;
==Team==&lt;br /&gt;
'''Mentor''' &amp;lt;br&amp;gt;&lt;br /&gt;
*Chetana Chunduru &amp;lt;cchetan2@ncsu.edu&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Students'''&amp;lt;br&amp;gt;&lt;br /&gt;
*Devansh Shah &amp;lt;dshah8@ncsu.edu&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
*Jay Patel &amp;lt;jhpatel9@ncsu.edu&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
*Mihir Bhanderi &amp;lt;mbhande2@ncsu.edu&amp;gt;&amp;lt;br&amp;gt;&lt;/div&gt;</summary>
		<author><name>Mbhande2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=File:Fork-expertiza-postman.png&amp;diff=153422</id>
		<title>File:Fork-expertiza-postman.png</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=File:Fork-expertiza-postman.png&amp;diff=153422"/>
		<updated>2024-03-24T16:14:10Z</updated>

		<summary type="html">&lt;p&gt;Mbhande2: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Mbhande2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2024_-_E2421._Reimplement_impersonating_users_(within_impersonate_controller.rb)&amp;diff=153295</id>
		<title>CSC/ECE 517 Spring 2024 - E2421. Reimplement impersonating users (within impersonate controller.rb)</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2024_-_E2421._Reimplement_impersonating_users_(within_impersonate_controller.rb)&amp;diff=153295"/>
		<updated>2024-03-24T01:20:37Z</updated>

		<summary type="html">&lt;p&gt;Mbhande2: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Expertiza==&lt;br /&gt;
&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is a [http://rubyonrails.org/ Ruby on Rails] based open source project. Instructors have the ability to add new projects, assignments, etc., as well as edit existing ones. Later on, they can view student submissions and grade them. Students can also use Expertiza to organize into teams to work on different projects and assignments and submit their work. They can also review other students' submissions.&lt;br /&gt;
&lt;br /&gt;
==Project Overview==&lt;br /&gt;
&lt;br /&gt;
The objective is to reimplement the backend code for the impersonation feature in the new implementation of Expertiza. The current implementation relies on sessions, which won't be compatible with the new implementation using JWT tokens for authentication and returning JSON responses. The challenge lies in transitioning the logic from session-based management to JWT-based authentication while maintaining the functionality of impersonating users. The reimplementation involves planning how the backend will communicate with the frontend, potentially requiring changes in existing or new files beyond the impersonate_controller.rb.&lt;br /&gt;
&lt;br /&gt;
==Implementation==&lt;br /&gt;
&lt;br /&gt;
===UML Diagram===&lt;br /&gt;
The following UML diagram shows the association between models we will be working on&lt;br /&gt;
&lt;br /&gt;
[[File:Uml reimplement impersonate.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Hierarchy Diagram===&lt;br /&gt;
Visualization of the hierarchical structure&lt;br /&gt;
&lt;br /&gt;
[[File:User-hierarchy.jpg]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Request===&lt;br /&gt;
&lt;br /&gt;
*GET: {BASE_URL}/api/v1/impersonate/:username&lt;br /&gt;
   - Response:&lt;br /&gt;
&lt;br /&gt;
    &amp;quot;message&amp;quot;: &amp;quot;Successfully Fetched User List!&amp;quot;,&lt;br /&gt;
    &amp;quot;userList&amp;quot;: [&lt;br /&gt;
        {&lt;br /&gt;
            &amp;quot;id&amp;quot;: 4,&lt;br /&gt;
            &amp;quot;name&amp;quot;: &amp;quot;Mihir&amp;quot;,&lt;br /&gt;
            &amp;quot;full_name&amp;quot;: &amp;quot;Mihir BHanderi&amp;quot;,&lt;br /&gt;
            &amp;quot;email&amp;quot;: &amp;quot;mbhande@example.com&amp;quot;,&lt;br /&gt;
            &amp;quot;email_on_review&amp;quot;: false,&lt;br /&gt;
            &amp;quot;email_on_submission&amp;quot;: false,&lt;br /&gt;
            &amp;quot;email_on_review_of_review&amp;quot;: false,&lt;br /&gt;
            &amp;quot;role&amp;quot;: {&lt;br /&gt;
                &amp;quot;id&amp;quot;: 4,&lt;br /&gt;
                &amp;quot;name&amp;quot;: &amp;quot;Teaching Assistant&amp;quot;&lt;br /&gt;
            },&lt;br /&gt;
            &amp;quot;institution&amp;quot;: {&lt;br /&gt;
                &amp;quot;id&amp;quot;: 1,&lt;br /&gt;
                &amp;quot;name&amp;quot;: &amp;quot;North Carolina State University&amp;quot;&lt;br /&gt;
            },&lt;br /&gt;
            &amp;quot;parent&amp;quot;: {&lt;br /&gt;
                &amp;quot;id&amp;quot;: null,&lt;br /&gt;
                &amp;quot;name&amp;quot;: null&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
    ],&lt;br /&gt;
    &amp;quot;success&amp;quot;: true&lt;br /&gt;
&lt;br /&gt;
*POST: {BASE_URL}/api/v1/impersonate&lt;br /&gt;
   - Payload: impersonate_id&lt;br /&gt;
   - Response: &lt;br /&gt;
&lt;br /&gt;
     &amp;quot;message&amp;quot;: &amp;quot;Successfully Impersonated Ketul!&amp;quot;,&lt;br /&gt;
     &amp;quot;token&amp;quot;: &amp;quot;eyJhbGciOiJSUzI1NiJ9.eyJpZCI6MywibmFtZSI6IktldHVsIiwiZnVsbF9uYW1lIjoiS2V0dWwgQ2hheXlhIiwicm9sZSI6Ikluc3RydWN0b3IiLCJpbnN0aXR1dGlvbl9pZCI6MSwiaW1wZXJzb25hdGVkIjp0cnVlLCJvcmlnaW5hbF91c2VyIjoiIzxVc2VyOjB4MDAwMDdmMzVmYTc5YjVmOD4iLCJleHAiOjE3MTEzMjc0MTV9.U9wDOT618UCkf25MnCiK8W3ybeZv5BSQDNTEPOMUDABAvDd0HWSj3kIGccITHaoVsIykZFsyUDY3rL_M32zmfEXvxZuEleWSqUZGxbjQRIFP1bR_Q5sPESoBdlxVJ4QG8sUGQtuhOzMyH3z4R4ruhz1JpsQlalVZQHCbdtJOI9B4WKhNJ98Dls1fefnzYwLMnTr6e3ttbGGGK5Bm8zSpPvIWmCVNoueKHNptFcNejbU4Mt9RHWHLsTwdAtuywNLCu7li7RRNXo00D5JOUMxL7eB5AiQRpxah8BF7b0lM_Xh7bB56WvD5JTjoNZu3c3AK_EJksGXiFxwlPzNRc8Q&amp;quot;,&lt;br /&gt;
    &amp;quot;success&amp;quot;: true&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Impersonate Controller===&lt;br /&gt;
The ImpersonateController facilitates user impersonation functionality. It includes methods to fetch a list of users available for impersonation based on a provided username parameter and to impersonate a selected user by generating a new JWT token with the necessary user information. The controller ensures that impersonation requests are handled securely, validating permissions before allowing impersonation to occur.&lt;br /&gt;
&lt;br /&gt;
*impersonate_controller.rb file&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 class Api::V1::ImpersonateController &amp;lt; ApplicationController&lt;br /&gt;
&lt;br /&gt;
  # Fetches users to impersonate whose name match the passed parameter&lt;br /&gt;
  def get_users_list&lt;br /&gt;
    users = current_user.get_available_users(params[:user_name])&lt;br /&gt;
    render json: { message: &amp;quot;Successfully Fetched User List!&amp;quot;, userList:users, success:true }, status: :ok&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def check_if_user_impersonateable?&lt;br /&gt;
    impersonate_user = User.find_by(id: params[:impersonate_id])&lt;br /&gt;
    if impersonate_user&lt;br /&gt;
      return current_user.can_impersonate? impersonate_user&lt;br /&gt;
    end&lt;br /&gt;
    false&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # Impersonates a new user and returns new jwt token&lt;br /&gt;
  def impersonate&lt;br /&gt;
    unless params[:impersonate_id].present?&lt;br /&gt;
      render json: { error: &amp;quot;impersonate_id is required&amp;quot;, success:false }, status: :unprocessable_entity&lt;br /&gt;
      return&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    if check_if_user_impersonateable?&lt;br /&gt;
      impersonate_user = User.find_by(id: params[:impersonate_id])&lt;br /&gt;
&lt;br /&gt;
      payload = { id: impersonate_user.id, name: impersonate_user.name, full_name: impersonate_user.full_name, role: impersonate_user.role.name,&lt;br /&gt;
                  institution_id: impersonate_user.institution.id, impersonated:true, original_user: current_user }&lt;br /&gt;
      impersonate_user_token = JsonWebToken.encode(payload, 24.hours.from_now)&lt;br /&gt;
&lt;br /&gt;
      render json: { message: &amp;quot;Successfully Impersonated #{impersonate_user.name}!&amp;quot;, token:impersonate_user_token, success:true }, status: :ok&lt;br /&gt;
&lt;br /&gt;
    else&lt;br /&gt;
      render json: { error: &amp;quot;You do not have permission to impersonate this user&amp;quot;, success:false }, status: :forbidden&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===User===&lt;br /&gt;
These methods extend the functionality of the User model. The get_available_users method retrieves users whose full names match a provided parameter. can_impersonate? determines whether the user has the authority to impersonate another user based on their role hierarchy. teaching_assistant_for? checks if the user is a teaching assistant for a given student, and teaching_assistant? determines if the user is a teaching assistant based on their role. Lastly, recursively_parent_of recursively checks for parent-child relationships between user roles.&lt;br /&gt;
&lt;br /&gt;
*user.rb file&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  # Check if the user can impersonate another user&lt;br /&gt;
  def can_impersonate?(user)&lt;br /&gt;
    return true if role.super_administrator?&lt;br /&gt;
    return true if recursively_parent_of(user.role)&lt;br /&gt;
    false&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # Check if the user is a teaching assistant for the student's course&lt;br /&gt;
  def teaching_assistant_for?(student)&lt;br /&gt;
    return false unless teaching_assistant?&lt;br /&gt;
    return false unless student.role.name == 'Student'&lt;br /&gt;
&lt;br /&gt;
    # We have to use the Ta object instead of User object&lt;br /&gt;
    # because single table inheritance is not currently functioning&lt;br /&gt;
    ta = Ta.find(id)&lt;br /&gt;
    ta.managed_users.each do |user|&lt;br /&gt;
      return true if user.id == student.id&lt;br /&gt;
    end&lt;br /&gt;
    false&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # Check if the user is a teaching assistant&lt;br /&gt;
  def teaching_assistant?&lt;br /&gt;
    true if role.ta?&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # Recursively check if parent child relationship exists&lt;br /&gt;
  def recursively_parent_of(user_role)&lt;br /&gt;
    p = user_role.parent&lt;br /&gt;
    return false if p.nil?&lt;br /&gt;
    return true if p == self.role&lt;br /&gt;
    return false if p.super_administrator?&lt;br /&gt;
    recursively_parent_of(p)&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Files added / modified ==&lt;br /&gt;
&lt;br /&gt;
*reimplementation-back-end/app/models/user.rb&lt;br /&gt;
*reimplementation-back-end/app/controllers/api/v1/impersonate_controller.rb&lt;br /&gt;
*reimplementation-back-end/config/routes.rb&lt;br /&gt;
&lt;br /&gt;
==List of Users in Database==&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! ID !! Email !! Password !! Role&lt;br /&gt;
|-&lt;br /&gt;
| 1 || admin2@example.com || password123 || Super-Administrator&lt;br /&gt;
|-&lt;br /&gt;
| 2 || jay@example.com || password123 || Administration&lt;br /&gt;
|-&lt;br /&gt;
| 3 || k2l@example.com || password123 || Instructor&lt;br /&gt;
|-&lt;br /&gt;
| 4 || mbhande@example.com || password123 || TA&lt;br /&gt;
|-&lt;br /&gt;
| 7 || dpatesl@example.com || password123 || Student&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==Testing on Postman==&lt;br /&gt;
&lt;br /&gt;
Postman was used to manually test the additional method in impersonate_controller.rb, as well as the actions and routes of the corresponding controllers. Before testing any of these methods with Postman, submit a request to /login using the user_name and password fields, which will send an authentication token. This token must be added to Postman's 'Authorization' tab as a 'Bearer token' before any further requests can be made. Postman collection [https://blue-water-189861.postman.co/workspace/New-Team-Workspace~5424a184-c780-48ec-8f35-3f009cce7e2e/collection/13428669-4d663583-0b90-4316-bd6c-9441ea576085?action=share&amp;amp;creator=13428669 link]&lt;br /&gt;
&lt;br /&gt;
*Fetch User List which can be impersonated (For eg: If Instructor fetches list he can see matched TAs and Students only)&lt;br /&gt;
[[File:Userlist.jpg | 500px]]&lt;br /&gt;
&lt;br /&gt;
* Login with provided credentials and copy the token&lt;br /&gt;
[[File:Postman-1.jpg | 500px]]&lt;br /&gt;
&lt;br /&gt;
*In the Expertiza/Authorization paste the token and save&lt;br /&gt;
[[File:Postman-2.jpg | 500px]]&lt;br /&gt;
&lt;br /&gt;
*Put the id for the user to be impersonated&lt;br /&gt;
[[File:Postman-3.jpg | 500px]]&lt;br /&gt;
&lt;br /&gt;
*Success message if the user is impersonable&lt;br /&gt;
[[File:Postman-4.jpg | 500px]]&lt;br /&gt;
&lt;br /&gt;
*Failure message if the user is not impersonable (Here instructor is trying to impersonate admin)&lt;br /&gt;
[[File:Inst-admin.jpg | 500px]]&lt;br /&gt;
&lt;br /&gt;
==Team==&lt;br /&gt;
'''Mentor''' &amp;lt;br&amp;gt;&lt;br /&gt;
*Chetana Chunduru &amp;lt;cchetan2@ncsu.edu&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Students'''&amp;lt;br&amp;gt;&lt;br /&gt;
*Devansh Shah &amp;lt;dshah8@ncsu.edu&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
*Jay Patel &amp;lt;jhpatel9@ncsu.edu&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
*Mihir Bhanderi &amp;lt;mbhande2@ncsu.edu&amp;gt;&amp;lt;br&amp;gt;&lt;/div&gt;</summary>
		<author><name>Mbhande2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2024_-_E2421._Reimplement_impersonating_users_(within_impersonate_controller.rb)&amp;diff=153286</id>
		<title>CSC/ECE 517 Spring 2024 - E2421. Reimplement impersonating users (within impersonate controller.rb)</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2024_-_E2421._Reimplement_impersonating_users_(within_impersonate_controller.rb)&amp;diff=153286"/>
		<updated>2024-03-24T01:15:52Z</updated>

		<summary type="html">&lt;p&gt;Mbhande2: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Expertiza==&lt;br /&gt;
&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is a [http://rubyonrails.org/ Ruby on Rails] based open source project. Instructors have the ability to add new projects, assignments, etc., as well as edit existing ones. Later on, they can view student submissions and grade them. Students can also use Expertiza to organize into teams to work on different projects and assignments and submit their work. They can also review other students' submissions.&lt;br /&gt;
&lt;br /&gt;
==Project Overview==&lt;br /&gt;
&lt;br /&gt;
The objective is to reimplement the backend code for the impersonation feature in the new implementation of Expertiza. The current implementation relies on sessions, which won't be compatible with the new implementation using JWT tokens for authentication and returning JSON responses. The challenge lies in transitioning the logic from session-based management to JWT-based authentication while maintaining the functionality of impersonating users. The reimplementation involves planning how the backend will communicate with the frontend, potentially requiring changes in existing or new files beyond the impersonate_controller.rb.&lt;br /&gt;
&lt;br /&gt;
==Implementation==&lt;br /&gt;
&lt;br /&gt;
===UML Diagram===&lt;br /&gt;
The following UML diagram shows the association between models we will be working on&lt;br /&gt;
&lt;br /&gt;
[[File:Uml reimplement impersonate.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Hierarchy Diagram===&lt;br /&gt;
Visualization of the hierarchical structure&lt;br /&gt;
&lt;br /&gt;
[[File:User-hierarchy.jpg]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Request===&lt;br /&gt;
&lt;br /&gt;
*GET: {BASE_URL}/api/v1/impersonate/:username&lt;br /&gt;
   - Response:&lt;br /&gt;
&lt;br /&gt;
    &amp;quot;message&amp;quot;: &amp;quot;Successfully Fetched User List!&amp;quot;,&lt;br /&gt;
    &amp;quot;userList&amp;quot;: [&lt;br /&gt;
        {&lt;br /&gt;
            &amp;quot;id&amp;quot;: 4,&lt;br /&gt;
            &amp;quot;name&amp;quot;: &amp;quot;Mihir&amp;quot;,&lt;br /&gt;
            &amp;quot;full_name&amp;quot;: &amp;quot;Mihir BHanderi&amp;quot;,&lt;br /&gt;
            &amp;quot;email&amp;quot;: &amp;quot;mbhande@example.com&amp;quot;,&lt;br /&gt;
            &amp;quot;email_on_review&amp;quot;: false,&lt;br /&gt;
            &amp;quot;email_on_submission&amp;quot;: false,&lt;br /&gt;
            &amp;quot;email_on_review_of_review&amp;quot;: false,&lt;br /&gt;
            &amp;quot;role&amp;quot;: {&lt;br /&gt;
                &amp;quot;id&amp;quot;: 4,&lt;br /&gt;
                &amp;quot;name&amp;quot;: &amp;quot;Teaching Assistant&amp;quot;&lt;br /&gt;
            },&lt;br /&gt;
            &amp;quot;institution&amp;quot;: {&lt;br /&gt;
                &amp;quot;id&amp;quot;: 1,&lt;br /&gt;
                &amp;quot;name&amp;quot;: &amp;quot;North Carolina State University&amp;quot;&lt;br /&gt;
            },&lt;br /&gt;
            &amp;quot;parent&amp;quot;: {&lt;br /&gt;
                &amp;quot;id&amp;quot;: null,&lt;br /&gt;
                &amp;quot;name&amp;quot;: null&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
    ],&lt;br /&gt;
    &amp;quot;success&amp;quot;: true&lt;br /&gt;
&lt;br /&gt;
*POST: {BASE_URL}/api/v1/impersonate&lt;br /&gt;
   - Payload: impersonate_id&lt;br /&gt;
   - Response: &lt;br /&gt;
&lt;br /&gt;
     &amp;quot;message&amp;quot;: &amp;quot;Successfully Impersonated Ketul!&amp;quot;,&lt;br /&gt;
     &amp;quot;token&amp;quot;: &amp;quot;eyJhbGciOiJSUzI1NiJ9.eyJpZCI6MywibmFtZSI6IktldHVsIiwiZnVsbF9uYW1lIjoiS2V0dWwgQ2hheXlhIiwicm9sZSI6Ikluc3RydWN0b3IiLCJpbnN0aXR1dGlvbl9pZCI6MSwiaW1wZXJzb25hdGVkIjp0cnVlLCJvcmlnaW5hbF91c2VyIjoiIzxVc2VyOjB4MDAwMDdmMzVmYTc5YjVmOD4iLCJleHAiOjE3MTEzMjc0MTV9.U9wDOT618UCkf25MnCiK8W3ybeZv5BSQDNTEPOMUDABAvDd0HWSj3kIGccITHaoVsIykZFsyUDY3rL_M32zmfEXvxZuEleWSqUZGxbjQRIFP1bR_Q5sPESoBdlxVJ4QG8sUGQtuhOzMyH3z4R4ruhz1JpsQlalVZQHCbdtJOI9B4WKhNJ98Dls1fefnzYwLMnTr6e3ttbGGGK5Bm8zSpPvIWmCVNoueKHNptFcNejbU4Mt9RHWHLsTwdAtuywNLCu7li7RRNXo00D5JOUMxL7eB5AiQRpxah8BF7b0lM_Xh7bB56WvD5JTjoNZu3c3AK_EJksGXiFxwlPzNRc8Q&amp;quot;,&lt;br /&gt;
    &amp;quot;success&amp;quot;: true&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Impersonate Controller===&lt;br /&gt;
impersonate_controller.rb file&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 class Api::V1::ImpersonateController &amp;lt; ApplicationController&lt;br /&gt;
&lt;br /&gt;
  # Fetches users to impersonate whose name match the passed parameter&lt;br /&gt;
  def get_users_list&lt;br /&gt;
    users = current_user.get_available_users(params[:user_name])&lt;br /&gt;
    render json: { message: &amp;quot;Successfully Fetched User List!&amp;quot;, userList:users, success:true }, status: :ok&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def check_if_user_impersonateable?&lt;br /&gt;
    impersonate_user = User.find_by(id: params[:impersonate_id])&lt;br /&gt;
    if impersonate_user&lt;br /&gt;
      return current_user.can_impersonate? impersonate_user&lt;br /&gt;
    end&lt;br /&gt;
    false&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # Impersonates a new user and returns new jwt token&lt;br /&gt;
  def impersonate&lt;br /&gt;
    unless params[:impersonate_id].present?&lt;br /&gt;
      render json: { error: &amp;quot;impersonate_id is required&amp;quot;, success:false }, status: :unprocessable_entity&lt;br /&gt;
      return&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    if check_if_user_impersonateable?&lt;br /&gt;
      impersonate_user = User.find_by(id: params[:impersonate_id])&lt;br /&gt;
&lt;br /&gt;
      payload = { id: impersonate_user.id, name: impersonate_user.name, full_name: impersonate_user.full_name, role: impersonate_user.role.name,&lt;br /&gt;
                  institution_id: impersonate_user.institution.id, impersonated:true, original_user: current_user }&lt;br /&gt;
      impersonate_user_token = JsonWebToken.encode(payload, 24.hours.from_now)&lt;br /&gt;
&lt;br /&gt;
      render json: { message: &amp;quot;Successfully Impersonated #{impersonate_user.name}!&amp;quot;, token:impersonate_user_token, success:true }, status: :ok&lt;br /&gt;
&lt;br /&gt;
    else&lt;br /&gt;
      render json: { error: &amp;quot;You do not have permission to impersonate this user&amp;quot;, success:false }, status: :forbidden&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Files added / modified ==&lt;br /&gt;
&lt;br /&gt;
*reimplementation-back-end/app/models/user.rb&lt;br /&gt;
*reimplementation-back-end/app/controllers/api/v1/impersonate_controller.rb&lt;br /&gt;
*reimplementation-back-end/config/routes.rb&lt;br /&gt;
&lt;br /&gt;
==List of Users in Database==&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! ID !! Email !! Password !! Role&lt;br /&gt;
|-&lt;br /&gt;
| 1 || admin2@example.com || password123 || Super-Administrator&lt;br /&gt;
|-&lt;br /&gt;
| 2 || jay@example.com || password123 || Administration&lt;br /&gt;
|-&lt;br /&gt;
| 3 || k2l@example.com || password123 || Instructor&lt;br /&gt;
|-&lt;br /&gt;
| 4 || mbhande@example.com || password123 || TA&lt;br /&gt;
|-&lt;br /&gt;
| 7 || dpatesl@example.com || password123 || Student&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==Testing on Postman==&lt;br /&gt;
&lt;br /&gt;
Postman was used to manually test the additional method in impersonate_controller.rb, as well as the actions and routes of the corresponding controllers. Before testing any of these methods with Postman, submit a request to /login using the user_name and password fields, which will send an authentication token. This token must be added to Postman's 'Authorization' tab as a 'Bearer token' before any further requests can be made. Postman collection [https://blue-water-189861.postman.co/workspace/New-Team-Workspace~5424a184-c780-48ec-8f35-3f009cce7e2e/collection/13428669-4d663583-0b90-4316-bd6c-9441ea576085?action=share&amp;amp;creator=13428669 link]&lt;br /&gt;
&lt;br /&gt;
*Fetch User List which can be impersonated (For eg: If Instructor fetches list he can see matched TAs and Students only)&lt;br /&gt;
[[File:Userlist.jpg | 500px]]&lt;br /&gt;
&lt;br /&gt;
* Login with provided credentials and copy the token&lt;br /&gt;
[[File:Postman-1.jpg | 500px]]&lt;br /&gt;
&lt;br /&gt;
*In the Expertiza/Authorization paste the token and save&lt;br /&gt;
[[File:Postman-2.jpg | 500px]]&lt;br /&gt;
&lt;br /&gt;
*Put the id for the user to be impersonated&lt;br /&gt;
[[File:Postman-3.jpg | 500px]]&lt;br /&gt;
&lt;br /&gt;
*Success message if the user is impersonable&lt;br /&gt;
[[File:Postman-4.jpg | 500px]]&lt;br /&gt;
&lt;br /&gt;
*Failure message if the user is not impersonable (Here instructor is trying to impersonate admin)&lt;br /&gt;
[[File:Inst-admin.jpg | 500px]]&lt;br /&gt;
&lt;br /&gt;
==Team==&lt;br /&gt;
'''Mentor''' &amp;lt;br&amp;gt;&lt;br /&gt;
*Chetana Chunduru &amp;lt;cchetan2@ncsu.edu&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Students'''&amp;lt;br&amp;gt;&lt;br /&gt;
*Devansh Shah &amp;lt;dshah8@ncsu.edu&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
*Jay Patel &amp;lt;jhpatel9@ncsu.edu&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
*Mihir Bhanderi &amp;lt;mbhande2@ncsu.edu&amp;gt;&amp;lt;br&amp;gt;&lt;/div&gt;</summary>
		<author><name>Mbhande2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=File:User-hierarchy.jpg&amp;diff=153280</id>
		<title>File:User-hierarchy.jpg</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=File:User-hierarchy.jpg&amp;diff=153280"/>
		<updated>2024-03-24T01:02:21Z</updated>

		<summary type="html">&lt;p&gt;Mbhande2: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Mbhande2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2024_-_E2421._Reimplement_impersonating_users_(within_impersonate_controller.rb)&amp;diff=153278</id>
		<title>CSC/ECE 517 Spring 2024 - E2421. Reimplement impersonating users (within impersonate controller.rb)</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2024_-_E2421._Reimplement_impersonating_users_(within_impersonate_controller.rb)&amp;diff=153278"/>
		<updated>2024-03-24T01:01:21Z</updated>

		<summary type="html">&lt;p&gt;Mbhande2: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Expertiza==&lt;br /&gt;
&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is a [http://rubyonrails.org/ Ruby on Rails] based open source project. Instructors have the ability to add new projects, assignments, etc., as well as edit existing ones. Later on, they can view student submissions and grade them. Students can also use Expertiza to organize into teams to work on different projects and assignments and submit their work. They can also review other students' submissions.&lt;br /&gt;
&lt;br /&gt;
==Project Overview==&lt;br /&gt;
&lt;br /&gt;
The objective is to reimplement the backend code for the impersonation feature in the new implementation of Expertiza. The current implementation relies on sessions, which won't be compatible with the new implementation using JWT tokens for authentication and returning JSON responses. The challenge lies in transitioning the logic from session-based management to JWT-based authentication while maintaining the functionality of impersonating users. The reimplementation involves planning how the backend will communicate with the frontend, potentially requiring changes in existing or new files beyond the impersonate_controller.rb.&lt;br /&gt;
&lt;br /&gt;
==Implementation==&lt;br /&gt;
&lt;br /&gt;
The following UML diagram shows the association between models we will be working on&lt;br /&gt;
&lt;br /&gt;
[[File:Uml reimplement impersonate.png]]&lt;br /&gt;
&lt;br /&gt;
===Request===&lt;br /&gt;
&lt;br /&gt;
*GET: {BASE_URL}/api/v1/impersonate/:username&lt;br /&gt;
   - Response:&lt;br /&gt;
&lt;br /&gt;
    &amp;quot;message&amp;quot;: &amp;quot;Successfully Fetched User List!&amp;quot;,&lt;br /&gt;
    &amp;quot;userList&amp;quot;: [&lt;br /&gt;
        {&lt;br /&gt;
            &amp;quot;id&amp;quot;: 4,&lt;br /&gt;
            &amp;quot;name&amp;quot;: &amp;quot;Mihir&amp;quot;,&lt;br /&gt;
            &amp;quot;full_name&amp;quot;: &amp;quot;Mihir BHanderi&amp;quot;,&lt;br /&gt;
            &amp;quot;email&amp;quot;: &amp;quot;mbhande@example.com&amp;quot;,&lt;br /&gt;
            &amp;quot;email_on_review&amp;quot;: false,&lt;br /&gt;
            &amp;quot;email_on_submission&amp;quot;: false,&lt;br /&gt;
            &amp;quot;email_on_review_of_review&amp;quot;: false,&lt;br /&gt;
            &amp;quot;role&amp;quot;: {&lt;br /&gt;
                &amp;quot;id&amp;quot;: 4,&lt;br /&gt;
                &amp;quot;name&amp;quot;: &amp;quot;Teaching Assistant&amp;quot;&lt;br /&gt;
            },&lt;br /&gt;
            &amp;quot;institution&amp;quot;: {&lt;br /&gt;
                &amp;quot;id&amp;quot;: 1,&lt;br /&gt;
                &amp;quot;name&amp;quot;: &amp;quot;North Carolina State University&amp;quot;&lt;br /&gt;
            },&lt;br /&gt;
            &amp;quot;parent&amp;quot;: {&lt;br /&gt;
                &amp;quot;id&amp;quot;: null,&lt;br /&gt;
                &amp;quot;name&amp;quot;: null&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
    ],&lt;br /&gt;
    &amp;quot;success&amp;quot;: true&lt;br /&gt;
&lt;br /&gt;
*POST: {BASE_URL}/api/v1/impersonate&lt;br /&gt;
   - Payload: impersonate_id&lt;br /&gt;
   - Response: &lt;br /&gt;
&lt;br /&gt;
     &amp;quot;message&amp;quot;: &amp;quot;Successfully Impersonated Ketul!&amp;quot;,&lt;br /&gt;
     &amp;quot;token&amp;quot;: &amp;quot;eyJhbGciOiJSUzI1NiJ9.eyJpZCI6MywibmFtZSI6IktldHVsIiwiZnVsbF9uYW1lIjoiS2V0dWwgQ2hheXlhIiwicm9sZSI6Ikluc3RydWN0b3IiLCJpbnN0aXR1dGlvbl9pZCI6MSwiaW1wZXJzb25hdGVkIjp0cnVlLCJvcmlnaW5hbF91c2VyIjoiIzxVc2VyOjB4MDAwMDdmMzVmYTc5YjVmOD4iLCJleHAiOjE3MTEzMjc0MTV9.U9wDOT618UCkf25MnCiK8W3ybeZv5BSQDNTEPOMUDABAvDd0HWSj3kIGccITHaoVsIykZFsyUDY3rL_M32zmfEXvxZuEleWSqUZGxbjQRIFP1bR_Q5sPESoBdlxVJ4QG8sUGQtuhOzMyH3z4R4ruhz1JpsQlalVZQHCbdtJOI9B4WKhNJ98Dls1fefnzYwLMnTr6e3ttbGGGK5Bm8zSpPvIWmCVNoueKHNptFcNejbU4Mt9RHWHLsTwdAtuywNLCu7li7RRNXo00D5JOUMxL7eB5AiQRpxah8BF7b0lM_Xh7bB56WvD5JTjoNZu3c3AK_EJksGXiFxwlPzNRc8Q&amp;quot;,&lt;br /&gt;
    &amp;quot;success&amp;quot;: true&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Files added / modified ==&lt;br /&gt;
&lt;br /&gt;
*reimplementation-back-end/app/models/user.rb&lt;br /&gt;
*reimplementation-back-end/app/controllers/api/v1/impersonate_controller.rb&lt;br /&gt;
*reimplementation-back-end/config/routes.rb&lt;br /&gt;
&lt;br /&gt;
==List of Users in Database==&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! ID !! Email !! Password !! Role&lt;br /&gt;
|-&lt;br /&gt;
| 1 || admin2@example.com || password123 || Super-Administrator&lt;br /&gt;
|-&lt;br /&gt;
| 2 || jay@example.com || password123 || Administration&lt;br /&gt;
|-&lt;br /&gt;
| 3 || k2l@example.com || password123 || Instructor&lt;br /&gt;
|-&lt;br /&gt;
| 4 || mbhande@example.com || password123 || TA&lt;br /&gt;
|-&lt;br /&gt;
| 7 || dpatesl@example.com || password123 || Student&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==Testing on Postman==&lt;br /&gt;
&lt;br /&gt;
Postman was used to manually test the additional method in impersonate_controller.rb, as well as the actions and routes of the corresponding controllers. Before testing any of these methods with Postman, submit a request to /login using the user_name and password fields, which will send an authentication token. This token must be added to Postman's 'Authorization' tab as a 'Bearer token' before any further requests can be made. Postman collection [https://blue-water-189861.postman.co/workspace/New-Team-Workspace~5424a184-c780-48ec-8f35-3f009cce7e2e/collection/13428669-4d663583-0b90-4316-bd6c-9441ea576085?action=share&amp;amp;creator=13428669 link]&lt;br /&gt;
&lt;br /&gt;
*Fetch User List which can be impersonated (For eg: If Instructor fetches list he can see matched TAs and Students only)&lt;br /&gt;
[[File:Userlist.jpg | 500px]]&lt;br /&gt;
&lt;br /&gt;
* Login with provided credentials and copy the token&lt;br /&gt;
[[File:Postman-1.jpg | 500px]]&lt;br /&gt;
&lt;br /&gt;
*In the Expertiza/Authorization paste the token and save&lt;br /&gt;
[[File:Postman-2.jpg | 500px]]&lt;br /&gt;
&lt;br /&gt;
*Put the id for the user to be impersonated&lt;br /&gt;
[[File:Postman-3.jpg | 500px]]&lt;br /&gt;
&lt;br /&gt;
*Success message if the user is impersonable&lt;br /&gt;
[[File:Postman-4.jpg | 500px]]&lt;br /&gt;
&lt;br /&gt;
*Failure message if the user is not impersonable (Here instructor is trying to impersonate admin)&lt;br /&gt;
[[File:Inst-admin.jpg | 500px]]&lt;br /&gt;
&lt;br /&gt;
==Team==&lt;br /&gt;
'''Mentor''' &amp;lt;br&amp;gt;&lt;br /&gt;
*Chetana Chunduru &amp;lt;cchetan2@ncsu.edu&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Students'''&amp;lt;br&amp;gt;&lt;br /&gt;
*Devansh Shah &amp;lt;dshah8@ncsu.edu&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
*Jay Patel &amp;lt;jhpatel9@ncsu.edu&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
*Mihir Bhanderi &amp;lt;mbhande2@ncsu.edu&amp;gt;&amp;lt;br&amp;gt;&lt;/div&gt;</summary>
		<author><name>Mbhande2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=File:Uml_reimplement_impersonate.png&amp;diff=153260</id>
		<title>File:Uml reimplement impersonate.png</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=File:Uml_reimplement_impersonate.png&amp;diff=153260"/>
		<updated>2024-03-24T00:42:29Z</updated>

		<summary type="html">&lt;p&gt;Mbhande2: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Mbhande2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=File:UML_Diagram.png&amp;diff=153257</id>
		<title>File:UML Diagram.png</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=File:UML_Diagram.png&amp;diff=153257"/>
		<updated>2024-03-24T00:41:46Z</updated>

		<summary type="html">&lt;p&gt;Mbhande2: Mbhande2 reverted File:UML Diagram.png to an old version&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Mbhande2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=File:UML_Diagram.png&amp;diff=153253</id>
		<title>File:UML Diagram.png</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=File:UML_Diagram.png&amp;diff=153253"/>
		<updated>2024-03-24T00:39:27Z</updated>

		<summary type="html">&lt;p&gt;Mbhande2: Mbhande2 uploaded a new version of File:UML Diagram.png&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Mbhande2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=File:Userlist.jpg&amp;diff=153237</id>
		<title>File:Userlist.jpg</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=File:Userlist.jpg&amp;diff=153237"/>
		<updated>2024-03-24T00:10:38Z</updated>

		<summary type="html">&lt;p&gt;Mbhande2: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Mbhande2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2024_-_E2421._Reimplement_impersonating_users_(within_impersonate_controller.rb)&amp;diff=153217</id>
		<title>CSC/ECE 517 Spring 2024 - E2421. Reimplement impersonating users (within impersonate controller.rb)</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2024_-_E2421._Reimplement_impersonating_users_(within_impersonate_controller.rb)&amp;diff=153217"/>
		<updated>2024-03-23T23:43:27Z</updated>

		<summary type="html">&lt;p&gt;Mbhande2: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Expertiza==&lt;br /&gt;
&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is a [http://rubyonrails.org/ Ruby on Rails] based open source project. Instructors have the ability to add new projects, assignments, etc., as well as edit existing ones. Later on, they can view student submissions and grade them. Students can also use Expertiza to organize into teams to work on different projects and assignments and submit their work. They can also review other students' submissions.&lt;br /&gt;
&lt;br /&gt;
==Project Overview==&lt;br /&gt;
&lt;br /&gt;
The objective is to reimplement the backend code for the impersonation feature in the new implementation of Expertiza. The current implementation relies on sessions, which won't be compatible with the new implementation using JWT tokens for authentication and returning JSON responses. The challenge lies in transitioning the logic from session-based management to JWT-based authentication while maintaining the functionality of impersonating users. The reimplementation involves planning how the backend will communicate with the frontend, potentially requiring changes in existing or new files beyond the impersonate_controller.rb.&lt;br /&gt;
&lt;br /&gt;
==Testing on Postman==&lt;br /&gt;
Postman was used to manually test the additional method in impersonate_controller.rb, as well as the actions and routes of the corresponding controllers. Before testing any of these methods with Postman, submit a request to /login using the user_name and password fields, which will send an authentication token. This token must be added to Postman's 'Authorization' tab as a 'Bearer token' before any further requests can be made.&lt;br /&gt;
&lt;br /&gt;
* Login with provided credentials and copy the token&lt;br /&gt;
[[File:Postman-1.jpg | 500px]]&lt;br /&gt;
&lt;br /&gt;
*In the Expertiza/Authorization paste the token and save&lt;br /&gt;
[[File:Postman-2.jpg | 500px]]&lt;br /&gt;
&lt;br /&gt;
*Put the id for the user to be impersonated&lt;br /&gt;
[[File:Postman-3.jpg | 500px]]&lt;br /&gt;
&lt;br /&gt;
*Success message if the user is impersonable&lt;br /&gt;
[[File:Postman-4.jpg | 500px]]&lt;br /&gt;
&lt;br /&gt;
*Failure message if the user is not impersonable (Here instructor is trying to impersonate admin)&lt;br /&gt;
[[File:Inst-admin.jpg | 500px]]&lt;br /&gt;
&lt;br /&gt;
==Team==&lt;br /&gt;
'''Mentor''' &amp;lt;br&amp;gt;&lt;br /&gt;
*Chetana Chunduru &amp;lt;cchetan2@ncsu.edu&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Students'''&amp;lt;br&amp;gt;&lt;br /&gt;
*Devansh Shah &amp;lt;dshah8@ncsu.edu&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
*Jay Patel &amp;lt;jhpatel9@ncsu.edu&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
*Mihir Bhanderi &amp;lt;mbhande2@ncsu.edu&amp;gt;&amp;lt;br&amp;gt;&lt;/div&gt;</summary>
		<author><name>Mbhande2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=File:Inst-admin.jpg&amp;diff=153206</id>
		<title>File:Inst-admin.jpg</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=File:Inst-admin.jpg&amp;diff=153206"/>
		<updated>2024-03-23T23:28:24Z</updated>

		<summary type="html">&lt;p&gt;Mbhande2: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Mbhande2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=File:Postman-4.jpg&amp;diff=153205</id>
		<title>File:Postman-4.jpg</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=File:Postman-4.jpg&amp;diff=153205"/>
		<updated>2024-03-23T23:28:11Z</updated>

		<summary type="html">&lt;p&gt;Mbhande2: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Mbhande2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=File:Postman-3.jpg&amp;diff=153204</id>
		<title>File:Postman-3.jpg</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=File:Postman-3.jpg&amp;diff=153204"/>
		<updated>2024-03-23T23:27:52Z</updated>

		<summary type="html">&lt;p&gt;Mbhande2: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Mbhande2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=File:Postman-2.jpg&amp;diff=153203</id>
		<title>File:Postman-2.jpg</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=File:Postman-2.jpg&amp;diff=153203"/>
		<updated>2024-03-23T23:27:26Z</updated>

		<summary type="html">&lt;p&gt;Mbhande2: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Mbhande2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=File:Postman-1.jpg&amp;diff=153200</id>
		<title>File:Postman-1.jpg</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=File:Postman-1.jpg&amp;diff=153200"/>
		<updated>2024-03-23T23:24:40Z</updated>

		<summary type="html">&lt;p&gt;Mbhande2: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Mbhande2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2024_-_E2421._Reimplement_impersonating_users_(within_impersonate_controller.rb)&amp;diff=153143</id>
		<title>CSC/ECE 517 Spring 2024 - E2421. Reimplement impersonating users (within impersonate controller.rb)</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2024_-_E2421._Reimplement_impersonating_users_(within_impersonate_controller.rb)&amp;diff=153143"/>
		<updated>2024-03-23T20:38:53Z</updated>

		<summary type="html">&lt;p&gt;Mbhande2: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Expertiza==&lt;br /&gt;
&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is a [http://rubyonrails.org/ Ruby on Rails] based open source project. Instructors have the ability to add new projects, assignments, etc., as well as edit existing ones. Later on, they can view student submissions and grade them. Students can also use Expertiza to organize into teams to work on different projects and assignments and submit their work. They can also review other students' submissions.&lt;br /&gt;
&lt;br /&gt;
==Project Overview==&lt;br /&gt;
&lt;br /&gt;
The objective is to reimplement the backend code for the impersonation feature in the new implementation of Expertiza. The current implementation relies on sessions, which won't be compatible with the new implementation using JWT tokens for authentication and returning JSON responses. The challenge lies in transitioning the logic from session-based management to JWT-based authentication while maintaining the functionality of impersonating users. The reimplementation involves planning how the backend will communicate with the frontend, potentially requiring changes in existing or new files beyond the impersonate_controller.rb.&lt;br /&gt;
&lt;br /&gt;
==Team==&lt;br /&gt;
'''Mentor''' &amp;lt;br&amp;gt;&lt;br /&gt;
Chetana Chunduru &amp;lt;cchetan2@ncsu.edu&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Students'''&amp;lt;br&amp;gt;&lt;br /&gt;
Devansh Shah &amp;lt;dshah8@ncsu.edu&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
Jay Patel &amp;lt;jhpatel9@ncsu.edu&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
Mihir Bhanderi &amp;lt;mbhande2@ncsu.edu&amp;gt;&amp;lt;br&amp;gt;&lt;/div&gt;</summary>
		<author><name>Mbhande2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2024_-_E2421._Reimplement_impersonating_users_(within_impersonate_controller.rb)&amp;diff=153103</id>
		<title>CSC/ECE 517 Spring 2024 - E2421. Reimplement impersonating users (within impersonate controller.rb)</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2024_-_E2421._Reimplement_impersonating_users_(within_impersonate_controller.rb)&amp;diff=153103"/>
		<updated>2024-03-23T18:38:13Z</updated>

		<summary type="html">&lt;p&gt;Mbhande2: Created page with &amp;quot;==Expertiza==  [http://expertiza.ncsu.edu/ Expertiza] is a [http://rubyonrails.org/ Ruby on Rails] based open source project. Instructors have the ability to add new projects, assignments, etc., as well as edit existing ones. Later on, they can view student submissions and grade them. Students can also use Expertiza to organize into teams to work on different projects and assignments and submit their work. They can also review other students' submissions.  ==Project Over...&amp;quot;&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Expertiza==&lt;br /&gt;
&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is a [http://rubyonrails.org/ Ruby on Rails] based open source project. Instructors have the ability to add new projects, assignments, etc., as well as edit existing ones. Later on, they can view student submissions and grade them. Students can also use Expertiza to organize into teams to work on different projects and assignments and submit their work. They can also review other students' submissions.&lt;br /&gt;
&lt;br /&gt;
==Project Overview==&lt;br /&gt;
&lt;br /&gt;
The objective is to reimplement the backend code for the impersonation feature in the new implementation of Expertiza. The current implementation relies on sessions, which won't be compatible with the new implementation using JWT tokens for authentication and returning JSON responses. The challenge lies in transitioning the logic from session-based management to JWT-based authentication while maintaining the functionality of impersonating users. The reimplementation involves planning how the backend will communicate with the frontend, potentially requiring changes in existing or new files beyond the impersonate_controller.rb.&lt;/div&gt;</summary>
		<author><name>Mbhande2</name></author>
	</entry>
</feed>