bcgov/common-object-management-service

View on GitHub

Showing 363 of 363 total issues

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

  static get relationMappings() {
    const Bucket = require('./bucket');
    const Permission = require('./permission');
    const User = require('./user');

Severity: Major
Found in app/src/db/models/tables/bucketPermission.js and 1 other location - About 4 hrs to fix
app/src/db/models/tables/objectPermission.js on lines 13..44

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

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

  static get relationMappings() {
    const ObjectModel = require('./objectModel');
    const Permission = require('./permission');
    const User = require('./user');

Severity: Major
Found in app/src/db/models/tables/objectPermission.js and 1 other location - About 4 hrs to fix
app/src/db/models/tables/bucketPermission.js on lines 13..44

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

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 createObject has 110 lines of code (exceeds 25 allowed). Consider refactoring.
Open

  async createObject(req, res, next) {
    try {
      const userId = await userService.getCurrentUserId(getCurrentIdentity(req.currentUser, SYSTEM_USER));

      // Preflight CREATE permission check if bucket scoped and OIDC authenticated
Severity: Major
Found in app/src/controllers/object.js - About 4 hrs to fix

    Function syncVersions has 109 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

      syncVersions: async (object, userId = SYSTEM_USER, etrx = undefined) => {
        let trx;
        try {
          trx = etrx ? etrx : await Version.startTransaction();
    
    
    Severity: Major
    Found in app/src/services/sync.js - About 4 hrs to fix

      Function modifiers has 107 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

        static get modifiers() {
          const Version = require('./version');
      
          return {
            filterIds(query, value) {
      Severity: Major
      Found in app/src/db/models/tables/objectModel.js - About 4 hrs to fix

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

        const { NIL: SYSTEM_USER, v4: uuidv4, validate: uuidValidate } = require('uuid');
        
        const log = require('../components/log')(module.filename);
        const utils = require('../db/models/utils');
        
        
        Severity: Minor
        Found in app/src/services/sync.js - About 4 hrs to fix

          Function updateObject has a Cognitive Complexity of 28 (exceeds 5 allowed). Consider refactoring.
          Open

            async updateObject(req, res, next) {
              try {
                const userId = await userService.getCurrentUserId(getCurrentIdentity(req.currentUser, SYSTEM_USER));
          
                // Preflight existence check for bucketId
          Severity: Minor
          Found in app/src/controllers/object.js - About 4 hrs 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 2 locations. Consider refactoring.
          Open

          exports.down = function (knex) {
            return Promise.resolve()
              .then(() => knex('metadata')
                .where({ key: 'coms-id' })
                .update({ key: 'id' })
          Severity: Major
          Found in app/src/db/migrations/20230427000000_006-metadata-fix.js and 1 other location - About 3 hrs to fix
          app/src/db/migrations/20230427000000_006-metadata-fix.js on lines 1..11

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

          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

            static get jsonSchema() {
              return {
                type: 'object',
                required: ['id', 'userId', 'bucketId', 'permCode'],
                properties: {
          Severity: Major
          Found in app/src/db/models/tables/bucketPermission.js and 1 other location - About 3 hrs to fix
          app/src/db/models/tables/objectPermission.js on lines 68..81

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

          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

            searchTags: (params) => {
              return Tag.query()
                .modify((query) => {
                  if (params.privacyMask) {
                    query
          Severity: Major
          Found in app/src/services/tag.js and 1 other location - About 3 hrs to fix
          app/src/services/metadata.js on lines 310..324

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

          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

            static get jsonSchema() {
              return {
                type: 'object',
                required: ['id', 'userId', 'objectId', 'permCode'],
                properties: {
          Severity: Major
          Found in app/src/db/models/tables/objectPermission.js and 1 other location - About 3 hrs to fix
          app/src/db/models/tables/bucketPermission.js on lines 60..73

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

          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

            searchMetadata: (params) => {
              return Metadata.query()
                .modify((query) => {
                  if (params.privacyMask) {
                    query
          Severity: Major
          Found in app/src/services/metadata.js and 1 other location - About 3 hrs to fix
          app/src/services/tag.js on lines 330..344

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

          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

          exports.up = function (knex) {
            return Promise.resolve()
              .then(() => knex('metadata')
                .where({ key: 'id' })
                .update({ key: 'coms-id' })
          Severity: Major
          Found in app/src/db/migrations/20230427000000_006-metadata-fix.js and 1 other location - About 3 hrs to fix
          app/src/db/migrations/20230427000000_006-metadata-fix.js on lines 13..23

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

          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 currentUser has a Cognitive Complexity of 26 (exceeds 5 allowed). Consider refactoring.
          Open

          const currentUser = async (req, res, next) => {
            const authorization = req.get('Authorization');
            const currentUser = {
              authType: AuthType.NONE
            };
          Severity: Minor
          Found in app/src/middleware/authentication.js - About 3 hrs 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 createInvite has 91 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

            async createInvite(req, res, next) {
              let resource, type;
          
              try {
                // Reject if expiresAt is more than 30 days away
          Severity: Major
          Found in app/src/controllers/invite.js - About 3 hrs to fix

            File storage.js has 317 lines of code (exceeds 250 allowed). Consider refactoring.
            Open

            const {
              CopyObjectCommand,
              DeleteObjectCommand,
              DeleteObjectTaggingCommand,
              GetBucketEncryptionCommand,
            Severity: Minor
            Found in app/src/services/storage.js - About 3 hrs to fix

              Function createObject has a Cognitive Complexity of 25 (exceeds 5 allowed). Consider refactoring.
              Open

                async createObject(req, res, next) {
                  try {
                    const userId = await userService.getCurrentUserId(getCurrentIdentity(req.currentUser, SYSTEM_USER));
              
                    // Preflight CREATE permission check if bucket scoped and OIDC authenticated
              Severity: Minor
              Found in app/src/controllers/object.js - About 3 hrs 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 modifiers has a Cognitive Complexity of 24 (exceeds 5 allowed). Consider refactoring.
              Open

                static get modifiers() {
                  const Version = require('./version');
              
                  return {
                    filterIds(query, value) {
              Severity: Minor
              Found in app/src/db/models/tables/objectModel.js - About 3 hrs 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 6 locations. Consider refactoring.
              Open

                async deleteObject({ filePath, s3VersionId = undefined, bucketId = undefined }) {
                  const data = await utils.getBucket(bucketId);
                  const params = {
                    Bucket: data.bucket,
                    Key: filePath,
              Severity: Major
              Found in app/src/services/storage.js and 5 other locations - About 3 hrs to fix
              app/src/services/storage.js on lines 136..145
              app/src/services/storage.js on lines 186..194
              app/src/services/storage.js on lines 219..228
              app/src/services/storage.js on lines 263..271
              app/src/services/storage.js on lines 532..541

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

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

                async getObjectTagging({ filePath, s3VersionId = undefined, bucketId = undefined }) {
                  const data = await utils.getBucket(bucketId);
                  const params = {
                    Bucket: data.bucket,
                    Key: filePath,
              Severity: Major
              Found in app/src/services/storage.js and 5 other locations - About 3 hrs to fix
              app/src/services/storage.js on lines 117..126
              app/src/services/storage.js on lines 136..145
              app/src/services/storage.js on lines 186..194
              app/src/services/storage.js on lines 263..271
              app/src/services/storage.js on lines 532..541

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

              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

              Severity
              Category
              Status
              Source
              Language