airbnb/superset

View on GitHub
superset/security/manager.py

Summary

Maintainability
F
1 wk
Test Coverage

File manager.py has 2030 lines of code (exceeds 250 allowed). Consider refactoring.
Open

# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements.  See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership.  The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
Severity: Major
Found in superset/security/manager.py - About 5 days to fix

    SupersetSecurityManager has 92 functions (exceeds 20 allowed). Consider refactoring.
    Open

    class SupersetSecurityManager(  # pylint: disable=too-many-public-methods
        SecurityManager
    ):
        userstatschartview = None
        READ_ONLY_MODEL_VIEWS = {"Database", "DynamicPlugin"}
    Severity: Major
    Found in superset/security/manager.py - About 1 day to fix

      Function raise_for_access has a Cognitive Complexity of 76 (exceeds 5 allowed). Consider refactoring.
      Open

          def raise_for_access(
              # pylint: disable=too-many-arguments,too-many-branches,too-many-locals,too-many-statements
              self,
              dashboard: Optional["Dashboard"] = None,
              chart: Optional["Slice"] = None,
      Severity: Minor
      Found in superset/security/manager.py - About 1 day 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

                  if not (
                      self.can_access_schema(datasource)
                      or self.can_access("datasource_access", datasource.perm or "")
                      or self.is_owner(datasource)
                      or (
      Severity: Critical
      Found in superset/security/manager.py - About 6 hrs to fix

        Function raise_for_access has 13 arguments (exceeds 4 allowed). Consider refactoring.
        Open

            def raise_for_access(
        Severity: Major
        Found in superset/security/manager.py - About 1 hr to fix

          Function _get_pvms_from_builtin_role has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
          Open

              def _get_pvms_from_builtin_role(self, role_name: str) -> list[PermissionView]:
                  """
                  Gets a list of model PermissionView permissions inferred from a builtin role
                  definition
                  """
          Severity: Minor
          Found in superset/security/manager.py - 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

          Function validate_guest_token_resources has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
          Open

              def validate_guest_token_resources(resources: GuestTokenResources) -> None:
                  # pylint: disable=import-outside-toplevel
                  from superset.commands.dashboard.embedded.exceptions import (
                      EmbeddedDashboardNotFoundError,
                  )
          Severity: Minor
          Found in superset/security/manager.py - 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

          Function copy_role has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
          Open

              def copy_role(
                  self, role_from_name: str, role_to_name: str, merge: bool = True
              ) -> None:
                  """
                  Copies permissions from a role to another.
          Severity: Minor
          Found in superset/security/manager.py - 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

          Function has_guest_access has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
          Open

              def has_guest_access(self, dashboard: "Dashboard") -> bool:
                  user = self.get_current_guest_user_if_guest()
                  if not user:
                      return False
          
          
          Severity: Minor
          Found in superset/security/manager.py - 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

          Avoid deeply nested control flow statements.
          Open

                                  if self.can_access(
                                      "datasource_access", datasource_.perm
                                  ) or self.is_owner(datasource_):
                                      break
                              else:
          Severity: Major
          Found in superset/security/manager.py - About 45 mins to fix

            Function _update_dataset_perm has 6 arguments (exceeds 4 allowed). Consider refactoring.
            Open

                def _update_dataset_perm(  # pylint: disable=too-many-arguments
            Severity: Minor
            Found in superset/security/manager.py - About 45 mins to fix

              Function _delete_pvm_on_sqla_event has 6 arguments (exceeds 4 allowed). Consider refactoring.
              Open

                  def _delete_pvm_on_sqla_event(  # pylint: disable=too-many-arguments
              Severity: Minor
              Found in superset/security/manager.py - About 45 mins to fix

                Function _update_vm_datasources_access has 5 arguments (exceeds 4 allowed). Consider refactoring.
                Open

                    def _update_vm_datasources_access(  # pylint: disable=too-many-locals
                Severity: Minor
                Found in superset/security/manager.py - About 35 mins to fix

                  Function query_context_modified has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
                  Open

                  def query_context_modified(query_context: "QueryContext") -> bool:
                      """
                      Check if a query context has been modified.
                  
                      This is used to ensure guest users don't modify the payload and fetch data
                  Severity: Minor
                  Found in superset/security/manager.py - 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

                  Function create_missing_perms has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
                  Open

                      def create_missing_perms(self) -> None:
                          """
                          Creates missing FAB permissions for datasources, schemas and metrics.
                          """
                  
                  
                  Severity: Minor
                  Found in superset/security/manager.py - 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

                  Avoid too many return statements within this function.
                  Open

                                  return
                  Severity: Major
                  Found in superset/security/manager.py - About 30 mins to fix

                    Avoid too many return statements within this function.
                    Open

                                    return
                    Severity: Major
                    Found in superset/security/manager.py - About 30 mins to fix

                      Avoid too many return statements within this function.
                      Open

                                      return
                      Severity: Major
                      Found in superset/security/manager.py - About 30 mins to fix

                        Avoid too many return statements within this function.
                        Open

                                return False
                        Severity: Major
                        Found in superset/security/manager.py - About 30 mins to fix

                          Function get_datasources_accessible_by_user has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                          Open

                              def get_datasources_accessible_by_user(  # pylint: disable=invalid-name
                                  self,
                                  database: "Database",
                                  datasource_names: list[DatasourceName],
                                  schema: Optional[str] = None,
                          Severity: Minor
                          Found in superset/security/manager.py - 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

                          Function get_guest_user_from_request has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                          Open

                              def get_guest_user_from_request(self, req: Request) -> Optional[GuestUser]:
                                  """
                                  If there is a guest token in the request (used for embedded),
                                  parses the token and returns the guest user.
                                  This is meant to be used as a request loader for the LoginManager.
                          Severity: Minor
                          Found in superset/security/manager.py - 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