Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disable Updating of User Emails #917

Merged
merged 4 commits into from
Oct 24, 2024
Merged

Disable Updating of User Emails #917

merged 4 commits into from
Oct 24, 2024

Conversation

aaronskiba
Copy link
Collaborator

Fixes #916

Changes proposed in this PR:

  • Set "disabled": true within f.email_field for all forms (the same approach is already used in app/views/org_admin/users/edit.html.erb)
  • For added security, remove :email from the .permit() update params of the controllers corresponding to the forms
  • Update layout of "Edit Profile" contents to correspond with the aforementioned changes

Notes regarding changes to app/controllers/registrations_controller.rb:

  • Because :email was removed from the .permit() params, all of the update_params[:email] - related code needed to be addressed/removed (lines 161, 174, and 200)
  • The removal of :email from update_params enabled the removal of a lot of other code in the file.
    • The if require_password check in the do_update method is no longer needed. The comment on 197 stated # user is changing email or password. However, line 204-206 pointed out how this case is never actually reached for password changes (def do_update_password is executed instead). Since we are no longer allowing for the email to be changed either, it follows that require_password should always evaluate to false.
    • As result, we only need the code that corresponded to the else statement for if require_password (previously lines 225-228, now 185-188)
    • Also, because require_password is now always false, it follows that we can remove both the require_password arg from def do_update as well as the entirety of def needs_password?

- For the edited .erb files, `"disabled": true` has been set for the email fields section of forms (copies approach used in `app/views/org_admin/users/edit.html.erb`)
- For added security, we are also removing `:email` from the .permit() update params of the corresponding controllers

- Notes regarding changes to app/controllers/registrations_controller.rb:
  - Because `:email` was removed from the .permit() params, all of the `update_params[:email]`-related code needed to be addressed/removed (lines 161, 174, and 200)
  - The removal of `:email` from the update params allows for the removal of a lot of other code in the file.
    - The `if require_password` check in the `do_update` method is no longer needed. The comment on 197 stated `# user is changing email or password`. However, line 204-206 pointed out how this case is never actually reached for password changes (`def do_update_password` is executed instead). Since we are no longer allowing for the email to be changed either, it follows that `require_password` should always evaluate to false.
      - As result, we only need the  code that corresponded to the `else` statement for `if require_password` (previously lines 225-228, now 185-188)
      - Also, because `require_password` is now always false, it follows that we can remove both the `require_password` arg from `def do_update` as well as the entirety of `def needs_password?`
These layout changes are being made to align with the changes in commit 74c960896 (i.e. setting `"disabled": true` to user.email in "Edit Profile")
Copy link

github-actions bot commented Sep 25, 2024

1 Warning
⚠️ There are code changes, but no corresponding tests. Please include tests if this PR introduces any modifications in behavior. \n
Ignore this warning if the PR ONLY contains translation.io synced updates.

Generated by 🚫 Danger

Copy link
Collaborator

@lagoan lagoan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a great start! I just have a couple of question regarding updating the system user password.

Let me know if I am off the mark.

app/controllers/registrations_controller.rb Show resolved Hide resolved

<div class="form-group col-xs-8">
<%= f.label(:email, _('Email'), class: 'control-label') %>
<%= f.email_field(:email, class: "form-control", "aria-required": true, value: @user.email) %>
<%= f.email_field(:email, class: "form-control", "aria-required": true, value: @user.email, "disabled": true) %>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like how we are still showing the information here.

app/controllers/registrations_controller.rb Show resolved Hide resolved
Copy link
Collaborator

@lagoan lagoan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your responses! The only thing that is missing is the changelog entry.

lagoan
lagoan previously approved these changes Oct 23, 2024
Copy link
Collaborator

@lagoan lagoan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Copy link
Collaborator

@lagoan lagoan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants