mongaku/mongaku

View on GitHub
src/logic/admin.js

Summary

Maintainability
F
5 days
Test Coverage

Function exports has 323 lines of code (exceeds 25 allowed). Consider refactoring.
Open

module.exports = function(app) {
    const {auth, isAdmin} = require("./shared/auth");

    return {
        admin(req, res) {
Severity: Major
Found in src/logic/admin.js - About 1 day to fix

    File admin.js has 424 lines of code (exceeds 250 allowed). Consider refactoring.
    Open

    const fs = require("fs");
    const path = require("path");
    const {Readable} = require("stream");
    
    const async = require("async");
    Severity: Minor
    Found in src/logic/admin.js - About 6 hrs to fix

      Function addSources has 92 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

              addSources(req, res, next) {
                  const {i18n, lang} = req;
                  const {isPrivate, type, converter, sources} = req.body;
      
                  let createdOrUpdated = 0;
      Severity: Major
      Found in src/logic/admin.js - About 3 hrs to fix

        Function addUsers has 85 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

                addUsers(req, res, next) {
                    const {lang, i18n} = req;
        
                    let createdOrUpdated = 0;
                    const failed = [];
        Severity: Major
        Found in src/logic/admin.js - About 3 hrs to fix

          Function addUser has 38 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

                  addUser(req, res, next) {
                      const {i18n, lang} = req;
                      const {
                          username: email,
                          password,
          Severity: Minor
          Found in src/logic/admin.js - About 1 hr to fix

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

                                        if (failed.length > 0) {
                                            qs.push(
                                                `error=${encodeURIComponent(
                                                    i18n.format(
                                                        i18n.gettext(
            Severity: Major
            Found in src/logic/admin.js and 1 other location - About 2 hrs to fix
            src/logic/admin.js on lines 259..275

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

            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 (failed.length > 0) {
                                            qs.push(
                                                `error=${encodeURIComponent(
                                                    i18n.format(
                                                        i18n.gettext(
            Severity: Major
            Found in src/logic/admin.js and 1 other location - About 2 hrs to fix
            src/logic/admin.js on lines 403..419

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

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

                    addUserPage(req, res) {
                        const {i18n, query} = req;
                        res.render("AddUser", {
                            title: i18n.gettext("Add or Update User"),
                            success: query.success,
            Severity: Major
            Found in src/logic/admin.js and 4 other locations - About 1 hr to fix
            src/logic/admin.js on lines 124..131
            src/logic/admin.js on lines 186..193
            src/logic/admin.js on lines 291..298
            src/logic/admin.js on lines 328..335

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

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

                    admin(req, res) {
                        const {i18n, query} = req;
                        res.render("Admin", {
                            title: i18n.gettext("Admin"),
                            success: query.success,
            Severity: Major
            Found in src/logic/admin.js and 4 other locations - About 1 hr to fix
            src/logic/admin.js on lines 133..140
            src/logic/admin.js on lines 186..193
            src/logic/admin.js on lines 291..298
            src/logic/admin.js on lines 328..335

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

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

                    addUsersPage(req, res) {
                        const {i18n, query} = req;
                        res.render("AddUsers", {
                            title: i18n.gettext("Bulk Add or Update Users"),
                            success: query.success,
            Severity: Major
            Found in src/logic/admin.js and 4 other locations - About 1 hr to fix
            src/logic/admin.js on lines 124..131
            src/logic/admin.js on lines 133..140
            src/logic/admin.js on lines 291..298
            src/logic/admin.js on lines 328..335

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

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

                    addSourcesPage(req, res) {
                        const {i18n, query} = req;
                        res.render("AddSources", {
                            title: i18n.gettext("Bulk Add or Update Sources"),
                            success: query.success,
            Severity: Major
            Found in src/logic/admin.js and 4 other locations - About 1 hr to fix
            src/logic/admin.js on lines 124..131
            src/logic/admin.js on lines 133..140
            src/logic/admin.js on lines 186..193
            src/logic/admin.js on lines 291..298

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

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

                    addSourcePage(req, res) {
                        const {i18n, query} = req;
                        res.render("AddSource", {
                            title: i18n.gettext("Add or Update Source"),
                            success: query.success,
            Severity: Major
            Found in src/logic/admin.js and 4 other locations - About 1 hr to fix
            src/logic/admin.js on lines 124..131
            src/logic/admin.js on lines 133..140
            src/logic/admin.js on lines 186..193
            src/logic/admin.js on lines 328..335

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

            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

                                            res.redirect(
                                                urls.gen(
                                                    lang,
                                                    `/admin/manage-sources${
                                                        qs.length > 0
            Severity: Major
            Found in src/logic/admin.js and 1 other location - About 1 hr to fix
            src/logic/admin.js on lines 277..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 60.

            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

                                        res.redirect(
                                            urls.gen(
                                                lang,
                                                `/admin/add-users${
                                                    qs.length > 0 ? `?${qs.join("&")}` : ""
            Severity: Major
            Found in src/logic/admin.js and 1 other location - About 1 hr to fix
            src/logic/admin.js on lines 424..433

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

            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 (createdOrUpdated > 0) {
                                            qs.push(
                                                `success=${encodeURIComponent(
                                                    i18n.format(
                                                        i18n.gettext(
            Severity: Major
            Found in src/logic/admin.js and 1 other location - About 1 hr to fix
            src/logic/admin.js on lines 246..257

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

            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 (createdOrUpdated > 0) {
                                            qs.push(
                                                `success=${encodeURIComponent(
                                                    i18n.format(
                                                        i18n.gettext(
            Severity: Major
            Found in src/logic/admin.js and 1 other location - About 1 hr to fix
            src/logic/admin.js on lines 390..401

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

            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

                        const sources = Source.getSourcesByViewable(user)
                            .map(source => {
                                const cloned = cloneModel(source, i18n);
                                cloned.numRecords = source.numRecords;
                                cloned.numImages = source.numImages;
            Severity: Minor
            Found in src/logic/admin.js and 1 other location - About 55 mins to fix
            src/logic/home.js on lines 12..19

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

            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