mirror of
https://github.com/pgadmin-org/pgadmin4.git
synced 2025-01-10 08:04:36 -06:00
Fixed an issue where some properties are not being updated correctly for the shared server. Fixes #5867
This commit is contained in:
parent
a707d818f5
commit
b097cec45e
Binary file not shown.
Before Width: | Height: | Size: 223 KiB After Width: | Height: | Size: 193 KiB |
Binary file not shown.
Before Width: | Height: | Size: 64 KiB After Width: | Height: | Size: 60 KiB |
@ -49,7 +49,7 @@ Use the fields on the *Display* panel to specify general display preferences:
|
||||
the client will display the animated dialogues/notifications otherwise it
|
||||
will be unanimated.
|
||||
|
||||
* When the *Hide shared server?* switch is set to *True*, the client will hide
|
||||
* When the *Hide shared servers?* switch is set to *True*, the client will hide
|
||||
all the shared servers from the browser tree.
|
||||
|
||||
* Use the *Lock layout* field to lock the UI layout at different levels. This
|
||||
|
@ -33,4 +33,5 @@ Bug fixes
|
||||
| `Issue #5841 <https://redmine.postgresql.org/issues/5841>`_ - Fixed an issue where the server is not able to connect using the service.
|
||||
| `Issue #5843 <https://redmine.postgresql.org/issues/5843>`_ - Fixed an issue where the 'PARALLEL UNSAFE' option is missing from reverse engineering SQL of function/procedure.
|
||||
| `Issue #5845 <https://redmine.postgresql.org/issues/5845>`_ - Fixed an issue where the query tool is not fetching more than 1000 rows for the table does not have any primary key.
|
||||
| `Issue #5861 <https://redmine.postgresql.org/issues/5861>`_ - Ensure that the 'Remove Server' option should be visible in the context menu.
|
||||
| `Issue #5861 <https://redmine.postgresql.org/issues/5861>`_ - Ensure that the 'Remove Server' option should be visible in the context menu.
|
||||
| `Issue #5867 <https://redmine.postgresql.org/issues/5867>`_ - Fixed an issue where some properties are not being updated correctly for the shared server.
|
@ -30,7 +30,7 @@ Use the fields in the *General* tab to identify the server:
|
||||
* If the *Connect now?* checkbox is checked, the client will attempt a
|
||||
connection to the server upon completion of the dialog; this is the default
|
||||
|
||||
* If the *Shared with all?* switch is moved to *Yes* then that server can be
|
||||
* If the *Shared?* switch is moved to *Yes* then that server can be
|
||||
shared with all the other users. This option is available only to admin users. For more information on users see :ref:`User Management Dialog <user_management>`. The users can access the shared servers with some restritctions. The Users accessing the shared servers cannot do the following operations on the shared servers:
|
||||
|
||||
* Create a server
|
||||
|
@ -27,10 +27,11 @@ def register_browser_preferences(self):
|
||||
if config.SERVER_MODE:
|
||||
self.hide_shared_server = self.preference.register(
|
||||
'display', 'hide_shared_server',
|
||||
gettext("Hide shared server?"), 'boolean', False,
|
||||
gettext("Hide shared servers?"), 'boolean', False,
|
||||
category_label=gettext('Display'),
|
||||
help_str=gettext(
|
||||
'If set to true, then all shared server will be hidden'
|
||||
'If set to True, then all shared servers will be '
|
||||
'hidden from browser tree'
|
||||
)
|
||||
)
|
||||
|
||||
|
@ -139,13 +139,16 @@ class ServerModule(sg.ServerGroupPluginModule):
|
||||
Return shared server properties
|
||||
:param server:
|
||||
:param sharedserver:
|
||||
:return:
|
||||
:return: shared server
|
||||
"""
|
||||
|
||||
server.bgcolor = sharedserver.bgcolor
|
||||
server.fgcolor = sharedserver.fgcolor
|
||||
server.name = sharedserver.name
|
||||
server.role = sharedserver.role
|
||||
server.use_ssh_tunnel = sharedserver.use_ssh_tunnel
|
||||
server.tunnel_host = sharedserver.tunnel_host
|
||||
server.tunnel_port = sharedserver.tunnel_port
|
||||
server.tunnel_authentication = sharedserver.tunnel_authentication
|
||||
server.tunnel_username = sharedserver.tunnel_username
|
||||
server.tunnel_password = sharedserver.tunnel_password
|
||||
server.save_password = sharedserver.save_password
|
||||
@ -157,45 +160,53 @@ class ServerModule(sg.ServerGroupPluginModule):
|
||||
|
||||
return server
|
||||
|
||||
@staticmethod
|
||||
def check_to_hide_shared_server(hide_shared_server, shared_server,
|
||||
auto_detected_server):
|
||||
def get_servers(self, all_servers, hide_shared_server, gid):
|
||||
"""
|
||||
This function creates list of servers which needs to display
|
||||
in browser tree
|
||||
:param all_servers:
|
||||
:param hide_shared_server:
|
||||
:param gid:
|
||||
:return: list of servers
|
||||
"""
|
||||
servers = []
|
||||
for server in all_servers:
|
||||
if server.discovery_id and \
|
||||
not server.shared and \
|
||||
config.SERVER_MODE and \
|
||||
len(SharedServer.query.filter_by(
|
||||
user_id=current_user.id,
|
||||
name=server.name).all()) > 0 and not hide_shared_server:
|
||||
continue
|
||||
|
||||
hide_server = False
|
||||
if hide_shared_server or \
|
||||
shared_server.name == auto_detected_server:
|
||||
hide_server = True
|
||||
if server.shared and server.user_id != current_user.id:
|
||||
|
||||
return hide_server
|
||||
shared_server = self.get_shared_server(server, gid)
|
||||
|
||||
if hide_shared_server:
|
||||
# Don't include shared server if hide shared server is
|
||||
# set to true.
|
||||
continue
|
||||
|
||||
server = self.get_shared_server_properties(server,
|
||||
shared_server)
|
||||
servers.append(server)
|
||||
|
||||
return servers
|
||||
|
||||
@login_required
|
||||
def get_nodes(self, gid):
|
||||
"""Return a JSON document listing the server groups for the user"""
|
||||
|
||||
hide_shared_server = get_preferences()
|
||||
|
||||
servers = Server.query.filter(
|
||||
or_(Server.user_id == current_user.id, Server.shared),
|
||||
Server.servergroup_id == gid)
|
||||
|
||||
driver = get_driver(PG_DEFAULT_DRIVER)
|
||||
servers = self.get_servers(servers, hide_shared_server, gid)
|
||||
|
||||
for server in servers:
|
||||
|
||||
if server.shared and server.user_id != current_user.id:
|
||||
|
||||
shared_server, auto_detected_server = \
|
||||
self.get_shared_server(server, gid)
|
||||
|
||||
if self.check_to_hide_shared_server(hide_shared_server,
|
||||
shared_server,
|
||||
auto_detected_server):
|
||||
# Don't include shared server if hide shared server is
|
||||
# set to true
|
||||
continue
|
||||
|
||||
server = self.get_shared_server_properties(server,
|
||||
shared_server)
|
||||
connected = False
|
||||
manager = None
|
||||
errmsg = None
|
||||
@ -323,6 +334,7 @@ class ServerModule(sg.ServerGroupPluginModule):
|
||||
|
||||
shared_server = None
|
||||
try:
|
||||
db.session.rollback()
|
||||
user = User.query.filter_by(id=data.user_id).first()
|
||||
shared_server = SharedServer(
|
||||
user_id=current_user.id,
|
||||
@ -346,13 +358,13 @@ class ServerModule(sg.ServerGroupPluginModule):
|
||||
fgcolor=data.fgcolor if data.fgcolor else None,
|
||||
service=data.service if data.service else None,
|
||||
connect_timeout=0,
|
||||
use_ssh_tunnel=0,
|
||||
tunnel_host=None,
|
||||
use_ssh_tunnel=data.use_ssh_tunnel,
|
||||
tunnel_host=data.tunnel_host,
|
||||
tunnel_port=22,
|
||||
tunnel_username=None,
|
||||
tunnel_authentication=0,
|
||||
tunnel_identity_file=None,
|
||||
shared=data.shared if data.shared else None
|
||||
shared=True
|
||||
)
|
||||
db.session.add(shared_server)
|
||||
db.session.commit()
|
||||
@ -372,12 +384,9 @@ class ServerModule(sg.ServerGroupPluginModule):
|
||||
:param gid:
|
||||
:return: shared_server
|
||||
"""
|
||||
auto_detected_server = None
|
||||
shared_server = SharedServer.query.filter_by(
|
||||
name=server.name, user_id=current_user.id,
|
||||
servergroup_id=gid).first()
|
||||
if server.discovery_id:
|
||||
auto_detected_server = server.name
|
||||
|
||||
if shared_server is None:
|
||||
ServerModule.create_shared_server(server, gid)
|
||||
@ -386,7 +395,7 @@ class ServerModule(sg.ServerGroupPluginModule):
|
||||
name=server.name, user_id=current_user.id,
|
||||
servergroup_id=gid).first()
|
||||
|
||||
return shared_server, auto_detected_server
|
||||
return shared_server
|
||||
|
||||
|
||||
class ServerMenuItem(MenuItem):
|
||||
@ -494,8 +503,7 @@ class ServerNode(PGChildNodeView):
|
||||
|
||||
for server in servers:
|
||||
if server.shared and server.user_id != current_user.id:
|
||||
shared_server, auto_detected_server = \
|
||||
ServerModule.get_shared_server(server, gid)
|
||||
shared_server = ServerModule.get_shared_server(server, gid)
|
||||
server = \
|
||||
ServerModule.get_shared_server_properties(server,
|
||||
shared_server)
|
||||
@ -552,8 +560,7 @@ class ServerNode(PGChildNodeView):
|
||||
server = Server.query.filter_by(id=sid).first()
|
||||
|
||||
if server.shared and server.user_id != current_user.id:
|
||||
shared_server, auto_detected_server = \
|
||||
ServerModule.get_shared_server(server, gid)
|
||||
shared_server = ServerModule.get_shared_server(server, gid)
|
||||
server = ServerModule.get_shared_server_properties(server,
|
||||
shared_server)
|
||||
|
||||
@ -677,8 +684,7 @@ class ServerNode(PGChildNodeView):
|
||||
|
||||
if config.SERVER_MODE and server.shared and \
|
||||
server.user_id != current_user.id:
|
||||
sharedserver, auto_detected_server = \
|
||||
ServerModule.get_shared_server(server, gid)
|
||||
sharedserver = ServerModule.get_shared_server(server, gid)
|
||||
|
||||
# Not all parameters can be modified, while the server is connected
|
||||
config_param_map = {
|
||||
@ -781,6 +787,8 @@ class ServerNode(PGChildNodeView):
|
||||
True,
|
||||
self.node_type,
|
||||
connected=connected,
|
||||
shared=server.shared,
|
||||
user_id=server.user_id,
|
||||
user=manager.user_info if connected else None,
|
||||
server_type='pg' # default server type
|
||||
)
|
||||
@ -849,8 +857,7 @@ class ServerNode(PGChildNodeView):
|
||||
|
||||
for server in servers:
|
||||
if server.shared and server.user_id != current_user.id:
|
||||
shared_server, auto_detected_server = \
|
||||
ServerModule.get_shared_server(server, gid)
|
||||
shared_server = ServerModule.get_shared_server(server, gid)
|
||||
server = \
|
||||
ServerModule.get_shared_server_properties(server,
|
||||
shared_server)
|
||||
@ -907,10 +914,8 @@ class ServerNode(PGChildNodeView):
|
||||
conn = manager.connection()
|
||||
connected = conn.connected()
|
||||
|
||||
# if server.shared and not current_user.has_role("Administrator"):
|
||||
if server.shared and server.user_id != current_user.id:
|
||||
shared_server, auto_detected_server = \
|
||||
ServerModule.get_shared_server(server, gid)
|
||||
shared_server = ServerModule.get_shared_server(server, gid)
|
||||
server = ServerModule.get_shared_server_properties(server,
|
||||
shared_server)
|
||||
server_owner = server.server_owner
|
||||
@ -1136,6 +1141,7 @@ class ServerNode(PGChildNodeView):
|
||||
self.node_type,
|
||||
user=user,
|
||||
connected=connected,
|
||||
shared=server.shared,
|
||||
server_type=manager.server_type
|
||||
if manager and manager.server_type
|
||||
else 'pg',
|
||||
@ -1265,8 +1271,7 @@ class ServerNode(PGChildNodeView):
|
||||
server = Server.query.filter_by(id=sid).first()
|
||||
shared_server = None
|
||||
if server.shared and server.user_id != current_user.id:
|
||||
shared_server, auto_detected_server = \
|
||||
ServerModule.get_shared_server(server, gid)
|
||||
shared_server = ServerModule.get_shared_server(server, gid)
|
||||
server = ServerModule.get_shared_server_properties(server,
|
||||
shared_server)
|
||||
if server is None:
|
||||
|
@ -269,7 +269,10 @@ define('pgadmin.node.server', [
|
||||
gettext('Are you sure you want to disconnect the server %s?', d.label),
|
||||
function() { disconnect(); },
|
||||
function() { return true;}
|
||||
);
|
||||
).set('labels', {
|
||||
ok: gettext('Ok'),
|
||||
cancel: gettext('Cancel'),
|
||||
});
|
||||
} else {
|
||||
disconnect();
|
||||
}
|
||||
@ -752,6 +755,11 @@ define('pgadmin.node.server', [
|
||||
},
|
||||
schema: [{
|
||||
id: 'id', label: gettext('ID'), type: 'int', mode: ['properties'],
|
||||
visible: function(model){
|
||||
if (model.attributes.user_id != current_user.id && pgAdmin.server_mode == 'True')
|
||||
return false;
|
||||
return true;
|
||||
},
|
||||
},{
|
||||
id: 'name', label: gettext('Name'), type: 'text',
|
||||
mode: ['properties', 'edit', 'create'], disabled: 'isShared',
|
||||
@ -759,7 +767,7 @@ define('pgadmin.node.server', [
|
||||
{
|
||||
id: 'gid', label: gettext('Server group'), type: 'int',
|
||||
control: 'node-list-by-id', node: 'server_group',
|
||||
mode: ['create', 'edit'], select2: {allowClear: false}, visible: 'isVisible',
|
||||
mode: ['create', 'edit'], select2: {allowClear: false}, disabled: 'isShared',
|
||||
},
|
||||
{
|
||||
id: 'server_owner', label: gettext('Shared Server Owner'), type: 'text', mode: ['properties'],
|
||||
@ -795,7 +803,7 @@ define('pgadmin.node.server', [
|
||||
id: 'connect_now', controlLabel: gettext('Connect now?'), type: 'checkbox',
|
||||
group: null, mode: ['create'],
|
||||
},{
|
||||
id: 'shared', label: gettext('Shared with all?'), type: 'switch',
|
||||
id: 'shared', label: gettext('Shared?'), type: 'switch',
|
||||
mode: ['properties', 'create', 'edit'], 'options': {'size': 'mini'},
|
||||
readonly: function(model){
|
||||
var serverOwner = model.attributes.user_id;
|
||||
|
@ -346,7 +346,7 @@
|
||||
"mock_data": {
|
||||
},
|
||||
"expected_data": {
|
||||
"status_code": 500
|
||||
"status_code": 200
|
||||
}
|
||||
},
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user