Skip to content
Snippets Groups Projects
Commit 563a5825 authored by Tom Robinson's avatar Tom Robinson
Browse files

Enforce collection permissions in drag and drop. Pending backend modifications...

Enforce collection permissions in drag and drop. Pending backend modifications to include can_write in various places
parent aefd3def
No related branches found
No related tags found
No related merge requests found
......@@ -212,13 +212,13 @@ class DefaultLanding extends React.Component {
<BrowserCrumbs
analyticsContext={ANALYTICS_CONTEXT}
crumbs={[
...ancestors.map(({ id, name }) => ({
...ancestors.map(ancestor => ({
title: (
<CollectionDropTarget collection={{ id }} margin={8}>
{name}
<CollectionDropTarget collection={ancestor} margin={8}>
{ancestor.name}
</CollectionDropTarget>
),
to: Urls.collection(id),
to: Urls.collection(ancestor.id),
})),
]}
/>
......@@ -261,7 +261,7 @@ class DefaultLanding extends React.Component {
className="relative"
key={index}
>
<ItemDragSource item={item}>
<ItemDragSource item={item} collection={collection}>
<PinnedItem
key={`${item.type}:${item.id}`}
index={index}
......@@ -349,6 +349,7 @@ class DefaultLanding extends React.Component {
<ItemDragSource
item={item}
selection={selection}
collection={collection}
>
<NormalItem
key={`${item.type}:${item.id}`}
......
......@@ -34,7 +34,10 @@ class CollectionList extends React.Component {
<GridItem w={w} key={collection.id}>
<CollectionDropTarget collection={collection}>
{({ highlighted, hovered }) => (
<ItemDragSource item={collection}>
<ItemDragSource
item={collection}
collection={currentCollection}
>
<CollectionItem
collection={collection}
highlighted={highlighted}
......
......@@ -11,6 +11,10 @@ const CollectionDropTarget = DropTarget(
},
canDrop(props, monitor) {
const { item } = monitor.getItem();
// can't drop if can't write the collection
if (props.collection.can_write === false) {
return false;
}
return item.model !== "collection" || item.id !== props.collection.id;
},
},
......
......@@ -9,6 +9,10 @@ import { dragTypeForItem } from ".";
props => dragTypeForItem(props.item),
{
canDrag(props, monitor) {
// can't drag if can't write the parent collection
if (props.collection && props.collection.can_write === false) {
return false;
}
// if items are selected only allow dragging selected items
if (
props.selection &&
......
......@@ -13,6 +13,8 @@ const PinDropTarget = DropTarget(
},
canDrop(props, monitor) {
const { item } = monitor.getItem();
// NOTE: not necessary to check collection permission here since we
// enforce it when beginning to drag and item within the same collection
return props.pinIndex != item.collection_position;
},
},
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment