Skip to content

feat: implement drive-style file management and related features - #784

Merged
pikann merged 5 commits into
masterfrom
feature/implement-file-management-feature
Nov 19, 2026
Merged

pikann merged 5 commits into
masterfrom
feature/implement-file-management-feature

Conversation

@pikann

@pikann pikann commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Adds a Drive-style file manager. Every uploaded file (user uploads, task attachments, document files, annotation screenshots) can be browsed, previewed, downloaded and organised in folders, in a project scope and a general (workspace) scope. Each project gets default folders for the files the product creates itself, and a global Files page lists everything the caller may read, with each project shown as a folder.

Design notes: docs/product/file-management.md.

Data model (migration 000093_file_management.sql)

  • New file_folders table. The existing files table becomes the manageable item and gains project_id (NULL = general scope), folder_id, source and trash columns. Names are not unique within a folder.
  • View file_items presents folders and uploaded files as one list, so listing, search, sort and paging are a single query.
  • Default folders per project (created by a trigger on projects, backfilled for existing ones): Task attachments (one subfolder per task, e.g. PACA-12), Document files, Annotation screenshots. They are locked: no rename, move or delete, and nothing can be created or moved into them.
  • A BEFORE INSERT trigger on files classifies a new row from its storage-key prefix and, for tasks and docs, resolves the project and folder. The existing upload services are unchanged. Screenshots get their folder when an annotation references them. Existing rows are backfilled.
  • Removing a task attachment from its task sends the file to the trash (only when it has a folder; a row whose task is gone is not in file_items, so it is left alone).
  • The same file also grants files:read / files:write to existing roles (see Permissions), because seeding never rewrites the policy of a role that already exists.
  • Avatars and workspace logos are not included: their bytes live in avatar_key columns and the upload row is deleted.

Backend

  • domain/file, service/file, Postgres repository, DTOs and FileHandler.
  • Routes under /projects/{projectId}/files/... and /files/... (shared handlers): list/search, breadcrumb, folders, rename/move, trash, restore, permanent delete, presigned upload (single and multipart), download URL, stars, recents, trash list. GET /files/roots lists the general folder plus every project the caller may read.
  • Trash is a shared deleted_at on a folder and its subtree, so restore brings back exactly that subtree. A FileTrashPurger worker deletes items and their objects after 30 days.
  • Files that something else uses (task attachments, document files, annotation screenshots) are deleted for good from the file manager, after a confirmation that names what uses them, instead of being trashed: a trash entry would only postpone, silently, the day the owner loses the file. Plain uploads go to the trash.
  • A node of another scope is reported as not found, so an id from one project cannot be read through another project's route.

Permissions

  • New IAM actions files:read and files:write. Project routes are gated on the project; the general scope uses the new platform root file/* (mirrored in the web role editor codec and the role-policy skill).
  • Default roles: project Viewer and Analyst get files:read, Editor and Admin get both. Platform ADMIN gets both on the general scope. Platform USER gets neither, because the actions apply to every file in a scope.
  • The migration adds the same to existing roles: ADMIN by name, and any other role that grants docs:read / docs:write in an Allow statement confined to projects gets the matching files action. A statement that can match file/* (resource *) is left alone.
  • Limiting a role to a single folder is not part of this change.

Web

  • Files section in the sidebar (Files, Recent, Starred, Trash), globally and per project. No separate left rail.
  • Drive-style browser: breadcrumb, list and grid views, sort, name search with type filters, context menu, multi-select with keyboard shortcuts, drag items onto a folder or breadcrumb to move, drag files or folders in from the desktop to upload, details panel. New is at the top right of the page.
  • Upload progress is reported through the existing toast component (one loading toast per batch, with Cancel).
  • Preview with @eternalheart/react-file-preview, loaded lazily; the PDF worker is served from our own origin. Previous/next across a folder.
  • Task detail: clicking a task attachment, an inline image or a file block in the description opens the preview instead of downloading.
  • Description editor: new file panel (Upload / From files / Embed link) that matches the app and can pick a file from the project's Files (stored as files://{project}/{file}).
  • Strings in all nine locales.

BlockNote fixes

  • Dark mode: file blocks turned white on hover because BlockNote hard-codes light greys. They now use the app's theme tokens.
  • "+" menu: in the document editor and task description the menu closed itself ~100 ms after opening, so options could only be chosen with the keyboard. In collaborative editors BlockNote tracked the menu with a Yjs relative position outside the paragraph; the first cursor update moved it. The "+" button now opens the menu the way typing "/" does (collaborative editors only) and removes the stray "/" if the menu is dismissed.
  • The description rendered two "/" menus on top of each other; it now matches the other editors (slashMenu={false}).
  • Menu items are grouped contiguously (the Mermaid item added a second "Advanced" group label and React logged a duplicate-key warning), and the item loaders have a stable identity.

Upgrade notes

  • One migration. Existing installs get the default folders, classified files and role grants on startup.
  • If you ran an earlier draft of 000093 locally (it created a file_nodes table), the runner will not re-run the file: drop file_nodes, file_stars, file_recents and the file_nodes_* triggers/functions and delete its schema_migrations row before starting the API.
  • This branch uses migration number 93; check for a clash with other branches that add 000093_… files.

Testing

  • Go: new service and Postgres repository tests; router authorization and route-coverage tests updated; role/default-policy and legacy-key tests updated.
  • Web: unit tests for the file helpers, inline-media parsing and menu grouping; full suite passes (1752), tsc -b and biome clean.
  • E2E (Playwright, Chromium, against the e2e stack): tests/files/file-manager.spec.ts (default folders and sidebar, folders/upload/preview/star/trash/restore, task attachment mirroring and deletion, task attachment, inline image and file block preview, picking from Files, dark-mode hover) and tests/ux/blocknote-add-block-menu.spec.ts (the "+" menu in the document, description and comment editors: mouse, keyboard, dismiss).
  • Not covered: previews of Word/Excel/PowerPoint files in a real browser (PDF, text, images and Markdown were exercised), small screens, and non-Chromium browsers.
  • Some existing tests already fail on master and are unrelated: TestSeedPlatformRoles_ReconcilesMigratedRoles, TestWriteDocumentAtPath_DocDeletedBeforeRowLockIsPathChanged, TestGitStore_ChangeRequestsAndTaskLinks, TestPluginManifestActionsMigration, TestProjectRoleResourcesMigration, TestRolesAssignMigration, TestRolesAPI_EndToEnd, TestServiceAccountsAPI_EndToEnd and TestIAMMigrationKeyMapping.

Known limitations

  • Recent, Starred and Trash show up to 100 items per scope without paging; the global versions merge one request per project.
  • No rubber-band selection, and dropping files onto a folder card uploads into the current folder only.

- Introduced a new file management system with a dedicated file handler.
- Added routes for file operations including listing, downloading, and managing files and folders.
- Created a file trash purger to permanently delete files after a retention period.
- Updated database schema to support file management, including new tables for file folders, stars, and recents.
- Implemented triggers and functions for automatic folder creation and file classification based on storage keys.
- Enhanced IAM policies to include new file management actions.
- Updated integration tests to account for new file management features and ensure legacy compatibility.

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Important

Two lifetime problems in the trash pipeline need a decision before merge: deleting a file from the manager (or letting the 30-day purger run) silently detaches it from live annotations and tasks, and the backfill creates trashed rows the purger can never reach.

Approach: sound — putting the manager on the existing files table with a classifying trigger leaves every existing upload path untouched and collapses folders and files into one file_items list; the cost is that the manager now owns the lifetime of rows other features still reference, which is where the findings below concentrate.

Reviewed changes — the whole PR: migration 000093, the file domain/repository/service, handler, router gates and IAM, the trash purger, the web Files UI, the task-attachment and BlockNote integrations, i18n, docs and the e2e spec.

  • Schema and migration — new files columns, file_folders, file_stars, file_recents, the file_items view, the classification/backfill triggers and the rewrite of existing roles.
  • Backend — filedom and FileRepository (reads through the view, scopeClause everywhere), filesvc with scope checks, presigned upload/download, trash/restore/purge, and the hourly leader-locked purger wired into bootstrap.
  • HTTP and IAM — shared handlers per scope, require.Project(files:*) / require.Global(files:*) on file/*, the ungated-but-filtered /files/roots, new apierr codes and presenter mappings, default role policies.
  • Web UI — Files page with grid/list, breadcrumbs, desktop drop and in-app drag-move, move/rename/confirm dialogs, details sheet, lazy preview overlay, batched upload queue with folder creation.
  • Integrations — task attachments previewing in place, BlockNote file panel (upload / pick from project Files / embed) with files:// URIs, inline media preview across a description.
  • Tests and docs — service tests, Postgres repository tests for classification and the trash lifecycle, route-coverage and authz test updates, a full e2e spec, and the product design doc.

Pullfrog  | Fix all ➔ | Fix 👍s ➔ | View workflow run | Using deepseek-v4.1-flash-1017 (free via Pullfrog for OSS) | 𝕏

Comment thread docs/product/file-management.md Resolved
…es, and annotation screenshots

- Added new confirmation messages for deleting managed files in Russian, Vietnamese, and Simplified Chinese.
- Updated the files API to include logic for determining if a file should be permanently deleted instead of moved to trash.
- Enhanced the file management documentation to reflect the new deletion behavior and UI changes.
- Modified the file service to handle the deletion of files referenced by tasks, documents, and annotations correctly.
- Created integration tests to ensure the correct behavior of file deletion and role grants after migration.

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ No new issues found.

Approach: sound — the new commit replaces the delayed, silent detachment of referenced files with an explicit delete-for-good plus a confirmation that names the owner, and it closes each of the lifetime and permission holes raised in the previous review.

Reviewed changes — the delta since the prior pullfrog review at ecb7450d (commit 5913b8a6, 21 files).

  • Added Node.DeletedForGood() and routed task attachments, document files and annotation screenshots through deleteReferencedFile (unlink, then purge the row and its bytes), leaving plain uploads and folders on the trash path.
  • Replaced the task-attachment-only confirmation with deleteManaged copy for documents and annotations, mirrored across all nine locales.
  • Unified every trash entry point in files-page.tsx through trashNodes, which filters system folders and scopes the caller cannot write.
  • Guarded the task-attachment trigger and the migration backfill with folder_id IS NOT NULL, so no row stamped as trashed can fall outside file_items.
  • Restricted the docs→files role mirror to Allow statements confined to project/…, so a * resource never derives the general file/* scope.
  • Added migration integration tests for the role matrix and the trigger predicate, an e2e delete-for-good case, and brought the design doc in line with the shipped API.

Pullfrog  | View workflow run | Using deepseek-v4.1-flash-1017 (free via Pullfrog for OSS) | 𝕏

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ℹ️ No critical issues — one minor scalability suggestion inline.

Approach: sound — the commit folds rename and move into a single validated Update, verifies the uploaded object before marking it uploaded, and forces active content to download; each change closes a real gap without adding a parallel mechanism.

Reviewed changes — the delta since the prior pullfrog review at 5913b8a6 (commit 62aaf8d3, 8 files).

  • Rename/move unified — Service.Update validates the name, lock state, destination and self/descendant move before either write, so a rejected move no longer leaves a rename applied; the handler delegates to it.
  • Upload integrity — CompleteUpload checks the object through a new optional objectStatter (S3Client.StatObject) and rejects the upload when the bytes are missing or their size differs from the declared one (ErrUploadNotComplete → 409).
  • Active content — DownloadURL forces Content-Disposition: attachment for HTML/XHTML/SVG/XML/JS/CSS content types and the same file extensions, so none of them render from the storage origin.
  • Trash pipeline — restore treats a missing parent folder as trashed (COALESCE(..., TRUE)), purgeTx unlinks task attachments inside the delete transaction (replacing UnlinkTaskAttachment), and the purger continues past a failing root and joins the errors.
  • Roots paging — /files/roots walks every project page instead of stopping at 10 000, and 000093 adds idx_files_project.
  • Tests — new service tests for the object/size check and the active-content predicate; the referenced-file test no longer expects a separate unlink.

Pullfrog  | Fix all ➔ | Fix 👍s ➔ | View workflow run | Using deepseek-v4.1-flash-1017 (free via Pullfrog for OSS) | 𝕏

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ No new issues found.

Approach: sound — the commit closes the remaining scalability note by batching every /files/roots scope check through AuthorizeMany, so the request costs one grants lookup regardless of project count.

Reviewed changes — the delta since the prior pullfrog review at 62aaf8d3 (commit a3d906c5, 1 file).

  • Batched /files/roots authorization — Roots builds one iam.Query for the general scope plus one per project and evaluates them through a new allowed helper, which type-asserts iam.Checker to an AuthorizeMany interface and keeps the per-query Authorize fallback for checkers that only implement Checker. Queries stay in the same order as the response, so the allowed[0] / allowed[i+1] indexing matches the existing root construction.
  • Deny-on-unknown preserved — an AuthorizeMany error aborts the request as before, a nil checker still returns iam.ErrNotConfigured, and a result slice shorter than the query slice leaves the remaining entries false rather than panicking.

Verified with go build of internal/transport/http/handler and internal/platform/authz/iam on this commit.

The earlier ℹ️ thread on the per-project grants lookups is addressed; replied and resolved.

Pullfrog  | View workflow run | Using deepseek-v4.1-flash-1017 (free via Pullfrog for OSS) | 𝕏

@pikann
pikann merged commit 17bbc97 into master Nov 19, 2026
8 checks passed
@pikann
pikann deleted the feature/implement-file-management-feature branch November 19, 2026 09:21
robertcoroianu added a commit to robertcoroianu/paca that referenced this pull request Nov 19, 2026
Secondary text and hairlines were faded well past readability. The base
tokens were fine on their own (muted text 4.7:1 on white), but
components layered heavy opacity on top: ~380 uses of muted text at
/30-/60 rendered at roughly 1.5-2.3:1, and borders at /10-/30 were
close to invisible (1.04-1.12:1).

Tokens (index.css):
- --muted-foreground: #737373 -> #5f5f5f (light, 6.4:1),
  #888888 -> #a0a0a0 (dark, 7.6:1)
- --border/--input: #d4d4d4 -> #c8c8c8 (light), #2a2a2a -> #3a3a3a (dark)
- --sidebar-border: #e8e8e8 -> #dedede (light), #1e1e1e -> #2a2a2a (dark)

Opacity floors across components (mechanical sweep):
- text-muted-foreground /30-/60 -> /90 (>= 4.5:1 on background, muted
  and secondary surfaces in both themes; /85 would still fail at
  4.48:1), /70-/90 -> full strength, so two tiers remain
- text-sidebar-foreground /30-/50 -> /60 (4.94:1 light, 6.53:1 dark);
  the sidebar has its own foreground token
- border/divide/ring/bg-border /10-/35 -> /50, /40 -> /60; Gantt
  gridlines /12 -> /30 so they stay lighter than row dividers. The
  dashed row dividers from Paca-AI#785 are left as tuned.

The Gantt drag tests located groups by a border class; they now use a
`data-gantt-group` attribute so styling changes don't break them.

Rebuilt on current master (after Paca-AI#784, Paca-AI#785-Paca-AI#787, Paca-AI#789) so the new
file-management components get the same treatment.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant