mirror of
https://github.com/pgadmin-org/pgadmin4.git
synced 2025-02-25 18:55:31 -06:00
Fixed vulnerabilities and few design suspicions where two conditional structures are having the same implementation. Reported by SonarQube
This commit is contained in:
parent
2ae5c0ec4f
commit
3e00fe2b0f
@ -1185,9 +1185,8 @@ class FunctionView(PGChildNodeView, DataTypeReader, SchemaDiffObjectCompare):
|
|||||||
|
|
||||||
data['change_func'] = False
|
data['change_func'] = False
|
||||||
for arg in fun_change_args:
|
for arg in fun_change_args:
|
||||||
if arg == 'arguments' and arg in data and len(data[arg]) > 0:
|
if (arg == 'arguments' and arg in data and len(data[arg]) > 0)\
|
||||||
data['change_func'] = True
|
or arg in data:
|
||||||
elif arg in data:
|
|
||||||
data['change_func'] = True
|
data['change_func'] = True
|
||||||
|
|
||||||
# If Function Definition/Arguments are changed then merge old
|
# If Function Definition/Arguments are changed then merge old
|
||||||
|
@ -233,11 +233,8 @@ define('pgadmin.node.schema', [
|
|||||||
disabled: function(m) {
|
disabled: function(m) {
|
||||||
// We need to check additional condition to toggle enable/disable
|
// We need to check additional condition to toggle enable/disable
|
||||||
// for table auto-vacuum
|
// for table auto-vacuum
|
||||||
if(!m.top.inSchema.apply(this, [m]) && m.isNew()) {
|
if(!m.top.inSchema.apply(this, [m]) &&
|
||||||
return false;
|
(m.isNew() || (m.get('toast_autovacuum_enabled') === true || m.top.get('hastoasttable') === true))) {
|
||||||
} else if(!m.top.inSchema.apply(this, [m]) &&
|
|
||||||
(m.get('toast_autovacuum_enabled') === true ||
|
|
||||||
m.top.get('hastoasttable') === true)) {
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
@ -164,9 +164,8 @@ def get_sql(conn, data, tid, cid=None, template_path=None):
|
|||||||
sql = render_template("/".join([template_path, 'update.sql']),
|
sql = render_template("/".join([template_path, 'update.sql']),
|
||||||
data=data, o_data=old_data, conn=conn)
|
data=data, o_data=old_data, conn=conn)
|
||||||
else:
|
else:
|
||||||
if 'consrc' not in data:
|
if 'consrc' not in data or \
|
||||||
return _('-- definition incomplete'), name
|
(isinstance(data['consrc'], list) and len(data['consrc']) < 1):
|
||||||
elif isinstance(data['consrc'], list) and len(data['consrc']) < 1:
|
|
||||||
return _('-- definition incomplete'), name
|
return _('-- definition incomplete'), name
|
||||||
|
|
||||||
sql = render_template("/".join([template_path, 'create.sql']),
|
sql = render_template("/".join([template_path, 'create.sql']),
|
||||||
|
@ -496,15 +496,8 @@ class ExclusionConstraintView(PGChildNodeView):
|
|||||||
data[k] = v
|
data[k] = v
|
||||||
|
|
||||||
for arg in required_args:
|
for arg in required_args:
|
||||||
if arg not in data:
|
if arg not in data or \
|
||||||
return make_json_response(
|
(isinstance(data[arg], list) and len(data[arg]) < 1):
|
||||||
status=400,
|
|
||||||
success=0,
|
|
||||||
errormsg=_(
|
|
||||||
"Could not find required parameter ({})."
|
|
||||||
).format(arg)
|
|
||||||
)
|
|
||||||
elif isinstance(data[arg], list) and len(data[arg]) < 1:
|
|
||||||
return make_json_response(
|
return make_json_response(
|
||||||
status=400,
|
status=400,
|
||||||
success=0,
|
success=0,
|
||||||
|
@ -204,9 +204,9 @@ def get_sql(conn, data, did, tid, exid=None, template_path=None):
|
|||||||
sql = render_template("/".join([template_path, 'update.sql']),
|
sql = render_template("/".join([template_path, 'update.sql']),
|
||||||
data=data, o_data=old_data)
|
data=data, o_data=old_data)
|
||||||
else:
|
else:
|
||||||
if 'columns' not in data:
|
if 'columns' not in data or \
|
||||||
return _('-- definition incomplete'), name
|
(isinstance(data['columns'], list) and
|
||||||
elif isinstance(data['columns'], list) and len(data['columns']) < 1:
|
len(data['columns']) < 1):
|
||||||
return _('-- definition incomplete'), name
|
return _('-- definition incomplete'), name
|
||||||
|
|
||||||
sql = render_template("/".join([template_path, 'create.sql']),
|
sql = render_template("/".join([template_path, 'create.sql']),
|
||||||
|
@ -513,15 +513,8 @@ class ForeignKeyConstraintView(PGChildNodeView):
|
|||||||
data[k] = v
|
data[k] = v
|
||||||
|
|
||||||
for arg in required_args:
|
for arg in required_args:
|
||||||
if arg not in data:
|
if arg not in data or \
|
||||||
return make_json_response(
|
(isinstance(data[arg], list) and len(data[arg]) < 1):
|
||||||
status=400,
|
|
||||||
success=0,
|
|
||||||
errormsg=gettext(
|
|
||||||
"Could not find required parameter ({})."
|
|
||||||
).format(arg)
|
|
||||||
)
|
|
||||||
elif isinstance(data[arg], list) and len(data[arg]) < 1:
|
|
||||||
return make_json_response(
|
return make_json_response(
|
||||||
status=400,
|
status=400,
|
||||||
success=0,
|
success=0,
|
||||||
|
@ -263,9 +263,9 @@ def get_sql(conn, data, tid, fkid=None, template_path=None):
|
|||||||
"/".join([template_path, 'create_index.sql']),
|
"/".join([template_path, 'create_index.sql']),
|
||||||
data=data, conn=conn)
|
data=data, conn=conn)
|
||||||
else:
|
else:
|
||||||
if 'columns' not in data:
|
if 'columns' not in data or \
|
||||||
return _('-- definition incomplete'), name
|
(isinstance(data['columns'], list) and
|
||||||
elif isinstance(data['columns'], list) and len(data['columns']) < 1:
|
len(data['columns']) < 1):
|
||||||
return _('-- definition incomplete'), name
|
return _('-- definition incomplete'), name
|
||||||
|
|
||||||
if data['autoindex'] and \
|
if data['autoindex'] and \
|
||||||
|
@ -1057,16 +1057,14 @@ class IndexesView(PGChildNodeView, SchemaDiffObjectCompare):
|
|||||||
|
|
||||||
for key in required_create_keys:
|
for key in required_create_keys:
|
||||||
if key in diff_dict:
|
if key in diff_dict:
|
||||||
if key == 'columns' and ((
|
if (key == 'columns' and ((
|
||||||
'added' in diff_dict[key] and
|
'added' in diff_dict[key] and
|
||||||
len(diff_dict[key]['added']) > 0
|
len(diff_dict[key]['added']) > 0
|
||||||
) or ('changed' in diff_dict[key] and
|
) or ('changed' in diff_dict[key] and
|
||||||
len(diff_dict[key]['changed']) > 0) or (
|
len(diff_dict[key]['changed']) > 0) or (
|
||||||
'deleted' in diff_dict[key] and
|
'deleted' in diff_dict[key] and
|
||||||
len(diff_dict[key]['deleted']) > 0)
|
len(diff_dict[key]['deleted']) > 0)
|
||||||
):
|
)) or key != 'columns':
|
||||||
create_req = True
|
|
||||||
elif key != 'columns':
|
|
||||||
create_req = True
|
create_req = True
|
||||||
|
|
||||||
if create_req:
|
if create_req:
|
||||||
|
@ -99,9 +99,7 @@ define('pgadmin.node.index', [
|
|||||||
type: 'text', disabled: 'checkAccessMethod',
|
type: 'text', disabled: 'checkAccessMethod',
|
||||||
editable: function(m) {
|
editable: function(m) {
|
||||||
// Header cell then skip
|
// Header cell then skip
|
||||||
if (m instanceof Backbone.Collection) {
|
if (m instanceof Backbone.Collection || m.inSchemaWithModelCheck.apply(this, arguments)) {
|
||||||
return false;
|
|
||||||
} else if (m.inSchemaWithModelCheck.apply(this, arguments)) {
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return !(m.checkAccessMethod.apply(this, arguments));
|
return !(m.checkAccessMethod.apply(this, arguments));
|
||||||
|
@ -134,9 +134,7 @@ define('pgadmin.node.rule', [
|
|||||||
if (m && m.get('name') == '_RETURN') {
|
if (m && m.get('name') == '_RETURN') {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (m.isNew()) {
|
if (m.isNew() || m.node_info.server.version >= 90400) {
|
||||||
return false;
|
|
||||||
} else if (m.node_info.server.version >= 90400) {
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
@ -1129,7 +1129,7 @@ define([
|
|||||||
// Check if unique columns provided are also in model attributes.
|
// Check if unique columns provided are also in model attributes.
|
||||||
if (uniqueCol.length > _.intersection(columns, uniqueCol).length) {
|
if (uniqueCol.length > _.intersection(columns, uniqueCol).length) {
|
||||||
var errorMsg = 'Developer: Unique columns [ ' + _.difference(uniqueCol, columns) + ' ] not found in collection model [ ' + columns + ' ].';
|
var errorMsg = 'Developer: Unique columns [ ' + _.difference(uniqueCol, columns) + ' ] not found in collection model [ ' + columns + ' ].';
|
||||||
alert(errorMsg);
|
throw errorMsg;
|
||||||
}
|
}
|
||||||
|
|
||||||
var collection = self.collection = self.model.get(self.field.get('name'));
|
var collection = self.collection = self.model.get(self.field.get('name'));
|
||||||
|
@ -25,6 +25,7 @@ class SimpleTemplateLoader(BaseLoader):
|
|||||||
def file_as_template(file_path):
|
def file_as_template(file_path):
|
||||||
"""This method returns a jinja template for the given filepath """
|
"""This method returns a jinja template for the given filepath """
|
||||||
file_content = open(file_path, 'r').read()
|
file_content = open(file_path, 'r').read()
|
||||||
env = Environment(loader=SimpleTemplateLoader(file_content))
|
env = Environment(loader=SimpleTemplateLoader(file_content),
|
||||||
|
autoescape=True)
|
||||||
template = env.get_template("")
|
template = env.get_template("")
|
||||||
return template
|
return template
|
||||||
|
Loading…
Reference in New Issue
Block a user