Fix: Add _open() and path() methods to TenantAwareFileSystemStorage

Critical fix for Celery photo processing. The storage class now correctly
handles file reading operations by automatically adding tenant_id prefix
when opening files.

Problems fixed:
- Celery tasks could not open image files from storage
- PIL/Pillow couldn't locate files in tenant-specific directories
- temp file deletion was failing due to path validation

Changes:
- Added _open() method to add tenant_id prefix when opening files
- Added path() method to convert relative paths to full filesystem paths
- Updated delete() method to handle paths with or without tenant prefix
- All methods include security checks to prevent cross-tenant access

Testing:
- All 5 existing tests pass
- Verified photo processing task works end-to-end:
  * Reads temp image file from disk
  * Processes and creates all image versions
  * Saves processed files to tenant-specific directory
  * Cleans up temporary files correctly
- Files correctly stored in: media/tenants/{tenant_id}/products/{product_id}/{photo_id}/

🤖 Generated with Claude Code

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
2025-11-23 20:30:52 +03:00
parent ff40a9c1f0
commit 87cba63c47
4 changed files with 114 additions and 20 deletions

View File

@@ -172,15 +172,24 @@ def pos_terminal(request):
current_warehouse = get_pos_warehouse(request)
if not current_warehouse:
# Нет активных складов - показываем ошибку
from django.contrib import messages
messages.error(request, 'Нет активных складов. Обратитесь к администратору.')
# Нет активных складов - информация отображается в блоке склада в шаблоне
# Получаем системного клиента для корректного рендеринга JSON в шаблоне
system_customer, _ = Customer.get_or_create_system_customer()
context = {
'categories_json': json.dumps([]),
'items_json': json.dumps([]),
'showcase_kits_json': json.dumps([]),
'current_warehouse': None,
'warehouses': [],
'system_customer': {
'id': system_customer.id,
'name': system_customer.name
},
'selected_customer': {
'id': system_customer.id,
'name': system_customer.name
},
'cart_data': json.dumps({}),
'title': 'POS Terminal',
}
return render(request, 'pos/terminal.html', context)