From e8cb9628906dcd7a4369f0d59a51a5f99c0fab0a Mon Sep 17 00:00:00 2001 From: Aditya Toshniwal Date: Wed, 16 Apr 2025 11:23:35 +0530 Subject: [PATCH] Add Cache-Control no-cache,no-store,must-revalidate header to dynamically generated utils.js file. #3688 --- docs/en_US/release_notes_9_3.rst | 1 + web/pgadmin/browser/__init__.py | 10 ++++---- web/pgadmin/misc/cloud/__init__.py | 11 --------- web/pgadmin/misc/file_manager/__init__.py | 10 -------- .../workspaces/static/js/AdHocConnection.jsx | 2 +- web/pgadmin/tools/import_export/__init__.py | 11 --------- web/pgadmin/tools/psql/__init__.py | 11 --------- web/pgadmin/tools/sqleditor/__init__.py | 23 ------------------- .../sqleditor/templates/sqleditor/filter.html | 3 --- web/pgadmin/tools/user_management/__init__.py | 5 ++-- web/pgadmin/utils/constants.py | 2 ++ 11 files changed, 12 insertions(+), 77 deletions(-) delete mode 100644 web/pgadmin/tools/sqleditor/templates/sqleditor/filter.html diff --git a/docs/en_US/release_notes_9_3.rst b/docs/en_US/release_notes_9_3.rst index b9aece942..73b43e324 100644 --- a/docs/en_US/release_notes_9_3.rst +++ b/docs/en_US/release_notes_9_3.rst @@ -31,6 +31,7 @@ Housekeeping Bug fixes ********* + | `Issue #3688 `_ - Add Cache-Control no-cache,no-store,must-revalidate header to dynamically generated utils.js file. | `Issue #5266 `_ - Fixed an issue where shift + click on rows/columns for range selection did not work in the query tool data output window. | `Issue #8443 `_ - Fixed an issue where the debugger hangs when stepping into nested function/procedure. | `Issue #8497 `_ - Fixed an issue where the scroll position in the Object Explorer was not retained when switching workspaces. diff --git a/web/pgadmin/browser/__init__.py b/web/pgadmin/browser/__init__.py index e9bd381c1..118bd5f55 100644 --- a/web/pgadmin/browser/__init__.py +++ b/web/pgadmin/browser/__init__.py @@ -61,7 +61,7 @@ from pgadmin.utils.master_password import validate_master_password, \ from pgadmin.model import User, db from pgadmin.utils.constants import MIMETYPE_APP_JS, PGADMIN_NODE, \ INTERNAL, KERBEROS, LDAP, QT_DEFAULT_PLACEHOLDER, OAUTH2, WEBSERVER, \ - VW_EDT_DEFAULT_PLACEHOLDER + VW_EDT_DEFAULT_PLACEHOLDER, NO_CACHE_CONTROL from pgadmin.authenticate import AuthSourceManager from pgadmin.utils.exception import CryptKeyMissing @@ -526,7 +526,7 @@ def utils(): shared_storage_list, \ restricted_shared_storage_list = get_shared_storage_list() - return make_response( + response = make_response( render_template( 'browser/js/utils.js', layout=layout, @@ -562,8 +562,10 @@ def utils(): "Administrator") else restricted_shared_storage_list, enable_server_passexec_cmd=config.ENABLE_SERVER_PASS_EXEC_CMD, max_server_tags_allowed=config.MAX_SERVER_TAGS_ALLOWED, - ), - 200, {'Content-Type': MIMETYPE_APP_JS}) + ), 200) + response.headers['Content-Type'] = MIMETYPE_APP_JS + response.headers['Cache-Control'] = NO_CACHE_CONTROL + return response @blueprint.route("/js/endpoints.js") diff --git a/web/pgadmin/misc/cloud/__init__.py b/web/pgadmin/misc/cloud/__init__.py index 485ff5488..acfeabd6e 100644 --- a/web/pgadmin/misc/cloud/__init__.py +++ b/web/pgadmin/misc/cloud/__init__.py @@ -89,17 +89,6 @@ def index(): ) -@blueprint.route("/cloud.js") -@pga_login_required -def script(): - """render own javascript""" - res = Response(response=render_template( - "cloud/js/cloud.js", _=gettext), - status=200, - mimetype=MIMETYPE_APP_JS) - return res - - @blueprint.route('/clear_cloud_session/', methods=['POST'], endpoint='clear_cloud_session') @pga_login_required diff --git a/web/pgadmin/misc/file_manager/__init__.py b/web/pgadmin/misc/file_manager/__init__.py index 10d11f015..6a3754bfb 100644 --- a/web/pgadmin/misc/file_manager/__init__.py +++ b/web/pgadmin/misc/file_manager/__init__.py @@ -192,16 +192,6 @@ def index(): ) -@blueprint.route("/utility.js") -@pga_login_required -def utility(): - """render the required javascript""" - return Response(response=render_template( - "file_manager/js/utility.js", _=gettext), - status=200, - mimetype=MIMETYPE_APP_JS) - - @blueprint.route( "/init", methods=["POST"], endpoint='init' ) diff --git a/web/pgadmin/misc/workspaces/static/js/AdHocConnection.jsx b/web/pgadmin/misc/workspaces/static/js/AdHocConnection.jsx index 7e3ac8546..0edad860e 100644 --- a/web/pgadmin/misc/workspaces/static/js/AdHocConnection.jsx +++ b/web/pgadmin/misc/workspaces/static/js/AdHocConnection.jsx @@ -93,7 +93,7 @@ class AdHocConnectionSchema extends BaseUISchema { this.api.get(url_for('sqleditor.get_new_connection_servers')) .then(({data: respData})=>{ // Sort the server list - respData.data.result.server_list.Servers.sort(function (a, b) { + respData.data.result.server_list.Servers?.sort(function (a, b) { return obj.pgAdmin.natural_sort(a.label, b.label); }); let groupedOptions = []; diff --git a/web/pgadmin/tools/import_export/__init__.py b/web/pgadmin/tools/import_export/__init__.py index 833d2d134..e3bdd963f 100644 --- a/web/pgadmin/tools/import_export/__init__.py +++ b/web/pgadmin/tools/import_export/__init__.py @@ -142,17 +142,6 @@ def index(): return bad_request(errormsg=_("This URL cannot be called directly.")) -@blueprint.route("/js/import_export.js") -@pga_login_required -def script(): - """render the import/export javascript file""" - return Response( - response=render_template("import_export/js/import_export.js", _=_), - status=200, - mimetype=MIMETYPE_APP_JS - ) - - def _get_ignored_column_list(data, driver, conn): """ Get list of ignored columns for import/export. diff --git a/web/pgadmin/tools/psql/__init__.py b/web/pgadmin/tools/psql/__init__.py index a7abdfd88..9ac05f89f 100644 --- a/web/pgadmin/tools/psql/__init__.py +++ b/web/pgadmin/tools/psql/__init__.py @@ -72,17 +72,6 @@ class PSQLModule(PgAdminModule): blueprint = PSQLModule('psql', __name__, static_url_path='/static') -@blueprint.route("/psql.js") -@pga_login_required -def script(): - """render the required javascript""" - return Response( - response=render_template("psql/js/psql.js", _=gettext), - status=200, - mimetype=MIMETYPE_APP_JS - ) - - @blueprint.route('/panel/', methods=["POST"], endpoint="panel") diff --git a/web/pgadmin/tools/sqleditor/__init__.py b/web/pgadmin/tools/sqleditor/__init__.py index 0a6ecf03d..9ca2859b2 100644 --- a/web/pgadmin/tools/sqleditor/__init__.py +++ b/web/pgadmin/tools/sqleditor/__init__.py @@ -108,7 +108,6 @@ class SqlEditorModule(PgAdminModule): 'sqleditor.initialize_sqleditor', 'sqleditor.initialize_sqleditor_with_did', 'sqleditor.filter_validate', - 'sqleditor.filter', 'sqleditor.panel', 'sqleditor.close', 'sqleditor.update_sqleditor_connection', @@ -179,12 +178,6 @@ def index(): ) -@blueprint.route("/filter", endpoint='filter') -@pga_login_required -def show_filter(): - return render_template(MODULE_NAME + '/filter.html') - - @blueprint.route( '/initialize/viewdata////' '///', @@ -1979,22 +1972,6 @@ def auto_complete(trans_id): return make_json_response(data={'status': status, 'result': res}) -@blueprint.route("/sqleditor.js") -@pga_login_required -def script(): - """render the required javascript""" - return Response( - response=render_template( - "sqleditor/js/sqleditor.js", - tab_size=blueprint.tab_size.get(), - use_spaces=blueprint.use_spaces.get(), - _=gettext - ), - status=200, - mimetype=MIMETYPE_APP_JS - ) - - @blueprint.route('/load_file/', methods=["PUT", "POST"], endpoint='load_file') @pga_login_required def load_file(): diff --git a/web/pgadmin/tools/sqleditor/templates/sqleditor/filter.html b/web/pgadmin/tools/sqleditor/templates/sqleditor/filter.html deleted file mode 100644 index 14ccb04ae..000000000 --- a/web/pgadmin/tools/sqleditor/templates/sqleditor/filter.html +++ /dev/null @@ -1,3 +0,0 @@ -
- -
diff --git a/web/pgadmin/tools/user_management/__init__.py b/web/pgadmin/tools/user_management/__init__.py index 3270ec41c..07060ced6 100644 --- a/web/pgadmin/tools/user_management/__init__.py +++ b/web/pgadmin/tools/user_management/__init__.py @@ -28,7 +28,7 @@ from pgadmin.utils.ajax import make_response as ajax_response, \ make_json_response, bad_request, internal_server_error from pgadmin.utils.csrf import pgCSRFProtect from pgadmin.utils.constants import MIMETYPE_APP_JS, INTERNAL, \ - SUPPORTED_AUTH_SOURCES + SUPPORTED_AUTH_SOURCES, NO_CACHE_CONTROL from pgadmin.utils.validation_utils import validate_email from pgadmin.model import db, Role, User, UserPreference, Server, \ ServerGroup, Process, Setting, roles_users, SharedServer @@ -99,7 +99,6 @@ def index(): @pgCSRFProtect.exempt @pga_login_required def current_user_info(): - current_user.has_permission return Response( response=render_template( "user_management/js/current_user.js", @@ -127,7 +126,7 @@ def current_user_info(): for p in r.get_permissions()}) ), headers={ - 'Cache-Control': 'no-cache, no-store, must-revalidate' + 'Cache-Control': NO_CACHE_CONTROL }, status=200, mimetype=MIMETYPE_APP_JS diff --git a/web/pgadmin/utils/constants.py b/web/pgadmin/utils/constants.py index 7534498c8..2ee659441 100644 --- a/web/pgadmin/utils/constants.py +++ b/web/pgadmin/utils/constants.py @@ -15,6 +15,8 @@ MIMETYPE_APP_HTML = 'text/html' MIMETYPE_APP_JS = 'application/javascript' MIMETYPE_APP_JSON = 'application/json' +NO_CACHE_CONTROL = 'no-cache, no-store, must-revalidate' + # Preference labels PREF_LABEL_KEYBOARD_SHORTCUTS = gettext('Keyboard shortcuts') PREF_LABEL_DISPLAY = gettext('Display')