Don't show collections that can't be update by user

This commit is contained in:
Saumya Pandey committed 2021-08-27 01:42:30 +05:30
1 parent ac64725964
commit 8efd31f1d2
3 files changed
+35 -7

No files matched your search

+1 -1
View File
@@ -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;
}
@@ -33,7 +33,7 @@ const PublishDialog = ({ dialog, document, onSave }: Props) => {
const { t } = useTranslation();
const [searchTerm, setSearchTerm] = React.useState();
const [selectedPath, setSelectedPath] = React.useState<?DocumentPath>();
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;
+17 -3
View File
@@ -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<?DocumentPath>();
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;