mirror of
https://github.com/strapi/strapi.git
synced 2025-11-01 18:33:55 +00:00
chore: create util to check if folder is the same as another one or a child one
This commit is contained in:
parent
a7b8ad0fd5
commit
087ff3765b
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,11 +76,7 @@ const validateMoveFoldersNotInsideThemselvesSchema = yup
|
||||
});
|
||||
|
||||
const unmovableFoldersNames = folders
|
||||
.filter(
|
||||
(folder) =>
|
||||
destinationFolder.path === folder.path ||
|
||||
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,11 +79,7 @@ const validateUpdateFolderSchema = (id) =>
|
||||
|
||||
if (!destinationFolder || !currentFolder) return true;
|
||||
|
||||
const isUnMovable =
|
||||
destinationFolder.path === currentFolder.path ||
|
||||
destinationFolder.path.startsWith(`${currentFolder.path}/`);
|
||||
|
||||
return !isUnMovable;
|
||||
return !isFolderOrChild(destinationFolder, currentFolder);
|
||||
}
|
||||
),
|
||||
})
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user