linagora/openpaas-esn

View on GitHub
backend/webserver/controllers/domains.js

Summary

Maintainability
D
2 days
Test Coverage

File domains.js has 255 lines of code (exceeds 250 allowed). Consider refactoring.
Open

'use strict';

const _ = require('lodash');
const q = require('q');

Severity: Minor
Found in backend/webserver/controllers/domains.js - About 2 hrs to fix

    Function getMembers has 37 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

    function getMembers(req, res) {
      const domain = req.domain;
      const query = {
        limit: +req.query.limit || DEFAULT_LIMIT,
        offset: +req.query.offset || DEFAULT_OFFSET,
    Severity: Minor
    Found in backend/webserver/controllers/domains.js - About 1 hr to fix

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

      function update(req, res) {
        const domain = {
          id: req.params.uuid,
          company_name: req.body.company_name || req.domain.company_name,
          hostnames: [...new Set(req.body.hostnames || req.domain.hostnames)]
      Severity: Minor
      Found in backend/webserver/controllers/domains.js - About 1 hr to fix

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

          userDomain.addDomainAdministrator(domain, userIds, err => {
            if (err) {
              logger.error('Error while adding domain administrators:', err);
        
              return res.status(500).json({
        Severity: Major
        Found in backend/webserver/controllers/domains.js and 1 other location - About 3 hrs to fix
        backend/webserver/controllers/domains.js on lines 336..346

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

        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

          userDomain.removeDomainAdministrator(domain, administratorId, err => {
            if (err) {
              logger.error('Error while removing domain administrator:', err);
        
              return res.status(500).json({
        Severity: Major
        Found in backend/webserver/controllers/domains.js and 1 other location - About 3 hrs to fix
        backend/webserver/controllers/domains.js on lines 313..323

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

        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 _createWithAdministrator(domain, administrator)
            .then(domain => res.status(201).json(denormalizeDomain(domain)))
            .catch(err => {
              const details = `Error while creating domain ${name}`;
        
        
        Severity: Major
        Found in backend/webserver/controllers/domains.js and 1 other location - About 2 hrs to fix
        backend/webserver/controllers/users.js on lines 506..521

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

          return q.ninvoke(coreDomain, 'update', domain)
            .then(updated => {
              if (updated) {
                return res.status(204).end();
              }
        Severity: Major
        Found in backend/webserver/controllers/domains.js and 10 other locations - About 1 hr to fix
        backend/webserver/controllers/platformadmins.js on lines 12..34
        backend/webserver/controllers/technicalusers.js on lines 25..42
        backend/webserver/controllers/technicalusers.js on lines 56..70
        backend/webserver/controllers/technicalusers.js on lines 85..99
        backend/webserver/controllers/technicalusers.js on lines 105..119
        backend/webserver/middleware/application-discovery-service.js on lines 42..63
        backend/webserver/middleware/passwordreset.js on lines 9..37
        backend/webserver/middleware/themes.js on lines 11..39
        backend/webserver/middleware/users.js on lines 20..44
        backend/webserver/middleware/users.js on lines 121..147

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

        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

        module.exports = {
          list,
          create,
          update,
          getMembers,
        Severity: Major
        Found in backend/webserver/controllers/domains.js and 1 other location - About 1 hr to fix
        backend/core/health-check/index.js on lines 8..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 64.

        We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

        The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

        If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

        See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

        Refactorings

        Further Reading

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

          if (!Array.isArray(userIds)) {
            return res.status(400).json({
              error: { code: 400, message: 'Bad request', details: 'body should be an array of user\'s ID'}
            });
          }
        Severity: Major
        Found in backend/webserver/controllers/domains.js and 3 other locations - About 1 hr to fix
        backend/webserver/middleware/domain.js on lines 74..76
        backend/webserver/middleware/domain.js on lines 104..106
        backend/webserver/middleware/resource-link.js on lines 44..46

        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

        There are no issues that match your filters.

        Category
        Status