FEATURE: User fields required for existing users - Part 2 (#27172)

We want to allow admins to make new required fields apply to existing users. In order for this to work we need to have a way to make those users fill up the fields on their next page load. This is very similar to how adding a 2FA requirement post-fact works. Users will be redirected to a page where they can fill up the remaining required fields, and until they do that they won't be able to do anything else.
This commit is contained in:
Ted Johansson
2024-06-25 19:32:18 +08:00
committed by GitHub
parent 867b3822f3
commit d63f1826fe
51 changed files with 661 additions and 209 deletions

View File

@ -41,6 +41,7 @@ class ApplicationController < ActionController::Base
before_action :authorize_mini_profiler
before_action :redirect_to_login_if_required
before_action :block_if_requires_login
before_action :redirect_to_profile_if_required
before_action :preload_json
before_action :check_xhr
after_action :add_readonly_header
@ -907,6 +908,34 @@ class ApplicationController < ActionController::Base
(!SiteSetting.enforce_second_factor_on_external_auth && secure_session["oauth"] == "true")
end
def redirect_to_profile_if_required
return if request.format.json?
return if !current_user
return if !current_user.needs_required_fields_check?
if current_user.populated_required_custom_fields?
current_user.bump_required_fields_version
return
end
redirect_path = path("/u/#{current_user.encoded_username}/preferences/profile")
second_factor_path = path("/u/#{current_user.encoded_username}/preferences/second-factor")
allowed_paths = [redirect_path, second_factor_path, path("/admin")]
if allowed_paths.none? { |p| request.fullpath.start_with?(p) }
rate_limiter = RateLimiter.new(current_user, "redirect_to_required_fields_log", 1, 24.hours)
if rate_limiter.performed!(raise_error: false)
UserHistory.create!(
action: UserHistory.actions[:redirected_to_required_fields],
acting_user_id: current_user.id,
)
end
redirect_to path(redirect_path)
nil
end
end
def build_not_found_page(opts = {})
if SiteSetting.bootstrap_error_pages?
preload_json