Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BHBC-2306: Hide Submit functionality #1001

Merged
merged 7 commits into from
Apr 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions app/src/components/attachments/list/AttachmentsList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,16 @@ import Typography from '@material-ui/core/Typography';
import { mdiFileOutline } from '@mdi/js';
import Icon from '@mdi/react';
import { SubmitStatusChip } from 'components/chips/SubmitStatusChip';
import { SystemRoleGuard } from 'components/security/Guards';
import { BioHubSubmittedStatusType } from 'constants/misc';
import { SYSTEM_ROLE } from 'constants/roles';
import { IGetProjectAttachment } from 'interfaces/useProjectApi.interface';
import { IGetSurveyAttachment } from 'interfaces/useSurveyApi.interface';
import React, { useState } from 'react';
import AttachmentsListItemMenuButton from './AttachmentsListItemMenuButton';

//TODO: PRODUCTION_BANDAGE: Remove <SystemRoleGuard validSystemRoles={[SYSTEM_ROLE.DATA_ADMINISTRATOR, SYSTEM_ROLE.SYSTEM_ADMIN]}>

const useStyles = makeStyles((theme: Theme) => ({
attachmentsTable: {
tableLayout: 'fixed'
Expand Down Expand Up @@ -59,7 +63,9 @@ const AttachmentsList = <T extends IGetProjectAttachment | IGetSurveyAttachment>
<TableRow>
<TableCell>Name</TableCell>
<TableCell width="130">Type</TableCell>
<TableCell width="130">Status</TableCell>
<SystemRoleGuard validSystemRoles={[SYSTEM_ROLE.DATA_ADMINISTRATOR, SYSTEM_ROLE.SYSTEM_ADMIN]}>
<TableCell width="130">Status</TableCell>
</SystemRoleGuard>
<TableCell width="75"></TableCell>
</TableRow>
</TableHead>
Expand Down Expand Up @@ -119,9 +125,11 @@ function AttachmentsTableRow<T extends IGetProjectAttachment | IGetSurveyAttachm
</Box>
</TableCell>
<TableCell>{attachment.fileType}</TableCell>
<TableCell>
<SubmitStatusChip status={getArtifactSubmissionStatus(attachment)} />
</TableCell>
<SystemRoleGuard validSystemRoles={[SYSTEM_ROLE.DATA_ADMINISTRATOR, SYSTEM_ROLE.SYSTEM_ADMIN]}>
<TableCell>
<SubmitStatusChip status={getArtifactSubmissionStatus(attachment)} />
</TableCell>
</SystemRoleGuard>
<TableCell align="right">
<AttachmentsListItemMenuButton
attachment={attachment}
Expand Down
54 changes: 48 additions & 6 deletions app/src/features/projects/list/ProjectsListPage.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,25 @@ describe('ProjectsListPage', () => {
});

test('renders with a proper list of projects when completed', async () => {
const authState = ({
keycloakWrapper: {
hasLoadedAllUserInfo: true,
systemRoles: [SYSTEM_ROLE.SYSTEM_ADMIN],
hasAccessRequest: false,
hasSystemRole: () => true,

keycloak: {},
getUserIdentifier: jest.fn(),
getIdentitySource: jest.fn(),
username: 'testusername',
displayName: 'testdisplayname',
email: '[email protected]',
firstName: 'testfirst',
lastName: 'testlast',
refresh: () => {}
}
} as unknown) as IAuthState;

mockBiohubApi().project.getProjectsList.mockResolvedValue([
{
id: 1,
Expand All @@ -104,9 +123,11 @@ describe('ProjectsListPage', () => {
]);

const { getByText, getByTestId } = render(
<MemoryRouter>
<ProjectsListPage />
</MemoryRouter>
<AuthStateContext.Provider value={authState}>
<MemoryRouter>
<ProjectsListPage />
</MemoryRouter>
</AuthStateContext.Provider>
);

await waitFor(() => {
Expand All @@ -116,6 +137,25 @@ describe('ProjectsListPage', () => {
});

test('renders with a proper list of projects when active', async () => {
const authState = ({
keycloakWrapper: {
hasLoadedAllUserInfo: true,
systemRoles: [SYSTEM_ROLE.SYSTEM_ADMIN],
hasAccessRequest: false,
hasSystemRole: () => true,

keycloak: {},
getUserIdentifier: jest.fn(),
getIdentitySource: jest.fn(),
username: 'testusername',
displayName: 'testdisplayname',
email: '[email protected]',
firstName: 'testfirst',
lastName: 'testlast',
refresh: () => {}
}
} as unknown) as IAuthState;

mockBiohubApi().project.getProjectsList.mockResolvedValue([
{
id: 1,
Expand All @@ -130,9 +170,11 @@ describe('ProjectsListPage', () => {
]);

const { getByText, getByTestId } = render(
<MemoryRouter>
<ProjectsListPage />
</MemoryRouter>
<AuthStateContext.Provider value={authState}>
<MemoryRouter>
<ProjectsListPage />
</MemoryRouter>
</AuthStateContext.Provider>
);

await waitFor(() => {
Expand Down
10 changes: 8 additions & 2 deletions app/src/features/projects/list/ProjectsListPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ import React, { useContext, useEffect, useRef, useState } from 'react';
import { Link as RouterLink } from 'react-router-dom';
import { getFormattedDate } from 'utils/Utils';

//TODO: PRODUCTION_BANDAGE: Remove <SystemRoleGuard validSystemRoles={[SYSTEM_ROLE.DATA_ADMINISTRATOR, SYSTEM_ROLE.SYSTEM_ADMIN]}>

const useStyles = makeStyles((theme: Theme) => ({
pageTitleContainer: {
maxWidth: '170ch',
Expand Down Expand Up @@ -266,7 +268,9 @@ const ProjectsListPage: React.FC = () => {
<TableCell>Name</TableCell>
<TableCell>Contact Agency</TableCell>
<TableCell width={150}>Type</TableCell>
<TableCell width={150}>Status</TableCell>
<SystemRoleGuard validSystemRoles={[SYSTEM_ROLE.DATA_ADMINISTRATOR, SYSTEM_ROLE.SYSTEM_ADMIN]}>
<TableCell width={150}>Status</TableCell>
</SystemRoleGuard>
<TableCell width={150}>Start Date</TableCell>
<TableCell width={150}>End Date</TableCell>
</TableRow>
Expand Down Expand Up @@ -305,7 +309,9 @@ const ProjectsListPage: React.FC = () => {
</TableCell>
<TableCell>{project.coordinator_agency}</TableCell>
<TableCell>{project.project_type}</TableCell>
<TableCell>{getChipIcon(project.completion_status)}</TableCell>
<SystemRoleGuard validSystemRoles={[SYSTEM_ROLE.DATA_ADMINISTRATOR, SYSTEM_ROLE.SYSTEM_ADMIN]}>
<TableCell>{getChipIcon(project.completion_status)}</TableCell>
</SystemRoleGuard>
<TableCell>{getFormattedDate(DATE_FORMAT.ShortMediumDateFormat, project.start_date)}</TableCell>
<TableCell>{getFormattedDate(DATE_FORMAT.ShortMediumDateFormat, project.end_date)}</TableCell>
</TableRow>
Expand Down
8 changes: 7 additions & 1 deletion app/src/features/surveys/view/SurveyPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import Container from '@material-ui/core/Container';
import Grid from '@material-ui/core/Grid';
import Paper from '@material-ui/core/Paper';
import SubmissionAlertBar from 'components/publish/SubmissionAlertBar';
import { SystemRoleGuard } from 'components/security/Guards';
import { SYSTEM_ROLE } from 'constants/roles';
import { CodesContext } from 'contexts/codesContext';
import { SurveyContext } from 'contexts/surveyContext';
import SurveyDetails from 'features/surveys/view/SurveyDetails';
Expand All @@ -14,6 +16,8 @@ import SurveyObservations from './survey-observations/SurveyObservations';
import SurveyAttachments from './SurveyAttachments';
import SurveyHeader from './SurveyHeader';

//TODO: PRODUCTION_BANDAGE: Remove <SystemRoleGuard validSystemRoles={[SYSTEM_ROLE.DATA_ADMINISTRATOR, SYSTEM_ROLE.SYSTEM_ADMIN]}>

/**
* Page to display a single Survey.
*
Expand All @@ -39,7 +43,9 @@ const SurveyPage: React.FC = () => {
<SurveyHeader />
<Container maxWidth="xl">
<Box my={3}>
<SubmissionAlertBar />
<SystemRoleGuard validSystemRoles={[SYSTEM_ROLE.DATA_ADMINISTRATOR, SYSTEM_ROLE.SYSTEM_ADMIN]}>
<SubmissionAlertBar />
</SystemRoleGuard>
<Grid container spacing={3}>
<Grid item md={12} lg={4}>
<Paper elevation={0}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,14 @@ import {
import Icon from '@mdi/react';
import clsx from 'clsx';
import { SubmitStatusChip } from 'components/chips/SubmitStatusChip';
import { SystemRoleGuard } from 'components/security/Guards';
import { BioHubSubmittedStatusType } from 'constants/misc';
import { SYSTEM_ROLE } from 'constants/roles';
import { IGetSummaryResultsResponse } from 'interfaces/useSummaryResultsApi.interface';
import React from 'react';

//TODO: PRODUCTION_BANDAGE: Remove <SystemRoleGuard validSystemRoles={[SYSTEM_ROLE.DATA_ADMINISTRATOR, SYSTEM_ROLE.SYSTEM_ADMIN]}>

interface IFileResultsProps {
fileData: IGetSummaryResultsResponse;
downloadFile: () => void;
Expand Down Expand Up @@ -103,9 +107,10 @@ const FileSummaryResults = (props: IFileResultsProps) => {

<Box flex="0 0 auto" display="flex" alignItems="center">
<Box mr={2}>
<SubmitStatusChip status={checkSubmissionStatus(fileData)} />
<SystemRoleGuard validSystemRoles={[SYSTEM_ROLE.DATA_ADMINISTRATOR, SYSTEM_ROLE.SYSTEM_ADMIN]}>
<SubmitStatusChip status={checkSubmissionStatus(fileData)} />
</SystemRoleGuard>
</Box>

<Box>
<IconButton
aria-controls="context-menu"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,14 @@ import {
import Icon from '@mdi/react';
import clsx from 'clsx';
import { SubmitStatusChip } from 'components/chips/SubmitStatusChip';
import { SystemRoleGuard } from 'components/security/Guards';
import { BioHubSubmittedStatusType } from 'constants/misc';
import { SYSTEM_ROLE } from 'constants/roles';
import { IGetObservationSubmissionResponse } from 'interfaces/useObservationApi.interface';
import React from 'react';

//TODO: PRODUCTION_BANDAGE: Remove <SystemRoleGuard validSystemRoles={[SYSTEM_ROLE.DATA_ADMINISTRATOR, SYSTEM_ROLE.SYSTEM_ADMIN]}>

const useStyles = makeStyles((theme: Theme) => ({
importFile: {
display: 'flex',
Expand Down Expand Up @@ -115,7 +119,9 @@ const ObservationFileCard = (props: IObservationFileCardProps) => {

<Box flex="0 0 auto" display="flex" alignItems="center">
<Box mr={2}>
<SubmitStatusChip status={status} />
<SystemRoleGuard validSystemRoles={[SYSTEM_ROLE.DATA_ADMINISTRATOR, SYSTEM_ROLE.SYSTEM_ADMIN]}>
<SubmitStatusChip status={status} />
</SystemRoleGuard>
</Box>
<Box>
<IconButton aria-controls="context-menu" aria-haspopup="true" onClick={handleOpenContextMenu}>
Expand Down