[PR #411] [MERGED] Tenant-scoped Video Studio storage resolver and legacy uploads migration #716

Closed
opened 2026-03-13 21:05:21 +03:00 by kerem · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/AJaySi/ALwrity/pull/411
Author: @AJaySi
Created: 3/12/2026
Status: Merged
Merged: 3/12/2026
Merged by: @AJaySi

Base: mainHead: codex/implement-shared-path-resolver-and-update-avatar.py


📝 Commits (1)

  • 29c268d Add tenant-aware video studio storage path resolver

📊 Changes

3 files changed (+222 additions, -13 deletions)

View changed files

📝 backend/api/video_studio/handlers/avatar.py (+26 -13)
backend/scripts/migrate_video_studio_uploads_to_workspace.py (+127 -0)
backend/utils/storage_paths.py (+69 -0)

📄 Description

Motivation

  • Centralize and standardize filesystem paths so Video Studio assets live under per-tenant workspaces (workspace/workspace_<safe_user_id>/media/...).
  • Avoid global import-time directory creation and ensure upload/output directories are created in the context of the current user/request.
  • Preserve compatibility with existing deployments that stored uploads in legacy global locations.
  • Provide a safe migration path to move legacy files into tenant media folders using available task/user metadata.

Description

  • Added a shared resolver backend/utils/storage_paths.py that exposes resolve_user_media_path, get_user_workspace, get_workspace_root, sanitize_user_id, and get_legacy_video_studio_upload_dirs, with path sanitization and escaping protection.
  • Updated backend/api/video_studio/handlers/avatar.py to remove the global UPLOAD_DIR, use resolve_user_media_path(user_id, "video_studio", "uploads", create=True) for temp uploads and resolve_user_media_path(user_id, "video_studio", "videos", create=True) for generated outputs, and to create these directories per-request.
  • Reworked the download route in avatar.py to search tenant media paths first and then fall back to known legacy global upload directories returned by get_legacy_video_studio_upload_dirs to maintain backward compatibility.
  • Added migration helper script backend/scripts/migrate_video_studio_uploads_to_workspace.py that builds task_id -> user_id mappings by scanning per-user DBs and can move legacy video_studio/uploads artifacts into tenant media/video_studio/{uploads|videos} directories (dry-run by default, --apply to move).

Testing

  • Compiled changed files with python -m py_compile backend/utils/storage_paths.py backend/api/video_studio/handlers/avatar.py backend/scripts/migrate_video_studio_uploads_to_workspace.py which completed successfully.
  • Static inspection and basic path resolution checks were performed via unitless dry-run logic in the migration script (no file moves without --apply).
  • No runtime integration tests were executed in this change set.

Codex Task


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/AJaySi/ALwrity/pull/411 **Author:** [@AJaySi](https://github.com/AJaySi) **Created:** 3/12/2026 **Status:** ✅ Merged **Merged:** 3/12/2026 **Merged by:** [@AJaySi](https://github.com/AJaySi) **Base:** `main` ← **Head:** `codex/implement-shared-path-resolver-and-update-avatar.py` --- ### 📝 Commits (1) - [`29c268d`](https://github.com/AJaySi/ALwrity/commit/29c268dda8821b52dcaf6de4a2f320e6990d9e07) Add tenant-aware video studio storage path resolver ### 📊 Changes **3 files changed** (+222 additions, -13 deletions) <details> <summary>View changed files</summary> 📝 `backend/api/video_studio/handlers/avatar.py` (+26 -13) ➕ `backend/scripts/migrate_video_studio_uploads_to_workspace.py` (+127 -0) ➕ `backend/utils/storage_paths.py` (+69 -0) </details> ### 📄 Description ### Motivation - Centralize and standardize filesystem paths so Video Studio assets live under per-tenant workspaces (`workspace/workspace_<safe_user_id>/media/...`). - Avoid global import-time directory creation and ensure upload/output directories are created in the context of the current user/request. - Preserve compatibility with existing deployments that stored uploads in legacy global locations. - Provide a safe migration path to move legacy files into tenant media folders using available task/user metadata. ### Description - Added a shared resolver `backend/utils/storage_paths.py` that exposes `resolve_user_media_path`, `get_user_workspace`, `get_workspace_root`, `sanitize_user_id`, and `get_legacy_video_studio_upload_dirs`, with path sanitization and escaping protection. - Updated `backend/api/video_studio/handlers/avatar.py` to remove the global `UPLOAD_DIR`, use `resolve_user_media_path(user_id, "video_studio", "uploads", create=True)` for temp uploads and `resolve_user_media_path(user_id, "video_studio", "videos", create=True)` for generated outputs, and to create these directories per-request. - Reworked the download route in `avatar.py` to search tenant media paths first and then fall back to known legacy global upload directories returned by `get_legacy_video_studio_upload_dirs` to maintain backward compatibility. - Added migration helper script `backend/scripts/migrate_video_studio_uploads_to_workspace.py` that builds `task_id -> user_id` mappings by scanning per-user DBs and can move legacy `video_studio/uploads` artifacts into tenant `media/video_studio/{uploads|videos}` directories (dry-run by default, `--apply` to move). ### Testing - Compiled changed files with `python -m py_compile backend/utils/storage_paths.py backend/api/video_studio/handlers/avatar.py backend/scripts/migrate_video_studio_uploads_to_workspace.py` which completed successfully. - Static inspection and basic path resolution checks were performed via unitless dry-run logic in the migration script (no file moves without `--apply`). - No runtime integration tests were executed in this change set. ------ [Codex Task](https://chatgpt.com/codex/tasks/task_e_69afb09d58788328adc677899e12d494) --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
kerem 2026-03-13 21:05:21 +03:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/ALwrity#716
No description provided.