From 2a9926d93485f2018279d57848245992617b5555 Mon Sep 17 00:00:00 2001 From: claudi Date: Wed, 18 Feb 2026 07:41:28 +0100 Subject: [PATCH] feat: Enhance checkout process by checking asset status before prompting user --- src/webdrop_bridge/ui/main_window.py | 74 +++++++++++++++++++++++++++- 1 file changed, 72 insertions(+), 2 deletions(-) diff --git a/src/webdrop_bridge/ui/main_window.py b/src/webdrop_bridge/ui/main_window.py index 34bb438..6c3b063 100644 --- a/src/webdrop_bridge/ui/main_window.py +++ b/src/webdrop_bridge/ui/main_window.py @@ -501,7 +501,9 @@ class MainWindow(QMainWindow): self._prompt_checkout(source, local_path) def _prompt_checkout(self, azure_url: str, local_path: str) -> None: - """Prompt user to check out the asset. + """Check checkout status and prompt user if needed. + + First checks if the asset is already checked out. Only shows dialog if not checked out. Args: azure_url: Azure Blob Storage URL @@ -512,7 +514,75 @@ class MainWindow(QMainWindow): # Extract filename for display filename = Path(local_path).name - # Show confirmation dialog + # Extract asset ID + match = re.search(r'/([^/]+)/[^/]+$', azure_url) + if not match: + logger.warning(f"Could not extract asset ID from URL: {azure_url}") + return + + asset_id = match.group(1) + + # Check checkout status first + js_code = f""" + (async function() {{ + try {{ + const authToken = window.capturedAuthToken; + if (!authToken) {{ + return {{ error: 'No auth token' }}; + }} + + const response = await fetch( + 'https://devagravityprivate.azurewebsites.net/api/assets/{asset_id}?fields=checkout', + {{ + method: 'GET', + headers: {{ + 'Accept': 'application/json', + 'Authorization': authToken + }} + }} + ); + + if (response.ok) {{ + const data = await response.json(); + return {{ checkout: data.checkout }}; + }} else {{ + return {{ error: 'Failed to fetch asset' }}; + }} + }} catch (error) {{ + return {{ error: error.toString() }}; + }} + }})(); + """ + + def on_checkout_status(result): + """Callback when checkout status is received.""" + if not result or isinstance(result, dict) and result.get('error'): + logger.warning(f"Could not check checkout status: {result}") + # Show dialog anyway as fallback + self._show_checkout_dialog(azure_url, filename) + return + + # Check if already checked out + checkout_info = result.get('checkout') + if checkout_info: + logger.info(f"Asset {filename} is already checked out, skipping dialog") + return + + # Not checked out, show confirmation dialog + self._show_checkout_dialog(azure_url, filename) + + # Execute JavaScript to check status + self.web_view.page().runJavaScript(js_code, on_checkout_status) + + def _show_checkout_dialog(self, azure_url: str, filename: str) -> None: + """Show the checkout confirmation dialog. + + Args: + azure_url: Azure Blob Storage URL + filename: Asset filename + """ + from PySide6.QtWidgets import QMessageBox + reply = QMessageBox.question( self, "Checkout Asset",