linagora/openpaas-esn

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

Summary

Maintainability
F
1 wk
Test Coverage

File users.js has 381 lines of code (exceeds 250 allowed). Consider refactoring.
Open

const { promisify } = require('util');
const Q = require('q');
const userModule = require('../../core').user;
const imageModule = require('../../core').image;
const logger = require('../../core').logger;
Severity: Minor
Found in backend/webserver/controllers/users.js - About 5 hrs to fix

    Function updateTargetUserAvatar has 48 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

    function updateTargetUserAvatar(req, res) {
      // assign our domain object to "domain" property of request object (by load domain middleware)
      // causes error "domain.enter is not a function" when process data stream (imageModule.recordAvatar function) on nodejs 8.
      // The reason is request object is an instance of EventEmitter that uses domain module to handle IO errors.
      // However, the domain module is deprecated (https://nodejs.org/api/domain.html)
    Severity: Minor
    Found in backend/webserver/controllers/users.js - About 1 hr to fix

      Function postProfileAvatar has 47 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

      function postProfileAvatar(req, res) {
        const avatarId = new ObjectId();
      
        Q.denodeify(imageModule.recordAvatar)(
          avatarId,
      Severity: Minor
      Found in backend/webserver/controllers/users.js - About 1 hr to fix

        Function getProfilesByQuery has 31 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

        function getProfilesByQuery(req, res) {
          let getUsers;
          let errorMessage;
        
          if (req.query.email) {
        Severity: Minor
        Found in backend/webserver/controllers/users.js - About 1 hr to fix

          Function profile has 28 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

          function profile(req, res) {
            var uuid = req.params.uuid;
            const denormalizeOptions = {
              includeIsFollowing: true,
              includeFollow: true,
          Severity: Minor
          Found in backend/webserver/controllers/users.js - About 1 hr to fix

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

              Q.denodeify(imageModule.recordAvatar)(
                avatarId,
                req.query.mimetype.toLowerCase(),
                {
                  creator: {
            Severity: Major
            Found in backend/webserver/controllers/users.js and 1 other location - About 2 days to fix
            backend/webserver/controllers/users.js on lines 149..201

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

            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

              Q.denodeify(imageModule.recordAvatar)(
                avatarId,
                req.query.mimetype.toLowerCase(),
                {
                  creator: {
            Severity: Major
            Found in backend/webserver/controllers/users.js and 1 other location - About 2 days to fix
            backend/webserver/controllers/users.js on lines 303..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 373.

            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

              Q.ninvoke(imageModule, 'getAvatar', req.user.currentAvatar, req.query.format)
                .spread((fileStoreMeta, readable) => {
                  if (!readable) {
                    logger.warn('Can not retrieve avatar stream for user %s', req.user._id);
            
            
            Severity: Major
            Found in backend/webserver/controllers/users.js and 1 other location - About 1 day to fix
            backend/webserver/controllers/users.js on lines 404..427

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

            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

              Q.ninvoke(imageModule, 'getAvatar', req.targetUser.currentAvatar, req.query.format)
                .spread((fileStoreMeta, readable) => {
                  if (!readable) {
                    logger.warn('Can not retrieve avatar stream for user %s', req.targetUser._id);
            
            
            Severity: Major
            Found in backend/webserver/controllers/users.js and 1 other location - About 1 day to fix
            backend/webserver/controllers/users.js on lines 367..390

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

            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

              userModule.updateStates(req.params.uuid, req.body, err => {
                if (err) {
                  const details = 'Error while updating user states';
            
                  logger.error(details, err);
            Severity: Major
            Found in backend/webserver/controllers/users.js and 1 other location - About 2 hrs to fix
            backend/webserver/controllers/users.js on lines 483..499

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

            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

              userModule.update(targetUser, err => {
                if (err) {
                  const details = 'Error while updating user emails';
            
                  logger.error(details, err);
            Severity: Major
            Found in backend/webserver/controllers/users.js and 1 other location - About 2 hrs to fix
            backend/webserver/controllers/users.js on lines 456..472

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

            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 provider.provision({ data: req.body, domainId: req.domain._id })
                .then(provisionedUsers => Promise.all(provisionedUsers.map(user => denormalizeUser(user))))
                .then(denormalizedUsers => res.status(201).json(denormalizedUsers))
                .catch(error => {
                  const details = `Error while provisioning users from ${source}`;
            Severity: Major
            Found in backend/webserver/controllers/users.js and 1 other location - About 2 hrs to fix
            backend/webserver/controllers/domains.js on lines 83..97

            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

            module.exports = {
              getProfileAvatar,
              getTargetUserAvatar,
              getProfilesByQuery,
              logmein,
            Severity: Major
            Found in backend/webserver/controllers/users.js and 1 other location - About 1 hr to fix
            frontend/js/modules/box-overlay/box-overlay-manager.service.js on lines 10..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 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

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

              userModule.updatePassword(req.user, req.body.password, function(err) {
                if (err) {
                  return res.status(500).json({error: 500, message: 'Server Error', details: err.message});
                }
            
            
            Severity: Major
            Found in backend/webserver/controllers/users.js and 1 other location - About 1 hr to fix
            backend/webserver/controllers/passwordreset.js on lines 43..49

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

            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

              if (!req.body && !req.body.password) {
                return res.status(400).json({error: 400, message: 'Bad Request', details: 'No password defined'});
              }
            Severity: Major
            Found in backend/webserver/controllers/users.js and 2 other locations - About 1 hr to fix
            backend/webserver/controllers/passwordreset.js on lines 35..37
            backend/webserver/middleware/collaboration.js on lines 48..50

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

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

              if (!req.user) {
                return res.status(404).json({error: 404, message: 'Not found', details: 'User not found'});
              }
            Severity: Major
            Found in backend/webserver/controllers/users.js and 8 other locations - About 40 mins to fix
            backend/webserver/controllers/collaborations.js on lines 434..436
            backend/webserver/controllers/users.js on lines 359..361
            backend/webserver/middleware/collaboration.js on lines 40..42
            backend/webserver/middleware/collaboration.js on lines 44..46
            backend/webserver/middleware/collaboration.js on lines 110..112
            backend/webserver/middleware/collaboration.js on lines 132..134
            backend/webserver/middleware/collaboration.js on lines 136..138
            backend/webserver/middleware/request.js on lines 32..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 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 9 locations. Consider refactoring.
            Open

              if (!req.user) {
                return res.status(404).json({error: 404, message: 'Not found', details: 'User not found'});
              }
            Severity: Major
            Found in backend/webserver/controllers/users.js and 8 other locations - About 40 mins to fix
            backend/webserver/controllers/collaborations.js on lines 434..436
            backend/webserver/controllers/users.js on lines 287..289
            backend/webserver/middleware/collaboration.js on lines 40..42
            backend/webserver/middleware/collaboration.js on lines 44..46
            backend/webserver/middleware/collaboration.js on lines 110..112
            backend/webserver/middleware/collaboration.js on lines 132..134
            backend/webserver/middleware/collaboration.js on lines 136..138
            backend/webserver/middleware/request.js on lines 32..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 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

            There are no issues that match your filters.

            Category
            Status