mirror of
https://github.com/strapi/strapi.git
synced 2026-01-08 13:17:47 +00:00
Merge pull request #16760 from strapi/fix/some-folders-cant-be-moved-inside-others
This commit is contained in:
commit
4e17f00e35
8
packages/core/upload/server/controllers/utils/folders.js
Normal file
8
packages/core/upload/server/controllers/utils/folders.js
Normal file
@ -0,0 +1,8 @@
|
||||
'use strict';
|
||||
|
||||
const isFolderOrChild = (folderOrChild, folder) =>
|
||||
folderOrChild.path === folder.path || folderOrChild.path.startsWith(`${folder.path}/`);
|
||||
|
||||
module.exports = {
|
||||
isFolderOrChild,
|
||||
};
|
||||
@ -4,6 +4,7 @@ const { intersection, map, isEmpty } = require('lodash/fp');
|
||||
const { yup, validateYupSchema } = require('@strapi/utils');
|
||||
const { FOLDER_MODEL_UID } = require('../../../constants');
|
||||
const { folderExists } = require('./utils');
|
||||
const { isFolderOrChild } = require('../../utils/folders');
|
||||
|
||||
const validateDeleteManyFoldersFilesSchema = yup
|
||||
.object()
|
||||
@ -75,7 +76,7 @@ const validateMoveFoldersNotInsideThemselvesSchema = yup
|
||||
});
|
||||
|
||||
const unmovableFoldersNames = folders
|
||||
.filter((folder) => destinationFolder.path.startsWith(folder.path))
|
||||
.filter((folder) => isFolderOrChild(destinationFolder, folder))
|
||||
.map((f) => f.name);
|
||||
if (unmovableFoldersNames.length > 0) {
|
||||
return this.createError({
|
||||
|
||||
@ -5,6 +5,7 @@ const { yup, validateYupSchema } = require('@strapi/utils');
|
||||
const { getService } = require('../../../utils');
|
||||
const { FOLDER_MODEL_UID } = require('../../../constants');
|
||||
const { folderExists } = require('./utils');
|
||||
const { isFolderOrChild } = require('../../utils/folders');
|
||||
|
||||
const NO_SLASH_REGEX = /^[^/]+$/;
|
||||
const NO_SPACES_AROUND = /^(?! ).+(?<! )$/;
|
||||
@ -78,7 +79,7 @@ const validateUpdateFolderSchema = (id) =>
|
||||
|
||||
if (!destinationFolder || !currentFolder) return true;
|
||||
|
||||
return !destinationFolder.path.startsWith(currentFolder.path);
|
||||
return !isFolderOrChild(destinationFolder, currentFolder);
|
||||
}
|
||||
),
|
||||
})
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user