CSC/ECE 517 Fall 2023 - E2359. Refactor user controller.rb, user.rb, and its child classes

From Expertiza_Wiki
Revision as of 01:51, 31 October 2023 by Srdodda (talk | contribs)
Jump to navigation Jump to search

Expertiza

Expertiza is a 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.

Problem Statement

Tasks that were accomplished:


Files Modified

We have recently made some improvements to the codebase by refactoring several methods in the application. These changes were made to enhance code readability, reduce redundancy, and promote best coding practices. In particular, we have streamlined methods related to listing, retrieving, and filtering data, resulting in cleaner and more maintainable code. These modifications aim to make our codebase more efficient while maintaining the same functionality as before.

Changed files:

  • app/controllers/impersonate_controller.rb
  • app/controllers/users_controller.rb
  • app/controllers/questionnaires_controller.rb
  • app/models/instructor.rb
  • app/models/ta.rb
  • app/models/user.rb
  • app/models/assignment_form.rb
  • spec/models/ta_spec.rb
  • spec/models/user_spec.rb

New Files:

  • app/helpers/anonymized_helper.rb

Refactoring

The refactoring includes the following changes to improve code quality, readability, and maintainability while preserving the functionality of our software.

  • Recognized the need for refactoring to improve code readability and maintainability.
  • Introduced a new method, get_participants_from_instructed_entities, to handle the retrieval of participants from entities (either Course or Assignment) where the given user is an instructor.
  • Replaced nested loops with more concise and efficient array operations using flat_map, reducing temporary arrays and enhancing code organization.
  • Introduced a new method, filter_participants, to handle participant filtering based on user privileges. This reduced code duplication and improved readability.
  • In the my_tas method, replaced the loop with a flat_map operation, extracting TA IDs directly from the TaMapping records. This simplified the code and improved efficiency.
  • In the list_all, list_mine, and get methods, introduced a new method, filter_by_instructor, to handle filtering records based on the instructor ID and whether private records should be included. This reduced code duplication and improved readability.
  • Throughout the refactoring process, maintained the same functionality while adding comments to explain the purpose of each method and operation.
  • Used string interpolation instead of string concatenation for better readability.
  • Removed redundant scopes in user.rb
  • Refactored validations in user.rb
  • Modified method names to reflect responsibility of the code
  • Followed DRY principle and extracted repeated methods into helpers
  • Added separate module for functionality pertaining to anonymized view.
instructor.rb

app/models/instructor.rb

ta.rb

app/models/ta.rb

--- ---

---

---

assignment_form.rb

assignment_form.rb


ta_spec.rb

spec/models/ta_spec.rb

---

app/controllers/users_controller.rb

Testing Plan

Next Steps

Team

Mentor
  • Devashish Vachhani
Members
  • Doddaguni, Sachin R
  • Mahesh, Amogh
  • Villar, Sergio Vargas

References

  1. Expertiza
  2. OSS Projects on Expertiza