-
Notifications
You must be signed in to change notification settings - Fork 618
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: use
location
field name when FLP-filtering ACO search records (#…
- Loading branch information
Showing
11 changed files
with
142 additions
and
112 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { CmsModel } from "@webiny/api-headless-cms/types"; | ||
import { isPageModel } from "./isPageModel"; | ||
|
||
export const createFolderType = (model: CmsModel): "FmFile" | "PbPage" | `cms:${string}` => { | ||
if (model.modelId === "fmFile") { | ||
return "FmFile"; | ||
} else if (isPageModel(model)) { | ||
return "PbPage"; | ||
} | ||
return `cms:${model.modelId}`; | ||
}; |
43 changes: 43 additions & 0 deletions
43
packages/api-aco/src/utils/decorators/filterEntriesByFolderFactory.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import { AcoContext } from "~/types"; | ||
import { CmsEntry, CmsModel } from "@webiny/api-headless-cms/types"; | ||
import { NotFoundError } from "@webiny/handler-graphql"; | ||
import { FolderLevelPermissions } from "~/utils/FolderLevelPermissions"; | ||
import { ROOT_FOLDER } from "./constants"; | ||
|
||
type Context = Pick<AcoContext, "aco" | "cms">; | ||
|
||
import { createFolderType } from "./createFolderType"; | ||
|
||
export const filterEntriesByFolderFactory = ( | ||
context: Context, | ||
permissions: FolderLevelPermissions | ||
) => { | ||
return async (model: CmsModel, entries: CmsEntry[]) => { | ||
const [folders] = await context.aco.folder.listAll({ | ||
where: { | ||
type: createFolderType(model) | ||
} | ||
}); | ||
|
||
const results = await Promise.all( | ||
entries.map(async entry => { | ||
const folderId = entry.location?.folderId; | ||
if (!folderId || folderId === ROOT_FOLDER) { | ||
return entry; | ||
} | ||
|
||
const folder = folders.find(folder => folder.id === folderId); | ||
if (!folder) { | ||
throw new NotFoundError(`Folder "${folderId}" not found.`); | ||
} | ||
const result = await permissions.canAccessFolderContent({ | ||
folder, | ||
rwd: "r" | ||
}); | ||
return result ? entry : null; | ||
}) | ||
); | ||
|
||
return results.filter((entry): entry is CmsEntry => !!entry); | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { CmsModel } from "@webiny/api-headless-cms/types"; | ||
|
||
/** | ||
* Keep this until we figure out how to fetch the folders. | ||
*/ | ||
export const isPageModel = (model: CmsModel): boolean => { | ||
if (model.modelId === "pbPage") { | ||
return true; | ||
} else if (model.modelId === "acoSearchRecord-pbpage") { | ||
return true; | ||
} | ||
return false; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters