From 86ddd147b75ad41ee023bdeeeb3636e025a3ed7d Mon Sep 17 00:00:00 2001 From: Curtis Upshall Date: Mon, 11 Jul 2022 17:00:51 -0700 Subject: [PATCH 1/9] BHBC-1841: Remove publishing logic - first pass --- api/package-lock.json | 2 +- .../paths/project/{projectId}/publish.test.ts | 141 ------------------ api/src/paths/project/{projectId}/publish.ts | 136 ----------------- .../survey/{surveyId}/publish.test.ts | 67 --------- .../{projectId}/survey/{surveyId}/publish.ts | 138 ----------------- api/src/queries/public/project-queries.ts | 17 +-- api/src/queries/public/search-queries.ts | 4 +- api/src/services/project-service.ts | 19 +-- api/src/services/survey-service.ts | 20 --- app/package-lock.json | 20 ++- app/src/constants/i18n.ts | 16 -- .../features/projects/view/ProjectHeader.tsx | 48 +----- .../features/surveys/view/SurveyHeader.tsx | 55 +------ app/src/hooks/api/useProjectApi.ts | 13 -- app/src/hooks/api/useSurveyApi.ts | 15 -- 15 files changed, 30 insertions(+), 681 deletions(-) delete mode 100644 api/src/paths/project/{projectId}/publish.test.ts delete mode 100644 api/src/paths/project/{projectId}/publish.ts delete mode 100644 api/src/paths/project/{projectId}/survey/{surveyId}/publish.test.ts delete mode 100644 api/src/paths/project/{projectId}/survey/{surveyId}/publish.ts diff --git a/api/package-lock.json b/api/package-lock.json index 6f5b522728..6170194ffd 100644 --- a/api/package-lock.json +++ b/api/package-lock.json @@ -1553,7 +1553,7 @@ "asynckit": { "version": "0.4.0", "resolved": "https://registry.npmjs.org/asynckit/-/asynckit-0.4.0.tgz", - "integrity": "sha1-x57Zf380y48robyXkLzDZkdLS3k=" + "integrity": "sha512-Oei9OH4tRh0YqU3GxhX79dM/mwVgvbZJaSNaRk+bshkj0S5cfHcgYakreBjrHwatXKbz+IoIdYLxrKim2MjW0Q==" }, "atob": { "version": "2.1.2", diff --git a/api/src/paths/project/{projectId}/publish.test.ts b/api/src/paths/project/{projectId}/publish.test.ts deleted file mode 100644 index 8cbdd3dcb7..0000000000 --- a/api/src/paths/project/{projectId}/publish.test.ts +++ /dev/null @@ -1,141 +0,0 @@ -import chai, { expect } from 'chai'; -import { describe } from 'mocha'; -import { QueryResult } from 'pg'; -import sinon from 'sinon'; -import sinonChai from 'sinon-chai'; -import * as db from '../../../database/db'; -import { HTTPError } from '../../../errors/custom-error'; -import { ProjectService } from '../../../services/project-service'; -import { getMockDBConnection } from '../../../__mocks__/db'; -import * as publish from './publish'; - -chai.use(sinonChai); - -const dbConnectionObj = getMockDBConnection(); - -const sampleReq = { - keycloak_token: {}, - params: { - projectId: 1 - }, - body: { - publish: true - } -} as any; - -let actualResult = { - id: null -}; - -const sampleRes = { - status: () => { - return { - json: (result: any) => { - actualResult = result; - } - }; - } -}; - -describe('project/{projectId}/publish', () => { - afterEach(() => { - sinon.restore(); - }); - - it('should throw a 400 error when missing request param projectId', async () => { - sinon.stub(db, 'getDBConnection').returns({ - ...dbConnectionObj, - systemUserId: () => { - return 20; - } - }); - - try { - const result = publish.publishProject(); - - await result( - { ...sampleReq, body: { ...sampleReq.body }, params: { projectId: undefined } }, - (null as unknown) as any, - (null as unknown) as any - ); - expect.fail(); - } catch (actualError) { - expect((actualError as HTTPError).status).to.equal(400); - expect((actualError as HTTPError).message).to.equal('Missing required path parameter: projectId'); - } - }); - - it('should throw a 400 error when missing request body', async () => { - sinon.stub(db, 'getDBConnection').returns({ - ...dbConnectionObj, - systemUserId: () => { - return 20; - } - }); - - try { - const result = publish.publishProject(); - - await result( - { ...sampleReq, body: (null as unknown) as any }, - (null as unknown) as any, - (null as unknown) as any - ); - expect.fail(); - } catch (actualError) { - expect((actualError as HTTPError).status).to.equal(400); - expect((actualError as HTTPError).message).to.equal('Missing request body'); - } - }); - - it('should throw a 400 error when missing publish flag in request body', async () => { - sinon.stub(db, 'getDBConnection').returns({ - ...dbConnectionObj, - systemUserId: () => { - return 20; - } - }); - - try { - const result = publish.publishProject(); - - await result( - { ...sampleReq, body: { ...sampleReq.body, publish: undefined } }, - (null as unknown) as any, - (null as unknown) as any - ); - expect.fail(); - } catch (actualError) { - expect((actualError as HTTPError).status).to.equal(400); - expect((actualError as HTTPError).message).to.equal('Missing publish flag in request body'); - } - }); - - it('should return the project id on success', async () => { - sinon.stub(db, 'getDBConnection').returns({ - ...dbConnectionObj, - systemUserId: () => { - return 20; - }, - query: async () => { - return { - rowCount: 1, - rows: [ - { - id: 1, - create_date: '2020/04/04' - } - ] - } as QueryResult; - } - }); - - sinon.stub(ProjectService.prototype, 'updatePublishStatus').resolves(1); - - const result = publish.publishProject(); - - await result(sampleReq, sampleRes as any, (null as unknown) as any); - - expect(actualResult.id).to.equal(1); - }); -}); diff --git a/api/src/paths/project/{projectId}/publish.ts b/api/src/paths/project/{projectId}/publish.ts deleted file mode 100644 index 1ae11be4e1..0000000000 --- a/api/src/paths/project/{projectId}/publish.ts +++ /dev/null @@ -1,136 +0,0 @@ -import { RequestHandler } from 'express'; -import { Operation } from 'express-openapi'; -import { PROJECT_ROLE } from '../../../constants/roles'; -import { getDBConnection } from '../../../database/db'; -import { HTTP400 } from '../../../errors/custom-error'; -import { projectIdResponseObject } from '../../../openapi/schemas/project'; -import { authorizeRequestHandler } from '../../../request-handlers/security/authorization'; -import { ProjectService } from '../../../services/project-service'; -import { getLogger } from '../../../utils/logger'; - -const defaultLog = getLogger('paths/project/{projectId}/publish'); - -export const PUT: Operation = [ - authorizeRequestHandler((req) => { - return { - and: [ - { - validProjectRoles: [PROJECT_ROLE.PROJECT_LEAD], - projectId: Number(req.params.projectId), - discriminator: 'ProjectRole' - } - ] - }; - }), - publishProject() -]; - -PUT.apiDoc = { - description: 'Publish or unpublish a project.', - tags: ['project'], - security: [ - { - Bearer: [] - } - ], - parameters: [ - { - in: 'path', - name: 'projectId', - schema: { - type: 'number' - }, - required: true - } - ], - requestBody: { - description: 'Publish or unpublish put request object.', - content: { - 'application/json': { - schema: { - title: 'Publish request object', - type: 'object', - required: ['publish'], - properties: { - publish: { - title: 'publish?', - type: 'boolean' - } - } - } - } - } - }, - responses: { - 200: { - description: 'Project publish request completed successfully.', - content: { - 'application/json': { - schema: { - // TODO is there any return value? or is it just an HTTP status with no content? - ...(projectIdResponseObject as object) - } - } - } - }, - 400: { - $ref: '#/components/responses/400' - }, - 401: { - $ref: '#/components/responses/401' - }, - 403: { - $ref: '#/components/responses/401' - }, - 500: { - $ref: '#/components/responses/500' - }, - default: { - $ref: '#/components/responses/default' - } - } -}; - -/** - * Update a project. - * - * @returns {RequestHandler} - */ -export function publishProject(): RequestHandler { - return async (req, res) => { - const connection = getDBConnection(req['keycloak_token']); - - try { - const projectId = Number(req.params.projectId); - - if (!projectId) { - throw new HTTP400('Missing required path parameter: projectId'); - } - - if (!req.body) { - throw new HTTP400('Missing request body'); - } - - if (req.body.publish === undefined) { - throw new HTTP400('Missing publish flag in request body'); - } - - const publish: boolean = req.body.publish; - - await connection.open(); - - const projectService = new ProjectService(connection); - - const result = await projectService.updatePublishStatus(projectId, publish); - - await connection.commit(); - return res.status(200).json({ id: result }); - } catch (error) { - defaultLog.error({ label: 'publishProject', message: 'error', error }); - await connection.rollback(); - throw error; - } finally { - connection.release(); - } - }; -} diff --git a/api/src/paths/project/{projectId}/survey/{surveyId}/publish.test.ts b/api/src/paths/project/{projectId}/survey/{surveyId}/publish.test.ts deleted file mode 100644 index e7b6ade228..0000000000 --- a/api/src/paths/project/{projectId}/survey/{surveyId}/publish.test.ts +++ /dev/null @@ -1,67 +0,0 @@ -import chai, { expect } from 'chai'; -import { describe } from 'mocha'; -import sinon from 'sinon'; -import sinonChai from 'sinon-chai'; -import * as db from '../../../../../database/db'; -import { HTTPError } from '../../../../../errors/custom-error'; -import { SurveyService } from '../../../../../services/survey-service'; -import { getMockDBConnection, getRequestHandlerMocks } from '../../../../../__mocks__/db'; -import { publishSurvey } from './publish'; - -chai.use(sinonChai); - -describe('publishSurvey', () => { - afterEach(() => { - sinon.restore(); - }); - - it('publishes a survey', async () => { - const dbConnectionObj = getMockDBConnection(); - - sinon.stub(db, 'getDBConnection').returns(dbConnectionObj); - - sinon.stub(SurveyService.prototype, 'publishSurvey').resolves(); - - const { mockReq, mockRes, mockNext } = getRequestHandlerMocks(); - - mockReq.params = { - projectId: '1', - surveyId: '2' - }; - - mockReq.body = { - publish: true - }; - - try { - const requestHandler = publishSurvey(); - - await requestHandler(mockReq, mockRes, mockNext); - } catch (actualError) { - expect.fail(); - } - - expect(mockRes.statusValue).to.equal(200); - }); - - it('catches and re-throws error', async () => { - const dbConnectionObj = getMockDBConnection({ release: sinon.stub() }); - - sinon.stub(db, 'getDBConnection').returns(dbConnectionObj); - - sinon.stub(SurveyService.prototype, 'publishSurvey').rejects(new Error('a test error')); - - const { mockReq, mockRes, mockNext } = getRequestHandlerMocks(); - - try { - const requestHandler = publishSurvey(); - - await requestHandler(mockReq, mockRes, mockNext); - expect.fail(); - } catch (actualError) { - expect(dbConnectionObj.release).to.have.been.called; - - expect((actualError as HTTPError).message).to.equal('a test error'); - } - }); -}); diff --git a/api/src/paths/project/{projectId}/survey/{surveyId}/publish.ts b/api/src/paths/project/{projectId}/survey/{surveyId}/publish.ts deleted file mode 100644 index db3f964610..0000000000 --- a/api/src/paths/project/{projectId}/survey/{surveyId}/publish.ts +++ /dev/null @@ -1,138 +0,0 @@ -import { RequestHandler } from 'express'; -import { Operation } from 'express-openapi'; -import { PROJECT_ROLE } from '../../../../../constants/roles'; -import { getDBConnection } from '../../../../../database/db'; -import { authorizeRequestHandler } from '../../../../../request-handlers/security/authorization'; -import { SurveyService } from '../../../../../services/survey-service'; -import { getLogger } from '../../../../../utils/logger'; - -const defaultLog = getLogger('paths/project/{projectId}/survey/{surveyId}/publish'); - -export const PUT: Operation = [ - authorizeRequestHandler((req) => { - return { - and: [ - { - validProjectRoles: [PROJECT_ROLE.PROJECT_LEAD], - projectId: Number(req.params.projectId), - discriminator: 'ProjectRole' - } - ] - }; - }), - publishSurvey() -]; - -PUT.apiDoc = { - description: 'Publish or unpublish a survey.', - tags: ['survey'], - security: [ - { - Bearer: [] - } - ], - parameters: [ - { - in: 'path', - name: 'projectId', - schema: { - type: 'integer', - minimum: 1 - }, - required: true - }, - { - in: 'path', - name: 'surveyId', - schema: { - type: 'integer', - minimum: 1 - }, - required: true - } - ], - requestBody: { - description: 'Publish or unpublish put request object.', - content: { - 'application/json': { - schema: { - title: 'Publish request object', - type: 'object', - required: ['publish'], - properties: { - publish: { - description: 'Set to `true` to publish the survey, `false` to unpublish the survey', - type: 'boolean' - } - } - } - } - } - }, - responses: { - 200: { - description: 'Survey publish request completed successfully.', - content: { - 'application/json': { - schema: { - // TODO is there any return value? or is it just an HTTP status with no content? - title: 'Survey Response Object', - type: 'object', - required: ['id'], - properties: { - id: { - type: 'number' - } - } - } - } - } - }, - 400: { - $ref: '#/components/responses/400' - }, - 401: { - $ref: '#/components/responses/401' - }, - 403: { - $ref: '#/components/responses/401' - }, - 500: { - $ref: '#/components/responses/500' - }, - default: { - $ref: '#/components/responses/default' - } - } -}; - -/** - * Publish survey. - * - * @returns {RequestHandler} - */ -export function publishSurvey(): RequestHandler { - return async (req, res) => { - const surveyId = Number(req.params.surveyId); - const publish: boolean = req.body.publish; - - const connection = getDBConnection(req['keycloak_token']); - try { - await connection.open(); - - const surveyService = new SurveyService(connection); - - await surveyService.publishSurvey(surveyId, publish); - - await connection.commit(); - - return res.status(200).send(); - } catch (error) { - defaultLog.error({ label: 'publishSurvey', message: 'error', error }); - await connection.rollback(); - throw error; - } finally { - connection.release(); - } - }; -} diff --git a/api/src/queries/public/project-queries.ts b/api/src/queries/public/project-queries.ts index f07fddc990..c030c648bb 100644 --- a/api/src/queries/public/project-queries.ts +++ b/api/src/queries/public/project-queries.ts @@ -30,8 +30,7 @@ export const getPublicProjectSQL = (projectId: number): SQLStatement | null => { project_type on project.project_type_id = project_type.project_type_id where - project.project_id = ${projectId} - and project.publish_timestamp is not null; + project.project_id = ${projectId}; `; }; @@ -57,9 +56,7 @@ export const getActivitiesByPublicProjectSQL = (projectId: number): SQLStatement ON p.project_id = pa.project_id WHERE - pa.project_id = ${projectId} - AND - p.publish_timestamp is not null; + pa.project_id = ${projectId}; `; }; @@ -84,8 +81,6 @@ export const getPublicProjectListSQL = (): SQLStatement | null => { on p.project_type_id = pt.project_type_id left outer join permit as pp on p.project_id = pp.project_id - where - p.publish_timestamp is not null group by p.project_id, p.name, @@ -123,9 +118,7 @@ export const getPublicProjectAttachmentsSQL = (projectId: number): SQLStatement on p.project_id = pa.project_id where - pa.project_id = ${projectId} - and - p.publish_timestamp is not null; + pa.project_id = ${projectId}; `; }; @@ -155,9 +148,7 @@ export const getPublicProjectReportAttachmentsSQL = (projectId: number): SQLStat on p.project_id = pa.project_id where - pa.project_id = ${projectId} - and - p.publish_timestamp is not null; + pa.project_id = ${projectId}; `; }; diff --git a/api/src/queries/public/search-queries.ts b/api/src/queries/public/search-queries.ts index d70adb3e11..329a006c3a 100644 --- a/api/src/queries/public/search-queries.ts +++ b/api/src/queries/public/search-queries.ts @@ -12,8 +12,6 @@ export const getPublicSpatialSearchResultsSQL = (): SQLStatement | null => { p.name, public.ST_asGeoJSON(p.geography) as geometry from - project as p - where - p.publish_timestamp is not null; + project as p; `; }; diff --git a/api/src/services/project-service.ts b/api/src/services/project-service.ts index 0e42c6bf9a..afb65ed9ae 100644 --- a/api/src/services/project-service.ts +++ b/api/src/services/project-service.ts @@ -1,7 +1,7 @@ import moment from 'moment'; import { PROJECT_ROLE, SYSTEM_ROLE } from '../constants/roles'; import { COMPLETION_STATUS } from '../constants/status'; -import { HTTP400, HTTP409, HTTP500 } from '../errors/custom-error'; +import { HTTP400, HTTP409 } from '../errors/custom-error'; import { IPostExistingPermit, IPostIUCN, @@ -1014,23 +1014,6 @@ export class ProjectService extends DBService { } } - async updatePublishStatus(projectId: number, publish: boolean): Promise { - const sqlStatement = queries.project.updateProjectPublishStatusSQL(projectId, publish); - - if (!sqlStatement) { - throw new HTTP400('Failed to build SQL statement'); - } - - const response = await this.connection.query(sqlStatement.text, sqlStatement.values); - const result = (response && response.rows && response.rows[0]) || null; - - if (!response || !result) { - throw new HTTP500('Failed to update project publish status'); - } - - return result.id; - } - async deleteProject(projectId: number, userRoles: string | string[]): Promise { /** * PART 1 diff --git a/api/src/services/survey-service.ts b/api/src/services/survey-service.ts index aaf0d930cb..88e5141bfc 100644 --- a/api/src/services/survey-service.ts +++ b/api/src/services/survey-service.ts @@ -587,24 +587,4 @@ export class SurveyService extends DBService { throw new ApiGeneralError('Failed to delete survey vantage codes'); } } - - /** - * Update a survey, marking it as published/unpublished. - * - * @param {number} surveyId - * @param {boolean} publish - * @return {*} {(Promise<{ id: number } | null>)} - * @memberof SurveyService - */ - async publishSurvey(surveyId: number, publish: boolean): Promise<{ id: number } | null> { - const sqlStatement = queries.survey.updateSurveyPublishStatusSQL(surveyId, publish); - - if (!sqlStatement) { - throw new ApiGeneralError('Failed to build survey publish SQL statement'); - } - - const response = await this.connection.sql<{ id: number }>(sqlStatement); - - return (response && response.rows && response.rows[0]) || null; - } } diff --git a/app/package-lock.json b/app/package-lock.json index 0da2e56ce1..95c4890d08 100644 --- a/app/package-lock.json +++ b/app/package-lock.json @@ -1765,15 +1765,27 @@ } }, "@material-ui/lab": { - "version": "4.0.0-alpha.60", - "resolved": "https://registry.npmjs.org/@material-ui/lab/-/lab-4.0.0-alpha.60.tgz", - "integrity": "sha512-fadlYsPJF+0fx2lRuyqAuJj7hAS1tLDdIEEdov5jlrpb5pp4b+mRDUqQTUxi4inRZHS1bEXpU8QWUhO6xX88aA==", + "version": "4.0.0-alpha.61", + "resolved": "https://registry.npmjs.org/@material-ui/lab/-/lab-4.0.0-alpha.61.tgz", + "integrity": "sha512-rSzm+XKiNUjKegj8bzt5+pygZeckNLOr+IjykH8sYdVk7dE9y2ZuUSofiMV2bJk3qU+JHwexmw+q0RyNZB9ugg==", "requires": { "@babel/runtime": "^7.4.4", - "@material-ui/utils": "^4.11.2", + "@material-ui/utils": "^4.11.3", "clsx": "^1.0.4", "prop-types": "^15.7.2", "react-is": "^16.8.0 || ^17.0.0" + }, + "dependencies": { + "@material-ui/utils": { + "version": "4.11.3", + "resolved": "https://registry.npmjs.org/@material-ui/utils/-/utils-4.11.3.tgz", + "integrity": "sha512-ZuQPV4rBK/V1j2dIkSSEcH5uT6AaHuKWFfotADHsC0wVL1NLd2WkFCm4ZZbX33iO4ydl6V0GPngKm8HZQ2oujg==", + "requires": { + "@babel/runtime": "^7.4.4", + "prop-types": "^15.7.2", + "react-is": "^16.8.0 || ^17.0.0" + } + } } }, "@material-ui/pickers": { diff --git a/app/src/constants/i18n.ts b/app/src/constants/i18n.ts index 0f510e8e8d..51dc35f38f 100644 --- a/app/src/constants/i18n.ts +++ b/app/src/constants/i18n.ts @@ -177,14 +177,6 @@ export const DeleteProjectI18N = { 'An error has occurred while attempting to delete this project, its attachments and associated surveys/observations, please try again. If the error persists, please contact your system administrator.' }; -export const PublishProjectI18N = { - publishTitle: 'Publish Project', - publishText: 'Are you sure you want to publish this project?', - publishErrorTitle: 'Error Publishing Project', - publishErrorText: - 'An error has occurred while attempting to publish this project, please try again. If the error persists, please contact your system administrator.' -}; - export const DeleteSurveyI18N = { deleteTitle: 'Delete Survey', deleteText: 'Are you sure you want to delete this survey, its attachments and associated observations?', @@ -193,14 +185,6 @@ export const DeleteSurveyI18N = { 'An error has occurred while attempting to delete this project, its attachments and associated surveys/observations, please try again. If the error persists, please contact your system administrator.' }; -export const PublishSurveyI18N = { - publishTitle: 'Publish Survey', - publishText: 'Are you sure you want to publish this survey?', - publishErrorTitle: 'Error Publishing Survey', - publishErrorText: - 'An error has occurred while attempting to publish this survey, please try again. If the error persists, please contact your system administrator.' -}; - export const EditReportMetaDataI18N = { editTitle: 'Edit Report Meta Data', editErrorTitle: 'Error Editing Report Meta Data', diff --git a/app/src/features/projects/view/ProjectHeader.tsx b/app/src/features/projects/view/ProjectHeader.tsx index 21ac758850..8248f2184e 100644 --- a/app/src/features/projects/view/ProjectHeader.tsx +++ b/app/src/features/projects/view/ProjectHeader.tsx @@ -15,7 +15,7 @@ import Icon from '@mdi/react'; import clsx from 'clsx'; import { IErrorDialogProps } from 'components/dialog/ErrorDialog'; import { DATE_FORMAT } from 'constants/dateTimeFormats'; -import { DeleteProjectI18N, PublishProjectI18N } from 'constants/i18n'; +import { DeleteProjectI18N } from 'constants/i18n'; import { ProjectStatusType } from 'constants/misc'; import { SYSTEM_ROLE } from 'constants/roles'; import { AuthStateContext } from 'contexts/authStateContext'; @@ -74,7 +74,7 @@ const useStyles = makeStyles((theme: Theme) => ({ export interface IProjectHeaderProps { projectWithDetails: IGetProjectForViewResponse; - refresh: () => void; + refresh?: () => void; } /** @@ -84,7 +84,7 @@ export interface IProjectHeaderProps { * @return {*} */ const ProjectHeader: React.FC = (props) => { - const { projectWithDetails, refresh } = props; + const { projectWithDetails } = props; const classes = useStyles(); const history = useHistory(); @@ -116,27 +116,6 @@ const ProjectHeader: React.FC = (props) => { } }; - const publishProject = async (publish: boolean) => { - if (!projectWithDetails) { - return; - } - - try { - const response = await biohubApi.project.publishProject(projectWithDetails.id, publish); - - if (!response) { - showPublishErrorDialog({ open: true }); - return; - } - - await refresh(); - } catch (error) { - const apiError = error as APIError; - showPublishErrorDialog({ dialogText: apiError.message, open: true }); - return error; - } - }; - const showDeleteProjectDialog = () => { dialogContext.setYesNoDialog({ ...defaultYesNoDialogProps, @@ -169,20 +148,10 @@ const ProjectHeader: React.FC = (props) => { } }; - const publishErrorDialogProps = { - ...deleteErrorDialogProps, - dialogTitle: PublishProjectI18N.publishErrorTitle, - dialogText: PublishProjectI18N.publishErrorText - }; - const showDeleteErrorDialog = (textDialogProps?: Partial) => { dialogContext.setErrorDialog({ ...deleteErrorDialogProps, ...textDialogProps, open: true }); }; - const showPublishErrorDialog = (textDialogProps?: Partial) => { - dialogContext.setErrorDialog({ ...publishErrorDialogProps, ...textDialogProps, open: true }); - }; - const getChipIcon = (status_name: string) => { let chipLabel; let chipStatusClass; @@ -266,17 +235,6 @@ const ProjectHeader: React.FC = (props) => { onClick={() => history.push('users')}> Manage Project Team - {showDeleteProjectButton && ( ({ @@ -77,7 +76,7 @@ const useStyles = makeStyles((theme: Theme) => ({ export interface ISurveyHeaderProps { projectWithDetails: IGetProjectForViewResponse; surveyWithDetails: IGetSurveyForViewResponse; - refresh: () => void; + refresh?: () => void; } /** @@ -87,11 +86,10 @@ export interface ISurveyHeaderProps { * @return {*} */ const SurveyHeader: React.FC = (props) => { - const { projectWithDetails, surveyWithDetails, refresh } = props; + const { projectWithDetails, surveyWithDetails } = props; const classes = useStyles(); const history = useHistory(); - const urlParams = useParams(); const biohubApi = useBiohubApi(); @@ -120,33 +118,6 @@ const SurveyHeader: React.FC = (props) => { } }; - const togglePublishSurvey = async () => { - if (!projectWithDetails || !surveyWithDetails) { - return; - } - - let publish = true; - - if (surveyWithDetails.surveyData.survey_details.publish_date) { - publish = false; - } - - try { - const response = await biohubApi.survey.publishSurvey(urlParams['id'], urlParams['survey_id'], publish); - - if (!response) { - showPublishErrorDialog({ open: true }); - return; - } - - await refresh(); - } catch (error) { - const apiError = error as APIError; - showPublishErrorDialog({ dialogText: apiError.message, open: true }); - return error; - } - }; - const showDeleteSurveyDialog = () => { dialogContext.setYesNoDialog({ ...defaultYesNoDialogProps, @@ -182,20 +153,10 @@ const SurveyHeader: React.FC = (props) => { } }; - const publishErrorDialogProps = { - ...deleteErrorDialogProps, - dialogTitle: PublishSurveyI18N.publishErrorTitle, - dialogText: PublishSurveyI18N.publishErrorText - }; - const showDeleteErrorDialog = (textDialogProps?: Partial) => { dialogContext.setErrorDialog({ ...deleteErrorDialogProps, ...textDialogProps, open: true }); }; - const showPublishErrorDialog = (textDialogProps?: Partial) => { - dialogContext.setErrorDialog({ ...publishErrorDialogProps, ...textDialogProps, open: true }); - }; - const getSurveyCompletionStatusType = (surveyObject: SurveyViewObject): SurveyStatusType => { if ( surveyObject.survey_details.end_date && @@ -279,14 +240,6 @@ const SurveyHeader: React.FC = (props) => { - {showDeleteSurveyButton && ( { return data; }; - /** - * Publish/unpublish a project. - * - * @param {number} projectId the project id - * @param {boolean} publish set to `true` to publish the project, `false` to unpublish the project. - * @return {*} {Promise} - */ - const publishProject = async (projectId: number, publish: boolean): Promise => { - const { data } = await axios.put(`/api/project/${projectId}/publish`, { publish: publish }); - return data; - }; - /** * Get project report metadata based on project ID, attachment ID, and attachmentType * @@ -461,7 +449,6 @@ const useProjectApi = (axios: AxiosInstance) => { deleteFundingSource, addFundingSource, deleteProject, - publishProject, makeAttachmentSecure, makeAttachmentUnsecure, getProjectReportMetadata, diff --git a/app/src/hooks/api/useSurveyApi.ts b/app/src/hooks/api/useSurveyApi.ts index 053636ae24..939b3c0de3 100644 --- a/app/src/hooks/api/useSurveyApi.ts +++ b/app/src/hooks/api/useSurveyApi.ts @@ -399,20 +399,6 @@ const useSurveyApi = (axios: AxiosInstance) => { return data; }; - /** - * Publish/unpublish a survey. - * - * @param {number} projectId - * @param {number} surveyId - * @param {boolean} publish set to `true` to publish the survey, `false` to unpublish the survey. - * @return {*} {Promise} `true` if the request was successful, false otherwise. - */ - const publishSurvey = async (projectId: number, surveyId: number, publish: boolean): Promise => { - const { status } = await axios.put(`/api/project/${projectId}/survey/${surveyId}/publish`, { publish: publish }); - - return status === 200; - }; - /** * Upload survey summary results. * @@ -525,7 +511,6 @@ const useSurveyApi = (axios: AxiosInstance) => { deleteSurvey, getSurveyPermits, getAvailableSurveyFundingSources, - publishSurvey, getSubmissionCSVForView, makeAttachmentUnsecure, makeAttachmentSecure, From 9e5bb8964a564cb6357a3870df4e17c7918cd585 Mon Sep 17 00:00:00 2001 From: Curtis Upshall Date: Tue, 12 Jul 2022 12:37:38 -0700 Subject: [PATCH 2/9] BHBC-1841: Remove publish logic - second pass --- api/src/constants/status.ts | 1 - api/src/models/project-view.ts | 2 - api/src/models/survey-view.ts | 2 - .../paths/project/{projectId}/delete.test.ts | 36 ---- .../survey/{surveyId}/view.test.ts | 2 - .../{projectId}/survey/{surveyId}/view.ts | 6 - api/src/paths/project/{projectId}/surveys.ts | 6 - .../paths/project/{projectId}/update.test.ts | 1 - api/src/paths/project/{projectId}/update.ts | 6 - api/src/paths/project/{projectId}/view.ts | 8 +- .../paths/public/project/{projectId}/view.ts | 8 +- api/src/queries/dwc/dwc-queries.ts | 2 - .../project/project-update-queries.test.ts | 28 +-- .../queries/project/project-update-queries.ts | 28 --- .../queries/project/project-view-queries.ts | 5 +- api/src/queries/public/project-queries.ts | 3 +- api/src/queries/search/search-queries.ts | 3 + .../survey/survey-update-queries.test.ts | 29 +-- .../queries/survey/survey-update-queries.ts | 43 ----- api/src/queries/survey/survey-view-queries.ts | 1 - api/src/services/eml-service.ts | 1 - api/src/services/project-service.test.ts | 4 - api/src/services/project-service.ts | 11 +- app/src/components/surveys/SurveysList.tsx | 21 +- app/src/constants/misc.ts | 4 - .../projects/list/ProjectsListPage.test.tsx | 9 +- .../projects/list/ProjectsListPage.tsx | 18 +- .../features/projects/view/ProjectHeader.tsx | 7 +- .../projects/view/ProjectPage.test.tsx | 181 +----------------- .../surveys/view/SurveyHeader.test.tsx | 77 -------- .../features/surveys/view/SurveyHeader.tsx | 6 +- .../SurveyGeneralInformation.test.tsx | 2 - .../view/components/SurveyStudyArea.test.tsx | 2 - app/src/hooks/api/useSurveyApi.test.ts | 9 - app/src/interfaces/useProjectApi.interface.ts | 2 - app/src/interfaces/useSurveyApi.interface.ts | 2 - app/src/test-helpers/project-helpers.ts | 3 +- app/src/test-helpers/survey-helpers.ts | 1 - .../src/migrations/release.0.34/biohub.sql | 4 +- .../smoke_1_CreateProjectMinimal.spec.ts | 3 - .../project/project-create-page.ts | 12 -- 41 files changed, 27 insertions(+), 572 deletions(-) diff --git a/api/src/constants/status.ts b/api/src/constants/status.ts index 49cfc4d3a8..249055dae8 100644 --- a/api/src/constants/status.ts +++ b/api/src/constants/status.ts @@ -25,7 +25,6 @@ export enum SUBMISSION_STATUS_TYPE { 'SUBMISSION_DATA_INGESTED' = 'Submission Data Ingested', 'SECURED' = 'Secured', 'AWAITING CURRATION' = 'Awaiting Curration', - 'PUBLISHED' = 'Published', 'REJECTED' = 'Rejected', 'ON HOLD' = 'On Hold', 'SYSTEM_ERROR' = 'System Error' diff --git a/api/src/models/project-view.ts b/api/src/models/project-view.ts index a577f15c42..64fac7ebdb 100644 --- a/api/src/models/project-view.ts +++ b/api/src/models/project-view.ts @@ -29,7 +29,6 @@ export class GetProjectData { end_date: string; comments: string; completion_status: string; - publish_date: string; revision_count: number; constructor(projectData?: any, activityData?: any[]) { @@ -46,7 +45,6 @@ export class GetProjectData { moment(projectData.end_date).endOf('day').isBefore(moment()) && COMPLETION_STATUS.COMPLETED) || COMPLETION_STATUS.ACTIVE; - this.publish_date = String(projectData?.publish_date || ''); this.revision_count = projectData?.revision_count ?? null; } } diff --git a/api/src/models/survey-view.ts b/api/src/models/survey-view.ts index ea863ffacd..0e37aa72f7 100644 --- a/api/src/models/survey-view.ts +++ b/api/src/models/survey-view.ts @@ -18,7 +18,6 @@ export class GetSurveyData { end_date: string; biologist_first_name: string; biologist_last_name: string; - publish_date: string; survey_area_name: string; geometry: Feature[]; revision_count: number; @@ -29,7 +28,6 @@ export class GetSurveyData { this.survey_name = obj?.name || ''; this.start_date = obj?.start_date || null; this.end_date = obj?.end_date || null; - this.publish_date = String(obj?.publish_date || ''); this.geometry = (obj?.geojson?.length && obj.geojson) || []; this.biologist_first_name = obj?.lead_first_name || ''; this.biologist_last_name = obj?.lead_last_name || ''; diff --git a/api/src/paths/project/{projectId}/delete.test.ts b/api/src/paths/project/{projectId}/delete.test.ts index 69e3571468..15bbaecacd 100644 --- a/api/src/paths/project/{projectId}/delete.test.ts +++ b/api/src/paths/project/{projectId}/delete.test.ts @@ -140,42 +140,6 @@ describe('deleteProject', () => { } }); - it('should throw a 400 error when user has insufficient role to delete published project', async () => { - sinon.stub(db, 'getDBConnection').returns({ - ...dbConnectionObj, - systemUserId: () => { - return 20; - }, - query: async () => { - return { - rowCount: 1, - rows: [ - { - id: 1, - publish_date: 'some date' - } - ] - } as QueryResult; - } - }); - - try { - const result = delete_project.deleteProject(); - - await result( - { ...sampleReq, system_user: { role_names: [SYSTEM_ROLE.PROJECT_CREATOR] } }, - (null as unknown) as any, - (null as unknown) as any - ); - expect.fail(); - } catch (actualError) { - expect((actualError as HTTPError).status).to.equal(400); - expect((actualError as HTTPError).message).to.equal( - 'Cannot delete a published project if you are not a system administrator.' - ); - } - }); - it('should throw a 400 error when failed to get result for project attachments', async () => { const mockQuery = sinon.stub(); diff --git a/api/src/paths/project/{projectId}/survey/{surveyId}/view.test.ts b/api/src/paths/project/{projectId}/survey/{surveyId}/view.test.ts index d678d3bd8f..f289c785ce 100644 --- a/api/src/paths/project/{projectId}/survey/{surveyId}/view.test.ts +++ b/api/src/paths/project/{projectId}/survey/{surveyId}/view.test.ts @@ -26,7 +26,6 @@ describe('survey/{surveyId}/view', () => { end_date: '2020-05-05', biologist_first_name: 'first', biologist_last_name: 'last', - publish_date: '', revision_count: 1 }, species: { @@ -97,7 +96,6 @@ describe('survey/{surveyId}/view', () => { end_date: '2020-05-05', biologist_first_name: 'first', biologist_last_name: 'last', - publish_date: null, revision_count: 1 }, species: { diff --git a/api/src/paths/project/{projectId}/survey/{surveyId}/view.ts b/api/src/paths/project/{projectId}/survey/{surveyId}/view.ts index e2002768eb..4d5f996d1f 100644 --- a/api/src/paths/project/{projectId}/survey/{surveyId}/view.ts +++ b/api/src/paths/project/{projectId}/survey/{surveyId}/view.ts @@ -82,7 +82,6 @@ GET.apiDoc = { 'start_date', 'biologist_first_name', 'biologist_last_name', - 'publish_date', 'revision_count' ], properties: { @@ -104,11 +103,6 @@ GET.apiDoc = { biologist_last_name: { type: 'string' }, - publish_date: { - oneOf: [{ type: 'object' }, { type: 'string', format: 'date' }], - nullable: true, - description: 'Determines if the record has been published' - }, revision_count: { type: 'number' } diff --git a/api/src/paths/project/{projectId}/surveys.ts b/api/src/paths/project/{projectId}/surveys.ts index 45ac18b757..4236e7faec 100644 --- a/api/src/paths/project/{projectId}/surveys.ts +++ b/api/src/paths/project/{projectId}/surveys.ts @@ -64,7 +64,6 @@ GET.apiDoc = { 'biologist_last_name', 'start_date', 'geometry', - 'publish_date', 'survey_area_name', 'survey_name', 'revision_count' @@ -95,11 +94,6 @@ GET.apiDoc = { ...(geoJsonFeature as object) } }, - publish_date: { - oneOf: [{ type: 'object' }, { type: 'string', format: 'date' }], - nullable: true, - description: 'Determines if the record has been published' - }, survey_area_name: { type: 'string' }, diff --git a/api/src/paths/project/{projectId}/update.test.ts b/api/src/paths/project/{projectId}/update.test.ts index 98767455ca..e5a57267cc 100644 --- a/api/src/paths/project/{projectId}/update.test.ts +++ b/api/src/paths/project/{projectId}/update.test.ts @@ -145,7 +145,6 @@ describe('update', () => { start_date: '2022-02-02', end_date: '2022-02-30', objectives: 'my objectives', - publish_date: '2022-02-02', revision_count: 0 }, iucn: {}, diff --git a/api/src/paths/project/{projectId}/update.ts b/api/src/paths/project/{projectId}/update.ts index fc6ae3ba0d..0664f872bd 100644 --- a/api/src/paths/project/{projectId}/update.ts +++ b/api/src/paths/project/{projectId}/update.ts @@ -86,7 +86,6 @@ GET.apiDoc = { 'project_activities', 'start_date', 'end_date', - 'publish_date', 'revision_count' ], nullable: true, @@ -113,11 +112,6 @@ GET.apiDoc = { format: 'date', description: 'ISO 8601 date string for the project end date' }, - publish_date: { - description: 'Status of the project being published/unpublished', - format: 'date', - type: 'string' - }, revision_count: { type: 'number' } diff --git a/api/src/paths/project/{projectId}/view.ts b/api/src/paths/project/{projectId}/view.ts index 54ae6159fe..fad2d3906b 100644 --- a/api/src/paths/project/{projectId}/view.ts +++ b/api/src/paths/project/{projectId}/view.ts @@ -76,8 +76,7 @@ GET.apiDoc = { 'start_date', 'end_date', 'comments', - 'completion_status', - 'publish_date' + 'completion_status' ], properties: { project_name: { @@ -109,11 +108,6 @@ GET.apiDoc = { completion_status: { description: 'Status of the project being active/completed', type: 'string' - }, - publish_date: { - description: 'Status of the project being published/unpublished', - format: 'date', - type: 'string' } } }, diff --git a/api/src/paths/public/project/{projectId}/view.ts b/api/src/paths/public/project/{projectId}/view.ts index 7485a53408..b332e1923a 100644 --- a/api/src/paths/public/project/{projectId}/view.ts +++ b/api/src/paths/public/project/{projectId}/view.ts @@ -56,8 +56,7 @@ GET.apiDoc = { 'start_date', 'end_date', 'comments', - 'completion_status', - 'publish_date' + 'completion_status' ], properties: { project_name: { @@ -89,11 +88,6 @@ GET.apiDoc = { completion_status: { description: 'Status of the project being active/completed', type: 'string' - }, - publish_date: { - description: 'Status of the project being published/unpublished', - format: 'date', - type: 'string' } } }, diff --git a/api/src/queries/dwc/dwc-queries.ts b/api/src/queries/dwc/dwc-queries.ts index 7c9f7d24f3..36bd7b95f0 100644 --- a/api/src/queries/dwc/dwc-queries.ts +++ b/api/src/queries/dwc/dwc-queries.ts @@ -81,7 +81,6 @@ export const getSurveySQL = (surveyId: number): SQLStatement => { end_date, location_description, location_name, - publish_timestamp, create_date, create_user, update_date, @@ -119,7 +118,6 @@ export const getProjectSQL = (projectId: number): SQLStatement => { coordinator_email_address, coordinator_agency_name, coordinator_public, - publish_timestamp, create_date, create_user, update_date, diff --git a/api/src/queries/project/project-update-queries.test.ts b/api/src/queries/project/project-update-queries.test.ts index f7cf2df7df..31e89cc9c3 100644 --- a/api/src/queries/project/project-update-queries.test.ts +++ b/api/src/queries/project/project-update-queries.test.ts @@ -15,8 +15,7 @@ import { getPermitsByProjectSQL, getProjectByProjectSQL, putProjectFundingSourceSQL, - putProjectSQL, - updateProjectPublishStatusSQL + putProjectSQL } from './project-update-queries'; describe('getIndigenousPartnershipsByProjectSQL', () => { @@ -273,28 +272,3 @@ describe('putProjectFundingSourceSQL', () => { }); }); -describe('updateProjectPublishStatusSQL', () => { - describe('with invalid parameters', () => { - it('returns null when project is null', () => { - const response = updateProjectPublishStatusSQL((null as unknown) as number, true); - - expect(response).to.be.null; - }); - }); - - describe('with valid parameters', () => { - it('returns a SQLStatement when there is a real date value', () => { - const response = updateProjectPublishStatusSQL(1, true); - - expect(response).to.not.be.null; - expect(response?.values).to.deep.include(1); - }); - - it('returns a SQLStatement when the date value is null', () => { - const response = updateProjectPublishStatusSQL(1, false); - - expect(response).to.not.be.null; - expect(response?.values).to.deep.include(1); - }); - }); -}); diff --git a/api/src/queries/project/project-update-queries.ts b/api/src/queries/project/project-update-queries.ts index 913a219027..070a2eeb8b 100644 --- a/api/src/queries/project/project-update-queries.ts +++ b/api/src/queries/project/project-update-queries.ts @@ -289,31 +289,3 @@ export const putProjectFundingSourceSQL = ( project_funding_source_id as id; `; }; - -/** - * SQL query to update the publish status of a project. - * - * @param {number} projectId - * @param {boolean} publish - * @returns {SQLStatement} sql query object - */ -export const updateProjectPublishStatusSQL = (projectId: number, publish: boolean): SQLStatement | null => { - if (!projectId) { - return null; - } - - const sqlStatement: SQLStatement = SQL`UPDATE project SET publish_timestamp = `; - - if (publish === true) { - sqlStatement.append(SQL` - now() WHERE publish_timestamp IS NULL AND project_id = ${projectId} - `); - } else { - sqlStatement.append(SQL` - null WHERE project_id = ${projectId} - `); - } - sqlStatement.append(SQL` RETURNING project_id as id;`); - - return sqlStatement; -}; diff --git a/api/src/queries/project/project-view-queries.ts b/api/src/queries/project/project-view-queries.ts index 616bb26eef..761921ff34 100644 --- a/api/src/queries/project/project-view-queries.ts +++ b/api/src/queries/project/project-view-queries.ts @@ -34,8 +34,7 @@ export const getProjectSQL = (projectId: number): SQLStatement | null => { project.create_user, project.update_date, project.update_user, - project.revision_count, - project.publish_timestamp as publish_date + project.revision_count from project left outer join @@ -70,7 +69,6 @@ export const getProjectListSQL = ( p.start_date, p.end_date, p.coordinator_agency_name as coordinator_agency, - p.publish_timestamp, pt.name as project_type, string_agg(DISTINCT pp.number, ', ') as permits_list from @@ -164,7 +162,6 @@ export const getProjectListSQL = ( p.start_date, p.end_date, p.coordinator_agency_name, - p.publish_timestamp, pt.name; `); diff --git a/api/src/queries/public/project-queries.ts b/api/src/queries/public/project-queries.ts index c030c648bb..5118ddbaf3 100644 --- a/api/src/queries/public/project-queries.ts +++ b/api/src/queries/public/project-queries.ts @@ -22,8 +22,7 @@ export const getPublicProjectSQL = (projectId: number): SQLStatement | null => { project.end_date, project.caveats, project.comments, - project.geojson as geometry, - project.publish_timestamp as publish_date + project.geojson as geometry from project left outer join diff --git a/api/src/queries/search/search-queries.ts b/api/src/queries/search/search-queries.ts index 81e438b1f1..ac2fccb3e9 100644 --- a/api/src/queries/search/search-queries.ts +++ b/api/src/queries/search/search-queries.ts @@ -12,6 +12,9 @@ export const getSpatialSearchResultsSQL = (isUserAdmin: boolean, systemUserId: n return null; } + /** + * @TODO Remove WHERE clause? + */ const sqlStatement = SQL` SELECT p.project_id as id, diff --git a/api/src/queries/survey/survey-update-queries.test.ts b/api/src/queries/survey/survey-update-queries.test.ts index db770d9913..30d2b6fdb8 100644 --- a/api/src/queries/survey/survey-update-queries.test.ts +++ b/api/src/queries/survey/survey-update-queries.test.ts @@ -14,8 +14,7 @@ import { associateSurveyToPermitSQL, insertSurveyPermitSQL, putSurveyDetailsSQL, - unassociatePermitFromSurveySQL, - updateSurveyPublishStatusSQL + unassociatePermitFromSurveySQL } from './survey-update-queries'; describe('putSurveyDetailsSQL', () => { @@ -84,29 +83,3 @@ describe('associateSurveyToPermitSQL', () => { expect(response).not.to.be.null; }); }); - -describe('updateSurveyPublishStatusSQL', () => { - describe('with invalid parameters', () => { - it('returns null when survey is null', () => { - const response = updateSurveyPublishStatusSQL((null as unknown) as number, true); - - expect(response).to.be.null; - }); - }); - - describe('with valid parameters', () => { - it('returns a SQLStatement when there is a real date value', () => { - const response = updateSurveyPublishStatusSQL(1, true); - - expect(response).to.not.be.null; - expect(response?.values).to.deep.include(1); - }); - - it('returns a SQLStatement when the date value is null', () => { - const response = updateSurveyPublishStatusSQL(1, false); - - expect(response).to.not.be.null; - expect(response?.values).to.deep.include(1); - }); - }); -}); diff --git a/api/src/queries/survey/survey-update-queries.ts b/api/src/queries/survey/survey-update-queries.ts index 2447200939..5c4e8fee25 100644 --- a/api/src/queries/survey/survey-update-queries.ts +++ b/api/src/queries/survey/survey-update-queries.ts @@ -157,46 +157,3 @@ export const putSurveyDetailsSQL = (surveyId: number, data: PutSurveyObject): Kn return knex('survey').update(fieldsToUpdate).where('survey_id', surveyId); }; -/** - * SQL query to update the publish status of a survey. - * - * @param {number} surveyId - * @param {boolean} publish - * @returns {SQLStatement} sql query object - */ -export const updateSurveyPublishStatusSQL = (surveyId: number, publish: boolean): SQLStatement | null => { - if (!surveyId) { - return null; - } - - const sqlStatement: SQLStatement = SQL` - UPDATE - survey - SET - publish_timestamp = `; - - if (publish) { - sqlStatement.append(SQL` - now() - WHERE - survey_id = ${surveyId} - AND - publish_timestamp IS NULL - `); - } else { - sqlStatement.append(SQL` - null - WHERE - survey_id = ${surveyId} - AND - publish_timestamp IS NOT NULL - `); - } - - sqlStatement.append(SQL` - RETURNING - survey_id as id; - `); - - return sqlStatement; -}; diff --git a/api/src/queries/survey/survey-view-queries.ts b/api/src/queries/survey/survey-view-queries.ts index edc3d0bef7..7b5cbef0ef 100644 --- a/api/src/queries/survey/survey-view-queries.ts +++ b/api/src/queries/survey/survey-view-queries.ts @@ -65,7 +65,6 @@ export const getSurveyBasicDataForViewSQL = (surveyId: number): SQLStatement | n s.location_name, s.geojson as geometry, s.revision_count, - s.publish_timestamp as publish_date, per.number, per.type, max(os.occurrence_submission_id) as occurrence_submission_id, diff --git a/api/src/services/eml-service.ts b/api/src/services/eml-service.ts index 23f8ed77ca..9e622fe9d1 100644 --- a/api/src/services/eml-service.ts +++ b/api/src/services/eml-service.ts @@ -251,7 +251,6 @@ export class EmlService extends DBService { $: { system: this.constants.EML_PROVIDER_URL, id: this.packageId }, title: options?.datasetTitle || this.projectData.project.project_name, creator: this.getDatasetCreator(), - ...(this.projectData.project.publish_date && { pubDate: this.projectData.project.publish_date }), metadataProvider: { organizationName: this.constants.EML_ORGANIZATION_NAME, onlineUrl: this.constants.EML_ORGANIZATION_URL diff --git a/api/src/services/project-service.test.ts b/api/src/services/project-service.test.ts index db5f7b8a6f..fa4a3000d3 100644 --- a/api/src/services/project-service.test.ts +++ b/api/src/services/project-service.test.ts @@ -412,7 +412,6 @@ describe('ProjectService', () => { start_date: '1900-01-01', end_date: '2200-10-10', coordinator_agency: 'Agency 1', - publish_timestamp: '2010-01-01', permits_list: '3, 100', project_type: 'Aquatic Habitat' }, @@ -422,7 +421,6 @@ describe('ProjectService', () => { start_date: '1900-01-01', end_date: '2000-12-31', coordinator_agency: 'Agency 2', - publish_timestamp: '', permits_list: '1, 4', project_type: 'Terrestrial Habitat' } @@ -439,12 +437,10 @@ describe('ProjectService', () => { expect(result[0].id).to.equal(123); expect(result[0].name).to.equal('Project 1'); expect(result[0].completion_status).to.equal('Active'); - expect(result[0].publish_status).to.equal('Published'); expect(result[1].id).to.equal(456); expect(result[1].name).to.equal('Project 2'); expect(result[1].completion_status).to.equal('Completed'); - expect(result[1].publish_status).to.equal('Unpublished'); }); }); diff --git a/api/src/services/project-service.ts b/api/src/services/project-service.ts index afb65ed9ae..6c4df8431d 100644 --- a/api/src/services/project-service.ts +++ b/api/src/services/project-service.ts @@ -1,5 +1,5 @@ import moment from 'moment'; -import { PROJECT_ROLE, SYSTEM_ROLE } from '../constants/roles'; +import { PROJECT_ROLE } from '../constants/roles'; import { COMPLETION_STATUS } from '../constants/status'; import { HTTP400, HTTP409 } from '../errors/custom-error'; import { @@ -34,7 +34,6 @@ import { import { getSurveyAttachmentS3Keys } from '../paths/project/{projectId}/survey/{surveyId}/delete'; import { GET_ENTITIES, IUpdateProject } from '../paths/project/{projectId}/update'; import { queries } from '../queries/queries'; -import { userHasValidRole } from '../request-handlers/security/authorization'; import { deleteFileFromS3 } from '../utils/file-utils'; import { DBService } from './service'; @@ -223,7 +222,6 @@ export class ProjectService extends DBService { start_date: row.start_date, end_date: row.end_date, coordinator_agency: row.coordinator_agency_name, - publish_status: row.publish_timestamp ? 'Published' : 'Unpublished', completion_status: (row.end_date && moment(row.end_date).endOf('day').isBefore(moment()) && COMPLETION_STATUS.COMPLETED) || COMPLETION_STATUS.ACTIVE, @@ -1017,8 +1015,7 @@ export class ProjectService extends DBService { async deleteProject(projectId: number, userRoles: string | string[]): Promise { /** * PART 1 - * Check that user is a system administrator - can delete a project (published or not) - * Check that user is a project administrator - can delete a project (unpublished only) + * Check that user is a system administrator - can delete a project * */ const getProjectSQLStatement = queries.project.getProjectSQL(projectId); @@ -1035,10 +1032,6 @@ export class ProjectService extends DBService { throw new HTTP400('Failed to get the project'); } - if (projectResult.publish_date && userHasValidRole([SYSTEM_ROLE.PROJECT_CREATOR], userRoles)) { - throw new HTTP400('Cannot delete a published project if you are not a system administrator.'); - } - /** * PART 2 * Get the attachment S3 keys for all attachments associated to this project and surveys under this project diff --git a/app/src/components/surveys/SurveysList.tsx b/app/src/components/surveys/SurveysList.tsx index bad1fb0e89..3025e4bad3 100644 --- a/app/src/components/surveys/SurveysList.tsx +++ b/app/src/components/surveys/SurveysList.tsx @@ -23,9 +23,6 @@ const useStyles = makeStyles((theme: Theme) => ({ chip: { color: '#ffffff' }, - chipUnpublished: { - backgroundColor: theme.palette.text.disabled - }, chipActive: { backgroundColor: theme.palette.success.main }, @@ -57,25 +54,11 @@ const SurveysList: React.FC = (props) => { return SurveyStatusType.ACTIVE; }; - const getSurveyPublishStatusType = (surveyObject: SurveyViewObject): SurveyStatusType => { - if (surveyObject.survey_details.publish_date) { - return SurveyStatusType.PUBLISHED; - } - - return SurveyStatusType.UNPUBLISHED; - }; - const getChipIcon = (status_name: string) => { let chipLabel; let chipStatusClass; - if (SurveyStatusType.UNPUBLISHED === status_name) { - chipLabel = 'Unpublished'; - chipStatusClass = classes.chipUnpublished; - } else if (SurveyStatusType.PUBLISHED === status_name) { - chipLabel = 'Published'; - chipStatusClass = classes.chipPublishedCompleted; - } else if (SurveyStatusType.ACTIVE === status_name) { + if (SurveyStatusType.ACTIVE === status_name) { chipLabel = 'Active'; chipStatusClass = classes.chipActive; } else if (SurveyStatusType.COMPLETED === status_name) { @@ -96,7 +79,6 @@ const SurveysList: React.FC = (props) => { Species Timeline Status - Published @@ -125,7 +107,6 @@ const SurveysList: React.FC = (props) => { )} {getChipIcon(getSurveyCompletionStatusType(row))} - {getChipIcon(getSurveyPublishStatusType(row))} ))} {!props.surveysList.length && ( diff --git a/app/src/constants/misc.ts b/app/src/constants/misc.ts index ea2ffe37ec..9d12a73180 100644 --- a/app/src/constants/misc.ts +++ b/app/src/constants/misc.ts @@ -9,16 +9,12 @@ export enum AdministrativeActivityStatusType { } export enum ProjectStatusType { - UNPUBLISHED = 'Unpublished', - PUBLISHED = 'Published', COMPLETED = 'Completed', ACTIVE = 'Active', DRAFT = 'Draft' } export enum SurveyStatusType { - UNPUBLISHED = 'Unpublished', - PUBLISHED = 'Published', COMPLETED = 'Completed', ACTIVE = 'Active' } diff --git a/app/src/features/projects/list/ProjectsListPage.test.tsx b/app/src/features/projects/list/ProjectsListPage.test.tsx index 138a81e494..85c7e3a619 100644 --- a/app/src/features/projects/list/ProjectsListPage.test.tsx +++ b/app/src/features/projects/list/ProjectsListPage.test.tsx @@ -89,7 +89,7 @@ describe('ProjectsListPage', () => { }); }); - test('renders with a proper list of projects when published and completed', async () => { + test('renders with a proper list of projects when completed', async () => { mockBiohubApi().project.getProjectsList.mockResolvedValue([ { id: 1, @@ -99,7 +99,6 @@ describe('ProjectsListPage', () => { coordinator_agency: 'contact agency', project_type: 'project type', permits_list: '1, 2, 3', - publish_status: 'Published', completion_status: 'Completed' } ]); @@ -112,12 +111,11 @@ describe('ProjectsListPage', () => { await waitFor(() => { expect(getByTestId('project-table')).toBeInTheDocument(); - expect(getByText('Published')).toBeInTheDocument(); expect(getByText('Completed')).toBeInTheDocument(); }); }); - test('renders with a proper list of projects when Unpublished and active', async () => { + test('renders with a proper list of projects when active', async () => { mockBiohubApi().project.getProjectsList.mockResolvedValue([ { id: 1, @@ -127,7 +125,6 @@ describe('ProjectsListPage', () => { coordinator_agency: 'contact agency', project_type: 'project type', permits_list: '1, 2, 3', - publish_status: 'Unpublished', completion_status: 'Active' } ]); @@ -140,7 +137,6 @@ describe('ProjectsListPage', () => { await waitFor(() => { expect(getByTestId('project-table')).toBeInTheDocument(); - expect(getByText('Unpublished')).toBeInTheDocument(); expect(getByText('Active')).toBeInTheDocument(); }); }); @@ -244,7 +240,6 @@ describe('ProjectsListPage', () => { coordinator_agency: 'contact agency', project_type: 'project type', permits_list: '1, 2, 3', - publish_status: 'Published', completion_status: 'Completed' } ]); diff --git a/app/src/features/projects/list/ProjectsListPage.tsx b/app/src/features/projects/list/ProjectsListPage.tsx index e18cac048b..f686554f34 100644 --- a/app/src/features/projects/list/ProjectsListPage.tsx +++ b/app/src/features/projects/list/ProjectsListPage.tsx @@ -55,12 +55,9 @@ const useStyles = makeStyles((theme: Theme) => ({ chipActive: { backgroundColor: theme.palette.success.main }, - chipPublishedCompleted: { + chipCompleted: { backgroundColor: theme.palette.success.main }, - chipUnpublished: { - backgroundColor: theme.palette.text.disabled - }, chipDraft: { backgroundColor: theme.palette.info.main } @@ -91,18 +88,12 @@ const ProjectsListPage: React.FC = () => { let chipLabel; let chipStatusClass; - if (ProjectStatusType.UNPUBLISHED === status_name) { - chipLabel = 'Unpublished'; - chipStatusClass = classes.chipUnpublished; - } else if (ProjectStatusType.PUBLISHED === status_name) { - chipLabel = 'Published'; - chipStatusClass = classes.chipPublishedCompleted; - } else if (ProjectStatusType.ACTIVE === status_name) { + if (ProjectStatusType.ACTIVE === status_name) { chipLabel = 'Active'; chipStatusClass = classes.chipActive; } else if (ProjectStatusType.COMPLETED === status_name) { chipLabel = 'Completed'; - chipStatusClass = classes.chipPublishedCompleted; + chipStatusClass = classes.chipCompleted; } else if (ProjectStatusType.DRAFT === status_name) { chipLabel = 'Draft'; chipStatusClass = classes.chipDraft; @@ -262,7 +253,6 @@ const ProjectsListPage: React.FC = () => { Start Date End Date Status - Publish Status @@ -285,7 +275,6 @@ const ProjectsListPage: React.FC = () => { {getChipIcon('Draft')} - {getChipIcon('Unpublished')} ))} {projects?.map((row) => ( @@ -306,7 +295,6 @@ const ProjectsListPage: React.FC = () => { {getFormattedDate(DATE_FORMAT.ShortMediumDateFormat, row.start_date)} {getFormattedDate(DATE_FORMAT.ShortMediumDateFormat, row.end_date)} {getChipIcon(row.completion_status)} - {getChipIcon(row.publish_status)} ))} diff --git a/app/src/features/projects/view/ProjectHeader.tsx b/app/src/features/projects/view/ProjectHeader.tsx index 8248f2184e..8764d572e3 100644 --- a/app/src/features/projects/view/ProjectHeader.tsx +++ b/app/src/features/projects/view/ProjectHeader.tsx @@ -172,10 +172,9 @@ const ProjectHeader: React.FC = (props) => { SYSTEM_ROLE.SYSTEM_ADMIN, SYSTEM_ROLE.PROJECT_CREATOR ]); - // Enable delete button if you a system admin OR a project admin and the project is not published + // Enable delete button if you a system admin OR a project admin const enableDeleteProjectButton = - keycloakWrapper?.hasSystemRole([SYSTEM_ROLE.SYSTEM_ADMIN]) || - (keycloakWrapper?.hasSystemRole([SYSTEM_ROLE.PROJECT_CREATOR]) && !projectWithDetails.project.publish_date); + keycloakWrapper?.hasSystemRole([SYSTEM_ROLE.SYSTEM_ADMIN, SYSTEM_ROLE.PROJECT_CREATOR]); return ( @@ -239,7 +238,7 @@ const ProjectHeader: React.FC = (props) => { + > <> { }); }); - it('sees delete project button as enabled when accessing an unpublished project as a project administrator', async () => { + it('sees delete project button as enabled when accessing a project as a project administrator', async () => { mockBiohubApi().codes.getAllCodeSets.mockResolvedValue({ activity: [{ id: 1, name: 'activity 1' }] } as any); mockBiohubApi().project.getProjectForView.mockResolvedValue({ ...getProjectForViewResponse, - project: { ...getProjectForViewResponse.project, publish_date: '' } + project: { ...getProjectForViewResponse.project } }); mockBiohubApi().project.deleteProject.mockResolvedValue(true); @@ -306,40 +306,6 @@ describe('ProjectPage', () => { expect(getByTestId('delete-project-button')).toBeEnabled(); }); - it('sees delete project button as disabled when accessing a published project as a project administrator', async () => { - mockBiohubApi().codes.getAllCodeSets.mockResolvedValue({ - activity: [{ id: 1, name: 'activity 1' }] - } as any); - mockBiohubApi().project.getProjectForView.mockResolvedValue({ - ...getProjectForViewResponse, - project: { ...getProjectForViewResponse.project, publish_date: '2021-07-07' } - }); - mockBiohubApi().project.deleteProject.mockResolvedValue(true); - - const authState = { - keycloakWrapper: { - ...defaultAuthState.keycloakWrapper, - systemRoles: [SYSTEM_ROLE.PROJECT_CREATOR] as string[], - hasSystemRole: jest.fn().mockReturnValueOnce(true).mockReturnValueOnce(false).mockReturnValueOnce(true) - } - }; - - const { getByTestId, findByText } = render( - - - - - - - - ); - - const projectHeaderText = await findByText('Test Project Name', { selector: 'h1 span' }); - expect(projectHeaderText).toBeVisible(); - - expect(getByTestId('delete-project-button')).toBeDisabled(); - }); - it('does not see the delete button when accessing project as non admin user', async () => { mockBiohubApi().codes.getAllCodeSets.mockResolvedValue({ activity: [{ id: 1, name: 'activity 1' }] @@ -395,147 +361,4 @@ describe('ProjectPage', () => { expect(asFragment()).toMatchSnapshot(); }); }); - - it('publishes and unpublishes a project', async () => { - mockBiohubApi().codes.getAllCodeSets.mockResolvedValue({ - activity: [{ id: 1, name: 'activity 1' }] - } as any); - mockBiohubApi().project.getProjectForView.mockResolvedValue({ - ...getProjectForViewResponse, - project: { ...getProjectForViewResponse.project, publish_date: '' } - }); - mockBiohubApi().project.publishProject.mockResolvedValue({ id: 1 }); - - const { getByTestId } = render( - - - - - - ); - - await waitFor(() => { - const publishButtonText1 = getByTestId('publish-project-button'); - expect(publishButtonText1).toBeVisible(); - expect(publishButtonText1.textContent).toEqual('Publish'); - }); - - //re-mock response to return the project with a non-null publish date - mockBiohubApi().project.getProjectForView.mockResolvedValue({ - ...getProjectForViewResponse, - project: { ...getProjectForViewResponse.project, publish_date: '2021-10-10' } - }); - - fireEvent.click(getByTestId('publish-project-button')); - - await waitFor(() => { - const publishButtonText1 = getByTestId('publish-project-button'); - expect(publishButtonText1).toBeVisible(); - expect(publishButtonText1.textContent).toEqual('Unpublish'); - }); - - //re-mock response to return the project with a null publish date - mockBiohubApi().project.getProjectForView.mockResolvedValue({ - ...getProjectForViewResponse, - project: { ...getProjectForViewResponse.project, publish_date: '' } - }); - - fireEvent.click(getByTestId('publish-project-button')); - - await waitFor(() => { - const publishButtonText1 = getByTestId('publish-project-button'); - expect(publishButtonText1).toBeVisible(); - expect(publishButtonText1.textContent).toEqual('Publish'); - }); - }); - - it('shows API error when fails to publish project', async () => { - mockBiohubApi().codes.getAllCodeSets.mockResolvedValue({ - activity: [{ id: 1, name: 'activity 1' }] - } as any); - mockBiohubApi().project.getProjectForView.mockResolvedValue({ - ...getProjectForViewResponse, - project: { ...getProjectForViewResponse.project, publish_date: '' } - }); - mockBiohubApi().project.publishProject = jest.fn(() => Promise.reject(new Error('API Error is Here'))); - - const { getByTestId, queryByText, getAllByRole } = render( - - - - - - ); - - await waitFor(() => { - const publishButtonText1 = getByTestId('publish-project-button'); - expect(publishButtonText1).toBeVisible(); - expect(publishButtonText1.textContent).toEqual('Publish'); - }); - - //re-mock response to return the project with a non-null publish date - mockBiohubApi().project.getProjectForView.mockResolvedValue({ - ...getProjectForViewResponse, - project: { ...getProjectForViewResponse.project, publish_date: '2021-10-10' } - }); - - fireEvent.click(getByTestId('publish-project-button')); - - await waitFor(() => { - expect(queryByText('API Error is Here')).toBeInTheDocument(); - }); - - // Get the backdrop, then get the firstChild because this is where the event listener is attached - //@ts-ignore - fireEvent.click(getAllByRole('presentation')[0].firstChild); - - await waitFor(() => { - expect(queryByText('API Error is Here')).toBeNull(); - }); - }); - - it('shows basic error dialog when publish project returns null response', async () => { - mockBiohubApi().codes.getAllCodeSets.mockResolvedValue({ - activity: [{ id: 1, name: 'activity 1' }] - } as any); - mockBiohubApi().project.getProjectForView.mockResolvedValue({ - ...getProjectForViewResponse, - project: { ...getProjectForViewResponse.project, publish_date: '' } - }); - mockBiohubApi().project.publishProject.mockResolvedValue(null); - - const { getByTestId, queryByText, getAllByRole } = render( - - - - - - ); - - await waitFor(() => { - const publishButtonText1 = getByTestId('publish-project-button'); - expect(publishButtonText1).toBeVisible(); - expect(publishButtonText1.textContent).toEqual('Publish'); - }); - - //re-mock response to return the project with a non-null publish date - mockBiohubApi().project.getProjectForView.mockResolvedValue({ - ...getProjectForViewResponse, - project: { ...getProjectForViewResponse.project, publish_date: '2021-10-10' } - }); - - fireEvent.click(getByTestId('publish-project-button')); - - await waitFor(() => { - expect(queryByText('Error Publishing Project')).toBeInTheDocument(); - }); - - // Get the backdrop, then get the firstChild because this is where the event listener is attached - //@ts-ignore - fireEvent.click(getAllByRole('presentation')[0].firstChild); - - await waitFor(() => { - expect(queryByText('Error Publishing Project')).toBeNull(); - }); - }); }); diff --git a/app/src/features/surveys/view/SurveyHeader.test.tsx b/app/src/features/surveys/view/SurveyHeader.test.tsx index 724e0689dd..89f869eb2b 100644 --- a/app/src/features/surveys/view/SurveyHeader.test.tsx +++ b/app/src/features/surveys/view/SurveyHeader.test.tsx @@ -109,60 +109,6 @@ describe('SurveyPage', () => { }); }); - it('sees delete survey button as enabled when accessing an unpublished survey as a project creator', async () => { - mockBiohubApi().survey.deleteSurvey.mockResolvedValue(true); - - const authState = { - keycloakWrapper: { - ...defaultAuthState.keycloakWrapper, - systemRoles: [SYSTEM_ROLE.PROJECT_CREATOR] as string[], - hasSystemRole: jest.fn().mockReturnValueOnce(true).mockReturnValueOnce(false).mockReturnValueOnce(true) - } - }; - - const surveyData: IGetSurveyForViewResponse = { - ...surveyForView, - surveyData: { - ...surveyForView.surveyData, - survey_details: { ...surveyForView.surveyData.survey_details, publish_date: '' } - } - }; - - const { getByTestId, findByText } = renderComponent(authState, surveyData); - - const surveyHeaderText = await findByText('survey name', { selector: 'h1 span' }); - expect(surveyHeaderText).toBeVisible(); - - expect(getByTestId('delete-survey-button')).toBeEnabled(); - }); - - it('sees delete survey button as disabled when accessing a published survey as a project creator', async () => { - mockBiohubApi().survey.deleteSurvey.mockResolvedValue(true); - - const authState = { - keycloakWrapper: { - ...defaultAuthState.keycloakWrapper, - systemRoles: [SYSTEM_ROLE.PROJECT_CREATOR] as string[], - hasSystemRole: jest.fn().mockReturnValueOnce(true).mockReturnValueOnce(false).mockReturnValueOnce(true) - } - }; - - const surveyData: IGetSurveyForViewResponse = { - ...surveyForView, - surveyData: { - ...surveyForView.surveyData, - survey_details: { ...surveyForView.surveyData.survey_details, publish_date: '2021-07-07' } - } - }; - - const { getByTestId, findByText } = renderComponent(authState, surveyData); - - const surveyHeaderText = await findByText('survey name', { selector: 'h1 span' }); - expect(surveyHeaderText).toBeVisible(); - - expect(getByTestId('delete-survey-button')).toBeDisabled(); - }); - it('does not see the delete button when accessing survey as non admin user', async () => { const authState = { keycloakWrapper: { @@ -179,27 +125,4 @@ describe('SurveyPage', () => { expect(queryByTestId('delete-survey-button')).toBeNull(); }); - - it('calls refresh after publishing or unpublishing a survey', async () => { - const surveyData: IGetSurveyForViewResponse = { - ...surveyForView, - surveyData: { - ...surveyForView.surveyData, - survey_details: { ...surveyForView.surveyData.survey_details, publish_date: '' } - } - }; - - mockBiohubApi().survey.publishSurvey.mockResolvedValue({ id: 1 }); - - const { getByTestId, findByText } = renderComponent(defaultAuthState, surveyData); - - const publishButtonText1 = await findByText('Publish Survey'); - expect(publishButtonText1).toBeVisible(); - - fireEvent.click(getByTestId('publish-survey-button')); - - waitFor(() => { - expect(refresh).toHaveBeenCalled(); - }); - }); }); diff --git a/app/src/features/surveys/view/SurveyHeader.tsx b/app/src/features/surveys/view/SurveyHeader.tsx index f1daccb3aa..53898d4982 100644 --- a/app/src/features/surveys/view/SurveyHeader.tsx +++ b/app/src/features/surveys/view/SurveyHeader.tsx @@ -188,11 +188,9 @@ const SurveyHeader: React.FC = (props) => { SYSTEM_ROLE.SYSTEM_ADMIN, SYSTEM_ROLE.PROJECT_CREATOR ]); - // Enable delete button if you a system admin OR a project admin and the survey is not published + // Enable delete button if you a system admin or a project admin const enableDeleteSurveyButton = - keycloakWrapper?.hasSystemRole([SYSTEM_ROLE.SYSTEM_ADMIN]) || - (keycloakWrapper?.hasSystemRole([SYSTEM_ROLE.PROJECT_CREATOR]) && - !surveyWithDetails.surveyData.survey_details.publish_date); + keycloakWrapper?.hasSystemRole([SYSTEM_ROLE.SYSTEM_ADMIN, SYSTEM_ROLE.PROJECT_CREATOR]) return ( <> diff --git a/app/src/features/surveys/view/components/SurveyGeneralInformation.test.tsx b/app/src/features/surveys/view/components/SurveyGeneralInformation.test.tsx index f706a61423..8e02e4e74c 100644 --- a/app/src/features/surveys/view/components/SurveyGeneralInformation.test.tsx +++ b/app/src/features/surveys/view/components/SurveyGeneralInformation.test.tsx @@ -99,7 +99,6 @@ describe('SurveyGeneralInformation', () => { end_date: '2021-01-25', biologist_first_name: 'firstttt', biologist_last_name: 'lastttt', - publish_date: '', survey_area_name: 'study area is this', geometry: [ { @@ -274,7 +273,6 @@ describe('SurveyGeneralInformation', () => { end_date: '2021-01-25', biologist_first_name: 'firstttt', biologist_last_name: 'lastttt', - publish_date: '', survey_area_name: 'study area is this', geometry: [ { diff --git a/app/src/features/surveys/view/components/SurveyStudyArea.test.tsx b/app/src/features/surveys/view/components/SurveyStudyArea.test.tsx index 715e153c54..6ccdac5889 100644 --- a/app/src/features/surveys/view/components/SurveyStudyArea.test.tsx +++ b/app/src/features/surveys/view/components/SurveyStudyArea.test.tsx @@ -93,7 +93,6 @@ describe('SurveyStudyArea', () => { end_date: '2021-01-25', biologist_first_name: 'firstttt', biologist_last_name: 'lastttt', - publish_date: '', survey_area_name: 'study area is this', geometry, revision_count: 0 @@ -210,7 +209,6 @@ describe('SurveyStudyArea', () => { biologist_first_name: 'firstttt', biologist_last_name: 'lastttt', survey_area_name: 'study area is this', - publish_date: '', geometry, revision_count: 0 } diff --git a/app/src/hooks/api/useSurveyApi.test.ts b/app/src/hooks/api/useSurveyApi.test.ts index aad50e08ae..670e819daf 100644 --- a/app/src/hooks/api/useSurveyApi.test.ts +++ b/app/src/hooks/api/useSurveyApi.test.ts @@ -136,7 +136,6 @@ describe('useSurveyApi', () => { species: ['species 1', 'species 2'], start_date: '2020/04/04', end_date: '2020/05/05', - publish_status: 'Published', completion_status: 'Completed' } } @@ -284,14 +283,6 @@ describe('useSurveyApi', () => { expect(result).toEqual(resultData); }); - it('publishSurvey works as expected', async () => { - mock.onPut(`/api/project/${projectId}/survey/${surveyId}/publish`).reply(200, true); - - const result = await useSurveyApi(axios).publishSurvey(projectId, surveyId, true); - - expect(result).toEqual(true); - }); - it('deleteSummarySubmission works as expected', async () => { const summaryId = 2; diff --git a/app/src/interfaces/useProjectApi.interface.ts b/app/src/interfaces/useProjectApi.interface.ts index 9dd9d6ce99..4e813deb14 100644 --- a/app/src/interfaces/useProjectApi.interface.ts +++ b/app/src/interfaces/useProjectApi.interface.ts @@ -72,7 +72,6 @@ export interface IGetProjectsListResponse { coordinator_agency: string; project_type: string; permits_list: string; - publish_status: string; completion_status: string; } @@ -235,7 +234,6 @@ export interface IGetProjectForViewResponseDetails { start_date: string; end_date: string; completion_status: string; - publish_date: string; } interface IGetProjectForViewResponsePermitArrayItem { diff --git a/app/src/interfaces/useSurveyApi.interface.ts b/app/src/interfaces/useSurveyApi.interface.ts index c3644544b3..25154c22fd 100644 --- a/app/src/interfaces/useSurveyApi.interface.ts +++ b/app/src/interfaces/useSurveyApi.interface.ts @@ -53,7 +53,6 @@ export interface IGetSurveyForViewResponseDetails { biologist_last_name: string; survey_area_name: string; geometry: Feature[]; - publish_date: string; revision_count: number; } @@ -148,7 +147,6 @@ export interface IGetSurveyDetailsResponse { name: string; start_date: string; end_date: string; - publish_status: string; completion_status: string; } diff --git a/app/src/test-helpers/project-helpers.ts b/app/src/test-helpers/project-helpers.ts index 7fb7ac7377..4b5064d367 100644 --- a/app/src/test-helpers/project-helpers.ts +++ b/app/src/test-helpers/project-helpers.ts @@ -8,8 +8,7 @@ export const getProjectForViewResponse: IGetProjectForViewResponse = { start_date: '1998-10-10', end_date: '2021-02-26', project_activities: [1], - completion_status: 'Active', - publish_date: '2021-01-26' + completion_status: 'Active' }, permit: { permits: [ diff --git a/app/src/test-helpers/survey-helpers.ts b/app/src/test-helpers/survey-helpers.ts index 0b1e3e3f8b..628428e6f6 100644 --- a/app/src/test-helpers/survey-helpers.ts +++ b/app/src/test-helpers/survey-helpers.ts @@ -34,7 +34,6 @@ export const surveyObject: SurveyViewObject = { } } ], - publish_date: (null as unknown) as string, revision_count: 0 }, purpose_and_methodology: { diff --git a/database/src/migrations/release.0.34/biohub.sql b/database/src/migrations/release.0.34/biohub.sql index a67c9f5259..1858f4dbcb 100644 --- a/database/src/migrations/release.0.34/biohub.sql +++ b/database/src/migrations/release.0.34/biohub.sql @@ -1014,7 +1014,7 @@ COMMENT ON COLUMN project.coordinator_agency_name IS 'Name of agency the project ; COMMENT ON COLUMN project.coordinator_public IS 'A flag that determines whether personal coordinator details are public. A value of "Y" provides that personal details are public.' ; -COMMENT ON COLUMN project.publish_timestamp IS 'A timestamp that indicates that the project metadata has been approved for discovery. If the timestamp is not null then project metadata is public. If the timestamp is null the project metadata is not yet public.' +COMMENT ON COLUMN project.publish_timestamp IS '(Depricated) A timestamp that indicates that the project metadata has been approved for discovery. If the timestamp is not null then project metadata is public. If the timestamp is null the project metadata is not yet public.' ; COMMENT ON COLUMN project.geometry IS 'The containing geometry of the record.' ; @@ -2198,7 +2198,7 @@ COMMENT ON COLUMN survey.location_description IS 'The location description.' ; COMMENT ON COLUMN survey.location_name IS 'The name of the survey location.' ; -COMMENT ON COLUMN survey.publish_timestamp IS 'A timestamp that indicates that the survey metadata has been approved for discovery. If the timestamp is not null then project metadata is public. If the timestamp is null the survey metadata is not yet public.' +COMMENT ON COLUMN survey.publish_timestamp IS '(Depricated) A timestamp that indicates that the survey metadata has been approved for discovery. If the timestamp is not null then project metadata is public. If the timestamp is null the survey metadata is not yet public.' ; COMMENT ON COLUMN survey.geometry IS 'The containing geometry of the record.' ; diff --git a/testing/e2e/cypress/integration/smoke_1_CreateProjectMinimal.spec.ts b/testing/e2e/cypress/integration/smoke_1_CreateProjectMinimal.spec.ts index ef81ddcd49..3b1549bfb7 100644 --- a/testing/e2e/cypress/integration/smoke_1_CreateProjectMinimal.spec.ts +++ b/testing/e2e/cypress/integration/smoke_1_CreateProjectMinimal.spec.ts @@ -18,7 +18,6 @@ import { add_classification, add_funding, add_partnerships, - publish_project, attach_file, add_survey, } from "../page-functions/project/project-create-page"; @@ -68,8 +67,6 @@ while (n < 1) { submit_project(); cy.wait(10000); - publish_project(); - attach_file(); add_survey(); diff --git a/testing/e2e/cypress/page-functions/project/project-create-page.ts b/testing/e2e/cypress/page-functions/project/project-create-page.ts index 92f831657b..1eef537c03 100644 --- a/testing/e2e/cypress/page-functions/project/project-create-page.ts +++ b/testing/e2e/cypress/page-functions/project/project-create-page.ts @@ -234,18 +234,6 @@ export function add_partnerships() { cy.wait(5000); } -export function publish_project() { - cy.get('button[data-testid="publish-project-button"]') - .contains("Publish") - .should("be.visible"); - cy.get('button[data-testid="publish-project-button"]').click(); - cy.wait(10000); - cy.get('button[data-testid="publish-project-button"]') - .contains("Unpublish") - .should("be.visible"); - cy.wait(2000); -} - export function attach_file() { cy.get("#custom-menu-button-Upload").focus().click(); cy.wait(1000); From 7ed8cf928df1482e793d3fc5ed8421060bcf6a7f Mon Sep 17 00:00:00 2001 From: Curtis Upshall Date: Tue, 12 Jul 2022 13:57:30 -0700 Subject: [PATCH 3/9] BHBC-1841: Update snapshots --- .../features/projects/view/ProjectHeader.tsx | 19 +- .../__snapshots__/ProjectPage.test.tsx.snap | 304 +++++++----------- .../__snapshots__/SurveyPage.test.tsx.snap | 30 -- 3 files changed, 125 insertions(+), 228 deletions(-) diff --git a/app/src/features/projects/view/ProjectHeader.tsx b/app/src/features/projects/view/ProjectHeader.tsx index 8764d572e3..5ccd150551 100644 --- a/app/src/features/projects/view/ProjectHeader.tsx +++ b/app/src/features/projects/view/ProjectHeader.tsx @@ -235,19 +235,12 @@ const ProjectHeader: React.FC = (props) => { Manage Project Team {showDeleteProjectButton && ( - - <> - - - - - + + + )} diff --git a/app/src/features/projects/view/__snapshots__/ProjectPage.test.tsx.snap b/app/src/features/projects/view/__snapshots__/ProjectPage.test.tsx.snap index 10e63a5431..658a069076 100644 --- a/app/src/features/projects/view/__snapshots__/ProjectPage.test.tsx.snap +++ b/app/src/features/projects/view/__snapshots__/ProjectPage.test.tsx.snap @@ -33,7 +33,7 @@ exports[`ProjectPage renders correctly with no end date 1`] = ` class="MuiContainer-root MuiContainer-maxWidthXl" >

Project - Test Project Name

-
@@ -159,7 +143,7 @@ exports[`ProjectPage renders correctly with no end date 1`] = ` class="MuiContainer-root MuiContainer-maxWidthXl" >