Skip to content

Commit

Permalink
Tweaks for parliamentary signature collection
Browse files Browse the repository at this point in the history
  • Loading branch information
juni-haukur committed Sep 23, 2024
1 parent 2f0c3c8 commit 4fd00a5
Show file tree
Hide file tree
Showing 8 changed files with 31 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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<boolean> {
return (
await this.signatureCollectionService.signee(user, input.signeeNationalId)
).canSign
return await this.signatureCollectionService.canSignFromPaper(user, input)
}

@Scopes(ApiScope.signatureCollection)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -142,4 +143,13 @@ export class SignatureCollectionService {
input,
)
}

async canSignFromPaper(
user: User,
input: SignatureCollectionCanSignFromPaperInput,
): Promise<boolean> {
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
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand All @@ -53,7 +53,7 @@ export class SignatureCollectionAdminResolver {
async signatureCollectionAdminCanSignInfo(
@CurrentUser()
user: User,
@Args('input') input: SignatureCollectionCanSignInput,
@Args('input') input: SignatureCollectionCanSignFromPaperInput,
): Promise<CanSignInfo> {
const canSignInfo = await this.signatureCollectionService.getCanSignInfo(
user,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -377,11 +377,7 @@ export class SignatureCollectionClientService {
isDigital: signature.isDigital,
pageNumber: signature.pageNumber,
isValid: signature.valid,
canUnsign:
signature.isDigital &&
signature.valid &&
list.active &&
signedThisPeriod,
canUnsign: signature.valid && list.active && signedThisPeriod,
...list,
} as SignedList
}),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
`
9 changes: 7 additions & 2 deletions libs/service-portal/signature-collection/src/hooks/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ export const PaperSignees = ({
})
const { canSign, loadingCanSign } = useGetCanSign(
nationalIdInput,
listId,
nationalId.isValid(nationalIdInput),
)

Expand Down

0 comments on commit 4fd00a5

Please sign in to comment.