E1914 Refactor users controller: Difference between revisions
No edit summary |
|||
Line 4: | Line 4: | ||
1) The users_controller.rb file included the standard CRUD methods for a User model along with methods for other workflows. <br> | 1) The users_controller.rb file included the standard CRUD methods for a User model along with methods for other workflows. <br> | ||
2) The users_controller.rb file handled the creation and management of a RequestedUser object.<br> | 2) The users_controller.rb file handled the creation and management of a RequestedUser object.<br> | ||
3) The file also included a few methods which have a bad name or lack documentation. | 3) The file also included a few methods which have a bad name or lack documentation. <br> | ||
4) The forms that come after "Request Account" button is clicked need to be changed.<br> | |||
5) When a list of all users are shown, the list is not paginated. | |||
== Solutions to the problems == | == Solutions to the problems == | ||
Line 17: | Line 19: | ||
5) roles_for_request_sign_up<br> | 5) roles_for_request_sign_up<br> | ||
6) requested_user_params<br> | 6) requested_user_params<br> | ||
=== Writing comments to make methods more understandable === | === Writing comments to make methods more understandable === | ||
Line 39: | Line 35: | ||
The get_role method was named more like it would be in Java. It was renamed to 'role' because that is how it would be named in ruby. | The get_role method was named more like it would be in Java. It was renamed to 'role' because that is how it would be named in ruby. | ||
We chose to keep the method in the controller instead of moving it to the model because it does not alter the data structure and it also has selection logic. | We chose to keep the method in the controller instead of moving it to the model because it does not alter the data structure and it also has selection logic. | ||
=== Make GUI changes in the form displayed after "Request Account" button is clicked === | |||
Only instructor accounts can be created, so the drop-down was removed.<br> | |||
All form labels were bold-faced.<br> | |||
The “Self Introduction” label was re-named to “Self-Introduction”. <br> | |||
The text-box for the self-introduction field now includes a hint "Please include a website name". <br> | |||
=== Paginating the list of users === | === Paginating the list of users === | ||
3. The paginate_list method is supposed to paginate the list of users. However, the list of users is currently not paginated. This is probably because this method is not being called in the right place. | 3. The paginate_list method is supposed to paginate the list of users. However, the list of users is currently not paginated. This is probably because this method is not being called in the right place. |
Revision as of 23:38, 24 March 2019
This is an Expertiza based OSS Project.
Problems
1) The users_controller.rb file included the standard CRUD methods for a User model along with methods for other workflows.
2) The users_controller.rb file handled the creation and management of a RequestedUser object.
3) The file also included a few methods which have a bad name or lack documentation.
4) The forms that come after "Request Account" button is clicked need to be changed.
5) When a list of all users are shown, the list is not paginated.
Solutions to the problems
The RequestedUser model was renamed to AccountRequest.
A new controller was created called the account_requests_controller.
The following methods were moved from users_controller to account_requests_controller.
1) created_approved_user
2) list_pending_requested
3) request_new
4) created_requested_user_record
5) roles_for_request_sign_up
6) requested_user_params
Writing comments to make methods more understandable
Wrote comments for the methods foreign. The comments include:
1) What the method does: This method is used to find the list of roles the current user can embody.
2) Where the method is used: Used to display a drop-down selection of roles for the current user in the views.
Wrote comments for the show and show_selection methods:
1) What the method does:
show(): If the current user is a student, they should only be able to see information about themselves. All other people should be able to see information about themselves or other students. If the request to show() passes these checks, then they are shown the view 'show'. Otherwise, they are redirected to the home page.
show_selection(): If the role of a user's parent is less than the current user or if the current user is requesting to see itself or if user's parent_id does not exist then the show() method is called. All these conditions boil down to whether the current user of the system is authorized to see/edit the information about the user specified in the params. If the requested user does not exist or if the current user is not authorized to see the requested user, then the current user is redirected back to the list page.
2) Scenarios in which show_selection is called: in users/list.html.erb, a list of users is shown. On top of the list there is a functionality to search the list. When a person searches for a particular student, and selects that student, the show_selection method is called. If the person is allowed to see that student, the user is directed to the show() method. Otherwise the person stays on the list view.
3) Scenarios in which show() is called: From the edit.html.erb, if the person wants to see the information instead of editing it. From show_selection() as described above.
Renaming methods to reflect their actual behavior
The get_role method was named more like it would be in Java. It was renamed to 'role' because that is how it would be named in ruby. We chose to keep the method in the controller instead of moving it to the model because it does not alter the data structure and it also has selection logic.
Make GUI changes in the form displayed after "Request Account" button is clicked
Only instructor accounts can be created, so the drop-down was removed.
All form labels were bold-faced.
The “Self Introduction” label was re-named to “Self-Introduction”.
The text-box for the self-introduction field now includes a hint "Please include a website name".
Paginating the list of users
3. The paginate_list method is supposed to paginate the list of users. However, the list of users is currently not paginated. This is probably because this method is not being called in the right place.