From 9a6516a8b3f1875424459d129edf8e92109ab11d Mon Sep 17 00:00:00 2001 From: Aditya Toshniwal Date: Fri, 23 Sep 2022 11:19:48 +0530 Subject: [PATCH] Ensure that the query tool creates a new tab with the appropriate user when pressing Alt+Shift+Q. #5210 (#5350) --- docs/en_US/release_notes_6_15.rst | 5 ++-- web/pgadmin/tools/sqleditor/__init__.py | 28 ++++++++++--------- .../sqleditor/static/js/SQLEditorModule.js | 26 +++++++++-------- .../js/components/QueryToolComponent.jsx | 23 +++++++++------ .../js/components/sections/ConnectionBar.jsx | 4 +-- .../sqleditor/static/js/show_query_tool.js | 9 +++--- .../sqleditor/static/js/show_view_data.js | 2 +- 7 files changed, 54 insertions(+), 43 deletions(-) diff --git a/docs/en_US/release_notes_6_15.rst b/docs/en_US/release_notes_6_15.rst index 1d9fde207..43187fa46 100644 --- a/docs/en_US/release_notes_6_15.rst +++ b/docs/en_US/release_notes_6_15.rst @@ -25,7 +25,8 @@ Housekeeping Bug fixes ********* + | `Issue #5188 `_ - Ensure that the continue/start button should be disabled if the user stops the Debugger for the procedures. + | `Issue #5210 `_ - Ensure that the query tool creates a new tab with the appropriate user when pressing Alt+Shift+Q. | `Issue #5249 `_ - Added the ability to display the selected text from the query tool in the find/replace box. | `Issue #5262 `_ - Ensure that the user management dialog should not allow the same email addresses with different letter casings when creating users. - | `Issue #5308 `_ - Ensure that the default value for a column should be used if it is made empty. - | `Issue #5188 `_ - Ensure that the continue/start button should be disabled if the user stops the Debugger for the procedures. + | `Issue #5308 `_ - Ensure that the default value for a column should be used if it is made empty. \ No newline at end of file diff --git a/web/pgadmin/tools/sqleditor/__init__.py b/web/pgadmin/tools/sqleditor/__init__.py index 92b7cfa60..bce3e3987 100644 --- a/web/pgadmin/tools/sqleditor/__init__.py +++ b/web/pgadmin/tools/sqleditor/__init__.py @@ -284,14 +284,9 @@ def panel(trans_id): if request.args: params = {k: v for k, v in request.args.items()} - close_url = '' if request.form: - params['title'] = request.form['title'] - close_url = request.form['close_url'] - if 'sql_filter' in request.form: - params['sql_filter'] = request.form['sql_filter'] - if 'query_url' in request.form: - params['query_url'] = request.form['query_url'] + for key, val in request.form.items(): + params[key] = val params['trans_id'] = trans_id @@ -318,7 +313,8 @@ def panel(trans_id): params['fgcolor'] = s.fgcolor or 'black' params['server_name'] = underscore_escape(s.name) - params['username'] = underscore_escape(s.username) + if 'user' not in params: + params['user'] = underscore_escape(s.username) params['layout'] = get_setting('SQLEditor/Layout') params['macros'] = get_user_macros() params['is_desktop_mode'] = current_app.PGADMIN_RUNTIME @@ -327,7 +323,6 @@ def panel(trans_id): return render_template( "sqleditor/index.html", - close_url=close_url, title=underscore_unescape(params['title']), params=json.dumps(params), requirejs=True, @@ -359,15 +354,21 @@ def initialize_sqleditor(trans_id, sgid, sid, did=None): # Read the data if present. Skipping read may cause connection # reset error if data is sent from the client if request.data: - _ = request.data + data = json.loads(request.data, encoding='utf-8') req_args = request.args if ('recreate' in req_args and req_args['recreate'] == '1'): connect = False + kwargs = { + 'user': data['user'] if 'user' in data else None, + 'role': data['role'] if 'role' in data else None, + 'password': None + } + is_error, errmsg, conn_id, version = _init_sqleditor( - trans_id, connect, sgid, sid, did) + trans_id, connect, sgid, sid, did, **kwargs) if is_error: return errmsg @@ -2437,8 +2438,9 @@ def clear_query_history(trans_id): status, error_msg, conn, trans_obj, session_ob = \ check_transaction_status(trans_id) - filter = request.get_json(silent=True) - return QueryHistory.clear(current_user.id, trans_obj.sid, conn.db, filter) + filter_json = request.get_json(silent=True) + return QueryHistory.clear(current_user.id, trans_obj.sid, conn.db, + filter_json) @blueprint.route( diff --git a/web/pgadmin/tools/sqleditor/static/js/SQLEditorModule.js b/web/pgadmin/tools/sqleditor/static/js/SQLEditorModule.js index 78159996f..1b15131e4 100644 --- a/web/pgadmin/tools/sqleditor/static/js/SQLEditorModule.js +++ b/web/pgadmin/tools/sqleditor/static/js/SQLEditorModule.js @@ -13,7 +13,6 @@ import * as toolBar from 'pgadmin.browser.toolbar'; import * as panelTitleFunc from './sqleditor_title'; import * as commonUtils from 'sources/utils'; import $ from 'jquery'; -import url_for from 'sources/url_for'; import _ from 'lodash'; import pgWindow from 'sources/window'; import pgAdmin from 'sources/pgadmin'; @@ -258,7 +257,7 @@ export default class SQLEditor { } - openQueryToolPanel(trans_id, is_query_tool, panel_title, closeUrl, queryToolForm) { + openQueryToolPanel(trans_id, is_query_tool, panel_title, queryToolForm) { let self = this; let browser_preferences = pgBrowser.get_preferences_for_module('browser'); let propertiesPanel = pgBrowser.docker.findPanels('properties'); @@ -310,21 +309,24 @@ export default class SQLEditor { openQueryToolURL(queryToolPanel); } - launch(trans_id, panel_url, is_query_tool, panel_title, sURL=null, sql_filter=null) { + launch(trans_id, panel_url, is_query_tool, panel_title, params={}) { const self = this; - let closeUrl = url_for('sqleditor.close', {'trans_id': trans_id}); let queryToolForm = `
- - - `; + `; - if(sURL && typeof(sURL) === 'string'){ - queryToolForm +=``; + if(params.query_url && typeof(params.query_url) === 'string'){ + queryToolForm +=``; } - if(sql_filter) { - queryToolForm +=``; + if(params.sql_filter) { + queryToolForm +=``; + } + if(params.user) { + queryToolForm +=``; + } + if(params.role) { + queryToolForm +=``; } /* Escape backslashes as it is stripped by back end */ @@ -354,7 +356,7 @@ export default class SQLEditor { /* On successfully initialization find the dashboard panel, * create new panel and add it to the dashboard panel. */ - self.openQueryToolPanel(trans_id, is_query_tool, panel_title, closeUrl, queryToolForm); + self.openQueryToolPanel(trans_id, is_query_tool, panel_title, queryToolForm); } return true; } diff --git a/web/pgadmin/tools/sqleditor/static/js/components/QueryToolComponent.jsx b/web/pgadmin/tools/sqleditor/static/js/components/QueryToolComponent.jsx index 18293ed18..921e4bb94 100644 --- a/web/pgadmin/tools/sqleditor/static/js/components/QueryToolComponent.jsx +++ b/web/pgadmin/tools/sqleditor/static/js/components/QueryToolComponent.jsx @@ -100,14 +100,14 @@ export default function QueryToolComponent({params, pgWindow, pgAdmin, selectedN sgid: params.sgid, sid: params.sid, did: params.did, - user: _.unescape(params.username), - role: null, + user: _.unescape(params.user), + role: _.unescape(params.role), title: _.unescape(params.title), fgcolor: params.fgcolor, bgcolor: params.bgcolor, conn_title: getTitle( pgAdmin, null, selectedNodeInfo, true, _.unescape(params.server_name), _.unescape(params.database_name) || getDatabaseLabel(selectedNodeInfo), - _.unescape(params.username), params.is_query_tool == 'true' ? true : false), + _.unescape(params.role) || _.unescape(params.user), params.is_query_tool == 'true' ? true : false), server_name: _.unescape(params.server_name), database_name: _.unescape(params.database_name) || getDatabaseLabel(selectedNodeInfo), is_selected: true, @@ -259,7 +259,10 @@ export default function QueryToolComponent({params, pgWindow, pgAdmin, selectedN ...qtState.params, }); } - api.post(baseUrl, qtState.params.is_query_tool ? null : JSON.stringify(qtState.params.sql_filter)) + api.post(baseUrl, qtState.params.is_query_tool ? { + user: qtState.params.user, + role: qtState.params.role, + } : JSON.stringify(qtState.params.sql_filter)) .then(()=>{ setQtState({ connected: true, @@ -578,7 +581,7 @@ export default function QueryToolComponent({params, pgWindow, pgAdmin, selectedN sid: data.sid, did: data.did, user: data.user, - role: data.role ?? null, + role: data.role, password: data.password, title: getTitle(pgAdmin, qtState.preferences.browser, null, false, data.server_name, data.database_name, data.role || data.user, true), conn_title: getTitle(pgAdmin, null, null, true, data.server_name, data.database_name, data.role || data.user, true), @@ -629,8 +632,11 @@ export default function QueryToolComponent({params, pgWindow, pgAdmin, selectedN }; const gridUrl = showQueryTool.generateUrl(transId, parentData, null); - const title = getTitle(pgAdmin, qtState.preferences.browser, null, false, selectedConn.server_name, selectedConn.database_name, selectedConn.user); - showQueryTool.launchQueryTool(pgWindow.pgAdmin.Tools.SQLEditor, transId, gridUrl, title, ''); + const title = getTitle(pgAdmin, qtState.preferences.browser, null, false, selectedConn.server_name, selectedConn.database_name, selectedConn.role || selectedConn.user); + showQueryTool.launchQueryTool(pgWindow.pgAdmin.Tools.SQLEditor, transId, gridUrl, title, { + user: selectedConn.user, + role: selectedConn.role, + }); }; const onManageMacros = useCallback(()=>{ @@ -734,7 +740,8 @@ QueryToolComponent.propTypes = { bgcolor: PropTypes.string, fgcolor: PropTypes.string, is_query_tool: PropTypes.oneOfType([PropTypes.bool, PropTypes.string]).isRequired, - username: PropTypes.string, + user: PropTypes.string, + role: PropTypes.string, server_name: PropTypes.string, database_name: PropTypes.string, layout: PropTypes.string, diff --git a/web/pgadmin/tools/sqleditor/static/js/components/sections/ConnectionBar.jsx b/web/pgadmin/tools/sqleditor/static/js/components/sections/ConnectionBar.jsx index e3584a7b6..a2e2a7548 100644 --- a/web/pgadmin/tools/sqleditor/static/js/components/sections/ConnectionBar.jsx +++ b/web/pgadmin/tools/sqleditor/static/js/components/sections/ConnectionBar.jsx @@ -135,9 +135,9 @@ export function ConnectionBar({connected, connecting, connectionStatus, connecti onClose={()=>{setConnDropdownOpen(false);}} className={classes.menu} > - {(connectionList||[]).map((conn)=>{ + {(connectionList||[]).map((conn, i)=>{ return ( - {conn.conn_title} ); })} diff --git a/web/pgadmin/tools/sqleditor/static/js/show_query_tool.js b/web/pgadmin/tools/sqleditor/static/js/show_query_tool.js index 8ba1b42f8..142c3bec4 100644 --- a/web/pgadmin/tools/sqleditor/static/js/show_query_tool.js +++ b/web/pgadmin/tools/sqleditor/static/js/show_query_tool.js @@ -50,7 +50,6 @@ function generateTitle(pgBrowser, treeIdentifier) { } export function showQueryTool(queryToolMod, pgBrowser, url, treeIdentifier, transId) { - const sURL = url || ''; const queryToolTitle = generateTitle(pgBrowser, treeIdentifier); const currentNode = pgBrowser.tree.findNodeByDomElement(treeIdentifier); @@ -69,7 +68,7 @@ export function showQueryTool(queryToolMod, pgBrowser, url, treeIdentifier, tran } const gridUrl = generateUrl(transId, parentData); - launchQueryTool(queryToolMod, transId, gridUrl, queryToolTitle, sURL); + launchQueryTool(queryToolMod, transId, gridUrl, queryToolTitle, {query_url: url}); } export function generateScript(parentData, queryToolMod) { @@ -108,11 +107,11 @@ export function showERDSqlTool(parentData, erdSqlId, queryToolTitle, queryToolMo }; const gridUrl = generateUrl(transId, parentData, erdSqlId); - launchQueryTool(queryToolMod, transId, gridUrl, queryToolTitle, ''); + launchQueryTool(queryToolMod, transId, gridUrl, queryToolTitle, {}); } -export function launchQueryTool(queryToolMod, transId, gridUrl, queryToolTitle, sURL) { - let retVal = queryToolMod.launch(transId, gridUrl, true, queryToolTitle, sURL); +export function launchQueryTool(queryToolMod, transId, gridUrl, queryToolTitle, params) { + let retVal = queryToolMod.launch(transId, gridUrl, true, queryToolTitle, params); if(!retVal) { Notify.alert( diff --git a/web/pgadmin/tools/sqleditor/static/js/show_view_data.js b/web/pgadmin/tools/sqleditor/static/js/show_view_data.js index e8a55893b..2c5ab6ef9 100644 --- a/web/pgadmin/tools/sqleditor/static/js/show_view_data.js +++ b/web/pgadmin/tools/sqleditor/static/js/show_view_data.js @@ -165,7 +165,7 @@ function showFilterDialog(pgBrowser, treeNodeInfo, queryToolMod, transId, let helpUrl = url_for('help.static', {'filename': 'viewdata_filter.html'}); let okCallback = function() { - queryToolMod.launch(transId, gridUrl, false, queryToolTitle, null, schema._sessData.filter_sql); + queryToolMod.launch(transId, gridUrl, false, queryToolTitle, null, {sql_filter: schema._sessData.filter_sql}); }; getUtilityView(schema, treeNodeInfo, 'create', 'dialog', j[0], panel,