fix(files): tenant root = shared org workspace, member-writable via explicit flag (B-7, #38) #80

Merged
amiryahaya merged 1 commit from fix/b7-root-folder-membership into main 2026-11-07 05:29:48 +01:00
Owner

Closes #38 (B-7 baseline finding — multi-member tenants: everyone but the first member got 403 uploading to the org root)

The bug

GetRootFolder picked the tenant root with no owner filter (first caller became OwnerId), and both upload gates (CreateUploadUrl + legacy multipart UploadFile) then required folder.OwnerId == user.Id or a personal write-share — members of an org couldn't use their own workspace root. The Personal-tenant auto-creation half of the finding was already resolved by ACC-03 (task 1.1).

The fix — explicit canonical-root flag

  • Folder.IsTenantRoot (migration FolderIsTenantRoot): marks THE shared workspace root, managed by GetRootFolder (created with the flag; pre-flag tenants converge by promoting the earliest root-level folder so members keep the workspace they know)
  • FolderAccessPolicy.IsTenantRootSharedAsync: canonical root + active tenant membership (UserTenant row) ⇒ write — wired into both upload gates
  • Other root-level folders stay personal: the first attempt inferred "tenant root" from ParentFolderId == null — the existing SecureFileSharingE2eTests.ReadShareHolder_CannotUploadToSharedFolder E2E caught it (Alice's root-level folder became member-writable). That E2E now passes unchanged, guarding the corrected semantics
  • Subfolders: owner/share semantics untouched (control test)

Verification

TDD: 3 tests first — RED ×2 (member root upload via upload-url + legacy multipart), subfolder control green throughout. One unrelated registry-E2E flake on first suite run, green on rerun.
Suite 872 / 0 failed / 39 skipped (Release + Debug) · coverage gate 84.99% ≥ 80

Closes #38 (B-7 baseline finding — multi-member tenants: everyone but the first member got 403 uploading to the org root) ## The bug `GetRootFolder` picked the tenant root with no owner filter (first caller became `OwnerId`), and both upload gates (`CreateUploadUrl` + legacy multipart `UploadFile`) then required `folder.OwnerId == user.Id` **or a personal write-share** — members of an org couldn't use their own workspace root. The Personal-tenant auto-creation half of the finding was already resolved by ACC-03 (task 1.1). ## The fix — explicit canonical-root flag - **`Folder.IsTenantRoot`** (migration `FolderIsTenantRoot`): marks THE shared workspace root, managed by `GetRootFolder` (created with the flag; pre-flag tenants converge by promoting the **earliest** root-level folder so members keep the workspace they know) - **`FolderAccessPolicy.IsTenantRootSharedAsync`**: canonical root + active tenant membership (`UserTenant` row) ⇒ write — wired into both upload gates - **Other root-level folders stay personal**: the first attempt inferred "tenant root" from `ParentFolderId == null` — the existing `SecureFileSharingE2eTests.ReadShareHolder_CannotUploadToSharedFolder` E2E caught it (Alice's root-level folder became member-writable). That E2E now passes **unchanged**, guarding the corrected semantics - Subfolders: owner/share semantics untouched (control test) ## Verification TDD: 3 tests first — RED ×2 (member root upload via upload-url + legacy multipart), subfolder control green throughout. One unrelated registry-E2E flake on first suite run, green on rerun. **Suite 872 / 0 failed / 39 skipped (Release + Debug) · coverage gate 84.99% ≥ 80**
fix(files): tenant root is the shared org workspace — member-writable via explicit flag (B-7, #38)
All checks were successful
API CI / build-and-test (pull_request) Successful in 35m29s
2832e747b1
The bug: GetRootFolder selected the tenant root with no owner filter (first
member to call it became OwnerId), and the upload gates then required
folder.OwnerId == user.Id or a personal write-share — so in a multi-member
tenant every member except the first got 403 uploading to the org root.
Nothing repaired ownership.

Fix — explicit canonical-root flag (Folder.IsTenantRoot):
- GetRootFolder creates/promotes the canonical root with IsTenantRoot =
  true; converges pre-flag tenants by promoting the EARLIEST root-level
  folder (members keep the workspace they know)
- FolderAccessPolicy.IsTenantRootSharedAsync: canonical root + active
  tenant membership (UserTenant row) => write access — wired into
  CreateUploadUrl and the legacy multipart UploadFile gate
- OTHER root-level folders (CreateFolder's ParentFolderId == null outputs)
  stay PERSONAL to their owner — the first implementation attempt inferred
  'tenant root' from ParentFolderId == null and the
  SecureFileSharingE2eTests.ReadShareHolder_CannotUploadToSharedFolder
  E2E caught it (Alice's root-level folder became member-writable); the
  E2E now passes unchanged, guarding the corrected semantics
- Subfolders unchanged: owner/share semantics untouched (control test)
- The Personal-tenant auto-creation half of the finding was already
  resolved by ACC-03 (task 1.1) — only SuperAdmin bootstraps a workspace

TDD: 3 tests first — RED x2 (member root upload via upload-url and legacy
multipart both 403), subfolder control green throughout.

Suite 872 / 0 failed / 39 skipped (Release + Debug; one unrelated
registry-E2E flake on first run, green on rerun); gate 84.99% >= 80.
Sign in to join this conversation.
No description provided.