diff --git a/app/menus/CollectionMenu.js b/app/menus/CollectionMenu.js index d63247c377..3f56cd45e7 100644 --- a/app/menus/CollectionMenu.js +++ b/app/menus/CollectionMenu.js @@ -168,7 +168,7 @@ function CollectionMenu({ [can, collection, handleNewDocument, handleImportDocument, t] ); - if (items.indexOf((item) => item.visible) === -1) { + if (!items.some((item) => item.visible)) { return null; } diff --git a/app/scenes/Document/components/PublishDialog.js b/app/scenes/Document/components/PublishDialog.js index 49eee67894..573dd929e8 100644 --- a/app/scenes/Document/components/PublishDialog.js +++ b/app/scenes/Document/components/PublishDialog.js @@ -33,7 +33,7 @@ const PublishDialog = ({ dialog, document, onSave }: Props) => { const { t } = useTranslation(); const [searchTerm, setSearchTerm] = React.useState(); const [selectedPath, setSelectedPath] = React.useState(); - const { collections, documents } = useStores(); + const { collections, documents, policies } = useStores(); const { showToast } = useToasts(); React.useEffect(() => { @@ -90,7 +90,21 @@ const PublishDialog = ({ dialog, document, onSave }: Props) => { ); const searchIndex = React.useMemo(() => { - const paths = collections.pathsToDocuments; + let paths = collections.pathsToDocuments; + + paths = paths.filter((path) => { + if (path.type === "collection" && policies.abilities(path.id).update) + return true; + + if ( + path.type === "document" && + policies.abilities(path.collectionId).update + ) + return true; + + return false; + }); + const index = new Search("id"); index.addIndex("title"); @@ -105,7 +119,7 @@ const PublishDialog = ({ dialog, document, onSave }: Props) => { index.addDocuments(indexeableDocuments); return index; - }, [documents, collections.pathsToDocuments]); + }, [collections.pathsToDocuments, policies, documents]); const results: DocumentPath[] = React.useMemo(() => { const onlyShowCollections = document.isTemplate; diff --git a/app/scenes/DocumentMove.js b/app/scenes/DocumentMove.js index c27f508d62..4f2c71a658 100644 --- a/app/scenes/DocumentMove.js +++ b/app/scenes/DocumentMove.js @@ -25,7 +25,7 @@ type Props = {| function DocumentMove({ document, onRequestClose }: Props) { const [searchTerm, setSearchTerm] = useState(); - const { collections, documents } = useStores(); + const { collections, documents, policies } = useStores(); const [selectedPath, setSelectedPath] = useState(); const { showToast } = useToasts(); const { t } = useTranslation(); @@ -50,7 +50,21 @@ function DocumentMove({ document, onRequestClose }: Props) { ); const searchIndex = useMemo(() => { - const paths = collections.pathsToDocuments; + let paths = collections.pathsToDocuments; + + paths = paths.filter((path) => { + if (path.type === "collection" && policies.abilities(path.id).update) + return true; + + if ( + path.type === "document" && + policies.abilities(path.collectionId).update + ) + return true; + + return false; + }); + const index = new Search("id"); index.addIndex("title"); @@ -65,7 +79,7 @@ function DocumentMove({ document, onRequestClose }: Props) { index.addDocuments(indexeableDocuments); return index; - }, [documents, collections.pathsToDocuments]); + }, [collections.pathsToDocuments, policies, documents]); const results: DocumentPath[] = useMemo(() => { const onlyShowCollections = document.isTemplate;