feat: Enhance checkout process by checking asset status before prompting user
This commit is contained in:
parent
dee02ad600
commit
2a9926d934
1 changed files with 72 additions and 2 deletions
|
|
@ -501,7 +501,9 @@ class MainWindow(QMainWindow):
|
||||||
self._prompt_checkout(source, local_path)
|
self._prompt_checkout(source, local_path)
|
||||||
|
|
||||||
def _prompt_checkout(self, azure_url: str, local_path: str) -> None:
|
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:
|
Args:
|
||||||
azure_url: Azure Blob Storage URL
|
azure_url: Azure Blob Storage URL
|
||||||
|
|
@ -512,7 +514,75 @@ class MainWindow(QMainWindow):
|
||||||
# Extract filename for display
|
# Extract filename for display
|
||||||
filename = Path(local_path).name
|
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(
|
reply = QMessageBox.question(
|
||||||
self,
|
self,
|
||||||
"Checkout Asset",
|
"Checkout Asset",
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue