ejplatform/ej-server

View on GitHub

Showing 185 of 185 total issues

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

    def save_metadata(self, user, request):
        metadata = request.data.get("metadata")
        if metadata:
            MetaData.objects.create(
                analytics_id=metadata.get("analytics_id"), mautic_id=metadata.get("mautic_id"), user=user
Severity: Major
Found in src/ej_users/api.py and 1 other location - About 2 hrs to fix
src/ej_users/rest_auth_serializer.py on lines 52..56

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

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

    def save_metadata(self, user, request):
        metadata = request.data.get("metadata")
        if metadata:
            MetaData.objects.create(
                analytics_id=metadata.get("analytics_id"), mautic_id=metadata.get("mautic_id"), user=user
Severity: Major
Found in src/ej_users/rest_auth_serializer.py and 1 other location - About 2 hrs to fix
src/ej_users/api.py on lines 58..62

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 conversation.py has 268 lines of code (exceeds 250 allowed). Consider refactoring.
Open

from autoslug import AutoSlugField
from boogie import models
from boogie import rules
from django.conf import settings
from django.contrib.auth import get_user_model
Severity: Minor
Found in src/ej_conversations/models/conversation.py - About 2 hrs to fix

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

    class IsOwner(permissions.BasePermission):  # For model cluster
        def has_permission(self, request, view):
            if request.user.is_authenticated:
                return True
    
    
    Severity: Major
    Found in src/ej/permissions.py and 2 other locations - About 2 hrs to fix
    src/ej/permissions.py on lines 4..13
    src/ej/permissions.py on lines 28..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 54.

    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

    class IsAuthor(permissions.BasePermission):
        def has_permission(self, request, view):
            if request.user.is_authenticated:
                return True
    
    
    Severity: Major
    Found in src/ej/permissions.py and 2 other locations - About 2 hrs to fix
    src/ej/permissions.py on lines 16..25
    src/ej/permissions.py on lines 28..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 54.

    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

    class IsUser(permissions.BasePermission):  # For model profile
        def has_permission(self, request, view):
            if request.user.is_authenticated:
                return True
    
    
    Severity: Major
    Found in src/ej/permissions.py and 2 other locations - About 2 hrs to fix
    src/ej/permissions.py on lines 4..13
    src/ej/permissions.py on lines 16..25

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

    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 AreaChart has 58 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

    function AreaChart(voteData, color) {
      const curve = d3.curveLinear;
      const margin = { top: 20, right: 30, bottom: 30, left: 40 };
    
      let width = d3.select("#votes-over-time").attr("width");
    Severity: Major
    Found in lib/assets/js/conversations/votes-over-time.js - About 2 hrs to fix

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

      def clean_migrations(_ctx, all=False, yes=False):
          """
          Remove all automatically created migrations.
          """
          import re
      Severity: Minor
      Found in etc/tasklib/django_tasks.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 constructor has 53 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          constructor({size, intersections, radius = 50, pos = null, vel = null, isUserGroup = false, name = "Group"}) {
              this.size = size;
              this.intersections = intersections.slice();
              this.radius = radius;
              this.mass = (this.radius / 100) ** 2;
      Severity: Major
      Found in lib/js/clusterviz/shape.ts - About 2 hrs to fix

        Function summarize_affinities has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring.
        Open

        def summarize_affinities(affinities):
            """
            Process the result of :func:`compute_cluster_affinities`
            and returns a list of summaries for each cluster/intersection. This data
            is exposed in the /api/v1/clusterizations/<id>/affinities/ as:
        Severity: Minor
        Found in src/ej_clusters/math/data.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 2 locations. Consider refactoring.
        Open

                function showLowerNav(windowWidth) {
                    if (windowWidth <= 550) {
                        $('.Page').css({'padding': '45px 0 45px 0', 'transition': 'padding 0.3s linear'});
                    } else {
                        $('.Page').css({'padding': '70px 0 45px 0', 'transition': 'padding 0.3s linear'});
        Severity: Major
        Found in lib/js/legacy/utils.ts and 1 other location - About 2 hrs to fix
        lib/js/legacy/utils.ts on lines 5..11

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

        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

                function hideLowerNav(windowWidth) {
                    if (windowWidth <= 550) {
                        $('.Page').css({'padding': '45px 0 0 0', 'transition': 'padding 0.3s linear'});
                    } else {
                        $('.Page').css({'padding': '70px 0 0 0', 'transition': 'padding 0.3s linear'});
        Severity: Major
        Found in lib/js/legacy/utils.ts and 1 other location - About 2 hrs to fix
        lib/js/legacy/utils.ts on lines 12..18

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

        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

            @action(detail=True)
            def clusters(self, request, pk):
                clusterization = self.get_object()
                clusters = clusterization.clusters.all()
                serializer = ClusterSerializer(clusters, context={"request": request}, many=True)
        Severity: Major
        Found in src/ej_clusters/api.py and 1 other location - About 2 hrs to fix
        src/ej_conversations/api.py on lines 103..109

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

        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

            @action(detail=True, url_path="approved-comments")
            def approved_comments(self, request, pk):
                conversation = self.get_object()
                comments = conversation.comments.approved()
                serializer = CommentSerializer(comments, context={"request": request}, many=True)
        Severity: Major
        Found in src/ej_conversations/api.py and 1 other location - About 2 hrs to fix
        src/ej_clusters/api.py on lines 29..34

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

        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 stereotype_votes has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
        Open

        def stereotype_votes(request, conversation_id, **kwargs):
            conversation = Conversation.objects.get(id=conversation_id)
            clusterization = conversation.get_clusterization(default=None)
            created_vote_id = None
            if clusterization is None:
        Severity: Minor
        Found in src/ej_clusters/views.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

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

                links["board"] = (
                    reverse("v1-boards-detail", args=[obj.board.id], request=self.context["request"])
                    if hasattr(obj, "board")
        Severity: Major
        Found in src/ej_conversations/serializers.py and 2 other locations - About 1 hr to fix
        src/ej_conversations/serializers.py on lines 54..58
        src/ej_conversations/serializers.py on lines 61..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 47.

        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

                links["clusterization"] = (
                    reverse(
                        "v1-clusterizations-detail", args=[obj.clusterization.id], request=self.context["request"]
                    )
                    if hasattr(obj, "clusterization")
        Severity: Major
        Found in src/ej_conversations/serializers.py and 2 other locations - About 1 hr to fix
        src/ej_conversations/serializers.py on lines 61..63
        src/ej_conversations/serializers.py on lines 66..68

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

        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

                links["author"] = (
                    reverse("v1-users-detail", args=[obj.author.id], request=self.context["request"])
                    if hasattr(obj, "author")
        Severity: Major
        Found in src/ej_conversations/serializers.py and 2 other locations - About 1 hr to fix
        src/ej_conversations/serializers.py on lines 54..58
        src/ej_conversations/serializers.py on lines 66..68

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

        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 with_template has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
        Open

        def with_template(model, role, template=None, queryset=False):
            """
            Decorator Register element rendered from a template.
        
            Args:
        Severity: Minor
        Found in src/ej/roles/utils.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 main has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
        Open

        def main():
            """
            This code was taken and adapted from
        
            django.core.management.commands.compilemessages
        Severity: Minor
        Found in etc/scripts/compilemessages.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

        Severity
        Category
        Status
        Source
        Language