| 2478 | |
| 2479 | |
| 2480 | def formatted_tree(params, folder, verbose=False, show_records=False, shares=False, |
| 2481 | nsf_shares=False, hide_shares_key=False, title=None, fmt='table'): |
| 2482 | as_json = (fmt == 'json') |
| 2483 | need_nsf_folders = bool(nsf_shares) |
| 2484 | need_nsf_records = bool(nsf_shares and show_records) |
| 2485 | need_classic_records = bool(shares and show_records) |
| 2486 | if need_nsf_folders or need_nsf_records or need_classic_records: |
| 2487 | nsf_folder_uids, classic_record_uids, nsf_record_uids = _collect_tree_share_targets( |
| 2488 | params, folder, show_records) |
| 2489 | from .. import nested_share_folder as _nsf |
| 2490 | _nsf.warm_for_tree( |
| 2491 | params, |
| 2492 | nsf_folder_uids=nsf_folder_uids if need_nsf_folders else None, |
| 2493 | classic_record_uids=classic_record_uids if need_classic_records else None, |
| 2494 | nsf_record_uids=nsf_record_uids if need_nsf_records else None, |
| 2495 | ) |
| 2496 | |
| 2497 | def print_share_permissions_key(): |
| 2498 | lines = [ |
| 2499 | 'Share Permissions Key:', |
| 2500 | '======================', |
| 2501 | ] |
| 2502 | if shares: |
| 2503 | lines.extend([ |
| 2504 | 'RO = Read-Only', |
| 2505 | 'MU = Can Manage Users', |
| 2506 | 'MR = Can Manage Records', |
| 2507 | 'CE = Can Edit', |
| 2508 | 'CS = Can Share', |
| 2509 | 'OW = Owner', |
| 2510 | ]) |
| 2511 | if nsf_shares: |
| 2512 | lines.extend([ |
| 2513 | 'OW = NSF Owner', |
| 2514 | 'VW = NSF Viewer', |
| 2515 | 'SM = NSF Share Manager', |
| 2516 | 'CM = NSF Content Manager', |
| 2517 | 'CSM = NSF Content + Share Manager', |
| 2518 | 'FM = NSF Full Manager', |
| 2519 | ]) |
| 2520 | lines.append('======================') |
| 2521 | print('\n'.join(lines) + '\n') |
| 2522 | |
| 2523 | def tree_node(node, parent_path=''): |
| 2524 | node_uid = node.record_uid if isinstance(node, Record) else (node.uid if hasattr(node, 'uid') else '') |
| 2525 | node_name = node.title if isinstance(node, Record) else (node.name if hasattr(node, 'name') else 'Unknown') |
| 2526 | |
| 2527 | is_nested_share = False |
| 2528 | if isinstance(node, Record): |
| 2529 | is_nested_share = hasattr(params, 'nested_share_records') and node.record_uid in params.nested_share_records |
| 2530 | elif hasattr(node, 'type') and node.type == 'nested_share_folder': |
| 2531 | is_nested_share = True |
| 2532 | elif isinstance(node, BaseFolderNode) and not isinstance(node, Record): |
| 2533 | is_nested_share = hasattr(params, 'nested_share_folders') and node_uid in params.nested_share_folders |
| 2534 | if is_nested_share and node_uid in params.nested_share_folders: |
| 2535 | nsf_folder_name = params.nested_share_folders[node_uid].get('name', node_name) |
| 2536 | if nsf_folder_name: |
| 2537 | node_name = nsf_folder_name |