scitran/core

View on GitHub
api/handlers/containerhandler.py

Summary

Maintainability
F
4 days
Test Coverage

File containerhandler.py has 509 lines of code (exceeds 250 allowed). Consider refactoring.
Open

import bson
import datetime
import dateutil

from .. import config
Severity: Major
Found in api/handlers/containerhandler.py - About 1 day to fix

    Function get_all has a Cognitive Complexity of 23 (exceeds 5 allowed). Consider refactoring.
    Open

        def get_all(self, cont_name, par_cont_name=None, par_id=None):
            self.config = self.container_handler_configurations[cont_name]
            self.storage = self.config['storage']
    
            projection = self.config['list_projection'].copy()
    Severity: Minor
    Found in api/handlers/containerhandler.py - About 3 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

    Function handle_origin has a Cognitive Complexity of 21 (exceeds 5 allowed). Consider refactoring.
    Open

        def handle_origin(self, result):
            """
            Given an object with a `files` array key, coalesce and merge file origins if requested.
            """
    
    
    Severity: Minor
    Found in api/handlers/containerhandler.py - 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

    ContainerHandler has 24 functions (exceeds 20 allowed). Consider refactoring.
    Open

    class ContainerHandler(base.RequestHandler):
        """
        This class handle operations on a generic container
    
        The pattern used is:
    Severity: Minor
    Found in api/handlers/containerhandler.py - About 2 hrs to fix

      Function put has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
      Open

          def put(self, cont_name, **kwargs):
              _id = kwargs.pop('cid')
              self.config = self.container_handler_configurations[cont_name]
              self.storage = self.config['storage']
              container = self._get_container(_id)
      Severity: Minor
      Found in api/handlers/containerhandler.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 get_jobs has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
      Open

          def get_jobs(self, cid):
              # Only enabled for sessions container type per url rule in api.py
              self.config = self.container_handler_configurations["sessions"]
              self.storage = self.config['storage']
              cont = self._get_container(cid, projection={'files': 0, 'metadata': 0}, get_children=True)
      Severity: Minor
      Found in api/handlers/containerhandler.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 delete has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
      Open

          def delete(self, cont_name, **kwargs):
              _id = kwargs.pop('cid')
              self.config = self.container_handler_configurations[cont_name]
              self.storage = self.config['storage']
      
      
      Severity: Minor
      Found in api/handlers/containerhandler.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 post has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
      Open

          def post(self, cont_name):
              self.config = self.container_handler_configurations[cont_name]
              self.storage = self.config['storage']
              mongo_validator, payload_validator = self._get_validators()
      
      
      Severity: Minor
      Found in api/handlers/containerhandler.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

      Avoid deeply nested control flow statements.
      Open

                              if cached_gears.get(gear_id, None) is not None:
                                  gear_name = cached_gears[gear_id]
                              else:
                                  gear_id_bson = bson.ObjectId(gear_id)
                                  gear = config.db.gears.find_one({'_id': gear_id_bson})
      Severity: Major
      Found in api/handlers/containerhandler.py - About 45 mins to fix

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

            def get(self, cont_name, **kwargs):
                _id = kwargs.get('cid')
                self.config = self.container_handler_configurations[cont_name]
                self.storage = self.config['storage']
                container = self._get_container(_id)
        Severity: Minor
        Found in api/handlers/containerhandler.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

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

            def get_all_for_user(self, cont_name, uid):
                self.config = self.container_handler_configurations[cont_name]
                self.storage = self.config['storage']
                projection = self.config['list_projection']
                # select which permission filter will be applied to the list of results.
        Severity: Minor
        Found in api/handlers/containerhandler.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 join_user_info has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
        Open

            def join_user_info(results):
                """
                Given a list of containers, adds avatar and name context to each member of the permissions and notes lists
                """
        
        
        Severity: Minor
        Found in api/handlers/containerhandler.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

        Identical blocks of code found in 2 locations. Consider refactoring.
        Open

                if result.modified_count == 1:
                    return {'modified': result.modified_count}
                else:
                    self.abort(404, 'Element not updated in container {} {}'.format(self.storage.cont_name, _id))
        Severity: Major
        Found in api/handlers/containerhandler.py and 1 other location - About 1 hr to fix
        api/handlers/refererhandler.py on lines 107..110

        Duplicated Code

        Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

        Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

        When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

        Tuning

        This issue has a mass of 43.

        We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

        The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

        If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

        See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

        Refactorings

        Further Reading

        Similar blocks of code found in 3 locations. Consider refactoring.
        Open

                if not self.superuser_request and not self.is_true('join_avatars'):
                    self._filter_all_permissions(results, self.uid)
        Severity: Major
        Found in api/handlers/containerhandler.py and 2 other locations - About 55 mins to fix
        api/handlers/collectionshandler.py on lines 128..129
        api/handlers/containerhandler.py on lines 107..108

        Duplicated Code

        Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

        Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

        When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

        Tuning

        This issue has a mass of 37.

        We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

        The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

        If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

        See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

        Refactorings

        Further Reading

        Identical blocks of code found in 2 locations. Consider refactoring.
        Open

                if self.superuser_request:
                    permchecker = always_ok
                elif self.public_request:
                    permchecker = containerauth.list_public_request
                else:
        Severity: Minor
        Found in api/handlers/containerhandler.py and 1 other location - About 55 mins to fix
        api/handlers/collectionshandler.py on lines 120..125

        Duplicated Code

        Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

        Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

        When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

        Tuning

        This issue has a mass of 37.

        We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

        The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

        If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

        See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

        Refactorings

        Further Reading

        Similar blocks of code found in 3 locations. Consider refactoring.
        Open

                if not self.superuser_request and not self.is_true('join_avatars'):
                    self._filter_permissions(result, self.uid)
        Severity: Major
        Found in api/handlers/containerhandler.py and 2 other locations - About 55 mins to fix
        api/handlers/collectionshandler.py on lines 128..129
        api/handlers/containerhandler.py on lines 344..345

        Duplicated Code

        Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

        Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

        When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

        Tuning

        This issue has a mass of 37.

        We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

        The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

        If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

        See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

        Refactorings

        Further Reading

        Similar blocks of code found in 2 locations. Consider refactoring.
        Open

                    if payload.get('subject') is not None and payload['subject'].get('_id') is not None:
        Severity: Minor
        Found in api/handlers/containerhandler.py and 1 other location - About 50 mins to fix
        api/dao/basecontainerstorage.py on lines 241..241

        Duplicated Code

        Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

        Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

        When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

        Tuning

        This issue has a mass of 36.

        We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

        The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

        If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

        See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

        Refactorings

        Further Reading

        Similar blocks of code found in 9 locations. Consider refactoring.
        Open

                if payload.get('timestamp'):
                    payload['timestamp'] = dateutil.parser.parse(payload['timestamp'])
        Severity: Major
        Found in api/handlers/containerhandler.py and 8 other locations - About 45 mins to fix
        api/dao/hierarchy.py on lines 512..513
        api/dao/hierarchy.py on lines 531..532
        api/handlers/containerhandler.py on lines 436..437
        api/handlers/listhandler.py on lines 282..283
        api/handlers/listhandler.py on lines 298..299
        bin/oneoffs/load_external_data.py on lines 32..33
        bin/oneoffs/load_external_data.py on lines 34..35
        bin/oneoffs/load_external_data.py on lines 36..37

        Duplicated Code

        Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

        Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

        When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

        Tuning

        This issue has a mass of 35.

        We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

        The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

        If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

        See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

        Refactorings

        Further Reading

        Identical blocks of code found in 2 locations. Consider refactoring.
        Open

                if user_perm.get('access') != 'admin':
                    result['permissions'] = [user_perm] if user_perm else []
        Severity: Minor
        Found in api/handlers/containerhandler.py and 1 other location - About 45 mins to fix
        api/handlers/grouphandler.py on lines 111..112

        Duplicated Code

        Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

        Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

        When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

        Tuning

        This issue has a mass of 35.

        We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

        The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

        If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

        See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

        Refactorings

        Further Reading

        Similar blocks of code found in 9 locations. Consider refactoring.
        Open

                if payload.get('timestamp'):
                    payload['timestamp'] = dateutil.parser.parse(payload['timestamp'])
        Severity: Major
        Found in api/handlers/containerhandler.py and 8 other locations - About 45 mins to fix
        api/dao/hierarchy.py on lines 512..513
        api/dao/hierarchy.py on lines 531..532
        api/handlers/containerhandler.py on lines 484..485
        api/handlers/listhandler.py on lines 282..283
        api/handlers/listhandler.py on lines 298..299
        bin/oneoffs/load_external_data.py on lines 32..33
        bin/oneoffs/load_external_data.py on lines 34..35
        bin/oneoffs/load_external_data.py on lines 36..37

        Duplicated Code

        Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

        Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

        When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

        Tuning

        This issue has a mass of 35.

        We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

        The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

        If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

        See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

        Refactorings

        Further Reading

        There are no issues that match your filters.

        Category
        Status