Skip to content

feat: add native server-side copy() for attachment duplication#405

Merged
schiwekM merged 20 commits intocap-js:mainfrom
cschuerings:feat/native-copy
Mar 31, 2026
Merged

feat: add native server-side copy() for attachment duplication#405
schiwekM merged 20 commits intocap-js:mainfrom
cschuerings:feat/native-copy

Conversation

@cschuerings
Copy link
Copy Markdown
Contributor

Summary

  • Add copy() method to AttachmentsService for server-side attachment duplication across active and draft tables
  • Implement storage-level copy for AWS S3, Azure Blob Storage, and GCP
  • Include safeguards against entity injection, targetKeys override, and copying infected/failed attachments
  • Add demo copyIncident bound action in the incident test FE UI showing the parent-entity copy use case

Closes #279

Details

The new copy() API accepts source and target attachment entities with their keys:

const AttachmentsSrv = await cds.connect.to('attachments')
const newAtt = await AttachmentsSrv.copy(
  sourceAttachments, { ID: sourceId },
  targetAttachments, { up__ID: targetParentId }
)

Supports active-to-active, active-to-draft, and draft-to-draft copies. When targeting a draft table, DraftAdministrativeData_DraftUUID must be provided in targetKeys.

As noted in #279, the primary use case is duplicating attachments when copying a parent entity. The test app demonstrates this with a copyIncident action that creates a new draft incident and clones all its attachments in one operation.

Note on multi-level associations: The copy() API operates on a single attachment composition at a time. For scenarios with nested associations (e.g. Catalog → Books → Attachments, as described in #279), consumers need to iterate over the child entities and call copy() for each.

Introduce a copy() method on AttachmentsService that duplicates an
attachment record and its binary content across active and draft tables.
Includes storage-level implementations for AWS S3, Azure Blob Storage,
and GCP, with safeguards against targetKeys override, entity injection,
and infected/failed source attachments.
Add a bound copyIncident action on ProcessorService.Incidents that
creates a new draft with all attachments cloned via AttachmentsSrv.copy().
The button is shown only in display mode on the Object Page header.
@cschuerings cschuerings requested a review from a team as a code owner March 16, 2026 15:04
@schiwekM
Copy link
Copy Markdown
Contributor

Hi @cschuerings,
thanks for the contribution - will review till end of week. Maybe we can automatically add the action the the Attachments aspect so the attachments table automatically has the Copy button.

BR,
Marten

Copy link
Copy Markdown
Member

@KoblerS KoblerS left a comment

Choose a reason for hiding this comment

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

thanks for your contribution I have added some comments! :)

@schiwekM schiwekM requested a review from KoblerS March 30, 2026 12:55
@schiwekM schiwekM deployed to pr-approval March 30, 2026 14:16 — with GitHub Actions Active
@schiwekM schiwekM enabled auto-merge (squash) March 30, 2026 14:49
@schiwekM schiwekM merged commit 9cef568 into cap-js:main Mar 31, 2026
64 of 72 checks passed
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.

Enable OData Action for Attachment Duplication

3 participants