diff --git a/api/src/paths/project/{projectId}/attachments/{attachmentId}/delete.ts b/api/src/paths/project/{projectId}/attachments/{attachmentId}/delete.ts index de1796a60b..4c23c534e5 100644 --- a/api/src/paths/project/{projectId}/attachments/{attachmentId}/delete.ts +++ b/api/src/paths/project/{projectId}/attachments/{attachmentId}/delete.ts @@ -5,6 +5,7 @@ import { PROJECT_ROLE, SYSTEM_ROLE } from '../../../../../constants/roles'; import { getDBConnection } from '../../../../../database/db'; import { authorizeRequestHandler } from '../../../../../request-handlers/security/authorization'; import { AttachmentService } from '../../../../../services/attachment-service'; +import { HistoryPublishService } from '../../../../../services/history-publish-service'; import { deleteFileFromS3 } from '../../../../../utils/file-utils'; import { getLogger } from '../../../../../utils/logger'; import { attachmentApiDocObject } from '../../../../../utils/shared-api-docs'; @@ -103,13 +104,16 @@ export function deleteAttachment(): RequestHandler { await connection.open(); const attachmentService = new AttachmentService(connection); + const historyPublishService = new HistoryPublishService(connection); let deleteResult: { key: string }; if (req.body.attachmentType === ATTACHMENT_TYPE.REPORT) { + await historyPublishService.deleteProjectReportAttachmentPublishRecord(Number(req.params.attachmentId)); await attachmentService.deleteProjectReportAttachmentAuthors(Number(req.params.attachmentId)); deleteResult = await attachmentService.deleteProjectReportAttachment(Number(req.params.attachmentId)); } else { + await historyPublishService.deleteProjectAttachmentPublishRecord(Number(req.params.attachmentId)); deleteResult = await attachmentService.deleteProjectAttachment(Number(req.params.attachmentId)); } diff --git a/api/src/repositories/history-publish-repository.ts b/api/src/repositories/history-publish-repository.ts index d0fcc46eb2..9fe31acfa5 100644 --- a/api/src/repositories/history-publish-repository.ts +++ b/api/src/repositories/history-publish-repository.ts @@ -623,6 +623,44 @@ export class HistoryPublishRepository extends BaseRepository { await this.connection.sql(sqlStatement); } + /** + * Deletes a record from `project_attachment_publish` for a given attachment id. + * + * @param {number} projectAttachmentId + * @return {*} {Promise} + * @memberof HistoryPublishRepository + */ + async deleteProjectAttachmentPublishRecord(projectAttachmentId: number): Promise { + const sqlStatement = SQL` + delete + from + project_attachment_publish + where + project_attachment_id = ${projectAttachmentId}; + `; + + await this.connection.sql(sqlStatement); + } + + /** + * Deletes a record from `project_report_publish` for a given attachment id. + * + * @param {number} projectAttachmentId + * @return {*} {Promise} + * @memberof HistoryPublishRepository + */ + async deleteProjectReportAttachmentPublishRecord(projectAttachmentId: number): Promise { + const sqlStatement = SQL` + delete + from + project_report_publish + where + project_report_attachment_id = ${projectAttachmentId}; + `; + + await this.connection.sql(sqlStatement); + } + /** * Gets the count of unpublished survey attachments * diff --git a/api/src/repositories/user-repository.ts b/api/src/repositories/user-repository.ts index 50a4831539..ae02805fa3 100644 --- a/api/src/repositories/user-repository.ts +++ b/api/src/repositories/user-repository.ts @@ -182,9 +182,9 @@ export class UserRepository extends BaseRepository { ON uis.user_identity_source_id = su.user_identity_source_id WHERE - su.user_identifier = ${userIdentifier} + su.user_identifier = ${userIdentifier.toLowerCase()} AND - uis.name = ${identitySource} + uis.name = ${identitySource.toUpperCase()} GROUP BY su.system_user_id, su.record_end_date, @@ -229,7 +229,7 @@ export class UserRepository extends BaseRepository { WHERE name = ${identitySource.toUpperCase()} ), - ${userIdentifier}, + ${userIdentifier.toLowerCase()}, now() ) RETURNING diff --git a/api/src/services/history-publish-service.ts b/api/src/services/history-publish-service.ts index 5ed43ea222..fe7ba8345f 100644 --- a/api/src/services/history-publish-service.ts +++ b/api/src/services/history-publish-service.ts @@ -250,6 +250,28 @@ export class HistoryPublishService extends DBService { return this.historyRepository.deleteSurveyReportAttachmentPublishRecord(surveyReportAttachmentId); } + /** + * Deletes a record from `project_attachment_publish` for a given attachment id. + * + * @param {number} surveyAttachmentId + * @return {*} {Promise} + * @memberof HistoryPublishService + */ + async deleteProjectAttachmentPublishRecord(surveyAttachmentId: number): Promise { + return this.historyRepository.deleteProjectAttachmentPublishRecord(surveyAttachmentId); + } + + /** + * Deletes a record from `project_report_publish` for a given attachment id. + * + * @param {number} surveyReportAttachmentId + * @return {*} {Promise} + * @memberof HistoryPublishService + */ + async deleteProjectReportAttachmentPublishRecord(surveyReportAttachmentId: number): Promise { + return this.historyRepository.deleteProjectReportAttachmentPublishRecord(surveyReportAttachmentId); + } + /** * Returns true if a given survey has any unpublished attachments and false if no unpublished attachments are found * diff --git a/app/src/components/dialog/__snapshots__/EditDialog.test.tsx.snap b/app/src/components/dialog/__snapshots__/EditDialog.test.tsx.snap index 059472899f..93c7868b32 100644 --- a/app/src/components/dialog/__snapshots__/EditDialog.test.tsx.snap +++ b/app/src/components/dialog/__snapshots__/EditDialog.test.tsx.snap @@ -53,7 +53,6 @@ exports[`EditDialog matches snapshot when open, with error message 1`] = `