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

fix(service-portal): Tweaks for parliamentary signature collection #16123

Merged
merged 6 commits into from
Sep 24, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
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
}
juni-haukur marked this conversation as resolved.
Show resolved Hide resolved
}
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
Loading