Fixed some SonarQube issues.

This commit is contained in:
Yogesh Mahajan 2022-08-30 14:21:33 +05:30 committed by Akshay Joshi
parent af1e9210b9
commit 71a4b20d90
10 changed files with 94 additions and 133 deletions

View File

@ -16,13 +16,62 @@ import _ from 'underscore';
import getApiInstance from 'sources/api_instance';
import { isEmptyString } from 'sources/validators';
function isTlengthEditable(state, options) {
// We will store type from selected from combobox
let of_type = state.type;
// iterating over all the types
_.each(options, function(o) {
// if type from selected from combobox matches in options
if ( of_type == o.value ) {
// if length is allowed for selected type
if(o.length)
{
// set the values in state
state.is_tlength = true;
state.min_val = o.min_val;
state.max_val = o.max_val;
} else {
// set the values in state
state.is_tlength = false;
}
}
});
return state.is_tlength;
}
function isPrecisionEditable(state, options) {
// We will store type from selected from combobox
let of_type = state.type;
// iterating over all the types
_.each(options, function(o) {
// if type from selected from combobox matches in options
if ( of_type == o.value ) {
// if precession is allowed for selected type
if(o.precision)
{
// set the values in model
state.is_precision = true;
state.min_val = o.min_val;
state.max_val = o.max_val;
} else {
// set the values in model
state.is_precision = false;
}
}
});
return state.is_precision;
}
function getTypes(nodeObj, treeNodeInfo, itemNodeData) {
return getNodeAjaxOptions('get_types', nodeObj, treeNodeInfo, itemNodeData, {
cacheLevel: 'domain'
});
}
function getCompositeSchema(nodeObj, treeNodeInfo, itemNodeData) {
return new CompositeSchema(
{
types: () => getNodeAjaxOptions('get_types', nodeObj, treeNodeInfo, itemNodeData, {
cacheLevel: 'domain'
}),
types: () => { return getTypes(nodeObj, treeNodeInfo, itemNodeData); },
collations: () => getNodeAjaxOptions('get_collations', nodeObj, treeNodeInfo, itemNodeData)
}
);
@ -126,9 +175,7 @@ function getExternalSchema(nodeObj, treeNodeInfo, itemNodeData) {
return new ExternalSchema(
{
externalFunctionsList: () => getNodeAjaxOptions('get_external_functions', nodeObj, treeNodeInfo, itemNodeData),
types: () => getNodeAjaxOptions('get_types', nodeObj, treeNodeInfo, itemNodeData, {
cacheLevel: 'domain'
})
types: () => { return getTypes(nodeObj, treeNodeInfo, itemNodeData); },
}, {
node_info: treeNodeInfo
}
@ -138,9 +185,7 @@ function getExternalSchema(nodeObj, treeNodeInfo, itemNodeData) {
function getDataTypeSchema(nodeObj, treeNodeInfo, itemNodeData) {
return new DataTypeSchema(
{
types: () => getNodeAjaxOptions('get_types', nodeObj, treeNodeInfo, itemNodeData, {
cacheLevel: 'domain'
})
types: () => { return getTypes(nodeObj, treeNodeInfo, itemNodeData); }
}
);
}
@ -877,30 +922,9 @@ class CompositeSchema extends BaseUISchema {
};
}
},
editable: (state) => {
// We will store type from selected from combobox
var of_type = state.type;
if(obj.type_options) {
// iterating over all the types
_.each(obj.type_options, function(o) {
// if type from selected from combobox matches in options
if ( of_type == o.value ) {
// if length is allowed for selected type
if(o.length)
{
// set the values in state
state.is_tlength = true;
state.min_val = o.min_val;
state.max_val = o.max_val;
} else {
// set the values in state
state.is_tlength = false;
}
}
});
}
return state.is_tlength;
},
editable: (state)=>{
return isTlengthEditable(state, obj.type_options);
}
}, {
// Note: There are ambiguities in the PG catalogs and docs between
// precision and scale. In the UI, we try to follow the docs as
@ -911,28 +935,7 @@ class CompositeSchema extends BaseUISchema {
return obj.onTypeChange(state, changeSource);
},
editable: (state) => {
// We will store type from selected from combobox
var of_type = state.type;
if(obj.type_options) {
// iterating over all the types
_.each(obj.type_options, function(o) {
// if type from selected from combobox matches in options
if ( of_type == o.value ) {
// if precession is allowed for selected type
if(o.precision)
{
// set the values in state
state.is_precision = true;
state.min_val = o.min_val;
state.max_val = o.max_val;
} else {
// set the values in state
state.is_precision = false;
}
}
});
}
return state.is_precision;
return isPrecisionEditable(state, obj.type_options);
},
}, {
id: 'collation', label: gettext('Collation'), type: 'text',
@ -1106,28 +1109,9 @@ class DataTypeSchema extends BaseUISchema {
}, 10);
return flag;
},
editable: function(state) {
// We will store type from selected from combobox
var of_type = state.type;
if (state.type_options) {
// iterating over all the types
_.each(state.type_options, function (o) {
// if type from selected from combobox matches in options
if (of_type == o.value) {
// if length is allowed for selected type
if (o.length) {
// set the values in state
state.is_tlength = true;
state.min_val = o.min_val;
state.max_val = o.max_val;
} else {
// set the values in staet
state.is_tlength = false;
}
}
});
}
return state.is_tlength;
editable: (state)=>{
let options = state.type_options;
return isTlengthEditable(state, options);
}
},{
// Note: There are ambiguities in the PG catalogs and docs between
@ -1165,28 +1149,8 @@ class DataTypeSchema extends BaseUISchema {
return flag;
},
editable: function(state) {
// We will store type from selected from combobox
var of_type = state.type;
if(state.type_options) {
// iterating over all the types
_.each(state.type_options, function(o) {
// if type from selected from combobox matches in options
if ( of_type == o.value ) {
// if precession is allowed for selected type
if(o.precision)
{
// set the values in model
state.is_precision = true;
state.min_val = o.min_val;
state.max_val = o.max_val;
} else {
// set the values in model
state.is_precision = false;
}
}
});
}
return state.is_precision;
let options = state.type_options;
return isPrecisionEditable(state, options);
},
}];
}
@ -1236,8 +1200,7 @@ export default class TypeSchema extends BaseUISchema {
}
schemaCheck(state) {
if(this.fieldOptions.node_info && 'schema' in this.fieldOptions.node_info)
{
if(this.fieldOptions.node_info && this.fieldOptions.node_info?.schema) {
if(!state)
return true;
if (this.isNew(state)) {

View File

@ -115,8 +115,8 @@ export function getUtilityView(schema, treeNodeInfo, actionType, formType, conta
console.error('error req', err.request);
} else if(err.message){
console.error('error msg', err.message);
}reject(err);
}
reject(err);
});
}

View File

@ -27,6 +27,7 @@ class CheckRoleMembershipControlFeatureTest(BaseFeatureTest):
]
role = ""
xss_test_role = "<h1>test</h1>"
def before(self):
with test_utils.Database(self.server) as (connection, _):
@ -40,10 +41,9 @@ class CheckRoleMembershipControlFeatureTest(BaseFeatureTest):
# Some test function is needed for debugger
test_utils.create_role(self.server, "postgres",
self.role)
test_utils.create_role(self.server, "postgres",
"<h1>test</h1>")
test_utils.create_role(self.server, "postgres", self.xss_test_role)
test_utils.grant_role(self.server, "postgres",
self.role, "<h1>test</h1>")
self.role, self.xss_test_role)
self.wait = WebDriverWait(self.page.driver, 20)
def runTest(self):
@ -56,8 +56,7 @@ class CheckRoleMembershipControlFeatureTest(BaseFeatureTest):
self.page.remove_server(self.server)
test_utils.drop_role(self.server, "postgres",
self.role)
test_utils.drop_role(self.server, "postgres",
"<h1>test</h1>")
test_utils.drop_role(self.server, "postgres",self.xss_test_role)
def _role_node_expandable(self, role):
retry = 3

View File

@ -84,7 +84,7 @@ define('pgadmin.misc.cloud', [
const axiosApi = getApiInstance();
let _url = url_for('cloud.clear_cloud_session');
axiosApi.post(_url)
.then(() => {})
.then(() => {/*This is intentional (SonarQube)*/})
.catch((error) => {
Notifier.error(gettext(`Error while clearing cloud wizard data: ${error.response.data.errormsg}`));
});

View File

@ -66,7 +66,7 @@ PolyLine.propTypes = {
function Multitext({currentXpos, currentYpos, label, maxWidth}) {
const theme = useTheme();
let abc = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
var xmlns = 'https://www.w3.org/2000/svg';
var xmlns = 'http://www.w3.org/2000/svg';
var svgElem = document.createElementNS(xmlns, 'svg');
svgElem.setAttributeNS(xmlns, 'height', '100%');
svgElem.setAttributeNS(xmlns, 'width', '100%');
@ -387,7 +387,7 @@ export default function Graphical({planData, ctx}) {
const onDownloadClick = ()=>{
downloadSvg(ReactDOMServer.renderToStaticMarkup(
<PlanSVG planData={planData} download={true} ctx={ctx} zoomFactor={INIT_ZOOM_FACTOR} onNodeClick={()=>{}}/>
<PlanSVG planData={planData} download={true} ctx={ctx} zoomFactor={INIT_ZOOM_FACTOR} onNodeClick={()=>{/*This is intentional (SonarQube)*/}}/>
), 'explain_plan_' + (new Date()).getTime() + '.svg');
};

View File

@ -442,27 +442,25 @@ function parsePlanData(data, ctx) {
'Triggers': [],
'Summary': {},
};
if (data && 'JIT' in data) {
if ('JIT' in data) {
retPlan['Statistics']['JIT'] = retPlan['JIT'];
}
if (data && 'Triggers' in data) {
if ('Triggers' in data) {
retPlan['Statistics']['Triggers'] = retPlan['JITriggersT'];
}
if(data) {
let summKeys = ['Planning Time', 'Execution Time'],
summary = {};
summKeys.forEach((key)=>{
if (key in data) {
summary[key] = data[key];
}
});
retPlan['Statistics']['Summary'] = summary;
}
if (data && 'Settings' in data) {
if ('Settings' in data) {
retPlan['Statistics']['Settings'] = data['Settings'];
}
let summKeys = ['Planning Time', 'Execution Time'],
summary = {};
summKeys.forEach((key)=>{
if (key in data) {
summary[key] = data[key];
}
});
retPlan['Statistics']['Summary'] = summary;
parseExplainTableData(retPlan['Plan'], ctx);
}

View File

@ -29,14 +29,14 @@ import ModalProvider from '../../../../static/js/helpers/ModalProvider';
import DebuggerComponent from './components/DebuggerComponent';
import Theme from '../../../../static/js/Theme';
export default class Debugger {
export default class DebuggerModule {
static instance;
static getInstance(...args) {
if (!Debugger.instance) {
Debugger.instance = new Debugger(...args);
if (!DebuggerModule.instance) {
DebuggerModule.instance = new DebuggerModule(...args);
}
return Debugger.instance;
return DebuggerModule.instance;
}
constructor(pgAdmin, pgBrowser) {

View File

@ -556,6 +556,7 @@ export default function QueryToolComponent({params, pgWindow, pgAdmin, selectedN
}, isNew)
);
}, ()=>{
/*This is intentional (SonarQube)*/
});
} else {
selectConn(currSelectedConn, currConnected, false);

View File

@ -386,7 +386,7 @@ UserManagementDialog.propTypes = {
onClose: PropTypes.func
};
export default function showUserManagement() {
export function showUserManagement() {
pgAdmin.Browser.Node.registerUtilityPanel();
let panel = pgAdmin.Browser.Node.addUtilityPanel(980, pgAdmin.Browser.stdH.md),
j = panel.$container.find('.obj_properties').first();

View File

@ -10,7 +10,7 @@
import pgAdmin from 'sources/pgadmin';
import gettext from 'sources/gettext';
import { showUrlDialog } from '../../../../static/js/Dialogs/index';
import showUserManagement from './UserManagementDialog';
import { showUserManagement } from './UserManagementDialog';
class UserManagement {
@ -49,4 +49,4 @@ pgAdmin.UserManagement = UserManagement.getInstance();
module.exports = {
UserManagement: UserManagement,
};
};