Confirmation modal when overriding assets with already existing name
This fixes #3159 and replaces #3165. The #3165 PR had two issues, this PR fixes both:
- It was missing the file names transformation to check for file names collision, thus missing some collisions.
- It was just showing a modal with an error and cancelling the upload, so it didn't allow a user who would want to override the files to do so.
The added snippet compares the names of the assets to upload with the names of the already existing assets in the current folder. If there is a conflict a confirmation modal asks for confirmation to override the existing assets having the same name.
Note:
- The assets names comparison only takes into account assets from the current folder, because
this.assetsis queried by thelistAssetQuerywith thefolderId: this.currentFolderIdfilter. - If the user cancel the upload none of the assets are uploaded, not even the one with no name conflict.
This PR need the following translation to be added (currently in server/locales/en.yml):
editor:
assets.overrideAssets: 'Override Assets'
assets.overrideAssetsConfirm: 'Conflicting file names, are you sure you want to override '
assets.overrideAssetsWarn: 'This action cannot be undone!'
assets.actions.override: 'Override'
:warning: This is kind of a quick fix, especially the check for asset names collision. The line sanitize(f.filename.toLowerCase().replace(/[\s,;]+/g, '_'))) was directly copied from the upload route in server/controllers/upload.js (see source). I think the right way to implement this would be to implement a collision AssetQuery in server/graph/resolvers/asset.js, that could also be used by the renameAsset query in server/graph/resolvers/asset.js.
Demo:
