Class User
has 82 methods (exceeds 20 allowed). Consider refactoring. Open
class User < ApplicationRecord
audited :except => [:last_login_on, :password_hash, :password_salt, :password_confirmation],
:associations => [:roles, :usergroups]
include Authorizable
include Foreman::TelemetryHelper
File user.rb
has 613 lines of code (exceeds 250 allowed). Consider refactoring. Open
require 'digest/sha1'
class User < ApplicationRecord
audited :except => [:last_login_on, :password_hash, :password_salt, :password_confirmation],
:associations => [:roles, :usergroups]
Method try_to_login
has a Cognitive Complexity of 31 (exceeds 5 allowed). Consider refactoring. Open
def self.try_to_login(login, password, api_request = false)
# Make sure no one can sign in with an empty password
return nil if password.to_s.empty?
# user is already in local database
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Method find_or_create_external_user
has a Cognitive Complexity of 20 (exceeds 5 allowed). Consider refactoring. Open
def self.find_or_create_external_user(attrs, auth_source_name)
external_groups = attrs.delete(:groups)
auth_source = AuthSource.find_by_name(auth_source_name.to_s)
# existing user, we'll update them
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Method try_to_login
has 39 lines of code (exceeds 25 allowed). Consider refactoring. Open
def self.try_to_login(login, password, api_request = false)
# Make sure no one can sign in with an empty password
return nil if password.to_s.empty?
# user is already in local database
Method find_or_create_external_user
has 36 lines of code (exceeds 25 allowed). Consider refactoring. Open
def self.find_or_create_external_user(attrs, auth_source_name)
external_groups = attrs.delete(:groups)
auth_source = AuthSource.find_by_name(auth_source_name.to_s)
# existing user, we'll update them
Method try_to_auto_create_user
has 27 lines of code (exceeds 25 allowed). Consider refactoring. Open
def self.try_to_auto_create_user(login, password)
return if login.blank? || password.blank?
# User is not yet registered, try to authenticate with available sources
logger.debug "Attempting to log into an auth source as #{login} for account auto-creation"
return unless (attrs = AuthSource.authenticate(login, password))
Method editing_self?
has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring. Open
def editing_self?(options = {})
options[:controller].to_s == 'users' &&
options[:action] =~ /edit|update/ &&
options[:id].to_i == id ||
options[:controller].to_s =~ /\Aapi\/v\d+\/users\Z/ &&
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Method try_to_auto_create_user
has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring. Open
def self.try_to_auto_create_user(login, password)
return if login.blank? || password.blank?
# User is not yet registered, try to authenticate with available sources
logger.debug "Attempting to log into an auth source as #{login} for account auto-creation"
return unless (attrs = AuthSource.authenticate(login, password))
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Avoid deeply nested control flow statements. Open
File.delete(old_avatar) if File.exist?(old_avatar)
Avoid deeply nested control flow statements. Open
unless user.update(valid_attrs)
logger.warn "Failed to update #{user.login} attributes: #{user.errors.full_messages.join(', ')}"
end
Method allowed_to?
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
def allowed_to?(action)
return false if disabled?
return true if admin?
if action.is_a?(Hash) || action.is_a?(ActionController::Parameters)
action = Foreman::AccessControl.normalize_path_hash(action)
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Method check_permissions_for_changing_login
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
def check_permissions_for_changing_login
if login_changed? && !new_record?
if !internal?
errors.add :login, _("It is not possible to change external users login")
elsif !(User.current.can?(:edit_users, self) || (id == User.current.id))
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Method search_by_admin
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
def self.search_by_admin(key, operator, value)
value = value == 'true'
value = !value if operator == '<>'
conditions = [table_name, Usergroup.table_name].map do |base|
"(#{base}.admin = ?" + (value ? ')' : " OR #{base}.admin IS NULL)")
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"