Skip to content

Commit f7a95a7

Browse files
KijongHanclaude
andcommitted
fix(import-export): accept Username or SharedUsername for shared servers
validate_json_data required Username for all non-Service connections, rejecting legitimate JSON that only carried SharedUsername. Accept either attribute when Shared is true; keep Username required for non-shared servers. Extract is_shared as a local while we're here — it's now referenced twice in the loop body. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
1 parent 86a8b16 commit f7a95a7

1 file changed

Lines changed: 20 additions & 7 deletions

File tree

web/pgadmin/utils/__init__.py

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -601,8 +601,10 @@ def validate_json_data(data, is_admin):
601601
for server in data["Servers"]:
602602
obj = data["Servers"][server]
603603

604+
is_shared = obj.get("Shared", None)
605+
604606
# Check if server is shared.Won't import if user is non-admin
605-
if obj.get('Shared', None) and not is_admin:
607+
if is_shared and not is_admin:
606608
print("Won't import the server '%s' as it is shared " %
607609
obj["Name"])
608610
skip_servers.append(server)
@@ -627,14 +629,25 @@ def check_is_integer(value):
627629
is_service_attrib_available = obj.get("Service", None) is not None
628630

629631
if not is_service_attrib_available:
630-
for attrib in ("Port", "Username"):
631-
errmsg = check_attrib(attrib)
632+
errmsg = check_attrib("Port")
633+
if errmsg:
634+
return errmsg
635+
errmsg = check_is_integer(obj["Port"])
636+
if errmsg:
637+
return errmsg
638+
639+
if is_shared:
640+
# Shared servers may carry either the owner's username
641+
# or a per-user override, so accept either attribute.
642+
if "Username" not in obj and "SharedUsername" not in obj:
643+
return gettext(
644+
"'Username' or 'SharedUsername' attribute not "
645+
"found for server '%s'" % server
646+
)
647+
else:
648+
errmsg = check_attrib("Username")
632649
if errmsg:
633650
return errmsg
634-
if attrib == 'Port':
635-
errmsg = check_is_integer(obj[attrib])
636-
if errmsg:
637-
return errmsg
638651

639652
errmsg = check_attrib("MaintenanceDB")
640653
if errmsg:

0 commit comments

Comments
 (0)