diff --git a/libs/api/domains/signature-collection/src/lib/dto/canSign.input.ts b/libs/api/domains/signature-collection/src/lib/dto/canSignFromPaper.input.ts similarity index 62% rename from libs/api/domains/signature-collection/src/lib/dto/canSign.input.ts rename to libs/api/domains/signature-collection/src/lib/dto/canSignFromPaper.input.ts index 3f00b419735f..1aa493259781 100644 --- a/libs/api/domains/signature-collection/src/lib/dto/canSign.input.ts +++ b/libs/api/domains/signature-collection/src/lib/dto/canSignFromPaper.input.ts @@ -2,8 +2,11 @@ import { IsString } from 'class-validator' import { Field, InputType } from '@nestjs/graphql' @InputType() -export class SignatureCollectionCanSignInput { +export class SignatureCollectionCanSignFromPaperInput { @Field() @IsString() signeeNationalId!: string + @Field() + @IsString() + listId!: string } diff --git a/libs/api/domains/signature-collection/src/lib/signatureCollection.resolver.ts b/libs/api/domains/signature-collection/src/lib/signatureCollection.resolver.ts index a1f783de22de..a6edb5d5df50 100644 --- a/libs/api/domains/signature-collection/src/lib/signatureCollection.resolver.ts +++ b/libs/api/domains/signature-collection/src/lib/signatureCollection.resolver.ts @@ -30,7 +30,7 @@ import { CurrentSignee } from './decorators/signee.decorator' import { ApiScope } from '@island.is/auth/scopes' import { SignatureCollectionCancelListsInput } from './dto/cencelLists.input' import { SignatureCollectionIdInput } from './dto/collectionId.input' -import { SignatureCollectionCanSignInput } from './dto/canSign.input' +import { SignatureCollectionCanSignFromPaperInput } from './dto/canSignFromPaper.input' import { SignatureCollectionAddListsInput } from './dto/addLists.input' import { SignatureCollectionListBulkUploadInput } from './dto/bulkUpload.input' import { SignatureCollectionUploadPaperSignatureInput } from './dto/uploadPaperSignature.input' @@ -133,13 +133,11 @@ export class SignatureCollectionResolver { @Query(() => Boolean) @AccessRequirement(OwnerAccess.AllowActor) @Audit() - async signatureCollectionCanSign( - @Args('input') input: SignatureCollectionCanSignInput, + async signatureCollectionCanSignFromPaper( + @Args('input') input: SignatureCollectionCanSignFromPaperInput, @CurrentUser() user: User, ): Promise { - return ( - await this.signatureCollectionService.signee(user, input.signeeNationalId) - ).canSign + return await this.signatureCollectionService.canSignFromPaper(user, input) } @Scopes(ApiScope.signatureCollection) diff --git a/libs/api/domains/signature-collection/src/lib/signatureCollection.service.ts b/libs/api/domains/signature-collection/src/lib/signatureCollection.service.ts index c7cd95b72e88..455958cf3a62 100644 --- a/libs/api/domains/signature-collection/src/lib/signatureCollection.service.ts +++ b/libs/api/domains/signature-collection/src/lib/signatureCollection.service.ts @@ -18,6 +18,7 @@ import { SignatureCollectionAddListsInput } from './dto/addLists.input' import { SignatureCollectionOwnerInput } from './dto/owner.input' import { SignatureCollectionListBulkUploadInput } from './dto/bulkUpload.input' import { SignatureCollectionUploadPaperSignatureInput } from './dto/uploadPaperSignature.input' +import { SignatureCollectionCanSignFromPaperInput } from './dto/canSignFromPaper.input' @Injectable() export class SignatureCollectionService { @@ -142,4 +143,13 @@ export class SignatureCollectionService { input, ) } + + async canSignFromPaper( + user: User, + input: SignatureCollectionCanSignFromPaperInput, + ): Promise { + const signee = await this.signee(user, input.signeeNationalId) + const list = await this.list(input.listId, user) + return signee.canSign && list.area.id === signee.area?.id + } } diff --git a/libs/api/domains/signature-collection/src/lib/signatureCollectionAdmin.resolver.ts b/libs/api/domains/signature-collection/src/lib/signatureCollectionAdmin.resolver.ts index 58f264dd8b90..29986111d194 100644 --- a/libs/api/domains/signature-collection/src/lib/signatureCollectionAdmin.resolver.ts +++ b/libs/api/domains/signature-collection/src/lib/signatureCollectionAdmin.resolver.ts @@ -31,7 +31,7 @@ import { SignatureCollectionNationalIdInput } from './dto/nationalId.input' import { SignatureCollectionSignatureIdInput } from './dto/signatureId.input' import { SignatureCollectionIdInput } from './dto/collectionId.input' import { SignatureCollectionCandidateIdInput } from './dto/candidateId.input' -import { SignatureCollectionCanSignInput } from './dto/canSign.input' +import { SignatureCollectionCanSignFromPaperInput } from './dto/canSignFromPaper.input' import { ReasonKey } from '@island.is/clients/signature-collection' import { CanSignInfo } from './models/canSignInfo.model' @@ -53,7 +53,7 @@ export class SignatureCollectionAdminResolver { async signatureCollectionAdminCanSignInfo( @CurrentUser() user: User, - @Args('input') input: SignatureCollectionCanSignInput, + @Args('input') input: SignatureCollectionCanSignFromPaperInput, ): Promise { const canSignInfo = await this.signatureCollectionService.getCanSignInfo( user, diff --git a/libs/clients/signature-collection/src/lib/signature-collection.service.ts b/libs/clients/signature-collection/src/lib/signature-collection.service.ts index d9df57925283..c2e1df76630a 100644 --- a/libs/clients/signature-collection/src/lib/signature-collection.service.ts +++ b/libs/clients/signature-collection/src/lib/signature-collection.service.ts @@ -358,7 +358,7 @@ export class SignatureCollectionClientService { async getSignedList(auth: User): Promise { const { signatures } = await this.getSignee(auth) - const { endTime } = await this.currentCollection() + const { endTime, isPresidential } = await this.currentCollection() if (!signatures) { return null } @@ -372,13 +372,14 @@ export class SignatureCollectionClientService { ) const isExtended = list.endTime > endTime const signedThisPeriod = signature.isInitialType === !isExtended + const canUnsignDigital = isPresidential ? signature.isDigital : true return { signedDate: signature.created, isDigital: signature.isDigital, pageNumber: signature.pageNumber, isValid: signature.valid, canUnsign: - signature.isDigital && + canUnsignDigital && signature.valid && list.active && signedThisPeriod, diff --git a/libs/service-portal/signature-collection/src/hooks/graphql/queries.ts b/libs/service-portal/signature-collection/src/hooks/graphql/queries.ts index 45d50fdbe81c..4eae87f09acd 100644 --- a/libs/service-portal/signature-collection/src/hooks/graphql/queries.ts +++ b/libs/service-portal/signature-collection/src/hooks/graphql/queries.ts @@ -159,7 +159,7 @@ export const GetCurrentCollection = gql` ` export const GetCanSign = gql` - query Query($input: SignatureCollectionCanSignInput!) { - signatureCollectionCanSign(input: $input) + query Query($input: SignatureCollectionCanSignFromPaperInput!) { + signatureCollectionCanSignFromPaper(input: $input) } ` diff --git a/libs/service-portal/signature-collection/src/hooks/index.ts b/libs/service-portal/signature-collection/src/hooks/index.ts index 9c3800136b8e..1c26cfd03b61 100644 --- a/libs/service-portal/signature-collection/src/hooks/index.ts +++ b/libs/service-portal/signature-collection/src/hooks/index.ts @@ -149,18 +149,23 @@ export const useGetCurrentCollection = () => { } } -export const useGetCanSign = (signeeId: string, isValidId: boolean) => { +export const useGetCanSign = ( + signeeId: string, + listId: string, + isValidId: boolean, +) => { const { data: getCanSignData, loading: loadingCanSign } = useQuery( GetCanSign, { variables: { input: { signeeNationalId: signeeId, + listId: listId, }, }, skip: !signeeId || signeeId.length !== 10 || !isValidId, }, ) - const canSign = getCanSignData?.signatureCollectionCanSign ?? false + const canSign = getCanSignData?.signatureCollectionCanSignFromPaper ?? false return { canSign, loadingCanSign } } diff --git a/libs/service-portal/signature-collection/src/screens/Parliamentary/OwnerView/ViewList/Signees/PaperSignees.tsx b/libs/service-portal/signature-collection/src/screens/Parliamentary/OwnerView/ViewList/Signees/PaperSignees.tsx index 877cf5b5bd8f..5519f717939d 100644 --- a/libs/service-portal/signature-collection/src/screens/Parliamentary/OwnerView/ViewList/Signees/PaperSignees.tsx +++ b/libs/service-portal/signature-collection/src/screens/Parliamentary/OwnerView/ViewList/Signees/PaperSignees.tsx @@ -44,6 +44,7 @@ export const PaperSignees = ({ }) const { canSign, loadingCanSign } = useGetCanSign( nationalIdInput, + listId, nationalId.isValid(nationalIdInput), )