diff --git a/web/pgadmin/authenticate/registry.py b/web/pgadmin/authenticate/registry.py index 3fad986f9..f6ec0c4a1 100644 --- a/web/pgadmin/authenticate/registry.py +++ b/web/pgadmin/authenticate/registry.py @@ -27,13 +27,13 @@ class AuthSourceRegistry(ABCMeta): registry = None auth_sources = dict() - def __init__(cls, name, bases, d): + def __init__(self, name, bases, d): # Register this type of auth_sources, based on the module name # Avoid registering the BaseAuthentication itself - AuthSourceRegistry.registry[_decorate_cls_name(d['__module__'])] = cls - ABCMeta.__init__(cls, name, bases, d) + AuthSourceRegistry.registry[_decorate_cls_name(d['__module__'])] = self + ABCMeta.__init__(self, name, bases, d) @classmethod def create(cls, name, **kwargs): diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/fts_configurations/static/js/fts_configuration.js b/web/pgadmin/browser/server_groups/servers/databases/schemas/fts_configurations/static/js/fts_configuration.js index d69e22a38..2cd9d997a 100644 --- a/web/pgadmin/browser/server_groups/servers/databases/schemas/fts_configurations/static/js/fts_configuration.js +++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/fts_configurations/static/js/fts_configuration.js @@ -333,42 +333,39 @@ define('pgadmin.node.fts_configuration', [ var self = this, token = self.headerData.get('token'); - if (!token || token == '') { - return false; - } - - var coll = self.model.get(self.field.get('name')), - m = new (self.field.get('model'))( - self.headerData.toJSON(), { - silent: true, top: self.model.top, - collection: coll, handler: coll, - }), - checkVars = ['token'], - idx = -1; - - // Find if token exists in grid - self.collection.each(function(local_model) { - _.each(checkVars, function(v) { - var val = local_model.get(v); - if(val == token) { - idx = coll.indexOf(local_model); - } + if (token && token != '') { + var coll = self.model.get(self.field.get('name')), + m = new (self.field.get('model'))( + self.headerData.toJSON(), { + silent: true, top: self.model.top, + collection: coll, handler: coll, + }), + checkVars = ['token'], + idx = -1; + + // Find if token exists in grid + self.collection.each(function(local_model) { + _.each(checkVars, function(v) { + var val = local_model.get(v); + if(val == token) { + idx = coll.indexOf(local_model); + } + }); }); - }); - // remove 'm' if duplicate value found. - if (idx == -1) { - coll.add(m); - idx = coll.indexOf(m); + // remove 'm' if duplicate value found. + if (idx == -1) { + coll.add(m); + idx = coll.indexOf(m); + } + self.$grid.find('.new').removeClass('new'); + var newRow = self.grid.body.rows[idx].$el; + newRow.addClass('new'); + //$(newRow).pgMakeVisible('table-bordered'); + $(newRow).pgMakeVisible('backform-tab'); } - self.$grid.find('.new').removeClass('new'); - var newRow = self.grid.body.rows[idx].$el; - newRow.addClass('new'); - //$(newRow).pgMakeVisible('table-bordered'); - $(newRow).pgMakeVisible('backform-tab'); - return false; }, diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/constraints/check_constraint/static/js/check_constraint.js b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/constraints/check_constraint/static/js/check_constraint.js index 209767d46..456d04bda 100644 --- a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/constraints/check_constraint/static/js/check_constraint.js +++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/constraints/check_constraint/static/js/check_constraint.js @@ -64,30 +64,28 @@ define('pgadmin.node.check_constraint', [ i = input.item || t.selected(), d = i && i.length == 1 ? t.itemData(i) : undefined; - if (!d) { - return false; - } - var data = d; - $.ajax({ - url: obj.generate_url(i, 'validate', d, true), - type:'GET', - }) - .done(function(res) { - if (res.success == 1) { - alertify.success(res.info); - t.removeIcon(i); - data.valid = true; - data.icon = 'icon-check_constraint'; - t.addIcon(i, {icon: data.icon}); - setTimeout(function() {t.deselect(i);}, 10); - setTimeout(function() {t.select(i);}, 100); - } + if (d) { + var data = d; + $.ajax({ + url: obj.generate_url(i, 'validate', d, true), + type:'GET', }) - .fail(function(xhr, status, error) { - alertify.pgRespErrorNotify(xhr, error); - t.unload(i); - }); - + .done(function(res) { + if (res.success == 1) { + alertify.success(res.info); + t.removeIcon(i); + data.valid = true; + data.icon = 'icon-check_constraint'; + t.addIcon(i, {icon: data.icon}); + setTimeout(function() {t.deselect(i);}, 10); + setTimeout(function() {t.select(i);}, 100); + } + }) + .fail(function(xhr, status, error) { + alertify.pgRespErrorNotify(xhr, error); + t.unload(i); + }); + } return false; }, }, 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 57d65d3bc..9353c036d 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 @@ -541,41 +541,39 @@ define('pgadmin.node.exclusion_constraint', [ var self = this, column = self.headerData.get('column'); - if (!column || column == '') { - return false; - } - - var coll = self.model.get(self.field.get('name')), - m = new (self.field.get('model'))( - self.headerData.toJSON(), { - silent: true, top: self.model.top, - collection: coll, handler: coll, - }), - col_types =self.field.get('col_types') || []; - - for(var i=0; i < col_types.length; i++) { - var col_type = col_types[i]; - if (col_type['name'] == m.get('column')) { - m.set({'col_type':col_type['type']}); - break; + if (column && column != '') { + var coll = self.model.get(self.field.get('name')), + m = new (self.field.get('model'))( + self.headerData.toJSON(), { + silent: true, top: self.model.top, + collection: coll, handler: coll, + }), + col_types =self.field.get('col_types') || []; + + for(var i=0; i < col_types.length; i++) { + var col_type = col_types[i]; + if (col_type['name'] == m.get('column')) { + m.set({'col_type':col_type['type']}); + break; + } } - } - coll.add(m); + coll.add(m); - var idx = coll.indexOf(m); + var idx = coll.indexOf(m); - // idx may not be always > -1 because our UniqueColCollection may - // remove 'm' if duplicate value found. - if (idx > -1) { - self.$grid.find('.new').removeClass('new'); + // idx may not be always > -1 because our UniqueColCollection may + // remove 'm' if duplicate value found. + if (idx > -1) { + self.$grid.find('.new').removeClass('new'); - var newRow = self.grid.body.rows[idx].$el; + var newRow = self.grid.body.rows[idx].$el; - newRow.addClass('new'); - $(newRow).pgMakeVisible('backform-tab'); - } else { - //delete m; + newRow.addClass('new'); + $(newRow).pgMakeVisible('backform-tab'); + } else { + //delete m; + } } return false; 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 49b533cf7..a02ecf0b7 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 @@ -27,7 +27,7 @@ define('pgadmin.node.foreign_key', [ return opt.text; } else { return $( - '' + opt.text + '' + '' + opt.text + '' ); } }, @@ -487,32 +487,28 @@ define('pgadmin.node.foreign_key', [ local_column = self.headerData.get('local_column'), referenced = self.headerData.get('referenced'); - if (!local_column || local_column == '' || - !referenced || referenced =='') { - return false; - } + if (local_column && local_column != '' && referenced && referenced != '') { + var m = new (self.field.get('model'))( + self.headerData.toJSON()), + coll = self.model.get(self.field.get('name')); - var m = new (self.field.get('model'))( - self.headerData.toJSON()), - coll = self.model.get(self.field.get('name')); + coll.add(m); - coll.add(m); + var idx = coll.indexOf(m); - var idx = coll.indexOf(m); + // idx may not be always > -1 because our UniqueColCollection may + // remove 'm' if duplicate value found. + if (idx > -1) { + self.$grid.find('.new').removeClass('new'); - // idx may not be always > -1 because our UniqueColCollection may - // remove 'm' if duplicate value found. - if (idx > -1) { - self.$grid.find('.new').removeClass('new'); + var newRow = self.grid.body.rows[idx].$el; - var newRow = self.grid.body.rows[idx].$el; - - newRow.addClass('new'); - $(newRow).pgMakeVisible('backform-tab'); - } else { - //delete m; + newRow.addClass('new'); + $(newRow).pgMakeVisible('backform-tab'); + } else { + //delete m; + } } - return false; }, @@ -663,30 +659,28 @@ define('pgadmin.node.foreign_key', [ i = input.item || t.selected(), d = i && i.length == 1 ? t.itemData(i) : undefined; - if (!d) { - return false; - } - var data = d; - $.ajax({ - url: obj.generate_url(i, 'validate', d, true), - type:'GET', - }) - .done(function(res) { - if (res.success == 1) { - Alertify.success(res.info); - t.removeIcon(i); - data.valid = true; - data.icon = 'icon-foreign_key'; - t.addIcon(i, {icon: data.icon}); - setTimeout(function() {t.deselect(i);}, 10); - setTimeout(function() {t.select(i);}, 100); - } + if (d) { + var data = d; + $.ajax({ + url: obj.generate_url(i, 'validate', d, true), + type:'GET', }) - .fail(function(xhr, status, error) { - Alertify.pgRespErrorNotify(xhr, error); - t.unload(i); - }); - + .done(function(res) { + if (res.success == 1) { + Alertify.success(res.info); + t.removeIcon(i); + data.valid = true; + data.icon = 'icon-foreign_key'; + t.addIcon(i, {icon: data.icon}); + setTimeout(function() {t.deselect(i);}, 10); + setTimeout(function() {t.select(i);}, 100); + } + }) + .fail(function(xhr, status, error) { + Alertify.pgRespErrorNotify(xhr, error); + t.unload(i); + }); + } return false; }, }, diff --git a/web/pgadmin/browser/server_groups/servers/databases/static/js/database.js b/web/pgadmin/browser/server_groups/servers/databases/static/js/database.js index 91e2da879..88cd8caf3 100644 --- a/web/pgadmin/browser/server_groups/servers/databases/static/js/database.js +++ b/web/pgadmin/browser/server_groups/servers/databases/static/js/database.js @@ -172,10 +172,9 @@ define('pgadmin.node.database', [ i = input.item || t.selected(), d = i && i.length == 1 ? t.itemData(i) : undefined; - if (!d || d.label == 'template0') - return false; - - connect_to_database(obj, d, t, i, true); + if (d && d.label != 'template0') { + connect_to_database(obj, d, t, i, true); + } return false; }, /* Disconnect the database */ @@ -186,54 +185,53 @@ define('pgadmin.node.database', [ i = input.item || t.selected(), d = i && i.length == 1 ? t.itemData(i) : undefined; - if (!d) - return false; - - Alertify.confirm( - gettext('Disconnect the database'), - gettext('Are you sure you want to disconnect the database - %s?', d.label), - function() { - var data = d; - $.ajax({ - url: obj.generate_url(i, 'connect', d, true), - type:'DELETE', - }) - .done(function(res) { - if (res.success == 1) { - var prv_i = t.parent(i); - if(res.data.info_prefix) { - res.info = `${_.escape(res.data.info_prefix)} - ${res.info}`; - } - Alertify.success(res.info); - t.removeIcon(i); - data.connected = false; - data.icon = 'icon-database-not-connected'; - t.addIcon(i, {icon: data.icon}); - t.unload(i); - t.setInode(i); - setTimeout(function() { - t.select(prv_i); - }, 10); - - } else { - try { - Alertify.error(res.errormsg); - } catch (e) { - console.warn(e.stack || e); + if (d) { + Alertify.confirm( + gettext('Disconnect the database'), + gettext('Are you sure you want to disconnect the database - %s?', d.label), + function() { + var data = d; + $.ajax({ + url: obj.generate_url(i, 'connect', d, true), + type:'DELETE', + }) + .done(function(res) { + if (res.success == 1) { + var prv_i = t.parent(i); + if(res.data.info_prefix) { + res.info = `${_.escape(res.data.info_prefix)} - ${res.info}`; + } + Alertify.success(res.info); + t.removeIcon(i); + data.connected = false; + data.icon = 'icon-database-not-connected'; + t.addIcon(i, {icon: data.icon}); + t.unload(i); + t.setInode(i); + setTimeout(function() { + t.select(prv_i); + }, 10); + + } else { + try { + Alertify.error(res.errormsg); + } catch (e) { + console.warn(e.stack || e); + } + t.unload(i); } + }) + .fail(function(xhr, status, error) { + Alertify.pgRespErrorNotify(xhr, error); t.unload(i); - } - }) - .fail(function(xhr, status, error) { - Alertify.pgRespErrorNotify(xhr, error); - t.unload(i); - }); - }, - function() { return true; } - ).set('labels', { - ok: gettext('Yes'), - cancel: gettext('No'), - }); + }); + }, + function() { return true; } + ).set('labels', { + ok: gettext('Yes'), + cancel: gettext('No'), + }); + } return false; }, diff --git a/web/pgadmin/browser/server_groups/servers/pgagent/static/js/pga_job.js b/web/pgadmin/browser/server_groups/servers/pgagent/static/js/pga_job.js index f5c8ddc6b..085f1a18b 100644 --- a/web/pgadmin/browser/server_groups/servers/pgagent/static/js/pga_job.js +++ b/web/pgadmin/browser/server_groups/servers/pgagent/static/js/pga_job.js @@ -177,20 +177,19 @@ define('pgadmin.node.pga_job', [ i = input.item || t.selected(), d = i && i.length == 1 ? t.itemData(i) : undefined; - if (!d) - return false; - - $.ajax({ - url: obj.generate_url(i, 'run_now', d, true), - method:'PUT', - }) - // 'pgagent.pga_job' table updated with current time to run the job - // now. - .done(function() { t.unload(i); }) - .fail(function(xhr, status, error) { - alertify.pgRespErrorNotify(xhr, error); - t.unload(i); - }); + if (d) { + $.ajax({ + url: obj.generate_url(i, 'run_now', d, true), + method:'PUT', + }) + // 'pgagent.pga_job' table updated with current time to run the job + // now. + .done(function() { t.unload(i); }) + .fail(function(xhr, status, error) { + alertify.pgRespErrorNotify(xhr, error); + t.unload(i); + }); + } return false; }, diff --git a/web/pgadmin/browser/server_groups/servers/static/js/server.js b/web/pgadmin/browser/server_groups/servers/static/js/server.js index 37d3f1693..95e2a5d59 100644 --- a/web/pgadmin/browser/server_groups/servers/static/js/server.js +++ b/web/pgadmin/browser/server_groups/servers/static/js/server.js @@ -199,10 +199,9 @@ define('pgadmin.node.server', [ i = input.item || t.selected(), d = i && i.length == 1 ? t.itemData(i) : undefined; - if (!d) - return false; - - connect_to_server(obj, d, t, i, false); + if (d) { + connect_to_server(obj, d, t, i, false); + } return false; }, /* Disconnect the server */ @@ -213,59 +212,58 @@ define('pgadmin.node.server', [ i = 'item' in input ? input.item : t.selected(), d = i && i.length == 1 ? t.itemData(i) : undefined; - if (!d) - return false; + if (d) { + notify = notify || _.isUndefined(notify) || _.isNull(notify); - notify = notify || _.isUndefined(notify) || _.isNull(notify); - - var disconnect = function() { - $.ajax({ - url: obj.generate_url(i, 'connect', d, true), - type:'DELETE', - }) - .done(function(res) { - if (res.success == 1) { - Alertify.success(res.info); - d = t.itemData(i); - t.removeIcon(i); - d.connected = false; - d.icon = 'icon-server-not-connected'; - t.addIcon(i, {icon: d.icon}); - obj.callbacks.refresh.apply(obj, [null, i]); - if (pgBrowser.serverInfo && d._id in pgBrowser.serverInfo) { - delete pgBrowser.serverInfo[d._id]; + var disconnect = function() { + $.ajax({ + url: obj.generate_url(i, 'connect', d, true), + type:'DELETE', + }) + .done(function(res) { + if (res.success == 1) { + Alertify.success(res.info); + d = t.itemData(i); + t.removeIcon(i); + d.connected = false; + d.icon = 'icon-server-not-connected'; + t.addIcon(i, {icon: d.icon}); + obj.callbacks.refresh.apply(obj, [null, i]); + if (pgBrowser.serverInfo && d._id in pgBrowser.serverInfo) { + delete pgBrowser.serverInfo[d._id]; + } + pgBrowser.enable_disable_menus(i); + // Trigger server disconnect event + pgBrowser.Events.trigger( + 'pgadmin:server:disconnect', + {item: i, data: d}, false + ); } - pgBrowser.enable_disable_menus(i); - // Trigger server disconnect event - pgBrowser.Events.trigger( - 'pgadmin:server:disconnect', - {item: i, data: d}, false - ); - } - else { - try { - Alertify.error(res.errormsg); - } catch (e) { - console.warn(e.stack || e); + else { + try { + Alertify.error(res.errormsg); + } catch (e) { + console.warn(e.stack || e); + } + t.unload(i); } + }) + .fail(function(xhr, status, error) { + Alertify.pgRespErrorNotify(xhr, error); t.unload(i); - } - }) - .fail(function(xhr, status, error) { - Alertify.pgRespErrorNotify(xhr, error); - t.unload(i); - }); - }; + }); + }; - if (notify) { - Alertify.confirm( - gettext('Disconnect server'), - gettext('Are you sure you want to disconnect the server %s?', d.label), - function() { disconnect(); }, - function() { return true;} - ); - } else { - disconnect(); + if (notify) { + Alertify.confirm( + gettext('Disconnect server'), + gettext('Are you sure you want to disconnect the server %s?', d.label), + function() { disconnect(); }, + function() { return true;} + ); + } else { + disconnect(); + } } return false; @@ -306,32 +304,31 @@ define('pgadmin.node.server', [ i = input.item || t.selected(), d = i && i.length == 1 ? t.itemData(i) : undefined; - if (!d) - return false; - - Alertify.confirm( - gettext('Reload server configuration'), - gettext('Are you sure you want to reload the server configuration on %s?', d.label), - function() { - $.ajax({ - url: obj.generate_url(i, 'reload', d, true), - method:'GET', - }) - .done(function(res) { - if (res.data.status) { - Alertify.success(res.data.result); - } - else { - Alertify.error(res.data.result); - } + if (d) { + Alertify.confirm( + gettext('Reload server configuration'), + gettext('Are you sure you want to reload the server configuration on %s?', d.label), + function() { + $.ajax({ + url: obj.generate_url(i, 'reload', d, true), + method:'GET', }) - .fail(function(xhr, status, error) { - Alertify.pgRespErrorNotify(xhr, error); - t.unload(i); - }); - }, - function() { return true; } - ); + .done(function(res) { + if (res.data.status) { + Alertify.success(res.data.result); + } + else { + Alertify.error(res.data.result); + } + }) + .fail(function(xhr, status, error) { + Alertify.pgRespErrorNotify(xhr, error); + t.unload(i); + }); + }, + function() { return true; } + ); + } return false; }, @@ -387,174 +384,173 @@ define('pgadmin.node.server', [ is_pgpass_file_used = false, check_pgpass_url = obj.generate_url(i, 'check_pgpass', d, true); - if (!d) - return false; - - if(!Alertify.changeServerPassword) { - var newPasswordModel = Backbone.Model.extend({ - defaults: { - user_name: undefined, - password: undefined, - newPassword: undefined, - confirmPassword: undefined, - }, - validate: function() { - return null; - }, - }), - passwordChangeFields = [{ - name: 'user_name', label: gettext('User'), - type: 'text', readonly: true, control: 'input', - },{ - name: 'password', label: gettext('Current Password'), - type: 'password', disabled: function() { return is_pgpass_file_used; }, - control: 'input', required: true, - },{ - name: 'newPassword', label: gettext('New Password'), - type: 'password', disabled: false, control: 'input', - required: true, - },{ - name: 'confirmPassword', label: gettext('Confirm Password'), - type: 'password', disabled: false, control: 'input', - required: true, - }]; - - - Alertify.dialog('changeServerPassword' ,function factory() { - return { - main: function(params) { - var title = gettext('Change Password'); - this.set('title', title); - this.user_name = params.user.name; - }, - setup:function() { - return { - buttons: [{ - text: gettext('Cancel'), key: 27, - className: 'btn btn-secondary fa fa-times pg-alertify-button', attrs: {name: 'cancel'}, - },{ - text: gettext('OK'), key: 13, className: 'btn btn-primary fa fa-check pg-alertify-button', - attrs: {name:'submit'}, - }], - // Set options for dialog - options: { - padding : !1, - overflow: !1, - modal:false, - resizable: true, - maximizable: true, - pinnable: false, - closableByDimmer: false, + if (d) { + if(!Alertify.changeServerPassword) { + var newPasswordModel = Backbone.Model.extend({ + defaults: { + user_name: undefined, + password: undefined, + newPassword: undefined, + confirmPassword: undefined, + }, + validate: function() { + return null; + }, + }), + passwordChangeFields = [{ + name: 'user_name', label: gettext('User'), + type: 'text', readonly: true, control: 'input', + },{ + name: 'password', label: gettext('Current Password'), + type: 'password', disabled: function() { return is_pgpass_file_used; }, + control: 'input', required: true, + },{ + name: 'newPassword', label: gettext('New Password'), + type: 'password', disabled: false, control: 'input', + required: true, + },{ + name: 'confirmPassword', label: gettext('Confirm Password'), + type: 'password', disabled: false, control: 'input', + required: true, + }]; + + + Alertify.dialog('changeServerPassword' ,function factory() { + return { + main: function(params) { + var title = gettext('Change Password'); + this.set('title', title); + this.user_name = params.user.name; + }, + setup:function() { + return { + buttons: [{ + text: gettext('Cancel'), key: 27, + className: 'btn btn-secondary fa fa-times pg-alertify-button', attrs: {name: 'cancel'}, + },{ + text: gettext('OK'), key: 13, className: 'btn btn-primary fa fa-check pg-alertify-button', + attrs: {name:'submit'}, + }], + // Set options for dialog + options: { + padding : !1, + overflow: !1, + modal:false, + resizable: true, + maximizable: true, + pinnable: false, + closableByDimmer: false, + }, + }; + }, + hooks: { + // triggered when the dialog is closed + onclose: function() { + if (this.view) { + this.view.remove({data: true, internal: true, silent: true}); + } }, - }; - }, - hooks: { - // triggered when the dialog is closed - onclose: function() { - if (this.view) { - this.view.remove({data: true, internal: true, silent: true}); - } }, - }, - prepare: function() { - var self = this; - // Disable Ok button until user provides input - this.__internal.buttons[1].element.disabled = true; - - var $container = $('
'), - newpasswordmodel = new newPasswordModel( - {'user_name': self.user_name} - ), - view = this.view = new Backform.Form({ - el: $container, - model: newpasswordmodel, - fields: passwordChangeFields, - }); - - view.render(); - - this.elements.content.appendChild($container.get(0)); - - // Listen to model & if filename is provided then enable Backup button - this.view.model.on('change', function() { - var that = this, - password = this.get('password'), - newPassword = this.get('newPassword'), - confirmPassword = this.get('confirmPassword'); - - // Only check password field if pgpass file is not available - if ((!is_pgpass_file_used && - (_.isUndefined(password) || _.isNull(password) || password == '')) || - _.isUndefined(newPassword) || _.isNull(newPassword) || newPassword == '' || - _.isUndefined(confirmPassword) || _.isNull(confirmPassword) || confirmPassword == '') { - self.__internal.buttons[1].element.disabled = true; - } else if (newPassword != confirmPassword) { - self.__internal.buttons[1].element.disabled = true; - - this.errorTimeout && clearTimeout(this.errorTimeout); - this.errorTimeout = setTimeout(function() { - that.errorModel.set('confirmPassword', gettext('Passwords do not match.')); - } ,400); - }else { - that.errorModel.clear(); - self.__internal.buttons[1].element.disabled = false; - } - }); - }, - // Callback functions when click on the buttons of the Alertify dialogs - callback: function(e) { - if (e.button.element.name == 'submit') { - var self = this, - alertArgs = this.view.model.toJSON(); - - e.cancel = true; - - $.ajax({ - url: url, - method:'POST', - data:{'data': JSON.stringify(alertArgs) }, - }) - .done(function(res) { - if (res.success) { - // Notify user to update pgpass file - if(is_pgpass_file_used) { - Alertify.alert( - gettext('Change Password'), - gettext('Please make sure to disconnect the server' - + ' and update the new password in the pgpass file' - + ' before performing any other operation') - ); - } + prepare: function() { + var self = this; + // Disable Ok button until user provides input + this.__internal.buttons[1].element.disabled = true; + + var $container = $(''), + newpasswordmodel = new newPasswordModel( + {'user_name': self.user_name} + ), + view = this.view = new Backform.Form({ + el: $container, + model: newpasswordmodel, + fields: passwordChangeFields, + }); - Alertify.success(res.info); - self.close(); - } else { - Alertify.error(res.errormsg); - } + view.render(); + + this.elements.content.appendChild($container.get(0)); + + // Listen to model & if filename is provided then enable Backup button + this.view.model.on('change', function() { + var that = this, + password = this.get('password'), + newPassword = this.get('newPassword'), + confirmPassword = this.get('confirmPassword'); + + // Only check password field if pgpass file is not available + if ((!is_pgpass_file_used && + (_.isUndefined(password) || _.isNull(password) || password == '')) || + _.isUndefined(newPassword) || _.isNull(newPassword) || newPassword == '' || + _.isUndefined(confirmPassword) || _.isNull(confirmPassword) || confirmPassword == '') { + self.__internal.buttons[1].element.disabled = true; + } else if (newPassword != confirmPassword) { + self.__internal.buttons[1].element.disabled = true; + + this.errorTimeout && clearTimeout(this.errorTimeout); + this.errorTimeout = setTimeout(function() { + that.errorModel.set('confirmPassword', gettext('Passwords do not match.')); + } ,400); + }else { + that.errorModel.clear(); + self.__internal.buttons[1].element.disabled = false; + } + }); + }, + // Callback functions when click on the buttons of the Alertify dialogs + callback: function(e) { + if (e.button.element.name == 'submit') { + var self = this, + alertArgs = this.view.model.toJSON(); + + e.cancel = true; + + $.ajax({ + url: url, + method:'POST', + data:{'data': JSON.stringify(alertArgs) }, }) - .fail(function(xhr, status, error) { - Alertify.pgRespErrorNotify(xhr, error); - }); - } - }, - }; - }); - } + .done(function(res) { + if (res.success) { + // Notify user to update pgpass file + if(is_pgpass_file_used) { + Alertify.alert( + gettext('Change Password'), + gettext('Please make sure to disconnect the server' + + ' and update the new password in the pgpass file' + + ' before performing any other operation') + ); + } + + Alertify.success(res.info); + self.close(); + } else { + Alertify.error(res.errormsg); + } + }) + .fail(function(xhr, status, error) { + Alertify.pgRespErrorNotify(xhr, error); + }); + } + }, + }; + }); + } - // Call to check if server is using pgpass file or not - $.ajax({ - url: check_pgpass_url, - method:'GET', - }) - .done(function(res) { - if (res.success && res.data.is_pgpass) { - is_pgpass_file_used = true; - } - Alertify.changeServerPassword(d).resizeTo('40%','52%'); + // Call to check if server is using pgpass file or not + $.ajax({ + url: check_pgpass_url, + method:'GET', }) - .fail(function(xhr, status, error) { - Alertify.pgRespErrorNotify(xhr, error); - }); + .done(function(res) { + if (res.success && res.data.is_pgpass) { + is_pgpass_file_used = true; + } + Alertify.changeServerPassword(d).resizeTo('40%','52%'); + }) + .fail(function(xhr, status, error) { + Alertify.pgRespErrorNotify(xhr, error); + }); + } return false; }, @@ -637,32 +633,31 @@ define('pgadmin.node.server', [ i = input.item || t.selected(), d = i && i.length == 1 ? t.itemData(i) : undefined; - if (!d) - return false; - - Alertify.confirm( - gettext('Clear saved password'), - gettext('Are you sure you want to clear the saved password for server %s?', d.label), - function() { - $.ajax({ - url: obj.generate_url(i, 'clear_saved_password', d, true), - method:'PUT', - }) - .done(function(res) { - if (res.success == 1) { - Alertify.success(res.info); - t.itemData(i).is_password_saved=res.data.is_password_saved; - } - else { - Alertify.error(res.info); - } + if (d) { + Alertify.confirm( + gettext('Clear saved password'), + gettext('Are you sure you want to clear the saved password for server %s?', d.label), + function() { + $.ajax({ + url: obj.generate_url(i, 'clear_saved_password', d, true), + method:'PUT', }) - .fail(function(xhr, status, error) { - Alertify.pgRespErrorNotify(xhr, error); - }); - }, - function() { return true; } - ); + .done(function(res) { + if (res.success == 1) { + Alertify.success(res.info); + t.itemData(i).is_password_saved=res.data.is_password_saved; + } + else { + Alertify.error(res.info); + } + }) + .fail(function(xhr, status, error) { + Alertify.pgRespErrorNotify(xhr, error); + }); + }, + function() { return true; } + ); + } return false; }, @@ -675,32 +670,31 @@ define('pgadmin.node.server', [ i = input.item || t.selected(), d = i && i.length == 1 ? t.itemData(i) : undefined; - if (!d) - return false; - - Alertify.confirm( - gettext('Clear SSH Tunnel password'), - gettext('Are you sure you want to clear the saved password of SSH Tunnel for server %s?', d.label), - function() { - $.ajax({ - url: obj.generate_url(i, 'clear_sshtunnel_password', d, true), - method:'PUT', - }) - .done(function(res) { - if (res.success == 1) { - Alertify.success(res.info); - t.itemData(i).is_tunnel_password_saved=res.data.is_tunnel_password_saved; - } - else { - Alertify.error(res.info); - } + if (d) { + Alertify.confirm( + gettext('Clear SSH Tunnel password'), + gettext('Are you sure you want to clear the saved password of SSH Tunnel for server %s?', d.label), + function() { + $.ajax({ + url: obj.generate_url(i, 'clear_sshtunnel_password', d, true), + method:'PUT', }) - .fail(function(xhr, status, error) { - Alertify.pgRespErrorNotify(xhr, error); - }); - }, - function() { return true; } - ); + .done(function(res) { + if (res.success == 1) { + Alertify.success(res.info); + t.itemData(i).is_tunnel_password_saved=res.data.is_tunnel_password_saved; + } + else { + Alertify.error(res.info); + } + }) + .fail(function(xhr, status, error) { + Alertify.pgRespErrorNotify(xhr, error); + }); + }, + function() { return true; } + ); + } return false; }, diff --git a/web/pgadmin/browser/static/js/browser.js b/web/pgadmin/browser/static/js/browser.js index c7f1b7216..e010458cc 100644 --- a/web/pgadmin/browser/static/js/browser.js +++ b/web/pgadmin/browser/static/js/browser.js @@ -31,7 +31,6 @@ define('pgadmin.browser', [ // Generally the one, which do no have AMD support. var wcDocker = window.wcDocker; $ = $ || window.jQuery || window.$; - Bootstrap = Bootstrap || window.Bootstrap; var CodeMirror = codemirror.default; var pgBrowser = pgAdmin.Browser = pgAdmin.Browser || {}; diff --git a/web/pgadmin/browser/static/js/datamodel.js b/web/pgadmin/browser/static/js/datamodel.js index 1e3c81c12..cd74982ec 100644 --- a/web/pgadmin/browser/static/js/datamodel.js +++ b/web/pgadmin/browser/static/js/datamodel.js @@ -154,7 +154,6 @@ define([ if (_.isUndefined(options) || _.isNull(options)) { options = attributes || {}; - attributes = null; } self.sessAttrs = {}; @@ -1029,128 +1028,124 @@ define([ return (_.findIndex(this.sessAttrs[type], comparator)); }, onModelAdd: function(obj) { - if (!this.trackChanges) - return true; - - var self = this, - msg, - idx = self.objFindInSession(obj, 'deleted'); + if (this.trackChanges) { + var self = this, + msg, + idx = self.objFindInSession(obj, 'deleted'); - // Hmm.. - it was originally deleted from this collection, we should - // remove it from the 'deleted' list. - if (idx >= 0) { - var origObj = self.sessAttrs['deleted'][idx]; - - obj.origSessAttrs = _.clone(origObj.origSessAttrs); - obj.attributes = _.extend(obj.attributes, origObj.attributes); - obj.sessAttrs = _.clone(origObj.sessAttrs); + // Hmm.. - it was originally deleted from this collection, we should + // remove it from the 'deleted' list. + if (idx >= 0) { + var origObj = self.sessAttrs['deleted'][idx]; - self.sessAttrs['deleted'].splice(idx, 1); + obj.origSessAttrs = _.clone(origObj.origSessAttrs); + obj.attributes = _.extend(obj.attributes, origObj.attributes); + obj.sessAttrs = _.clone(origObj.sessAttrs); - // It has been changed originally! - if ((!('sessChanged' in obj)) || obj.sessChanged()) { - self.sessAttrs['changed'].push(obj); - } + self.sessAttrs['deleted'].splice(idx, 1); - (self.handler || self).trigger('pgadmin-session:added', self, obj); + // It has been changed originally! + if ((!('sessChanged' in obj)) || obj.sessChanged()) { + self.sessAttrs['changed'].push(obj); + } + (self.handler || self).trigger('pgadmin-session:added', self, obj); - if ('default_validate' in obj && typeof(obj.default_validate) == 'function') { - msg = obj.default_validate(); - } - if (_.isString(msg)) { - (self.sessAttrs['invalid'])[obj.cid] = msg; - } else if ('validate' in obj && typeof(obj.validate) === 'function') { - msg = obj.validate(); + if ('default_validate' in obj && typeof(obj.default_validate) == 'function') { + msg = obj.default_validate(); + } - if (msg) { + if (_.isString(msg)) { (self.sessAttrs['invalid'])[obj.cid] = msg; - } - } - } else { + } else if ('validate' in obj && typeof(obj.validate) === 'function') { + msg = obj.validate(); - if ('default_validate' in obj && typeof(obj.default_validate) == 'function') { - msg = obj.default_validate(); - } + if (msg) { + (self.sessAttrs['invalid'])[obj.cid] = msg; + } + } + } else { - if (_.isString(msg)) { - (self.sessAttrs['invalid'])[obj.cid] = msg; - } else if ('validate' in obj && typeof(obj.validate) === 'function') { - msg = obj.validate(); + if ('default_validate' in obj && typeof(obj.default_validate) == 'function') { + msg = obj.default_validate(); + } - if (msg) { + if (_.isString(msg)) { (self.sessAttrs['invalid'])[obj.cid] = msg; + } else if ('validate' in obj && typeof(obj.validate) === 'function') { + msg = obj.validate(); + + if (msg) { + (self.sessAttrs['invalid'])[obj.cid] = msg; + } } + self.sessAttrs['added'].push(obj); + + /* + * Session has been changed + */ + (self.handler || self).trigger('pgadmin-session:added', self, obj); } - self.sessAttrs['added'].push(obj); - /* - * Session has been changed - */ - (self.handler || self).trigger('pgadmin-session:added', self, obj); + // Let the parent/listener know about my status (valid/invalid). + this.triggerValidationEvent.apply(this); } - // Let the parent/listener know about my status (valid/invalid). - this.triggerValidationEvent.apply(this); - return true; }, onModelRemove: function(obj) { - if (!this.trackChanges) - return true; - - /* Once model is removed from collection clear its errorModel as it's no longer relevant - * for us. Otherwise it creates problem in 'clearInvalidSessionIfModelValid' function. - */ - obj.errorModel.clear(); - - var self = this, - invalidModels = self.sessAttrs['invalid'], - copy = _.clone(obj), - idx = self.objFindInSession(obj, 'added'); - - // We need to remove it from the invalid object list first. - if (obj.cid in invalidModels) { - delete invalidModels[obj.cid]; - } + if (this.trackChanges) { + /* Once model is removed from collection clear its errorModel as it's no longer relevant + * for us. Otherwise it creates problem in 'clearInvalidSessionIfModelValid' function. + */ + obj.errorModel.clear(); - // Hmm - it was newly added, we can safely remove it. - if (idx >= 0) { - self.sessAttrs['added'].splice(idx, 1); + var self = this, + invalidModels = self.sessAttrs['invalid'], + copy = _.clone(obj), + idx = self.objFindInSession(obj, 'added'); - (self.handler || self).trigger('pgadmin-session:removed', self, copy); + // We need to remove it from the invalid object list first. + if (obj.cid in invalidModels) { + delete invalidModels[obj.cid]; + } - self.checkDuplicateWithModel(copy); + // Hmm - it was newly added, we can safely remove it. + if (idx >= 0) { + self.sessAttrs['added'].splice(idx, 1); - // Let the parent/listener know about my status (valid/invalid). - this.triggerValidationEvent.apply(this); + (self.handler || self).trigger('pgadmin-session:removed', self, copy); - return true; - } + self.checkDuplicateWithModel(copy); - // Hmm - it was changed in this session, we should remove it from the - // changed models. - idx = self.objFindInSession(obj, 'changed'); + // Let the parent/listener know about my status (valid/invalid). + this.triggerValidationEvent.apply(this); + } else { + // Hmm - it was changed in this session, we should remove it from the + // changed models. + idx = self.objFindInSession(obj, 'changed'); - if (idx >= 0) { - self.sessAttrs['changed'].splice(idx, 1); - (self.handler || self).trigger('pgadmin-session:removed', self, copy); - } else { - (self.handler || self).trigger('pgadmin-session:removed', self, copy); - } + if (idx >= 0) { + self.sessAttrs['changed'].splice(idx, 1); + (self.handler || self).trigger('pgadmin-session:removed', self, copy); + } else { + (self.handler || self).trigger('pgadmin-session:removed', self, copy); + } - self.sessAttrs['deleted'].push(obj); + self.sessAttrs['deleted'].push(obj); - self.checkDuplicateWithModel(obj); + self.checkDuplicateWithModel(obj); - // Let the parent/listener know about my status (valid/invalid). - this.triggerValidationEvent.apply(this); + // Let the parent/listener know about my status (valid/invalid). + this.triggerValidationEvent.apply(this); + } - /* - * This object has been remove, we need to check (if we still have any - * other invalid message pending). - */ + /* + * This object has been remove, we need to check (if we still have any + * other invalid message pending). + */ + } return true; }, @@ -1194,52 +1189,39 @@ define([ onModelChange: function(obj) { var self = this; - if (!this.trackChanges || !(obj instanceof pgBrowser.Node.Model)) - return true; - - var idx = self.objFindInSession(obj, 'added'); - - // It was newly added model, we don't need to add into the changed - // list. - if (idx >= 0) { - (self.handler || self).trigger('pgadmin-session:changed', self, obj); - - return true; - } - - idx = self.objFindInSession(obj, 'changed'); - - if (!('sessChanged' in obj)) { - (self.handler || self).trigger('pgadmin-session:changed', self, obj); + if (this.trackChanges && obj instanceof pgBrowser.Node.Model) { + var idx = self.objFindInSession(obj, 'added'); + // It was newly added model, we don't need to add into the changed + // list. if (idx >= 0) { - return true; - } - - self.sessAttrs['changed'].push(obj); - - return true; - } - - if (idx >= 0) { - - if (!obj.sessChanged()) { - // This object is no more updated, removing it from the changed - // models list. - self.sessAttrs['changed'].splice(idx, 1); - (self.handler || self).trigger('pgadmin-session:changed', self, obj); - return true; - } + } else { + idx = self.objFindInSession(obj, 'changed'); - (self.handler || self).trigger('pgadmin-session:changed', self, obj); + if (!('sessChanged' in obj)) { + (self.handler || self).trigger('pgadmin-session:changed', self, obj); - return true; - } + if (idx < 0) { + self.sessAttrs['changed'].push(obj); + } + } else { + if (idx >= 0) { + if (!obj.sessChanged()) { + // This object is no more updated, removing it from the changed + // models list. + self.sessAttrs['changed'].splice(idx, 1); - if (obj.sessChanged()) { - self.sessAttrs['changed'].push(obj); - (self.handler || self).trigger('pgadmin-session:changed', self, obj); + (self.handler || self).trigger('pgadmin-session:changed', self, obj); + } else { + (self.handler || self).trigger('pgadmin-session:changed', self, obj); + } + } else if (obj.sessChanged()) { + self.sessAttrs['changed'].push(obj); + (self.handler || self).trigger('pgadmin-session:changed', self, obj); + } + } + } } return true; diff --git a/web/pgadmin/preferences/static/js/preferences.js b/web/pgadmin/preferences/static/js/preferences.js index 2afa9fe36..1364b931b 100644 --- a/web/pgadmin/preferences/static/js/preferences.js +++ b/web/pgadmin/preferences/static/js/preferences.js @@ -320,7 +320,7 @@ define('pgadmin.preferences', [ switch (eventName) { case 'selected': if (!d) - return true; + break; if (d.preferences) { /* @@ -330,14 +330,14 @@ define('pgadmin.preferences', [ renderPreferencePanel(d.preferences); - return true; + break; } else { selectFirstCategory(api, item); } break; case 'added': if (!d) - return true; + break; // We will add the preferences in to the preferences data // collection. diff --git a/web/pgadmin/tools/import_export/static/js/import_export.js b/web/pgadmin/tools/import_export/static/js/import_export.js index e2afa6b37..1475023de 100644 --- a/web/pgadmin/tools/import_export/static/js/import_export.js +++ b/web/pgadmin/tools/import_export/static/js/import_export.js @@ -136,7 +136,6 @@ define([ } } catch (e) { // Do nothing - options = []; console.warn(e.stack || e); } } else { diff --git a/web/pgadmin/tools/sqleditor/command.py b/web/pgadmin/tools/sqleditor/command.py index 9c6f1e715..288e145be 100644 --- a/web/pgadmin/tools/sqleditor/command.py +++ b/web/pgadmin/tools/sqleditor/command.py @@ -45,15 +45,15 @@ class ObjectRegistry(ABCMeta): registry = dict() - def __init__(cls, name, bases, d): + def __init__(self, name, bases, d): """ This method is used to register the objects based on object type. """ if d and 'object_type' in d: - ObjectRegistry.registry[d['object_type']] = cls + ObjectRegistry.registry[d['object_type']] = self - ABCMeta.__init__(cls, name, bases, d) + ABCMeta.__init__(self, name, bases, d) @classmethod def get_object(cls, name, **kwargs): diff --git a/web/pgadmin/tools/user_management/static/js/user_management.js b/web/pgadmin/tools/user_management/static/js/user_management.js index c93de5397..29f4a4628 100644 --- a/web/pgadmin/tools/user_management/static/js/user_management.js +++ b/web/pgadmin/tools/user_management/static/js/user_management.js @@ -953,28 +953,31 @@ define([ this.$content.find('button.add').first().on('click',(e) => { e.preventDefault(); // There should be only one empty row. + let anyNew = false; for(const [idx, model] of userCollection.models.entries()) { if(model.isNew()) { let row = view.body.rows[idx].$el; row.addClass('new'); $(row).pgMakeVisible('backgrid'); $(row).find('.email').trigger('click'); - return false; + anyNew = true; } } - $(view.body.$el.find($('tr.new'))).removeClass('new'); - var m = new(UserModel)(null, { - handler: userCollection, - top: userCollection, - collection: userCollection, - }); - userCollection.add(m); + if(!anyNew) { + $(view.body.$el.find($('tr.new'))).removeClass('new'); + var m = new(UserModel)(null, { + handler: userCollection, + top: userCollection, + collection: userCollection, + }); + userCollection.add(m); - var newRow = view.body.rows[userCollection.indexOf(m)].$el; - newRow.addClass('new'); - $(newRow).pgMakeVisible('backgrid'); - $(newRow).find('.email').trigger('click'); + var newRow = view.body.rows[userCollection.indexOf(m)].$el; + newRow.addClass('new'); + $(newRow).pgMakeVisible('backgrid'); + $(newRow).find('.email').trigger('click'); + } return false; }); diff --git a/web/pgadmin/utils/driver/psycopg2/__init__.py b/web/pgadmin/utils/driver/psycopg2/__init__.py index 992c85f5c..9d6c5ab64 100644 --- a/web/pgadmin/utils/driver/psycopg2/__init__.py +++ b/web/pgadmin/utils/driver/psycopg2/__init__.py @@ -120,7 +120,7 @@ class Driver(BaseDriver): return managers[str(sid)] - def version(cls): + def version(self): """ version(...) @@ -135,7 +135,7 @@ class Driver(BaseDriver): "Driver Version information for psycopg2 is not available!" ) - def libpq_version(cls): + def libpq_version(self): """ Returns the loaded libpq version """ diff --git a/web/pgadmin/utils/driver/registry.py b/web/pgadmin/utils/driver/registry.py index 536178075..fbffb7e44 100644 --- a/web/pgadmin/utils/driver/registry.py +++ b/web/pgadmin/utils/driver/registry.py @@ -50,15 +50,15 @@ class DriverRegistry(ABCMeta): registry = None drivers = dict() - def __init__(cls, name, bases, d): + def __init__(self, name, bases, d): # Register this type of driver, based on the module name # Avoid registering the BaseDriver itself if name != 'BaseDriver': - DriverRegistry.registry[_decorate_cls_name(d['__module__'])] = cls + DriverRegistry.registry[_decorate_cls_name(d['__module__'])] = self - ABCMeta.__init__(cls, name, bases, d) + ABCMeta.__init__(self, name, bases, d) @classmethod def create(cls, name, **kwargs): diff --git a/web/pgadmin/utils/route.py b/web/pgadmin/utils/route.py index 3a5d7ab9a..0d646bb45 100644 --- a/web/pgadmin/utils/route.py +++ b/web/pgadmin/utils/route.py @@ -42,7 +42,7 @@ class TestsGeneratorRegistry(ABCMeta): registry = dict() - def __init__(cls, name, bases, d): + def __init__(self, name, bases, d): # Register this type of module, based on the module name # Avoid registering the BaseDriver itself @@ -51,11 +51,11 @@ class TestsGeneratorRegistry(ABCMeta): # Store/append test classes in 'registry' if test modules has # multiple classes if d['__module__'] in TestsGeneratorRegistry.registry: - TestsGeneratorRegistry.registry[d['__module__']].append(cls) + TestsGeneratorRegistry.registry[d['__module__']].append(self) else: - TestsGeneratorRegistry.registry[d['__module__']] = [cls] + TestsGeneratorRegistry.registry[d['__module__']] = [self] - ABCMeta.__init__(cls, name, bases, d) + ABCMeta.__init__(self, name, bases, d) @classmethod def load_generators(cls, pkg_root, exclude_pkgs, for_modules=[],