MCPcopy Index your code
hub / github.com/pgadmin-org/pgadmin4 / get_server

Function get_server

web/pgadmin/utils/server_access.py:24–65  ·  view source on GitHub ↗

Fetch a server by ID, verifying the current user has access. Args: sid: Server ID. only_owned: If True, only return servers owned by the current user. Use this for write operations (change_password, clear_saved_password, etc.) that must not mutate another

(sid, only_owned=False)

Source from the content-addressed store, hash-verified

22
23
24def get_server(sid, only_owned=False):
25 """Fetch a server by ID, verifying the current user has access.
26
27 Args:
28 sid: Server ID.
29 only_owned: If True, only return servers owned by the current
30 user. Use this for write operations (change_password,
31 clear_saved_password, etc.) that must not mutate another
32 user's server record via shared access.
33
34 Returns the server if:
35 - Desktop mode (single user, no isolation needed), OR
36 - The user owns it, OR
37 - The server is shared AND only_owned is False.
38
39 Returns None otherwise (caller should return HTTP 410 Gone, in
40 line with the rest of the server views — see e.g.
41 web/pgadmin/browser/server_groups/servers/__init__.py).
42
43 The Administrator role does not grant access to other users'
44 private servers — admins are subject to the same data isolation
45 as regular users. To make a server admin-visible, share it
46 (Server.shared=True).
47
48 Note: In pgAdmin, Server.shared=True means the server is visible
49 to all authenticated users. SharedServer records are created
50 lazily for per-user customization, not for access control.
51 """
52 if not config.SERVER_MODE:
53 return Server.query.filter_by(id=sid).first()
54
55 if only_owned:
56 return Server.query.filter_by(
57 id=sid, user_id=current_user.id).first()
58
59 return Server.query.filter(
60 Server.id == sid,
61 or_(
62 Server.user_id == current_user.id,
63 Server.shared
64 )
65 ).first()
66
67
68def get_server_group(gid):

Callers 15

nodeMethod · 0.90
updateMethod · 0.90
propertiesMethod · 0.90
connect_statusMethod · 0.90
connectMethod · 0.90
disconnectMethod · 0.90
change_passwordMethod · 0.90
wal_replayMethod · 0.90
check_pgpassMethod · 0.90
clear_saved_passwordMethod · 0.90
connectMethod · 0.90

Calls 2

filterMethod · 0.80
firstMethod · 0.65

Tested by

no test coverage detected