Ensure port and username should not be mandatory when a service is provided. Fixes #4642

This commit is contained in:
Akshay Joshi 2019-09-13 11:54:16 +05:30
parent 9a69d27009
commit da553eec9b
5 changed files with 105 additions and 14 deletions

View File

@ -45,6 +45,7 @@ Bug fixes
| `Issue #4577 <https://redmine.postgresql.org/issues/4577>`_ - Fix an error that could be seen when click on any system column of a table.
| `Issue #4584 <https://redmine.postgresql.org/issues/4584>`_ - Unescape HTML entities in database names in the Query Tool title bar.
| `Issue #4631 <https://redmine.postgresql.org/issues/4631>`_ - Add editor options for plain text mode and to disable block folding to workaround rendering speed issues in CodeMirror with very large scripts.
| `Issue #4642 <https://redmine.postgresql.org/issues/4642>`_ - Ensure port and username should not be mandatory when a service is provided.
| `Issue #4643 <https://redmine.postgresql.org/issues/4643>`_ - Fix Truncate option deselect issue for compound triggers.
| `Issue #4644 <https://redmine.postgresql.org/issues/4644>`_ - Fix length and precision enable/disable issue when changing the data type for Domain node.
| `Issue #4650 <https://redmine.postgresql.org/issues/4650>`_ - Fix SQL tab issue for Views. It's a regression of compound triggers.

View File

@ -0,0 +1,91 @@
"""Change the not null constraints for port, username as it should not
compulsory when service is provided. RM #4642
Revision ID: a77a0932a568
Revises: 35f29b1701bd
Create Date: 2019-09-09 15:41:30.084753
"""
from alembic import op
import sqlalchemy as sa
from pgadmin.model import db
# revision identifiers, used by Alembic.
revision = 'a77a0932a568'
down_revision = '35f29b1701bd'
branch_labels = None
depends_on = None
def upgrade():
# To Save previous data
db.engine.execute("ALTER TABLE server RENAME TO server_old")
# Create table with drop constraint for port and username definition
db.engine.execute("""
CREATE TABLE server (
id INTEGER NOT NULL,
user_id INTEGER NOT NULL,
servergroup_id INTEGER NOT NULL,
name VARCHAR(128) NOT NULL,
host VARCHAR(128),
port INTEGER,
maintenance_db VARCHAR(64) NOT NULL,
username VARCHAR(64),
password VARCHAR(64),
role VARCHAR(64),
ssl_mode VARCHAR(16) NOT NULL CHECK(ssl_mode IN
( 'allow' , 'prefer' , 'require' , 'disable' ,
'verify-ca' , 'verify-full' )
),
comment VARCHAR(1024),
discovery_id VARCHAR(128),
hostaddr TEXT(1024),
db_res TEXT,
passfile TEXT,
sslcert TEXT,
sslkey TEXT,
sslrootcert TEXT,
sslcrl TEXT,
sslcompression INTEGER DEFAULT 0,
bgcolor TEXT(10),
fgcolor TEXT(10),
service TEXT,
use_ssh_tunnel INTEGER DEFAULT 0,
tunnel_host TEXT,
tunnel_port TEXT,
tunnel_username TEXT,
tunnel_authentication INTEGER DEFAULT 0,
tunnel_identity_file TEXT, connect_timeout INTEGER DEFAULT 0, tunnel_password TEXT(64),
PRIMARY KEY(id),
FOREIGN KEY(user_id) REFERENCES user(id),
FOREIGN KEY(servergroup_id) REFERENCES servergroup(id)
)
""")
# Copy old data again into table
db.engine.execute("""
INSERT INTO server (
id, user_id, servergroup_id, name, host, port, maintenance_db,
username, password, role, ssl_mode, comment, discovery_id, hostaddr,
db_res, passfile, sslcert, sslkey, sslrootcert, sslcrl,
sslcompression, bgcolor, fgcolor, service, use_ssh_tunnel,
tunnel_host, tunnel_port, tunnel_username, tunnel_authentication,
tunnel_identity_file
) SELECT
id, user_id, servergroup_id, name, host, port, maintenance_db,
username, password, role, ssl_mode, comment, discovery_id, hostaddr,
db_res, passfile, sslcert, sslkey, sslrootcert, sslcrl,
sslcompression, bgcolor, fgcolor, service, use_ssh_tunnel,
tunnel_host, tunnel_port, tunnel_username, tunnel_authentication,
tunnel_identity_file
FROM server_old""")
# Remove old data
db.engine.execute("DROP TABLE server_old")
def downgrade():
pass

View File

@ -723,9 +723,8 @@ class ServerNode(PGChildNodeView):
"""Add a server node to the settings database"""
required_args = [
u'name',
u'port',
u'db',
u'sslmode',
u'username'
]
data = request.form if request.form else json.loads(
@ -741,7 +740,8 @@ class ServerNode(PGChildNodeView):
if 'service' in data and not data['service']:
required_args.extend([
u'host',
u'db',
u'port',
u'username',
u'role'
])
for arg in required_args:

View File

@ -36,12 +36,12 @@ export class ModelValidation {
this.checkHostAndHostAddress();
this.checkForEmpty('db', gettext('Maintenance database must be specified.'));
} else {
this.clearHostAddressAndDbErrors();
}
this.checkForEmpty('username', gettext('Username must be specified.'));
this.checkForEmpty('port', gettext('Port must be specified.'));
} else {
this.checkForEmpty('db', gettext('Maintenance database must be specified.'));
this.clearHostAddressAndDbErrors();
}
if (this.model.get('use_ssh_tunnel')) {
this.checkForEmpty('tunnel_host', gettext('SSH Tunnel host must be specified.'));
@ -73,7 +73,7 @@ export class ModelValidation {
}
clearHostAddressAndDbErrors() {
_.each(['host', 'hostaddr', 'db'], (item) => {
_.each(['host', 'hostaddr', 'db', 'username', 'port'], (item) => {
this.setNullValueForEmptyString(item);
this.model.errorModel.unset(item);
});

View File

@ -47,9 +47,10 @@ describe('Server#ModelValidation', () => {
});
});
describe('Service id present', () => {
describe('Service id and Maintenance database present', () => {
it('does not set any error in the model', () => {
model.allValues['service'] = 'asdfg';
model.allValues['db'] = 'postgres';
expect(modelValidation.validate()).toBeNull();
expect(model.errorModel.set).toHaveBeenCalledWith({});
});
@ -147,14 +148,12 @@ describe('Server#ModelValidation', () => {
});
describe('Service id present', () => {
it('does not set any error in the model', () => {
it('set the "Maintenance database must be specified." error', () => {
model.allValues['name'] = 'some name';
model.allValues['service'] = 'asdfg';
expect(modelValidation.validate()).toEqual('Name must be specified.');
expect(model.errorModel.set).toHaveBeenCalledTimes(1);
expect(modelValidation.validate()).toEqual('Maintenance database must be specified.');
expect(model.errorModel.set).toHaveBeenCalledWith({
name: 'Name must be specified.',
username: 'Username must be specified.',
port: 'Port must be specified.',
db: 'Maintenance database must be specified.',
});
});
});