SysMO-DB/seek

View on GitHub
lib/seek/permissions/policy_based_authorization.rb

Summary

Maintainability
C
1 day
Test Coverage

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

Severity: Minor
Found in lib/seek/permissions/policy_based_authorization.rb - About 2 hrs to fix

    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)
    Severity: Minor
    Found in lib/seek/permissions/policy_based_authorization.rb - About 2 hrs to fix

    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))
    Severity: Minor
    Found in lib/seek/permissions/policy_based_authorization.rb - About 1 hr to fix

    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)
    Severity: Minor
    Found in lib/seek/permissions/policy_based_authorization.rb - About 55 mins to fix

    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
    
    
    Severity: Minor
    Found in lib/seek/permissions/policy_based_authorization.rb - About 45 mins to fix

    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
    Severity: Minor
    Found in lib/seek/permissions/policy_based_authorization.rb - About 45 mins to fix

    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)
    Severity: Major
    Found in lib/seek/permissions/policy_based_authorization.rb - About 40 mins to fix

      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]
      Severity: Minor
      Found in lib/seek/permissions/policy_based_authorization.rb - About 35 mins to fix

      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}
      Severity: Minor
      Found in lib/seek/permissions/policy_based_authorization.rb - About 35 mins to fix

      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
      Severity: Minor
      Found in lib/seek/permissions/policy_based_authorization.rb - About 25 mins to fix

      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

      There are no issues that match your filters.

      Category
      Status