bcgov/common-object-management-service

View on GitHub

Showing 363 of 363 total issues

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

exports.up = function (knex) {
  return Promise.resolve()
    .then(() => knex.schema.alterTable('bucket', table => {
      table.timestamp('updatedAt', { useTz: true }).alter();
    }))
Severity: Minor
Found in app/src/db/migrations/20230503000000_007-default-updatedat.js - About 1 hr to fix

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

      async searchObjects(req, res, next) {
        // TODO: Consider support for filtering by set of permissions?
        // TODO: handle additional parameters. Eg: deleteMarker, latest
        try {
          const bucketIds = mixedQueryToArray(req.query.bucketId);
    Severity: Minor
    Found in app/src/controllers/object.js - About 1 hr to fix

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

        addPermissions: async (objId, data, currentUserId = SYSTEM_USER, etrx = undefined) => {
          if (!objId) {
            throw new Error('Invalid objId supplied');
          }
          if (!data || !Array.isArray(data) || !data.length) {
      Severity: Minor
      Found in app/src/services/objectPermission.js - About 1 hr to fix

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

          addPermissions: async (bucketId, data, currentUserId = SYSTEM_USER, etrx = undefined) => {
            if (!bucketId) {
              throw new Error('Invalid bucketId supplied');
            }
            if (!data || !Array.isArray(data) || !data.length) {
        Severity: Minor
        Found in app/src/services/bucketPermission.js - About 1 hr to fix

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

          exports.down = function (knex) {
            return Promise.resolve()
              .then(() => knex.schema.alterTable('version_tag', table => {
                table.timestamp('updatedAt', { useTz: true }).defaultTo(knex.fn.now()).alter();
              }))
          Severity: Minor
          Found in app/src/db/migrations/20230503000000_007-default-updatedat.js - About 1 hr to fix

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

                  const dbResponse = await utils.trxWrapper(async (trx) => {
                    // Update Object
                    const object = await objectService.update({
                      ...data,
                      userId: userId,
            Severity: Minor
            Found in app/src/controllers/object.js - About 1 hr to fix

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

              router.patch('/:bucketId', express.json(), bucketValidator.updateBucket, hasPermission(Permissions.MANAGE),
                (req, res, next) => {
                  bucketController.updateBucket(req, res, next);
                }
              );
              Severity: Major
              Found in app/src/routes/v1/bucket.js and 1 other location - About 1 hr to fix
              app/src/routes/v1/bucket.js on lines 50..54

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

              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

              Function createMetadata has 30 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                createMetadata: async (metadata, etrx = undefined) => {
                  let trx;
                  let response = [];
                  try {
                    trx = etrx ? etrx : await Metadata.startTransaction();
              Severity: Minor
              Found in app/src/services/metadata.js - About 1 hr to fix

                Function up has 30 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

                exports.up = function (knex) {
                  return Promise.resolve()
                    // create version table
                    .then(() => knex.schema.createTable('version', table => {
                      table.uuid('id').primary();
                Severity: Minor
                Found in app/src/db/migrations/20220516000000_001-version.js - About 1 hr to fix

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

                  router.put('/:bucketId/child', express.json(), bucketValidator.createBucketChild, hasPermission(Permissions.MANAGE),
                    (req, res, next) => {
                      bucketController.createBucketChild(req, res, next);
                    }
                  );
                  Severity: Major
                  Found in app/src/routes/v1/bucket.js and 1 other location - About 1 hr to fix
                  app/src/routes/v1/bucket.js on lines 38..42

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

                  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

                  Function createTags has 30 lines of code (exceeds 25 allowed). Consider refactoring.
                  Open

                    createTags: async (tags, etrx = undefined) => {
                      let trx;
                      let response = [];
                      try {
                        trx = etrx ? etrx : await Tag.startTransaction();
                  Severity: Minor
                  Found in app/src/services/tag.js - About 1 hr to fix

                    Function updateUser has 30 lines of code (exceeds 25 allowed). Consider refactoring.
                    Open

                      updateUser: async (userId, data, etrx = undefined) => {
                        let trx;
                        try {
                          // Check if any user values have changed
                          const oldUser = await service.readUser(userId);
                    Severity: Minor
                    Found in app/src/services/user.js - About 1 hr to fix

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

                            filterMetadataTag(query, value) {
                              const subqueries = [];
                      
                              if (value.metadata && Object.keys(value.metadata).length) {
                                Object.entries(value.metadata).forEach(([key, val]) => {
                      Severity: Minor
                      Found in app/src/db/models/tables/objectModel.js - About 1 hr to fix

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

                          create: async (data, etrx = undefined) => {
                            let trx;
                            try {
                              trx = etrx ? etrx : await Bucket.startTransaction();
                        
                        
                        Severity: Minor
                        Found in app/src/services/bucket.js - About 1 hr to fix

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

                            static get relationMappings() {
                              const ObjectModel = require('./objectModel');
                              const Permission = require('./permission');
                              const User = require('./user');
                          
                          
                          Severity: Minor
                          Found in app/src/db/models/tables/objectPermission.js - About 1 hr to fix

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

                              static get relationMappings() {
                                const Bucket = require('./bucket');
                                const Permission = require('./permission');
                                const User = require('./user');
                            
                            
                            Severity: Minor
                            Found in app/src/db/models/tables/bucketPermission.js - About 1 hr to fix

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

                              process.on('unhandledRejection', err => {
                                log.error(`Unhandled Rejection: ${err.message ?? err}`, { function: 'onUnhandledRejection' });
                                fatalErrorHandler();
                              });
                              Severity: Major
                              Found in app/app.js and 1 other location - About 1 hr to fix
                              app/app.js on lines 133..136

                              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

                              process.on('uncaughtException', err => {
                                log.error(`Unhandled Exception: ${err.message ?? err}`, { function: 'onUncaughtException' });
                                fatalErrorHandler();
                              });
                              Severity: Major
                              Found in app/app.js and 1 other location - About 1 hr to fix
                              app/app.js on lines 129..132

                              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

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

                              const hasPermission = (permission) => {
                                return async (req, _res, next) => {
                                  const authMode = getAppAuthMode();
                                  const authType = req.currentUser ? req.currentUser.authType : undefined;
                              
                              
                              Severity: Minor
                              Found in app/src/middleware/authorization.js - About 1 hr to fix

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

                                  _processS3Headers(s3Resp, res) {
                                    // TODO: Consider adding 'x-coms-public' and 'x-coms-path' headers into API spec?
                                    const exposedHeaders = [];
                                
                                    if (s3Resp.ContentLength) res.set('Content-Length', s3Resp.ContentLength);
                                Severity: Minor
                                Found in app/src/controllers/bucket.js - About 1 hr to fix
                                  Severity
                                  Category
                                  Status
                                  Source
                                  Language