From 1013d7ccdd3431d354fa0a23b987a13a919d8ad0 Mon Sep 17 00:00:00 2001 From: Akshay Joshi Date: Thu, 20 Jan 2022 16:58:21 +0530 Subject: [PATCH] Fixed code smell reported by SonarQube. --- web/pgadmin/authenticate/ldap.py | 13 ++++++------ .../browser/server_groups/servers/__init__.py | 8 +++---- .../languages/static/js/language.ui.js | 7 ++----- .../schemas/synonyms/static/js/synonym.ui.js | 6 +----- .../tables/columns/static/js/column.ui.js | 4 ++-- .../static/js/exclusion_constraint.ui.js | 6 +----- .../foreign_key/static/js/foreign_key.ui.js | 12 ++--------- .../tables/indexes/static/js/index.ui.js | 5 ++--- .../tables/static/js/partition.utils.ui.js | 6 ++++-- .../servers/databases/schemas/tables/utils.py | 8 +++---- .../schemas/types/static/js/type.ui.js | 4 +--- .../servers/static/js/server.ui.js | 2 +- web/pgadmin/browser/static/js/layout.js | 4 +--- web/pgadmin/browser/static/js/panel.js | 3 --- web/pgadmin/model/__init__.py | 7 ++++--- .../static/js/SchemaView/MappedControl.jsx | 4 ++-- web/pgadmin/static/js/SchemaView/index.jsx | 8 ++----- web/pgadmin/static/js/backform.pgadmin.js | 3 +-- web/pgadmin/static/js/backgrid.pgadmin.js | 5 +++-- web/pgadmin/static/js/csrf.js | 2 +- web/pgadmin/static/js/dialog_tab_navigator.js | 3 +-- web/pgadmin/static/js/helpers/Notifier.jsx | 2 +- web/pgadmin/static/js/tree/tree_init.tsx | 16 +++++++------- web/pgadmin/static/js/tree/tree_nodes.ts | 12 +++++------ .../static/scss/_jsoneditor.overrides.scss | 2 +- .../static/scss/_webcabin.pgadmin.scss | 3 --- .../static/vendor/backform/backform.js | 6 +++--- .../tools/backup/static/js/backup.ui.js | 2 +- .../tools/erd/static/js/erd_tool/ERDCore.js | 3 +-- .../grant_wizard/static/js/GrantWizard.jsx | 6 +----- .../static/js/ImportExportServers.jsx | 7 +------ .../tools/restore/static/js/restore.ui.js | 2 +- .../utils/driver/psycopg2/connection.py | 21 +++++++++---------- .../javascript/dashboard/graphs_spec.js | 5 ++--- .../schema_ui_files/domain.ui.spec.js | 3 +-- .../schema_ui_files/pga_schedule.ui.spec.js | 3 +-- .../search_objects_dialog_wrapper_spec.js | 2 +- .../table/enable_disable_triggers_spec.js | 8 ++----- web/regression/javascript/tree/tree_spec.js | 8 ++----- 39 files changed, 90 insertions(+), 141 deletions(-) diff --git a/web/pgadmin/authenticate/ldap.py b/web/pgadmin/authenticate/ldap.py index d53fb46ac..1d2c14e88 100644 --- a/web/pgadmin/authenticate/ldap.py +++ b/web/pgadmin/authenticate/ldap.py @@ -29,6 +29,9 @@ from pgadmin.utils.constants import LDAP ERROR_SEARCHING_LDAP_DIRECTORY = gettext( "Error searching the LDAP directory: {}") +ERROR_CONNECTING_LDAP_SERVER = gettext( + "Error connecting to the LDAP server: {}\n") + class LDAPAuthentication(BaseAuthentication): """Ldap Authentication Class""" @@ -122,18 +125,16 @@ class LDAPAuthentication(BaseAuthentication): except LDAPSocketOpenError as e: current_app.logger.exception( - "Error connecting to the LDAP server: {}\n".format(e)) - return False, gettext("Error connecting to the LDAP server: {}\n" - ).format(e.args[0]) + ERROR_CONNECTING_LDAP_SERVER.format(e)) + return False, ERROR_CONNECTING_LDAP_SERVER.format(e.args[0]) except LDAPBindError as e: current_app.logger.exception( "Error binding to the LDAP server.") return False, gettext("Error binding to the LDAP server.") except Exception as e: current_app.logger.exception( - "Error connecting to the LDAP server: {}\n".format(e)) - return False, gettext("Error connecting to the LDAP server: {}\n" - ).format(e.args[0]) + ERROR_CONNECTING_LDAP_SERVER.format(e)) + return False, ERROR_CONNECTING_LDAP_SERVER.format(e.args[0]) # Enable TLS if STARTTLS is configured if self.start_tls: diff --git a/web/pgadmin/browser/server_groups/servers/__init__.py b/web/pgadmin/browser/server_groups/servers/__init__.py index a1d184b73..392c81ae8 100644 --- a/web/pgadmin/browser/server_groups/servers/__init__.py +++ b/web/pgadmin/browser/server_groups/servers/__init__.py @@ -1512,10 +1512,10 @@ class ServerNode(PGChildNodeView): # Check if any psql terminal is running for the current disconnecting # server. If any terminate the psql tool connection. if 'sid_soid_mapping' in current_app.config and str(sid) in \ - current_app.config['sid_soid_mapping']: - if str(sid) in current_app.config['sid_soid_mapping']: - for i in current_app.config['sid_soid_mapping'][str(sid)]: - sio.emit('disconnect-psql', namespace='/pty', to=i) + current_app.config['sid_soid_mapping'] and \ + str(sid) in current_app.config['sid_soid_mapping']: + for i in current_app.config['sid_soid_mapping'][str(sid)]: + sio.emit('disconnect-psql', namespace='/pty', to=i) status = manager.release() diff --git a/web/pgadmin/browser/server_groups/servers/databases/languages/static/js/language.ui.js b/web/pgadmin/browser/server_groups/servers/databases/languages/static/js/language.ui.js index 1ce85de1c..54fea1060 100644 --- a/web/pgadmin/browser/server_groups/servers/databases/languages/static/js/language.ui.js +++ b/web/pgadmin/browser/server_groups/servers/databases/languages/static/js/language.ui.js @@ -38,13 +38,10 @@ export default class LanguageSchema extends BaseUISchema { } // This function check whether the server is less than 13 or not. isLessThan13(){ - if(!_.isUndefined(this.node_info) + return !_.isUndefined(this.node_info) && !_.isUndefined(this.node_info['node_info']) && !_.isUndefined(this.node_info['node_info'].version) - && this.node_info['node_info'].version < 130000) - { return true; } - else{ return false; } - + && this.node_info['node_info'].version < 130000; } isDisabled(state){ if (this.templateList.some(template => template.tmplname === state.name)){ diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/synonyms/static/js/synonym.ui.js b/web/pgadmin/browser/server_groups/servers/databases/schemas/synonyms/static/js/synonym.ui.js index e2502acf3..f3f4955a4 100644 --- a/web/pgadmin/browser/server_groups/servers/databases/schemas/synonyms/static/js/synonym.ui.js +++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/synonyms/static/js/synonym.ui.js @@ -70,11 +70,7 @@ export default class SynonymSchema extends BaseUISchema { readonly: function(state) { // If tagetType is synonym then disable it if(!obj.inCatalog()) { - if(state.targettype == 's') { - return true; - } else { - return false; - } + return state.targettype == 's'; } return true; }, diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/columns/static/js/column.ui.js b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/columns/static/js/column.ui.js index f57d540f0..95d16a7c7 100644 --- a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/columns/static/js/column.ui.js +++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/columns/static/js/column.ui.js @@ -196,12 +196,12 @@ export default class ColumnSchema extends BaseUISchema { editable: function(state) { // If primary key already exist then disable. if ( - obj.top && (( + obj.top && ( !_.isUndefined(obj.top.origData['oid']) && !_.isUndefined(obj.top.origData['primary_key']) && obj.top.origData['primary_key'].length > 0 && !_.isUndefined(obj.top.origData['primary_key'][0]['oid']) - )) + ) ) { return false; } diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/constraints/exclusion_constraint/static/js/exclusion_constraint.ui.js b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/constraints/exclusion_constraint/static/js/exclusion_constraint.ui.js index e6ce63136..7c718fda3 100644 --- a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/constraints/exclusion_constraint/static/js/exclusion_constraint.ui.js +++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/constraints/exclusion_constraint/static/js/exclusion_constraint.ui.js @@ -325,11 +325,7 @@ export default class ExclusionConstraintSchema extends BaseUISchema { deps: ['condeferrable'], disabled: function(state) { // Disable if condeferred is false or unselected. - if(state.condeferrable) { - return false; - } else { - return true; - } + return !state.condeferrable; }, readonly: obj.isReadonly, depChange: (state)=>{ diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/constraints/foreign_key/static/js/foreign_key.ui.js b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/constraints/foreign_key/static/js/foreign_key.ui.js index 0ee0622c5..f046155fd 100644 --- a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/constraints/foreign_key/static/js/foreign_key.ui.js +++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/constraints/foreign_key/static/js/foreign_key.ui.js @@ -204,11 +204,7 @@ export default class ForeignKeySchema extends BaseUISchema { deps: ['condeferrable'], disabled: function(state) { // Disable if condeferred is false or unselected. - if(state.condeferrable) { - return false; - } else { - return true; - } + return !state.condeferrable; }, readonly: obj.isReadonly, depChange: (state)=>{ @@ -284,11 +280,7 @@ export default class ForeignKeySchema extends BaseUISchema { mode: ['properties', 'create', 'edit'], group: gettext('Definition'), deps:['autoindex', 'hasindex'], disabled: (state)=>{ - if(!state.autoindex && !state.hasindex) { - return true; - } else { - return false; - } + return !state.autoindex && !state.hasindex; }, readonly: this.isReadonly, },{ diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/indexes/static/js/index.ui.js b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/indexes/static/js/index.ui.js index 259cc0ced..87fa07096 100644 --- a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/indexes/static/js/index.ui.js +++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/indexes/static/js/index.ui.js @@ -27,7 +27,7 @@ export function getColumnSchema(nodeObj, treeNodeInfo, itemNodeData) { } export class ColumnSchema extends BaseUISchema { - constructor(fieldOptions = {}, nodeData, initValues={}) { + constructor(fieldOptions = {}, nodeData = [], initValues={}) { super({ name: null, oid: undefined, @@ -121,7 +121,6 @@ export class ColumnSchema extends BaseUISchema { _.each(this.op_class_types, function(v, k) { if(amname === k) { options = v; - return; } }); return options; @@ -209,7 +208,7 @@ function inSchema(node_info) { } export default class IndexSchema extends BaseUISchema { - constructor(getColumnSchema, fieldOptions = {}, nodeData, initValues={}) { + constructor(getColumnSchema, fieldOptions = {}, nodeData = [], initValues={}) { super({ name: undefined, oid: undefined, diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/static/js/partition.utils.ui.js b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/static/js/partition.utils.ui.js index 8d0212ea0..aeecaeaa6 100644 --- a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/static/js/partition.utils.ui.js +++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/static/js/partition.utils.ui.js @@ -4,7 +4,7 @@ import BaseUISchema from 'sources/SchemaView/base_schema.ui'; import { emptyValidator, isEmptyString } from '../../../../../../../../static/js/validators'; export class PartitionKeysSchema extends BaseUISchema { - constructor(columns=[], getCollations, getOperatorClass) { + constructor(columns=[], getCollations=[], getOperatorClass=[]) { super({ key_type: 'column', }); @@ -424,7 +424,9 @@ export class PartitionsSchema extends BaseUISchema { msg = gettext('For hash partition Modulus field cannot be empty.'); setError('values_modulus', msg); return true; - } if(isEmptyString(state.values_remainder)) { + } + + if(isEmptyString(state.values_remainder)) { msg = gettext('For hash partition Remainder field cannot be empty.'); setError('values_remainder', msg); return true; diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/utils.py b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/utils.py index cb919fd12..efea7911d 100644 --- a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/utils.py +++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/utils.py @@ -333,10 +333,10 @@ class BaseTableView(PGChildNodeView, BasePartitionTable, VacuumSettings): :return: True or False based on condition """ # check whether the table is partition or not, then check conislocal - if 'relispartition' in data and data['relispartition'] is True: - if 'conislocal' in constraint \ - and constraint['conislocal'] is False: - return True + if 'relispartition' in data and data['relispartition'] is True and \ + 'conislocal' in constraint and \ + constraint['conislocal'] is False: + return True return False def get_table_dependents(self, tid): diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/types/static/js/type.ui.js b/web/pgadmin/browser/server_groups/servers/databases/schemas/types/static/js/type.ui.js index 08eb6d3cc..6e01ccb1b 100644 --- a/web/pgadmin/browser/server_groups/servers/databases/schemas/types/static/js/type.ui.js +++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/types/static/js/type.ui.js @@ -958,7 +958,6 @@ class CompositeSchema extends BaseUISchema { // set the values in state state.is_tlength = false; } - return; } }); } @@ -1306,7 +1305,6 @@ export default class TypeSchema extends BaseUISchema { tempCol.forEach(function(enumVal) { if(enumVal == undefined) { dontAddColumn = true; - return; } }); } @@ -1314,7 +1312,7 @@ export default class TypeSchema extends BaseUISchema { } schemaCheck(state) { - if(this.fieldOptions.node_info && 'schema' in this.fieldOptions.node_info) + if(this.fieldOptions.node_info && this.fieldOptions.node_info.indexOf('schema') >= 0) { if(!state) return true; diff --git a/web/pgadmin/browser/server_groups/servers/static/js/server.ui.js b/web/pgadmin/browser/server_groups/servers/static/js/server.ui.js index f6d81f0bd..b0dd28e86 100644 --- a/web/pgadmin/browser/server_groups/servers/static/js/server.ui.js +++ b/web/pgadmin/browser/server_groups/servers/static/js/server.ui.js @@ -19,7 +19,7 @@ import current_user from 'pgadmin.user_management.current_user'; import { isEmptyString } from 'sources/validators'; export default class ServerSchema extends BaseUISchema { - constructor(serverGroupOptions=[], userId, initValues={}) { + constructor(serverGroupOptions=[], userId=0, initValues={}) { super({ gid: undefined, id: undefined, diff --git a/web/pgadmin/browser/static/js/layout.js b/web/pgadmin/browser/static/js/layout.js index f5d1b39d1..689028f3d 100644 --- a/web/pgadmin/browser/static/js/layout.js +++ b/web/pgadmin/browser/static/js/layout.js @@ -68,9 +68,7 @@ _.extend(pgBrowser, { // clear the wcDocker before reset layout. docker.clear(); Notify.info(gettext('pgAdmin has reset the layout because the previously saved layout is invalid.'), null); - if(defaultLayoutCallback){ - defaultLayoutCallback(docker); - } + defaultLayoutCallback(docker); } } } diff --git a/web/pgadmin/browser/static/js/panel.js b/web/pgadmin/browser/static/js/panel.js index cac452f41..7f408d63b 100644 --- a/web/pgadmin/browser/static/js/panel.js +++ b/web/pgadmin/browser/static/js/panel.js @@ -171,9 +171,6 @@ define( p.pgResizeTimeout = null; /** Calculations based on https://getbootstrap.com/docs/4.1/layout/grid/#grid-options **/ - if (w < 480) { - elAttr = 'xs'; - } if (w >= 480) { elAttr = 'sm'; } diff --git a/web/pgadmin/model/__init__.py b/web/pgadmin/model/__init__.py index b7c65d1ba..38a88992c 100644 --- a/web/pgadmin/model/__init__.py +++ b/web/pgadmin/model/__init__.py @@ -40,6 +40,7 @@ SCHEMA_VERSION = 32 db = SQLAlchemy() USER_ID = 'user.id' +SERVER_ID = 'server.id' # Define models roles_users = db.Table( @@ -341,7 +342,7 @@ class QueryHistoryModel(db.Model): db.Integer, db.ForeignKey(USER_ID), nullable=False, primary_key=True ) sid = db.Column( - db.Integer(), db.ForeignKey('server.id'), nullable=False, + db.Integer(), db.ForeignKey(SERVER_ID), nullable=False, primary_key=True) dbname = db.Column(db.String(), nullable=False, primary_key=True) query_info = db.Column(db.String(), nullable=False) @@ -357,7 +358,7 @@ class Database(db.Model): schema_res = db.Column(db.String(256), nullable=True) server = db.Column( db.Integer, - db.ForeignKey('server.id'), + db.ForeignKey(SERVER_ID), nullable=False, primary_key=True ) @@ -370,7 +371,7 @@ class SharedServer(db.Model): id = db.Column(db.Integer, primary_key=True) osid = db.Column( db.Integer, - db.ForeignKey('server.id'), + db.ForeignKey(SERVER_ID), nullable=False ) user_id = db.Column( diff --git a/web/pgadmin/static/js/SchemaView/MappedControl.jsx b/web/pgadmin/static/js/SchemaView/MappedControl.jsx index d1323c0ef..62c211b08 100644 --- a/web/pgadmin/static/js/SchemaView/MappedControl.jsx +++ b/web/pgadmin/static/js/SchemaView/MappedControl.jsx @@ -11,8 +11,8 @@ import React, { useCallback } from 'react'; import _ from 'lodash'; import { FormInputText, FormInputSelect, FormInputSwitch, FormInputCheckbox, FormInputColor, - FormInputFileSelect, FormInputToggle, InputSwitch, FormInputSQL, FormNote, FormInputDateTimePicker, PlainString } from '../components/FormComponents'; -import { InputSelect, InputText, InputCheckbox, InputDateTimePicker } from '../components/FormComponents'; + FormInputFileSelect, FormInputToggle, InputSwitch, FormInputSQL, FormNote, FormInputDateTimePicker, PlainString, + InputSelect, InputText, InputCheckbox, InputDateTimePicker } from '../components/FormComponents'; import Privilege from '../components/Privilege'; import { evalFunc } from 'sources/utils'; import PropTypes from 'prop-types'; diff --git a/web/pgadmin/static/js/SchemaView/index.jsx b/web/pgadmin/static/js/SchemaView/index.jsx index 59a891c64..52ab97a30 100644 --- a/web/pgadmin/static/js/SchemaView/index.jsx +++ b/web/pgadmin/static/js/SchemaView/index.jsx @@ -89,15 +89,11 @@ function isValueEqual(val1, val2) { /* If the orig value was null and new one is empty string, then its a "no change" */ /* If the orig value and new value are of different datatype but of same value(numeric) "no change" */ /* If the orig value is undefined or null and new value is boolean false "no change" */ - if ((_.isEqual(val1, val2) + return (_.isEqual(val1, val2) || ((val1 === null || _.isUndefined(val1)) && val2 === '') || ((val1 === null || _.isUndefined(val1)) && typeof(val2) === 'boolean' && !val2) || (attrDefined ? _.isEqual(val1.toString(), val2.toString()) : false - ))) { - return true; - } else { - return false; - } + )); } function getChangedData(topSchema, viewHelperProps, sessData, stringify=false, includeSkipChange=true) { diff --git a/web/pgadmin/static/js/backform.pgadmin.js b/web/pgadmin/static/js/backform.pgadmin.js index 75dad3650..0f0a8ab4d 100644 --- a/web/pgadmin/static/js/backform.pgadmin.js +++ b/web/pgadmin/static/js/backform.pgadmin.js @@ -74,8 +74,7 @@ define([ return m; } - var idx = 1, - len = _.size(m); + var idx, len = _.size(m); switch (mode) { case 'properties': diff --git a/web/pgadmin/static/js/backgrid.pgadmin.js b/web/pgadmin/static/js/backgrid.pgadmin.js index 43ef08dbf..927ab96c2 100644 --- a/web/pgadmin/static/js/backgrid.pgadmin.js +++ b/web/pgadmin/static/js/backgrid.pgadmin.js @@ -1589,9 +1589,10 @@ define([ if (_.isUndefined(rawValue) || _.isNull(rawValue)) return ''; var pass = ''; - for (var i = 0; i < rawValue.length; i++) { + rawValue.forEach(() => { pass += '*'; - } + }); + return pass; }, }); diff --git a/web/pgadmin/static/js/csrf.js b/web/pgadmin/static/js/csrf.js index 44873614c..a6a092b7e 100644 --- a/web/pgadmin/static/js/csrf.js +++ b/web/pgadmin/static/js/csrf.js @@ -14,7 +14,7 @@ import axios from 'axios'; export function setPGCSRFToken(header, token) { if (!token) { // Throw error message. - throw 'csrf-token meta tag has not been set'; + throw new Error('csrf-token meta tag has not been set'); } // Configure Backbone.sync to set CSRF-Token-header request header for diff --git a/web/pgadmin/static/js/dialog_tab_navigator.js b/web/pgadmin/static/js/dialog_tab_navigator.js index c1838c11c..9f9916629 100644 --- a/web/pgadmin/static/js/dialog_tab_navigator.js +++ b/web/pgadmin/static/js/dialog_tab_navigator.js @@ -9,8 +9,7 @@ import $ from 'jquery'; import Mousetrap from 'mousetrap'; -import { findAndSetFocus } from './utils'; -import { parseShortcutValue } from './utils'; +import { findAndSetFocus, parseShortcutValue } from './utils'; class dialogTabNavigator { constructor(dialogContainer, backwardShortcut, forwardShortcut) { diff --git a/web/pgadmin/static/js/helpers/Notifier.jsx b/web/pgadmin/static/js/helpers/Notifier.jsx index 8d06bd265..b865d7cc6 100644 --- a/web/pgadmin/static/js/helpers/Notifier.jsx +++ b/web/pgadmin/static/js/helpers/Notifier.jsx @@ -220,7 +220,7 @@ var Notifier = { } this.alert(promptmsg, msg.replace(new RegExp(/\r?\n/, 'g'), '
')); }, - alert: (title, text, okLabel=gettext('OK'), onOkClick)=>{ + alert: (title, text, onOkClick, okLabel=gettext('OK'))=>{ if(!modalInitialized) { initializeModalProvider(); } diff --git a/web/pgadmin/static/js/tree/tree_init.tsx b/web/pgadmin/static/js/tree/tree_init.tsx index 89a25fe2e..6ecb3647e 100644 --- a/web/pgadmin/static/js/tree/tree_init.tsx +++ b/web/pgadmin/static/js/tree/tree_init.tsx @@ -12,9 +12,8 @@ import { render } from 'react-dom'; import { FileTreeX, TreeModelX } from 'pgadmin4-tree'; import {Tree} from './tree'; -import { IBasicFileSystemHost } from 'react-aspen'; +import { IBasicFileSystemHost, Directory } from 'react-aspen'; import { ManageTreeNodes } from './tree_nodes'; -import { Directory } from 'react-aspen'; import pgAdmin from 'sources/pgadmin'; var initBrowserTree = async (pgBrowser) => { @@ -29,8 +28,7 @@ var initBrowserTree = async (pgBrowser) => { const host: IBasicFileSystemHost = { pathStyle: 'unix', getItems: async (path) => { - let nodes = await mtree.readNode(path); - return nodes; + return await mtree.readNode(path); }, sortComparator: (a: FileEntry | Directory, b: FileEntry | Directory) => { // No nee to sort columns @@ -39,9 +37,13 @@ var initBrowserTree = async (pgBrowser) => { if (a.constructor === b.constructor) { return pgAdmin.natural_sort(a.fileName, b.fileName); } - return a.constructor === Directory ? -1 - : b.constructor === Directory ? 1 - : 0 + let retval = 0; + if (a.constructor === Directory) { + retval = -1; + } else if (b.constructor === Directory) { + retval = 1; + } + return retval; }, } diff --git a/web/pgadmin/static/js/tree/tree_nodes.ts b/web/pgadmin/static/js/tree/tree_nodes.ts index 670f6a3c9..7953ea26d 100644 --- a/web/pgadmin/static/js/tree/tree_nodes.ts +++ b/web/pgadmin/static/js/tree/tree_nodes.ts @@ -14,7 +14,7 @@ import _ from 'underscore'; import { FileType } from 'react-aspen' import { findInTree } from './tree'; -import { dirname, unix } from 'path-fx'; +import { unix } from 'path-fx'; export class ManageTreeNodes { constructor(fs) { @@ -115,17 +115,17 @@ export class ManageTreeNodes { } } - async function jsonData(url) { - let res = await fetch(url, { + async function jsonData(fetch_url) { + let result = await fetch(fetch_url, { headers: { 'X-Requested-With': 'XMLHttpRequest', 'X-pgA-CSRFToken': pgAdmin.csrf_token }, }); - if (res.status == 200) { + if (result.status == 200) { try { - let json = await res.json(); + let json = await result.json(); return json.data; } catch (e) { console.warn(e); @@ -146,7 +146,7 @@ export class ManageTreeNodes { } } - let d = await fill(treeData); + await fill(treeData); if (node.children.length > 0) res(node.children); else res(null); diff --git a/web/pgadmin/static/scss/_jsoneditor.overrides.scss b/web/pgadmin/static/scss/_jsoneditor.overrides.scss index b572b5508..b32c5aeb2 100644 --- a/web/pgadmin/static/scss/_jsoneditor.overrides.scss +++ b/web/pgadmin/static/scss/_jsoneditor.overrides.scss @@ -318,7 +318,7 @@ div.jsoneditor-value[contenteditable=true]:hover .jsoneditor .jsoneditor-text-errors { width: 100%; border-collapse: collapse; - border-top: 1px solid $color-gray;; + border-top: 1px solid $color-gray; } diff --git a/web/pgadmin/static/scss/_webcabin.pgadmin.scss b/web/pgadmin/static/scss/_webcabin.pgadmin.scss index 2ec19d893..ea4905e76 100644 --- a/web/pgadmin/static/scss/_webcabin.pgadmin.scss +++ b/web/pgadmin/static/scss/_webcabin.pgadmin.scss @@ -62,9 +62,6 @@ display: -webkit-flex; /* Safari */ display: flex; -} - -.wcFrameButtonBar { flex-direction: row-reverse; } diff --git a/web/pgadmin/static/vendor/backform/backform.js b/web/pgadmin/static/vendor/backform/backform.js index ea7b69579..a1b2316d0 100644 --- a/web/pgadmin/static/vendor/backform/backform.js +++ b/web/pgadmin/static/vendor/backform/backform.js @@ -363,10 +363,10 @@ keyPathAccessor: function(obj, path) { var res = obj; path = path.split('.'); - for (var i = 0; i < path.length; i++) { + for (let path_val of path) { if (_.isNull(res)) return null; - if (_.isEmpty(path[i])) continue; - if (!_.isUndefined(res[path[i]])) res = res[path[i]]; + if (_.isEmpty(path_val)) continue; + if (!_.isUndefined(res[path_val])) res = res[path_val]; } return _.isObject(res) && !_.isArray(res) ? null : res; }, diff --git a/web/pgadmin/tools/backup/static/js/backup.ui.js b/web/pgadmin/tools/backup/static/js/backup.ui.js index bda79f630..8b18b8ea6 100644 --- a/web/pgadmin/tools/backup/static/js/backup.ui.js +++ b/web/pgadmin/tools/backup/static/js/backup.ui.js @@ -381,7 +381,7 @@ export function getMiscellaneousSchema(fieldOptions) { } export default class BackupSchema extends BaseUISchema { - constructor(getSectionSchema, getTypeObjSchema, getSaveOptSchema, getQueryOptionSchema, getDisabledOptionSchema, getMiscellaneousSchema, fieldOptions = {}, treeNodeInfo, pgBrowser, backupType) { + constructor(getSectionSchema, getTypeObjSchema, getSaveOptSchema, getQueryOptionSchema, getDisabledOptionSchema, getMiscellaneousSchema, fieldOptions = {}, treeNodeInfo=[], pgBrowser=null, backupType='server') { super({ file: undefined, format: 'custom', diff --git a/web/pgadmin/tools/erd/static/js/erd_tool/ERDCore.js b/web/pgadmin/tools/erd/static/js/erd_tool/ERDCore.js index f193f5354..690534b70 100644 --- a/web/pgadmin/tools/erd/static/js/erd_tool/ERDCore.js +++ b/web/pgadmin/tools/erd/static/js/erd_tool/ERDCore.js @@ -10,8 +10,7 @@ /* * The ERDCore is the middleware between the canvas engine and the UI DOM. */ -import createEngine from '@projectstorm/react-diagrams'; -import {DagreEngine, PathFindingLinkFactory, PortModelAlignment} from '@projectstorm/react-diagrams'; +import createEngine, {DagreEngine, PathFindingLinkFactory, PortModelAlignment} from '@projectstorm/react-diagrams'; import { ZoomCanvasAction } from '@projectstorm/react-canvas-core'; import _ from 'lodash'; diff --git a/web/pgadmin/tools/grant_wizard/static/js/GrantWizard.jsx b/web/pgadmin/tools/grant_wizard/static/js/GrantWizard.jsx index 8a8ce3bc6..449f7a934 100644 --- a/web/pgadmin/tools/grant_wizard/static/js/GrantWizard.jsx +++ b/web/pgadmin/tools/grant_wizard/static/js/GrantWizard.jsx @@ -189,8 +189,7 @@ export default function GrantWizard({ sid, did, nodeInfo, nodeData }) { }, [nodeData]); const wizardStepChange = (data) => { - switch (data.currentStep) { - case 2: + if (data.currentStep == 2) { setLoaderText('Loading SQL ...'); var msql_url = url_for( 'grant_wizard.modified_sql', { @@ -209,9 +208,6 @@ export default function GrantWizard({ sid, did, nodeInfo, nodeData }) { .catch(() => { Notify.error(gettext('Error while fetching SQL.')); }); - break; - default: - break; } }; diff --git a/web/pgadmin/tools/import_export_servers/static/js/ImportExportServers.jsx b/web/pgadmin/tools/import_export_servers/static/js/ImportExportServers.jsx index 4a4bd369e..fee04719c 100644 --- a/web/pgadmin/tools/import_export_servers/static/js/ImportExportServers.jsx +++ b/web/pgadmin/tools/import_export_servers/static/js/ImportExportServers.jsx @@ -131,8 +131,7 @@ export default function ImportExportServers() { }); const wizardStepChange= (data) => { - switch (data.currentStep) { - case 2: { + if (data.currentStep == 2) { let sumData = [], serverSerialNumber = 0; serverData.forEach((server_group) => { @@ -158,10 +157,6 @@ export default function ImportExportServers() { setNoteText('On a successful import process, the browser tree will be refreshed.'); } } - break; - } - default: - break; } }; diff --git a/web/pgadmin/tools/restore/static/js/restore.ui.js b/web/pgadmin/tools/restore/static/js/restore.ui.js index 92f3c678a..792e7f8dc 100644 --- a/web/pgadmin/tools/restore/static/js/restore.ui.js +++ b/web/pgadmin/tools/restore/static/js/restore.ui.js @@ -331,7 +331,7 @@ export function getRestoreMiscellaneousSchema(fieldOptions) { //Restore Schema export default class RestoreSchema extends BaseUISchema { - constructor(getRestoreSectionSchema, getRestoreTypeObjSchema, getRestoreSaveOptSchema, getRestoreQueryOptionSchema, getRestoreDisableOptionSchema, getRestoreMiscellaneousSchema, fieldOptions = {}, treeNodeInfo, pgBrowser) { + constructor(getRestoreSectionSchema, getRestoreTypeObjSchema, getRestoreSaveOptSchema, getRestoreQueryOptionSchema, getRestoreDisableOptionSchema, getRestoreMiscellaneousSchema, fieldOptions = {}, treeNodeInfo=[], pgBrowser=null) { super({ custom: false, file: undefined, diff --git a/web/pgadmin/utils/driver/psycopg2/connection.py b/web/pgadmin/utils/driver/psycopg2/connection.py index 5c5278b33..4991d7bae 100644 --- a/web/pgadmin/utils/driver/psycopg2/connection.py +++ b/web/pgadmin/utils/driver/psycopg2/connection.py @@ -569,18 +569,17 @@ WHERE db.datname = current_database()""") FROM pg_catalog.pg_stat_gssapi WHERE pid = pg_backend_pid()""") - if status is None: - if cur.rowcount > 0: - res_enc = cur.fetchmany(1)[0] - manager.db_info[res['did']]['gss_authenticated'] =\ - res_enc['gss_authenticated'] - manager.db_info[res['did']]['gss_encrypted'] = \ - res_enc['encrypted'] + if status is None and cur.rowcount > 0: + res_enc = cur.fetchmany(1)[0] + manager.db_info[res['did']]['gss_authenticated'] =\ + res_enc['gss_authenticated'] + manager.db_info[res['did']]['gss_encrypted'] = \ + res_enc['encrypted'] - if len(manager.db_info) == 1: - manager.gss_authenticated = \ - res_enc['gss_authenticated'] - manager.gss_encrypted = res_enc['encrypted'] + if len(manager.db_info) == 1: + manager.gss_authenticated = \ + res_enc['gss_authenticated'] + manager.gss_encrypted = res_enc['encrypted'] self._set_user_info(cur, manager, **kwargs) diff --git a/web/regression/javascript/dashboard/graphs_spec.js b/web/regression/javascript/dashboard/graphs_spec.js index aa51d52ec..5d419034b 100644 --- a/web/regression/javascript/dashboard/graphs_spec.js +++ b/web/regression/javascript/dashboard/graphs_spec.js @@ -3,8 +3,7 @@ import React from 'react'; import {mount} from 'enzyme'; import '../helper/enzyme.helper'; -import Graphs, {GraphsWrapper} from '../../../pgadmin/dashboard/static/js/Graphs'; -import {X_AXIS_LENGTH, POINT_SIZE, transformData, legendCallback, +import Graphs, {GraphsWrapper, X_AXIS_LENGTH, POINT_SIZE, transformData, legendCallback, getStatsUrl, statsReducer} from '../../../pgadmin/dashboard/static/js/Graphs'; describe('Graphs.js', ()=>{ @@ -166,4 +165,4 @@ describe('Graphs.js', ()=>{ done(); }); }); -}); \ No newline at end of file +}); diff --git a/web/regression/javascript/schema_ui_files/domain.ui.spec.js b/web/regression/javascript/schema_ui_files/domain.ui.spec.js index 6c35e1ebe..2c8993b6d 100644 --- a/web/regression/javascript/schema_ui_files/domain.ui.spec.js +++ b/web/regression/javascript/schema_ui_files/domain.ui.spec.js @@ -15,8 +15,7 @@ import pgAdmin from 'sources/pgadmin'; import {messages} from '../fake_messages'; import SchemaView from '../../../pgadmin/static/js/SchemaView'; import BaseUISchema from 'sources/SchemaView/base_schema.ui'; -import DomainSchema from '../../../pgadmin/browser/server_groups/servers/databases/schemas/domains/static/js/domain.ui'; -import { DomainConstSchema } from '../../../pgadmin/browser/server_groups/servers/databases/schemas/domains/static/js/domain.ui'; +import DomainSchema, { DomainConstSchema } from '../../../pgadmin/browser/server_groups/servers/databases/schemas/domains/static/js/domain.ui'; describe('DomainSchema', ()=>{ let mount; diff --git a/web/regression/javascript/schema_ui_files/pga_schedule.ui.spec.js b/web/regression/javascript/schema_ui_files/pga_schedule.ui.spec.js index 9d42c3d1a..9d77ba730 100644 --- a/web/regression/javascript/schema_ui_files/pga_schedule.ui.spec.js +++ b/web/regression/javascript/schema_ui_files/pga_schedule.ui.spec.js @@ -14,8 +14,7 @@ import { createMount } from '@material-ui/core/test-utils'; import pgAdmin from 'sources/pgadmin'; import {messages} from '../fake_messages'; import SchemaView from '../../../pgadmin/static/js/SchemaView'; -import PgaJobScheduleSchema from '../../../pgadmin/browser/server_groups/servers/pgagent/schedules/static/js/pga_schedule.ui'; -import { ExceptionsSchema } from '../../../pgadmin/browser/server_groups/servers/pgagent/schedules/static/js/pga_schedule.ui'; +import PgaJobScheduleSchema, { ExceptionsSchema } from '../../../pgadmin/browser/server_groups/servers/pgagent/schedules/static/js/pga_schedule.ui'; describe('PgaJobScheduleSchema', ()=>{ let mount; diff --git a/web/regression/javascript/search_objects/search_objects_dialog_wrapper_spec.js b/web/regression/javascript/search_objects/search_objects_dialog_wrapper_spec.js index 008ed95a9..996e32650 100644 --- a/web/regression/javascript/search_objects/search_objects_dialog_wrapper_spec.js +++ b/web/regression/javascript/search_objects/search_objects_dialog_wrapper_spec.js @@ -73,7 +73,7 @@ describe('SearchObjectsDialogWrapper', () => { }, keyboardNavigation: jasmine.createSpyObj('keyboardNavigation', ['getDialogTabNavigator']), }; - pgBrowser.tree = new TreeFake(pgBrowser), + pgBrowser.tree = new TreeFake(pgBrowser); noDataNode = pgBrowser.tree.addNewNode('level1.1', undefined, [{id: 'level1'}]); serverTreeNode = pgBrowser.tree.addNewNode('level2.1', { _type: 'server', diff --git a/web/regression/javascript/table/enable_disable_triggers_spec.js b/web/regression/javascript/table/enable_disable_triggers_spec.js index 1b24c5de7..117e1a5ee 100644 --- a/web/regression/javascript/table/enable_disable_triggers_spec.js +++ b/web/regression/javascript/table/enable_disable_triggers_spec.js @@ -26,9 +26,7 @@ describe('#enableTriggers', () => { tree = new TreeFake(); spyOn(tree, 'unload').and.callFake(function() { - return new Promise((resolve)=>{ - resolve('Success!'); - }); + return Promise.resolve('Success!'); }); const server1 = tree.addNewNode('server1', {_id: 1}, ['
  • server1
  • ']); @@ -180,9 +178,7 @@ describe('#disableTriggers', () => { generateUrlSpy = jasmine.createSpy('generateUrl'); generateUrlSpy.and.returnValue('/some/place'); spyOn(tree, 'unload').and.callFake(function() { - return new Promise((resolve)=>{ - resolve('Success!'); - }); + return Promise.resolve('Success!'); }); }); diff --git a/web/regression/javascript/tree/tree_spec.js b/web/regression/javascript/tree/tree_spec.js index 2f80f6304..117f2ffe6 100644 --- a/web/regression/javascript/tree/tree_spec.js +++ b/web/regression/javascript/tree/tree_spec.js @@ -181,9 +181,7 @@ describe('tree tests', () => { 'setActiveFile', 'closeDirectory', 'getActiveFile', 'deSelectActiveFile']); tree.tree.unload.and.callFake(function() { - return new Promise((resolve)=>{ - resolve('Success!'); - }); + return Promise.resolve('Success!'); }); }); @@ -260,9 +258,7 @@ describe('tree tests', () => { tree.addNewNode('level3', {data: 'more data'}, ['
  • level3
  • '], ['level1','level2']); tree.tree = jasmine.createSpyObj('tree', ['unload']); tree.tree.unload.and.callFake(() => { - return new Promise((resolve)=>{ - resolve('Success!'); - }); + return Promise.resolve('Success!'); }); });