Fixed vulnerabilities and few design suspicions where two conditional structures are having the same implementation. Reported by SonarQube

pull/33/head
Aditya Toshniwal 2020-06-16 11:14:57 +05:30 committed by Akshay Joshi
parent 2ae5c0ec4f
commit 3e00fe2b0f
12 changed files with 23 additions and 47 deletions

View File

@ -1185,9 +1185,8 @@ class FunctionView(PGChildNodeView, DataTypeReader, SchemaDiffObjectCompare):
data['change_func'] = False
for arg in fun_change_args:
if arg == 'arguments' and arg in data and len(data[arg]) > 0:
data['change_func'] = True
elif arg in data:
if (arg == 'arguments' and arg in data and len(data[arg]) > 0)\
or arg in data:
data['change_func'] = True
# If Function Definition/Arguments are changed then merge old

View File

@ -233,11 +233,8 @@ define('pgadmin.node.schema', [
disabled: function(m) {
// We need to check additional condition to toggle enable/disable
// for table auto-vacuum
if(!m.top.inSchema.apply(this, [m]) && m.isNew()) {
return false;
} else if(!m.top.inSchema.apply(this, [m]) &&
(m.get('toast_autovacuum_enabled') === true ||
m.top.get('hastoasttable') === true)) {
if(!m.top.inSchema.apply(this, [m]) &&
(m.isNew() || (m.get('toast_autovacuum_enabled') === true || m.top.get('hastoasttable') === true))) {
return false;
}
return true;

View File

@ -164,9 +164,8 @@ def get_sql(conn, data, tid, cid=None, template_path=None):
sql = render_template("/".join([template_path, 'update.sql']),
data=data, o_data=old_data, conn=conn)
else:
if 'consrc' not in data:
return _('-- definition incomplete'), name
elif isinstance(data['consrc'], list) and len(data['consrc']) < 1:
if 'consrc' not in data or \
(isinstance(data['consrc'], list) and len(data['consrc']) < 1):
return _('-- definition incomplete'), name
sql = render_template("/".join([template_path, 'create.sql']),

View File

@ -496,15 +496,8 @@ class ExclusionConstraintView(PGChildNodeView):
data[k] = v
for arg in required_args:
if arg not in data:
return make_json_response(
status=400,
success=0,
errormsg=_(
"Could not find required parameter ({})."
).format(arg)
)
elif isinstance(data[arg], list) and len(data[arg]) < 1:
if arg not in data or \
(isinstance(data[arg], list) and len(data[arg]) < 1):
return make_json_response(
status=400,
success=0,

View File

@ -204,9 +204,9 @@ def get_sql(conn, data, did, tid, exid=None, template_path=None):
sql = render_template("/".join([template_path, 'update.sql']),
data=data, o_data=old_data)
else:
if 'columns' not in data:
return _('-- definition incomplete'), name
elif isinstance(data['columns'], list) and len(data['columns']) < 1:
if 'columns' not in data or \
(isinstance(data['columns'], list) and
len(data['columns']) < 1):
return _('-- definition incomplete'), name
sql = render_template("/".join([template_path, 'create.sql']),

View File

@ -513,15 +513,8 @@ class ForeignKeyConstraintView(PGChildNodeView):
data[k] = v
for arg in required_args:
if arg not in data:
return make_json_response(
status=400,
success=0,
errormsg=gettext(
"Could not find required parameter ({})."
).format(arg)
)
elif isinstance(data[arg], list) and len(data[arg]) < 1:
if arg not in data or \
(isinstance(data[arg], list) and len(data[arg]) < 1):
return make_json_response(
status=400,
success=0,

View File

@ -263,9 +263,9 @@ def get_sql(conn, data, tid, fkid=None, template_path=None):
"/".join([template_path, 'create_index.sql']),
data=data, conn=conn)
else:
if 'columns' not in data:
return _('-- definition incomplete'), name
elif isinstance(data['columns'], list) and len(data['columns']) < 1:
if 'columns' not in data or \
(isinstance(data['columns'], list) and
len(data['columns']) < 1):
return _('-- definition incomplete'), name
if data['autoindex'] and \

View File

@ -1057,16 +1057,14 @@ class IndexesView(PGChildNodeView, SchemaDiffObjectCompare):
for key in required_create_keys:
if key in diff_dict:
if key == 'columns' and ((
if (key == 'columns' and ((
'added' in diff_dict[key] and
len(diff_dict[key]['added']) > 0
) or ('changed' in diff_dict[key] and
len(diff_dict[key]['changed']) > 0) or (
'deleted' in diff_dict[key] and
len(diff_dict[key]['deleted']) > 0)
):
create_req = True
elif key != 'columns':
)) or key != 'columns':
create_req = True
if create_req:

View File

@ -99,9 +99,7 @@ define('pgadmin.node.index', [
type: 'text', disabled: 'checkAccessMethod',
editable: function(m) {
// Header cell then skip
if (m instanceof Backbone.Collection) {
return false;
} else if (m.inSchemaWithModelCheck.apply(this, arguments)) {
if (m instanceof Backbone.Collection || m.inSchemaWithModelCheck.apply(this, arguments)) {
return false;
}
return !(m.checkAccessMethod.apply(this, arguments));

View File

@ -134,9 +134,7 @@ define('pgadmin.node.rule', [
if (m && m.get('name') == '_RETURN') {
return true;
}
if (m.isNew()) {
return false;
} else if (m.node_info.server.version >= 90400) {
if (m.isNew() || m.node_info.server.version >= 90400) {
return false;
}
return true;

View File

@ -1129,7 +1129,7 @@ define([
// Check if unique columns provided are also in model attributes.
if (uniqueCol.length > _.intersection(columns, uniqueCol).length) {
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'));

View File

@ -25,6 +25,7 @@ class SimpleTemplateLoader(BaseLoader):
def file_as_template(file_path):
"""This method returns a jinja template for the given filepath """
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("")
return template