public inbox for [email protected]  
help / color / mirror / Atom feed
[pgAdmin][RM6385]: Backup on a shared server doesn't seem to work
6+ messages / 2 participants
[nested] [flat]

* [pgAdmin][RM6385]: Backup on a shared server doesn't seem to work
@ 2021-04-13 17:05 Pradip Parkale <[email protected]>
  2021-04-14 06:43 ` Re: [pgAdmin][RM6385]: Backup on a shared server doesn't seem to work Akshay Joshi <[email protected]>
  0 siblings, 1 reply; 6+ messages in thread

From: Pradip Parkale @ 2021-04-13 17:05 UTC (permalink / raw)
  To: pgadmin-hackers

Hi Hackers,

Please find the attached patch for #6385 Backup on a shared server doesn't
seem to work.



-- 
Thanks & Regards,
Pradip Parkale
Software Engineer | EnterpriseDB Corporation


Attachments:

  [application/octet-stream] RM6385.patch (8.6K, 3-RM6385.patch)
  download | inline diff:
diff --git a/web/pgadmin/browser/server_groups/servers/__init__.py b/web/pgadmin/browser/server_groups/servers/__init__.py
index bc0bd4611..00025196b 100644
--- a/web/pgadmin/browser/server_groups/servers/__init__.py
+++ b/web/pgadmin/browser/server_groups/servers/__init__.py
@@ -346,7 +346,7 @@ class ServerModule(sg.ServerGroupPluginModule):
                 host=data.host,
                 hostaddr=data.hostaddr,
                 port=data.port,
-                maintenance_db=None,
+                maintenance_db=data.maintenance_db,
                 username=None,
                 save_password=0,
                 ssl_mode=data.ssl_mode,
diff --git a/web/pgadmin/browser/server_groups/servers/utils.py b/web/pgadmin/browser/server_groups/servers/utils.py
index e074ea735..34892804c 100644
--- a/web/pgadmin/browser/server_groups/servers/utils.py
+++ b/web/pgadmin/browser/server_groups/servers/utils.py
@@ -12,7 +12,7 @@ from ipaddress import ip_address
 
 from pgadmin.utils.crypto import encrypt, decrypt
 import config
-from pgadmin.model import db, Server
+from pgadmin.model import db, Server, SharedServer
 
 
 def is_valid_ipaddress(address):
@@ -283,8 +283,15 @@ def does_server_exists(sid, user_id):
     # **kwargs parameter can be added to function to filter with more
     # parameters.
     try:
-        return True if Server.query.filter_by(
-            id=sid, user_id=user_id
-        ).first() is not None else False
+        if Server.query.filter_by(id=sid, user_id=user_id).first():
+            server = Server.query.filter_by(
+                id=sid, user_id=user_id
+            ).first()
+        else:
+            server = SharedServer.query.filter_by(
+                id=sid, user_id=user_id
+            ).first()
+
+        return True if server is not None else False
     except Exception:
         return False
diff --git a/web/pgadmin/tools/backup/__init__.py b/web/pgadmin/tools/backup/__init__.py
index 0d67804dd..aacb2e5d4 100644
--- a/web/pgadmin/tools/backup/__init__.py
+++ b/web/pgadmin/tools/backup/__init__.py
@@ -24,7 +24,7 @@ from pgadmin.utils import PgAdminModule, get_storage_directory, html, \
 from pgadmin.utils.ajax import make_json_response, bad_request
 
 from config import PG_DEFAULT_DRIVER
-from pgadmin.model import Server
+from pgadmin.model import Server, SharedServer
 from pgadmin.misc.bgprocess import escape_dquotes_process_arg
 from pgadmin.utils.constants import MIMETYPE_APP_JS
 
@@ -115,10 +115,15 @@ class BackupMessage(IProcessDesc):
                 self.cmd += cmd_arg(arg)
 
     def get_server_details(self):
-        # Fetch the server details like hostname, port, roles etc
-        s = Server.query.filter_by(
-            id=self.sid, user_id=current_user.id
-        ).first()
+        if Server.query.filter_by(id=self.sid,
+                                  user_id=current_user.id).first():
+            s = Server.query.filter_by(
+                id=self.sid, user_id=current_user.id
+            ).first()
+        else:
+            s = SharedServer.query.filter_by(
+                id=self.sid, user_id=current_user.id
+            ).first()
 
         from pgadmin.utils.driver import get_driver
         driver = get_driver(PG_DEFAULT_DRIVER)
@@ -417,9 +422,14 @@ def create_backup_objects_job(sid):
         return bad_request(errormsg=str(e))
 
     # Fetch the server details like hostname, port, roles etc
-    server = Server.query.filter_by(
-        id=sid, user_id=current_user.id
-    ).first()
+    if Server.query.filter_by(id=sid, user_id=current_user.id).first():
+        server = Server.query.filter_by(
+            id=sid, user_id=current_user.id
+        ).first()
+    else:
+        server = SharedServer.query.filter_by(
+            id=sid, user_id=current_user.id
+        ).first()
 
     if server is None:
         return make_json_response(
@@ -521,9 +531,14 @@ def check_utility_exists(sid, backup_obj_type):
     Returns:
         None
     """
-    server = Server.query.filter_by(
-        id=sid, user_id=current_user.id
-    ).first()
+    if Server.query.filter_by(id=sid, user_id=current_user.id).first():
+        server = Server.query.filter_by(
+            id=sid, user_id=current_user.id
+        ).first()
+    else:
+        server = SharedServer.query.filter_by(
+            id=sid, user_id=current_user.id
+        ).first()
 
     if server is None:
         return make_json_response(
diff --git a/web/pgadmin/tools/maintenance/__init__.py b/web/pgadmin/tools/maintenance/__init__.py
index cc84399b2..160573a1c 100644
--- a/web/pgadmin/tools/maintenance/__init__.py
+++ b/web/pgadmin/tools/maintenance/__init__.py
@@ -20,7 +20,7 @@ from pgadmin.utils.ajax import bad_request, make_json_response
 from pgadmin.utils.driver import get_driver
 
 from config import PG_DEFAULT_DRIVER
-from pgadmin.model import Server
+from pgadmin.model import Server, SharedServer
 from pgadmin.utils.constants import MIMETYPE_APP_JS
 
 MODULE_NAME = 'maintenance'
@@ -209,8 +209,14 @@ def create_maintenance_job(sid, did):
     index_name = get_index_name(data)
 
     # Fetch the server details like hostname, port, roles etc
-    server = Server.query.filter_by(
-        id=sid).first()
+    if Server.query.filter_by(id=sid, user_id=current_user.id).first():
+        server = Server.query.filter_by(
+            id=sid, user_id=current_user.id
+        ).first()
+    else:
+        server = SharedServer.query.filter_by(
+            id=sid, user_id=current_user.id
+        ).first()
 
     if server is None:
         return make_json_response(
@@ -300,9 +306,18 @@ def check_utility_exists(sid):
     Returns:
         None
     """
-    server = Server.query.filter_by(
-        id=sid, user_id=current_user.id
-    ).first()
+    # server = Server.query.filter_by(
+    #     id=sid, user_id=current_user.id
+    # ).first()
+
+    if Server.query.filter_by(id=sid, user_id=current_user.id).first():
+        server = Server.query.filter_by(
+            id=sid, user_id=current_user.id
+        ).first()
+    else:
+        server = SharedServer.query.filter_by(
+            id=sid, user_id=current_user.id
+        ).first()
 
     if server is None:
         return make_json_response(
diff --git a/web/pgadmin/tools/restore/__init__.py b/web/pgadmin/tools/restore/__init__.py
index ea9a3e82f..3bb9a9c5d 100644
--- a/web/pgadmin/tools/restore/__init__.py
+++ b/web/pgadmin/tools/restore/__init__.py
@@ -22,7 +22,7 @@ from pgadmin.utils import PgAdminModule, get_storage_directory, html, \
 from pgadmin.utils.ajax import make_json_response, bad_request
 
 from config import PG_DEFAULT_DRIVER
-from pgadmin.model import Server
+from pgadmin.model import Server, SharedServer
 from pgadmin.utils.constants import MIMETYPE_APP_JS
 
 # set template path for sql scripts
@@ -88,9 +88,15 @@ class RestoreMessage(IProcessDesc):
 
     def get_server_details(self):
         # Fetch the server details like hostname, port, roles etc
-        s = Server.query.filter_by(
-            id=self.sid, user_id=current_user.id
-        ).first()
+        if Server.query.filter_by(id=self.sid,
+                                  user_id=current_user.id).first():
+            s = Server.query.filter_by(
+                id=self.sid, user_id=current_user.id
+            ).first()
+        else:
+            s = SharedServer.query.filter_by(
+                id=self.sid, user_id=current_user.id
+            ).first()
 
         from pgadmin.utils.driver import get_driver
         driver = get_driver(PG_DEFAULT_DRIVER)
@@ -209,10 +215,14 @@ def _connect_server(sid):
     :param sid: Server ID.
     :return: if not error occurred then return connection data.
     """
-    # Fetch the server details like hostname, port, roles etc
-    server = Server.query.filter_by(
-        id=sid
-    ).first()
+    if Server.query.filter_by(id=sid, user_id=current_user.id).first():
+        server = Server.query.filter_by(
+            id=sid, user_id=current_user.id
+        ).first()
+    else:
+        server = SharedServer.query.filter_by(
+            id=sid, user_id=current_user.id
+        ).first()
 
     if server is None:
         return make_json_response(
@@ -466,9 +476,15 @@ def check_utility_exists(sid):
     Returns:
         None
     """
-    server = Server.query.filter_by(
-        id=sid, user_id=current_user.id
-    ).first()
+    # Fetch the server details like hostname, port, roles etc
+    if Server.query.filter_by(id=sid, user_id=current_user.id).first():
+        server = Server.query.filter_by(
+            id=sid, user_id=current_user.id
+        ).first()
+    else:
+        server = SharedServer.query.filter_by(
+            id=sid, user_id=current_user.id
+        ).first()
 
     if server is None:
         return make_json_response(


^ permalink  raw  reply  [nested|flat] 6+ messages in thread

* Re: [pgAdmin][RM6385]: Backup on a shared server doesn't seem to work
  2021-04-13 17:05 [pgAdmin][RM6385]: Backup on a shared server doesn't seem to work Pradip Parkale <[email protected]>
@ 2021-04-14 06:43 ` Akshay Joshi <[email protected]>
  2021-04-22 09:07   ` Re: [pgAdmin][RM6385]: Backup on a shared server doesn't seem to work Pradip Parkale <[email protected]>
  0 siblings, 1 reply; 6+ messages in thread

From: Akshay Joshi @ 2021-04-14 06:43 UTC (permalink / raw)
  To: Pradip Parkale <[email protected]>; +Cc: pgadmin-hackers

Thanks, patch applied.

On Tue, Apr 13, 2021 at 10:35 PM Pradip Parkale <
[email protected]> wrote:

> Hi Hackers,
>
> Please find the attached patch for #6385 Backup on a shared server doesn't
> seem to work.
>
>
>
> --
> Thanks & Regards,
> Pradip Parkale
> Software Engineer | EnterpriseDB Corporation
>


-- 
*Thanks & Regards*
*Akshay Joshi*
*pgAdmin Hacker | Principal Software Architect*
*EDB Postgres <http://edbpostgres.com>*

*Mobile: +91 976-788-8246*


^ permalink  raw  reply  [nested|flat] 6+ messages in thread

* Re: [pgAdmin][RM6385]: Backup on a shared server doesn't seem to work
  2021-04-13 17:05 [pgAdmin][RM6385]: Backup on a shared server doesn't seem to work Pradip Parkale <[email protected]>
  2021-04-14 06:43 ` Re: [pgAdmin][RM6385]: Backup on a shared server doesn't seem to work Akshay Joshi <[email protected]>
@ 2021-04-22 09:07   ` Pradip Parkale <[email protected]>
  2021-04-22 12:13     ` Re: [pgAdmin][RM6385]: Backup on a shared server doesn't seem to work Akshay Joshi <[email protected]>
  0 siblings, 1 reply; 6+ messages in thread

From: Pradip Parkale @ 2021-04-22 09:07 UTC (permalink / raw)
  To: Akshay Joshi <[email protected]>; +Cc: pgadmin-hackers

Hi Akshay,

Please find the updated patch. I did some modifications as some cases were
failing due to my initial changes.
Sorry for the inconvenience.

On Wed, Apr 14, 2021 at 12:13 PM Akshay Joshi <[email protected]>
wrote:

> Thanks, patch applied.
>
> On Tue, Apr 13, 2021 at 10:35 PM Pradip Parkale <
> [email protected]> wrote:
>
>> Hi Hackers,
>>
>> Please find the attached patch for #6385 Backup on a shared server
>> doesn't seem to work.
>>
>>
>>
>> --
>> Thanks & Regards,
>> Pradip Parkale
>> Software Engineer | EnterpriseDB Corporation
>>
>
>
> --
> *Thanks & Regards*
> *Akshay Joshi*
> *pgAdmin Hacker | Principal Software Architect*
> *EDB Postgres <http://edbpostgres.com>*
>
> *Mobile: +91 976-788-8246*
>


-- 
Thanks & Regards,
Pradip Parkale
Software Engineer | EnterpriseDB Corporation


Attachments:

  [application/x-patch] RM6385_v2.patch (11.3K, 3-RM6385_v2.patch)
  download | inline diff:
diff --git a/web/migrations/versions/c6974f64df08_.py b/web/migrations/versions/c6974f64df08_.py
new file mode 100644
index 000000000..277853631
--- /dev/null
+++ b/web/migrations/versions/c6974f64df08_.py
@@ -0,0 +1,28 @@
+
+"""empty message
+
+Revision ID: c6974f64df08
+Revises: a39bd015b644
+Create Date: 2021-04-22 10:06:21.282770
+
+"""
+from pgadmin.model import db
+
+
+
+# revision identifiers, used by Alembic.
+revision = 'c6974f64df08'
+down_revision = 'a39bd015b644'
+branch_labels = None
+depends_on = None
+
+
+def upgrade():
+    db.engine.execute(
+        'ALTER TABLE sharedserver ADD COLUMN osid INTEGER'
+    )
+
+
+def downgrade():
+    # pgAdmin only upgrades, downgrade not implemented.
+    pass
diff --git a/web/pgadmin/browser/server_groups/servers/__init__.py b/web/pgadmin/browser/server_groups/servers/__init__.py
index 00025196b..233ea07f8 100644
--- a/web/pgadmin/browser/server_groups/servers/__init__.py
+++ b/web/pgadmin/browser/server_groups/servers/__init__.py
@@ -339,6 +339,7 @@ class ServerModule(sg.ServerGroupPluginModule):
             db.session.rollback()
             user = User.query.filter_by(id=data.user_id).first()
             shared_server = SharedServer(
+                osid=data.id,
                 user_id=current_user.id,
                 server_owner=user.username,
                 servergroup_id=gid,
@@ -388,14 +389,14 @@ class ServerModule(sg.ServerGroupPluginModule):
         """
         shared_server = SharedServer.query.filter_by(
             name=server.name, user_id=current_user.id,
-            servergroup_id=gid).first()
+            servergroup_id=gid, osid=server.id).first()
 
         if shared_server is None:
             ServerModule.create_shared_server(server, gid)
 
             shared_server = SharedServer.query.filter_by(
                 name=server.name, user_id=current_user.id,
-                servergroup_id=gid).first()
+                servergroup_id=gid, osid=server.id).first()
 
         return shared_server
 
diff --git a/web/pgadmin/model/__init__.py b/web/pgadmin/model/__init__.py
index d1f498181..d849b8c26 100644
--- a/web/pgadmin/model/__init__.py
+++ b/web/pgadmin/model/__init__.py
@@ -29,7 +29,7 @@ from flask_sqlalchemy import SQLAlchemy
 #
 ##########################################################################
 
-SCHEMA_VERSION = 27
+SCHEMA_VERSION = 28
 
 ##########################################################################
 #
@@ -361,6 +361,11 @@ class SharedServer(db.Model):
 
     __tablename__ = 'sharedserver'
     id = db.Column(db.Integer, primary_key=True)
+    osid = db.Column(
+        db.Integer,
+        db.ForeignKey('server.id'),
+        nullable=False
+    )
     user_id = db.Column(
         db.Integer,
         db.ForeignKey(USER_ID)
diff --git a/web/pgadmin/tools/backup/__init__.py b/web/pgadmin/tools/backup/__init__.py
index aacb2e5d4..2e166b5b4 100644
--- a/web/pgadmin/tools/backup/__init__.py
+++ b/web/pgadmin/tools/backup/__init__.py
@@ -20,7 +20,7 @@ from flask_babelex import gettext as _
 from flask_security import login_required, current_user
 from pgadmin.misc.bgprocess.processes import BatchProcess, IProcessDesc
 from pgadmin.utils import PgAdminModule, get_storage_directory, html, \
-    fs_short_path, document_dir, does_utility_exist
+    fs_short_path, document_dir, does_utility_exist, get_server
 from pgadmin.utils.ajax import make_json_response, bad_request
 
 from config import PG_DEFAULT_DRIVER
@@ -115,15 +115,7 @@ class BackupMessage(IProcessDesc):
                 self.cmd += cmd_arg(arg)
 
     def get_server_details(self):
-        if Server.query.filter_by(id=self.sid,
-                                  user_id=current_user.id).first():
-            s = Server.query.filter_by(
-                id=self.sid, user_id=current_user.id
-            ).first()
-        else:
-            s = SharedServer.query.filter_by(
-                id=self.sid, user_id=current_user.id
-            ).first()
+        s = get_server(self.sid)
 
         from pgadmin.utils.driver import get_driver
         driver = get_driver(PG_DEFAULT_DRIVER)
@@ -422,14 +414,7 @@ def create_backup_objects_job(sid):
         return bad_request(errormsg=str(e))
 
     # Fetch the server details like hostname, port, roles etc
-    if Server.query.filter_by(id=sid, user_id=current_user.id).first():
-        server = Server.query.filter_by(
-            id=sid, user_id=current_user.id
-        ).first()
-    else:
-        server = SharedServer.query.filter_by(
-            id=sid, user_id=current_user.id
-        ).first()
+    server = get_server(sid)
 
     if server is None:
         return make_json_response(
@@ -474,7 +459,7 @@ def create_backup_objects_job(sid):
             escaped_args.append(data['database'])
             p = BatchProcess(
                 desc=BackupMessage(
-                    BACKUP.OBJECT, sid, bfile,
+                    BACKUP.OBJECT, server.id, bfile,
                     *args,
                     database=data['database']
                 ),
@@ -485,7 +470,7 @@ def create_backup_objects_job(sid):
                 desc=BackupMessage(
                     BACKUP.SERVER if backup_obj_type != 'globals'
                     else BACKUP.GLOBALS,
-                    sid, bfile,
+                    server.id, bfile,
                     *args
                 ),
                 cmd=utility, args=escaped_args
@@ -531,14 +516,7 @@ def check_utility_exists(sid, backup_obj_type):
     Returns:
         None
     """
-    if Server.query.filter_by(id=sid, user_id=current_user.id).first():
-        server = Server.query.filter_by(
-            id=sid, user_id=current_user.id
-        ).first()
-    else:
-        server = SharedServer.query.filter_by(
-            id=sid, user_id=current_user.id
-        ).first()
+    server = get_server(sid)
 
     if server is None:
         return make_json_response(
diff --git a/web/pgadmin/tools/maintenance/__init__.py b/web/pgadmin/tools/maintenance/__init__.py
index 160573a1c..378b00020 100644
--- a/web/pgadmin/tools/maintenance/__init__.py
+++ b/web/pgadmin/tools/maintenance/__init__.py
@@ -15,7 +15,7 @@ from flask import url_for, Response, render_template, request, current_app
 from flask_babelex import gettext as _
 from flask_security import login_required, current_user
 from pgadmin.misc.bgprocess.processes import BatchProcess, IProcessDesc
-from pgadmin.utils import PgAdminModule, html, does_utility_exist
+from pgadmin.utils import PgAdminModule, html, does_utility_exist, get_server
 from pgadmin.utils.ajax import bad_request, make_json_response
 from pgadmin.utils.driver import get_driver
 
@@ -209,14 +209,8 @@ def create_maintenance_job(sid, did):
     index_name = get_index_name(data)
 
     # Fetch the server details like hostname, port, roles etc
-    if Server.query.filter_by(id=sid, user_id=current_user.id).first():
-        server = Server.query.filter_by(
-            id=sid, user_id=current_user.id
-        ).first()
-    else:
-        server = SharedServer.query.filter_by(
-            id=sid, user_id=current_user.id
-        ).first()
+
+    server = get_server(sid)
 
     if server is None:
         return make_json_response(
@@ -263,7 +257,7 @@ def create_maintenance_job(sid, did):
 
     try:
         p = BatchProcess(
-            desc=Message(sid, data, query),
+            desc=Message(server.id, data, query),
             cmd=utility, args=args
         )
         manager.export_password_env(p.id)
@@ -306,18 +300,8 @@ def check_utility_exists(sid):
     Returns:
         None
     """
-    # server = Server.query.filter_by(
-    #     id=sid, user_id=current_user.id
-    # ).first()
-
-    if Server.query.filter_by(id=sid, user_id=current_user.id).first():
-        server = Server.query.filter_by(
-            id=sid, user_id=current_user.id
-        ).first()
-    else:
-        server = SharedServer.query.filter_by(
-            id=sid, user_id=current_user.id
-        ).first()
+
+    server = get_server(sid)
 
     if server is None:
         return make_json_response(
diff --git a/web/pgadmin/tools/restore/__init__.py b/web/pgadmin/tools/restore/__init__.py
index 3bb9a9c5d..94fac8046 100644
--- a/web/pgadmin/tools/restore/__init__.py
+++ b/web/pgadmin/tools/restore/__init__.py
@@ -18,7 +18,7 @@ from flask_babelex import gettext as _
 from flask_security import login_required, current_user
 from pgadmin.misc.bgprocess.processes import BatchProcess, IProcessDesc
 from pgadmin.utils import PgAdminModule, get_storage_directory, html, \
-    fs_short_path, document_dir, does_utility_exist
+    fs_short_path, document_dir, does_utility_exist, get_server
 from pgadmin.utils.ajax import make_json_response, bad_request
 
 from config import PG_DEFAULT_DRIVER
@@ -87,16 +87,9 @@ class RestoreMessage(IProcessDesc):
                 self.cmd += cmd_arg(arg)
 
     def get_server_details(self):
+
         # Fetch the server details like hostname, port, roles etc
-        if Server.query.filter_by(id=self.sid,
-                                  user_id=current_user.id).first():
-            s = Server.query.filter_by(
-                id=self.sid, user_id=current_user.id
-            ).first()
-        else:
-            s = SharedServer.query.filter_by(
-                id=self.sid, user_id=current_user.id
-            ).first()
+        s = get_server(self.sid)
 
         from pgadmin.utils.driver import get_driver
         driver = get_driver(PG_DEFAULT_DRIVER)
@@ -215,14 +208,7 @@ def _connect_server(sid):
     :param sid: Server ID.
     :return: if not error occurred then return connection data.
     """
-    if Server.query.filter_by(id=sid, user_id=current_user.id).first():
-        server = Server.query.filter_by(
-            id=sid, user_id=current_user.id
-        ).first()
-    else:
-        server = SharedServer.query.filter_by(
-            id=sid, user_id=current_user.id
-        ).first()
+    server = get_server(sid)
 
     if server is None:
         return make_json_response(
@@ -430,7 +416,7 @@ def create_restore_job(sid):
     try:
         p = BatchProcess(
             desc=RestoreMessage(
-                sid,
+                server.id,
                 data['file'].encode('utf-8') if hasattr(
                     data['file'], 'encode'
                 ) else data['file'],
@@ -477,14 +463,7 @@ def check_utility_exists(sid):
         None
     """
     # Fetch the server details like hostname, port, roles etc
-    if Server.query.filter_by(id=sid, user_id=current_user.id).first():
-        server = Server.query.filter_by(
-            id=sid, user_id=current_user.id
-        ).first()
-    else:
-        server = SharedServer.query.filter_by(
-            id=sid, user_id=current_user.id
-        ).first()
+    server = get_server(sid)
 
     if server is None:
         return make_json_response(
diff --git a/web/pgadmin/utils/__init__.py b/web/pgadmin/utils/__init__.py
index 83659a653..705e7d991 100644
--- a/web/pgadmin/utils/__init__.py
+++ b/web/pgadmin/utils/__init__.py
@@ -19,6 +19,7 @@ from threading import Lock
 
 from .paths import get_storage_directory
 from .preferences import Preferences
+from pgadmin.model import Server, SharedServer
 
 
 class PgAdminModule(Blueprint):
@@ -278,6 +279,16 @@ def does_utility_exist(file):
     return error_msg
 
 
+def get_server(sid):
+    """
+    # Fetch the server  etc
+    :param sid:
+    :return: server
+    """
+    server = Server.query.filter_by(id=sid).first()
+    return server
+
+
 # Shortcut configuration for Accesskey
 ACCESSKEY_FIELDS = [
     {


^ permalink  raw  reply  [nested|flat] 6+ messages in thread

* Re: [pgAdmin][RM6385]: Backup on a shared server doesn't seem to work
  2021-04-13 17:05 [pgAdmin][RM6385]: Backup on a shared server doesn't seem to work Pradip Parkale <[email protected]>
  2021-04-14 06:43 ` Re: [pgAdmin][RM6385]: Backup on a shared server doesn't seem to work Akshay Joshi <[email protected]>
  2021-04-22 09:07   ` Re: [pgAdmin][RM6385]: Backup on a shared server doesn't seem to work Pradip Parkale <[email protected]>
@ 2021-04-22 12:13     ` Akshay Joshi <[email protected]>
  2021-04-27 06:18       ` Re: [pgAdmin][RM6385]: Backup on a shared server doesn't seem to work Pradip Parkale <[email protected]>
  0 siblings, 1 reply; 6+ messages in thread

From: Akshay Joshi @ 2021-04-22 12:13 UTC (permalink / raw)
  To: Pradip Parkale <[email protected]>; +Cc: pgadmin-hackers

Thanks, patch applied.

On Thu, Apr 22, 2021 at 2:37 PM Pradip Parkale <
[email protected]> wrote:

> Hi Akshay,
>
> Please find the updated patch. I did some modifications as some cases were
> failing due to my initial changes.
> Sorry for the inconvenience.
>
> On Wed, Apr 14, 2021 at 12:13 PM Akshay Joshi <
> [email protected]> wrote:
>
>> Thanks, patch applied.
>>
>> On Tue, Apr 13, 2021 at 10:35 PM Pradip Parkale <
>> [email protected]> wrote:
>>
>>> Hi Hackers,
>>>
>>> Please find the attached patch for #6385 Backup on a shared server
>>> doesn't seem to work.
>>>
>>>
>>>
>>> --
>>> Thanks & Regards,
>>> Pradip Parkale
>>> Software Engineer | EnterpriseDB Corporation
>>>
>>
>>
>> --
>> *Thanks & Regards*
>> *Akshay Joshi*
>> *pgAdmin Hacker | Principal Software Architect*
>> *EDB Postgres <http://edbpostgres.com>*
>>
>> *Mobile: +91 976-788-8246*
>>
>
>
> --
> Thanks & Regards,
> Pradip Parkale
> Software Engineer | EnterpriseDB Corporation
>


-- 
*Thanks & Regards*
*Akshay Joshi*
*pgAdmin Hacker | Principal Software Architect*
*EDB Postgres <http://edbpostgres.com>*

*Mobile: +91 976-788-8246*


^ permalink  raw  reply  [nested|flat] 6+ messages in thread

* Re: [pgAdmin][RM6385]: Backup on a shared server doesn't seem to work
  2021-04-13 17:05 [pgAdmin][RM6385]: Backup on a shared server doesn't seem to work Pradip Parkale <[email protected]>
  2021-04-14 06:43 ` Re: [pgAdmin][RM6385]: Backup on a shared server doesn't seem to work Akshay Joshi <[email protected]>
  2021-04-22 09:07   ` Re: [pgAdmin][RM6385]: Backup on a shared server doesn't seem to work Pradip Parkale <[email protected]>
  2021-04-22 12:13     ` Re: [pgAdmin][RM6385]: Backup on a shared server doesn't seem to work Akshay Joshi <[email protected]>
@ 2021-04-27 06:18       ` Pradip Parkale <[email protected]>
  2021-04-27 06:29         ` Re: [pgAdmin][RM6385]: Backup on a shared server doesn't seem to work Akshay Joshi <[email protected]>
  0 siblings, 1 reply; 6+ messages in thread

From: Pradip Parkale @ 2021-04-27 06:18 UTC (permalink / raw)
  To: Akshay Joshi <[email protected]>; +Cc: pgadmin-hackers

Hi Akshay,

Please find the updated patch. I have added more checks so that it will
pick the correct shared server.

On Thu, Apr 22, 2021 at 5:43 PM Akshay Joshi <[email protected]>
wrote:

> Thanks, patch applied.
>
> On Thu, Apr 22, 2021 at 2:37 PM Pradip Parkale <
> [email protected]> wrote:
>
>> Hi Akshay,
>>
>> Please find the updated patch. I did some modifications as some cases
>> were failing due to my initial changes.
>> Sorry for the inconvenience.
>>
>> On Wed, Apr 14, 2021 at 12:13 PM Akshay Joshi <
>> [email protected]> wrote:
>>
>>> Thanks, patch applied.
>>>
>>> On Tue, Apr 13, 2021 at 10:35 PM Pradip Parkale <
>>> [email protected]> wrote:
>>>
>>>> Hi Hackers,
>>>>
>>>> Please find the attached patch for #6385 Backup on a shared server
>>>> doesn't seem to work.
>>>>
>>>>
>>>>
>>>> --
>>>> Thanks & Regards,
>>>> Pradip Parkale
>>>> Software Engineer | EnterpriseDB Corporation
>>>>
>>>
>>>
>>> --
>>> *Thanks & Regards*
>>> *Akshay Joshi*
>>> *pgAdmin Hacker | Principal Software Architect*
>>> *EDB Postgres <http://edbpostgres.com>*
>>>
>>> *Mobile: +91 976-788-8246*
>>>
>>
>>
>> --
>> Thanks & Regards,
>> Pradip Parkale
>> Software Engineer | EnterpriseDB Corporation
>>
>
>
> --
> *Thanks & Regards*
> *Akshay Joshi*
> *pgAdmin Hacker | Principal Software Architect*
> *EDB Postgres <http://edbpostgres.com>*
>
> *Mobile: +91 976-788-8246*
>


-- 
Thanks & Regards,
Pradip Parkale
Software Engineer | EnterpriseDB Corporation


Attachments:

  [application/octet-stream] RM6385_v3.patch (3.4K, 3-RM6385_v3.patch)
  download | inline diff:
diff --git a/web/pgadmin/browser/server_groups/servers/__init__.py b/web/pgadmin/browser/server_groups/servers/__init__.py
index 233ea07f8..105e90c8d 100644
--- a/web/pgadmin/browser/server_groups/servers/__init__.py
+++ b/web/pgadmin/browser/server_groups/servers/__init__.py
@@ -618,7 +618,7 @@ class ServerNode(PGChildNodeView):
             ),
         )
 
-    def delete_shared_server(self, server_name, gid):
+    def delete_shared_server(self, server_name, gid, osid):
         """
         Delete the shared server
         :param server_name:
@@ -626,7 +626,8 @@ class ServerNode(PGChildNodeView):
         """
         try:
             shared_server = SharedServer.query.filter_by(name=server_name,
-                                                         servergroup_id=gid)
+                                                         servergroup_id=gid,
+                                                         osid=osid)
             for s in shared_server:
                 get_driver(PG_DEFAULT_DRIVER).delete_manager(s.id)
                 db.session.delete(s)
@@ -662,7 +663,7 @@ class ServerNode(PGChildNodeView):
                     get_driver(PG_DEFAULT_DRIVER).delete_manager(s.id)
                     db.session.delete(s)
                 db.session.commit()
-                self.delete_shared_server(server_name, gid)
+                self.delete_shared_server(server_name, gid, sid)
                 QueryHistory.clear_history(current_user.id, sid)
 
             except Exception as e:
@@ -819,7 +820,7 @@ class ServerNode(PGChildNodeView):
                 if 'shared' in data and not data['shared']:
                     # Delete the shared server from DB if server
                     # owner uncheck shared property
-                    self.delete_shared_server(server.name, gid)
+                    self.delete_shared_server(server.name, gid, server.id)
                 if arg == 'sslcompression':
                     value = 1 if value else 0
                 self._update_server_details(server, sharedserver,
@@ -1879,7 +1880,7 @@ class ServerNode(PGChildNodeView):
             if server.shared and server.user_id != current_user.id:
                 shared_server = SharedServer.query.filter_by(
                     name=server.name, user_id=current_user.id,
-                    servergroup_id=gid).first()
+                    servergroup_id=gid, osid=server.id).first()
 
                 if shared_server is None:
                     return make_json_response(
diff --git a/web/pgadmin/browser/server_groups/servers/utils.py b/web/pgadmin/browser/server_groups/servers/utils.py
index e07a6273a..69ddf6c39 100644
--- a/web/pgadmin/browser/server_groups/servers/utils.py
+++ b/web/pgadmin/browser/server_groups/servers/utils.py
@@ -282,15 +282,7 @@ def does_server_exists(sid, user_id):
     # **kwargs parameter can be added to function to filter with more
     # parameters.
     try:
-        if Server.query.filter_by(id=sid, user_id=user_id).first():
-            server = Server.query.filter_by(
-                id=sid, user_id=user_id
-            ).first()
-        else:
-            server = SharedServer.query.filter_by(
-                id=sid, user_id=user_id
-            ).first()
-
-        return True if server is not None else False
+        return True if Server.query.filter_by(
+            id=sid).first() is not None else False
     except Exception:
         return False


^ permalink  raw  reply  [nested|flat] 6+ messages in thread

* Re: [pgAdmin][RM6385]: Backup on a shared server doesn't seem to work
  2021-04-13 17:05 [pgAdmin][RM6385]: Backup on a shared server doesn't seem to work Pradip Parkale <[email protected]>
  2021-04-14 06:43 ` Re: [pgAdmin][RM6385]: Backup on a shared server doesn't seem to work Akshay Joshi <[email protected]>
  2021-04-22 09:07   ` Re: [pgAdmin][RM6385]: Backup on a shared server doesn't seem to work Pradip Parkale <[email protected]>
  2021-04-22 12:13     ` Re: [pgAdmin][RM6385]: Backup on a shared server doesn't seem to work Akshay Joshi <[email protected]>
  2021-04-27 06:18       ` Re: [pgAdmin][RM6385]: Backup on a shared server doesn't seem to work Pradip Parkale <[email protected]>
@ 2021-04-27 06:29         ` Akshay Joshi <[email protected]>
  0 siblings, 0 replies; 6+ messages in thread

From: Akshay Joshi @ 2021-04-27 06:29 UTC (permalink / raw)
  To: Pradip Parkale <[email protected]>; +Cc: pgadmin-hackers

Thanks, patch applied.

On Tue, Apr 27, 2021 at 11:48 AM Pradip Parkale <
[email protected]> wrote:

> Hi Akshay,
>
> Please find the updated patch. I have added more checks so that it will
> pick the correct shared server.
>
> On Thu, Apr 22, 2021 at 5:43 PM Akshay Joshi <
> [email protected]> wrote:
>
>> Thanks, patch applied.
>>
>> On Thu, Apr 22, 2021 at 2:37 PM Pradip Parkale <
>> [email protected]> wrote:
>>
>>> Hi Akshay,
>>>
>>> Please find the updated patch. I did some modifications as some cases
>>> were failing due to my initial changes.
>>> Sorry for the inconvenience.
>>>
>>> On Wed, Apr 14, 2021 at 12:13 PM Akshay Joshi <
>>> [email protected]> wrote:
>>>
>>>> Thanks, patch applied.
>>>>
>>>> On Tue, Apr 13, 2021 at 10:35 PM Pradip Parkale <
>>>> [email protected]> wrote:
>>>>
>>>>> Hi Hackers,
>>>>>
>>>>> Please find the attached patch for #6385 Backup on a shared server
>>>>> doesn't seem to work.
>>>>>
>>>>>
>>>>>
>>>>> --
>>>>> Thanks & Regards,
>>>>> Pradip Parkale
>>>>> Software Engineer | EnterpriseDB Corporation
>>>>>
>>>>
>>>>
>>>> --
>>>> *Thanks & Regards*
>>>> *Akshay Joshi*
>>>> *pgAdmin Hacker | Principal Software Architect*
>>>> *EDB Postgres <http://edbpostgres.com>*
>>>>
>>>> *Mobile: +91 976-788-8246*
>>>>
>>>
>>>
>>> --
>>> Thanks & Regards,
>>> Pradip Parkale
>>> Software Engineer | EnterpriseDB Corporation
>>>
>>
>>
>> --
>> *Thanks & Regards*
>> *Akshay Joshi*
>> *pgAdmin Hacker | Principal Software Architect*
>> *EDB Postgres <http://edbpostgres.com>*
>>
>> *Mobile: +91 976-788-8246*
>>
>
>
> --
> Thanks & Regards,
> Pradip Parkale
> Software Engineer | EnterpriseDB Corporation
>


-- 
*Thanks & Regards*
*Akshay Joshi*
*pgAdmin Hacker | Principal Software Architect*
*EDB Postgres <http://edbpostgres.com>*

*Mobile: +91 976-788-8246*


^ permalink  raw  reply  [nested|flat] 6+ messages in thread


end of thread, other threads:[~2021-04-27 06:29 UTC | newest]

Thread overview: 6+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2021-04-13 17:05 [pgAdmin][RM6385]: Backup on a shared server doesn't seem to work Pradip Parkale <[email protected]>
2021-04-14 06:43 ` Akshay Joshi <[email protected]>
2021-04-22 09:07   ` Pradip Parkale <[email protected]>
2021-04-22 12:13     ` Akshay Joshi <[email protected]>
2021-04-27 06:18       ` Pradip Parkale <[email protected]>
2021-04-27 06:29         ` Akshay Joshi <[email protected]>

This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox