Skip to content

feat(storage): support chat attachment storage CU-86agmkyyu - #3243

Merged
yevhenii-flamingo merged 9 commits into
mainfrom
feat/chat-attachments-audit
Dec 4, 2026
Merged

yevhenii-flamingo merged 9 commits into
mainfrom
feat/chat-attachments-audit

Conversation

@yevhenii-flamingo

@yevhenii-flamingo yevhenii-flamingo commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • Add signed GCS upload headers and immutable copy operations for verified chat files.
  • Add an insert-once ticket attachment repository operation and audit actions for upload, link issuance and deletion.

Verification

Focused storage and Mongo repository regression tests passed locally. Tenant integration used the reviewed library changes in an isolated Maven cache.

ClickUp task

Change-Set: feat-chat-attachments-audit

Change set flamingo-stack/openframe-oss-lib#3243: these pull requests are one change, reviewed together.

Linked work

  • …and 1 linked item not shown here

Linked by the Depends-On / Change-Set lines in these descriptions; this block is maintained by the hub.

@yevhenii-flamingo yevhenii-flamingo added the build Run the PR builds and publish snapshots (Java, npm preview); stays on until removed label Nov 27, 2026
@yevhenii-flamingo
yevhenii-flamingo marked this pull request as ready for review November 27, 2026 16:13
@yevhenii-flamingo
yevhenii-flamingo marked this pull request as draft November 27, 2026 16:23
@yevhenii-flamingo yevhenii-flamingo removed the build Run the PR builds and publish snapshots (Java, npm preview); stays on until removed label Nov 27, 2026
@flamingo

flamingo Bot commented Dec 4, 2026

Copy link
Copy Markdown
Contributor

🦩 flamingo Code Review

4 findings: 🔴 1 action required · 🟠 0 recommended · 🔵 3 informational

Advisory: findings do not block the merge.

Rules cited: OFJAVA-007, OFJAVA-002, OFJAVA-013 · 1 defect outside any rule

Files Lines 🔴 Action required 🟠 Recommended 🔵 Informational
9 +594 / -3 1 0 3

🔴 Action required (1)

# Where Finding Flagged by
1 CustomTicketAttachmentRepositoryImpl.java:41 Derived _id ignores ticketId while the upsert query filters on it, so two tickets sharing a storagePath collide Review

🔵 Informational (3)

# Where Finding Flagged by
2 GcsPresignedUrlService.java:262 Five-clause copy-match condition inlined instead of a named predicate (Minor) OFJAVA-007
3 GcsPresignedUrlService.java:165 Nested method calls as arguments in the new GCS read/copy helpers (Minor) OFJAVA-002
4 CustomTicketAttachmentRepositoryImpl.java:52 findOrInsert returns null to signal "inserted" and the caller null-checks it (Minor) OFJAVA-013

✅ What this change does well

  • GcsPresignedUrlService now takes Storage via a package-private constructor, which makes the new read/copy logic unit-testable (GcsPresignedUrlServiceReadTest covers size bounds, 412 retry and copy preconditions).
  • The immutable copy path uses generationMatch + doesNotExist preconditions and verifies an existing target by crc32c before accepting it, avoiding silent overwrites.
  • TicketAttachmentRepositoryIT covers the idempotent-insert branch, asserting the retry returns the original document and is not counted as an insertion.

Inline comments: 4 new

11 possible problems checked and ruled out, 2 after reading more of the repository
  • openframe-data-mongo-common/src/main/java/com/openframe/data/document/audit/AuditAction.java:378 17 new or changed definitions have no test referencing them: Listed items are enum constants and declarative repository signatures; missing tests for these is boilerplate noise.
  • openframe-data-mongo-sync/src/main/java/com/openframe/data/repository/ticket/CustomTicketAttachmentRepository.java:6 New /** ... / doc blocks added on the attachment repository types: File line 6 does add a /* ... */ block that largely describes WHAT the type does; R4 forbids doc blocks, though this is a single short line arguably stating an invariant, small.
  • openframe-data-mongo-sync/src/main/java/com/openframe/data/repository/ticket/CustomTicketAttachmentRepositoryImpl.java:60 findOrInsert returns null to signal "inserted" and the caller null-checks it: duplicate of candidate 6
  • openframe-data-mongo-sync/src/main/java/com/openframe/data/service/GcsPresignedUrlService.java:199 copyImmutableFile lacks the idempotent 412 retry path its sibling copyImmutableDownload has: copyImmutableFile line 199 calls copyIfAbsent with no 412 handling while sibling copyImmutableDownload wraps the identical call; asymmetry visible in diff, retry path unknown.
  • openframe-data-mongo-sync/src/main/java/com/openframe/data/service/GcsPresignedUrlService.java:279 Immutable-write retry reports a size error instead of a content mismatch when the stored object is larger: line 279 readFile(path, content.length) throws IllegalArgumentException("File exceeds the allowed size") when the stored blob is larger, masking the intended IllegalStateException; real edge case.
  • openframe-data-mongo-sync/src/main/java/com/openframe/data/repository/ticket/CustomTicketAttachmentRepositoryImpl.java:73 findConcurrentCopy mutates the caller's Query by setting a read preference on it: Line 73 mutates the caller-owned Query in place, but it happens after findAndModify completed and the query is not reused, so the effect is benign; still a real hidden mutation.
  • openframe-data-mongo-sync/src/main/java/com/openframe/data/service/GcsPresignedUrlService.java:143 Percent-encoding and RFC 5987 filename literals inlined in generateReadUrl: Percent-encoding fixups and the RFC 5987 prefix are local formatting literals; naming them is a pedantic nit, not the magic-number problem the rule targets in logic/comparisons.
  • openframe-data-mongo-sync/src/main/java/com/openframe/data/service/GcsPresignedUrlService.java:49 @‍Autowired added to the @‍Service GcsPresignedUrlService constructor: The rule forbids field injection via @‍Autowired and manual loggers; an @‍Autowired marking the chosen constructor among two is standard Spring and not what the rule names.
  • openframe-data-mongo-sync/src/main/java/com/openframe/data/repository/ticket/CustomTicketAttachmentRepository.java:13 InsertionResult data carrier uses @‍Value instead of the Lombok quad: InsertionResult is an internal method-return tuple, not a document/DTO/model needing Jackson or a builder; the rule's scope does not cover it.
  • openframe-data-mongo-sync/src/main/java/com/openframe/data/repository/ticket/CustomTicketAttachmentRepositoryImpl.java:23 New custom repository impl is neither tenant-gated nor using TenantAwareMongoTemplate: Many sibling custom impls in openframe-data-mongo-sync (CustomScriptRepositoryImpl:42-44, CustomUserRepositoryImpl:19-21, CustomOrganizationRepositoryImpl:25-28, CustomDeviceOsUpdateHistoryRepositoryImpl:18-20) use plain MongoTemplate with no tenant-isolation gate; the gate is applied only to impls extending TenantAwareRepositorySupport. The new impl takes tenantId from the entity and filters on…
  • openframe-data-mongo-sync/src/main/java/com/openframe/data/repository/ticket/CustomTicketAttachmentRepositoryImpl.java:23 Custom tenant-scoped repository implementation is not gated with the tenant-isolation property: Same claim as candidate 0 and refuted the same way: the impl uses plain MongoTemplate with explicit tenantId criteria, matching the many ungated sibling impls (e.g. CustomScriptRepositoryImpl:42-44).
🤖 Prompt for AI agents: fix every finding
Address these code-review findings on pull request #3243 of flamingo-stack/openframe-oss-lib, most important first.
For each one, make the minimal change that resolves it and do not refactor unrelated code.
If you can show a finding is wrong, skip it and say why.

1. [Action required] openframe-data-mongo-sync/src/main/java/com/openframe/data/repository/ticket/CustomTicketAttachmentRepositoryImpl.java:41 Derived _id ignores ticketId while the upsert query filters on it, so two tickets sharing a storagePath collide
   The lookup query keys on tenantId + ticketId + storagePath, but the deterministic id is derived only from `tenantId + "/" + storagePath`. If the same storagePath is ever reused under a different ticketId in the same tenant (the query treats these as distinct documents), the upsert will not match any document and will try to insert with an _id that already exists. The DuplicateKeyException path then re-queries with the same ticketId-bearing filter, finds nothing (the existing doc has the other ticketId), and `orElseThrow(() -> exception)` rethrows the duplicate-key error to the caller, so the attachment can never be recorded. Either the identity must include ticketId, or the query must drop it.
2. [Informational] openframe-data-mongo-sync/src/main/java/com/openframe/data/service/GcsPresignedUrlService.java:262 Five-clause copy-match condition inlined instead of a named predicate
   OFJAVA-007 makes a named private predicate mandatory for any condition containing && . requireMatchingCopy builds a five-term boolean inline, mixing the null guard, checksum comparison and four metadata comparisons at one level.
3. [Informational] openframe-data-mongo-sync/src/main/java/com/openframe/data/service/GcsPresignedUrlService.java:165 Nested method calls as arguments in the new GCS read/copy helpers
   PMD's NoMethodCallAsArgument fails the build on calls inside another call's argument list. The new storage helpers do this repeatedly, e.g. `storage.get(BlobId.of(bucketName, withPrefix(path)))` in readFile, fileExists and requireCopySource. Each inner call must be extracted to a named local first.
4. [Informational] openframe-data-mongo-sync/src/main/java/com/openframe/data/repository/ticket/CustomTicketAttachmentRepositoryImpl.java:52 findOrInsert returns null to signal "inserted" and the caller null-checks it
   `findOrInsert` returns null on the insert path (findAndModify with upsert and returnNew=false returns null when it created the document) and the caller distinguishes the two outcomes with `existing != null`. Returning null as a control signal is forbidden; the insert/existing distinction should be carried by a real value such as Optional or the InsertionResult itself.

Next: commit a suggestion, or hand a comment's prompt to your coding agent. React 👍 on a finding that helped and 👎 on one that is wrong: the reviewer learns from both.

Review again. New commits are not reviewed until you ask:

  • Review the new commits: only what was pushed since this review
  • Review the whole diff again: everything, including what was already reviewed

Or comment @flamingo-review (new commits) or @flamingo-review full (everything). Add the flamingo-review-always label to review every push.

Updated 2026-12-04 12:51 UTC · reviewed from Yevhenii Basarab's machine

@yevhenii-flamingo yevhenii-flamingo left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

A few follow-ups on attachments, compatibility and test coverage.

kirill-567
kirill-567 previously approved these changes Dec 4, 2026
@yevhenii-flamingo
yevhenii-flamingo force-pushed the feat/chat-attachments-audit branch from 334dbc4 to cd6c54c Compare December 4, 2026 20:55
@yevhenii-flamingo
yevhenii-flamingo marked this pull request as ready for review December 4, 2026 20:56
@flamingo

flamingo Bot commented Dec 4, 2026 •

Copy link
Copy Markdown
Contributor

🦩 flamingo Code Review / security

✅ No findings on the current head.

Advisory: findings do not block the merge.

Files Lines 🔴 Action required 🟠 Recommended 🔵 Informational
28 +1020 / -278 0 0 0
2 possible problems checked and ruled out
  • openframe-data-mongo-sync/src/main/java/com/openframe/data/repository/ticket/TicketAttachmentUpsertOperationsImpl.java:50 New attachment upsert takes the tenant key from the caller-supplied document instead of the pod tenant context, and suppresses TenantAwareMongoTemplate's injection: The whole file shows insertIfAbsentWithResult scopes every query by Fields.tenantId/Fields.ticketId taken from the TicketAttachment it is handed (lines 50-53), as the other write fragments in this data layer do; the finder itself states the caller that fills tenantId lives in an unindexed sibling PR, so no attacker-controlled value reaches this code in this repository. This is the explicitly…
  • openframe-data-mongo-sync/src/main/java/com/openframe/data/service/GcsPresignedUrlService.java:143 generatePreviewUrl forces inline disposition with an unvalidated, caller-supplied response-content-type: GcsPresignedUrlService.generateReadUrl (lines 147-158) signs the URL with the response-content-type/disposition its caller supplies; generatePreviewUrl is a library helper whose INLINE_DISPOSITION is its entire purpose, and the finder states it searched the checkout and found no production caller (only GcsPresignedUrlServiceReadTest), deferring the validation question to an unseen sibling pull…

Review again. New commits are not reviewed until you ask:

  • Security-check the new commits: only what was pushed since this security review
  • Security-check the whole diff again: everything, including what was already checked

Or comment @flamingo-review security (new commits) or @flamingo-review security full (everything). Add the flamingo-security-review-always label to security-review every push.

Updated 2026-12-04 21:36 UTC · reviewed from Yevhenii Basarab's machine

@yevhenii-flamingo
yevhenii-flamingo added this pull request to the merge queue Dec 4, 2026
Merged via the queue into main with commit d1dc1a1 Dec 4, 2026
19 checks passed
@yevhenii-flamingo
yevhenii-flamingo deleted the feat/chat-attachments-audit branch December 4, 2026 21:56
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.

2 participants