Skip to content

Commit

Permalink
Use User.unlock_in in other locked account text
Browse files Browse the repository at this point in the history
While this is a bit orthogonal to the current PR, I thought it was worth
bringing these usages into line with the changes I made in the previous
commit.

This method is provided by Devise's Lockable module and reads its value
from the Devise configuration. The value is returned as an
`ActiveSupport::Duration` and so it can be converted into a
human-readable string by calling `ActiveSupport::Duration#inspect`.

I think it's clearer to use `User.unlock_in` vs `Devise.unlock_in`,
because the `Devise::Lockable` module is included in the `User` model.

I think using `ActiveSupport::Duration#inspect` rather than
reconstructing the duration string as per the previous implementation of
`EventLog::LOCKED_DURATION` is a lot simpler and easier to read.

Note that these changes won't currently change what is displayed,
because `Devise.unlock_in` is currently configured to be `1.hour`.
  • Loading branch information
floehopper committed Nov 30, 2023
1 parent f6d2204 commit 3b82f06
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion app/models/event_log.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
require "ipaddr"

class EventLog < ApplicationRecord
LOCKED_DURATION = "#{Devise.unlock_in / 1.hour} #{'hour'.pluralize(Devise.unlock_in / 1.hour)}".freeze
LOCKED_DURATION = User.unlock_in.inspect.freeze

EVENTS = [
ACCOUNT_LOCKED = LogEntry.new(id: 1, description: "Password verification failed too many times, account locked for #{LOCKED_DURATION}", require_uid: true),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<p class="lead">
Your account has been locked because an incorrect 2-step verification code was entered too many times.
</p>
<p>Your account will be unlocked at <%= Devise.unlock_in.from_now.to_fs(:govuk_time)%></p>
<p>Your account will be unlocked at <%= User.unlock_in.from_now.to_fs(:govuk_time)%></p>
<p>
If you need your account unlocked sooner, please contact a managing <%= t('department.name') %> editor in your organisation
(or your parent organisation). They can use the support form to get help from the <%= t('department.name') %> team.
Expand Down

0 comments on commit 3b82f06

Please sign in to comment.