-
Notifications
You must be signed in to change notification settings - Fork 583
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(api-aco): flp entry decorator (#3664)
- Loading branch information
1 parent
bad0068
commit 607b8af
Showing
7 changed files
with
194 additions
and
28 deletions.
There are no files selected for viewing
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 @@ | ||
export const ROOT_FOLDER = "root"; |
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,53 @@ | ||
import { CmsEntryListWhere } from "@webiny/api-headless-cms/types"; | ||
import { Folder } from "~/folder/folder.types"; | ||
import { ROOT_FOLDER } from "./constants"; | ||
|
||
interface Params { | ||
where: CmsEntryListWhere | undefined; | ||
folders: Folder[]; | ||
} | ||
|
||
/** | ||
* There are multiple cases that we need to handle: | ||
* * existing location with no AND conditional | ||
* * existing location with AND conditional | ||
* * no existing location with no AND conditional + with AND conditional | ||
*/ | ||
export const createWhere = (params: Params): CmsEntryListWhere | undefined => { | ||
const { where, folders } = params; | ||
if (!where) { | ||
return undefined; | ||
} | ||
const whereLocation = { | ||
wbyAco_location: { | ||
// At the moment, all users can access entries in the root folder. | ||
// Root folder level permissions cannot be set yet. | ||
folderId_in: [ROOT_FOLDER, ...folders.map(folder => folder.id)] | ||
} | ||
}; | ||
const whereAnd = where.AND; | ||
if (where.wbyAco_location && !whereAnd) { | ||
return { | ||
...where, | ||
AND: [ | ||
{ | ||
...whereLocation | ||
} | ||
] | ||
}; | ||
} else if (where.wbyAco_location && whereAnd) { | ||
return { | ||
...where, | ||
AND: [ | ||
{ | ||
...whereLocation | ||
}, | ||
...whereAnd | ||
] | ||
}; | ||
} | ||
return { | ||
...where, | ||
...whereLocation | ||
}; | ||
}; |
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