18123: Disable delete group link if user lacks permission.
authorStephen Smith <stephen@curii.com>
Wed, 1 Dec 2021 00:20:27 +0000 (19:20 -0500)
committerStephen Smith <stephen@curii.com>
Wed, 1 Dec 2021 00:20:27 +0000 (19:20 -0500)
Arvados-DCO-1.1-Signed-off-by: Stephen Smith <stephen@curii.com>

src/views-components/data-explorer/renderers.tsx

index 398933925ca8708558a5b224529aa9c9f5692399..457de5043cc6e59f3333f2cda57d949caf091f5e 100644 (file)
@@ -403,13 +403,19 @@ export const ResourceLinkTailUuid = connect(
         return tailResource || { uuid: '' };
     })(renderUuid);
 
-const renderLinkDelete = (dispatch: Dispatch, item: LinkResource) => {
+const renderLinkDelete = (dispatch: Dispatch, item: LinkResource, canManage: boolean) => {
     if (item.uuid) {
-        return <Typography noWrap>
-            <IconButton data-cy="resource-delete-button" onClick={() => dispatch<any>(openRemoveGroupMemberDialog(item.uuid))}>
-                <RemoveIcon />
-            </IconButton>
-        </Typography>;
+        return canManage ?
+            <Typography noWrap>
+                <IconButton data-cy="resource-delete-button" onClick={() => dispatch<any>(openRemoveGroupMemberDialog(item.uuid))}>
+                    <RemoveIcon />
+                </IconButton>
+            </Typography> :
+            <Typography noWrap>
+                <IconButton disabled data-cy="resource-delete-button">
+                    <RemoveIcon />
+                </IconButton>
+            </Typography>;
     } else {
       return <Typography noWrap></Typography>;
     }
@@ -419,10 +425,11 @@ export const ResourceLinkDelete = connect(
     (state: RootState, props: { uuid: string }) => {
         const link = getResource<LinkResource>(props.uuid)(state.resources);
         return {
-            item: link || { uuid: '', kind: ResourceKind.NONE }
+            item: link || { uuid: '', kind: ResourceKind.NONE },
+            canManage: link && getResourceLinkCanManage(state, link),
         };
-    })((props: { item: LinkResource } & DispatchProp<any>) =>
-      renderLinkDelete(props.dispatch, props.item));
+    })((props: { item: LinkResource, canManage: boolean } & DispatchProp<any>) =>
+      renderLinkDelete(props.dispatch, props.item, props.canManage));
 
 export const ResourceLinkTailEmail = connect(
     (state: RootState, props: { uuid: string }) => {