public inbox for [email protected]
help / color / mirror / Atom feedFrom: Murtuza Zabuawala <[email protected]>
To: pgadmin-hackers <[email protected]>
Subject: [pgAdmin4][RM#3200] Don't set empty string for host/hostaddr in model when service is used
Date: Mon, 19 Mar 2018 15:37:25 +0530
Message-ID: <CAKKotZQZBa=eZkzK4dTch3K=2D-zhCeHYomZHyVJaEaK2=PThg@mail.gmail.com> (raw)
Hi,
PFA patch to fix the issue where pgAdmin4 was not able to utilise the host
parameter from service file.
--
Regards,
Murtuza Zabuawala
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company
Attachments:
[application/octet-stream] RM_3200.diff (3.8K, 3-RM_3200.diff)
download | inline diff:
diff --git a/web/pgadmin/browser/server_groups/servers/__init__.py b/web/pgadmin/browser/server_groups/servers/__init__.py
index fecb66d..41eb429 100644
--- a/web/pgadmin/browser/server_groups/servers/__init__.py
+++ b/web/pgadmin/browser/server_groups/servers/__init__.py
@@ -500,7 +500,7 @@ class ServerNode(PGChildNodeView):
if 'db_res' in data:
data['db_res'] = ','.join(data['db_res'])
- if 'hostaddr' in data and data['hostaddr'] != '':
+ if 'hostaddr' in data and data['hostaddr'] and data['hostaddr'] != '':
if not self.pat4.match(data['hostaddr']):
if not self.pat6.match(data['hostaddr']):
return make_json_response(
@@ -700,7 +700,7 @@ class ServerNode(PGChildNodeView):
)
)
- if 'hostaddr' in data and data['hostaddr'] != '':
+ if 'hostaddr' in data and data['hostaddr'] and data['hostaddr'] != '':
if not self.pat4.match(data['hostaddr']):
if not self.pat6.match(data['hostaddr']):
return make_json_response(
diff --git a/web/pgadmin/static/js/browser/server_groups/servers/model_validation.js b/web/pgadmin/static/js/browser/server_groups/servers/model_validation.js
index 948af3d..f1627aa 100644
--- a/web/pgadmin/static/js/browser/server_groups/servers/model_validation.js
+++ b/web/pgadmin/static/js/browser/server_groups/servers/model_validation.js
@@ -31,6 +31,8 @@ export class ModelValidation {
this.checkForEmpty('name', gettext('Name must be specified.'));
if (ModelValidation.isEmptyString(serviceId)) {
+ // Do not sent empty string
+ this.setNullValueForEmptyString('service');
this.checkHostAndHostAddress();
this.checkForEmpty('db', gettext('Maintenance database must be specified.'));
@@ -50,8 +52,20 @@ export class ModelValidation {
return null;
}
+ setNullValueForEmptyString(field) {
+ let val = this.model.get(field);
+ if (_.isUndefined(val) || _.isNull(val))
+ return;
+
+ // To avoid passing empty string to connection parameter
+ if(String(val).trim() === '') {
+ this.model.set(field, null);
+ }
+ }
+
clearHostAddressAndDbErrors() {
_.each(['host', 'hostaddr', 'db'], (item) => {
+ this.setNullValueForEmptyString(item);
this.model.errorModel.unset(item);
});
}
diff --git a/web/regression/javascript/browser/server_groups/servers/model_validation_spec.js b/web/regression/javascript/browser/server_groups/servers/model_validation_spec.js
index 560d8b6..85e51eb 100644
--- a/web/regression/javascript/browser/server_groups/servers/model_validation_spec.js
+++ b/web/regression/javascript/browser/server_groups/servers/model_validation_spec.js
@@ -20,6 +20,9 @@ describe('Server#ModelValidation', () => {
get: function (key) {
return this.allValues[key];
},
+ set: function (key, value) {
+ this.key = value;
+ },
sessAttrs: {},
};
model.isNew = jasmine.createSpy('isNew');
@@ -51,6 +54,20 @@ describe('Server#ModelValidation', () => {
expect(model.errorModel.set).toHaveBeenCalledWith({});
});
});
+
+ describe('Service id present', () => {
+ it('sets empty service name which should throw an error', () => {
+ model.allValues['service'] = '';
+ expect(modelValidation.validate()).toBe('Either Host name, Address or Service must be specified.');
+ expect(model.errorModel.set).toHaveBeenCalledWith({
+ host: 'Either Host name, Address or Service must be specified.',
+ hostaddr: 'Either Host name, Address or Service must be specified.',
+ db: 'Maintenance database must be specified.'
+ });
+ });
+ });
+
+
});
describe('When no parameters are valid', () => {
view thread (2+ 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: [pgAdmin4][RM#3200] Don't set empty string for host/hostaddr in model when service is used
In-Reply-To: <CAKKotZQZBa=eZkzK4dTch3K=2D-zhCeHYomZHyVJaEaK2=PThg@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