Fix `Style/GuardClause` cop in app/controllers (#28420)
parent
3205a654ca
commit
17ea22671d
|
@ -121,10 +121,6 @@ Style/GlobalStdStream:
|
||||||
# Configuration parameters: MinBodyLength, AllowConsecutiveConditionals.
|
# Configuration parameters: MinBodyLength, AllowConsecutiveConditionals.
|
||||||
Style/GuardClause:
|
Style/GuardClause:
|
||||||
Exclude:
|
Exclude:
|
||||||
- 'app/controllers/admin/confirmations_controller.rb'
|
|
||||||
- 'app/controllers/auth/confirmations_controller.rb'
|
|
||||||
- 'app/controllers/auth/passwords_controller.rb'
|
|
||||||
- 'app/controllers/settings/two_factor_authentication/webauthn_credentials_controller.rb'
|
|
||||||
- 'app/lib/activitypub/activity/block.rb'
|
- 'app/lib/activitypub/activity/block.rb'
|
||||||
- 'app/lib/request.rb'
|
- 'app/lib/request.rb'
|
||||||
- 'app/lib/request_pool.rb'
|
- 'app/lib/request_pool.rb'
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
module Admin
|
module Admin
|
||||||
class ConfirmationsController < BaseController
|
class ConfirmationsController < BaseController
|
||||||
before_action :set_user
|
before_action :set_user
|
||||||
before_action :check_confirmation, only: [:resend]
|
before_action :redirect_confirmed_user, only: [:resend], if: :user_confirmed?
|
||||||
|
|
||||||
def create
|
def create
|
||||||
authorize @user, :confirm?
|
authorize @user, :confirm?
|
||||||
|
@ -25,11 +25,13 @@ module Admin
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def check_confirmation
|
def redirect_confirmed_user
|
||||||
if @user.confirmed?
|
flash[:error] = I18n.t('admin.accounts.resend_confirmation.already_confirmed')
|
||||||
flash[:error] = I18n.t('admin.accounts.resend_confirmation.already_confirmed')
|
redirect_to admin_accounts_path
|
||||||
redirect_to admin_accounts_path
|
end
|
||||||
end
|
|
||||||
|
def user_confirmed?
|
||||||
|
@user.confirmed?
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -7,7 +7,7 @@ class Auth::ConfirmationsController < Devise::ConfirmationsController
|
||||||
|
|
||||||
before_action :set_body_classes
|
before_action :set_body_classes
|
||||||
before_action :set_confirmation_user!, only: [:show, :confirm_captcha]
|
before_action :set_confirmation_user!, only: [:show, :confirm_captcha]
|
||||||
before_action :require_unconfirmed!
|
before_action :redirect_confirmed_user, if: :signed_in_confirmed_user?
|
||||||
|
|
||||||
before_action :extend_csp_for_captcha!, only: [:show, :confirm_captcha]
|
before_action :extend_csp_for_captcha!, only: [:show, :confirm_captcha]
|
||||||
before_action :require_captcha_if_needed!, only: [:show]
|
before_action :require_captcha_if_needed!, only: [:show]
|
||||||
|
@ -65,10 +65,12 @@ class Auth::ConfirmationsController < Devise::ConfirmationsController
|
||||||
@confirmation_user.nil? || @confirmation_user.confirmed?
|
@confirmation_user.nil? || @confirmation_user.confirmed?
|
||||||
end
|
end
|
||||||
|
|
||||||
def require_unconfirmed!
|
def redirect_confirmed_user
|
||||||
if user_signed_in? && current_user.confirmed? && current_user.unconfirmed_email.blank?
|
redirect_to(current_user.approved? ? root_path : edit_user_registration_path)
|
||||||
redirect_to(current_user.approved? ? root_path : edit_user_registration_path)
|
end
|
||||||
end
|
|
||||||
|
def signed_in_confirmed_user?
|
||||||
|
user_signed_in? && current_user.confirmed? && current_user.unconfirmed_email.blank?
|
||||||
end
|
end
|
||||||
|
|
||||||
def set_body_classes
|
def set_body_classes
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
class Auth::PasswordsController < Devise::PasswordsController
|
class Auth::PasswordsController < Devise::PasswordsController
|
||||||
skip_before_action :check_self_destruct!
|
skip_before_action :check_self_destruct!
|
||||||
before_action :check_validity_of_reset_password_token, only: :edit
|
before_action :redirect_invalid_reset_token, only: :edit, unless: :reset_password_token_is_valid?
|
||||||
before_action :set_body_classes
|
before_action :set_body_classes
|
||||||
|
|
||||||
layout 'auth'
|
layout 'auth'
|
||||||
|
@ -19,11 +19,9 @@ class Auth::PasswordsController < Devise::PasswordsController
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def check_validity_of_reset_password_token
|
def redirect_invalid_reset_token
|
||||||
unless reset_password_token_is_valid?
|
flash[:error] = I18n.t('auth.invalid_reset_password_token')
|
||||||
flash[:error] = I18n.t('auth.invalid_reset_password_token')
|
redirect_to new_password_path(resource_name)
|
||||||
redirect_to new_password_path(resource_name)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def set_body_classes
|
def set_body_classes
|
||||||
|
|
|
@ -6,8 +6,8 @@ module Settings
|
||||||
skip_before_action :check_self_destruct!
|
skip_before_action :check_self_destruct!
|
||||||
skip_before_action :require_functional!
|
skip_before_action :require_functional!
|
||||||
|
|
||||||
before_action :require_otp_enabled
|
before_action :redirect_invalid_otp, unless: -> { current_user.otp_enabled? }
|
||||||
before_action :require_webauthn_enabled, only: [:index, :destroy]
|
before_action :redirect_invalid_webauthn, only: [:index, :destroy], unless: -> { current_user.webauthn_enabled? }
|
||||||
|
|
||||||
def index; end
|
def index; end
|
||||||
def new; end
|
def new; end
|
||||||
|
@ -85,18 +85,14 @@ module Settings
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def require_otp_enabled
|
def redirect_invalid_otp
|
||||||
unless current_user.otp_enabled?
|
flash[:error] = t('webauthn_credentials.otp_required')
|
||||||
flash[:error] = t('webauthn_credentials.otp_required')
|
redirect_to settings_two_factor_authentication_methods_path
|
||||||
redirect_to settings_two_factor_authentication_methods_path
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def require_webauthn_enabled
|
def redirect_invalid_webauthn
|
||||||
unless current_user.webauthn_enabled?
|
flash[:error] = t('webauthn_credentials.not_enabled')
|
||||||
flash[:error] = t('webauthn_credentials.not_enabled')
|
redirect_to settings_two_factor_authentication_methods_path
|
||||||
redirect_to settings_two_factor_authentication_methods_path
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue