Jul 16 - Fill the gaps between Single-tenant mode and Multi-tenant mode - MT2

This commit is contained in:
2026-07-16 16:59:17 -04:00
parent 8ff38578ad
commit a60afc6c41
10 changed files with 478 additions and 44 deletions
+9 -13
View File
@@ -59,11 +59,10 @@ def _save_photo(file_obj, subfolder='inspection_photos'):
file_obj.seek(0)
if not any(header.startswith(m) for m in _IMAGE_MAGIC):
return None
filename = f"{uuid.uuid4().hex}.{ext}"
dest_dir = os.path.join(current_app.config['UPLOAD_FOLDER'], subfolder)
os.makedirs(dest_dir, exist_ok=True)
file_obj.save(os.path.join(dest_dir, filename))
return f"uploads/{subfolder}/{filename}"
# Write via the active storage backend (local disk or R2). Key format
# 'uploads/<subfolder>/<uuid>.<ext>' is unchanged across backends.
from app.utils import storage
return storage.save(file_obj, subfolder)
def _collect_form_responses(form_fields, existing_responses=None):
@@ -1323,15 +1322,12 @@ def delete(inspection_id):
db.session.delete(inspection)
db.session.commit()
# Remove orphaned photo files from the active storage backend — best-effort.
# (Also fixes the previous double-'static' path that normalized to
# app/static/static/... and never actually deleted anything.)
from app.utils import storage
for rel_path in photo_paths:
abs_path = os.path.normpath(
os.path.join(current_app.config['UPLOAD_FOLDER'], '..', 'static', rel_path)
)
try:
if os.path.isfile(abs_path):
os.remove(abs_path)
except OSError:
pass
storage.delete(rel_path)
current_app.logger.info(
'INSPECTION DELETED | id=%s | facility="%s" | template="%s" | '
+3 -8
View File
@@ -1008,15 +1008,10 @@ def delete(issue_id):
db.session.delete(issue)
db.session.commit()
# Remove orphaned photo files — best-effort, never block on failure
static_folder = current_app.root_path
# Remove orphaned photo files from the active storage backend — best-effort.
from app.utils import storage
for rel_path in photo_paths:
abs_path = os.path.normpath(os.path.join(static_folder, 'static', rel_path))
try:
if os.path.isfile(abs_path):
os.remove(abs_path)
except OSError:
pass
storage.delete(rel_path)
current_app.logger.info(
'ISSUE DELETED | id=%s | severity=%s | area=%s | facility=%s | deleted_by=%s',