Fix validation for external and range types. Fixes #1795

This commit is contained in:
Murtuza Zabuawala 2017-06-06 11:24:10 +01:00 committed by Dave Page
parent e6aa3e1494
commit bf06d82870
2 changed files with 87 additions and 35 deletions

View File

@ -907,7 +907,7 @@ class TypeView(PGChildNodeView, DataTypeReader):
)
# If type is range then check if subtype is defined or not
if data and data[arg] == 'r':
if data['typname'] is None:
if 'typname' not in data or data['typname'] is None:
return make_json_response(
status=410,
success=0,
@ -918,7 +918,9 @@ class TypeView(PGChildNodeView, DataTypeReader):
# If type is external then check if input/output
# conversion function is defined
if data and data[arg] == 'b':
if data['typinput'] is None or \
if 'typinput' not in data or \
'typoutput' not in data or \
data['typinput'] is None or \
data['typoutput'] is None:
return make_json_response(
status=410,
@ -1224,7 +1226,27 @@ class TypeView(PGChildNodeView, DataTypeReader):
for arg in required_args:
if arg not in data:
return " --definition incomplete"
return "-- definition incomplete"
# Additional checks go here
# If type is composite then check if it has two members
if data and data[arg] == 'c':
if len(data['composite']) < 2:
return "-- definition incomplete"
# If type is range then check if subtype is defined or not
if data and data[arg] == 'r':
if 'typname' not in data or data['typname'] is None:
return "-- definition incomplete"
# If type is external then check if input/output
# conversion function is defined
if data and data[arg] == 'b':
if 'typinput' not in data or \
'typoutput' not in data or \
data['typinput'] is None or \
data['typoutput'] is None:
return "-- definition incomplete"
# Privileges
if 'typacl' in data and data['typacl'] is not None:

View File

@ -789,42 +789,72 @@ function($, _, S, pgAdmin, pgBrowser, alertify, Backgrid) {
this.errorModel.clear();
if (_.has(changedAttrs, 'name') &&
(_.isUndefined(this.get('name'))
|| String(this.get('name')).replace(/^\s+|\s+$/g, '') == '')) {
if (
_.isUndefined(this.get('name')) ||
_.isNull(this.get('name')) ||
String(this.get('name')).replace(/^\s+|\s+$/g, '') == ''
) {
msg = '{{ _('Name cannot be empty.') }}';
this.errorModel.set('name', msg);
} else if (_.has(changedAttrs, 'schema') &&
(_.isUndefined(this.get('schema'))
|| String(this.get('schema')).replace(/^\s+|\s+$/g, '') == '')) {
msg = '{{ _('Schema cannot be empty.') }}';
this.errorModel.set('schema', msg);
} else if (_.has(changedAttrs, 'typtype') &&
(_.isUndefined(this.get('typtype'))
|| String(this.get('name')).replace(/^\s+|\s+$/g, '') == '')) {
msg = '{{ _('Type cannot be empty.') }}';
this.errorModel.set('typtype', msg);
} else if (this.get('typtype') == 'r' &&
_.has(changedAttrs, 'typname')
&& (_.isUndefined(this.get('typname'))
|| String(this.get('typname')).replace(/^\s+|\s+$/g, '') == '')) {
msg = '{{ _('Subtype name cannot be empty.') }}';
this.errorModel.set('typname', msg);
} else if (this.get('typtype') == 'x' &&
_.has(changedAttrs, 'typinput')
&& (_.isUndefined(this.get('typinput'))
|| String(this.get('typinput')).replace(/^\s+|\s+$/g, '') == '')) {
msg = '{{ _('Input function cannot be empty.') }}';
this.errorModel.set('typinput', msg);
} else if (this.get('typtype') == 'x' &&
_.has(changedAttrs, 'typoutput')
&& (_.isUndefined(this.get('typoutput'))
|| String(this.get('typoutput')).replace(/^\s+|\s+$/g, '') == '')) {
msg = '{{ _('Output function cannot be empty.') }}';
this.errorModel.set('typoutput', msg);
return msg;
}
return msg ? msg : null;
if (
_.isUndefined(this.get('schema')) ||
_.isNull(this.get('schema')) ||
String(this.get('schema')).replace(/^\s+|\s+$/g, '') == ''
) {
msg = '{{ _('Schema cannot be empty.') }}';
this.errorModel.set('schema', msg);
return msg;
}
if (
_.isUndefined(this.get('typtype')) ||
_.isNull(this.get('typtype')) ||
String(this.get('typtype')).replace(/^\s+|\s+$/g, '') == ''
) {
msg = '{{ _('Type cannot be empty.') }}';
this.errorModel.set('typtype', msg);
return msg;
}
// For Range
if(this.get('typtype') == 'r') {
if (
_.isUndefined(this.get('typname')) ||
_.isNull(this.get('typname')) ||
String(this.get('typname')).replace(/^\s+|\s+$/g, '') == ''
) {
msg = '{{ _('Subtype name cannot be empty.') }}';
this.errorModel.set('typname', msg);
return msg;
}
}
// For External
if(this.get('typtype') == 'b') {
if (
_.isUndefined(this.get('typinput')) ||
_.isNull(this.get('typinput')) ||
String(this.get('typinput')).replace(/^\s+|\s+$/g, '') == ''
) {
msg = '{{ _('Input function cannot be empty.') }}';
this.errorModel.set('typinput', msg);
return msg;
}
if (
_.isUndefined(this.get('typoutput')) ||
_.isNull(this.get('typoutput')) ||
String(this.get('typoutput')).replace(/^\s+|\s+$/g, '') == ''
) {
msg = '{{ _('Output function cannot be empty.') }}';
this.errorModel.set('typoutput', msg);
return msg;
}
}
return null;
},
// We will disable everything if we are under catalog node
inSchema: function() {