gecos-team/gecoscc-ui

View on GitHub
gecoscc/permissions.py

Summary

Maintainability
C
1 day
Test Coverage

Function can_access_to_this_path has a Cognitive Complexity of 20 (exceeds 5 allowed). Consider refactoring.
Open

def can_access_to_this_path(request, collection_nodes, oid_or_obj, ou_type='ou_managed'):
    obj = None
    request = request
    ou_managed_ids = request.user.get(ou_type, [])
    if not request.user.get('is_superuser'):
Severity: Minor
Found in gecoscc/permissions.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 master_policy_no_updated_or_403 has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
Open

def master_policy_no_updated_or_403(request, collection_nodes, obj):
    if obj['type'] in RESOURCES_EMITTERS_TYPES or is_local_user(obj, collection_nodes):
        return
    domain = get_domain(obj, collection_nodes) or {}
    master_policies = domain.get('master_policies', {})
Severity: Minor
Found in gecoscc/permissions.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 nodes_path_filter has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
Open

def nodes_path_filter(request, ou_type='ou_managed'):
    if isinstance(ou_type, str):
        ou_type =[ou_type]

    params = request.GET
Severity: Minor
Found in gecoscc/permissions.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 is_gecos_master_or_403 has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
Open

def is_gecos_master_or_403(request, collection_nodes, obj, schema_detail):
    domain = get_domain(obj, collection_nodes)
    if domain and domain['master'] != MASTER_DEFAULT and not is_local_user(obj, collection_nodes):
        if '_id' not in obj:
            raise HTTPForbidden()
Severity: Minor
Found in gecoscc/permissions.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 __acl__ has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
Open

    def __acl__(self):
        user = self.request.user
        if user:
            username = self.request.matchdict.get('username') or self.request.GET.get('username')
            is_superuser = user.get('is_superuser')
Severity: Minor
Found in gecoscc/permissions.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 http_basic_login_required has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
Open

def http_basic_login_required(request, **kwargs):
    try:
        api_login_required(request)
    except HTTPForbidden as e:
        authorization = request.headers.get('Authorization')
Severity: Minor
Found in gecoscc/permissions.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 __acl__ has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
Open

    def __acl__(self):
        # Get the remote address
        remote_addr = self.request.remote_addr
        header = 'remote_addr'
        if 'X-Real-IP' in self.request.headers:
Severity: Minor
Found in gecoscc/permissions.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 __acl__ has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
Open

    def __acl__(self):
        user = self.request.user
        if user:
            if user.get('is_superuser', False):
                return [(Allow, Authenticated, 'edit'), (Allow, Authenticated, 'is_superuser')]
Severity: Minor
Found in gecoscc/permissions.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 is_path_right has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
Open

def is_path_right(request, path, ou_type='ou_managed'):
    ou_managed_ids = []
    if path is None:
        path = ''

Severity: Minor
Found in gecoscc/permissions.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 self.maintenance and self.maintenance.get('value') is True:
                return [(Allow,'g:maintenance',ALL_PERMISSIONS)]
Severity: Minor
Found in gecoscc/permissions.py and 1 other location - About 40 mins to fix
gecoscc/permissions.py on lines 218..219

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 34.

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.maintenance and self.maintenance.get('value') is True:
            return [(Allow,'g:maintenance', ALL_PERMISSIONS)]
Severity: Minor
Found in gecoscc/permissions.py and 1 other location - About 40 mins to fix
gecoscc/permissions.py on lines 299..300

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 34.

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 4 locations. Consider refactoring.
Open

        if 'X-Forwarded-For' in self.request.headers:
            remote_addr = self.request.headers['X-Forwarded-For']
            header = 'X-Forwarded-For'
Severity: Major
Found in gecoscc/permissions.py and 3 other locations - About 40 mins to fix
gecoscc/api/help_channel_client.py on lines 353..355
gecoscc/api/help_channel_client.py on lines 356..358
gecoscc/permissions.py on lines 248..250

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 34.

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 4 locations. Consider refactoring.
Open

        if 'X-Real-IP' in self.request.headers:
            remote_addr = self.request.headers['X-Real-IP']
            header = 'X-Real-IP'
Severity: Major
Found in gecoscc/permissions.py and 3 other locations - About 40 mins to fix
gecoscc/api/help_channel_client.py on lines 353..355
gecoscc/api/help_channel_client.py on lines 356..358
gecoscc/permissions.py on lines 251..253

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 34.

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