fossasia/open-event-orga-server

View on GitHub

Showing 1,194 of 1,194 total issues

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

class GroupRelationship(ResourceRelationship):
    """
    Group Relationship
    """

Severity: Major
Found in app/api/groups.py and 3 other locations - About 2 hrs to fix
app/api/microlocations.py on lines 103..118
app/api/social_links.py on lines 69..84
app/api/sponsors.py on lines 84..99

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

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

class SocialLinkRelationship(ResourceRelationship):
    """
    Social Link Relationship
    """

Severity: Major
Found in app/api/social_links.py and 3 other locations - About 2 hrs to fix
app/api/groups.py on lines 174..188
app/api/microlocations.py on lines 103..118
app/api/sponsors.py on lines 84..99

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

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

File check_in_stats.py has 268 lines of code (exceeds 250 allowed). Consider refactoring.
Open

import datetime

from flask import Blueprint, request
from sqlalchemy import desc

Severity: Minor
Found in app/api/custom/check_in_stats.py - About 2 hrs to fix

Function validate_fields has a Cognitive Complexity of 18 (exceeds 5 allowed). Consider refactoring.
Open

    def validate_fields(self, data, original_data):
        is_patch_request = 'id' in original_data['data']
        if is_patch_request:
            try:
                session = Session.query.filter_by(id=original_data['data']['id']).one()
Severity: Minor
Found in app/api/schema/sessions.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 get_token has a Cognitive Complexity of 18 (exceeds 5 allowed). Consider refactoring.
Open

    def get_token(
        self,
        user: User,
        event: Optional[Event] = None,
        retried=False,
Severity: Minor
Found in app/api/chat/rocket_chat.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 get_token_virtual_room has a Cognitive Complexity of 18 (exceeds 5 allowed). Consider refactoring.
Open

    def get_token_virtual_room(
        self,
        user: User,
        event: Optional[Event] = None,
        retried=False,
Severity: Minor
Found in app/api/chat/rocket_chat.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 before_create_object has a Cognitive Complexity of 18 (exceeds 5 allowed). Consider refactoring.
Open

    def before_create_object(self, data, view_kwargs):
        if data.get('used_for') == 'ticket' and (event_id := data.get('event')):
            discount_codes = DiscountCode.query.filter_by(
                event_id=event_id, code=data['code'], deleted_at=None
            )
Severity: Minor
Found in app/api/discount_codes.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 get_value_from_qr_filed has a Cognitive Complexity of 18 (exceeds 5 allowed). Consider refactoring.
Open

def get_value_from_qr_filed(field: BadgeFieldForms, ticket_holder: TicketHolder) -> dict:
    """Get the value of a QR code field."""
    qr_value = {}
    custom_fields = []
    if field.qr_custom_field is not None:
Severity: Minor
Found in app/api/helpers/badge_forms.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 _fix_related_fields has a Cognitive Complexity of 18 (exceeds 5 allowed). Consider refactoring.
Open

def _fix_related_fields(srv, data, service_ids):
    """
    Fixes the ids services which are related to others.
    Like track, format -> session
    Also fixes their schema
Severity: Minor
Found in app/api/helpers/import_helpers.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

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

    def mail_last_30_days(self, obj):
        mails_till_last_30_day = Mail.query.filter(
            Mail.time >= datetime.now(pytz.utc) - timedelta(days=30)
        ).count()
        return mails_till_last_30_day
Severity: Major
Found in app/api/admin_statistics_api/mails.py and 3 other locations - About 2 hrs to fix
app/api/admin_statistics_api/mails.py on lines 35..39
app/api/admin_statistics_api/mails.py on lines 41..45
app/api/admin_statistics_api/mails.py on lines 47..51

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

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 'max_order' in data and 'min_order' in data:
            if data['max_order'] < data['min_order']:
                raise UnprocessableEntityError(
                    {'pointer': '/data/attributes/max-order'},
                    "max-order should be greater than or equal to min-order",
Severity: Major
Found in app/api/schema/tickets.py and 2 other locations - About 2 hrs to fix
app/api/schema/tickets.py on lines 59..63
app/api/schema/tickets.py on lines 73..77

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

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 'quantity' in data and 'max_order' in data:
            if data['quantity'] < data['max_order']:
                raise UnprocessableEntityError(
                    {'pointer': '/data/attributes/quantity'},
                    "quantity should be greater than or equal to max-order",
Severity: Major
Found in app/api/schema/tickets.py and 2 other locations - About 2 hrs to fix
app/api/schema/tickets.py on lines 52..56
app/api/schema/tickets.py on lines 59..63

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

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

    def mail_last_3_days(self, obj):
        mails_till_last_3_day = Mail.query.filter(
            Mail.time >= datetime.now(pytz.utc) - timedelta(days=3)
        ).count()
        return mails_till_last_3_day
Severity: Major
Found in app/api/admin_statistics_api/mails.py and 3 other locations - About 2 hrs to fix
app/api/admin_statistics_api/mails.py on lines 35..39
app/api/admin_statistics_api/mails.py on lines 47..51
app/api/admin_statistics_api/mails.py on lines 53..57

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

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

    def mail_last_7_days(self, obj):
        mails_till_last_7_day = Mail.query.filter(
            Mail.time >= datetime.now(pytz.utc) - timedelta(days=7)
        ).count()
        return mails_till_last_7_day
Severity: Major
Found in app/api/admin_statistics_api/mails.py and 3 other locations - About 2 hrs to fix
app/api/admin_statistics_api/mails.py on lines 35..39
app/api/admin_statistics_api/mails.py on lines 41..45
app/api/admin_statistics_api/mails.py on lines 53..57

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

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

    def mail_last_1_day(self, obj):
        mails_till_last_1_day = Mail.query.filter(
            Mail.time >= datetime.now(pytz.utc) - timedelta(days=1)
        ).count()
        return mails_till_last_1_day
Severity: Major
Found in app/api/admin_statistics_api/mails.py and 3 other locations - About 2 hrs to fix
app/api/admin_statistics_api/mails.py on lines 41..45
app/api/admin_statistics_api/mails.py on lines 47..51
app/api/admin_statistics_api/mails.py on lines 53..57

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

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 'quantity' in data and 'min_order' in data:
            if data['quantity'] < data['min_order']:
                raise UnprocessableEntityError(
                    {'pointer': '/data/attributes/quantity'},
                    "quantity should be greater than or equal to min-order",
Severity: Major
Found in app/api/schema/tickets.py and 2 other locations - About 2 hrs to fix
app/api/schema/tickets.py on lines 52..56
app/api/schema/tickets.py on lines 73..77

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

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

    for service in services:
        perm, _ = get_or_create(Permission, role=regist, service=service)
        perm.can_create, perm.can_update, perm.can_delete = False, False, False
        db.session.add(perm)
Severity: Major
Found in populate_db.py and 1 other location - About 2 hrs to fix
populate_db.py on lines 274..277

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

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

    for service in services:
        perm, _ = get_or_create(Permission, role=mod, service=service)
        perm.can_create, perm.can_update, perm.can_delete = False, False, False
        db.session.add(perm)
Severity: Major
Found in populate_db.py and 1 other location - About 2 hrs to fix
populate_db.py on lines 281..284

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

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

Function upgrade has 60 lines of code (exceeds 25 allowed). Consider refactoring.
Open

def upgrade():
    ### commands auto generated by Alembic - please adjust! ###
    op.rename_table('user', 'temp_user')
    op.create_table('users',
    sa.Column('id', sa.Integer(), nullable=False, autoincrement=True),
Severity: Major
Found in migrations/versions/9105f9e64cdc_.py - About 2 hrs to fix

File ticketing.py has 265 lines of code (exceeds 250 allowed). Consider refactoring.
Open

import logging
from datetime import datetime

import pytz
from flask_rest_jsonapi.exceptions import ObjectNotFound
Severity: Minor
Found in app/api/helpers/ticketing.py - About 2 hrs to fix
Severity
Category
Status
Source
Language