fix: Only display collections for move/publish with permission
This commit is contained in:
@@ -20,7 +20,7 @@ type Props = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
function DocumentMove({ document }: Props) {
|
function DocumentMove({ document }: Props) {
|
||||||
const { dialogs } = useStores();
|
const { dialogs, policies } = useStores();
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
const collectionTrees = useCollectionTrees();
|
const collectionTrees = useCollectionTrees();
|
||||||
const [selectedPath, selectPath] = React.useState<NavigationNode | null>(
|
const [selectedPath, selectPath] = React.useState<NavigationNode | null>(
|
||||||
@@ -29,9 +29,16 @@ function DocumentMove({ document }: Props) {
|
|||||||
|
|
||||||
const items = React.useMemo(() => {
|
const items = React.useMemo(() => {
|
||||||
// Filter out the document itself and its existing parent doc, if any.
|
// Filter out the document itself and its existing parent doc, if any.
|
||||||
const nodes = flatten(collectionTrees.map(flattenTree)).filter(
|
const nodes = flatten(collectionTrees.map(flattenTree))
|
||||||
(node) => node.id !== document.id && node.id !== document.parentDocumentId
|
.filter(
|
||||||
);
|
(node) =>
|
||||||
|
node.id !== document.id && node.id !== document.parentDocumentId
|
||||||
|
)
|
||||||
|
.filter((node) =>
|
||||||
|
node.collectionId
|
||||||
|
? policies.get(node.collectionId)?.abilities.createDocument
|
||||||
|
: true
|
||||||
|
);
|
||||||
|
|
||||||
// If the document we're moving is a template, only show collections as
|
// If the document we're moving is a template, only show collections as
|
||||||
// move targets.
|
// move targets.
|
||||||
@@ -42,6 +49,7 @@ function DocumentMove({ document }: Props) {
|
|||||||
}
|
}
|
||||||
return nodes;
|
return nodes;
|
||||||
}, [
|
}, [
|
||||||
|
policies,
|
||||||
collectionTrees,
|
collectionTrees,
|
||||||
document.id,
|
document.id,
|
||||||
document.parentDocumentId,
|
document.parentDocumentId,
|
||||||
|
|||||||
@@ -21,15 +21,20 @@ type Props = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
function DocumentPublish({ document }: Props) {
|
function DocumentPublish({ document }: Props) {
|
||||||
const { dialogs } = useStores();
|
const { dialogs, policies } = useStores();
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
const collectionTrees = useCollectionTrees();
|
const collectionTrees = useCollectionTrees();
|
||||||
const [selectedPath, selectPath] = React.useState<NavigationNode | null>(
|
const [selectedPath, selectPath] = React.useState<NavigationNode | null>(
|
||||||
null
|
null
|
||||||
);
|
);
|
||||||
const publishOptions = React.useMemo(
|
const publishOptions = React.useMemo(
|
||||||
() => flatten(collectionTrees.map(flattenTree)),
|
() =>
|
||||||
[collectionTrees]
|
flatten(collectionTrees.map(flattenTree)).filter((node) =>
|
||||||
|
node.collectionId
|
||||||
|
? policies.get(node.collectionId)?.abilities.createDocument
|
||||||
|
: true
|
||||||
|
),
|
||||||
|
[policies, collectionTrees]
|
||||||
);
|
);
|
||||||
|
|
||||||
const publish = async () => {
|
const publish = async () => {
|
||||||
|
|||||||
Reference in New Issue
Block a user