bcgov/common-object-management-service

View on GitHub

Showing 363 of 363 total issues

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

  fetchMetadataForObject: (params) => {
    return ObjectModel.query()
      .select('object.id AS objectId', 'object.bucketId as bucketId')
      .allowGraph('[bucketPermission, objectPermission, version.metadata]')
      .withGraphJoined('version.metadata')
Severity: Minor
Found in app/src/services/metadata.js - About 1 hr to fix

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

      fetchTagsForObject: (params) => {
        return ObjectModel.query()
          .select('object.id AS objectId', 'object.bucketId as bucketId')
          .allowGraph('[bucketPermission, objectPermission, version.tag]')
          .withGraphJoined('version.tag')
    Severity: Minor
    Found in app/src/services/tag.js - About 1 hr to fix

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

        async searchPermissions(req, res, next) {
          try {
            const bucketIds = utils.mixedQueryToArray(req.query.bucketId);
            const objIds = utils.mixedQueryToArray(req.query.objectId);
            const permCodes = utils.mixedQueryToArray(req.query.permCode);
      Severity: Minor
      Found in app/src/controllers/objectPermission.js - About 1 hr to fix

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

          async getBucket(bucketId = undefined) {
            try {
              const data = { region: DEFAULTREGION };
              if (bucketId) {
                // Function scoped import to avoid circular dependencies
        Severity: Minor
        Found in app/src/components/utils.js - About 1 hr to fix

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

            checkGrantPermissions: 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 initializeConnections has 28 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

            function initializeConnections() {
              // Initialize connections and exit if unsuccessful
              dataConnection.checkAll()
                .then(results => {
                  state.connections.data = results;
            Severity: Minor
            Found in app/app.js - About 1 hr to fix

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

                    const newTags = Object.entries({ ...req.query.tagset }).map(([k, v]) => ({ Key: k, Value: v }));
              Severity: Major
              Found in app/src/controllers/object.js and 1 other location - About 1 hr to fix
              app/src/controllers/object.js on lines 890..890

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

              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

                    const newTags = Object.entries({ ...req.query.tagset }).map(([k, v]) => ({ Key: k, Value: v }));
              Severity: Major
              Found in app/src/controllers/object.js and 1 other location - About 1 hr to fix
              app/src/controllers/object.js on lines 194..194

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

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

                static get modifiers() {
                  return {
                    filterKey(query, value) {
                      const subqueries = [];
                      if (value.metadata && Object.keys(value.metadata).length) {
              Severity: Minor
              Found in app/src/db/models/tables/metadata.js - About 1 hr 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 syncJob has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
              Open

                syncJob: async (path, bucketId, full = false, userId = SYSTEM_USER) => {
                  try {
                    if (!path) throw new Error('Path must be defined');
              
                    return await utils.trxWrapper(async (trx) => {
              Severity: Minor
              Found in app/src/services/sync.js - About 1 hr 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 replaceTags has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
              Open

                replaceTags: async (versionId, tags, currentUserId = SYSTEM_USER, etrx = undefined) => {
                  let trx;
                  try {
                    trx = etrx ? etrx : await Tag.startTransaction();
                    let response = [];
              Severity: Minor
              Found in app/src/services/tag.js - About 1 hr 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 addPermissions has a Cognitive Complexity of 10 (exceeds 5 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

              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 addPermissions has a Cognitive Complexity of 10 (exceeds 5 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

              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 10 (exceeds 5 allowed). Consider refactoring.
              Open

                static get modifiers() {
                  return {
                    filterKey(query, value) {
                      const subqueries = [];
                      if (value.tag && Object.keys(value.tag).length) {
              Severity: Minor
              Found in app/src/db/models/tables/tag.js - About 1 hr 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 updateIsLatest has 27 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                updateIsLatest: async (objectId, etrx = undefined) => {
                  // TODO: consider having accepting a `userId` argument for version.updatedBy when a version becomes 'latest'
                  let trx;
                  try {
                    trx = etrx ? etrx : await Version.startTransaction();
              Severity: Minor
              Found in app/src/services/version.js - About 1 hr to fix

                Function associateTags has 27 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

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

                  Function errorToProblem has 27 lines of code (exceeds 25 allowed). Consider refactoring.
                  Open

                  function errorToProblem(service, e) {
                    // If already problem type, just return as is
                    if (e instanceof Problem) {
                      return e;
                    } else if (e.response) {
                  Severity: Minor
                  Found in app/src/components/errorToProblem.js - About 1 hr to fix

                    Function _processS3Headers has 27 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/object.js - About 1 hr to fix

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

                      exports.down = function (knex) {
                        return Promise.resolve()
                          // additional DB update: change user.identityId field back
                          // NOTE: Destructive change - removes all data in identityId column
                          .then(() => knex('user').update({ identityId: null }))
                      Severity: Minor
                      Found in app/src/db/migrations/20220627000000_002-metadata-tags.js - About 1 hr to fix

                        Function listAllObjectVersions has 26 lines of code (exceeds 25 allowed). Consider refactoring.
                        Open

                          async listAllObjectVersions({
                            filePath = undefined, bucketId = undefined, precisePath = true, filterLatest = false
                          } = {}) {
                            const key = filePath ?? (await utils.getBucket(bucketId)).key;
                            const path = key !== DELIMITER ? key : '';
                        Severity: Minor
                        Found in app/src/services/storage.js - About 1 hr to fix
                          Severity
                          Category
                          Status
                          Source
                          Language