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.
()
| 25 | |
| 26 | |
| 27 | def _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 | |
| 65 | def _is_within(expanded, allowed): |
no test coverage detected