From 71a4b20d904248b53bf3d3f9dd459be10a1fc533 Mon Sep 17 00:00:00 2001 From: Yogesh Mahajan Date: Tue, 30 Aug 2022 14:21:33 +0530 Subject: [PATCH] Fixed some SonarQube issues. --- .../schemas/types/static/js/type.ui.js | 165 +++++++----------- .../browser/static/js/utility_view.jsx | 4 +- .../xss_checks_roles_control_test.py | 9 +- web/pgadmin/misc/cloud/static/js/cloud.js | 2 +- web/pgadmin/static/js/Explain/Graphical.jsx | 4 +- web/pgadmin/static/js/Explain/index.jsx | 28 ++- .../debugger/static/js/DebuggerModule.js | 8 +- .../js/components/QueryToolComponent.jsx | 1 + .../static/js/UserManagementDialog.jsx | 2 +- .../static/js/user_management.js | 4 +- 10 files changed, 94 insertions(+), 133 deletions(-) diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/types/static/js/type.ui.js b/web/pgadmin/browser/server_groups/servers/databases/schemas/types/static/js/type.ui.js index d9b09db3d..92e71b1ec 100644 --- a/web/pgadmin/browser/server_groups/servers/databases/schemas/types/static/js/type.ui.js +++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/types/static/js/type.ui.js @@ -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)) { diff --git a/web/pgadmin/browser/static/js/utility_view.jsx b/web/pgadmin/browser/static/js/utility_view.jsx index 19250c2f4..afca107a2 100644 --- a/web/pgadmin/browser/static/js/utility_view.jsx +++ b/web/pgadmin/browser/static/js/utility_view.jsx @@ -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); }); } diff --git a/web/pgadmin/feature_tests/xss_checks_roles_control_test.py b/web/pgadmin/feature_tests/xss_checks_roles_control_test.py index 94fc856c5..7499f6b54 100644 --- a/web/pgadmin/feature_tests/xss_checks_roles_control_test.py +++ b/web/pgadmin/feature_tests/xss_checks_roles_control_test.py @@ -27,6 +27,7 @@ class CheckRoleMembershipControlFeatureTest(BaseFeatureTest): ] role = "" + xss_test_role = "

test

" 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", - "

test

") + test_utils.create_role(self.server, "postgres", self.xss_test_role) test_utils.grant_role(self.server, "postgres", - self.role, "

test

") + 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", - "

test

") + test_utils.drop_role(self.server, "postgres",self.xss_test_role) def _role_node_expandable(self, role): retry = 3 diff --git a/web/pgadmin/misc/cloud/static/js/cloud.js b/web/pgadmin/misc/cloud/static/js/cloud.js index e8260eee7..2d8a32542 100644 --- a/web/pgadmin/misc/cloud/static/js/cloud.js +++ b/web/pgadmin/misc/cloud/static/js/cloud.js @@ -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}`)); }); diff --git a/web/pgadmin/static/js/Explain/Graphical.jsx b/web/pgadmin/static/js/Explain/Graphical.jsx index 59137e1de..0f54ee1ec 100644 --- a/web/pgadmin/static/js/Explain/Graphical.jsx +++ b/web/pgadmin/static/js/Explain/Graphical.jsx @@ -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( - {}}/> + {/*This is intentional (SonarQube)*/}}/> ), 'explain_plan_' + (new Date()).getTime() + '.svg'); }; diff --git a/web/pgadmin/static/js/Explain/index.jsx b/web/pgadmin/static/js/Explain/index.jsx index 9f6854080..96efa3cf1 100644 --- a/web/pgadmin/static/js/Explain/index.jsx +++ b/web/pgadmin/static/js/Explain/index.jsx @@ -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); } diff --git a/web/pgadmin/tools/debugger/static/js/DebuggerModule.js b/web/pgadmin/tools/debugger/static/js/DebuggerModule.js index 3c2fe29dd..2911c6fbb 100644 --- a/web/pgadmin/tools/debugger/static/js/DebuggerModule.js +++ b/web/pgadmin/tools/debugger/static/js/DebuggerModule.js @@ -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) { diff --git a/web/pgadmin/tools/sqleditor/static/js/components/QueryToolComponent.jsx b/web/pgadmin/tools/sqleditor/static/js/components/QueryToolComponent.jsx index 3f2fe509c..18293ed18 100644 --- a/web/pgadmin/tools/sqleditor/static/js/components/QueryToolComponent.jsx +++ b/web/pgadmin/tools/sqleditor/static/js/components/QueryToolComponent.jsx @@ -556,6 +556,7 @@ export default function QueryToolComponent({params, pgWindow, pgAdmin, selectedN }, isNew) ); }, ()=>{ + /*This is intentional (SonarQube)*/ }); } else { selectConn(currSelectedConn, currConnected, false); diff --git a/web/pgadmin/tools/user_management/static/js/UserManagementDialog.jsx b/web/pgadmin/tools/user_management/static/js/UserManagementDialog.jsx index 51b2b5c3a..e107e7050 100644 --- a/web/pgadmin/tools/user_management/static/js/UserManagementDialog.jsx +++ b/web/pgadmin/tools/user_management/static/js/UserManagementDialog.jsx @@ -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(); diff --git a/web/pgadmin/tools/user_management/static/js/user_management.js b/web/pgadmin/tools/user_management/static/js/user_management.js index 07eee217a..ca7432af0 100644 --- a/web/pgadmin/tools/user_management/static/js/user_management.js +++ b/web/pgadmin/tools/user_management/static/js/user_management.js @@ -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, -}; \ No newline at end of file +};