CSC/ECE 517 Fall 2022 - E2252. Refactor auth controller.rb & password retrieval controller.rb: Difference between revisions

From Expertiza_Wiki
Jump to navigation Jump to search
(Added description of expertiza and changes to auth_controller.rb)
Line 1: Line 1:
== Overview of Expertiza ==
== Overview of Expertiza ==
TODO: Add description of general expertiza system and how our controllers relate to the overall functionality.
Expertiza is an open source software written using Ruby on Rails which functions as a learning management software system. It has man different functions and abilities including the ability to create assignments, quizzes, assignment groups and topics, and also a complete mechanism for providing peer reviews and feedback for other groups and other teammates. Part of its functionality is a system for user authentication with different user roles and permissions that determine how each user interacts with the content. The <code>auth_controller.rb</code> and <code>password_retrieval_controller.rb</code> which are the files primarily addressed in this project are both critical controllers in providing this functionality.
== Description of Project ==
== Description of Project ==
TODO: Describe the objectives of the project and what issues we were attempting to address.
TODO: Describe the objectives of the project and what issues we were attempting to address.
== Files Modified ==
== Files Modified ==
Changes to <code>app/controllers/password_retrieval_controller.rb</code>:
=== Changes to <code>app/controllers/password_retrieval_controller.rb</code> ===
{| class="wikitable" style="width: 100%;
{| class="wikitable" style="width: 100%;
! &nbsp;#&nbsp; !! Change !! Rationale !! Commit Link
! &nbsp;#&nbsp; !! Change !! Rationale !! Commit Link
Line 34: Line 34:
|}
|}


Changes to <code>config/routes.rb</code>:
=== Changes to <code>config/routes.rb</code> ===
{| class="wikitable" style="width: 100%;
{| class="wikitable" style="width: 100%;
! &nbsp;#&nbsp; !! Change !! Rationale !! Commit Link
! &nbsp;#&nbsp; !! Change !! Rationale !! Commit Link
Line 43: Line 43:
|[https://github.com/expertiza/expertiza/commit/3f9f63ab51e90743dfab0b860574aa9b673f2717 Commit]
|[https://github.com/expertiza/expertiza/commit/3f9f63ab51e90743dfab0b860574aa9b673f2717 Commit]
|-
|-
|}
=== Changes to <code>app/controllers/auth_controller.rb</code> ===
{| class="wikitable" style="width: 100%;
! &nbsp;#&nbsp; !! Change !! Rationale !! Commit Link
|-
|1
|Move logger messages to <code>before_action</code> blocks wherever possible
|Logger messages are inserted to log important events occurring in the code and do not relate directly to the logic. When possible, moving them to either <code>before_action</code> or <code>after_action</code> blocks makes the code more readable and easier to understand. It also separates the functionality of the method itself and the logging functionality.
|[https://github.com/greyfiles/expertiza/commit/7069f5d3cbfa2b7259e85e39dbfbf6fb41a0ce1d Commit]
|-
|2
|Replaced repeated code for both handling a failed login and re-caching the user role
|We noticed that although not listed on the recommended changes, these two actions involved exactly repeated code in the controller. The use of repeated code violates the DRY principle and so it was moved to a new method.
|[https://github.com/greyfiles/expertiza/commit/9ef20cffa0fe7b8440b97856a6db4b5351eece35 Commit]
|-
|3
|Improved helper function names
|Originally we made the new helper functions used in logging have unhelpful, confusing names. Making them more clear helps the code to be more understandable.
|[https://github.com/greyfiles/expertiza/commit/32f8435255add7b44b38fd747f81f435d331d14d Commit]
|}
|}


== Testing ==
== Testing ==
TODO: Show how the existing testing suite was passing before and after our refactoring - preserving functionality.
TODO: Show how the existing testing suite was passing before and after our refactoring - preserving functionality.
=== Testing <code>password_retrieval_controller.rb</code> ===
TODO: Add testing description for password_retrieval_controller.rb
=== Testing <code>auth_controller_.rb</code> ===


== Relevant Links ==
== Relevant Links ==
* '''Github Repository:''' https://github.com/greyfiles/expertiza
* '''Github Repository:''' https://github.com/greyfiles/expertiza
* '''Pull Request:''' https://github.com/expertiza/expertiza/pull/2460
* '''Pull Request:''' https://github.com/expertiza/expertiza/pull/2460

Revision as of 22:20, 25 October 2022

Overview of Expertiza

Expertiza is an open source software written using Ruby on Rails which functions as a learning management software system. It has man different functions and abilities including the ability to create assignments, quizzes, assignment groups and topics, and also a complete mechanism for providing peer reviews and feedback for other groups and other teammates. Part of its functionality is a system for user authentication with different user roles and permissions that determine how each user interacts with the content. The auth_controller.rb and password_retrieval_controller.rb which are the files primarily addressed in this project are both critical controllers in providing this functionality.

Description of Project

TODO: Describe the objectives of the project and what issues we were attempting to address.

Files Modified

Changes to app/controllers/password_retrieval_controller.rb

 #  Change Rationale Commit Link
1 Updated check_reset_url method name to check_token_validity The method validates that the password reset token is valid and present. The updated method name provides a more functionally descriptive name. Commit
2 Replaced repeated code in lines 35-36 and 62-63 The use of repeated code violates the DRY principle and so it was moved to a new method. Commit
3 Change token expiration time to constant in line 41 This time should not be hardwired; it should be a constant or a parameter. Commit
4 Reload page if email is nil or empty on password_retrieval/forgotten view An empty email parameter was causing the send password button to freeze. Commit
5 Improve overall comments and rewrite error messages The comments and error messages in the controller need to be more meaningful, specific and clear. Commit

Changes to config/routes.rb

 #  Change Rationale Commit Link
1 Updated URL path and controller action to updated method name check_token_validity The action and URL path must be renamed to generate pathing to the controller method and views. Commit

Changes to app/controllers/auth_controller.rb

 #  Change Rationale Commit Link
1 Move logger messages to before_action blocks wherever possible Logger messages are inserted to log important events occurring in the code and do not relate directly to the logic. When possible, moving them to either before_action or after_action blocks makes the code more readable and easier to understand. It also separates the functionality of the method itself and the logging functionality. Commit
2 Replaced repeated code for both handling a failed login and re-caching the user role We noticed that although not listed on the recommended changes, these two actions involved exactly repeated code in the controller. The use of repeated code violates the DRY principle and so it was moved to a new method. Commit
3 Improved helper function names Originally we made the new helper functions used in logging have unhelpful, confusing names. Making them more clear helps the code to be more understandable. Commit

Testing

TODO: Show how the existing testing suite was passing before and after our refactoring - preserving functionality.

Testing password_retrieval_controller.rb

TODO: Add testing description for password_retrieval_controller.rb

Testing auth_controller_.rb

Relevant Links