linagora/openpaas-esn

View on GitHub
backend/webserver/middleware/configuration.js

Summary

Maintainability
F
1 wk
Test Coverage

File configuration.js has 343 lines of code (exceeds 250 allowed). Consider refactoring.
Open

'use strict';

const q = require('q');
const { promisify } = require('util');
const composableMw = require('composable-middleware');
Severity: Minor
Found in backend/webserver/middleware/configuration.js - About 4 hrs to fix

    Function qualifyTargetUser has 52 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

    function qualifyTargetUser(req, res, next) {
      if (req.query.scope !== SCOPE.user) {
        return next();
      }
    
    
    Severity: Major
    Found in backend/webserver/middleware/configuration.js - About 2 hrs to fix

      Function validateWriteBody has 51 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

      function validateWriteBody(req, res, next) {
        const modules = req.body;
      
        const invalidModules = modules.map(module => {
          if (!Array.isArray(module.configurations)) {
      Severity: Major
      Found in backend/webserver/middleware/configuration.js - About 2 hrs to fix

        Function canWriteUserConfig has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
        Open

        function canWriteUserConfig(req, res, next) {
          const modules = req.body;
        
          const hasUnwritableConfig = modules.some(module => {
            if (!module || !Array.isArray(module.configurations)) {
        Severity: Minor
        Found in backend/webserver/middleware/configuration.js - About 35 mins 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 canWriteAdminConfig has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
        Open

        function canWriteAdminConfig(req, res, next) {
          const modules = req.body;
        
          const hasUnwritableConfig = modules.some(module => {
            if (!module || !Array.isArray(module.configurations)) {
        Severity: Minor
        Found in backend/webserver/middleware/configuration.js - About 25 mins 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 canWritePlatformConfig has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
        Open

        function canWritePlatformConfig(req, res, next) {
          const modules = req.body;
        
          const hasUnwritableConfig = modules.some(module => {
            if (!module || !Array.isArray(module.configurations)) {
        Severity: Minor
        Found in backend/webserver/middleware/configuration.js - About 25 mins 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

        function canWriteAdminConfig(req, res, next) {
          const modules = req.body;
        
          const hasUnwritableConfig = modules.some(module => {
            if (!module || !Array.isArray(module.configurations)) {
        Severity: Major
        Found in backend/webserver/middleware/configuration.js and 2 other locations - About 7 hrs to fix
        backend/webserver/middleware/configuration.js on lines 195..223
        backend/webserver/middleware/configuration.js on lines 303..331

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

        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

        function canWriteUserConfig(req, res, next) {
          const modules = req.body;
        
          const hasUnwritableConfig = modules.some(module => {
            if (!module || !Array.isArray(module.configurations)) {
        Severity: Major
        Found in backend/webserver/middleware/configuration.js and 2 other locations - About 7 hrs to fix
        backend/webserver/middleware/configuration.js on lines 249..277
        backend/webserver/middleware/configuration.js on lines 303..331

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

        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

        function canWritePlatformConfig(req, res, next) {
          const modules = req.body;
        
          const hasUnwritableConfig = modules.some(module => {
            if (!module || !Array.isArray(module.configurations)) {
        Severity: Major
        Found in backend/webserver/middleware/configuration.js and 2 other locations - About 7 hrs to fix
        backend/webserver/middleware/configuration.js on lines 195..223
        backend/webserver/middleware/configuration.js on lines 249..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 182.

        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

        function canReadAdminConfig(req, res, next) {
          const modules = req.body;
        
          const hasUnreadableConfig = modules.some(module => {
            if (!module || !Array.isArray(module.keys)) {
        Severity: Major
        Found in backend/webserver/middleware/configuration.js and 2 other locations - About 6 hrs to fix
        backend/webserver/middleware/configuration.js on lines 225..247
        backend/webserver/middleware/configuration.js on lines 333..355

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

        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

        function canReadPlatformConfig(req, res, next) {
          const modules = req.body;
        
          const hasUnreadableConfig = modules.some(module => {
            if (!module || !Array.isArray(module.keys)) {
        Severity: Major
        Found in backend/webserver/middleware/configuration.js and 2 other locations - About 6 hrs to fix
        backend/webserver/middleware/configuration.js on lines 225..247
        backend/webserver/middleware/configuration.js on lines 279..301

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

        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

        function canReadUserConfig(req, res, next) {
          const modules = req.body;
        
          const hasUnreadableConfig = modules.some(module => {
            if (!module || !Array.isArray(module.keys)) {
        Severity: Major
        Found in backend/webserver/middleware/configuration.js and 2 other locations - About 6 hrs to fix
        backend/webserver/middleware/configuration.js on lines 279..301
        backend/webserver/middleware/configuration.js on lines 333..355

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

        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 checkWritePermission(req, res, next) {
          const scope = req.query.scope;
          const middlewares = [];
        
          if (scope === SCOPE.platform) {
        Severity: Major
        Found in backend/webserver/middleware/configuration.js and 1 other location - About 4 hrs to fix
        backend/webserver/middleware/configuration.js on lines 70..83

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

        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 checkReadPermission(req, res, next) {
          const scope = req.query.scope;
          const middlewares = [];
        
          if (scope === SCOPE.platform) {
        Severity: Major
        Found in backend/webserver/middleware/configuration.js and 1 other location - About 4 hrs to fix
        backend/webserver/middleware/configuration.js on lines 85..98

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

        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 (invalidModules.length > 0) {
            return res.status(400).json({
              error: {
                code: 400,
                message: 'Bad Request',
        Severity: Major
        Found in backend/webserver/middleware/configuration.js and 1 other location - About 1 hr to fix
        backend/webserver/middleware/users.js on lines 123..131

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

        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

          return getDomainById(domainId)
            .then(domain => checkUserIsDomainAdministrator(req.user, domain))
            .then(isDomainAdministrator => {
              if (!isDomainAdministrator) {
                return res.status(403).json({
        Severity: Major
        Found in backend/webserver/middleware/configuration.js and 2 other locations - About 1 hr to fix
        backend/webserver/controllers/css.js on lines 15..30
        backend/webserver/middleware/domain.js on lines 333..359

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

        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

          } else if (scope === SCOPE.user) {
            req.query.user_id = req.query.user_id || req.user.id;
            req.query.domain_id = req.user.preferredDomainId;
          } else {
        Severity: Major
        Found in backend/webserver/middleware/configuration.js and 1 other location - About 1 hr to fix
        frontend/js/modules/maps.js on lines 73..76

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

        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

        module.exports = {
          qualifyScopeQueries,
          checkAuthorizedRole,
          checkReadPermission,
          checkWritePermission,
        Severity: Minor
        Found in backend/webserver/middleware/configuration.js and 2 other locations - About 35 mins to fix
        backend/core/db/redis/index.js on lines 7..15
        backend/webserver/controllers/usernotifications.js on lines 6..14

        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

        There are no issues that match your filters.

        Category
        Status