Skip to content

Commit

Permalink
DAM: Fix the duplicate name check when updating a file (v5) (#2065)
Browse files Browse the repository at this point in the history
Backport of #2049
  • Loading branch information
thomasdax98 authored May 15, 2024
1 parent e8fa938 commit 91b7343
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
14 changes: 14 additions & 0 deletions .changeset/khaki-beans-clean.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
---
"@comet/cms-api": patch
"@comet/cms-admin": patch
---

DAM: Fix the duplicate name check when updating a file

Previously, there were two bugs:

1. In the `EditFile` form, the `folderId` wasn't passed to the mutation
2. In `FilesService#updateByEntity`, the duplicate check was always done against the root folder if no `folderId` was passed

This caused an error when saving a file in any folder if there was another file with the same name in the root folder.
And it was theoretically possible to create two files with the same name in one folder (though this was still prevented by admin-side validation).
3 changes: 2 additions & 1 deletion packages/admin/cms-admin/src/dam/FileForm/EditFile.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -157,11 +157,12 @@ const EditFileInner = ({ file, id }: EditFileInnerProps) => {
cropArea,
},
license: values.license?.type === "NO_LICENSE" ? null : { ...values.license, type: values.license?.type },
folderId: file.folder?.id ?? null,
},
},
});
},
[id, updateDamFile],
[file.folder?.id, id, updateDamFile],
);

const initialBlockListWidth = 100 / 3;
Expand Down
3 changes: 2 additions & 1 deletion packages/api/cms-api/src/dam/files/files.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,8 @@ export class FilesService {
return this.updateByEntity(file, data);
}

async updateByEntity(entity: FileInterface, { folderId, image, ...input }: UpdateFileInput): Promise<FileInterface> {
async updateByEntity(entity: FileInterface, { image, ...input }: UpdateFileInput): Promise<FileInterface> {
const folderId = input.folderId !== undefined ? input.folderId : entity.folder?.id;
const folder = folderId ? await this.foldersService.findOneById(folderId) : null;

if (entity.image && image?.cropArea) {
Expand Down

0 comments on commit 91b7343

Please sign in to comment.