* Shows a lock icon indicating the read-only access.
* The three-dotted 'More options' menu only shows appropriate actions.
* The properties panel only shows properties without the 'delete tag' button.
* The files panel general 'More options' menu shows appropriate actions.
* The files panel individual context menu also filters editing action when
read-only.
* The files panel's upload button isn't rendered on read-only collections.
Arvados-DCO-1.1-Signed-off-by: Lucas Di Pentima <lucas@di-pentima.com.ar>
export interface CollectionPanelFilesProps {
items: Array<TreeItem<FileTreeData>>;
+ isWritable: boolean;
onUploadDataClick: () => void;
- onItemMenuOpen: (event: React.MouseEvent<HTMLElement>, item: TreeItem<FileTreeData>) => void;
- onOptionsMenuOpen: (event: React.MouseEvent<HTMLElement>) => void;
+ onItemMenuOpen: (event: React.MouseEvent<HTMLElement>, item: TreeItem<FileTreeData>, isWritable: boolean) => void;
+ onOptionsMenuOpen: (event: React.MouseEvent<HTMLElement>, isWritable: boolean) => void;
onSelectionToggle: (event: React.MouseEvent<HTMLElement>, item: TreeItem<FileTreeData>) => void;
onCollapseToggle: (id: string, status: TreeItemStatus) => void;
onFileClick: (id: string) => void;
export const CollectionPanelFiles =
withStyles(styles)(
- ({ onItemMenuOpen, onOptionsMenuOpen, onUploadDataClick, classes, ...treeProps }: CollectionPanelFilesProps & WithStyles<CssRules>) =>
+ ({ onItemMenuOpen, onOptionsMenuOpen, onUploadDataClick, classes, isWritable, ...treeProps }: CollectionPanelFilesProps & WithStyles<CssRules>) =>
<Card className={classes.root}>
<CardHeader
title="Files"
classes={{ action: classes.button }}
action={
- <Button onClick={onUploadDataClick}
+ isWritable && <Button onClick={onUploadDataClick}
variant='contained'
color='primary'
size='small'>
<DownloadIcon className={classes.uploadIcon} />
Upload data
- </Button>
+ </Button>
} />
<CardHeader
className={classes.cardSubheader}
action={
<Tooltip title="More options" disableFocusListener>
- <IconButton onClick={onOptionsMenuOpen}>
+ <IconButton onClick={(ev) => onOptionsMenuOpen(ev, isWritable)}>
<CustomizeTableIcon />
</IconButton>
</Tooltip>
File size
</Typography>
</Grid>
- <FileTree onMenuOpen={onItemMenuOpen} {...treeProps} />
+ <FileTree onMenuOpen={(ev, item) => onItemMenuOpen(ev, item, isWritable)} {...treeProps} />
</Card>);
onContextMenu={this.handleContextMenu}
toggleItemActive={this.handleToggleActive}
toggleItemOpen={this.handleToggle}
- toggleItemSelection={this.handleSelectionChange}
+ toggleItemSelection={this.handleSelectionChange}
currentItemUuid={this.props.currentItemUuid} />;
}
import Star from '@material-ui/icons/Star';
import StarBorder from '@material-ui/icons/StarBorder';
import Warning from '@material-ui/icons/Warning';
+import Visibility from '@material-ui/icons/Lock';
import VpnKey from '@material-ui/icons/VpnKey';
export type IconType = React.SFC<{ className?: string, style?: object }>;
export const ProjectIcon: IconType = (props) => <Folder {...props} />;
export const ProjectsIcon: IconType = (props) => <Inbox {...props} />;
export const ProvenanceGraphIcon: IconType = (props) => <DeviceHub {...props} />;
+export const ReadOnlyIcon: IconType = (props) => <Visibility {...props} />;
export const RemoveIcon: IconType = (props) => <Delete {...props} />;
export const RemoveFavoriteIcon: IconType = (props) => <Star {...props} />;
export const PublicFavoriteIcon: IconType = (props) => <Public {...props} />;
import { projectActionSet } from "~/views-components/context-menu/action-sets/project-action-set";
import { resourceActionSet } from '~/views-components/context-menu/action-sets/resource-action-set';
import { favoriteActionSet } from "~/views-components/context-menu/action-sets/favorite-action-set";
-import { collectionFilesActionSet } from '~/views-components/context-menu/action-sets/collection-files-action-set';
-import { collectionFilesItemActionSet } from '~/views-components/context-menu/action-sets/collection-files-item-action-set';
+import { collectionFilesActionSet, readOnlyCollectionFilesActionSet } from '~/views-components/context-menu/action-sets/collection-files-action-set';
+import { collectionFilesItemActionSet, readOnlyCollectionFilesItemActionSet } from '~/views-components/context-menu/action-sets/collection-files-item-action-set';
import { collectionFilesNotSelectedActionSet } from '~/views-components/context-menu/action-sets/collection-files-not-selected-action-set';
-import { collectionActionSet } from '~/views-components/context-menu/action-sets/collection-action-set';
+import { collectionActionSet, readOnlyCollectionActionSet } from '~/views-components/context-menu/action-sets/collection-action-set';
import { collectionResourceActionSet } from '~/views-components/context-menu/action-sets/collection-resource-action-set';
import { processActionSet } from '~/views-components/context-menu/action-sets/process-action-set';
import { loadWorkbench } from '~/store/workbench/workbench-actions';
addMenuActionSet(ContextMenuKind.RESOURCE, resourceActionSet);
addMenuActionSet(ContextMenuKind.FAVORITE, favoriteActionSet);
addMenuActionSet(ContextMenuKind.COLLECTION_FILES, collectionFilesActionSet);
+addMenuActionSet(ContextMenuKind.READONLY_COLLECTION_FILES, readOnlyCollectionFilesActionSet);
addMenuActionSet(ContextMenuKind.COLLECTION_FILES_NOT_SELECTED, collectionFilesNotSelectedActionSet);
addMenuActionSet(ContextMenuKind.COLLECTION_FILES_ITEM, collectionFilesItemActionSet);
+addMenuActionSet(ContextMenuKind.READONLY_COLLECTION_FILES_ITEM, readOnlyCollectionFilesItemActionSet);
addMenuActionSet(ContextMenuKind.COLLECTION, collectionActionSet);
addMenuActionSet(ContextMenuKind.COLLECTION_RESOURCE, collectionResourceActionSet);
+addMenuActionSet(ContextMenuKind.READONLY_COLLECTION, readOnlyCollectionActionSet);
addMenuActionSet(ContextMenuKind.TRASHED_COLLECTION, trashedCollectionActionSet);
addMenuActionSet(ContextMenuKind.PROCESS, processActionSet);
addMenuActionSet(ContextMenuKind.PROCESS_RESOURCE, processResourceActionSet);
);
};
-export const openCollectionFilesContextMenu = (event: React.MouseEvent<HTMLElement>) =>
+export const openCollectionFilesContextMenu = (event: React.MouseEvent<HTMLElement>, isWritable: boolean) =>
(dispatch: Dispatch, getState: () => RootState) => {
const isCollectionFileSelected = JSON.stringify(getState().collectionPanelFiles).includes('"selected":true');
dispatch<any>(openContextMenu(event, {
uuid: '',
ownerUuid: '',
kind: ResourceKind.COLLECTION,
- menuKind: isCollectionFileSelected ? ContextMenuKind.COLLECTION_FILES : ContextMenuKind.COLLECTION_FILES_NOT_SELECTED
+ menuKind: isCollectionFileSelected
+ ? isWritable
+ ? ContextMenuKind.COLLECTION_FILES
+ : ContextMenuKind.READONLY_COLLECTION_FILES
+ : ContextMenuKind.COLLECTION_FILES_NOT_SELECTED
}));
};
export const resourcesReducer = (state: ResourcesState = {}, action: ResourcesAction) =>
resourcesActions.match(action, {
- SET_RESOURCES: resources => resources.reduce((state, resource) => setResource(resource.uuid, resource)(state), state),
- DELETE_RESOURCES: ids => ids.reduce((state, id) => deleteResource(id)(state), state),
+ SET_RESOURCES: resources => resources.reduce(
+ (state, resource) => setResource(resource.uuid, resource)(state),
+ state),
+ DELETE_RESOURCES: ids => ids.reduce(
+ (state, id) => deleteResource(id)(state),
+ state),
default: () => state,
});
\ No newline at end of file
OWNED: async collection => {
dispatch(collectionPanelActions.SET_COLLECTION(collection as CollectionResource));
dispatch(updateResources([collection]));
- await dispatch(activateSidePanelTreeItem(collection.ownerUuid));
+ dispatch(activateSidePanelTreeItem(collection.ownerUuid));
dispatch(setSidePanelBreadcrumbs(collection.ownerUuid));
dispatch(loadCollectionPanel(collection.uuid));
},
dispatch(activateSidePanelTreeItem(SidePanelTreeCategory.TRASH));
dispatch(loadCollectionPanel(collection.uuid));
},
-
});
}
});
onSelectionToggle: (event, item) => {
dispatch(collectionPanelFilesAction.TOGGLE_COLLECTION_FILE_SELECTION({ id: item.id }));
},
- onItemMenuOpen: (event, item) => {
- dispatch<any>(openContextMenu(event, { menuKind: ContextMenuKind.COLLECTION_FILES_ITEM, kind: ResourceKind.COLLECTION, name: item.data.name, uuid: item.id, ownerUuid: '' }));
+ onItemMenuOpen: (event, item, isWritable) => {
+ dispatch<any>(openContextMenu(
+ event,
+ {
+ menuKind: isWritable
+ ? ContextMenuKind.COLLECTION_FILES_ITEM
+ : ContextMenuKind.READONLY_COLLECTION_FILES_ITEM,
+ kind: ResourceKind.COLLECTION,
+ name: item.data.name,
+ uuid: item.id,
+ ownerUuid: ''
+ }
+ ));
},
- onOptionsMenuOpen: (event) => {
- dispatch<any>(openCollectionFilesContextMenu(event));
+ onOptionsMenuOpen: (event, isWritable) => {
+ dispatch<any>(openCollectionFilesContextMenu(event, isWritable));
},
onFileClick: (id) => {
dispatch(openDetailsPanel(id));
import { openAdvancedTabDialog } from "~/store/advanced-tab/advanced-tab";
import { toggleDetailsPanel } from '~/store/details-panel/details-panel-action';
-export const collectionActionSet: ContextMenuActionSet = [[
- {
- icon: RenameIcon,
- name: "Edit collection",
- execute: (dispatch, resource) => {
- dispatch<any>(openCollectionUpdateDialog(resource));
- }
- },
- {
- icon: ShareIcon,
- name: "Share",
- execute: (dispatch, { uuid }) => {
- dispatch<any>(openSharingDialog(uuid));
- }
- },
+export const readOnlyCollectionActionSet: ContextMenuActionSet = [[
{
component: ToggleFavoriteAction,
execute: (dispatch, resource) => {
});
}
},
- {
- icon: MoveToIcon,
- name: "Move to",
- execute: (dispatch, resource) => dispatch<any>(openMoveCollectionDialog(resource))
- },
{
icon: CopyIcon,
name: "Copy to project",
dispatch<any>(toggleDetailsPanel());
}
},
- // {
- // icon: ProvenanceGraphIcon,
- // name: "Provenance graph",
- // execute: (dispatch, resource) => {
- // // add code
- // }
- // },
{
icon: AdvancedIcon,
name: "Advanced",
dispatch<any>(openAdvancedTabDialog(resource.uuid));
}
},
+]];
+
+export const collectionActionSet: ContextMenuActionSet = readOnlyCollectionActionSet.concat([[
+ {
+ icon: RenameIcon,
+ name: "Edit collection",
+ execute: (dispatch, resource) => {
+ dispatch<any>(openCollectionUpdateDialog(resource));
+ }
+ },
+ {
+ icon: ShareIcon,
+ name: "Share",
+ execute: (dispatch, { uuid }) => {
+ dispatch<any>(openSharingDialog(uuid));
+ }
+ },
+ {
+ icon: MoveToIcon,
+ name: "Move to",
+ execute: (dispatch, resource) => dispatch<any>(openMoveCollectionDialog(resource))
+ },
{
component: ToggleTrashAction,
execute: (dispatch, resource) => {
dispatch<any>(toggleCollectionTrashed(resource.uuid, resource.isTrashed!!));
}
},
- // {
- // icon: RemoveIcon,
- // name: "Remove",
- // execute: (dispatch, resource) => {
- // // add code
- // }
- // }
-]];
+]]);
import { openCollectionPartialCopyDialog, openCollectionPartialCopyToSelectedCollectionDialog } from '~/store/collections/collection-partial-copy-actions';
import { DownloadCollectionFileAction } from "~/views-components/context-menu/actions/download-collection-file-action";
-export const collectionFilesActionSet: ContextMenuActionSet = [[{
- name: "Select all",
- execute: dispatch => {
- dispatch(collectionPanelFilesAction.SELECT_ALL_COLLECTION_FILES());
+export const readOnlyCollectionFilesActionSet: ContextMenuActionSet = [[
+ {
+ name: "Select all",
+ execute: dispatch => {
+ dispatch(collectionPanelFilesAction.SELECT_ALL_COLLECTION_FILES());
+ }
+ },
+ {
+ name: "Unselect all",
+ execute: dispatch => {
+ dispatch(collectionPanelFilesAction.UNSELECT_ALL_COLLECTION_FILES());
+ }
+ },
+ {
+ component: DownloadCollectionFileAction,
+ execute: () => { return; }
+ },
+ {
+ name: "Create a new collection with selected",
+ execute: dispatch => {
+ dispatch<any>(openCollectionPartialCopyDialog());
+ }
+ },
+ {
+ name: "Copy selected into the collection",
+ execute: dispatch => {
+ dispatch<any>(openCollectionPartialCopyToSelectedCollectionDialog());
+ }
}
-}, {
- name: "Unselect all",
- execute: dispatch => {
- dispatch(collectionPanelFilesAction.UNSELECT_ALL_COLLECTION_FILES());
- }
-}, {
- name: "Remove selected",
- execute: dispatch => {
- dispatch(openMultipleFilesRemoveDialog());
- }
-}, {
- component: DownloadCollectionFileAction,
- execute: () => { return; }
-}, {
- name: "Create a new collection with selected",
- execute: dispatch => {
- dispatch<any>(openCollectionPartialCopyDialog());
- }
-}, {
- name: "Copy selected into the collection",
- execute: dispatch => {
- dispatch<any>(openCollectionPartialCopyToSelectedCollectionDialog());
- }
-}]];
+]];
+
+export const collectionFilesActionSet: ContextMenuActionSet = readOnlyCollectionFilesActionSet.concat([[
+ {
+ name: "Remove selected",
+ execute: dispatch => {
+ dispatch(openMultipleFilesRemoveDialog());
+ }
+ },
+]]);
import { CollectionFileViewerAction } from '~/views-components/context-menu/actions/collection-file-viewer-action';
-export const collectionFilesItemActionSet: ContextMenuActionSet = [[{
- name: "Rename",
- icon: RenameIcon,
- execute: (dispatch, resource) => {
- dispatch<any>(openRenameFileDialog({ name: resource.name, id: resource.uuid }));
+export const readOnlyCollectionFilesItemActionSet: ContextMenuActionSet = [[
+ {
+ component: DownloadCollectionFileAction,
+ execute: () => { return; }
+ },
+ {
+ component: CollectionFileViewerAction,
+ execute: () => { return; },
}
-}, {
- component: DownloadCollectionFileAction,
- execute: () => { return; }
-}, {
- name: "Remove",
- icon: RemoveIcon,
- execute: (dispatch, resource) => {
- dispatch<any>(openFileRemoveDialog(resource.uuid));
+]];
+
+export const collectionFilesItemActionSet: ContextMenuActionSet = readOnlyCollectionFilesItemActionSet.concat([[
+ {
+ name: "Rename",
+ icon: RenameIcon,
+ execute: (dispatch, resource) => {
+ dispatch<any>(openRenameFileDialog({ name: resource.name, id: resource.uuid }));
+ }
+ },
+ {
+ name: "Remove",
+ icon: RemoveIcon,
+ execute: (dispatch, resource) => {
+ dispatch<any>(openFileRemoveDialog(resource.uuid));
+ }
}
-}], [{
- component: CollectionFileViewerAction,
- execute: () => { return; },
-}]];
+]]);
\ No newline at end of file
FAVORITE = "Favorite",
TRASH = "Trash",
COLLECTION_FILES = "CollectionFiles",
+ READONLY_COLLECTION_FILES = "ReadOnlyCollectionFiles",
COLLECTION_FILES_ITEM = "CollectionFilesItem",
+ READONLY_COLLECTION_FILES_ITEM = "ReadOnlyCollectionFilesItem",
COLLECTION_FILES_NOT_SELECTED = "CollectionFilesNotSelected",
COLLECTION = 'Collection',
COLLECTION_ADMIN = 'CollectionAdmin',
COLLECTION_RESOURCE = 'CollectionResource',
+ READONLY_COLLECTION = 'ReadOnlyCollection',
TRASHED_COLLECTION = 'TrashedCollection',
PROCESS = "Process",
PROCESS_ADMIN = 'ProcessAdmin',
import { RouteComponentProps } from 'react-router';
import { ArvadosTheme } from '~/common/custom-theme';
import { RootState } from '~/store/store';
-import { MoreOptionsIcon, CollectionIcon } from '~/components/icon/icon';
+import { MoreOptionsIcon, CollectionIcon, ReadOnlyIcon } from '~/components/icon/icon';
import { DetailsAttribute } from '~/components/details-attribute/details-attribute';
import { CollectionResource } from '~/models/collection';
import { CollectionPanelFiles } from '~/views-components/collection-panel-files/collection-panel-files';
import { snackbarActions, SnackbarKind } from '~/store/snackbar/snackbar-actions';
import { getPropertyChip } from '~/views-components/resource-properties-form/property-chip';
import { IllegalNamingWarning } from '~/components/warning/warning';
+import { GroupResource } from '~/models/group';
+import { UserResource } from '~/models/user';
+import { getUserUuid } from '~/common/getuser';
-type CssRules = 'card' | 'iconHeader' | 'tag' | 'label' | 'value' | 'link';
+type CssRules = 'card' | 'iconHeader' | 'tag' | 'label' | 'value' | 'link' | 'centeredLabel';
const styles: StyleRulesCallback<CssRules> = (theme: ArvadosTheme) => ({
card: {
label: {
fontSize: '0.875rem'
},
+ centeredLabel: {
+ fontSize: '0.875rem',
+ textAlign: 'center'
+ },
value: {
textTransform: 'none',
fontSize: '0.875rem'
interface CollectionPanelDataProps {
item: CollectionResource;
+ isWritable: boolean;
}
type CollectionPanelProps = CollectionPanelDataProps & DispatchProp
export const CollectionPanel = withStyles(styles)(
connect((state: RootState, props: RouteComponentProps<{ id: string }>) => {
- const item = getResource(props.match.params.id)(state.resources);
- return { item };
+ const currentUserUUID = getUserUuid(state);
+ const item = getResource<CollectionResource>(props.match.params.id)(state.resources);
+ let isWritable = false;
+ if (item && item.ownerUuid === currentUserUUID) {
+ isWritable = true;
+ } else if (item) {
+ const itemOwner = getResource<GroupResource|UserResource>(item.ownerUuid)(state.resources);
+ if (itemOwner) {
+ isWritable = itemOwner.writableBy.indexOf(currentUserUUID || '') >= 0;
+ }
+ }
+ return { item, isWritable };
})(
class extends React.Component<CollectionPanelProps> {
-
render() {
- const { classes, item, dispatch } = this.props;
+ const { classes, item, dispatch, isWritable } = this.props;
return item
? <>
<Card className={classes.card}>
<CollectionIcon className={classes.iconHeader} />
</IconButton>
}
- action={
+ action={<div>
+ {isWritable === false &&
+ <Tooltip title="This collection is read-only">
+ <ReadOnlyIcon />
+ </Tooltip>}
<Tooltip title="More options" disableFocusListener>
<IconButton
aria-label="More options"
<MoreOptionsIcon />
</IconButton>
</Tooltip>
- }
- title={item && <span><IllegalNamingWarning name={item.name}/>{item.name}</span>}
+ </div>}
+ title={<span><IllegalNamingWarning name={item.name}/>{item.name}</span>}
titleTypographyProps={this.titleProps}
- subheader={item && item.description}
+ subheader={item.description}
subheaderTypographyProps={this.titleProps} />
<CardContent>
<Grid container direction="column">
<Grid item xs={10}>
<DetailsAttribute classLabel={classes.label} classValue={classes.value}
label='Collection UUID'
- linkToUuid={item && item.uuid} />
+ linkToUuid={item.uuid} />
<DetailsAttribute classLabel={classes.label} classValue={classes.value}
label='Portable data hash'
- linkToUuid={item && item.portableDataHash} />
+ linkToUuid={item.portableDataHash} />
<DetailsAttribute classLabel={classes.label} classValue={classes.value}
- label='Number of files' value={item && item.fileCount} />
+ label='Number of files' value={item.fileCount} />
<DetailsAttribute classLabel={classes.label} classValue={classes.value}
- label='Content size' value={item && formatFileSize(item.fileSizeTotal)} />
+ label='Content size' value={formatFileSize(item.fileSizeTotal)} />
<DetailsAttribute classLabel={classes.label} classValue={classes.value}
- label='Owner' linkToUuid={item && item.ownerUuid} />
+ label='Owner' linkToUuid={item.ownerUuid} />
{(item.properties.container_request || item.properties.containerRequest) &&
<span onClick={() => dispatch<any>(navigateToProcess(item.properties.container_request || item.properties.containerRequest))}>
<DetailsAttribute classLabel={classes.link} label='Link to process' />
<CardHeader title="Properties" />
<CardContent>
<Grid container direction="column">
- <Grid item xs={12}>
+ {isWritable && <Grid item xs={12}>
<CollectionTagForm />
- </Grid>
+ </Grid>}
<Grid item xs={12}>
- {Object.keys(item.properties).map(k =>
+ { Object.keys(item.properties).length > 0
+ ? Object.keys(item.properties).map(k =>
Array.isArray(item.properties[k])
? item.properties[k].map((v: string) =>
getPropertyChip(
k, v,
- this.handleDelete(k, v),
+ isWritable
+ ? this.handleDelete(k, item.properties[k])
+ : undefined,
classes.tag))
: getPropertyChip(
k, item.properties[k],
- this.handleDelete(k, item.properties[k]),
+ isWritable
+ ? this.handleDelete(k, item.properties[k])
+ : undefined,
classes.tag)
- )}
+ )
+ : <div className={classes.centeredLabel}>No properties set on this collection.</div>
+ }
</Grid>
</Grid>
</CardContent>
</Card>
<div className={classes.card}>
- <CollectionPanelFiles />
+ <CollectionPanelFiles isWritable={isWritable} />
</div>
</>
: null;
handleContextMenu = (event: React.MouseEvent<any>) => {
const { uuid, ownerUuid, name, description, kind, isTrashed } = this.props.item;
+ const { isWritable } = this.props;
const resource = {
uuid,
ownerUuid,
name,
description,
kind,
- menuKind: isTrashed
- ? ContextMenuKind.TRASHED_COLLECTION
- : ContextMenuKind.COLLECTION
+ menuKind: isWritable
+ ? isTrashed
+ ? ContextMenuKind.TRASHED_COLLECTION
+ : ContextMenuKind.COLLECTION
+ : ContextMenuKind.READONLY_COLLECTION
};
this.props.dispatch<any>(openContextMenu(event, resource));
}