CSC/ECE 517 Spring 2024 - E2403 Mentor-Meeting Management

From Expertiza_Wiki
Revision as of 15:49, 24 March 2024 by Slkwiatk (talk | contribs) (Created page with "== Introduction == <nowiki>The User model is a crucial component of the Expertiza application, managing user data and authentication/authorization. It has 9 class methods, 23 instance methods, and is linked with other models for personalized user experience. The user controller is smaller but could benefit from refactoring and improved comments.</nowiki> ==Files Changes== #app/models/user.rb #app/models/instructor.rb #app/models/ta.rb #app/models/superadministrator.rb...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Introduction

The User model is a crucial component of the Expertiza application, managing user data and authentication/authorization. It has 9 class methods, 23 instance methods, and is linked with other models for personalized user experience. The user controller is smaller but could benefit from refactoring and improved comments.

Files Changes

  1. app/models/user.rb
  2. app/models/instructor.rb
  3. app/models/ta.rb
  4. app/models/superadministrator.rb
  5. app/controller/user_controller.rb

Test Plan

Since this is a refactoring project no new features were introduced and any modifications made were focused on refactoring the code and eliminating redundant elements. The main objective of our task was to refactor the user-related methods so that the existing tests pass. New tests have been created, and they along with existing tests run successfully indicating that the code still functions properly.

Modifications made

  1. Refactor can_impersonate? method in user.rb
  2. Refactor recursively_parent_of? method by shorting
  3. Refactor teaching_assistant_for? method by shorting
  4. Refactor validate methods in user.rb
  5. Removed unused method salt_first?
  6. Bug fix in teaching_assistant_for? method
  7. Remove unused method creator_of? in user.rb
  8. Refactor get_user_list method in instructor.rb
  9. Removed unused scope in user.rb
  10. Removed redundant delete calls in user_controller#destroy
  11. Removed params.permit! by passing required params in user_params
  12. Refactor user_controller#show_if_authorized
  13. Refactor user_controller#create method
  14. Extracted anonymized methods from user.rb to anonymized_helpers.rb
  15. Renamed get_available_users to get_visible_users_with_lesser_roles to
  16. Replace delegate methods in user.rb to follows same method style
  17. Refactor yesorno method in UserHelper method
  18. Rename method foreign to get_roles

Description of the Refactored Changes

Rename method foreign to get_roles: 

Renamed the method foreign in a precise manner so that it describes the functionality of the method, as the method foreign gets the role of the User.

Refactor yesorno method in UserHelper method: 

Removed redundant lines of code in the yesorno method and made changes in the code in such a way that the code looks cleaner and describable.

To make it more concise, we added a return statement for the functionality of the method.

Replace delegate methods in user.rb to follows same method style: 

Replaced all the delegate methods in the user model to make every function of the model to be in the similar fashion. This change increases the code readability.

Renamed get_available_users to get_visible_users_with_lesser_roles to: 

Replaced all the occurrences of the ‘get_available_users’ to ‘get_visible_users_with_lesser_roles’ as the method is obtaining results of the users with roles and not the available users. This change makes the function more descriptive on what the method is returning.

Extracted anonymized methods from user.rb to anonymized_helpers.rb: 

Created a separate module named AnonymizedHelper with the details extracted from the anonymized view in the user model and then included the module in the user model for the extraction of the anonymized view from the model.

Refactor user_controller#show_if_authorized:

Refactored the user controller method by removing redundant statements.


Refactor user_controller#create method:

Refactored the create method in the user_controller by adding appropriate functions separately rather including many lines of code into the single functions and enhancing the readability of the method.

Removed redundant delete calls in user_controller#destroy:

Removed all the redundant lines of code from the destroy method in the user controller.

Removed params.permit! by passing required params in user_params:

Removed the params.permit! statement and included them while passing the user_params.

Removed unused scope in user.rb:

Removed all the unused redundant scope variables from the user model.

Refactor can_impersonate? method in user.rb:

Removed all the extra lines of code and refactored it to a single line statement to determine the can_impersonate user function.

Refactor recursively_parent_of? method by shorting:

Removed and deduced the code present in the recursively_parent function into a single statement.

Refactor teaching_assistant_for? method by shorting:

Reduce the code size of teaching_assistant_for? Function by using an or operator to combine two separate return statements.

Refactor validate methods in user.rb

Reduced the code size by combining multiple validation attributes written separately into one line validation containing all attributes.

removed unused method salt_first? In user.rb and user_spec.rb

Removed salt_first? Function in user.rb and its tests in user_spec.rb as it doesn’t have any it is not used for any functionality of the app



bug fix in teaching_assistant_for? Method in user.rb

Bug cause by the code written by us was fixed in this commit


remove unused method creator_of? in user.rb

creator_of function is removed from user.rb as it doesn’t contribute to the functionality of app and its test in user_spec.rb are also deleted.



refactor get_user_list method in instructor.rb 


<be>

Additional Tests Added

Tests added for yesorno method: 

Added additional tests for yesorno function in User Helper file
<be>


Tests for show_if_authorized: 

Added additional tests for show_if_authorized function in user controller file. The test redirects to lists and sets a flash message if user doesn't exit
<be>

Test Coverage

Test coverage has been increased by 39.5% as it can be seen in the PR.

Project Mentor

Ankur Mundra(amundra@ncsu.edu)

Contributors to this project

Dhrumil Jignesh Shah (dshah6@ncsu.edu) Keerthana Telaprolu (ktelapr@ncsu.edu) Saigirishwar Rohit Geddam (sgeddam2@ncsu.edu)

Relevant Links

GitHub PR [[1]]