Skip to content

Commit

Permalink
Bug/wp 47 fix shared workspace manage team modal (#922)
Browse files Browse the repository at this point in the history
* WP-47: if user is Guest, disable rename & trash

* css to Update button

* npm run prettier

* update to unit test

* ran prettier

* check for 'USER' to prevent file move

* 'GUEST' cannot move files

---------

Co-authored-by: edmondsgarrett <[email protected]>
Co-authored-by: Chandra Y <[email protected]>
  • Loading branch information
3 people authored Dec 22, 2023
1 parent 7fd106f commit 7335dcb
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 5 deletions.
1 change: 1 addition & 0 deletions Core-Portal
Submodule Core-Portal added at 272c63
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,10 @@
composes: c-button--secondary from '../../../styles/components/c-button.css';
}

.ownership-button {
margin-left: 5px;
}

div > .project-role-selector {
height: auto; /* overwrite .form-control height to accommodate dropdown selector next to small button in this instance */
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { useSelector } from 'react-redux';
import Cookies from 'js-cookie';
import fetch from 'cross-fetch';
import DropdownSelector from '_common/DropdownSelector';
import { Button } from 'reactstrap';
import { Button } from '_common';
import styles from '../DataFilesProjectMembers.module.scss';
import LoadingSpinner from '_common/LoadingSpinner';

Expand Down Expand Up @@ -109,7 +109,8 @@ const SystemRoleSelector = ({ projectId, username }) => {
</DropdownSelector>
{data.role !== selectedRole && !isFetching && (
<Button
style={{ marginLeft: '5px' }}
type="secondary"
size="small"
className={styles['ownership-button']}
onClick={() => setSystemRole(selectedRole)}
>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import PropTypes from 'prop-types';
import { Button } from '_common';
import getFilePermissions from 'utils/filePermissions';
import { useModal, useSelectedFiles, useFileListing } from 'hooks/datafiles';
import { useSystemRole } from '../DataFilesProjectMembers/_cells/SystemRoleSelector';
import './DataFilesToolbar.scss';

export const ToolbarButton = ({ text, iconName, onClick, disabled }) => {
Expand Down Expand Up @@ -55,6 +56,19 @@ const DataFilesToolbar = ({ scheme, api }) => {
(sys) => sys.system === params.system && sys.scheme === params.scheme
);

const { projectId } = useSelector((state) => state.projects.metadata);

const authenticatedUser = useSelector(
(state) => state.authenticatedUser.user.username
);

const { query: authenticatedUserQuery } = useSystemRole(
projectId,
authenticatedUser
);

const isGuest = authenticatedUserQuery?.data?.role === 'GUEST';

const inTrash = useSelector((state) => {
// remove leading slash from homeDir value
const homeDir = selectedSystem?.homeDir?.slice(1);
Expand Down Expand Up @@ -177,10 +191,10 @@ const DataFilesToolbar = ({ scheme, api }) => {
'areMultipleFilesOrFolderSelected',
permissionParams
);
const canRename = getFilePermissions('rename', permissionParams);
const canMove = getFilePermissions('move', permissionParams);
const canRename = getFilePermissions('rename', permissionParams) && !isGuest;
const canMove = getFilePermissions('move', permissionParams) && !isGuest;
const canCopy = getFilePermissions('copy', permissionParams);
const canTrash = getFilePermissions('trash', permissionParams);
const canTrash = getFilePermissions('trash', permissionParams) && !isGuest;
const canCompress = getFilePermissions('compress', permissionParams);
const canExtract = getFilePermissions('extract', permissionParams);
const canMakePublic =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ describe('DataFilesToolbar', () => {
},
listing: { selected: { FilesListing: [] } },
systems: systemsFixture,
projects: { metadata: [] },
authenticatedUser: { user: { username: 'testuser' } },
}),
createMemoryHistory()
);
Expand Down Expand Up @@ -82,6 +84,8 @@ describe('DataFilesToolbar', () => {
},
listing: { selected: { FilesListing: [] } },
systems: systemsFixture,
projects: { metadata: [] },
authenticatedUser: { user: { username: 'testuser' } },
}),
createMemoryHistory()
);
Expand Down Expand Up @@ -114,6 +118,8 @@ describe('DataFilesToolbar', () => {
},
listing: { selected: { FilesListing: [] } },
systems: systemsFixture,
projects: { metadata: [] },
authenticatedUser: { user: { username: 'testuser' } },
}),
createMemoryHistory()
);
Expand Down Expand Up @@ -146,6 +152,8 @@ describe('DataFilesToolbar', () => {
},
listing: { selected: { FilesListing: [] } },
systems: systemsFixture,
projects: { metadata: [] },
authenticatedUser: { user: { username: 'testuser' } },
}),
createMemoryHistory()
);
Expand Down Expand Up @@ -187,6 +195,8 @@ describe('DataFilesToolbar', () => {
operationStatus: { trash: false },
},
systems: systemsFixture,
projects: { metadata: [] },
authenticatedUser: { user: { username: 'testuser' } },
}),
createMemoryHistory()
);
Expand Down Expand Up @@ -218,6 +228,8 @@ describe('DataFilesToolbar', () => {
},
//listing: { } },
systems: systemsFixture,
projects: { metadata: [] },
authenticatedUser: { user: { username: 'testuser' } },
}),
createMemoryHistory()
);
Expand Down

0 comments on commit 7335dcb

Please sign in to comment.