From f522e6f674516e3eaeb0b2492cbfa549bc436681 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=81sd=C3=ADs=20Erna=20Gu=C3=B0mundsd=C3=B3ttir?= Date: Fri, 4 Oct 2024 09:53:11 +0000 Subject: [PATCH] fix(service-portal): subpoena fixes (#16261) * feat: add more audit logs * fix: download id * fix: PR comments --------- Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com> --- .../documents/src/lib/documentV2.resolver.ts | 22 +++++++++++++++ .../documents/src/lib/documentV2.service.ts | 4 ++- .../src/lib/models/v2/confirmActions.input.ts | 12 +++++++++ .../src/lib/models/v2/confirmActions.model.ts | 12 +++++++++ .../ConfirmationModal/ConfirmationModal.tsx | 1 + .../DocumentLine/DocumentLineV3.tsx | 27 ++++++++++++++++--- .../src/screens/Overview/Overview.graphql | 7 +++++ 7 files changed, 81 insertions(+), 4 deletions(-) create mode 100644 libs/api/domains/documents/src/lib/models/v2/confirmActions.input.ts create mode 100644 libs/api/domains/documents/src/lib/models/v2/confirmActions.model.ts diff --git a/libs/api/domains/documents/src/lib/documentV2.resolver.ts b/libs/api/domains/documents/src/lib/documentV2.resolver.ts index 406ae800989a..3622993197f9 100644 --- a/libs/api/domains/documents/src/lib/documentV2.resolver.ts +++ b/libs/api/domains/documents/src/lib/documentV2.resolver.ts @@ -30,6 +30,8 @@ import { DocumentMailAction } from './models/v2/mailAction.model.' import { LOGGER_PROVIDER, type Logger } from '@island.is/logging' import { DocumentV2MarkAllMailAsRead } from './models/v2/markAllMailAsRead.model' import type { Locale } from '@island.is/shared/types' +import { DocumentConfirmActionsInput } from './models/v2/confirmActions.input' +import { DocumentConfirmActions } from './models/v2/confirmActions.model' const LOG_CATEGORY = 'documents-resolver' @@ -87,6 +89,26 @@ export class DocumentResolverV2 { return this.documentServiceV2.listDocuments(user.nationalId, input) } + @Scopes(DocumentsScope.main) + @Query(() => DocumentConfirmActions, { + nullable: true, + name: 'documentV2ConfirmActions', + }) + async confirmActions( + @Args('input') input: DocumentConfirmActionsInput, + @CurrentUser() user: User, + ) { + this.auditService.audit({ + auth: user, + namespace: '@island.is/api/document-v2', + action: 'confirmModal', + resources: input.id, + meta: { confirmed: input.confirmed }, + }) + + return { id: input.id, confirmed: input.confirmed } + } + @ResolveField('categories', () => [Category]) documentCategories(@CurrentUser() user: User): Promise> { return this.documentServiceV2.getCategories(user.nationalId) diff --git a/libs/api/domains/documents/src/lib/documentV2.service.ts b/libs/api/domains/documents/src/lib/documentV2.service.ts index 351ddc4055f2..aaf967fc8dbe 100644 --- a/libs/api/domains/documents/src/lib/documentV2.service.ts +++ b/libs/api/domains/documents/src/lib/documentV2.service.ts @@ -64,9 +64,11 @@ export class DocumentServiceV2 { default: type = FileType.UNKNOWN } + // Data for the confirmation modal const confirmation = document.actions?.find( (action) => action.type === 'confirmation', ) + // Data for the alert box const alert = document.actions?.find((action) => action.type === 'alert') const actions = document.actions?.filter( (action) => action.type !== 'alert' && action.type !== 'confirmation', @@ -376,7 +378,7 @@ export class DocumentServiceV2 { return { ...x, icon: 'download', - data: `${this.downloadServiceConfig.baseUrl}/download/v1/electronic-documents/${x.data}`, // if type file, we download + data: `${this.downloadServiceConfig.baseUrl}/download/v1/electronic-documents/${id}`, } } if (x.type === 'url') { diff --git a/libs/api/domains/documents/src/lib/models/v2/confirmActions.input.ts b/libs/api/domains/documents/src/lib/models/v2/confirmActions.input.ts new file mode 100644 index 000000000000..12128a9e50d9 --- /dev/null +++ b/libs/api/domains/documents/src/lib/models/v2/confirmActions.input.ts @@ -0,0 +1,12 @@ +import { InputType, Field } from '@nestjs/graphql' +import { IsString } from 'class-validator' + +@InputType('DocumentConfirmActionsInput') +export class DocumentConfirmActionsInput { + @Field() + @IsString() + readonly id!: string + + @Field(() => Boolean, { nullable: true }) + readonly confirmed?: boolean +} diff --git a/libs/api/domains/documents/src/lib/models/v2/confirmActions.model.ts b/libs/api/domains/documents/src/lib/models/v2/confirmActions.model.ts new file mode 100644 index 000000000000..35e2fb23b03a --- /dev/null +++ b/libs/api/domains/documents/src/lib/models/v2/confirmActions.model.ts @@ -0,0 +1,12 @@ +import { Field, ObjectType } from '@nestjs/graphql' +import { IsString } from 'class-validator' + +@ObjectType('DocumentConfirmActions') +export class DocumentConfirmActions { + @Field() + @IsString() + readonly id!: string + + @Field(() => Boolean, { nullable: true }) + readonly confirmed?: boolean +} diff --git a/libs/service-portal/core/src/components/ConfirmationModal/ConfirmationModal.tsx b/libs/service-portal/core/src/components/ConfirmationModal/ConfirmationModal.tsx index ada8abcc210a..0cf59af09b9b 100644 --- a/libs/service-portal/core/src/components/ConfirmationModal/ConfirmationModal.tsx +++ b/libs/service-portal/core/src/components/ConfirmationModal/ConfirmationModal.tsx @@ -11,6 +11,7 @@ import * as styles from './ConfirmationModal.css' import Modal from '../Modal/Modal' import LinkResolver from '../LinkResolver/LinkResolver' import { m } from '../..' + interface Props { onSubmit: () => void onCancel: () => void diff --git a/libs/service-portal/documents/src/components/DocumentLine/DocumentLineV3.tsx b/libs/service-portal/documents/src/components/DocumentLine/DocumentLineV3.tsx index 499477b92e30..bff0538f0760 100644 --- a/libs/service-portal/documents/src/components/DocumentLine/DocumentLineV3.tsx +++ b/libs/service-portal/documents/src/components/DocumentLine/DocumentLineV3.tsx @@ -22,7 +22,10 @@ import { useIsChildFocusedorHovered } from '../../hooks/useIsChildFocused' import { useMailAction } from '../../hooks/useMailActionV2' import { DocumentsPaths } from '../../lib/paths' import { useDocumentContext } from '../../screens/Overview/DocumentContext' -import { useGetDocumentInboxLineV3LazyQuery } from '../../screens/Overview/Overview.generated' +import { + useDocumentConfirmActionsLazyQuery, + useGetDocumentInboxLineV3LazyQuery, +} from '../../screens/Overview/Overview.generated' import { messages } from '../../utils/messages' import { FavAndStashV3 } from '../FavAndStash/FavAndStashV3' import UrgentTag from '../UrgentTag/UrgentTag' @@ -125,7 +128,12 @@ export const DocumentLineV3: FC = ({ behavior: 'smooth', }) } + const [confirmAction] = useDocumentConfirmActionsLazyQuery({ + fetchPolicy: 'no-cache', + }) + //TODO: When merged with V2 + //refactor queries and move to shared file instead of importing from screens const [getDocument, { loading: fileLoading }] = useGetDocumentInboxLineV3LazyQuery({ variables: { @@ -177,6 +185,7 @@ export const DocumentLineV3: FC = ({ includeDocument: false, }, }, + fetchPolicy: 'no-cache', onCompleted: (data) => { const actions: DocumentV2Action | undefined | null = @@ -239,6 +248,11 @@ export const DocumentLineV3: FC = ({ } } + const confirmActionCaller = (confirmed: boolean | null) => { + confirmAction({ + variables: { input: { id: documentLine.id, confirmed: confirmed } }, + }) + } const unread = !documentLine.opened && !localRead.includes(documentLine.id) const isBookmarked = bookmarked || bookmarkSuccess @@ -361,10 +375,17 @@ export const DocumentLineV3: FC = ({ { setModalVisible(false) + confirmActionCaller(true) getDocument() }} - onCancel={() => setModalVisible(false)} - onClose={toggleModal} + onCancel={() => { + setModalVisible(false) + confirmActionCaller(false) + }} + onClose={() => { + toggleModal() + confirmActionCaller(null) + }} loading={false} modalTitle={modalData?.title || formatMessage(m.acknowledgeTitle)} modalText={ diff --git a/libs/service-portal/documents/src/screens/Overview/Overview.graphql b/libs/service-portal/documents/src/screens/Overview/Overview.graphql index 0a481efd364b..229e88f87e5b 100644 --- a/libs/service-portal/documents/src/screens/Overview/Overview.graphql +++ b/libs/service-portal/documents/src/screens/Overview/Overview.graphql @@ -105,6 +105,13 @@ query GetDocumentInboxLineV2($input: DocumentInput!) { } } +query DocumentConfirmActions($input: DocumentConfirmActionsInput!) { + documentV2ConfirmActions(input: $input) { + id + confirmed + } +} + mutation MailActionV2($input: DocumentsV2MailActionInput!) { postMailActionV2(input: $input) { success