UX: Add description to the 2FA page when adding new admins (#16098)

This PR adds an extra description to the 2FA page when granting a user admin access. It also introduces a general system for adding customized descriptions that can be used by future actions.

(Follow-up to dd6ec65061)
This commit is contained in:
Osama Sayegh
2022-03-04 06:43:06 +03:00
committed by GitHub
parent 967946378a
commit 8c71878ff5
11 changed files with 53 additions and 4 deletions

View File

@@ -9,9 +9,14 @@ module SecondFactor::Actions
def second_factor_auth_required!(params)
user = find_user(params[:user_id])
description = I18n.t(
"second_factor_auth.actions.grant_admin.description",
username: "@#{user.username}"
)
{
callback_params: { user_id: user.id },
redirect_path: admin_user_show_path(id: user.id, username: user.username)
redirect_path: admin_user_show_path(id: user.id, username: user.username),
description: description
}
end

View File

@@ -52,6 +52,9 @@ the following methods:
redirected to after the action is finished. When this key is omitted, the
redirect path is set to the homepage (/).
:description => optional action-specific description message that's shown on
the 2FA page.
After this method is called, the auth manager will send a 403 response with a
JSON body. It does that by raising an exception that's then rescued by a
`rescue_from` handler. The JSON response contains a challenge nonce which the
@@ -169,6 +172,9 @@ class SecondFactor::AuthManager
allowed_methods: allowed_methods.to_a,
generated_at: Time.zone.now.to_i
}
if config[:description]
challenge[:description] = config[:description]
end
secure_session["current_second_factor_auth_challenge"] = challenge.to_json
nonce
end