Skip to content

Commit

Permalink
fix(service-portal): subpoena fixes (#16261)
Browse files Browse the repository at this point in the history
* feat: add more audit logs

* fix: download id

* fix: PR comments

---------

Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
  • Loading branch information
disaerna and kodiakhq[bot] authored Oct 4, 2024
1 parent babf669 commit f522e6f
Show file tree
Hide file tree
Showing 7 changed files with 81 additions and 4 deletions.
22 changes: 22 additions & 0 deletions libs/api/domains/documents/src/lib/documentV2.resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand Down Expand Up @@ -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<Array<Category>> {
return this.documentServiceV2.getCategories(user.nationalId)
Expand Down
4 changes: 3 additions & 1 deletion libs/api/domains/documents/src/lib/documentV2.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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') {
Expand Down
Original file line number Diff line number Diff line change
@@ -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
}
Original file line number Diff line number Diff line change
@@ -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
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -125,7 +128,12 @@ export const DocumentLineV3: FC<Props> = ({
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: {
Expand Down Expand Up @@ -177,6 +185,7 @@ export const DocumentLineV3: FC<Props> = ({
includeDocument: false,
},
},

fetchPolicy: 'no-cache',
onCompleted: (data) => {
const actions: DocumentV2Action | undefined | null =
Expand Down Expand Up @@ -239,6 +248,11 @@ export const DocumentLineV3: FC<Props> = ({
}
}

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

Expand Down Expand Up @@ -361,10 +375,17 @@ export const DocumentLineV3: FC<Props> = ({
<ConfirmationModal
onSubmit={() => {
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={
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit f522e6f

Please sign in to comment.