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

feat(backend, website): Use version comments field for revocations as well. #2352

Merged
merged 17 commits into from
Aug 19, 2024
Merged
Show file tree
Hide file tree
Changes from 12 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
11 changes: 11 additions & 0 deletions backend/src/main/kotlin/org/loculus/backend/api/SubmissionTypes.kt
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,17 @@ data class AccessionVersionsFilterWithDeletionScope(
val scope: DeleteSequenceScope,
)

data class AccessionsToRevokeWithComment(
@Schema(
description = "List of accessions to revoke.",
)
val accessions: List<Accession>,
@Schema(
description = "Reason for revocation or other details, added as version_comment",
)
val versionComment: String? = null,
)

enum class ApproveDataScope {
ALL,
WITHOUT_WARNINGS,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import org.jetbrains.exposed.sql.transactions.transaction
import org.loculus.backend.api.AccessionVersion
import org.loculus.backend.api.AccessionVersionsFilterWithApprovalScope
import org.loculus.backend.api.AccessionVersionsFilterWithDeletionScope
import org.loculus.backend.api.Accessions
import org.loculus.backend.api.AccessionsToRevokeWithComment
import org.loculus.backend.api.CompressionFormat
import org.loculus.backend.api.DataUseTerms
import org.loculus.backend.api.DataUseTermsType
Expand Down Expand Up @@ -397,9 +397,10 @@ class SubmissionController(
fun revoke(
@PathVariable @Valid
organism: Organism,
@RequestBody body: Accessions,
@RequestBody body: AccessionsToRevokeWithComment,
@HiddenParam authenticatedUser: AuthenticatedUser,
): List<SubmissionIdMapping> = submissionDatabaseService.revoke(body.accessions, authenticatedUser, organism)
): List<SubmissionIdMapping> =
submissionDatabaseService.revoke(body.accessions, authenticatedUser, organism, body.versionComment)

@Operation(description = DELETE_SEQUENCES_DESCRIPTION)
@ResponseStatus(HttpStatus.OK)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,8 @@ class ReleasedDataModel(
("releasedDate" to TextNode(rawProcessedData.releasedAtTimestamp.toUtcDateString())) +
("versionStatus" to TextNode(siloVersionStatus.name)) +
("dataUseTerms" to TextNode(currentDataUseTerms.type.name)) +
("dataUseTermsRestrictedUntil" to restrictedDataUseTermsUntil)
("dataUseTermsRestrictedUntil" to restrictedDataUseTermsUntil) +
("version_comment" to TextNode(rawProcessedData.versionComment))

if (backendConfig.dataUseTermsUrls != null) {
val url = if (rawProcessedData.dataUseTerms == DataUseTerms.Open) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ object SequenceEntriesTable : Table(SEQUENCE_ENTRIES_TABLE_NAME) {

val accessionColumn = varchar("accession", 255)
val versionColumn = long("version")
val versionCommentColumn = varchar("version_comment", 255).nullable()
val organismColumn = varchar("organism", 255)
val submissionIdColumn = varchar("submission_id", 255)
val submitterColumn = varchar("submitter", 255)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ object SequenceEntriesView : Table(SEQUENCE_ENTRIES_VIEW_NAME) {
val releasedAtTimestampColumn = datetime("released_at").nullable()
val statusColumn = varchar("status", 255)
val isRevocationColumn = bool("is_revocation").default(false)
val versionCommentColumn = varchar("version_comment", 255).nullable()
val errorsColumn = jacksonSerializableJsonb<List<PreprocessingAnnotation>>("errors").nullable()
val warningsColumn = jacksonSerializableJsonb<List<PreprocessingAnnotation>>("warnings").nullable()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import org.jetbrains.exposed.sql.not
import org.jetbrains.exposed.sql.notExists
import org.jetbrains.exposed.sql.selectAll
import org.jetbrains.exposed.sql.statements.StatementType
import org.jetbrains.exposed.sql.stringParam
import org.jetbrains.exposed.sql.transactions.transaction
import org.jetbrains.exposed.sql.update
import org.loculus.backend.api.AccessionVersion
Expand Down Expand Up @@ -538,6 +539,7 @@ class SubmissionDatabaseService(
SequenceEntriesView.accessionColumn,
SequenceEntriesView.versionColumn,
SequenceEntriesView.isRevocationColumn,
SequenceEntriesView.versionCommentColumn,
SequenceEntriesView.jointDataColumn,
SequenceEntriesView.submitterColumn,
SequenceEntriesView.groupIdColumn,
Expand Down Expand Up @@ -577,6 +579,7 @@ class SubmissionDatabaseService(
DataUseTermsType.fromString(it[DataUseTermsTable.dataUseTermsTypeColumn]),
it[DataUseTermsTable.restrictedUntilColumn],
),
versionComment = it[SequenceEntriesView.versionCommentColumn],
)
}

Expand Down Expand Up @@ -673,6 +676,7 @@ class SubmissionDatabaseService(
accessions: List<Accession>,
authenticatedUser: AuthenticatedUser,
organism: Organism,
versionComment: String?,
): List<SubmissionIdMapping> {
log.info { "revoking ${accessions.size} sequences" }

Expand All @@ -682,30 +686,35 @@ class SubmissionDatabaseService(
.andThatSequenceEntriesAreInStates(listOf(Status.APPROVED_FOR_RELEASE))
.andThatOrganismIs(organism)
}

val now = Clock.System.now().toLocalDateTime(TimeZone.UTC)

SequenceEntriesTable.insert(
SequenceEntriesTable
.select(
SequenceEntriesTable.accessionColumn,
SequenceEntriesTable.versionColumn.plus(1),
SequenceEntriesTable.submissionIdColumn,
SequenceEntriesTable.submitterColumn,
SequenceEntriesTable.groupIdColumn,
dateTimeParam(now),
booleanParam(true),
SequenceEntriesTable.organismColumn,
)
.where {
(SequenceEntriesTable.accessionColumn inList accessions) and
SequenceEntriesTable.isMaxVersion
SequenceEntriesTable.select(
SequenceEntriesTable.accessionColumn, SequenceEntriesTable.versionColumn.plus(1),
when (versionComment) {
null -> Op.nullOp()
else -> stringParam(versionComment)
},
SequenceEntriesTable.submissionIdColumn,
SequenceEntriesTable.submitterColumn,
SequenceEntriesTable.groupIdColumn,
dateTimeParam(
now,
),
booleanParam(true), SequenceEntriesTable.organismColumn,
).where {
(
SequenceEntriesTable.accessionColumn inList
accessions
) and
SequenceEntriesTable.isMaxVersion
},
columns = listOf(
SequenceEntriesTable.accessionColumn,
SequenceEntriesTable.versionColumn,
SequenceEntriesTable.versionCommentColumn,
SequenceEntriesTable.submissionIdColumn,
SequenceEntriesTable.submitterColumn,
SequenceEntriesTable.groupIdColumn,
SequenceEntriesTable.submitterColumn, SequenceEntriesTable.groupIdColumn,
SequenceEntriesTable.submittedAtTimestampColumn,
SequenceEntriesTable.isRevocationColumn,
SequenceEntriesTable.organismColumn,
Expand Down Expand Up @@ -1017,6 +1026,7 @@ data class RawProcessedData(
override val accession: Accession,
override val version: Version,
val isRevocation: Boolean,
val versionComment: String?,
val submitter: String,
val groupId: Int,
val groupName: String,
Expand Down
2 changes: 2 additions & 0 deletions backend/src/main/resources/db/migration/V1__init.sql
anna-parker marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ values (1, now());
create table sequence_entries (
accession text not null,
version bigint not null,
version_comment text,
organism text not null,
submission_id text not null,
submitter text not null,
Expand Down Expand Up @@ -134,6 +135,7 @@ from
create table metadata_upload_aux_table (
accession text,
version bigint,
version_comment text,
upload_id text not null,
organism text not null,
submission_id text not null,
Expand Down
anna-parker marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ class GetReleasedDataEndpointTest(
"releasedDate" to TextNode(Clock.System.now().toLocalDateTime(TimeZone.UTC).date.toString()),
"submittedDate" to TextNode(Clock.System.now().toLocalDateTime(TimeZone.UTC).date.toString()),
"dataUseTermsRestrictedUntil" to NullNode.getInstance(),
"version_comment" to NullNode.getInstance(),
anna-parker marked this conversation as resolved.
Show resolved Hide resolved
"booleanColumn" to BooleanNode.TRUE,
)

Expand Down Expand Up @@ -214,10 +215,17 @@ class GetReleasedDataEndpointTest(
value,
`is`(TextNode(Clock.System.now().toLocalDateTime(TimeZone.UTC).date.toString())),
)

"releasedDate" -> assertThat(
value,
`is`(TextNode(Clock.System.now().toLocalDateTime(TimeZone.UTC).date.toString())),
)

"version_comment" -> assertThat(
value,
`is`(TextNode("This is a test revocation")),
)

else -> assertThat("value for $key", value, `is`(NullNode.instance))
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,10 +178,17 @@ class SubmissionControllerClient(private val mockMvc: MockMvc, private val objec
listOfSequenceEntriesToRevoke: List<Accession>,
organism: String = DEFAULT_ORGANISM,
jwt: String? = jwtForDefaultUser,
versionComment: String? = null,
): ResultActions = mockMvc.perform(
post(addOrganismToPath("/revoke", organism = organism))
.contentType(MediaType.APPLICATION_JSON)
.content("""{"accessions":${objectMapper.writeValueAsString(listOfSequenceEntriesToRevoke)}}""")
.content(
"""{"accessions":${
objectMapper.writeValueAsString(
listOfSequenceEntriesToRevoke,
)
}, "versionComment":$versionComment"}""",
anna-parker marked this conversation as resolved.
Show resolved Hide resolved
)
.withAuth(jwt),
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,14 @@ class SubmissionConvenienceClient(

fun prepareRevokedSequenceEntries(organism: String = DEFAULT_ORGANISM): List<AccessionVersionInterface> {
val accessionVersions = prepareDataTo(Status.APPROVED_FOR_RELEASE, organism = organism)
val revocationVersions = revokeSequenceEntries(accessionVersions.map { it.accession }, organism = organism)
val revocationVersions =
revokeSequenceEntries(
accessionVersions.map {
it.accession
},
organism = organism,
versionComment = "This is a test revocation",
)
return approveProcessedSequenceEntries(revocationVersions, organism = organism)
}

Expand Down Expand Up @@ -323,11 +330,13 @@ class SubmissionConvenienceClient(
listOfAccessionsToRevoke: List<Accession>,
organism: String = DEFAULT_ORGANISM,
username: String = DEFAULT_USER_NAME,
versionComment: String? = null,
): List<SubmissionIdMapping> = deserializeJsonResponse(
client.revokeSequenceEntries(
listOfAccessionsToRevoke,
organism = organism,
jwt = generateJwtFor(username),
versionComment = versionComment,
),
)

Expand Down
86 changes: 80 additions & 6 deletions website/src/components/SequenceDetailsPage/RevokeButton.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { type FC } from 'react';
import { type FC, useState } from 'react';
import { confirmAlert } from 'react-confirm-alert';
import { toast } from 'react-toastify';

import { routes } from '../../routes/routes';
import { backendClientHooks } from '../../services/serviceHooks';
import type { ClientConfig } from '../../types/runtimeConfig';
import { createAuthorizationHeader } from '../../utils/createAuthorizationHeader';
import { stringifyMaybeAxiosError } from '../../utils/stringifyMaybeAxiosError';
import { displayConfirmationDialog } from '../ConfirmationDialog';
import { withQueryProvider } from '../common/withQueryProvider';

type RevokeSequenceEntryProps = {
Expand All @@ -26,7 +26,10 @@ const InnerRevokeButton: FC<RevokeSequenceEntryProps> = ({
}) => {
const hooks = backendClientHooks(clientConfig);
const useRevokeSequenceEntries = hooks.useRevokeSequences(
{ headers: createAuthorizationHeader(accessToken), params: { organism } },
{
headers: createAuthorizationHeader(accessToken),
params: { organism },
},
{
onSuccess: () => {
document.location = routes.userSequenceReviewPage(organism, groupId);
Expand All @@ -39,15 +42,15 @@ const InnerRevokeButton: FC<RevokeSequenceEntryProps> = ({
},
);

const handleRevokeSequenceEntry = () => {
useRevokeSequenceEntries.mutate({ accessions: [accessionVersion] });
const handleRevokeSequenceEntry = (inputValue: string) => {
useRevokeSequenceEntries.mutate({ accessions: [accessionVersion], versionComment: inputValue });
};

return (
<button
className='btn btn-sm bg-red-400'
onClick={() =>
displayConfirmationDialog({
displayRevocationDialog({
dialogText: 'Are you sure you want to create a revocation for this sequence?',
onConfirmation: handleRevokeSequenceEntry,
})
Expand All @@ -58,6 +61,77 @@ const InnerRevokeButton: FC<RevokeSequenceEntryProps> = ({
);
};

interface DisplayRevocationProps {
dialogText: string;
onConfirmation: (inputValue: string) => void;
}

export const displayRevocationDialog = ({ dialogText, onConfirmation }: DisplayRevocationProps) => {
confirmAlert({
anna-parker marked this conversation as resolved.
Show resolved Hide resolved
closeOnClickOutside: true,

customUI: ({ onClose }) => (
<RevocationDialog
dialogText={dialogText}
onConfirmation={async (inputValue) => {
await onConfirmation(inputValue);
onClose();
}}
onClose={onClose}
/>
),
});
};

interface RevocationDialogProps {
dialogText: string;
onConfirmation: (inputValue: string) => void;
onClose: () => void;
}

export const RevocationDialog: React.FC<RevocationDialogProps> = ({ dialogText, onConfirmation, onClose }) => {
const [inputValue, setInputValue] = useState('');

return (
<div className='modal-box'>
<form method='dialog'>
<button className='btn btn-sm btn-circle btn-ghost absolute right-2 top-2' onClick={onClose}>
</button>
</form>

<h3 className='font-bold text-lg'>{dialogText}</h3>

<input
type='text'
value={inputValue}
onChange={(e) => setInputValue(e.target.value)}
placeholder='Enter reason for revocation'
className='mt-4 w-11/12 mx-auto block'
/>

<div className='flex justify-end gap-4 mt-4'>
<form method='dialog'>
<button className='btn loculusColor text-white hover:bg-primary-700' onClick={onClose}>
Cancel
</button>
</form>
<form method='dialog'>
<button
className='btn loculusColor text-white hover:bg-primary-700'
onClick={(e) => {
e.preventDefault();
onConfirmation(inputValue);
}}
>
Confirm
</button>
</form>
</div>
</div>
);
};

export const RevokeButton = withQueryProvider(InnerRevokeButton);

function getRevokeSequenceEntryErrorMessage(error: unknown) {
Expand Down
Loading
Loading