RocketChat/Rocket.Chat

View on GitHub
apps/meteor/app/api/server/v1/moderation.ts

Summary

Maintainability
D
2 days
Test Coverage

File moderation.ts has 335 lines of code (exceeds 250 allowed). Consider refactoring.
Open

import type { IModerationReport, IUser, IUserEmail } from '@rocket.chat/core-typings';
import { ModerationReports, Users } from '@rocket.chat/models';
import {
    isReportHistoryProps,
    isArchiveReportProps,
Severity: Minor
Found in apps/meteor/app/api/server/v1/moderation.ts - About 4 hrs to fix

    Function get has 39 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

            async get() {
                const { userId, selector = '' } = this.queryParams;
                const { sort } = await this.parseJsonQuery();
                const { count = 50, offset = 0 } = await getPaginationItems(this.queryParams);
    
    
    Severity: Minor
    Found in apps/meteor/app/api/server/v1/moderation.ts - About 1 hr to fix

      Function get has 29 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

              async get() {
                  const { userId, selector = '' } = this.queryParams;
      
                  const { sort } = await this.parseJsonQuery();
      
      
      Severity: Minor
      Found in apps/meteor/app/api/server/v1/moderation.ts - About 1 hr to fix

        Function post has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
        Open

                async post() {
                    const { userId, msgId, reason, action: actionParam } = this.bodyParams;
        
                    if (userId) {
                        const report = await ModerationReports.findOne({ 'message.u._id': userId, '_hidden': { $ne: true } }, { projection: { _id: 1 } });
        Severity: Minor
        Found in apps/meteor/app/api/server/v1/moderation.ts - 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 has 27 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

                async get() {
                    const { latest: _latest, oldest: _oldest, selector = '' } = this.queryParams;
        
                    const { count = 20, offset = 0 } = await getPaginationItems(this.queryParams);
        
        
        Severity: Minor
        Found in apps/meteor/app/api/server/v1/moderation.ts - About 1 hr to fix

          Function get has 26 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

                  async get() {
                      const { latest: _latest, oldest: _oldest, selector = '' } = this.queryParams;
          
                      const { count = 20, offset = 0 } = await getPaginationItems(this.queryParams);
                      const { sort } = await this.parseJsonQuery();
          Severity: Minor
          Found in apps/meteor/app/api/server/v1/moderation.ts - About 1 hr to fix

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

                        if (userId) {
                            const report = await ModerationReports.findOne({ 'message.u._id': userId, '_hidden': { $ne: true } }, { projection: { _id: 1 } });
                            if (!report) {
                                return API.v1.failure('no-reports-found');
                            }
            Severity: Major
            Found in apps/meteor/app/api/server/v1/moderation.ts and 1 other location - About 2 hrs to fix
            apps/meteor/app/api/server/v1/moderation.ts on lines 283..288

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

            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 (msgId) {
                            const report = await ModerationReports.findOne({ 'message._id': msgId, '_hidden': { $ne: true } }, { projection: { _id: 1 } });
                            if (!report) {
                                return API.v1.failure('no-reports-found');
                            }
            Severity: Major
            Found in apps/meteor/app/api/server/v1/moderation.ts and 1 other location - About 2 hrs to fix
            apps/meteor/app/api/server/v1/moderation.ts on lines 276..281

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

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

                        const user = await Users.findOneById<Pick<IUser, '_id' | 'username' | 'name'>>(userId, {
                            projection: { _id: 1, username: 1, name: 1 },
                        });
            Severity: Major
            Found in apps/meteor/app/api/server/v1/moderation.ts and 6 other locations - About 1 hr to fix
            apps/meteor/app/livechat/server/api/v1/agent.ts on lines 76..82
            apps/meteor/app/livechat/server/api/v1/transcript.ts on lines 38..40
            apps/meteor/app/livechat/server/lib/Helper.ts on lines 597..605
            apps/meteor/ee/server/api/audit.ts on lines 54..54
            apps/meteor/server/services/nps/service.ts on lines 153..155
            ee/packages/presence/src/Presence.ts on lines 186..188

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

            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 (reports.length === 0) {
                            return API.v1.success({
                                reports,
                                count: 0,
                                offset,
            Severity: Minor
            Found in apps/meteor/app/api/server/v1/moderation.ts and 1 other location - About 50 mins to fix
            apps/meteor/app/api/server/v1/moderation.ts on lines 45..52

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

            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 (reports.length === 0) {
                            return API.v1.success({
                                reports,
                                count: 0,
                                offset,
            Severity: Minor
            Found in apps/meteor/app/api/server/v1/moderation.ts and 1 other location - About 50 mins to fix
            apps/meteor/app/api/server/v1/moderation.ts on lines 93..100

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

            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

                        const user = await Users.findOneById<IUser>(userId, {
                            projection: {
                                _id: 1,
                                username: 1,
                                name: 1,
            Severity: Minor
            Found in apps/meteor/app/api/server/v1/moderation.ts and 1 other location - About 40 mins to fix
            apps/meteor/app/reactions/server/setReaction.ts on lines 143..143

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

            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

                        return API.v1.success({
                            user,
                            messages: uniqueMessages,
                            count: reports.length,
                            total,
            Severity: Minor
            Found in apps/meteor/app/api/server/v1/moderation.ts and 1 other location - About 30 mins to fix
            apps/meteor/app/api/server/v1/moderation.ts on lines 212..218

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

            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

                        return API.v1.success({
                            user,
                            reports,
                            count: reports.length,
                            total,
            Severity: Minor
            Found in apps/meteor/app/api/server/v1/moderation.ts and 1 other location - About 30 mins to fix
            apps/meteor/app/api/server/v1/moderation.ts on lines 154..160

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

            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