File policy_based_authorization.rb
has 280 lines of code (exceeds 250 allowed). Consider refactoring. Open
require 'project_compat'
module Seek
module Permissions
module PolicyBasedAuthorization
Method managers
has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring. Open
def managers
#FIXME: how to handle projects as contributors - return all people or just specific people (pals or other role)?
people=[]
unless self.contributor.nil?
people << self.contributor.person if self.contributor.kind_of?(User)
- 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 all_authorized_for
has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring. Open
def all_authorized_for action, user=User.current_user, projects=nil, filter_by_permissions=true
projects=Array(projects) unless projects.nil?
user_id = user.nil? ? 0 : user.id
assets = []
programatic_project_filter = !projects.nil? && (!Seek::Config.auth_lookup_enabled || (self==Assay || self==Study))
- 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 authorization_permissions
has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring. Open
def authorization_permissions user=User.current_user
@@expected_true_value ||= ActiveRecord::Base.connection.quoted_true.gsub("'","")
permissions = AuthPermissions.new
user_id = user.nil? ? 0 : user.id
if Seek::Config.auth_lookup_enabled && self.class.lookup_table_consistent?(user_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 update_lookup_table
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Open
def update_lookup_table user=nil
self.class.isolation_level( :repeatable_read ) do #ensure it allows it see another worker may have inserted a record already
self.class.transaction do
user_id = user.nil? ? 0 : user.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 lookup_table_consistent?
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Open
def lookup_table_consistent? user_id
unless user_id.is_a?(Numeric)
user_id = user_id.nil? ? 0 : user_id.id
end
#cannot rely purely on the count, since an item could have been deleted and a new one added
- 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
Consider simplifying this complex logical expression. Open
unless res.nil?
permissions.can_view = res["can_view"].to_s==@@expected_true_value && state_allows_manage?(user)
permissions.can_download = res["can_download"].to_s==@@expected_true_value && state_allows_manage?(user)
permissions.can_edit = res["can_edit"].to_s==@@expected_true_value && state_allows_manage?(user)
permissions.can_manage = res["can_manage"].to_s==@@expected_true_value && state_allows_manage?(user)
Method last_asset_id_for_user
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
def last_asset_id_for_user user_id
unless user_id.is_a?(Numeric)
user_id = user_id.nil? ? 0 : user_id.id
end
v = ActiveRecord::Base.connection.select_one("select max(asset_id) from #{lookup_table_name} where user_id = #{user_id}").values[0]
- 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 authorize_asset_collection
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
def authorize_asset_collection assets, action, user=User.current_user,filter_by_permissions=true
return assets if assets.empty?
user_id = user.nil? ? 0 : user.id
if Seek::Config.auth_lookup_enabled && self.lookup_table_consistent?(user_id)
ids=assets.collect{|asset| asset.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 included
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
def self.included klass
attr_accessor :permission_for
klass.extend AuthLookupClassMethods
klass.class_eval do
belongs_to :contributor, :polymorphic => true unless method_defined? :contributor
- 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"