Refactor UsersController (#11143)

* Refactor UsersController

Removed unused method #less_than_one_day_old? and refactor a few lines of code

* Undo reduce
This commit is contained in:
WenYu 2020-10-29 03:41:33 +08:00 committed by GitHub
parent 8f5954aeb8
commit 0067a2124c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -271,14 +271,10 @@ class UsersController < ApplicationController
end
def render_update_response
if current_user.save
respond_to do |format|
format.json { render json: { outcome: "updated successfully" } }
end
else
respond_to do |format|
format.json { render json: { outcome: "update failed" } }
end
outcome = current_user.save ? "updated successfully" : "update failed"
respond_to do |format|
format.json { render json: { outcome: outcome } }
end
end
@ -326,22 +322,6 @@ class UsersController < ApplicationController
params[:user].include?(:config_theme)
end
def less_than_one_day_old?(user)
# we check all the `_created_at` fields for all available providers
# we use `.available` and not `.enabled` to avoid a situation in which
# an admin disables an authentication method after users have already
# registered, risking that they would be flagged as new
# the last one is a fallback in case all created_at fields are nil
user_identity_age = Authentication::Providers.available.map do |provider|
user.public_send("#{provider}_created_at")
end.detect(&:present?)
user_identity_age = user_identity_age.presence || 8.days.ago
range = 1.day.ago.beginning_of_day..Time.current
range.cover?(user_identity_age)
end
def destroy_request_in_progress?
Rails.cache.exist?("user-destroy-token-#{@user.id}")
end