-
Notifications
You must be signed in to change notification settings - Fork 596
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(page-builder-flp): do not show editor-related actions for viewers (…
…#3825) Co-authored-by: Pavel Denisjuk <pavel@webiny.com>
- Loading branch information
Showing
43 changed files
with
767 additions
and
264 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
38 changes: 38 additions & 0 deletions
38
packages/api-page-builder-aco/src/page/graphql/createPbPageWbyAcoLocationGqlField.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,38 @@ | ||
import { PbAcoContext } from "~/types"; | ||
import { Page } from "@webiny/api-page-builder/types"; | ||
import { GraphQLSchemaPlugin } from "@webiny/handler-graphql"; | ||
|
||
export const createPbPageWbyAcoLocationGqlField = (context: PbAcoContext) => { | ||
context.plugins.register( | ||
new GraphQLSchemaPlugin<PbAcoContext>({ | ||
typeDefs: /* GraphQL */ ` | ||
type WbyPbAcoLocation { | ||
folderId: String | ||
} | ||
extend type PbPage { | ||
wbyAco_location: WbyPbAcoLocation | ||
} | ||
`, | ||
resolvers: { | ||
PbPage: { | ||
wbyAco_location: async (page: Page, args, context: PbAcoContext) => { | ||
const pageSearchRecord = await context.pageBuilderAco.app.search.get( | ||
page.pid | ||
); | ||
|
||
if (pageSearchRecord && pageSearchRecord.location.folderId !== "root") { | ||
return { | ||
folderId: pageSearchRecord.location.folderId | ||
}; | ||
} | ||
|
||
return { | ||
folderId: null | ||
}; | ||
} | ||
} | ||
} | ||
}) | ||
); | ||
}; |
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 |
---|---|---|
|
@@ -98,6 +98,9 @@ describe("page custom field", () => { | |
}, | ||
{ | ||
name: "customViews" | ||
}, | ||
{ | ||
name: "wbyAco_location" | ||
} | ||
] | ||
}); | ||
|
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
2 changes: 1 addition & 1 deletion
2
packages/app-page-builder/src/admin/components/BulkActions/ActionMove.tsx
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
29 changes: 29 additions & 0 deletions
29
packages/app-page-builder/src/admin/components/BulkActions/SecureActionDelete.tsx
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,29 @@ | ||
import React, { useMemo } from "react"; | ||
import { useFolders } from "@webiny/app-aco"; | ||
import { observer } from "mobx-react-lite"; | ||
import { PageListConfig } from "~/admin/config/pages"; | ||
import { usePagesPermissions } from "~/hooks/permissions"; | ||
import { ActionDelete as ActionDeleteBase } from "~/admin/components/BulkActions"; | ||
|
||
export const SecureActionDelete = observer(() => { | ||
const { canDelete } = usePagesPermissions(); | ||
const { folderLevelPermissions: flp } = useFolders(); | ||
|
||
const { useWorker } = PageListConfig.Browser.BulkAction; | ||
const worker = useWorker(); | ||
|
||
const canDeleteAll = useMemo(() => { | ||
return worker.items.every(item => { | ||
return ( | ||
canDelete(item.data.createdBy.id) && flp.canManageContent(item.location?.folderId) | ||
); | ||
}); | ||
}, [worker.items]); | ||
|
||
if (!canDeleteAll) { | ||
console.log("You don't have permissions to delete pages."); | ||
return null; | ||
} | ||
|
||
return <ActionDeleteBase />; | ||
}); |
23 changes: 23 additions & 0 deletions
23
packages/app-page-builder/src/admin/components/BulkActions/SecureActionMove.tsx
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,23 @@ | ||
import React, { useMemo } from "react"; | ||
import { useFolders } from "@webiny/app-aco"; | ||
import { observer } from "mobx-react-lite"; | ||
import { PageListConfig } from "~/admin/config/pages"; | ||
import { ActionMove as ActionMoveBase } from "~/admin/components/BulkActions"; | ||
|
||
export const SecureActionMove = observer(() => { | ||
const { useWorker } = PageListConfig.Browser.BulkAction; | ||
const worker = useWorker(); | ||
const { folderLevelPermissions: flp } = useFolders(); | ||
|
||
const canMoveAll = useMemo(() => { | ||
return worker.items.every(item => { | ||
return flp.canManageContent(item.location?.folderId); | ||
}); | ||
}, [worker.items]); | ||
|
||
if (!canMoveAll) { | ||
return null; | ||
} | ||
|
||
return <ActionMoveBase />; | ||
}); |
28 changes: 28 additions & 0 deletions
28
packages/app-page-builder/src/admin/components/BulkActions/SecureActionPublish.tsx
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,28 @@ | ||
import React, { useMemo } from "react"; | ||
import { useFolders } from "@webiny/app-aco"; | ||
import { observer } from "mobx-react-lite"; | ||
import { PageListConfig } from "~/admin/config/pages"; | ||
import { usePagesPermissions } from "~/hooks/permissions"; | ||
import { ActionPublish as ActionPublishBase } from "~/admin/components/BulkActions"; | ||
|
||
export const SecureActionPublish = observer(() => { | ||
const { canPublish } = usePagesPermissions(); | ||
|
||
const { folderLevelPermissions: flp } = useFolders(); | ||
|
||
const { useWorker } = PageListConfig.Browser.BulkAction; | ||
const worker = useWorker(); | ||
|
||
const canPublishAll = useMemo(() => { | ||
return worker.items.every(item => { | ||
return canPublish() && flp.canManageContent(item.location?.folderId); | ||
}); | ||
}, [worker.items]); | ||
|
||
if (!canPublishAll) { | ||
console.log("You don't have permissions to publish pages."); | ||
return null; | ||
} | ||
|
||
return <ActionPublishBase />; | ||
}); |
28 changes: 28 additions & 0 deletions
28
packages/app-page-builder/src/admin/components/BulkActions/SecureActionUnpublish.tsx
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,28 @@ | ||
import React, { useMemo } from "react"; | ||
import { observer } from "mobx-react-lite"; | ||
import { useFolders } from "@webiny/app-aco"; | ||
import { PageListConfig } from "~/admin/config/pages"; | ||
import { usePagesPermissions } from "~/hooks/permissions"; | ||
import { ActionUnpublish as ActionUnpublishBase } from "~/admin/components/BulkActions"; | ||
|
||
export const SecureActionUnpublish = observer(() => { | ||
const { canUnpublish } = usePagesPermissions(); | ||
const { folderLevelPermissions: flp } = useFolders(); | ||
|
||
const { useWorker } = PageListConfig.Browser.BulkAction; | ||
|
||
const worker = useWorker(); | ||
|
||
const canUnpublishAll = useMemo(() => { | ||
return worker.items.every(item => { | ||
return canUnpublish() && flp.canManageContent(item.location?.folderId); | ||
}); | ||
}, [worker.items]); | ||
|
||
if (!canUnpublishAll) { | ||
console.log("You don't have permissions to unpublish pages."); | ||
return null; | ||
} | ||
|
||
return <ActionUnpublishBase />; | ||
}); |
4 changes: 4 additions & 0 deletions
4
packages/app-page-builder/src/admin/components/BulkActions/index.tsx
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 |
---|---|---|
@@ -1,6 +1,10 @@ | ||
export { ActionDelete } from "./ActionDelete"; | ||
export { SecureActionDelete } from "./SecureActionDelete"; | ||
export { ActionExport } from "./ActionExport"; | ||
export { ActionMove } from "./ActionMove"; | ||
export { SecureActionMove } from "./SecureActionMove"; | ||
export { ActionPublish } from "./ActionPublish"; | ||
export { SecureActionPublish } from "./SecureActionPublish"; | ||
export { ActionUnpublish } from "./ActionUnpublish"; | ||
export { SecureActionUnpublish } from "./SecureActionUnpublish"; | ||
export * from "./BulkActions"; |
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
Oops, something went wrong.