edgewall/trac

View on GitHub
trac/perm.py

Summary

Maintainability
F
3 days
Test Coverage

File perm.py has 664 lines of code (exceeds 250 allowed). Consider refactoring.
Open

# -*- coding: utf-8 -*-
#
# Copyright (C) 2003-2023 Edgewall Software
# Copyright (C) 2003-2004 Jonas Borgström <jonas@edgewall.com>
# Copyright (C) 2005 Christopher Lenz <cmlenz@gmx.de>
Severity: Major
Found in trac/perm.py - About 1 day to fix

    Function _get_actions_and_groups has a Cognitive Complexity of 17 (exceeds 5 allowed). Consider refactoring.
    Open

        def _get_actions_and_groups(self, subjects):
            """Get actions and groups for `subjects`, an iterable of username
            and groups that username is a member of.
            """
            actions = set()
    Severity: Minor
    Found in trac/perm.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

    Function _do_remove has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
    Open

        def _do_remove(self, user, *actions):
            permsys = PermissionSystem(self.env)
            rows = permsys.get_all_permissions()
            for action in actions:
                found = False
    Severity: Minor
    Found in trac/perm.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 _do_add has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
    Open

        def _do_add(self, user, *actions):
            permsys = PermissionSystem(self.env)
            if user.isupper():
                raise AdminCommandError(_("All upper-cased tokens are reserved "
                                          "for permission names"))
    Severity: Minor
    Found in trac/perm.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 _do_import has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
    Open

        def _do_import(self, filename=None):
            permsys = PermissionSystem(self.env)
            linesep = os.linesep if filename else '\n'
            try:
                with file_or_std(filename, 'r') as f:
    Severity: Minor
    Found in trac/perm.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_actions_dict has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
    Open

        def get_actions_dict(self, skip=None):
            """Get all actions from permission requestors as a `dict`.
    
            The keys are the action names. The values are the additional actions
            granted by each action. For simple actions, this is an empty list.
    Severity: Minor
    Found in trac/perm.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_users_with_permission has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
    Open

        def get_users_with_permission(self, permission):
            """Return all users that have the specified permission.
    
            Users are returned as a list of user names.
            """
    Severity: Minor
    Found in trac/perm.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 check_permission has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
    Open

        def check_permission(self, action, username=None, resource=None,
                             perm=None):
            """Return True if permission to perform action for the given
            resource is allowed.
            """
    Severity: Minor
    Found in trac/perm.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 get_actions has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
    Open

        def get_actions(self, skip=None):
            """Get a list of all actions defined by permission requestors."""
            actions = set()
            for requestor in self.requestors:
                if requestor is skip:
    Severity: Minor
    Found in trac/perm.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 __init__ has 5 arguments (exceeds 4 allowed). Consider refactoring.
    Open

        def __init__(self, env, username=None, resource=None, cache=None,
    Severity: Minor
    Found in trac/perm.py - About 35 mins to fix

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

          def require(self, action, realm_or_resource=None, id=False, version=False,
      Severity: Minor
      Found in trac/perm.py - About 35 mins to fix

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

            def _do_list(self, user=None):
                permsys = PermissionSystem(self.env)
                if user:
                    rows = []
                    perms = permsys.get_user_permissions(user, undefined=True)
        Severity: Minor
        Found in trac/perm.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 grant_permission has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
        Open

            def grant_permission(self, username, action):
                """Grant the user with the given name permission to perform to
                specified action.
        
                :raises PermissionExistsError: if user already has the permission
        Severity: Minor
        Found in trac/perm.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 __init__ has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
        Open

            def __init__(self, action=None, resource=None, env=None, msg=None):
                self.action = action
                self.resource = resource
                self.env = env
                if self.action:
        Severity: Minor
        Found in trac/perm.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 expand_actions has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
        Open

            def expand_actions(self, actions):
                """Helper method for expanding all meta actions."""
                all_actions = self.get_actions_dict()
                expanded_actions = set()
                def expand_action(action):
        Severity: Minor
        Found in trac/perm.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_users_with_permissions has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
        Open

            def get_users_with_permissions(self, permissions):
                """Retrieve a list of users that have any of the specified
                permissions
        
                Users are returned as a list of usernames.
        Severity: Minor
        Found in trac/perm.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