X-Git-Url: https://git.arvados.org/arvados-workbench2.git/blobdiff_plain/416d4f0f57336b2225bcc82b0f4db8873adf8cd2..7e1669d2263cdf8e9066057fd126007b755ba7f5:/src/views-components/data-explorer/renderers.tsx

diff --git a/src/views-components/data-explorer/renderers.tsx b/src/views-components/data-explorer/renderers.tsx
index 39893392..2ec4bf51 100644
--- a/src/views-components/data-explorer/renderers.tsx
+++ b/src/views-components/data-explorer/renderers.tsx
@@ -28,7 +28,7 @@ import { withResourceData } from 'views-components/data-explorer/with-resources'
 import { CollectionResource } from 'models/collection';
 import { IllegalNamingWarning } from 'components/warning/warning';
 import { loadResource } from 'store/resources/resources-actions';
-import { GroupClass, GroupResource } from 'models/group';
+import { GroupClass, GroupResource, isBuiltinGroup } from 'models/group';
 import { openRemoveGroupMemberDialog } from 'store/group-details-panel/group-details-panel-actions';
 import { setMemberIsHidden } from 'store/group-details-panel/group-details-panel-actions';
 import { formatPermissionLevel } from 'views-components/sharing-dialog/permission-select';
@@ -171,7 +171,7 @@ export const ResourceFullName = connect(
 
 
 const renderUuid = (item: { uuid: string }) =>
-    <Typography noWrap>{item.uuid}</Typography>;
+    <Typography data-cy="uuid" noWrap>{item.uuid}</Typography>;
 
 export const ResourceUuid = connect(
     (state: RootState, props: { uuid: string }) => {
@@ -215,18 +215,26 @@ export const ResourceLinkTailIsActive = connect(
     }, { toggleIsActive }
 )(renderIsActive);
 
-const renderIsHidden = (props: { memberLinkUuid: string, permissionLinkUuid: string, hidden: boolean, setMemberIsHidden: (memberLinkUuid: string, permissionLinkUuid: string, hide: boolean) => void }) => {
+const renderIsHidden = (props: {
+                            memberLinkUuid: string,
+                            permissionLinkUuid: string,
+                            visible: boolean,
+                            canManage: boolean,
+                            setMemberIsHidden: (memberLinkUuid: string, permissionLinkUuid: string, hide: boolean) => void 
+                        }) => {
     if (props.memberLinkUuid) {
         return <Checkbox
+                data-cy="user-visible-checkbox"
                 color="primary"
-                checked={props.hidden}
-                onClick={() => props.setMemberIsHidden(props.memberLinkUuid, props.permissionLinkUuid, !props.hidden)} />;
+                checked={props.visible}
+                disabled={!props.canManage}
+                onClick={() => props.setMemberIsHidden(props.memberLinkUuid, props.permissionLinkUuid, !props.visible)} />;
     } else {
         return <Typography />;
     }
 }
 
-export const ResourceLinkTailIsHidden = connect(
+export const ResourceLinkTailIsVisible = connect(
     (state: RootState, props: { uuid: string }) => {
         const link = getResource<LinkResource>(props.uuid)(state.resources);
         const member = getResource<Resource>(link?.tailUuid || '')(state.resources);
@@ -240,10 +248,12 @@ export const ResourceLinkTailIsHidden = connect(
 
         const permissionLinkUuid = permissions.length > 0 ? permissions[0].uuid : '';
         const isVisible = link && group && permissions.length > 0;
+        // Consider whether the current user canManage this resurce in addition when it's possible
+        const isBuiltin = isBuiltinGroup(link?.headUuid || '');
 
         return member?.kind === ResourceKind.USER
-            ? { memberLinkUuid: link?.uuid, permissionLinkUuid, hidden: !isVisible }
-            : { memberLinkUuid: '', permissionLinkUuid: '', hidden: false};
+            ? { memberLinkUuid: link?.uuid, permissionLinkUuid, visible: isVisible, canManage: !isBuiltin }
+            : { memberLinkUuid: '', permissionLinkUuid: '', visible: false, canManage: false };
     }, { setMemberIsHidden }
 )(renderIsHidden);
 
@@ -403,13 +413,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>;
     }
@@ -418,11 +434,14 @@ const renderLinkDelete = (dispatch: Dispatch, item: LinkResource) => {
 export const ResourceLinkDelete = connect(
     (state: RootState, props: { uuid: string }) => {
         const link = getResource<LinkResource>(props.uuid)(state.resources);
+        const isBuiltin = isBuiltinGroup(link?.headUuid || '') || isBuiltinGroup(link?.tailUuid || '');
+
         return {
-            item: link || { uuid: '', kind: ResourceKind.NONE }
+            item: link || { uuid: '', kind: ResourceKind.NONE },
+            canManage: link && getResourceLinkCanManage(state, link) && !isBuiltin,
         };
-    })((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 }) => {
@@ -444,7 +463,7 @@ const renderPermissionLevel = (dispatch: Dispatch, link: LinkResource, canManage
     return <Typography noWrap>
         {formatPermissionLevel(link.name as PermissionLevel)}
         {canManage ?
-            <IconButton onClick={(event) => dispatch<any>(openPermissionEditContextMenu(event, link))}>
+            <IconButton data-cy="edit-permission-button" onClick={(event) => dispatch<any>(openPermissionEditContextMenu(event, link))}>
                 <RenameIcon />
             </IconButton> :
             ''
@@ -455,10 +474,11 @@ const renderPermissionLevel = (dispatch: Dispatch, link: LinkResource, canManage
 export const ResourceLinkHeadPermissionLevel = connect(
     (state: RootState, props: { uuid: string }) => {
         const link = getResource<LinkResource>(props.uuid)(state.resources);
+        const isBuiltin = isBuiltinGroup(link?.headUuid || '') || isBuiltinGroup(link?.tailUuid || '');
 
         return {
             link: link || { uuid: '', name: '', kind: ResourceKind.NONE },
-            canManage: link && getResourceLinkCanManage(state, link),
+            canManage: link && getResourceLinkCanManage(state, link) && !isBuiltin,
         };
     })((props: { link: LinkResource, canManage: boolean } & DispatchProp<any>) =>
         renderPermissionLevel(props.dispatch, props.link, props.canManage));
@@ -466,10 +486,11 @@ export const ResourceLinkHeadPermissionLevel = connect(
 export const ResourceLinkTailPermissionLevel = connect(
     (state: RootState, props: { uuid: string }) => {
         const link = getResource<LinkResource>(props.uuid)(state.resources);
+        const isBuiltin = isBuiltinGroup(link?.headUuid || '') || isBuiltinGroup(link?.tailUuid || '');
 
         return {
             link: link || { uuid: '', name: '', kind: ResourceKind.NONE },
-            canManage: link && getResourceLinkCanManage(state, link),
+            canManage: link && getResourceLinkCanManage(state, link) && !isBuiltin,
         };
     })((props: { link: LinkResource, canManage: boolean } & DispatchProp<any>) =>
         renderPermissionLevel(props.dispatch, props.link, props.canManage));
