roadmap
roadmap copied to clipboard
Re-Implement Email Confirmation
Note
- This PR was previously approved and merged into
development. https://github.com/DMPRoadmap/roadmap/pull/3507 - However, only a subset of
developmentwas merged intomainfor release v5.0.1. - These changes have still not been merged into main.
Changes proposed in this PR:
-
Added
:confirmablemodule to User model, which implements email confirmation via Devise. -
Added the rake task,
email_confirmation:clear_all(seelib/tasks/email_confirmation.rake)- The rake task sets the values of all email confirmation-related columns (
confirmed_at,confirmation_token, andconfirmation_sent_at) to nil for all users. It then proceeds to confirm all superusers within the app.
- The rake task sets the values of all email confirmation-related columns (
-
Streamline the email confirmation process for existing users
- By default, Devise's
:confirmablemodule generates aconfirmation_tokenand auto-sends confirmation instructions when a new user is created. - Because we are only implementing
:confirmablenow, existing users can't receive these autosent instructions. However, this PR implements autosent confirmation instructions in the following manner:- A user attempts to sign into the app. (Note, this sign-in can either be performed via the system sign-in, or via the Shibboleth sign-in).
- The
return if confirmation_instructions_missing_and_handled?(user)line of code is executed. This method belongs to theEmailConfirmationHandlerconcern, and works as follows: i) returnsfalseif the user is either already confirmed or has an outstanding confirmation_token ii) Else (the user is unconfirmed AND has no outstanding confirmation_token). Generate the confirmation token and auto-send the confirmation instructions email. (Note: on subsequent sign-in attempts, attempts, the method will returnfalse, preventing redundant emails.)
- By default, Devise's
-
Customise
devise.failure.unconfirmedvalue in variousconfig/locales/*.ymlfiles. The customised value includes an embedded link to/users/confirmation/new. The following is a screenshot of the customised value for:"en-CA": -
Updated existing tests
- Added
confirmed_at { Time.current }to User factory - Added
config.action_mailer.default_options = { from: '[email protected]' }to enable email confirmation tests
- Added
-
Add new tests (spec/features/email_confirmation_spec.rb)
- These tests verify the streamlined email confirmation behaviour for existing users
- Quite a bit of config was needed to enable testing of behaviour with shibboleth (see
spec/support/helpers/omniauth_helper.rband additions tospec/rails_helper.rb)
- Quite a bit of config was needed to enable testing of behaviour with shibboleth (see
- They also test the clickable link to
/users/confirmation/newembedded in the customiseddevise.failure.unconfirmedflash message.
- These tests verify the streamlined email confirmation behaviour for existing users
-
Refactoring
- Addressed some rubocop offences within
SessionsController#createandUsers::OmniauthCallbacksController#handle_omniauth
- Addressed some rubocop offences within
-
https://github.com/DMPRoadmap/roadmap/pull/3511
- Update
spec/support/faker.rbto replace'en'withI18n.default_localefor assigning locales. This change should allow for more accurate testing by using the application's specified locale. - Prior to this PR, there was a commit in the aforementioned file that read
"Keep this as :en. Faker doesn't have :en-GB". However,I18n.default_localeevaluates to:"en-GB"for this codebase, and all of the tests appear to be passing. Additionally, the branch that this PR is pointed at (upstream/aaron/add-email-confirmation), usesI18n.t(...)for several tests, and this change is required for those tests to pass.
- Update
| 1 Error | |
|---|---|
| :no_entry_sign: | Please include a CHANGELOG entry. |
Generated by :no_entry_sign: Danger