Re: [INSTALLERS] pgAdmin 4: Add-on support

2018-01-04 Thread Dave Page
On Wed, Jan 3, 2018 at 1:04 PM, Ashesh Vashi 
wrote:

> Gentle Reminder. :-)
>
> FYI - I've rebased this branch from origin/master.
>

Tarball and Windows installer creation spat out the following error, then
continued anyway:

[INFO]: +++ Building the module - 'codemirror'...
[INFO]: +++ Module Built! (Name: codemirror, Time: 8093ms)
[INFO]: +++ Building the module - 'react'...
[INFO]: +++ Module Built! (Name: react, Time: 7416ms)
[INFO]: +++ Building the module - 'vendor'...
[INFO]: +++ Module Built! (Name: vendor, Time: 51483ms)
[INFO]: +++ Building the module - 'slickgrid'...
[INFO]: +++ Module Built! (Name: slickgrid, Time: 5190ms)
[INFO]: +++ Building the module - 'core'...
Error building the module - 'core' with error code: 2!
Error: Command failed: node ./node_modules/webpack/bin/webpack.js -p
--config webpack.config.js

error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this
command.
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this
command.
Adding pgadmin/static/css/generated
Adding pgadmin/static/js/generated
Adding webpack/references/core.json
Adding webpack/references/react.json
Adding webpack/references/vendor.json
~/git/pgadmin4
Creating tarball...



>
> -- Thanks, Ashesh
>
> On Wed, Dec 13, 2017 at 8:36 PM, Dave Page  wrote:
>
>> The code is broken right now - see https://redmine.postgresql
>> .org/issues/2952. Once it's fixed, I can do this, assuming I can find
>> the spare time.
>>
>
>> On Thu, Dec 7, 2017 at 4:05 PM, Ashesh Vashi <
>> ashesh.va...@enterprisedb.com> wrote:
>>
>>> Hi Dave,
>>>
>>> I've merged the master branch in the 'WEBPACK_DEVEL2' branch.
>>>
>>> In this branch, I've modified the code for adding back the support of
>>> pluggability, which was broken due to webpack changes.
>>>
>>> Would you please create the set of installers?
>>> And, share it with Fahar for doing the integration testing after these
>>> changes.
>>>
>>> --
>>>
>>> Thanks & Regards,
>>>
>>> Ashesh Vashi
>>> EnterpriseDB INDIA: Enterprise PostgreSQL Company
>>> 
>>>
>>>
>>> *http://www.linkedin.com/in/asheshvashi*
>>> 
>>>
>>
>>
>>
>> --
>> Dave Page
>> Blog: http://pgsnake.blogspot.com
>> Twitter: @pgsnake
>>
>> EnterpriseDB UK: http://www.enterprisedb.com
>> The Enterprise PostgreSQL Company
>>
>
>


-- 
Dave Page
Blog: http://pgsnake.blogspot.com
Twitter: @pgsnake

EnterpriseDB UK: http://www.enterprisedb.com
The Enterprise PostgreSQL Company


pgAdmin 4 commit: Fixed regression (typos) introduced during the 'pgadm

2018-01-04 Thread Ashesh Vashi
Fixed regression (typos) introduced during the 'pgadmin4/master' merge.

Branch
--
WEBPACK_DEVEL2

Details
---
https://git.postgresql.org/gitweb?p=pgadmin4.git;a=commitdiff;h=ae601581a9ae58b69ea7c7f4b664d248b1d7ec27

Modified Files
--
web/pgadmin/static/js/backform.pgadmin.js  | 249 ++---
web/pgadmin/tools/datagrid/static/js/datagrid.js   |   7 +-
.../tools/debugger/static/js/debugger_ui.js|   2 +-
3 files changed, 78 insertions(+), 180 deletions(-)



RM2815: Relogin to pgAdmin from sqleditor/datadrid if session exprires

2018-01-04 Thread Harshal Dhumal
Hi,

Plz find attached patch to fix session expired issue
from sqleditor/datadrid.

-- 
*Harshal Dhumal*
*Sr. Software Engineer*

EnterpriseDB India: http://www.enterprisedb.com
The Enterprise PostgreSQL Company
diff --git a/web/pgadmin/__init__.py b/web/pgadmin/__init__.py
index db676c5..220ea6b 100644
--- a/web/pgadmin/__init__.py
+++ b/web/pgadmin/__init__.py
@@ -25,7 +25,7 @@ from flask_paranoid import Paranoid
 
 from pgadmin.utils import PgAdminModule, driver
 from pgadmin.utils.versioned_template_loader import VersionedTemplateLoader
-from pgadmin.utils.session import create_session_interface
+from pgadmin.utils.session import create_session_interface, pga_unauthorised
 from werkzeug.local import LocalProxy
 from werkzeug.utils import find_modules
 
@@ -344,6 +344,9 @@ def create_app(app_name=None):
 
 security.init_app(app, user_datastore)
 
+# register custom unauthorised handler.
+app.login_manager.unauthorized_handler(pga_unauthorised)
+
 app.session_interface = create_session_interface(app)
 
 # Make the Session more secure against XSS & CSRF when running in web mode
diff --git a/web/pgadmin/browser/server_groups/servers/__init__.py b/web/pgadmin/browser/server_groups/servers/__init__.py
index 5330942..626526c 100644
--- a/web/pgadmin/browser/server_groups/servers/__init__.py
+++ b/web/pgadmin/browser/server_groups/servers/__init__.py
@@ -202,6 +202,9 @@ class ServerModule(sg.ServerGroupPluginModule):
 """
 ServerType.register_preferences()
 
+def get_exposed_url_endpoints(self):
+return ['NODE-server.connect_id']
+
 
 class ServerMenuItem(MenuItem):
 def __init__(self, **kwargs):
diff --git a/web/pgadmin/tools/datagrid/__init__.py b/web/pgadmin/tools/datagrid/__init__.py
index 6b1d699..75f63d7 100644
--- a/web/pgadmin/tools/datagrid/__init__.py
+++ b/web/pgadmin/tools/datagrid/__init__.py
@@ -17,7 +17,6 @@ import random
 from flask import Response, url_for, session, request, make_response
 from werkzeug.useragents import UserAgent
 from flask import current_app as app
-from flask_babel import gettext
 from flask_security import login_required
 from pgadmin.tools.sqleditor.command import *
 from pgadmin.utils import PgAdminModule
@@ -27,6 +26,9 @@ from pgadmin.utils.ajax import make_json_response, bad_request, \
 from config import PG_DEFAULT_DRIVER
 from pgadmin.utils.preferences import Preferences
 from pgadmin.model import Server
+from pgadmin.utils.driver import get_driver
+from pgadmin.utils.exception import ConnectionLost
+
 
 class DataGridModule(PgAdminModule):
 """
@@ -90,11 +92,11 @@ def show_filter():
 
 
 @blueprint.route(
-'/initialize/datagrid/',
+'/initialize/datagrid//',
 methods=["PUT", "POST"], endpoint="initialize_datagrid"
 )
 @login_required
-def initialize_datagrid(cmd_type, obj_type, sid, did, obj_id):
+def initialize_datagrid(cmd_type, obj_type, sgid, sid, did, obj_id):
 """
 This method is responsible for creating an asynchronous connection.
 After creating the connection it will instantiate and initialize
@@ -104,6 +106,7 @@ def initialize_datagrid(cmd_type, obj_type, sid, did, obj_id):
 Args:
 cmd_type: Contains value for which menu item is clicked.
 obj_type: Contains type of selected object for which data grid to be render
+sgid: Server group Id
 sid: Server Id
 did: Database Id
 obj_id: Id of currently selected object
@@ -118,15 +121,26 @@ def initialize_datagrid(cmd_type, obj_type, sid, did, obj_id):
 conn_id = str(random.randint(1, 999))
 try:
 manager = get_driver(PG_DEFAULT_DRIVER).connection_manager(sid)
+# default_conn is same connection which is created when user connect to
+# database from tree
+default_conn = manager.connection(did=did)
 conn = manager.connection(did=did, conn_id=conn_id,
   use_binary_placeholder=True,
   array_to_string=True)
+except ConnectionLost as e:
+raise
 except Exception as e:
+app.logger.error(e)
 return internal_server_error(errormsg=str(e))
 
-# Connect the Server
+status, msg = default_conn.connect()
+if not status:
+app.logger.error(msg)
+return internal_server_error(errormsg=str(msg))
+
 status, msg = conn.connect()
 if not status:
+app.logger.error(msg)
 return internal_server_error(errormsg=str(msg))
 
 try:
@@ -135,10 +149,13 @@ def initialize_datagrid(cmd_type, obj_type, sid, did, obj_id):
 obj_type = 'table'
 
 # Get the object as per the object type
-command_obj = ObjectRegistry.get_object(obj_type, conn_id=conn_id, sid=sid,
-did=did, obj_id=obj_id, cmd_type=cmd_type,
+command_obj = ObjectRegistry.get_object(obj_type, conn_id=conn_id,
+sgid=sgid, sid=

Re: RM2815: Relogin to pgAdmin from sqleditor/datadrid if session exprires

2018-01-04 Thread Harshal Dhumal
Further details:

1. If session is expired and user performs any action from sqleditor that
makes ajax call
then in ajax error call back user can check and handle login related error
using code snippet.

if (pgAdmin.Browser.UserManagement.is_pga_login_required(xhr)) {
  return pgAdmin.Browser.UserManagement.pga_login();
}

Where is xhr is standard xhr or jqxhr object.

2. Similarly for connection lost (only maintenance db connection as we can
recover or reconnect other
connections if maintenance db connection is alive). It will attempt to
create/reconnect connection without
asking password (to handle passwordless connection, or saveed password  or
password from pgpass file)
If connection to database still fails then it'll prompt for password.

Code snippet:
SqlEditorController.handle_connection_lost();
 once connection lost is detected one can call handle_connection_lost() to
reconnect.

3. We maintain some additional data in session to maintain affinity between
each sqleditor/datagrid instance to backend database connection. However if
session expires and user
re-loggins then we need to first restore affinity between sqleditor to
backend database before we can start
using query tool.

Code snippet:

if(is_new_transaction_required(xhr)) {
  SqlEditorController.init_transaction();
}




-- 
*Harshal Dhumal*
*Sr. Software Engineer*

EnterpriseDB India: http://www.enterprisedb.com
The Enterprise PostgreSQL Company

On Fri, Jan 5, 2018 at 11:44 AM, Harshal Dhumal <
harshal.dhu...@enterprisedb.com> wrote:

> Hi,
>
> Plz find attached patch to fix session expired issue
> from sqleditor/datadrid.
>
> --
> *Harshal Dhumal*
> *Sr. Software Engineer*
>
> EnterpriseDB India: http://www.enterprisedb.com
> The Enterprise PostgreSQL Company
>