Fix various issues that could cause an exception on startup. Fixes #2713

This commit is contained in:
Harshal Dhumal 2017-10-10 09:50:47 +01:00 committed by Dave Page
parent 2f5a2b2392
commit 04beec1309
4 changed files with 38 additions and 16 deletions

View File

@ -13,9 +13,9 @@ import simplejson as json
from abc import ABCMeta, abstractmethod
import six
from flask import request, render_template, make_response, jsonify, current_app
from flask import request, jsonify
from flask_babel import gettext
from flask_security import current_user
from flask_security import current_user, login_required
from pgadmin.browser import BrowserPluginModule
from pgadmin.browser.utils import NodeView
from pgadmin.utils.ajax import make_json_response, gone, \
@ -95,6 +95,7 @@ class ServerGroupView(NodeView):
parent_ids = []
ids = [{'type': 'int', 'id': 'gid'}]
@login_required
def list(self):
res = []
@ -108,6 +109,7 @@ class ServerGroupView(NodeView):
return ajax_response(response=res, status=200)
@login_required
def delete(self, gid):
"""Delete a server group node in the settings database"""
@ -149,6 +151,7 @@ class ServerGroupView(NodeView):
return make_json_response(result=request.form)
@login_required
def update(self, gid):
"""Update the server-group properties"""
@ -195,6 +198,7 @@ class ServerGroupView(NodeView):
)
)
@login_required
def properties(self, gid):
"""Update the server-group properties"""
@ -217,6 +221,7 @@ class ServerGroupView(NodeView):
status=200
)
@login_required
def create(self):
"""Creates new server-group """
data = request.form if request.form else json.loads(
@ -261,21 +266,27 @@ class ServerGroupView(NodeView):
success=0,
errormsg=gettext('No server group name was specified'))
@login_required
def sql(self, gid):
return make_json_response(status=422)
@login_required
def modified_sql(self, gid):
return make_json_response(status=422)
@login_required
def statistics(self, gid):
return make_json_response(status=422)
@login_required
def dependencies(self, gid):
return make_json_response(status=422)
@login_required
def dependents(self, gid):
return make_json_response(status=422)
@login_required
def nodes(self, gid=None):
"""Return a JSON document listing the server groups for the user"""
nodes = []

View File

@ -13,7 +13,7 @@ import pgadmin.browser.server_groups as sg
from flask import render_template, request, make_response, jsonify, \
current_app, url_for
from flask_babel import gettext
from flask_security import current_user
from flask_security import current_user, login_required
from pgadmin.browser.server_groups.servers.types import ServerType
from pgadmin.browser.utils import PGChildNodeView
from pgadmin.utils.ajax import make_json_response, bad_request, forbidden, \
@ -73,6 +73,7 @@ class ServerModule(sg.ServerGroupPluginModule):
"""
return sg.ServerGroupModule.NODE_TYPE
@login_required
def get_nodes(self, gid):
"""Return a JSON document listing the server groups for the user"""
servers = Server.query.filter_by(user_id=current_user.id,
@ -276,6 +277,7 @@ class ServerNode(PGChildNodeView):
return flag, data
@login_required
def nodes(self, gid):
res = []
"""
@ -324,7 +326,7 @@ class ServerNode(PGChildNodeView):
return make_json_response(result=res)
@login_required
def node(self, gid, sid):
"""Return a JSON document listing the server groups for the user"""
server = Server.query.filter_by(user_id=current_user.id,
@ -371,6 +373,7 @@ class ServerNode(PGChildNodeView):
)
)
@login_required
def delete(self, gid, sid):
"""Delete a server node in the settings database."""
servers = Server.query.filter_by(user_id=current_user.id, id=sid)
@ -401,6 +404,7 @@ class ServerNode(PGChildNodeView):
return make_json_response(success=1,
info=gettext("Server deleted"))
@login_required
def update(self, gid, sid):
"""Update the server settings"""
server = Server.query.filter_by(
@ -520,6 +524,7 @@ class ServerNode(PGChildNodeView):
)
)
@login_required
def list(self, gid):
"""
Return list of attributes of all servers.
@ -561,6 +566,7 @@ class ServerNode(PGChildNodeView):
response=res
)
@login_required
def properties(self, gid, sid):
"""Return list of attributes of a server"""
server = Server.query.filter_by(
@ -615,6 +621,7 @@ class ServerNode(PGChildNodeView):
}
)
@login_required
def create(self, gid):
"""Add a server node to the settings database"""
required_args = [
@ -752,12 +759,15 @@ class ServerNode(PGChildNodeView):
errormsg=str(e)
)
@login_required
def sql(self, gid, sid):
return make_json_response(data='')
@login_required
def modified_sql(self, gid, sid):
return make_json_response(data='')
@login_required
def statistics(self, gid, sid):
manager = get_driver(PG_DEFAULT_DRIVER).connection_manager(sid)
conn = manager.connection()
@ -781,9 +791,11 @@ class ServerNode(PGChildNodeView):
)
)
@login_required
def dependencies(self, gid, sid):
return make_json_response(data='')
@login_required
def dependents(self, gid, sid):
return make_json_response(data='')

View File

@ -8,10 +8,7 @@
##########################################################################
"""A blueprint module implementing the dashboard frame."""
MODULE_NAME = 'dashboard'
from functools import wraps
from flask import render_template, url_for, Response, g
from flask_babel import gettext
from flask_security import login_required
@ -25,6 +22,8 @@ from pgadmin.utils.preferences import Preferences
from config import PG_DEFAULT_DRIVER
MODULE_NAME = 'dashboard'
class DashboardModule(PgAdminModule):
def __init__(self, *args, **kwargs):

View File

@ -1997,8 +1997,8 @@ class Driver(BaseDriver):
assert (sid is not None and isinstance(sid, int))
managers = None
if session['_id'] not in self.managers:
self.managers[session['_id']] = managers = dict()
if session.sid not in self.managers:
self.managers[session.sid] = managers = dict()
if '__pgsql_server_managers' in session:
session_managers = session['__pgsql_server_managers'].copy()
session['__pgsql_server_managers'] = dict()
@ -2013,7 +2013,7 @@ class Driver(BaseDriver):
manager._restore(session_managers[server_id])
manager.update_session()
else:
managers = self.managers[session['_id']]
managers = self.managers[session.sid]
managers['pinged'] = datetime.datetime.now()
if str(sid) not in managers:
@ -2101,9 +2101,9 @@ class Driver(BaseDriver):
manager = self.connection_manager(sid)
if manager is not None:
manager.release()
if session['_id'] in self.managers and \
str(sid) in self.managers[session['_id']]:
del self.managers[session['_id']][str(sid)]
if session.sid in self.managers and \
str(sid) in self.managers[session.sid]:
del self.managers[session.sid][str(sid)]
def gc(self):
"""
@ -2111,7 +2111,7 @@ class Driver(BaseDriver):
server for more than config.MAX_SESSION_IDLE_TIME.
"""
# Mininum session idle is 20 minutes
# Minimum session idle is 20 minutes
max_idle_time = max(config.MAX_SESSION_IDLE_TIME or 60, 20)
session_idle_timeout = datetime.timedelta(minutes=max_idle_time)
@ -2120,11 +2120,11 @@ class Driver(BaseDriver):
for sess in self.managers:
sess_mgr = self.managers[sess]
if sess == session.get('_id'):
if sess == session.sid:
sess_mgr['pinged'] = curr_time
continue
if (curr_time - sess_mgr['pinged'] >= session_idle_timeout):
if curr_time - sess_mgr['pinged'] >= session_idle_timeout:
for mgr in [m for m in sess_mgr if isinstance(m,
ServerManager)]:
mgr.release()