MCPcopy Create free account
hub / github.com/pgadmin-org/pgadmin4 / _get_user_storage_dirs

Function _get_user_storage_dirs

web/pgadmin/llm/utils.py:27–62  ·  view source on GitHub ↗

Compute possible storage directory paths for the current user WITHOUT creating them. Returns a list of candidate directories (new-style first, then old-style if different). Returns an empty list if not in server mode or if the user cannot be determined.

()

Source from the content-addressed store, hash-verified

25
26
27def _get_user_storage_dirs():
28 """
29 Compute possible storage directory paths for the current user
30 WITHOUT creating them. Returns a list of candidate directories
31 (new-style first, then old-style if different).
32
33 Returns an empty list if not in server mode or if the user
34 cannot be determined.
35 """
36 from flask_security import current_user
37 from pgadmin.utils.paths import preprocess_username
38
39 if not config.SERVER_MODE:
40 return []
41
42 storage_dir = getattr(config, 'STORAGE_DIR', None)
43 if not storage_dir:
44 return []
45
46 base = (storage_dir.decode('utf-8')
47 if hasattr(storage_dir, 'decode') else storage_dir)
48
49 try:
50 # New-style: full username
51 username_new = preprocess_username(current_user.username)
52 # Old-style: username split at @
53 username_old = preprocess_username(
54 current_user.username.split('@')[0]
55 )
56 except Exception:
57 return []
58
59 dirs = [os.path.join(base, username_new)]
60 if username_old != username_new:
61 dirs.append(os.path.join(base, username_old))
62 return dirs
63
64
65def _is_within(expanded, allowed):

Callers 1

validate_api_key_pathFunction · 0.85

Calls 4

preprocess_usernameFunction · 0.90
decodeMethod · 0.80
joinMethod · 0.80
appendMethod · 0.80

Tested by

no test coverage detected