Skip to content

Commit 6f08154

Browse files
paullizerCopilotChrisSheppard-UICGSodaysecCopilot
authored
Development (#223)
* Fix Enhanced Citations Errors When Deleting Documents (#218) * Suggested update to README.md (#216) In deploying the latest release, I found that uploading documents to a user workspace fails when Enhanced Citations are enabled but containers have not manually been added to the storage account. * Initial plan for issue * Fix enhanced citations errors when deleting documents Co-authored-by: paullizer <34814295+paullizer@users.noreply.github.com> * Fixed simplemde location * Add flash message display to admin settings template Co-authored-by: paullizer <34814295+paullizer@users.noreply.github.com> --------- Co-authored-by: ChrisSheppard-UICGS <Christopher.Sheppard@bowhead.com> Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: paullizer <34814295+paullizer@users.noreply.github.com> Co-authored-by: Paul Lizer <paullizer@microsoft.com> * Fix document dropdown to show all personal and group files in chat (#211) * Initial plan for issue * Implement custom document dropdown with search and scrolling Co-authored-by: paullizer <34814295+paullizer@users.noreply.github.com> * Add dropdown interaction improvements for better user experience Co-authored-by: paullizer <34814295+paullizer@users.noreply.github.com> * Add styling improvements and better initialization for document dropdown Co-authored-by: paullizer <34814295+paullizer@users.noreply.github.com> * Fix document dropdown display and interaction Co-authored-by: paullizer <34814295+paullizer@users.noreply.github.com> * Additional fixes for document dropdown functionality Co-authored-by: paullizer <34814295+paullizer@users.noreply.github.com> * Fix document dropdown to stay within browser viewport bounds Co-authored-by: paullizer <34814295+paullizer@users.noreply.github.com> * Fix document dropdown width to stay within right pane Co-authored-by: paullizer <34814295+paullizer@users.noreply.github.com> * Reduce document dropdown width for better fit within right pane Co-authored-by: paullizer <34814295+paullizer@users.noreply.github.com> * Update document dropdown width to 400px as requested Co-authored-by: paullizer <34814295+paullizer@users.noreply.github.com> * Fix document dropdown to show all personal and group files Co-authored-by: paullizer <34814295+paullizer@users.noreply.github.com> * Fix document dropdown search filter functionality Co-authored-by: paullizer <34814295+paullizer@users.noreply.github.com> * Fix document search filter functionality to properly filter documents Co-authored-by: paullizer <34814295+paullizer@users.noreply.github.com> * Fix document dropdown to close when clicking outside Co-authored-by: paullizer <34814295+paullizer@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: paullizer <34814295+paullizer@users.noreply.github.com> * Improve Admin Settings Save Button Functionality (#222) * Suggested update to README.md (#216) In deploying the latest release, I found that uploading documents to a user workspace fails when Enhanced Citations are enabled but containers have not manually been added to the storage account. * Initial plan for issue * Improve save button functionality in admin settings Co-authored-by: paullizer <34814295+paullizer@users.noreply.github.com> --------- Co-authored-by: ChrisSheppard-UICGS <Christopher.Sheppard@bowhead.com> Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: paullizer <34814295+paullizer@users.noreply.github.com> * Fix: Persistent update notification in admin settings (#191) * Initial plan for issue * Fix update notification persistence in admin settings Co-authored-by: paullizer <34814295+paullizer@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: paullizer <34814295+paullizer@users.noreply.github.com> Co-authored-by: Paul Lizer <paullizer@microsoft.com> * Fix route_backend_settings uncontrolled data used in path expression (#220) * Suggested update to README.md (#216) In deploying the latest release, I found that uploading documents to a user workspace fails when Enhanced Citations are enabled but containers have not manually been added to the storage account. * Update route_backend_settings.py * Update application/single_app/route_backend_settings.py Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --------- Co-authored-by: ChrisSheppard-UICGS <Christopher.Sheppard@bowhead.com> Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Create containers when Enhanced Citations is enabled (#226) * Suggested update to README.md (#216) In deploying the latest release, I found that uploading documents to a user workspace fails when Enhanced Citations are enabled but containers have not manually been added to the storage account. * Initial plan for issue * Implement container creation when Enhanced citations is enabled Co-authored-by: paullizer <34814295+paullizer@users.noreply.github.com> * Add additional comments and container existence logging Co-authored-by: paullizer <34814295+paullizer@users.noreply.github.com> --------- Co-authored-by: ChrisSheppard-UICGS <Christopher.Sheppard@bowhead.com> Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: paullizer <34814295+paullizer@users.noreply.github.com> * Add App Settings Walkthrough for First-Time Deployment (#225) * Suggested update to README.md (#216) In deploying the latest release, I found that uploading documents to a user workspace fails when Enhanced Citations are enabled but containers have not manually been added to the storage account. * Initial plan for issue * Implement app settings walkthrough functionality Co-authored-by: paullizer <34814295+paullizer@users.noreply.github.com> * Finalize settings walkthrough implementation and update documentation Co-authored-by: paullizer <34814295+paullizer@users.noreply.github.com> * Add button to manually launch settings walkthrough Co-authored-by: paullizer <34814295+paullizer@users.noreply.github.com> * Convert modal walkthrough to inline container Co-authored-by: paullizer <34814295+paullizer@users.noreply.github.com> * Enhance inline walkthrough with scrolling and proper tab selection Co-authored-by: paullizer <34814295+paullizer@users.noreply.github.com> * Add validation feedback and completion indicators to walkthrough Co-authored-by: paullizer <34814295+paullizer@users.noreply.github.com> * Implement dynamic step skipping based on selected features Co-authored-by: paullizer <34814295+paullizer@users.noreply.github.com> * Add feedback for optional features in walkthrough and update Finish Setup button Co-authored-by: paullizer <34814295+paullizer@users.noreply.github.com> * Fix Previous button in walkthrough and remove duplicate video/audio toggles Co-authored-by: paullizer <34814295+paullizer@users.noreply.github.com> * Fix Next button on Document Intelligence step in settings walkthrough Co-authored-by: paullizer <34814295+paullizer@users.noreply.github.com> * Fix walkthrough button and classification categories JSON parsing error Co-authored-by: paullizer <34814295+paullizer@users.noreply.github.com> * Fix walkthrough navigation buttons and classification categories JSON parsing Co-authored-by: paullizer <34814295+paullizer@users.noreply.github.com> * Remove Save Settings button from walkthrough step 1 Co-authored-by: paullizer <34814295+paullizer@users.noreply.github.com> * Remove enable button from Content Safety Settings walkthrough step Co-authored-by: paullizer <34814295+paullizer@users.noreply.github.com> * Add APIM support to settings walkthrough with informative tooltips Co-authored-by: paullizer <34814295+paullizer@users.noreply.github.com> --------- Co-authored-by: ChrisSheppard-UICGS <Christopher.Sheppard@bowhead.com> Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: paullizer <34814295+paullizer@users.noreply.github.com> Co-authored-by: Paul Lizer <paullizer@microsoft.com> * Updated version, README, and RELEASE NOTES --------- Co-authored-by: Copilot <198982749+Copilot@users.noreply.github.com> Co-authored-by: ChrisSheppard-UICGS <Christopher.Sheppard@bowhead.com> Co-authored-by: Zeroday BYTE <github@zerodaysec.org> Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
1 parent ef66657 commit 6f08154

15 files changed

+2578
-122
lines changed

README.md

Lines changed: 52 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -215,52 +215,53 @@ Below is a summary of recent additions, reflecting the state as of version `v0.2
215215

216216
Here's a structured changelog entry for version `v0.213.001` following your previous format:
217217

218-
### **(v0.213.001)**
218+
### **(v0.214.001)**
219219

220220
#### New Features
221221

222-
1. **Dark Mode Support**
223-
- Added full dark mode theming with support for:
224-
- Chat interface (left and right panes)
225-
- File metadata panels
226-
- Dropdowns, headers, buttons, and classification tables
227-
- User preferences persist across sessions.
228-
- Dark mode toggle in navbar with text labels and styling fixes (no flash during navigation).
229-
2. **Admin Management Enhancements**
230-
- Admin Settings UI updated to show version check.
231-
- Added logout_hint parameter to resolve multi-identity logout errors.
232-
- Updated favicon and admin settings layout for improved clarity and usability.
233-
3. **UI Banner & Visual Updates**
234-
- New top-of-page banner added (configurable).
235-
- Local CSS/JS used across admin, group, and user workspaces for consistency and performance.
236-
- Updated `base.html` and `workspace.html` to reflect visual improvements.
237-
4. **Security Improvements**
238-
- Implemented `X-Content-Type-Options: nosniff` header to mitigate MIME sniffing vulnerabilities.
239-
5. **Build & Deployment**
240-
- Added `docker_image_publish_dev.yml` GitHub Action workflow for publishing dev Docker images.
241-
- Updated Dockerfile to use **Python 3.12**.
242-
6. **Version Enforcement**
243-
- GitHub workflow `enforce-dev-to-main.yml` added to prevent pull requests to `main` unless from `development`.
222+
* **Dark Mode Support**
223+
* Added full dark mode theming with support for:
224+
* Chat interface (left and right panes)
225+
* File metadata panels
226+
* Dropdowns, headers, buttons, and classification tables
227+
* User preferences persist across sessions.
228+
* Dark mode toggle in navbar with text labels and styling fixes (no flash during navigation).
229+
* **Admin Management Enhancements**
230+
* **First-Time Configuration Wizard**: Introduced a guided setup wizard on the Admin Settings page. This wizard simplifies the initial configuration process for application basics (title, logo), GPT API settings, workspace settings, additional services (Embedding, AI Search, Document Intelligence), and optional features. (Ref: `README.md`, `admin_settings.js`, `admin_settings.html`)
231+
* Admin Settings UI updated to show application version check status, comparing against the latest GitHub release. (Ref: `route_frontend_admin_settings.py`, `admin_settings.html`)
232+
* Added `logout_hint` parameter to resolve multi-identity logout errors.
233+
* Updated favicon and admin settings layout for improved clarity and usability.
234+
* **UI Banner & Visual Updates**
235+
* **Enhanced Document Dropdown (Chat Interface)**: The document selection dropdown in the chat interface has been significantly improved:
236+
* Increased width and scrollability for better handling of numerous documents.
237+
* Client-side search/filter functionality added to quickly find documents.
238+
* Improved visual feedback, including a "no matches found" message. (Ref: `chats.css`, `chat-documents.js`, `chats.html`)
239+
* New top-of-page banner added (configurable).
240+
* Local CSS/JS used across admin, group, and user workspaces for consistency and performance.
241+
* Updated `base.html` and `workspace.html` to reflect visual improvements.
242+
* **Application Setup & Configuration**
243+
* **Automatic Storage Container Creation**: The application now attempts to automatically create the `user-documents` and `group-documents` Azure Storage containers during initialization if they are not found, provided "Enhanced Citations" are enabled and a valid storage connection string is configured. Manual creation as per documentation is still the recommended primary approach. (Ref: `config.py`)
244+
* Updated documentation for Azure Storage Account setup, including guidance for the new First-Time Configuration Wizard. (Ref: `README.md`)
245+
* **Security Improvements**
246+
* Implemented `X-Content-Type-Options: nosniff` header to mitigate MIME sniffing vulnerabilities.
247+
* Enhanced security for loading AI Search index schema JSON files by implementing path validation and using `secure_filename` in backend settings. (Ref: `route_backend_settings.py`)
248+
* **Build & Deployment**
249+
* Added `docker_image_publish_dev.yml` GitHub Action workflow for publishing dev Docker images.
250+
* Updated Dockerfile to use Python 3.12.
251+
* **Version Enforcement**
252+
* GitHub workflow `enforce-dev-to-main.yml` added to prevent pull requests to `main` unless from `development`.
244253

245254
#### Bug Fixes
246255

247-
A. **Document Processing**
248-
249-
- Resolved document deletion error.
250-
251-
C. **UI & Usability**
252-
253-
- Local assets now used for JS/CSS to improve load times and offline compatibility.
254-
- General CSS cleanups across admin and workspace UIs.
255-
256-
D. **General Stability**
257-
258-
- Merged contributions from multiple devs including UI fixes, backend updates, and config changes.
259-
- Removed unused video/audio container declarations for a leaner frontend.
260-
261-
------
262-
263-
Let me know if you'd like a markdown-formatted file or a GitHub release tag summary version.
256+
* **A. Document Processing**
257+
* **Document Deletion**: Resolved an issue where documents were not properly deleted from Azure Blob Storage. Now, when a document is deleted from the application, its corresponding blob is also removed from the `user-documents` or `group-documents` container if enhanced citations are enabled. (Ref: `functions_documents.py`)
258+
* **Configuration Validation (Enhanced Citations)**: Added validation in Admin Settings to ensure that if "Enhanced Citations" is enabled, the "Office Docs Storage Account Connection String" is also provided. If the connection string is missing, Enhanced Citations will be automatically disabled, and a warning message will be displayed to the admin, preventing silent failures. (Ref: `route_frontend_admin_settings.py`)
259+
* **C. UI & Usability**
260+
* **Local Assets for SimpleMDE**: The SimpleMDE Markdown editor assets (JS/CSS) are now served locally from `/static/js/simplemde/` and `/static/css/simplemde.min.css` instead of a CDN. This improves page load times, reduces external dependencies, and allows for use in offline or air-gapped environments. (Ref: `simplemde.min.js`, `simplemde.min.css` additions, template updates in `group_workspaces.html`, `workspace.html`)
261+
* General CSS cleanups across admin and workspace UIs.
262+
* **D. General Stability**
263+
* Merged contributions from multiple devs including UI fixes, backend updates, and config changes.
264+
* Removed unused video/audio container declarations for a leaner frontend.
264265

265266
## Release Notes
266267

@@ -636,7 +637,17 @@ Core configuration values are managed via environment variables, typically set i
636637
* To verify or synchronize settings from Azure back to a local `.env` file:
637638
* Press `Ctrl+Shift+P`, type `Azure App Service: Download Remote Settings`, select your App Service, and choose where to save the file (e.g., overwrite your local `.env`). This is useful to capture settings automatically added by Azure (like `APPLICATIONINSIGHTS_CONNECTION_STRING` or `WEBSITE_AUTH_AAD_ALLOWED_TENANTS`).
638639
639-
![Download remote settings command](./images/download_remote_settings.png)
640+
![Download remote settings command](./images/download_remote_settings.png)
641+
642+
5. **First-Time Configuration Wizard**:
643+
* When you first access the admin settings page, a configuration wizard will guide you through the required and optional settings.
644+
* The wizard will help you configure:
645+
* **Application basics**: Title and logo customization
646+
* **GPT API settings**: Configure Azure OpenAI endpoints and models
647+
* **Workspace settings**: Enable personal and group workspaces
648+
* **Additional services**: Configure embedding, AI Search, Document Intelligence, and other required services
649+
* **Optional features**: Content safety, user feedback, conversation archiving, and other optional features
650+
* Required settings are clearly marked, ensuring that you configure all necessary components for your deployment scenario.
640651
641652
#### Alternate Method: Update App Settings via JSON (Advanced)
642653

RELEASE_NOTES.md

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,54 @@
22

33
# Feature Release
44

5+
### **(v0.214.001)**
6+
7+
#### New Features
8+
9+
* **Dark Mode Support**
10+
* Added full dark mode theming with support for:
11+
* Chat interface (left and right panes)
12+
* File metadata panels
13+
* Dropdowns, headers, buttons, and classification tables
14+
* User preferences persist across sessions.
15+
* Dark mode toggle in navbar with text labels and styling fixes (no flash during navigation).
16+
* **Admin Management Enhancements**
17+
* **First-Time Configuration Wizard**: Introduced a guided setup wizard on the Admin Settings page. This wizard simplifies the initial configuration process for application basics (title, logo), GPT API settings, workspace settings, additional services (Embedding, AI Search, Document Intelligence), and optional features. (Ref: `README.md`, `admin_settings.js`, `admin_settings.html`)
18+
* Admin Settings UI updated to show application version check status, comparing against the latest GitHub release. (Ref: `route_frontend_admin_settings.py`, `admin_settings.html`)
19+
* Added `logout_hint` parameter to resolve multi-identity logout errors.
20+
* Updated favicon and admin settings layout for improved clarity and usability.
21+
* **UI Banner & Visual Updates**
22+
* **Enhanced Document Dropdown (Chat Interface)**: The document selection dropdown in the chat interface has been significantly improved:
23+
* Increased width and scrollability for better handling of numerous documents.
24+
* Client-side search/filter functionality added to quickly find documents.
25+
* Improved visual feedback, including a "no matches found" message. (Ref: `chats.css`, `chat-documents.js`, `chats.html`)
26+
* New top-of-page banner added (configurable).
27+
* Local CSS/JS used across admin, group, and user workspaces for consistency and performance.
28+
* Updated `base.html` and `workspace.html` to reflect visual improvements.
29+
* **Application Setup & Configuration**
30+
* **Automatic Storage Container Creation**: The application now attempts to automatically create the `user-documents` and `group-documents` Azure Storage containers during initialization if they are not found, provided "Enhanced Citations" are enabled and a valid storage connection string is configured. Manual creation as per documentation is still the recommended primary approach. (Ref: `config.py`)
31+
* Updated documentation for Azure Storage Account setup, including guidance for the new First-Time Configuration Wizard. (Ref: `README.md`)
32+
* **Security Improvements**
33+
* Implemented `X-Content-Type-Options: nosniff` header to mitigate MIME sniffing vulnerabilities.
34+
* Enhanced security for loading AI Search index schema JSON files by implementing path validation and using `secure_filename` in backend settings. (Ref: `route_backend_settings.py`)
35+
* **Build & Deployment**
36+
* Added `docker_image_publish_dev.yml` GitHub Action workflow for publishing dev Docker images.
37+
* Updated Dockerfile to use Python 3.12.
38+
* **Version Enforcement**
39+
* GitHub workflow `enforce-dev-to-main.yml` added to prevent pull requests to `main` unless from `development`.
40+
41+
#### Bug Fixes
42+
43+
* **A. Document Processing**
44+
* **Document Deletion**: Resolved an issue where documents were not properly deleted from Azure Blob Storage. Now, when a document is deleted from the application, its corresponding blob is also removed from the `user-documents` or `group-documents` container if enhanced citations are enabled. (Ref: `functions_documents.py`)
45+
* **Configuration Validation (Enhanced Citations)**: Added validation in Admin Settings to ensure that if "Enhanced Citations" is enabled, the "Office Docs Storage Account Connection String" is also provided. If the connection string is missing, Enhanced Citations will be automatically disabled, and a warning message will be displayed to the admin, preventing silent failures. (Ref: `route_frontend_admin_settings.py`)
46+
* **C. UI & Usability**
47+
* **Local Assets for SimpleMDE**: The SimpleMDE Markdown editor assets (JS/CSS) are now served locally from `/static/js/simplemde/` and `/static/css/simplemde.min.css` instead of a CDN. This improves page load times, reduces external dependencies, and allows for use in offline or air-gapped environments. (Ref: `simplemde.min.js`, `simplemde.min.css` additions, template updates in `group_workspaces.html`, `workspace.html`)
48+
* General CSS cleanups across admin and workspace UIs.
49+
* **D. General Stability**
50+
* Merged contributions from multiple devs including UI fixes, backend updates, and config changes.
51+
* Removed unused video/audio container declarations for a leaner frontend.
52+
553
### **(v0.213.001)**
654

755
#### New Features

application/single_app/config.py

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@
8686

8787
app.config['SECRET_KEY'] = os.getenv("SECRET_KEY")
8888
app.config['SESSION_TYPE'] = 'filesystem'
89-
app.config['VERSION'] = '0.213.003'
89+
app.config['VERSION'] = '0.214.001'
9090
Session(app)
9191

9292
CLIENTS = {}
@@ -383,10 +383,32 @@ def initialize_clients(settings):
383383

384384
try:
385385
if enable_enhanced_citations:
386-
CLIENTS["storage_account_office_docs_client"] = BlobServiceClient.from_connection_string(settings.get("office_docs_storage_account_url"))
386+
blob_service_client = BlobServiceClient.from_connection_string(settings.get("office_docs_storage_account_url"))
387+
CLIENTS["storage_account_office_docs_client"] = blob_service_client
388+
389+
# Create containers if they don't exist
390+
# This addresses the issue where the application assumes containers exist
391+
for container_name in [storage_account_user_documents_container_name, storage_account_group_documents_container_name]:
392+
try:
393+
container_client = blob_service_client.get_container_client(container_name)
394+
if not container_client.exists():
395+
print(f"Container '{container_name}' does not exist. Creating...")
396+
container_client.create_container()
397+
print(f"Container '{container_name}' created successfully.")
398+
else:
399+
print(f"Container '{container_name}' already exists.")
400+
except Exception as container_error:
401+
print(f"Error creating container {container_name}: {str(container_error)}")
402+
403+
# Handle video and audio support when enabled
387404
# if enable_video_file_support:
388-
# CLIENTS["storage_account_video_files_client"] = BlobServiceClient.from_connection_string(settings.get("video_files_storage_account_url"))
405+
# video_client = BlobServiceClient.from_connection_string(settings.get("video_files_storage_account_url"))
406+
# CLIENTS["storage_account_video_files_client"] = video_client
407+
# # Create video containers if needed
408+
#
389409
# if enable_audio_file_support:
390-
# CLIENTS["storage_account_audio_files_client"] = BlobServiceClient.from_connection_string(settings.get("audio_files_storage_account_url"))
410+
# audio_client = BlobServiceClient.from_connection_string(settings.get("audio_files_storage_account_url"))
411+
# CLIENTS["storage_account_audio_files_client"] = audio_client
412+
# # Create audio containers if needed
391413
except Exception as e:
392414
print(f"Failed to initialize Blob Storage clients: {e}")

application/single_app/functions_documents.py

Lines changed: 61 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1110,8 +1110,55 @@ def get_document_version(user_id, document_id, version, group_id=None):
11101110
except Exception as e:
11111111
return jsonify({'error': f'Error retrieving document version: {str(e)}'}), 500
11121112

1113+
def delete_from_blob_storage(document_id, user_id, file_name, group_id=None):
1114+
"""Delete a document from Azure Blob Storage."""
1115+
is_group = group_id is not None
1116+
storage_account_container_name = (
1117+
storage_account_group_documents_container_name
1118+
if is_group else
1119+
storage_account_user_documents_container_name
1120+
)
1121+
1122+
# Check if enhanced citations are enabled and blob client is available
1123+
settings = get_settings()
1124+
enable_enhanced_citations = settings.get("enable_enhanced_citations", False)
1125+
1126+
if not enable_enhanced_citations:
1127+
return # No need to proceed if enhanced citations are disabled
1128+
1129+
try:
1130+
# Construct the blob path using the same format as in upload_to_blob
1131+
blob_path = f"{group_id}/{file_name}" if is_group else f"{user_id}/{file_name}"
1132+
1133+
# Get the blob client
1134+
blob_service_client = CLIENTS.get("storage_account_office_docs_client")
1135+
if not blob_service_client:
1136+
print(f"Warning: Enhanced citations enabled but blob service client not configured.")
1137+
return
1138+
1139+
# Get container client
1140+
container_client = blob_service_client.get_container_client(storage_account_container_name)
1141+
if not container_client:
1142+
print(f"Warning: Could not get container client for {storage_account_container_name}")
1143+
return
1144+
1145+
# Get blob client
1146+
blob_client = container_client.get_blob_client(blob_path)
1147+
1148+
# Delete the blob if it exists
1149+
if blob_client.exists():
1150+
blob_client.delete_blob()
1151+
print(f"Successfully deleted blob at {blob_path}")
1152+
else:
1153+
print(f"No blob found at {blob_path} to delete")
1154+
1155+
except Exception as e:
1156+
print(f"Error deleting document from blob storage: {str(e)}")
1157+
# Don't raise the exception, as we want the Cosmos DB deletion to proceed
1158+
# even if blob deletion fails
1159+
11131160
def delete_document(user_id, document_id, group_id=None):
1114-
"""Delete a document from the user's documents in Cosmos DB."""
1161+
"""Delete a document from the user's documents in Cosmos DB and blob storage if enhanced citations are enabled."""
11151162
is_group = group_id is not None
11161163
cosmos_container = cosmos_group_documents_container if is_group else cosmos_user_documents_container
11171164

@@ -1123,7 +1170,19 @@ def delete_document(user_id, document_id, group_id=None):
11231170

11241171
if (document_item.get('user_id') != user_id) or (is_group and document_item.get('group_id') != group_id):
11251172
raise Exception("Unauthorized access to document")
1126-
1173+
1174+
# Get the file name from the document to use for blob deletion
1175+
file_name = document_item.get('file_name')
1176+
1177+
# First try to delete from blob storage
1178+
try:
1179+
if file_name:
1180+
delete_from_blob_storage(document_id, user_id, file_name, group_id)
1181+
except Exception as blob_error:
1182+
# Log the error but continue with Cosmos DB deletion
1183+
print(f"Error deleting from blob storage (continuing with document deletion): {str(blob_error)}")
1184+
1185+
# Then delete from Cosmos DB
11271186
cosmos_container.delete_item(
11281187
item=document_id,
11291188
partition_key=document_id

0 commit comments

Comments
 (0)