From 9c418188eeaa63306c15865955455ab71e42ec6f Mon Sep 17 00:00:00 2001 From: Nikhil Mohite Date: Wed, 10 Aug 2022 15:05:20 +0530 Subject: [PATCH] Fixed SonarQube issues. --- web/pgadmin/browser/static/js/browser.js | 3 - ...dContent.jsx => ChangePasswordContent.jsx} | 0 ...dContent.jsx => MasterPasswordContent.jsx} | 2 +- web/pgadmin/static/js/Dialogs/index.jsx | 8 +- web/pgadmin/tools/debugger/__init__.py | 92 +++++++++++-------- 5 files changed, 59 insertions(+), 46 deletions(-) rename web/pgadmin/static/js/Dialogs/{ChangePassowrdContent.jsx => ChangePasswordContent.jsx} (100%) rename web/pgadmin/static/js/Dialogs/{MasterPassowrdContent.jsx => MasterPasswordContent.jsx} (98%) diff --git a/web/pgadmin/browser/static/js/browser.js b/web/pgadmin/browser/static/js/browser.js index 60e081463..96bf6850d 100644 --- a/web/pgadmin/browser/static/js/browser.js +++ b/web/pgadmin/browser/static/js/browser.js @@ -608,9 +608,6 @@ define('pgadmin.browser', [ cancel_callback=()=>{/*This is intentional (SonarQube)*/}) { let data=null, self = this; - // data = JSON.stringify({ - // 'password': password, - // }); data = { 'password': password, }; diff --git a/web/pgadmin/static/js/Dialogs/ChangePassowrdContent.jsx b/web/pgadmin/static/js/Dialogs/ChangePasswordContent.jsx similarity index 100% rename from web/pgadmin/static/js/Dialogs/ChangePassowrdContent.jsx rename to web/pgadmin/static/js/Dialogs/ChangePasswordContent.jsx diff --git a/web/pgadmin/static/js/Dialogs/MasterPassowrdContent.jsx b/web/pgadmin/static/js/Dialogs/MasterPasswordContent.jsx similarity index 98% rename from web/pgadmin/static/js/Dialogs/MasterPassowrdContent.jsx rename to web/pgadmin/static/js/Dialogs/MasterPasswordContent.jsx index 3166616b3..dad8a1c5d 100644 --- a/web/pgadmin/static/js/Dialogs/MasterPassowrdContent.jsx +++ b/web/pgadmin/static/js/Dialogs/MasterPasswordContent.jsx @@ -87,7 +87,7 @@ export default function MasterPasswordContent({ closeModal, onResetPassowrd, onO }} > {isPWDPresent && - } + } onClick={() => {onResetPassowrd?.();}} > {gettext('Reset Master Password')} diff --git a/web/pgadmin/static/js/Dialogs/index.jsx b/web/pgadmin/static/js/Dialogs/index.jsx index d66a7d02f..7a08a76c3 100644 --- a/web/pgadmin/static/js/Dialogs/index.jsx +++ b/web/pgadmin/static/js/Dialogs/index.jsx @@ -17,8 +17,8 @@ import gettext from 'sources/gettext'; import getApiInstance from '../api_instance'; import Notify from '../helpers/Notifier'; -import MasterPasswordContent from './MasterPassowrdContent'; -import ChangePasswordContent from './ChangePassowrdContent'; +import MasterPasswordContent from './MasterPasswordContent'; +import ChangePasswordContent from './ChangePasswordContent'; import NamedRestoreContent from './NamedRestoreContent'; import ChangeOwnershipContent from './ChangeOwnershipContent'; @@ -169,7 +169,7 @@ export function checkMasterPassword(data, masterpass_callback_queue, cancel_call } // This functions is used to show the master password dialog. -export function showMasterPassword(isPWDPresent, errmsg=null, masterpass_callback_queue, cancel_callback) { +export function showMasterPassword(isPWDPresent, errmsg, masterpass_callback_queue, cancel_callback) { const api = getApiInstance(); let title = isPWDPresent ? gettext('Unlock Saved Passwords') : gettext('Set Master Password'); @@ -346,4 +346,4 @@ export function showChangeOwnership() { }, { isFullScreen: false, isResizeable: true, showFullScreen: true, isFullWidth: true, dialogWidth: pgAdmin.Browser.stdW.md, dialogHeight: pgAdmin.Browser.stdH.md}); -} \ No newline at end of file +} diff --git a/web/pgadmin/tools/debugger/__init__.py b/web/pgadmin/tools/debugger/__init__.py index 23ff9e6b6..3db12da01 100644 --- a/web/pgadmin/tools/debugger/__init__.py +++ b/web/pgadmin/tools/debugger/__init__.py @@ -1069,15 +1069,10 @@ def start_debugger_listener(trans_id): debugger_args_values = copy.deepcopy( de_inst.function_data['args_value']) for arg in debugger_args_values: - if arg['type'].endswith('[]'): - if arg['value'] and arg['value'] != 'NULL': - val_list = arg['value'][1:-1].split(',') - debugger_args_data = [] - for _val in val_list: - debugger_args_data.append({ - 'value': _val - }) - arg['value'] = debugger_args_data + if arg['type'].endswith('[]') and arg['value'] and arg[ + 'value'] != 'NULL': + val_list = arg['value'][1:-1].split(',') + arg['value'] = get_debugger_arg_val(val_list) # Below are two different template to execute and start executer if manager.server_type != 'pg' and manager.version < 90300: @@ -1175,6 +1170,16 @@ def start_debugger_listener(trans_id): return make_json_response(data={'status': status, 'result': result}) +def get_debugger_arg_val(val_list): + """Get debugger arguments is list""" + debugger_args_data = [] + for _val in val_list: + debugger_args_data.append({ + 'value': _val + }) + return debugger_args_data + + @blueprint.route( '/execute_query//', methods=['GET'], endpoint='execute_query' @@ -1483,6 +1488,17 @@ def set_clear_breakpoint(trans_id, line_no, set_type): ) +def get_debugger_template_path(de_inst): + # find the debugger version and execute the query accordingly + dbg_version = de_inst.debugger_data['debugger_version'] + if dbg_version <= 2: + template_path = DEBUGGER_SQL_V1_PATH + else: + template_path = DEBUGGER_SQL_V3_PATH + + return template_path + + @blueprint.route( '/clear_all_breakpoint/', methods=['POST'], endpoint='clear_all_breakpoint' @@ -1514,42 +1530,42 @@ def clear_all_breakpoint(trans_id): conn_id=de_inst.debugger_data['exe_conn_id']) # find the debugger version and execute the query accordingly - dbg_version = de_inst.debugger_data['debugger_version'] - if dbg_version <= 2: - template_path = DEBUGGER_SQL_V1_PATH - else: - template_path = DEBUGGER_SQL_V3_PATH + template_path = get_debugger_template_path(de_inst) status = True result = '' - if conn.connected(): - # get the data sent through post from client - if 'breakpoint_list' in json.loads(request.data): - line_numbers = [] - if json.loads(request.data)['breakpoint_list'] is not None and \ - json.loads(request.data)['breakpoint_list'] != '': - line_numbers = json.loads(request.data)[ - 'breakpoint_list'].split(",") - for line_no in line_numbers: - sql = render_template( - "/".join([template_path, "clear_breakpoint.sql"]), - session_id=de_inst.debugger_data['session_id'], - foid=de_inst.debugger_data['function_id'], - line_number=line_no - ) - - status, result = execute_dict_search_path( - conn, sql, de_inst.debugger_data['search_path']) - if not status: - return internal_server_error(errormsg=result) - result = result['rows'] - else: - return make_json_response(data={'status': False}) - else: + if not conn.connected(): status = False result = SERVER_CONNECTION_CLOSED + return make_json_response( + data={'status': status, 'result': result} + ) + + if 'breakpoint_list' in json.loads(request.data): + line_numbers = [] + if json.loads(request.data)['breakpoint_list'] is not None and \ + json.loads(request.data)['breakpoint_list'] != '': + line_numbers = json.loads(request.data)[ + 'breakpoint_list'].split(",") + + for line_no in line_numbers: + sql = render_template( + "/".join([template_path, "clear_breakpoint.sql"]), + session_id=de_inst.debugger_data['session_id'], + foid=de_inst.debugger_data['function_id'], + line_number=line_no + ) + + status, result = execute_dict_search_path( + conn, sql, de_inst.debugger_data['search_path']) + if not status: + return internal_server_error(errormsg=result) + result = result['rows'] + else: + return make_json_response(data={'status': False}) + return make_json_response( data={'status': status, 'result': result} )