Skip to content

Commit fc5d9ce

Browse files
abc
1 parent 576a3cb commit fc5d9ce

18 files changed

Lines changed: 66 additions & 193 deletions

File tree

web/migrations/versions/4aa49c5d8eb1_.py

Lines changed: 0 additions & 41 deletions
This file was deleted.

web/migrations/versions/c62bcc14c3d6_.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,16 @@ def upgrade():
4040
))
4141
)
4242

43+
op.create_table(
44+
'application_state',
45+
sa.Column('uid', sa.Integer(), nullable=False),
46+
sa.Column('id', sa.Integer()),
47+
sa.Column('connection_info', sa.JSON()),
48+
sa.Column('tool_name', sa.String(length=64)),
49+
sa.Column('tool_data', sa.String()),
50+
sa.ForeignKeyConstraint(['uid'], ['user.id'], ondelete='CASCADE'),
51+
sa.PrimaryKeyConstraint('id', 'uid'))
52+
4353

4454
def downgrade():
4555
# pgAdmin only upgrades, downgrade not implemented.

web/pgadmin/authenticate/__init__.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -274,9 +274,6 @@ def authenticate(self):
274274
"""Authenticate through all the sources."""
275275
status = False
276276
msg = None
277-
username = self.form.data['email']
278-
users = User.query.filter_by(username=username).all()
279-
280277
for src in self.auth_sources:
281278
source = get_auth_sources(src)
282279
self.set_source(source)

web/pgadmin/browser/static/js/browser.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -306,20 +306,17 @@ define('pgadmin.browser', [
306306
if(res.data.success && res.data.data.result.length > 0){
307307
_.each(res.data.data.result, function(toolState){
308308
let toolNme = toolState.tool_name;
309-
let toolData = toolState.tool_data;
310309
let toolDataId = `${toolNme}-${getRandomInt(1, 9999999)}`;
311310
let connectionInfo = toolState.connection_info;
311+
localStorage.setItem(toolDataId, toolState.tool_data);
312312

313313
if (toolNme == 'sqleditor'){
314-
localStorage.setItem(toolDataId, toolData);
315314
showQueryTool.relaunchSqlTool(connectionInfo, toolDataId);
316315
}else if(toolNme == 'psql'){
317316
pgAdmin.Tools.Psql.openPsqlTool(null, null, connectionInfo);
318317
}else if(toolNme == 'ERD'){
319-
localStorage.setItem(toolDataId, toolData);
320318
pgAdmin.Tools.ERD.showErdTool(null, null, false, connectionInfo, toolDataId);
321319
}else if(toolNme == 'schema_diff'){
322-
localStorage.setItem(toolDataId, toolData);
323320
pgAdmin.Tools.SchemaDiff.launchSchemaDiff(toolDataId);
324321
}
325322
});

web/pgadmin/model/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -399,7 +399,7 @@ class ApplicationState(db.Model):
399399
primary_key=True)
400400
id = db.Column(db.Integer(),nullable=False,primary_key=True)
401401
connection_info = db.Column(MutableDict.as_mutable(types.JSON))
402-
tool_name = db.Column(db.String(), nullable=False)
402+
tool_name = db.Column(db.String(64), nullable=False)
403403
tool_data = db.Column(PgAdminDbBinaryString())
404404

405405

web/pgadmin/settings/__init__.py

Lines changed: 9 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,12 @@
1111
import os
1212
import json
1313

14-
from flask import Response, request, render_template, url_for, current_app
14+
from flask import Response, request, render_template, current_app
1515
from flask_babel import gettext
1616
from flask_login import current_user
1717

1818
from pgadmin.user_login_check import pga_login_required
19-
from pgadmin.utils import PgAdminModule
19+
from pgadmin.utils import PgAdminModule, get_complete_file_path
2020
from pgadmin.utils.ajax import make_json_response, bad_request,\
2121
success_return, internal_server_error
2222
from pgadmin.utils.menu import MenuItem
@@ -26,9 +26,6 @@
2626
from .utils import get_dialog_type, get_file_type_setting
2727
from cryptography.fernet import Fernet
2828
import hashlib
29-
from urllib.parse import unquote
30-
from pgadmin.utils.preferences import Preferences
31-
from pgadmin.utils import get_storage_directory
3229

3330
MODULE_NAME = 'settings'
3431

@@ -284,8 +281,7 @@ def save_application_state():
284281
if 'connection_info' in data else None
285282
if ('open_file_name' in connection_info and
286283
connection_info['open_file_name']):
287-
file_path = get_file_path(connection_info['open_file_name'],
288-
connection_info['storage'])
284+
file_path = get_complete_file_path(connection_info['open_file_name'])
289285
connection_info['last_saved_file_hash'] = (
290286
get_last_saved_file_hash(file_path, trans_id))
291287

@@ -323,7 +319,7 @@ def get_last_saved_file_hash(file_path, trans_id):
323319
last_saved_file_hash = connection_info['last_saved_file_hash']
324320

325321
if file_hash_update_require:
326-
last_saved_file_hash = compute_sha256_large_file(file_path)
322+
last_saved_file_hash = compute_md5_hash_file(file_path)
327323

328324
return last_saved_file_hash
329325

@@ -348,8 +344,8 @@ def get_application_state():
348344
connection_info = row.connection_info
349345
if ('open_file_name' in connection_info and
350346
connection_info['open_file_name']):
351-
file_path = get_file_path(
352-
connection_info['open_file_name'], connection_info['storage'])
347+
file_path = get_complete_file_path(
348+
connection_info['open_file_name'])
353349
file_deleted = False if os.path.exists(file_path) else True
354350
connection_info['file_deleted'] = file_deleted
355351

@@ -374,31 +370,6 @@ def get_application_state():
374370
)
375371

376372

377-
def get_file_path(file_name, storage):
378-
379-
file_path = unquote(file_name)
380-
381-
# get the current storage from request if available
382-
# or get it from last_storage preference.
383-
if storage:
384-
storage_folder = storage
385-
else:
386-
storage_folder = Preferences.module('file_manager').preference(
387-
'last_storage').get()
388-
389-
# retrieve storage directory path
390-
storage_manager_path = get_storage_directory(
391-
shared_storage=storage_folder)
392-
393-
if storage_manager_path:
394-
# generate full path of file
395-
file_path = os.path.join(
396-
storage_manager_path,
397-
file_path.lstrip('/').lstrip('\\')
398-
)
399-
return file_path
400-
401-
402373
@blueprint.route(
403374
'/delete_application_state/',
404375
methods=["DELETE"], endpoint='delete_application_state')
@@ -439,20 +410,8 @@ def delete_tool_data(trans_id=None):
439410
return False, str(e)
440411

441412

442-
def compute_sha256_large_data_in_memory(data, chunk_size=8192):
443-
"""Hash large data (in-memory) by processing in chunks."""
444-
md5_hash = hashlib.md5()
445-
# Process data in 8 KB chunks
446-
string_data = json.loads(data)
447-
for i in range(0, len(string_data), chunk_size):
448-
chunk = string_data[i:i + chunk_size]
449-
md5_hash.update(chunk.encode("utf-8"))
450-
451-
return md5_hash.hexdigest()
452-
453-
454-
def compute_sha256_large_file(file_path, chunk_size=8192):
455-
"""Compute SHA-256 hash for large files by reading in chunks."""
413+
def compute_md5_hash_file(file_path, chunk_size=8192):
414+
"""Compute md5 hash for large files by reading in chunks."""
456415
md5_hash = hashlib.md5()
457416

458417
# Open the file in binary mode
@@ -465,7 +424,7 @@ def compute_sha256_large_file(file_path, chunk_size=8192):
465424

466425

467426
def check_external_file_changes(file_path, last_saved_file_hash):
468-
current_file_hash = compute_sha256_large_file(file_path)
427+
current_file_hash = compute_md5_hash_file(file_path)
469428
if current_file_hash != last_saved_file_hash:
470429
return True
471430
return False

web/pgadmin/settings/static/ApplicationStateProvider.jsx

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,9 @@ import getApiInstance from '../../static/js/api_instance';
1212
import url_for from 'sources/url_for';
1313
import { getBrowser } from '../../static/js/utils';
1414
import usePreferences from '../../preferences/static/js/store';
15-
import { usePgAdmin } from '../../static/js/PgAdminProvider';
15+
import pgAdmin from 'sources/pgadmin';
1616

1717
const ApplicationStateContext = React.createContext();
18-
1918
export const useApplicationState = ()=>useContext(ApplicationStateContext);
2019

2120
export function getToolData(localStorageId){
@@ -24,9 +23,22 @@ export function getToolData(localStorageId){
2423
return toolDataJson;
2524
}
2625

26+
export function deleteToolData(panelId, closePanelId){
27+
const saveAppState = usePreferences.getState().getPreferencesForModule('misc')?.save_app_state;
28+
if(saveAppState){
29+
if(panelId == closePanelId){
30+
let api = getApiInstance();
31+
api.delete(
32+
url_for('settings.delete_application_state'), {data:{'panelId': panelId}}
33+
).then(()=> { /* Sonar Qube */}).catch(function(error) {
34+
pgAdmin.Browser.notifier.pgRespErrorNotify(error);
35+
});
36+
}
37+
}
38+
};
39+
2740
export function ApplicationStateProvider({children}){
2841
const preferencesStore = usePreferences();
29-
const pgAdmin = usePgAdmin();
3042
const saveAppState = preferencesStore?.getPreferencesForModule('misc')?.save_app_state;
3143
const openNewTab = preferencesStore?.getPreferencesForModule('browser')?.new_browser_tab_open;
3244

@@ -43,29 +55,17 @@ export function ApplicationStateProvider({children}){
4355
).catch((error)=>{console.error(error);});
4456
};
4557

46-
const enableSaveToolData = (toolName)=>{
58+
const isSaveToolDataEnabled = (toolName)=>{
4759
let toolMapping = {'sqleditor': 'qt', 'schema_diff': 'schema_diff', 'psql': 'psql_tool', 'ERD': 'erd_tool'};
4860
if(openNewTab?.includes(toolMapping[toolName])){
4961
return saveAppState && getBrowser().name == 'Electron';
5062
}
5163
return saveAppState;
5264
};
5365

54-
const deleteToolData = (panelId, closePanelId) =>{
55-
if(panelId == closePanelId){
56-
let api = getApiInstance();
57-
api.delete(
58-
url_for('settings.delete_application_state'), {data:{'panelId': panelId}}
59-
).then(()=> { /* Sonar Qube */}).catch(function(error) {
60-
pgAdmin.Browser.notifier.pgRespErrorNotify(error);
61-
});
62-
}
63-
};
64-
6566
const value = useMemo(()=>({
6667
saveToolData,
67-
enableSaveToolData,
68-
deleteToolData
68+
isSaveToolDataEnabled,
6969
}), []);
7070

7171
return <ApplicationStateContext.Provider value={value}>

web/pgadmin/static/js/ToolErrorView.jsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import HTMLReactParse from 'html-react-parser';
1010
const StyledBox = styled(Box)(({theme}) => ({
1111
color: theme.palette.text.primary,
1212
margin: '24px auto 12px',
13-
fontSize: '0.8rem',
1413
display: 'flex',
1514
alignItems: 'center',
1615
justifyContent: 'center',

web/pgadmin/static/js/ToolView.jsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import { BROWSER_PANELS } from '../../browser/static/js/constants';
1414
import PropTypes from 'prop-types';
1515
import LayoutIframeTab from './helpers/Layout/LayoutIframeTab';
1616
import { LAYOUT_EVENTS } from './helpers/Layout';
17-
import { useApplicationState } from '../../settings/static/ApplicationStateProvider';
17+
import { deleteToolData } from '../../settings/static/ApplicationStateProvider';
1818

1919

2020
function ToolForm({actionUrl, params}) {
@@ -40,7 +40,6 @@ ToolForm.propTypes = {
4040

4141
export default function ToolView({dockerObj}) {
4242
const pgAdmin = usePgAdmin();
43-
const {deleteToolData} = useApplicationState();
4443

4544
useEffect(()=>{
4645
pgAdmin.Browser.Events.on('pgadmin:tool:show', (panelId, toolUrl, formParams, tabParams, newTab)=>{

web/pgadmin/static/js/custom_hooks.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ export function usePrevious(value) {
7777
}
7878

7979
export function useDelayDebounce(callback, args, delay) {
80-
useEffect(() => {
80+
useEffect(() => {
8181
const delayDebounceFn = setTimeout(() => {
8282
if (args) {
8383
callback(args);

0 commit comments

Comments
 (0)