public inbox for [email protected]  
help / color / mirror / Atom feed
From: Pradip Parkale <[email protected]>
To: pgadmin-hackers <[email protected]>
Subject: [pgAdmin]:SonarQube fixes.
Date: Wed, 7 Apr 2021 16:53:49 +0530
Message-ID: <CAJ9T6SsDROcdX3bO3fOHSdF0F-46UHODR5we7s3Bk4SAhmxQ3Q@mail.gmail.com> (raw)

Hi Hackers,

Please find the attached patch for few SonaQube Fixes.

I have fixed the issues in the below files.

   1. foreign_key.js
   2. exclusion_constraint.js
   3. function.js


-- 
Thanks & Regards,
Pradip Parkale
Software Engineer | EnterpriseDB Corporation


Attachments:

  [application/octet-stream] SonarQube.patch (7.5K, 3-SonarQube.patch)
  download | inline diff:
diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/functions/static/js/function.js b/web/pgadmin/browser/server_groups/servers/databases/schemas/functions/static/js/function.js
index 9feea15ec..536dc9472 100644
--- a/web/pgadmin/browser/server_groups/servers/databases/schemas/functions/static/js/function.js
+++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/functions/static/js/function.js
@@ -91,8 +91,6 @@ define('pgadmin.node.function', [
       }
       return true;
     },
-    validate: function() {
-    },
   });
 
   if (!pgBrowser.Nodes['function']) {
diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/constraints/exclusion_constraint/static/js/exclusion_constraint.js b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/constraints/exclusion_constraint/static/js/exclusion_constraint.js
index 91579c07a..2ac92bf14 100644
--- a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/constraints/exclusion_constraint/static/js/exclusion_constraint.js
+++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/constraints/exclusion_constraint/static/js/exclusion_constraint.js
@@ -125,42 +125,14 @@ define('pgadmin.node.exclusion_constraint', [
         onText: 'ASC',
         offText: 'DESC',
       },
-      editable: function(m) {
-        if (m instanceof Backbone.Collection) {
-          return true;
-        } else if ((_.has(m.collection, 'handler') &&
-          !_.isUndefined(m.collection.handler) &&
-            !_.isUndefined(m.collection.handler.get('oid')))) {
-          return false;
-        } else if (m.top.get('amname') === 'btree') {
-          m.set('is_sort_nulls_applicable', true);
-          return true;
-        } else {
-          m.set('is_sort_nulls_applicable', false);
-          return false;
-        }
-      },
+      editable: 'isEditable',
     },{
       id: 'nulls_order', label: gettext('NULLs order'), type:'switch',
       options: {
         onText: 'FIRST',
         offText: 'LAST',
       },
-      editable: function(m) {
-        if (m instanceof Backbone.Collection) {
-          return true;
-        } else if ((_.has(m.collection, 'handler') &&
-          !_.isUndefined(m.collection.handler) &&
-            !_.isUndefined(m.collection.handler.get('oid')))) {
-          return false;
-        } else if (m.top.get('amname') === 'btree') {
-          m.set('is_sort_nulls_applicable', true);
-          return true;
-        } else {
-          m.set('is_sort_nulls_applicable', false);
-          return false;
-        }
-      },
+      editable: 'isEditable',
     },{
       id: 'operator', label: gettext('Operator'), type: 'text',
       node: 'table', url: 'get_operator',
@@ -220,6 +192,21 @@ define('pgadmin.node.exclusion_constraint', [
       }),
     },
     ],
+    isEditable: function(m) {
+      if (m instanceof Backbone.Collection) {
+        return true;
+      } else if ((_.has(m.collection, 'handler') &&
+        !_.isUndefined(m.collection.handler) &&
+        !_.isUndefined(m.collection.handler.get('oid')))) {
+        return false;
+      } else if (m.top.get('amname') === 'btree') {
+        m.set('is_sort_nulls_applicable', true);
+        return true;
+      } else {
+        m.set('is_sort_nulls_applicable', false);
+        return false;
+      }
+    },
     validate: function() {
       this.errorModel.clear();
       var operator = this.get('operator'),
@@ -775,22 +762,14 @@ define('pgadmin.node.exclusion_constraint', [
             },
           }),
           select2:{allowClear:true},
-          readonly: function(m) {
-            return ((_.has(m, 'handler') &&
-              !_.isUndefined(m.handler) &&
-                !_.isUndefined(m.get('oid'))) || (_.isFunction(m.isNew) && !m.isNew()));
-          },
+          readonly: 'isReadonly',
         },{
           id: 'fillfactor', label: gettext('Fill factor'),
           type: 'int', group: gettext('Definition'), allowNull: true,
         },{
           id: 'condeferrable', label: gettext('Deferrable?'),
           type: 'switch', group: gettext('Definition'), deps: ['index'],
-          readonly: function(m) {
-            return ((_.has(m, 'handler') &&
-              !_.isUndefined(m.handler) &&
-                !_.isUndefined(m.get('oid'))) || (_.isFunction(m.isNew) && !m.isNew()));
-          },
+          readonly: 'isReadonly',
         },{
           id: 'condeferred', label: gettext('Deferred?'),
           type: 'switch', group: gettext('Definition'),
@@ -817,11 +796,7 @@ define('pgadmin.node.exclusion_constraint', [
         },{
           id: 'indconstraint', label: gettext('Constraint'), cell: 'string',
           type: 'multiline', mode: ['create', 'edit', 'properties'], editable: false,
-          group: gettext('Definition'), readonly: function(m) {
-            return ((_.has(m, 'handler') &&
-              !_.isUndefined(m.handler) &&
-                !_.isUndefined(m.get('oid'))) || (_.isFunction(m.isNew) && !m.isNew()));
-          },
+          group: gettext('Definition'), readonly: 'isReadonly',
         },{
           id: 'columns', label: gettext('Columns/Expressions'),
           type: 'collection', group: gettext('Columns'),
@@ -834,11 +809,7 @@ define('pgadmin.node.exclusion_constraint', [
           },
           control: ExclusionConstraintColumnControl,
           model: ExclusionConstraintColumnModel,
-          readonly: function(m) {
-            return ((_.has(m, 'handler') &&
-              !_.isUndefined(m.handler) &&
-                !_.isUndefined(m.get('oid'))) || (_.isFunction(m.isNew) && !m.isNew()));
-          },
+          readonly: 'isReadonly',
           cell: Backgrid.StringCell.extend({
             initialize: function() {
               Backgrid.StringCell.prototype.initialize.apply(this, arguments);
@@ -1041,6 +1012,11 @@ define('pgadmin.node.exclusion_constraint', [
             return !m.isNew();
           },
         }],
+        isReadonly: function(m) {
+          return ((_.has(m, 'handler') &&
+              !_.isUndefined(m.handler) &&
+              !_.isUndefined(m.get('oid'))) || (_.isFunction(m.isNew) && !m.isNew()));
+        },
         validate: function() {
           this.errorModel.clear();
           var columns = this.get('columns'),
diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/constraints/foreign_key/static/js/foreign_key.js b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/constraints/foreign_key/static/js/foreign_key.js
index 6819025a5..e8d04e336 100644
--- a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/constraints/foreign_key/static/js/foreign_key.js
+++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/constraints/foreign_key/static/js/foreign_key.js
@@ -505,8 +505,6 @@ define('pgadmin.node.foreign_key', [
 
             newRow.addClass('new');
             $(newRow).pgMakeVisible('backform-tab');
-          } else {
-            //delete m;
           }
         }
         return false;
@@ -1083,6 +1081,15 @@ define('pgadmin.node.foreign_key', [
           },
         },
         ],
+        isReadonly:function(m) {
+          // If we are in table edit mode then
+          if (_.has(m, 'handler') && !_.isUndefined(m.handler)) {
+            // If OID is undefined then user is trying to add
+            // new constraint which should allowed for Unique
+            return !_.isUndefined(m.get('oid'));
+          }
+          return !m.isNew();
+        },
         validate: function() {
           var columns = this.get('columns'),
             msg;


view thread (11+ messages)  latest in thread

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: [email protected]
  Cc: [email protected]
  Subject: Re: [pgAdmin]:SonarQube fixes.
  In-Reply-To: <CAJ9T6SsDROcdX3bO3fOHSdF0F-46UHODR5we7s3Bk4SAhmxQ3Q@mail.gmail.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox