CSC/ECE 517 Fall 2022 - E2283 Refactor student teams functionality

From Expertiza_Wiki
Jump to navigation Jump to search

Introduction and prior work

The Expertiza project is software to create reusable learning objects through peer review. It also supports team projects, and the submission of almost any document type, including URLs and wiki pages.

Users & Participants: Everyone who took the CSC517 OODD class at NC State is a user in Expertiza, and instructors can add users as participants in an assignment so that they can access it to contribute, make changes and submit their work to be graded.

Almost all of the work within Assignments is done by participants, not users. All the tables use participant_id to track contributions to assignments, except teams_users. The team_users table references users instead of participants. This anomaly in the teams_users relation causes problems with how student teams are rendered in the UI, and it doesn’t mix well with the new functionality that was recently introduced. The participant_id field should be added to the model, and references that use user_id should also incorporate participant_id. Ideally, the application should use only participant_id, but to handle the existing data in the database without running a massive migration, the application should be able to handle both old records that use user_id and new ones that shall, from after this project is completed, use participant_id instead.

E2263 contains detailed information on the previous team's work on this feature.

Tasks

Issue 1

  • Changing the schema without directly modifying schema.rb file. Changes in schema are done through the migration files.
    • We need to rename the table table 'teams_users' to teams_participants
    • Create a column called “participant_id”, which is a foreign key that references participants table.
    • Create a migration that fetches the assignment_id for each tuple from the teams table. We would find the participant with the help of the assignment_id we just got from the teams table and the user_id that is already present in the current table, and store its “id” in the participant_id column we created in the last step. We have to come with optimal migration strategy that reliably calculates the participant_id
    • Find out all the places where user_id is being used, refactor those so that participant id is used. It would be good if changes are made in one place so that we won’t have to change code everywhere
    • Get rid of the user_id column.

Issue 2

  • Refactoring the teams rendering (/views/student_teams/view.html.erb)
    • The logic in the team's view (where participants can see their team members) that iterates and fetches information of all the team members and displays them would be refactored so that it matches our new design. A data migration will be needed.
    • The view is quite bloated and has lots of functionalities written on it. We’ll be making partials and placing those functionality in their specific partials.
    • The new changes should not break the view that works for data where things are populated with user_id. We need to separate the older functionality into a separate partial and code the new functionality into a separate partial.
    • We must ensure that going forward, all the teams are being formed with participant_id instead of user_id.

Issue 3

  • Fix failing tests and modify tests to add participant_id
    • The current program has lot of failing tests and coverage is pretty low. We need to fix those test cases.
    • We also have to modify the existing test cases to use user_id instead of participant_id.

Issue 4

  • Rename the teams_users_controller to teams_participants_controller (and all its references)

Issue 5

  • The html.erb files have extensive ruby code written for fetching data from the database. This code need to be removed from the view files and placed into helper classes.

Issue 6

  • Need to write extensive test cases for all the code that we add.

Issue 7

  • There is some code where sql queries are written to fetch data (Line 16 & 17 on app/models/signed_up_team.rb), which need to be replaced with fetching data from rails ActiveRecord methods.

Issue 8

  • Need to update logic for all the crud functionalities in teams_users controller.

Issue 9

  • Bug in the Team information page
    • Bug in team information page (“Your team” tab where we can view and manage our team), which allows the same user to be added twice (or many times). Below image can help understand the issue better.
    • This is most likely due to the instructor adding a member to a team whom the user has already invited, but we’ve to dig deep into how exactly we can recreate this issue. Mentioning in writeup all the ways we can create a team (this will help us in weeding out redundant features).

Design Implementation

Schema changes

A new column participant_id is added in the teams_users table, which is a foreign key from the participants table, and the column user_id is removed. We removed the user_id column only after data migration since the user_id field is used predominantly in other controllers in several ways.

The participant_id field in the teams_users relation is calculated as follows:

Finding assignment_id by team_id: The teams_users table contains team_id, user_id, and duty_id but not the participant_id. Since the same user can participate in multiple assignments and gets a unique participant_id in each assignment they take part in, the same user_id can be associated with multiple participant_id. So, we need to get the user_ids in the assignment for which we need the particular user's participant_id and we need to first find the assignment_id.

Finding participant_id by assignment_id and user_id: With the assignment_id, we can find the list of participant_ids that participated in the assignment, and using the user_id we can get the participant_id which is saved in the participants table.

The user_id column is removed and participant_id column is added.

View Changes

One of the requirements is the refactoring of the student_teams view in views/student_teams/view.html.erb

This view is quite cluttered and makes editing and understanding difficult for any future updates to the Expertiza application. The code here can be changed to obtain simpler and easier-to-understand. The view can be refactored to incorporate partials, and some of the partials that can be created are:

_invited_people.html.erb : partial for displaying the invited participants to the assignment team
_display_advertisements.html.erb : partial for displaying advertisements in the view
_send_invitaions.html.erb : partial for the send invitations functionality
_received_invitations.html.erb : partial to display the received invitations for the current user

Changed Files

  • signed_up_team.rb (expertiza/app/models/signed_up_team.rb)

The model will be updated to fetch data from rails ActiveRecord methods instead of SQL queries.

  • Remove code for fetching data from the following files:
    • app/views/advertise_for_partner/show.html.erb
    • app/views/assignments/edit/_badges.html.erb
    • app/views/assignments/edit/_calibration.html.erb
    • app/views/assignments/edit/_late_policy.html.erb
    • app/views/bookmarks/list.html.erb
    • app/views/duties/_add_duties.html.erb
    • app/views/grades/_author_feedback_tab.html.erb
    • app/views/grades/_questionnaire.html.erb
    • app/views/grades/_reviews.html.erb
    • app/views/grades/_tabbed_reviews.html.erb
    • app/views/grades/view_team.html.erb
    • app/views/join_team_requests/_list_received.html.erb
    • app/views/join_team_requests/_list_sent.html.erb
    • app/views/popup/participants_popup.html.erb
    • app/views/popup/view_review_scores_popup.html.erb
    • app/views/questionnaires/_quiz_questionnaire.html.erb
    • app/views/reports/_bookmark_rating_report.html.erb
    • app/views/reports/_calibration_report.html.erb
    • app/views/reports/_feedback_report.html.erb
    • app/views/reports/_review_report.html.erb
    • app/views/reports/_teammate_review_report.html.erb
    • app/views/response/response.html.erb
    • app/views/response/show_calibration_results_for_student.html.erb
    • app/views/response/view.html.erb
    • app/views/review_mapping/_list_review_mappings.html.erb
    • app/views/shared/_flash_notifications.html.erb
    • app/views/shared/responses/_response_actions.html.erb
    • app/views/sign_up_sheet/_actions.html.erb
    • app/views/sign_up_sheet/_add_signup_topics_staggered.html.erb
    • app/views/sign_up_sheet/_add_signup_topics.html.erb
    • app/views/sign_up_sheet/_topic_names.html.erb
    • app/views/sign_up_sheet/_total_1_2_bids.html.erb
    • app/views/sign_up_sheet/_total_bids.html.erb
    • app/views/sign_up_sheet/review_bids_others_work.html.erb
    • app/views/sign_up_sheet/show_team.html.erb
    • app/views/student_quizzes/finished_quiz.html.erb
    • app/views/student_quizzes/review_questions.html.erb
    • app/views/student_quizzes/take_quiz.html.erb
    • app/views/student_review/_responses.html.erb
    • app/views/student_teams/_received_invitations.html.erb
    • app/views/student_teams/_select_duty_form.html.erb
    • app/views/student_teams/view.html.erb
    • app/views/submitted_content/_main.html.erb
    • app/views/submitted_content/_self_review.html.erb
    • app/views/submitted_content/_submitted_files.html.erb
    • app/views/versions/search.html.erb
  • Add code to fetch data in the helpers files of the corresponding files above.
  • teams_controller.rb

Resolve a bug in the teams information view page

Changes Made

There are other changes made too. However, we are just providing a brief outlook of our project here.

Issue 1 & 2
'participant_id' column is added and is referenced as foreign key from the 'participants' table. Then, the data is fetched using the following migration.


A method "add_participant_to_team" is added in "team" model and used to add a participant to a team.

Issue 3

This is only one of the many changes we are giving here.
The code in teams views' html.erb file is divided into partials.

The html code to display team information is placed into a new file and called here as a partial.
File:Writing ‘view’ code into partials.jpeg


Code to display team - added in a new html.erb file
File:Writing ‘view’ code into partials 2.jpeg


Issue 7

The SQL queries are replaced by queries using ActiveRecord methods in the following way.


Issue 8

Fetching the participant object corresponding to the user_id and assignment_id and using this to create a team_user.


Fetching the participant object corresponding to the user_id and assignment_id and using this to delete a team_user object.


Whenever a user is deleted, the corresponding entries for team_user for that user will also be deleted.

Test Plan

RSpec Unit Tests

Test cases provided here will add RSpec code blocks for the final submission
Case 1: Scenario: The participant is adding a new team member to the team Given: Logged in as a student or instructor When: The participant adds a new team member under the "Invite people" section on the "Your team" page Then: The participant is able to add the member to the team

Case 2: Scenario: The participant is adding an already existing team member to the team Given: Logged in as a student or instructor When: The participant adds an already existing team member under the "Invite people" section on the "Your team" page Then: The participant is not able to add the team member

Manual Testing

First login in as instructor using:

  • Username: instructor6
  • Password: password

When logged in as an instructor:

  • Impersonate a student
  • Navigate to the "Your team" page in project details.
  • Add a team member by entering their UnityID in the text box under "Invite people" section.
  • Click "Invite".
  • An invitation is sent to the member, accept it by impersonation receiving user.
  • Once the team member is added, impersonate the sender again.
  • Enter the already existing team member's UnityID and click on "Invite"
  • A message saying "The user "student2" is already a member of the team." should appear and text box should be cleared.

Important Links

Github Pull Request: https://github.com/expertiza/expertiza/pull/2484

Github Repo: https://github.com/rjain09/e2283-development

Demo: https://www.youtube.com/watch?v=qJhhFgmVvKs

Team Information

Mentors:
Naman Shrimali (nshrima@ncsu.edu)
Neha Kotcherlakota (nkotche@ncsu.edu)

Team members:
Sahithi Ammana (sammana@ncsu.edu)
Rithik Jain (rjain25@ncsu.edu)